Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 1 | // 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 Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 14 | #include "shill/error.h" |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 15 | #include "shill/logging.h" |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 16 | #include "shill/pending_activation_store.h" |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 17 | #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 | |
| 23 | using base::UintToString; |
| 24 | |
| 25 | using std::string; |
| 26 | using std::vector; |
| 27 | |
| 28 | namespace shill { |
| 29 | |
| 30 | namespace { |
| 31 | |
| 32 | string FormattedSID(const string &sid) { |
| 33 | return "[SID=" + sid + "]"; |
| 34 | } |
| 35 | |
| 36 | } // namespace |
| 37 | |
| 38 | // static |
| 39 | unsigned int |
| 40 | CellularCapabilityUniversalCDMA::friendly_service_name_id_cdma_ = 0; |
| 41 | |
| 42 | CellularCapabilityUniversalCDMA::CellularCapabilityUniversalCDMA( |
| 43 | Cellular *cellular, |
| 44 | ProxyFactory *proxy_factory, |
| 45 | ModemInfo *modem_info) |
| 46 | : CellularCapabilityUniversal(cellular, |
| 47 | proxy_factory, |
| 48 | modem_info), |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 49 | weak_cdma_ptr_factory_(this), |
| 50 | activation_state_(MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED), |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 51 | cdma_1x_registration_state_(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN), |
| 52 | cdma_evdo_registration_state_(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN), |
| 53 | nid_(0), |
| 54 | sid_(0) { |
| 55 | SLOG(Cellular, 2) << "Cellular capability constructed: Universal CDMA"; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 56 | // TODO(armansito): Update PRL for activation over cellular. |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 57 | // See crbug.com/197330. |
| 58 | } |
| 59 | |
| 60 | void CellularCapabilityUniversalCDMA::InitProxies() { |
| 61 | SLOG(Cellular, 2) << __func__; |
| 62 | modem_cdma_proxy_.reset( |
| 63 | proxy_factory()->CreateMM1ModemModemCdmaProxy(cellular()->dbus_path(), |
| 64 | cellular()->dbus_owner())); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 65 | modem_cdma_proxy_->set_activation_state_callback( |
| 66 | Bind(&CellularCapabilityUniversalCDMA::OnActivationStateChangedSignal, |
| 67 | weak_cdma_ptr_factory_.GetWeakPtr())); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 68 | CellularCapabilityUniversal::InitProxies(); |
| 69 | } |
| 70 | |
| 71 | void CellularCapabilityUniversalCDMA::ReleaseProxies() { |
| 72 | SLOG(Cellular, 2) << __func__; |
| 73 | modem_cdma_proxy_.reset(); |
| 74 | CellularCapabilityUniversal::ReleaseProxies(); |
| 75 | } |
| 76 | |
| 77 | void CellularCapabilityUniversalCDMA::Activate( |
| 78 | const string &carrier, |
| 79 | Error *error, |
| 80 | const ResultCallback &callback) { |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 81 | // Currently activation over the cellular network is not supported using |
| 82 | // ModemManager-next. Service activation is currently carried through over |
| 83 | // non-cellular networks and only the final step of the OTA activation |
| 84 | // procedure ("automatic activation") is performed by this class. |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 85 | OnUnsupportedOperation(__func__, error); |
| 86 | } |
| 87 | |
| 88 | void CellularCapabilityUniversalCDMA::CompleteActivation(Error *error) { |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 89 | SLOG(Cellular, 2) << __func__; |
| 90 | if (cellular()->state() < Cellular::kStateEnabled) { |
| 91 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 92 | "Unable to activate in state " + |
| 93 | Cellular::GetStateString(cellular()->state())); |
| 94 | return; |
| 95 | } |
| 96 | ActivateAutomatic(); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 97 | } |
| 98 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 99 | void CellularCapabilityUniversalCDMA::ActivateAutomatic() { |
| 100 | if (activation_code_.empty()) { |
| 101 | SLOG(Cellular, 2) << "OTA activation cannot be run in the presence of no " |
| 102 | << "activation code."; |
| 103 | return; |
| 104 | } |
| 105 | PendingActivationStore::State state = |
| 106 | modem_info()->pending_activation_store()->GetActivationState( |
| 107 | PendingActivationStore::kIdentifierMEID, meid()); |
| 108 | if (state == PendingActivationStore::kStatePending) { |
| 109 | SLOG(Cellular, 2) << "There's already a pending activation. Ignoring."; |
| 110 | return; |
| 111 | } |
| 112 | if (state == PendingActivationStore::kStateActivated) { |
| 113 | SLOG(Cellular, 2) << "A call to OTA activation has already completed " |
| 114 | << "successfully. Ignoring."; |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | // Mark as pending activation, so that shill can recover if anything fails |
| 119 | // during OTA activation. |
| 120 | modem_info()->pending_activation_store()->SetActivationState( |
| 121 | PendingActivationStore::kIdentifierMEID, |
| 122 | meid(), |
| 123 | PendingActivationStore::kStatePending); |
| 124 | |
| 125 | // Initiate OTA activation. |
| 126 | ResultCallback activation_callback = |
| 127 | Bind(&CellularCapabilityUniversalCDMA::OnActivateReply, |
| 128 | weak_cdma_ptr_factory_.GetWeakPtr(), |
| 129 | ResultCallback()); |
| 130 | // TODO(armansito): Read the activation code from CellularOperatorInfo |
| 131 | Error error; |
| 132 | modem_cdma_proxy_->Activate( |
| 133 | activation_code_, &error, activation_callback, kTimeoutActivate); |
| 134 | } |
| 135 | |
| 136 | void CellularCapabilityUniversalCDMA::UpdatePendingActivationState() { |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 137 | SLOG(Cellular, 2) << __func__; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 138 | if (IsActivated()) { |
| 139 | SLOG(Cellular, 3) << "CDMA service activated. Clear store."; |
| 140 | modem_info()->pending_activation_store()->RemoveEntry( |
| 141 | PendingActivationStore::kIdentifierMEID, meid()); |
| 142 | return; |
| 143 | } |
| 144 | PendingActivationStore::State state = |
| 145 | modem_info()->pending_activation_store()->GetActivationState( |
| 146 | PendingActivationStore::kIdentifierMEID, meid()); |
| 147 | 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 | |
| 167 | bool CellularCapabilityUniversalCDMA::IsServiceActivationRequired() const { |
| 168 | // If there is no online payment portal information, it's safer to assume |
| 169 | // the service does not require activation. |
| 170 | if (!modem_info()->cellular_operator_info()) |
| 171 | return false; |
| 172 | |
| 173 | const CellularService::OLP *olp = |
| 174 | modem_info()->cellular_operator_info()->GetOLPBySID(UintToString(sid_)); |
| 175 | if (!olp) |
| 176 | return false; |
| 177 | |
| 178 | // We could also use the MDN to determine whether or not the service is |
| 179 | // activated, however, the CDMA ActivatonState property is a more absolute |
| 180 | // and fine-grained indicator of activation status. |
| 181 | return (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED); |
| 182 | } |
| 183 | |
| 184 | bool CellularCapabilityUniversalCDMA::IsActivated() const { |
| 185 | return (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | void CellularCapabilityUniversalCDMA::OnServiceCreated() { |
| 189 | SLOG(Cellular, 2) << __func__; |
| 190 | // TODO (armansito): Set storage identifier here based on the superclass |
| 191 | // implementation. |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 192 | UpdateServiceActivationStateProperty(); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 193 | UpdateServingOperator(); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 194 | HandleNewActivationStatus(MM_CDMA_ACTIVATION_ERROR_NONE); |
| 195 | UpdatePendingActivationState(); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 196 | UpdateOLP(); |
| 197 | } |
| 198 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 199 | void CellularCapabilityUniversalCDMA::UpdateServiceActivationStateProperty() { |
| 200 | bool activation_required = IsServiceActivationRequired(); |
| 201 | cellular()->service()->SetActivateOverNonCellularNetwork(activation_required); |
| 202 | string activation_state; |
| 203 | if (IsActivating()) |
| 204 | activation_state = flimflam::kActivationStateActivating; |
| 205 | else if (activation_required) |
| 206 | activation_state = flimflam::kActivationStateNotActivated; |
| 207 | else |
| 208 | activation_state = flimflam::kActivationStateActivated; |
| 209 | cellular()->service()->SetActivationState(activation_state); |
| 210 | } |
| 211 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 212 | void CellularCapabilityUniversalCDMA::UpdateOLP() { |
| 213 | SLOG(Cellular,2) << __func__; |
| 214 | if (!modem_info()->cellular_operator_info()) |
| 215 | return; |
| 216 | |
| 217 | const CellularService::OLP *result = |
| 218 | modem_info()->cellular_operator_info()->GetOLPBySID( |
| 219 | UintToString(sid_)); |
| 220 | if (!result) |
| 221 | return; |
| 222 | |
| 223 | CellularService::OLP olp; |
| 224 | olp.CopyFrom(*result); |
| 225 | string post_data = olp.GetPostData(); |
| 226 | ReplaceSubstringsAfterOffset(&post_data, 0, "${esn}", esn()); |
| 227 | ReplaceSubstringsAfterOffset(&post_data, 0, "${mdn}", mdn()); |
| 228 | ReplaceSubstringsAfterOffset(&post_data, 0, "${meid}", meid()); |
| 229 | olp.SetPostData(post_data); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 230 | if (cellular()->service().get()) |
| 231 | cellular()->service()->SetOLP(olp); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | void CellularCapabilityUniversalCDMA::GetProperties() { |
| 235 | SLOG(Cellular, 2) << __func__; |
| 236 | CellularCapabilityUniversal::GetProperties(); |
| 237 | |
| 238 | scoped_ptr<DBusPropertiesProxyInterface> properties_proxy( |
| 239 | proxy_factory()->CreateDBusPropertiesProxy(cellular()->dbus_path(), |
| 240 | cellular()->dbus_owner())); |
| 241 | DBusPropertiesMap properties( |
| 242 | properties_proxy->GetAll(MM_DBUS_INTERFACE_MODEM_MODEMCDMA)); |
| 243 | OnModemCDMAPropertiesChanged(properties, vector<string>()); |
| 244 | } |
| 245 | |
| 246 | string CellularCapabilityUniversalCDMA::CreateFriendlyServiceName() { |
| 247 | SLOG(Cellular, 2) << __func__ << ": " << GetRoamingStateString(); |
| 248 | |
| 249 | if (provider_.GetCode().empty()) { |
| 250 | UpdateOperatorInfo(); |
| 251 | } |
| 252 | |
| 253 | string name = provider_.GetName(); |
| 254 | if (!name.empty()) { |
| 255 | // TODO(armansito): We may need to show the provider name in a |
| 256 | // specific way if roaming. |
| 257 | return name; |
| 258 | } |
| 259 | |
| 260 | string code = provider_.GetCode(); |
| 261 | if (!code.empty()) { |
| 262 | return "cellular_sid_" + code; |
| 263 | } |
| 264 | |
| 265 | return base::StringPrintf("CDMANetwork%u", friendly_service_name_id_cdma_++); |
| 266 | } |
| 267 | |
| 268 | void CellularCapabilityUniversalCDMA::UpdateOperatorInfo() { |
| 269 | SLOG(Cellular, 2) << __func__; |
| 270 | |
| 271 | if (sid_ == 0 || !modem_info()->cellular_operator_info()) { |
| 272 | SLOG(Cellular, 2) << "No provider is currently available."; |
| 273 | provider_.SetCode(""); |
| 274 | return; |
| 275 | } |
| 276 | |
| 277 | string sid = UintToString(sid_); |
| 278 | const CellularOperatorInfo::CellularOperator *provider = |
| 279 | modem_info()->cellular_operator_info()->GetCellularOperatorBySID(sid); |
| 280 | if (!provider) { |
| 281 | SLOG(Cellular, 2) << "CDMA provider with " |
| 282 | << FormattedSID(sid) |
| 283 | << " not found."; |
| 284 | return; |
| 285 | } |
| 286 | |
| 287 | if (!provider->name_list().empty()) { |
| 288 | provider_.SetName(provider->name_list()[0].name); |
| 289 | } |
| 290 | provider_.SetCode(sid); |
| 291 | provider_.SetCountry(provider->country()); |
| 292 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 293 | activation_code_ = provider->activation_code(); |
| 294 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 295 | // TODO(armansito): The CDMA interface only returns information about the |
| 296 | // current serving carrier, so for now both the home provider and the |
| 297 | // serving operator will be the same in case of roaming. We should figure |
| 298 | // out if there is a way to (and whether or not it is necessary to) |
| 299 | // determine if we're roaming. |
| 300 | cellular()->set_home_provider(provider_); |
| 301 | |
| 302 | UpdateServingOperator(); |
| 303 | } |
| 304 | |
| 305 | void CellularCapabilityUniversalCDMA::UpdateServingOperator() { |
| 306 | SLOG(Cellular, 2) << __func__; |
| 307 | if (cellular()->service().get()) { |
| 308 | cellular()->service()->SetServingOperator(cellular()->home_provider()); |
| 309 | } |
| 310 | } |
| 311 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 312 | void CellularCapabilityUniversalCDMA::OnActivationStateChangedSignal( |
| 313 | uint32 activation_state, |
| 314 | uint32 activation_error, |
| 315 | const DBusPropertiesMap &status_changes) { |
| 316 | SLOG(Cellular, 2) << __func__; |
| 317 | |
| 318 | activation_state_ = |
| 319 | static_cast<MMModemCdmaActivationState>(activation_state); |
| 320 | |
| 321 | string value; |
| 322 | if (DBusProperties::GetString(status_changes, "mdn", &value)) |
| 323 | set_mdn(value); |
| 324 | if (DBusProperties::GetString(status_changes, "min", &value)) |
| 325 | set_min(value); |
| 326 | |
| 327 | SLOG(Cellular, 2) << "Activation state: " |
| 328 | << GetActivationStateString(activation_state_); |
| 329 | |
| 330 | HandleNewActivationStatus(activation_error); |
| 331 | UpdatePendingActivationState(); |
| 332 | } |
| 333 | |
| 334 | void CellularCapabilityUniversalCDMA::OnActivateReply( |
| 335 | const ResultCallback &callback, |
| 336 | const Error &error) { |
| 337 | SLOG(Cellular, 2) << __func__; |
| 338 | if (error.IsSuccess()) { |
| 339 | LOG(INFO) << "Activation completed successfully."; |
| 340 | modem_info()->pending_activation_store()->SetActivationState( |
| 341 | PendingActivationStore::kIdentifierMEID, |
| 342 | meid(), |
| 343 | PendingActivationStore::kStateActivated); |
| 344 | } else { |
| 345 | LOG(ERROR) << "Activation failed with error: " << error; |
| 346 | modem_info()->pending_activation_store()->SetActivationState( |
| 347 | PendingActivationStore::kIdentifierMEID, |
| 348 | meid(), |
| 349 | PendingActivationStore::kStateFailureRetry); |
| 350 | } |
| 351 | UpdatePendingActivationState(); |
| 352 | callback.Run(error); |
| 353 | } |
| 354 | |
| 355 | void CellularCapabilityUniversalCDMA::HandleNewActivationStatus(uint32 error) { |
| 356 | SLOG(Cellular, 2) << __func__ << "(" << error << ")"; |
| 357 | if (!cellular()->service().get()) { |
| 358 | LOG(ERROR) << "In " << __func__ << "(): service is null."; |
| 359 | return; |
| 360 | } |
| 361 | SLOG(Cellular, 2) << "Activation State: " << activation_state_; |
| 362 | cellular()->service()->SetActivationState( |
| 363 | GetActivationStateString(activation_state_)); |
| 364 | cellular()->service()->set_error(GetActivationErrorString(error)); |
| 365 | UpdateOLP(); |
| 366 | } |
| 367 | |
| 368 | // static |
| 369 | string CellularCapabilityUniversalCDMA::GetActivationStateString( |
| 370 | uint32 state) { |
| 371 | switch (state) { |
| 372 | case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED: |
| 373 | return flimflam::kActivationStateActivated; |
| 374 | case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING: |
| 375 | return flimflam::kActivationStateActivating; |
| 376 | case MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED: |
| 377 | return flimflam::kActivationStateNotActivated; |
| 378 | case MM_MODEM_CDMA_ACTIVATION_STATE_PARTIALLY_ACTIVATED: |
| 379 | return flimflam::kActivationStatePartiallyActivated; |
| 380 | default: |
| 381 | return flimflam::kActivationStateUnknown; |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | // static |
| 386 | string CellularCapabilityUniversalCDMA::GetActivationErrorString( |
| 387 | uint32 error) { |
| 388 | switch (error) { |
| 389 | case MM_CDMA_ACTIVATION_ERROR_WRONG_RADIO_INTERFACE: |
| 390 | return flimflam::kErrorNeedEvdo; |
| 391 | case MM_CDMA_ACTIVATION_ERROR_ROAMING: |
| 392 | return flimflam::kErrorNeedHomeNetwork; |
| 393 | case MM_CDMA_ACTIVATION_ERROR_COULD_NOT_CONNECT: |
| 394 | case MM_CDMA_ACTIVATION_ERROR_SECURITY_AUTHENTICATION_FAILED: |
| 395 | case MM_CDMA_ACTIVATION_ERROR_PROVISIONING_FAILED: |
| 396 | return flimflam::kErrorOtaspFailed; |
| 397 | case MM_CDMA_ACTIVATION_ERROR_NONE: |
| 398 | return ""; |
| 399 | case MM_CDMA_ACTIVATION_ERROR_NO_SIGNAL: |
| 400 | default: |
| 401 | return flimflam::kErrorActivationFailed; |
| 402 | } |
| 403 | } |
| 404 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 405 | void CellularCapabilityUniversalCDMA::Register(const ResultCallback &callback) { |
| 406 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 407 | } |
| 408 | |
| 409 | void CellularCapabilityUniversalCDMA::RegisterOnNetwork( |
| 410 | const string &network_id, |
| 411 | Error *error, |
| 412 | const ResultCallback &callback) { |
| 413 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 414 | } |
| 415 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 416 | bool CellularCapabilityUniversalCDMA::IsActivating() const { |
| 417 | PendingActivationStore::State state = |
| 418 | modem_info()->pending_activation_store()->GetActivationState( |
| 419 | PendingActivationStore::kIdentifierMEID, meid()); |
| 420 | return (state == PendingActivationStore::kStatePending) || |
| 421 | (state == PendingActivationStore::kStateFailureRetry) || |
| 422 | (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING); |
| 423 | } |
| 424 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 425 | bool CellularCapabilityUniversalCDMA::IsRegistered() { |
| 426 | return (cdma_1x_registration_state_ == |
| 427 | MM_MODEM_CDMA_REGISTRATION_STATE_HOME || |
| 428 | cdma_1x_registration_state_ == |
| 429 | MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING || |
| 430 | cdma_evdo_registration_state_ == |
| 431 | MM_MODEM_CDMA_REGISTRATION_STATE_HOME || |
| 432 | cdma_evdo_registration_state_ == |
| 433 | MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING); |
| 434 | } |
| 435 | |
| 436 | void CellularCapabilityUniversalCDMA::SetUnregistered(bool /*searching*/) { |
| 437 | cdma_1x_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; |
| 438 | cdma_evdo_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; |
| 439 | } |
| 440 | |
| 441 | void CellularCapabilityUniversalCDMA::RequirePIN( |
| 442 | const string &pin, bool require, |
| 443 | Error *error, const ResultCallback &callback) { |
| 444 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 445 | } |
| 446 | |
| 447 | void CellularCapabilityUniversalCDMA::EnterPIN( |
| 448 | const string &pin, |
| 449 | Error *error, |
| 450 | const ResultCallback &callback) { |
| 451 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 452 | } |
| 453 | |
| 454 | void CellularCapabilityUniversalCDMA::UnblockPIN( |
| 455 | const string &unblock_code, |
| 456 | const string &pin, |
| 457 | Error *error, |
| 458 | const ResultCallback &callback) { |
| 459 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 460 | } |
| 461 | |
| 462 | void CellularCapabilityUniversalCDMA::ChangePIN( |
| 463 | const string &old_pin, const string &new_pin, |
| 464 | Error *error, const ResultCallback &callback) { |
| 465 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 466 | } |
| 467 | |
| 468 | void CellularCapabilityUniversalCDMA::Scan(Error *error, |
| 469 | const ResultCallback &callback) { |
| 470 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 471 | } |
| 472 | |
| 473 | void CellularCapabilityUniversalCDMA::OnSimPathChanged( |
| 474 | const string &sim_path) { |
| 475 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 476 | } |
| 477 | |
| 478 | string CellularCapabilityUniversalCDMA::GetRoamingStateString() const { |
| 479 | uint32 state = cdma_evdo_registration_state_; |
| 480 | if (state == MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN) { |
| 481 | state = cdma_1x_registration_state_; |
| 482 | } |
| 483 | switch (state) { |
| 484 | case MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN: |
| 485 | case MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED: |
| 486 | break; |
| 487 | case MM_MODEM_CDMA_REGISTRATION_STATE_HOME: |
| 488 | return flimflam::kRoamingStateHome; |
| 489 | case MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING: |
| 490 | return flimflam::kRoamingStateRoaming; |
| 491 | default: |
| 492 | NOTREACHED(); |
| 493 | } |
| 494 | return flimflam::kRoamingStateUnknown; |
| 495 | } |
| 496 | |
| 497 | void CellularCapabilityUniversalCDMA::OnDBusPropertiesChanged( |
| 498 | const string &interface, |
| 499 | const DBusPropertiesMap &changed_properties, |
| 500 | const vector<string> &invalidated_properties) { |
| 501 | SLOG(Cellular, 2) << __func__ << "(" << interface << ")"; |
| 502 | if (interface == MM_DBUS_INTERFACE_MODEM_MODEMCDMA) { |
| 503 | OnModemCDMAPropertiesChanged(changed_properties, invalidated_properties); |
| 504 | } else { |
| 505 | CellularCapabilityUniversal::OnDBusPropertiesChanged( |
| 506 | interface, changed_properties, invalidated_properties); |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | void CellularCapabilityUniversalCDMA::OnModemCDMAPropertiesChanged( |
| 511 | const DBusPropertiesMap &properties, |
| 512 | const std::vector<std::string> &/*invalidated_properties*/) { |
| 513 | SLOG(Cellular, 2) << __func__; |
| 514 | string str_value; |
| 515 | if (DBusProperties::GetString(properties, |
| 516 | MM_MODEM_MODEMCDMA_PROPERTY_MEID, |
| 517 | &str_value)) |
| 518 | set_meid(str_value); |
| 519 | if (DBusProperties::GetString(properties, |
| 520 | MM_MODEM_MODEMCDMA_PROPERTY_ESN, |
| 521 | &str_value)) |
| 522 | set_esn(str_value); |
| 523 | |
| 524 | uint32_t sid = sid_; |
| 525 | uint32_t nid = nid_; |
| 526 | MMModemCdmaRegistrationState state_1x = cdma_1x_registration_state_; |
| 527 | MMModemCdmaRegistrationState state_evdo = cdma_evdo_registration_state_; |
| 528 | bool registration_changed = false; |
| 529 | uint32_t uint_value; |
| 530 | if (DBusProperties::GetUint32( |
| 531 | properties, |
| 532 | MM_MODEM_MODEMCDMA_PROPERTY_CDMA1XREGISTRATIONSTATE, |
| 533 | &uint_value)) { |
| 534 | state_1x = static_cast<MMModemCdmaRegistrationState>(uint_value); |
| 535 | registration_changed = true; |
| 536 | } |
| 537 | if (DBusProperties::GetUint32( |
| 538 | properties, |
| 539 | MM_MODEM_MODEMCDMA_PROPERTY_EVDOREGISTRATIONSTATE, |
| 540 | &uint_value)) { |
| 541 | state_evdo = static_cast<MMModemCdmaRegistrationState>(uint_value); |
| 542 | registration_changed = true; |
| 543 | } |
| 544 | if (DBusProperties::GetUint32( |
| 545 | properties, |
| 546 | MM_MODEM_MODEMCDMA_PROPERTY_SID, |
| 547 | &uint_value)) { |
| 548 | sid = uint_value; |
| 549 | registration_changed = true; |
| 550 | } |
| 551 | if (DBusProperties::GetUint32( |
| 552 | properties, |
| 553 | MM_MODEM_MODEMCDMA_PROPERTY_NID, |
| 554 | &uint_value)) { |
| 555 | nid = uint_value; |
| 556 | registration_changed = true; |
| 557 | } |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame^] | 558 | if (DBusProperties::GetUint32( |
| 559 | properties, |
| 560 | MM_MODEM_MODEMCDMA_PROPERTY_ACTIVATIONSTATE, |
| 561 | &uint_value)) { |
| 562 | activation_state_ = static_cast<MMModemCdmaActivationState>(uint_value); |
| 563 | HandleNewActivationStatus(MM_CDMA_ACTIVATION_ERROR_NONE); |
| 564 | } |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 565 | if (registration_changed) |
| 566 | OnCDMARegistrationChanged(state_1x, state_evdo, sid, nid); |
| 567 | } |
| 568 | |
| 569 | void CellularCapabilityUniversalCDMA::OnCDMARegistrationChanged( |
| 570 | MMModemCdmaRegistrationState state_1x, |
| 571 | MMModemCdmaRegistrationState state_evdo, |
| 572 | uint32_t sid, uint32_t nid) { |
| 573 | SLOG(Cellular, 2) << __func__ |
| 574 | << ": state_1x=" << state_1x |
| 575 | << ", state_evdo=" << state_evdo; |
| 576 | cdma_1x_registration_state_ = state_1x; |
| 577 | cdma_evdo_registration_state_ = state_evdo; |
| 578 | sid_ = sid; |
| 579 | nid_ = nid; |
| 580 | UpdateOperatorInfo(); |
| 581 | cellular()->HandleNewRegistrationState(); |
| 582 | } |
| 583 | |
| 584 | } // namespace shill |