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; |
| 75 | // StopModem is also a multi-step operation consisting of several |
| 76 | // non-blocking calls. |
| 77 | virtual void StopModem(Error *error, const ResultCallback &callback) = 0; |
| 78 | virtual void Connect(const DBusPropertiesMap &properties, Error *error, |
| 79 | const ResultCallback &callback); |
| 80 | virtual void Disconnect(Error *error, const ResultCallback &callback); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 81 | |
| 82 | // Activates the modem. Returns an Error on failure. |
| 83 | // The default implementation fails by returning a kNotSupported error |
| 84 | // to the caller. |
| 85 | virtual void Activate(const std::string &carrier, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 86 | Error *error, const ResultCallback &callback); |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 87 | |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 88 | // Network registration. |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 89 | virtual void RegisterOnNetwork(const std::string &network_id, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 90 | Error *error, |
| 91 | const ResultCallback &callback); |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 92 | virtual bool IsRegistered() = 0; |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 93 | |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 94 | virtual std::string CreateFriendlyServiceName() = 0; |
| 95 | |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 96 | // PIN management. The default implementation fails by returning an error. |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 97 | virtual void RequirePIN(const std::string &pin, bool require, |
| 98 | Error *error, const ResultCallback &callback); |
| 99 | virtual void EnterPIN(const std::string &pin, |
| 100 | Error *error, const ResultCallback &callback); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 101 | virtual void UnblockPIN(const std::string &unblock_code, |
| 102 | const std::string &pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 103 | Error *error, const ResultCallback &callback); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 104 | virtual void ChangePIN(const std::string &old_pin, |
| 105 | const std::string &new_pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 106 | Error *error, const ResultCallback &callback); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 107 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 108 | // Network scanning. The default implementation fails by invoking |
| 109 | // the reply handler with an error. |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 110 | virtual void Scan(Error *error, const ResultCallback &callback); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 111 | |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 112 | // Returns an empty string if the network technology is unknown. |
| 113 | virtual std::string GetNetworkTechnologyString() const = 0; |
| 114 | |
| 115 | virtual std::string GetRoamingStateString() const = 0; |
| 116 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 117 | virtual void GetSignalQuality() = 0; |
| 118 | |
Eric Shienbrood | 0db6a9b | 2012-03-30 16:11:39 -0400 | [diff] [blame] | 119 | virtual std::string GetTypeString() const = 0; |
| 120 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 121 | virtual void OnModemManagerPropertiesChanged( |
| 122 | const DBusPropertiesMap &properties) = 0; |
| 123 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 124 | protected: |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 125 | // The following five methods are only ever called as |
| 126 | // callbacks (from the main loop), which is why they |
| 127 | // don't take an Error * argument. |
| 128 | virtual void EnableModem(const ResultCallback &callback); |
| 129 | virtual void DisableModem(const ResultCallback &callback); |
| 130 | virtual void GetModemStatus(const ResultCallback &callback); |
| 131 | virtual void GetModemInfo(const ResultCallback &callback); |
| 132 | virtual void GetProperties(const ResultCallback &callback) = 0; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 133 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 134 | virtual void GetRegistrationState() = 0; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 135 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 136 | void FinishEnable(const ResultCallback &callback); |
| 137 | void FinishDisable(const ResultCallback &callback); |
| 138 | virtual void InitProxies(); |
| 139 | virtual void ReleaseProxies(); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 140 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 141 | static void OnUnsupportedOperation(const char *operation, Error *error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 142 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 143 | virtual void OnConnectReply(const ResultCallback &callback, |
| 144 | const Error &error); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 145 | // Run the next task in a list. |
| 146 | // Precondition: |tasks| is not empty. |
| 147 | void RunNextStep(CellularTaskList *tasks); |
| 148 | void StepCompletedCallback(const ResultCallback &callback, |
| 149 | CellularTaskList *tasks, const Error &error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 150 | // Properties |
| 151 | bool allow_roaming_; |
Darin Petkov | 0d06f7d | 2012-02-03 13:08:19 +0100 | [diff] [blame] | 152 | bool scanning_supported_; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 153 | std::string carrier_; |
| 154 | std::string meid_; |
| 155 | std::string imei_; |
| 156 | std::string imsi_; |
| 157 | std::string esn_; |
| 158 | std::string mdn_; |
| 159 | std::string min_; |
| 160 | std::string model_id_; |
| 161 | std::string manufacturer_; |
| 162 | std::string firmware_revision_; |
| 163 | std::string hardware_revision_; |
| 164 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 165 | private: |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 166 | friend class CellularTest; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 167 | friend class CellularCapabilityTest; |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 168 | FRIEND_TEST(CellularCapabilityGSMTest, SetStorageIdentifier); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 169 | FRIEND_TEST(CellularCapabilityGSMTest, UpdateStatus); |
Darin Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 170 | FRIEND_TEST(CellularCapabilityTest, AllowRoaming); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 171 | FRIEND_TEST(CellularCapabilityTest, EnableModemFail); |
| 172 | FRIEND_TEST(CellularCapabilityTest, EnableModemSucceed); |
| 173 | FRIEND_TEST(CellularCapabilityTest, FinishEnable); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 174 | FRIEND_TEST(CellularCapabilityTest, GetModemInfo); |
| 175 | FRIEND_TEST(CellularCapabilityTest, GetModemStatus); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 176 | FRIEND_TEST(CellularCapabilityTest, TryApns); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 177 | FRIEND_TEST(CellularServiceTest, FriendlyName); |
| 178 | FRIEND_TEST(CellularTest, StartCDMARegister); |
| 179 | FRIEND_TEST(CellularTest, StartConnected); |
| 180 | FRIEND_TEST(CellularTest, StartGSMRegister); |
| 181 | FRIEND_TEST(CellularTest, StartLinked); |
| 182 | FRIEND_TEST(CellularTest, Connect); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 183 | FRIEND_TEST(CellularTest, Disconnect); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 184 | |
Darin Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 185 | void HelpRegisterDerivedBool( |
| 186 | const std::string &name, |
| 187 | bool(CellularCapability::*get)(Error *error), |
| 188 | void(CellularCapability::*set)(const bool &value, Error *error)); |
| 189 | |
| 190 | bool GetAllowRoaming(Error */*error*/) { return allow_roaming_; } |
| 191 | void SetAllowRoaming(const bool &value, Error *error); |
| 192 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 193 | // Method reply and signal callbacks from Modem interface |
| 194 | virtual void OnModemStateChangedSignal( |
| 195 | uint32 old_state, uint32 new_state, uint32 reason); |
| 196 | virtual void OnGetModemInfoReply(const ResultCallback &callback, |
| 197 | const ModemHardwareInfo &info, |
| 198 | const Error &error); |
| 199 | |
| 200 | // Method reply callbacks from Modem.Simple interface |
| 201 | virtual void OnGetModemStatusReply(const ResultCallback &callback, |
| 202 | const DBusPropertiesMap &props, |
| 203 | const Error &error); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 204 | virtual void OnDisconnectReply(const ResultCallback &callback, |
| 205 | const Error &error); |
| 206 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 207 | Cellular *cellular_; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 208 | |
| 209 | // Store cached copies of singletons for speed/ease of testing. |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 210 | ProxyFactory *proxy_factory_; |
| 211 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 212 | scoped_ptr<ModemProxyInterface> proxy_; |
| 213 | scoped_ptr<ModemSimpleProxyInterface> simple_proxy_; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 214 | base::WeakPtrFactory<CellularCapability> weak_ptr_factory_; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 215 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 216 | DISALLOW_COPY_AND_ASSIGN(CellularCapability); |
| 217 | }; |
| 218 | |
| 219 | } // namespace shill |
| 220 | |
| 221 | #endif // SHILL_CELLULAR_CAPABILITY_ |