blob: dfa5d24c8b9f371ad6fab639c85e439ef39e539d [file] [log] [blame]
Darin Petkovc64fe5e2012-01-11 12:46:13 +01001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Darin Petkovdaf43862011-10-27 11:37:28 +02002// 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 Glasgow4c0724a2012-04-17 15:47:40 -04007#include <string>
8#include <vector>
9
Eric Shienbrood3e20a232012-02-16 11:35:56 -050010#include <base/bind.h>
Eric Shienbrood3e20a232012-02-16 11:35:56 -050011#include <base/stl_util.h>
Ben Chana0ddf462014-02-06 11:32:42 -080012#include <base/strings/string_number_conversions.h>
13#include <base/strings/stringprintf.h>
Darin Petkov20c13ec2011-11-09 15:07:15 +010014#include <chromeos/dbus/service_constants.h>
15#include <mm/mm-modem.h>
Darin Petkovdaf43862011-10-27 11:37:28 +020016
Darin Petkov3cfbf212011-11-21 16:02:09 +010017#include "shill/adaptor_interfaces.h"
Darin Petkovae0c64e2011-11-15 15:50:27 +010018#include "shill/cellular_service.h"
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050019#include "shill/error.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070020#include "shill/logging.h"
Darin Petkov721ac932011-11-16 15:43:09 +010021#include "shill/property_accessor.h"
Darin Petkovdaf43862011-10-27 11:37:28 +020022#include "shill/proxy_factory.h"
23
Eric Shienbrood3e20a232012-02-16 11:35:56 -050024using base::Bind;
Darin Petkovb05315f2011-11-07 10:14:25 +010025using std::string;
Jason Glasgow4c0724a2012-04-17 15:47:40 -040026using std::vector;
Darin Petkovb05315f2011-11-07 10:14:25 +010027
Darin Petkovdaf43862011-10-27 11:37:28 +020028namespace shill {
29
Darin Petkovac635a82012-01-10 16:51:58 +010030// static
Darin Petkov1272a432011-11-10 15:53:37 +010031const char CellularCapabilityGSM::kNetworkPropertyAccessTechnology[] =
32 "access-tech";
33const char CellularCapabilityGSM::kNetworkPropertyID[] = "operator-num";
34const char CellularCapabilityGSM::kNetworkPropertyLongName[] = "operator-long";
35const char CellularCapabilityGSM::kNetworkPropertyShortName[] =
36 "operator-short";
37const char CellularCapabilityGSM::kNetworkPropertyStatus[] = "status";
Darin Petkovae0c64e2011-11-15 15:50:27 +010038const char CellularCapabilityGSM::kPhoneNumber[] = "*99#";
39const char CellularCapabilityGSM::kPropertyAccessTechnology[] =
40 "AccessTechnology";
Darin Petkov63138a92012-02-06 14:09:15 +010041const char CellularCapabilityGSM::kPropertyEnabledFacilityLocks[] =
42 "EnabledFacilityLocks";
Darin Petkov721ac932011-11-16 15:43:09 +010043const char CellularCapabilityGSM::kPropertyUnlockRequired[] = "UnlockRequired";
44const char CellularCapabilityGSM::kPropertyUnlockRetries[] = "UnlockRetries";
Darin Petkov1272a432011-11-10 15:53:37 +010045
Ben Chanc89b9282012-12-12 14:00:29 -080046const int CellularCapabilityGSM::kGetIMSIRetryLimit = 40;
47const int64 CellularCapabilityGSM::kGetIMSIRetryDelayMilliseconds = 500;
Gary Morain82a31a02012-08-02 18:03:32 -070048
49
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050050CellularCapabilityGSM::CellularCapabilityGSM(Cellular *cellular,
Thieu Lece4483e2013-01-23 15:12:03 -080051 ProxyFactory *proxy_factory,
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070052 ModemInfo *modem_info)
53 : CellularCapabilityClassic(cellular, proxy_factory, modem_info),
Eric Shienbrood3e20a232012-02-16 11:35:56 -050054 weak_ptr_factory_(this),
Prathmesh Prabhuafe63662014-05-20 11:03:58 -070055 mobile_operator_info_(new MobileOperatorInfo(cellular->dispatcher(),
56 "ParseScanResult")),
Darin Petkov184c54e2011-11-15 12:44:39 +010057 registration_state_(MM_MODEM_GSM_NETWORK_REG_STATUS_UNKNOWN),
Darin Petkovae0c64e2011-11-15 15:50:27 +010058 access_technology_(MM_MODEM_GSM_ACCESS_TECH_UNKNOWN),
Prathmesh Prabhu99ec94d2013-11-22 10:43:37 -080059 home_provider_info_(NULL),
Gary Morain82a31a02012-08-02 18:03:32 -070060 get_imsi_retries_(0),
Prathmesh Prabhu49ffffd2014-01-09 18:28:55 -080061 get_imsi_retry_delay_milliseconds_(kGetIMSIRetryDelayMilliseconds) {
Ben Chanfad4a0b2012-04-18 15:49:59 -070062 SLOG(Cellular, 2) << "Cellular capability constructed: GSM";
Prathmesh Prabhuafe63662014-05-20 11:03:58 -070063 mobile_operator_info_->Init();
mukesh agrawalbebf1b82013-04-23 15:06:33 -070064 HelpRegisterConstDerivedKeyValueStore(
Ben Chan7ea768e2013-09-20 15:08:40 -070065 kSIMLockStatusProperty, &CellularCapabilityGSM::SimLockStatusToProperty);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -080066 this->cellular()->set_scanning_supported(true);
Ben Chan3ecdf822012-08-06 12:29:23 -070067
68 // TODO(benchan): This is a hack to initialize the GSM card proxy for GetIMSI
69 // before InitProxies is called. There are side-effects of calling InitProxies
70 // before the device is enabled. It's better to refactor InitProxies such that
71 // proxies can be created when the cellular device/capability is constructed,
72 // but callbacks for DBus signal updates are not set up until the device is
73 // enabled.
74 card_proxy_.reset(
75 proxy_factory->CreateModemGSMCardProxy(cellular->dbus_path(),
76 cellular->dbus_owner()));
77 // TODO(benchan): To allow unit testing using a mock proxy without further
78 // complicating the code, the test proxy factory is set up to return a NULL
79 // pointer when CellularCapabilityGSM is constructed. Refactor the code to
80 // avoid this hack.
81 if (card_proxy_.get())
82 InitProperties();
Darin Petkov1272a432011-11-10 15:53:37 +010083}
Darin Petkovdaf43862011-10-27 11:37:28 +020084
Ben Chanf98f00e2014-02-05 14:48:43 -080085CellularCapabilityGSM::~CellularCapabilityGSM() {}
86
87string CellularCapabilityGSM::GetTypeString() const {
88 return kTechnologyFamilyGsm;
89}
90
Darin Petkov63138a92012-02-06 14:09:15 +010091KeyValueStore CellularCapabilityGSM::SimLockStatusToProperty(Error */*error*/) {
92 KeyValueStore status;
Ben Chan7ea768e2013-09-20 15:08:40 -070093 status.SetBool(kSIMLockEnabledProperty, sim_lock_status_.enabled);
94 status.SetString(kSIMLockTypeProperty, sim_lock_status_.lock_type);
95 status.SetUint(kSIMLockRetriesLeftProperty, sim_lock_status_.retries_left);
Darin Petkov63138a92012-02-06 14:09:15 +010096 return status;
Darin Petkov721ac932011-11-16 15:43:09 +010097}
98
mukesh agrawalbebf1b82013-04-23 15:06:33 -070099void CellularCapabilityGSM::HelpRegisterConstDerivedKeyValueStore(
Darin Petkov721ac932011-11-16 15:43:09 +0100100 const string &name,
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700101 KeyValueStore(CellularCapabilityGSM::*get)(Error *error)) {
Darin Petkov63138a92012-02-06 14:09:15 +0100102 cellular()->mutable_store()->RegisterDerivedKeyValueStore(
Darin Petkov721ac932011-11-16 15:43:09 +0100103 name,
Darin Petkov63138a92012-02-06 14:09:15 +0100104 KeyValueStoreAccessor(
105 new CustomAccessor<CellularCapabilityGSM, KeyValueStore>(
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700106 this, get, NULL)));
Darin Petkov721ac932011-11-16 15:43:09 +0100107}
108
Eric Shienbrood9a245532012-03-07 14:20:39 -0500109void CellularCapabilityGSM::InitProxies() {
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400110 CellularCapabilityClassic::InitProxies();
Ben Chan3ecdf822012-08-06 12:29:23 -0700111 // TODO(benchan): Remove this check after refactoring the proxy
112 // initialization.
113 if (!card_proxy_.get()) {
114 card_proxy_.reset(
115 proxy_factory()->CreateModemGSMCardProxy(cellular()->dbus_path(),
116 cellular()->dbus_owner()));
117 }
Darin Petkov184c54e2011-11-15 12:44:39 +0100118 network_proxy_.reset(
Eric Shienbrood9a245532012-03-07 14:20:39 -0500119 proxy_factory()->CreateModemGSMNetworkProxy(cellular()->dbus_path(),
Darin Petkovdaf43862011-10-27 11:37:28 +0200120 cellular()->dbus_owner()));
Eric Shienbrood9a245532012-03-07 14:20:39 -0500121 network_proxy_->set_signal_quality_callback(
122 Bind(&CellularCapabilityGSM::OnSignalQualitySignal,
123 weak_ptr_factory_.GetWeakPtr()));
124 network_proxy_->set_network_mode_callback(
125 Bind(&CellularCapabilityGSM::OnNetworkModeSignal,
126 weak_ptr_factory_.GetWeakPtr()));
127 network_proxy_->set_registration_info_callback(
128 Bind(&CellularCapabilityGSM::OnRegistrationInfoSignal,
129 weak_ptr_factory_.GetWeakPtr()));
Darin Petkovdaf43862011-10-27 11:37:28 +0200130}
131
Ben Chan3ecdf822012-08-06 12:29:23 -0700132void CellularCapabilityGSM::InitProperties() {
133 CellularTaskList *tasks = new CellularTaskList();
134 ResultCallback cb_ignore_error =
135 Bind(&CellularCapabilityGSM::StepCompletedCallback,
136 weak_ptr_factory_.GetWeakPtr(), ResultCallback(), true, tasks);
Ben Chanbd3aee82012-10-16 23:52:04 -0700137 // Chrome checks if a SIM is present before allowing the modem to be enabled,
138 // so shill needs to obtain IMSI, as an indicator of SIM presence, even
139 // before the device is enabled.
Ben Chan3ecdf822012-08-06 12:29:23 -0700140 tasks->push_back(Bind(&CellularCapabilityGSM::GetIMSI,
141 weak_ptr_factory_.GetWeakPtr(), cb_ignore_error));
142 RunNextStep(tasks);
143}
144
Eric Shienbrood9a245532012-03-07 14:20:39 -0500145void CellularCapabilityGSM::StartModem(Error *error,
146 const ResultCallback &callback) {
147 InitProxies();
148
149 CellularTaskList *tasks = new CellularTaskList();
150 ResultCallback cb =
151 Bind(&CellularCapabilityGSM::StepCompletedCallback,
Thieu Le923006b2012-04-05 16:32:58 -0700152 weak_ptr_factory_.GetWeakPtr(), callback, false, tasks);
153 ResultCallback cb_ignore_error =
154 Bind(&CellularCapabilityGSM::StepCompletedCallback,
155 weak_ptr_factory_.GetWeakPtr(), callback, true, tasks);
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400156 if (!cellular()->IsUnderlyingDeviceEnabled())
157 tasks->push_back(Bind(&CellularCapabilityGSM::EnableModem,
158 weak_ptr_factory_.GetWeakPtr(), cb));
159 // If we're within range of the home network, the modem will try to
160 // register once it's enabled, or may be already registered if we
161 // started out enabled.
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800162 if (!IsUnderlyingDeviceRegistered() &&
163 !cellular()->selected_network().empty())
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400164 tasks->push_back(Bind(&CellularCapabilityGSM::Register,
165 weak_ptr_factory_.GetWeakPtr(), cb));
Eric Shienbrood9a245532012-03-07 14:20:39 -0500166 tasks->push_back(Bind(&CellularCapabilityGSM::GetIMEI,
167 weak_ptr_factory_.GetWeakPtr(), cb));
Gary Morain82a31a02012-08-02 18:03:32 -0700168 get_imsi_retries_ = 0;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500169 tasks->push_back(Bind(&CellularCapabilityGSM::GetIMSI,
170 weak_ptr_factory_.GetWeakPtr(), cb));
171 tasks->push_back(Bind(&CellularCapabilityGSM::GetSPN,
Thieu Le923006b2012-04-05 16:32:58 -0700172 weak_ptr_factory_.GetWeakPtr(), cb_ignore_error));
Eric Shienbrood9a245532012-03-07 14:20:39 -0500173 tasks->push_back(Bind(&CellularCapabilityGSM::GetMSISDN,
Thieu Le923006b2012-04-05 16:32:58 -0700174 weak_ptr_factory_.GetWeakPtr(), cb_ignore_error));
Eric Shienbrood9a245532012-03-07 14:20:39 -0500175 tasks->push_back(Bind(&CellularCapabilityGSM::GetProperties,
176 weak_ptr_factory_.GetWeakPtr(), cb));
177 tasks->push_back(Bind(&CellularCapabilityGSM::GetModemInfo,
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400178 weak_ptr_factory_.GetWeakPtr(), cb_ignore_error));
Eric Shienbrood9a245532012-03-07 14:20:39 -0500179 tasks->push_back(Bind(&CellularCapabilityGSM::FinishEnable,
180 weak_ptr_factory_.GetWeakPtr(), cb));
181
182 RunNextStep(tasks);
183}
184
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400185bool CellularCapabilityGSM::IsUnderlyingDeviceRegistered() const {
186 switch (cellular()->modem_state()) {
Ben Chan7b7d63d2013-10-18 14:53:05 -0700187 case Cellular::kModemStateFailed:
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400188 case Cellular::kModemStateUnknown:
189 case Cellular::kModemStateDisabled:
190 case Cellular::kModemStateInitializing:
191 case Cellular::kModemStateLocked:
192 case Cellular::kModemStateDisabling:
193 case Cellular::kModemStateEnabling:
194 case Cellular::kModemStateEnabled:
195 return false;
196 case Cellular::kModemStateSearching:
197 case Cellular::kModemStateRegistered:
198 case Cellular::kModemStateDisconnecting:
199 case Cellular::kModemStateConnecting:
200 case Cellular::kModemStateConnected:
201 return true;
202 }
203 return false;
204}
205
Eric Shienbrood9a245532012-03-07 14:20:39 -0500206void CellularCapabilityGSM::ReleaseProxies() {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700207 SLOG(Cellular, 2) << __func__;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400208 CellularCapabilityClassic::ReleaseProxies();
Darin Petkov721ac932011-11-16 15:43:09 +0100209 card_proxy_.reset();
210 network_proxy_.reset();
211}
212
Darin Petkov5f316f62011-11-18 12:10:26 +0100213void CellularCapabilityGSM::OnServiceCreated() {
Ben Chan7ea768e2013-09-20 15:08:40 -0700214 cellular()->service()->SetActivationState(kActivationStateActivated);
Darin Petkovae0c64e2011-11-15 15:50:27 +0100215}
216
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400217// Create the list of APNs to try, in the following order:
218// - last APN that resulted in a successful connection attempt on the
219// current network (if any)
220// - the APN, if any, that was set by the user
221// - the list of APNs found in the mobile broadband provider DB for the
222// home provider associated with the current SIM
223// - as a last resort, attempt to connect with no APN
224void CellularCapabilityGSM::SetupApnTryList() {
225 apn_try_list_.clear();
226
227 DCHECK(cellular()->service().get());
228 const Stringmap *apn_info = cellular()->service()->GetLastGoodApn();
229 if (apn_info)
230 apn_try_list_.push_back(*apn_info);
231
232 apn_info = cellular()->service()->GetUserSpecifiedApn();
233 if (apn_info)
234 apn_try_list_.push_back(*apn_info);
235
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800236 apn_try_list_.insert(apn_try_list_.end(),
237 cellular()->apn_list().begin(),
238 cellular()->apn_list().end());
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400239}
240
Darin Petkovae0c64e2011-11-15 15:50:27 +0100241void CellularCapabilityGSM::SetupConnectProperties(
242 DBusPropertiesMap *properties) {
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400243 SetupApnTryList();
244 FillConnectPropertyMap(properties);
245}
246
247void CellularCapabilityGSM::FillConnectPropertyMap(
248 DBusPropertiesMap *properties) {
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500249 (*properties)[kConnectPropertyPhoneNumber].writer().append_string(
Darin Petkovae0c64e2011-11-15 15:50:27 +0100250 kPhoneNumber);
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400251
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400252 if (!AllowRoaming())
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400253 (*properties)[kConnectPropertyHomeOnly].writer().append_bool(true);
254
255 if (!apn_try_list_.empty()) {
256 // Leave the APN at the front of the list, so that it can be recorded
257 // if the connect attempt succeeds.
258 Stringmap apn_info = apn_try_list_.front();
Ben Chan7ea768e2013-09-20 15:08:40 -0700259 SLOG(Cellular, 2) << __func__ << ": Using APN " << apn_info[kApnProperty];
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400260 (*properties)[kConnectPropertyApn].writer().append_string(
Ben Chan7ea768e2013-09-20 15:08:40 -0700261 apn_info[kApnProperty].c_str());
262 if (ContainsKey(apn_info, kApnUsernameProperty))
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400263 (*properties)[kConnectPropertyApnUsername].writer().append_string(
Ben Chan7ea768e2013-09-20 15:08:40 -0700264 apn_info[kApnUsernameProperty].c_str());
265 if (ContainsKey(apn_info, kApnPasswordProperty))
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400266 (*properties)[kConnectPropertyApnPassword].writer().append_string(
Ben Chan7ea768e2013-09-20 15:08:40 -0700267 apn_info[kApnPasswordProperty].c_str());
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400268 }
269}
270
Nathan Williamsb54974f2012-04-19 11:16:30 -0400271void CellularCapabilityGSM::Connect(const DBusPropertiesMap &properties,
272 Error *error,
273 const ResultCallback &callback) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700274 SLOG(Cellular, 2) << __func__;
Nathan Williamsb54974f2012-04-19 11:16:30 -0400275 ResultCallback cb = Bind(&CellularCapabilityGSM::OnConnectReply,
276 weak_ptr_factory_.GetWeakPtr(),
277 callback);
278 simple_proxy_->Connect(properties, error, cb, kTimeoutConnect);
279}
280
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400281void CellularCapabilityGSM::OnConnectReply(const ResultCallback &callback,
282 const Error &error) {
Thieu Leb5954a22012-05-18 10:37:34 -0700283 CellularServiceRefPtr service = cellular()->service();
284 if (!service) {
285 // The service could have been deleted before our Connect() request
286 // completes if the modem was enabled and then quickly disabled.
287 apn_try_list_.clear();
288 } else if (error.IsFailure()) {
289 service->ClearLastGoodApn();
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400290 // The APN that was just tried (and failed) is still at the
291 // front of the list, about to be removed. If the list is empty
292 // after that, try one last time without an APN. This may succeed
293 // with some modems in some cases.
294 if (error.type() == Error::kInvalidApn && !apn_try_list_.empty()) {
295 apn_try_list_.pop_front();
Ben Chanfad4a0b2012-04-18 15:49:59 -0700296 SLOG(Cellular, 2) << "Connect failed with invalid APN, "
297 << apn_try_list_.size() << " remaining APNs to try";
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400298 DBusPropertiesMap props;
299 FillConnectPropertyMap(&props);
300 Error error;
301 Connect(props, &error, callback);
302 return;
303 }
304 } else if (!apn_try_list_.empty()) {
Thieu Leb5954a22012-05-18 10:37:34 -0700305 service->SetLastGoodApn(apn_try_list_.front());
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400306 apn_try_list_.clear();
307 }
Nathan Williamsb54974f2012-04-19 11:16:30 -0400308 if (!callback.is_null())
309 callback.Run(error);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400310}
311
312bool CellularCapabilityGSM::AllowRoaming() {
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800313 return cellular()->provider_requires_roaming() || allow_roaming_property();
Darin Petkovae0c64e2011-11-15 15:50:27 +0100314}
315
Eric Shienbrood9a245532012-03-07 14:20:39 -0500316// always called from an async context
317void CellularCapabilityGSM::GetIMEI(const ResultCallback &callback) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700318 SLOG(Cellular, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500319 CHECK(!callback.is_null());
320 Error error;
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800321 if (cellular()->imei().empty()) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500322 GSMIdentifierCallback cb = Bind(&CellularCapabilityGSM::OnGetIMEIReply,
323 weak_ptr_factory_.GetWeakPtr(), callback);
324 card_proxy_->GetIMEI(&error, cb, kTimeoutDefault);
325 if (error.IsFailure())
326 callback.Run(error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500327 } else {
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800328 SLOG(Cellular, 2) << "Already have IMEI " << cellular()->imei();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500329 callback.Run(error);
Darin Petkovcb547732011-11-09 13:55:26 +0100330 }
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500331}
332
Eric Shienbrood9a245532012-03-07 14:20:39 -0500333// always called from an async context
334void CellularCapabilityGSM::GetIMSI(const ResultCallback &callback) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700335 SLOG(Cellular, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500336 CHECK(!callback.is_null());
337 Error error;
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800338 if (cellular()->imsi().empty()) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500339 GSMIdentifierCallback cb = Bind(&CellularCapabilityGSM::OnGetIMSIReply,
340 weak_ptr_factory_.GetWeakPtr(),
341 callback);
342 card_proxy_->GetIMSI(&error, cb, kTimeoutDefault);
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700343 if (error.IsFailure()) {
Prathmesh Prabhu8599e052014-04-25 14:20:22 -0700344 cellular()->home_provider_info()->Reset();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500345 callback.Run(error);
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700346 }
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500347 } else {
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800348 SLOG(Cellular, 2) << "Already have IMSI " << cellular()->imsi();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500349 callback.Run(error);
Darin Petkovcb547732011-11-09 13:55:26 +0100350 }
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500351}
352
Eric Shienbrood9a245532012-03-07 14:20:39 -0500353// always called from an async context
354void CellularCapabilityGSM::GetSPN(const ResultCallback &callback) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700355 SLOG(Cellular, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500356 CHECK(!callback.is_null());
357 Error error;
Darin Petkovae0c64e2011-11-15 15:50:27 +0100358 if (spn_.empty()) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500359 GSMIdentifierCallback cb = Bind(&CellularCapabilityGSM::OnGetSPNReply,
360 weak_ptr_factory_.GetWeakPtr(),
361 callback);
362 card_proxy_->GetSPN(&error, cb, kTimeoutDefault);
363 if (error.IsFailure())
364 callback.Run(error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500365 } else {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700366 SLOG(Cellular, 2) << "Already have SPN " << spn_;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500367 callback.Run(error);
Darin Petkovcb547732011-11-09 13:55:26 +0100368 }
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500369}
370
Eric Shienbrood9a245532012-03-07 14:20:39 -0500371// always called from an async context
372void CellularCapabilityGSM::GetMSISDN(const ResultCallback &callback) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700373 SLOG(Cellular, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500374 CHECK(!callback.is_null());
375 Error error;
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800376 string mdn = cellular()->mdn();
377 if (mdn.empty()) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500378 GSMIdentifierCallback cb = Bind(&CellularCapabilityGSM::OnGetMSISDNReply,
379 weak_ptr_factory_.GetWeakPtr(),
380 callback);
381 card_proxy_->GetMSISDN(&error, cb, kTimeoutDefault);
382 if (error.IsFailure())
383 callback.Run(error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500384 } else {
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800385 SLOG(Cellular, 2) << "Already have MSISDN " << mdn;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500386 callback.Run(error);
Darin Petkovcb547732011-11-09 13:55:26 +0100387 }
388}
389
Darin Petkov3e509242011-11-10 14:46:44 +0100390void CellularCapabilityGSM::GetSignalQuality() {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700391 SLOG(Cellular, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500392 SignalQualityCallback callback =
393 Bind(&CellularCapabilityGSM::OnGetSignalQualityReply,
394 weak_ptr_factory_.GetWeakPtr());
395 network_proxy_->GetSignalQuality(NULL, callback, kTimeoutDefault);
Darin Petkov3e509242011-11-10 14:46:44 +0100396}
397
Eric Shienbrood9a245532012-03-07 14:20:39 -0500398void CellularCapabilityGSM::GetRegistrationState() {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700399 SLOG(Cellular, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500400 RegistrationInfoCallback callback =
401 Bind(&CellularCapabilityGSM::OnGetRegistrationInfoReply,
402 weak_ptr_factory_.GetWeakPtr());
403 network_proxy_->GetRegistrationInfo(NULL, callback, kTimeoutDefault);
Darin Petkov184c54e2011-11-15 12:44:39 +0100404}
405
Eric Shienbrood9a245532012-03-07 14:20:39 -0500406void CellularCapabilityGSM::GetProperties(const ResultCallback &callback) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700407 SLOG(Cellular, 2) << __func__;
Darin Petkov63138a92012-02-06 14:09:15 +0100408
Paul Stewartee6b3d72013-07-12 16:07:51 -0700409 // TODO(petkov): Switch to asynchronous calls (crbug.com/200687).
Darin Petkov184c54e2011-11-15 12:44:39 +0100410 uint32 tech = network_proxy_->AccessTechnology();
Darin Petkovae0c64e2011-11-15 15:50:27 +0100411 SetAccessTechnology(tech);
Ben Chanfad4a0b2012-04-18 15:49:59 -0700412 SLOG(Cellular, 2) << "GSM AccessTechnology: " << tech;
Darin Petkov63138a92012-02-06 14:09:15 +0100413
Paul Stewartee6b3d72013-07-12 16:07:51 -0700414 // TODO(petkov): Switch to asynchronous calls (crbug.com/200687).
Darin Petkov63138a92012-02-06 14:09:15 +0100415 uint32 locks = card_proxy_->EnabledFacilityLocks();
416 sim_lock_status_.enabled = locks & MM_MODEM_GSM_FACILITY_SIM;
Ben Chanfad4a0b2012-04-18 15:49:59 -0700417 SLOG(Cellular, 2) << "GSM EnabledFacilityLocks: " << locks;
Darin Petkov63138a92012-02-06 14:09:15 +0100418
Eric Shienbrood9a245532012-03-07 14:20:39 -0500419 callback.Run(Error());
Darin Petkov184c54e2011-11-15 12:44:39 +0100420}
421
Eric Shienbrood9a245532012-03-07 14:20:39 -0500422// always called from an async context
423void CellularCapabilityGSM::Register(const ResultCallback &callback) {
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800424 SLOG(Cellular, 2) << __func__ << " \"" << cellular()->selected_network()
425 << "\"";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500426 CHECK(!callback.is_null());
427 Error error;
428 ResultCallback cb = Bind(&CellularCapabilityGSM::OnRegisterReply,
429 weak_ptr_factory_.GetWeakPtr(), callback);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800430 network_proxy_->Register(cellular()->selected_network(), &error, cb,
431 kTimeoutRegister);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500432 if (error.IsFailure())
433 callback.Run(error);
Darin Petkov184c54e2011-11-15 12:44:39 +0100434}
435
436void CellularCapabilityGSM::RegisterOnNetwork(
Eric Shienbrood9a245532012-03-07 14:20:39 -0500437 const string &network_id,
438 Error *error,
439 const ResultCallback &callback) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700440 SLOG(Cellular, 2) << __func__ << "(" << network_id << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500441 CHECK(error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500442 desired_network_ = network_id;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500443 ResultCallback cb = Bind(&CellularCapabilityGSM::OnRegisterReply,
444 weak_ptr_factory_.GetWeakPtr(), callback);
445 network_proxy_->Register(network_id, error, cb, kTimeoutRegister);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500446}
447
Eric Shienbrood9a245532012-03-07 14:20:39 -0500448void CellularCapabilityGSM::OnRegisterReply(const ResultCallback &callback,
449 const Error &error) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700450 SLOG(Cellular, 2) << __func__ << "(" << error << ")";
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500451
452 if (error.IsSuccess()) {
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800453 cellular()->set_selected_network(desired_network_);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500454 desired_network_.clear();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500455 callback.Run(error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500456 return;
457 }
458 // If registration on the desired network failed,
459 // try to register on the home network.
460 if (!desired_network_.empty()) {
461 desired_network_.clear();
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800462 cellular()->set_selected_network("");
Eric Shienbrood9a245532012-03-07 14:20:39 -0500463 LOG(INFO) << "Couldn't register on selected network, trying home network";
464 Register(callback);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500465 return;
466 }
Eric Shienbrood9a245532012-03-07 14:20:39 -0500467 callback.Run(error);
Darin Petkov184c54e2011-11-15 12:44:39 +0100468}
469
Ben Chan31ce5642013-11-14 13:37:40 -0800470bool CellularCapabilityGSM::IsRegistered() const {
Darin Petkovb72cf402011-11-22 14:51:39 +0100471 return (registration_state_ == MM_MODEM_GSM_NETWORK_REG_STATUS_HOME ||
472 registration_state_ == MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING);
473}
474
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400475void CellularCapabilityGSM::SetUnregistered(bool searching) {
476 // If we're already in some non-registered state, don't override that
477 if (registration_state_ == MM_MODEM_GSM_NETWORK_REG_STATUS_HOME ||
478 registration_state_ == MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING) {
479 registration_state_ =
480 (searching ? MM_MODEM_GSM_NETWORK_REG_STATUS_SEARCHING :
481 MM_MODEM_GSM_NETWORK_REG_STATUS_IDLE);
482 }
483}
484
Darin Petkovb05315f2011-11-07 10:14:25 +0100485void CellularCapabilityGSM::RequirePIN(
Eric Shienbrood9a245532012-03-07 14:20:39 -0500486 const std::string &pin, bool require,
487 Error *error, const ResultCallback &callback) {
488 CHECK(error);
489 card_proxy_->EnablePIN(pin, require, error, callback, kTimeoutDefault);
Darin Petkovb05315f2011-11-07 10:14:25 +0100490}
491
Darin Petkove5bc2cb2011-12-07 14:47:32 +0100492void CellularCapabilityGSM::EnterPIN(const string &pin,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500493 Error *error,
494 const ResultCallback &callback) {
495 CHECK(error);
496 card_proxy_->SendPIN(pin, error, callback, kTimeoutDefault);
Darin Petkovb05315f2011-11-07 10:14:25 +0100497}
498
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100499void CellularCapabilityGSM::UnblockPIN(const string &unblock_code,
500 const string &pin,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500501 Error *error,
502 const ResultCallback &callback) {
503 CHECK(error);
504 card_proxy_->SendPUK(unblock_code, pin, error, callback, kTimeoutDefault);
Darin Petkovb05315f2011-11-07 10:14:25 +0100505}
506
507void CellularCapabilityGSM::ChangePIN(
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500508 const string &old_pin, const string &new_pin,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500509 Error *error, const ResultCallback &callback) {
510 CHECK(error);
511 card_proxy_->ChangePIN(old_pin, new_pin, error, callback, kTimeoutDefault);
Darin Petkovb05315f2011-11-07 10:14:25 +0100512}
513
Prathmesh Prabhu49ffffd2014-01-09 18:28:55 -0800514void CellularCapabilityGSM::Scan(Error *error,
515 const ResultStringmapsCallback &callback) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500516 ScanResultsCallback cb = Bind(&CellularCapabilityGSM::OnScanReply,
517 weak_ptr_factory_.GetWeakPtr(), callback);
518 network_proxy_->Scan(error, cb, kTimeoutScan);
Darin Petkov1272a432011-11-10 15:53:37 +0100519}
520
Prathmesh Prabhu49ffffd2014-01-09 18:28:55 -0800521void CellularCapabilityGSM::OnScanReply(
522 const ResultStringmapsCallback &callback,
523 const GSMScanResults &results,
524 const Error &error) {
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800525 Stringmaps found_networks;
Prathmesh Prabhu49ffffd2014-01-09 18:28:55 -0800526 for (const auto &result : results)
527 found_networks.push_back(ParseScanResult(result));
528 callback.Run(found_networks, error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500529}
530
531Stringmap CellularCapabilityGSM::ParseScanResult(const GSMScanResult &result) {
Darin Petkov1272a432011-11-10 15:53:37 +0100532 Stringmap parsed;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500533 for (GSMScanResult::const_iterator it = result.begin();
534 it != result.end(); ++it) {
Darin Petkov1272a432011-11-10 15:53:37 +0100535 // TODO(petkov): Define these in system_api/service_constants.h. The
536 // numerical values are taken from 3GPP TS 27.007 Section 7.3.
537 static const char * const kStatusString[] = {
538 "unknown",
539 "available",
540 "current",
541 "forbidden",
542 };
543 static const char * const kTechnologyString[] = {
Ben Chan7ea768e2013-09-20 15:08:40 -0700544 kNetworkTechnologyGsm,
Darin Petkov1272a432011-11-10 15:53:37 +0100545 "GSM Compact",
Ben Chan7ea768e2013-09-20 15:08:40 -0700546 kNetworkTechnologyUmts,
547 kNetworkTechnologyEdge,
Darin Petkov1272a432011-11-10 15:53:37 +0100548 "HSDPA",
549 "HSUPA",
Ben Chan7ea768e2013-09-20 15:08:40 -0700550 kNetworkTechnologyHspa,
Darin Petkov1272a432011-11-10 15:53:37 +0100551 };
Ben Chanfad4a0b2012-04-18 15:49:59 -0700552 SLOG(Cellular, 2) << "Network property: " << it->first << " = "
553 << it->second;
Darin Petkov1272a432011-11-10 15:53:37 +0100554 if (it->first == kNetworkPropertyStatus) {
555 int status = 0;
556 if (base::StringToInt(it->second, &status) &&
557 status >= 0 &&
558 status < static_cast<int>(arraysize(kStatusString))) {
Ben Chan7ea768e2013-09-20 15:08:40 -0700559 parsed[kStatusProperty] = kStatusString[status];
Darin Petkov1272a432011-11-10 15:53:37 +0100560 } else {
561 LOG(ERROR) << "Unexpected status value: " << it->second;
562 }
563 } else if (it->first == kNetworkPropertyID) {
Ben Chan7ea768e2013-09-20 15:08:40 -0700564 parsed[kNetworkIdProperty] = it->second;
Darin Petkov1272a432011-11-10 15:53:37 +0100565 } else if (it->first == kNetworkPropertyLongName) {
Ben Chan7ea768e2013-09-20 15:08:40 -0700566 parsed[kLongNameProperty] = it->second;
Darin Petkov1272a432011-11-10 15:53:37 +0100567 } else if (it->first == kNetworkPropertyShortName) {
Ben Chan7ea768e2013-09-20 15:08:40 -0700568 parsed[kShortNameProperty] = it->second;
Darin Petkov1272a432011-11-10 15:53:37 +0100569 } else if (it->first == kNetworkPropertyAccessTechnology) {
570 int tech = 0;
571 if (base::StringToInt(it->second, &tech) &&
572 tech >= 0 &&
573 tech < static_cast<int>(arraysize(kTechnologyString))) {
Ben Chan7ea768e2013-09-20 15:08:40 -0700574 parsed[kTechnologyProperty] = kTechnologyString[tech];
Darin Petkov1272a432011-11-10 15:53:37 +0100575 } else {
576 LOG(ERROR) << "Unexpected technology value: " << it->second;
577 }
578 } else {
579 LOG(WARNING) << "Unknown network property ignored: " << it->first;
580 }
581 }
582 // If the long name is not available but the network ID is, look up the long
583 // name in the mobile provider database.
Ben Chan7ea768e2013-09-20 15:08:40 -0700584 if ((!ContainsKey(parsed, kLongNameProperty) ||
585 parsed[kLongNameProperty].empty()) &&
586 ContainsKey(parsed, kNetworkIdProperty)) {
Prathmesh Prabhuafe63662014-05-20 11:03:58 -0700587 mobile_operator_info_->Reset();
588 mobile_operator_info_->UpdateMCCMNC(parsed[kNetworkIdProperty]);
589 if (mobile_operator_info_->IsMobileNetworkOperatorKnown() &&
590 !mobile_operator_info_->operator_name().empty()) {
591 parsed[kLongNameProperty] = mobile_operator_info_->operator_name();
Darin Petkov1272a432011-11-10 15:53:37 +0100592 }
593 }
594 return parsed;
595}
596
Darin Petkovae0c64e2011-11-15 15:50:27 +0100597void CellularCapabilityGSM::SetAccessTechnology(uint32 access_technology) {
598 access_technology_ = access_technology;
599 if (cellular()->service().get()) {
Darin Petkovb72cf402011-11-22 14:51:39 +0100600 cellular()->service()->SetNetworkTechnology(GetNetworkTechnologyString());
Darin Petkovae0c64e2011-11-15 15:50:27 +0100601 }
602}
603
Darin Petkov20c13ec2011-11-09 15:07:15 +0100604string CellularCapabilityGSM::GetNetworkTechnologyString() const {
Darin Petkovb72cf402011-11-22 14:51:39 +0100605 switch (access_technology_) {
606 case MM_MODEM_GSM_ACCESS_TECH_GSM:
607 case MM_MODEM_GSM_ACCESS_TECH_GSM_COMPACT:
Ben Chan7ea768e2013-09-20 15:08:40 -0700608 return kNetworkTechnologyGsm;
Darin Petkovb72cf402011-11-22 14:51:39 +0100609 case MM_MODEM_GSM_ACCESS_TECH_GPRS:
Ben Chan7ea768e2013-09-20 15:08:40 -0700610 return kNetworkTechnologyGprs;
Darin Petkovb72cf402011-11-22 14:51:39 +0100611 case MM_MODEM_GSM_ACCESS_TECH_EDGE:
Ben Chan7ea768e2013-09-20 15:08:40 -0700612 return kNetworkTechnologyEdge;
Darin Petkovb72cf402011-11-22 14:51:39 +0100613 case MM_MODEM_GSM_ACCESS_TECH_UMTS:
Ben Chan7ea768e2013-09-20 15:08:40 -0700614 return kNetworkTechnologyUmts;
Darin Petkovb72cf402011-11-22 14:51:39 +0100615 case MM_MODEM_GSM_ACCESS_TECH_HSDPA:
616 case MM_MODEM_GSM_ACCESS_TECH_HSUPA:
617 case MM_MODEM_GSM_ACCESS_TECH_HSPA:
Ben Chan7ea768e2013-09-20 15:08:40 -0700618 return kNetworkTechnologyHspa;
Darin Petkovb72cf402011-11-22 14:51:39 +0100619 case MM_MODEM_GSM_ACCESS_TECH_HSPA_PLUS:
Ben Chan7ea768e2013-09-20 15:08:40 -0700620 return kNetworkTechnologyHspaPlus;
Darin Petkovb72cf402011-11-22 14:51:39 +0100621 default:
622 break;
Darin Petkov20c13ec2011-11-09 15:07:15 +0100623 }
624 return "";
625}
626
627string CellularCapabilityGSM::GetRoamingStateString() const {
Darin Petkov184c54e2011-11-15 12:44:39 +0100628 switch (registration_state_) {
Darin Petkov20c13ec2011-11-09 15:07:15 +0100629 case MM_MODEM_GSM_NETWORK_REG_STATUS_HOME:
Ben Chan7ea768e2013-09-20 15:08:40 -0700630 return kRoamingStateHome;
Darin Petkov20c13ec2011-11-09 15:07:15 +0100631 case MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING:
Ben Chan7ea768e2013-09-20 15:08:40 -0700632 return kRoamingStateRoaming;
Darin Petkov20c13ec2011-11-09 15:07:15 +0100633 default:
634 break;
635 }
Ben Chan7ea768e2013-09-20 15:08:40 -0700636 return kRoamingStateUnknown;
Darin Petkov20c13ec2011-11-09 15:07:15 +0100637}
638
Jason Glasgow4c0724a2012-04-17 15:47:40 -0400639void CellularCapabilityGSM::OnDBusPropertiesChanged(
640 const string &interface,
641 const DBusPropertiesMap &properties,
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400642 const vector<string> &invalidated_properties) {
643 CellularCapabilityClassic::OnDBusPropertiesChanged(interface,
644 properties,
645 invalidated_properties);
646 if (interface == MM_MODEM_GSM_NETWORK_INTERFACE) {
647 uint32 access_technology = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN;
648 if (DBusProperties::GetUint32(properties,
649 kPropertyAccessTechnology,
650 &access_technology)) {
651 SetAccessTechnology(access_technology);
652 }
Gary Morainbaeefdf2012-04-30 14:53:35 -0700653 } else {
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400654 bool emit = false;
Gary Morainbaeefdf2012-04-30 14:53:35 -0700655 if (interface == MM_MODEM_GSM_CARD_INTERFACE) {
656 uint32 locks = 0;
657 if (DBusProperties::GetUint32(
658 properties, kPropertyEnabledFacilityLocks, &locks)) {
659 sim_lock_status_.enabled = locks & MM_MODEM_GSM_FACILITY_SIM;
660 emit = true;
661 }
662 } else if (interface == MM_MODEM_INTERFACE) {
663 if (DBusProperties::GetString(properties, kPropertyUnlockRequired,
664 &sim_lock_status_.lock_type)) {
665 emit = true;
666 }
667 if (DBusProperties::GetUint32(properties, kPropertyUnlockRetries,
668 &sim_lock_status_.retries_left)) {
669 emit = true;
670 }
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400671 }
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800672 // TODO(pprabhu) Rename |emit| to |sim_present| after |sim_lock_status|
673 // moves to cellular.
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400674 if (emit) {
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800675 cellular()->set_sim_present(true);
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400676 cellular()->adaptor()->EmitKeyValueStoreChanged(
Ben Chan7ea768e2013-09-20 15:08:40 -0700677 kSIMLockStatusProperty, SimLockStatusToProperty(NULL));
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400678 }
Darin Petkov63138a92012-02-06 14:09:15 +0100679 }
Darin Petkovae0c64e2011-11-15 15:50:27 +0100680}
681
Eric Shienbrood9a245532012-03-07 14:20:39 -0500682void CellularCapabilityGSM::OnNetworkModeSignal(uint32 /*mode*/) {
Darin Petkov184c54e2011-11-15 12:44:39 +0100683 // TODO(petkov): Implement this.
684 NOTIMPLEMENTED();
685}
686
Eric Shienbrood9a245532012-03-07 14:20:39 -0500687void CellularCapabilityGSM::OnRegistrationInfoSignal(
688 uint32 status, const string &operator_code, const string &operator_name) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700689 SLOG(Cellular, 2) << __func__ << ": regstate=" << status
690 << ", opercode=" << operator_code
691 << ", opername=" << operator_name;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500692 registration_state_ = status;
693 serving_operator_.SetCode(operator_code);
694 serving_operator_.SetName(operator_name);
Prathmesh Prabhu8599e052014-04-25 14:20:22 -0700695 cellular()->serving_operator_info()->UpdateMCCMNC(operator_code);
696 cellular()->serving_operator_info()->UpdateOperatorName(operator_name);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500697 cellular()->HandleNewRegistrationState();
Darin Petkov184c54e2011-11-15 12:44:39 +0100698}
699
Eric Shienbrood9a245532012-03-07 14:20:39 -0500700void CellularCapabilityGSM::OnSignalQualitySignal(uint32 quality) {
Darin Petkov184c54e2011-11-15 12:44:39 +0100701 cellular()->HandleNewSignalQuality(quality);
702}
703
Eric Shienbrood9a245532012-03-07 14:20:39 -0500704void CellularCapabilityGSM::OnGetRegistrationInfoReply(
705 uint32 status, const string &operator_code, const string &operator_name,
706 const Error &error) {
707 if (error.IsSuccess())
708 OnRegistrationInfoSignal(status, operator_code, operator_name);
709}
710
711void CellularCapabilityGSM::OnGetSignalQualityReply(uint32 quality,
712 const Error &error) {
713 if (error.IsSuccess())
714 OnSignalQualitySignal(quality);
715}
716
717void CellularCapabilityGSM::OnGetIMEIReply(const ResultCallback &callback,
718 const string &imei,
719 const Error &error) {
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500720 if (error.IsSuccess()) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700721 SLOG(Cellular, 2) << "IMEI: " << imei;
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800722 cellular()->set_imei(imei);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500723 } else {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700724 SLOG(Cellular, 2) << "GetIMEI failed - " << error;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500725 }
Eric Shienbrood9a245532012-03-07 14:20:39 -0500726 callback.Run(error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500727}
728
Eric Shienbrood9a245532012-03-07 14:20:39 -0500729void CellularCapabilityGSM::OnGetIMSIReply(const ResultCallback &callback,
730 const string &imsi,
731 const Error &error) {
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500732 if (error.IsSuccess()) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700733 SLOG(Cellular, 2) << "IMSI: " << imsi;
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800734 cellular()->set_imsi(imsi);
735 cellular()->set_sim_present(true);
Prathmesh Prabhu8599e052014-04-25 14:20:22 -0700736 cellular()->home_provider_info()->UpdateIMSI(imsi);
Gary Morain82a31a02012-08-02 18:03:32 -0700737 callback.Run(error);
Arman Uguray29505ec2013-09-12 20:37:53 -0700738 } else if (!sim_lock_status_.lock_type.empty()) {
739 SLOG(Cellular, 2) << "GetIMSI failed - SIM lock in place.";
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800740 cellular()->set_sim_present(true);
Arman Uguray29505ec2013-09-12 20:37:53 -0700741 callback.Run(error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500742 } else {
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800743 cellular()->set_sim_present(false);
Gary Morain82a31a02012-08-02 18:03:32 -0700744 if (get_imsi_retries_++ < kGetIMSIRetryLimit) {
745 SLOG(Cellular, 2) << "GetIMSI failed - " << error << ". Retrying";
746 base::Callback<void(void)> retry_get_imsi_cb =
747 Bind(&CellularCapabilityGSM::GetIMSI,
748 weak_ptr_factory_.GetWeakPtr(), callback);
749 cellular()->dispatcher()->PostDelayedTask(
750 retry_get_imsi_cb,
751 get_imsi_retry_delay_milliseconds_);
752 } else {
753 LOG(INFO) << "GetIMSI failed - " << error;
Prathmesh Prabhu8599e052014-04-25 14:20:22 -0700754 cellular()->home_provider_info()->Reset();
Gary Morain82a31a02012-08-02 18:03:32 -0700755 callback.Run(error);
756 }
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500757 }
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500758}
759
Eric Shienbrood9a245532012-03-07 14:20:39 -0500760void CellularCapabilityGSM::OnGetSPNReply(const ResultCallback &callback,
761 const string &spn,
762 const Error &error) {
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500763 if (error.IsSuccess()) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700764 SLOG(Cellular, 2) << "SPN: " << spn;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500765 spn_ = spn;
Prathmesh Prabhu8599e052014-04-25 14:20:22 -0700766 cellular()->home_provider_info()->UpdateOperatorName(spn);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500767 } else {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700768 SLOG(Cellular, 2) << "GetSPN failed - " << error;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500769 }
Thieu Le923006b2012-04-05 16:32:58 -0700770 callback.Run(error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500771}
772
Eric Shienbrood9a245532012-03-07 14:20:39 -0500773void CellularCapabilityGSM::OnGetMSISDNReply(const ResultCallback &callback,
774 const string &msisdn,
775 const Error &error) {
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500776 if (error.IsSuccess()) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700777 SLOG(Cellular, 2) << "MSISDN: " << msisdn;
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800778 cellular()->set_mdn(msisdn);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500779 } else {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700780 SLOG(Cellular, 2) << "GetMSISDN failed - " << error;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500781 }
Thieu Le923006b2012-04-05 16:32:58 -0700782 callback.Run(error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500783}
784
Darin Petkovdaf43862011-10-27 11:37:28 +0200785} // namespace shill