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 | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 11 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 12 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 13 | #include "shill/device.h" |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame^] | 14 | #include "shill/modem_cdma_proxy_interface.h" |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 15 | #include "shill/refptr_types.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 16 | #include "shill/shill_event.h" |
| 17 | |
| 18 | namespace shill { |
| 19 | |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 20 | class ModemProxyInterface; |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 21 | class ModemSimpleProxyInterface; |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 22 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame^] | 23 | class Cellular : public Device, |
| 24 | public ModemCDMAProxyListener { |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 25 | public: |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 26 | enum Type { |
| 27 | kTypeGSM, |
| 28 | kTypeCDMA |
| 29 | }; |
| 30 | |
| 31 | enum State { |
| 32 | kStateDisabled, |
| 33 | kStateEnabled, |
| 34 | kStateRegistered, |
| 35 | kStateConnected, |
| 36 | }; |
| 37 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 38 | class Network { |
| 39 | public: |
| 40 | Network(); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 41 | ~Network(); |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 42 | |
| 43 | const std::string &GetStatus() const; |
| 44 | void SetStatus(const std::string &status); |
| 45 | |
| 46 | const std::string &GetId() const; |
| 47 | void SetId(const std::string &id); |
| 48 | |
| 49 | const std::string &GetShortName() const; |
| 50 | void SetShortName(const std::string &name); |
| 51 | |
| 52 | const std::string &GetLongName() const; |
| 53 | void SetLongName(const std::string &name); |
| 54 | |
| 55 | const std::string &GetTechnology() const; |
| 56 | void SetTechnology(const std::string &technology); |
| 57 | |
| 58 | const Stringmap &ToDict() const; |
| 59 | |
| 60 | private: |
| 61 | Stringmap dict_; |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 62 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 63 | DISALLOW_COPY_AND_ASSIGN(Network); |
| 64 | }; |
| 65 | |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 66 | struct CDMA { |
| 67 | CDMA(); |
| 68 | |
| 69 | uint32 registration_state_evdo; |
| 70 | uint32 registration_state_1x; |
| 71 | uint32 activation_state; |
| 72 | }; |
| 73 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 74 | struct SimLockStatus { |
| 75 | public: |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 76 | SimLockStatus() : retries_left(0) {} |
| 77 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 78 | std::string lock_type; |
| 79 | uint32 retries_left; |
| 80 | }; |
| 81 | |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 82 | // |owner| is the ModemManager DBus service owner (e.g., ":1.17"). |path| is |
| 83 | // the ModemManager.Modem DBus object path (e.g., |
| 84 | // "/org/chromium/ModemManager/Gobi/0"). |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 85 | Cellular(ControlInterface *control_interface, |
| 86 | EventDispatcher *dispatcher, |
| 87 | Manager *manager, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 88 | const std::string &link_name, |
| 89 | int interface_index, |
| 90 | Type type, |
| 91 | const std::string &owner, |
| 92 | const std::string &path); |
| 93 | virtual ~Cellular(); |
| 94 | |
| 95 | // Inherited from Device. |
| 96 | virtual void Start(); |
| 97 | virtual void Stop(); |
| 98 | virtual bool TechnologyIs(Technology type); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 99 | |
| 100 | private: |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 101 | FRIEND_TEST(CellularTest, GetCDMARegistrationState); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame^] | 102 | FRIEND_TEST(CellularTest, GetCDMASignalQuality); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 103 | FRIEND_TEST(CellularTest, GetModemInfo); |
| 104 | FRIEND_TEST(CellularTest, GetModemStatus); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 105 | FRIEND_TEST(CellularTest, GetStateString); |
| 106 | FRIEND_TEST(CellularTest, GetTypeString); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 107 | FRIEND_TEST(CellularTest, InitProxiesCDMA); |
| 108 | FRIEND_TEST(CellularTest, InitProxiesGSM); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 109 | FRIEND_TEST(CellularTest, Start); |
| 110 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 111 | Stringmaps EnumerateNetworks(); |
| 112 | StrIntPair SimLockStatusToProperty(); |
| 113 | void HelpRegisterDerivedStringmaps(const std::string &name, |
| 114 | Stringmaps(Cellular::*get)(void), |
| 115 | bool(Cellular::*set)(const Stringmaps&)); |
| 116 | void HelpRegisterDerivedStrIntPair(const std::string &name, |
| 117 | StrIntPair(Cellular::*get)(void), |
| 118 | bool(Cellular::*set)(const StrIntPair&)); |
| 119 | |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 120 | void InitProxies(); |
| 121 | |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 122 | std::string GetTypeString(); |
| 123 | std::string GetStateString(); |
| 124 | |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 125 | void EnableModem(); |
| 126 | void GetModemStatus(); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 127 | void GetGSMProperties(); |
| 128 | void RegisterGSMModem(); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 129 | |
| 130 | // Obtains the modem identifiers: MEID for CDMA; IMEI, IMSI, SPN and MSISDN |
| 131 | // for GSM. |
| 132 | void GetModemIdentifiers(); |
| 133 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame^] | 134 | // Obtains modem's manufacturer, model ID, and hardware revision. |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 135 | void GetModemInfo(); |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 136 | |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 137 | void GetModemRegistrationState(); |
| 138 | void GetCDMARegistrationState(); |
| 139 | void GetGSMRegistrationState(); |
| 140 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame^] | 141 | // Processes a change in the modem registration state, possibly creating, |
| 142 | // destroying or updating the CellularService. |
| 143 | void HandleNewRegistrationState(); |
| 144 | |
| 145 | void CreateService(); |
| 146 | |
| 147 | void GetModemSignalQuality(); |
| 148 | uint32 GetCDMASignalQuality(); |
| 149 | uint32 GetGSMSignalQuality(); |
| 150 | |
| 151 | void HandleNewSignalQuality(uint32 strength); |
| 152 | |
| 153 | // Returns true if the modem is registered. Note that this method looks at the |
| 154 | // latest CDMA/GSM registration info obtained from the modem rather than the |
| 155 | // device |state_|. |
| 156 | bool IsModemRegistered(); |
| 157 | |
| 158 | // Signal callbacks from ModemCDMAProxyListener. |
| 159 | virtual void OnCDMARegistrationStateChanged(uint32 state_1x, |
| 160 | uint32 state_evdo); |
| 161 | virtual void OnCDMASignalQualityChanged(uint32 strength); |
| 162 | |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 163 | Type type_; |
| 164 | State state_; |
| 165 | |
| 166 | const std::string dbus_owner_; // ModemManager.Modem |
| 167 | const std::string dbus_path_; // ModemManager.Modem |
| 168 | scoped_ptr<ModemProxyInterface> proxy_; |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 169 | scoped_ptr<ModemSimpleProxyInterface> simple_proxy_; |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 170 | scoped_ptr<ModemCDMAProxyInterface> cdma_proxy_; |
| 171 | |
| 172 | CDMA cdma_; |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 173 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame^] | 174 | CellularServiceRefPtr service_; |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 175 | bool service_registered_; |
| 176 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 177 | // Properties |
| 178 | bool allow_roaming_; |
| 179 | std::string carrier_; |
| 180 | std::string meid_; |
| 181 | std::string imei_; |
| 182 | std::string imsi_; |
| 183 | std::string esn_; |
| 184 | std::string mdn_; |
| 185 | std::string min_; |
| 186 | std::string model_id_; |
| 187 | std::string manufacturer_; |
| 188 | std::string firmware_revision_; |
| 189 | std::string hardware_revision_; |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 190 | uint16 prl_version_; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 191 | bool scanning_; |
| 192 | uint16 scan_interval_; |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 193 | std::vector<Network> found_networks_; |
| 194 | SimLockStatus sim_lock_status_; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 195 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 196 | DISALLOW_COPY_AND_ASSIGN(Cellular); |
| 197 | }; |
| 198 | |
| 199 | } // namespace shill |
| 200 | |
| 201 | #endif // SHILL_CELLULAR_ |