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> |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 8 | #include <base/strings/stringprintf.h> |
| 9 | #include <base/strings/string_number_conversions.h> |
| 10 | #include <base/strings/string_util.h> |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 11 | |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 12 | #include "shill/cellular_bearer.h" |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 13 | #include "shill/cellular_operator_info.h" |
| 14 | #include "shill/dbus_properties_proxy_interface.h" |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 15 | #include "shill/error.h" |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 16 | #include "shill/logging.h" |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 17 | #include "shill/pending_activation_store.h" |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 18 | #include "shill/proxy_factory.h" |
| 19 | |
| 20 | #ifdef MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN |
| 21 | #error "Do not include mm-modem.h" |
| 22 | #endif |
| 23 | |
| 24 | using base::UintToString; |
| 25 | |
| 26 | using std::string; |
| 27 | using std::vector; |
| 28 | |
| 29 | namespace shill { |
| 30 | |
| 31 | namespace { |
| 32 | |
Arman Uguray | c967306 | 2013-05-13 21:21:53 -0700 | [diff] [blame] | 33 | const char kPhoneNumber[] = "#777"; |
| 34 | const char kPropertyConnectNumber[] = "number"; |
| 35 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 36 | } // namespace |
| 37 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 38 | CellularCapabilityUniversalCDMA::CellularCapabilityUniversalCDMA( |
| 39 | Cellular *cellular, |
| 40 | ProxyFactory *proxy_factory, |
| 41 | ModemInfo *modem_info) |
Ben Chan | f98f00e | 2014-02-05 14:48:43 -0800 | [diff] [blame] | 42 | : CellularCapabilityUniversal(cellular, proxy_factory, modem_info), |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 43 | weak_cdma_ptr_factory_(this), |
| 44 | activation_state_(MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED), |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 45 | cdma_1x_registration_state_(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN), |
| 46 | cdma_evdo_registration_state_(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN), |
| 47 | nid_(0), |
| 48 | sid_(0) { |
| 49 | SLOG(Cellular, 2) << "Cellular capability constructed: Universal CDMA"; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 50 | // TODO(armansito): Update PRL for activation over cellular. |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 51 | // See crbug.com/197330. |
| 52 | } |
| 53 | |
Ben Chan | f98f00e | 2014-02-05 14:48:43 -0800 | [diff] [blame] | 54 | CellularCapabilityUniversalCDMA::~CellularCapabilityUniversalCDMA() {} |
| 55 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 56 | void CellularCapabilityUniversalCDMA::InitProxies() { |
| 57 | SLOG(Cellular, 2) << __func__; |
| 58 | modem_cdma_proxy_.reset( |
| 59 | proxy_factory()->CreateMM1ModemModemCdmaProxy(cellular()->dbus_path(), |
| 60 | cellular()->dbus_owner())); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 61 | modem_cdma_proxy_->set_activation_state_callback( |
| 62 | Bind(&CellularCapabilityUniversalCDMA::OnActivationStateChangedSignal, |
| 63 | weak_cdma_ptr_factory_.GetWeakPtr())); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 64 | CellularCapabilityUniversal::InitProxies(); |
| 65 | } |
| 66 | |
| 67 | void CellularCapabilityUniversalCDMA::ReleaseProxies() { |
| 68 | SLOG(Cellular, 2) << __func__; |
| 69 | modem_cdma_proxy_.reset(); |
| 70 | CellularCapabilityUniversal::ReleaseProxies(); |
| 71 | } |
| 72 | |
Ben Chan | f98f00e | 2014-02-05 14:48:43 -0800 | [diff] [blame] | 73 | void CellularCapabilityUniversalCDMA::Activate(const string &carrier, |
| 74 | Error *error, |
| 75 | const ResultCallback &callback) { |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 76 | // Currently activation over the cellular network is not supported using |
| 77 | // ModemManager-next. Service activation is currently carried through over |
| 78 | // non-cellular networks and only the final step of the OTA activation |
| 79 | // procedure ("automatic activation") is performed by this class. |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 80 | OnUnsupportedOperation(__func__, error); |
| 81 | } |
| 82 | |
| 83 | void CellularCapabilityUniversalCDMA::CompleteActivation(Error *error) { |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 84 | SLOG(Cellular, 2) << __func__; |
| 85 | if (cellular()->state() < Cellular::kStateEnabled) { |
| 86 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 87 | "Unable to activate in state " + |
| 88 | Cellular::GetStateString(cellular()->state())); |
| 89 | return; |
| 90 | } |
| 91 | ActivateAutomatic(); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 92 | } |
| 93 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 94 | void CellularCapabilityUniversalCDMA::ActivateAutomatic() { |
| 95 | if (activation_code_.empty()) { |
| 96 | SLOG(Cellular, 2) << "OTA activation cannot be run in the presence of no " |
| 97 | << "activation code."; |
| 98 | return; |
| 99 | } |
| 100 | PendingActivationStore::State state = |
| 101 | modem_info()->pending_activation_store()->GetActivationState( |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 102 | PendingActivationStore::kIdentifierMEID, cellular()->meid()); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 103 | if (state == PendingActivationStore::kStatePending) { |
| 104 | SLOG(Cellular, 2) << "There's already a pending activation. Ignoring."; |
| 105 | return; |
| 106 | } |
| 107 | if (state == PendingActivationStore::kStateActivated) { |
| 108 | SLOG(Cellular, 2) << "A call to OTA activation has already completed " |
| 109 | << "successfully. Ignoring."; |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | // Mark as pending activation, so that shill can recover if anything fails |
| 114 | // during OTA activation. |
| 115 | modem_info()->pending_activation_store()->SetActivationState( |
| 116 | PendingActivationStore::kIdentifierMEID, |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 117 | cellular()->meid(), |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 118 | PendingActivationStore::kStatePending); |
| 119 | |
| 120 | // Initiate OTA activation. |
| 121 | ResultCallback activation_callback = |
| 122 | Bind(&CellularCapabilityUniversalCDMA::OnActivateReply, |
| 123 | weak_cdma_ptr_factory_.GetWeakPtr(), |
| 124 | ResultCallback()); |
Arman Uguray | f2b4a34 | 2013-05-23 18:26:52 -0700 | [diff] [blame] | 125 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 126 | Error error; |
| 127 | modem_cdma_proxy_->Activate( |
| 128 | activation_code_, &error, activation_callback, kTimeoutActivate); |
| 129 | } |
| 130 | |
| 131 | void CellularCapabilityUniversalCDMA::UpdatePendingActivationState() { |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 132 | SLOG(Cellular, 2) << __func__; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 133 | if (IsActivated()) { |
| 134 | SLOG(Cellular, 3) << "CDMA service activated. Clear store."; |
| 135 | modem_info()->pending_activation_store()->RemoveEntry( |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 136 | PendingActivationStore::kIdentifierMEID, cellular()->meid()); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 137 | return; |
| 138 | } |
| 139 | PendingActivationStore::State state = |
| 140 | modem_info()->pending_activation_store()->GetActivationState( |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 141 | PendingActivationStore::kIdentifierMEID, cellular()->meid()); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 142 | if (IsActivating() && state != PendingActivationStore::kStateFailureRetry) { |
| 143 | SLOG(Cellular, 3) << "OTA activation in progress. Nothing to do."; |
| 144 | return; |
| 145 | } |
| 146 | switch (state) { |
| 147 | case PendingActivationStore::kStateFailureRetry: |
| 148 | SLOG(Cellular, 3) << "OTA activation failed. Scheduling a retry."; |
| 149 | cellular()->dispatcher()->PostTask( |
| 150 | Bind(&CellularCapabilityUniversalCDMA::ActivateAutomatic, |
| 151 | weak_cdma_ptr_factory_.GetWeakPtr())); |
| 152 | break; |
| 153 | case PendingActivationStore::kStateActivated: |
| 154 | SLOG(Cellular, 3) << "OTA Activation has completed successfully. " |
| 155 | << "Waiting for activation state update to finalize."; |
| 156 | break; |
| 157 | default: |
| 158 | break; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | bool CellularCapabilityUniversalCDMA::IsServiceActivationRequired() const { |
| 163 | // If there is no online payment portal information, it's safer to assume |
| 164 | // the service does not require activation. |
| 165 | if (!modem_info()->cellular_operator_info()) |
| 166 | return false; |
| 167 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 168 | const CellularOperatorInfo::OLP *olp = |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 169 | modem_info()->cellular_operator_info()->GetOLPBySID(UintToString(sid_)); |
| 170 | if (!olp) |
| 171 | return false; |
| 172 | |
| 173 | // We could also use the MDN to determine whether or not the service is |
| 174 | // activated, however, the CDMA ActivatonState property is a more absolute |
| 175 | // and fine-grained indicator of activation status. |
| 176 | return (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED); |
| 177 | } |
| 178 | |
| 179 | bool CellularCapabilityUniversalCDMA::IsActivated() const { |
| 180 | return (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | void CellularCapabilityUniversalCDMA::OnServiceCreated() { |
| 184 | SLOG(Cellular, 2) << __func__; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 185 | UpdateServiceActivationStateProperty(); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 186 | HandleNewActivationStatus(MM_CDMA_ACTIVATION_ERROR_NONE); |
| 187 | UpdatePendingActivationState(); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 188 | } |
| 189 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 190 | void CellularCapabilityUniversalCDMA::UpdateServiceActivationStateProperty() { |
| 191 | bool activation_required = IsServiceActivationRequired(); |
| 192 | cellular()->service()->SetActivateOverNonCellularNetwork(activation_required); |
| 193 | string activation_state; |
| 194 | if (IsActivating()) |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 195 | activation_state = kActivationStateActivating; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 196 | else if (activation_required) |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 197 | activation_state = kActivationStateNotActivated; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 198 | else |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 199 | activation_state = kActivationStateActivated; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 200 | cellular()->service()->SetActivationState(activation_state); |
| 201 | } |
| 202 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 203 | void CellularCapabilityUniversalCDMA::UpdateServiceOLP() { |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 204 | SLOG(Cellular, 2) << __func__; |
| 205 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 206 | // In this case, the Home Provider is trivial. All information comes from the |
| 207 | // Serving Operator. |
| 208 | if (!cellular()->serving_operator_info()->IsMobileNetworkOperatorKnown()) { |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 209 | return; |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 210 | } |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 211 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 212 | const vector<MobileOperatorInfo::OnlinePortal> &olp_list = |
| 213 | cellular()->serving_operator_info()->olp_list(); |
| 214 | if (olp_list.empty()) { |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 215 | return; |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 216 | } |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 217 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 218 | if (olp_list.size() > 1) { |
| 219 | SLOG(Cellular, 1) << "Found multiple online portals. Choosing the first."; |
| 220 | } |
| 221 | string post_data = olp_list[0].post_data; |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 222 | ReplaceSubstringsAfterOffset(&post_data, 0, "${esn}", cellular()->esn()); |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 223 | ReplaceSubstringsAfterOffset( |
| 224 | &post_data, 0, "${mdn}", |
| 225 | GetMdnForOLP(cellular()->serving_operator_info())); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 226 | ReplaceSubstringsAfterOffset(&post_data, 0, "${meid}", cellular()->meid()); |
Arman Uguray | f87fa2f | 2013-10-16 14:24:56 -0700 | [diff] [blame] | 227 | ReplaceSubstringsAfterOffset(&post_data, 0, "${oem}", "GOG2"); |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 228 | cellular()->service()->SetOLP(olp_list[0].url, olp_list[0].method, post_data); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | void CellularCapabilityUniversalCDMA::GetProperties() { |
| 232 | SLOG(Cellular, 2) << __func__; |
| 233 | CellularCapabilityUniversal::GetProperties(); |
| 234 | |
| 235 | scoped_ptr<DBusPropertiesProxyInterface> properties_proxy( |
| 236 | proxy_factory()->CreateDBusPropertiesProxy(cellular()->dbus_path(), |
| 237 | cellular()->dbus_owner())); |
| 238 | DBusPropertiesMap properties( |
| 239 | properties_proxy->GetAll(MM_DBUS_INTERFACE_MODEM_MODEMCDMA)); |
| 240 | OnModemCDMAPropertiesChanged(properties, vector<string>()); |
| 241 | } |
| 242 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 243 | void CellularCapabilityUniversalCDMA::OnActivationStateChangedSignal( |
| 244 | uint32 activation_state, |
| 245 | uint32 activation_error, |
| 246 | const DBusPropertiesMap &status_changes) { |
| 247 | SLOG(Cellular, 2) << __func__; |
| 248 | |
| 249 | activation_state_ = |
| 250 | static_cast<MMModemCdmaActivationState>(activation_state); |
| 251 | |
| 252 | string value; |
| 253 | if (DBusProperties::GetString(status_changes, "mdn", &value)) |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 254 | cellular()->set_mdn(value); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 255 | if (DBusProperties::GetString(status_changes, "min", &value)) |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 256 | cellular()->set_min(value); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 257 | |
| 258 | SLOG(Cellular, 2) << "Activation state: " |
| 259 | << GetActivationStateString(activation_state_); |
| 260 | |
| 261 | HandleNewActivationStatus(activation_error); |
| 262 | UpdatePendingActivationState(); |
| 263 | } |
| 264 | |
| 265 | void CellularCapabilityUniversalCDMA::OnActivateReply( |
| 266 | const ResultCallback &callback, |
| 267 | const Error &error) { |
| 268 | SLOG(Cellular, 2) << __func__; |
| 269 | if (error.IsSuccess()) { |
| 270 | LOG(INFO) << "Activation completed successfully."; |
| 271 | modem_info()->pending_activation_store()->SetActivationState( |
| 272 | PendingActivationStore::kIdentifierMEID, |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 273 | cellular()->meid(), |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 274 | PendingActivationStore::kStateActivated); |
| 275 | } else { |
| 276 | LOG(ERROR) << "Activation failed with error: " << error; |
| 277 | modem_info()->pending_activation_store()->SetActivationState( |
| 278 | PendingActivationStore::kIdentifierMEID, |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 279 | cellular()->meid(), |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 280 | PendingActivationStore::kStateFailureRetry); |
| 281 | } |
| 282 | UpdatePendingActivationState(); |
Arman Uguray | f2b4a34 | 2013-05-23 18:26:52 -0700 | [diff] [blame] | 283 | |
| 284 | // CellularCapabilityUniversalCDMA::ActivateAutomatic passes a dummy |
| 285 | // ResultCallback when it calls Activate on the proxy object, in which case |
| 286 | // |callback.is_null()| will return true. |
| 287 | if (!callback.is_null()) |
| 288 | callback.Run(error); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | void CellularCapabilityUniversalCDMA::HandleNewActivationStatus(uint32 error) { |
| 292 | SLOG(Cellular, 2) << __func__ << "(" << error << ")"; |
| 293 | if (!cellular()->service().get()) { |
| 294 | LOG(ERROR) << "In " << __func__ << "(): service is null."; |
| 295 | return; |
| 296 | } |
| 297 | SLOG(Cellular, 2) << "Activation State: " << activation_state_; |
| 298 | cellular()->service()->SetActivationState( |
| 299 | GetActivationStateString(activation_state_)); |
| 300 | cellular()->service()->set_error(GetActivationErrorString(error)); |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 301 | UpdateServiceOLP(); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | // static |
| 305 | string CellularCapabilityUniversalCDMA::GetActivationStateString( |
| 306 | uint32 state) { |
| 307 | switch (state) { |
| 308 | case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 309 | return kActivationStateActivated; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 310 | case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 311 | return kActivationStateActivating; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 312 | case MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 313 | return kActivationStateNotActivated; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 314 | case MM_MODEM_CDMA_ACTIVATION_STATE_PARTIALLY_ACTIVATED: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 315 | return kActivationStatePartiallyActivated; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 316 | default: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 317 | return kActivationStateUnknown; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | |
| 321 | // static |
| 322 | string CellularCapabilityUniversalCDMA::GetActivationErrorString( |
| 323 | uint32 error) { |
| 324 | switch (error) { |
| 325 | case MM_CDMA_ACTIVATION_ERROR_WRONG_RADIO_INTERFACE: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 326 | return kErrorNeedEvdo; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 327 | case MM_CDMA_ACTIVATION_ERROR_ROAMING: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 328 | return kErrorNeedHomeNetwork; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 329 | case MM_CDMA_ACTIVATION_ERROR_COULD_NOT_CONNECT: |
| 330 | case MM_CDMA_ACTIVATION_ERROR_SECURITY_AUTHENTICATION_FAILED: |
| 331 | case MM_CDMA_ACTIVATION_ERROR_PROVISIONING_FAILED: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 332 | return kErrorOtaspFailed; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 333 | case MM_CDMA_ACTIVATION_ERROR_NONE: |
| 334 | return ""; |
| 335 | case MM_CDMA_ACTIVATION_ERROR_NO_SIGNAL: |
| 336 | default: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 337 | return kErrorActivationFailed; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 338 | } |
| 339 | } |
| 340 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 341 | void CellularCapabilityUniversalCDMA::Register(const ResultCallback &callback) { |
| 342 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 343 | } |
| 344 | |
| 345 | void CellularCapabilityUniversalCDMA::RegisterOnNetwork( |
| 346 | const string &network_id, |
| 347 | Error *error, |
| 348 | const ResultCallback &callback) { |
| 349 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 350 | } |
| 351 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 352 | bool CellularCapabilityUniversalCDMA::IsActivating() const { |
| 353 | PendingActivationStore::State state = |
| 354 | modem_info()->pending_activation_store()->GetActivationState( |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 355 | PendingActivationStore::kIdentifierMEID, cellular()->meid()); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 356 | return (state == PendingActivationStore::kStatePending) || |
| 357 | (state == PendingActivationStore::kStateFailureRetry) || |
| 358 | (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING); |
| 359 | } |
| 360 | |
Ben Chan | 31ce564 | 2013-11-14 13:37:40 -0800 | [diff] [blame] | 361 | bool CellularCapabilityUniversalCDMA::IsRegistered() const { |
Ben Chan | b2c4a80 | 2013-11-14 12:47:52 -0800 | [diff] [blame] | 362 | return (cdma_1x_registration_state_ != |
| 363 | MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN || |
| 364 | cdma_evdo_registration_state_ != |
| 365 | MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | void CellularCapabilityUniversalCDMA::SetUnregistered(bool /*searching*/) { |
| 369 | cdma_1x_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; |
| 370 | cdma_evdo_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; |
| 371 | } |
| 372 | |
Arman Uguray | c967306 | 2013-05-13 21:21:53 -0700 | [diff] [blame] | 373 | void CellularCapabilityUniversalCDMA::SetupConnectProperties( |
| 374 | DBusPropertiesMap *properties) { |
| 375 | (*properties)[kPropertyConnectNumber].writer().append_string( |
| 376 | kPhoneNumber); |
| 377 | } |
| 378 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 379 | void CellularCapabilityUniversalCDMA::RequirePIN( |
| 380 | const string &pin, bool require, |
| 381 | Error *error, const ResultCallback &callback) { |
| 382 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 383 | } |
| 384 | |
| 385 | void CellularCapabilityUniversalCDMA::EnterPIN( |
| 386 | const string &pin, |
| 387 | Error *error, |
| 388 | const ResultCallback &callback) { |
| 389 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 390 | } |
| 391 | |
| 392 | void CellularCapabilityUniversalCDMA::UnblockPIN( |
| 393 | const string &unblock_code, |
| 394 | const string &pin, |
| 395 | Error *error, |
| 396 | const ResultCallback &callback) { |
| 397 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 398 | } |
| 399 | |
| 400 | void CellularCapabilityUniversalCDMA::ChangePIN( |
| 401 | const string &old_pin, const string &new_pin, |
| 402 | Error *error, const ResultCallback &callback) { |
| 403 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 404 | } |
| 405 | |
Prathmesh Prabhu | 49ffffd | 2014-01-09 18:28:55 -0800 | [diff] [blame] | 406 | void CellularCapabilityUniversalCDMA::Scan( |
| 407 | Error *error, |
| 408 | const ResultStringmapsCallback &callback) { |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 409 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
Prathmesh Prabhu | 49ffffd | 2014-01-09 18:28:55 -0800 | [diff] [blame] | 410 | OnUnsupportedOperation(__func__, error); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | void CellularCapabilityUniversalCDMA::OnSimPathChanged( |
| 414 | const string &sim_path) { |
| 415 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 416 | } |
| 417 | |
| 418 | string CellularCapabilityUniversalCDMA::GetRoamingStateString() const { |
| 419 | uint32 state = cdma_evdo_registration_state_; |
| 420 | if (state == MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN) { |
| 421 | state = cdma_1x_registration_state_; |
| 422 | } |
| 423 | switch (state) { |
| 424 | case MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN: |
| 425 | case MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED: |
| 426 | break; |
| 427 | case MM_MODEM_CDMA_REGISTRATION_STATE_HOME: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 428 | return kRoamingStateHome; |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 429 | case MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 430 | return kRoamingStateRoaming; |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 431 | default: |
| 432 | NOTREACHED(); |
| 433 | } |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 434 | return kRoamingStateUnknown; |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | void CellularCapabilityUniversalCDMA::OnDBusPropertiesChanged( |
| 438 | const string &interface, |
| 439 | const DBusPropertiesMap &changed_properties, |
| 440 | const vector<string> &invalidated_properties) { |
| 441 | SLOG(Cellular, 2) << __func__ << "(" << interface << ")"; |
| 442 | if (interface == MM_DBUS_INTERFACE_MODEM_MODEMCDMA) { |
| 443 | OnModemCDMAPropertiesChanged(changed_properties, invalidated_properties); |
| 444 | } else { |
| 445 | CellularCapabilityUniversal::OnDBusPropertiesChanged( |
| 446 | interface, changed_properties, invalidated_properties); |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | void CellularCapabilityUniversalCDMA::OnModemCDMAPropertiesChanged( |
| 451 | const DBusPropertiesMap &properties, |
| 452 | const std::vector<std::string> &/*invalidated_properties*/) { |
| 453 | SLOG(Cellular, 2) << __func__; |
| 454 | string str_value; |
| 455 | if (DBusProperties::GetString(properties, |
| 456 | MM_MODEM_MODEMCDMA_PROPERTY_MEID, |
| 457 | &str_value)) |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 458 | cellular()->set_meid(str_value); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 459 | if (DBusProperties::GetString(properties, |
| 460 | MM_MODEM_MODEMCDMA_PROPERTY_ESN, |
| 461 | &str_value)) |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 462 | cellular()->set_esn(str_value); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 463 | |
| 464 | uint32_t sid = sid_; |
| 465 | uint32_t nid = nid_; |
| 466 | MMModemCdmaRegistrationState state_1x = cdma_1x_registration_state_; |
| 467 | MMModemCdmaRegistrationState state_evdo = cdma_evdo_registration_state_; |
| 468 | bool registration_changed = false; |
| 469 | uint32_t uint_value; |
| 470 | if (DBusProperties::GetUint32( |
| 471 | properties, |
| 472 | MM_MODEM_MODEMCDMA_PROPERTY_CDMA1XREGISTRATIONSTATE, |
| 473 | &uint_value)) { |
| 474 | state_1x = static_cast<MMModemCdmaRegistrationState>(uint_value); |
| 475 | registration_changed = true; |
| 476 | } |
| 477 | if (DBusProperties::GetUint32( |
| 478 | properties, |
| 479 | MM_MODEM_MODEMCDMA_PROPERTY_EVDOREGISTRATIONSTATE, |
| 480 | &uint_value)) { |
| 481 | state_evdo = static_cast<MMModemCdmaRegistrationState>(uint_value); |
| 482 | registration_changed = true; |
| 483 | } |
| 484 | if (DBusProperties::GetUint32( |
| 485 | properties, |
| 486 | MM_MODEM_MODEMCDMA_PROPERTY_SID, |
| 487 | &uint_value)) { |
| 488 | sid = uint_value; |
| 489 | registration_changed = true; |
| 490 | } |
| 491 | if (DBusProperties::GetUint32( |
| 492 | properties, |
| 493 | MM_MODEM_MODEMCDMA_PROPERTY_NID, |
| 494 | &uint_value)) { |
| 495 | nid = uint_value; |
| 496 | registration_changed = true; |
| 497 | } |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 498 | if (DBusProperties::GetUint32( |
| 499 | properties, |
| 500 | MM_MODEM_MODEMCDMA_PROPERTY_ACTIVATIONSTATE, |
| 501 | &uint_value)) { |
| 502 | activation_state_ = static_cast<MMModemCdmaActivationState>(uint_value); |
| 503 | HandleNewActivationStatus(MM_CDMA_ACTIVATION_ERROR_NONE); |
| 504 | } |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 505 | if (registration_changed) |
| 506 | OnCDMARegistrationChanged(state_1x, state_evdo, sid, nid); |
| 507 | } |
| 508 | |
| 509 | void CellularCapabilityUniversalCDMA::OnCDMARegistrationChanged( |
| 510 | MMModemCdmaRegistrationState state_1x, |
| 511 | MMModemCdmaRegistrationState state_evdo, |
| 512 | uint32_t sid, uint32_t nid) { |
| 513 | SLOG(Cellular, 2) << __func__ |
| 514 | << ": state_1x=" << state_1x |
| 515 | << ", state_evdo=" << state_evdo; |
| 516 | cdma_1x_registration_state_ = state_1x; |
| 517 | cdma_evdo_registration_state_ = state_evdo; |
| 518 | sid_ = sid; |
| 519 | nid_ = nid; |
Prathmesh Prabhu | 8599e05 | 2014-04-25 14:20:22 -0700 | [diff] [blame] | 520 | cellular()->serving_operator_info()->UpdateSID(UintToString(sid)); |
| 521 | cellular()->serving_operator_info()->UpdateNID(UintToString(nid)); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 522 | cellular()->HandleNewRegistrationState(); |
| 523 | } |
| 524 | |
| 525 | } // namespace shill |