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> |
| 9 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 10 | #include <base/basictypes.h> |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame^] | 11 | #include <base/memory/scoped_ptr.h> |
| 12 | #include <base/memory/scoped_vector.h> |
| 13 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 14 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame^] | 15 | #include "shill/async_call_handler.h" |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 16 | #include "shill/dbus_properties.h" |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame^] | 17 | #include "shill/modem_proxy_interface.h" |
| 18 | #include "shill/modem_simple_proxy_interface.h" |
| 19 | |
| 20 | class Task; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 21 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 22 | namespace shill { |
| 23 | |
| 24 | class Cellular; |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 25 | class Error; |
| 26 | class EventDispatcher; |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 27 | class ProxyFactory; |
| 28 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame^] | 29 | // Cellular devices instantiate subclasses of CellularCapability that |
| 30 | // handle the specific modem technologies and capabilities. |
| 31 | class CellularCapability : public ModemProxyDelegate, |
| 32 | public ModemSimpleProxyDelegate { |
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; |
| 37 | static const int kTimeoutRegister; |
| 38 | static const int kTimeoutScan; |
| 39 | |
| 40 | static const char kConnectPropertyPhoneNumber[]; |
| 41 | static const char kPropertyIMSI[]; |
| 42 | |
| 43 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 44 | // |cellular| is the parent Cellular device. |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame^] | 45 | CellularCapability(Cellular *cellular, ProxyFactory *proxy_factory); |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 46 | virtual ~CellularCapability(); |
| 47 | |
| 48 | Cellular *cellular() const { return cellular_; } |
| 49 | ProxyFactory *proxy_factory() const { return proxy_factory_; } |
Darin Petkov | 5f316f6 | 2011-11-18 12:10:26 +0100 | [diff] [blame] | 50 | |
| 51 | // Invoked by the parent Cellular device when a new service is created. |
| 52 | virtual void OnServiceCreated() = 0; |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 53 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 54 | virtual void UpdateStatus(const DBusPropertiesMap &properties) = 0; |
| 55 | |
| 56 | virtual void SetupConnectProperties(DBusPropertiesMap *properties) = 0; |
| 57 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame^] | 58 | bool allow_roaming() const { return allow_roaming_; } |
| 59 | |
| 60 | // StartModem attempts to put the modem in a state in which it is |
| 61 | // usable for creating services and establishing connections (if |
| 62 | // network conditions permit). It potentially consists of multiple |
| 63 | // non-blocking calls to the modem-manager server. After each call, |
| 64 | // control is passed back up to the main loop. Each time a reply to |
| 65 | // a non-blocking call is received, the operation advances to the next |
| 66 | // step, until either an error occurs in one of them, or all the steps |
| 67 | // have been completed, at which point StartModem() is finished. |
| 68 | virtual void StartModem(); |
| 69 | virtual void StopModem(); |
| 70 | // EnableModem ensures that the modem device is powered. |
| 71 | virtual void EnableModem(AsyncCallHandler *call_handler); |
| 72 | virtual void DisableModem(AsyncCallHandler *call_handler); |
| 73 | virtual void GetModemStatus(AsyncCallHandler *call_handler); |
| 74 | virtual void GetModemInfo(AsyncCallHandler *call_handler); |
| 75 | virtual void Connect(const DBusPropertiesMap &properties); |
| 76 | virtual void Disconnect(); |
| 77 | |
| 78 | // Activates the modem. Returns an Error on failure. |
| 79 | // The default implementation fails by returning a kNotSupported error |
| 80 | // to the caller. |
| 81 | virtual void Activate(const std::string &carrier, |
| 82 | AsyncCallHandler *call_handler); |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 83 | |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 84 | // Network registration. |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame^] | 85 | virtual void RegisterOnNetwork(const std::string &network_id, |
| 86 | AsyncCallHandler *call_handler); |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 87 | virtual bool IsRegistered() = 0; |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 88 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame^] | 89 | virtual void GetProperties(AsyncCallHandler *call_handler) = 0; |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 90 | |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 91 | // Retrieves the current cellular signal strength. |
| 92 | virtual void GetSignalQuality() = 0; |
| 93 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame^] | 94 | virtual void GetRegistrationState(AsyncCallHandler *call_handler) = 0; |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 95 | |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 96 | virtual std::string CreateFriendlyServiceName() = 0; |
| 97 | |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 98 | // PIN management. The default implementation fails by returning an error. |
| 99 | virtual void RequirePIN( |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame^] | 100 | const std::string &pin, bool require, AsyncCallHandler *call_handler); |
| 101 | virtual void EnterPIN(const std::string &pin, AsyncCallHandler *call_handler); |
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 | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame^] | 104 | AsyncCallHandler *call_handler); |
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 | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame^] | 107 | AsyncCallHandler *call_handler); |
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. |
| 111 | virtual void Scan(AsyncCallHandler *call_handler); |
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 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 118 | virtual void OnModemManagerPropertiesChanged( |
| 119 | const DBusPropertiesMap &properties) = 0; |
| 120 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame^] | 121 | // Method and signal callbacks inherited from ModemProxyDelegate. |
| 122 | virtual void OnModemStateChanged( |
| 123 | uint32 old_state, uint32 new_state, uint32 reason); |
| 124 | virtual void OnModemEnableCallback(const Error &error, |
| 125 | AsyncCallHandler *call_handler); |
| 126 | virtual void OnGetModemInfoCallback(const ModemHardwareInfo &info, |
| 127 | const Error &error, |
| 128 | AsyncCallHandler *call_handler); |
| 129 | |
| 130 | // Method and signal callbacks inherited from ModemSimpleProxyDelegate. |
| 131 | virtual void OnGetModemStatusCallback(const DBusPropertiesMap &props, |
| 132 | const Error &error, |
| 133 | AsyncCallHandler *call_handler); |
| 134 | virtual void OnConnectCallback(const Error &error, |
| 135 | AsyncCallHandler *call_handler); |
| 136 | virtual void OnDisconnectCallback(const Error &error, |
| 137 | AsyncCallHandler *call_handler); |
| 138 | |
| 139 | protected: |
| 140 | class MultiStepAsyncCallHandler : public AsyncCallHandler { |
| 141 | public: |
| 142 | explicit MultiStepAsyncCallHandler(EventDispatcher *dispatcher); |
| 143 | virtual ~MultiStepAsyncCallHandler(); |
| 144 | |
| 145 | // Override the non-error case |
| 146 | virtual bool CompleteOperation(); |
| 147 | |
| 148 | void AddTask(Task *task); |
| 149 | void PostNextTask(); |
| 150 | |
| 151 | private: |
| 152 | EventDispatcher *dispatcher_; |
| 153 | ScopedVector<Task> tasks_; |
| 154 | |
| 155 | DISALLOW_COPY_AND_ASSIGN(MultiStepAsyncCallHandler); |
| 156 | }; |
| 157 | |
| 158 | static void CompleteOperation(AsyncCallHandler *reply_handler); |
| 159 | static void CompleteOperation(AsyncCallHandler *reply_handler, |
| 160 | const Error &error); |
| 161 | // Generic synthetic callback by which a Capability class can indicate |
| 162 | // that a requested operation is not supported. |
| 163 | void static OnUnsupportedOperation(const char *operation, |
| 164 | AsyncCallHandler *call_handler); |
| 165 | |
| 166 | // Properties |
| 167 | bool allow_roaming_; |
| 168 | std::string carrier_; |
| 169 | std::string meid_; |
| 170 | std::string imei_; |
| 171 | std::string imsi_; |
| 172 | std::string esn_; |
| 173 | std::string mdn_; |
| 174 | std::string min_; |
| 175 | std::string model_id_; |
| 176 | std::string manufacturer_; |
| 177 | std::string firmware_revision_; |
| 178 | std::string hardware_revision_; |
| 179 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 180 | private: |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 181 | friend class CellularTest; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame^] | 182 | friend class CellularCapabilityTest; |
| 183 | FRIEND_TEST(CellularCapabilityGSMTest, UpdateStatus); |
| 184 | FRIEND_TEST(CellularCapabilityTest, GetModemInfo); |
| 185 | FRIEND_TEST(CellularCapabilityTest, GetModemStatus); |
| 186 | FRIEND_TEST(CellularServiceTest, FriendlyName); |
| 187 | FRIEND_TEST(CellularTest, StartCDMARegister); |
| 188 | FRIEND_TEST(CellularTest, StartConnected); |
| 189 | FRIEND_TEST(CellularTest, StartGSMRegister); |
| 190 | FRIEND_TEST(CellularTest, StartLinked); |
| 191 | FRIEND_TEST(CellularTest, Connect); |
| 192 | FRIEND_TEST(CellularTest, DisconnectModem); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 193 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 194 | Cellular *cellular_; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame^] | 195 | |
| 196 | // Store cached copies of singletons for speed/ease of testing. |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 197 | ProxyFactory *proxy_factory_; |
| 198 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame^] | 199 | scoped_ptr<ModemProxyInterface> proxy_; |
| 200 | scoped_ptr<ModemSimpleProxyInterface> simple_proxy_; |
| 201 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 202 | DISALLOW_COPY_AND_ASSIGN(CellularCapability); |
| 203 | }; |
| 204 | |
| 205 | } // namespace shill |
| 206 | |
| 207 | #endif // SHILL_CELLULAR_CAPABILITY_ |