1 // 2 // Copyright (C) 2012 The Android Open Source Project 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #ifndef SHILL_CELLULAR_CELLULAR_CAPABILITY_GSM_H_ 18 #define SHILL_CELLULAR_CELLULAR_CAPABILITY_GSM_H_ 19 20 #include <deque> 21 #include <memory> 22 #include <string> 23 #include <vector> 24 25 #include <base/memory/weak_ptr.h> 26 #if defined(__ANDROID__) 27 #include <dbus/service_constants.h> 28 #else 29 #include <chromeos/dbus/service_constants.h> 30 #endif // __ANDROID__ 31 #include <gtest/gtest_prod.h> // for FRIEND_TEST 32 33 #include "shill/accessor_interface.h" 34 #include "shill/cellular/cellular.h" 35 #include "shill/cellular/cellular_capability.h" 36 #include "shill/cellular/cellular_capability_classic.h" 37 #include "shill/cellular/modem_gsm_card_proxy_interface.h" 38 #include "shill/cellular/modem_gsm_network_proxy_interface.h" 39 40 struct mobile_provider; 41 42 namespace shill { 43 44 class ModemInfo; 45 46 class CellularCapabilityGSM : public CellularCapabilityClassic { 47 public: 48 CellularCapabilityGSM(Cellular* cellular, 49 ControlInterface* control_interface, 50 ModemInfo* modem_info); 51 ~CellularCapabilityGSM() override; 52 53 // Inherited from CellularCapability. 54 std::string GetTypeString() const override; 55 void OnPropertiesChanged( 56 const std::string& interface, 57 const KeyValueStore& changed_properties, 58 const std::vector<std::string>& invalidated_properties) override; 59 void StartModem(Error* error, const ResultCallback& callback) override; 60 bool AreProxiesInitialized() const override; 61 void Scan(Error* error, const ResultStringmapsCallback& callback) override; 62 void RegisterOnNetwork(const std::string& network_id, 63 Error* error, 64 const ResultCallback& callback) override; 65 bool IsRegistered() const override; 66 void SetUnregistered(bool searching) override; 67 void OnServiceCreated() override; 68 std::string GetNetworkTechnologyString() const override; 69 std::string GetRoamingStateString() const override; 70 bool AllowRoaming() override; 71 void GetSignalQuality() override; 72 void SetupConnectProperties(KeyValueStore* properties) override; 73 void Connect(const KeyValueStore& properties, 74 Error* error, 75 const ResultCallback& callback) override; 76 void RequirePIN(const std::string& pin, 77 bool require, 78 Error* error, 79 const ResultCallback& callback) override; 80 void EnterPIN(const std::string& pin, 81 Error* error, 82 const ResultCallback& callback) override; 83 void UnblockPIN(const std::string& unblock_code, 84 const std::string& pin, 85 Error* error, 86 const ResultCallback& callback) override; 87 void ChangePIN(const std::string& old_pin, 88 const std::string& new_pin, 89 Error* error, 90 const ResultCallback& callback) override; 91 92 // Inherited from CellularCapabilityClassic. 93 void GetRegistrationState() override; 94 // The following six methods are only ever called as callbacks (from the main 95 // loop), which is why they don't take an Error* argument. 96 void GetProperties(const ResultCallback& callback) override; 97 98 virtual void GetIMEI(const ResultCallback& callback); 99 virtual void GetIMSI(const ResultCallback& callback); 100 virtual void GetSPN(const ResultCallback& callback); 101 virtual void GetMSISDN(const ResultCallback& callback); 102 virtual void Register(const ResultCallback& callback); 103 104 protected: 105 // Inherited from CellularCapabilityClassic. 106 void InitProxies() override; 107 void ReleaseProxies() override; 108 109 // Initializes properties, such as IMSI, which are required before the device 110 // is enabled. 111 virtual void InitProperties(); 112 113 private: 114 friend class CellularTest; 115 friend class CellularCapabilityGSMTest; 116 friend class CellularCapabilityTest; 117 FRIEND_TEST(CellularCapabilityGSMTest, AllowRoaming); 118 FRIEND_TEST(CellularCapabilityGSMTest, CreateDeviceFromProperties); 119 FRIEND_TEST(CellularCapabilityGSMTest, GetIMEI); 120 FRIEND_TEST(CellularCapabilityGSMTest, GetIMSI); 121 FRIEND_TEST(CellularCapabilityGSMTest, GetIMSIFails); 122 FRIEND_TEST(CellularCapabilityGSMTest, GetMSISDN); 123 FRIEND_TEST(CellularCapabilityGSMTest, GetSPN); 124 FRIEND_TEST(CellularCapabilityGSMTest, RequirePIN); 125 FRIEND_TEST(CellularCapabilityGSMTest, EnterPIN); 126 FRIEND_TEST(CellularCapabilityGSMTest, UnblockPIN); 127 FRIEND_TEST(CellularCapabilityGSMTest, ChangePIN); 128 FRIEND_TEST(CellularCapabilityGSMTest, ParseScanResult); 129 FRIEND_TEST(CellularCapabilityGSMTest, ParseScanResultProviderLookup); 130 FRIEND_TEST(CellularCapabilityGSMTest, RegisterOnNetwork); 131 FRIEND_TEST(CellularCapabilityGSMTest, SetAccessTechnology); 132 FRIEND_TEST(CellularCapabilityGSMTest, GetRegistrationState); 133 FRIEND_TEST(CellularCapabilityGSMTest, OnPropertiesChanged); 134 FRIEND_TEST(CellularCapabilityTest, AllowRoaming); 135 FRIEND_TEST(CellularCapabilityTest, TryApns); 136 FRIEND_TEST(CellularTest, ScanAsynchronousFailure); 137 FRIEND_TEST(CellularTest, ScanImmediateFailure); 138 FRIEND_TEST(CellularTest, ScanSuccess); 139 FRIEND_TEST(CellularTest, StartGSMRegister); 140 FRIEND_TEST(ModemTest, CreateDeviceFromProperties); 141 142 // SimLockStatus represents the fields in the Cellular.SIMLockStatus 143 // DBUS property of the shill device. 144 struct SimLockStatus { 145 public: 146 SimLockStatus() : enabled(false), retries_left(0) {} 147 148 bool enabled; 149 std::string lock_type; 150 uint32_t retries_left; 151 }; 152 153 static const char kNetworkPropertyAccessTechnology[]; 154 static const char kNetworkPropertyID[]; 155 static const char kNetworkPropertyLongName[]; 156 static const char kNetworkPropertyShortName[]; 157 static const char kNetworkPropertyStatus[]; 158 static const char kPhoneNumber[]; 159 static const char kPropertyAccessTechnology[]; 160 static const char kPropertyEnabledFacilityLocks[]; 161 static const char kPropertyUnlockRequired[]; 162 static const char kPropertyUnlockRetries[]; 163 164 // Calls to the proxy's GetIMSI() will be retried this many times. 165 static const int kGetIMSIRetryLimit; 166 167 // This much time will pass between retries of GetIMSI(). 168 static const int64_t kGetIMSIRetryDelayMilliseconds; 169 170 void SetAccessTechnology(uint32_t access_technology); 171 172 Stringmap ParseScanResult(const GSMScanResult& result); 173 174 KeyValueStore SimLockStatusToProperty(Error* error); 175 176 void SetupApnTryList(); 177 void FillConnectPropertyMap(KeyValueStore* properties); 178 179 void HelpRegisterConstDerivedKeyValueStore( 180 const std::string& name, 181 KeyValueStore(CellularCapabilityGSM::*get)(Error* error)); 182 183 bool IsUnderlyingDeviceRegistered() const; 184 185 // Signal callbacks 186 void OnNetworkModeSignal(uint32_t mode); 187 void OnRegistrationInfoSignal(uint32_t status, 188 const std::string& operator_code, 189 const std::string& operator_name); 190 void OnSignalQualitySignal(uint32_t quality); 191 192 // Method callbacks 193 void OnGetRegistrationInfoReply(uint32_t status, 194 const std::string& operator_code, 195 const std::string& operator_name, 196 const Error& error); 197 void OnGetSignalQualityReply(uint32_t quality, const Error& error); 198 void OnRegisterReply(const ResultCallback& callback, 199 const Error& error); 200 void OnGetIMEIReply(const ResultCallback& callback, 201 const std::string& imei, 202 const Error& error); 203 void OnGetIMSIReply(const ResultCallback& callback, 204 const std::string& imsi, 205 const Error& error); 206 void OnGetSPNReply(const ResultCallback& callback, 207 const std::string& spn, 208 const Error& error); 209 void OnGetMSISDNReply(const ResultCallback& callback, 210 const std::string& msisdn, 211 const Error& error); 212 void OnScanReply(const ResultStringmapsCallback& callback, 213 const GSMScanResults& results, 214 const Error& error); 215 void OnConnectReply(const ResultCallback& callback, const Error& error); 216 217 std::unique_ptr<ModemGSMCardProxyInterface> card_proxy_; 218 std::unique_ptr<ModemGSMNetworkProxyInterface> network_proxy_; 219 base::WeakPtrFactory<CellularCapabilityGSM> weak_ptr_factory_; 220 // Used to enrich information about the network operator in |ParseScanResult|. 221 // TODO(pprabhu) Instead instantiate a local |MobileOperatorInfo| instance 222 // once the context has been separated out. (crbug.com/363874) 223 std::unique_ptr<MobileOperatorInfo> mobile_operator_info_; 224 225 uint32_t registration_state_; 226 uint32_t access_technology_; 227 std::string spn_; 228 mobile_provider* home_provider_info_; 229 std::string desired_network_; 230 231 // The number of times GetIMSI() has been retried. 232 int get_imsi_retries_; 233 234 // Amount of time to wait between retries of GetIMSI. Defaults to 235 // kGetIMSIRetryDelayMilliseconds, but can be altered by a unit test. 236 int64_t get_imsi_retry_delay_milliseconds_; 237 238 // Properties. 239 std::deque<Stringmap> apn_try_list_; 240 SimLockStatus sim_lock_status_; 241 242 DISALLOW_COPY_AND_ASSIGN(CellularCapabilityGSM); 243 }; 244 245 } // namespace shill 246 247 #endif // SHILL_CELLULAR_CELLULAR_CAPABILITY_GSM_H_ 248