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 | |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 5 | #ifndef SHILL_CELLULAR_CAPABILITY_H_ |
| 6 | #define SHILL_CELLULAR_CAPABILITY_H_ |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 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 | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 14 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 15 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 16 | #include "shill/callbacks.h" |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 17 | #include "shill/cellular.h" |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 18 | #include "shill/dbus_properties.h" |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 19 | #include "shill/metrics.h" |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 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; |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 25 | class ProxyFactory; |
| 26 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 27 | // Cellular devices instantiate subclasses of CellularCapability that |
| 28 | // handle the specific modem technologies and capabilities. |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 29 | // |
| 30 | // The CellularCapability is directly subclassed by: |
| 31 | // * CelllularCapabilityUniversal which handles all modems managed by |
| 32 | // a modem manager using the the org.chromium.ModemManager1 DBUS |
| 33 | // interface |
| 34 | // * CellularCapabilityClassic which handles all modems managed by a |
| 35 | // modem manager using the older org.chromium.ModemManager DBUS |
| 36 | // interface. This class is further subclassed to represent CDMA |
| 37 | // and GSM modems |
| 38 | // |
| 39 | // Pictorially: |
| 40 | // |
| 41 | // CellularCapability |
| 42 | // | |
| 43 | // |-- CellularCapabilityUniversal |
| 44 | // | |
| 45 | // |-- CellularCapabilityClassic |
| 46 | // | |
| 47 | // |-- CellularCapabilityGSM |
| 48 | // | |
| 49 | // |-- CellularCapabilityCDMA |
| 50 | // |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 51 | class CellularCapability { |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 52 | public: |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 53 | // SimLockStatus represents the fields in the Cellular.SIMLockStatus |
| 54 | // DBUS property of the shill device. |
| 55 | struct SimLockStatus { |
| 56 | SimLockStatus() : enabled(false), retries_left(0) {} |
| 57 | |
| 58 | bool enabled; |
| 59 | std::string lock_type; |
| 60 | uint32 retries_left; |
| 61 | }; |
| 62 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 63 | static const int kTimeoutActivate; |
| 64 | static const int kTimeoutConnect; |
| 65 | static const int kTimeoutDefault; |
Thieu Le | 049adb5 | 2012-11-12 17:14:51 -0800 | [diff] [blame] | 66 | static const int kTimeoutDisconnect; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 67 | static const int kTimeoutEnable; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 68 | static const int kTimeoutRegister; |
Ben Chan | 5d0d32c | 2013-01-08 02:05:29 -0800 | [diff] [blame] | 69 | static const int kTimeoutReset; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 70 | static const int kTimeoutScan; |
| 71 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 72 | static const char kModemPropertyIMSI[]; |
| 73 | static const char kModemPropertyState[]; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 74 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 75 | // |cellular| is the parent Cellular device. |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 76 | CellularCapability(Cellular *cellular, |
| 77 | ProxyFactory *proxy_factory, |
| 78 | Metrics *metrics); |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 79 | virtual ~CellularCapability(); |
| 80 | |
| 81 | Cellular *cellular() const { return cellular_; } |
| 82 | ProxyFactory *proxy_factory() const { return proxy_factory_; } |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 83 | Metrics *metrics() const { return metrics_; } |
Darin Petkov | 5f316f6 | 2011-11-18 12:10:26 +0100 | [diff] [blame] | 84 | |
| 85 | // Invoked by the parent Cellular device when a new service is created. |
| 86 | virtual void OnServiceCreated() = 0; |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 87 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 88 | virtual void SetupConnectProperties(DBusPropertiesMap *properties) = 0; |
| 89 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 90 | // StartModem attempts to put the modem in a state in which it is |
| 91 | // usable for creating services and establishing connections (if |
| 92 | // network conditions permit). It potentially consists of multiple |
| 93 | // non-blocking calls to the modem-manager server. After each call, |
| 94 | // control is passed back up to the main loop. Each time a reply to |
| 95 | // a non-blocking call is received, the operation advances to the next |
| 96 | // step, until either an error occurs in one of them, or all the steps |
| 97 | // have been completed, at which point StartModem() is finished. |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 98 | virtual void StartModem(Error *error, |
| 99 | const ResultCallback &callback) = 0; |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 100 | // StopModem disconnects and disables a modem asynchronously. |
| 101 | // |callback| is invoked when this completes and the result is passed |
| 102 | // to the callback. |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 103 | virtual void StopModem(Error *error, const ResultCallback &callback) = 0; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 104 | virtual void Connect(const DBusPropertiesMap &properties, Error *error, |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 105 | const ResultCallback &callback) = 0; |
| 106 | virtual void Disconnect(Error *error, const ResultCallback &callback) = 0; |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 107 | // Called when a disconnect completes, successful or not. |
| 108 | virtual void DisconnectCleanup() = 0; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 109 | |
| 110 | // Activates the modem. Returns an Error on failure. |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 111 | virtual void Activate(const std::string &carrier, |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 112 | Error *error, const ResultCallback &callback) = 0; |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 113 | |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 114 | // Initiates the necessary to steps to verify that the cellular service has |
| 115 | // been activated. Once these steps have been completed, the service should |
| 116 | // be marked as activated. |
| 117 | // |
| 118 | // The default implementation fails by returning a kNotSupported error |
| 119 | // to the caller. |
| 120 | virtual void CompleteActivation(Error *error); |
| 121 | |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 122 | // Returns true if service activation is required. Returns false by default |
| 123 | // in this base class. |
| 124 | virtual bool IsServiceActivationRequired() const; |
| 125 | |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 126 | // Network registration. |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 127 | virtual void RegisterOnNetwork(const std::string &network_id, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 128 | Error *error, |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 129 | const ResultCallback &callback) = 0; |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 130 | virtual bool IsRegistered() = 0; |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 131 | // If we are informed by means of something other than a signal indicating |
| 132 | // a registration state change that the modem has unregistered from the |
| 133 | // network, we need to update the network-type-specific capability object. |
| 134 | virtual void SetUnregistered(bool searching) = 0; |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 135 | |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 136 | virtual std::string CreateFriendlyServiceName() = 0; |
| 137 | |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 138 | // PIN management. The default implementation fails by returning an error. |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 139 | virtual void RequirePIN(const std::string &pin, bool require, |
| 140 | Error *error, const ResultCallback &callback); |
| 141 | virtual void EnterPIN(const std::string &pin, |
| 142 | Error *error, const ResultCallback &callback); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 143 | virtual void UnblockPIN(const std::string &unblock_code, |
| 144 | const std::string &pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 145 | Error *error, const ResultCallback &callback); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 146 | virtual void ChangePIN(const std::string &old_pin, |
| 147 | const std::string &new_pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 148 | Error *error, const ResultCallback &callback); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 149 | |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 150 | // The default implementation fails by returning an error. |
Ben Chan | 5d0d32c | 2013-01-08 02:05:29 -0800 | [diff] [blame] | 151 | virtual void Reset(Error *error, const ResultCallback &callback); |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 152 | virtual void SetCarrier(const std::string &carrier, |
| 153 | Error *error, const ResultCallback &callback); |
| 154 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 155 | // Asks the modem to scan for networks. |
| 156 | // |
| 157 | // The default implementation fails by filling error with |
| 158 | // kNotSupported. |
| 159 | // |
| 160 | // Subclasses should implement this by fetching scan results |
| 161 | // asynchronously. When the results are ready, update the |
| 162 | // flimflam::kFoundNetworksProperty and send a property change |
| 163 | // notification. Finally, callback must be invoked to inform the |
| 164 | // caller that the scan has completed. |
| 165 | // |
| 166 | // Errors are not generally reported, but on error the |
| 167 | // kFoundNetworksProperty should be cleared and a property change |
| 168 | // notification sent out. |
| 169 | // |
| 170 | // TODO(jglasgow): Refactor to reuse code by putting notification |
| 171 | // logic into Cellular or CellularCapability. |
| 172 | // |
| 173 | // TODO(jglasgow): Implement real error handling. |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 174 | virtual void Scan(Error *error, const ResultCallback &callback); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 175 | |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 176 | // Returns an empty string if the network technology is unknown. |
| 177 | virtual std::string GetNetworkTechnologyString() const = 0; |
| 178 | |
| 179 | virtual std::string GetRoamingStateString() const = 0; |
| 180 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 181 | virtual void GetSignalQuality() = 0; |
| 182 | |
Eric Shienbrood | 0db6a9b | 2012-03-30 16:11:39 -0400 | [diff] [blame] | 183 | virtual std::string GetTypeString() const = 0; |
| 184 | |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 185 | // Called when ModemManager has sent a property change notification |
| 186 | // signal over DBUS. |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 187 | virtual void OnDBusPropertiesChanged( |
| 188 | const std::string &interface, |
| 189 | const DBusPropertiesMap &changed_properties, |
| 190 | const std::vector<std::string> &invalidated_properties) = 0; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 191 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 192 | // Should this device allow roaming? |
| 193 | // The decision to allow roaming or not is based on the home |
| 194 | // provider as well as on the user modifiable "allow_roaming" |
| 195 | // property. |
| 196 | virtual bool AllowRoaming() = 0; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 197 | |
Christopher Wiley | 1582bdd | 2012-11-15 11:31:14 -0800 | [diff] [blame] | 198 | virtual bool IsActivating() const; |
| 199 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 200 | protected: |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 201 | // Releases all proxies held by the object. This is most useful |
| 202 | // during unit tests. |
| 203 | virtual void ReleaseProxies() = 0; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 204 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 205 | static void OnUnsupportedOperation(const char *operation, Error *error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 206 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 207 | // accessor for subclasses to read the allow roaming property |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 208 | bool allow_roaming_property() const { |
| 209 | return cellular_->allow_roaming_property(); |
| 210 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 211 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 212 | private: |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 213 | friend class CellularCapabilityGSMTest; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 214 | friend class CellularCapabilityTest; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 215 | friend class CellularCapabilityUniversalTest; |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 216 | friend class CellularTest; |
Darin Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 217 | FRIEND_TEST(CellularCapabilityTest, AllowRoaming); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 218 | FRIEND_TEST(CellularTest, Connect); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 219 | FRIEND_TEST(CellularTest, TearDown); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 220 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 221 | Cellular *cellular_; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 222 | |
| 223 | // Store cached copies of singletons for speed/ease of testing. |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 224 | ProxyFactory *proxy_factory_; |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 225 | Metrics *metrics_; |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 226 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 227 | DISALLOW_COPY_AND_ASSIGN(CellularCapability); |
| 228 | }; |
| 229 | |
| 230 | } // namespace shill |
| 231 | |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 232 | #endif // SHILL_CELLULAR_CAPABILITY_H_ |