Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 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.h" |
| 6 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 7 | #include <netinet/in.h> |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 8 | #include <linux/if.h> // Needs definitions from netinet/in.h |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 9 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 10 | #include <string> |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 11 | #include <utility> |
| 12 | #include <vector> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 13 | |
| 14 | #include <base/logging.h> |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 15 | #include <base/stringprintf.h> |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 16 | #include <chromeos/dbus/service_constants.h> |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 17 | #include <mm/mm-modem.h> |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 18 | #include <mobile_provider.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 19 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 20 | #include "shill/cellular_capability_cdma.h" |
| 21 | #include "shill/cellular_capability_gsm.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 22 | #include "shill/cellular_service.h" |
| 23 | #include "shill/control_interface.h" |
| 24 | #include "shill/device.h" |
| 25 | #include "shill/device_info.h" |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 26 | #include "shill/error.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 27 | #include "shill/event_dispatcher.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 28 | #include "shill/manager.h" |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 29 | #include "shill/modem_simple_proxy_interface.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 30 | #include "shill/profile.h" |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 31 | #include "shill/property_accessor.h" |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 32 | #include "shill/proxy_factory.h" |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 33 | #include "shill/rtnl_handler.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 34 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 35 | using std::make_pair; |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 36 | using std::map; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 37 | using std::string; |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 38 | using std::vector; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 39 | |
| 40 | namespace shill { |
| 41 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 42 | const char Cellular::kConnectPropertyPhoneNumber[] = "number"; |
| 43 | const char Cellular::kPhoneNumberCDMA[] = "#777"; |
| 44 | const char Cellular::kPhoneNumberGSM[] = "*99#"; |
| 45 | |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 46 | Cellular::Operator::Operator() { |
| 47 | SetName(""); |
| 48 | SetCode(""); |
| 49 | SetCountry(""); |
| 50 | } |
| 51 | |
| 52 | Cellular::Operator::~Operator() {} |
| 53 | |
| 54 | void Cellular::Operator::CopyFrom(const Operator &oper) { |
| 55 | dict_ = oper.dict_; |
| 56 | } |
| 57 | |
| 58 | const string &Cellular::Operator::GetName() const { |
| 59 | return dict_.find(flimflam::kOperatorNameKey)->second; |
| 60 | } |
| 61 | |
| 62 | void Cellular::Operator::SetName(const string &name) { |
| 63 | dict_[flimflam::kOperatorNameKey] = name; |
| 64 | } |
| 65 | |
| 66 | const string &Cellular::Operator::GetCode() const { |
| 67 | return dict_.find(flimflam::kOperatorCodeKey)->second; |
| 68 | } |
| 69 | |
| 70 | void Cellular::Operator::SetCode(const string &code) { |
| 71 | dict_[flimflam::kOperatorCodeKey] = code; |
| 72 | } |
| 73 | |
| 74 | const string &Cellular::Operator::GetCountry() const { |
| 75 | return dict_.find(flimflam::kOperatorCountryKey)->second; |
| 76 | } |
| 77 | |
| 78 | void Cellular::Operator::SetCountry(const string &country) { |
| 79 | dict_[flimflam::kOperatorCountryKey] = country; |
| 80 | } |
| 81 | |
| 82 | const Stringmap &Cellular::Operator::ToDict() const { |
| 83 | return dict_; |
| 84 | } |
| 85 | |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 86 | Cellular::CDMA::CDMA() |
| 87 | : registration_state_evdo(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN), |
| 88 | registration_state_1x(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN), |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 89 | activation_state(MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED), |
| 90 | prl_version(0) {} |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 91 | |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 92 | Cellular::GSM::GSM() |
| 93 | : registration_state(MM_MODEM_GSM_NETWORK_REG_STATUS_UNKNOWN), |
| 94 | access_technology(MM_MODEM_GSM_ACCESS_TECH_UNKNOWN) {} |
| 95 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 96 | Cellular::Cellular(ControlInterface *control_interface, |
| 97 | EventDispatcher *dispatcher, |
| 98 | Manager *manager, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 99 | const string &link_name, |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 100 | const string &address, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 101 | int interface_index, |
| 102 | Type type, |
| 103 | const string &owner, |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 104 | const string &path, |
| 105 | mobile_provider_db *provider_db) |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 106 | : Device(control_interface, |
| 107 | dispatcher, |
| 108 | manager, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 109 | link_name, |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 110 | address, |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 111 | interface_index), |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 112 | proxy_factory_(ProxyFactory::GetInstance()), |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 113 | type_(type), |
| 114 | state_(kStateDisabled), |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 115 | modem_state_(kModemStateUnknown), |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 116 | dbus_owner_(owner), |
| 117 | dbus_path_(path), |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 118 | provider_db_(provider_db), |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 119 | task_factory_(this), |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame^] | 120 | allow_roaming_(false) { |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 121 | PropertyStore *store = this->mutable_store(); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 122 | store->RegisterConstString(flimflam::kCarrierProperty, &carrier_); |
| 123 | store->RegisterConstString(flimflam::kDBusConnectionProperty, &dbus_owner_); |
| 124 | store->RegisterConstString(flimflam::kDBusObjectProperty, &dbus_path_); |
| 125 | store->RegisterBool(flimflam::kCellularAllowRoamingProperty, &allow_roaming_); |
| 126 | store->RegisterConstString(flimflam::kEsnProperty, &esn_); |
| 127 | store->RegisterConstString(flimflam::kFirmwareRevisionProperty, |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 128 | &firmware_revision_); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 129 | store->RegisterConstString(flimflam::kHardwareRevisionProperty, |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 130 | &hardware_revision_); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 131 | store->RegisterConstStringmap(flimflam::kHomeProviderProperty, |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 132 | &home_provider_.ToDict()); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 133 | store->RegisterConstString(flimflam::kImeiProperty, &imei_); |
| 134 | store->RegisterConstString(flimflam::kImsiProperty, &imsi_); |
| 135 | store->RegisterConstString(flimflam::kManufacturerProperty, &manufacturer_); |
| 136 | store->RegisterConstString(flimflam::kMdnProperty, &mdn_); |
| 137 | store->RegisterConstString(flimflam::kMeidProperty, &meid_); |
| 138 | store->RegisterConstString(flimflam::kMinProperty, &min_); |
| 139 | store->RegisterConstString(flimflam::kModelIDProperty, &model_id_); |
| 140 | store->RegisterConstUint16(flimflam::kPRLVersionProperty, &cdma_.prl_version); |
| 141 | store->RegisterConstString(flimflam::kSelectedNetworkProperty, |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 142 | &selected_network_); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 143 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 144 | HelpRegisterDerivedStrIntPair(flimflam::kSIMLockStatusProperty, |
| 145 | &Cellular::SimLockStatusToProperty, |
| 146 | NULL); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 147 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 148 | VLOG(2) << "Cellular device " << this->link_name() << " initialized: " |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 149 | << GetTypeString(); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 152 | Cellular::~Cellular() {} |
| 153 | |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 154 | string Cellular::GetTypeString() const { |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 155 | switch (type_) { |
| 156 | case kTypeGSM: return "CellularTypeGSM"; |
| 157 | case kTypeCDMA: return "CellularTypeCDMA"; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 158 | default: NOTREACHED(); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 159 | } |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 160 | return StringPrintf("CellularTypeUnknown-%d", type_); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 163 | // static |
| 164 | string Cellular::GetStateString(State state) { |
| 165 | switch (state) { |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 166 | case kStateDisabled: return "CellularStateDisabled"; |
| 167 | case kStateEnabled: return "CellularStateEnabled"; |
| 168 | case kStateRegistered: return "CellularStateRegistered"; |
| 169 | case kStateConnected: return "CellularStateConnected"; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 170 | case kStateLinked: return "CellularStateLinked"; |
| 171 | default: NOTREACHED(); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 172 | } |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 173 | return StringPrintf("CellularStateUnknown-%d", state); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 176 | // static |
| 177 | string Cellular::GetCDMAActivationStateString(uint32 state) { |
| 178 | switch (state) { |
| 179 | case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED: |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 180 | return flimflam::kActivationStateActivated; |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 181 | case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING: |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 182 | return flimflam::kActivationStateActivating; |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 183 | case MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED: |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 184 | return flimflam::kActivationStateNotActivated; |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 185 | case MM_MODEM_CDMA_ACTIVATION_STATE_PARTIALLY_ACTIVATED: |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 186 | return flimflam::kActivationStatePartiallyActivated; |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 187 | default: |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 188 | return flimflam::kActivationStateUnknown; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | // static |
| 193 | string Cellular::GetCDMAActivationErrorString(uint32 error) { |
| 194 | switch (error) { |
| 195 | case MM_MODEM_CDMA_ACTIVATION_ERROR_WRONG_RADIO_INTERFACE: |
| 196 | return flimflam::kErrorNeedEvdo; |
| 197 | case MM_MODEM_CDMA_ACTIVATION_ERROR_ROAMING: |
| 198 | return flimflam::kErrorNeedHomeNetwork; |
| 199 | case MM_MODEM_CDMA_ACTIVATION_ERROR_COULD_NOT_CONNECT: |
| 200 | case MM_MODEM_CDMA_ACTIVATION_ERROR_SECURITY_AUTHENTICATION_FAILED: |
| 201 | case MM_MODEM_CDMA_ACTIVATION_ERROR_PROVISIONING_FAILED: |
| 202 | return flimflam::kErrorOtaspFailed; |
| 203 | case MM_MODEM_CDMA_ACTIVATION_ERROR_NO_ERROR: |
| 204 | return ""; |
| 205 | case MM_MODEM_CDMA_ACTIVATION_ERROR_NO_SIGNAL: |
| 206 | default: |
| 207 | return flimflam::kErrorActivationFailed; |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 211 | void Cellular::SetState(State state) { |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 212 | VLOG(2) << GetStateString(state_) << " -> " << GetStateString(state); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 213 | state_ = state; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | void Cellular::Start() { |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 217 | LOG(INFO) << __func__ << ": " << GetStateString(state_); |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 218 | Device::Start(); |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 219 | InitCapability(); // For now, only a single capability is supported. |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 220 | InitProxies(); |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 221 | EnableModem(); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 222 | if (type_ == kTypeGSM) { |
| 223 | RegisterGSMModem(); |
| 224 | } |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 225 | GetModemStatus(); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 226 | capability_->GetIdentifiers(); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 227 | if (type_ == kTypeGSM) { |
| 228 | GetGSMProperties(); |
| 229 | } |
| 230 | GetModemInfo(); |
| 231 | GetModemRegistrationState(); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | void Cellular::Stop() { |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 235 | capability_.reset(); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 236 | proxy_.reset(); |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 237 | simple_proxy_.reset(); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 238 | cdma_proxy_.reset(); |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 239 | gsm_network_proxy_.reset(); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 240 | manager()->DeregisterService(service_); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 241 | service_ = NULL; // Breaks a reference cycle. |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 242 | SetState(kStateDisabled); |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 243 | Device::Stop(); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 246 | void Cellular::InitCapability() { |
| 247 | VLOG(2) << __func__; |
| 248 | switch (type_) { |
| 249 | case kTypeGSM: |
| 250 | capability_.reset(new CellularCapabilityGSM(this)); |
| 251 | break; |
| 252 | case kTypeCDMA: |
| 253 | capability_.reset(new CellularCapabilityCDMA(this)); |
| 254 | break; |
| 255 | default: NOTREACHED(); |
| 256 | } |
| 257 | } |
| 258 | |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 259 | void Cellular::InitProxies() { |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 260 | VLOG(2) << __func__; |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 261 | proxy_.reset(proxy_factory_->CreateModemProxy(this, dbus_path_, dbus_owner_)); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 262 | simple_proxy_.reset( |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 263 | proxy_factory_->CreateModemSimpleProxy(dbus_path_, dbus_owner_)); |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 264 | capability_->InitProxies(); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 267 | void Cellular::EnableModem() { |
| 268 | CHECK_EQ(kStateDisabled, state_); |
| 269 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 270 | proxy_->Enable(true); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 271 | SetState(kStateEnabled); |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | void Cellular::GetModemStatus() { |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 275 | CHECK_EQ(kStateEnabled, state_); |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 276 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 277 | DBusPropertiesMap properties = simple_proxy_->GetStatus(); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 278 | if (DBusProperties::GetString(properties, "carrier", &carrier_) && |
| 279 | type_ == kTypeCDMA) { |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 280 | home_provider_.SetName(carrier_); |
| 281 | home_provider_.SetCode(""); |
| 282 | home_provider_.SetCountry("us"); |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 283 | } |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 284 | DBusProperties::GetString(properties, "meid", &meid_); |
| 285 | DBusProperties::GetString(properties, "imei", &imei_); |
| 286 | if (DBusProperties::GetString(properties, "imsi", &imsi_) && |
| 287 | type_ == kTypeGSM) { |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 288 | // TODO(petkov): Set GSM provider based on IMSI and SPN. |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 289 | } |
| 290 | DBusProperties::GetString(properties, "esn", &esn_); |
| 291 | DBusProperties::GetString(properties, "mdn", &mdn_); |
| 292 | DBusProperties::GetString(properties, "min", &min_); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 293 | DBusProperties::GetString( |
| 294 | properties, "firmware_revision", &firmware_revision_); |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 295 | |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 296 | uint32 state = 0; |
| 297 | if (DBusProperties::GetUint32(properties, "state", &state)) { |
| 298 | modem_state_ = static_cast<ModemState>(state); |
| 299 | } |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 300 | |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 301 | if (type_ == kTypeCDMA) { |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 302 | DBusProperties::GetUint32( |
| 303 | properties, "activation_state", &cdma_.activation_state); |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 304 | DBusProperties::GetUint16(properties, "prl_version", &cdma_.prl_version); |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 305 | // TODO(petkov): For now, get the payment and usage URLs from ModemManager |
| 306 | // to match flimflam. In the future, provide a plugin API to get these |
| 307 | // directly from the modem driver. |
| 308 | DBusProperties::GetString(properties, "payment_url", &cdma_.payment_url); |
| 309 | DBusProperties::GetString(properties, "usage_url", &cdma_.usage_url); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 313 | void Cellular::GetGSMProperties() { |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 314 | CHECK_EQ(kTypeGSM, type_); |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 315 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 316 | gsm_.access_technology = gsm_network_proxy_->AccessTechnology(); |
| 317 | VLOG(2) << "GSM AccessTechnology: " << gsm_.access_technology; |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | void Cellular::RegisterGSMModem() { |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 321 | CHECK_EQ(kTypeGSM, type_); |
Darin Petkov | 9ae310f | 2011-08-30 15:41:13 -0700 | [diff] [blame] | 322 | LOG(INFO) << "Registering on \"" << selected_network_ << "\""; |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 323 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 324 | gsm_network_proxy_->Register(selected_network_); |
Darin Petkov | 9ae310f | 2011-08-30 15:41:13 -0700 | [diff] [blame] | 325 | // TODO(petkov): Handle registration failure including trying the home network |
| 326 | // when selected_network_ is not empty. |
| 327 | } |
| 328 | |
| 329 | void Cellular::RegisterOnNetwork(const string &network_id, Error *error) { |
| 330 | LOG(INFO) << __func__ << "(" << network_id << ")"; |
| 331 | if (type_ != kTypeGSM) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 332 | Error::PopulateAndLog(error, Error::kNotSupported, |
| 333 | "Network registration supported only for GSM."); |
Darin Petkov | 9ae310f | 2011-08-30 15:41:13 -0700 | [diff] [blame] | 334 | return; |
| 335 | } |
| 336 | // Defer registration because we may be in a dbus-c++ callback. |
| 337 | dispatcher()->PostTask( |
| 338 | task_factory_.NewRunnableMethod(&Cellular::RegisterOnNetworkTask, |
| 339 | network_id)); |
| 340 | } |
| 341 | |
| 342 | void Cellular::RegisterOnNetworkTask(const string &network_id) { |
| 343 | LOG(INFO) << __func__ << "(" << network_id << ")"; |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 344 | CHECK_EQ(kTypeGSM, type_); |
Darin Petkov | 9ae310f | 2011-08-30 15:41:13 -0700 | [diff] [blame] | 345 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 346 | gsm_network_proxy_->Register(network_id); |
| 347 | // TODO(petkov): Handle registration failure. |
| 348 | selected_network_ = network_id; |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 351 | void Cellular::RequirePIN(const string &pin, bool require, Error *error) { |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 352 | capability_->RequirePIN(pin, require, error); |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | void Cellular::EnterPIN(const string &pin, Error *error) { |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 356 | capability_->EnterPIN(pin, error); |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 359 | void Cellular::UnblockPIN( |
| 360 | const string &unblock_code, const string &pin, Error *error) { |
| 361 | capability_->UnblockPIN(unblock_code, pin, error); |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 364 | void Cellular::ChangePIN( |
| 365 | const string &old_pin, const string &new_pin, Error *error) { |
| 366 | capability_->ChangePIN(old_pin, new_pin, error); |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame^] | 369 | void Cellular::Scan(Error *error) { |
| 370 | capability_->Scan(error); |
| 371 | } |
| 372 | |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 373 | void Cellular::GetModemInfo() { |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 374 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 375 | ModemProxyInterface::Info info = proxy_->GetInfo(); |
| 376 | manufacturer_ = info._1; |
| 377 | model_id_ = info._2; |
| 378 | hardware_revision_ = info._3; |
| 379 | VLOG(2) << "ModemInfo: " << manufacturer_ << ", " << model_id_ << ", " |
| 380 | << hardware_revision_; |
| 381 | } |
| 382 | |
| 383 | void Cellular::GetModemRegistrationState() { |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 384 | switch (type_) { |
| 385 | case kTypeGSM: |
| 386 | GetGSMRegistrationState(); |
| 387 | break; |
| 388 | case kTypeCDMA: |
| 389 | GetCDMARegistrationState(); |
| 390 | break; |
| 391 | default: NOTREACHED(); |
| 392 | } |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 393 | HandleNewRegistrationState(); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | void Cellular::GetCDMARegistrationState() { |
| 397 | CHECK_EQ(kTypeCDMA, type_); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 398 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 399 | cdma_proxy_->GetRegistrationState(&cdma_.registration_state_1x, |
| 400 | &cdma_.registration_state_evdo); |
| 401 | VLOG(2) << "CDMA Registration: 1x(" << cdma_.registration_state_1x |
| 402 | << ") EVDO(" << cdma_.registration_state_evdo << ")"; |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | void Cellular::GetGSMRegistrationState() { |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 406 | CHECK_EQ(kTypeGSM, type_); |
| 407 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 408 | ModemGSMNetworkProxyInterface::RegistrationInfo info = |
| 409 | gsm_network_proxy_->GetRegistrationInfo(); |
| 410 | gsm_.registration_state = info._1; |
| 411 | gsm_.network_id = info._2; |
| 412 | gsm_.operator_name = info._3; |
| 413 | VLOG(2) << "GSM Registration: " << gsm_.registration_state << ", " |
| 414 | << gsm_.network_id << ", " << gsm_.operator_name; |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 415 | UpdateGSMOperatorInfo(); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 418 | void Cellular::HandleNewRegistrationState() { |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 419 | dispatcher()->PostTask( |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 420 | task_factory_.NewRunnableMethod( |
| 421 | &Cellular::HandleNewRegistrationStateTask)); |
| 422 | } |
| 423 | |
| 424 | void Cellular::HandleNewRegistrationStateTask() { |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 425 | VLOG(2) << __func__; |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 426 | const string network_tech = capability_->GetNetworkTechnologyString(); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 427 | if (network_tech.empty()) { |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 428 | if (state_ == kStateLinked) { |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 429 | manager()->DeregisterService(service_); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 430 | } |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 431 | service_ = NULL; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 432 | if (state_ == kStateLinked || |
| 433 | state_ == kStateConnected || |
| 434 | state_ == kStateRegistered) { |
| 435 | SetState(kStateEnabled); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 436 | } |
| 437 | return; |
| 438 | } |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 439 | if (state_ == kStateEnabled) { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 440 | SetState(kStateRegistered); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 441 | } |
| 442 | if (!service_.get()) { |
| 443 | // For now, no endpoint is created. Revisit if necessary. |
| 444 | CreateService(); |
| 445 | } |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 446 | capability_->GetSignalQuality(); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 447 | if (state_ == kStateRegistered && modem_state_ == kModemStateConnected) { |
| 448 | SetState(kStateConnected); |
| 449 | EstablishLink(); |
| 450 | } |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 451 | service_->set_network_tech(network_tech); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 452 | service_->set_roaming_state(capability_->GetRoamingStateString()); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 455 | void Cellular::HandleNewSignalQuality(uint32 strength) { |
| 456 | VLOG(2) << "Signal strength: " << strength; |
| 457 | if (service_.get()) { |
| 458 | service_->set_strength(strength); |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | void Cellular::CreateService() { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 463 | VLOG(2) << __func__; |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 464 | CHECK(!service_.get()); |
| 465 | service_ = |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 466 | new CellularService(control_interface(), dispatcher(), manager(), this); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 467 | switch (type_) { |
| 468 | case kTypeGSM: |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 469 | service_->set_activation_state(flimflam::kActivationStateActivated); |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 470 | UpdateServingOperator(); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 471 | break; |
| 472 | case kTypeCDMA: |
| 473 | service_->set_payment_url(cdma_.payment_url); |
| 474 | service_->set_usage_url(cdma_.usage_url); |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 475 | UpdateServingOperator(); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 476 | HandleNewCDMAActivationState(MM_MODEM_CDMA_ACTIVATION_ERROR_NO_ERROR); |
| 477 | break; |
| 478 | default: |
| 479 | NOTREACHED(); |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 480 | } |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Paul Stewart | fdd1607 | 2011-09-16 12:41:35 -0700 | [diff] [blame] | 483 | bool Cellular::TechnologyIs(const Technology::Identifier type) const { |
| 484 | return type == Technology::kCellular; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 487 | void Cellular::Connect(Error *error) { |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 488 | VLOG(2) << __func__; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 489 | if (state_ == kStateConnected || |
| 490 | state_ == kStateLinked) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 491 | Error::PopulateAndLog(error, Error::kAlreadyConnected, |
| 492 | "Already connected; connection request ignored."); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 493 | return; |
| 494 | } |
| 495 | CHECK_EQ(kStateRegistered, state_); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 496 | |
| 497 | if (!allow_roaming_ && |
| 498 | service_->roaming_state() == flimflam::kRoamingStateRoaming) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 499 | Error::PopulateAndLog(error, Error::kNotOnHomeNetwork, |
| 500 | "Roaming disallowed; connection request ignored."); |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 501 | CHECK(error); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 502 | return; |
| 503 | } |
| 504 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 505 | DBusPropertiesMap properties; |
| 506 | const char *phone_number = NULL; |
| 507 | switch (type_) { |
| 508 | case kTypeGSM: |
| 509 | phone_number = kPhoneNumberGSM; |
| 510 | break; |
| 511 | case kTypeCDMA: |
| 512 | phone_number = kPhoneNumberCDMA; |
| 513 | break; |
| 514 | default: NOTREACHED(); |
| 515 | } |
| 516 | properties[kConnectPropertyPhoneNumber].writer().append_string(phone_number); |
| 517 | // TODO(petkov): Setup apn and "home_only". |
| 518 | |
| 519 | // Defer connect because we may be in a dbus-c++ callback. |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 520 | dispatcher()->PostTask( |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 521 | task_factory_.NewRunnableMethod(&Cellular::ConnectTask, properties)); |
| 522 | } |
| 523 | |
| 524 | void Cellular::ConnectTask(const DBusPropertiesMap &properties) { |
| 525 | VLOG(2) << __func__; |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 526 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 527 | simple_proxy_->Connect(properties); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 528 | SetState(kStateConnected); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 529 | EstablishLink(); |
| 530 | } |
| 531 | |
| 532 | void Cellular::EstablishLink() { |
| 533 | VLOG(2) << __func__; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 534 | CHECK_EQ(kStateConnected, state_); |
| 535 | unsigned int flags = 0; |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 536 | if (manager()->device_info()->GetFlags(interface_index(), &flags) && |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 537 | (flags & IFF_UP) != 0) { |
| 538 | LinkEvent(flags, IFF_UP); |
| 539 | return; |
| 540 | } |
| 541 | // TODO(petkov): Provide a timeout for a failed link-up request. |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 542 | rtnl_handler()->SetInterfaceFlags(interface_index(), IFF_UP, IFF_UP); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | void Cellular::LinkEvent(unsigned int flags, unsigned int change) { |
| 546 | Device::LinkEvent(flags, change); |
| 547 | if ((flags & IFF_UP) != 0 && state_ == kStateConnected) { |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 548 | LOG(INFO) << link_name() << " is up."; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 549 | SetState(kStateLinked); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 550 | manager()->RegisterService(service_); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 551 | // TODO(petkov): For GSM, remember the APN. |
Darin Petkov | 60b8c3b | 2011-08-25 11:03:20 -0700 | [diff] [blame] | 552 | if (AcquireDHCPConfig()) { |
| 553 | SelectService(service_); |
| 554 | SetServiceState(Service::kStateConfiguring); |
| 555 | } else { |
| 556 | LOG(ERROR) << "Unable to acquire DHCP config."; |
| 557 | } |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 558 | } else if ((flags & IFF_UP) == 0 && state_ == kStateLinked) { |
| 559 | SetState(kStateConnected); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 560 | manager()->DeregisterService(service_); |
Darin Petkov | 60b8c3b | 2011-08-25 11:03:20 -0700 | [diff] [blame] | 561 | SelectService(NULL); |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 562 | DestroyIPConfig(); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 563 | } |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 564 | } |
| 565 | |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 566 | void Cellular::Activate(const string &carrier, Error *error) { |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 567 | VLOG(2) << __func__ << "(" << carrier << ")"; |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 568 | if (type_ != kTypeCDMA) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 569 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 570 | "Unable to activate non-CDMA modem."); |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 571 | return; |
| 572 | } |
| 573 | if (state_ != kStateEnabled && |
| 574 | state_ != kStateRegistered) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 575 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 576 | "Unable to activate in " + GetStateString(state_)); |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 577 | return; |
| 578 | } |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 579 | // Defer connect because we may be in a dbus-c++ callback. |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 580 | dispatcher()->PostTask( |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 581 | task_factory_.NewRunnableMethod(&Cellular::ActivateTask, carrier)); |
| 582 | } |
| 583 | |
| 584 | void Cellular::ActivateTask(const string &carrier) { |
| 585 | VLOG(2) << __func__ << "(" << carrier << ")"; |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 586 | CHECK_EQ(kTypeCDMA, type_); |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 587 | if (state_ != kStateEnabled && |
| 588 | state_ != kStateRegistered) { |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 589 | LOG(ERROR) << "Unable to activate in " << GetStateString(state_); |
| 590 | return; |
| 591 | } |
| 592 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 593 | uint32 status = cdma_proxy_->Activate(carrier); |
| 594 | if (status == MM_MODEM_CDMA_ACTIVATION_ERROR_NO_ERROR) { |
| 595 | cdma_.activation_state = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING; |
| 596 | } |
| 597 | HandleNewCDMAActivationState(status); |
| 598 | } |
| 599 | |
| 600 | void Cellular::HandleNewCDMAActivationState(uint32 error) { |
| 601 | if (!service_.get()) { |
| 602 | return; |
| 603 | } |
| 604 | service_->set_activation_state( |
| 605 | GetCDMAActivationStateString(cdma_.activation_state)); |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 606 | service_->set_error(GetCDMAActivationErrorString(error)); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 609 | void Cellular::OnCDMAActivationStateChanged( |
| 610 | uint32 activation_state, |
| 611 | uint32 activation_error, |
| 612 | const DBusPropertiesMap &status_changes) { |
| 613 | CHECK_EQ(kTypeCDMA, type_); |
| 614 | DBusProperties::GetString(status_changes, "mdn", &mdn_); |
| 615 | DBusProperties::GetString(status_changes, "min", &min_); |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 616 | if (DBusProperties::GetString( |
| 617 | status_changes, "payment_url", &cdma_.payment_url) && |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 618 | service_.get()) { |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 619 | service_->set_payment_url(cdma_.payment_url); |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 620 | } |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 621 | cdma_.activation_state = activation_state; |
| 622 | HandleNewCDMAActivationState(activation_error); |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 625 | void Cellular::OnCDMARegistrationStateChanged(uint32 state_1x, |
| 626 | uint32 state_evdo) { |
| 627 | CHECK_EQ(kTypeCDMA, type_); |
| 628 | cdma_.registration_state_1x = state_1x; |
| 629 | cdma_.registration_state_evdo = state_evdo; |
| 630 | HandleNewRegistrationState(); |
| 631 | } |
| 632 | |
| 633 | void Cellular::OnCDMASignalQualityChanged(uint32 strength) { |
| 634 | CHECK_EQ(kTypeCDMA, type_); |
| 635 | HandleNewSignalQuality(strength); |
| 636 | } |
| 637 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 638 | void Cellular::OnGSMNetworkModeChanged(uint32 /*mode*/) { |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 639 | // TODO(petkov): Implement this. |
| 640 | NOTIMPLEMENTED(); |
| 641 | } |
| 642 | |
| 643 | void Cellular::OnGSMRegistrationInfoChanged(uint32 status, |
| 644 | const string &operator_code, |
| 645 | const string &operator_name) { |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 646 | CHECK_EQ(kTypeGSM, type_); |
| 647 | gsm_.registration_state = status; |
| 648 | gsm_.network_id = operator_code; |
| 649 | gsm_.operator_name = operator_name; |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 650 | UpdateGSMOperatorInfo(); |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 651 | HandleNewRegistrationState(); |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | void Cellular::OnGSMSignalQualityChanged(uint32 quality) { |
Darin Petkov | 22b72bf | 2011-08-29 14:01:20 -0700 | [diff] [blame] | 655 | CHECK_EQ(kTypeGSM, type_); |
| 656 | HandleNewSignalQuality(quality); |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 657 | } |
| 658 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 659 | void Cellular::OnModemStateChanged(uint32 /*old_state*/, |
| 660 | uint32 /*new_state*/, |
| 661 | uint32 /*reason*/) { |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 662 | // TODO(petkov): Implement this. |
| 663 | NOTIMPLEMENTED(); |
| 664 | } |
| 665 | |
Darin Petkov | 48a511a | 2011-09-15 10:33:37 -0700 | [diff] [blame] | 666 | void Cellular::SetGSMAccessTechnology(uint32 access_technology) { |
| 667 | CHECK_EQ(kTypeGSM, type_); |
| 668 | gsm_.access_technology = access_technology; |
| 669 | if (service_.get()) { |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 670 | service_->set_network_tech(capability_->GetNetworkTechnologyString()); |
Darin Petkov | 48a511a | 2011-09-15 10:33:37 -0700 | [diff] [blame] | 671 | } |
| 672 | } |
| 673 | |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 674 | void Cellular::UpdateGSMOperatorInfo() { |
| 675 | if (!gsm_.network_id.empty()) { |
| 676 | VLOG(2) << "Looking up network id: " << gsm_.network_id; |
| 677 | mobile_provider *provider = |
| 678 | mobile_provider_lookup_by_network(provider_db_, |
| 679 | gsm_.network_id.c_str()); |
| 680 | if (provider) { |
| 681 | const char *provider_name = mobile_provider_get_name(provider); |
| 682 | if (provider_name && *provider_name) { |
| 683 | gsm_.operator_name = provider_name; |
| 684 | gsm_.operator_country = provider->country; |
| 685 | VLOG(2) << "Operator name: " << gsm_.operator_name |
| 686 | << ", country: " << gsm_.operator_country; |
| 687 | } |
| 688 | } else { |
| 689 | VLOG(2) << "GSM provider not found."; |
| 690 | } |
| 691 | } |
| 692 | UpdateServingOperator(); |
| 693 | } |
| 694 | |
| 695 | void Cellular::UpdateServingOperator() { |
| 696 | if (!service_.get()) { |
| 697 | return; |
| 698 | } |
| 699 | switch (type_) { |
| 700 | case kTypeGSM: { |
| 701 | Operator oper; |
| 702 | oper.SetName(gsm_.operator_name); |
| 703 | oper.SetCode(gsm_.network_id); |
| 704 | oper.SetCountry(gsm_.operator_country); |
| 705 | service_->set_serving_operator(oper); |
| 706 | break; |
| 707 | } |
| 708 | case kTypeCDMA: |
| 709 | service_->set_serving_operator(home_provider_); |
| 710 | break; |
| 711 | default: NOTREACHED(); |
| 712 | } |
| 713 | } |
| 714 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 715 | StrIntPair Cellular::SimLockStatusToProperty() { |
| 716 | return StrIntPair(make_pair(flimflam::kSIMLockTypeProperty, |
| 717 | sim_lock_status_.lock_type), |
| 718 | make_pair(flimflam::kSIMLockRetriesLeftProperty, |
| 719 | sim_lock_status_.retries_left)); |
| 720 | } |
| 721 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 722 | void Cellular::HelpRegisterDerivedStrIntPair( |
| 723 | const string &name, |
| 724 | StrIntPair(Cellular::*get)(void), |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 725 | void(Cellular::*set)(const StrIntPair&, Error *)) { |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 726 | mutable_store()->RegisterDerivedStrIntPair( |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 727 | name, |
| 728 | StrIntPairAccessor( |
| 729 | new CustomAccessor<Cellular, StrIntPair>(this, get, set))); |
| 730 | } |
| 731 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 732 | } // namespace shill |