blob: 09f79679fafca4deaac67450b03aa0df624af786 [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 -080036string FormattedSID(const string &sid) {
37 return "[SID=" + sid + "]";
38}
39
40} // namespace
41
Arman Uguray72fab6a2013-01-10 19:32:42 -080042CellularCapabilityUniversalCDMA::CellularCapabilityUniversalCDMA(
43 Cellular *cellular,
44 ProxyFactory *proxy_factory,
45 ModemInfo *modem_info)
Ben Chanf98f00e2014-02-05 14:48:43 -080046 : CellularCapabilityUniversal(cellular, proxy_factory, modem_info),
Arman Uguray0a3e2792013-01-17 16:31:50 -080047 weak_cdma_ptr_factory_(this),
48 activation_state_(MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED),
Arman Uguray72fab6a2013-01-10 19:32:42 -080049 cdma_1x_registration_state_(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN),
50 cdma_evdo_registration_state_(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN),
51 nid_(0),
52 sid_(0) {
53 SLOG(Cellular, 2) << "Cellular capability constructed: Universal CDMA";
Arman Uguray0a3e2792013-01-17 16:31:50 -080054 // TODO(armansito): Update PRL for activation over cellular.
Arman Uguray72fab6a2013-01-10 19:32:42 -080055 // See crbug.com/197330.
56}
57
Ben Chanf98f00e2014-02-05 14:48:43 -080058CellularCapabilityUniversalCDMA::~CellularCapabilityUniversalCDMA() {}
59
Arman Uguray72fab6a2013-01-10 19:32:42 -080060void CellularCapabilityUniversalCDMA::InitProxies() {
61 SLOG(Cellular, 2) << __func__;
62 modem_cdma_proxy_.reset(
63 proxy_factory()->CreateMM1ModemModemCdmaProxy(cellular()->dbus_path(),
64 cellular()->dbus_owner()));
Arman Uguray0a3e2792013-01-17 16:31:50 -080065 modem_cdma_proxy_->set_activation_state_callback(
66 Bind(&CellularCapabilityUniversalCDMA::OnActivationStateChangedSignal,
67 weak_cdma_ptr_factory_.GetWeakPtr()));
Arman Uguray72fab6a2013-01-10 19:32:42 -080068 CellularCapabilityUniversal::InitProxies();
69}
70
71void CellularCapabilityUniversalCDMA::ReleaseProxies() {
72 SLOG(Cellular, 2) << __func__;
73 modem_cdma_proxy_.reset();
74 CellularCapabilityUniversal::ReleaseProxies();
75}
76
Ben Chanf98f00e2014-02-05 14:48:43 -080077void CellularCapabilityUniversalCDMA::Activate(const string &carrier,
78 Error *error,
79 const ResultCallback &callback) {
Arman Uguray0a3e2792013-01-17 16:31:50 -080080 // Currently activation over the cellular network is not supported using
81 // ModemManager-next. Service activation is currently carried through over
82 // non-cellular networks and only the final step of the OTA activation
83 // procedure ("automatic activation") is performed by this class.
Arman Uguray72fab6a2013-01-10 19:32:42 -080084 OnUnsupportedOperation(__func__, error);
85}
86
87void CellularCapabilityUniversalCDMA::CompleteActivation(Error *error) {
Arman Uguray0a3e2792013-01-17 16:31:50 -080088 SLOG(Cellular, 2) << __func__;
89 if (cellular()->state() < Cellular::kStateEnabled) {
90 Error::PopulateAndLog(error, Error::kInvalidArguments,
91 "Unable to activate in state " +
92 Cellular::GetStateString(cellular()->state()));
93 return;
94 }
95 ActivateAutomatic();
Arman Uguray72fab6a2013-01-10 19:32:42 -080096}
97
Arman Uguray0a3e2792013-01-17 16:31:50 -080098void CellularCapabilityUniversalCDMA::ActivateAutomatic() {
99 if (activation_code_.empty()) {
100 SLOG(Cellular, 2) << "OTA activation cannot be run in the presence of no "
101 << "activation code.";
102 return;
103 }
104 PendingActivationStore::State state =
105 modem_info()->pending_activation_store()->GetActivationState(
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800106 PendingActivationStore::kIdentifierMEID, cellular()->meid());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800107 if (state == PendingActivationStore::kStatePending) {
108 SLOG(Cellular, 2) << "There's already a pending activation. Ignoring.";
109 return;
110 }
111 if (state == PendingActivationStore::kStateActivated) {
112 SLOG(Cellular, 2) << "A call to OTA activation has already completed "
113 << "successfully. Ignoring.";
114 return;
115 }
116
117 // Mark as pending activation, so that shill can recover if anything fails
118 // during OTA activation.
119 modem_info()->pending_activation_store()->SetActivationState(
120 PendingActivationStore::kIdentifierMEID,
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800121 cellular()->meid(),
Arman Uguray0a3e2792013-01-17 16:31:50 -0800122 PendingActivationStore::kStatePending);
123
124 // Initiate OTA activation.
125 ResultCallback activation_callback =
126 Bind(&CellularCapabilityUniversalCDMA::OnActivateReply,
127 weak_cdma_ptr_factory_.GetWeakPtr(),
128 ResultCallback());
Arman Ugurayf2b4a342013-05-23 18:26:52 -0700129
Arman Uguray0a3e2792013-01-17 16:31:50 -0800130 Error error;
131 modem_cdma_proxy_->Activate(
132 activation_code_, &error, activation_callback, kTimeoutActivate);
133}
134
135void CellularCapabilityUniversalCDMA::UpdatePendingActivationState() {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800136 SLOG(Cellular, 2) << __func__;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800137 if (IsActivated()) {
138 SLOG(Cellular, 3) << "CDMA service activated. Clear store.";
139 modem_info()->pending_activation_store()->RemoveEntry(
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800140 PendingActivationStore::kIdentifierMEID, cellular()->meid());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800141 return;
142 }
143 PendingActivationStore::State state =
144 modem_info()->pending_activation_store()->GetActivationState(
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800145 PendingActivationStore::kIdentifierMEID, cellular()->meid());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800146 if (IsActivating() && state != PendingActivationStore::kStateFailureRetry) {
147 SLOG(Cellular, 3) << "OTA activation in progress. Nothing to do.";
148 return;
149 }
150 switch (state) {
151 case PendingActivationStore::kStateFailureRetry:
152 SLOG(Cellular, 3) << "OTA activation failed. Scheduling a retry.";
153 cellular()->dispatcher()->PostTask(
154 Bind(&CellularCapabilityUniversalCDMA::ActivateAutomatic,
155 weak_cdma_ptr_factory_.GetWeakPtr()));
156 break;
157 case PendingActivationStore::kStateActivated:
158 SLOG(Cellular, 3) << "OTA Activation has completed successfully. "
159 << "Waiting for activation state update to finalize.";
160 break;
161 default:
162 break;
163 }
164}
165
166bool CellularCapabilityUniversalCDMA::IsServiceActivationRequired() const {
167 // If there is no online payment portal information, it's safer to assume
168 // the service does not require activation.
169 if (!modem_info()->cellular_operator_info())
170 return false;
171
172 const CellularService::OLP *olp =
173 modem_info()->cellular_operator_info()->GetOLPBySID(UintToString(sid_));
174 if (!olp)
175 return false;
176
177 // We could also use the MDN to determine whether or not the service is
178 // activated, however, the CDMA ActivatonState property is a more absolute
179 // and fine-grained indicator of activation status.
180 return (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED);
181}
182
183bool CellularCapabilityUniversalCDMA::IsActivated() const {
184 return (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800185}
186
187void CellularCapabilityUniversalCDMA::OnServiceCreated() {
188 SLOG(Cellular, 2) << __func__;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800189 UpdateServiceActivationStateProperty();
Arman Uguray72fab6a2013-01-10 19:32:42 -0800190 UpdateServingOperator();
Arman Uguray0a3e2792013-01-17 16:31:50 -0800191 HandleNewActivationStatus(MM_CDMA_ACTIVATION_ERROR_NONE);
192 UpdatePendingActivationState();
Arman Uguray72fab6a2013-01-10 19:32:42 -0800193 UpdateOLP();
194}
195
Arman Uguray0a3e2792013-01-17 16:31:50 -0800196void CellularCapabilityUniversalCDMA::UpdateServiceActivationStateProperty() {
197 bool activation_required = IsServiceActivationRequired();
198 cellular()->service()->SetActivateOverNonCellularNetwork(activation_required);
199 string activation_state;
200 if (IsActivating())
Ben Chan7ea768e2013-09-20 15:08:40 -0700201 activation_state = kActivationStateActivating;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800202 else if (activation_required)
Ben Chan7ea768e2013-09-20 15:08:40 -0700203 activation_state = kActivationStateNotActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800204 else
Ben Chan7ea768e2013-09-20 15:08:40 -0700205 activation_state = kActivationStateActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800206 cellular()->service()->SetActivationState(activation_state);
207}
208
Arman Uguray72fab6a2013-01-10 19:32:42 -0800209void CellularCapabilityUniversalCDMA::UpdateOLP() {
Ben Chan07193fd2013-07-12 22:10:55 -0700210 SLOG(Cellular, 2) << __func__;
211
212 const CellularOperatorInfo *cellular_operator_info =
213 modem_info()->cellular_operator_info();
214 if (!cellular_operator_info)
215 return;
216
217 string sid_string = UintToString(sid_);
218 const CellularOperatorInfo::CellularOperator *cellular_operator =
219 cellular_operator_info->GetCellularOperatorBySID(sid_string);
220 if (!cellular_operator)
Arman Uguray72fab6a2013-01-10 19:32:42 -0800221 return;
222
223 const CellularService::OLP *result =
Ben Chan07193fd2013-07-12 22:10:55 -0700224 cellular_operator_info->GetOLPBySID(sid_string);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800225 if (!result)
226 return;
227
228 CellularService::OLP olp;
229 olp.CopyFrom(*result);
230 string post_data = olp.GetPostData();
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800231 ReplaceSubstringsAfterOffset(&post_data, 0, "${esn}", cellular()->esn());
Ben Chan07193fd2013-07-12 22:10:55 -0700232 ReplaceSubstringsAfterOffset(&post_data, 0, "${mdn}",
233 GetMdnForOLP(*cellular_operator));
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800234 ReplaceSubstringsAfterOffset(&post_data, 0, "${meid}", cellular()->meid());
Arman Ugurayf87fa2f2013-10-16 14:24:56 -0700235 ReplaceSubstringsAfterOffset(&post_data, 0, "${oem}", "GOG2");
Arman Uguray72fab6a2013-01-10 19:32:42 -0800236 olp.SetPostData(post_data);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800237 if (cellular()->service().get())
238 cellular()->service()->SetOLP(olp);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800239}
240
241void CellularCapabilityUniversalCDMA::GetProperties() {
242 SLOG(Cellular, 2) << __func__;
243 CellularCapabilityUniversal::GetProperties();
244
245 scoped_ptr<DBusPropertiesProxyInterface> properties_proxy(
246 proxy_factory()->CreateDBusPropertiesProxy(cellular()->dbus_path(),
247 cellular()->dbus_owner()));
248 DBusPropertiesMap properties(
249 properties_proxy->GetAll(MM_DBUS_INTERFACE_MODEM_MODEMCDMA));
250 OnModemCDMAPropertiesChanged(properties, vector<string>());
251}
252
Arman Uguray72fab6a2013-01-10 19:32:42 -0800253void CellularCapabilityUniversalCDMA::UpdateOperatorInfo() {
254 SLOG(Cellular, 2) << __func__;
255
256 if (sid_ == 0 || !modem_info()->cellular_operator_info()) {
257 SLOG(Cellular, 2) << "No provider is currently available.";
258 provider_.SetCode("");
259 return;
260 }
261
262 string sid = UintToString(sid_);
263 const CellularOperatorInfo::CellularOperator *provider =
264 modem_info()->cellular_operator_info()->GetCellularOperatorBySID(sid);
265 if (!provider) {
266 SLOG(Cellular, 2) << "CDMA provider with "
267 << FormattedSID(sid)
268 << " not found.";
Arman Uguraye015faf2013-08-16 17:54:59 -0700269 // If a matching provider is not found, shill should update the
270 // Cellular.ServingOperator property to to display the Sid.
271 provider_.SetCode(sid);
272 provider_.SetCountry("");
273 provider_.SetName("");
274 activation_code_.clear();
275 } else {
276 if (!provider->name_list().empty()) {
277 provider_.SetName(provider->name_list()[0].name);
278 }
279 provider_.SetCode(sid);
280 provider_.SetCountry(provider->country());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800281
Arman Uguraye015faf2013-08-16 17:54:59 -0700282 activation_code_ = provider->activation_code();
Arman Uguray72fab6a2013-01-10 19:32:42 -0800283 }
Arman Uguray0a3e2792013-01-17 16:31:50 -0800284
Arman Uguray72fab6a2013-01-10 19:32:42 -0800285 // TODO(armansito): The CDMA interface only returns information about the
286 // current serving carrier, so for now both the home provider and the
287 // serving operator will be the same in case of roaming. We should figure
288 // out if there is a way to (and whether or not it is necessary to)
289 // determine if we're roaming.
290 cellular()->set_home_provider(provider_);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800291 UpdateServingOperator();
292}
293
294void CellularCapabilityUniversalCDMA::UpdateServingOperator() {
295 SLOG(Cellular, 2) << __func__;
296 if (cellular()->service().get()) {
297 cellular()->service()->SetServingOperator(cellular()->home_provider());
298 }
299}
300
Arman Uguray0a3e2792013-01-17 16:31:50 -0800301void CellularCapabilityUniversalCDMA::OnActivationStateChangedSignal(
302 uint32 activation_state,
303 uint32 activation_error,
304 const DBusPropertiesMap &status_changes) {
305 SLOG(Cellular, 2) << __func__;
306
307 activation_state_ =
308 static_cast<MMModemCdmaActivationState>(activation_state);
309
310 string value;
311 if (DBusProperties::GetString(status_changes, "mdn", &value))
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800312 cellular()->set_mdn(value);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800313 if (DBusProperties::GetString(status_changes, "min", &value))
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800314 cellular()->set_min(value);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800315
316 SLOG(Cellular, 2) << "Activation state: "
317 << GetActivationStateString(activation_state_);
318
319 HandleNewActivationStatus(activation_error);
320 UpdatePendingActivationState();
321}
322
323void CellularCapabilityUniversalCDMA::OnActivateReply(
324 const ResultCallback &callback,
325 const Error &error) {
326 SLOG(Cellular, 2) << __func__;
327 if (error.IsSuccess()) {
328 LOG(INFO) << "Activation completed successfully.";
329 modem_info()->pending_activation_store()->SetActivationState(
330 PendingActivationStore::kIdentifierMEID,
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800331 cellular()->meid(),
Arman Uguray0a3e2792013-01-17 16:31:50 -0800332 PendingActivationStore::kStateActivated);
333 } else {
334 LOG(ERROR) << "Activation failed with error: " << error;
335 modem_info()->pending_activation_store()->SetActivationState(
336 PendingActivationStore::kIdentifierMEID,
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800337 cellular()->meid(),
Arman Uguray0a3e2792013-01-17 16:31:50 -0800338 PendingActivationStore::kStateFailureRetry);
339 }
340 UpdatePendingActivationState();
Arman Ugurayf2b4a342013-05-23 18:26:52 -0700341
342 // CellularCapabilityUniversalCDMA::ActivateAutomatic passes a dummy
343 // ResultCallback when it calls Activate on the proxy object, in which case
344 // |callback.is_null()| will return true.
345 if (!callback.is_null())
346 callback.Run(error);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800347}
348
349void CellularCapabilityUniversalCDMA::HandleNewActivationStatus(uint32 error) {
350 SLOG(Cellular, 2) << __func__ << "(" << error << ")";
351 if (!cellular()->service().get()) {
352 LOG(ERROR) << "In " << __func__ << "(): service is null.";
353 return;
354 }
355 SLOG(Cellular, 2) << "Activation State: " << activation_state_;
356 cellular()->service()->SetActivationState(
357 GetActivationStateString(activation_state_));
358 cellular()->service()->set_error(GetActivationErrorString(error));
359 UpdateOLP();
360}
361
362// static
363string CellularCapabilityUniversalCDMA::GetActivationStateString(
364 uint32 state) {
365 switch (state) {
366 case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700367 return kActivationStateActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800368 case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING:
Ben Chan7ea768e2013-09-20 15:08:40 -0700369 return kActivationStateActivating;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800370 case MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700371 return kActivationStateNotActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800372 case MM_MODEM_CDMA_ACTIVATION_STATE_PARTIALLY_ACTIVATED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700373 return kActivationStatePartiallyActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800374 default:
Ben Chan7ea768e2013-09-20 15:08:40 -0700375 return kActivationStateUnknown;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800376 }
377}
378
379// static
380string CellularCapabilityUniversalCDMA::GetActivationErrorString(
381 uint32 error) {
382 switch (error) {
383 case MM_CDMA_ACTIVATION_ERROR_WRONG_RADIO_INTERFACE:
Ben Chan7ea768e2013-09-20 15:08:40 -0700384 return kErrorNeedEvdo;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800385 case MM_CDMA_ACTIVATION_ERROR_ROAMING:
Ben Chan7ea768e2013-09-20 15:08:40 -0700386 return kErrorNeedHomeNetwork;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800387 case MM_CDMA_ACTIVATION_ERROR_COULD_NOT_CONNECT:
388 case MM_CDMA_ACTIVATION_ERROR_SECURITY_AUTHENTICATION_FAILED:
389 case MM_CDMA_ACTIVATION_ERROR_PROVISIONING_FAILED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700390 return kErrorOtaspFailed;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800391 case MM_CDMA_ACTIVATION_ERROR_NONE:
392 return "";
393 case MM_CDMA_ACTIVATION_ERROR_NO_SIGNAL:
394 default:
Ben Chan7ea768e2013-09-20 15:08:40 -0700395 return kErrorActivationFailed;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800396 }
397}
398
Arman Uguray72fab6a2013-01-10 19:32:42 -0800399void CellularCapabilityUniversalCDMA::Register(const ResultCallback &callback) {
400 // TODO(armansito): Remove once 3GPP is implemented in its own class.
401}
402
403void CellularCapabilityUniversalCDMA::RegisterOnNetwork(
404 const string &network_id,
405 Error *error,
406 const ResultCallback &callback) {
407 // TODO(armansito): Remove once 3GPP is implemented in its own class.
408}
409
Arman Uguray0a3e2792013-01-17 16:31:50 -0800410bool CellularCapabilityUniversalCDMA::IsActivating() const {
411 PendingActivationStore::State state =
412 modem_info()->pending_activation_store()->GetActivationState(
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800413 PendingActivationStore::kIdentifierMEID, cellular()->meid());
Arman Uguray0a3e2792013-01-17 16:31:50 -0800414 return (state == PendingActivationStore::kStatePending) ||
415 (state == PendingActivationStore::kStateFailureRetry) ||
416 (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING);
417}
418
Ben Chan31ce5642013-11-14 13:37:40 -0800419bool CellularCapabilityUniversalCDMA::IsRegistered() const {
Ben Chanb2c4a802013-11-14 12:47:52 -0800420 return (cdma_1x_registration_state_ !=
421 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN ||
422 cdma_evdo_registration_state_ !=
423 MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800424}
425
426void CellularCapabilityUniversalCDMA::SetUnregistered(bool /*searching*/) {
427 cdma_1x_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
428 cdma_evdo_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
429}
430
Arman Ugurayc9673062013-05-13 21:21:53 -0700431void CellularCapabilityUniversalCDMA::SetupConnectProperties(
432 DBusPropertiesMap *properties) {
433 (*properties)[kPropertyConnectNumber].writer().append_string(
434 kPhoneNumber);
435}
436
Arman Uguray72fab6a2013-01-10 19:32:42 -0800437void CellularCapabilityUniversalCDMA::RequirePIN(
438 const string &pin, bool require,
439 Error *error, const ResultCallback &callback) {
440 // TODO(armansito): Remove once 3GPP is implemented in its own class.
441}
442
443void CellularCapabilityUniversalCDMA::EnterPIN(
444 const string &pin,
445 Error *error,
446 const ResultCallback &callback) {
447 // TODO(armansito): Remove once 3GPP is implemented in its own class.
448}
449
450void CellularCapabilityUniversalCDMA::UnblockPIN(
451 const string &unblock_code,
452 const string &pin,
453 Error *error,
454 const ResultCallback &callback) {
455 // TODO(armansito): Remove once 3GPP is implemented in its own class.
456}
457
458void CellularCapabilityUniversalCDMA::ChangePIN(
459 const string &old_pin, const string &new_pin,
460 Error *error, const ResultCallback &callback) {
461 // TODO(armansito): Remove once 3GPP is implemented in its own class.
462}
463
Prathmesh Prabhu49ffffd2014-01-09 18:28:55 -0800464void CellularCapabilityUniversalCDMA::Scan(
465 Error *error,
466 const ResultStringmapsCallback &callback) {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800467 // TODO(armansito): Remove once 3GPP is implemented in its own class.
Prathmesh Prabhu49ffffd2014-01-09 18:28:55 -0800468 OnUnsupportedOperation(__func__, error);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800469}
470
471void CellularCapabilityUniversalCDMA::OnSimPathChanged(
472 const string &sim_path) {
473 // TODO(armansito): Remove once 3GPP is implemented in its own class.
474}
475
476string CellularCapabilityUniversalCDMA::GetRoamingStateString() const {
477 uint32 state = cdma_evdo_registration_state_;
478 if (state == MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN) {
479 state = cdma_1x_registration_state_;
480 }
481 switch (state) {
482 case MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN:
483 case MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED:
484 break;
485 case MM_MODEM_CDMA_REGISTRATION_STATE_HOME:
Ben Chan7ea768e2013-09-20 15:08:40 -0700486 return kRoamingStateHome;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800487 case MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING:
Ben Chan7ea768e2013-09-20 15:08:40 -0700488 return kRoamingStateRoaming;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800489 default:
490 NOTREACHED();
491 }
Ben Chan7ea768e2013-09-20 15:08:40 -0700492 return kRoamingStateUnknown;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800493}
494
495void CellularCapabilityUniversalCDMA::OnDBusPropertiesChanged(
496 const string &interface,
497 const DBusPropertiesMap &changed_properties,
498 const vector<string> &invalidated_properties) {
499 SLOG(Cellular, 2) << __func__ << "(" << interface << ")";
500 if (interface == MM_DBUS_INTERFACE_MODEM_MODEMCDMA) {
501 OnModemCDMAPropertiesChanged(changed_properties, invalidated_properties);
502 } else {
503 CellularCapabilityUniversal::OnDBusPropertiesChanged(
504 interface, changed_properties, invalidated_properties);
505 }
506}
507
508void CellularCapabilityUniversalCDMA::OnModemCDMAPropertiesChanged(
509 const DBusPropertiesMap &properties,
510 const std::vector<std::string> &/*invalidated_properties*/) {
511 SLOG(Cellular, 2) << __func__;
512 string str_value;
513 if (DBusProperties::GetString(properties,
514 MM_MODEM_MODEMCDMA_PROPERTY_MEID,
515 &str_value))
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800516 cellular()->set_meid(str_value);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800517 if (DBusProperties::GetString(properties,
518 MM_MODEM_MODEMCDMA_PROPERTY_ESN,
519 &str_value))
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800520 cellular()->set_esn(str_value);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800521
522 uint32_t sid = sid_;
523 uint32_t nid = nid_;
524 MMModemCdmaRegistrationState state_1x = cdma_1x_registration_state_;
525 MMModemCdmaRegistrationState state_evdo = cdma_evdo_registration_state_;
526 bool registration_changed = false;
527 uint32_t uint_value;
528 if (DBusProperties::GetUint32(
529 properties,
530 MM_MODEM_MODEMCDMA_PROPERTY_CDMA1XREGISTRATIONSTATE,
531 &uint_value)) {
532 state_1x = static_cast<MMModemCdmaRegistrationState>(uint_value);
533 registration_changed = true;
534 }
535 if (DBusProperties::GetUint32(
536 properties,
537 MM_MODEM_MODEMCDMA_PROPERTY_EVDOREGISTRATIONSTATE,
538 &uint_value)) {
539 state_evdo = static_cast<MMModemCdmaRegistrationState>(uint_value);
540 registration_changed = true;
541 }
542 if (DBusProperties::GetUint32(
543 properties,
544 MM_MODEM_MODEMCDMA_PROPERTY_SID,
545 &uint_value)) {
546 sid = uint_value;
547 registration_changed = true;
548 }
549 if (DBusProperties::GetUint32(
550 properties,
551 MM_MODEM_MODEMCDMA_PROPERTY_NID,
552 &uint_value)) {
553 nid = uint_value;
554 registration_changed = true;
555 }
Arman Uguray0a3e2792013-01-17 16:31:50 -0800556 if (DBusProperties::GetUint32(
557 properties,
558 MM_MODEM_MODEMCDMA_PROPERTY_ACTIVATIONSTATE,
559 &uint_value)) {
560 activation_state_ = static_cast<MMModemCdmaActivationState>(uint_value);
561 HandleNewActivationStatus(MM_CDMA_ACTIVATION_ERROR_NONE);
562 }
Arman Uguray72fab6a2013-01-10 19:32:42 -0800563 if (registration_changed)
564 OnCDMARegistrationChanged(state_1x, state_evdo, sid, nid);
565}
566
567void CellularCapabilityUniversalCDMA::OnCDMARegistrationChanged(
568 MMModemCdmaRegistrationState state_1x,
569 MMModemCdmaRegistrationState state_evdo,
570 uint32_t sid, uint32_t nid) {
571 SLOG(Cellular, 2) << __func__
572 << ": state_1x=" << state_1x
573 << ", state_evdo=" << state_evdo;
574 cdma_1x_registration_state_ = state_1x;
575 cdma_evdo_registration_state_ = state_evdo;
576 sid_ = sid;
577 nid_ = nid;
Prathmesh Prabhu8599e052014-04-25 14:20:22 -0700578 cellular()->serving_operator_info()->UpdateSID(UintToString(sid));
579 cellular()->serving_operator_info()->UpdateNID(UintToString(nid));
Arman Uguray72fab6a2013-01-10 19:32:42 -0800580 UpdateOperatorInfo();
581 cellular()->HandleNewRegistrationState();
582}
583
584} // namespace shill