blob: 0d7d2ec830609c9c72a865a2ecc18769768350ac [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);
Arman Ugurayc7b15602013-02-16 00:56:18 -080070 virtual void CompleteCellularActivation(Error *error);
Darin Petkovc408e692011-08-17 13:47:15 -070071
Darin Petkov31332412012-01-28 01:50:02 +010072 virtual std::string GetStorageIdentifier() const;
73 void SetStorageIdentifier(const std::string &identifier);
Chris Masone34af2182011-08-22 11:59:36 -070074
Ben Chan3d6de0e2012-12-10 12:01:34 -080075 void SetActivateOverNonCellularNetwork(bool state);
76 bool activate_over_non_cellular_network() const {
77 return activate_over_non_cellular_network_;
78 }
79
Arman Ugurayc7b15602013-02-16 00:56:18 -080080 virtual void SetActivationState(const std::string &state);
Darin Petkovc408e692011-08-17 13:47:15 -070081 const std::string &activation_state() const { return activation_state_; }
Chris Masone3bd3c8c2011-06-13 08:20:26 -070082
Darin Petkov381928f2012-02-02 23:00:12 +010083 void SetOLP(const OLP &olp);
84 const OLP &olp() const { return olp_; }
Darin Petkovb27e5442011-08-16 14:36:45 -070085
Darin Petkov381928f2012-02-02 23:00:12 +010086 void SetUsageURL(const std::string &url);
Darin Petkovb27e5442011-08-16 14:36:45 -070087 const std::string &usage_url() const { return usage_url_; }
Darin Petkovb27e5442011-08-16 14:36:45 -070088
Darin Petkov9cb02682012-01-28 00:17:38 +010089 void SetServingOperator(const Cellular::Operator &oper);
Darin Petkov3335b372011-08-22 11:05:32 -070090 const Cellular::Operator &serving_operator() const;
Darin Petkov3335b372011-08-22 11:05:32 -070091
Darin Petkovb72cf402011-11-22 14:51:39 +010092 // Sets network technology to |technology| and broadcasts the property change.
93 void SetNetworkTechnology(const std::string &technology);
94 const std::string &network_technology() const { return network_technology_; }
Darin Petkovd2045802011-08-23 11:09:25 -070095
Darin Petkovb72cf402011-11-22 14:51:39 +010096 // Sets roaming state to |state| and broadcasts the property change.
97 void SetRoamingState(const std::string &state);
Darin Petkovd2045802011-08-23 11:09:25 -070098 const std::string &roaming_state() const { return roaming_state_; }
Darin Petkovd2045802011-08-23 11:09:25 -070099
Thieu Le7cf36b02013-01-30 17:15:56 -0800100 bool is_auto_connecting() const {
101 return is_auto_connecting_;
102 }
103
Ben Chan19f83972012-10-03 23:25:56 -0700104 // Overrides Load and Save from parent Service class. We will call
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400105 // the parent method.
106 virtual bool Load(StoreInterface *storage);
107 virtual bool Save(StoreInterface *storage);
108
109 Stringmap *GetUserSpecifiedApn();
110 Stringmap *GetLastGoodApn();
Jason Glasgow14521872012-05-07 19:12:15 -0400111 virtual void SetLastGoodApn(const Stringmap &apn_info);
112 virtual void ClearLastGoodApn();
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400113
Ben Chan19f83972012-10-03 23:25:56 -0700114 protected:
115 // Overrides IsAutoConnectable from parent Service class.
116 virtual bool IsAutoConnectable(const char **reason) const;
117
Paul Stewartac4ac002011-08-26 12:04:26 -0700118 private:
Arman Ugurayc9533572013-01-22 17:34:20 -0800119 friend class CellularCapabilityUniversalTest;
Darin Petkovb72cf402011-11-22 14:51:39 +0100120 friend class CellularServiceTest;
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400121 FRIEND_TEST(CellularCapabilityGSMTest, SetupApnTryList);
122 FRIEND_TEST(CellularCapabilityTest, TryApns);
Arman Ugurayc7b15602013-02-16 00:56:18 -0800123 FRIEND_TEST(CellularCapabilityUniversalMainTest, UpdateIccidActivationState);
Arman Uguray1361c032013-02-11 17:53:39 -0800124 FRIEND_TEST(CellularCapabilityUniversalMainTest, UpdateServiceName);
125 FRIEND_TEST(CellularCapabilityUniversalMainTest, UpdateStorageIdentifier);
Darin Petkovb72cf402011-11-22 14:51:39 +0100126 FRIEND_TEST(CellularTest, Connect);
Eric Shienbroodc7073302012-04-03 14:41:44 -0400127 FRIEND_TEST(CellularServiceTest, SetApn);
128 FRIEND_TEST(CellularServiceTest, ClearApn);
129 FRIEND_TEST(CellularServiceTest, LastGoodApn);
Ben Chan19f83972012-10-03 23:25:56 -0700130 FRIEND_TEST(CellularServiceTest, IsAutoConnectable);
131
Christopher Wiley1582bdd2012-11-15 11:31:14 -0800132 static const char kAutoConnActivating[];
Ben Chan19f83972012-10-03 23:25:56 -0700133 static const char kAutoConnDeviceDisabled[];
Darin Petkovb72cf402011-11-22 14:51:39 +0100134
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400135 void HelpRegisterDerivedStringmap(
136 const std::string &name,
137 Stringmap(CellularService::*get)(Error *error),
138 void(CellularService::*set)(const Stringmap &value, Error *error));
139
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800140 virtual std::string GetDeviceRpcId(Error *error);
Paul Stewartac4ac002011-08-26 12:04:26 -0700141
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400142 Stringmap GetApn(Error *error);
143 void SetApn(const Stringmap &value, Error *error);
144 static void SaveApn(StoreInterface *storage,
145 const std::string &storage_group,
146 const Stringmap *apn_info,
147 const std::string &keytag);
148 static void SaveApnField(StoreInterface *storage,
149 const std::string &storage_group,
150 const Stringmap *apn_info,
151 const std::string &keytag,
152 const std::string &apntag);
153 static void LoadApn(StoreInterface *storage,
154 const std::string &storage_group,
155 const std::string &keytag,
156 Stringmap *apn_info);
157 static bool LoadApnField(StoreInterface *storage,
158 const std::string &storage_group,
159 const std::string &keytag,
160 const std::string &apntag,
161 Stringmap *apn_info);
162
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700163 // Properties
Ben Chan3d6de0e2012-12-10 12:01:34 -0800164 bool activate_over_non_cellular_network_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700165 std::string activation_state_;
Darin Petkov3335b372011-08-22 11:05:32 -0700166 Cellular::Operator serving_operator_;
Darin Petkovb72cf402011-11-22 14:51:39 +0100167 std::string network_technology_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700168 std::string roaming_state_;
Darin Petkov381928f2012-02-02 23:00:12 +0100169 OLP olp_;
Darin Petkovb27e5442011-08-16 14:36:45 -0700170 std::string usage_url_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700171
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400172 Stringmap apn_info_;
173 Stringmap last_good_apn_info_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700174
Darin Petkov31332412012-01-28 01:50:02 +0100175 std::string storage_identifier_;
176
Chris Masone2b105542011-06-22 10:58:09 -0700177 CellularRefPtr cellular_;
Darin Petkovd9661952011-08-03 16:25:42 -0700178
Thieu Le7cf36b02013-01-30 17:15:56 -0800179 // Flag indicating that a connect request is an auto-connect request.
180 // Note: Since Connect() is asynchronous, this flag is only set during the
181 // call to Connect(). It does not remain set while the async request is
182 // in flight.
183 bool is_auto_connecting_;
184
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700185 DISALLOW_COPY_AND_ASSIGN(CellularService);
186};
187
188} // namespace shill
189
Ben Chan19f83972012-10-03 23:25:56 -0700190#endif // SHILL_CELLULAR_SERVICE_H_