Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 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_ |
| 6 | #define SHILL_CELLULAR_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include <base/basictypes.h> |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 11 | #include <base/task.h> |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 12 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 13 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 14 | #include "shill/dbus_properties.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 15 | #include "shill/device.h" |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 16 | #include "shill/modem_cdma_proxy_interface.h" |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 17 | #include "shill/modem_proxy_interface.h" |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 18 | #include "shill/refptr_types.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 19 | #include "shill/shill_event.h" |
| 20 | |
| 21 | namespace shill { |
| 22 | |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 23 | class ModemSimpleProxyInterface; |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 24 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 25 | class Cellular : public Device, |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 26 | public ModemCDMAProxyListener, |
| 27 | public ModemProxyListener { |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 28 | public: |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 29 | enum Type { |
| 30 | kTypeGSM, |
| 31 | kTypeCDMA |
| 32 | }; |
| 33 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 34 | // The device states progress linearly from Disabled to Linked. |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 35 | enum State { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 36 | // This is the initial state of the modem and indicates that the modem radio |
| 37 | // is not turned on. |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 38 | kStateDisabled, |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 39 | // This state indicates that the modem radio is turned on, and it should be |
| 40 | // possible to measure signal strength. |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 41 | kStateEnabled, |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 42 | // The modem has registered with a network and has signal quality |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 43 | // measurements. A cellular service object is created. |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 44 | kStateRegistered, |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 45 | // The modem has connected to a network. |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 46 | kStateConnected, |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 47 | // The network interface is UP. |
| 48 | kStateLinked, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 49 | }; |
| 50 | |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 51 | // These should be kept in sync with ModemManager's mm-modem.h:MMModemState. |
| 52 | enum ModemState { |
| 53 | kModemStateUnknown = 0, |
| 54 | kModemStateDisabled = 10, |
| 55 | kModemStateDisabling = 20, |
| 56 | kModemStateEnabling = 30, |
| 57 | kModemStateEnabled = 40, |
| 58 | kModemStateSearching = 50, |
| 59 | kModemStateRegistered = 60, |
| 60 | kModemStateDisconnecting = 70, |
| 61 | kModemStateConnecting = 80, |
| 62 | kModemStateConnected = 90, |
| 63 | }; |
| 64 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 65 | class Network { |
| 66 | public: |
| 67 | Network(); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 68 | ~Network(); |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 69 | |
| 70 | const std::string &GetStatus() const; |
| 71 | void SetStatus(const std::string &status); |
| 72 | |
| 73 | const std::string &GetId() const; |
| 74 | void SetId(const std::string &id); |
| 75 | |
| 76 | const std::string &GetShortName() const; |
| 77 | void SetShortName(const std::string &name); |
| 78 | |
| 79 | const std::string &GetLongName() const; |
| 80 | void SetLongName(const std::string &name); |
| 81 | |
| 82 | const std::string &GetTechnology() const; |
| 83 | void SetTechnology(const std::string &technology); |
| 84 | |
| 85 | const Stringmap &ToDict() const; |
| 86 | |
| 87 | private: |
| 88 | Stringmap dict_; |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 89 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 90 | DISALLOW_COPY_AND_ASSIGN(Network); |
| 91 | }; |
| 92 | |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 93 | struct CDMA { |
| 94 | CDMA(); |
| 95 | |
| 96 | uint32 registration_state_evdo; |
| 97 | uint32 registration_state_1x; |
| 98 | uint32 activation_state; |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 99 | |
| 100 | uint16 prl_version; |
| 101 | std::string payment_url; |
| 102 | std::string usage_url; |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 105 | struct SimLockStatus { |
| 106 | public: |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 107 | SimLockStatus() : retries_left(0) {} |
| 108 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 109 | std::string lock_type; |
| 110 | uint32 retries_left; |
| 111 | }; |
| 112 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 113 | static const char kConnectPropertyPhoneNumber[]; |
| 114 | |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 115 | // |owner| is the ModemManager DBus service owner (e.g., ":1.17"). |path| is |
| 116 | // the ModemManager.Modem DBus object path (e.g., |
| 117 | // "/org/chromium/ModemManager/Gobi/0"). |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 118 | Cellular(ControlInterface *control_interface, |
| 119 | EventDispatcher *dispatcher, |
| 120 | Manager *manager, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 121 | const std::string &link_name, |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 122 | const std::string &address, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 123 | int interface_index, |
| 124 | Type type, |
| 125 | const std::string &owner, |
| 126 | const std::string &path); |
| 127 | virtual ~Cellular(); |
| 128 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 129 | // Asynchronously connects the modem to the network. |
| 130 | void Connect(); |
| 131 | |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 132 | // Asynchronously activates the modem. |
| 133 | void Activate(const std::string &carrier); |
| 134 | |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 135 | void set_modem_state(ModemState state) { modem_state_ = state; } |
| 136 | ModemState modem_state() const { return modem_state_; } |
| 137 | |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 138 | // Inherited from Device. |
| 139 | virtual void Start(); |
| 140 | virtual void Stop(); |
Darin Petkov | 6f9eaa3 | 2011-08-09 15:26:44 -0700 | [diff] [blame] | 141 | virtual bool TechnologyIs(Technology type) const; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 142 | virtual void LinkEvent(unsigned int flags, unsigned int change); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 143 | |
| 144 | private: |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 145 | FRIEND_TEST(CellularTest, Activate); |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 146 | FRIEND_TEST(CellularTest, ActivateError); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 147 | FRIEND_TEST(CellularTest, Connect); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 148 | FRIEND_TEST(CellularTest, GetCDMAActivationStateString); |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 149 | FRIEND_TEST(CellularTest, GetCDMAActivationErrorString); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 150 | FRIEND_TEST(CellularTest, GetCDMARegistrationState); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 151 | FRIEND_TEST(CellularTest, GetCDMASignalQuality); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 152 | FRIEND_TEST(CellularTest, GetModemInfo); |
| 153 | FRIEND_TEST(CellularTest, GetModemStatus); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 154 | FRIEND_TEST(CellularTest, GetStateString); |
| 155 | FRIEND_TEST(CellularTest, GetTypeString); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 156 | FRIEND_TEST(CellularTest, InitProxiesCDMA); |
| 157 | FRIEND_TEST(CellularTest, InitProxiesGSM); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 158 | FRIEND_TEST(CellularTest, Start); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 159 | FRIEND_TEST(CellularTest, StartConnected); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 160 | FRIEND_TEST(CellularTest, StartLinked); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 161 | FRIEND_TEST(CellularTest, StartRegister); |
| 162 | |
| 163 | static const char kPhoneNumberCDMA[]; |
| 164 | static const char kPhoneNumberGSM[]; |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 165 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 166 | void SetState(State state); |
| 167 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 168 | void ConnectTask(const DBusPropertiesMap &properties); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 169 | void ActivateTask(const std::string &carrier); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 170 | |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 171 | // Invoked when the modem is connected to the cellular network to transition |
| 172 | // to the network-connected state and bring the network interface up. |
| 173 | void EstablishLink(); |
| 174 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 175 | Stringmaps EnumerateNetworks(); |
| 176 | StrIntPair SimLockStatusToProperty(); |
| 177 | void HelpRegisterDerivedStringmaps(const std::string &name, |
| 178 | Stringmaps(Cellular::*get)(void), |
| 179 | bool(Cellular::*set)(const Stringmaps&)); |
| 180 | void HelpRegisterDerivedStrIntPair(const std::string &name, |
| 181 | StrIntPair(Cellular::*get)(void), |
| 182 | bool(Cellular::*set)(const StrIntPair&)); |
| 183 | |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 184 | void InitProxies(); |
| 185 | |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 186 | std::string GetTypeString() const; |
| 187 | static std::string GetStateString(State state); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 188 | |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 189 | static std::string GetCDMAActivationStateString(uint32 state); |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 190 | static std::string GetCDMAActivationErrorString(uint32 error); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 191 | |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 192 | void EnableModem(); |
| 193 | void GetModemStatus(); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 194 | void GetGSMProperties(); |
| 195 | void RegisterGSMModem(); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 196 | |
| 197 | // Obtains the modem identifiers: MEID for CDMA; IMEI, IMSI, SPN and MSISDN |
| 198 | // for GSM. |
| 199 | void GetModemIdentifiers(); |
| 200 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 201 | // Obtains modem's manufacturer, model ID, and hardware revision. |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 202 | void GetModemInfo(); |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 203 | |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 204 | void GetModemRegistrationState(); |
| 205 | void GetCDMARegistrationState(); |
| 206 | void GetGSMRegistrationState(); |
| 207 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 208 | // Processes a change in the modem registration state, possibly creating, |
| 209 | // destroying or updating the CellularService. |
| 210 | void HandleNewRegistrationState(); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 211 | void HandleNewRegistrationStateTask(); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 212 | |
| 213 | void CreateService(); |
| 214 | |
| 215 | void GetModemSignalQuality(); |
| 216 | uint32 GetCDMASignalQuality(); |
| 217 | uint32 GetGSMSignalQuality(); |
| 218 | |
| 219 | void HandleNewSignalQuality(uint32 strength); |
| 220 | |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 221 | void HandleNewCDMAActivationState(uint32 error); |
| 222 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 223 | // Returns true if the modem is registered. Note that this method looks at the |
| 224 | // latest CDMA/GSM registration info obtained from the modem rather than the |
| 225 | // device |state_|. |
| 226 | bool IsModemRegistered(); |
| 227 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 228 | // Signal callbacks inherited from ModemCDMAProxyListener. |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 229 | virtual void OnCDMAActivationStateChanged( |
| 230 | uint32 activation_state, |
| 231 | uint32 activation_error, |
| 232 | const DBusPropertiesMap &status_changes); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 233 | virtual void OnCDMARegistrationStateChanged(uint32 state_1x, |
| 234 | uint32 state_evdo); |
| 235 | virtual void OnCDMASignalQualityChanged(uint32 strength); |
| 236 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 237 | // Signal callbacks inherited from ModemProxyListener. |
| 238 | virtual void OnModemStateChanged(uint32 old_state, |
| 239 | uint32 new_state, |
| 240 | uint32 reason); |
| 241 | |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 242 | Type type_; |
| 243 | State state_; |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 244 | ModemState modem_state_; |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 245 | |
| 246 | const std::string dbus_owner_; // ModemManager.Modem |
| 247 | const std::string dbus_path_; // ModemManager.Modem |
| 248 | scoped_ptr<ModemProxyInterface> proxy_; |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 249 | scoped_ptr<ModemSimpleProxyInterface> simple_proxy_; |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 250 | scoped_ptr<ModemCDMAProxyInterface> cdma_proxy_; |
| 251 | |
| 252 | CDMA cdma_; |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 253 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 254 | CellularServiceRefPtr service_; |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 255 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 256 | ScopedRunnableMethodFactory<Cellular> task_factory_; |
| 257 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 258 | // Properties |
| 259 | bool allow_roaming_; |
| 260 | std::string carrier_; |
| 261 | std::string meid_; |
| 262 | std::string imei_; |
| 263 | std::string imsi_; |
| 264 | std::string esn_; |
| 265 | std::string mdn_; |
| 266 | std::string min_; |
| 267 | std::string model_id_; |
| 268 | std::string manufacturer_; |
| 269 | std::string firmware_revision_; |
| 270 | std::string hardware_revision_; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 271 | bool scanning_; |
| 272 | uint16 scan_interval_; |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 273 | std::vector<Network> found_networks_; |
| 274 | SimLockStatus sim_lock_status_; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 275 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 276 | DISALLOW_COPY_AND_ASSIGN(Cellular); |
| 277 | }; |
| 278 | |
| 279 | } // namespace shill |
| 280 | |
| 281 | #endif // SHILL_CELLULAR_ |