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