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