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