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