Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [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 | |
| 5 | #ifndef SHILL_CELLULAR_CAPABILITY_ |
| 6 | #define SHILL_CELLULAR_CAPABILITY_ |
| 7 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 8 | #include <string> |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 9 | #include <vector> |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 10 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 11 | #include <base/basictypes.h> |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 12 | #include <base/callback.h> |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 13 | #include <base/memory/scoped_ptr.h> |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 14 | #include <base/memory/weak_ptr.h> |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 15 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 16 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 17 | #include "shill/dbus_properties.h" |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 18 | #include "shill/modem_proxy_interface.h" |
| 19 | #include "shill/modem_simple_proxy_interface.h" |
| 20 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 21 | namespace shill { |
| 22 | |
| 23 | class Cellular; |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 24 | class Error; |
| 25 | class EventDispatcher; |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 26 | class ProxyFactory; |
| 27 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 28 | typedef std::vector<base::Closure> CellularTaskList; |
| 29 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 30 | // Cellular devices instantiate subclasses of CellularCapability that |
| 31 | // handle the specific modem technologies and capabilities. |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 32 | class CellularCapability { |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 33 | public: |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 34 | static const int kTimeoutActivate; |
| 35 | static const int kTimeoutConnect; |
| 36 | static const int kTimeoutDefault; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 37 | static const int kTimeoutEnable; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 38 | static const int kTimeoutRegister; |
| 39 | static const int kTimeoutScan; |
| 40 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 41 | static const char kConnectPropertyApn[]; |
| 42 | static const char kConnectPropertyApnUsername[]; |
| 43 | static const char kConnectPropertyApnPassword[]; |
| 44 | static const char kConnectPropertyHomeOnly[]; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 45 | static const char kConnectPropertyPhoneNumber[]; |
| 46 | static const char kPropertyIMSI[]; |
| 47 | |
| 48 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 49 | // |cellular| is the parent Cellular device. |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 50 | CellularCapability(Cellular *cellular, ProxyFactory *proxy_factory); |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 51 | virtual ~CellularCapability(); |
| 52 | |
| 53 | Cellular *cellular() const { return cellular_; } |
| 54 | ProxyFactory *proxy_factory() const { return proxy_factory_; } |
Darin Petkov | 5f316f6 | 2011-11-18 12:10:26 +0100 | [diff] [blame] | 55 | |
| 56 | // Invoked by the parent Cellular device when a new service is created. |
| 57 | virtual void OnServiceCreated() = 0; |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 58 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 59 | virtual void UpdateStatus(const DBusPropertiesMap &properties) = 0; |
| 60 | |
| 61 | virtual void SetupConnectProperties(DBusPropertiesMap *properties) = 0; |
| 62 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 63 | bool allow_roaming() const { return allow_roaming_; } |
| 64 | |
| 65 | // StartModem attempts to put the modem in a state in which it is |
| 66 | // usable for creating services and establishing connections (if |
| 67 | // network conditions permit). It potentially consists of multiple |
| 68 | // non-blocking calls to the modem-manager server. After each call, |
| 69 | // control is passed back up to the main loop. Each time a reply to |
| 70 | // a non-blocking call is received, the operation advances to the next |
| 71 | // step, until either an error occurs in one of them, or all the steps |
| 72 | // have been completed, at which point StartModem() is finished. |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 73 | virtual void StartModem(Error *error, |
| 74 | const ResultCallback &callback) = 0; |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 75 | // StopModem disconnects and disables a modem asynchronously. |
| 76 | // |callback| is invoked when this completes and the result is passed |
| 77 | // to the callback. |
| 78 | virtual void StopModem(Error *error, const ResultCallback &callback); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 79 | virtual void Connect(const DBusPropertiesMap &properties, Error *error, |
| 80 | const ResultCallback &callback); |
| 81 | virtual void Disconnect(Error *error, const ResultCallback &callback); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 82 | |
| 83 | // Activates the modem. Returns an Error on failure. |
| 84 | // The default implementation fails by returning a kNotSupported error |
| 85 | // to the caller. |
| 86 | virtual void Activate(const std::string &carrier, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 87 | Error *error, const ResultCallback &callback); |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 88 | |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 89 | // Network registration. |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 90 | virtual void RegisterOnNetwork(const std::string &network_id, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 91 | Error *error, |
| 92 | const ResultCallback &callback); |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 93 | virtual bool IsRegistered() = 0; |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 94 | |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 95 | virtual std::string CreateFriendlyServiceName() = 0; |
| 96 | |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 97 | // PIN management. The default implementation fails by returning an error. |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 98 | virtual void RequirePIN(const std::string &pin, bool require, |
| 99 | Error *error, const ResultCallback &callback); |
| 100 | virtual void EnterPIN(const std::string &pin, |
| 101 | Error *error, const ResultCallback &callback); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 102 | virtual void UnblockPIN(const std::string &unblock_code, |
| 103 | const std::string &pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 104 | Error *error, const ResultCallback &callback); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 105 | virtual void ChangePIN(const std::string &old_pin, |
| 106 | const std::string &new_pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 107 | Error *error, const ResultCallback &callback); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 108 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 109 | // Network scanning. The default implementation fails by invoking |
| 110 | // the reply handler with an error. |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 111 | virtual void Scan(Error *error, const ResultCallback &callback); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 112 | |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 113 | // Returns an empty string if the network technology is unknown. |
| 114 | virtual std::string GetNetworkTechnologyString() const = 0; |
| 115 | |
| 116 | virtual std::string GetRoamingStateString() const = 0; |
| 117 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 118 | virtual void GetSignalQuality() = 0; |
| 119 | |
Eric Shienbrood | 0db6a9b | 2012-03-30 16:11:39 -0400 | [diff] [blame] | 120 | virtual std::string GetTypeString() const = 0; |
| 121 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 122 | virtual void OnModemManagerPropertiesChanged( |
| 123 | const DBusPropertiesMap &properties) = 0; |
| 124 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 125 | protected: |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 126 | // The following five methods are only ever called as |
| 127 | // callbacks (from the main loop), which is why they |
| 128 | // don't take an Error * argument. |
| 129 | virtual void EnableModem(const ResultCallback &callback); |
| 130 | virtual void DisableModem(const ResultCallback &callback); |
| 131 | virtual void GetModemStatus(const ResultCallback &callback); |
| 132 | virtual void GetModemInfo(const ResultCallback &callback); |
| 133 | virtual void GetProperties(const ResultCallback &callback) = 0; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 134 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 135 | virtual void GetRegistrationState() = 0; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 136 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 137 | void FinishEnable(const ResultCallback &callback); |
| 138 | void FinishDisable(const ResultCallback &callback); |
| 139 | virtual void InitProxies(); |
| 140 | virtual void ReleaseProxies(); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 141 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 142 | static void OnUnsupportedOperation(const char *operation, Error *error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 143 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 144 | virtual void OnConnectReply(const ResultCallback &callback, |
| 145 | const Error &error); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 146 | // Run the next task in a list. |
| 147 | // Precondition: |tasks| is not empty. |
| 148 | void RunNextStep(CellularTaskList *tasks); |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 149 | // StepCompletedCallback is called after a task completes. |
| 150 | // |callback| is the original callback that needs to be invoked when all of |
| 151 | // the tasks complete or if there is a failure. |ignore_error| will be set |
| 152 | // to true if the next task should be run regardless of the result of the |
| 153 | // just-completed task. |tasks| is the list of tasks remaining. |error| is |
| 154 | // the result of the just-completed task. |
| 155 | void StepCompletedCallback(const ResultCallback &callback, bool ignore_error, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 156 | CellularTaskList *tasks, const Error &error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 157 | // Properties |
| 158 | bool allow_roaming_; |
Darin Petkov | 0d06f7d | 2012-02-03 13:08:19 +0100 | [diff] [blame] | 159 | bool scanning_supported_; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 160 | std::string carrier_; |
| 161 | std::string meid_; |
| 162 | std::string imei_; |
| 163 | std::string imsi_; |
| 164 | std::string esn_; |
| 165 | std::string mdn_; |
| 166 | std::string min_; |
| 167 | std::string model_id_; |
| 168 | std::string manufacturer_; |
| 169 | std::string firmware_revision_; |
| 170 | std::string hardware_revision_; |
| 171 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 172 | private: |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 173 | friend class CellularCapabilityGSMTest; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 174 | friend class CellularCapabilityTest; |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 175 | friend class CellularTest; |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 176 | FRIEND_TEST(CellularCapabilityGSMTest, SetStorageIdentifier); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 177 | FRIEND_TEST(CellularCapabilityGSMTest, UpdateStatus); |
Darin Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 178 | FRIEND_TEST(CellularCapabilityTest, AllowRoaming); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 179 | FRIEND_TEST(CellularCapabilityTest, EnableModemFail); |
| 180 | FRIEND_TEST(CellularCapabilityTest, EnableModemSucceed); |
| 181 | FRIEND_TEST(CellularCapabilityTest, FinishEnable); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 182 | FRIEND_TEST(CellularCapabilityTest, GetModemInfo); |
| 183 | FRIEND_TEST(CellularCapabilityTest, GetModemStatus); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 184 | FRIEND_TEST(CellularCapabilityTest, TryApns); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 185 | FRIEND_TEST(CellularServiceTest, FriendlyName); |
| 186 | FRIEND_TEST(CellularTest, StartCDMARegister); |
| 187 | FRIEND_TEST(CellularTest, StartConnected); |
| 188 | FRIEND_TEST(CellularTest, StartGSMRegister); |
| 189 | FRIEND_TEST(CellularTest, StartLinked); |
| 190 | FRIEND_TEST(CellularTest, Connect); |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 191 | FRIEND_TEST(CellularTest, ConnectFailure); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 192 | FRIEND_TEST(CellularTest, Disconnect); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 193 | |
Darin Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 194 | void HelpRegisterDerivedBool( |
| 195 | const std::string &name, |
| 196 | bool(CellularCapability::*get)(Error *error), |
| 197 | void(CellularCapability::*set)(const bool &value, Error *error)); |
| 198 | |
| 199 | bool GetAllowRoaming(Error */*error*/) { return allow_roaming_; } |
| 200 | void SetAllowRoaming(const bool &value, Error *error); |
| 201 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 202 | // Method reply and signal callbacks from Modem interface |
| 203 | virtual void OnModemStateChangedSignal( |
| 204 | uint32 old_state, uint32 new_state, uint32 reason); |
| 205 | virtual void OnGetModemInfoReply(const ResultCallback &callback, |
| 206 | const ModemHardwareInfo &info, |
| 207 | const Error &error); |
| 208 | |
| 209 | // Method reply callbacks from Modem.Simple interface |
| 210 | virtual void OnGetModemStatusReply(const ResultCallback &callback, |
| 211 | const DBusPropertiesMap &props, |
| 212 | const Error &error); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 213 | virtual void OnDisconnectReply(const ResultCallback &callback, |
| 214 | const Error &error); |
| 215 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 216 | Cellular *cellular_; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 217 | |
| 218 | // Store cached copies of singletons for speed/ease of testing. |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 219 | ProxyFactory *proxy_factory_; |
| 220 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 221 | scoped_ptr<ModemProxyInterface> proxy_; |
| 222 | scoped_ptr<ModemSimpleProxyInterface> simple_proxy_; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 223 | base::WeakPtrFactory<CellularCapability> weak_ptr_factory_; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 224 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 225 | DISALLOW_COPY_AND_ASSIGN(CellularCapability); |
| 226 | }; |
| 227 | |
| 228 | } // namespace shill |
| 229 | |
| 230 | #endif // SHILL_CELLULAR_CAPABILITY_ |