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 | #include "shill/cellular_capability_gsm.h" |
| 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> |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 12 | #include <base/string_number_conversions.h> |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 13 | #include <base/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 | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 16 | #include <mobile_provider.h> |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 17 | |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 18 | #include "shill/adaptor_interfaces.h" |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 19 | #include "shill/cellular_service.h" |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 20 | #include "shill/error.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 21 | #include "shill/logging.h" |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 22 | #include "shill/property_accessor.h" |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 23 | #include "shill/proxy_factory.h" |
| 24 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 25 | using base::Bind; |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 26 | using std::string; |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 27 | using std::vector; |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 28 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 29 | namespace shill { |
| 30 | |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 31 | // static |
| 32 | unsigned int CellularCapabilityGSM::friendly_service_name_id_ = 0; |
| 33 | |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 34 | const char CellularCapabilityGSM::kNetworkPropertyAccessTechnology[] = |
| 35 | "access-tech"; |
| 36 | const char CellularCapabilityGSM::kNetworkPropertyID[] = "operator-num"; |
| 37 | const char CellularCapabilityGSM::kNetworkPropertyLongName[] = "operator-long"; |
| 38 | const char CellularCapabilityGSM::kNetworkPropertyShortName[] = |
| 39 | "operator-short"; |
| 40 | const char CellularCapabilityGSM::kNetworkPropertyStatus[] = "status"; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 41 | const char CellularCapabilityGSM::kPhoneNumber[] = "*99#"; |
| 42 | const char CellularCapabilityGSM::kPropertyAccessTechnology[] = |
| 43 | "AccessTechnology"; |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 44 | const char CellularCapabilityGSM::kPropertyEnabledFacilityLocks[] = |
| 45 | "EnabledFacilityLocks"; |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 46 | const char CellularCapabilityGSM::kPropertyUnlockRequired[] = "UnlockRequired"; |
| 47 | const char CellularCapabilityGSM::kPropertyUnlockRetries[] = "UnlockRetries"; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 48 | |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 49 | const int CellularCapabilityGSM::kGetIMSIRetryLimit = 10; |
| 50 | const int64 CellularCapabilityGSM::kGetIMSIRetryDelayMilliseconds = 200; |
| 51 | |
| 52 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 53 | CellularCapabilityGSM::CellularCapabilityGSM(Cellular *cellular, |
| 54 | ProxyFactory *proxy_factory) |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 55 | : CellularCapabilityClassic(cellular, proxy_factory), |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 56 | weak_ptr_factory_(this), |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 57 | registration_state_(MM_MODEM_GSM_NETWORK_REG_STATUS_UNKNOWN), |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 58 | access_technology_(MM_MODEM_GSM_ACCESS_TECH_UNKNOWN), |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 59 | home_provider_(NULL), |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 60 | get_imsi_retries_(0), |
| 61 | get_imsi_retry_delay_milliseconds_(kGetIMSIRetryDelayMilliseconds), |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 62 | scanning_(false), |
| 63 | scan_interval_(0) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 64 | SLOG(Cellular, 2) << "Cellular capability constructed: GSM"; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 65 | PropertyStore *store = cellular->mutable_store(); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 66 | store->RegisterConstString(flimflam::kSelectedNetworkProperty, |
| 67 | &selected_network_); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 68 | store->RegisterConstStringmaps(flimflam::kFoundNetworksProperty, |
| 69 | &found_networks_); |
| 70 | store->RegisterConstBool(flimflam::kScanningProperty, &scanning_); |
| 71 | store->RegisterUint16(flimflam::kScanIntervalProperty, &scan_interval_); |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 72 | HelpRegisterDerivedKeyValueStore( |
| 73 | flimflam::kSIMLockStatusProperty, |
| 74 | &CellularCapabilityGSM::SimLockStatusToProperty, |
| 75 | NULL); |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 76 | store->RegisterConstStringmaps(flimflam::kCellularApnListProperty, |
| 77 | &apn_list_); |
Darin Petkov | 0d06f7d | 2012-02-03 13:08:19 +0100 | [diff] [blame] | 78 | scanning_supported_ = true; |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 79 | |
| 80 | // TODO(benchan): This is a hack to initialize the GSM card proxy for GetIMSI |
| 81 | // before InitProxies is called. There are side-effects of calling InitProxies |
| 82 | // before the device is enabled. It's better to refactor InitProxies such that |
| 83 | // proxies can be created when the cellular device/capability is constructed, |
| 84 | // but callbacks for DBus signal updates are not set up until the device is |
| 85 | // enabled. |
| 86 | card_proxy_.reset( |
| 87 | proxy_factory->CreateModemGSMCardProxy(cellular->dbus_path(), |
| 88 | cellular->dbus_owner())); |
| 89 | // TODO(benchan): To allow unit testing using a mock proxy without further |
| 90 | // complicating the code, the test proxy factory is set up to return a NULL |
| 91 | // pointer when CellularCapabilityGSM is constructed. Refactor the code to |
| 92 | // avoid this hack. |
| 93 | if (card_proxy_.get()) |
| 94 | InitProperties(); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 95 | } |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 96 | |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 97 | KeyValueStore CellularCapabilityGSM::SimLockStatusToProperty(Error */*error*/) { |
| 98 | KeyValueStore status; |
| 99 | status.SetBool(flimflam::kSIMLockEnabledProperty, sim_lock_status_.enabled); |
| 100 | status.SetString(flimflam::kSIMLockTypeProperty, sim_lock_status_.lock_type); |
| 101 | status.SetUint(flimflam::kSIMLockRetriesLeftProperty, |
| 102 | sim_lock_status_.retries_left); |
| 103 | return status; |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 104 | } |
| 105 | |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 106 | void CellularCapabilityGSM::HelpRegisterDerivedKeyValueStore( |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 107 | const string &name, |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 108 | KeyValueStore(CellularCapabilityGSM::*get)(Error *error), |
| 109 | void(CellularCapabilityGSM::*set)( |
| 110 | const KeyValueStore &value, Error *error)) { |
| 111 | cellular()->mutable_store()->RegisterDerivedKeyValueStore( |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 112 | name, |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 113 | KeyValueStoreAccessor( |
| 114 | new CustomAccessor<CellularCapabilityGSM, KeyValueStore>( |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 115 | this, get, set))); |
| 116 | } |
| 117 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 118 | void CellularCapabilityGSM::InitProxies() { |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 119 | CellularCapabilityClassic::InitProxies(); |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 120 | // TODO(benchan): Remove this check after refactoring the proxy |
| 121 | // initialization. |
| 122 | if (!card_proxy_.get()) { |
| 123 | card_proxy_.reset( |
| 124 | proxy_factory()->CreateModemGSMCardProxy(cellular()->dbus_path(), |
| 125 | cellular()->dbus_owner())); |
| 126 | } |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 127 | network_proxy_.reset( |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 128 | proxy_factory()->CreateModemGSMNetworkProxy(cellular()->dbus_path(), |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 129 | cellular()->dbus_owner())); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 130 | network_proxy_->set_signal_quality_callback( |
| 131 | Bind(&CellularCapabilityGSM::OnSignalQualitySignal, |
| 132 | weak_ptr_factory_.GetWeakPtr())); |
| 133 | network_proxy_->set_network_mode_callback( |
| 134 | Bind(&CellularCapabilityGSM::OnNetworkModeSignal, |
| 135 | weak_ptr_factory_.GetWeakPtr())); |
| 136 | network_proxy_->set_registration_info_callback( |
| 137 | Bind(&CellularCapabilityGSM::OnRegistrationInfoSignal, |
| 138 | weak_ptr_factory_.GetWeakPtr())); |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 139 | } |
| 140 | |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 141 | void CellularCapabilityGSM::InitProperties() { |
| 142 | CellularTaskList *tasks = new CellularTaskList(); |
| 143 | ResultCallback cb_ignore_error = |
| 144 | Bind(&CellularCapabilityGSM::StepCompletedCallback, |
| 145 | weak_ptr_factory_.GetWeakPtr(), ResultCallback(), true, tasks); |
| 146 | // Chrome uses IMSI to determine if a SIM is present before allowing the |
| 147 | // modem to be enabled, so shill needs to obtain IMSI even before the device |
| 148 | // is enabled. |
| 149 | tasks->push_back(Bind(&CellularCapabilityGSM::GetIMSI, |
| 150 | weak_ptr_factory_.GetWeakPtr(), cb_ignore_error)); |
| 151 | RunNextStep(tasks); |
| 152 | } |
| 153 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 154 | void CellularCapabilityGSM::StartModem(Error *error, |
| 155 | const ResultCallback &callback) { |
| 156 | InitProxies(); |
| 157 | |
| 158 | CellularTaskList *tasks = new CellularTaskList(); |
| 159 | ResultCallback cb = |
| 160 | Bind(&CellularCapabilityGSM::StepCompletedCallback, |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 161 | weak_ptr_factory_.GetWeakPtr(), callback, false, tasks); |
| 162 | ResultCallback cb_ignore_error = |
| 163 | Bind(&CellularCapabilityGSM::StepCompletedCallback, |
| 164 | weak_ptr_factory_.GetWeakPtr(), callback, true, tasks); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 165 | if (!cellular()->IsUnderlyingDeviceEnabled()) |
| 166 | tasks->push_back(Bind(&CellularCapabilityGSM::EnableModem, |
| 167 | weak_ptr_factory_.GetWeakPtr(), cb)); |
| 168 | // If we're within range of the home network, the modem will try to |
| 169 | // register once it's enabled, or may be already registered if we |
| 170 | // started out enabled. |
| 171 | if (!IsUnderlyingDeviceRegistered() && !selected_network_.empty()) |
| 172 | tasks->push_back(Bind(&CellularCapabilityGSM::Register, |
| 173 | weak_ptr_factory_.GetWeakPtr(), cb)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 174 | tasks->push_back(Bind(&CellularCapabilityGSM::GetIMEI, |
| 175 | weak_ptr_factory_.GetWeakPtr(), cb)); |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 176 | get_imsi_retries_ = 0; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 177 | tasks->push_back(Bind(&CellularCapabilityGSM::GetIMSI, |
| 178 | weak_ptr_factory_.GetWeakPtr(), cb)); |
| 179 | tasks->push_back(Bind(&CellularCapabilityGSM::GetSPN, |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 180 | weak_ptr_factory_.GetWeakPtr(), cb_ignore_error)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 181 | tasks->push_back(Bind(&CellularCapabilityGSM::GetMSISDN, |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 182 | weak_ptr_factory_.GetWeakPtr(), cb_ignore_error)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 183 | tasks->push_back(Bind(&CellularCapabilityGSM::GetProperties, |
| 184 | weak_ptr_factory_.GetWeakPtr(), cb)); |
| 185 | tasks->push_back(Bind(&CellularCapabilityGSM::GetModemInfo, |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 186 | weak_ptr_factory_.GetWeakPtr(), cb_ignore_error)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 187 | tasks->push_back(Bind(&CellularCapabilityGSM::FinishEnable, |
| 188 | weak_ptr_factory_.GetWeakPtr(), cb)); |
| 189 | |
| 190 | RunNextStep(tasks); |
| 191 | } |
| 192 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 193 | bool CellularCapabilityGSM::IsUnderlyingDeviceRegistered() const { |
| 194 | switch (cellular()->modem_state()) { |
| 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() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 214 | SLOG(Cellular, 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 | |
Darin Petkov | 5f316f6 | 2011-11-18 12:10:26 +0100 | [diff] [blame] | 220 | void CellularCapabilityGSM::OnServiceCreated() { |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 221 | // If IMSI is available, base the service's storage identifier on it. |
| 222 | if (!imsi_.empty()) { |
| 223 | cellular()->service()->SetStorageIdentifier( |
Darin Petkov | dd3e866 | 2012-02-03 13:16:20 +0100 | [diff] [blame] | 224 | string(flimflam::kTypeCellular) + "_" + |
| 225 | cellular()->address() + "_" + imsi_); |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 226 | } |
Darin Petkov | b9c9933 | 2012-01-12 13:13:00 +0100 | [diff] [blame] | 227 | cellular()->service()->SetActivationState( |
Darin Petkov | 5f316f6 | 2011-11-18 12:10:26 +0100 | [diff] [blame] | 228 | flimflam::kActivationStateActivated); |
| 229 | UpdateServingOperator(); |
| 230 | } |
| 231 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 232 | void CellularCapabilityGSM::UpdateStatus(const DBusPropertiesMap &properties) { |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 233 | if (ContainsKey(properties, kModemPropertyIMSI)) { |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 234 | SetHomeProvider(); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 238 | // Create the list of APNs to try, in the following order: |
| 239 | // - last APN that resulted in a successful connection attempt on the |
| 240 | // current network (if any) |
| 241 | // - the APN, if any, that was set by the user |
| 242 | // - the list of APNs found in the mobile broadband provider DB for the |
| 243 | // home provider associated with the current SIM |
| 244 | // - as a last resort, attempt to connect with no APN |
| 245 | void CellularCapabilityGSM::SetupApnTryList() { |
| 246 | apn_try_list_.clear(); |
| 247 | |
| 248 | DCHECK(cellular()->service().get()); |
| 249 | const Stringmap *apn_info = cellular()->service()->GetLastGoodApn(); |
| 250 | if (apn_info) |
| 251 | apn_try_list_.push_back(*apn_info); |
| 252 | |
| 253 | apn_info = cellular()->service()->GetUserSpecifiedApn(); |
| 254 | if (apn_info) |
| 255 | apn_try_list_.push_back(*apn_info); |
| 256 | |
| 257 | apn_try_list_.insert(apn_try_list_.end(), apn_list_.begin(), apn_list_.end()); |
| 258 | } |
| 259 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 260 | void CellularCapabilityGSM::SetupConnectProperties( |
| 261 | DBusPropertiesMap *properties) { |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 262 | SetupApnTryList(); |
| 263 | FillConnectPropertyMap(properties); |
| 264 | } |
| 265 | |
| 266 | void CellularCapabilityGSM::FillConnectPropertyMap( |
| 267 | DBusPropertiesMap *properties) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 268 | (*properties)[kConnectPropertyPhoneNumber].writer().append_string( |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 269 | kPhoneNumber); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 270 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 271 | if (!AllowRoaming()) |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 272 | (*properties)[kConnectPropertyHomeOnly].writer().append_bool(true); |
| 273 | |
| 274 | if (!apn_try_list_.empty()) { |
| 275 | // Leave the APN at the front of the list, so that it can be recorded |
| 276 | // if the connect attempt succeeds. |
| 277 | Stringmap apn_info = apn_try_list_.front(); |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 278 | SLOG(Cellular, 2) << __func__ << ": Using APN " |
| 279 | << apn_info[flimflam::kApnProperty]; |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 280 | (*properties)[kConnectPropertyApn].writer().append_string( |
| 281 | apn_info[flimflam::kApnProperty].c_str()); |
| 282 | if (ContainsKey(apn_info, flimflam::kApnUsernameProperty)) |
| 283 | (*properties)[kConnectPropertyApnUsername].writer().append_string( |
| 284 | apn_info[flimflam::kApnUsernameProperty].c_str()); |
| 285 | if (ContainsKey(apn_info, flimflam::kApnPasswordProperty)) |
| 286 | (*properties)[kConnectPropertyApnPassword].writer().append_string( |
| 287 | apn_info[flimflam::kApnPasswordProperty].c_str()); |
| 288 | } |
| 289 | } |
| 290 | |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 291 | void CellularCapabilityGSM::Connect(const DBusPropertiesMap &properties, |
| 292 | Error *error, |
| 293 | const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 294 | SLOG(Cellular, 2) << __func__; |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 295 | ResultCallback cb = Bind(&CellularCapabilityGSM::OnConnectReply, |
| 296 | weak_ptr_factory_.GetWeakPtr(), |
| 297 | callback); |
| 298 | simple_proxy_->Connect(properties, error, cb, kTimeoutConnect); |
| 299 | } |
| 300 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 301 | void CellularCapabilityGSM::OnConnectReply(const ResultCallback &callback, |
| 302 | const Error &error) { |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 303 | CellularServiceRefPtr service = cellular()->service(); |
| 304 | if (!service) { |
| 305 | // The service could have been deleted before our Connect() request |
| 306 | // completes if the modem was enabled and then quickly disabled. |
| 307 | apn_try_list_.clear(); |
| 308 | } else if (error.IsFailure()) { |
| 309 | service->ClearLastGoodApn(); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 310 | // The APN that was just tried (and failed) is still at the |
| 311 | // front of the list, about to be removed. If the list is empty |
| 312 | // after that, try one last time without an APN. This may succeed |
| 313 | // with some modems in some cases. |
| 314 | if (error.type() == Error::kInvalidApn && !apn_try_list_.empty()) { |
| 315 | apn_try_list_.pop_front(); |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 316 | SLOG(Cellular, 2) << "Connect failed with invalid APN, " |
| 317 | << apn_try_list_.size() << " remaining APNs to try"; |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 318 | DBusPropertiesMap props; |
| 319 | FillConnectPropertyMap(&props); |
| 320 | Error error; |
| 321 | Connect(props, &error, callback); |
| 322 | return; |
| 323 | } |
| 324 | } else if (!apn_try_list_.empty()) { |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 325 | service->SetLastGoodApn(apn_try_list_.front()); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 326 | apn_try_list_.clear(); |
| 327 | } |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 328 | if (!callback.is_null()) |
| 329 | callback.Run(error); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | bool CellularCapabilityGSM::AllowRoaming() { |
| 333 | bool requires_roaming = |
| 334 | home_provider_ ? home_provider_->requires_roaming : false; |
| 335 | return requires_roaming || allow_roaming_property(); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 336 | } |
| 337 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 338 | // always called from an async context |
| 339 | void CellularCapabilityGSM::GetIMEI(const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 340 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 341 | CHECK(!callback.is_null()); |
| 342 | Error error; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 343 | if (imei_.empty()) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 344 | GSMIdentifierCallback cb = Bind(&CellularCapabilityGSM::OnGetIMEIReply, |
| 345 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 346 | card_proxy_->GetIMEI(&error, cb, kTimeoutDefault); |
| 347 | if (error.IsFailure()) |
| 348 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 349 | } else { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 350 | SLOG(Cellular, 2) << "Already have IMEI " << imei_; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 351 | callback.Run(error); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 352 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 353 | } |
| 354 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 355 | // always called from an async context |
| 356 | void CellularCapabilityGSM::GetIMSI(const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 357 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 358 | CHECK(!callback.is_null()); |
| 359 | Error error; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 360 | if (imsi_.empty()) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 361 | GSMIdentifierCallback cb = Bind(&CellularCapabilityGSM::OnGetIMSIReply, |
| 362 | weak_ptr_factory_.GetWeakPtr(), |
| 363 | callback); |
| 364 | card_proxy_->GetIMSI(&error, cb, kTimeoutDefault); |
| 365 | if (error.IsFailure()) |
| 366 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 367 | } else { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 368 | SLOG(Cellular, 2) << "Already have IMSI " << imsi_; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 369 | callback.Run(error); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 370 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 371 | } |
| 372 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 373 | // always called from an async context |
| 374 | void CellularCapabilityGSM::GetSPN(const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 375 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 376 | CHECK(!callback.is_null()); |
| 377 | Error error; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 378 | if (spn_.empty()) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 379 | GSMIdentifierCallback cb = Bind(&CellularCapabilityGSM::OnGetSPNReply, |
| 380 | weak_ptr_factory_.GetWeakPtr(), |
| 381 | callback); |
| 382 | card_proxy_->GetSPN(&error, cb, kTimeoutDefault); |
| 383 | if (error.IsFailure()) |
| 384 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 385 | } else { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 386 | SLOG(Cellular, 2) << "Already have SPN " << spn_; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 387 | callback.Run(error); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 388 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 389 | } |
| 390 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 391 | // always called from an async context |
| 392 | void CellularCapabilityGSM::GetMSISDN(const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 393 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 394 | CHECK(!callback.is_null()); |
| 395 | Error error; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 396 | if (mdn_.empty()) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 397 | GSMIdentifierCallback cb = Bind(&CellularCapabilityGSM::OnGetMSISDNReply, |
| 398 | weak_ptr_factory_.GetWeakPtr(), |
| 399 | callback); |
| 400 | card_proxy_->GetMSISDN(&error, cb, kTimeoutDefault); |
| 401 | if (error.IsFailure()) |
| 402 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 403 | } else { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 404 | SLOG(Cellular, 2) << "Already have MSISDN " << mdn_; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 405 | callback.Run(error); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 406 | } |
| 407 | } |
| 408 | |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 409 | void CellularCapabilityGSM::GetSignalQuality() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 410 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 411 | SignalQualityCallback callback = |
| 412 | Bind(&CellularCapabilityGSM::OnGetSignalQualityReply, |
| 413 | weak_ptr_factory_.GetWeakPtr()); |
| 414 | network_proxy_->GetSignalQuality(NULL, callback, kTimeoutDefault); |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 415 | } |
| 416 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 417 | void CellularCapabilityGSM::GetRegistrationState() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 418 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 419 | RegistrationInfoCallback callback = |
| 420 | Bind(&CellularCapabilityGSM::OnGetRegistrationInfoReply, |
| 421 | weak_ptr_factory_.GetWeakPtr()); |
| 422 | network_proxy_->GetRegistrationInfo(NULL, callback, kTimeoutDefault); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 423 | } |
| 424 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 425 | void CellularCapabilityGSM::GetProperties(const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 426 | SLOG(Cellular, 2) << __func__; |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 427 | |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 428 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 429 | uint32 tech = network_proxy_->AccessTechnology(); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 430 | SetAccessTechnology(tech); |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 431 | SLOG(Cellular, 2) << "GSM AccessTechnology: " << tech; |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 432 | |
| 433 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 434 | uint32 locks = card_proxy_->EnabledFacilityLocks(); |
| 435 | sim_lock_status_.enabled = locks & MM_MODEM_GSM_FACILITY_SIM; |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 436 | SLOG(Cellular, 2) << "GSM EnabledFacilityLocks: " << locks; |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 437 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 438 | callback.Run(Error()); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 439 | } |
| 440 | |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 441 | string CellularCapabilityGSM::CreateFriendlyServiceName() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 442 | SLOG(Cellular, 2) << __func__; |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 443 | if (registration_state_ == MM_MODEM_GSM_NETWORK_REG_STATUS_HOME && |
| 444 | !cellular()->home_provider().GetName().empty()) { |
| 445 | return cellular()->home_provider().GetName(); |
| 446 | } |
| 447 | if (!serving_operator_.GetName().empty()) { |
| 448 | return serving_operator_.GetName(); |
| 449 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 450 | if (!carrier_.empty()) { |
| 451 | return carrier_; |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 452 | } |
| 453 | if (!serving_operator_.GetCode().empty()) { |
| 454 | return "cellular_" + serving_operator_.GetCode(); |
| 455 | } |
| 456 | return base::StringPrintf("GSMNetwork%u", friendly_service_name_id_++); |
| 457 | } |
| 458 | |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 459 | void CellularCapabilityGSM::SetHomeProvider() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 460 | SLOG(Cellular, 2) << __func__ << "(IMSI: " << imsi_ |
| 461 | << " SPN: " << spn_ << ")"; |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 462 | // TODO(petkov): The test for NULL provider_db should be done by |
| 463 | // mobile_provider_lookup_best_match. |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 464 | if (imsi_.empty() || !cellular()->provider_db()) { |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 465 | return; |
| 466 | } |
| 467 | mobile_provider *provider = |
| 468 | mobile_provider_lookup_best_match( |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 469 | cellular()->provider_db(), spn_.c_str(), imsi_.c_str()); |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 470 | if (!provider) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 471 | SLOG(Cellular, 2) << "GSM provider not found."; |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 472 | return; |
| 473 | } |
| 474 | home_provider_ = provider; |
| 475 | Cellular::Operator oper; |
| 476 | if (provider->networks) { |
| 477 | oper.SetCode(provider->networks[0]); |
| 478 | } |
| 479 | if (provider->country) { |
| 480 | oper.SetCountry(provider->country); |
| 481 | } |
| 482 | if (spn_.empty()) { |
| 483 | const char *name = mobile_provider_get_name(provider); |
| 484 | if (name) { |
| 485 | oper.SetName(name); |
| 486 | } |
| 487 | } else { |
| 488 | oper.SetName(spn_); |
| 489 | } |
| 490 | cellular()->set_home_provider(oper); |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 491 | InitAPNList(); |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 492 | } |
| 493 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 494 | void CellularCapabilityGSM::UpdateOperatorInfo() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 495 | SLOG(Cellular, 2) << __func__; |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 496 | const string &network_id = serving_operator_.GetCode(); |
| 497 | if (!network_id.empty()) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 498 | SLOG(Cellular, 2) << "Looking up network id: " << network_id; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 499 | mobile_provider *provider = |
| 500 | mobile_provider_lookup_by_network(cellular()->provider_db(), |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 501 | network_id.c_str()); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 502 | if (provider) { |
| 503 | const char *provider_name = mobile_provider_get_name(provider); |
| 504 | if (provider_name && *provider_name) { |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 505 | serving_operator_.SetName(provider_name); |
| 506 | if (provider->country) { |
| 507 | serving_operator_.SetCountry(provider->country); |
| 508 | } |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 509 | SLOG(Cellular, 2) << "Operator name: " << serving_operator_.GetName() |
| 510 | << ", country: " << serving_operator_.GetCountry(); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 511 | } |
| 512 | } else { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 513 | SLOG(Cellular, 2) << "GSM provider not found."; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | UpdateServingOperator(); |
| 517 | } |
| 518 | |
| 519 | void CellularCapabilityGSM::UpdateServingOperator() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 520 | SLOG(Cellular, 2) << __func__; |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 521 | if (cellular()->service().get()) { |
Darin Petkov | 9cb0268 | 2012-01-28 00:17:38 +0100 | [diff] [blame] | 522 | cellular()->service()->SetServingOperator(serving_operator_); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 523 | } |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 524 | } |
| 525 | |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 526 | void CellularCapabilityGSM::InitAPNList() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 527 | SLOG(Cellular, 2) << __func__; |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 528 | if (!home_provider_) { |
| 529 | return; |
| 530 | } |
| 531 | apn_list_.clear(); |
| 532 | for (int i = 0; i < home_provider_->num_apns; ++i) { |
| 533 | Stringmap props; |
| 534 | mobile_apn *apn = home_provider_->apns[i]; |
| 535 | if (apn->value) { |
| 536 | props[flimflam::kApnProperty] = apn->value; |
| 537 | } |
| 538 | if (apn->username) { |
| 539 | props[flimflam::kApnUsernameProperty] = apn->username; |
| 540 | } |
| 541 | if (apn->password) { |
| 542 | props[flimflam::kApnPasswordProperty] = apn->password; |
| 543 | } |
| 544 | // Find the first localized and non-localized name, if any. |
| 545 | const localized_name *lname = NULL; |
| 546 | const localized_name *name = NULL; |
| 547 | for (int j = 0; j < apn->num_names; ++j) { |
| 548 | if (apn->names[j]->lang) { |
| 549 | if (!lname) { |
| 550 | lname = apn->names[j]; |
| 551 | } |
| 552 | } else if (!name) { |
| 553 | name = apn->names[j]; |
| 554 | } |
| 555 | } |
| 556 | if (name) { |
| 557 | props[flimflam::kApnNameProperty] = name->name; |
| 558 | } |
| 559 | if (lname) { |
| 560 | props[flimflam::kApnLocalizedNameProperty] = lname->name; |
| 561 | props[flimflam::kApnLanguageProperty] = lname->lang; |
| 562 | } |
| 563 | apn_list_.push_back(props); |
| 564 | } |
| 565 | cellular()->adaptor()->EmitStringmapsChanged( |
| 566 | flimflam::kCellularApnListProperty, apn_list_); |
| 567 | } |
| 568 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 569 | // always called from an async context |
| 570 | void CellularCapabilityGSM::Register(const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 571 | SLOG(Cellular, 2) << __func__ << " \"" << selected_network_ << "\""; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 572 | CHECK(!callback.is_null()); |
| 573 | Error error; |
| 574 | ResultCallback cb = Bind(&CellularCapabilityGSM::OnRegisterReply, |
| 575 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 576 | network_proxy_->Register(selected_network_, &error, cb, kTimeoutRegister); |
| 577 | if (error.IsFailure()) |
| 578 | callback.Run(error); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | void CellularCapabilityGSM::RegisterOnNetwork( |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 582 | const string &network_id, |
| 583 | Error *error, |
| 584 | const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 585 | SLOG(Cellular, 2) << __func__ << "(" << network_id << ")"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 586 | CHECK(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 587 | desired_network_ = network_id; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 588 | ResultCallback cb = Bind(&CellularCapabilityGSM::OnRegisterReply, |
| 589 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 590 | network_proxy_->Register(network_id, error, cb, kTimeoutRegister); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 591 | } |
| 592 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 593 | void CellularCapabilityGSM::OnRegisterReply(const ResultCallback &callback, |
| 594 | const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 595 | SLOG(Cellular, 2) << __func__ << "(" << error << ")"; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 596 | |
| 597 | if (error.IsSuccess()) { |
| 598 | selected_network_ = desired_network_; |
| 599 | desired_network_.clear(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 600 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 601 | return; |
| 602 | } |
| 603 | // If registration on the desired network failed, |
| 604 | // try to register on the home network. |
| 605 | if (!desired_network_.empty()) { |
| 606 | desired_network_.clear(); |
| 607 | selected_network_.clear(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 608 | LOG(INFO) << "Couldn't register on selected network, trying home network"; |
| 609 | Register(callback); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 610 | return; |
| 611 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 612 | callback.Run(error); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 613 | } |
| 614 | |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 615 | bool CellularCapabilityGSM::IsRegistered() { |
| 616 | return (registration_state_ == MM_MODEM_GSM_NETWORK_REG_STATUS_HOME || |
| 617 | registration_state_ == MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING); |
| 618 | } |
| 619 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 620 | void CellularCapabilityGSM::SetUnregistered(bool searching) { |
| 621 | // If we're already in some non-registered state, don't override that |
| 622 | if (registration_state_ == MM_MODEM_GSM_NETWORK_REG_STATUS_HOME || |
| 623 | registration_state_ == MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING) { |
| 624 | registration_state_ = |
| 625 | (searching ? MM_MODEM_GSM_NETWORK_REG_STATUS_SEARCHING : |
| 626 | MM_MODEM_GSM_NETWORK_REG_STATUS_IDLE); |
| 627 | } |
| 628 | } |
| 629 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 630 | void CellularCapabilityGSM::RequirePIN( |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 631 | const std::string &pin, bool require, |
| 632 | Error *error, const ResultCallback &callback) { |
| 633 | CHECK(error); |
| 634 | card_proxy_->EnablePIN(pin, require, error, callback, kTimeoutDefault); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 635 | } |
| 636 | |
Darin Petkov | e5bc2cb | 2011-12-07 14:47:32 +0100 | [diff] [blame] | 637 | void CellularCapabilityGSM::EnterPIN(const string &pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 638 | Error *error, |
| 639 | const ResultCallback &callback) { |
| 640 | CHECK(error); |
| 641 | card_proxy_->SendPIN(pin, error, callback, kTimeoutDefault); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 642 | } |
| 643 | |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 644 | void CellularCapabilityGSM::UnblockPIN(const string &unblock_code, |
| 645 | const string &pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 646 | Error *error, |
| 647 | const ResultCallback &callback) { |
| 648 | CHECK(error); |
| 649 | card_proxy_->SendPUK(unblock_code, pin, error, callback, kTimeoutDefault); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | void CellularCapabilityGSM::ChangePIN( |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 653 | const string &old_pin, const string &new_pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 654 | Error *error, const ResultCallback &callback) { |
| 655 | CHECK(error); |
| 656 | card_proxy_->ChangePIN(old_pin, new_pin, error, callback, kTimeoutDefault); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 657 | } |
| 658 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 659 | void CellularCapabilityGSM::Scan(Error *error, const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 660 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 661 | CHECK(error); |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 662 | if (scanning_) { |
| 663 | Error::PopulateAndLog(error, Error::kInProgress, "Already scanning"); |
| 664 | return; |
| 665 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 666 | ScanResultsCallback cb = Bind(&CellularCapabilityGSM::OnScanReply, |
| 667 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 668 | network_proxy_->Scan(error, cb, kTimeoutScan); |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 669 | if (!error->IsFailure()) { |
| 670 | scanning_ = true; |
| 671 | cellular()->adaptor()->EmitBoolChanged(flimflam::kScanningProperty, |
| 672 | scanning_); |
| 673 | } |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 674 | } |
| 675 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 676 | void CellularCapabilityGSM::OnScanReply(const ResultCallback &callback, |
| 677 | const GSMScanResults &results, |
| 678 | const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 679 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 680 | |
| 681 | // Error handling is weak. The current expectation is that on any |
| 682 | // error, found_networks_ should be cleared and a property change |
| 683 | // notification sent out. |
| 684 | // |
| 685 | // TODO(jglasgow): fix error handling |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 686 | scanning_ = false; |
| 687 | cellular()->adaptor()->EmitBoolChanged(flimflam::kScanningProperty, |
| 688 | scanning_); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 689 | found_networks_.clear(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 690 | if (!error.IsFailure()) { |
| 691 | for (GSMScanResults::const_iterator it = results.begin(); |
| 692 | it != results.end(); ++it) { |
| 693 | found_networks_.push_back(ParseScanResult(*it)); |
| 694 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 695 | } |
Darin Petkov | b7828b0 | 2012-02-03 12:34:30 +0100 | [diff] [blame] | 696 | cellular()->adaptor()->EmitStringmapsChanged(flimflam::kFoundNetworksProperty, |
| 697 | found_networks_); |
Gary Morain | a49062a | 2012-04-27 13:48:41 -0700 | [diff] [blame] | 698 | if (!callback.is_null()) |
| 699 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | Stringmap CellularCapabilityGSM::ParseScanResult(const GSMScanResult &result) { |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 703 | Stringmap parsed; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 704 | for (GSMScanResult::const_iterator it = result.begin(); |
| 705 | it != result.end(); ++it) { |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 706 | // TODO(petkov): Define these in system_api/service_constants.h. The |
| 707 | // numerical values are taken from 3GPP TS 27.007 Section 7.3. |
| 708 | static const char * const kStatusString[] = { |
| 709 | "unknown", |
| 710 | "available", |
| 711 | "current", |
| 712 | "forbidden", |
| 713 | }; |
| 714 | static const char * const kTechnologyString[] = { |
| 715 | flimflam::kNetworkTechnologyGsm, |
| 716 | "GSM Compact", |
| 717 | flimflam::kNetworkTechnologyUmts, |
| 718 | flimflam::kNetworkTechnologyEdge, |
| 719 | "HSDPA", |
| 720 | "HSUPA", |
| 721 | flimflam::kNetworkTechnologyHspa, |
| 722 | }; |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 723 | SLOG(Cellular, 2) << "Network property: " << it->first << " = " |
| 724 | << it->second; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 725 | if (it->first == kNetworkPropertyStatus) { |
| 726 | int status = 0; |
| 727 | if (base::StringToInt(it->second, &status) && |
| 728 | status >= 0 && |
| 729 | status < static_cast<int>(arraysize(kStatusString))) { |
| 730 | parsed[flimflam::kStatusProperty] = kStatusString[status]; |
| 731 | } else { |
| 732 | LOG(ERROR) << "Unexpected status value: " << it->second; |
| 733 | } |
| 734 | } else if (it->first == kNetworkPropertyID) { |
| 735 | parsed[flimflam::kNetworkIdProperty] = it->second; |
| 736 | } else if (it->first == kNetworkPropertyLongName) { |
| 737 | parsed[flimflam::kLongNameProperty] = it->second; |
| 738 | } else if (it->first == kNetworkPropertyShortName) { |
| 739 | parsed[flimflam::kShortNameProperty] = it->second; |
| 740 | } else if (it->first == kNetworkPropertyAccessTechnology) { |
| 741 | int tech = 0; |
| 742 | if (base::StringToInt(it->second, &tech) && |
| 743 | tech >= 0 && |
| 744 | tech < static_cast<int>(arraysize(kTechnologyString))) { |
| 745 | parsed[flimflam::kTechnologyProperty] = kTechnologyString[tech]; |
| 746 | } else { |
| 747 | LOG(ERROR) << "Unexpected technology value: " << it->second; |
| 748 | } |
| 749 | } else { |
| 750 | LOG(WARNING) << "Unknown network property ignored: " << it->first; |
| 751 | } |
| 752 | } |
| 753 | // If the long name is not available but the network ID is, look up the long |
| 754 | // name in the mobile provider database. |
| 755 | if ((!ContainsKey(parsed, flimflam::kLongNameProperty) || |
| 756 | parsed[flimflam::kLongNameProperty].empty()) && |
| 757 | ContainsKey(parsed, flimflam::kNetworkIdProperty)) { |
| 758 | mobile_provider *provider = |
| 759 | mobile_provider_lookup_by_network( |
| 760 | cellular()->provider_db(), |
| 761 | parsed[flimflam::kNetworkIdProperty].c_str()); |
| 762 | if (provider) { |
| 763 | const char *long_name = mobile_provider_get_name(provider); |
| 764 | if (long_name && *long_name) { |
| 765 | parsed[flimflam::kLongNameProperty] = long_name; |
| 766 | } |
| 767 | } |
| 768 | } |
| 769 | return parsed; |
| 770 | } |
| 771 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 772 | void CellularCapabilityGSM::SetAccessTechnology(uint32 access_technology) { |
| 773 | access_technology_ = access_technology; |
| 774 | if (cellular()->service().get()) { |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 775 | cellular()->service()->SetNetworkTechnology(GetNetworkTechnologyString()); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 776 | } |
| 777 | } |
| 778 | |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 779 | string CellularCapabilityGSM::GetNetworkTechnologyString() const { |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 780 | switch (access_technology_) { |
| 781 | case MM_MODEM_GSM_ACCESS_TECH_GSM: |
| 782 | case MM_MODEM_GSM_ACCESS_TECH_GSM_COMPACT: |
| 783 | return flimflam::kNetworkTechnologyGsm; |
| 784 | case MM_MODEM_GSM_ACCESS_TECH_GPRS: |
| 785 | return flimflam::kNetworkTechnologyGprs; |
| 786 | case MM_MODEM_GSM_ACCESS_TECH_EDGE: |
| 787 | return flimflam::kNetworkTechnologyEdge; |
| 788 | case MM_MODEM_GSM_ACCESS_TECH_UMTS: |
| 789 | return flimflam::kNetworkTechnologyUmts; |
| 790 | case MM_MODEM_GSM_ACCESS_TECH_HSDPA: |
| 791 | case MM_MODEM_GSM_ACCESS_TECH_HSUPA: |
| 792 | case MM_MODEM_GSM_ACCESS_TECH_HSPA: |
| 793 | return flimflam::kNetworkTechnologyHspa; |
| 794 | case MM_MODEM_GSM_ACCESS_TECH_HSPA_PLUS: |
| 795 | return flimflam::kNetworkTechnologyHspaPlus; |
| 796 | default: |
| 797 | break; |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 798 | } |
| 799 | return ""; |
| 800 | } |
| 801 | |
| 802 | string CellularCapabilityGSM::GetRoamingStateString() const { |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 803 | switch (registration_state_) { |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 804 | case MM_MODEM_GSM_NETWORK_REG_STATUS_HOME: |
| 805 | return flimflam::kRoamingStateHome; |
| 806 | case MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING: |
| 807 | return flimflam::kRoamingStateRoaming; |
| 808 | default: |
| 809 | break; |
| 810 | } |
| 811 | return flimflam::kRoamingStateUnknown; |
| 812 | } |
| 813 | |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 814 | void CellularCapabilityGSM::OnDBusPropertiesChanged( |
| 815 | const string &interface, |
| 816 | const DBusPropertiesMap &properties, |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 817 | const vector<string> &invalidated_properties) { |
| 818 | CellularCapabilityClassic::OnDBusPropertiesChanged(interface, |
| 819 | properties, |
| 820 | invalidated_properties); |
| 821 | if (interface == MM_MODEM_GSM_NETWORK_INTERFACE) { |
| 822 | uint32 access_technology = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; |
| 823 | if (DBusProperties::GetUint32(properties, |
| 824 | kPropertyAccessTechnology, |
| 825 | &access_technology)) { |
| 826 | SetAccessTechnology(access_technology); |
| 827 | } |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 828 | } else { |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 829 | bool emit = false; |
Gary Morain | baeefdf | 2012-04-30 14:53:35 -0700 | [diff] [blame] | 830 | if (interface == MM_MODEM_GSM_CARD_INTERFACE) { |
| 831 | uint32 locks = 0; |
| 832 | if (DBusProperties::GetUint32( |
| 833 | properties, kPropertyEnabledFacilityLocks, &locks)) { |
| 834 | sim_lock_status_.enabled = locks & MM_MODEM_GSM_FACILITY_SIM; |
| 835 | emit = true; |
| 836 | } |
| 837 | } else if (interface == MM_MODEM_INTERFACE) { |
| 838 | if (DBusProperties::GetString(properties, kPropertyUnlockRequired, |
| 839 | &sim_lock_status_.lock_type)) { |
| 840 | emit = true; |
| 841 | } |
| 842 | if (DBusProperties::GetUint32(properties, kPropertyUnlockRetries, |
| 843 | &sim_lock_status_.retries_left)) { |
| 844 | emit = true; |
| 845 | } |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 846 | } |
| 847 | if (emit) { |
| 848 | cellular()->adaptor()->EmitKeyValueStoreChanged( |
| 849 | flimflam::kSIMLockStatusProperty, SimLockStatusToProperty(NULL)); |
| 850 | } |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 851 | } |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 852 | } |
| 853 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 854 | void CellularCapabilityGSM::OnNetworkModeSignal(uint32 /*mode*/) { |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 855 | // TODO(petkov): Implement this. |
| 856 | NOTIMPLEMENTED(); |
| 857 | } |
| 858 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 859 | void CellularCapabilityGSM::OnRegistrationInfoSignal( |
| 860 | uint32 status, const string &operator_code, const string &operator_name) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 861 | SLOG(Cellular, 2) << __func__ << ": regstate=" << status |
| 862 | << ", opercode=" << operator_code |
| 863 | << ", opername=" << operator_name; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 864 | registration_state_ = status; |
| 865 | serving_operator_.SetCode(operator_code); |
| 866 | serving_operator_.SetName(operator_name); |
| 867 | UpdateOperatorInfo(); |
| 868 | cellular()->HandleNewRegistrationState(); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 869 | } |
| 870 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 871 | void CellularCapabilityGSM::OnSignalQualitySignal(uint32 quality) { |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 872 | cellular()->HandleNewSignalQuality(quality); |
| 873 | } |
| 874 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 875 | void CellularCapabilityGSM::OnGetRegistrationInfoReply( |
| 876 | uint32 status, const string &operator_code, const string &operator_name, |
| 877 | const Error &error) { |
| 878 | if (error.IsSuccess()) |
| 879 | OnRegistrationInfoSignal(status, operator_code, operator_name); |
| 880 | } |
| 881 | |
| 882 | void CellularCapabilityGSM::OnGetSignalQualityReply(uint32 quality, |
| 883 | const Error &error) { |
| 884 | if (error.IsSuccess()) |
| 885 | OnSignalQualitySignal(quality); |
| 886 | } |
| 887 | |
| 888 | void CellularCapabilityGSM::OnGetIMEIReply(const ResultCallback &callback, |
| 889 | const string &imei, |
| 890 | const Error &error) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 891 | if (error.IsSuccess()) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 892 | SLOG(Cellular, 2) << "IMEI: " << imei; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 893 | imei_ = imei; |
| 894 | } else { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 895 | SLOG(Cellular, 2) << "GetIMEI failed - " << error; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 896 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 897 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 898 | } |
| 899 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 900 | void CellularCapabilityGSM::OnGetIMSIReply(const ResultCallback &callback, |
| 901 | const string &imsi, |
| 902 | const Error &error) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 903 | if (error.IsSuccess()) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 904 | SLOG(Cellular, 2) << "IMSI: " << imsi; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 905 | imsi_ = imsi; |
| 906 | SetHomeProvider(); |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 907 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 908 | } else { |
Gary Morain | 82a31a0 | 2012-08-02 18:03:32 -0700 | [diff] [blame] | 909 | if (get_imsi_retries_++ < kGetIMSIRetryLimit) { |
| 910 | SLOG(Cellular, 2) << "GetIMSI failed - " << error << ". Retrying"; |
| 911 | base::Callback<void(void)> retry_get_imsi_cb = |
| 912 | Bind(&CellularCapabilityGSM::GetIMSI, |
| 913 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 914 | cellular()->dispatcher()->PostDelayedTask( |
| 915 | retry_get_imsi_cb, |
| 916 | get_imsi_retry_delay_milliseconds_); |
| 917 | } else { |
| 918 | LOG(INFO) << "GetIMSI failed - " << error; |
| 919 | callback.Run(error); |
| 920 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 921 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 922 | } |
| 923 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 924 | void CellularCapabilityGSM::OnGetSPNReply(const ResultCallback &callback, |
| 925 | const string &spn, |
| 926 | const Error &error) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 927 | if (error.IsSuccess()) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 928 | SLOG(Cellular, 2) << "SPN: " << spn; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 929 | spn_ = spn; |
| 930 | SetHomeProvider(); |
| 931 | } else { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 932 | SLOG(Cellular, 2) << "GetSPN failed - " << error; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 933 | } |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 934 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 935 | } |
| 936 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 937 | void CellularCapabilityGSM::OnGetMSISDNReply(const ResultCallback &callback, |
| 938 | const string &msisdn, |
| 939 | const Error &error) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 940 | if (error.IsSuccess()) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 941 | SLOG(Cellular, 2) << "MSISDN: " << msisdn; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 942 | mdn_ = msisdn; |
| 943 | } else { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 944 | SLOG(Cellular, 2) << "GetMSISDN failed - " << error; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 945 | } |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 946 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 947 | } |
| 948 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 949 | } // namespace shill |