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