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 | |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 5 | #ifndef SHILL_CELLULAR_CAPABILITY_UNIVERSAL_H_ |
| 6 | #define SHILL_CELLULAR_CAPABILITY_UNIVERSAL_H_ |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 7 | |
| 8 | #include <deque> |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 9 | #include <map> |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 10 | #include <string> |
| 11 | #include <vector> |
| 12 | |
| 13 | #include <base/memory/scoped_ptr.h> |
| 14 | #include <base/memory/weak_ptr.h> |
| 15 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 16 | #include <mm/ModemManager-enums.h> |
| 17 | |
| 18 | #include "shill/accessor_interface.h" |
| 19 | #include "shill/cellular.h" |
| 20 | #include "shill/cellular_capability.h" |
| 21 | #include "shill/mm1_modem_modem3gpp_proxy_interface.h" |
| 22 | #include "shill/mm1_modem_modemcdma_proxy_interface.h" |
| 23 | #include "shill/mm1_modem_proxy_interface.h" |
| 24 | #include "shill/mm1_modem_simple_proxy_interface.h" |
| 25 | #include "shill/mm1_sim_proxy_interface.h" |
| 26 | |
| 27 | |
| 28 | struct mobile_provider; |
| 29 | |
| 30 | namespace shill { |
| 31 | |
| 32 | // CellularCapabilityUniversal handles modems using the |
| 33 | // org.chromium.ModemManager1 DBUS interface. This class is used for |
| 34 | // all types of modems, i.e. CDMA, GSM, and LTE modems. |
| 35 | class CellularCapabilityUniversal : public CellularCapability { |
| 36 | public: |
| 37 | typedef std::vector<DBusPropertiesMap> ScanResults; |
| 38 | typedef DBusPropertiesMap ScanResult; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 39 | typedef std::map< uint32_t, uint32_t > LockRetryData; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 40 | |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 41 | // Constants used in connect method call. Make available to test matchers. |
| 42 | // TODO(jglasgow): Generate from modem manager into |
| 43 | // ModemManager-names.h. |
| 44 | // See http://crosbug.com/30551. |
| 45 | static const char kConnectPin[]; |
| 46 | static const char kConnectOperatorId[]; |
| 47 | static const char kConnectBands[]; |
| 48 | static const char kConnectAllowedModes[]; |
| 49 | static const char kConnectPreferredMode[]; |
| 50 | static const char kConnectApn[]; |
| 51 | static const char kConnectIPType[]; |
| 52 | static const char kConnectUser[]; |
| 53 | static const char kConnectPassword[]; |
| 54 | static const char kConnectNumber[]; |
| 55 | static const char kConnectAllowRoaming[]; |
| 56 | static const char kConnectRMProtocol[]; |
| 57 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 58 | CellularCapabilityUniversal(Cellular *cellular, ProxyFactory *proxy_factory); |
| 59 | |
| 60 | // Inherited from CellularCapability. |
| 61 | virtual void StartModem(Error *error, const ResultCallback &callback); |
| 62 | virtual void StopModem(Error *error, const ResultCallback &callback); |
| 63 | virtual void Connect(const DBusPropertiesMap &properties, Error *error, |
| 64 | const ResultCallback &callback); |
| 65 | virtual void Disconnect(Error *error, const ResultCallback &callback); |
| 66 | virtual void Activate(const std::string &carrier, |
| 67 | Error *error, const ResultCallback &callback); |
| 68 | |
| 69 | virtual void OnServiceCreated(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 70 | virtual void SetupConnectProperties(DBusPropertiesMap *properties); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 71 | virtual void GetProperties(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 72 | virtual void Register(const ResultCallback &callback); |
| 73 | |
| 74 | virtual void RegisterOnNetwork(const std::string &network_id, |
| 75 | Error *error, |
| 76 | const ResultCallback &callback); |
| 77 | virtual bool IsRegistered(); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 78 | virtual void SetUnregistered(bool searching); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 79 | virtual std::string CreateFriendlyServiceName(); |
| 80 | virtual void RequirePIN(const std::string &pin, bool require, |
| 81 | Error *error, const ResultCallback &callback); |
| 82 | virtual void EnterPIN(const std::string &pin, |
| 83 | Error *error, const ResultCallback &callback); |
| 84 | virtual void UnblockPIN(const std::string &unblock_code, |
| 85 | const std::string &pin, |
| 86 | Error *error, const ResultCallback &callback); |
| 87 | virtual void ChangePIN(const std::string &old_pin, |
| 88 | const std::string &new_pin, |
| 89 | Error *error, const ResultCallback &callback); |
| 90 | |
| 91 | virtual void Scan(Error *error, const ResultCallback &callback); |
| 92 | virtual std::string GetNetworkTechnologyString() const; |
| 93 | virtual std::string GetRoamingStateString() const; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 94 | virtual void GetSignalQuality(); |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 95 | virtual std::string GetTypeString() const; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 96 | virtual void OnDBusPropertiesChanged( |
| 97 | const std::string &interface, |
| 98 | const DBusPropertiesMap &changed_properties, |
| 99 | const std::vector<std::string> &invalidated_properties); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 100 | virtual bool AllowRoaming(); |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 101 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 102 | protected: |
| 103 | virtual void InitProxies(); |
| 104 | virtual void ReleaseProxies(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 105 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 106 | private: |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 107 | // Constants used in scan results. Make available to unit tests. |
| 108 | // TODO(jglasgow): Generate from modem manager into ModemManager-names.h. |
| 109 | // See http://crosbug.com/30551. |
| 110 | static const char kStatusProperty[]; |
| 111 | static const char kOperatorLongProperty[]; |
| 112 | static const char kOperatorShortProperty[]; |
| 113 | static const char kOperatorCodeProperty[]; |
| 114 | static const char kOperatorAccessTechnologyProperty[]; |
| 115 | |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 116 | // Modem Model ID strings. From modem firmware via modemmanager. |
| 117 | static const char kE362ModelId[]; |
| 118 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 119 | friend class CellularTest; |
| 120 | friend class CellularCapabilityUniversalTest; |
| 121 | friend class CellularCapabilityTest; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 122 | FRIEND_TEST(CellularCapabilityUniversalTest, StartModem); |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 123 | FRIEND_TEST(CellularCapabilityUniversalTest, StopModem); |
| 124 | FRIEND_TEST(CellularCapabilityUniversalTest, StopModemConnected); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 125 | FRIEND_TEST(CellularCapabilityUniversalTest, PropertiesChanged); |
| 126 | FRIEND_TEST(CellularCapabilityUniversalTest, SimPropertiesChanged); |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 127 | FRIEND_TEST(CellularCapabilityUniversalTest, Scan); |
| 128 | FRIEND_TEST(CellularCapabilityUniversalTest, ScanFailure); |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 129 | FRIEND_TEST(CellularCapabilityUniversalTest, Connect); |
| 130 | FRIEND_TEST(CellularCapabilityUniversalTest, ConnectApns); |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 131 | FRIEND_TEST(CellularCapabilityUniversalTest, GetTypeString); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 132 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 133 | // Methods used in starting a modem |
| 134 | void Start_EnableModemCompleted(const ResultCallback &callback, |
| 135 | const Error &error); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 136 | |
| 137 | // Methods used in stopping a modem |
| 138 | void Stop_DisconnectCompleted(const ResultCallback &callback, |
| 139 | const Error &error); |
| 140 | void Stop_Disable(const ResultCallback &callback); |
| 141 | void Stop_DisableCompleted(const ResultCallback &callback, |
| 142 | const Error &error); |
| 143 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 144 | // Sets the upper level information about the home cellular provider from the |
| 145 | // modem's IMSI and SPN. |
| 146 | void SetHomeProvider(); |
| 147 | |
| 148 | // Updates the Universal operator name and country based on a newly |
| 149 | // obtained network id. |
| 150 | void UpdateOperatorInfo(); |
| 151 | |
| 152 | // Updates the serving operator on the active service. |
| 153 | void UpdateServingOperator(); |
| 154 | |
| 155 | // Initializes the |apn_list_| property based on the current |home_provider_|. |
| 156 | void InitAPNList(); |
| 157 | |
| 158 | Stringmap ParseScanResult(const ScanResult &result); |
| 159 | |
| 160 | KeyValueStore SimLockStatusToProperty(Error *error); |
| 161 | |
| 162 | void SetupApnTryList(); |
| 163 | void FillConnectPropertyMap(DBusPropertiesMap *properties); |
| 164 | |
| 165 | void HelpRegisterDerivedKeyValueStore( |
| 166 | const std::string &name, |
| 167 | KeyValueStore(CellularCapabilityUniversal::*get)(Error *error), |
| 168 | void(CellularCapabilityUniversal::*set)( |
| 169 | const KeyValueStore &value, Error *error)); |
| 170 | |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 171 | // Returns true if a connect error should be retried. This function |
| 172 | // abstracts modem specific behavior for modems which do a lousy job |
| 173 | // of returning specific errors on connect failures. |
| 174 | bool RetriableConnectError(const Error &error) const; |
| 175 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 176 | // Signal callbacks |
Nathan Williams | 3022be5 | 2012-04-19 17:40:49 -0400 | [diff] [blame] | 177 | void OnNetworkModeSignal(uint32 mode); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 178 | void OnModemStateChangedSignal(int32 old_state, |
| 179 | int32 new_state, |
| 180 | uint32 reason); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 181 | |
| 182 | // Property Change notification handlers |
Nathan Williams | 3022be5 | 2012-04-19 17:40:49 -0400 | [diff] [blame] | 183 | void OnModemPropertiesChanged( |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 184 | const DBusPropertiesMap &properties, |
| 185 | const std::vector<std::string> &invalidated_properties); |
| 186 | |
Nathan Williams | 3022be5 | 2012-04-19 17:40:49 -0400 | [diff] [blame] | 187 | void OnSignalQualityChanged(uint32 quality); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 188 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 189 | // Updates the sim_path_ variable and creates a new proxy to the |
| 190 | // DBUS ModemManager1.Sim interface |
Nathan Williams | 3022be5 | 2012-04-19 17:40:49 -0400 | [diff] [blame] | 191 | void OnSimPathChanged(const std::string &sim_path); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 192 | void OnModemCapabilitesChanged(uint32 capabilities); |
| 193 | void OnModemCurrentCapabilitiesChanged(uint32 current_capabilities); |
| 194 | void OnMdnChanged(const std::string &mdn); |
| 195 | void OnModemManufacturerChanged(const std::string &manufacturer); |
| 196 | void OnModemModelChanged(const std::string &model); |
| 197 | void OnModemRevisionChanged(const std::string &revision); |
| 198 | void OnModemStateChanged(Cellular::ModemState state); |
| 199 | void OnAccessTechnologiesChanged(uint32 access_technologies); |
| 200 | void OnSupportedModesChanged(uint32 supported_modes); |
| 201 | void OnAllowedModesChanged(uint32 allowed_modes); |
| 202 | void OnPreferredModeChanged(MMModemMode preferred_mode); |
| 203 | void OnLockRetriesChanged(MMModemLock unlock_required, |
| 204 | const LockRetryData &lock_retries); |
| 205 | void OnSimLockStatusChanged(); |
| 206 | |
| 207 | // 3GPP property change handlers |
| 208 | virtual void OnModem3GPPPropertiesChanged( |
| 209 | const DBusPropertiesMap &properties, |
| 210 | const std::vector<std::string> &invalidated_properties); |
| 211 | void OnImeiChanged(const std::string &imei); |
| 212 | void On3GPPRegistrationChanged(MMModem3gppRegistrationState state, |
| 213 | const std::string &operator_code, |
| 214 | const std::string &operator_name); |
| 215 | void OnFacilityLocksChanged(uint32 locks); |
| 216 | |
| 217 | // SIM property change handlers |
| 218 | void OnSimPropertiesChanged( |
| 219 | const DBusPropertiesMap &props, |
| 220 | const std::vector<std::string> &invalidated_properties); |
| 221 | void OnImsiChanged(const std::string &imsi); |
| 222 | void OnSimIdentifierChanged(const std::string &id); |
| 223 | void OnOperatorIdChanged(const std::string &operator_id); |
| 224 | void OnOperatorNameChanged(const std::string &operator_name); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 225 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 226 | // Method callbacks |
Nathan Williams | 3022be5 | 2012-04-19 17:40:49 -0400 | [diff] [blame] | 227 | void OnRegisterReply(const ResultCallback &callback, |
| 228 | const Error &error); |
| 229 | void OnScanReply(const ResultCallback &callback, |
| 230 | const ScanResults &results, |
| 231 | const Error &error); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 232 | void OnConnectReply(const ResultCallback &callback, |
| 233 | const DBus::Path &bearer, |
| 234 | const Error &error); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 235 | |
| 236 | scoped_ptr<mm1::ModemModem3gppProxyInterface> modem_3gpp_proxy_; |
| 237 | scoped_ptr<mm1::ModemModemCdmaProxyInterface> modem_cdma_proxy_; |
| 238 | scoped_ptr<mm1::ModemProxyInterface> modem_proxy_; |
| 239 | scoped_ptr<mm1::ModemSimpleProxyInterface> modem_simple_proxy_; |
| 240 | scoped_ptr<mm1::SimProxyInterface> sim_proxy_; |
| 241 | |
| 242 | base::WeakPtrFactory<CellularCapabilityUniversal> weak_ptr_factory_; |
| 243 | |
| 244 | MMModem3gppRegistrationState registration_state_; |
| 245 | MMModemCdmaRegistrationState cdma_registration_state_; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 246 | |
| 247 | // Bits based on MMModemCapabilities |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 248 | uint32 capabilities_; // technologies supported, may require reload |
| 249 | uint32 current_capabilities_; // technologies supportsed without a reload |
| 250 | uint32 access_technologies_; // Bits based on MMModemAccessTechnology |
| 251 | uint32 supported_modes_; // Bits based on MMModemMode |
| 252 | uint32 allowed_modes_; // Bits based on MMModemMode |
| 253 | MMModemMode preferred_mode_; // A single MMModemMode bit |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 254 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 255 | Cellular::Operator serving_operator_; |
| 256 | std::string spn_; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 257 | std::string sim_identifier_; |
| 258 | std::string operator_id_; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 259 | mobile_provider *home_provider_; |
| 260 | std::string desired_network_; |
| 261 | |
| 262 | // Properties. |
| 263 | std::string carrier_; |
| 264 | std::string esn_; |
| 265 | std::string firmware_revision_; |
| 266 | std::string hardware_revision_; |
| 267 | std::string imei_; |
| 268 | std::string imsi_; |
| 269 | std::string manufacturer_; |
| 270 | std::string mdn_; |
| 271 | std::string meid_; |
| 272 | std::string min_; |
| 273 | std::string model_id_; |
| 274 | std::string selected_network_; |
| 275 | Stringmaps found_networks_; |
| 276 | std::deque<Stringmap> apn_try_list_; |
| 277 | bool scanning_supported_; |
| 278 | bool scanning_; |
| 279 | uint16 scan_interval_; |
| 280 | SimLockStatus sim_lock_status_; |
| 281 | Stringmaps apn_list_; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 282 | std::string sim_path_; |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 283 | DBus::Path bearer_path_; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 284 | |
| 285 | static unsigned int friendly_service_name_id_; |
| 286 | |
| 287 | DISALLOW_COPY_AND_ASSIGN(CellularCapabilityUniversal); |
| 288 | }; |
| 289 | |
| 290 | } // namespace shill |
| 291 | |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 292 | #endif // SHILL_CELLULAR_CAPABILITY_UNIVERSAL_H_ |