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 | |
Ben Chan | c54afe5 | 2014-11-05 10:28:08 -0800 | [diff] [blame^] | 5 | #include "shill/cellular/cellular_capability_gsm.h" |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 6 | |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 7 | #include <string> |
| 8 | #include <vector> |
| 9 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 10 | #include <base/bind.h> |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 11 | #include <base/stl_util.h> |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 12 | #include <base/strings/string_number_conversions.h> |
| 13 | #include <base/strings/stringprintf.h> |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 14 | #include <chromeos/dbus/service_constants.h> |
| 15 | #include <mm/mm-modem.h> |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 16 | |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 17 | #include "shill/adaptor_interfaces.h" |
Ben Chan | c54afe5 | 2014-11-05 10:28:08 -0800 | [diff] [blame^] | 18 | #include "shill/cellular/cellular_service.h" |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 19 | #include "shill/error.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 20 | #include "shill/logging.h" |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 21 | #include "shill/property_accessor.h" |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 22 | #include "shill/proxy_factory.h" |
| 23 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 24 | using base::Bind; |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 25 | using std::string; |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 26 | using std::vector; |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 27 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 28 | namespace shill { |
| 29 | |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 30 | namespace Logging { |
| 31 | static auto kModuleLogScope = ScopeLogger::kCellular; |
| 32 | static string ObjectID(CellularCapabilityGSM *c) { |
| 33 | return c->cellular()->GetRpcIdentifier(); |
| 34 | } |
| 35 | } |
| 36 | |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 37 | // static |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 38 | const char CellularCapabilityGSM::kNetworkPropertyAccessTechnology[] = |
| 39 | "access-tech"; |
| 40 | const char CellularCapabilityGSM::kNetworkPropertyID[] = "operator-num"; |
| 41 | const char CellularCapabilityGSM::kNetworkPropertyLongName[] = "operator-long"; |
| 42 | const char CellularCapabilityGSM::kNetworkPropertyShortName[] = |
| 43 | "operator-short"; |
| 44 | const char CellularCapabilityGSM::kNetworkPropertyStatus[] = "status"; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 45 | const char CellularCapabilityGSM::kPhoneNumber[] = "*99#"; |
| 46 | const char CellularCapabilityGSM::kPropertyAccessTechnology[] = |
| 47 | "AccessTechnology"; |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 48 | const char CellularCapabilityGSM::kPropertyEnabledFacilityLocks[] = |
| 49 | "EnabledFacilityLocks"; |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 50 | const char CellularCapabilityGSM::kPropertyUnlockRequired[] = "UnlockRequired"; |
| 51 | const char CellularCapabilityGSM::kPropertyUnlockRetries[] = "UnlockRetries"; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 52 | |
Ben Chan | c89b928 | 2012-12-12 14:00:29 -0800 | [diff] [blame] | 53 | const int CellularCapabilityGSM::kGetIMSIRetryLimit = 40; |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 54 | const int64_t CellularCapabilityGSM::kGetIMSIRetryDelayMilliseconds = 500; |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 55 | |
| 56 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 57 | CellularCapabilityGSM::CellularCapabilityGSM(Cellular *cellular, |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 58 | ProxyFactory *proxy_factory, |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 59 | ModemInfo *modem_info) |
| 60 | : CellularCapabilityClassic(cellular, proxy_factory, modem_info), |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 61 | weak_ptr_factory_(this), |
Prathmesh Prabhu | afe6366 | 2014-05-20 11:03:58 -0700 | [diff] [blame] | 62 | mobile_operator_info_(new MobileOperatorInfo(cellular->dispatcher(), |
| 63 | "ParseScanResult")), |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 64 | registration_state_(MM_MODEM_GSM_NETWORK_REG_STATUS_UNKNOWN), |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 65 | access_technology_(MM_MODEM_GSM_ACCESS_TECH_UNKNOWN), |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 66 | home_provider_info_(nullptr), |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 67 | get_imsi_retries_(0), |
Prathmesh Prabhu | 49ffffd | 2014-01-09 18:28:55 -0800 | [diff] [blame] | 68 | get_imsi_retry_delay_milliseconds_(kGetIMSIRetryDelayMilliseconds) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 69 | SLOG(this, 2) << "Cellular capability constructed: GSM"; |
Prathmesh Prabhu | afe6366 | 2014-05-20 11:03:58 -0700 | [diff] [blame] | 70 | mobile_operator_info_->Init(); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 71 | HelpRegisterConstDerivedKeyValueStore( |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 72 | kSIMLockStatusProperty, &CellularCapabilityGSM::SimLockStatusToProperty); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 73 | this->cellular()->set_scanning_supported(true); |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 74 | |
| 75 | // TODO(benchan): This is a hack to initialize the GSM card proxy for GetIMSI |
| 76 | // before InitProxies is called. There are side-effects of calling InitProxies |
| 77 | // before the device is enabled. It's better to refactor InitProxies such that |
| 78 | // proxies can be created when the cellular device/capability is constructed, |
| 79 | // but callbacks for DBus signal updates are not set up until the device is |
| 80 | // enabled. |
| 81 | card_proxy_.reset( |
| 82 | proxy_factory->CreateModemGSMCardProxy(cellular->dbus_path(), |
| 83 | cellular->dbus_owner())); |
| 84 | // TODO(benchan): To allow unit testing using a mock proxy without further |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 85 | // complicating the code, the test proxy factory is set up to return a nullptr |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 86 | // pointer when CellularCapabilityGSM is constructed. Refactor the code to |
| 87 | // avoid this hack. |
| 88 | if (card_proxy_.get()) |
| 89 | InitProperties(); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 90 | } |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 91 | |
Ben Chan | f98f00e | 2014-02-05 14:48:43 -0800 | [diff] [blame] | 92 | CellularCapabilityGSM::~CellularCapabilityGSM() {} |
| 93 | |
| 94 | string CellularCapabilityGSM::GetTypeString() const { |
| 95 | return kTechnologyFamilyGsm; |
| 96 | } |
| 97 | |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 98 | KeyValueStore CellularCapabilityGSM::SimLockStatusToProperty(Error */*error*/) { |
| 99 | KeyValueStore status; |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 100 | status.SetBool(kSIMLockEnabledProperty, sim_lock_status_.enabled); |
| 101 | status.SetString(kSIMLockTypeProperty, sim_lock_status_.lock_type); |
| 102 | status.SetUint(kSIMLockRetriesLeftProperty, sim_lock_status_.retries_left); |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 103 | return status; |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 104 | } |
| 105 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 106 | void CellularCapabilityGSM::HelpRegisterConstDerivedKeyValueStore( |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 107 | const string &name, |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 108 | KeyValueStore(CellularCapabilityGSM::*get)(Error *error)) { |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 109 | cellular()->mutable_store()->RegisterDerivedKeyValueStore( |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 110 | name, |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 111 | KeyValueStoreAccessor( |
| 112 | new CustomAccessor<CellularCapabilityGSM, KeyValueStore>( |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 113 | this, get, nullptr))); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 114 | } |
| 115 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 116 | void CellularCapabilityGSM::InitProxies() { |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 117 | CellularCapabilityClassic::InitProxies(); |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 118 | // TODO(benchan): Remove this check after refactoring the proxy |
| 119 | // initialization. |
| 120 | if (!card_proxy_.get()) { |
| 121 | card_proxy_.reset( |
| 122 | proxy_factory()->CreateModemGSMCardProxy(cellular()->dbus_path(), |
| 123 | cellular()->dbus_owner())); |
| 124 | } |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 125 | network_proxy_.reset( |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 126 | proxy_factory()->CreateModemGSMNetworkProxy(cellular()->dbus_path(), |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 127 | cellular()->dbus_owner())); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 128 | network_proxy_->set_signal_quality_callback( |
| 129 | Bind(&CellularCapabilityGSM::OnSignalQualitySignal, |
| 130 | weak_ptr_factory_.GetWeakPtr())); |
| 131 | network_proxy_->set_network_mode_callback( |
| 132 | Bind(&CellularCapabilityGSM::OnNetworkModeSignal, |
| 133 | weak_ptr_factory_.GetWeakPtr())); |
| 134 | network_proxy_->set_registration_info_callback( |
| 135 | Bind(&CellularCapabilityGSM::OnRegistrationInfoSignal, |
| 136 | weak_ptr_factory_.GetWeakPtr())); |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 137 | } |
| 138 | |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 139 | void CellularCapabilityGSM::InitProperties() { |
| 140 | CellularTaskList *tasks = new CellularTaskList(); |
| 141 | ResultCallback cb_ignore_error = |
| 142 | Bind(&CellularCapabilityGSM::StepCompletedCallback, |
| 143 | weak_ptr_factory_.GetWeakPtr(), ResultCallback(), true, tasks); |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 144 | // Chrome checks if a SIM is present before allowing the modem to be enabled, |
| 145 | // so shill needs to obtain IMSI, as an indicator of SIM presence, even |
| 146 | // before the device is enabled. |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 147 | tasks->push_back(Bind(&CellularCapabilityGSM::GetIMSI, |
| 148 | weak_ptr_factory_.GetWeakPtr(), cb_ignore_error)); |
| 149 | RunNextStep(tasks); |
| 150 | } |
| 151 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 152 | void CellularCapabilityGSM::StartModem(Error *error, |
| 153 | const ResultCallback &callback) { |
| 154 | InitProxies(); |
| 155 | |
| 156 | CellularTaskList *tasks = new CellularTaskList(); |
| 157 | ResultCallback cb = |
| 158 | Bind(&CellularCapabilityGSM::StepCompletedCallback, |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 159 | weak_ptr_factory_.GetWeakPtr(), callback, false, tasks); |
| 160 | ResultCallback cb_ignore_error = |
| 161 | Bind(&CellularCapabilityGSM::StepCompletedCallback, |
| 162 | weak_ptr_factory_.GetWeakPtr(), callback, true, tasks); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 163 | if (!cellular()->IsUnderlyingDeviceEnabled()) |
| 164 | tasks->push_back(Bind(&CellularCapabilityGSM::EnableModem, |
| 165 | weak_ptr_factory_.GetWeakPtr(), cb)); |
| 166 | // If we're within range of the home network, the modem will try to |
| 167 | // register once it's enabled, or may be already registered if we |
| 168 | // started out enabled. |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 169 | if (!IsUnderlyingDeviceRegistered() && |
| 170 | !cellular()->selected_network().empty()) |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 171 | tasks->push_back(Bind(&CellularCapabilityGSM::Register, |
| 172 | weak_ptr_factory_.GetWeakPtr(), cb)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 173 | tasks->push_back(Bind(&CellularCapabilityGSM::GetIMEI, |
| 174 | weak_ptr_factory_.GetWeakPtr(), cb)); |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 175 | get_imsi_retries_ = 0; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 176 | tasks->push_back(Bind(&CellularCapabilityGSM::GetIMSI, |
| 177 | weak_ptr_factory_.GetWeakPtr(), cb)); |
| 178 | tasks->push_back(Bind(&CellularCapabilityGSM::GetSPN, |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 179 | weak_ptr_factory_.GetWeakPtr(), cb_ignore_error)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 180 | tasks->push_back(Bind(&CellularCapabilityGSM::GetMSISDN, |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 181 | weak_ptr_factory_.GetWeakPtr(), cb_ignore_error)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 182 | tasks->push_back(Bind(&CellularCapabilityGSM::GetProperties, |
| 183 | weak_ptr_factory_.GetWeakPtr(), cb)); |
| 184 | tasks->push_back(Bind(&CellularCapabilityGSM::GetModemInfo, |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 185 | weak_ptr_factory_.GetWeakPtr(), cb_ignore_error)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 186 | tasks->push_back(Bind(&CellularCapabilityGSM::FinishEnable, |
| 187 | weak_ptr_factory_.GetWeakPtr(), cb)); |
| 188 | |
| 189 | RunNextStep(tasks); |
| 190 | } |
| 191 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 192 | bool CellularCapabilityGSM::IsUnderlyingDeviceRegistered() const { |
| 193 | switch (cellular()->modem_state()) { |
Ben Chan | 7b7d63d | 2013-10-18 14:53:05 -0700 | [diff] [blame] | 194 | case Cellular::kModemStateFailed: |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 195 | case Cellular::kModemStateUnknown: |
| 196 | case Cellular::kModemStateDisabled: |
| 197 | case Cellular::kModemStateInitializing: |
| 198 | case Cellular::kModemStateLocked: |
| 199 | case Cellular::kModemStateDisabling: |
| 200 | case Cellular::kModemStateEnabling: |
| 201 | case Cellular::kModemStateEnabled: |
| 202 | return false; |
| 203 | case Cellular::kModemStateSearching: |
| 204 | case Cellular::kModemStateRegistered: |
| 205 | case Cellular::kModemStateDisconnecting: |
| 206 | case Cellular::kModemStateConnecting: |
| 207 | case Cellular::kModemStateConnected: |
| 208 | return true; |
| 209 | } |
| 210 | return false; |
| 211 | } |
| 212 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 213 | void CellularCapabilityGSM::ReleaseProxies() { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 214 | SLOG(this, 2) << __func__; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 215 | CellularCapabilityClassic::ReleaseProxies(); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 216 | card_proxy_.reset(); |
| 217 | network_proxy_.reset(); |
| 218 | } |
| 219 | |
Thieu Le | 63881a7 | 2014-07-28 17:28:36 -0700 | [diff] [blame] | 220 | bool CellularCapabilityGSM::AreProxiesInitialized() const { |
| 221 | return (CellularCapabilityClassic::AreProxiesInitialized() && |
| 222 | card_proxy_.get() && network_proxy_.get()); |
| 223 | } |
| 224 | |
Darin Petkov | 5f316f6 | 2011-11-18 12:10:26 +0100 | [diff] [blame] | 225 | void CellularCapabilityGSM::OnServiceCreated() { |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 226 | cellular()->service()->SetActivationState(kActivationStateActivated); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 227 | } |
| 228 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 229 | // Create the list of APNs to try, in the following order: |
| 230 | // - last APN that resulted in a successful connection attempt on the |
| 231 | // current network (if any) |
| 232 | // - the APN, if any, that was set by the user |
| 233 | // - the list of APNs found in the mobile broadband provider DB for the |
| 234 | // home provider associated with the current SIM |
| 235 | // - as a last resort, attempt to connect with no APN |
| 236 | void CellularCapabilityGSM::SetupApnTryList() { |
| 237 | apn_try_list_.clear(); |
| 238 | |
| 239 | DCHECK(cellular()->service().get()); |
| 240 | const Stringmap *apn_info = cellular()->service()->GetLastGoodApn(); |
| 241 | if (apn_info) |
| 242 | apn_try_list_.push_back(*apn_info); |
| 243 | |
| 244 | apn_info = cellular()->service()->GetUserSpecifiedApn(); |
| 245 | if (apn_info) |
| 246 | apn_try_list_.push_back(*apn_info); |
| 247 | |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 248 | apn_try_list_.insert(apn_try_list_.end(), |
| 249 | cellular()->apn_list().begin(), |
| 250 | cellular()->apn_list().end()); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 251 | } |
| 252 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 253 | void CellularCapabilityGSM::SetupConnectProperties( |
| 254 | DBusPropertiesMap *properties) { |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 255 | SetupApnTryList(); |
| 256 | FillConnectPropertyMap(properties); |
| 257 | } |
| 258 | |
| 259 | void CellularCapabilityGSM::FillConnectPropertyMap( |
| 260 | DBusPropertiesMap *properties) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 261 | (*properties)[kConnectPropertyPhoneNumber].writer().append_string( |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 262 | kPhoneNumber); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 263 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 264 | if (!AllowRoaming()) |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 265 | (*properties)[kConnectPropertyHomeOnly].writer().append_bool(true); |
| 266 | |
| 267 | if (!apn_try_list_.empty()) { |
| 268 | // Leave the APN at the front of the list, so that it can be recorded |
| 269 | // if the connect attempt succeeds. |
| 270 | Stringmap apn_info = apn_try_list_.front(); |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 271 | SLOG(this, 2) << __func__ << ": Using APN " << apn_info[kApnProperty]; |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 272 | (*properties)[kConnectPropertyApn].writer().append_string( |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 273 | apn_info[kApnProperty].c_str()); |
| 274 | if (ContainsKey(apn_info, kApnUsernameProperty)) |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 275 | (*properties)[kConnectPropertyApnUsername].writer().append_string( |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 276 | apn_info[kApnUsernameProperty].c_str()); |
| 277 | if (ContainsKey(apn_info, kApnPasswordProperty)) |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 278 | (*properties)[kConnectPropertyApnPassword].writer().append_string( |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 279 | apn_info[kApnPasswordProperty].c_str()); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 283 | void CellularCapabilityGSM::Connect(const DBusPropertiesMap &properties, |
| 284 | Error *error, |
| 285 | const ResultCallback &callback) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 286 | SLOG(this, 2) << __func__; |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 287 | ResultCallback cb = Bind(&CellularCapabilityGSM::OnConnectReply, |
| 288 | weak_ptr_factory_.GetWeakPtr(), |
| 289 | callback); |
| 290 | simple_proxy_->Connect(properties, error, cb, kTimeoutConnect); |
| 291 | } |
| 292 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 293 | void CellularCapabilityGSM::OnConnectReply(const ResultCallback &callback, |
| 294 | const Error &error) { |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 295 | CellularServiceRefPtr service = cellular()->service(); |
| 296 | if (!service) { |
| 297 | // The service could have been deleted before our Connect() request |
| 298 | // completes if the modem was enabled and then quickly disabled. |
| 299 | apn_try_list_.clear(); |
| 300 | } else if (error.IsFailure()) { |
| 301 | service->ClearLastGoodApn(); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 302 | // The APN that was just tried (and failed) is still at the |
| 303 | // front of the list, about to be removed. If the list is empty |
| 304 | // after that, try one last time without an APN. This may succeed |
| 305 | // with some modems in some cases. |
| 306 | if (error.type() == Error::kInvalidApn && !apn_try_list_.empty()) { |
| 307 | apn_try_list_.pop_front(); |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 308 | SLOG(this, 2) << "Connect failed with invalid APN, " |
| 309 | << apn_try_list_.size() << " remaining APNs to try"; |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 310 | DBusPropertiesMap props; |
| 311 | FillConnectPropertyMap(&props); |
| 312 | Error error; |
| 313 | Connect(props, &error, callback); |
| 314 | return; |
| 315 | } |
| 316 | } else if (!apn_try_list_.empty()) { |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 317 | service->SetLastGoodApn(apn_try_list_.front()); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 318 | apn_try_list_.clear(); |
| 319 | } |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 320 | if (!callback.is_null()) |
| 321 | callback.Run(error); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | bool CellularCapabilityGSM::AllowRoaming() { |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 325 | return cellular()->provider_requires_roaming() || allow_roaming_property(); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 326 | } |
| 327 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 328 | // always called from an async context |
| 329 | void CellularCapabilityGSM::GetIMEI(const ResultCallback &callback) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 330 | SLOG(this, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 331 | CHECK(!callback.is_null()); |
| 332 | Error error; |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 333 | if (cellular()->imei().empty()) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 334 | GSMIdentifierCallback cb = Bind(&CellularCapabilityGSM::OnGetIMEIReply, |
| 335 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 336 | card_proxy_->GetIMEI(&error, cb, kTimeoutDefault); |
| 337 | if (error.IsFailure()) |
| 338 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 339 | } else { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 340 | SLOG(this, 2) << "Already have IMEI " << cellular()->imei(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 341 | callback.Run(error); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 342 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 343 | } |
| 344 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 345 | // always called from an async context |
| 346 | void CellularCapabilityGSM::GetIMSI(const ResultCallback &callback) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 347 | SLOG(this, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 348 | CHECK(!callback.is_null()); |
| 349 | Error error; |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 350 | if (cellular()->imsi().empty()) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 351 | GSMIdentifierCallback cb = Bind(&CellularCapabilityGSM::OnGetIMSIReply, |
| 352 | weak_ptr_factory_.GetWeakPtr(), |
| 353 | callback); |
| 354 | card_proxy_->GetIMSI(&error, cb, kTimeoutDefault); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 355 | if (error.IsFailure()) { |
Prathmesh Prabhu | 8599e05 | 2014-04-25 14:20:22 -0700 | [diff] [blame] | 356 | cellular()->home_provider_info()->Reset(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 357 | callback.Run(error); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 358 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 359 | } else { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 360 | SLOG(this, 2) << "Already have IMSI " << cellular()->imsi(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 361 | callback.Run(error); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 362 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 363 | } |
| 364 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 365 | // always called from an async context |
| 366 | void CellularCapabilityGSM::GetSPN(const ResultCallback &callback) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 367 | SLOG(this, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 368 | CHECK(!callback.is_null()); |
| 369 | Error error; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 370 | if (spn_.empty()) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 371 | GSMIdentifierCallback cb = Bind(&CellularCapabilityGSM::OnGetSPNReply, |
| 372 | weak_ptr_factory_.GetWeakPtr(), |
| 373 | callback); |
| 374 | card_proxy_->GetSPN(&error, cb, kTimeoutDefault); |
| 375 | if (error.IsFailure()) |
| 376 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 377 | } else { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 378 | SLOG(this, 2) << "Already have SPN " << spn_; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 379 | callback.Run(error); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 380 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 381 | } |
| 382 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 383 | // always called from an async context |
| 384 | void CellularCapabilityGSM::GetMSISDN(const ResultCallback &callback) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 385 | SLOG(this, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 386 | CHECK(!callback.is_null()); |
| 387 | Error error; |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 388 | string mdn = cellular()->mdn(); |
| 389 | if (mdn.empty()) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 390 | GSMIdentifierCallback cb = Bind(&CellularCapabilityGSM::OnGetMSISDNReply, |
| 391 | weak_ptr_factory_.GetWeakPtr(), |
| 392 | callback); |
| 393 | card_proxy_->GetMSISDN(&error, cb, kTimeoutDefault); |
| 394 | if (error.IsFailure()) |
| 395 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 396 | } else { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 397 | SLOG(this, 2) << "Already have MSISDN " << mdn; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 398 | callback.Run(error); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 402 | void CellularCapabilityGSM::GetSignalQuality() { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 403 | SLOG(this, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 404 | SignalQualityCallback callback = |
| 405 | Bind(&CellularCapabilityGSM::OnGetSignalQualityReply, |
| 406 | weak_ptr_factory_.GetWeakPtr()); |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 407 | network_proxy_->GetSignalQuality(nullptr, callback, kTimeoutDefault); |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 408 | } |
| 409 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 410 | void CellularCapabilityGSM::GetRegistrationState() { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 411 | SLOG(this, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 412 | RegistrationInfoCallback callback = |
| 413 | Bind(&CellularCapabilityGSM::OnGetRegistrationInfoReply, |
| 414 | weak_ptr_factory_.GetWeakPtr()); |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 415 | network_proxy_->GetRegistrationInfo(nullptr, callback, kTimeoutDefault); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 416 | } |
| 417 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 418 | void CellularCapabilityGSM::GetProperties(const ResultCallback &callback) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 419 | SLOG(this, 2) << __func__; |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 420 | |
Paul Stewart | ee6b3d7 | 2013-07-12 16:07:51 -0700 | [diff] [blame] | 421 | // TODO(petkov): Switch to asynchronous calls (crbug.com/200687). |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 422 | uint32_t tech = network_proxy_->AccessTechnology(); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 423 | SetAccessTechnology(tech); |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 424 | SLOG(this, 2) << "GSM AccessTechnology: " << tech; |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 425 | |
Paul Stewart | ee6b3d7 | 2013-07-12 16:07:51 -0700 | [diff] [blame] | 426 | // TODO(petkov): Switch to asynchronous calls (crbug.com/200687). |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 427 | uint32_t locks = card_proxy_->EnabledFacilityLocks(); |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 428 | sim_lock_status_.enabled = locks & MM_MODEM_GSM_FACILITY_SIM; |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 429 | SLOG(this, 2) << "GSM EnabledFacilityLocks: " << locks; |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 430 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 431 | callback.Run(Error()); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 432 | } |
| 433 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 434 | // always called from an async context |
| 435 | void CellularCapabilityGSM::Register(const ResultCallback &callback) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 436 | SLOG(this, 2) << __func__ << " \"" << cellular()->selected_network() |
| 437 | << "\""; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 438 | CHECK(!callback.is_null()); |
| 439 | Error error; |
| 440 | ResultCallback cb = Bind(&CellularCapabilityGSM::OnRegisterReply, |
| 441 | weak_ptr_factory_.GetWeakPtr(), callback); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 442 | network_proxy_->Register(cellular()->selected_network(), &error, cb, |
| 443 | kTimeoutRegister); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 444 | if (error.IsFailure()) |
| 445 | callback.Run(error); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | void CellularCapabilityGSM::RegisterOnNetwork( |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 449 | const string &network_id, |
| 450 | Error *error, |
| 451 | const ResultCallback &callback) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 452 | SLOG(this, 2) << __func__ << "(" << network_id << ")"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 453 | CHECK(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 454 | desired_network_ = network_id; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 455 | ResultCallback cb = Bind(&CellularCapabilityGSM::OnRegisterReply, |
| 456 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 457 | network_proxy_->Register(network_id, error, cb, kTimeoutRegister); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 458 | } |
| 459 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 460 | void CellularCapabilityGSM::OnRegisterReply(const ResultCallback &callback, |
| 461 | const Error &error) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 462 | SLOG(this, 2) << __func__ << "(" << error << ")"; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 463 | |
| 464 | if (error.IsSuccess()) { |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 465 | cellular()->set_selected_network(desired_network_); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 466 | desired_network_.clear(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 467 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 468 | return; |
| 469 | } |
| 470 | // If registration on the desired network failed, |
| 471 | // try to register on the home network. |
| 472 | if (!desired_network_.empty()) { |
| 473 | desired_network_.clear(); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 474 | cellular()->set_selected_network(""); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 475 | LOG(INFO) << "Couldn't register on selected network, trying home network"; |
| 476 | Register(callback); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 477 | return; |
| 478 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 479 | callback.Run(error); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 480 | } |
| 481 | |
Ben Chan | 31ce564 | 2013-11-14 13:37:40 -0800 | [diff] [blame] | 482 | bool CellularCapabilityGSM::IsRegistered() const { |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 483 | return (registration_state_ == MM_MODEM_GSM_NETWORK_REG_STATUS_HOME || |
| 484 | registration_state_ == MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING); |
| 485 | } |
| 486 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 487 | void CellularCapabilityGSM::SetUnregistered(bool searching) { |
| 488 | // If we're already in some non-registered state, don't override that |
| 489 | if (registration_state_ == MM_MODEM_GSM_NETWORK_REG_STATUS_HOME || |
| 490 | registration_state_ == MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING) { |
| 491 | registration_state_ = |
| 492 | (searching ? MM_MODEM_GSM_NETWORK_REG_STATUS_SEARCHING : |
| 493 | MM_MODEM_GSM_NETWORK_REG_STATUS_IDLE); |
| 494 | } |
| 495 | } |
| 496 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 497 | void CellularCapabilityGSM::RequirePIN( |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 498 | const std::string &pin, bool require, |
| 499 | Error *error, const ResultCallback &callback) { |
| 500 | CHECK(error); |
| 501 | card_proxy_->EnablePIN(pin, require, error, callback, kTimeoutDefault); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 502 | } |
| 503 | |
Darin Petkov | e5bc2cb | 2011-12-07 14:47:32 +0100 | [diff] [blame] | 504 | void CellularCapabilityGSM::EnterPIN(const string &pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 505 | Error *error, |
| 506 | const ResultCallback &callback) { |
| 507 | CHECK(error); |
| 508 | card_proxy_->SendPIN(pin, error, callback, kTimeoutDefault); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 509 | } |
| 510 | |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 511 | void CellularCapabilityGSM::UnblockPIN(const string &unblock_code, |
| 512 | const string &pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 513 | Error *error, |
| 514 | const ResultCallback &callback) { |
| 515 | CHECK(error); |
| 516 | card_proxy_->SendPUK(unblock_code, pin, error, callback, kTimeoutDefault); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | void CellularCapabilityGSM::ChangePIN( |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 520 | const string &old_pin, const string &new_pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 521 | Error *error, const ResultCallback &callback) { |
| 522 | CHECK(error); |
| 523 | card_proxy_->ChangePIN(old_pin, new_pin, error, callback, kTimeoutDefault); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 524 | } |
| 525 | |
Prathmesh Prabhu | 49ffffd | 2014-01-09 18:28:55 -0800 | [diff] [blame] | 526 | void CellularCapabilityGSM::Scan(Error *error, |
| 527 | const ResultStringmapsCallback &callback) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 528 | ScanResultsCallback cb = Bind(&CellularCapabilityGSM::OnScanReply, |
| 529 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 530 | network_proxy_->Scan(error, cb, kTimeoutScan); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 531 | } |
| 532 | |
Prathmesh Prabhu | 49ffffd | 2014-01-09 18:28:55 -0800 | [diff] [blame] | 533 | void CellularCapabilityGSM::OnScanReply( |
| 534 | const ResultStringmapsCallback &callback, |
| 535 | const GSMScanResults &results, |
| 536 | const Error &error) { |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 537 | Stringmaps found_networks; |
Prathmesh Prabhu | 49ffffd | 2014-01-09 18:28:55 -0800 | [diff] [blame] | 538 | for (const auto &result : results) |
| 539 | found_networks.push_back(ParseScanResult(result)); |
| 540 | callback.Run(found_networks, error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | Stringmap CellularCapabilityGSM::ParseScanResult(const GSMScanResult &result) { |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 544 | Stringmap parsed; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 545 | for (GSMScanResult::const_iterator it = result.begin(); |
| 546 | it != result.end(); ++it) { |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 547 | // TODO(petkov): Define these in system_api/service_constants.h. The |
| 548 | // numerical values are taken from 3GPP TS 27.007 Section 7.3. |
| 549 | static const char * const kStatusString[] = { |
| 550 | "unknown", |
| 551 | "available", |
| 552 | "current", |
| 553 | "forbidden", |
| 554 | }; |
| 555 | static const char * const kTechnologyString[] = { |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 556 | kNetworkTechnologyGsm, |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 557 | "GSM Compact", |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 558 | kNetworkTechnologyUmts, |
| 559 | kNetworkTechnologyEdge, |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 560 | "HSDPA", |
| 561 | "HSUPA", |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 562 | kNetworkTechnologyHspa, |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 563 | }; |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 564 | SLOG(this, 2) << "Network property: " << it->first << " = " |
| 565 | << it->second; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 566 | if (it->first == kNetworkPropertyStatus) { |
| 567 | int status = 0; |
| 568 | if (base::StringToInt(it->second, &status) && |
| 569 | status >= 0 && |
| 570 | status < static_cast<int>(arraysize(kStatusString))) { |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 571 | parsed[kStatusProperty] = kStatusString[status]; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 572 | } else { |
| 573 | LOG(ERROR) << "Unexpected status value: " << it->second; |
| 574 | } |
| 575 | } else if (it->first == kNetworkPropertyID) { |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 576 | parsed[kNetworkIdProperty] = it->second; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 577 | } else if (it->first == kNetworkPropertyLongName) { |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 578 | parsed[kLongNameProperty] = it->second; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 579 | } else if (it->first == kNetworkPropertyShortName) { |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 580 | parsed[kShortNameProperty] = it->second; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 581 | } else if (it->first == kNetworkPropertyAccessTechnology) { |
| 582 | int tech = 0; |
| 583 | if (base::StringToInt(it->second, &tech) && |
| 584 | tech >= 0 && |
| 585 | tech < static_cast<int>(arraysize(kTechnologyString))) { |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 586 | parsed[kTechnologyProperty] = kTechnologyString[tech]; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 587 | } else { |
| 588 | LOG(ERROR) << "Unexpected technology value: " << it->second; |
| 589 | } |
| 590 | } else { |
| 591 | LOG(WARNING) << "Unknown network property ignored: " << it->first; |
| 592 | } |
| 593 | } |
| 594 | // If the long name is not available but the network ID is, look up the long |
| 595 | // name in the mobile provider database. |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 596 | if ((!ContainsKey(parsed, kLongNameProperty) || |
| 597 | parsed[kLongNameProperty].empty()) && |
| 598 | ContainsKey(parsed, kNetworkIdProperty)) { |
Prathmesh Prabhu | afe6366 | 2014-05-20 11:03:58 -0700 | [diff] [blame] | 599 | mobile_operator_info_->Reset(); |
| 600 | mobile_operator_info_->UpdateMCCMNC(parsed[kNetworkIdProperty]); |
| 601 | if (mobile_operator_info_->IsMobileNetworkOperatorKnown() && |
| 602 | !mobile_operator_info_->operator_name().empty()) { |
| 603 | parsed[kLongNameProperty] = mobile_operator_info_->operator_name(); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 604 | } |
| 605 | } |
| 606 | return parsed; |
| 607 | } |
| 608 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 609 | void CellularCapabilityGSM::SetAccessTechnology(uint32_t access_technology) { |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 610 | access_technology_ = access_technology; |
| 611 | if (cellular()->service().get()) { |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 612 | cellular()->service()->SetNetworkTechnology(GetNetworkTechnologyString()); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 613 | } |
| 614 | } |
| 615 | |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 616 | string CellularCapabilityGSM::GetNetworkTechnologyString() const { |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 617 | switch (access_technology_) { |
| 618 | case MM_MODEM_GSM_ACCESS_TECH_GSM: |
| 619 | case MM_MODEM_GSM_ACCESS_TECH_GSM_COMPACT: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 620 | return kNetworkTechnologyGsm; |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 621 | case MM_MODEM_GSM_ACCESS_TECH_GPRS: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 622 | return kNetworkTechnologyGprs; |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 623 | case MM_MODEM_GSM_ACCESS_TECH_EDGE: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 624 | return kNetworkTechnologyEdge; |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 625 | case MM_MODEM_GSM_ACCESS_TECH_UMTS: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 626 | return kNetworkTechnologyUmts; |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 627 | case MM_MODEM_GSM_ACCESS_TECH_HSDPA: |
| 628 | case MM_MODEM_GSM_ACCESS_TECH_HSUPA: |
| 629 | case MM_MODEM_GSM_ACCESS_TECH_HSPA: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 630 | return kNetworkTechnologyHspa; |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 631 | case MM_MODEM_GSM_ACCESS_TECH_HSPA_PLUS: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 632 | return kNetworkTechnologyHspaPlus; |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 633 | default: |
| 634 | break; |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 635 | } |
| 636 | return ""; |
| 637 | } |
| 638 | |
| 639 | string CellularCapabilityGSM::GetRoamingStateString() const { |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 640 | switch (registration_state_) { |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 641 | case MM_MODEM_GSM_NETWORK_REG_STATUS_HOME: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 642 | return kRoamingStateHome; |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 643 | case MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 644 | return kRoamingStateRoaming; |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 645 | default: |
| 646 | break; |
| 647 | } |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 648 | return kRoamingStateUnknown; |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 649 | } |
| 650 | |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 651 | void CellularCapabilityGSM::OnDBusPropertiesChanged( |
| 652 | const string &interface, |
| 653 | const DBusPropertiesMap &properties, |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 654 | const vector<string> &invalidated_properties) { |
| 655 | CellularCapabilityClassic::OnDBusPropertiesChanged(interface, |
| 656 | properties, |
| 657 | invalidated_properties); |
| 658 | if (interface == MM_MODEM_GSM_NETWORK_INTERFACE) { |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 659 | uint32_t access_technology = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 660 | if (DBusProperties::GetUint32(properties, |
| 661 | kPropertyAccessTechnology, |
| 662 | &access_technology)) { |
| 663 | SetAccessTechnology(access_technology); |
| 664 | } |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 665 | } else { |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 666 | bool emit = false; |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 667 | if (interface == MM_MODEM_GSM_CARD_INTERFACE) { |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 668 | uint32_t locks = 0; |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 669 | if (DBusProperties::GetUint32( |
| 670 | properties, kPropertyEnabledFacilityLocks, &locks)) { |
| 671 | sim_lock_status_.enabled = locks & MM_MODEM_GSM_FACILITY_SIM; |
| 672 | emit = true; |
| 673 | } |
| 674 | } else if (interface == MM_MODEM_INTERFACE) { |
| 675 | if (DBusProperties::GetString(properties, kPropertyUnlockRequired, |
| 676 | &sim_lock_status_.lock_type)) { |
| 677 | emit = true; |
| 678 | } |
| 679 | if (DBusProperties::GetUint32(properties, kPropertyUnlockRetries, |
| 680 | &sim_lock_status_.retries_left)) { |
| 681 | emit = true; |
| 682 | } |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 683 | } |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 684 | // TODO(pprabhu) Rename |emit| to |sim_present| after |sim_lock_status| |
| 685 | // moves to cellular. |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 686 | if (emit) { |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 687 | cellular()->set_sim_present(true); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 688 | cellular()->adaptor()->EmitKeyValueStoreChanged( |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 689 | kSIMLockStatusProperty, SimLockStatusToProperty(nullptr)); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 690 | } |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 691 | } |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 692 | } |
| 693 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 694 | void CellularCapabilityGSM::OnNetworkModeSignal(uint32_t /*mode*/) { |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 695 | // TODO(petkov): Implement this. |
| 696 | NOTIMPLEMENTED(); |
| 697 | } |
| 698 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 699 | void CellularCapabilityGSM::OnRegistrationInfoSignal( |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 700 | uint32_t status, const string &operator_code, const string &operator_name) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 701 | SLOG(this, 2) << __func__ << ": regstate=" << status |
| 702 | << ", opercode=" << operator_code |
| 703 | << ", opername=" << operator_name; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 704 | registration_state_ = status; |
Prathmesh Prabhu | 8599e05 | 2014-04-25 14:20:22 -0700 | [diff] [blame] | 705 | cellular()->serving_operator_info()->UpdateMCCMNC(operator_code); |
| 706 | cellular()->serving_operator_info()->UpdateOperatorName(operator_name); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 707 | cellular()->HandleNewRegistrationState(); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 708 | } |
| 709 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 710 | void CellularCapabilityGSM::OnSignalQualitySignal(uint32_t quality) { |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 711 | cellular()->HandleNewSignalQuality(quality); |
| 712 | } |
| 713 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 714 | void CellularCapabilityGSM::OnGetRegistrationInfoReply( |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 715 | uint32_t status, const string &operator_code, const string &operator_name, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 716 | const Error &error) { |
| 717 | if (error.IsSuccess()) |
| 718 | OnRegistrationInfoSignal(status, operator_code, operator_name); |
| 719 | } |
| 720 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 721 | void CellularCapabilityGSM::OnGetSignalQualityReply(uint32_t quality, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 722 | const Error &error) { |
| 723 | if (error.IsSuccess()) |
| 724 | OnSignalQualitySignal(quality); |
| 725 | } |
| 726 | |
| 727 | void CellularCapabilityGSM::OnGetIMEIReply(const ResultCallback &callback, |
| 728 | const string &imei, |
| 729 | const Error &error) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 730 | if (error.IsSuccess()) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 731 | SLOG(this, 2) << "IMEI: " << imei; |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 732 | cellular()->set_imei(imei); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 733 | } else { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 734 | SLOG(this, 2) << "GetIMEI failed - " << error; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 735 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 736 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 737 | } |
| 738 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 739 | void CellularCapabilityGSM::OnGetIMSIReply(const ResultCallback &callback, |
| 740 | const string &imsi, |
| 741 | const Error &error) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 742 | if (error.IsSuccess()) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 743 | SLOG(this, 2) << "IMSI: " << imsi; |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 744 | cellular()->set_imsi(imsi); |
| 745 | cellular()->set_sim_present(true); |
Prathmesh Prabhu | 8599e05 | 2014-04-25 14:20:22 -0700 | [diff] [blame] | 746 | cellular()->home_provider_info()->UpdateIMSI(imsi); |
Prathmesh Prabhu | c93b6bc | 2014-07-28 15:20:11 -0700 | [diff] [blame] | 747 | // We do not currently obtain the IMSI OTA at all. Provide the IMSI from the |
| 748 | // SIM to the serving operator as well to aid in MVNO identification. |
| 749 | cellular()->serving_operator_info()->UpdateIMSI(imsi); |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 750 | callback.Run(error); |
Arman Uguray | 29505ec | 2013-09-12 20:37:53 -0700 | [diff] [blame] | 751 | } else if (!sim_lock_status_.lock_type.empty()) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 752 | SLOG(this, 2) << "GetIMSI failed - SIM lock in place."; |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 753 | cellular()->set_sim_present(true); |
Arman Uguray | 29505ec | 2013-09-12 20:37:53 -0700 | [diff] [blame] | 754 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 755 | } else { |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 756 | cellular()->set_sim_present(false); |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 757 | if (get_imsi_retries_++ < kGetIMSIRetryLimit) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 758 | SLOG(this, 2) << "GetIMSI failed - " << error << ". Retrying"; |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 759 | base::Callback<void(void)> retry_get_imsi_cb = |
| 760 | Bind(&CellularCapabilityGSM::GetIMSI, |
| 761 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 762 | cellular()->dispatcher()->PostDelayedTask( |
| 763 | retry_get_imsi_cb, |
| 764 | get_imsi_retry_delay_milliseconds_); |
| 765 | } else { |
| 766 | LOG(INFO) << "GetIMSI failed - " << error; |
Prathmesh Prabhu | 8599e05 | 2014-04-25 14:20:22 -0700 | [diff] [blame] | 767 | cellular()->home_provider_info()->Reset(); |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 768 | callback.Run(error); |
| 769 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 770 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 771 | } |
| 772 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 773 | void CellularCapabilityGSM::OnGetSPNReply(const ResultCallback &callback, |
| 774 | const string &spn, |
| 775 | const Error &error) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 776 | if (error.IsSuccess()) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 777 | SLOG(this, 2) << "SPN: " << spn; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 778 | spn_ = spn; |
Prathmesh Prabhu | 8599e05 | 2014-04-25 14:20:22 -0700 | [diff] [blame] | 779 | cellular()->home_provider_info()->UpdateOperatorName(spn); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 780 | } else { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 781 | SLOG(this, 2) << "GetSPN failed - " << error; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 782 | } |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 783 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 784 | } |
| 785 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 786 | void CellularCapabilityGSM::OnGetMSISDNReply(const ResultCallback &callback, |
| 787 | const string &msisdn, |
| 788 | const Error &error) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 789 | if (error.IsSuccess()) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 790 | SLOG(this, 2) << "MSISDN: " << msisdn; |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 791 | cellular()->set_mdn(msisdn); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 792 | } else { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 793 | SLOG(this, 2) << "GetMSISDN failed - " << error; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 794 | } |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 795 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 796 | } |
| 797 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 798 | } // namespace shill |