blob: 273abff263e6bb5577a8bfbfae0d491a1a867587 [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());
259 olp.SetPostData(post_data);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800260 if (cellular()->service().get())
261 cellular()->service()->SetOLP(olp);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800262}
263
264void CellularCapabilityUniversalCDMA::GetProperties() {
265 SLOG(Cellular, 2) << __func__;
266 CellularCapabilityUniversal::GetProperties();
267
268 scoped_ptr<DBusPropertiesProxyInterface> properties_proxy(
269 proxy_factory()->CreateDBusPropertiesProxy(cellular()->dbus_path(),
270 cellular()->dbus_owner()));
271 DBusPropertiesMap properties(
272 properties_proxy->GetAll(MM_DBUS_INTERFACE_MODEM_MODEMCDMA));
273 OnModemCDMAPropertiesChanged(properties, vector<string>());
274}
275
276string CellularCapabilityUniversalCDMA::CreateFriendlyServiceName() {
277 SLOG(Cellular, 2) << __func__ << ": " << GetRoamingStateString();
278
279 if (provider_.GetCode().empty()) {
280 UpdateOperatorInfo();
281 }
282
283 string name = provider_.GetName();
284 if (!name.empty()) {
285 // TODO(armansito): We may need to show the provider name in a
286 // specific way if roaming.
287 return name;
288 }
289
290 string code = provider_.GetCode();
291 if (!code.empty()) {
292 return "cellular_sid_" + code;
293 }
294
295 return base::StringPrintf("CDMANetwork%u", friendly_service_name_id_cdma_++);
296}
297
298void CellularCapabilityUniversalCDMA::UpdateOperatorInfo() {
299 SLOG(Cellular, 2) << __func__;
300
301 if (sid_ == 0 || !modem_info()->cellular_operator_info()) {
302 SLOG(Cellular, 2) << "No provider is currently available.";
303 provider_.SetCode("");
304 return;
305 }
306
307 string sid = UintToString(sid_);
308 const CellularOperatorInfo::CellularOperator *provider =
309 modem_info()->cellular_operator_info()->GetCellularOperatorBySID(sid);
310 if (!provider) {
311 SLOG(Cellular, 2) << "CDMA provider with "
312 << FormattedSID(sid)
313 << " not found.";
Arman Uguraye015faf2013-08-16 17:54:59 -0700314 // If a matching provider is not found, shill should update the
315 // Cellular.ServingOperator property to to display the Sid.
316 provider_.SetCode(sid);
317 provider_.SetCountry("");
318 provider_.SetName("");
319 activation_code_.clear();
320 } else {
321 if (!provider->name_list().empty()) {
322 provider_.SetName(provider->name_list()[0].name);
323 }
324 provider_.SetCode(sid);
325 provider_.SetCountry(provider->country());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800326
Arman Uguraye015faf2013-08-16 17:54:59 -0700327 activation_code_ = provider->activation_code();
Arman Uguray72fab6a2013-01-10 19:32:42 -0800328 }
Arman Uguray0a3e2792013-01-17 16:31:50 -0800329
Arman Uguray72fab6a2013-01-10 19:32:42 -0800330 // TODO(armansito): The CDMA interface only returns information about the
331 // current serving carrier, so for now both the home provider and the
332 // serving operator will be the same in case of roaming. We should figure
333 // out if there is a way to (and whether or not it is necessary to)
334 // determine if we're roaming.
335 cellular()->set_home_provider(provider_);
Arman Uguray72fab6a2013-01-10 19:32:42 -0800336 UpdateServingOperator();
337}
338
339void CellularCapabilityUniversalCDMA::UpdateServingOperator() {
340 SLOG(Cellular, 2) << __func__;
341 if (cellular()->service().get()) {
342 cellular()->service()->SetServingOperator(cellular()->home_provider());
Arman Uguray2269bb62013-07-26 14:53:30 -0700343 cellular()->service()->SetFriendlyName(CreateFriendlyServiceName());
Arman Uguray72fab6a2013-01-10 19:32:42 -0800344 }
345}
346
Arman Uguray0a3e2792013-01-17 16:31:50 -0800347void CellularCapabilityUniversalCDMA::OnActivationStateChangedSignal(
348 uint32 activation_state,
349 uint32 activation_error,
350 const DBusPropertiesMap &status_changes) {
351 SLOG(Cellular, 2) << __func__;
352
353 activation_state_ =
354 static_cast<MMModemCdmaActivationState>(activation_state);
355
356 string value;
357 if (DBusProperties::GetString(status_changes, "mdn", &value))
358 set_mdn(value);
359 if (DBusProperties::GetString(status_changes, "min", &value))
360 set_min(value);
361
362 SLOG(Cellular, 2) << "Activation state: "
363 << GetActivationStateString(activation_state_);
364
365 HandleNewActivationStatus(activation_error);
366 UpdatePendingActivationState();
367}
368
369void CellularCapabilityUniversalCDMA::OnActivateReply(
370 const ResultCallback &callback,
371 const Error &error) {
372 SLOG(Cellular, 2) << __func__;
373 if (error.IsSuccess()) {
374 LOG(INFO) << "Activation completed successfully.";
375 modem_info()->pending_activation_store()->SetActivationState(
376 PendingActivationStore::kIdentifierMEID,
377 meid(),
378 PendingActivationStore::kStateActivated);
379 } else {
380 LOG(ERROR) << "Activation failed with error: " << error;
381 modem_info()->pending_activation_store()->SetActivationState(
382 PendingActivationStore::kIdentifierMEID,
383 meid(),
384 PendingActivationStore::kStateFailureRetry);
385 }
386 UpdatePendingActivationState();
Arman Ugurayf2b4a342013-05-23 18:26:52 -0700387
388 // CellularCapabilityUniversalCDMA::ActivateAutomatic passes a dummy
389 // ResultCallback when it calls Activate on the proxy object, in which case
390 // |callback.is_null()| will return true.
391 if (!callback.is_null())
392 callback.Run(error);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800393}
394
395void CellularCapabilityUniversalCDMA::HandleNewActivationStatus(uint32 error) {
396 SLOG(Cellular, 2) << __func__ << "(" << error << ")";
397 if (!cellular()->service().get()) {
398 LOG(ERROR) << "In " << __func__ << "(): service is null.";
399 return;
400 }
401 SLOG(Cellular, 2) << "Activation State: " << activation_state_;
402 cellular()->service()->SetActivationState(
403 GetActivationStateString(activation_state_));
404 cellular()->service()->set_error(GetActivationErrorString(error));
405 UpdateOLP();
406}
407
408// static
409string CellularCapabilityUniversalCDMA::GetActivationStateString(
410 uint32 state) {
411 switch (state) {
412 case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700413 return kActivationStateActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800414 case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING:
Ben Chan7ea768e2013-09-20 15:08:40 -0700415 return kActivationStateActivating;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800416 case MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700417 return kActivationStateNotActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800418 case MM_MODEM_CDMA_ACTIVATION_STATE_PARTIALLY_ACTIVATED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700419 return kActivationStatePartiallyActivated;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800420 default:
Ben Chan7ea768e2013-09-20 15:08:40 -0700421 return kActivationStateUnknown;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800422 }
423}
424
425// static
426string CellularCapabilityUniversalCDMA::GetActivationErrorString(
427 uint32 error) {
428 switch (error) {
429 case MM_CDMA_ACTIVATION_ERROR_WRONG_RADIO_INTERFACE:
Ben Chan7ea768e2013-09-20 15:08:40 -0700430 return kErrorNeedEvdo;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800431 case MM_CDMA_ACTIVATION_ERROR_ROAMING:
Ben Chan7ea768e2013-09-20 15:08:40 -0700432 return kErrorNeedHomeNetwork;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800433 case MM_CDMA_ACTIVATION_ERROR_COULD_NOT_CONNECT:
434 case MM_CDMA_ACTIVATION_ERROR_SECURITY_AUTHENTICATION_FAILED:
435 case MM_CDMA_ACTIVATION_ERROR_PROVISIONING_FAILED:
Ben Chan7ea768e2013-09-20 15:08:40 -0700436 return kErrorOtaspFailed;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800437 case MM_CDMA_ACTIVATION_ERROR_NONE:
438 return "";
439 case MM_CDMA_ACTIVATION_ERROR_NO_SIGNAL:
440 default:
Ben Chan7ea768e2013-09-20 15:08:40 -0700441 return kErrorActivationFailed;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800442 }
443}
444
Arman Uguray72fab6a2013-01-10 19:32:42 -0800445void CellularCapabilityUniversalCDMA::Register(const ResultCallback &callback) {
446 // TODO(armansito): Remove once 3GPP is implemented in its own class.
447}
448
449void CellularCapabilityUniversalCDMA::RegisterOnNetwork(
450 const string &network_id,
451 Error *error,
452 const ResultCallback &callback) {
453 // TODO(armansito): Remove once 3GPP is implemented in its own class.
454}
455
Arman Uguray0a3e2792013-01-17 16:31:50 -0800456bool CellularCapabilityUniversalCDMA::IsActivating() const {
457 PendingActivationStore::State state =
458 modem_info()->pending_activation_store()->GetActivationState(
459 PendingActivationStore::kIdentifierMEID, meid());
460 return (state == PendingActivationStore::kStatePending) ||
461 (state == PendingActivationStore::kStateFailureRetry) ||
462 (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING);
463}
464
Arman Uguray72fab6a2013-01-10 19:32:42 -0800465bool CellularCapabilityUniversalCDMA::IsRegistered() {
466 return (cdma_1x_registration_state_ ==
467 MM_MODEM_CDMA_REGISTRATION_STATE_HOME ||
468 cdma_1x_registration_state_ ==
469 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING ||
470 cdma_evdo_registration_state_ ==
471 MM_MODEM_CDMA_REGISTRATION_STATE_HOME ||
472 cdma_evdo_registration_state_ ==
473 MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING);
474}
475
476void CellularCapabilityUniversalCDMA::SetUnregistered(bool /*searching*/) {
477 cdma_1x_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
478 cdma_evdo_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
479}
480
Arman Ugurayc9673062013-05-13 21:21:53 -0700481void CellularCapabilityUniversalCDMA::SetupConnectProperties(
482 DBusPropertiesMap *properties) {
483 (*properties)[kPropertyConnectNumber].writer().append_string(
484 kPhoneNumber);
485}
486
Arman Uguray72fab6a2013-01-10 19:32:42 -0800487void CellularCapabilityUniversalCDMA::RequirePIN(
488 const string &pin, bool require,
489 Error *error, const ResultCallback &callback) {
490 // TODO(armansito): Remove once 3GPP is implemented in its own class.
491}
492
493void CellularCapabilityUniversalCDMA::EnterPIN(
494 const string &pin,
495 Error *error,
496 const ResultCallback &callback) {
497 // TODO(armansito): Remove once 3GPP is implemented in its own class.
498}
499
500void CellularCapabilityUniversalCDMA::UnblockPIN(
501 const string &unblock_code,
502 const string &pin,
503 Error *error,
504 const ResultCallback &callback) {
505 // TODO(armansito): Remove once 3GPP is implemented in its own class.
506}
507
508void CellularCapabilityUniversalCDMA::ChangePIN(
509 const string &old_pin, const string &new_pin,
510 Error *error, const ResultCallback &callback) {
511 // TODO(armansito): Remove once 3GPP is implemented in its own class.
512}
513
514void CellularCapabilityUniversalCDMA::Scan(Error *error,
515 const ResultCallback &callback) {
516 // TODO(armansito): Remove once 3GPP is implemented in its own class.
517}
518
519void CellularCapabilityUniversalCDMA::OnSimPathChanged(
520 const string &sim_path) {
521 // TODO(armansito): Remove once 3GPP is implemented in its own class.
522}
523
524string CellularCapabilityUniversalCDMA::GetRoamingStateString() const {
525 uint32 state = cdma_evdo_registration_state_;
526 if (state == MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN) {
527 state = cdma_1x_registration_state_;
528 }
529 switch (state) {
530 case MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN:
531 case MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED:
532 break;
533 case MM_MODEM_CDMA_REGISTRATION_STATE_HOME:
Ben Chan7ea768e2013-09-20 15:08:40 -0700534 return kRoamingStateHome;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800535 case MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING:
Ben Chan7ea768e2013-09-20 15:08:40 -0700536 return kRoamingStateRoaming;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800537 default:
538 NOTREACHED();
539 }
Ben Chan7ea768e2013-09-20 15:08:40 -0700540 return kRoamingStateUnknown;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800541}
542
543void CellularCapabilityUniversalCDMA::OnDBusPropertiesChanged(
544 const string &interface,
545 const DBusPropertiesMap &changed_properties,
546 const vector<string> &invalidated_properties) {
547 SLOG(Cellular, 2) << __func__ << "(" << interface << ")";
548 if (interface == MM_DBUS_INTERFACE_MODEM_MODEMCDMA) {
549 OnModemCDMAPropertiesChanged(changed_properties, invalidated_properties);
550 } else {
551 CellularCapabilityUniversal::OnDBusPropertiesChanged(
552 interface, changed_properties, invalidated_properties);
553 }
554}
555
556void CellularCapabilityUniversalCDMA::OnModemCDMAPropertiesChanged(
557 const DBusPropertiesMap &properties,
558 const std::vector<std::string> &/*invalidated_properties*/) {
559 SLOG(Cellular, 2) << __func__;
560 string str_value;
561 if (DBusProperties::GetString(properties,
562 MM_MODEM_MODEMCDMA_PROPERTY_MEID,
563 &str_value))
564 set_meid(str_value);
565 if (DBusProperties::GetString(properties,
566 MM_MODEM_MODEMCDMA_PROPERTY_ESN,
567 &str_value))
568 set_esn(str_value);
569
570 uint32_t sid = sid_;
571 uint32_t nid = nid_;
572 MMModemCdmaRegistrationState state_1x = cdma_1x_registration_state_;
573 MMModemCdmaRegistrationState state_evdo = cdma_evdo_registration_state_;
574 bool registration_changed = false;
575 uint32_t uint_value;
576 if (DBusProperties::GetUint32(
577 properties,
578 MM_MODEM_MODEMCDMA_PROPERTY_CDMA1XREGISTRATIONSTATE,
579 &uint_value)) {
580 state_1x = static_cast<MMModemCdmaRegistrationState>(uint_value);
581 registration_changed = true;
582 }
583 if (DBusProperties::GetUint32(
584 properties,
585 MM_MODEM_MODEMCDMA_PROPERTY_EVDOREGISTRATIONSTATE,
586 &uint_value)) {
587 state_evdo = static_cast<MMModemCdmaRegistrationState>(uint_value);
588 registration_changed = true;
589 }
590 if (DBusProperties::GetUint32(
591 properties,
592 MM_MODEM_MODEMCDMA_PROPERTY_SID,
593 &uint_value)) {
594 sid = uint_value;
595 registration_changed = true;
596 }
597 if (DBusProperties::GetUint32(
598 properties,
599 MM_MODEM_MODEMCDMA_PROPERTY_NID,
600 &uint_value)) {
601 nid = uint_value;
602 registration_changed = true;
603 }
Arman Uguray0a3e2792013-01-17 16:31:50 -0800604 if (DBusProperties::GetUint32(
605 properties,
606 MM_MODEM_MODEMCDMA_PROPERTY_ACTIVATIONSTATE,
607 &uint_value)) {
608 activation_state_ = static_cast<MMModemCdmaActivationState>(uint_value);
609 HandleNewActivationStatus(MM_CDMA_ACTIVATION_ERROR_NONE);
610 }
Arman Uguray72fab6a2013-01-10 19:32:42 -0800611 if (registration_changed)
612 OnCDMARegistrationChanged(state_1x, state_evdo, sid, nid);
613}
614
615void CellularCapabilityUniversalCDMA::OnCDMARegistrationChanged(
616 MMModemCdmaRegistrationState state_1x,
617 MMModemCdmaRegistrationState state_evdo,
618 uint32_t sid, uint32_t nid) {
619 SLOG(Cellular, 2) << __func__
620 << ": state_1x=" << state_1x
621 << ", state_evdo=" << state_evdo;
622 cdma_1x_registration_state_ = state_1x;
623 cdma_evdo_registration_state_ = state_evdo;
624 sid_ = sid;
625 nid_ = nid;
626 UpdateOperatorInfo();
627 cellular()->HandleNewRegistrationState();
628}
629
630} // namespace shill