Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [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_ |
| 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" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 16 | #include "shill/event_dispatcher.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 | |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 20 | struct mobile_provider_db; |
| 21 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 22 | namespace shill { |
| 23 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 24 | class CellularCapability; |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 25 | class Error; |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 26 | class ModemSimpleProxyInterface; |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 27 | class ProxyFactory; |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 28 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 29 | class Cellular : public Device, |
Darin Petkov | 580c7af | 2011-10-24 12:32:50 +0200 | [diff] [blame] | 30 | public ModemProxyDelegate { |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 31 | public: |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 32 | enum Type { |
| 33 | kTypeGSM, |
| 34 | kTypeCDMA |
| 35 | }; |
| 36 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 37 | // The device states progress linearly from Disabled to Linked. |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 38 | enum State { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 39 | // This is the initial state of the modem and indicates that the modem radio |
| 40 | // is not turned on. |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 41 | kStateDisabled, |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 42 | // This state indicates that the modem radio is turned on, and it should be |
| 43 | // possible to measure signal strength. |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 44 | kStateEnabled, |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 45 | // The modem has registered with a network and has signal quality |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 46 | // measurements. A cellular service object is created. |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 47 | kStateRegistered, |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 48 | // The modem has connected to a network. |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 49 | kStateConnected, |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 50 | // The network interface is UP. |
| 51 | kStateLinked, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 54 | // These should be kept in sync with ModemManager's mm-modem.h:MMModemState. |
| 55 | enum ModemState { |
| 56 | kModemStateUnknown = 0, |
| 57 | kModemStateDisabled = 10, |
| 58 | kModemStateDisabling = 20, |
| 59 | kModemStateEnabling = 30, |
| 60 | kModemStateEnabled = 40, |
| 61 | kModemStateSearching = 50, |
| 62 | kModemStateRegistered = 60, |
| 63 | kModemStateDisconnecting = 70, |
| 64 | kModemStateConnecting = 80, |
| 65 | kModemStateConnected = 90, |
| 66 | }; |
| 67 | |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 68 | class Operator { |
| 69 | public: |
| 70 | Operator(); |
| 71 | ~Operator(); |
| 72 | |
| 73 | void CopyFrom(const Operator &oper); |
| 74 | |
| 75 | const std::string &GetName() const; |
| 76 | void SetName(const std::string &name); |
| 77 | |
| 78 | const std::string &GetCode() const; |
| 79 | void SetCode(const std::string &code); |
| 80 | |
| 81 | const std::string &GetCountry() const; |
| 82 | void SetCountry(const std::string &country); |
| 83 | |
| 84 | const Stringmap &ToDict() const; |
| 85 | |
| 86 | private: |
| 87 | Stringmap dict_; |
| 88 | |
| 89 | DISALLOW_COPY_AND_ASSIGN(Operator); |
| 90 | }; |
| 91 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 92 | static const char kConnectPropertyPhoneNumber[]; |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 93 | static const char kPropertyIMSI[]; |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 94 | |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 95 | // |owner| is the ModemManager DBus service owner (e.g., ":1.17"). |path| is |
| 96 | // the ModemManager.Modem DBus object path (e.g., |
| 97 | // "/org/chromium/ModemManager/Gobi/0"). |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 98 | Cellular(ControlInterface *control_interface, |
| 99 | EventDispatcher *dispatcher, |
| 100 | Manager *manager, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 101 | const std::string &link_name, |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 102 | const std::string &address, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 103 | int interface_index, |
| 104 | Type type, |
| 105 | const std::string &owner, |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 106 | const std::string &path, |
| 107 | mobile_provider_db *provider_db); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 108 | virtual ~Cellular(); |
| 109 | |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 110 | // Asynchronously connects the modem to the network. Populates |error| on |
| 111 | // failure, leaves it unchanged otherwise. |
| 112 | void Connect(Error *error); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 113 | |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 114 | // Asynchronously activates the modem. Populates |error| on failure, leaves it |
| 115 | // unchanged otherwise. |
| 116 | void Activate(const std::string &carrier, Error *error); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 117 | |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 118 | const CellularServiceRefPtr &service() const { return service_; } |
| 119 | |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 120 | static std::string GetStateString(State state); |
| 121 | |
| 122 | State state() const { return state_; } |
| 123 | |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 124 | void set_modem_state(ModemState state) { modem_state_ = state; } |
| 125 | ModemState modem_state() const { return modem_state_; } |
| 126 | |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 127 | mobile_provider_db *provider_db() const { return provider_db_; } |
| 128 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 129 | const std::string &dbus_owner() const { return dbus_owner_; } |
| 130 | const std::string &dbus_path() const { return dbus_path_; } |
| 131 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 132 | const Operator &home_provider() const { return home_provider_; } |
| 133 | void set_home_provider(const Operator &oper); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 134 | |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 135 | const std::string &meid() const { return meid_; } |
| 136 | void set_meid(const std::string &meid) { meid_ = meid; } |
| 137 | |
| 138 | const std::string &imei() const { return imei_; } |
| 139 | void set_imei(const std::string &imei) { imei_ = imei; } |
| 140 | |
| 141 | const std::string &imsi() const { return imsi_; } |
| 142 | void set_imsi(const std::string &imsi) { imsi_ = imsi; } |
| 143 | |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 144 | const std::string &mdn() const { return mdn_; } |
| 145 | void set_mdn(const std::string &mdn) { mdn_ = mdn; } |
| 146 | |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 147 | const std::string &min() const { return min_; } |
| 148 | void set_min(const std::string &min) { min_ = min; } |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 149 | |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 150 | ProxyFactory *proxy_factory() const { return proxy_factory_; } |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 151 | |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 152 | void HandleNewSignalQuality(uint32 strength); |
| 153 | |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 154 | // Processes a change in the modem registration state, possibly creating, |
| 155 | // destroying or updating the CellularService. |
| 156 | void HandleNewRegistrationState(); |
| 157 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 158 | void OnModemManagerPropertiesChanged(const DBusPropertiesMap &properties); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 159 | |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 160 | // Inherited from Device. |
| 161 | virtual void Start(); |
| 162 | virtual void Stop(); |
Paul Stewart | fdd1607 | 2011-09-16 12:41:35 -0700 | [diff] [blame] | 163 | virtual bool TechnologyIs(Technology::Identifier type) const; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 164 | virtual void LinkEvent(unsigned int flags, unsigned int change); |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 165 | virtual void Scan(Error *error); |
Darin Petkov | 9ae310f | 2011-08-30 15:41:13 -0700 | [diff] [blame] | 166 | virtual void RegisterOnNetwork(const std::string &network_id, Error *error); |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 167 | virtual void RequirePIN( |
| 168 | const std::string &pin, bool require, ReturnerInterface *returner); |
Darin Petkov | e5bc2cb | 2011-12-07 14:47:32 +0100 | [diff] [blame] | 169 | virtual void EnterPIN(const std::string &pin, ReturnerInterface *returner); |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 170 | virtual void UnblockPIN(const std::string &unblock_code, |
| 171 | const std::string &pin, |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 172 | ReturnerInterface *returner); |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 173 | virtual void ChangePIN(const std::string &old_pin, |
| 174 | const std::string &new_pin, |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 175 | ReturnerInterface *returner); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 176 | |
| 177 | private: |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 178 | friend class CellularTest; |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 179 | friend class CellularCapabilityCDMATest; |
| 180 | friend class CellularCapabilityGSMTest; |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 181 | friend class ModemTest; |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 182 | FRIEND_TEST(CellularTest, CreateService); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 183 | FRIEND_TEST(CellularTest, Connect); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 184 | FRIEND_TEST(CellularTest, GetModemInfo); |
| 185 | FRIEND_TEST(CellularTest, GetModemStatus); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 186 | FRIEND_TEST(CellularTest, InitProxies); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 187 | FRIEND_TEST(CellularTest, StartConnected); |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 188 | FRIEND_TEST(CellularTest, StartCDMARegister); |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 189 | FRIEND_TEST(CellularTest, StartGSMRegister); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 190 | FRIEND_TEST(CellularTest, StartLinked); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 191 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 192 | void SetState(State state); |
| 193 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 194 | void ConnectTask(const DBusPropertiesMap &properties); |
| 195 | |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 196 | // Invoked when the modem is connected to the cellular network to transition |
| 197 | // to the network-connected state and bring the network interface up. |
| 198 | void EstablishLink(); |
| 199 | |
Darin Petkov | 5f316f6 | 2011-11-18 12:10:26 +0100 | [diff] [blame] | 200 | void InitCapability(Type type); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 201 | void InitProxies(); |
| 202 | |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 203 | void EnableModem(); |
| 204 | void GetModemStatus(); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 205 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 206 | // Obtains modem's manufacturer, model ID, and hardware revision. |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 207 | void GetModemInfo(); |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 208 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 209 | void HandleNewRegistrationStateTask(); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 210 | |
| 211 | void CreateService(); |
Darin Petkov | 2c37738 | 2012-01-11 11:40:43 +0100 | [diff] [blame^] | 212 | void DestroyService(); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 213 | |
Darin Petkov | 580c7af | 2011-10-24 12:32:50 +0200 | [diff] [blame] | 214 | // Signal callbacks inherited from ModemProxyDelegate. |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 215 | virtual void OnModemStateChanged(uint32 old_state, |
| 216 | uint32 new_state, |
| 217 | uint32 reason); |
| 218 | |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 219 | // Store cached copies of singletons for speed/ease of testing. |
| 220 | ProxyFactory *proxy_factory_; |
| 221 | |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 222 | State state_; |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 223 | ModemState modem_state_; |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 224 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 225 | scoped_ptr<CellularCapability> capability_; |
| 226 | |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 227 | const std::string dbus_owner_; // ModemManager.Modem |
| 228 | const std::string dbus_path_; // ModemManager.Modem |
| 229 | scoped_ptr<ModemProxyInterface> proxy_; |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 230 | scoped_ptr<ModemSimpleProxyInterface> simple_proxy_; |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 231 | |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 232 | mobile_provider_db *provider_db_; |
| 233 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 234 | CellularServiceRefPtr service_; |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 235 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 236 | ScopedRunnableMethodFactory<Cellular> task_factory_; |
| 237 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 238 | // Properties |
| 239 | bool allow_roaming_; |
| 240 | std::string carrier_; |
| 241 | std::string meid_; |
| 242 | std::string imei_; |
| 243 | std::string imsi_; |
| 244 | std::string esn_; |
| 245 | std::string mdn_; |
| 246 | std::string min_; |
| 247 | std::string model_id_; |
| 248 | std::string manufacturer_; |
| 249 | std::string firmware_revision_; |
| 250 | std::string hardware_revision_; |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 251 | Operator home_provider_; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 252 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 253 | DISALLOW_COPY_AND_ASSIGN(Cellular); |
| 254 | }; |
| 255 | |
| 256 | } // namespace shill |
| 257 | |
| 258 | #endif // SHILL_CELLULAR_ |