blob: fac61a9f64e96a01454e3874d7cfa6605450cc43 [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.
Darin Petkov4d6d9412011-08-24 13:19:54 -070064 virtual void Connect(Error *error);
Darin Petkovfb0625e2012-01-16 13:05:56 +010065 virtual void Disconnect(Error *error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050066 virtual void ActivateCellularModem(const std::string &carrier,
Eric Shienbrood9a245532012-03-07 14:20:39 -050067 Error *error,
68 const ResultCallback &callback);
Darin Petkovc408e692011-08-17 13:47:15 -070069
Darin Petkov31332412012-01-28 01:50:02 +010070 virtual std::string GetStorageIdentifier() const;
71 void SetStorageIdentifier(const std::string &identifier);
Chris Masone34af2182011-08-22 11:59:36 -070072
Ben Chan3d6de0e2012-12-10 12:01:34 -080073 void SetActivateOverNonCellularNetwork(bool state);
74 bool activate_over_non_cellular_network() const {
75 return activate_over_non_cellular_network_;
76 }
77
Darin Petkovb9c99332012-01-12 13:13:00 +010078 void SetActivationState(const std::string &state);
Darin Petkovc408e692011-08-17 13:47:15 -070079 const std::string &activation_state() const { return activation_state_; }
Chris Masone3bd3c8c2011-06-13 08:20:26 -070080
Darin Petkov381928f2012-02-02 23:00:12 +010081 void SetOLP(const OLP &olp);
82 const OLP &olp() const { return olp_; }
Darin Petkovb27e5442011-08-16 14:36:45 -070083
Darin Petkov381928f2012-02-02 23:00:12 +010084 void SetUsageURL(const std::string &url);
Darin Petkovb27e5442011-08-16 14:36:45 -070085 const std::string &usage_url() const { return usage_url_; }
Darin Petkovb27e5442011-08-16 14:36:45 -070086
Darin Petkov9cb02682012-01-28 00:17:38 +010087 void SetServingOperator(const Cellular::Operator &oper);
Darin Petkov3335b372011-08-22 11:05:32 -070088 const Cellular::Operator &serving_operator() const;
Darin Petkov3335b372011-08-22 11:05:32 -070089
Darin Petkovb72cf402011-11-22 14:51:39 +010090 // Sets network technology to |technology| and broadcasts the property change.
91 void SetNetworkTechnology(const std::string &technology);
92 const std::string &network_technology() const { return network_technology_; }
Darin Petkovd2045802011-08-23 11:09:25 -070093
Darin Petkovb72cf402011-11-22 14:51:39 +010094 // Sets roaming state to |state| and broadcasts the property change.
95 void SetRoamingState(const std::string &state);
Darin Petkovd2045802011-08-23 11:09:25 -070096 const std::string &roaming_state() const { return roaming_state_; }
Darin Petkovd2045802011-08-23 11:09:25 -070097
Ben Chan19f83972012-10-03 23:25:56 -070098 // Overrides Load and Save from parent Service class. We will call
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -040099 // the parent method.
100 virtual bool Load(StoreInterface *storage);
101 virtual bool Save(StoreInterface *storage);
102
103 Stringmap *GetUserSpecifiedApn();
104 Stringmap *GetLastGoodApn();
Jason Glasgow14521872012-05-07 19:12:15 -0400105 virtual void SetLastGoodApn(const Stringmap &apn_info);
106 virtual void ClearLastGoodApn();
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400107
Ben Chan19f83972012-10-03 23:25:56 -0700108 protected:
109 // Overrides IsAutoConnectable from parent Service class.
110 virtual bool IsAutoConnectable(const char **reason) const;
111
Paul Stewartac4ac002011-08-26 12:04:26 -0700112 private:
Darin Petkovb72cf402011-11-22 14:51:39 +0100113 friend class CellularServiceTest;
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400114 FRIEND_TEST(CellularCapabilityGSMTest, SetupApnTryList);
115 FRIEND_TEST(CellularCapabilityTest, TryApns);
Darin Petkovb72cf402011-11-22 14:51:39 +0100116 FRIEND_TEST(CellularTest, Connect);
Eric Shienbroodc7073302012-04-03 14:41:44 -0400117 FRIEND_TEST(CellularServiceTest, SetApn);
118 FRIEND_TEST(CellularServiceTest, ClearApn);
119 FRIEND_TEST(CellularServiceTest, LastGoodApn);
Ben Chan19f83972012-10-03 23:25:56 -0700120 FRIEND_TEST(CellularServiceTest, IsAutoConnectable);
121
Christopher Wiley1582bdd2012-11-15 11:31:14 -0800122 static const char kAutoConnActivating[];
Ben Chan19f83972012-10-03 23:25:56 -0700123 static const char kAutoConnDeviceDisabled[];
Darin Petkovb72cf402011-11-22 14:51:39 +0100124
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400125 void HelpRegisterDerivedStringmap(
126 const std::string &name,
127 Stringmap(CellularService::*get)(Error *error),
128 void(CellularService::*set)(const Stringmap &value, Error *error));
129
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800130 virtual std::string GetDeviceRpcId(Error *error);
Paul Stewartac4ac002011-08-26 12:04:26 -0700131
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400132 Stringmap GetApn(Error *error);
133 void SetApn(const Stringmap &value, Error *error);
134 static void SaveApn(StoreInterface *storage,
135 const std::string &storage_group,
136 const Stringmap *apn_info,
137 const std::string &keytag);
138 static void SaveApnField(StoreInterface *storage,
139 const std::string &storage_group,
140 const Stringmap *apn_info,
141 const std::string &keytag,
142 const std::string &apntag);
143 static void LoadApn(StoreInterface *storage,
144 const std::string &storage_group,
145 const std::string &keytag,
146 Stringmap *apn_info);
147 static bool LoadApnField(StoreInterface *storage,
148 const std::string &storage_group,
149 const std::string &keytag,
150 const std::string &apntag,
151 Stringmap *apn_info);
152
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700153 // Properties
Ben Chan3d6de0e2012-12-10 12:01:34 -0800154 bool activate_over_non_cellular_network_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700155 std::string activation_state_;
Darin Petkov3335b372011-08-22 11:05:32 -0700156 Cellular::Operator serving_operator_;
Darin Petkovb72cf402011-11-22 14:51:39 +0100157 std::string network_technology_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700158 std::string roaming_state_;
Darin Petkov381928f2012-02-02 23:00:12 +0100159 OLP olp_;
Darin Petkovb27e5442011-08-16 14:36:45 -0700160 std::string usage_url_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700161
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400162 Stringmap apn_info_;
163 Stringmap last_good_apn_info_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700164
Darin Petkov31332412012-01-28 01:50:02 +0100165 std::string storage_identifier_;
166
Chris Masone2b105542011-06-22 10:58:09 -0700167 CellularRefPtr cellular_;
Darin Petkovd9661952011-08-03 16:25:42 -0700168
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700169 DISALLOW_COPY_AND_ASSIGN(CellularService);
170};
171
172} // namespace shill
173
Ben Chan19f83972012-10-03 23:25:56 -0700174#endif // SHILL_CELLULAR_SERVICE_H_