Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 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_CLASSIC_H_ |
| 6 | #define SHILL_CELLULAR_CAPABILITY_CLASSIC_H_ |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include <base/basictypes.h> |
| 12 | #include <base/callback.h> |
| 13 | #include <base/memory/scoped_ptr.h> |
| 14 | #include <base/memory/weak_ptr.h> |
Liam McLoughlin | 0fec81c | 2013-02-28 10:31:47 -0500 | [diff] [blame] | 15 | #include <base/gtest_prod_util.h> // for FRIEND_TEST_ALL_PREFIXES |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 16 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 17 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 18 | #include "shill/cellular.h" |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 19 | #include "shill/cellular_capability.h" |
| 20 | #include "shill/dbus_properties.h" |
| 21 | #include "shill/modem_proxy_interface.h" |
| 22 | #include "shill/modem_simple_proxy_interface.h" |
| 23 | |
| 24 | namespace shill { |
| 25 | |
| 26 | class Cellular; |
| 27 | class Error; |
| 28 | class EventDispatcher; |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 29 | class ModemGobiProxyInterface; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 30 | class ModemInfo; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 31 | class ProxyFactory; |
| 32 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 33 | enum ModemClassicState { |
| 34 | kModemClassicStateUnknown = 0, |
| 35 | kModemClassicStateDisabled = 10, |
| 36 | kModemClassicStateDisabling = 20, |
| 37 | kModemClassicStateEnabling = 30, |
| 38 | kModemClassicStateEnabled = 40, |
| 39 | kModemClassicStateSearching = 50, |
| 40 | kModemClassicStateRegistered = 60, |
| 41 | kModemClassicStateDisconnecting = 70, |
| 42 | kModemClassicStateConnecting = 80, |
| 43 | kModemClassicStateConnected = 90, |
| 44 | }; |
| 45 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 46 | // CellularCapabilityClassic handles modems using the |
| 47 | // org.chromium.ModemManager DBUS interface. |
| 48 | class CellularCapabilityClassic : public CellularCapability { |
| 49 | public: |
| 50 | static const char kConnectPropertyApn[]; |
| 51 | static const char kConnectPropertyApnUsername[]; |
| 52 | static const char kConnectPropertyApnPassword[]; |
| 53 | static const char kConnectPropertyHomeOnly[]; |
| 54 | static const char kConnectPropertyPhoneNumber[]; |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 55 | static const char kModemPropertyEnabled[]; |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 56 | static const int kTimeoutSetCarrierMilliseconds; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 57 | |
| 58 | // |cellular| is the parent Cellular device. |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 59 | CellularCapabilityClassic(Cellular *cellular, |
| 60 | ProxyFactory *proxy_factory, |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 61 | ModemInfo *modem_info); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 62 | virtual ~CellularCapabilityClassic(); |
| 63 | |
| 64 | virtual void StopModem(Error *error, const ResultCallback &callback); |
| 65 | virtual void Connect(const DBusPropertiesMap &properties, Error *error, |
| 66 | const ResultCallback &callback); |
| 67 | virtual void Disconnect(Error *error, const ResultCallback &callback); |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 68 | virtual void DisconnectCleanup(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 69 | |
| 70 | virtual void Activate(const std::string &carrier, |
| 71 | Error *error, const ResultCallback &callback); |
| 72 | |
| 73 | // Network registration. |
| 74 | virtual void RegisterOnNetwork(const std::string &network_id, |
| 75 | Error *error, |
| 76 | const ResultCallback &callback); |
| 77 | |
| 78 | // PIN management. The default implementation fails by returning an error. |
| 79 | virtual void RequirePIN(const std::string &pin, bool require, |
| 80 | Error *error, const ResultCallback &callback); |
| 81 | virtual void EnterPIN(const std::string &pin, |
| 82 | Error *error, const ResultCallback &callback); |
| 83 | virtual void UnblockPIN(const std::string &unblock_code, |
| 84 | const std::string &pin, |
| 85 | Error *error, const ResultCallback &callback); |
| 86 | virtual void ChangePIN(const std::string &old_pin, |
| 87 | const std::string &new_pin, |
| 88 | Error *error, const ResultCallback &callback); |
| 89 | |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 90 | virtual void SetCarrier(const std::string &carrier, |
| 91 | Error *error, const ResultCallback &callback); |
| 92 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 93 | virtual void Scan(Error *error, const ResultCallback &callback); |
| 94 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 95 | virtual void OnDBusPropertiesChanged( |
| 96 | const std::string &interface, |
| 97 | const DBusPropertiesMap &properties, |
| 98 | const std::vector<std::string> &invalidated_properties); |
| 99 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 100 | protected: |
Jason Glasgow | a0caabf | 2012-05-04 11:31:41 -0400 | [diff] [blame] | 101 | typedef std::vector<base::Closure> CellularTaskList; |
| 102 | |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 103 | virtual void GetRegistrationState() = 0; |
| 104 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 105 | // The following five methods are only ever called as |
| 106 | // callbacks (from the main loop), which is why they |
| 107 | // don't take an Error * argument. |
| 108 | virtual void EnableModem(const ResultCallback &callback); |
| 109 | virtual void DisableModem(const ResultCallback &callback); |
| 110 | virtual void GetModemStatus(const ResultCallback &callback); |
| 111 | virtual void GetModemInfo(const ResultCallback &callback); |
| 112 | virtual void GetProperties(const ResultCallback &callback) = 0; |
| 113 | |
| 114 | void FinishEnable(const ResultCallback &callback); |
| 115 | void FinishDisable(const ResultCallback &callback); |
| 116 | virtual void InitProxies(); |
| 117 | virtual void ReleaseProxies(); |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 118 | virtual void UpdateStatus(const DBusPropertiesMap &properties) = 0; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 119 | |
| 120 | static void OnUnsupportedOperation(const char *operation, Error *error); |
| 121 | |
Jason Glasgow | a0caabf | 2012-05-04 11:31:41 -0400 | [diff] [blame] | 122 | // Runs the next task in a list. |
| 123 | // Precondition: |tasks| is not empty. |
| 124 | void RunNextStep(CellularTaskList *tasks); |
| 125 | // StepCompletedCallback is called after a task completes. |
| 126 | // |callback| is the original callback that needs to be invoked when all of |
| 127 | // the tasks complete or if there is a failure. |ignore_error| will be set |
| 128 | // to true if the next task should be run regardless of the result of the |
| 129 | // just-completed task. |tasks| is the list of tasks remaining. |error| is |
| 130 | // the result of the just-completed task. |
| 131 | void StepCompletedCallback(const ResultCallback &callback, bool ignore_error, |
| 132 | CellularTaskList *tasks, const Error &error); |
| 133 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 134 | // Properties |
| 135 | bool scanning_supported_; |
| 136 | std::string meid_; |
| 137 | std::string imsi_; |
| 138 | std::string imei_; |
| 139 | std::string esn_; |
| 140 | std::string mdn_; |
| 141 | std::string min_; |
| 142 | std::string model_id_; |
| 143 | std::string manufacturer_; |
| 144 | std::string firmware_revision_; |
| 145 | std::string hardware_revision_; |
| 146 | std::string carrier_; |
| 147 | |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 148 | scoped_ptr<ModemSimpleProxyInterface> simple_proxy_; |
| 149 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 150 | private: |
| 151 | friend class CellularTest; |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 152 | friend class CellularCapabilityCDMATest; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 153 | friend class CellularCapabilityTest; |
| 154 | friend class CellularCapabilityGSMTest; |
| 155 | FRIEND_TEST(CellularCapabilityGSMTest, SetProxy); |
| 156 | FRIEND_TEST(CellularCapabilityGSMTest, SetStorageIdentifier); |
| 157 | FRIEND_TEST(CellularCapabilityGSMTest, UpdateStatus); |
| 158 | FRIEND_TEST(CellularCapabilityTest, AllowRoaming); |
| 159 | FRIEND_TEST(CellularCapabilityTest, EnableModemFail); |
| 160 | FRIEND_TEST(CellularCapabilityTest, EnableModemSucceed); |
| 161 | FRIEND_TEST(CellularCapabilityTest, FinishEnable); |
| 162 | FRIEND_TEST(CellularCapabilityTest, GetModemInfo); |
| 163 | FRIEND_TEST(CellularCapabilityTest, GetModemStatus); |
| 164 | FRIEND_TEST(CellularCapabilityTest, TryApns); |
| 165 | FRIEND_TEST(CellularServiceTest, FriendlyName); |
| 166 | FRIEND_TEST(CellularTest, StartCDMARegister); |
| 167 | FRIEND_TEST(CellularTest, StartConnected); |
| 168 | FRIEND_TEST(CellularTest, StartGSMRegister); |
| 169 | FRIEND_TEST(CellularTest, StartLinked); |
| 170 | FRIEND_TEST(CellularTest, Connect); |
Liam McLoughlin | 0fec81c | 2013-02-28 10:31:47 -0500 | [diff] [blame] | 171 | FRIEND_TEST_ALL_PREFIXES(CellularTest, ConnectAddsTerminationAction); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 172 | FRIEND_TEST(CellularTest, ConnectFailure); |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 173 | FRIEND_TEST(CellularTest, ConnectFailureNoService); |
Thieu Le | d4974cd | 2013-05-23 10:39:28 -0700 | [diff] [blame] | 174 | FRIEND_TEST(CellularTest, ConnectSuccessNoService); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 175 | FRIEND_TEST(CellularTest, Disconnect); |
Arman Uguray | 539c423 | 2012-09-11 10:00:22 -0700 | [diff] [blame] | 176 | FRIEND_TEST(CellularTest, DisconnectFailure); |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 177 | FRIEND_TEST(CellularTest, DisconnectWithCallback); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 178 | FRIEND_TEST(CellularTest, ModemStateChangeEnable); |
| 179 | FRIEND_TEST(CellularTest, ModemStateChangeDisable); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 180 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 181 | // Method reply and signal callbacks from Modem interface |
Nathan Williams | 3022be5 | 2012-04-19 17:40:49 -0400 | [diff] [blame] | 182 | void OnModemStateChangedSignal( |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 183 | uint32 old_state, uint32 new_state, uint32 reason); |
Nathan Williams | 3022be5 | 2012-04-19 17:40:49 -0400 | [diff] [blame] | 184 | void OnGetModemInfoReply(const ResultCallback &callback, |
| 185 | const ModemHardwareInfo &info, |
| 186 | const Error &error); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 187 | |
| 188 | // Method reply callbacks from Modem.Simple interface |
Nathan Williams | 3022be5 | 2012-04-19 17:40:49 -0400 | [diff] [blame] | 189 | void OnGetModemStatusReply(const ResultCallback &callback, |
| 190 | const DBusPropertiesMap &props, |
| 191 | const Error &error); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 192 | |
| 193 | Cellular *cellular_; |
| 194 | base::WeakPtrFactory<CellularCapabilityClassic> weak_ptr_factory_; |
| 195 | |
| 196 | scoped_ptr<ModemProxyInterface> proxy_; |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 197 | scoped_ptr<ModemGobiProxyInterface> gobi_proxy_; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 198 | |
Darin Petkov | 1abca3e | 2012-09-12 11:44:07 +0200 | [diff] [blame] | 199 | Strings supported_carriers_; |
| 200 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 201 | DISALLOW_COPY_AND_ASSIGN(CellularCapabilityClassic); |
| 202 | }; |
| 203 | |
| 204 | } // namespace shill |
| 205 | |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 206 | #endif // SHILL_CELLULAR_CAPABILITY_CLASSIC_H_ |