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 | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 15 | #include <base/string_number_conversions.h> |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 16 | #include <base/stringprintf.h> |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 17 | #include <chromeos/dbus/service_constants.h> |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 18 | #include <mm/mm-modem.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 19 | |
| 20 | #include "shill/cellular_service.h" |
| 21 | #include "shill/control_interface.h" |
| 22 | #include "shill/device.h" |
| 23 | #include "shill/device_info.h" |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 24 | #include "shill/error.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 25 | #include "shill/manager.h" |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 26 | #include "shill/modem_simple_proxy_interface.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 27 | #include "shill/profile.h" |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 28 | #include "shill/property_accessor.h" |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 29 | #include "shill/proxy_factory.h" |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 30 | #include "shill/rtnl_handler.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 31 | #include "shill/shill_event.h" |
| 32 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 33 | using std::make_pair; |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 34 | using std::map; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 35 | using std::string; |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 36 | using std::vector; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 37 | |
| 38 | namespace shill { |
| 39 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 40 | const char Cellular::kConnectPropertyPhoneNumber[] = "number"; |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 41 | const char Cellular::kNetworkPropertyAccessTechnology[] = "access-tech"; |
| 42 | const char Cellular::kNetworkPropertyID[] = "operator-num"; |
| 43 | const char Cellular::kNetworkPropertyLongName[] = "operator-long"; |
| 44 | const char Cellular::kNetworkPropertyShortName[] = "operator-short"; |
| 45 | const char Cellular::kNetworkPropertyStatus[] = "status"; |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 46 | const char Cellular::kPhoneNumberCDMA[] = "#777"; |
| 47 | const char Cellular::kPhoneNumberGSM[] = "*99#"; |
| 48 | |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 49 | Cellular::Operator::Operator() { |
| 50 | SetName(""); |
| 51 | SetCode(""); |
| 52 | SetCountry(""); |
| 53 | } |
| 54 | |
| 55 | Cellular::Operator::~Operator() {} |
| 56 | |
| 57 | void Cellular::Operator::CopyFrom(const Operator &oper) { |
| 58 | dict_ = oper.dict_; |
| 59 | } |
| 60 | |
| 61 | const string &Cellular::Operator::GetName() const { |
| 62 | return dict_.find(flimflam::kOperatorNameKey)->second; |
| 63 | } |
| 64 | |
| 65 | void Cellular::Operator::SetName(const string &name) { |
| 66 | dict_[flimflam::kOperatorNameKey] = name; |
| 67 | } |
| 68 | |
| 69 | const string &Cellular::Operator::GetCode() const { |
| 70 | return dict_.find(flimflam::kOperatorCodeKey)->second; |
| 71 | } |
| 72 | |
| 73 | void Cellular::Operator::SetCode(const string &code) { |
| 74 | dict_[flimflam::kOperatorCodeKey] = code; |
| 75 | } |
| 76 | |
| 77 | const string &Cellular::Operator::GetCountry() const { |
| 78 | return dict_.find(flimflam::kOperatorCountryKey)->second; |
| 79 | } |
| 80 | |
| 81 | void Cellular::Operator::SetCountry(const string &country) { |
| 82 | dict_[flimflam::kOperatorCountryKey] = country; |
| 83 | } |
| 84 | |
| 85 | const Stringmap &Cellular::Operator::ToDict() const { |
| 86 | return dict_; |
| 87 | } |
| 88 | |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 89 | Cellular::CDMA::CDMA() |
| 90 | : registration_state_evdo(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN), |
| 91 | registration_state_1x(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN), |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 92 | activation_state(MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED), |
| 93 | prl_version(0) {} |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 94 | |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 95 | Cellular::GSM::GSM() |
| 96 | : registration_state(MM_MODEM_GSM_NETWORK_REG_STATUS_UNKNOWN), |
| 97 | access_technology(MM_MODEM_GSM_ACCESS_TECH_UNKNOWN) {} |
| 98 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 99 | Cellular::Cellular(ControlInterface *control_interface, |
| 100 | EventDispatcher *dispatcher, |
| 101 | Manager *manager, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 102 | const string &link_name, |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 103 | const string &address, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 104 | int interface_index, |
| 105 | Type type, |
| 106 | const string &owner, |
| 107 | const string &path) |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 108 | : Device(control_interface, |
| 109 | dispatcher, |
| 110 | manager, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 111 | link_name, |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 112 | address, |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 113 | interface_index), |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame^] | 114 | proxy_factory_(ProxyFactory::GetInstance()), |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 115 | type_(type), |
| 116 | state_(kStateDisabled), |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 117 | modem_state_(kModemStateUnknown), |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 118 | dbus_owner_(owner), |
| 119 | dbus_path_(path), |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 120 | task_factory_(this), |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 121 | allow_roaming_(false), |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 122 | scanning_(false), |
| 123 | scan_interval_(0) { |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 124 | PropertyStore *store = this->mutable_store(); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 125 | store->RegisterConstString(flimflam::kCarrierProperty, &carrier_); |
| 126 | store->RegisterConstString(flimflam::kDBusConnectionProperty, &dbus_owner_); |
| 127 | store->RegisterConstString(flimflam::kDBusObjectProperty, &dbus_path_); |
| 128 | store->RegisterBool(flimflam::kCellularAllowRoamingProperty, &allow_roaming_); |
| 129 | store->RegisterConstString(flimflam::kEsnProperty, &esn_); |
| 130 | store->RegisterConstString(flimflam::kFirmwareRevisionProperty, |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 131 | &firmware_revision_); |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 132 | store->RegisterConstStringmaps(flimflam::kFoundNetworksProperty, |
| 133 | &found_networks_); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 134 | store->RegisterConstString(flimflam::kHardwareRevisionProperty, |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 135 | &hardware_revision_); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 136 | store->RegisterConstStringmap(flimflam::kHomeProviderProperty, |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 137 | &home_provider_.ToDict()); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 138 | store->RegisterConstString(flimflam::kImeiProperty, &imei_); |
| 139 | store->RegisterConstString(flimflam::kImsiProperty, &imsi_); |
| 140 | store->RegisterConstString(flimflam::kManufacturerProperty, &manufacturer_); |
| 141 | store->RegisterConstString(flimflam::kMdnProperty, &mdn_); |
| 142 | store->RegisterConstString(flimflam::kMeidProperty, &meid_); |
| 143 | store->RegisterConstString(flimflam::kMinProperty, &min_); |
| 144 | store->RegisterConstString(flimflam::kModelIDProperty, &model_id_); |
| 145 | store->RegisterConstUint16(flimflam::kPRLVersionProperty, &cdma_.prl_version); |
| 146 | store->RegisterConstString(flimflam::kSelectedNetworkProperty, |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 147 | &selected_network_); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 148 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 149 | HelpRegisterDerivedStrIntPair(flimflam::kSIMLockStatusProperty, |
| 150 | &Cellular::SimLockStatusToProperty, |
| 151 | NULL); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 152 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 153 | store->RegisterConstBool(flimflam::kScanningProperty, &scanning_); |
| 154 | store->RegisterUint16(flimflam::kScanIntervalProperty, &scan_interval_); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 155 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 156 | VLOG(2) << "Cellular device " << this->link_name() << " initialized: " |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 157 | << GetTypeString(); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 160 | Cellular::~Cellular() {} |
| 161 | |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 162 | string Cellular::GetTypeString() const { |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 163 | switch (type_) { |
| 164 | case kTypeGSM: return "CellularTypeGSM"; |
| 165 | case kTypeCDMA: return "CellularTypeCDMA"; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 166 | default: NOTREACHED(); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 167 | } |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 168 | return StringPrintf("CellularTypeUnknown-%d", type_); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 171 | // static |
| 172 | string Cellular::GetStateString(State state) { |
| 173 | switch (state) { |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 174 | case kStateDisabled: return "CellularStateDisabled"; |
| 175 | case kStateEnabled: return "CellularStateEnabled"; |
| 176 | case kStateRegistered: return "CellularStateRegistered"; |
| 177 | case kStateConnected: return "CellularStateConnected"; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 178 | case kStateLinked: return "CellularStateLinked"; |
| 179 | default: NOTREACHED(); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 180 | } |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 181 | return StringPrintf("CellularStateUnknown-%d", state); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 184 | string Cellular::GetNetworkTechnologyString() const { |
| 185 | switch (type_) { |
| 186 | case kTypeGSM: |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 187 | if (gsm_.registration_state == MM_MODEM_GSM_NETWORK_REG_STATUS_HOME || |
| 188 | gsm_.registration_state == MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING) { |
| 189 | switch (gsm_.access_technology) { |
| 190 | case MM_MODEM_GSM_ACCESS_TECH_GSM: |
| 191 | case MM_MODEM_GSM_ACCESS_TECH_GSM_COMPACT: |
Darin Petkov | e1a3e24 | 2011-08-29 12:44:30 -0700 | [diff] [blame] | 192 | return flimflam::kNetworkTechnologyGsm; |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 193 | case MM_MODEM_GSM_ACCESS_TECH_GPRS: |
| 194 | return flimflam::kNetworkTechnologyGprs; |
| 195 | case MM_MODEM_GSM_ACCESS_TECH_EDGE: |
| 196 | return flimflam::kNetworkTechnologyEdge; |
| 197 | case MM_MODEM_GSM_ACCESS_TECH_UMTS: |
| 198 | return flimflam::kNetworkTechnologyUmts; |
| 199 | case MM_MODEM_GSM_ACCESS_TECH_HSDPA: |
| 200 | case MM_MODEM_GSM_ACCESS_TECH_HSUPA: |
| 201 | case MM_MODEM_GSM_ACCESS_TECH_HSPA: |
| 202 | return flimflam::kNetworkTechnologyHspa; |
| 203 | case MM_MODEM_GSM_ACCESS_TECH_HSPA_PLUS: |
| 204 | return flimflam::kNetworkTechnologyHspaPlus; |
| 205 | default: |
| 206 | NOTREACHED(); |
| 207 | } |
| 208 | } |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 209 | break; |
| 210 | case kTypeCDMA: |
| 211 | if (cdma_.registration_state_evdo != |
| 212 | MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN) { |
| 213 | return flimflam::kNetworkTechnologyEvdo; |
| 214 | } |
| 215 | if (cdma_.registration_state_1x != |
| 216 | MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN) { |
| 217 | return flimflam::kNetworkTechnology1Xrtt; |
| 218 | } |
| 219 | break; |
| 220 | default: |
| 221 | NOTREACHED(); |
| 222 | } |
| 223 | return ""; |
| 224 | } |
| 225 | |
| 226 | string Cellular::GetRoamingStateString() const { |
| 227 | switch (type_) { |
| 228 | case kTypeGSM: |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 229 | switch (gsm_.registration_state) { |
| 230 | case MM_MODEM_GSM_NETWORK_REG_STATUS_HOME: |
| 231 | return flimflam::kRoamingStateHome; |
| 232 | case MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING: |
| 233 | return flimflam::kRoamingStateRoaming; |
| 234 | default: |
| 235 | break; |
| 236 | } |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 237 | break; |
| 238 | case kTypeCDMA: { |
| 239 | uint32 state = cdma_.registration_state_evdo; |
| 240 | if (state == MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN) { |
| 241 | state = cdma_.registration_state_1x; |
| 242 | } |
| 243 | switch (state) { |
| 244 | case MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN: |
| 245 | case MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED: |
| 246 | break; |
| 247 | case MM_MODEM_CDMA_REGISTRATION_STATE_HOME: |
| 248 | return flimflam::kRoamingStateHome; |
| 249 | case MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING: |
| 250 | return flimflam::kRoamingStateRoaming; |
| 251 | default: |
| 252 | NOTREACHED(); |
| 253 | } |
| 254 | break; |
| 255 | } |
| 256 | default: |
| 257 | NOTREACHED(); |
| 258 | } |
| 259 | return flimflam::kRoamingStateUnknown; |
| 260 | } |
| 261 | |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 262 | // static |
| 263 | string Cellular::GetCDMAActivationStateString(uint32 state) { |
| 264 | switch (state) { |
| 265 | case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED: |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 266 | return flimflam::kActivationStateActivated; |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 267 | case MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING: |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 268 | return flimflam::kActivationStateActivating; |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 269 | case MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED: |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 270 | return flimflam::kActivationStateNotActivated; |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 271 | case MM_MODEM_CDMA_ACTIVATION_STATE_PARTIALLY_ACTIVATED: |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 272 | return flimflam::kActivationStatePartiallyActivated; |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 273 | default: |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 274 | return flimflam::kActivationStateUnknown; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | // static |
| 279 | string Cellular::GetCDMAActivationErrorString(uint32 error) { |
| 280 | switch (error) { |
| 281 | case MM_MODEM_CDMA_ACTIVATION_ERROR_WRONG_RADIO_INTERFACE: |
| 282 | return flimflam::kErrorNeedEvdo; |
| 283 | case MM_MODEM_CDMA_ACTIVATION_ERROR_ROAMING: |
| 284 | return flimflam::kErrorNeedHomeNetwork; |
| 285 | case MM_MODEM_CDMA_ACTIVATION_ERROR_COULD_NOT_CONNECT: |
| 286 | case MM_MODEM_CDMA_ACTIVATION_ERROR_SECURITY_AUTHENTICATION_FAILED: |
| 287 | case MM_MODEM_CDMA_ACTIVATION_ERROR_PROVISIONING_FAILED: |
| 288 | return flimflam::kErrorOtaspFailed; |
| 289 | case MM_MODEM_CDMA_ACTIVATION_ERROR_NO_ERROR: |
| 290 | return ""; |
| 291 | case MM_MODEM_CDMA_ACTIVATION_ERROR_NO_SIGNAL: |
| 292 | default: |
| 293 | return flimflam::kErrorActivationFailed; |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 297 | void Cellular::SetState(State state) { |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 298 | VLOG(2) << GetStateString(state_) << " -> " << GetStateString(state); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 299 | state_ = state; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | void Cellular::Start() { |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 303 | LOG(INFO) << __func__ << ": " << GetStateString(state_); |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 304 | Device::Start(); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 305 | InitProxies(); |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 306 | EnableModem(); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 307 | if (type_ == kTypeGSM) { |
| 308 | RegisterGSMModem(); |
| 309 | } |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 310 | GetModemStatus(); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 311 | GetModemIdentifiers(); |
| 312 | if (type_ == kTypeGSM) { |
| 313 | GetGSMProperties(); |
| 314 | } |
| 315 | GetModemInfo(); |
| 316 | GetModemRegistrationState(); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | void Cellular::Stop() { |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 320 | proxy_.reset(); |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 321 | simple_proxy_.reset(); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 322 | cdma_proxy_.reset(); |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 323 | gsm_card_proxy_.reset(); |
| 324 | gsm_network_proxy_.reset(); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 325 | manager()->DeregisterService(service_); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 326 | service_ = NULL; // Breaks a reference cycle. |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 327 | SetState(kStateDisabled); |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 328 | Device::Stop(); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 331 | void Cellular::InitProxies() { |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 332 | VLOG(2) << __func__; |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame^] | 333 | proxy_.reset(proxy_factory_->CreateModemProxy(this, dbus_path_, dbus_owner_)); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 334 | simple_proxy_.reset( |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame^] | 335 | proxy_factory_->CreateModemSimpleProxy(dbus_path_, dbus_owner_)); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 336 | switch (type_) { |
| 337 | case kTypeGSM: |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 338 | gsm_card_proxy_.reset( |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame^] | 339 | proxy_factory_->CreateModemGSMCardProxy( |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 340 | this, dbus_path_, dbus_owner_)); |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 341 | gsm_network_proxy_.reset( |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame^] | 342 | proxy_factory_->CreateModemGSMNetworkProxy( |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 343 | this, dbus_path_, dbus_owner_)); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 344 | break; |
| 345 | case kTypeCDMA: |
| 346 | cdma_proxy_.reset( |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame^] | 347 | proxy_factory_->CreateModemCDMAProxy(this, dbus_path_, dbus_owner_)); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 348 | break; |
| 349 | default: NOTREACHED(); |
| 350 | } |
| 351 | } |
| 352 | |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 353 | void Cellular::EnableModem() { |
| 354 | CHECK_EQ(kStateDisabled, state_); |
| 355 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 356 | proxy_->Enable(true); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 357 | SetState(kStateEnabled); |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | void Cellular::GetModemStatus() { |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 361 | CHECK_EQ(kStateEnabled, state_); |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 362 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 363 | DBusPropertiesMap properties = simple_proxy_->GetStatus(); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 364 | if (DBusProperties::GetString(properties, "carrier", &carrier_) && |
| 365 | type_ == kTypeCDMA) { |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 366 | home_provider_.SetName(carrier_); |
| 367 | home_provider_.SetCode(""); |
| 368 | home_provider_.SetCountry("us"); |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 369 | } |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 370 | DBusProperties::GetString(properties, "meid", &meid_); |
| 371 | DBusProperties::GetString(properties, "imei", &imei_); |
| 372 | if (DBusProperties::GetString(properties, "imsi", &imsi_) && |
| 373 | type_ == kTypeGSM) { |
| 374 | // TODO(petkov): Set GSM provider. |
| 375 | } |
| 376 | DBusProperties::GetString(properties, "esn", &esn_); |
| 377 | DBusProperties::GetString(properties, "mdn", &mdn_); |
| 378 | DBusProperties::GetString(properties, "min", &min_); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 379 | DBusProperties::GetString( |
| 380 | properties, "firmware_revision", &firmware_revision_); |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 381 | |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 382 | uint32 state = 0; |
| 383 | if (DBusProperties::GetUint32(properties, "state", &state)) { |
| 384 | modem_state_ = static_cast<ModemState>(state); |
| 385 | } |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 386 | |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 387 | if (type_ == kTypeCDMA) { |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 388 | DBusProperties::GetUint32( |
| 389 | properties, "activation_state", &cdma_.activation_state); |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 390 | DBusProperties::GetUint16(properties, "prl_version", &cdma_.prl_version); |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 391 | // TODO(petkov): For now, get the payment and usage URLs from ModemManager |
| 392 | // to match flimflam. In the future, provide a plugin API to get these |
| 393 | // directly from the modem driver. |
| 394 | DBusProperties::GetString(properties, "payment_url", &cdma_.payment_url); |
| 395 | DBusProperties::GetString(properties, "usage_url", &cdma_.usage_url); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 396 | } |
| 397 | } |
| 398 | |
| 399 | void Cellular::GetModemIdentifiers() { |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 400 | VLOG(2) << __func__; |
| 401 | switch (type_) { |
| 402 | case kTypeGSM: |
| 403 | GetGSMIdentifiers(); |
| 404 | break; |
| 405 | case kTypeCDMA: |
| 406 | GetCDMAIdentifiers(); |
| 407 | break; |
| 408 | default: NOTREACHED(); |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | void Cellular::GetCDMAIdentifiers() { |
| 413 | CHECK_EQ(kTypeCDMA, type_); |
| 414 | if (meid_.empty()) { |
| 415 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 416 | meid_ = cdma_proxy_->MEID(); |
| 417 | VLOG(2) << "MEID: " << imei_; |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | void Cellular::GetGSMIdentifiers() { |
| 422 | CHECK_EQ(kTypeGSM, type_); |
| 423 | if (imei_.empty()) { |
| 424 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 425 | imei_ = gsm_card_proxy_->GetIMEI(); |
| 426 | VLOG(2) << "IMEI: " << imei_; |
| 427 | } |
| 428 | if (imsi_.empty()) { |
| 429 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 430 | imsi_ = gsm_card_proxy_->GetIMSI(); |
| 431 | VLOG(2) << "IMSI: " << imsi_; |
| 432 | } |
| 433 | if (gsm_.spn.empty()) { |
| 434 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 435 | try { |
| 436 | gsm_.spn = gsm_card_proxy_->GetSPN(); |
| 437 | VLOG(2) << "SPN: " << gsm_.spn; |
| 438 | } catch (const DBus::Error e) { |
| 439 | // Some modems don't support this call so catch the exception explicitly. |
| 440 | LOG(WARNING) << "Unable to obtain SPN: " << e.what(); |
| 441 | } |
| 442 | } |
| 443 | if (mdn_.empty()) { |
| 444 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 445 | mdn_ = gsm_card_proxy_->GetMSISDN(); |
| 446 | VLOG(2) << "MSISDN/MDN: " << mdn_; |
| 447 | } |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | void Cellular::GetGSMProperties() { |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 451 | CHECK_EQ(kTypeGSM, type_); |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 452 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 453 | gsm_.access_technology = gsm_network_proxy_->AccessTechnology(); |
| 454 | VLOG(2) << "GSM AccessTechnology: " << gsm_.access_technology; |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | void Cellular::RegisterGSMModem() { |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 458 | CHECK_EQ(kTypeGSM, type_); |
Darin Petkov | 9ae310f | 2011-08-30 15:41:13 -0700 | [diff] [blame] | 459 | LOG(INFO) << "Registering on \"" << selected_network_ << "\""; |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 460 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 461 | gsm_network_proxy_->Register(selected_network_); |
Darin Petkov | 9ae310f | 2011-08-30 15:41:13 -0700 | [diff] [blame] | 462 | // TODO(petkov): Handle registration failure including trying the home network |
| 463 | // when selected_network_ is not empty. |
| 464 | } |
| 465 | |
| 466 | void Cellular::RegisterOnNetwork(const string &network_id, Error *error) { |
| 467 | LOG(INFO) << __func__ << "(" << network_id << ")"; |
| 468 | if (type_ != kTypeGSM) { |
| 469 | const string kMessage = "Network registration supported only for GSM."; |
| 470 | LOG(ERROR) << kMessage; |
| 471 | CHECK(error); |
| 472 | error->Populate(Error::kNotSupported, kMessage); |
| 473 | return; |
| 474 | } |
| 475 | // Defer registration because we may be in a dbus-c++ callback. |
| 476 | dispatcher()->PostTask( |
| 477 | task_factory_.NewRunnableMethod(&Cellular::RegisterOnNetworkTask, |
| 478 | network_id)); |
| 479 | } |
| 480 | |
| 481 | void Cellular::RegisterOnNetworkTask(const string &network_id) { |
| 482 | LOG(INFO) << __func__ << "(" << network_id << ")"; |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 483 | CHECK_EQ(kTypeGSM, type_); |
Darin Petkov | 9ae310f | 2011-08-30 15:41:13 -0700 | [diff] [blame] | 484 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 485 | gsm_network_proxy_->Register(network_id); |
| 486 | // TODO(petkov): Handle registration failure. |
| 487 | selected_network_ = network_id; |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 490 | void Cellular::RequirePIN(const string &pin, bool require, Error *error) { |
| 491 | VLOG(2) << __func__ << "(" << pin << ", " << require << ")"; |
| 492 | if (type_ != kTypeGSM) { |
| 493 | const string kMessage = "RequirePIN supported only for GSM."; |
| 494 | LOG(ERROR) << kMessage; |
| 495 | CHECK(error); |
| 496 | error->Populate(Error::kNotSupported, kMessage); |
| 497 | return; |
| 498 | } |
| 499 | // Defer registration because we may be in a dbus-c++ callback. |
| 500 | dispatcher()->PostTask( |
| 501 | task_factory_.NewRunnableMethod(&Cellular::RequirePINTask, pin, require)); |
| 502 | } |
| 503 | |
| 504 | void Cellular::RequirePINTask(const string &pin, bool require) { |
| 505 | VLOG(2) << __func__ << "(" << pin << ", " << require << ")"; |
| 506 | CHECK_EQ(kTypeGSM, type_); |
| 507 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 508 | gsm_card_proxy_->EnablePIN(pin, require); |
| 509 | } |
| 510 | |
| 511 | void Cellular::EnterPIN(const string &pin, Error *error) { |
| 512 | VLOG(2) << __func__ << "(" << pin << ")"; |
| 513 | if (type_ != kTypeGSM) { |
| 514 | const string kMessage = "EnterPIN supported only for GSM."; |
| 515 | LOG(ERROR) << kMessage; |
| 516 | CHECK(error); |
| 517 | error->Populate(Error::kNotSupported, kMessage); |
| 518 | return; |
| 519 | } |
| 520 | // Defer registration because we may be in a dbus-c++ callback. |
| 521 | dispatcher()->PostTask( |
| 522 | task_factory_.NewRunnableMethod(&Cellular::EnterPINTask, pin)); |
| 523 | } |
| 524 | |
| 525 | void Cellular::EnterPINTask(const string &pin) { |
| 526 | VLOG(2) << __func__ << "(" << pin << ")"; |
| 527 | CHECK_EQ(kTypeGSM, type_); |
| 528 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 529 | gsm_card_proxy_->SendPIN(pin); |
| 530 | } |
| 531 | |
| 532 | void Cellular::UnblockPIN(const string &unblock_code, |
| 533 | const string &pin, |
| 534 | Error *error) { |
| 535 | VLOG(2) << __func__ << "(" << unblock_code << ", " << pin << ")"; |
| 536 | if (type_ != kTypeGSM) { |
| 537 | const string kMessage = "UnblockPIN supported only for GSM."; |
| 538 | LOG(ERROR) << kMessage; |
| 539 | CHECK(error); |
| 540 | error->Populate(Error::kNotSupported, kMessage); |
| 541 | return; |
| 542 | } |
| 543 | // Defer registration because we may be in a dbus-c++ callback. |
| 544 | dispatcher()->PostTask( |
| 545 | task_factory_.NewRunnableMethod( |
| 546 | &Cellular::UnblockPINTask, unblock_code, pin)); |
| 547 | } |
| 548 | |
| 549 | void Cellular::UnblockPINTask(const string &unblock_code, const string &pin) { |
| 550 | VLOG(2) << __func__ << "(" << unblock_code << ", " << pin << ")"; |
| 551 | CHECK_EQ(kTypeGSM, type_); |
| 552 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 553 | gsm_card_proxy_->SendPUK(unblock_code, pin); |
| 554 | } |
| 555 | |
| 556 | void Cellular::ChangePIN(const string &old_pin, |
| 557 | const string &new_pin, |
| 558 | Error *error) { |
| 559 | VLOG(2) << __func__ << "(" << old_pin << ", " << new_pin << ")"; |
| 560 | if (type_ != kTypeGSM) { |
| 561 | const string kMessage = "ChangePIN supported only for GSM."; |
| 562 | LOG(ERROR) << kMessage; |
| 563 | CHECK(error); |
| 564 | error->Populate(Error::kNotSupported, kMessage); |
| 565 | return; |
| 566 | } |
| 567 | // Defer registration because we may be in a dbus-c++ callback. |
| 568 | dispatcher()->PostTask( |
| 569 | task_factory_.NewRunnableMethod( |
| 570 | &Cellular::ChangePINTask, old_pin, new_pin)); |
| 571 | } |
| 572 | |
| 573 | void Cellular::ChangePINTask(const string &old_pin, const string &new_pin) { |
| 574 | VLOG(2) << __func__ << "(" << old_pin << ", " << new_pin << ")"; |
| 575 | CHECK_EQ(kTypeGSM, type_); |
| 576 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 577 | gsm_card_proxy_->ChangePIN(old_pin, new_pin); |
| 578 | } |
| 579 | |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 580 | void Cellular::GetModemInfo() { |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 581 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 582 | ModemProxyInterface::Info info = proxy_->GetInfo(); |
| 583 | manufacturer_ = info._1; |
| 584 | model_id_ = info._2; |
| 585 | hardware_revision_ = info._3; |
| 586 | VLOG(2) << "ModemInfo: " << manufacturer_ << ", " << model_id_ << ", " |
| 587 | << hardware_revision_; |
| 588 | } |
| 589 | |
| 590 | void Cellular::GetModemRegistrationState() { |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 591 | switch (type_) { |
| 592 | case kTypeGSM: |
| 593 | GetGSMRegistrationState(); |
| 594 | break; |
| 595 | case kTypeCDMA: |
| 596 | GetCDMARegistrationState(); |
| 597 | break; |
| 598 | default: NOTREACHED(); |
| 599 | } |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 600 | HandleNewRegistrationState(); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | void Cellular::GetCDMARegistrationState() { |
| 604 | CHECK_EQ(kTypeCDMA, type_); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 605 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 606 | cdma_proxy_->GetRegistrationState(&cdma_.registration_state_1x, |
| 607 | &cdma_.registration_state_evdo); |
| 608 | VLOG(2) << "CDMA Registration: 1x(" << cdma_.registration_state_1x |
| 609 | << ") EVDO(" << cdma_.registration_state_evdo << ")"; |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | void Cellular::GetGSMRegistrationState() { |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 613 | CHECK_EQ(kTypeGSM, type_); |
| 614 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 615 | ModemGSMNetworkProxyInterface::RegistrationInfo info = |
| 616 | gsm_network_proxy_->GetRegistrationInfo(); |
| 617 | gsm_.registration_state = info._1; |
| 618 | gsm_.network_id = info._2; |
| 619 | gsm_.operator_name = info._3; |
| 620 | VLOG(2) << "GSM Registration: " << gsm_.registration_state << ", " |
| 621 | << gsm_.network_id << ", " << gsm_.operator_name; |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 622 | } |
| 623 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 624 | void Cellular::HandleNewRegistrationState() { |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 625 | dispatcher()->PostTask( |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 626 | task_factory_.NewRunnableMethod( |
| 627 | &Cellular::HandleNewRegistrationStateTask)); |
| 628 | } |
| 629 | |
| 630 | void Cellular::HandleNewRegistrationStateTask() { |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 631 | VLOG(2) << __func__; |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 632 | const string network_tech = GetNetworkTechnologyString(); |
| 633 | if (network_tech.empty()) { |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 634 | if (state_ == kStateLinked) { |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 635 | manager()->DeregisterService(service_); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 636 | } |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 637 | service_ = NULL; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 638 | if (state_ == kStateLinked || |
| 639 | state_ == kStateConnected || |
| 640 | state_ == kStateRegistered) { |
| 641 | SetState(kStateEnabled); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 642 | } |
| 643 | return; |
| 644 | } |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 645 | if (state_ == kStateEnabled) { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 646 | SetState(kStateRegistered); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 647 | } |
| 648 | if (!service_.get()) { |
| 649 | // For now, no endpoint is created. Revisit if necessary. |
| 650 | CreateService(); |
| 651 | } |
| 652 | GetModemSignalQuality(); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 653 | if (state_ == kStateRegistered && modem_state_ == kModemStateConnected) { |
| 654 | SetState(kStateConnected); |
| 655 | EstablishLink(); |
| 656 | } |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 657 | service_->set_network_tech(network_tech); |
| 658 | service_->set_roaming_state(GetRoamingStateString()); |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 659 | // TODO(petkov): For GSM, update the serving operator based on the network id |
| 660 | // and the mobile provider database. |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | void Cellular::GetModemSignalQuality() { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 664 | VLOG(2) << __func__; |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 665 | uint32 strength = 0; |
| 666 | switch (type_) { |
| 667 | case kTypeGSM: |
| 668 | strength = GetGSMSignalQuality(); |
| 669 | break; |
| 670 | case kTypeCDMA: |
| 671 | strength = GetCDMASignalQuality(); |
| 672 | break; |
| 673 | default: NOTREACHED(); |
| 674 | } |
| 675 | HandleNewSignalQuality(strength); |
| 676 | } |
| 677 | |
| 678 | uint32 Cellular::GetCDMASignalQuality() { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 679 | VLOG(2) << __func__; |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 680 | CHECK_EQ(kTypeCDMA, type_); |
| 681 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 682 | return cdma_proxy_->GetSignalQuality(); |
| 683 | } |
| 684 | |
| 685 | uint32 Cellular::GetGSMSignalQuality() { |
Darin Petkov | 22b72bf | 2011-08-29 14:01:20 -0700 | [diff] [blame] | 686 | VLOG(2) << __func__; |
| 687 | CHECK_EQ(kTypeGSM, type_); |
| 688 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 689 | return gsm_network_proxy_->GetSignalQuality(); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | void Cellular::HandleNewSignalQuality(uint32 strength) { |
| 693 | VLOG(2) << "Signal strength: " << strength; |
| 694 | if (service_.get()) { |
| 695 | service_->set_strength(strength); |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | void Cellular::CreateService() { |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 700 | VLOG(2) << __func__; |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 701 | CHECK(!service_.get()); |
| 702 | service_ = |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 703 | new CellularService(control_interface(), dispatcher(), manager(), this); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 704 | switch (type_) { |
| 705 | case kTypeGSM: |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 706 | service_->set_activation_state(flimflam::kActivationStateActivated); |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 707 | // TODO(petkov): Set serving operator. |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 708 | break; |
| 709 | case kTypeCDMA: |
| 710 | service_->set_payment_url(cdma_.payment_url); |
| 711 | service_->set_usage_url(cdma_.usage_url); |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 712 | service_->set_serving_operator(home_provider_); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 713 | HandleNewCDMAActivationState(MM_MODEM_CDMA_ACTIVATION_ERROR_NO_ERROR); |
| 714 | break; |
| 715 | default: |
| 716 | NOTREACHED(); |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 717 | } |
Darin Petkov | f5f61e0 | 2011-07-29 11:35:40 -0700 | [diff] [blame] | 718 | } |
| 719 | |
Paul Stewart | fdd1607 | 2011-09-16 12:41:35 -0700 | [diff] [blame] | 720 | bool Cellular::TechnologyIs(const Technology::Identifier type) const { |
| 721 | return type == Technology::kCellular; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 722 | } |
| 723 | |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 724 | void Cellular::Connect(Error *error) { |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 725 | VLOG(2) << __func__; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 726 | if (state_ == kStateConnected || |
| 727 | state_ == kStateLinked) { |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 728 | LOG(ERROR) << "Already connected; connection request ignored."; |
| 729 | CHECK(error); |
| 730 | error->Populate(Error::kAlreadyConnected); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 731 | return; |
| 732 | } |
| 733 | CHECK_EQ(kStateRegistered, state_); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 734 | |
| 735 | if (!allow_roaming_ && |
| 736 | service_->roaming_state() == flimflam::kRoamingStateRoaming) { |
| 737 | LOG(ERROR) << "Roaming disallowed; connection request ignored."; |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 738 | CHECK(error); |
| 739 | error->Populate(Error::kNotOnHomeNetwork); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 740 | return; |
| 741 | } |
| 742 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 743 | DBusPropertiesMap properties; |
| 744 | const char *phone_number = NULL; |
| 745 | switch (type_) { |
| 746 | case kTypeGSM: |
| 747 | phone_number = kPhoneNumberGSM; |
| 748 | break; |
| 749 | case kTypeCDMA: |
| 750 | phone_number = kPhoneNumberCDMA; |
| 751 | break; |
| 752 | default: NOTREACHED(); |
| 753 | } |
| 754 | properties[kConnectPropertyPhoneNumber].writer().append_string(phone_number); |
| 755 | // TODO(petkov): Setup apn and "home_only". |
| 756 | |
| 757 | // Defer connect because we may be in a dbus-c++ callback. |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 758 | dispatcher()->PostTask( |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 759 | task_factory_.NewRunnableMethod(&Cellular::ConnectTask, properties)); |
| 760 | } |
| 761 | |
| 762 | void Cellular::ConnectTask(const DBusPropertiesMap &properties) { |
| 763 | VLOG(2) << __func__; |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 764 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 765 | simple_proxy_->Connect(properties); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 766 | SetState(kStateConnected); |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 767 | EstablishLink(); |
| 768 | } |
| 769 | |
| 770 | void Cellular::EstablishLink() { |
| 771 | VLOG(2) << __func__; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 772 | CHECK_EQ(kStateConnected, state_); |
| 773 | unsigned int flags = 0; |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 774 | if (manager()->device_info()->GetFlags(interface_index(), &flags) && |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 775 | (flags & IFF_UP) != 0) { |
| 776 | LinkEvent(flags, IFF_UP); |
| 777 | return; |
| 778 | } |
| 779 | // TODO(petkov): Provide a timeout for a failed link-up request. |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 780 | rtnl_handler()->SetInterfaceFlags(interface_index(), IFF_UP, IFF_UP); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | void Cellular::LinkEvent(unsigned int flags, unsigned int change) { |
| 784 | Device::LinkEvent(flags, change); |
| 785 | if ((flags & IFF_UP) != 0 && state_ == kStateConnected) { |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 786 | LOG(INFO) << link_name() << " is up."; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 787 | SetState(kStateLinked); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 788 | manager()->RegisterService(service_); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 789 | // TODO(petkov): For GSM, remember the APN. |
Darin Petkov | 60b8c3b | 2011-08-25 11:03:20 -0700 | [diff] [blame] | 790 | if (AcquireDHCPConfig()) { |
| 791 | SelectService(service_); |
| 792 | SetServiceState(Service::kStateConfiguring); |
| 793 | } else { |
| 794 | LOG(ERROR) << "Unable to acquire DHCP config."; |
| 795 | } |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 796 | } else if ((flags & IFF_UP) == 0 && state_ == kStateLinked) { |
| 797 | SetState(kStateConnected); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 798 | manager()->DeregisterService(service_); |
Darin Petkov | 60b8c3b | 2011-08-25 11:03:20 -0700 | [diff] [blame] | 799 | SelectService(NULL); |
Darin Petkov | 77cb681 | 2011-08-15 16:19:41 -0700 | [diff] [blame] | 800 | DestroyIPConfig(); |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 801 | } |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 802 | } |
| 803 | |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 804 | void Cellular::Scan(Error *error) { |
| 805 | VLOG(2) << __func__; |
| 806 | if (type_ != kTypeGSM) { |
| 807 | const string kMessage = "Network scanning support for GSM only."; |
| 808 | LOG(ERROR) << kMessage; |
| 809 | CHECK(error); |
| 810 | error->Populate(Error::kNotSupported, kMessage); |
| 811 | return; |
| 812 | } |
| 813 | // Defer scan because we may be in a dbus-c++ callback. |
| 814 | dispatcher()->PostTask( |
| 815 | task_factory_.NewRunnableMethod(&Cellular::ScanTask)); |
| 816 | } |
| 817 | |
| 818 | void Cellular::ScanTask() { |
| 819 | VLOG(2) << __func__; |
| 820 | // TODO(petkov): Defer scan requests if a scan is in progress already. |
| 821 | CHECK_EQ(kTypeGSM, type_); |
| 822 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). This is a |
| 823 | // must for this call which is basically a stub at this point. |
| 824 | ModemGSMNetworkProxyInterface::ScanResults results = |
| 825 | gsm_network_proxy_->Scan(); |
| 826 | found_networks_.clear(); |
| 827 | for (ModemGSMNetworkProxyInterface::ScanResults::const_iterator it = |
| 828 | results.begin(); it != results.end(); ++it) { |
| 829 | found_networks_.push_back(ParseScanResult(*it)); |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | Stringmap Cellular::ParseScanResult( |
| 834 | const ModemGSMNetworkProxyInterface::ScanResult &result) { |
| 835 | Stringmap parsed; |
| 836 | for (ModemGSMNetworkProxyInterface::ScanResult::const_iterator it = |
| 837 | result.begin(); it != result.end(); ++it) { |
| 838 | // TODO(petkov): Define these in system_api/service_constants.h. The |
| 839 | // numerical values are taken from 3GPP TS 27.007 Section 7.3. |
| 840 | static const char * const kStatusString[] = { |
| 841 | "unknown", |
| 842 | "available", |
| 843 | "current", |
| 844 | "forbidden", |
| 845 | }; |
| 846 | // TODO(petkov): Do we need the finer level of granularity here or can we |
| 847 | // use the same granularity as GetNetworkTechnologyString (e.g., |
| 848 | // HSDPA->"HSPA"). |
| 849 | static const char * const kTechnologyString[] = { |
| 850 | flimflam::kNetworkTechnologyGsm, |
| 851 | "GSM Compact", |
| 852 | flimflam::kNetworkTechnologyUmts, |
| 853 | flimflam::kNetworkTechnologyEdge, |
| 854 | "HSDPA", |
| 855 | "HSUPA", |
| 856 | flimflam::kNetworkTechnologyHspa, |
| 857 | }; |
| 858 | VLOG(2) << "Network property: " << it->first << " = " << it->second; |
| 859 | if (it->first == kNetworkPropertyStatus) { |
| 860 | int status = 0; |
| 861 | if (base::StringToInt(it->second, &status) && |
| 862 | status >= 0 && |
| 863 | status < static_cast<int>(arraysize(kStatusString))) { |
| 864 | parsed[flimflam::kStatusProperty] = kStatusString[status]; |
| 865 | } else { |
| 866 | LOG(ERROR) << "Unexpected status value: " << it->second; |
| 867 | } |
| 868 | } else if (it->first == kNetworkPropertyID) { |
| 869 | parsed[flimflam::kNetworkIdProperty] = it->second; |
| 870 | } else if (it->first == kNetworkPropertyLongName) { |
| 871 | parsed[flimflam::kLongNameProperty] = it->second; |
| 872 | } else if (it->first == kNetworkPropertyShortName) { |
| 873 | parsed[flimflam::kShortNameProperty] = it->second; |
| 874 | } else if (it->first == kNetworkPropertyAccessTechnology) { |
| 875 | int tech = 0; |
| 876 | if (base::StringToInt(it->second, &tech) && |
| 877 | tech >= 0 && |
| 878 | tech < static_cast<int>(arraysize(kTechnologyString))) { |
| 879 | parsed[flimflam::kTechnologyProperty] = kTechnologyString[tech]; |
| 880 | } else { |
| 881 | LOG(ERROR) << "Unexpected technology value: " << it->second; |
| 882 | } |
| 883 | } else { |
| 884 | LOG(WARNING) << "Unknown network property ignored: " << it->first; |
| 885 | } |
| 886 | } |
| 887 | // TODO(petkov): If long name is not set and there's a network ID, do a mobile |
| 888 | // database lookup (crosbug.com/19699). |
| 889 | return parsed; |
| 890 | } |
| 891 | |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 892 | void Cellular::Activate(const string &carrier, Error *error) { |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 893 | VLOG(2) << __func__ << "(" << carrier << ")"; |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 894 | if (type_ != kTypeCDMA) { |
| 895 | const string kMessage = "Unable to activate non-CDMA modem."; |
| 896 | LOG(ERROR) << kMessage; |
| 897 | CHECK(error); |
| 898 | error->Populate(Error::kInvalidArguments, kMessage); |
| 899 | return; |
| 900 | } |
| 901 | if (state_ != kStateEnabled && |
| 902 | state_ != kStateRegistered) { |
| 903 | const string kMessage = "Unable to activate in " + GetStateString(state_); |
| 904 | LOG(ERROR) << kMessage; |
| 905 | CHECK(error); |
| 906 | error->Populate(Error::kInvalidArguments, kMessage); |
| 907 | return; |
| 908 | } |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 909 | // Defer connect because we may be in a dbus-c++ callback. |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 910 | dispatcher()->PostTask( |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 911 | task_factory_.NewRunnableMethod(&Cellular::ActivateTask, carrier)); |
| 912 | } |
| 913 | |
| 914 | void Cellular::ActivateTask(const string &carrier) { |
| 915 | VLOG(2) << __func__ << "(" << carrier << ")"; |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 916 | CHECK_EQ(kTypeCDMA, type_); |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 917 | if (state_ != kStateEnabled && |
| 918 | state_ != kStateRegistered) { |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 919 | LOG(ERROR) << "Unable to activate in " << GetStateString(state_); |
| 920 | return; |
| 921 | } |
| 922 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 923 | uint32 status = cdma_proxy_->Activate(carrier); |
| 924 | if (status == MM_MODEM_CDMA_ACTIVATION_ERROR_NO_ERROR) { |
| 925 | cdma_.activation_state = MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING; |
| 926 | } |
| 927 | HandleNewCDMAActivationState(status); |
| 928 | } |
| 929 | |
| 930 | void Cellular::HandleNewCDMAActivationState(uint32 error) { |
| 931 | if (!service_.get()) { |
| 932 | return; |
| 933 | } |
| 934 | service_->set_activation_state( |
| 935 | GetCDMAActivationStateString(cdma_.activation_state)); |
Darin Petkov | 5148900 | 2011-08-18 13:13:20 -0700 | [diff] [blame] | 936 | service_->set_error(GetCDMAActivationErrorString(error)); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 937 | } |
| 938 | |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 939 | void Cellular::OnCDMAActivationStateChanged( |
| 940 | uint32 activation_state, |
| 941 | uint32 activation_error, |
| 942 | const DBusPropertiesMap &status_changes) { |
| 943 | CHECK_EQ(kTypeCDMA, type_); |
| 944 | DBusProperties::GetString(status_changes, "mdn", &mdn_); |
| 945 | DBusProperties::GetString(status_changes, "min", &min_); |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 946 | if (DBusProperties::GetString( |
| 947 | status_changes, "payment_url", &cdma_.payment_url) && |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 948 | service_.get()) { |
Darin Petkov | cc04442 | 2011-08-17 13:30:06 -0700 | [diff] [blame] | 949 | service_->set_payment_url(cdma_.payment_url); |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 950 | } |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 951 | cdma_.activation_state = activation_state; |
| 952 | HandleNewCDMAActivationState(activation_error); |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 953 | } |
| 954 | |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 955 | void Cellular::OnCDMARegistrationStateChanged(uint32 state_1x, |
| 956 | uint32 state_evdo) { |
| 957 | CHECK_EQ(kTypeCDMA, type_); |
| 958 | cdma_.registration_state_1x = state_1x; |
| 959 | cdma_.registration_state_evdo = state_evdo; |
| 960 | HandleNewRegistrationState(); |
| 961 | } |
| 962 | |
| 963 | void Cellular::OnCDMASignalQualityChanged(uint32 strength) { |
| 964 | CHECK_EQ(kTypeCDMA, type_); |
| 965 | HandleNewSignalQuality(strength); |
| 966 | } |
| 967 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 968 | void Cellular::OnGSMNetworkModeChanged(uint32 /*mode*/) { |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 969 | // TODO(petkov): Implement this. |
| 970 | NOTIMPLEMENTED(); |
| 971 | } |
| 972 | |
| 973 | void Cellular::OnGSMRegistrationInfoChanged(uint32 status, |
| 974 | const string &operator_code, |
| 975 | const string &operator_name) { |
Darin Petkov | 9bac6fe | 2011-08-26 12:49:05 -0700 | [diff] [blame] | 976 | CHECK_EQ(kTypeGSM, type_); |
| 977 | gsm_.registration_state = status; |
| 978 | gsm_.network_id = operator_code; |
| 979 | gsm_.operator_name = operator_name; |
| 980 | HandleNewRegistrationState(); |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | void Cellular::OnGSMSignalQualityChanged(uint32 quality) { |
Darin Petkov | 22b72bf | 2011-08-29 14:01:20 -0700 | [diff] [blame] | 984 | CHECK_EQ(kTypeGSM, type_); |
| 985 | HandleNewSignalQuality(quality); |
Darin Petkov | a1e0a1c | 2011-08-25 15:08:33 -0700 | [diff] [blame] | 986 | } |
| 987 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 988 | void Cellular::OnModemStateChanged(uint32 /*old_state*/, |
| 989 | uint32 /*new_state*/, |
| 990 | uint32 /*reason*/) { |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 991 | // TODO(petkov): Implement this. |
| 992 | NOTIMPLEMENTED(); |
| 993 | } |
| 994 | |
Darin Petkov | 48a511a | 2011-09-15 10:33:37 -0700 | [diff] [blame] | 995 | void Cellular::SetGSMAccessTechnology(uint32 access_technology) { |
| 996 | CHECK_EQ(kTypeGSM, type_); |
| 997 | gsm_.access_technology = access_technology; |
| 998 | if (service_.get()) { |
| 999 | service_->set_network_tech(GetNetworkTechnologyString()); |
| 1000 | } |
| 1001 | } |
| 1002 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 1003 | StrIntPair Cellular::SimLockStatusToProperty() { |
| 1004 | return StrIntPair(make_pair(flimflam::kSIMLockTypeProperty, |
| 1005 | sim_lock_status_.lock_type), |
| 1006 | make_pair(flimflam::kSIMLockRetriesLeftProperty, |
| 1007 | sim_lock_status_.retries_left)); |
| 1008 | } |
| 1009 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 1010 | void Cellular::HelpRegisterDerivedStrIntPair( |
| 1011 | const string &name, |
| 1012 | StrIntPair(Cellular::*get)(void), |
| 1013 | bool(Cellular::*set)(const StrIntPair&)) { |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 1014 | mutable_store()->RegisterDerivedStrIntPair( |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 1015 | name, |
| 1016 | StrIntPairAccessor( |
| 1017 | new CustomAccessor<Cellular, StrIntPair>(this, get, set))); |
| 1018 | } |
| 1019 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 1020 | } // namespace shill |