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