Darin Petkov | b9c9933 | 2012-01-12 13:13:00 +0100 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 5 | #ifndef SHILL_CELLULAR_SERVICE_H_ |
| 6 | #define SHILL_CELLULAR_SERVICE_H_ |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 7 | |
| 8 | #include <map> |
| 9 | #include <string> |
| 10 | |
| 11 | #include <base/basictypes.h> |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 12 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 13 | |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 14 | #include "shill/cellular.h" |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 15 | #include "shill/refptr_types.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 16 | #include "shill/service.h" |
| 17 | |
| 18 | namespace shill { |
| 19 | |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 20 | class ControlInterface; |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 21 | class Error; |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 22 | class EventDispatcher; |
| 23 | class Manager; |
| 24 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 25 | class CellularService : public Service { |
| 26 | public: |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 27 | static const char kStorageAPN[]; |
| 28 | static const char kStorageLastGoodAPN[]; |
| 29 | |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 30 | // 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 Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 56 | CellularService(ControlInterface *control_interface, |
| 57 | EventDispatcher *dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 58 | Metrics *metrics, |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 59 | Manager *manager, |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 60 | const CellularRefPtr &device); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 61 | virtual ~CellularService(); |
| 62 | |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 63 | // Inherited from Service. |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 64 | virtual void Connect(Error *error); |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 65 | virtual void Disconnect(Error *error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 66 | virtual void ActivateCellularModem(const std::string &carrier, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 67 | Error *error, |
| 68 | const ResultCallback &callback); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 69 | |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 70 | virtual std::string GetStorageIdentifier() const; |
| 71 | void SetStorageIdentifier(const std::string &identifier); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 72 | |
Darin Petkov | b9c9933 | 2012-01-12 13:13:00 +0100 | [diff] [blame] | 73 | void SetActivationState(const std::string &state); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 74 | const std::string &activation_state() const { return activation_state_; } |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 75 | |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 76 | void SetOLP(const OLP &olp); |
| 77 | const OLP &olp() const { return olp_; } |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 78 | |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 79 | void SetUsageURL(const std::string &url); |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 80 | const std::string &usage_url() const { return usage_url_; } |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 81 | |
Darin Petkov | 9cb0268 | 2012-01-28 00:17:38 +0100 | [diff] [blame] | 82 | void SetServingOperator(const Cellular::Operator &oper); |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 83 | const Cellular::Operator &serving_operator() const; |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 84 | |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 85 | // Sets network technology to |technology| and broadcasts the property change. |
| 86 | void SetNetworkTechnology(const std::string &technology); |
| 87 | const std::string &network_technology() const { return network_technology_; } |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 88 | |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 89 | // Sets roaming state to |state| and broadcasts the property change. |
| 90 | void SetRoamingState(const std::string &state); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 91 | const std::string &roaming_state() const { return roaming_state_; } |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 92 | |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 93 | // Overrides Load and Save from parent Service class. We will call |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 94 | // the parent method. |
| 95 | virtual bool Load(StoreInterface *storage); |
| 96 | virtual bool Save(StoreInterface *storage); |
| 97 | |
| 98 | Stringmap *GetUserSpecifiedApn(); |
| 99 | Stringmap *GetLastGoodApn(); |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 100 | virtual void SetLastGoodApn(const Stringmap &apn_info); |
| 101 | virtual void ClearLastGoodApn(); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 102 | |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 103 | protected: |
| 104 | // Overrides IsAutoConnectable from parent Service class. |
| 105 | virtual bool IsAutoConnectable(const char **reason) const; |
| 106 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 107 | private: |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 108 | friend class CellularServiceTest; |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 109 | FRIEND_TEST(CellularCapabilityGSMTest, SetupApnTryList); |
| 110 | FRIEND_TEST(CellularCapabilityTest, TryApns); |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 111 | FRIEND_TEST(CellularTest, Connect); |
Eric Shienbrood | c707330 | 2012-04-03 14:41:44 -0400 | [diff] [blame] | 112 | FRIEND_TEST(CellularServiceTest, SetApn); |
| 113 | FRIEND_TEST(CellularServiceTest, ClearApn); |
| 114 | FRIEND_TEST(CellularServiceTest, LastGoodApn); |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 115 | FRIEND_TEST(CellularServiceTest, IsAutoConnectable); |
| 116 | |
| 117 | static const char kAutoConnDeviceDisabled[]; |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 118 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 119 | void HelpRegisterDerivedStringmap( |
| 120 | const std::string &name, |
| 121 | Stringmap(CellularService::*get)(Error *error), |
| 122 | void(CellularService::*set)(const Stringmap &value, Error *error)); |
| 123 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 124 | virtual std::string GetDeviceRpcId(Error *error); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 125 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 126 | Stringmap GetApn(Error *error); |
| 127 | void SetApn(const Stringmap &value, Error *error); |
| 128 | static void SaveApn(StoreInterface *storage, |
| 129 | const std::string &storage_group, |
| 130 | const Stringmap *apn_info, |
| 131 | const std::string &keytag); |
| 132 | static void SaveApnField(StoreInterface *storage, |
| 133 | const std::string &storage_group, |
| 134 | const Stringmap *apn_info, |
| 135 | const std::string &keytag, |
| 136 | const std::string &apntag); |
| 137 | static void LoadApn(StoreInterface *storage, |
| 138 | const std::string &storage_group, |
| 139 | const std::string &keytag, |
| 140 | Stringmap *apn_info); |
| 141 | static bool LoadApnField(StoreInterface *storage, |
| 142 | const std::string &storage_group, |
| 143 | const std::string &keytag, |
| 144 | const std::string &apntag, |
| 145 | Stringmap *apn_info); |
| 146 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 147 | // Properties |
| 148 | std::string activation_state_; |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 149 | Cellular::Operator serving_operator_; |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 150 | std::string network_technology_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 151 | std::string roaming_state_; |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 152 | OLP olp_; |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 153 | std::string usage_url_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 154 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 155 | Stringmap apn_info_; |
| 156 | Stringmap last_good_apn_info_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 157 | |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 158 | std::string storage_identifier_; |
| 159 | |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 160 | CellularRefPtr cellular_; |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 161 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 162 | DISALLOW_COPY_AND_ASSIGN(CellularService); |
| 163 | }; |
| 164 | |
| 165 | } // namespace shill |
| 166 | |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 167 | #endif // SHILL_CELLULAR_SERVICE_H_ |