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