blob: 6dbe1831219574d239d7869dfb1bf16feb50fa7d [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.";
Arman Uguraye015faf2013-08-16 17:54:59 -0700296 // If a matching provider is not found, shill should update the
297 // Cellular.ServingOperator property to to display the Sid.
298 provider_.SetCode(sid);
299 provider_.SetCountry("");
300 provider_.SetName("");
301 activation_code_.clear();
302 } else {
303 if (!provider->name_list().empty()) {
304 provider_.SetName(provider->name_list()[0].name);
305 }
306 provider_.SetCode(sid);
307 provider_.SetCountry(provider->country());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800308
Arman Uguraye015faf2013-08-16 17:54:59 -0700309 activation_code_ = provider->activation_code();
Arman Uguray72fab6a2013-01-10 19:32:42 -0800310 }
Arman Uguray0a3e2792013-01-17 16:31:50 -0800311
Arman Uguray72fab6a2013-01-10 19:32:42 -0800312 // TODO(armansito): The CDMA interface only returns information about the
313 // current serving carrier, so for now both the home provider and the
314 // serving operator will be the same in case of roaming. We should figure
315 // out if there is a way to (and whether or not it is necessary to)
316 // determine if we're roaming.
317 cellular()->set_home_provider(provider_);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800318 UpdateServingOperator();
319}
320
321void CellularCapabilityUniversalCDMA::UpdateServingOperator() {
322 SLOG(Cellular, 2) << __func__;
323 if (cellular()->service().get()) {
324 cellular()->service()->SetServingOperator(cellular()->home_provider());
Arman Uguray2269bb62013-07-26 14:53:30 -0700325 cellular()->service()->SetFriendlyName(CreateFriendlyServiceName());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800326 }
327}
328
Arman Uguray0a3e2792013-01-17 16:31:50 -0800329void CellularCapabilityUniversalCDMA::OnActivationStateChangedSignal(
330 uint32 activation_state,
331 uint32 activation_error,
332 const DBusPropertiesMap &status_changes) {
333 SLOG(Cellular, 2) << __func__;
334
335 activation_state_ =
336 static_cast<MMModemCdmaActivationState>(activation_state);
337
338 string value;
339 if (DBusProperties::GetString(status_changes, "mdn", &value))
340 set_mdn(value);
341 if (DBusProperties::GetString(status_changes, "min", &value))
342 set_min(value);
343
344 SLOG(Cellular, 2) << "Activation state: "
345 << GetActivationStateString(activation_state_);
346
347 HandleNewActivationStatus(activation_error);
348 UpdatePendingActivationState();
349}
350
351void CellularCapabilityUniversalCDMA::OnActivateReply(
352 const ResultCallback &callback,
353 const Error &error) {
354 SLOG(Cellular, 2) << __func__;
355 if (error.IsSuccess()) {
356 LOG(INFO) << "Activation completed successfully.";
357 modem_info()->pending_activation_store()->SetActivationState(
358 PendingActivationStore::kIdentifierMEID,
359 meid(),
360 PendingActivationStore::kStateActivated);
361 } else {
362 LOG(ERROR) << "Activation failed with error: " << error;
363 modem_info()->pending_activation_store()->SetActivationState(
364 PendingActivationStore::kIdentifierMEID,
365 meid(),
366 PendingActivationStore::kStateFailureRetry);
367 }
368 UpdatePendingActivationState();
Arman Ugurayf2b4a342013-05-23 18:26:52 -0700369
370 // CellularCapabilityUniversalCDMA::ActivateAutomatic passes a dummy
371 // ResultCallback when it calls Activate on the proxy object, in which case
372 // |callback.is_null()| will return true.
373 if (!callback.is_null())
374 callback.Run(error);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800375}
376
377void CellularCapabilityUniversalCDMA::HandleNewActivationStatus(uint32 error) {
378 SLOG(Cellular, 2) << __func__ << "(" << error << ")";
379 if (!cellular()->service().get()) {
380 LOG(ERROR) << "In " << __func__ << "(): service is null.";
381 return;
382 }
383 SLOG(Cellular, 2) << "Activation State: " << activation_state_;
384 cellular()->service()->SetActivationState(
385 GetActivationStateString(activation_state_));
386 cellular()->service()->set_error(GetActivationErrorString(error));
387 UpdateOLP();
388}
389
390// static
391string CellularCapabilityUniversalCDMA::GetActivationStateString(
392 uint32 state) {
393 switch (state) {
394 case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED:
395 return flimflam::kActivationStateActivated;
396 case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING:
397 return flimflam::kActivationStateActivating;
398 case MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED:
399 return flimflam::kActivationStateNotActivated;
400 case MM_MODEM_CDMA_ACTIVATION_STATE_PARTIALLY_ACTIVATED:
401 return flimflam::kActivationStatePartiallyActivated;
402 default:
403 return flimflam::kActivationStateUnknown;
404 }
405}
406
407// static
408string CellularCapabilityUniversalCDMA::GetActivationErrorString(
409 uint32 error) {
410 switch (error) {
411 case MM_CDMA_ACTIVATION_ERROR_WRONG_RADIO_INTERFACE:
412 return flimflam::kErrorNeedEvdo;
413 case MM_CDMA_ACTIVATION_ERROR_ROAMING:
414 return flimflam::kErrorNeedHomeNetwork;
415 case MM_CDMA_ACTIVATION_ERROR_COULD_NOT_CONNECT:
416 case MM_CDMA_ACTIVATION_ERROR_SECURITY_AUTHENTICATION_FAILED:
417 case MM_CDMA_ACTIVATION_ERROR_PROVISIONING_FAILED:
418 return flimflam::kErrorOtaspFailed;
419 case MM_CDMA_ACTIVATION_ERROR_NONE:
420 return "";
421 case MM_CDMA_ACTIVATION_ERROR_NO_SIGNAL:
422 default:
423 return flimflam::kErrorActivationFailed;
424 }
425}
426
Arman Uguray72fab6a2013-01-10 19:32:42 -0800427void CellularCapabilityUniversalCDMA::Register(const ResultCallback &callback) {
428 // TODO(armansito): Remove once 3GPP is implemented in its own class.
429}
430
431void CellularCapabilityUniversalCDMA::RegisterOnNetwork(
432 const string &network_id,
433 Error *error,
434 const ResultCallback &callback) {
435 // TODO(armansito): Remove once 3GPP is implemented in its own class.
436}
437
Arman Uguray0a3e2792013-01-17 16:31:50 -0800438bool CellularCapabilityUniversalCDMA::IsActivating() const {
439 PendingActivationStore::State state =
440 modem_info()->pending_activation_store()->GetActivationState(
441 PendingActivationStore::kIdentifierMEID, meid());
442 return (state == PendingActivationStore::kStatePending) ||
443 (state == PendingActivationStore::kStateFailureRetry) ||
444 (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING);
445}
446
Arman Uguray72fab6a2013-01-10 19:32:42 -0800447bool CellularCapabilityUniversalCDMA::IsRegistered() {
448 return (cdma_1x_registration_state_ ==
449 MM_MODEM_CDMA_REGISTRATION_STATE_HOME ||
450 cdma_1x_registration_state_ ==
451 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING ||
452 cdma_evdo_registration_state_ ==
453 MM_MODEM_CDMA_REGISTRATION_STATE_HOME ||
454 cdma_evdo_registration_state_ ==
455 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING);
456}
457
458void CellularCapabilityUniversalCDMA::SetUnregistered(bool /*searching*/) {
459 cdma_1x_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
460 cdma_evdo_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
461}
462
Arman Ugurayc9673062013-05-13 21:21:53 -0700463void CellularCapabilityUniversalCDMA::SetupConnectProperties(
464 DBusPropertiesMap *properties) {
465 (*properties)[kPropertyConnectNumber].writer().append_string(
466 kPhoneNumber);
467}
468
Arman Uguray72fab6a2013-01-10 19:32:42 -0800469void CellularCapabilityUniversalCDMA::RequirePIN(
470 const string &pin, bool require,
471 Error *error, const ResultCallback &callback) {
472 // TODO(armansito): Remove once 3GPP is implemented in its own class.
473}
474
475void CellularCapabilityUniversalCDMA::EnterPIN(
476 const string &pin,
477 Error *error,
478 const ResultCallback &callback) {
479 // TODO(armansito): Remove once 3GPP is implemented in its own class.
480}
481
482void CellularCapabilityUniversalCDMA::UnblockPIN(
483 const string &unblock_code,
484 const string &pin,
485 Error *error,
486 const ResultCallback &callback) {
487 // TODO(armansito): Remove once 3GPP is implemented in its own class.
488}
489
490void CellularCapabilityUniversalCDMA::ChangePIN(
491 const string &old_pin, const string &new_pin,
492 Error *error, const ResultCallback &callback) {
493 // TODO(armansito): Remove once 3GPP is implemented in its own class.
494}
495
496void CellularCapabilityUniversalCDMA::Scan(Error *error,
497 const ResultCallback &callback) {
498 // TODO(armansito): Remove once 3GPP is implemented in its own class.
499}
500
501void CellularCapabilityUniversalCDMA::OnSimPathChanged(
502 const string &sim_path) {
503 // TODO(armansito): Remove once 3GPP is implemented in its own class.
504}
505
506string CellularCapabilityUniversalCDMA::GetRoamingStateString() const {
507 uint32 state = cdma_evdo_registration_state_;
508 if (state == MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN) {
509 state = cdma_1x_registration_state_;
510 }
511 switch (state) {
512 case MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN:
513 case MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED:
514 break;
515 case MM_MODEM_CDMA_REGISTRATION_STATE_HOME:
516 return flimflam::kRoamingStateHome;
517 case MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING:
518 return flimflam::kRoamingStateRoaming;
519 default:
520 NOTREACHED();
521 }
522 return flimflam::kRoamingStateUnknown;
523}
524
525void CellularCapabilityUniversalCDMA::OnDBusPropertiesChanged(
526 const string &interface,
527 const DBusPropertiesMap &changed_properties,
528 const vector<string> &invalidated_properties) {
529 SLOG(Cellular, 2) << __func__ << "(" << interface << ")";
530 if (interface == MM_DBUS_INTERFACE_MODEM_MODEMCDMA) {
531 OnModemCDMAPropertiesChanged(changed_properties, invalidated_properties);
532 } else {
533 CellularCapabilityUniversal::OnDBusPropertiesChanged(
534 interface, changed_properties, invalidated_properties);
535 }
536}
537
538void CellularCapabilityUniversalCDMA::OnModemCDMAPropertiesChanged(
539 const DBusPropertiesMap &properties,
540 const std::vector<std::string> &/*invalidated_properties*/) {
541 SLOG(Cellular, 2) << __func__;
542 string str_value;
543 if (DBusProperties::GetString(properties,
544 MM_MODEM_MODEMCDMA_PROPERTY_MEID,
545 &str_value))
546 set_meid(str_value);
547 if (DBusProperties::GetString(properties,
548 MM_MODEM_MODEMCDMA_PROPERTY_ESN,
549 &str_value))
550 set_esn(str_value);
551
552 uint32_t sid = sid_;
553 uint32_t nid = nid_;
554 MMModemCdmaRegistrationState state_1x = cdma_1x_registration_state_;
555 MMModemCdmaRegistrationState state_evdo = cdma_evdo_registration_state_;
556 bool registration_changed = false;
557 uint32_t uint_value;
558 if (DBusProperties::GetUint32(
559 properties,
560 MM_MODEM_MODEMCDMA_PROPERTY_CDMA1XREGISTRATIONSTATE,
561 &uint_value)) {
562 state_1x = static_cast<MMModemCdmaRegistrationState>(uint_value);
563 registration_changed = true;
564 }
565 if (DBusProperties::GetUint32(
566 properties,
567 MM_MODEM_MODEMCDMA_PROPERTY_EVDOREGISTRATIONSTATE,
568 &uint_value)) {
569 state_evdo = static_cast<MMModemCdmaRegistrationState>(uint_value);
570 registration_changed = true;
571 }
572 if (DBusProperties::GetUint32(
573 properties,
574 MM_MODEM_MODEMCDMA_PROPERTY_SID,
575 &uint_value)) {
576 sid = uint_value;
577 registration_changed = true;
578 }
579 if (DBusProperties::GetUint32(
580 properties,
581 MM_MODEM_MODEMCDMA_PROPERTY_NID,
582 &uint_value)) {
583 nid = uint_value;
584 registration_changed = true;
585 }
Arman Uguray0a3e2792013-01-17 16:31:50 -0800586 if (DBusProperties::GetUint32(
587 properties,
588 MM_MODEM_MODEMCDMA_PROPERTY_ACTIVATIONSTATE,
589 &uint_value)) {
590 activation_state_ = static_cast<MMModemCdmaActivationState>(uint_value);
591 HandleNewActivationStatus(MM_CDMA_ACTIVATION_ERROR_NONE);
592 }
Arman Uguray72fab6a2013-01-10 19:32:42 -0800593 if (registration_changed)
594 OnCDMARegistrationChanged(state_1x, state_evdo, sid, nid);
595}
596
597void CellularCapabilityUniversalCDMA::OnCDMARegistrationChanged(
598 MMModemCdmaRegistrationState state_1x,
599 MMModemCdmaRegistrationState state_evdo,
600 uint32_t sid, uint32_t nid) {
601 SLOG(Cellular, 2) << __func__
602 << ": state_1x=" << state_1x
603 << ", state_evdo=" << state_evdo;
604 cdma_1x_registration_state_ = state_1x;
605 cdma_evdo_registration_state_ = state_evdo;
606 sid_ = sid;
607 nid_ = nid;
608 UpdateOperatorInfo();
609 cellular()->HandleNewRegistrationState();
610}
611
612} // namespace shill