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 | |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 227 | void CellularCapabilityGSM::Connect(const DBusPropertiesMap &properties, |
| 228 | Error *error, |
| 229 | const ResultCallback &callback) { |
| 230 | VLOG(2) << __func__; |
| 231 | ResultCallback cb = Bind(&CellularCapabilityGSM::OnConnectReply, |
| 232 | weak_ptr_factory_.GetWeakPtr(), |
| 233 | callback); |
| 234 | simple_proxy_->Connect(properties, error, cb, kTimeoutConnect); |
| 235 | } |
| 236 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 237 | void CellularCapabilityGSM::OnConnectReply(const ResultCallback &callback, |
| 238 | const Error &error) { |
| 239 | if (error.IsFailure()) { |
| 240 | cellular()->service()->ClearLastGoodApn(); |
| 241 | // The APN that was just tried (and failed) is still at the |
| 242 | // front of the list, about to be removed. If the list is empty |
| 243 | // after that, try one last time without an APN. This may succeed |
| 244 | // with some modems in some cases. |
| 245 | if (error.type() == Error::kInvalidApn && !apn_try_list_.empty()) { |
| 246 | apn_try_list_.pop_front(); |
| 247 | VLOG(2) << "Connect failed with invalid APN, " << apn_try_list_.size() |
| 248 | << " remaining APNs to try"; |
| 249 | DBusPropertiesMap props; |
| 250 | FillConnectPropertyMap(&props); |
| 251 | Error error; |
| 252 | Connect(props, &error, callback); |
| 253 | return; |
| 254 | } |
| 255 | } else if (!apn_try_list_.empty()) { |
| 256 | cellular()->service()->SetLastGoodApn(apn_try_list_.front()); |
| 257 | apn_try_list_.clear(); |
| 258 | } |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 259 | if (!callback.is_null()) |
| 260 | callback.Run(error); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | bool CellularCapabilityGSM::AllowRoaming() { |
| 264 | bool requires_roaming = |
| 265 | home_provider_ ? home_provider_->requires_roaming : false; |
| 266 | return requires_roaming || allow_roaming_property(); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 267 | } |
| 268 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 269 | // always called from an async context |
| 270 | void CellularCapabilityGSM::GetIMEI(const ResultCallback &callback) { |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 271 | VLOG(2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 272 | CHECK(!callback.is_null()); |
| 273 | Error error; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 274 | if (imei_.empty()) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 275 | GSMIdentifierCallback cb = Bind(&CellularCapabilityGSM::OnGetIMEIReply, |
| 276 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 277 | card_proxy_->GetIMEI(&error, cb, kTimeoutDefault); |
| 278 | if (error.IsFailure()) |
| 279 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 280 | } else { |
| 281 | VLOG(2) << "Already have IMEI " << imei_; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 282 | callback.Run(error); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 283 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 284 | } |
| 285 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 286 | // always called from an async context |
| 287 | void CellularCapabilityGSM::GetIMSI(const ResultCallback &callback) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 288 | VLOG(2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 289 | CHECK(!callback.is_null()); |
| 290 | Error error; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 291 | if (imsi_.empty()) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 292 | GSMIdentifierCallback cb = Bind(&CellularCapabilityGSM::OnGetIMSIReply, |
| 293 | weak_ptr_factory_.GetWeakPtr(), |
| 294 | callback); |
| 295 | card_proxy_->GetIMSI(&error, cb, kTimeoutDefault); |
| 296 | if (error.IsFailure()) |
| 297 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 298 | } else { |
| 299 | VLOG(2) << "Already have IMSI " << imsi_; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 300 | callback.Run(error); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 301 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 302 | } |
| 303 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 304 | // always called from an async context |
| 305 | void CellularCapabilityGSM::GetSPN(const ResultCallback &callback) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 306 | VLOG(2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 307 | CHECK(!callback.is_null()); |
| 308 | Error error; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 309 | if (spn_.empty()) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 310 | GSMIdentifierCallback cb = Bind(&CellularCapabilityGSM::OnGetSPNReply, |
| 311 | weak_ptr_factory_.GetWeakPtr(), |
| 312 | callback); |
| 313 | card_proxy_->GetSPN(&error, cb, kTimeoutDefault); |
| 314 | if (error.IsFailure()) |
| 315 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 316 | } else { |
| 317 | VLOG(2) << "Already have SPN " << spn_; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 318 | callback.Run(error); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 319 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 320 | } |
| 321 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 322 | // always called from an async context |
| 323 | void CellularCapabilityGSM::GetMSISDN(const ResultCallback &callback) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 324 | VLOG(2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 325 | CHECK(!callback.is_null()); |
| 326 | Error error; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 327 | if (mdn_.empty()) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 328 | GSMIdentifierCallback cb = Bind(&CellularCapabilityGSM::OnGetMSISDNReply, |
| 329 | weak_ptr_factory_.GetWeakPtr(), |
| 330 | callback); |
| 331 | card_proxy_->GetMSISDN(&error, cb, kTimeoutDefault); |
| 332 | if (error.IsFailure()) |
| 333 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 334 | } else { |
| 335 | VLOG(2) << "Already have MSISDN " << mdn_; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 336 | callback.Run(error); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 340 | void CellularCapabilityGSM::GetSignalQuality() { |
| 341 | VLOG(2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 342 | SignalQualityCallback callback = |
| 343 | Bind(&CellularCapabilityGSM::OnGetSignalQualityReply, |
| 344 | weak_ptr_factory_.GetWeakPtr()); |
| 345 | network_proxy_->GetSignalQuality(NULL, callback, kTimeoutDefault); |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 346 | } |
| 347 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 348 | void CellularCapabilityGSM::GetRegistrationState() { |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 349 | VLOG(2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 350 | RegistrationInfoCallback callback = |
| 351 | Bind(&CellularCapabilityGSM::OnGetRegistrationInfoReply, |
| 352 | weak_ptr_factory_.GetWeakPtr()); |
| 353 | network_proxy_->GetRegistrationInfo(NULL, callback, kTimeoutDefault); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 354 | } |
| 355 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 356 | void CellularCapabilityGSM::GetProperties(const ResultCallback &callback) { |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 357 | VLOG(2) << __func__; |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 358 | |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 359 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 360 | uint32 tech = network_proxy_->AccessTechnology(); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 361 | SetAccessTechnology(tech); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 362 | VLOG(2) << "GSM AccessTechnology: " << tech; |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 363 | |
| 364 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 365 | uint32 locks = card_proxy_->EnabledFacilityLocks(); |
| 366 | sim_lock_status_.enabled = locks & MM_MODEM_GSM_FACILITY_SIM; |
| 367 | VLOG(2) << "GSM EnabledFacilityLocks: " << locks; |
| 368 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 369 | callback.Run(Error()); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 370 | } |
| 371 | |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 372 | string CellularCapabilityGSM::CreateFriendlyServiceName() { |
| 373 | VLOG(2) << __func__; |
| 374 | if (registration_state_ == MM_MODEM_GSM_NETWORK_REG_STATUS_HOME && |
| 375 | !cellular()->home_provider().GetName().empty()) { |
| 376 | return cellular()->home_provider().GetName(); |
| 377 | } |
| 378 | if (!serving_operator_.GetName().empty()) { |
| 379 | return serving_operator_.GetName(); |
| 380 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 381 | if (!carrier_.empty()) { |
| 382 | return carrier_; |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 383 | } |
| 384 | if (!serving_operator_.GetCode().empty()) { |
| 385 | return "cellular_" + serving_operator_.GetCode(); |
| 386 | } |
| 387 | return base::StringPrintf("GSMNetwork%u", friendly_service_name_id_++); |
| 388 | } |
| 389 | |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 390 | void CellularCapabilityGSM::SetHomeProvider() { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 391 | VLOG(2) << __func__ << "(IMSI: " << imsi_ |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 392 | << " SPN: " << spn_ << ")"; |
| 393 | // TODO(petkov): The test for NULL provider_db should be done by |
| 394 | // mobile_provider_lookup_best_match. |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 395 | if (imsi_.empty() || !cellular()->provider_db()) { |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 396 | return; |
| 397 | } |
| 398 | mobile_provider *provider = |
| 399 | mobile_provider_lookup_best_match( |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 400 | cellular()->provider_db(), spn_.c_str(), imsi_.c_str()); |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 401 | if (!provider) { |
| 402 | VLOG(2) << "GSM provider not found."; |
| 403 | return; |
| 404 | } |
| 405 | home_provider_ = provider; |
| 406 | Cellular::Operator oper; |
| 407 | if (provider->networks) { |
| 408 | oper.SetCode(provider->networks[0]); |
| 409 | } |
| 410 | if (provider->country) { |
| 411 | oper.SetCountry(provider->country); |
| 412 | } |
| 413 | if (spn_.empty()) { |
| 414 | const char *name = mobile_provider_get_name(provider); |
| 415 | if (name) { |
| 416 | oper.SetName(name); |
| 417 | } |
| 418 | } else { |
| 419 | oper.SetName(spn_); |
| 420 | } |
| 421 | cellular()->set_home_provider(oper); |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 422 | InitAPNList(); |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 423 | } |
| 424 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 425 | void CellularCapabilityGSM::UpdateOperatorInfo() { |
| 426 | VLOG(2) << __func__; |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 427 | const string &network_id = serving_operator_.GetCode(); |
| 428 | if (!network_id.empty()) { |
| 429 | VLOG(2) << "Looking up network id: " << network_id; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 430 | mobile_provider *provider = |
| 431 | mobile_provider_lookup_by_network(cellular()->provider_db(), |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 432 | network_id.c_str()); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 433 | if (provider) { |
| 434 | const char *provider_name = mobile_provider_get_name(provider); |
| 435 | if (provider_name && *provider_name) { |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 436 | serving_operator_.SetName(provider_name); |
| 437 | if (provider->country) { |
| 438 | serving_operator_.SetCountry(provider->country); |
| 439 | } |
| 440 | VLOG(2) << "Operator name: " << serving_operator_.GetName() |
| 441 | << ", country: " << serving_operator_.GetCountry(); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 442 | } |
| 443 | } else { |
| 444 | VLOG(2) << "GSM provider not found."; |
| 445 | } |
| 446 | } |
| 447 | UpdateServingOperator(); |
| 448 | } |
| 449 | |
| 450 | void CellularCapabilityGSM::UpdateServingOperator() { |
| 451 | VLOG(2) << __func__; |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 452 | if (cellular()->service().get()) { |
Darin Petkov | 9cb0268 | 2012-01-28 00:17:38 +0100 | [diff] [blame] | 453 | cellular()->service()->SetServingOperator(serving_operator_); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 454 | } |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 455 | } |
| 456 | |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame] | 457 | void CellularCapabilityGSM::InitAPNList() { |
| 458 | VLOG(2) << __func__; |
| 459 | if (!home_provider_) { |
| 460 | return; |
| 461 | } |
| 462 | apn_list_.clear(); |
| 463 | for (int i = 0; i < home_provider_->num_apns; ++i) { |
| 464 | Stringmap props; |
| 465 | mobile_apn *apn = home_provider_->apns[i]; |
| 466 | if (apn->value) { |
| 467 | props[flimflam::kApnProperty] = apn->value; |
| 468 | } |
| 469 | if (apn->username) { |
| 470 | props[flimflam::kApnUsernameProperty] = apn->username; |
| 471 | } |
| 472 | if (apn->password) { |
| 473 | props[flimflam::kApnPasswordProperty] = apn->password; |
| 474 | } |
| 475 | // Find the first localized and non-localized name, if any. |
| 476 | const localized_name *lname = NULL; |
| 477 | const localized_name *name = NULL; |
| 478 | for (int j = 0; j < apn->num_names; ++j) { |
| 479 | if (apn->names[j]->lang) { |
| 480 | if (!lname) { |
| 481 | lname = apn->names[j]; |
| 482 | } |
| 483 | } else if (!name) { |
| 484 | name = apn->names[j]; |
| 485 | } |
| 486 | } |
| 487 | if (name) { |
| 488 | props[flimflam::kApnNameProperty] = name->name; |
| 489 | } |
| 490 | if (lname) { |
| 491 | props[flimflam::kApnLocalizedNameProperty] = lname->name; |
| 492 | props[flimflam::kApnLanguageProperty] = lname->lang; |
| 493 | } |
| 494 | apn_list_.push_back(props); |
| 495 | } |
| 496 | cellular()->adaptor()->EmitStringmapsChanged( |
| 497 | flimflam::kCellularApnListProperty, apn_list_); |
| 498 | } |
| 499 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 500 | // always called from an async context |
| 501 | void CellularCapabilityGSM::Register(const ResultCallback &callback) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 502 | VLOG(2) << __func__ << " \"" << selected_network_ << "\""; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 503 | CHECK(!callback.is_null()); |
| 504 | Error error; |
| 505 | ResultCallback cb = Bind(&CellularCapabilityGSM::OnRegisterReply, |
| 506 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 507 | network_proxy_->Register(selected_network_, &error, cb, kTimeoutRegister); |
| 508 | if (error.IsFailure()) |
| 509 | callback.Run(error); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | void CellularCapabilityGSM::RegisterOnNetwork( |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 513 | const string &network_id, |
| 514 | Error *error, |
| 515 | const ResultCallback &callback) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 516 | VLOG(2) << __func__ << "(" << network_id << ")"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 517 | CHECK(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 518 | desired_network_ = network_id; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 519 | ResultCallback cb = Bind(&CellularCapabilityGSM::OnRegisterReply, |
| 520 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 521 | network_proxy_->Register(network_id, error, cb, kTimeoutRegister); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 522 | } |
| 523 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 524 | void CellularCapabilityGSM::OnRegisterReply(const ResultCallback &callback, |
| 525 | const Error &error) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 526 | VLOG(2) << __func__ << "(" << error << ")"; |
| 527 | |
| 528 | if (error.IsSuccess()) { |
| 529 | selected_network_ = desired_network_; |
| 530 | desired_network_.clear(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 531 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 532 | return; |
| 533 | } |
| 534 | // If registration on the desired network failed, |
| 535 | // try to register on the home network. |
| 536 | if (!desired_network_.empty()) { |
| 537 | desired_network_.clear(); |
| 538 | selected_network_.clear(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 539 | LOG(INFO) << "Couldn't register on selected network, trying home network"; |
| 540 | Register(callback); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 541 | return; |
| 542 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 543 | callback.Run(error); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 544 | } |
| 545 | |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 546 | bool CellularCapabilityGSM::IsRegistered() { |
| 547 | return (registration_state_ == MM_MODEM_GSM_NETWORK_REG_STATUS_HOME || |
| 548 | registration_state_ == MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING); |
| 549 | } |
| 550 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 551 | void CellularCapabilityGSM::RequirePIN( |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 552 | const std::string &pin, bool require, |
| 553 | Error *error, const ResultCallback &callback) { |
| 554 | CHECK(error); |
| 555 | card_proxy_->EnablePIN(pin, require, error, callback, kTimeoutDefault); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 556 | } |
| 557 | |
Darin Petkov | e5bc2cb | 2011-12-07 14:47:32 +0100 | [diff] [blame] | 558 | void CellularCapabilityGSM::EnterPIN(const string &pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 559 | Error *error, |
| 560 | const ResultCallback &callback) { |
| 561 | CHECK(error); |
| 562 | card_proxy_->SendPIN(pin, error, callback, kTimeoutDefault); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 563 | } |
| 564 | |
Darin Petkov | c64fe5e | 2012-01-11 12:46:13 +0100 | [diff] [blame] | 565 | void CellularCapabilityGSM::UnblockPIN(const string &unblock_code, |
| 566 | const string &pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 567 | Error *error, |
| 568 | const ResultCallback &callback) { |
| 569 | CHECK(error); |
| 570 | card_proxy_->SendPUK(unblock_code, pin, error, callback, kTimeoutDefault); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | void CellularCapabilityGSM::ChangePIN( |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 574 | const string &old_pin, const string &new_pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 575 | Error *error, const ResultCallback &callback) { |
| 576 | CHECK(error); |
| 577 | card_proxy_->ChangePIN(old_pin, new_pin, error, callback, kTimeoutDefault); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 578 | } |
| 579 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 580 | void CellularCapabilityGSM::Scan(Error *error, const ResultCallback &callback) { |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 581 | VLOG(2) << __func__; |
| 582 | // TODO(petkov): Defer scan requests if a scan is in progress already. |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 583 | CHECK(error); |
| 584 | ScanResultsCallback cb = Bind(&CellularCapabilityGSM::OnScanReply, |
| 585 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 586 | network_proxy_->Scan(error, cb, kTimeoutScan); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 587 | } |
| 588 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 589 | void CellularCapabilityGSM::OnScanReply(const ResultCallback &callback, |
| 590 | const GSMScanResults &results, |
| 591 | const Error &error) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 592 | VLOG(2) << __func__; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 593 | |
| 594 | // Error handling is weak. The current expectation is that on any |
| 595 | // error, found_networks_ should be cleared and a property change |
| 596 | // notification sent out. |
| 597 | // |
| 598 | // TODO(jglasgow): fix error handling |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 599 | found_networks_.clear(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 600 | if (!error.IsFailure()) { |
| 601 | for (GSMScanResults::const_iterator it = results.begin(); |
| 602 | it != results.end(); ++it) { |
| 603 | found_networks_.push_back(ParseScanResult(*it)); |
| 604 | } |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 605 | } |
Darin Petkov | b7828b0 | 2012-02-03 12:34:30 +0100 | [diff] [blame] | 606 | cellular()->adaptor()->EmitStringmapsChanged(flimflam::kFoundNetworksProperty, |
| 607 | found_networks_); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 608 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | Stringmap CellularCapabilityGSM::ParseScanResult(const GSMScanResult &result) { |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 612 | Stringmap parsed; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 613 | for (GSMScanResult::const_iterator it = result.begin(); |
| 614 | it != result.end(); ++it) { |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 615 | // TODO(petkov): Define these in system_api/service_constants.h. The |
| 616 | // numerical values are taken from 3GPP TS 27.007 Section 7.3. |
| 617 | static const char * const kStatusString[] = { |
| 618 | "unknown", |
| 619 | "available", |
| 620 | "current", |
| 621 | "forbidden", |
| 622 | }; |
| 623 | static const char * const kTechnologyString[] = { |
| 624 | flimflam::kNetworkTechnologyGsm, |
| 625 | "GSM Compact", |
| 626 | flimflam::kNetworkTechnologyUmts, |
| 627 | flimflam::kNetworkTechnologyEdge, |
| 628 | "HSDPA", |
| 629 | "HSUPA", |
| 630 | flimflam::kNetworkTechnologyHspa, |
| 631 | }; |
| 632 | VLOG(2) << "Network property: " << it->first << " = " << it->second; |
| 633 | if (it->first == kNetworkPropertyStatus) { |
| 634 | int status = 0; |
| 635 | if (base::StringToInt(it->second, &status) && |
| 636 | status >= 0 && |
| 637 | status < static_cast<int>(arraysize(kStatusString))) { |
| 638 | parsed[flimflam::kStatusProperty] = kStatusString[status]; |
| 639 | } else { |
| 640 | LOG(ERROR) << "Unexpected status value: " << it->second; |
| 641 | } |
| 642 | } else if (it->first == kNetworkPropertyID) { |
| 643 | parsed[flimflam::kNetworkIdProperty] = it->second; |
| 644 | } else if (it->first == kNetworkPropertyLongName) { |
| 645 | parsed[flimflam::kLongNameProperty] = it->second; |
| 646 | } else if (it->first == kNetworkPropertyShortName) { |
| 647 | parsed[flimflam::kShortNameProperty] = it->second; |
| 648 | } else if (it->first == kNetworkPropertyAccessTechnology) { |
| 649 | int tech = 0; |
| 650 | if (base::StringToInt(it->second, &tech) && |
| 651 | tech >= 0 && |
| 652 | tech < static_cast<int>(arraysize(kTechnologyString))) { |
| 653 | parsed[flimflam::kTechnologyProperty] = kTechnologyString[tech]; |
| 654 | } else { |
| 655 | LOG(ERROR) << "Unexpected technology value: " << it->second; |
| 656 | } |
| 657 | } else { |
| 658 | LOG(WARNING) << "Unknown network property ignored: " << it->first; |
| 659 | } |
| 660 | } |
| 661 | // If the long name is not available but the network ID is, look up the long |
| 662 | // name in the mobile provider database. |
| 663 | if ((!ContainsKey(parsed, flimflam::kLongNameProperty) || |
| 664 | parsed[flimflam::kLongNameProperty].empty()) && |
| 665 | ContainsKey(parsed, flimflam::kNetworkIdProperty)) { |
| 666 | mobile_provider *provider = |
| 667 | mobile_provider_lookup_by_network( |
| 668 | cellular()->provider_db(), |
| 669 | parsed[flimflam::kNetworkIdProperty].c_str()); |
| 670 | if (provider) { |
| 671 | const char *long_name = mobile_provider_get_name(provider); |
| 672 | if (long_name && *long_name) { |
| 673 | parsed[flimflam::kLongNameProperty] = long_name; |
| 674 | } |
| 675 | } |
| 676 | } |
| 677 | return parsed; |
| 678 | } |
| 679 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 680 | void CellularCapabilityGSM::SetAccessTechnology(uint32 access_technology) { |
| 681 | access_technology_ = access_technology; |
| 682 | if (cellular()->service().get()) { |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 683 | cellular()->service()->SetNetworkTechnology(GetNetworkTechnologyString()); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 684 | } |
| 685 | } |
| 686 | |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 687 | string CellularCapabilityGSM::GetNetworkTechnologyString() const { |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 688 | switch (access_technology_) { |
| 689 | case MM_MODEM_GSM_ACCESS_TECH_GSM: |
| 690 | case MM_MODEM_GSM_ACCESS_TECH_GSM_COMPACT: |
| 691 | return flimflam::kNetworkTechnologyGsm; |
| 692 | case MM_MODEM_GSM_ACCESS_TECH_GPRS: |
| 693 | return flimflam::kNetworkTechnologyGprs; |
| 694 | case MM_MODEM_GSM_ACCESS_TECH_EDGE: |
| 695 | return flimflam::kNetworkTechnologyEdge; |
| 696 | case MM_MODEM_GSM_ACCESS_TECH_UMTS: |
| 697 | return flimflam::kNetworkTechnologyUmts; |
| 698 | case MM_MODEM_GSM_ACCESS_TECH_HSDPA: |
| 699 | case MM_MODEM_GSM_ACCESS_TECH_HSUPA: |
| 700 | case MM_MODEM_GSM_ACCESS_TECH_HSPA: |
| 701 | return flimflam::kNetworkTechnologyHspa; |
| 702 | case MM_MODEM_GSM_ACCESS_TECH_HSPA_PLUS: |
| 703 | return flimflam::kNetworkTechnologyHspaPlus; |
| 704 | default: |
| 705 | break; |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 706 | } |
| 707 | return ""; |
| 708 | } |
| 709 | |
| 710 | string CellularCapabilityGSM::GetRoamingStateString() const { |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 711 | switch (registration_state_) { |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 712 | case MM_MODEM_GSM_NETWORK_REG_STATUS_HOME: |
| 713 | return flimflam::kRoamingStateHome; |
| 714 | case MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING: |
| 715 | return flimflam::kRoamingStateRoaming; |
| 716 | default: |
| 717 | break; |
| 718 | } |
| 719 | return flimflam::kRoamingStateUnknown; |
| 720 | } |
| 721 | |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 722 | void CellularCapabilityGSM::OnDBusPropertiesChanged( |
| 723 | const string &interface, |
| 724 | const DBusPropertiesMap &properties, |
| 725 | const vector<string> &/* invalidated_properties */) { |
| 726 | if (interface != MM_MODEM_INTERFACE) |
| 727 | return; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 728 | uint32 access_technology = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; |
| 729 | if (DBusProperties::GetUint32(properties, |
| 730 | kPropertyAccessTechnology, |
| 731 | &access_technology)) { |
| 732 | SetAccessTechnology(access_technology); |
| 733 | } |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 734 | bool emit = false; |
| 735 | uint32 locks = 0; |
| 736 | if (DBusProperties::GetUint32( |
| 737 | properties, kPropertyEnabledFacilityLocks, &locks)) { |
| 738 | sim_lock_status_.enabled = locks & MM_MODEM_GSM_FACILITY_SIM; |
| 739 | emit = true; |
| 740 | } |
| 741 | if (DBusProperties::GetString( |
| 742 | properties, kPropertyUnlockRequired, &sim_lock_status_.lock_type)) { |
| 743 | emit = true; |
| 744 | } |
| 745 | if (DBusProperties::GetUint32( |
| 746 | properties, kPropertyUnlockRetries, &sim_lock_status_.retries_left)) { |
| 747 | emit = true; |
| 748 | } |
| 749 | if (emit) { |
| 750 | cellular()->adaptor()->EmitKeyValueStoreChanged( |
| 751 | flimflam::kSIMLockStatusProperty, SimLockStatusToProperty(NULL)); |
| 752 | } |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 753 | } |
| 754 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 755 | void CellularCapabilityGSM::OnNetworkModeSignal(uint32 /*mode*/) { |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 756 | // TODO(petkov): Implement this. |
| 757 | NOTIMPLEMENTED(); |
| 758 | } |
| 759 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 760 | void CellularCapabilityGSM::OnRegistrationInfoSignal( |
| 761 | uint32 status, const string &operator_code, const string &operator_name) { |
| 762 | VLOG(2) << __func__ << ": regstate=" << status |
| 763 | << ", opercode=" << operator_code |
| 764 | << ", opername=" << operator_name; |
| 765 | registration_state_ = status; |
| 766 | serving_operator_.SetCode(operator_code); |
| 767 | serving_operator_.SetName(operator_name); |
| 768 | UpdateOperatorInfo(); |
| 769 | cellular()->HandleNewRegistrationState(); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 770 | } |
| 771 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 772 | void CellularCapabilityGSM::OnSignalQualitySignal(uint32 quality) { |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 773 | cellular()->HandleNewSignalQuality(quality); |
| 774 | } |
| 775 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 776 | void CellularCapabilityGSM::OnGetRegistrationInfoReply( |
| 777 | uint32 status, const string &operator_code, const string &operator_name, |
| 778 | const Error &error) { |
| 779 | if (error.IsSuccess()) |
| 780 | OnRegistrationInfoSignal(status, operator_code, operator_name); |
| 781 | } |
| 782 | |
| 783 | void CellularCapabilityGSM::OnGetSignalQualityReply(uint32 quality, |
| 784 | const Error &error) { |
| 785 | if (error.IsSuccess()) |
| 786 | OnSignalQualitySignal(quality); |
| 787 | } |
| 788 | |
| 789 | void CellularCapabilityGSM::OnGetIMEIReply(const ResultCallback &callback, |
| 790 | const string &imei, |
| 791 | const Error &error) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 792 | if (error.IsSuccess()) { |
| 793 | VLOG(2) << "IMEI: " << imei; |
| 794 | imei_ = imei; |
| 795 | } else { |
| 796 | VLOG(2) << "GetIMEI failed - " << error; |
| 797 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 798 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 799 | } |
| 800 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 801 | void CellularCapabilityGSM::OnGetIMSIReply(const ResultCallback &callback, |
| 802 | const string &imsi, |
| 803 | const Error &error) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 804 | if (error.IsSuccess()) { |
| 805 | VLOG(2) << "IMSI: " << imsi; |
| 806 | imsi_ = imsi; |
| 807 | SetHomeProvider(); |
| 808 | } else { |
| 809 | VLOG(2) << "GetIMSI failed - " << error; |
| 810 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 811 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 812 | } |
| 813 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 814 | void CellularCapabilityGSM::OnGetSPNReply(const ResultCallback &callback, |
| 815 | const string &spn, |
| 816 | const Error &error) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 817 | if (error.IsSuccess()) { |
| 818 | VLOG(2) << "SPN: " << spn; |
| 819 | spn_ = spn; |
| 820 | SetHomeProvider(); |
| 821 | } else { |
| 822 | VLOG(2) << "GetSPN failed - " << error; |
| 823 | } |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 824 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 825 | } |
| 826 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 827 | void CellularCapabilityGSM::OnGetMSISDNReply(const ResultCallback &callback, |
| 828 | const string &msisdn, |
| 829 | const Error &error) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 830 | if (error.IsSuccess()) { |
| 831 | VLOG(2) << "MSISDN: " << msisdn; |
| 832 | mdn_ = msisdn; |
| 833 | } else { |
| 834 | VLOG(2) << "GetMSISDN failed - " << error; |
| 835 | } |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 836 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 837 | } |
| 838 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 839 | } // namespace shill |