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