Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 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_cdma.h" |
| 6 | |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 7 | #include <string> |
| 8 | #include <vector> |
| 9 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 10 | #include <base/bind.h> |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 11 | #include <base/stringprintf.h> |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 12 | #include <chromeos/dbus/service_constants.h> |
| 13 | #include <mm/mm-modem.h> |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 14 | |
| 15 | #include "shill/cellular.h" |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 16 | #include "shill/cellular_service.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 17 | #include "shill/logging.h" |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 18 | #include "shill/proxy_factory.h" |
| 19 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 20 | using base::Bind; |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 21 | using std::string; |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 22 | using std::vector; |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 23 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 24 | namespace shill { |
| 25 | |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 26 | // static |
| 27 | unsigned int CellularCapabilityCDMA::friendly_service_name_id_ = 0; |
| 28 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 29 | const char CellularCapabilityCDMA::kPhoneNumber[] = "#777"; |
| 30 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 31 | CellularCapabilityCDMA::CellularCapabilityCDMA(Cellular *cellular, |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 32 | ProxyFactory *proxy_factory, |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 33 | ModemInfo *modem_info) |
| 34 | : CellularCapabilityClassic(cellular, proxy_factory, modem_info), |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 35 | weak_ptr_factory_(this), |
Christopher Wiley | 1582bdd | 2012-11-15 11:31:14 -0800 | [diff] [blame] | 36 | activation_starting_(false), |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 37 | activation_state_(MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED), |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 38 | registration_state_evdo_(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN), |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 39 | registration_state_1x_(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN), |
| 40 | prl_version_(0) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 41 | SLOG(Cellular, 2) << "Cellular capability constructed: CDMA"; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 42 | PropertyStore *store = cellular->mutable_store(); |
| 43 | store->RegisterConstUint16(flimflam::kPRLVersionProperty, &prl_version_); |
| 44 | } |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 45 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 46 | void CellularCapabilityCDMA::InitProxies() { |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 47 | CellularCapabilityClassic::InitProxies(); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 48 | proxy_.reset(proxy_factory()->CreateModemCDMAProxy( |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 49 | cellular()->dbus_path(), cellular()->dbus_owner())); |
| 50 | proxy_->set_signal_quality_callback( |
| 51 | Bind(&CellularCapabilityCDMA::OnSignalQualitySignal, |
| 52 | weak_ptr_factory_.GetWeakPtr())); |
| 53 | proxy_->set_activation_state_callback( |
| 54 | Bind(&CellularCapabilityCDMA::OnActivationStateChangedSignal, |
| 55 | weak_ptr_factory_.GetWeakPtr())); |
| 56 | proxy_->set_registration_state_callback( |
| 57 | Bind(&CellularCapabilityCDMA::OnRegistrationStateChangedSignal, |
| 58 | weak_ptr_factory_.GetWeakPtr())); |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 59 | } |
| 60 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 61 | void CellularCapabilityCDMA::StartModem(Error *error, |
| 62 | const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 63 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 64 | InitProxies(); |
| 65 | |
| 66 | CellularTaskList *tasks = new CellularTaskList(); |
| 67 | ResultCallback cb = |
| 68 | Bind(&CellularCapabilityCDMA::StepCompletedCallback, |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 69 | weak_ptr_factory_.GetWeakPtr(), callback, false, tasks); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 70 | if (!cellular()->IsUnderlyingDeviceEnabled()) |
| 71 | tasks->push_back(Bind(&CellularCapabilityCDMA::EnableModem, |
| 72 | weak_ptr_factory_.GetWeakPtr(), cb)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 73 | tasks->push_back(Bind(&CellularCapabilityCDMA::GetModemStatus, |
| 74 | weak_ptr_factory_.GetWeakPtr(), cb)); |
| 75 | tasks->push_back(Bind(&CellularCapabilityCDMA::GetMEID, |
| 76 | weak_ptr_factory_.GetWeakPtr(), cb)); |
| 77 | tasks->push_back(Bind(&CellularCapabilityCDMA::GetModemInfo, |
| 78 | weak_ptr_factory_.GetWeakPtr(), cb)); |
| 79 | tasks->push_back(Bind(&CellularCapabilityCDMA::FinishEnable, |
| 80 | weak_ptr_factory_.GetWeakPtr(), cb)); |
| 81 | |
| 82 | RunNextStep(tasks); |
| 83 | } |
| 84 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 85 | void CellularCapabilityCDMA::ReleaseProxies() { |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 86 | CellularCapabilityClassic::ReleaseProxies(); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 87 | proxy_.reset(); |
| 88 | } |
| 89 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 90 | bool CellularCapabilityCDMA::AllowRoaming() { |
| 91 | return allow_roaming_property(); |
| 92 | } |
| 93 | |
| 94 | |
Darin Petkov | 5f316f6 | 2011-11-18 12:10:26 +0100 | [diff] [blame] | 95 | void CellularCapabilityCDMA::OnServiceCreated() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 96 | SLOG(Cellular, 2) << __func__; |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 97 | cellular()->service()->SetOLP(olp_); |
| 98 | cellular()->service()->SetUsageURL(usage_url_); |
Darin Petkov | 5f316f6 | 2011-11-18 12:10:26 +0100 | [diff] [blame] | 99 | UpdateServingOperator(); |
| 100 | HandleNewActivationState(MM_MODEM_CDMA_ACTIVATION_ERROR_NO_ERROR); |
| 101 | } |
| 102 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 103 | void CellularCapabilityCDMA::UpdateStatus(const DBusPropertiesMap &properties) { |
| 104 | string carrier; |
| 105 | if (DBusProperties::GetString(properties, "carrier", &carrier)) { |
| 106 | Cellular::Operator oper; |
| 107 | oper.SetName(carrier); |
| 108 | oper.SetCountry("us"); |
| 109 | cellular()->set_home_provider(oper); |
| 110 | } |
| 111 | DBusProperties::GetUint32( |
| 112 | properties, "activation_state", &activation_state_); |
| 113 | DBusProperties::GetUint16(properties, "prl_version", &prl_version_); |
Darin Petkov | 5f316f6 | 2011-11-18 12:10:26 +0100 | [diff] [blame] | 114 | // TODO(petkov): For now, get the payment and usage URLs from ModemManager to |
| 115 | // match flimflam. In the future, get these from an alternative source (e.g., |
| 116 | // database, carrier-specific properties, etc.). |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 117 | string payment; |
| 118 | if (DBusProperties::GetString(properties, "payment_url", &payment)) { |
| 119 | olp_.SetURL(payment); |
| 120 | } |
| 121 | if (DBusProperties::GetString(properties, "payment_url_method", &payment)) { |
| 122 | olp_.SetMethod(payment); |
| 123 | } |
| 124 | if (DBusProperties::GetString(properties, "payment_url_postdata", &payment)) { |
| 125 | olp_.SetPostData(payment); |
| 126 | } |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 127 | DBusProperties::GetString(properties, "usage_url", &usage_url_); |
| 128 | } |
| 129 | |
| 130 | void CellularCapabilityCDMA::SetupConnectProperties( |
| 131 | DBusPropertiesMap *properties) { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 132 | (*properties)[kConnectPropertyPhoneNumber].writer().append_string( |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 133 | kPhoneNumber); |
| 134 | } |
| 135 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 136 | void CellularCapabilityCDMA::Activate(const string &carrier, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 137 | Error *error, |
| 138 | const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 139 | SLOG(Cellular, 2) << __func__ << "(" << carrier << ")"; |
Christopher Wiley | 1582bdd | 2012-11-15 11:31:14 -0800 | [diff] [blame] | 140 | // We're going to trigger something which leads to an activation. |
| 141 | activation_starting_ = true; |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 142 | if (cellular()->state() == Cellular::kStateEnabled || |
| 143 | cellular()->state() == Cellular::kStateRegistered) { |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 144 | ActivationResultCallback activation_callback = |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 145 | Bind(&CellularCapabilityCDMA::OnActivateReply, |
| 146 | weak_ptr_factory_.GetWeakPtr(), |
| 147 | callback); |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 148 | proxy_->Activate(carrier, error, activation_callback, kTimeoutActivate); |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 149 | } else if (cellular()->state() == Cellular::kStateConnected || |
| 150 | cellular()->state() == Cellular::kStateLinked) { |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 151 | pending_activation_callback_ = callback; |
| 152 | pending_activation_carrier_ = carrier; |
| 153 | cellular()->Disconnect(error); |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 154 | } else { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 155 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 156 | "Unable to activate in " + |
| 157 | Cellular::GetStateString(cellular()->state())); |
Christopher Wiley | 1582bdd | 2012-11-15 11:31:14 -0800 | [diff] [blame] | 158 | activation_starting_ = false; |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 159 | } |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | void CellularCapabilityCDMA::HandleNewActivationState(uint32 error) { |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 163 | SLOG(Cellular, 2) << __func__ << "(" << error << ")"; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 164 | if (!cellular()->service().get()) { |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 165 | LOG(ERROR) << "In " << __func__ << "(): service is null."; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 166 | return; |
| 167 | } |
Darin Petkov | b9c9933 | 2012-01-12 13:13:00 +0100 | [diff] [blame] | 168 | cellular()->service()->SetActivationState( |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 169 | GetActivationStateString(activation_state_)); |
| 170 | cellular()->service()->set_error(GetActivationErrorString(error)); |
| 171 | } |
| 172 | |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 173 | void CellularCapabilityCDMA::DisconnectCleanup() { |
| 174 | CellularCapabilityClassic::DisconnectCleanup(); |
| 175 | if (pending_activation_callback_.is_null()) { |
| 176 | return; |
| 177 | } |
| 178 | if (cellular()->state() == Cellular::kStateEnabled || |
| 179 | cellular()->state() == Cellular::kStateRegistered) { |
| 180 | Error ignored_error; |
| 181 | Activate(pending_activation_carrier_, |
| 182 | &ignored_error, |
| 183 | pending_activation_callback_); |
| 184 | } else { |
| 185 | Error error; |
| 186 | Error::PopulateAndLog( |
| 187 | &error, |
| 188 | Error::kOperationFailed, |
| 189 | "Tried to disconnect before activating cellular service and failed"); |
| 190 | HandleNewActivationState(MM_MODEM_CDMA_ACTIVATION_ERROR_UNKNOWN); |
| 191 | activation_starting_ = false; |
| 192 | pending_activation_callback_.Run(error); |
| 193 | } |
| 194 | pending_activation_callback_.Reset(); |
| 195 | pending_activation_carrier_.clear(); |
| 196 | } |
| 197 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 198 | // static |
| 199 | string CellularCapabilityCDMA::GetActivationStateString(uint32 state) { |
| 200 | switch (state) { |
| 201 | case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED: |
| 202 | return flimflam::kActivationStateActivated; |
| 203 | case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING: |
| 204 | return flimflam::kActivationStateActivating; |
| 205 | case MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED: |
| 206 | return flimflam::kActivationStateNotActivated; |
| 207 | case MM_MODEM_CDMA_ACTIVATION_STATE_PARTIALLY_ACTIVATED: |
| 208 | return flimflam::kActivationStatePartiallyActivated; |
| 209 | default: |
| 210 | return flimflam::kActivationStateUnknown; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | // static |
| 215 | string CellularCapabilityCDMA::GetActivationErrorString(uint32 error) { |
| 216 | switch (error) { |
| 217 | case MM_MODEM_CDMA_ACTIVATION_ERROR_WRONG_RADIO_INTERFACE: |
| 218 | return flimflam::kErrorNeedEvdo; |
| 219 | case MM_MODEM_CDMA_ACTIVATION_ERROR_ROAMING: |
| 220 | return flimflam::kErrorNeedHomeNetwork; |
| 221 | case MM_MODEM_CDMA_ACTIVATION_ERROR_COULD_NOT_CONNECT: |
| 222 | case MM_MODEM_CDMA_ACTIVATION_ERROR_SECURITY_AUTHENTICATION_FAILED: |
| 223 | case MM_MODEM_CDMA_ACTIVATION_ERROR_PROVISIONING_FAILED: |
| 224 | return flimflam::kErrorOtaspFailed; |
| 225 | case MM_MODEM_CDMA_ACTIVATION_ERROR_NO_ERROR: |
| 226 | return ""; |
| 227 | case MM_MODEM_CDMA_ACTIVATION_ERROR_NO_SIGNAL: |
| 228 | default: |
| 229 | return flimflam::kErrorActivationFailed; |
| 230 | } |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 231 | } |
| 232 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 233 | void CellularCapabilityCDMA::GetMEID(const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 234 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 235 | if (meid_.empty()) { |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 236 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 237 | meid_ = proxy_->MEID(); |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 238 | SLOG(Cellular, 2) << "MEID: " << meid_; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 239 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 240 | callback.Run(Error()); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 241 | } |
| 242 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 243 | void CellularCapabilityCDMA::GetProperties(const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 244 | SLOG(Cellular, 2) << __func__; |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 245 | // No properties. |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 246 | callback.Run(Error()); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 247 | } |
| 248 | |
Christopher Wiley | 1582bdd | 2012-11-15 11:31:14 -0800 | [diff] [blame] | 249 | bool CellularCapabilityCDMA::IsActivating() const { |
| 250 | return activation_starting_ || |
| 251 | activation_state_ == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING; |
| 252 | } |
| 253 | |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 254 | bool CellularCapabilityCDMA::IsRegistered() { |
| 255 | return registration_state_evdo_ != MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN || |
| 256 | registration_state_1x_ != MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; |
| 257 | } |
| 258 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 259 | void CellularCapabilityCDMA::SetUnregistered(bool searching) { |
| 260 | registration_state_evdo_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; |
| 261 | registration_state_1x_ = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; |
| 262 | } |
| 263 | |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 264 | string CellularCapabilityCDMA::GetNetworkTechnologyString() const { |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 265 | if (registration_state_evdo_ != MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN) { |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 266 | return flimflam::kNetworkTechnologyEvdo; |
| 267 | } |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 268 | if (registration_state_1x_ != MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN) { |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 269 | return flimflam::kNetworkTechnology1Xrtt; |
| 270 | } |
| 271 | return ""; |
| 272 | } |
| 273 | |
| 274 | string CellularCapabilityCDMA::GetRoamingStateString() const { |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 275 | uint32 state = registration_state_evdo_; |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 276 | if (state == MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN) { |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 277 | state = registration_state_1x_; |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 278 | } |
| 279 | switch (state) { |
| 280 | case MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN: |
| 281 | case MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED: |
| 282 | break; |
| 283 | case MM_MODEM_CDMA_REGISTRATION_STATE_HOME: |
| 284 | return flimflam::kRoamingStateHome; |
| 285 | case MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING: |
| 286 | return flimflam::kRoamingStateRoaming; |
| 287 | default: |
| 288 | NOTREACHED(); |
| 289 | } |
| 290 | return flimflam::kRoamingStateUnknown; |
| 291 | } |
| 292 | |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 293 | void CellularCapabilityCDMA::GetSignalQuality() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 294 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 295 | SignalQualityCallback callback = |
| 296 | Bind(&CellularCapabilityCDMA::OnGetSignalQualityReply, |
| 297 | weak_ptr_factory_.GetWeakPtr()); |
| 298 | proxy_->GetSignalQuality(NULL, callback, kTimeoutDefault); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 299 | } |
| 300 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 301 | void CellularCapabilityCDMA::GetRegistrationState() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 302 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 303 | RegistrationStateCallback callback = |
| 304 | Bind(&CellularCapabilityCDMA::OnGetRegistrationStateReply, |
| 305 | weak_ptr_factory_.GetWeakPtr()); |
| 306 | proxy_->GetRegistrationState(NULL, callback, kTimeoutDefault); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 307 | } |
| 308 | |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 309 | string CellularCapabilityCDMA::CreateFriendlyServiceName() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 310 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 311 | if (!carrier_.empty()) { |
| 312 | return carrier_; |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 313 | } |
| 314 | return base::StringPrintf("CDMANetwork%u", friendly_service_name_id_++); |
| 315 | } |
| 316 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 317 | void CellularCapabilityCDMA::UpdateServingOperator() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 318 | SLOG(Cellular, 2) << __func__; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 319 | if (cellular()->service().get()) { |
Darin Petkov | 9cb0268 | 2012-01-28 00:17:38 +0100 | [diff] [blame] | 320 | cellular()->service()->SetServingOperator(cellular()->home_provider()); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 324 | void CellularCapabilityCDMA::OnActivateReply( |
| 325 | const ResultCallback &callback, uint32 status, const Error &error) { |
Christopher Wiley | 1582bdd | 2012-11-15 11:31:14 -0800 | [diff] [blame] | 326 | activation_starting_ = false; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 327 | if (error.IsSuccess()) { |
| 328 | if (status == MM_MODEM_CDMA_ACTIVATION_ERROR_NO_ERROR) { |
| 329 | activation_state_ = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING; |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 330 | } else { |
| 331 | LOG(WARNING) << "Modem activation failed with status: " |
| 332 | << GetActivationErrorString(status) << " (" << status << ")"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 333 | } |
| 334 | HandleNewActivationState(status); |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 335 | } else { |
| 336 | LOG(ERROR) << "Activate() failed with error: " << error; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 337 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 338 | callback.Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 339 | } |
| 340 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 341 | void CellularCapabilityCDMA::OnGetRegistrationStateReply( |
| 342 | uint32 state_1x, uint32 state_evdo, const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 343 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 344 | if (error.IsSuccess()) |
| 345 | OnRegistrationStateChangedSignal(state_1x, state_evdo); |
| 346 | } |
| 347 | |
| 348 | void CellularCapabilityCDMA::OnGetSignalQualityReply(uint32 quality, |
| 349 | const Error &error) { |
| 350 | if (error.IsSuccess()) |
| 351 | OnSignalQualitySignal(quality); |
| 352 | } |
| 353 | |
| 354 | void CellularCapabilityCDMA::OnActivationStateChangedSignal( |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 355 | uint32 activation_state, |
| 356 | uint32 activation_error, |
| 357 | const DBusPropertiesMap &status_changes) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 358 | SLOG(Cellular, 2) << __func__; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 359 | DBusProperties::GetString(status_changes, "mdn", &mdn_); |
| 360 | DBusProperties::GetString(status_changes, "min", &min_); |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 361 | string payment; |
| 362 | if (DBusProperties::GetString(status_changes, "payment_url", &payment)) { |
| 363 | olp_.SetURL(payment); |
| 364 | } |
| 365 | if (DBusProperties::GetString( |
| 366 | status_changes, "payment_url_method", &payment)) { |
| 367 | olp_.SetMethod(payment); |
| 368 | } |
| 369 | if (DBusProperties::GetString( |
| 370 | status_changes, "payment_url_postdata", &payment)) { |
| 371 | olp_.SetPostData(payment); |
| 372 | } |
| 373 | if (cellular()->service().get()) { |
| 374 | cellular()->service()->SetOLP(olp_); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 375 | } |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 376 | activation_state_ = activation_state; |
| 377 | HandleNewActivationState(activation_error); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 378 | } |
| 379 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 380 | void CellularCapabilityCDMA::OnRegistrationStateChangedSignal( |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 381 | uint32 state_1x, uint32 state_evdo) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 382 | SLOG(Cellular, 2) << __func__; |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 383 | registration_state_1x_ = state_1x; |
| 384 | registration_state_evdo_ = state_evdo; |
| 385 | cellular()->HandleNewRegistrationState(); |
| 386 | } |
| 387 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 388 | void CellularCapabilityCDMA::OnSignalQualitySignal(uint32 strength) { |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 389 | cellular()->HandleNewSignalQuality(strength); |
| 390 | } |
| 391 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 392 | } // namespace shill |