blob: 3d6f65dede75f41017410895e6b074e4ffe4f275 [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>
Ben Chana0ddf462014-02-06 11:32:42 -08008#include <base/strings/stringprintf.h>
9#include <base/strings/string_number_conversions.h>
10#include <base/strings/string_util.h>
Arman Uguray72fab6a2013-01-10 19:32:42 -080011
Ben Chan539ab022014-02-03 16:34:57 -080012#include "shill/cellular_bearer.h"
Prathmesh Prabhu3b66bb92014-05-22 11:15:25 -070013#include "shill/cellular_service.h"
Arman Uguray72fab6a2013-01-10 19:32:42 -080014#include "shill/dbus_properties_proxy_interface.h"
Arman Uguray0a3e2792013-01-17 16:31:50 -080015#include "shill/error.h"
Arman Uguray72fab6a2013-01-10 19:32:42 -080016#include "shill/logging.h"
Arman Uguray0a3e2792013-01-17 16:31:50 -080017#include "shill/pending_activation_store.h"
Arman Uguray72fab6a2013-01-10 19:32:42 -080018#include "shill/proxy_factory.h"
19
20#ifdef MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN
21#error "Do not include mm-modem.h"
22#endif
23
24using base::UintToString;
25
26using std::string;
27using std::vector;
28
29namespace shill {
30
31namespace {
32
Arman Ugurayc9673062013-05-13 21:21:53 -070033const char kPhoneNumber[] = "#777";
34const char kPropertyConnectNumber[] = "number";
35
Arman Uguray72fab6a2013-01-10 19:32:42 -080036} // namespace
37
Arman Uguray72fab6a2013-01-10 19:32:42 -080038CellularCapabilityUniversalCDMA::CellularCapabilityUniversalCDMA(
39 Cellular *cellular,
40 ProxyFactory *proxy_factory,
41 ModemInfo *modem_info)
Ben Chanf98f00e2014-02-05 14:48:43 -080042 : CellularCapabilityUniversal(cellular, proxy_factory, modem_info),
Arman Uguray0a3e2792013-01-17 16:31:50 -080043 weak_cdma_ptr_factory_(this),
44 activation_state_(MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED),
Arman Uguray72fab6a2013-01-10 19:32:42 -080045 cdma_1x_registration_state_(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN),
46 cdma_evdo_registration_state_(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN),
47 nid_(0),
48 sid_(0) {
49 SLOG(Cellular, 2) << "Cellular capability constructed: Universal CDMA";
Arman Uguray0a3e2792013-01-17 16:31:50 -080050 // TODO(armansito): Update PRL for activation over cellular.
Arman Uguray72fab6a2013-01-10 19:32:42 -080051 // See crbug.com/197330.
52}
53
Ben Chanf98f00e2014-02-05 14:48:43 -080054CellularCapabilityUniversalCDMA::~CellularCapabilityUniversalCDMA() {}
55
Arman Uguray72fab6a2013-01-10 19:32:42 -080056void CellularCapabilityUniversalCDMA::InitProxies() {
57 SLOG(Cellular, 2) << __func__;
58 modem_cdma_proxy_.reset(
59 proxy_factory()->CreateMM1ModemModemCdmaProxy(cellular()->dbus_path(),
60 cellular()->dbus_owner()));
Arman Uguray0a3e2792013-01-17 16:31:50 -080061 modem_cdma_proxy_->set_activation_state_callback(
62 Bind(&CellularCapabilityUniversalCDMA::OnActivationStateChangedSignal,
63 weak_cdma_ptr_factory_.GetWeakPtr()));
Arman Uguray72fab6a2013-01-10 19:32:42 -080064 CellularCapabilityUniversal::InitProxies();
65}
66
67void CellularCapabilityUniversalCDMA::ReleaseProxies() {
68 SLOG(Cellular, 2) << __func__;
69 modem_cdma_proxy_.reset();
70 CellularCapabilityUniversal::ReleaseProxies();
71}
72
Ben Chanf98f00e2014-02-05 14:48:43 -080073void CellularCapabilityUniversalCDMA::Activate(const string &carrier,
74 Error *error,
75 const ResultCallback &callback) {
Arman Uguray0a3e2792013-01-17 16:31:50 -080076 // Currently activation over the cellular network is not supported using
77 // ModemManager-next. Service activation is currently carried through over
78 // non-cellular networks and only the final step of the OTA activation
79 // procedure ("automatic activation") is performed by this class.
Arman Uguray72fab6a2013-01-10 19:32:42 -080080 OnUnsupportedOperation(__func__, error);
81}
82
83void CellularCapabilityUniversalCDMA::CompleteActivation(Error *error) {
Arman Uguray0a3e2792013-01-17 16:31:50 -080084 SLOG(Cellular, 2) << __func__;
85 if (cellular()->state() < Cellular::kStateEnabled) {
86 Error::PopulateAndLog(error, Error::kInvalidArguments,
87 "Unable to activate in state " +
88 Cellular::GetStateString(cellular()->state()));
89 return;
90 }
91 ActivateAutomatic();
Arman Uguray72fab6a2013-01-10 19:32:42 -080092}
93
Arman Uguray0a3e2792013-01-17 16:31:50 -080094void CellularCapabilityUniversalCDMA::ActivateAutomatic() {
95 if (activation_code_.empty()) {
96 SLOG(Cellular, 2) << "OTA activation cannot be run in the presence of no "
97 << "activation code.";
98 return;
99 }
100 PendingActivationStore::State state =
101 modem_info()->pending_activation_store()->GetActivationState(
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800102 PendingActivationStore::kIdentifierMEID, cellular()->meid());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800103 if (state == PendingActivationStore::kStatePending) {
104 SLOG(Cellular, 2) << "There's already a pending activation. Ignoring.";
105 return;
106 }
107 if (state == PendingActivationStore::kStateActivated) {
108 SLOG(Cellular, 2) << "A call to OTA activation has already completed "
109 << "successfully. Ignoring.";
110 return;
111 }
112
113 // Mark as pending activation, so that shill can recover if anything fails
114 // during OTA activation.
115 modem_info()->pending_activation_store()->SetActivationState(
116 PendingActivationStore::kIdentifierMEID,
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800117 cellular()->meid(),
Arman Uguray0a3e2792013-01-17 16:31:50 -0800118 PendingActivationStore::kStatePending);
119
120 // Initiate OTA activation.
121 ResultCallback activation_callback =
122 Bind(&CellularCapabilityUniversalCDMA::OnActivateReply,
123 weak_cdma_ptr_factory_.GetWeakPtr(),
124 ResultCallback());
Arman Ugurayf2b4a342013-05-23 18:26:52 -0700125
Arman Uguray0a3e2792013-01-17 16:31:50 -0800126 Error error;
127 modem_cdma_proxy_->Activate(
128 activation_code_, &error, activation_callback, kTimeoutActivate);
129}
130
131void CellularCapabilityUniversalCDMA::UpdatePendingActivationState() {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800132 SLOG(Cellular, 2) << __func__;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800133 if (IsActivated()) {
134 SLOG(Cellular, 3) << "CDMA service activated. Clear store.";
135 modem_info()->pending_activation_store()->RemoveEntry(
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800136 PendingActivationStore::kIdentifierMEID, cellular()->meid());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800137 return;
138 }
139 PendingActivationStore::State state =
140 modem_info()->pending_activation_store()->GetActivationState(
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800141 PendingActivationStore::kIdentifierMEID, cellular()->meid());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800142 if (IsActivating() && state != PendingActivationStore::kStateFailureRetry) {
143 SLOG(Cellular, 3) << "OTA activation in progress. Nothing to do.";
144 return;
145 }
146 switch (state) {
147 case PendingActivationStore::kStateFailureRetry:
148 SLOG(Cellular, 3) << "OTA activation failed. Scheduling a retry.";
149 cellular()->dispatcher()->PostTask(
150 Bind(&CellularCapabilityUniversalCDMA::ActivateAutomatic,
151 weak_cdma_ptr_factory_.GetWeakPtr()));
152 break;
153 case PendingActivationStore::kStateActivated:
154 SLOG(Cellular, 3) << "OTA Activation has completed successfully. "
155 << "Waiting for activation state update to finalize.";
156 break;
157 default:
158 break;
159 }
160}
161
162bool CellularCapabilityUniversalCDMA::IsServiceActivationRequired() const {
163 // If there is no online payment portal information, it's safer to assume
164 // the service does not require activation.
Prathmesh Prabhu3ee2f412014-05-20 17:30:19 -0700165 if (!cellular()->serving_operator_info()->IsMobileNetworkOperatorKnown() ||
166 cellular()->serving_operator_info()->olp_list().empty()) {
Arman Uguray0a3e2792013-01-17 16:31:50 -0800167 return false;
Prathmesh Prabhu3ee2f412014-05-20 17:30:19 -0700168 }
Arman Uguray0a3e2792013-01-17 16:31:50 -0800169
170 // We could also use the MDN to determine whether or not the service is
171 // activated, however, the CDMA ActivatonState property is a more absolute
172 // and fine-grained indicator of activation status.
173 return (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED);
174}
175
176bool CellularCapabilityUniversalCDMA::IsActivated() const {
177 return (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800178}
179
180void CellularCapabilityUniversalCDMA::OnServiceCreated() {
181 SLOG(Cellular, 2) << __func__;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800182 UpdateServiceActivationStateProperty();
Arman Uguray0a3e2792013-01-17 16:31:50 -0800183 HandleNewActivationStatus(MM_CDMA_ACTIVATION_ERROR_NONE);
184 UpdatePendingActivationState();
Arman Uguray72fab6a2013-01-10 19:32:42 -0800185}
186
Arman Uguray0a3e2792013-01-17 16:31:50 -0800187void CellularCapabilityUniversalCDMA::UpdateServiceActivationStateProperty() {
188 bool activation_required = IsServiceActivationRequired();
189 cellular()->service()->SetActivateOverNonCellularNetwork(activation_required);
190 string activation_state;
191 if (IsActivating())
Ben Chan7ea768e2013-09-20 15:08:40 -0700192 activation_state = kActivationStateActivating;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800193 else if (activation_required)
Ben Chan7ea768e2013-09-20 15:08:40 -0700194 activation_state = kActivationStateNotActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800195 else
Ben Chan7ea768e2013-09-20 15:08:40 -0700196 activation_state = kActivationStateActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800197 cellular()->service()->SetActivationState(activation_state);
198}
199
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700200void CellularCapabilityUniversalCDMA::UpdateServiceOLP() {
Ben Chan07193fd2013-07-12 22:10:55 -0700201 SLOG(Cellular, 2) << __func__;
202
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700203 // In this case, the Home Provider is trivial. All information comes from the
204 // Serving Operator.
205 if (!cellular()->serving_operator_info()->IsMobileNetworkOperatorKnown()) {
Ben Chan07193fd2013-07-12 22:10:55 -0700206 return;
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700207 }
Ben Chan07193fd2013-07-12 22:10:55 -0700208
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700209 const vector<MobileOperatorInfo::OnlinePortal> &olp_list =
210 cellular()->serving_operator_info()->olp_list();
211 if (olp_list.empty()) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800212 return;
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700213 }
Arman Uguray72fab6a2013-01-10 19:32:42 -0800214
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700215 if (olp_list.size() > 1) {
216 SLOG(Cellular, 1) << "Found multiple online portals. Choosing the first.";
217 }
218 string post_data = olp_list[0].post_data;
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800219 ReplaceSubstringsAfterOffset(&post_data, 0, "${esn}", cellular()->esn());
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700220 ReplaceSubstringsAfterOffset(
221 &post_data, 0, "${mdn}",
222 GetMdnForOLP(cellular()->serving_operator_info()));
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800223 ReplaceSubstringsAfterOffset(&post_data, 0, "${meid}", cellular()->meid());
Arman Ugurayf87fa2f2013-10-16 14:24:56 -0700224 ReplaceSubstringsAfterOffset(&post_data, 0, "${oem}", "GOG2");
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700225 cellular()->service()->SetOLP(olp_list[0].url, olp_list[0].method, post_data);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800226}
227
228void CellularCapabilityUniversalCDMA::GetProperties() {
229 SLOG(Cellular, 2) << __func__;
230 CellularCapabilityUniversal::GetProperties();
231
232 scoped_ptr<DBusPropertiesProxyInterface> properties_proxy(
233 proxy_factory()->CreateDBusPropertiesProxy(cellular()->dbus_path(),
234 cellular()->dbus_owner()));
235 DBusPropertiesMap properties(
236 properties_proxy->GetAll(MM_DBUS_INTERFACE_MODEM_MODEMCDMA));
237 OnModemCDMAPropertiesChanged(properties, vector<string>());
238}
239
Arman Uguray0a3e2792013-01-17 16:31:50 -0800240void CellularCapabilityUniversalCDMA::OnActivationStateChangedSignal(
241 uint32 activation_state,
242 uint32 activation_error,
243 const DBusPropertiesMap &status_changes) {
244 SLOG(Cellular, 2) << __func__;
245
246 activation_state_ =
247 static_cast<MMModemCdmaActivationState>(activation_state);
248
249 string value;
250 if (DBusProperties::GetString(status_changes, "mdn", &value))
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800251 cellular()->set_mdn(value);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800252 if (DBusProperties::GetString(status_changes, "min", &value))
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800253 cellular()->set_min(value);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800254
255 SLOG(Cellular, 2) << "Activation state: "
256 << GetActivationStateString(activation_state_);
257
258 HandleNewActivationStatus(activation_error);
259 UpdatePendingActivationState();
260}
261
262void CellularCapabilityUniversalCDMA::OnActivateReply(
263 const ResultCallback &callback,
264 const Error &error) {
265 SLOG(Cellular, 2) << __func__;
266 if (error.IsSuccess()) {
267 LOG(INFO) << "Activation completed successfully.";
268 modem_info()->pending_activation_store()->SetActivationState(
269 PendingActivationStore::kIdentifierMEID,
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800270 cellular()->meid(),
Arman Uguray0a3e2792013-01-17 16:31:50 -0800271 PendingActivationStore::kStateActivated);
272 } else {
273 LOG(ERROR) << "Activation failed with error: " << error;
274 modem_info()->pending_activation_store()->SetActivationState(
275 PendingActivationStore::kIdentifierMEID,
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800276 cellular()->meid(),
Arman Uguray0a3e2792013-01-17 16:31:50 -0800277 PendingActivationStore::kStateFailureRetry);
278 }
279 UpdatePendingActivationState();
Arman Ugurayf2b4a342013-05-23 18:26:52 -0700280
281 // CellularCapabilityUniversalCDMA::ActivateAutomatic passes a dummy
282 // ResultCallback when it calls Activate on the proxy object, in which case
283 // |callback.is_null()| will return true.
284 if (!callback.is_null())
285 callback.Run(error);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800286}
287
288void CellularCapabilityUniversalCDMA::HandleNewActivationStatus(uint32 error) {
289 SLOG(Cellular, 2) << __func__ << "(" << error << ")";
290 if (!cellular()->service().get()) {
291 LOG(ERROR) << "In " << __func__ << "(): service is null.";
292 return;
293 }
294 SLOG(Cellular, 2) << "Activation State: " << activation_state_;
295 cellular()->service()->SetActivationState(
296 GetActivationStateString(activation_state_));
297 cellular()->service()->set_error(GetActivationErrorString(error));
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700298 UpdateServiceOLP();
Arman Uguray0a3e2792013-01-17 16:31:50 -0800299}
300
301// static
302string CellularCapabilityUniversalCDMA::GetActivationStateString(
303 uint32 state) {
304 switch (state) {
305 case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700306 return kActivationStateActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800307 case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING:
Ben Chan7ea768e2013-09-20 15:08:40 -0700308 return kActivationStateActivating;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800309 case MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700310 return kActivationStateNotActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800311 case MM_MODEM_CDMA_ACTIVATION_STATE_PARTIALLY_ACTIVATED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700312 return kActivationStatePartiallyActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800313 default:
Ben Chan7ea768e2013-09-20 15:08:40 -0700314 return kActivationStateUnknown;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800315 }
316}
317
318// static
319string CellularCapabilityUniversalCDMA::GetActivationErrorString(
320 uint32 error) {
321 switch (error) {
322 case MM_CDMA_ACTIVATION_ERROR_WRONG_RADIO_INTERFACE:
Ben Chan7ea768e2013-09-20 15:08:40 -0700323 return kErrorNeedEvdo;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800324 case MM_CDMA_ACTIVATION_ERROR_ROAMING:
Ben Chan7ea768e2013-09-20 15:08:40 -0700325 return kErrorNeedHomeNetwork;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800326 case MM_CDMA_ACTIVATION_ERROR_COULD_NOT_CONNECT:
327 case MM_CDMA_ACTIVATION_ERROR_SECURITY_AUTHENTICATION_FAILED:
328 case MM_CDMA_ACTIVATION_ERROR_PROVISIONING_FAILED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700329 return kErrorOtaspFailed;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800330 case MM_CDMA_ACTIVATION_ERROR_NONE:
331 return "";
332 case MM_CDMA_ACTIVATION_ERROR_NO_SIGNAL:
333 default:
Ben Chan7ea768e2013-09-20 15:08:40 -0700334 return kErrorActivationFailed;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800335 }
336}
337
Arman Uguray72fab6a2013-01-10 19:32:42 -0800338void CellularCapabilityUniversalCDMA::Register(const ResultCallback &callback) {
339 // TODO(armansito): Remove once 3GPP is implemented in its own class.
340}
341
342void CellularCapabilityUniversalCDMA::RegisterOnNetwork(
343 const string &network_id,
344 Error *error,
345 const ResultCallback &callback) {
346 // TODO(armansito): Remove once 3GPP is implemented in its own class.
347}
348
Arman Uguray0a3e2792013-01-17 16:31:50 -0800349bool CellularCapabilityUniversalCDMA::IsActivating() const {
350 PendingActivationStore::State state =
351 modem_info()->pending_activation_store()->GetActivationState(
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800352 PendingActivationStore::kIdentifierMEID, cellular()->meid());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800353 return (state == PendingActivationStore::kStatePending) ||
354 (state == PendingActivationStore::kStateFailureRetry) ||
355 (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING);
356}
357
Ben Chan31ce5642013-11-14 13:37:40 -0800358bool CellularCapabilityUniversalCDMA::IsRegistered() const {
Ben Chanb2c4a802013-11-14 12:47:52 -0800359 return (cdma_1x_registration_state_ !=
360 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN ||
361 cdma_evdo_registration_state_ !=
362 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800363}
364
365void CellularCapabilityUniversalCDMA::SetUnregistered(bool /*searching*/) {
366 cdma_1x_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
367 cdma_evdo_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
368}
369
Arman Ugurayc9673062013-05-13 21:21:53 -0700370void CellularCapabilityUniversalCDMA::SetupConnectProperties(
371 DBusPropertiesMap *properties) {
372 (*properties)[kPropertyConnectNumber].writer().append_string(
373 kPhoneNumber);
374}
375
Arman Uguray72fab6a2013-01-10 19:32:42 -0800376void CellularCapabilityUniversalCDMA::RequirePIN(
377 const string &pin, bool require,
378 Error *error, const ResultCallback &callback) {
379 // TODO(armansito): Remove once 3GPP is implemented in its own class.
380}
381
382void CellularCapabilityUniversalCDMA::EnterPIN(
383 const string &pin,
384 Error *error,
385 const ResultCallback &callback) {
386 // TODO(armansito): Remove once 3GPP is implemented in its own class.
387}
388
389void CellularCapabilityUniversalCDMA::UnblockPIN(
390 const string &unblock_code,
391 const string &pin,
392 Error *error,
393 const ResultCallback &callback) {
394 // TODO(armansito): Remove once 3GPP is implemented in its own class.
395}
396
397void CellularCapabilityUniversalCDMA::ChangePIN(
398 const string &old_pin, const string &new_pin,
399 Error *error, const ResultCallback &callback) {
400 // TODO(armansito): Remove once 3GPP is implemented in its own class.
401}
402
Prathmesh Prabhu49ffffd2014-01-09 18:28:55 -0800403void CellularCapabilityUniversalCDMA::Scan(
404 Error *error,
405 const ResultStringmapsCallback &callback) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800406 // TODO(armansito): Remove once 3GPP is implemented in its own class.
Prathmesh Prabhu49ffffd2014-01-09 18:28:55 -0800407 OnUnsupportedOperation(__func__, error);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800408}
409
410void CellularCapabilityUniversalCDMA::OnSimPathChanged(
411 const string &sim_path) {
412 // TODO(armansito): Remove once 3GPP is implemented in its own class.
413}
414
415string CellularCapabilityUniversalCDMA::GetRoamingStateString() const {
416 uint32 state = cdma_evdo_registration_state_;
417 if (state == MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN) {
418 state = cdma_1x_registration_state_;
419 }
420 switch (state) {
421 case MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN:
422 case MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED:
423 break;
424 case MM_MODEM_CDMA_REGISTRATION_STATE_HOME:
Ben Chan7ea768e2013-09-20 15:08:40 -0700425 return kRoamingStateHome;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800426 case MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING:
Ben Chan7ea768e2013-09-20 15:08:40 -0700427 return kRoamingStateRoaming;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800428 default:
429 NOTREACHED();
430 }
Ben Chan7ea768e2013-09-20 15:08:40 -0700431 return kRoamingStateUnknown;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800432}
433
434void CellularCapabilityUniversalCDMA::OnDBusPropertiesChanged(
435 const string &interface,
436 const DBusPropertiesMap &changed_properties,
437 const vector<string> &invalidated_properties) {
438 SLOG(Cellular, 2) << __func__ << "(" << interface << ")";
439 if (interface == MM_DBUS_INTERFACE_MODEM_MODEMCDMA) {
440 OnModemCDMAPropertiesChanged(changed_properties, invalidated_properties);
441 } else {
442 CellularCapabilityUniversal::OnDBusPropertiesChanged(
443 interface, changed_properties, invalidated_properties);
444 }
445}
446
447void CellularCapabilityUniversalCDMA::OnModemCDMAPropertiesChanged(
448 const DBusPropertiesMap &properties,
449 const std::vector<std::string> &/*invalidated_properties*/) {
450 SLOG(Cellular, 2) << __func__;
451 string str_value;
452 if (DBusProperties::GetString(properties,
453 MM_MODEM_MODEMCDMA_PROPERTY_MEID,
454 &str_value))
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800455 cellular()->set_meid(str_value);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800456 if (DBusProperties::GetString(properties,
457 MM_MODEM_MODEMCDMA_PROPERTY_ESN,
458 &str_value))
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800459 cellular()->set_esn(str_value);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800460
461 uint32_t sid = sid_;
462 uint32_t nid = nid_;
463 MMModemCdmaRegistrationState state_1x = cdma_1x_registration_state_;
464 MMModemCdmaRegistrationState state_evdo = cdma_evdo_registration_state_;
465 bool registration_changed = false;
466 uint32_t uint_value;
467 if (DBusProperties::GetUint32(
468 properties,
469 MM_MODEM_MODEMCDMA_PROPERTY_CDMA1XREGISTRATIONSTATE,
470 &uint_value)) {
471 state_1x = static_cast<MMModemCdmaRegistrationState>(uint_value);
472 registration_changed = true;
473 }
474 if (DBusProperties::GetUint32(
475 properties,
476 MM_MODEM_MODEMCDMA_PROPERTY_EVDOREGISTRATIONSTATE,
477 &uint_value)) {
478 state_evdo = static_cast<MMModemCdmaRegistrationState>(uint_value);
479 registration_changed = true;
480 }
481 if (DBusProperties::GetUint32(
482 properties,
483 MM_MODEM_MODEMCDMA_PROPERTY_SID,
484 &uint_value)) {
485 sid = uint_value;
486 registration_changed = true;
487 }
488 if (DBusProperties::GetUint32(
489 properties,
490 MM_MODEM_MODEMCDMA_PROPERTY_NID,
491 &uint_value)) {
492 nid = uint_value;
493 registration_changed = true;
494 }
Arman Uguray0a3e2792013-01-17 16:31:50 -0800495 if (DBusProperties::GetUint32(
496 properties,
497 MM_MODEM_MODEMCDMA_PROPERTY_ACTIVATIONSTATE,
498 &uint_value)) {
499 activation_state_ = static_cast<MMModemCdmaActivationState>(uint_value);
500 HandleNewActivationStatus(MM_CDMA_ACTIVATION_ERROR_NONE);
501 }
Arman Uguray72fab6a2013-01-10 19:32:42 -0800502 if (registration_changed)
503 OnCDMARegistrationChanged(state_1x, state_evdo, sid, nid);
504}
505
506void CellularCapabilityUniversalCDMA::OnCDMARegistrationChanged(
507 MMModemCdmaRegistrationState state_1x,
508 MMModemCdmaRegistrationState state_evdo,
509 uint32_t sid, uint32_t nid) {
510 SLOG(Cellular, 2) << __func__
511 << ": state_1x=" << state_1x
512 << ", state_evdo=" << state_evdo;
513 cdma_1x_registration_state_ = state_1x;
514 cdma_evdo_registration_state_ = state_evdo;
515 sid_ = sid;
516 nid_ = nid;
Prathmesh Prabhu8599e052014-04-25 14:20:22 -0700517 cellular()->serving_operator_info()->UpdateSID(UintToString(sid));
518 cellular()->serving_operator_info()->UpdateNID(UintToString(nid));
Arman Uguray72fab6a2013-01-10 19:32:42 -0800519 cellular()->HandleNewRegistrationState();
520}
521
522} // namespace shill