Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [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_CAPABILITY_GSM_ |
| 6 | #define SHILL_CELLULAR_CAPABILITY_GSM_ |
| 7 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 8 | #include <deque> |
| 9 | |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 10 | #include <base/memory/scoped_ptr.h> |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 11 | #include <base/memory/weak_ptr.h> |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 12 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 13 | |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 14 | #include "shill/accessor_interface.h" |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 15 | #include "shill/cellular.h" |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 16 | #include "shill/cellular_capability.h" |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 17 | #include "shill/modem_gsm_card_proxy_interface.h" |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 18 | #include "shill/modem_gsm_network_proxy_interface.h" |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 19 | |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 20 | struct mobile_provider; |
| 21 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 22 | namespace shill { |
| 23 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 24 | class CellularCapabilityGSM : public CellularCapability { |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 25 | public: |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 26 | CellularCapabilityGSM(Cellular *cellular, ProxyFactory *proxy_factory); |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 27 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 28 | // Inherited from CellularCapability. |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 29 | virtual void StartModem(Error *error, const ResultCallback &callback); |
| 30 | virtual void StopModem(Error *error, const ResultCallback &callback); |
Darin Petkov | 5f316f6 | 2011-11-18 12:10:26 +0100 | [diff] [blame] | 31 | virtual void OnServiceCreated(); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 32 | virtual void UpdateStatus(const DBusPropertiesMap &properties); |
| 33 | virtual void SetupConnectProperties(DBusPropertiesMap *properties); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 34 | // The following two methods never need to report results |
| 35 | // via callbacks, which is why they don't take callbacks |
| 36 | // as arguments. |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 37 | virtual void GetSignalQuality(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 38 | virtual void GetRegistrationState(); |
| 39 | // The following six methods are only ever called as |
| 40 | // callbacks (from the main loop), which is why they |
| 41 | // don't take an Error * argument. |
| 42 | virtual void GetProperties(const ResultCallback &callback); |
| 43 | virtual void GetIMEI(const ResultCallback &callback); |
| 44 | virtual void GetIMSI(const ResultCallback &callback); |
| 45 | virtual void GetSPN(const ResultCallback &callback); |
| 46 | virtual void GetMSISDN(const ResultCallback &callback); |
| 47 | virtual void Register(const ResultCallback &callback); |
| 48 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 49 | virtual void RegisterOnNetwork(const std::string &network_id, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 50 | Error *error, |
| 51 | const ResultCallback &callback); |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 52 | virtual bool IsRegistered(); |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 53 | virtual std::string CreateFriendlyServiceName(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 54 | virtual void RequirePIN(const std::string &pin, bool require, |
| 55 | Error *error, const ResultCallback &callback); |
| 56 | virtual void EnterPIN(const std::string &pin, |
| 57 | Error *error, const ResultCallback &callback); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 58 | virtual void UnblockPIN(const std::string &unblock_code, |
| 59 | const std::string &pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 60 | Error *error, const ResultCallback &callback); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 61 | virtual void ChangePIN(const std::string &old_pin, |
| 62 | const std::string &new_pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 63 | Error *error, const ResultCallback &callback); |
| 64 | virtual void Scan(Error *error, const ResultCallback &callback); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 65 | virtual std::string GetNetworkTechnologyString() const; |
| 66 | virtual std::string GetRoamingStateString() const; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 67 | virtual void OnModemManagerPropertiesChanged( |
| 68 | const DBusPropertiesMap &properties); |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 69 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 70 | protected: |
| 71 | virtual void InitProxies(); |
| 72 | virtual void ReleaseProxies(); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 73 | // Override OnConnectReply in order to handle the possibility of |
| 74 | // retrying the Connect operation. |
| 75 | virtual void OnConnectReply(const ResultCallback &callback, |
| 76 | const Error &error); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 77 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 78 | private: |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 79 | friend class CellularTest; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 80 | friend class CellularCapabilityGSMTest; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 81 | friend class CellularCapabilityTest; |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 82 | FRIEND_TEST(CellularCapabilityGSMTest, CreateDeviceFromProperties); |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 83 | FRIEND_TEST(CellularCapabilityGSMTest, CreateFriendlyServiceName); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 84 | FRIEND_TEST(CellularCapabilityGSMTest, GetIMEI); |
| 85 | FRIEND_TEST(CellularCapabilityGSMTest, GetIMSI); |
| 86 | FRIEND_TEST(CellularCapabilityGSMTest, GetMSISDN); |
| 87 | FRIEND_TEST(CellularCapabilityGSMTest, GetSPN); |
| 88 | FRIEND_TEST(CellularCapabilityGSMTest, RequirePIN); |
| 89 | FRIEND_TEST(CellularCapabilityGSMTest, EnterPIN); |
| 90 | FRIEND_TEST(CellularCapabilityGSMTest, UnblockPIN); |
| 91 | FRIEND_TEST(CellularCapabilityGSMTest, ChangePIN); |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 92 | FRIEND_TEST(CellularCapabilityGSMTest, InitAPNList); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 93 | FRIEND_TEST(CellularCapabilityGSMTest, ParseScanResult); |
| 94 | FRIEND_TEST(CellularCapabilityGSMTest, ParseScanResultProviderLookup); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 95 | FRIEND_TEST(CellularCapabilityGSMTest, RegisterOnNetwork); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 96 | FRIEND_TEST(CellularCapabilityGSMTest, Scan); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 97 | FRIEND_TEST(CellularCapabilityGSMTest, SetAccessTechnology); |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 98 | FRIEND_TEST(CellularCapabilityGSMTest, SetHomeProvider); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 99 | FRIEND_TEST(CellularCapabilityGSMTest, UpdateOperatorInfo); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 100 | FRIEND_TEST(CellularCapabilityGSMTest, GetRegistrationState); |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 101 | FRIEND_TEST(CellularCapabilityGSMTest, OnModemManagerPropertiesChanged); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 102 | FRIEND_TEST(CellularCapabilityGSMTest, SetupApnTryList); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 103 | FRIEND_TEST(CellularCapabilityTest, AllowRoaming); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 104 | FRIEND_TEST(CellularCapabilityTest, TryApns); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 105 | FRIEND_TEST(CellularTest, StartGSMRegister); |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 106 | FRIEND_TEST(ModemTest, CreateDeviceFromProperties); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 107 | |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 108 | struct SimLockStatus { |
| 109 | public: |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 110 | SimLockStatus() : enabled(false), retries_left(0) {} |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 111 | |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 112 | bool enabled; |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 113 | std::string lock_type; |
| 114 | uint32 retries_left; |
| 115 | }; |
| 116 | |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 117 | static const char kNetworkPropertyAccessTechnology[]; |
| 118 | static const char kNetworkPropertyID[]; |
| 119 | static const char kNetworkPropertyLongName[]; |
| 120 | static const char kNetworkPropertyShortName[]; |
| 121 | static const char kNetworkPropertyStatus[]; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 122 | static const char kPhoneNumber[]; |
| 123 | static const char kPropertyAccessTechnology[]; |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 124 | static const char kPropertyEnabledFacilityLocks[]; |
| 125 | static const char kPropertyUnlockRequired[]; |
| 126 | static const char kPropertyUnlockRetries[]; |
| 127 | |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 128 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 129 | void SetAccessTechnology(uint32 access_technology); |
| 130 | |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 131 | // Sets the upper level information about the home cellular provider from the |
| 132 | // modem's IMSI and SPN. |
| 133 | void SetHomeProvider(); |
| 134 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 135 | // Updates the GSM operator name and country based on a newly obtained network |
| 136 | // id. |
| 137 | void UpdateOperatorInfo(); |
| 138 | |
| 139 | // Updates the serving operator on the active service. |
| 140 | void UpdateServingOperator(); |
| 141 | |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 142 | // Initializes the |apn_list_| property based on the current |home_provider_|. |
| 143 | void InitAPNList(); |
| 144 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 145 | Stringmap ParseScanResult(const GSMScanResult &result); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 146 | |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 147 | KeyValueStore SimLockStatusToProperty(Error *error); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 148 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 149 | void SetupApnTryList(); |
| 150 | void FillConnectPropertyMap(DBusPropertiesMap *properties); |
| 151 | |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 152 | void HelpRegisterDerivedKeyValueStore( |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 153 | const std::string &name, |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 154 | KeyValueStore(CellularCapabilityGSM::*get)(Error *error), |
| 155 | void(CellularCapabilityGSM::*set)( |
| 156 | const KeyValueStore &value, Error *error)); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 157 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 158 | // Signal callbacks |
| 159 | virtual void OnNetworkModeSignal(uint32 mode); |
| 160 | virtual void OnRegistrationInfoSignal(uint32 status, |
| 161 | const std::string &operator_code, |
| 162 | const std::string &operator_name); |
| 163 | virtual void OnSignalQualitySignal(uint32 quality); |
| 164 | |
| 165 | // Method callbacks |
| 166 | virtual void OnGetRegistrationInfoReply(uint32 status, |
| 167 | const std::string &operator_code, |
| 168 | const std::string &operator_name, |
| 169 | const Error &error); |
| 170 | virtual void OnGetSignalQualityReply(uint32 quality, const Error &error); |
| 171 | virtual void OnRegisterReply(const ResultCallback &callback, |
| 172 | const Error &error); |
| 173 | virtual void OnGetIMEIReply(const ResultCallback &callback, |
| 174 | const std::string &imei, |
| 175 | const Error &error); |
| 176 | virtual void OnGetIMSIReply(const ResultCallback &callback, |
| 177 | const std::string &imsi, |
| 178 | const Error &error); |
| 179 | virtual void OnGetSPNReply(const ResultCallback &callback, |
| 180 | const std::string &spn, |
| 181 | const Error &error); |
| 182 | virtual void OnGetMSISDNReply(const ResultCallback &callback, |
| 183 | const std::string &msisdn, |
| 184 | const Error &error); |
| 185 | virtual void OnScanReply(const ResultCallback &callback, |
| 186 | const GSMScanResults &results, |
| 187 | const Error &error); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 188 | |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 189 | scoped_ptr<ModemGSMCardProxyInterface> card_proxy_; |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 190 | scoped_ptr<ModemGSMNetworkProxyInterface> network_proxy_; |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 191 | base::WeakPtrFactory<CellularCapabilityGSM> weak_ptr_factory_; |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 192 | |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 193 | uint32 registration_state_; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 194 | uint32 access_technology_; |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 195 | Cellular::Operator serving_operator_; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 196 | std::string spn_; |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 197 | mobile_provider *home_provider_; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 198 | std::string desired_network_; |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 199 | |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 200 | // Properties. |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 201 | std::string selected_network_; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 202 | Stringmaps found_networks_; |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 203 | std::deque<Stringmap> apn_try_list_; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 204 | bool scanning_; |
| 205 | uint16 scan_interval_; |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 206 | SimLockStatus sim_lock_status_; |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 207 | Stringmaps apn_list_; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 208 | |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 209 | static unsigned int friendly_service_name_id_; |
| 210 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 211 | DISALLOW_COPY_AND_ASSIGN(CellularCapabilityGSM); |
| 212 | }; |
| 213 | |
| 214 | } // namespace shill |
| 215 | |
| 216 | #endif // SHILL_CELLULAR_CAPABILITY_GSM_ |