blob: 4c1a8c158816b45e3d0f9442925a7a4935d0e036 [file] [log] [blame]
Darin Petkovb9c99332012-01-12 13:13:00 +01001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Chris Masone3bd3c8c2011-06-13 08:20:26 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Ben Chan19f83972012-10-03 23:25:56 -07005#ifndef SHILL_CELLULAR_SERVICE_H_
6#define SHILL_CELLULAR_SERVICE_H_
Chris Masone3bd3c8c2011-06-13 08:20:26 -07007
8#include <map>
9#include <string>
10
11#include <base/basictypes.h>
Darin Petkovb72cf402011-11-22 14:51:39 +010012#include <gtest/gtest_prod.h> // for FRIEND_TEST
Chris Masone3bd3c8c2011-06-13 08:20:26 -070013
Darin Petkov3335b372011-08-22 11:05:32 -070014#include "shill/cellular.h"
Chris Masone2b105542011-06-22 10:58:09 -070015#include "shill/refptr_types.h"
Chris Masone3bd3c8c2011-06-13 08:20:26 -070016#include "shill/service.h"
17
18namespace shill {
19
Chris Masone6791a432011-07-12 13:23:19 -070020class ControlInterface;
Darin Petkovb100ae72011-08-24 16:19:45 -070021class Error;
Chris Masone6791a432011-07-12 13:23:19 -070022class EventDispatcher;
23class Manager;
24
Chris Masone3bd3c8c2011-06-13 08:20:26 -070025class CellularService : public Service {
26 public:
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -040027 static const char kStorageAPN[];
28 static const char kStorageLastGoodAPN[];
29
Darin Petkov381928f2012-02-02 23:00:12 +010030 // Online payment portal.
31 class OLP {
32 public:
33 OLP();
34 ~OLP();
35
36 void CopyFrom(const OLP &olp);
37 bool Equals(const OLP &olp) const;
38
39 const std::string &GetURL() const;
40 void SetURL(const std::string &url);
41
42 const std::string &GetMethod() const;
43 void SetMethod(const std::string &method);
44
45 const std::string &GetPostData() const;
46 void SetPostData(const std::string &post_data);
47
48 const Stringmap &ToDict() const;
49
50 private:
51 Stringmap dict_;
52
53 DISALLOW_COPY_AND_ASSIGN(OLP);
54 };
55
Chris Masone3bd3c8c2011-06-13 08:20:26 -070056 CellularService(ControlInterface *control_interface,
57 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -080058 Metrics *metrics,
Chris Masone6791a432011-07-12 13:23:19 -070059 Manager *manager,
mukesh agrawal51a7e932011-07-27 16:18:26 -070060 const CellularRefPtr &device);
Darin Petkovd9661952011-08-03 16:25:42 -070061 virtual ~CellularService();
62
Darin Petkovc408e692011-08-17 13:47:15 -070063 // Inherited from Service.
Thieu Le7cf36b02013-01-30 17:15:56 -080064 virtual void AutoConnect();
Darin Petkov4d6d9412011-08-24 13:19:54 -070065 virtual void Connect(Error *error);
Darin Petkovfb0625e2012-01-16 13:05:56 +010066 virtual void Disconnect(Error *error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050067 virtual void ActivateCellularModem(const std::string &carrier,
Eric Shienbrood9a245532012-03-07 14:20:39 -050068 Error *error,
69 const ResultCallback &callback);
Darin Petkovc408e692011-08-17 13:47:15 -070070
Darin Petkov31332412012-01-28 01:50:02 +010071 virtual std::string GetStorageIdentifier() const;
72 void SetStorageIdentifier(const std::string &identifier);
Chris Masone34af2182011-08-22 11:59:36 -070073
Ben Chan3d6de0e2012-12-10 12:01:34 -080074 void SetActivateOverNonCellularNetwork(bool state);
75 bool activate_over_non_cellular_network() const {
76 return activate_over_non_cellular_network_;
77 }
78
Darin Petkovb9c99332012-01-12 13:13:00 +010079 void SetActivationState(const std::string &state);
Darin Petkovc408e692011-08-17 13:47:15 -070080 const std::string &activation_state() const { return activation_state_; }
Chris Masone3bd3c8c2011-06-13 08:20:26 -070081
Darin Petkov381928f2012-02-02 23:00:12 +010082 void SetOLP(const OLP &olp);
83 const OLP &olp() const { return olp_; }
Darin Petkovb27e5442011-08-16 14:36:45 -070084
Darin Petkov381928f2012-02-02 23:00:12 +010085 void SetUsageURL(const std::string &url);
Darin Petkovb27e5442011-08-16 14:36:45 -070086 const std::string &usage_url() const { return usage_url_; }
Darin Petkovb27e5442011-08-16 14:36:45 -070087
Darin Petkov9cb02682012-01-28 00:17:38 +010088 void SetServingOperator(const Cellular::Operator &oper);
Darin Petkov3335b372011-08-22 11:05:32 -070089 const Cellular::Operator &serving_operator() const;
Darin Petkov3335b372011-08-22 11:05:32 -070090
Darin Petkovb72cf402011-11-22 14:51:39 +010091 // Sets network technology to |technology| and broadcasts the property change.
92 void SetNetworkTechnology(const std::string &technology);
93 const std::string &network_technology() const { return network_technology_; }
Darin Petkovd2045802011-08-23 11:09:25 -070094
Darin Petkovb72cf402011-11-22 14:51:39 +010095 // Sets roaming state to |state| and broadcasts the property change.
96 void SetRoamingState(const std::string &state);
Darin Petkovd2045802011-08-23 11:09:25 -070097 const std::string &roaming_state() const { return roaming_state_; }
Darin Petkovd2045802011-08-23 11:09:25 -070098
Thieu Le7cf36b02013-01-30 17:15:56 -080099 bool is_auto_connecting() const {
100 return is_auto_connecting_;
101 }
102
Ben Chan19f83972012-10-03 23:25:56 -0700103 // Overrides Load and Save from parent Service class. We will call
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400104 // the parent method.
105 virtual bool Load(StoreInterface *storage);
106 virtual bool Save(StoreInterface *storage);
107
108 Stringmap *GetUserSpecifiedApn();
109 Stringmap *GetLastGoodApn();
Jason Glasgow14521872012-05-07 19:12:15 -0400110 virtual void SetLastGoodApn(const Stringmap &apn_info);
111 virtual void ClearLastGoodApn();
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400112
Ben Chan19f83972012-10-03 23:25:56 -0700113 protected:
114 // Overrides IsAutoConnectable from parent Service class.
115 virtual bool IsAutoConnectable(const char **reason) const;
116
Paul Stewartac4ac002011-08-26 12:04:26 -0700117 private:
Arman Ugurayc9533572013-01-22 17:34:20 -0800118 friend class CellularCapabilityUniversalTest;
Darin Petkovb72cf402011-11-22 14:51:39 +0100119 friend class CellularServiceTest;
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400120 FRIEND_TEST(CellularCapabilityGSMTest, SetupApnTryList);
121 FRIEND_TEST(CellularCapabilityTest, TryApns);
Arman Uguray1361c032013-02-11 17:53:39 -0800122 FRIEND_TEST(CellularCapabilityUniversalMainTest, UpdateServiceName);
123 FRIEND_TEST(CellularCapabilityUniversalMainTest, UpdateStorageIdentifier);
Darin Petkovb72cf402011-11-22 14:51:39 +0100124 FRIEND_TEST(CellularTest, Connect);
Eric Shienbroodc7073302012-04-03 14:41:44 -0400125 FRIEND_TEST(CellularServiceTest, SetApn);
126 FRIEND_TEST(CellularServiceTest, ClearApn);
127 FRIEND_TEST(CellularServiceTest, LastGoodApn);
Ben Chan19f83972012-10-03 23:25:56 -0700128 FRIEND_TEST(CellularServiceTest, IsAutoConnectable);
129
Christopher Wiley1582bdd2012-11-15 11:31:14 -0800130 static const char kAutoConnActivating[];
Ben Chan19f83972012-10-03 23:25:56 -0700131 static const char kAutoConnDeviceDisabled[];
Darin Petkovb72cf402011-11-22 14:51:39 +0100132
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400133 void HelpRegisterDerivedStringmap(
134 const std::string &name,
135 Stringmap(CellularService::*get)(Error *error),
136 void(CellularService::*set)(const Stringmap &value, Error *error));
137
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800138 virtual std::string GetDeviceRpcId(Error *error);
Paul Stewartac4ac002011-08-26 12:04:26 -0700139
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400140 Stringmap GetApn(Error *error);
141 void SetApn(const Stringmap &value, Error *error);
142 static void SaveApn(StoreInterface *storage,
143 const std::string &storage_group,
144 const Stringmap *apn_info,
145 const std::string &keytag);
146 static void SaveApnField(StoreInterface *storage,
147 const std::string &storage_group,
148 const Stringmap *apn_info,
149 const std::string &keytag,
150 const std::string &apntag);
151 static void LoadApn(StoreInterface *storage,
152 const std::string &storage_group,
153 const std::string &keytag,
154 Stringmap *apn_info);
155 static bool LoadApnField(StoreInterface *storage,
156 const std::string &storage_group,
157 const std::string &keytag,
158 const std::string &apntag,
159 Stringmap *apn_info);
160
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700161 // Properties
Ben Chan3d6de0e2012-12-10 12:01:34 -0800162 bool activate_over_non_cellular_network_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700163 std::string activation_state_;
Darin Petkov3335b372011-08-22 11:05:32 -0700164 Cellular::Operator serving_operator_;
Darin Petkovb72cf402011-11-22 14:51:39 +0100165 std::string network_technology_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700166 std::string roaming_state_;
Darin Petkov381928f2012-02-02 23:00:12 +0100167 OLP olp_;
Darin Petkovb27e5442011-08-16 14:36:45 -0700168 std::string usage_url_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700169
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400170 Stringmap apn_info_;
171 Stringmap last_good_apn_info_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700172
Darin Petkov31332412012-01-28 01:50:02 +0100173 std::string storage_identifier_;
174
Chris Masone2b105542011-06-22 10:58:09 -0700175 CellularRefPtr cellular_;
Darin Petkovd9661952011-08-03 16:25:42 -0700176
Thieu Le7cf36b02013-01-30 17:15:56 -0800177 // Flag indicating that a connect request is an auto-connect request.
178 // Note: Since Connect() is asynchronous, this flag is only set during the
179 // call to Connect(). It does not remain set while the async request is
180 // in flight.
181 bool is_auto_connecting_;
182
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700183 DISALLOW_COPY_AND_ASSIGN(CellularService);
184};
185
186} // namespace shill
187
Ben Chan19f83972012-10-03 23:25:56 -0700188#endif // SHILL_CELLULAR_SERVICE_H_