blob: 040249e6f47f86d05df97019ba711a30d348d26a [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"
Arman Uguray72fab6a2013-01-10 19:32:42 -080013#include "shill/cellular_operator_info.h"
14#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.
165 if (!modem_info()->cellular_operator_info())
166 return false;
167
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700168 const CellularOperatorInfo::OLP *olp =
Arman Uguray0a3e2792013-01-17 16:31:50 -0800169 modem_info()->cellular_operator_info()->GetOLPBySID(UintToString(sid_));
170 if (!olp)
171 return false;
172
173 // We could also use the MDN to determine whether or not the service is
174 // activated, however, the CDMA ActivatonState property is a more absolute
175 // and fine-grained indicator of activation status.
176 return (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED);
177}
178
179bool CellularCapabilityUniversalCDMA::IsActivated() const {
180 return (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800181}
182
183void CellularCapabilityUniversalCDMA::OnServiceCreated() {
184 SLOG(Cellular, 2) << __func__;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800185 UpdateServiceActivationStateProperty();
Arman Uguray0a3e2792013-01-17 16:31:50 -0800186 HandleNewActivationStatus(MM_CDMA_ACTIVATION_ERROR_NONE);
187 UpdatePendingActivationState();
Arman Uguray72fab6a2013-01-10 19:32:42 -0800188}
189
Arman Uguray0a3e2792013-01-17 16:31:50 -0800190void CellularCapabilityUniversalCDMA::UpdateServiceActivationStateProperty() {
191 bool activation_required = IsServiceActivationRequired();
192 cellular()->service()->SetActivateOverNonCellularNetwork(activation_required);
193 string activation_state;
194 if (IsActivating())
Ben Chan7ea768e2013-09-20 15:08:40 -0700195 activation_state = kActivationStateActivating;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800196 else if (activation_required)
Ben Chan7ea768e2013-09-20 15:08:40 -0700197 activation_state = kActivationStateNotActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800198 else
Ben Chan7ea768e2013-09-20 15:08:40 -0700199 activation_state = kActivationStateActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800200 cellular()->service()->SetActivationState(activation_state);
201}
202
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700203void CellularCapabilityUniversalCDMA::UpdateServiceOLP() {
Ben Chan07193fd2013-07-12 22:10:55 -0700204 SLOG(Cellular, 2) << __func__;
205
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700206 // In this case, the Home Provider is trivial. All information comes from the
207 // Serving Operator.
208 if (!cellular()->serving_operator_info()->IsMobileNetworkOperatorKnown()) {
Ben Chan07193fd2013-07-12 22:10:55 -0700209 return;
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700210 }
Ben Chan07193fd2013-07-12 22:10:55 -0700211
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700212 const vector<MobileOperatorInfo::OnlinePortal> &olp_list =
213 cellular()->serving_operator_info()->olp_list();
214 if (olp_list.empty()) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800215 return;
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700216 }
Arman Uguray72fab6a2013-01-10 19:32:42 -0800217
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700218 if (olp_list.size() > 1) {
219 SLOG(Cellular, 1) << "Found multiple online portals. Choosing the first.";
220 }
221 string post_data = olp_list[0].post_data;
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800222 ReplaceSubstringsAfterOffset(&post_data, 0, "${esn}", cellular()->esn());
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700223 ReplaceSubstringsAfterOffset(
224 &post_data, 0, "${mdn}",
225 GetMdnForOLP(cellular()->serving_operator_info()));
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800226 ReplaceSubstringsAfterOffset(&post_data, 0, "${meid}", cellular()->meid());
Arman Ugurayf87fa2f2013-10-16 14:24:56 -0700227 ReplaceSubstringsAfterOffset(&post_data, 0, "${oem}", "GOG2");
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700228 cellular()->service()->SetOLP(olp_list[0].url, olp_list[0].method, post_data);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800229}
230
231void CellularCapabilityUniversalCDMA::GetProperties() {
232 SLOG(Cellular, 2) << __func__;
233 CellularCapabilityUniversal::GetProperties();
234
235 scoped_ptr<DBusPropertiesProxyInterface> properties_proxy(
236 proxy_factory()->CreateDBusPropertiesProxy(cellular()->dbus_path(),
237 cellular()->dbus_owner()));
238 DBusPropertiesMap properties(
239 properties_proxy->GetAll(MM_DBUS_INTERFACE_MODEM_MODEMCDMA));
240 OnModemCDMAPropertiesChanged(properties, vector<string>());
241}
242
Arman Uguray0a3e2792013-01-17 16:31:50 -0800243void CellularCapabilityUniversalCDMA::OnActivationStateChangedSignal(
244 uint32 activation_state,
245 uint32 activation_error,
246 const DBusPropertiesMap &status_changes) {
247 SLOG(Cellular, 2) << __func__;
248
249 activation_state_ =
250 static_cast<MMModemCdmaActivationState>(activation_state);
251
252 string value;
253 if (DBusProperties::GetString(status_changes, "mdn", &value))
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800254 cellular()->set_mdn(value);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800255 if (DBusProperties::GetString(status_changes, "min", &value))
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800256 cellular()->set_min(value);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800257
258 SLOG(Cellular, 2) << "Activation state: "
259 << GetActivationStateString(activation_state_);
260
261 HandleNewActivationStatus(activation_error);
262 UpdatePendingActivationState();
263}
264
265void CellularCapabilityUniversalCDMA::OnActivateReply(
266 const ResultCallback &callback,
267 const Error &error) {
268 SLOG(Cellular, 2) << __func__;
269 if (error.IsSuccess()) {
270 LOG(INFO) << "Activation completed successfully.";
271 modem_info()->pending_activation_store()->SetActivationState(
272 PendingActivationStore::kIdentifierMEID,
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800273 cellular()->meid(),
Arman Uguray0a3e2792013-01-17 16:31:50 -0800274 PendingActivationStore::kStateActivated);
275 } else {
276 LOG(ERROR) << "Activation failed with error: " << error;
277 modem_info()->pending_activation_store()->SetActivationState(
278 PendingActivationStore::kIdentifierMEID,
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800279 cellular()->meid(),
Arman Uguray0a3e2792013-01-17 16:31:50 -0800280 PendingActivationStore::kStateFailureRetry);
281 }
282 UpdatePendingActivationState();
Arman Ugurayf2b4a342013-05-23 18:26:52 -0700283
284 // CellularCapabilityUniversalCDMA::ActivateAutomatic passes a dummy
285 // ResultCallback when it calls Activate on the proxy object, in which case
286 // |callback.is_null()| will return true.
287 if (!callback.is_null())
288 callback.Run(error);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800289}
290
291void CellularCapabilityUniversalCDMA::HandleNewActivationStatus(uint32 error) {
292 SLOG(Cellular, 2) << __func__ << "(" << error << ")";
293 if (!cellular()->service().get()) {
294 LOG(ERROR) << "In " << __func__ << "(): service is null.";
295 return;
296 }
297 SLOG(Cellular, 2) << "Activation State: " << activation_state_;
298 cellular()->service()->SetActivationState(
299 GetActivationStateString(activation_state_));
300 cellular()->service()->set_error(GetActivationErrorString(error));
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700301 UpdateServiceOLP();
Arman Uguray0a3e2792013-01-17 16:31:50 -0800302}
303
304// static
305string CellularCapabilityUniversalCDMA::GetActivationStateString(
306 uint32 state) {
307 switch (state) {
308 case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700309 return kActivationStateActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800310 case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING:
Ben Chan7ea768e2013-09-20 15:08:40 -0700311 return kActivationStateActivating;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800312 case MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700313 return kActivationStateNotActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800314 case MM_MODEM_CDMA_ACTIVATION_STATE_PARTIALLY_ACTIVATED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700315 return kActivationStatePartiallyActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800316 default:
Ben Chan7ea768e2013-09-20 15:08:40 -0700317 return kActivationStateUnknown;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800318 }
319}
320
321// static
322string CellularCapabilityUniversalCDMA::GetActivationErrorString(
323 uint32 error) {
324 switch (error) {
325 case MM_CDMA_ACTIVATION_ERROR_WRONG_RADIO_INTERFACE:
Ben Chan7ea768e2013-09-20 15:08:40 -0700326 return kErrorNeedEvdo;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800327 case MM_CDMA_ACTIVATION_ERROR_ROAMING:
Ben Chan7ea768e2013-09-20 15:08:40 -0700328 return kErrorNeedHomeNetwork;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800329 case MM_CDMA_ACTIVATION_ERROR_COULD_NOT_CONNECT:
330 case MM_CDMA_ACTIVATION_ERROR_SECURITY_AUTHENTICATION_FAILED:
331 case MM_CDMA_ACTIVATION_ERROR_PROVISIONING_FAILED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700332 return kErrorOtaspFailed;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800333 case MM_CDMA_ACTIVATION_ERROR_NONE:
334 return "";
335 case MM_CDMA_ACTIVATION_ERROR_NO_SIGNAL:
336 default:
Ben Chan7ea768e2013-09-20 15:08:40 -0700337 return kErrorActivationFailed;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800338 }
339}
340
Arman Uguray72fab6a2013-01-10 19:32:42 -0800341void CellularCapabilityUniversalCDMA::Register(const ResultCallback &callback) {
342 // TODO(armansito): Remove once 3GPP is implemented in its own class.
343}
344
345void CellularCapabilityUniversalCDMA::RegisterOnNetwork(
346 const string &network_id,
347 Error *error,
348 const ResultCallback &callback) {
349 // TODO(armansito): Remove once 3GPP is implemented in its own class.
350}
351
Arman Uguray0a3e2792013-01-17 16:31:50 -0800352bool CellularCapabilityUniversalCDMA::IsActivating() const {
353 PendingActivationStore::State state =
354 modem_info()->pending_activation_store()->GetActivationState(
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800355 PendingActivationStore::kIdentifierMEID, cellular()->meid());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800356 return (state == PendingActivationStore::kStatePending) ||
357 (state == PendingActivationStore::kStateFailureRetry) ||
358 (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING);
359}
360
Ben Chan31ce5642013-11-14 13:37:40 -0800361bool CellularCapabilityUniversalCDMA::IsRegistered() const {
Ben Chanb2c4a802013-11-14 12:47:52 -0800362 return (cdma_1x_registration_state_ !=
363 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN ||
364 cdma_evdo_registration_state_ !=
365 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800366}
367
368void CellularCapabilityUniversalCDMA::SetUnregistered(bool /*searching*/) {
369 cdma_1x_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
370 cdma_evdo_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
371}
372
Arman Ugurayc9673062013-05-13 21:21:53 -0700373void CellularCapabilityUniversalCDMA::SetupConnectProperties(
374 DBusPropertiesMap *properties) {
375 (*properties)[kPropertyConnectNumber].writer().append_string(
376 kPhoneNumber);
377}
378
Arman Uguray72fab6a2013-01-10 19:32:42 -0800379void CellularCapabilityUniversalCDMA::RequirePIN(
380 const string &pin, bool require,
381 Error *error, const ResultCallback &callback) {
382 // TODO(armansito): Remove once 3GPP is implemented in its own class.
383}
384
385void CellularCapabilityUniversalCDMA::EnterPIN(
386 const string &pin,
387 Error *error,
388 const ResultCallback &callback) {
389 // TODO(armansito): Remove once 3GPP is implemented in its own class.
390}
391
392void CellularCapabilityUniversalCDMA::UnblockPIN(
393 const string &unblock_code,
394 const string &pin,
395 Error *error,
396 const ResultCallback &callback) {
397 // TODO(armansito): Remove once 3GPP is implemented in its own class.
398}
399
400void CellularCapabilityUniversalCDMA::ChangePIN(
401 const string &old_pin, const string &new_pin,
402 Error *error, const ResultCallback &callback) {
403 // TODO(armansito): Remove once 3GPP is implemented in its own class.
404}
405
Prathmesh Prabhu49ffffd2014-01-09 18:28:55 -0800406void CellularCapabilityUniversalCDMA::Scan(
407 Error *error,
408 const ResultStringmapsCallback &callback) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800409 // TODO(armansito): Remove once 3GPP is implemented in its own class.
Prathmesh Prabhu49ffffd2014-01-09 18:28:55 -0800410 OnUnsupportedOperation(__func__, error);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800411}
412
413void CellularCapabilityUniversalCDMA::OnSimPathChanged(
414 const string &sim_path) {
415 // TODO(armansito): Remove once 3GPP is implemented in its own class.
416}
417
418string CellularCapabilityUniversalCDMA::GetRoamingStateString() const {
419 uint32 state = cdma_evdo_registration_state_;
420 if (state == MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN) {
421 state = cdma_1x_registration_state_;
422 }
423 switch (state) {
424 case MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN:
425 case MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED:
426 break;
427 case MM_MODEM_CDMA_REGISTRATION_STATE_HOME:
Ben Chan7ea768e2013-09-20 15:08:40 -0700428 return kRoamingStateHome;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800429 case MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING:
Ben Chan7ea768e2013-09-20 15:08:40 -0700430 return kRoamingStateRoaming;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800431 default:
432 NOTREACHED();
433 }
Ben Chan7ea768e2013-09-20 15:08:40 -0700434 return kRoamingStateUnknown;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800435}
436
437void CellularCapabilityUniversalCDMA::OnDBusPropertiesChanged(
438 const string &interface,
439 const DBusPropertiesMap &changed_properties,
440 const vector<string> &invalidated_properties) {
441 SLOG(Cellular, 2) << __func__ << "(" << interface << ")";
442 if (interface == MM_DBUS_INTERFACE_MODEM_MODEMCDMA) {
443 OnModemCDMAPropertiesChanged(changed_properties, invalidated_properties);
444 } else {
445 CellularCapabilityUniversal::OnDBusPropertiesChanged(
446 interface, changed_properties, invalidated_properties);
447 }
448}
449
450void CellularCapabilityUniversalCDMA::OnModemCDMAPropertiesChanged(
451 const DBusPropertiesMap &properties,
452 const std::vector<std::string> &/*invalidated_properties*/) {
453 SLOG(Cellular, 2) << __func__;
454 string str_value;
455 if (DBusProperties::GetString(properties,
456 MM_MODEM_MODEMCDMA_PROPERTY_MEID,
457 &str_value))
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800458 cellular()->set_meid(str_value);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800459 if (DBusProperties::GetString(properties,
460 MM_MODEM_MODEMCDMA_PROPERTY_ESN,
461 &str_value))
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800462 cellular()->set_esn(str_value);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800463
464 uint32_t sid = sid_;
465 uint32_t nid = nid_;
466 MMModemCdmaRegistrationState state_1x = cdma_1x_registration_state_;
467 MMModemCdmaRegistrationState state_evdo = cdma_evdo_registration_state_;
468 bool registration_changed = false;
469 uint32_t uint_value;
470 if (DBusProperties::GetUint32(
471 properties,
472 MM_MODEM_MODEMCDMA_PROPERTY_CDMA1XREGISTRATIONSTATE,
473 &uint_value)) {
474 state_1x = static_cast<MMModemCdmaRegistrationState>(uint_value);
475 registration_changed = true;
476 }
477 if (DBusProperties::GetUint32(
478 properties,
479 MM_MODEM_MODEMCDMA_PROPERTY_EVDOREGISTRATIONSTATE,
480 &uint_value)) {
481 state_evdo = static_cast<MMModemCdmaRegistrationState>(uint_value);
482 registration_changed = true;
483 }
484 if (DBusProperties::GetUint32(
485 properties,
486 MM_MODEM_MODEMCDMA_PROPERTY_SID,
487 &uint_value)) {
488 sid = uint_value;
489 registration_changed = true;
490 }
491 if (DBusProperties::GetUint32(
492 properties,
493 MM_MODEM_MODEMCDMA_PROPERTY_NID,
494 &uint_value)) {
495 nid = uint_value;
496 registration_changed = true;
497 }
Arman Uguray0a3e2792013-01-17 16:31:50 -0800498 if (DBusProperties::GetUint32(
499 properties,
500 MM_MODEM_MODEMCDMA_PROPERTY_ACTIVATIONSTATE,
501 &uint_value)) {
502 activation_state_ = static_cast<MMModemCdmaActivationState>(uint_value);
503 HandleNewActivationStatus(MM_CDMA_ACTIVATION_ERROR_NONE);
504 }
Arman Uguray72fab6a2013-01-10 19:32:42 -0800505 if (registration_changed)
506 OnCDMARegistrationChanged(state_1x, state_evdo, sid, nid);
507}
508
509void CellularCapabilityUniversalCDMA::OnCDMARegistrationChanged(
510 MMModemCdmaRegistrationState state_1x,
511 MMModemCdmaRegistrationState state_evdo,
512 uint32_t sid, uint32_t nid) {
513 SLOG(Cellular, 2) << __func__
514 << ": state_1x=" << state_1x
515 << ", state_evdo=" << state_evdo;
516 cdma_1x_registration_state_ = state_1x;
517 cdma_evdo_registration_state_ = state_evdo;
518 sid_ = sid;
519 nid_ = nid;
Prathmesh Prabhu8599e052014-04-25 14:20:22 -0700520 cellular()->serving_operator_info()->UpdateSID(UintToString(sid));
521 cellular()->serving_operator_info()->UpdateNID(UintToString(nid));
Arman Uguray72fab6a2013-01-10 19:32:42 -0800522 cellular()->HandleNewRegistrationState();
523}
524
525} // namespace shill