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