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