blob: af148bd4a41928d8a0595463ca282ef4425b4d2c [file] [log] [blame]
Arman Uguray72fab6a2013-01-10 19:32:42 -08001// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
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_universal_cdma.h"
6
7#include <chromeos/dbus/service_constants.h>
8#include <base/stringprintf.h>
9#include <base/string_number_conversions.h>
10#include <base/string_util.h>
11
12#include "shill/cellular_operator_info.h"
13#include "shill/dbus_properties_proxy_interface.h"
Arman Uguray0a3e2792013-01-17 16:31:50 -080014#include "shill/error.h"
Arman Uguray72fab6a2013-01-10 19:32:42 -080015#include "shill/logging.h"
Arman Uguray0a3e2792013-01-17 16:31:50 -080016#include "shill/pending_activation_store.h"
Arman Uguray72fab6a2013-01-10 19:32:42 -080017#include "shill/proxy_factory.h"
18
19#ifdef MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN
20#error "Do not include mm-modem.h"
21#endif
22
23using base::UintToString;
24
25using std::string;
26using std::vector;
27
28namespace shill {
29
30namespace {
31
Arman Ugurayc9673062013-05-13 21:21:53 -070032const char kPhoneNumber[] = "#777";
33const char kPropertyConnectNumber[] = "number";
34
Arman Uguray72fab6a2013-01-10 19:32:42 -080035string FormattedSID(const string &sid) {
36 return "[SID=" + sid + "]";
37}
38
39} // namespace
40
41// static
42unsigned int
43CellularCapabilityUniversalCDMA::friendly_service_name_id_cdma_ = 0;
44
45CellularCapabilityUniversalCDMA::CellularCapabilityUniversalCDMA(
46 Cellular *cellular,
47 ProxyFactory *proxy_factory,
48 ModemInfo *modem_info)
49 : CellularCapabilityUniversal(cellular,
50 proxy_factory,
51 modem_info),
Arman Uguray0a3e2792013-01-17 16:31:50 -080052 weak_cdma_ptr_factory_(this),
53 activation_state_(MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED),
Arman Uguray72fab6a2013-01-10 19:32:42 -080054 cdma_1x_registration_state_(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN),
55 cdma_evdo_registration_state_(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN),
56 nid_(0),
57 sid_(0) {
58 SLOG(Cellular, 2) << "Cellular capability constructed: Universal CDMA";
Arman Uguray0a3e2792013-01-17 16:31:50 -080059 // TODO(armansito): Update PRL for activation over cellular.
Arman Uguray72fab6a2013-01-10 19:32:42 -080060 // See crbug.com/197330.
61}
62
63void CellularCapabilityUniversalCDMA::InitProxies() {
64 SLOG(Cellular, 2) << __func__;
65 modem_cdma_proxy_.reset(
66 proxy_factory()->CreateMM1ModemModemCdmaProxy(cellular()->dbus_path(),
67 cellular()->dbus_owner()));
Arman Uguray0a3e2792013-01-17 16:31:50 -080068 modem_cdma_proxy_->set_activation_state_callback(
69 Bind(&CellularCapabilityUniversalCDMA::OnActivationStateChangedSignal,
70 weak_cdma_ptr_factory_.GetWeakPtr()));
Arman Uguray72fab6a2013-01-10 19:32:42 -080071 CellularCapabilityUniversal::InitProxies();
72}
73
74void CellularCapabilityUniversalCDMA::ReleaseProxies() {
75 SLOG(Cellular, 2) << __func__;
76 modem_cdma_proxy_.reset();
77 CellularCapabilityUniversal::ReleaseProxies();
78}
79
80void CellularCapabilityUniversalCDMA::Activate(
81 const string &carrier,
82 Error *error,
83 const ResultCallback &callback) {
Arman Uguray0a3e2792013-01-17 16:31:50 -080084 // Currently activation over the cellular network is not supported using
85 // ModemManager-next. Service activation is currently carried through over
86 // non-cellular networks and only the final step of the OTA activation
87 // procedure ("automatic activation") is performed by this class.
Arman Uguray72fab6a2013-01-10 19:32:42 -080088 OnUnsupportedOperation(__func__, error);
89}
90
91void CellularCapabilityUniversalCDMA::CompleteActivation(Error *error) {
Arman Uguray0a3e2792013-01-17 16:31:50 -080092 SLOG(Cellular, 2) << __func__;
93 if (cellular()->state() < Cellular::kStateEnabled) {
94 Error::PopulateAndLog(error, Error::kInvalidArguments,
95 "Unable to activate in state " +
96 Cellular::GetStateString(cellular()->state()));
97 return;
98 }
99 ActivateAutomatic();
Arman Uguray72fab6a2013-01-10 19:32:42 -0800100}
101
Arman Uguray0a3e2792013-01-17 16:31:50 -0800102void CellularCapabilityUniversalCDMA::ActivateAutomatic() {
103 if (activation_code_.empty()) {
104 SLOG(Cellular, 2) << "OTA activation cannot be run in the presence of no "
105 << "activation code.";
106 return;
107 }
108 PendingActivationStore::State state =
109 modem_info()->pending_activation_store()->GetActivationState(
110 PendingActivationStore::kIdentifierMEID, meid());
111 if (state == PendingActivationStore::kStatePending) {
112 SLOG(Cellular, 2) << "There's already a pending activation. Ignoring.";
113 return;
114 }
115 if (state == PendingActivationStore::kStateActivated) {
116 SLOG(Cellular, 2) << "A call to OTA activation has already completed "
117 << "successfully. Ignoring.";
118 return;
119 }
120
121 // Mark as pending activation, so that shill can recover if anything fails
122 // during OTA activation.
123 modem_info()->pending_activation_store()->SetActivationState(
124 PendingActivationStore::kIdentifierMEID,
125 meid(),
126 PendingActivationStore::kStatePending);
127
128 // Initiate OTA activation.
129 ResultCallback activation_callback =
130 Bind(&CellularCapabilityUniversalCDMA::OnActivateReply,
131 weak_cdma_ptr_factory_.GetWeakPtr(),
132 ResultCallback());
Arman Ugurayf2b4a342013-05-23 18:26:52 -0700133
Arman Uguray0a3e2792013-01-17 16:31:50 -0800134 Error error;
135 modem_cdma_proxy_->Activate(
136 activation_code_, &error, activation_callback, kTimeoutActivate);
137}
138
139void CellularCapabilityUniversalCDMA::UpdatePendingActivationState() {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800140 SLOG(Cellular, 2) << __func__;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800141 if (IsActivated()) {
142 SLOG(Cellular, 3) << "CDMA service activated. Clear store.";
143 modem_info()->pending_activation_store()->RemoveEntry(
144 PendingActivationStore::kIdentifierMEID, meid());
145 return;
146 }
147 PendingActivationStore::State state =
148 modem_info()->pending_activation_store()->GetActivationState(
149 PendingActivationStore::kIdentifierMEID, meid());
150 if (IsActivating() && state != PendingActivationStore::kStateFailureRetry) {
151 SLOG(Cellular, 3) << "OTA activation in progress. Nothing to do.";
152 return;
153 }
154 switch (state) {
155 case PendingActivationStore::kStateFailureRetry:
156 SLOG(Cellular, 3) << "OTA activation failed. Scheduling a retry.";
157 cellular()->dispatcher()->PostTask(
158 Bind(&CellularCapabilityUniversalCDMA::ActivateAutomatic,
159 weak_cdma_ptr_factory_.GetWeakPtr()));
160 break;
161 case PendingActivationStore::kStateActivated:
162 SLOG(Cellular, 3) << "OTA Activation has completed successfully. "
163 << "Waiting for activation state update to finalize.";
164 break;
165 default:
166 break;
167 }
168}
169
170bool CellularCapabilityUniversalCDMA::IsServiceActivationRequired() const {
171 // If there is no online payment portal information, it's safer to assume
172 // the service does not require activation.
173 if (!modem_info()->cellular_operator_info())
174 return false;
175
176 const CellularService::OLP *olp =
177 modem_info()->cellular_operator_info()->GetOLPBySID(UintToString(sid_));
178 if (!olp)
179 return false;
180
181 // We could also use the MDN to determine whether or not the service is
182 // activated, however, the CDMA ActivatonState property is a more absolute
183 // and fine-grained indicator of activation status.
184 return (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED);
185}
186
187bool CellularCapabilityUniversalCDMA::IsActivated() const {
188 return (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800189}
190
191void CellularCapabilityUniversalCDMA::OnServiceCreated() {
192 SLOG(Cellular, 2) << __func__;
193 // TODO (armansito): Set storage identifier here based on the superclass
194 // implementation.
Arman Uguray0a3e2792013-01-17 16:31:50 -0800195 UpdateServiceActivationStateProperty();
Arman Uguray72fab6a2013-01-10 19:32:42 -0800196 UpdateServingOperator();
Arman Uguray0a3e2792013-01-17 16:31:50 -0800197 HandleNewActivationStatus(MM_CDMA_ACTIVATION_ERROR_NONE);
198 UpdatePendingActivationState();
Arman Uguray72fab6a2013-01-10 19:32:42 -0800199 UpdateOLP();
200}
201
Arman Uguray0a3e2792013-01-17 16:31:50 -0800202void CellularCapabilityUniversalCDMA::UpdateServiceActivationStateProperty() {
203 bool activation_required = IsServiceActivationRequired();
204 cellular()->service()->SetActivateOverNonCellularNetwork(activation_required);
205 string activation_state;
206 if (IsActivating())
207 activation_state = flimflam::kActivationStateActivating;
208 else if (activation_required)
209 activation_state = flimflam::kActivationStateNotActivated;
210 else
211 activation_state = flimflam::kActivationStateActivated;
212 cellular()->service()->SetActivationState(activation_state);
213}
214
Arman Uguray72fab6a2013-01-10 19:32:42 -0800215void CellularCapabilityUniversalCDMA::UpdateOLP() {
Ben Chan07193fd2013-07-12 22:10:55 -0700216 SLOG(Cellular, 2) << __func__;
217
218 const CellularOperatorInfo *cellular_operator_info =
219 modem_info()->cellular_operator_info();
220 if (!cellular_operator_info)
221 return;
222
223 string sid_string = UintToString(sid_);
224 const CellularOperatorInfo::CellularOperator *cellular_operator =
225 cellular_operator_info->GetCellularOperatorBySID(sid_string);
226 if (!cellular_operator)
Arman Uguray72fab6a2013-01-10 19:32:42 -0800227 return;
228
229 const CellularService::OLP *result =
Ben Chan07193fd2013-07-12 22:10:55 -0700230 cellular_operator_info->GetOLPBySID(sid_string);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800231 if (!result)
232 return;
233
234 CellularService::OLP olp;
235 olp.CopyFrom(*result);
236 string post_data = olp.GetPostData();
237 ReplaceSubstringsAfterOffset(&post_data, 0, "${esn}", esn());
Ben Chan07193fd2013-07-12 22:10:55 -0700238 ReplaceSubstringsAfterOffset(&post_data, 0, "${mdn}",
239 GetMdnForOLP(*cellular_operator));
Arman Uguray72fab6a2013-01-10 19:32:42 -0800240 ReplaceSubstringsAfterOffset(&post_data, 0, "${meid}", meid());
241 olp.SetPostData(post_data);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800242 if (cellular()->service().get())
243 cellular()->service()->SetOLP(olp);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800244}
245
246void CellularCapabilityUniversalCDMA::GetProperties() {
247 SLOG(Cellular, 2) << __func__;
248 CellularCapabilityUniversal::GetProperties();
249
250 scoped_ptr<DBusPropertiesProxyInterface> properties_proxy(
251 proxy_factory()->CreateDBusPropertiesProxy(cellular()->dbus_path(),
252 cellular()->dbus_owner()));
253 DBusPropertiesMap properties(
254 properties_proxy->GetAll(MM_DBUS_INTERFACE_MODEM_MODEMCDMA));
255 OnModemCDMAPropertiesChanged(properties, vector<string>());
256}
257
258string CellularCapabilityUniversalCDMA::CreateFriendlyServiceName() {
259 SLOG(Cellular, 2) << __func__ << ": " << GetRoamingStateString();
260
261 if (provider_.GetCode().empty()) {
262 UpdateOperatorInfo();
263 }
264
265 string name = provider_.GetName();
266 if (!name.empty()) {
267 // TODO(armansito): We may need to show the provider name in a
268 // specific way if roaming.
269 return name;
270 }
271
272 string code = provider_.GetCode();
273 if (!code.empty()) {
274 return "cellular_sid_" + code;
275 }
276
277 return base::StringPrintf("CDMANetwork%u", friendly_service_name_id_cdma_++);
278}
279
280void CellularCapabilityUniversalCDMA::UpdateOperatorInfo() {
281 SLOG(Cellular, 2) << __func__;
282
283 if (sid_ == 0 || !modem_info()->cellular_operator_info()) {
284 SLOG(Cellular, 2) << "No provider is currently available.";
285 provider_.SetCode("");
286 return;
287 }
288
289 string sid = UintToString(sid_);
290 const CellularOperatorInfo::CellularOperator *provider =
291 modem_info()->cellular_operator_info()->GetCellularOperatorBySID(sid);
292 if (!provider) {
293 SLOG(Cellular, 2) << "CDMA provider with "
294 << FormattedSID(sid)
295 << " not found.";
296 return;
297 }
298
299 if (!provider->name_list().empty()) {
300 provider_.SetName(provider->name_list()[0].name);
301 }
302 provider_.SetCode(sid);
303 provider_.SetCountry(provider->country());
304
Arman Uguray0a3e2792013-01-17 16:31:50 -0800305 activation_code_ = provider->activation_code();
306
Arman Uguray72fab6a2013-01-10 19:32:42 -0800307 // TODO(armansito): The CDMA interface only returns information about the
308 // current serving carrier, so for now both the home provider and the
309 // serving operator will be the same in case of roaming. We should figure
310 // out if there is a way to (and whether or not it is necessary to)
311 // determine if we're roaming.
312 cellular()->set_home_provider(provider_);
313
314 UpdateServingOperator();
315}
316
317void CellularCapabilityUniversalCDMA::UpdateServingOperator() {
318 SLOG(Cellular, 2) << __func__;
319 if (cellular()->service().get()) {
320 cellular()->service()->SetServingOperator(cellular()->home_provider());
321 }
322}
323
Arman Uguray0a3e2792013-01-17 16:31:50 -0800324void CellularCapabilityUniversalCDMA::OnActivationStateChangedSignal(
325 uint32 activation_state,
326 uint32 activation_error,
327 const DBusPropertiesMap &status_changes) {
328 SLOG(Cellular, 2) << __func__;
329
330 activation_state_ =
331 static_cast<MMModemCdmaActivationState>(activation_state);
332
333 string value;
334 if (DBusProperties::GetString(status_changes, "mdn", &value))
335 set_mdn(value);
336 if (DBusProperties::GetString(status_changes, "min", &value))
337 set_min(value);
338
339 SLOG(Cellular, 2) << "Activation state: "
340 << GetActivationStateString(activation_state_);
341
342 HandleNewActivationStatus(activation_error);
343 UpdatePendingActivationState();
344}
345
346void CellularCapabilityUniversalCDMA::OnActivateReply(
347 const ResultCallback &callback,
348 const Error &error) {
349 SLOG(Cellular, 2) << __func__;
350 if (error.IsSuccess()) {
351 LOG(INFO) << "Activation completed successfully.";
352 modem_info()->pending_activation_store()->SetActivationState(
353 PendingActivationStore::kIdentifierMEID,
354 meid(),
355 PendingActivationStore::kStateActivated);
356 } else {
357 LOG(ERROR) << "Activation failed with error: " << error;
358 modem_info()->pending_activation_store()->SetActivationState(
359 PendingActivationStore::kIdentifierMEID,
360 meid(),
361 PendingActivationStore::kStateFailureRetry);
362 }
363 UpdatePendingActivationState();
Arman Ugurayf2b4a342013-05-23 18:26:52 -0700364
365 // CellularCapabilityUniversalCDMA::ActivateAutomatic passes a dummy
366 // ResultCallback when it calls Activate on the proxy object, in which case
367 // |callback.is_null()| will return true.
368 if (!callback.is_null())
369 callback.Run(error);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800370}
371
372void CellularCapabilityUniversalCDMA::HandleNewActivationStatus(uint32 error) {
373 SLOG(Cellular, 2) << __func__ << "(" << error << ")";
374 if (!cellular()->service().get()) {
375 LOG(ERROR) << "In " << __func__ << "(): service is null.";
376 return;
377 }
378 SLOG(Cellular, 2) << "Activation State: " << activation_state_;
379 cellular()->service()->SetActivationState(
380 GetActivationStateString(activation_state_));
381 cellular()->service()->set_error(GetActivationErrorString(error));
382 UpdateOLP();
383}
384
385// static
386string CellularCapabilityUniversalCDMA::GetActivationStateString(
387 uint32 state) {
388 switch (state) {
389 case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED:
390 return flimflam::kActivationStateActivated;
391 case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING:
392 return flimflam::kActivationStateActivating;
393 case MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED:
394 return flimflam::kActivationStateNotActivated;
395 case MM_MODEM_CDMA_ACTIVATION_STATE_PARTIALLY_ACTIVATED:
396 return flimflam::kActivationStatePartiallyActivated;
397 default:
398 return flimflam::kActivationStateUnknown;
399 }
400}
401
402// static
403string CellularCapabilityUniversalCDMA::GetActivationErrorString(
404 uint32 error) {
405 switch (error) {
406 case MM_CDMA_ACTIVATION_ERROR_WRONG_RADIO_INTERFACE:
407 return flimflam::kErrorNeedEvdo;
408 case MM_CDMA_ACTIVATION_ERROR_ROAMING:
409 return flimflam::kErrorNeedHomeNetwork;
410 case MM_CDMA_ACTIVATION_ERROR_COULD_NOT_CONNECT:
411 case MM_CDMA_ACTIVATION_ERROR_SECURITY_AUTHENTICATION_FAILED:
412 case MM_CDMA_ACTIVATION_ERROR_PROVISIONING_FAILED:
413 return flimflam::kErrorOtaspFailed;
414 case MM_CDMA_ACTIVATION_ERROR_NONE:
415 return "";
416 case MM_CDMA_ACTIVATION_ERROR_NO_SIGNAL:
417 default:
418 return flimflam::kErrorActivationFailed;
419 }
420}
421
Arman Uguray72fab6a2013-01-10 19:32:42 -0800422void CellularCapabilityUniversalCDMA::Register(const ResultCallback &callback) {
423 // TODO(armansito): Remove once 3GPP is implemented in its own class.
424}
425
426void CellularCapabilityUniversalCDMA::RegisterOnNetwork(
427 const string &network_id,
428 Error *error,
429 const ResultCallback &callback) {
430 // TODO(armansito): Remove once 3GPP is implemented in its own class.
431}
432
Arman Uguray0a3e2792013-01-17 16:31:50 -0800433bool CellularCapabilityUniversalCDMA::IsActivating() const {
434 PendingActivationStore::State state =
435 modem_info()->pending_activation_store()->GetActivationState(
436 PendingActivationStore::kIdentifierMEID, meid());
437 return (state == PendingActivationStore::kStatePending) ||
438 (state == PendingActivationStore::kStateFailureRetry) ||
439 (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING);
440}
441
Arman Uguray72fab6a2013-01-10 19:32:42 -0800442bool CellularCapabilityUniversalCDMA::IsRegistered() {
443 return (cdma_1x_registration_state_ ==
444 MM_MODEM_CDMA_REGISTRATION_STATE_HOME ||
445 cdma_1x_registration_state_ ==
446 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING ||
447 cdma_evdo_registration_state_ ==
448 MM_MODEM_CDMA_REGISTRATION_STATE_HOME ||
449 cdma_evdo_registration_state_ ==
450 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING);
451}
452
453void CellularCapabilityUniversalCDMA::SetUnregistered(bool /*searching*/) {
454 cdma_1x_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
455 cdma_evdo_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
456}
457
Arman Ugurayc9673062013-05-13 21:21:53 -0700458void CellularCapabilityUniversalCDMA::SetupConnectProperties(
459 DBusPropertiesMap *properties) {
460 (*properties)[kPropertyConnectNumber].writer().append_string(
461 kPhoneNumber);
462}
463
Arman Uguray72fab6a2013-01-10 19:32:42 -0800464void CellularCapabilityUniversalCDMA::RequirePIN(
465 const string &pin, bool require,
466 Error *error, const ResultCallback &callback) {
467 // TODO(armansito): Remove once 3GPP is implemented in its own class.
468}
469
470void CellularCapabilityUniversalCDMA::EnterPIN(
471 const string &pin,
472 Error *error,
473 const ResultCallback &callback) {
474 // TODO(armansito): Remove once 3GPP is implemented in its own class.
475}
476
477void CellularCapabilityUniversalCDMA::UnblockPIN(
478 const string &unblock_code,
479 const string &pin,
480 Error *error,
481 const ResultCallback &callback) {
482 // TODO(armansito): Remove once 3GPP is implemented in its own class.
483}
484
485void CellularCapabilityUniversalCDMA::ChangePIN(
486 const string &old_pin, const string &new_pin,
487 Error *error, const ResultCallback &callback) {
488 // TODO(armansito): Remove once 3GPP is implemented in its own class.
489}
490
491void CellularCapabilityUniversalCDMA::Scan(Error *error,
492 const ResultCallback &callback) {
493 // TODO(armansito): Remove once 3GPP is implemented in its own class.
494}
495
496void CellularCapabilityUniversalCDMA::OnSimPathChanged(
497 const string &sim_path) {
498 // TODO(armansito): Remove once 3GPP is implemented in its own class.
499}
500
501string CellularCapabilityUniversalCDMA::GetRoamingStateString() const {
502 uint32 state = cdma_evdo_registration_state_;
503 if (state == MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN) {
504 state = cdma_1x_registration_state_;
505 }
506 switch (state) {
507 case MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN:
508 case MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED:
509 break;
510 case MM_MODEM_CDMA_REGISTRATION_STATE_HOME:
511 return flimflam::kRoamingStateHome;
512 case MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING:
513 return flimflam::kRoamingStateRoaming;
514 default:
515 NOTREACHED();
516 }
517 return flimflam::kRoamingStateUnknown;
518}
519
520void CellularCapabilityUniversalCDMA::OnDBusPropertiesChanged(
521 const string &interface,
522 const DBusPropertiesMap &changed_properties,
523 const vector<string> &invalidated_properties) {
524 SLOG(Cellular, 2) << __func__ << "(" << interface << ")";
525 if (interface == MM_DBUS_INTERFACE_MODEM_MODEMCDMA) {
526 OnModemCDMAPropertiesChanged(changed_properties, invalidated_properties);
527 } else {
528 CellularCapabilityUniversal::OnDBusPropertiesChanged(
529 interface, changed_properties, invalidated_properties);
530 }
531}
532
533void CellularCapabilityUniversalCDMA::OnModemCDMAPropertiesChanged(
534 const DBusPropertiesMap &properties,
535 const std::vector<std::string> &/*invalidated_properties*/) {
536 SLOG(Cellular, 2) << __func__;
537 string str_value;
538 if (DBusProperties::GetString(properties,
539 MM_MODEM_MODEMCDMA_PROPERTY_MEID,
540 &str_value))
541 set_meid(str_value);
542 if (DBusProperties::GetString(properties,
543 MM_MODEM_MODEMCDMA_PROPERTY_ESN,
544 &str_value))
545 set_esn(str_value);
546
547 uint32_t sid = sid_;
548 uint32_t nid = nid_;
549 MMModemCdmaRegistrationState state_1x = cdma_1x_registration_state_;
550 MMModemCdmaRegistrationState state_evdo = cdma_evdo_registration_state_;
551 bool registration_changed = false;
552 uint32_t uint_value;
553 if (DBusProperties::GetUint32(
554 properties,
555 MM_MODEM_MODEMCDMA_PROPERTY_CDMA1XREGISTRATIONSTATE,
556 &uint_value)) {
557 state_1x = static_cast<MMModemCdmaRegistrationState>(uint_value);
558 registration_changed = true;
559 }
560 if (DBusProperties::GetUint32(
561 properties,
562 MM_MODEM_MODEMCDMA_PROPERTY_EVDOREGISTRATIONSTATE,
563 &uint_value)) {
564 state_evdo = static_cast<MMModemCdmaRegistrationState>(uint_value);
565 registration_changed = true;
566 }
567 if (DBusProperties::GetUint32(
568 properties,
569 MM_MODEM_MODEMCDMA_PROPERTY_SID,
570 &uint_value)) {
571 sid = uint_value;
572 registration_changed = true;
573 }
574 if (DBusProperties::GetUint32(
575 properties,
576 MM_MODEM_MODEMCDMA_PROPERTY_NID,
577 &uint_value)) {
578 nid = uint_value;
579 registration_changed = true;
580 }
Arman Uguray0a3e2792013-01-17 16:31:50 -0800581 if (DBusProperties::GetUint32(
582 properties,
583 MM_MODEM_MODEMCDMA_PROPERTY_ACTIVATIONSTATE,
584 &uint_value)) {
585 activation_state_ = static_cast<MMModemCdmaActivationState>(uint_value);
586 HandleNewActivationStatus(MM_CDMA_ACTIVATION_ERROR_NONE);
587 }
Arman Uguray72fab6a2013-01-10 19:32:42 -0800588 if (registration_changed)
589 OnCDMARegistrationChanged(state_1x, state_evdo, sid, nid);
590}
591
592void CellularCapabilityUniversalCDMA::OnCDMARegistrationChanged(
593 MMModemCdmaRegistrationState state_1x,
594 MMModemCdmaRegistrationState state_evdo,
595 uint32_t sid, uint32_t nid) {
596 SLOG(Cellular, 2) << __func__
597 << ": state_1x=" << state_1x
598 << ", state_evdo=" << state_evdo;
599 cdma_1x_registration_state_ = state_1x;
600 cdma_evdo_registration_state_ = state_evdo;
601 sid_ = sid;
602 nid_ = nid;
603 UpdateOperatorInfo();
604 cellular()->HandleNewRegistrationState();
605}
606
607} // namespace shill