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" |
Prathmesh Prabhu | 3b66bb9 | 2014-05-22 11:15:25 -0700 | [diff] [blame^] | 13 | #include "shill/cellular_service.h" |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 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. |
Prathmesh Prabhu | 3ee2f41 | 2014-05-20 17:30:19 -0700 | [diff] [blame] | 165 | if (!cellular()->serving_operator_info()->IsMobileNetworkOperatorKnown() || |
| 166 | cellular()->serving_operator_info()->olp_list().empty()) { |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 167 | return false; |
Prathmesh Prabhu | 3ee2f41 | 2014-05-20 17:30:19 -0700 | [diff] [blame] | 168 | } |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 169 | |
| 170 | // We could also use the MDN to determine whether or not the service is |
| 171 | // activated, however, the CDMA ActivatonState property is a more absolute |
| 172 | // and fine-grained indicator of activation status. |
| 173 | return (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED); |
| 174 | } |
| 175 | |
| 176 | bool CellularCapabilityUniversalCDMA::IsActivated() const { |
| 177 | return (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | void CellularCapabilityUniversalCDMA::OnServiceCreated() { |
| 181 | SLOG(Cellular, 2) << __func__; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 182 | UpdateServiceActivationStateProperty(); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 183 | HandleNewActivationStatus(MM_CDMA_ACTIVATION_ERROR_NONE); |
| 184 | UpdatePendingActivationState(); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 185 | } |
| 186 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 187 | void CellularCapabilityUniversalCDMA::UpdateServiceActivationStateProperty() { |
| 188 | bool activation_required = IsServiceActivationRequired(); |
| 189 | cellular()->service()->SetActivateOverNonCellularNetwork(activation_required); |
| 190 | string activation_state; |
| 191 | if (IsActivating()) |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 192 | activation_state = kActivationStateActivating; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 193 | else if (activation_required) |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 194 | activation_state = kActivationStateNotActivated; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 195 | else |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 196 | activation_state = kActivationStateActivated; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 197 | cellular()->service()->SetActivationState(activation_state); |
| 198 | } |
| 199 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 200 | void CellularCapabilityUniversalCDMA::UpdateServiceOLP() { |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 201 | SLOG(Cellular, 2) << __func__; |
| 202 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 203 | // In this case, the Home Provider is trivial. All information comes from the |
| 204 | // Serving Operator. |
| 205 | if (!cellular()->serving_operator_info()->IsMobileNetworkOperatorKnown()) { |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 206 | return; |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 207 | } |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 208 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 209 | const vector<MobileOperatorInfo::OnlinePortal> &olp_list = |
| 210 | cellular()->serving_operator_info()->olp_list(); |
| 211 | if (olp_list.empty()) { |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 212 | return; |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 213 | } |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 214 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 215 | if (olp_list.size() > 1) { |
| 216 | SLOG(Cellular, 1) << "Found multiple online portals. Choosing the first."; |
| 217 | } |
| 218 | string post_data = olp_list[0].post_data; |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 219 | ReplaceSubstringsAfterOffset(&post_data, 0, "${esn}", cellular()->esn()); |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 220 | ReplaceSubstringsAfterOffset( |
| 221 | &post_data, 0, "${mdn}", |
| 222 | GetMdnForOLP(cellular()->serving_operator_info())); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 223 | ReplaceSubstringsAfterOffset(&post_data, 0, "${meid}", cellular()->meid()); |
Arman Uguray | f87fa2f | 2013-10-16 14:24:56 -0700 | [diff] [blame] | 224 | ReplaceSubstringsAfterOffset(&post_data, 0, "${oem}", "GOG2"); |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 225 | 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] | 226 | } |
| 227 | |
| 228 | void CellularCapabilityUniversalCDMA::GetProperties() { |
| 229 | SLOG(Cellular, 2) << __func__; |
| 230 | CellularCapabilityUniversal::GetProperties(); |
| 231 | |
| 232 | scoped_ptr<DBusPropertiesProxyInterface> properties_proxy( |
| 233 | proxy_factory()->CreateDBusPropertiesProxy(cellular()->dbus_path(), |
| 234 | cellular()->dbus_owner())); |
| 235 | DBusPropertiesMap properties( |
| 236 | properties_proxy->GetAll(MM_DBUS_INTERFACE_MODEM_MODEMCDMA)); |
| 237 | OnModemCDMAPropertiesChanged(properties, vector<string>()); |
| 238 | } |
| 239 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 240 | void CellularCapabilityUniversalCDMA::OnActivationStateChangedSignal( |
| 241 | uint32 activation_state, |
| 242 | uint32 activation_error, |
| 243 | const DBusPropertiesMap &status_changes) { |
| 244 | SLOG(Cellular, 2) << __func__; |
| 245 | |
| 246 | activation_state_ = |
| 247 | static_cast<MMModemCdmaActivationState>(activation_state); |
| 248 | |
| 249 | string value; |
| 250 | if (DBusProperties::GetString(status_changes, "mdn", &value)) |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 251 | cellular()->set_mdn(value); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 252 | if (DBusProperties::GetString(status_changes, "min", &value)) |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 253 | cellular()->set_min(value); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 254 | |
| 255 | SLOG(Cellular, 2) << "Activation state: " |
| 256 | << GetActivationStateString(activation_state_); |
| 257 | |
| 258 | HandleNewActivationStatus(activation_error); |
| 259 | UpdatePendingActivationState(); |
| 260 | } |
| 261 | |
| 262 | void CellularCapabilityUniversalCDMA::OnActivateReply( |
| 263 | const ResultCallback &callback, |
| 264 | const Error &error) { |
| 265 | SLOG(Cellular, 2) << __func__; |
| 266 | if (error.IsSuccess()) { |
| 267 | LOG(INFO) << "Activation completed successfully."; |
| 268 | modem_info()->pending_activation_store()->SetActivationState( |
| 269 | PendingActivationStore::kIdentifierMEID, |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 270 | cellular()->meid(), |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 271 | PendingActivationStore::kStateActivated); |
| 272 | } else { |
| 273 | LOG(ERROR) << "Activation failed with error: " << error; |
| 274 | modem_info()->pending_activation_store()->SetActivationState( |
| 275 | PendingActivationStore::kIdentifierMEID, |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 276 | cellular()->meid(), |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 277 | PendingActivationStore::kStateFailureRetry); |
| 278 | } |
| 279 | UpdatePendingActivationState(); |
Arman Uguray | f2b4a34 | 2013-05-23 18:26:52 -0700 | [diff] [blame] | 280 | |
| 281 | // CellularCapabilityUniversalCDMA::ActivateAutomatic passes a dummy |
| 282 | // ResultCallback when it calls Activate on the proxy object, in which case |
| 283 | // |callback.is_null()| will return true. |
| 284 | if (!callback.is_null()) |
| 285 | callback.Run(error); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | void CellularCapabilityUniversalCDMA::HandleNewActivationStatus(uint32 error) { |
| 289 | SLOG(Cellular, 2) << __func__ << "(" << error << ")"; |
| 290 | if (!cellular()->service().get()) { |
| 291 | LOG(ERROR) << "In " << __func__ << "(): service is null."; |
| 292 | return; |
| 293 | } |
| 294 | SLOG(Cellular, 2) << "Activation State: " << activation_state_; |
| 295 | cellular()->service()->SetActivationState( |
| 296 | GetActivationStateString(activation_state_)); |
| 297 | cellular()->service()->set_error(GetActivationErrorString(error)); |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 298 | UpdateServiceOLP(); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | // static |
| 302 | string CellularCapabilityUniversalCDMA::GetActivationStateString( |
| 303 | uint32 state) { |
| 304 | switch (state) { |
| 305 | case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 306 | return kActivationStateActivated; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 307 | case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 308 | return kActivationStateActivating; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 309 | case MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 310 | return kActivationStateNotActivated; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 311 | case MM_MODEM_CDMA_ACTIVATION_STATE_PARTIALLY_ACTIVATED: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 312 | return kActivationStatePartiallyActivated; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 313 | default: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 314 | return kActivationStateUnknown; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | |
| 318 | // static |
| 319 | string CellularCapabilityUniversalCDMA::GetActivationErrorString( |
| 320 | uint32 error) { |
| 321 | switch (error) { |
| 322 | case MM_CDMA_ACTIVATION_ERROR_WRONG_RADIO_INTERFACE: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 323 | return kErrorNeedEvdo; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 324 | case MM_CDMA_ACTIVATION_ERROR_ROAMING: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 325 | return kErrorNeedHomeNetwork; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 326 | case MM_CDMA_ACTIVATION_ERROR_COULD_NOT_CONNECT: |
| 327 | case MM_CDMA_ACTIVATION_ERROR_SECURITY_AUTHENTICATION_FAILED: |
| 328 | case MM_CDMA_ACTIVATION_ERROR_PROVISIONING_FAILED: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 329 | return kErrorOtaspFailed; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 330 | case MM_CDMA_ACTIVATION_ERROR_NONE: |
| 331 | return ""; |
| 332 | case MM_CDMA_ACTIVATION_ERROR_NO_SIGNAL: |
| 333 | default: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 334 | return kErrorActivationFailed; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 335 | } |
| 336 | } |
| 337 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 338 | void CellularCapabilityUniversalCDMA::Register(const ResultCallback &callback) { |
| 339 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 340 | } |
| 341 | |
| 342 | void CellularCapabilityUniversalCDMA::RegisterOnNetwork( |
| 343 | const string &network_id, |
| 344 | Error *error, |
| 345 | const ResultCallback &callback) { |
| 346 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 347 | } |
| 348 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 349 | bool CellularCapabilityUniversalCDMA::IsActivating() const { |
| 350 | PendingActivationStore::State state = |
| 351 | modem_info()->pending_activation_store()->GetActivationState( |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 352 | PendingActivationStore::kIdentifierMEID, cellular()->meid()); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 353 | return (state == PendingActivationStore::kStatePending) || |
| 354 | (state == PendingActivationStore::kStateFailureRetry) || |
| 355 | (activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING); |
| 356 | } |
| 357 | |
Ben Chan | 31ce564 | 2013-11-14 13:37:40 -0800 | [diff] [blame] | 358 | bool CellularCapabilityUniversalCDMA::IsRegistered() const { |
Ben Chan | b2c4a80 | 2013-11-14 12:47:52 -0800 | [diff] [blame] | 359 | return (cdma_1x_registration_state_ != |
| 360 | MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN || |
| 361 | cdma_evdo_registration_state_ != |
| 362 | MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | void CellularCapabilityUniversalCDMA::SetUnregistered(bool /*searching*/) { |
| 366 | cdma_1x_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; |
| 367 | cdma_evdo_registration_state_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; |
| 368 | } |
| 369 | |
Arman Uguray | c967306 | 2013-05-13 21:21:53 -0700 | [diff] [blame] | 370 | void CellularCapabilityUniversalCDMA::SetupConnectProperties( |
| 371 | DBusPropertiesMap *properties) { |
| 372 | (*properties)[kPropertyConnectNumber].writer().append_string( |
| 373 | kPhoneNumber); |
| 374 | } |
| 375 | |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 376 | void CellularCapabilityUniversalCDMA::RequirePIN( |
| 377 | const string &pin, bool require, |
| 378 | Error *error, const ResultCallback &callback) { |
| 379 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 380 | } |
| 381 | |
| 382 | void CellularCapabilityUniversalCDMA::EnterPIN( |
| 383 | const string &pin, |
| 384 | Error *error, |
| 385 | const ResultCallback &callback) { |
| 386 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 387 | } |
| 388 | |
| 389 | void CellularCapabilityUniversalCDMA::UnblockPIN( |
| 390 | const string &unblock_code, |
| 391 | const string &pin, |
| 392 | Error *error, |
| 393 | const ResultCallback &callback) { |
| 394 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 395 | } |
| 396 | |
| 397 | void CellularCapabilityUniversalCDMA::ChangePIN( |
| 398 | const string &old_pin, const string &new_pin, |
| 399 | Error *error, const ResultCallback &callback) { |
| 400 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 401 | } |
| 402 | |
Prathmesh Prabhu | 49ffffd | 2014-01-09 18:28:55 -0800 | [diff] [blame] | 403 | void CellularCapabilityUniversalCDMA::Scan( |
| 404 | Error *error, |
| 405 | const ResultStringmapsCallback &callback) { |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 406 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
Prathmesh Prabhu | 49ffffd | 2014-01-09 18:28:55 -0800 | [diff] [blame] | 407 | OnUnsupportedOperation(__func__, error); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | void CellularCapabilityUniversalCDMA::OnSimPathChanged( |
| 411 | const string &sim_path) { |
| 412 | // TODO(armansito): Remove once 3GPP is implemented in its own class. |
| 413 | } |
| 414 | |
| 415 | string CellularCapabilityUniversalCDMA::GetRoamingStateString() const { |
| 416 | uint32 state = cdma_evdo_registration_state_; |
| 417 | if (state == MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN) { |
| 418 | state = cdma_1x_registration_state_; |
| 419 | } |
| 420 | switch (state) { |
| 421 | case MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN: |
| 422 | case MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED: |
| 423 | break; |
| 424 | case MM_MODEM_CDMA_REGISTRATION_STATE_HOME: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 425 | return kRoamingStateHome; |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 426 | case MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 427 | return kRoamingStateRoaming; |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 428 | default: |
| 429 | NOTREACHED(); |
| 430 | } |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 431 | return kRoamingStateUnknown; |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | void CellularCapabilityUniversalCDMA::OnDBusPropertiesChanged( |
| 435 | const string &interface, |
| 436 | const DBusPropertiesMap &changed_properties, |
| 437 | const vector<string> &invalidated_properties) { |
| 438 | SLOG(Cellular, 2) << __func__ << "(" << interface << ")"; |
| 439 | if (interface == MM_DBUS_INTERFACE_MODEM_MODEMCDMA) { |
| 440 | OnModemCDMAPropertiesChanged(changed_properties, invalidated_properties); |
| 441 | } else { |
| 442 | CellularCapabilityUniversal::OnDBusPropertiesChanged( |
| 443 | interface, changed_properties, invalidated_properties); |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | void CellularCapabilityUniversalCDMA::OnModemCDMAPropertiesChanged( |
| 448 | const DBusPropertiesMap &properties, |
| 449 | const std::vector<std::string> &/*invalidated_properties*/) { |
| 450 | SLOG(Cellular, 2) << __func__; |
| 451 | string str_value; |
| 452 | if (DBusProperties::GetString(properties, |
| 453 | MM_MODEM_MODEMCDMA_PROPERTY_MEID, |
| 454 | &str_value)) |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 455 | cellular()->set_meid(str_value); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 456 | if (DBusProperties::GetString(properties, |
| 457 | MM_MODEM_MODEMCDMA_PROPERTY_ESN, |
| 458 | &str_value)) |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 459 | cellular()->set_esn(str_value); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 460 | |
| 461 | uint32_t sid = sid_; |
| 462 | uint32_t nid = nid_; |
| 463 | MMModemCdmaRegistrationState state_1x = cdma_1x_registration_state_; |
| 464 | MMModemCdmaRegistrationState state_evdo = cdma_evdo_registration_state_; |
| 465 | bool registration_changed = false; |
| 466 | uint32_t uint_value; |
| 467 | if (DBusProperties::GetUint32( |
| 468 | properties, |
| 469 | MM_MODEM_MODEMCDMA_PROPERTY_CDMA1XREGISTRATIONSTATE, |
| 470 | &uint_value)) { |
| 471 | state_1x = static_cast<MMModemCdmaRegistrationState>(uint_value); |
| 472 | registration_changed = true; |
| 473 | } |
| 474 | if (DBusProperties::GetUint32( |
| 475 | properties, |
| 476 | MM_MODEM_MODEMCDMA_PROPERTY_EVDOREGISTRATIONSTATE, |
| 477 | &uint_value)) { |
| 478 | state_evdo = static_cast<MMModemCdmaRegistrationState>(uint_value); |
| 479 | registration_changed = true; |
| 480 | } |
| 481 | if (DBusProperties::GetUint32( |
| 482 | properties, |
| 483 | MM_MODEM_MODEMCDMA_PROPERTY_SID, |
| 484 | &uint_value)) { |
| 485 | sid = uint_value; |
| 486 | registration_changed = true; |
| 487 | } |
| 488 | if (DBusProperties::GetUint32( |
| 489 | properties, |
| 490 | MM_MODEM_MODEMCDMA_PROPERTY_NID, |
| 491 | &uint_value)) { |
| 492 | nid = uint_value; |
| 493 | registration_changed = true; |
| 494 | } |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 495 | if (DBusProperties::GetUint32( |
| 496 | properties, |
| 497 | MM_MODEM_MODEMCDMA_PROPERTY_ACTIVATIONSTATE, |
| 498 | &uint_value)) { |
| 499 | activation_state_ = static_cast<MMModemCdmaActivationState>(uint_value); |
| 500 | HandleNewActivationStatus(MM_CDMA_ACTIVATION_ERROR_NONE); |
| 501 | } |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 502 | if (registration_changed) |
| 503 | OnCDMARegistrationChanged(state_1x, state_evdo, sid, nid); |
| 504 | } |
| 505 | |
| 506 | void CellularCapabilityUniversalCDMA::OnCDMARegistrationChanged( |
| 507 | MMModemCdmaRegistrationState state_1x, |
| 508 | MMModemCdmaRegistrationState state_evdo, |
| 509 | uint32_t sid, uint32_t nid) { |
| 510 | SLOG(Cellular, 2) << __func__ |
| 511 | << ": state_1x=" << state_1x |
| 512 | << ", state_evdo=" << state_evdo; |
| 513 | cdma_1x_registration_state_ = state_1x; |
| 514 | cdma_evdo_registration_state_ = state_evdo; |
| 515 | sid_ = sid; |
| 516 | nid_ = nid; |
Prathmesh Prabhu | 8599e05 | 2014-04-25 14:20:22 -0700 | [diff] [blame] | 517 | cellular()->serving_operator_info()->UpdateSID(UintToString(sid)); |
| 518 | cellular()->serving_operator_info()->UpdateNID(UintToString(nid)); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 519 | cellular()->HandleNewRegistrationState(); |
| 520 | } |
| 521 | |
| 522 | } // namespace shill |