blob: dd925f3ce12a904647df0f3911c01ab1c602e8ff [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() {
Prathmesh Prabhuf2288212014-05-21 19:19:19 -070095 if (!cellular()->serving_operator_info()->IsMobileNetworkOperatorKnown() ||
96 cellular()->serving_operator_info()->activation_code().empty()) {
Arman Uguray0a3e2792013-01-17 16:31:50 -080097 SLOG(Cellular, 2) << "OTA activation cannot be run in the presence of no "
98 << "activation code.";
99 return;
100 }
Prathmesh Prabhuf2288212014-05-21 19:19:19 -0700101
Arman Uguray0a3e2792013-01-17 16:31:50 -0800102 PendingActivationStore::State state =
103 modem_info()->pending_activation_store()->GetActivationState(
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800104 PendingActivationStore::kIdentifierMEID, cellular()->meid());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800105 if (state == PendingActivationStore::kStatePending) {
106 SLOG(Cellular, 2) << "There's already a pending activation. Ignoring.";
107 return;
108 }
109 if (state == PendingActivationStore::kStateActivated) {
110 SLOG(Cellular, 2) << "A call to OTA activation has already completed "
111 << "successfully. Ignoring.";
112 return;
113 }
114
115 // Mark as pending activation, so that shill can recover if anything fails
116 // during OTA activation.
117 modem_info()->pending_activation_store()->SetActivationState(
118 PendingActivationStore::kIdentifierMEID,
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800119 cellular()->meid(),
Arman Uguray0a3e2792013-01-17 16:31:50 -0800120 PendingActivationStore::kStatePending);
121
122 // Initiate OTA activation.
123 ResultCallback activation_callback =
124 Bind(&CellularCapabilityUniversalCDMA::OnActivateReply,
125 weak_cdma_ptr_factory_.GetWeakPtr(),
126 ResultCallback());
Arman Ugurayf2b4a342013-05-23 18:26:52 -0700127
Arman Uguray0a3e2792013-01-17 16:31:50 -0800128 Error error;
129 modem_cdma_proxy_->Activate(
Prathmesh Prabhuf2288212014-05-21 19:19:19 -0700130 cellular()->serving_operator_info()->activation_code(),
131 &error,
132 activation_callback,
133 kTimeoutActivate);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800134}
135
136void CellularCapabilityUniversalCDMA::UpdatePendingActivationState() {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800137 SLOG(Cellular, 2) << __func__;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800138 if (IsActivated()) {
139 SLOG(Cellular, 3) << "CDMA service activated. Clear store.";
140 modem_info()->pending_activation_store()->RemoveEntry(
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800141 PendingActivationStore::kIdentifierMEID, cellular()->meid());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800142 return;
143 }
144 PendingActivationStore::State state =
145 modem_info()->pending_activation_store()->GetActivationState(
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800146 PendingActivationStore::kIdentifierMEID, cellular()->meid());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800147 if (IsActivating() && state != PendingActivationStore::kStateFailureRetry) {
148 SLOG(Cellular, 3) << "OTA activation in progress. Nothing to do.";
149 return;
150 }
151 switch (state) {
152 case PendingActivationStore::kStateFailureRetry:
153 SLOG(Cellular, 3) << "OTA activation failed. Scheduling a retry.";
154 cellular()->dispatcher()->PostTask(
155 Bind(&CellularCapabilityUniversalCDMA::ActivateAutomatic,
156 weak_cdma_ptr_factory_.GetWeakPtr()));
157 break;
158 case PendingActivationStore::kStateActivated:
159 SLOG(Cellular, 3) << "OTA Activation has completed successfully. "
160 << "Waiting for activation state update to finalize.";
161 break;
162 default:
163 break;
164 }
165}
166
167bool CellularCapabilityUniversalCDMA::IsServiceActivationRequired() const {
168 // If there is no online payment portal information, it's safer to assume
169 // the service does not require activation.
Prathmesh Prabhu3ee2f412014-05-20 17:30:19 -0700170 if (!cellular()->serving_operator_info()->IsMobileNetworkOperatorKnown() ||
171 cellular()->serving_operator_info()->olp_list().empty()) {
Arman Uguray0a3e2792013-01-17 16:31:50 -0800172 return false;
Prathmesh Prabhu3ee2f412014-05-20 17:30:19 -0700173 }
Arman Uguray0a3e2792013-01-17 16:31:50 -0800174
175 // We could also use the MDN to determine whether or not the service is
176 // activated, however, the CDMA ActivatonState property is a more absolute
177 // and fine-grained indicator of activation status.
178 return (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED);
179}
180
181bool CellularCapabilityUniversalCDMA::IsActivated() const {
182 return (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800183}
184
185void CellularCapabilityUniversalCDMA::OnServiceCreated() {
186 SLOG(Cellular, 2) << __func__;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800187 UpdateServiceActivationStateProperty();
Arman Uguray0a3e2792013-01-17 16:31:50 -0800188 HandleNewActivationStatus(MM_CDMA_ACTIVATION_ERROR_NONE);
189 UpdatePendingActivationState();
Arman Uguray72fab6a2013-01-10 19:32:42 -0800190}
191
Arman Uguray0a3e2792013-01-17 16:31:50 -0800192void CellularCapabilityUniversalCDMA::UpdateServiceActivationStateProperty() {
193 bool activation_required = IsServiceActivationRequired();
194 cellular()->service()->SetActivateOverNonCellularNetwork(activation_required);
195 string activation_state;
196 if (IsActivating())
Ben Chan7ea768e2013-09-20 15:08:40 -0700197 activation_state = kActivationStateActivating;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800198 else if (activation_required)
Ben Chan7ea768e2013-09-20 15:08:40 -0700199 activation_state = kActivationStateNotActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800200 else
Ben Chan7ea768e2013-09-20 15:08:40 -0700201 activation_state = kActivationStateActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800202 cellular()->service()->SetActivationState(activation_state);
203}
204
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700205void CellularCapabilityUniversalCDMA::UpdateServiceOLP() {
Ben Chan07193fd2013-07-12 22:10:55 -0700206 SLOG(Cellular, 2) << __func__;
207
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700208 // In this case, the Home Provider is trivial. All information comes from the
209 // Serving Operator.
210 if (!cellular()->serving_operator_info()->IsMobileNetworkOperatorKnown()) {
Ben Chan07193fd2013-07-12 22:10:55 -0700211 return;
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700212 }
Ben Chan07193fd2013-07-12 22:10:55 -0700213
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700214 const vector<MobileOperatorInfo::OnlinePortal> &olp_list =
215 cellular()->serving_operator_info()->olp_list();
216 if (olp_list.empty()) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800217 return;
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700218 }
Arman Uguray72fab6a2013-01-10 19:32:42 -0800219
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700220 if (olp_list.size() > 1) {
221 SLOG(Cellular, 1) << "Found multiple online portals. Choosing the first.";
222 }
223 string post_data = olp_list[0].post_data;
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800224 ReplaceSubstringsAfterOffset(&post_data, 0, "${esn}", cellular()->esn());
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700225 ReplaceSubstringsAfterOffset(
226 &post_data, 0, "${mdn}",
227 GetMdnForOLP(cellular()->serving_operator_info()));
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800228 ReplaceSubstringsAfterOffset(&post_data, 0, "${meid}", cellular()->meid());
Arman Ugurayf87fa2f2013-10-16 14:24:56 -0700229 ReplaceSubstringsAfterOffset(&post_data, 0, "${oem}", "GOG2");
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700230 cellular()->service()->SetOLP(olp_list[0].url, olp_list[0].method, post_data);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800231}
232
233void CellularCapabilityUniversalCDMA::GetProperties() {
234 SLOG(Cellular, 2) << __func__;
235 CellularCapabilityUniversal::GetProperties();
236
237 scoped_ptr<DBusPropertiesProxyInterface> properties_proxy(
238 proxy_factory()->CreateDBusPropertiesProxy(cellular()->dbus_path(),
239 cellular()->dbus_owner()));
240 DBusPropertiesMap properties(
241 properties_proxy->GetAll(MM_DBUS_INTERFACE_MODEM_MODEMCDMA));
242 OnModemCDMAPropertiesChanged(properties, vector<string>());
243}
244
Arman Uguray0a3e2792013-01-17 16:31:50 -0800245void CellularCapabilityUniversalCDMA::OnActivationStateChangedSignal(
246 uint32 activation_state,
247 uint32 activation_error,
248 const DBusPropertiesMap &status_changes) {
249 SLOG(Cellular, 2) << __func__;
250
251 activation_state_ =
252 static_cast<MMModemCdmaActivationState>(activation_state);
253
254 string value;
255 if (DBusProperties::GetString(status_changes, "mdn", &value))
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800256 cellular()->set_mdn(value);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800257 if (DBusProperties::GetString(status_changes, "min", &value))
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800258 cellular()->set_min(value);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800259
260 SLOG(Cellular, 2) << "Activation state: "
261 << GetActivationStateString(activation_state_);
262
263 HandleNewActivationStatus(activation_error);
264 UpdatePendingActivationState();
265}
266
267void CellularCapabilityUniversalCDMA::OnActivateReply(
268 const ResultCallback &callback,
269 const Error &error) {
270 SLOG(Cellular, 2) << __func__;
271 if (error.IsSuccess()) {
272 LOG(INFO) << "Activation completed successfully.";
273 modem_info()->pending_activation_store()->SetActivationState(
274 PendingActivationStore::kIdentifierMEID,
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800275 cellular()->meid(),
Arman Uguray0a3e2792013-01-17 16:31:50 -0800276 PendingActivationStore::kStateActivated);
277 } else {
278 LOG(ERROR) << "Activation failed with error: " << error;
279 modem_info()->pending_activation_store()->SetActivationState(
280 PendingActivationStore::kIdentifierMEID,
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800281 cellular()->meid(),
Arman Uguray0a3e2792013-01-17 16:31:50 -0800282 PendingActivationStore::kStateFailureRetry);
283 }
284 UpdatePendingActivationState();
Arman Ugurayf2b4a342013-05-23 18:26:52 -0700285
286 // CellularCapabilityUniversalCDMA::ActivateAutomatic passes a dummy
287 // ResultCallback when it calls Activate on the proxy object, in which case
288 // |callback.is_null()| will return true.
289 if (!callback.is_null())
290 callback.Run(error);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800291}
292
293void CellularCapabilityUniversalCDMA::HandleNewActivationStatus(uint32 error) {
294 SLOG(Cellular, 2) << __func__ << "(" << error << ")";
295 if (!cellular()->service().get()) {
296 LOG(ERROR) << "In " << __func__ << "(): service is null.";
297 return;
298 }
299 SLOG(Cellular, 2) << "Activation State: " << activation_state_;
300 cellular()->service()->SetActivationState(
301 GetActivationStateString(activation_state_));
302 cellular()->service()->set_error(GetActivationErrorString(error));
Prathmesh Prabhu92df6192014-04-29 18:08:08 -0700303 UpdateServiceOLP();
Arman Uguray0a3e2792013-01-17 16:31:50 -0800304}
305
306// static
307string CellularCapabilityUniversalCDMA::GetActivationStateString(
308 uint32 state) {
309 switch (state) {
310 case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700311 return kActivationStateActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800312 case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING:
Ben Chan7ea768e2013-09-20 15:08:40 -0700313 return kActivationStateActivating;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800314 case MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700315 return kActivationStateNotActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800316 case MM_MODEM_CDMA_ACTIVATION_STATE_PARTIALLY_ACTIVATED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700317 return kActivationStatePartiallyActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800318 default:
Ben Chan7ea768e2013-09-20 15:08:40 -0700319 return kActivationStateUnknown;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800320 }
321}
322
323// static
324string CellularCapabilityUniversalCDMA::GetActivationErrorString(
325 uint32 error) {
326 switch (error) {
327 case MM_CDMA_ACTIVATION_ERROR_WRONG_RADIO_INTERFACE:
Ben Chan7ea768e2013-09-20 15:08:40 -0700328 return kErrorNeedEvdo;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800329 case MM_CDMA_ACTIVATION_ERROR_ROAMING:
Ben Chan7ea768e2013-09-20 15:08:40 -0700330 return kErrorNeedHomeNetwork;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800331 case MM_CDMA_ACTIVATION_ERROR_COULD_NOT_CONNECT:
332 case MM_CDMA_ACTIVATION_ERROR_SECURITY_AUTHENTICATION_FAILED:
333 case MM_CDMA_ACTIVATION_ERROR_PROVISIONING_FAILED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700334 return kErrorOtaspFailed;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800335 case MM_CDMA_ACTIVATION_ERROR_NONE:
336 return "";
337 case MM_CDMA_ACTIVATION_ERROR_NO_SIGNAL:
338 default:
Ben Chan7ea768e2013-09-20 15:08:40 -0700339 return kErrorActivationFailed;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800340 }
341}
342
Arman Uguray72fab6a2013-01-10 19:32:42 -0800343void CellularCapabilityUniversalCDMA::Register(const ResultCallback &callback) {
344 // TODO(armansito): Remove once 3GPP is implemented in its own class.
345}
346
347void CellularCapabilityUniversalCDMA::RegisterOnNetwork(
348 const string &network_id,
349 Error *error,
350 const ResultCallback &callback) {
351 // TODO(armansito): Remove once 3GPP is implemented in its own class.
352}
353
Arman Uguray0a3e2792013-01-17 16:31:50 -0800354bool CellularCapabilityUniversalCDMA::IsActivating() const {
355 PendingActivationStore::State state =
356 modem_info()->pending_activation_store()->GetActivationState(
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800357 PendingActivationStore::kIdentifierMEID, cellular()->meid());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800358 return (state == PendingActivationStore::kStatePending) ||
359 (state == PendingActivationStore::kStateFailureRetry) ||
360 (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING);
361}
362
Ben Chan31ce5642013-11-14 13:37:40 -0800363bool CellularCapabilityUniversalCDMA::IsRegistered() const {
Ben Chanb2c4a802013-11-14 12:47:52 -0800364 return (cdma_1x_registration_state_ !=
365 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN ||
366 cdma_evdo_registration_state_ !=
367 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800368}
369
370void CellularCapabilityUniversalCDMA::SetUnregistered(bool /*searching*/) {
371 cdma_1x_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
372 cdma_evdo_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
373}
374
Arman Ugurayc9673062013-05-13 21:21:53 -0700375void CellularCapabilityUniversalCDMA::SetupConnectProperties(
376 DBusPropertiesMap *properties) {
377 (*properties)[kPropertyConnectNumber].writer().append_string(
378 kPhoneNumber);
379}
380
Arman Uguray72fab6a2013-01-10 19:32:42 -0800381void CellularCapabilityUniversalCDMA::RequirePIN(
382 const string &pin, bool require,
383 Error *error, const ResultCallback &callback) {
384 // TODO(armansito): Remove once 3GPP is implemented in its own class.
385}
386
387void CellularCapabilityUniversalCDMA::EnterPIN(
388 const string &pin,
389 Error *error,
390 const ResultCallback &callback) {
391 // TODO(armansito): Remove once 3GPP is implemented in its own class.
392}
393
394void CellularCapabilityUniversalCDMA::UnblockPIN(
395 const string &unblock_code,
396 const string &pin,
397 Error *error,
398 const ResultCallback &callback) {
399 // TODO(armansito): Remove once 3GPP is implemented in its own class.
400}
401
402void CellularCapabilityUniversalCDMA::ChangePIN(
403 const string &old_pin, const string &new_pin,
404 Error *error, const ResultCallback &callback) {
405 // TODO(armansito): Remove once 3GPP is implemented in its own class.
406}
407
Prathmesh Prabhu49ffffd2014-01-09 18:28:55 -0800408void CellularCapabilityUniversalCDMA::Scan(
409 Error *error,
410 const ResultStringmapsCallback &callback) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800411 // TODO(armansito): Remove once 3GPP is implemented in its own class.
Prathmesh Prabhu49ffffd2014-01-09 18:28:55 -0800412 OnUnsupportedOperation(__func__, error);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800413}
414
415void CellularCapabilityUniversalCDMA::OnSimPathChanged(
416 const string &sim_path) {
417 // TODO(armansito): Remove once 3GPP is implemented in its own class.
418}
419
420string CellularCapabilityUniversalCDMA::GetRoamingStateString() const {
421 uint32 state = cdma_evdo_registration_state_;
422 if (state == MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN) {
423 state = cdma_1x_registration_state_;
424 }
425 switch (state) {
426 case MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN:
427 case MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED:
428 break;
429 case MM_MODEM_CDMA_REGISTRATION_STATE_HOME:
Ben Chan7ea768e2013-09-20 15:08:40 -0700430 return kRoamingStateHome;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800431 case MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING:
Ben Chan7ea768e2013-09-20 15:08:40 -0700432 return kRoamingStateRoaming;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800433 default:
434 NOTREACHED();
435 }
Ben Chan7ea768e2013-09-20 15:08:40 -0700436 return kRoamingStateUnknown;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800437}
438
439void CellularCapabilityUniversalCDMA::OnDBusPropertiesChanged(
440 const string &interface,
441 const DBusPropertiesMap &changed_properties,
442 const vector<string> &invalidated_properties) {
443 SLOG(Cellular, 2) << __func__ << "(" << interface << ")";
444 if (interface == MM_DBUS_INTERFACE_MODEM_MODEMCDMA) {
445 OnModemCDMAPropertiesChanged(changed_properties, invalidated_properties);
446 } else {
447 CellularCapabilityUniversal::OnDBusPropertiesChanged(
448 interface, changed_properties, invalidated_properties);
449 }
450}
451
452void CellularCapabilityUniversalCDMA::OnModemCDMAPropertiesChanged(
453 const DBusPropertiesMap &properties,
454 const std::vector<std::string> &/*invalidated_properties*/) {
455 SLOG(Cellular, 2) << __func__;
456 string str_value;
457 if (DBusProperties::GetString(properties,
458 MM_MODEM_MODEMCDMA_PROPERTY_MEID,
459 &str_value))
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800460 cellular()->set_meid(str_value);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800461 if (DBusProperties::GetString(properties,
462 MM_MODEM_MODEMCDMA_PROPERTY_ESN,
463 &str_value))
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800464 cellular()->set_esn(str_value);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800465
466 uint32_t sid = sid_;
467 uint32_t nid = nid_;
468 MMModemCdmaRegistrationState state_1x = cdma_1x_registration_state_;
469 MMModemCdmaRegistrationState state_evdo = cdma_evdo_registration_state_;
470 bool registration_changed = false;
471 uint32_t uint_value;
472 if (DBusProperties::GetUint32(
473 properties,
474 MM_MODEM_MODEMCDMA_PROPERTY_CDMA1XREGISTRATIONSTATE,
475 &uint_value)) {
476 state_1x = static_cast<MMModemCdmaRegistrationState>(uint_value);
477 registration_changed = true;
478 }
479 if (DBusProperties::GetUint32(
480 properties,
481 MM_MODEM_MODEMCDMA_PROPERTY_EVDOREGISTRATIONSTATE,
482 &uint_value)) {
483 state_evdo = static_cast<MMModemCdmaRegistrationState>(uint_value);
484 registration_changed = true;
485 }
486 if (DBusProperties::GetUint32(
487 properties,
488 MM_MODEM_MODEMCDMA_PROPERTY_SID,
489 &uint_value)) {
490 sid = uint_value;
491 registration_changed = true;
492 }
493 if (DBusProperties::GetUint32(
494 properties,
495 MM_MODEM_MODEMCDMA_PROPERTY_NID,
496 &uint_value)) {
497 nid = uint_value;
498 registration_changed = true;
499 }
Arman Uguray0a3e2792013-01-17 16:31:50 -0800500 if (DBusProperties::GetUint32(
501 properties,
502 MM_MODEM_MODEMCDMA_PROPERTY_ACTIVATIONSTATE,
503 &uint_value)) {
504 activation_state_ = static_cast<MMModemCdmaActivationState>(uint_value);
505 HandleNewActivationStatus(MM_CDMA_ACTIVATION_ERROR_NONE);
506 }
Arman Uguray72fab6a2013-01-10 19:32:42 -0800507 if (registration_changed)
508 OnCDMARegistrationChanged(state_1x, state_evdo, sid, nid);
509}
510
511void CellularCapabilityUniversalCDMA::OnCDMARegistrationChanged(
512 MMModemCdmaRegistrationState state_1x,
513 MMModemCdmaRegistrationState state_evdo,
514 uint32_t sid, uint32_t nid) {
515 SLOG(Cellular, 2) << __func__
516 << ": state_1x=" << state_1x
517 << ", state_evdo=" << state_evdo;
518 cdma_1x_registration_state_ = state_1x;
519 cdma_evdo_registration_state_ = state_evdo;
520 sid_ = sid;
521 nid_ = nid;
Prathmesh Prabhu8599e052014-04-25 14:20:22 -0700522 cellular()->serving_operator_info()->UpdateSID(UintToString(sid));
523 cellular()->serving_operator_info()->UpdateNID(UintToString(nid));
Arman Uguray72fab6a2013-01-10 19:32:42 -0800524 cellular()->HandleNewRegistrationState();
525}
526
527} // namespace shill