blob: a1a4eccc2c2fb32f823559c82afd95f932ace437 [file] [log] [blame]
Arman Uguray72fab6a2013-01-10 19:32:42 -08001// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "shill/cellular_capability_universal_cdma.h"
6
7#include <chromeos/dbus/service_constants.h>
8#include <base/stringprintf.h>
9#include <base/string_number_conversions.h>
10#include <base/string_util.h>
11
12#include "shill/cellular_operator_info.h"
13#include "shill/dbus_properties_proxy_interface.h"
Arman Uguray0a3e2792013-01-17 16:31:50 -080014#include "shill/error.h"
Arman Uguray72fab6a2013-01-10 19:32:42 -080015#include "shill/logging.h"
Arman Uguray0a3e2792013-01-17 16:31:50 -080016#include "shill/pending_activation_store.h"
Arman Uguray72fab6a2013-01-10 19:32:42 -080017#include "shill/proxy_factory.h"
18
19#ifdef MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN
20#error "Do not include mm-modem.h"
21#endif
22
23using base::UintToString;
24
25using std::string;
26using std::vector;
27
28namespace shill {
29
30namespace {
31
Arman Ugurayc9673062013-05-13 21:21:53 -070032const char kPhoneNumber[] = "#777";
33const char kPropertyConnectNumber[] = "number";
34
Arman Uguray72fab6a2013-01-10 19:32:42 -080035string FormattedSID(const string &sid) {
36 return "[SID=" + sid + "]";
37}
38
39} // namespace
40
41// static
42unsigned int
43CellularCapabilityUniversalCDMA::friendly_service_name_id_cdma_ = 0;
44
45CellularCapabilityUniversalCDMA::CellularCapabilityUniversalCDMA(
46 Cellular *cellular,
47 ProxyFactory *proxy_factory,
48 ModemInfo *modem_info)
49 : CellularCapabilityUniversal(cellular,
50 proxy_factory,
51 modem_info),
Arman Uguray0a3e2792013-01-17 16:31:50 -080052 weak_cdma_ptr_factory_(this),
53 activation_state_(MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED),
Arman Uguray72fab6a2013-01-10 19:32:42 -080054 cdma_1x_registration_state_(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN),
55 cdma_evdo_registration_state_(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN),
56 nid_(0),
57 sid_(0) {
58 SLOG(Cellular, 2) << "Cellular capability constructed: Universal CDMA";
Arman Uguray0a3e2792013-01-17 16:31:50 -080059 // TODO(armansito): Update PRL for activation over cellular.
Arman Uguray72fab6a2013-01-10 19:32:42 -080060 // See crbug.com/197330.
61}
62
63void CellularCapabilityUniversalCDMA::InitProxies() {
64 SLOG(Cellular, 2) << __func__;
65 modem_cdma_proxy_.reset(
66 proxy_factory()->CreateMM1ModemModemCdmaProxy(cellular()->dbus_path(),
67 cellular()->dbus_owner()));
Arman Uguray0a3e2792013-01-17 16:31:50 -080068 modem_cdma_proxy_->set_activation_state_callback(
69 Bind(&CellularCapabilityUniversalCDMA::OnActivationStateChangedSignal,
70 weak_cdma_ptr_factory_.GetWeakPtr()));
Arman Uguray72fab6a2013-01-10 19:32:42 -080071 CellularCapabilityUniversal::InitProxies();
72}
73
74void CellularCapabilityUniversalCDMA::ReleaseProxies() {
75 SLOG(Cellular, 2) << __func__;
76 modem_cdma_proxy_.reset();
77 CellularCapabilityUniversal::ReleaseProxies();
78}
79
80void CellularCapabilityUniversalCDMA::Activate(
81 const string &carrier,
82 Error *error,
83 const ResultCallback &callback) {
Arman Uguray0a3e2792013-01-17 16:31:50 -080084 // Currently activation over the cellular network is not supported using
85 // ModemManager-next. Service activation is currently carried through over
86 // non-cellular networks and only the final step of the OTA activation
87 // procedure ("automatic activation") is performed by this class.
Arman Uguray72fab6a2013-01-10 19:32:42 -080088 OnUnsupportedOperation(__func__, error);
89}
90
91void CellularCapabilityUniversalCDMA::CompleteActivation(Error *error) {
Arman Uguray0a3e2792013-01-17 16:31:50 -080092 SLOG(Cellular, 2) << __func__;
93 if (cellular()->state() < Cellular::kStateEnabled) {
94 Error::PopulateAndLog(error, Error::kInvalidArguments,
95 "Unable to activate in state " +
96 Cellular::GetStateString(cellular()->state()));
97 return;
98 }
99 ActivateAutomatic();
Arman Uguray72fab6a2013-01-10 19:32:42 -0800100}
101
Arman Uguray0a3e2792013-01-17 16:31:50 -0800102void CellularCapabilityUniversalCDMA::ActivateAutomatic() {
103 if (activation_code_.empty()) {
104 SLOG(Cellular, 2) << "OTA activation cannot be run in the presence of no "
105 << "activation code.";
106 return;
107 }
108 PendingActivationStore::State state =
109 modem_info()->pending_activation_store()->GetActivationState(
110 PendingActivationStore::kIdentifierMEID, meid());
111 if (state == PendingActivationStore::kStatePending) {
112 SLOG(Cellular, 2) << "There's already a pending activation. Ignoring.";
113 return;
114 }
115 if (state == PendingActivationStore::kStateActivated) {
116 SLOG(Cellular, 2) << "A call to OTA activation has already completed "
117 << "successfully. Ignoring.";
118 return;
119 }
120
121 // Mark as pending activation, so that shill can recover if anything fails
122 // during OTA activation.
123 modem_info()->pending_activation_store()->SetActivationState(
124 PendingActivationStore::kIdentifierMEID,
125 meid(),
126 PendingActivationStore::kStatePending);
127
128 // Initiate OTA activation.
129 ResultCallback activation_callback =
130 Bind(&CellularCapabilityUniversalCDMA::OnActivateReply,
131 weak_cdma_ptr_factory_.GetWeakPtr(),
132 ResultCallback());
Arman Ugurayf2b4a342013-05-23 18:26:52 -0700133
Arman Uguray0a3e2792013-01-17 16:31:50 -0800134 Error error;
135 modem_cdma_proxy_->Activate(
136 activation_code_, &error, activation_callback, kTimeoutActivate);
137}
138
139void CellularCapabilityUniversalCDMA::UpdatePendingActivationState() {
Arman Uguray72fab6a2013-01-10 19:32:42 -0800140 SLOG(Cellular, 2) << __func__;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800141 if (IsActivated()) {
142 SLOG(Cellular, 3) << "CDMA service activated. Clear store.";
143 modem_info()->pending_activation_store()->RemoveEntry(
144 PendingActivationStore::kIdentifierMEID, meid());
145 return;
146 }
147 PendingActivationStore::State state =
148 modem_info()->pending_activation_store()->GetActivationState(
149 PendingActivationStore::kIdentifierMEID, meid());
150 if (IsActivating() && state != PendingActivationStore::kStateFailureRetry) {
151 SLOG(Cellular, 3) << "OTA activation in progress. Nothing to do.";
152 return;
153 }
154 switch (state) {
155 case PendingActivationStore::kStateFailureRetry:
156 SLOG(Cellular, 3) << "OTA activation failed. Scheduling a retry.";
157 cellular()->dispatcher()->PostTask(
158 Bind(&CellularCapabilityUniversalCDMA::ActivateAutomatic,
159 weak_cdma_ptr_factory_.GetWeakPtr()));
160 break;
161 case PendingActivationStore::kStateActivated:
162 SLOG(Cellular, 3) << "OTA Activation has completed successfully. "
163 << "Waiting for activation state update to finalize.";
164 break;
165 default:
166 break;
167 }
168}
169
170bool CellularCapabilityUniversalCDMA::IsServiceActivationRequired() const {
171 // If there is no online payment portal information, it's safer to assume
172 // the service does not require activation.
173 if (!modem_info()->cellular_operator_info())
174 return false;
175
176 const CellularService::OLP *olp =
177 modem_info()->cellular_operator_info()->GetOLPBySID(UintToString(sid_));
178 if (!olp)
179 return false;
180
181 // We could also use the MDN to determine whether or not the service is
182 // activated, however, the CDMA ActivatonState property is a more absolute
183 // and fine-grained indicator of activation status.
184 return (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED);
185}
186
187bool CellularCapabilityUniversalCDMA::IsActivated() const {
188 return (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800189}
190
Arman Ugurayc5391232013-09-23 21:30:46 -0700191void CellularCapabilityUniversalCDMA::UpdateStorageIdentifier() {
192 if (!cellular()->service().get())
193 return;
194
195 // Lookup the unique identifier assigned to the current network and base the
196 // service's storage identifier on it.
197 const CellularOperatorInfo::CellularOperator *provider =
198 modem_info()->cellular_operator_info()->GetCellularOperatorBySID(
199 UintToString(sid_));
200 if (!provider || provider->identifier().empty())
201 // Don't update the identifier if a better one could not be built. The
202 // default identifier initialized in cellular_service.cc still applies
203 // here.
204 return;
205 cellular()->service()->SetStorageIdentifier(
206 string(shill::kTypeCellular) + "_" + cellular()->address() +
207 "_" + provider->identifier());
208}
209
Arman Uguray72fab6a2013-01-10 19:32:42 -0800210void CellularCapabilityUniversalCDMA::OnServiceCreated() {
211 SLOG(Cellular, 2) << __func__;
Arman Ugurayc5391232013-09-23 21:30:46 -0700212 UpdateStorageIdentifier();
Arman Uguray0a3e2792013-01-17 16:31:50 -0800213 UpdateServiceActivationStateProperty();
Arman Uguray72fab6a2013-01-10 19:32:42 -0800214 UpdateServingOperator();
Arman Uguray0a3e2792013-01-17 16:31:50 -0800215 HandleNewActivationStatus(MM_CDMA_ACTIVATION_ERROR_NONE);
216 UpdatePendingActivationState();
Arman Uguray72fab6a2013-01-10 19:32:42 -0800217 UpdateOLP();
218}
219
Arman Uguray0a3e2792013-01-17 16:31:50 -0800220void CellularCapabilityUniversalCDMA::UpdateServiceActivationStateProperty() {
221 bool activation_required = IsServiceActivationRequired();
222 cellular()->service()->SetActivateOverNonCellularNetwork(activation_required);
223 string activation_state;
224 if (IsActivating())
Ben Chan7ea768e2013-09-20 15:08:40 -0700225 activation_state = kActivationStateActivating;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800226 else if (activation_required)
Ben Chan7ea768e2013-09-20 15:08:40 -0700227 activation_state = kActivationStateNotActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800228 else
Ben Chan7ea768e2013-09-20 15:08:40 -0700229 activation_state = kActivationStateActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800230 cellular()->service()->SetActivationState(activation_state);
231}
232
Arman Uguray72fab6a2013-01-10 19:32:42 -0800233void CellularCapabilityUniversalCDMA::UpdateOLP() {
Ben Chan07193fd2013-07-12 22:10:55 -0700234 SLOG(Cellular, 2) << __func__;
235
236 const CellularOperatorInfo *cellular_operator_info =
237 modem_info()->cellular_operator_info();
238 if (!cellular_operator_info)
239 return;
240
241 string sid_string = UintToString(sid_);
242 const CellularOperatorInfo::CellularOperator *cellular_operator =
243 cellular_operator_info->GetCellularOperatorBySID(sid_string);
244 if (!cellular_operator)
Arman Uguray72fab6a2013-01-10 19:32:42 -0800245 return;
246
247 const CellularService::OLP *result =
Ben Chan07193fd2013-07-12 22:10:55 -0700248 cellular_operator_info->GetOLPBySID(sid_string);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800249 if (!result)
250 return;
251
252 CellularService::OLP olp;
253 olp.CopyFrom(*result);
254 string post_data = olp.GetPostData();
255 ReplaceSubstringsAfterOffset(&post_data, 0, "${esn}", esn());
Ben Chan07193fd2013-07-12 22:10:55 -0700256 ReplaceSubstringsAfterOffset(&post_data, 0, "${mdn}",
257 GetMdnForOLP(*cellular_operator));
Arman Uguray72fab6a2013-01-10 19:32:42 -0800258 ReplaceSubstringsAfterOffset(&post_data, 0, "${meid}", meid());
Arman Ugurayf87fa2f2013-10-16 14:24:56 -0700259 ReplaceSubstringsAfterOffset(&post_data, 0, "${oem}", "GOG2");
Arman Uguray72fab6a2013-01-10 19:32:42 -0800260 olp.SetPostData(post_data);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800261 if (cellular()->service().get())
262 cellular()->service()->SetOLP(olp);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800263}
264
265void CellularCapabilityUniversalCDMA::GetProperties() {
266 SLOG(Cellular, 2) << __func__;
267 CellularCapabilityUniversal::GetProperties();
268
269 scoped_ptr<DBusPropertiesProxyInterface> properties_proxy(
270 proxy_factory()->CreateDBusPropertiesProxy(cellular()->dbus_path(),
271 cellular()->dbus_owner()));
272 DBusPropertiesMap properties(
273 properties_proxy->GetAll(MM_DBUS_INTERFACE_MODEM_MODEMCDMA));
274 OnModemCDMAPropertiesChanged(properties, vector<string>());
275}
276
277string CellularCapabilityUniversalCDMA::CreateFriendlyServiceName() {
278 SLOG(Cellular, 2) << __func__ << ": " << GetRoamingStateString();
279
280 if (provider_.GetCode().empty()) {
281 UpdateOperatorInfo();
282 }
283
284 string name = provider_.GetName();
285 if (!name.empty()) {
286 // TODO(armansito): We may need to show the provider name in a
287 // specific way if roaming.
288 return name;
289 }
290
291 string code = provider_.GetCode();
292 if (!code.empty()) {
293 return "cellular_sid_" + code;
294 }
295
296 return base::StringPrintf("CDMANetwork%u", friendly_service_name_id_cdma_++);
297}
298
299void CellularCapabilityUniversalCDMA::UpdateOperatorInfo() {
300 SLOG(Cellular, 2) << __func__;
301
302 if (sid_ == 0 || !modem_info()->cellular_operator_info()) {
303 SLOG(Cellular, 2) << "No provider is currently available.";
304 provider_.SetCode("");
305 return;
306 }
307
308 string sid = UintToString(sid_);
309 const CellularOperatorInfo::CellularOperator *provider =
310 modem_info()->cellular_operator_info()->GetCellularOperatorBySID(sid);
311 if (!provider) {
312 SLOG(Cellular, 2) << "CDMA provider with "
313 << FormattedSID(sid)
314 << " not found.";
Arman Uguraye015faf2013-08-16 17:54:59 -0700315 // If a matching provider is not found, shill should update the
316 // Cellular.ServingOperator property to to display the Sid.
317 provider_.SetCode(sid);
318 provider_.SetCountry("");
319 provider_.SetName("");
320 activation_code_.clear();
321 } else {
322 if (!provider->name_list().empty()) {
323 provider_.SetName(provider->name_list()[0].name);
324 }
325 provider_.SetCode(sid);
326 provider_.SetCountry(provider->country());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800327
Arman Uguraye015faf2013-08-16 17:54:59 -0700328 activation_code_ = provider->activation_code();
Arman Uguray72fab6a2013-01-10 19:32:42 -0800329 }
Arman Uguray0a3e2792013-01-17 16:31:50 -0800330
Arman Uguray72fab6a2013-01-10 19:32:42 -0800331 // TODO(armansito): The CDMA interface only returns information about the
332 // current serving carrier, so for now both the home provider and the
333 // serving operator will be the same in case of roaming. We should figure
334 // out if there is a way to (and whether or not it is necessary to)
335 // determine if we're roaming.
336 cellular()->set_home_provider(provider_);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800337 UpdateServingOperator();
338}
339
340void CellularCapabilityUniversalCDMA::UpdateServingOperator() {
341 SLOG(Cellular, 2) << __func__;
342 if (cellular()->service().get()) {
343 cellular()->service()->SetServingOperator(cellular()->home_provider());
Arman Uguray2269bb62013-07-26 14:53:30 -0700344 cellular()->service()->SetFriendlyName(CreateFriendlyServiceName());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800345 }
346}
347
Arman Uguray0a3e2792013-01-17 16:31:50 -0800348void CellularCapabilityUniversalCDMA::OnActivationStateChangedSignal(
349 uint32 activation_state,
350 uint32 activation_error,
351 const DBusPropertiesMap &status_changes) {
352 SLOG(Cellular, 2) << __func__;
353
354 activation_state_ =
355 static_cast<MMModemCdmaActivationState>(activation_state);
356
357 string value;
358 if (DBusProperties::GetString(status_changes, "mdn", &value))
359 set_mdn(value);
360 if (DBusProperties::GetString(status_changes, "min", &value))
361 set_min(value);
362
363 SLOG(Cellular, 2) << "Activation state: "
364 << GetActivationStateString(activation_state_);
365
366 HandleNewActivationStatus(activation_error);
367 UpdatePendingActivationState();
368}
369
370void CellularCapabilityUniversalCDMA::OnActivateReply(
371 const ResultCallback &callback,
372 const Error &error) {
373 SLOG(Cellular, 2) << __func__;
374 if (error.IsSuccess()) {
375 LOG(INFO) << "Activation completed successfully.";
376 modem_info()->pending_activation_store()->SetActivationState(
377 PendingActivationStore::kIdentifierMEID,
378 meid(),
379 PendingActivationStore::kStateActivated);
380 } else {
381 LOG(ERROR) << "Activation failed with error: " << error;
382 modem_info()->pending_activation_store()->SetActivationState(
383 PendingActivationStore::kIdentifierMEID,
384 meid(),
385 PendingActivationStore::kStateFailureRetry);
386 }
387 UpdatePendingActivationState();
Arman Ugurayf2b4a342013-05-23 18:26:52 -0700388
389 // CellularCapabilityUniversalCDMA::ActivateAutomatic passes a dummy
390 // ResultCallback when it calls Activate on the proxy object, in which case
391 // |callback.is_null()| will return true.
392 if (!callback.is_null())
393 callback.Run(error);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800394}
395
396void CellularCapabilityUniversalCDMA::HandleNewActivationStatus(uint32 error) {
397 SLOG(Cellular, 2) << __func__ << "(" << error << ")";
398 if (!cellular()->service().get()) {
399 LOG(ERROR) << "In " << __func__ << "(): service is null.";
400 return;
401 }
402 SLOG(Cellular, 2) << "Activation State: " << activation_state_;
403 cellular()->service()->SetActivationState(
404 GetActivationStateString(activation_state_));
405 cellular()->service()->set_error(GetActivationErrorString(error));
406 UpdateOLP();
407}
408
409// static
410string CellularCapabilityUniversalCDMA::GetActivationStateString(
411 uint32 state) {
412 switch (state) {
413 case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700414 return kActivationStateActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800415 case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING:
Ben Chan7ea768e2013-09-20 15:08:40 -0700416 return kActivationStateActivating;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800417 case MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700418 return kActivationStateNotActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800419 case MM_MODEM_CDMA_ACTIVATION_STATE_PARTIALLY_ACTIVATED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700420 return kActivationStatePartiallyActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800421 default:
Ben Chan7ea768e2013-09-20 15:08:40 -0700422 return kActivationStateUnknown;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800423 }
424}
425
426// static
427string CellularCapabilityUniversalCDMA::GetActivationErrorString(
428 uint32 error) {
429 switch (error) {
430 case MM_CDMA_ACTIVATION_ERROR_WRONG_RADIO_INTERFACE:
Ben Chan7ea768e2013-09-20 15:08:40 -0700431 return kErrorNeedEvdo;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800432 case MM_CDMA_ACTIVATION_ERROR_ROAMING:
Ben Chan7ea768e2013-09-20 15:08:40 -0700433 return kErrorNeedHomeNetwork;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800434 case MM_CDMA_ACTIVATION_ERROR_COULD_NOT_CONNECT:
435 case MM_CDMA_ACTIVATION_ERROR_SECURITY_AUTHENTICATION_FAILED:
436 case MM_CDMA_ACTIVATION_ERROR_PROVISIONING_FAILED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700437 return kErrorOtaspFailed;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800438 case MM_CDMA_ACTIVATION_ERROR_NONE:
439 return "";
440 case MM_CDMA_ACTIVATION_ERROR_NO_SIGNAL:
441 default:
Ben Chan7ea768e2013-09-20 15:08:40 -0700442 return kErrorActivationFailed;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800443 }
444}
445
Arman Uguray72fab6a2013-01-10 19:32:42 -0800446void CellularCapabilityUniversalCDMA::Register(const ResultCallback &callback) {
447 // TODO(armansito): Remove once 3GPP is implemented in its own class.
448}
449
450void CellularCapabilityUniversalCDMA::RegisterOnNetwork(
451 const string &network_id,
452 Error *error,
453 const ResultCallback &callback) {
454 // TODO(armansito): Remove once 3GPP is implemented in its own class.
455}
456
Arman Uguray0a3e2792013-01-17 16:31:50 -0800457bool CellularCapabilityUniversalCDMA::IsActivating() const {
458 PendingActivationStore::State state =
459 modem_info()->pending_activation_store()->GetActivationState(
460 PendingActivationStore::kIdentifierMEID, meid());
461 return (state == PendingActivationStore::kStatePending) ||
462 (state == PendingActivationStore::kStateFailureRetry) ||
463 (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING);
464}
465
Arman Uguray72fab6a2013-01-10 19:32:42 -0800466bool CellularCapabilityUniversalCDMA::IsRegistered() {
467 return (cdma_1x_registration_state_ ==
468 MM_MODEM_CDMA_REGISTRATION_STATE_HOME ||
469 cdma_1x_registration_state_ ==
470 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING ||
471 cdma_evdo_registration_state_ ==
472 MM_MODEM_CDMA_REGISTRATION_STATE_HOME ||
473 cdma_evdo_registration_state_ ==
474 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING);
475}
476
477void CellularCapabilityUniversalCDMA::SetUnregistered(bool /*searching*/) {
478 cdma_1x_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
479 cdma_evdo_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
480}
481
Arman Ugurayc9673062013-05-13 21:21:53 -0700482void CellularCapabilityUniversalCDMA::SetupConnectProperties(
483 DBusPropertiesMap *properties) {
484 (*properties)[kPropertyConnectNumber].writer().append_string(
485 kPhoneNumber);
486}
487
Arman Uguray72fab6a2013-01-10 19:32:42 -0800488void CellularCapabilityUniversalCDMA::RequirePIN(
489 const string &pin, bool require,
490 Error *error, const ResultCallback &callback) {
491 // TODO(armansito): Remove once 3GPP is implemented in its own class.
492}
493
494void CellularCapabilityUniversalCDMA::EnterPIN(
495 const string &pin,
496 Error *error,
497 const ResultCallback &callback) {
498 // TODO(armansito): Remove once 3GPP is implemented in its own class.
499}
500
501void CellularCapabilityUniversalCDMA::UnblockPIN(
502 const string &unblock_code,
503 const string &pin,
504 Error *error,
505 const ResultCallback &callback) {
506 // TODO(armansito): Remove once 3GPP is implemented in its own class.
507}
508
509void CellularCapabilityUniversalCDMA::ChangePIN(
510 const string &old_pin, const string &new_pin,
511 Error *error, const ResultCallback &callback) {
512 // TODO(armansito): Remove once 3GPP is implemented in its own class.
513}
514
515void CellularCapabilityUniversalCDMA::Scan(Error *error,
516 const ResultCallback &callback) {
517 // TODO(armansito): Remove once 3GPP is implemented in its own class.
518}
519
520void CellularCapabilityUniversalCDMA::OnSimPathChanged(
521 const string &sim_path) {
522 // TODO(armansito): Remove once 3GPP is implemented in its own class.
523}
524
525string CellularCapabilityUniversalCDMA::GetRoamingStateString() const {
526 uint32 state = cdma_evdo_registration_state_;
527 if (state == MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN) {
528 state = cdma_1x_registration_state_;
529 }
530 switch (state) {
531 case MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN:
532 case MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED:
533 break;
534 case MM_MODEM_CDMA_REGISTRATION_STATE_HOME:
Ben Chan7ea768e2013-09-20 15:08:40 -0700535 return kRoamingStateHome;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800536 case MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING:
Ben Chan7ea768e2013-09-20 15:08:40 -0700537 return kRoamingStateRoaming;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800538 default:
539 NOTREACHED();
540 }
Ben Chan7ea768e2013-09-20 15:08:40 -0700541 return kRoamingStateUnknown;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800542}
543
544void CellularCapabilityUniversalCDMA::OnDBusPropertiesChanged(
545 const string &interface,
546 const DBusPropertiesMap &changed_properties,
547 const vector<string> &invalidated_properties) {
548 SLOG(Cellular, 2) << __func__ << "(" << interface << ")";
549 if (interface == MM_DBUS_INTERFACE_MODEM_MODEMCDMA) {
550 OnModemCDMAPropertiesChanged(changed_properties, invalidated_properties);
551 } else {
552 CellularCapabilityUniversal::OnDBusPropertiesChanged(
553 interface, changed_properties, invalidated_properties);
554 }
555}
556
557void CellularCapabilityUniversalCDMA::OnModemCDMAPropertiesChanged(
558 const DBusPropertiesMap &properties,
559 const std::vector<std::string> &/*invalidated_properties*/) {
560 SLOG(Cellular, 2) << __func__;
561 string str_value;
562 if (DBusProperties::GetString(properties,
563 MM_MODEM_MODEMCDMA_PROPERTY_MEID,
564 &str_value))
565 set_meid(str_value);
566 if (DBusProperties::GetString(properties,
567 MM_MODEM_MODEMCDMA_PROPERTY_ESN,
568 &str_value))
569 set_esn(str_value);
570
571 uint32_t sid = sid_;
572 uint32_t nid = nid_;
573 MMModemCdmaRegistrationState state_1x = cdma_1x_registration_state_;
574 MMModemCdmaRegistrationState state_evdo = cdma_evdo_registration_state_;
575 bool registration_changed = false;
576 uint32_t uint_value;
577 if (DBusProperties::GetUint32(
578 properties,
579 MM_MODEM_MODEMCDMA_PROPERTY_CDMA1XREGISTRATIONSTATE,
580 &uint_value)) {
581 state_1x = static_cast<MMModemCdmaRegistrationState>(uint_value);
582 registration_changed = true;
583 }
584 if (DBusProperties::GetUint32(
585 properties,
586 MM_MODEM_MODEMCDMA_PROPERTY_EVDOREGISTRATIONSTATE,
587 &uint_value)) {
588 state_evdo = static_cast<MMModemCdmaRegistrationState>(uint_value);
589 registration_changed = true;
590 }
591 if (DBusProperties::GetUint32(
592 properties,
593 MM_MODEM_MODEMCDMA_PROPERTY_SID,
594 &uint_value)) {
595 sid = uint_value;
596 registration_changed = true;
597 }
598 if (DBusProperties::GetUint32(
599 properties,
600 MM_MODEM_MODEMCDMA_PROPERTY_NID,
601 &uint_value)) {
602 nid = uint_value;
603 registration_changed = true;
604 }
Arman Uguray0a3e2792013-01-17 16:31:50 -0800605 if (DBusProperties::GetUint32(
606 properties,
607 MM_MODEM_MODEMCDMA_PROPERTY_ACTIVATIONSTATE,
608 &uint_value)) {
609 activation_state_ = static_cast<MMModemCdmaActivationState>(uint_value);
610 HandleNewActivationStatus(MM_CDMA_ACTIVATION_ERROR_NONE);
611 }
Arman Uguray72fab6a2013-01-10 19:32:42 -0800612 if (registration_changed)
613 OnCDMARegistrationChanged(state_1x, state_evdo, sid, nid);
614}
615
616void CellularCapabilityUniversalCDMA::OnCDMARegistrationChanged(
617 MMModemCdmaRegistrationState state_1x,
618 MMModemCdmaRegistrationState state_evdo,
619 uint32_t sid, uint32_t nid) {
620 SLOG(Cellular, 2) << __func__
621 << ": state_1x=" << state_1x
622 << ", state_evdo=" << state_evdo;
623 cdma_1x_registration_state_ = state_1x;
624 cdma_evdo_registration_state_ = state_evdo;
625 sid_ = sid;
626 nid_ = nid;
627 UpdateOperatorInfo();
628 cellular()->HandleNewRegistrationState();
629}
630
631} // namespace shill