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 | |
Arman Uguray | c967306 | 2013-05-13 21:21:53 -0700 | [diff] [blame] | 32 | const char kPhoneNumber[] = "#777"; |
| 33 | const char kPropertyConnectNumber[] = "number"; |
| 34 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 35 | string FormattedSID(const string &sid) { |
| 36 | return "[SID=" + sid + "]"; |
| 37 | } |
| 38 | |
| 39 | } // namespace |
| 40 | |
| 41 | // static |
| 42 | unsigned int |
| 43 | CellularCapabilityUniversalCDMA::friendly_service_name_id_cdma_ = 0; |
| 44 | |
| 45 | CellularCapabilityUniversalCDMA::CellularCapabilityUniversalCDMA( |
| 46 | Cellular *cellular, |
| 47 | ProxyFactory *proxy_factory, |
| 48 | ModemInfo *modem_info) |
| 49 | : CellularCapabilityUniversal(cellular, |
| 50 | proxy_factory, |
| 51 | modem_info), |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 52 | weak_cdma_ptr_factory_(this), |
| 53 | activation_state_(MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED), |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 54 | 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 Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 59 | // TODO(armansito): Update PRL for activation over cellular. |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 60 | // See crbug.com/197330. |
| 61 | } |
| 62 | |
| 63 | void CellularCapabilityUniversalCDMA::InitProxies() { |
| 64 | SLOG(Cellular, 2) << __func__; |
| 65 | modem_cdma_proxy_.reset( |
| 66 | proxy_factory()->CreateMM1ModemModemCdmaProxy(cellular()->dbus_path(), |
| 67 | cellular()->dbus_owner())); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 68 | modem_cdma_proxy_->set_activation_state_callback( |
| 69 | Bind(&CellularCapabilityUniversalCDMA::OnActivationStateChangedSignal, |
| 70 | weak_cdma_ptr_factory_.GetWeakPtr())); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 71 | CellularCapabilityUniversal::InitProxies(); |
| 72 | } |
| 73 | |
| 74 | void CellularCapabilityUniversalCDMA::ReleaseProxies() { |
| 75 | SLOG(Cellular, 2) << __func__; |
| 76 | modem_cdma_proxy_.reset(); |
| 77 | CellularCapabilityUniversal::ReleaseProxies(); |
| 78 | } |
| 79 | |
| 80 | void CellularCapabilityUniversalCDMA::Activate( |
| 81 | const string &carrier, |
| 82 | Error *error, |
| 83 | const ResultCallback &callback) { |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 84 | // 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 Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 88 | OnUnsupportedOperation(__func__, error); |
| 89 | } |
| 90 | |
| 91 | void CellularCapabilityUniversalCDMA::CompleteActivation(Error *error) { |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 92 | 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 Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 100 | } |
| 101 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 102 | void 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( |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 110 | PendingActivationStore::kIdentifierMEID, cellular()->meid()); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 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, |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 125 | cellular()->meid(), |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 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 Uguray | f2b4a34 | 2013-05-23 18:26:52 -0700 | [diff] [blame] | 133 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 134 | Error error; |
| 135 | modem_cdma_proxy_->Activate( |
| 136 | activation_code_, &error, activation_callback, kTimeoutActivate); |
| 137 | } |
| 138 | |
| 139 | void CellularCapabilityUniversalCDMA::UpdatePendingActivationState() { |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 140 | SLOG(Cellular, 2) << __func__; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 141 | if (IsActivated()) { |
| 142 | SLOG(Cellular, 3) << "CDMA service activated. Clear store."; |
| 143 | modem_info()->pending_activation_store()->RemoveEntry( |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 144 | PendingActivationStore::kIdentifierMEID, cellular()->meid()); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 145 | return; |
| 146 | } |
| 147 | PendingActivationStore::State state = |
| 148 | modem_info()->pending_activation_store()->GetActivationState( |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 149 | PendingActivationStore::kIdentifierMEID, cellular()->meid()); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 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 | |
| 170 | bool 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 | |
| 187 | bool CellularCapabilityUniversalCDMA::IsActivated() const { |
| 188 | return (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 189 | } |
| 190 | |
Arman Uguray | c539123 | 2013-09-23 21:30:46 -0700 | [diff] [blame] | 191 | void 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 Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 210 | void CellularCapabilityUniversalCDMA::OnServiceCreated() { |
| 211 | SLOG(Cellular, 2) << __func__; |
Arman Uguray | c539123 | 2013-09-23 21:30:46 -0700 | [diff] [blame] | 212 | UpdateStorageIdentifier(); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 213 | UpdateServiceActivationStateProperty(); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 214 | UpdateServingOperator(); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 215 | HandleNewActivationStatus(MM_CDMA_ACTIVATION_ERROR_NONE); |
| 216 | UpdatePendingActivationState(); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 217 | UpdateOLP(); |
| 218 | } |
| 219 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 220 | void CellularCapabilityUniversalCDMA::UpdateServiceActivationStateProperty() { |
| 221 | bool activation_required = IsServiceActivationRequired(); |
| 222 | cellular()->service()->SetActivateOverNonCellularNetwork(activation_required); |
| 223 | string activation_state; |
| 224 | if (IsActivating()) |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 225 | activation_state = kActivationStateActivating; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 226 | else if (activation_required) |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 227 | activation_state = kActivationStateNotActivated; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 228 | else |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 229 | activation_state = kActivationStateActivated; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 230 | cellular()->service()->SetActivationState(activation_state); |
| 231 | } |
| 232 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 233 | void CellularCapabilityUniversalCDMA::UpdateOLP() { |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 234 | 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 Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 245 | return; |
| 246 | |
| 247 | const CellularService::OLP *result = |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 248 | cellular_operator_info->GetOLPBySID(sid_string); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 249 | if (!result) |
| 250 | return; |
| 251 | |
| 252 | CellularService::OLP olp; |
| 253 | olp.CopyFrom(*result); |
| 254 | string post_data = olp.GetPostData(); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 255 | ReplaceSubstringsAfterOffset(&post_data, 0, "${esn}", cellular()->esn()); |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 256 | ReplaceSubstringsAfterOffset(&post_data, 0, "${mdn}", |
| 257 | GetMdnForOLP(*cellular_operator)); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 258 | ReplaceSubstringsAfterOffset(&post_data, 0, "${meid}", cellular()->meid()); |
Arman Uguray | f87fa2f | 2013-10-16 14:24:56 -0700 | [diff] [blame] | 259 | ReplaceSubstringsAfterOffset(&post_data, 0, "${oem}", "GOG2"); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 260 | olp.SetPostData(post_data); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 261 | if (cellular()->service().get()) |
| 262 | cellular()->service()->SetOLP(olp); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | void 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 | |
| 277 | string 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 | |
| 299 | void 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 Uguray | e015faf | 2013-08-16 17:54:59 -0700 | [diff] [blame] | 315 | // 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 Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 327 | |
Arman Uguray | e015faf | 2013-08-16 17:54:59 -0700 | [diff] [blame] | 328 | activation_code_ = provider->activation_code(); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 329 | } |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 330 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 331 | // 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 Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 337 | UpdateServingOperator(); |
| 338 | } |
| 339 | |
| 340 | void CellularCapabilityUniversalCDMA::UpdateServingOperator() { |
| 341 | SLOG(Cellular, 2) << __func__; |
| 342 | if (cellular()->service().get()) { |
| 343 | cellular()->service()->SetServingOperator(cellular()->home_provider()); |
Arman Uguray | 2269bb6 | 2013-07-26 14:53:30 -0700 | [diff] [blame] | 344 | cellular()->service()->SetFriendlyName(CreateFriendlyServiceName()); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 345 | } |
| 346 | } |
| 347 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 348 | void 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)) |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 359 | cellular()->set_mdn(value); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 360 | if (DBusProperties::GetString(status_changes, "min", &value)) |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 361 | cellular()->set_min(value); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 362 | |
| 363 | SLOG(Cellular, 2) << "Activation state: " |
| 364 | << GetActivationStateString(activation_state_); |
| 365 | |
| 366 | HandleNewActivationStatus(activation_error); |
| 367 | UpdatePendingActivationState(); |
| 368 | } |
| 369 | |
| 370 | void 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, |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 378 | cellular()->meid(), |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 379 | PendingActivationStore::kStateActivated); |
| 380 | } else { |
| 381 | LOG(ERROR) << "Activation failed with error: " << error; |
| 382 | modem_info()->pending_activation_store()->SetActivationState( |
| 383 | PendingActivationStore::kIdentifierMEID, |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 384 | cellular()->meid(), |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 385 | PendingActivationStore::kStateFailureRetry); |
| 386 | } |
| 387 | UpdatePendingActivationState(); |
Arman Uguray | f2b4a34 | 2013-05-23 18:26:52 -0700 | [diff] [blame] | 388 | |
| 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 Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | void 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 |
| 410 | string CellularCapabilityUniversalCDMA::GetActivationStateString( |
| 411 | uint32 state) { |
| 412 | switch (state) { |
| 413 | case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 414 | return kActivationStateActivated; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 415 | case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 416 | return kActivationStateActivating; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 417 | case MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 418 | return kActivationStateNotActivated; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 419 | case MM_MODEM_CDMA_ACTIVATION_STATE_PARTIALLY_ACTIVATED: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 420 | return kActivationStatePartiallyActivated; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 421 | default: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 422 | return kActivationStateUnknown; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | |
| 426 | // static |
| 427 | string CellularCapabilityUniversalCDMA::GetActivationErrorString( |
| 428 | uint32 error) { |
| 429 | switch (error) { |
| 430 | case MM_CDMA_ACTIVATION_ERROR_WRONG_RADIO_INTERFACE: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 431 | return kErrorNeedEvdo; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 432 | case MM_CDMA_ACTIVATION_ERROR_ROAMING: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 433 | return kErrorNeedHomeNetwork; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 434 | 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 Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 437 | return kErrorOtaspFailed; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 438 | case MM_CDMA_ACTIVATION_ERROR_NONE: |
| 439 | return ""; |
| 440 | case MM_CDMA_ACTIVATION_ERROR_NO_SIGNAL: |
| 441 | default: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 442 | return kErrorActivationFailed; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 443 | } |
| 444 | } |
| 445 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 446 | void CellularCapabilityUniversalCDMA::Register(const ResultCallback &callback) { |
| 447 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 448 | } |
| 449 | |
| 450 | void 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 Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 457 | bool CellularCapabilityUniversalCDMA::IsActivating() const { |
| 458 | PendingActivationStore::State state = |
| 459 | modem_info()->pending_activation_store()->GetActivationState( |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 460 | PendingActivationStore::kIdentifierMEID, cellular()->meid()); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 461 | return (state == PendingActivationStore::kStatePending) || |
| 462 | (state == PendingActivationStore::kStateFailureRetry) || |
| 463 | (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING); |
| 464 | } |
| 465 | |
Ben Chan | 31ce564 | 2013-11-14 13:37:40 -0800 | [diff] [blame] | 466 | bool CellularCapabilityUniversalCDMA::IsRegistered() const { |
Ben Chan | b2c4a80 | 2013-11-14 12:47:52 -0800 | [diff] [blame] | 467 | return (cdma_1x_registration_state_ != |
| 468 | MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN || |
| 469 | cdma_evdo_registration_state_ != |
| 470 | MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | void CellularCapabilityUniversalCDMA::SetUnregistered(bool /*searching*/) { |
| 474 | cdma_1x_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; |
| 475 | cdma_evdo_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; |
| 476 | } |
| 477 | |
Arman Uguray | c967306 | 2013-05-13 21:21:53 -0700 | [diff] [blame] | 478 | void CellularCapabilityUniversalCDMA::SetupConnectProperties( |
| 479 | DBusPropertiesMap *properties) { |
| 480 | (*properties)[kPropertyConnectNumber].writer().append_string( |
| 481 | kPhoneNumber); |
| 482 | } |
| 483 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 484 | void CellularCapabilityUniversalCDMA::RequirePIN( |
| 485 | const string &pin, bool require, |
| 486 | Error *error, const ResultCallback &callback) { |
| 487 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 488 | } |
| 489 | |
| 490 | void CellularCapabilityUniversalCDMA::EnterPIN( |
| 491 | const string &pin, |
| 492 | Error *error, |
| 493 | const ResultCallback &callback) { |
| 494 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 495 | } |
| 496 | |
| 497 | void CellularCapabilityUniversalCDMA::UnblockPIN( |
| 498 | const string &unblock_code, |
| 499 | const string &pin, |
| 500 | Error *error, |
| 501 | const ResultCallback &callback) { |
| 502 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 503 | } |
| 504 | |
| 505 | void CellularCapabilityUniversalCDMA::ChangePIN( |
| 506 | const string &old_pin, const string &new_pin, |
| 507 | Error *error, const ResultCallback &callback) { |
| 508 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 509 | } |
| 510 | |
Prathmesh Prabhu | 49ffffd | 2014-01-09 18:28:55 -0800 | [diff] [blame] | 511 | void CellularCapabilityUniversalCDMA::Scan( |
| 512 | Error *error, |
| 513 | const ResultStringmapsCallback &callback) { |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 514 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
Prathmesh Prabhu | 49ffffd | 2014-01-09 18:28:55 -0800 | [diff] [blame] | 515 | OnUnsupportedOperation(__func__, error); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | void CellularCapabilityUniversalCDMA::OnSimPathChanged( |
| 519 | const string &sim_path) { |
| 520 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 521 | } |
| 522 | |
| 523 | string CellularCapabilityUniversalCDMA::GetRoamingStateString() const { |
| 524 | uint32 state = cdma_evdo_registration_state_; |
| 525 | if (state == MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN) { |
| 526 | state = cdma_1x_registration_state_; |
| 527 | } |
| 528 | switch (state) { |
| 529 | case MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN: |
| 530 | case MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED: |
| 531 | break; |
| 532 | case MM_MODEM_CDMA_REGISTRATION_STATE_HOME: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 533 | return kRoamingStateHome; |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 534 | case MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 535 | return kRoamingStateRoaming; |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 536 | default: |
| 537 | NOTREACHED(); |
| 538 | } |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 539 | return kRoamingStateUnknown; |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | void CellularCapabilityUniversalCDMA::OnDBusPropertiesChanged( |
| 543 | const string &interface, |
| 544 | const DBusPropertiesMap &changed_properties, |
| 545 | const vector<string> &invalidated_properties) { |
| 546 | SLOG(Cellular, 2) << __func__ << "(" << interface << ")"; |
| 547 | if (interface == MM_DBUS_INTERFACE_MODEM_MODEMCDMA) { |
| 548 | OnModemCDMAPropertiesChanged(changed_properties, invalidated_properties); |
| 549 | } else { |
| 550 | CellularCapabilityUniversal::OnDBusPropertiesChanged( |
| 551 | interface, changed_properties, invalidated_properties); |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | void CellularCapabilityUniversalCDMA::OnModemCDMAPropertiesChanged( |
| 556 | const DBusPropertiesMap &properties, |
| 557 | const std::vector<std::string> &/*invalidated_properties*/) { |
| 558 | SLOG(Cellular, 2) << __func__; |
| 559 | string str_value; |
| 560 | if (DBusProperties::GetString(properties, |
| 561 | MM_MODEM_MODEMCDMA_PROPERTY_MEID, |
| 562 | &str_value)) |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 563 | cellular()->set_meid(str_value); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 564 | if (DBusProperties::GetString(properties, |
| 565 | MM_MODEM_MODEMCDMA_PROPERTY_ESN, |
| 566 | &str_value)) |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 567 | cellular()->set_esn(str_value); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 568 | |
| 569 | uint32_t sid = sid_; |
| 570 | uint32_t nid = nid_; |
| 571 | MMModemCdmaRegistrationState state_1x = cdma_1x_registration_state_; |
| 572 | MMModemCdmaRegistrationState state_evdo = cdma_evdo_registration_state_; |
| 573 | bool registration_changed = false; |
| 574 | uint32_t uint_value; |
| 575 | if (DBusProperties::GetUint32( |
| 576 | properties, |
| 577 | MM_MODEM_MODEMCDMA_PROPERTY_CDMA1XREGISTRATIONSTATE, |
| 578 | &uint_value)) { |
| 579 | state_1x = static_cast<MMModemCdmaRegistrationState>(uint_value); |
| 580 | registration_changed = true; |
| 581 | } |
| 582 | if (DBusProperties::GetUint32( |
| 583 | properties, |
| 584 | MM_MODEM_MODEMCDMA_PROPERTY_EVDOREGISTRATIONSTATE, |
| 585 | &uint_value)) { |
| 586 | state_evdo = static_cast<MMModemCdmaRegistrationState>(uint_value); |
| 587 | registration_changed = true; |
| 588 | } |
| 589 | if (DBusProperties::GetUint32( |
| 590 | properties, |
| 591 | MM_MODEM_MODEMCDMA_PROPERTY_SID, |
| 592 | &uint_value)) { |
| 593 | sid = uint_value; |
| 594 | registration_changed = true; |
| 595 | } |
| 596 | if (DBusProperties::GetUint32( |
| 597 | properties, |
| 598 | MM_MODEM_MODEMCDMA_PROPERTY_NID, |
| 599 | &uint_value)) { |
| 600 | nid = uint_value; |
| 601 | registration_changed = true; |
| 602 | } |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 603 | if (DBusProperties::GetUint32( |
| 604 | properties, |
| 605 | MM_MODEM_MODEMCDMA_PROPERTY_ACTIVATIONSTATE, |
| 606 | &uint_value)) { |
| 607 | activation_state_ = static_cast<MMModemCdmaActivationState>(uint_value); |
| 608 | HandleNewActivationStatus(MM_CDMA_ACTIVATION_ERROR_NONE); |
| 609 | } |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 610 | if (registration_changed) |
| 611 | OnCDMARegistrationChanged(state_1x, state_evdo, sid, nid); |
| 612 | } |
| 613 | |
| 614 | void CellularCapabilityUniversalCDMA::OnCDMARegistrationChanged( |
| 615 | MMModemCdmaRegistrationState state_1x, |
| 616 | MMModemCdmaRegistrationState state_evdo, |
| 617 | uint32_t sid, uint32_t nid) { |
| 618 | SLOG(Cellular, 2) << __func__ |
| 619 | << ": state_1x=" << state_1x |
| 620 | << ", state_evdo=" << state_evdo; |
| 621 | cdma_1x_registration_state_ = state_1x; |
| 622 | cdma_evdo_registration_state_ = state_evdo; |
| 623 | sid_ = sid; |
| 624 | nid_ = nid; |
| 625 | UpdateOperatorInfo(); |
| 626 | cellular()->HandleNewRegistrationState(); |
| 627 | } |
| 628 | |
| 629 | } // namespace shill |