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