Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "shill/cellular_capability_universal.h" |
| 6 | |
| 7 | #include <base/bind.h> |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 8 | #include <base/stl_util.h> |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 9 | #include <base/stringprintf.h> |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 10 | #include <base/string_util.h> |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 11 | #include <chromeos/dbus/service_constants.h> |
| 12 | #include <mobile_provider.h> |
Ben Chan | 5c853ef | 2012-10-05 00:05:37 -0700 | [diff] [blame] | 13 | #include <ModemManager/ModemManager.h> |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 14 | |
| 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
| 18 | #include "shill/adaptor_interfaces.h" |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 19 | #include "shill/cellular_operator_info.h" |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 20 | #include "shill/cellular_service.h" |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 21 | #include "shill/dbus_properties_proxy_interface.h" |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 22 | #include "shill/error.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 23 | #include "shill/logging.h" |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 24 | #include "shill/property_accessor.h" |
| 25 | #include "shill/proxy_factory.h" |
| 26 | |
| 27 | #ifdef MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN |
| 28 | #error "Do not include mm-modem.h" |
| 29 | #endif |
| 30 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 31 | using base::Bind; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 32 | using base::Closure; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 33 | using std::string; |
| 34 | using std::vector; |
| 35 | |
| 36 | namespace shill { |
| 37 | |
| 38 | // static |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 39 | const char CellularCapabilityUniversal::kConnectPin[] = "pin"; |
| 40 | const char CellularCapabilityUniversal::kConnectOperatorId[] = "operator-id"; |
| 41 | const char CellularCapabilityUniversal::kConnectBands[] = "bands"; |
| 42 | const char CellularCapabilityUniversal::kConnectAllowedModes[] = |
| 43 | "allowed-modes"; |
| 44 | const char CellularCapabilityUniversal::kConnectPreferredMode[] = |
| 45 | "preferred-mode"; |
| 46 | const char CellularCapabilityUniversal::kConnectApn[] = "apn"; |
| 47 | const char CellularCapabilityUniversal::kConnectIPType[] = "ip-type"; |
| 48 | const char CellularCapabilityUniversal::kConnectUser[] = "user"; |
| 49 | const char CellularCapabilityUniversal::kConnectPassword[] = "password"; |
| 50 | const char CellularCapabilityUniversal::kConnectNumber[] = "number"; |
| 51 | const char CellularCapabilityUniversal::kConnectAllowRoaming[] = |
| 52 | "allow-roaming"; |
| 53 | const char CellularCapabilityUniversal::kConnectRMProtocol[] = "rm-protocol"; |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 54 | const char CellularCapabilityUniversal::kStatusProperty[] = "status"; |
| 55 | const char CellularCapabilityUniversal::kOperatorLongProperty[] = |
| 56 | "operator-long"; |
| 57 | const char CellularCapabilityUniversal::kOperatorShortProperty[] = |
| 58 | "operator-short"; |
| 59 | const char CellularCapabilityUniversal::kOperatorCodeProperty[] = |
| 60 | "operator-code"; |
| 61 | const char CellularCapabilityUniversal::kOperatorAccessTechnologyProperty[] = |
| 62 | "access-technology"; |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 63 | const char CellularCapabilityUniversal::kE362ModelId[] = "E362 WWAN"; |
| 64 | unsigned int CellularCapabilityUniversal::friendly_service_name_id_ = 0; |
| 65 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 66 | |
| 67 | static const char kPhoneNumber[] = "*99#"; |
| 68 | |
| 69 | static string AccessTechnologyToString(uint32 access_technologies) { |
| 70 | if (access_technologies & MM_MODEM_ACCESS_TECHNOLOGY_LTE) |
| 71 | return flimflam::kNetworkTechnologyLte; |
| 72 | if (access_technologies & (MM_MODEM_ACCESS_TECHNOLOGY_EVDO0 | |
| 73 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA | |
| 74 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB)) |
| 75 | return flimflam::kNetworkTechnologyEvdo; |
| 76 | if (access_technologies & MM_MODEM_ACCESS_TECHNOLOGY_1XRTT) |
| 77 | return flimflam::kNetworkTechnology1Xrtt; |
| 78 | if (access_technologies & MM_MODEM_ACCESS_TECHNOLOGY_HSPA_PLUS) |
| 79 | return flimflam::kNetworkTechnologyHspaPlus; |
| 80 | if (access_technologies & (MM_MODEM_ACCESS_TECHNOLOGY_HSPA | |
| 81 | MM_MODEM_ACCESS_TECHNOLOGY_HSUPA | |
| 82 | MM_MODEM_ACCESS_TECHNOLOGY_HSDPA)) |
| 83 | return flimflam::kNetworkTechnologyHspa; |
| 84 | if (access_technologies & MM_MODEM_ACCESS_TECHNOLOGY_UMTS) |
| 85 | return flimflam::kNetworkTechnologyUmts; |
| 86 | if (access_technologies & MM_MODEM_ACCESS_TECHNOLOGY_EDGE) |
| 87 | return flimflam::kNetworkTechnologyEdge; |
| 88 | if (access_technologies & MM_MODEM_ACCESS_TECHNOLOGY_GPRS) |
| 89 | return flimflam::kNetworkTechnologyGprs; |
| 90 | if (access_technologies & (MM_MODEM_ACCESS_TECHNOLOGY_GSM_COMPACT | |
| 91 | MM_MODEM_ACCESS_TECHNOLOGY_GSM)) |
| 92 | return flimflam::kNetworkTechnologyGsm; |
| 93 | return ""; |
| 94 | } |
| 95 | |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 96 | static string AccessTechnologyToTechnologyFamily(uint32 access_technologies) { |
| 97 | if (access_technologies & (MM_MODEM_ACCESS_TECHNOLOGY_LTE | |
| 98 | MM_MODEM_ACCESS_TECHNOLOGY_HSPA_PLUS | |
| 99 | MM_MODEM_ACCESS_TECHNOLOGY_HSPA | |
| 100 | MM_MODEM_ACCESS_TECHNOLOGY_HSUPA | |
| 101 | MM_MODEM_ACCESS_TECHNOLOGY_HSDPA | |
| 102 | MM_MODEM_ACCESS_TECHNOLOGY_UMTS | |
| 103 | MM_MODEM_ACCESS_TECHNOLOGY_EDGE | |
| 104 | MM_MODEM_ACCESS_TECHNOLOGY_GPRS | |
| 105 | MM_MODEM_ACCESS_TECHNOLOGY_GSM_COMPACT | |
| 106 | MM_MODEM_ACCESS_TECHNOLOGY_GSM)) |
| 107 | return flimflam::kTechnologyFamilyGsm; |
| 108 | if (access_technologies & (MM_MODEM_ACCESS_TECHNOLOGY_EVDO0 | |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 109 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA | |
| 110 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB | |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 111 | MM_MODEM_ACCESS_TECHNOLOGY_1XRTT)) |
| 112 | return flimflam::kTechnologyFamilyCdma; |
| 113 | return ""; |
| 114 | } |
| 115 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 116 | CellularCapabilityUniversal::CellularCapabilityUniversal( |
| 117 | Cellular *cellular, |
| 118 | ProxyFactory *proxy_factory) |
| 119 | : CellularCapability(cellular, proxy_factory), |
| 120 | weak_ptr_factory_(this), |
| 121 | registration_state_(MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN), |
| 122 | cdma_registration_state_(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN), |
Darin Petkov | e636c69 | 2012-05-31 10:22:17 +0200 | [diff] [blame] | 123 | capabilities_(MM_MODEM_CAPABILITY_NONE), |
| 124 | current_capabilities_(MM_MODEM_CAPABILITY_NONE), |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 125 | access_technologies_(MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN), |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 126 | supported_modes_(MM_MODEM_MODE_NONE), |
| 127 | allowed_modes_(MM_MODEM_MODE_NONE), |
| 128 | preferred_mode_(MM_MODEM_MODE_NONE), |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 129 | home_provider_(NULL), |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 130 | provider_requires_roaming_(false), |
Ben Chan | 5d0d32c | 2013-01-08 02:05:29 -0800 | [diff] [blame] | 131 | resetting_(false), |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 132 | scanning_supported_(true), |
| 133 | scanning_(false), |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 134 | scan_interval_(0), |
| 135 | sim_present_(false) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 136 | SLOG(Cellular, 2) << "Cellular capability constructed: Universal"; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 137 | PropertyStore *store = cellular->mutable_store(); |
| 138 | |
| 139 | store->RegisterConstString(flimflam::kCarrierProperty, &carrier_); |
| 140 | store->RegisterConstBool(flimflam::kSupportNetworkScanProperty, |
| 141 | &scanning_supported_); |
| 142 | store->RegisterConstString(flimflam::kEsnProperty, &esn_); |
| 143 | store->RegisterConstString(flimflam::kFirmwareRevisionProperty, |
| 144 | &firmware_revision_); |
| 145 | store->RegisterConstString(flimflam::kHardwareRevisionProperty, |
| 146 | &hardware_revision_); |
| 147 | store->RegisterConstString(flimflam::kImeiProperty, &imei_); |
| 148 | store->RegisterConstString(flimflam::kImsiProperty, &imsi_); |
Ben Chan | a5e2708 | 2012-07-31 14:30:28 -0700 | [diff] [blame] | 149 | store->RegisterConstString(flimflam::kIccidProperty, &sim_identifier_); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 150 | store->RegisterConstString(flimflam::kManufacturerProperty, &manufacturer_); |
| 151 | store->RegisterConstString(flimflam::kMdnProperty, &mdn_); |
| 152 | store->RegisterConstString(flimflam::kMeidProperty, &meid_); |
| 153 | store->RegisterConstString(flimflam::kMinProperty, &min_); |
| 154 | store->RegisterConstString(flimflam::kModelIDProperty, &model_id_); |
| 155 | store->RegisterConstString(flimflam::kSelectedNetworkProperty, |
| 156 | &selected_network_); |
| 157 | store->RegisterConstStringmaps(flimflam::kFoundNetworksProperty, |
| 158 | &found_networks_); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 159 | store->RegisterConstBool(shill::kProviderRequiresRoamingProperty, |
| 160 | &provider_requires_roaming_); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 161 | store->RegisterConstBool(flimflam::kScanningProperty, &scanning_); |
| 162 | store->RegisterUint16(flimflam::kScanIntervalProperty, &scan_interval_); |
| 163 | HelpRegisterDerivedKeyValueStore( |
| 164 | flimflam::kSIMLockStatusProperty, |
| 165 | &CellularCapabilityUniversal::SimLockStatusToProperty, |
| 166 | NULL); |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 167 | store->RegisterConstBool(shill::kSIMPresentProperty, &sim_present_); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 168 | store->RegisterConstStringmaps(flimflam::kCellularApnListProperty, |
| 169 | &apn_list_); |
| 170 | } |
| 171 | |
| 172 | KeyValueStore CellularCapabilityUniversal::SimLockStatusToProperty( |
| 173 | Error */*error*/) { |
| 174 | KeyValueStore status; |
| 175 | status.SetBool(flimflam::kSIMLockEnabledProperty, sim_lock_status_.enabled); |
| 176 | status.SetString(flimflam::kSIMLockTypeProperty, sim_lock_status_.lock_type); |
| 177 | status.SetUint(flimflam::kSIMLockRetriesLeftProperty, |
| 178 | sim_lock_status_.retries_left); |
| 179 | return status; |
| 180 | } |
| 181 | |
| 182 | void CellularCapabilityUniversal::HelpRegisterDerivedKeyValueStore( |
| 183 | const string &name, |
| 184 | KeyValueStore(CellularCapabilityUniversal::*get)(Error *error), |
| 185 | void(CellularCapabilityUniversal::*set)( |
| 186 | const KeyValueStore &value, Error *error)) { |
| 187 | cellular()->mutable_store()->RegisterDerivedKeyValueStore( |
| 188 | name, |
| 189 | KeyValueStoreAccessor( |
| 190 | new CustomAccessor<CellularCapabilityUniversal, KeyValueStore>( |
| 191 | this, get, set))); |
| 192 | } |
| 193 | |
| 194 | void CellularCapabilityUniversal::InitProxies() { |
| 195 | modem_3gpp_proxy_.reset( |
| 196 | proxy_factory()->CreateMM1ModemModem3gppProxy(cellular()->dbus_path(), |
| 197 | cellular()->dbus_owner())); |
| 198 | modem_cdma_proxy_.reset( |
| 199 | proxy_factory()->CreateMM1ModemModemCdmaProxy(cellular()->dbus_path(), |
| 200 | cellular()->dbus_owner())); |
| 201 | modem_proxy_.reset( |
| 202 | proxy_factory()->CreateMM1ModemProxy(cellular()->dbus_path(), |
| 203 | cellular()->dbus_owner())); |
| 204 | modem_simple_proxy_.reset( |
| 205 | proxy_factory()->CreateMM1ModemSimpleProxy(cellular()->dbus_path(), |
| 206 | cellular()->dbus_owner())); |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 207 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 208 | modem_proxy_->set_state_changed_callback( |
| 209 | Bind(&CellularCapabilityUniversal::OnModemStateChangedSignal, |
| 210 | weak_ptr_factory_.GetWeakPtr())); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 211 | // Do not create a SIM proxy until the device is enabled because we |
| 212 | // do not yet know the object path of the sim object. |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 213 | // TODO(jglasgow): register callbacks |
| 214 | } |
| 215 | |
| 216 | void CellularCapabilityUniversal::StartModem(Error *error, |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 217 | const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 218 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 219 | InitProxies(); |
| 220 | |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 221 | // ModemManager must be in the disabled state to accept the Enable command. |
| 222 | Cellular::ModemState state = |
| 223 | static_cast<Cellular::ModemState>(modem_proxy_->State()); |
| 224 | if (state == Cellular::kModemStateDisabled) { |
| 225 | EnableModem(error, callback); |
| 226 | } else if (!cellular()->IsUnderlyingDeviceEnabled()) { |
| 227 | SLOG(Cellular, 2) << "Enabling of modem deferred because state is " |
| 228 | << state; |
| 229 | deferred_enable_modem_callback_ = |
| 230 | Bind(&CellularCapabilityUniversal::EnableModem, |
| 231 | weak_ptr_factory_.GetWeakPtr(), static_cast<Error *>(NULL), |
| 232 | callback); |
| 233 | } else { |
Arman Uguray | 403fad4 | 2012-09-25 17:08:39 -0700 | [diff] [blame] | 234 | // Call GetProperties() here to sync up with the modem state |
| 235 | GetProperties(); |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 236 | callback.Run(*error); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | void CellularCapabilityUniversal::EnableModem(Error *error, |
| 241 | const ResultCallback &callback) { |
| 242 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 243 | CHECK(!callback.is_null()); |
Thieu Le | e3b3659 | 2012-08-30 17:50:26 -0700 | [diff] [blame] | 244 | Error local_error(Error::kOperationInitiated); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 245 | modem_proxy_->Enable( |
| 246 | true, |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 247 | &local_error, |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 248 | Bind(&CellularCapabilityUniversal::Start_EnableModemCompleted, |
| 249 | weak_ptr_factory_.GetWeakPtr(), callback), |
| 250 | kTimeoutEnable); |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 251 | if (local_error.IsFailure()) { |
| 252 | SLOG(Cellular, 2) << __func__ << "Call to modem_proxy_->Enable() failed"; |
| 253 | callback.Run(local_error); |
| 254 | } |
| 255 | if (error) { |
| 256 | error->CopyFrom(local_error); |
| 257 | } |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | void CellularCapabilityUniversal::Start_EnableModemCompleted( |
| 261 | const ResultCallback &callback, const Error &error) { |
Eric Shienbrood | 9b1bd7b | 2012-04-20 16:42:26 -0400 | [diff] [blame] | 262 | SLOG(Cellular, 2) << __func__ << ": " << error; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 263 | if (error.IsFailure()) { |
| 264 | callback.Run(error); |
| 265 | return; |
| 266 | } |
| 267 | |
| 268 | // After modem is enabled, it should be possible to get properties |
| 269 | // TODO(jglasgow): handle errors from GetProperties |
| 270 | GetProperties(); |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 271 | callback.Run(error); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | void CellularCapabilityUniversal::StopModem(Error *error, |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 275 | const ResultCallback &callback) { |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 276 | CHECK(!callback.is_null()); |
| 277 | CHECK(error); |
Thieu Le | d001205 | 2012-07-25 16:09:09 -0700 | [diff] [blame] | 278 | Cellular::ModemState state = cellular()->modem_state(); |
| 279 | SLOG(Cellular, 2) << __func__ << "(" << state << ")"; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 280 | |
Thieu Le | d001205 | 2012-07-25 16:09:09 -0700 | [diff] [blame] | 281 | if (cellular()->IsModemRegistered()) { |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 282 | string all_bearers("/"); // "/" means all bearers. See Modemanager docs. |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 283 | modem_simple_proxy_->Disconnect( |
| 284 | all_bearers, |
| 285 | error, |
| 286 | Bind(&CellularCapabilityUniversal::Stop_DisconnectCompleted, |
| 287 | weak_ptr_factory_.GetWeakPtr(), callback), |
Thieu Le | 049adb5 | 2012-11-12 17:14:51 -0800 | [diff] [blame] | 288 | kTimeoutDisconnect); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 289 | if (error->IsFailure()) |
| 290 | callback.Run(*error); |
| 291 | } else { |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 292 | Closure task = Bind(&CellularCapabilityUniversal::Stop_Disable, |
| 293 | weak_ptr_factory_.GetWeakPtr(), |
| 294 | callback); |
| 295 | cellular()->dispatcher()->PostTask(task); |
| 296 | } |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 297 | deferred_enable_modem_callback_.Reset(); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | void CellularCapabilityUniversal::Stop_DisconnectCompleted( |
| 301 | const ResultCallback &callback, const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 302 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 303 | |
| 304 | LOG_IF(ERROR, error.IsFailure()) << "Disconnect failed. Ignoring."; |
| 305 | Stop_Disable(callback); |
| 306 | } |
| 307 | |
| 308 | void CellularCapabilityUniversal::Stop_Disable(const ResultCallback &callback) { |
| 309 | Error error; |
| 310 | modem_proxy_->Enable( |
| 311 | false, &error, |
| 312 | Bind(&CellularCapabilityUniversal::Stop_DisableCompleted, |
| 313 | weak_ptr_factory_.GetWeakPtr(), callback), |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 314 | kTimeoutEnable); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 315 | if (error.IsFailure()) |
| 316 | callback.Run(error); |
| 317 | } |
| 318 | |
| 319 | void CellularCapabilityUniversal::Stop_DisableCompleted( |
| 320 | const ResultCallback &callback, const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 321 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 322 | |
| 323 | if (error.IsSuccess()) |
| 324 | ReleaseProxies(); |
| 325 | callback.Run(error); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | void CellularCapabilityUniversal::Connect(const DBusPropertiesMap &properties, |
| 329 | Error *error, |
| 330 | const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 331 | SLOG(Cellular, 2) << __func__; |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 332 | DBusPathCallback cb = Bind(&CellularCapabilityUniversal::OnConnectReply, |
| 333 | weak_ptr_factory_.GetWeakPtr(), |
| 334 | callback); |
| 335 | modem_simple_proxy_->Connect(properties, error, cb, kTimeoutConnect); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | void CellularCapabilityUniversal::Disconnect(Error *error, |
| 339 | const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 340 | SLOG(Cellular, 2) << __func__; |
Thieu Le | 5d6864a | 2012-07-20 11:43:51 -0700 | [diff] [blame] | 341 | if (bearer_path_.empty()) { |
| 342 | LOG(WARNING) << "In " << __func__ << "(): " |
| 343 | << "Ignoring attempt to disconnect without bearer"; |
Thieu Le | 3d27539 | 2012-07-20 15:32:58 -0700 | [diff] [blame] | 344 | } else if (modem_simple_proxy_.get()) { |
Thieu Le | 5d6864a | 2012-07-20 11:43:51 -0700 | [diff] [blame] | 345 | modem_simple_proxy_->Disconnect(bearer_path_, |
| 346 | error, |
| 347 | callback, |
Thieu Le | 049adb5 | 2012-11-12 17:14:51 -0800 | [diff] [blame] | 348 | kTimeoutDisconnect); |
Thieu Le | 5d6864a | 2012-07-20 11:43:51 -0700 | [diff] [blame] | 349 | } |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 350 | } |
| 351 | |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 352 | void CellularCapabilityUniversal::DisconnectCleanup() { |
| 353 | SLOG(Cellular, 2) << __func__; |
| 354 | } |
| 355 | |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 356 | void CellularCapabilityUniversal::Activate(const string &carrier, |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 357 | Error *error, |
| 358 | const ResultCallback &callback) { |
| 359 | OnUnsupportedOperation(__func__, error); |
| 360 | } |
| 361 | |
| 362 | void CellularCapabilityUniversal::ReleaseProxies() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 363 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 364 | modem_3gpp_proxy_.reset(); |
| 365 | modem_cdma_proxy_.reset(); |
| 366 | modem_proxy_.reset(); |
| 367 | modem_simple_proxy_.reset(); |
| 368 | sim_proxy_.reset(); |
| 369 | } |
| 370 | |
| 371 | void CellularCapabilityUniversal::OnServiceCreated() { |
| 372 | // If IMSI is available, base the service's storage identifier on it. |
| 373 | if (!imsi_.empty()) { |
| 374 | cellular()->service()->SetStorageIdentifier( |
| 375 | string(flimflam::kTypeCellular) + "_" + |
| 376 | cellular()->address() + "_" + imsi_); |
| 377 | } |
Ben Chan | 3d6de0e | 2012-12-10 12:01:34 -0800 | [diff] [blame] | 378 | bool activation_required = IsServiceActivationRequired(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 379 | cellular()->service()->SetActivationState( |
Ben Chan | 3d6de0e | 2012-12-10 12:01:34 -0800 | [diff] [blame] | 380 | activation_required ? |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 381 | flimflam::kActivationStateNotActivated : |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 382 | flimflam::kActivationStateActivated); |
Ben Chan | 3d6de0e | 2012-12-10 12:01:34 -0800 | [diff] [blame] | 383 | // TODO(benchan): For now, assume the cellular service is activated over |
| 384 | // a non-cellular network if service activation is required (i.e. a |
| 385 | // corresponding entry is found in the cellular operator info file). |
| 386 | // We will need to generalize this logic when migrating CDMA support from |
| 387 | // cromo to ModemManager. |
| 388 | cellular()->service()->SetActivateOverNonCellularNetwork(activation_required); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 389 | UpdateServingOperator(); |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 390 | UpdateOLP(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 391 | } |
| 392 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 393 | // Create the list of APNs to try, in the following order: |
| 394 | // - last APN that resulted in a successful connection attempt on the |
| 395 | // current network (if any) |
| 396 | // - the APN, if any, that was set by the user |
| 397 | // - the list of APNs found in the mobile broadband provider DB for the |
| 398 | // home provider associated with the current SIM |
| 399 | // - as a last resort, attempt to connect with no APN |
| 400 | void CellularCapabilityUniversal::SetupApnTryList() { |
| 401 | apn_try_list_.clear(); |
| 402 | |
| 403 | DCHECK(cellular()->service().get()); |
| 404 | const Stringmap *apn_info = cellular()->service()->GetLastGoodApn(); |
| 405 | if (apn_info) |
| 406 | apn_try_list_.push_back(*apn_info); |
| 407 | |
| 408 | apn_info = cellular()->service()->GetUserSpecifiedApn(); |
| 409 | if (apn_info) |
| 410 | apn_try_list_.push_back(*apn_info); |
| 411 | |
| 412 | apn_try_list_.insert(apn_try_list_.end(), apn_list_.begin(), apn_list_.end()); |
| 413 | } |
| 414 | |
| 415 | void CellularCapabilityUniversal::SetupConnectProperties( |
| 416 | DBusPropertiesMap *properties) { |
| 417 | SetupApnTryList(); |
| 418 | FillConnectPropertyMap(properties); |
| 419 | } |
| 420 | |
| 421 | void CellularCapabilityUniversal::FillConnectPropertyMap( |
| 422 | DBusPropertiesMap *properties) { |
| 423 | |
| 424 | // TODO(jglasgow): Is this really needed anymore? |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 425 | (*properties)[kConnectNumber].writer().append_string( |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 426 | kPhoneNumber); |
| 427 | |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 428 | (*properties)[kConnectAllowRoaming].writer().append_bool( |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 429 | AllowRoaming()); |
| 430 | |
| 431 | if (!apn_try_list_.empty()) { |
| 432 | // Leave the APN at the front of the list, so that it can be recorded |
| 433 | // if the connect attempt succeeds. |
| 434 | Stringmap apn_info = apn_try_list_.front(); |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 435 | SLOG(Cellular, 2) << __func__ << ": Using APN " |
| 436 | << apn_info[flimflam::kApnProperty]; |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 437 | (*properties)[kConnectApn].writer().append_string( |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 438 | apn_info[flimflam::kApnProperty].c_str()); |
| 439 | if (ContainsKey(apn_info, flimflam::kApnUsernameProperty)) |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 440 | (*properties)[kConnectUser].writer().append_string( |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 441 | apn_info[flimflam::kApnUsernameProperty].c_str()); |
| 442 | if (ContainsKey(apn_info, flimflam::kApnPasswordProperty)) |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 443 | (*properties)[kConnectPassword].writer().append_string( |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 444 | apn_info[flimflam::kApnPasswordProperty].c_str()); |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | void CellularCapabilityUniversal::OnConnectReply(const ResultCallback &callback, |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 449 | const DBus::Path &path, |
| 450 | const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 451 | SLOG(Cellular, 2) << __func__ << "(" << error << ")"; |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 452 | |
Jason Glasgow | 7234ec3 | 2012-05-23 16:01:21 -0400 | [diff] [blame] | 453 | CellularServiceRefPtr service = cellular()->service(); |
| 454 | if (!service) { |
| 455 | // The service could have been deleted before our Connect() request |
| 456 | // completes if the modem was enabled and then quickly disabled. |
| 457 | apn_try_list_.clear(); |
| 458 | } else if (error.IsFailure()) { |
| 459 | service->ClearLastGoodApn(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 460 | // The APN that was just tried (and failed) is still at the |
| 461 | // front of the list, about to be removed. If the list is empty |
| 462 | // after that, try one last time without an APN. This may succeed |
| 463 | // with some modems in some cases. |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 464 | if (RetriableConnectError(error) && !apn_try_list_.empty()) { |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 465 | apn_try_list_.pop_front(); |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 466 | SLOG(Cellular, 2) << "Connect failed with invalid APN, " |
| 467 | << apn_try_list_.size() << " remaining APNs to try"; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 468 | DBusPropertiesMap props; |
| 469 | FillConnectPropertyMap(&props); |
| 470 | Error error; |
| 471 | Connect(props, &error, callback); |
| 472 | return; |
| 473 | } |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 474 | } else { |
| 475 | if (!apn_try_list_.empty()) { |
Jason Glasgow | 7234ec3 | 2012-05-23 16:01:21 -0400 | [diff] [blame] | 476 | service->SetLastGoodApn(apn_try_list_.front()); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 477 | apn_try_list_.clear(); |
| 478 | } |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 479 | bearer_path_ = path; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | if (!callback.is_null()) |
| 483 | callback.Run(error); |
| 484 | } |
| 485 | |
| 486 | bool CellularCapabilityUniversal::AllowRoaming() { |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 487 | return provider_requires_roaming_ || allow_roaming_property(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 488 | } |
| 489 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 490 | void CellularCapabilityUniversal::GetProperties() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 491 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 492 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 493 | scoped_ptr<DBusPropertiesProxyInterface> properties_proxy( |
| 494 | proxy_factory()->CreateDBusPropertiesProxy(cellular()->dbus_path(), |
| 495 | cellular()->dbus_owner())); |
| 496 | DBusPropertiesMap properties( |
| 497 | properties_proxy->GetAll(MM_DBUS_INTERFACE_MODEM)); |
| 498 | OnModemPropertiesChanged(properties, vector<string>()); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 499 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 500 | properties = properties_proxy->GetAll(MM_DBUS_INTERFACE_MODEM_MODEM3GPP); |
| 501 | OnModem3GPPPropertiesChanged(properties, vector<string>()); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | string CellularCapabilityUniversal::CreateFriendlyServiceName() { |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 505 | SLOG(Cellular, 2) << __func__ << ": " << GetRoamingStateString(); |
Ben Chan | 092b12b | 2012-11-07 22:04:05 -0800 | [diff] [blame] | 506 | |
| 507 | // If |serving_operator_| does not have an operator ID, call |
| 508 | // UpdateOperatorInfo() to use |operator_id_| as a fallback when appropriate. |
| 509 | if (serving_operator_.GetCode().empty()) { |
| 510 | UpdateOperatorInfo(); |
| 511 | } |
| 512 | |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 513 | string name = serving_operator_.GetName(); |
| 514 | string home_provider_name = cellular()->home_provider().GetName(); |
| 515 | if (!name.empty()) { |
| 516 | // If roaming, try to show "<home-provider> | <serving-operator>", per 3GPP |
| 517 | // rules (TS 31.102 and annex A of 122.101). |
| 518 | if (registration_state_ == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING && |
| 519 | !home_provider_name.empty()) { |
| 520 | return home_provider_name + " | " + name; |
| 521 | } |
| 522 | return name; |
| 523 | } |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 524 | if (registration_state_ == MM_MODEM_3GPP_REGISTRATION_STATE_HOME && |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 525 | !home_provider_name.empty()) { |
| 526 | return home_provider_name; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 527 | } |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 528 | string serving_operator_code = serving_operator_.GetCode(); |
| 529 | if (!serving_operator_code.empty()) { |
| 530 | return "cellular_" + serving_operator_code; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 531 | } |
| 532 | return base::StringPrintf("GSMNetwork%u", friendly_service_name_id_++); |
| 533 | } |
| 534 | |
| 535 | void CellularCapabilityUniversal::SetHomeProvider() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 536 | SLOG(Cellular, 2) << __func__ << "(IMSI: " << imsi_ |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 537 | << " SPN: " << spn_ << ")"; |
| 538 | // TODO(petkov): The test for NULL provider_db should be done by |
| 539 | // mobile_provider_lookup_best_match. |
| 540 | if (imsi_.empty() || !cellular()->provider_db()) { |
| 541 | return; |
| 542 | } |
| 543 | mobile_provider *provider = |
| 544 | mobile_provider_lookup_best_match( |
| 545 | cellular()->provider_db(), spn_.c_str(), imsi_.c_str()); |
| 546 | if (!provider) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 547 | SLOG(Cellular, 2) << "GSM provider not found."; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 548 | return; |
| 549 | } |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 550 | |
| 551 | // Even if provider is the same as home_provider_, it is possible |
| 552 | // that the spn_ has changed. Run all the code below. |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 553 | home_provider_ = provider; |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 554 | provider_requires_roaming_ = home_provider_->requires_roaming; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 555 | Cellular::Operator oper; |
Darin Petkov | b4fccd2 | 2012-08-10 11:59:26 +0200 | [diff] [blame] | 556 | if (provider->networks && provider->networks[0]) { |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 557 | oper.SetCode(provider->networks[0]); |
| 558 | } |
| 559 | if (provider->country) { |
| 560 | oper.SetCountry(provider->country); |
| 561 | } |
| 562 | if (spn_.empty()) { |
| 563 | const char *name = mobile_provider_get_name(provider); |
| 564 | if (name) { |
| 565 | oper.SetName(name); |
| 566 | } |
| 567 | } else { |
| 568 | oper.SetName(spn_); |
| 569 | } |
| 570 | cellular()->set_home_provider(oper); |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 571 | SLOG(Cellular, 2) << "Home provider: " << oper.GetCode() << ", " |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 572 | << oper.GetName() << ", " << oper.GetCountry() |
| 573 | << (provider_requires_roaming_ ? ", roaming required" : ""); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 574 | InitAPNList(); |
| 575 | } |
| 576 | |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 577 | void CellularCapabilityUniversal::UpdateOLP() { |
| 578 | if (!cellular()->cellular_operator_info()) |
| 579 | return; |
| 580 | |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 581 | const CellularService::OLP *result = |
| 582 | cellular()->cellular_operator_info()->GetOLPByMCCMNC(operator_id_); |
| 583 | if (!result) |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 584 | return; |
| 585 | |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 586 | CellularService::OLP olp; |
| 587 | olp.CopyFrom(*result); |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 588 | string post_data = olp.GetPostData(); |
| 589 | ReplaceSubstringsAfterOffset(&post_data, 0, "${esn}", esn_); |
| 590 | ReplaceSubstringsAfterOffset(&post_data, 0, "${iccid}", sim_identifier_); |
| 591 | ReplaceSubstringsAfterOffset(&post_data, 0, "${imei}", imei_); |
| 592 | ReplaceSubstringsAfterOffset(&post_data, 0, "${imsi}", imsi_); |
| 593 | ReplaceSubstringsAfterOffset(&post_data, 0, "${mdn}", mdn_); |
| 594 | ReplaceSubstringsAfterOffset(&post_data, 0, "${meid}", meid_); |
| 595 | ReplaceSubstringsAfterOffset(&post_data, 0, "${min}", min_); |
| 596 | olp.SetPostData(post_data); |
| 597 | cellular()->service()->SetOLP(olp); |
| 598 | } |
| 599 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 600 | void CellularCapabilityUniversal::UpdateOperatorInfo() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 601 | SLOG(Cellular, 2) << __func__; |
Ben Chan | 092b12b | 2012-11-07 22:04:05 -0800 | [diff] [blame] | 602 | |
| 603 | // If service activation is required, |serving_operator_| may not have an |
| 604 | // operator ID. Use |operator_id_| as a fallback when available. |
| 605 | // |operator_id_| is retrieved from the SIM card. |
| 606 | if (IsServiceActivationRequired() && serving_operator_.GetCode().empty() && |
| 607 | !operator_id_.empty()) { |
| 608 | SLOG(Cellular, 2) << "Assuming operator '" << operator_id_ |
| 609 | << "' as serving operator."; |
| 610 | serving_operator_.SetCode(operator_id_); |
| 611 | } |
| 612 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 613 | const string &network_id = serving_operator_.GetCode(); |
| 614 | if (!network_id.empty()) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 615 | SLOG(Cellular, 2) << "Looking up network id: " << network_id; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 616 | mobile_provider *provider = |
| 617 | mobile_provider_lookup_by_network(cellular()->provider_db(), |
| 618 | network_id.c_str()); |
| 619 | if (provider) { |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 620 | if (serving_operator_.GetName().empty()) { |
| 621 | const char *provider_name = mobile_provider_get_name(provider); |
| 622 | if (provider_name && *provider_name) { |
| 623 | serving_operator_.SetName(provider_name); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 624 | } |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 625 | } |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 626 | if (provider->country && *provider->country) { |
| 627 | serving_operator_.SetCountry(provider->country); |
| 628 | } |
| 629 | SLOG(Cellular, 2) << "Operator name: " << serving_operator_.GetName() |
| 630 | << ", country: " << serving_operator_.GetCountry(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 631 | } else { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 632 | SLOG(Cellular, 2) << "GSM provider not found."; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | UpdateServingOperator(); |
| 636 | } |
| 637 | |
| 638 | void CellularCapabilityUniversal::UpdateServingOperator() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 639 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 640 | if (cellular()->service().get()) { |
| 641 | cellular()->service()->SetServingOperator(serving_operator_); |
| 642 | } |
| 643 | } |
| 644 | |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 645 | void CellularCapabilityUniversal::UpdateBearerPath() { |
| 646 | SLOG(Cellular, 2) << __func__; |
| 647 | DBusPathsCallback cb = Bind(&CellularCapabilityUniversal::OnListBearersReply, |
| 648 | weak_ptr_factory_.GetWeakPtr()); |
| 649 | Error error; |
| 650 | modem_proxy_->ListBearers(&error, cb, kTimeoutDefault); |
| 651 | } |
| 652 | |
| 653 | void CellularCapabilityUniversal::OnListBearersReply( |
| 654 | const std::vector<DBus::Path> &paths, |
| 655 | const Error &error) { |
| 656 | SLOG(Cellular, 2) << __func__ << "(" << error << ")"; |
| 657 | if (error.IsFailure()) { |
| 658 | SLOG(Cellular, 2) << "ListBearers failed with error: " << error; |
| 659 | return; |
| 660 | } |
| 661 | // Look for the first active bearer and use its path as the connected |
| 662 | // one. Right now, we don't allow more than one active bearer. |
| 663 | bool found_active = false; |
| 664 | for (size_t i = 0; i < paths.size(); ++i) { |
| 665 | const DBus::Path &path = paths[i]; |
| 666 | scoped_ptr<mm1::BearerProxyInterface> bearer_proxy( |
| 667 | proxy_factory()->CreateBearerProxy(path, cellular()->dbus_owner())); |
| 668 | bool is_active = bearer_proxy->Connected(); |
| 669 | if (is_active) { |
| 670 | if (!found_active) { |
| 671 | SLOG(Cellular, 2) << "Found active bearer \"" << path << "\"."; |
| 672 | bearer_path_ = path; |
| 673 | found_active = true; |
| 674 | } else { |
| 675 | LOG(FATAL) << "Found more than one active bearer."; |
| 676 | } |
| 677 | } |
| 678 | } |
| 679 | if (!found_active) { |
| 680 | SLOG(Cellular, 2) << "No active bearer found, clearing bearer_path_."; |
| 681 | bearer_path_.clear(); |
| 682 | } |
| 683 | } |
| 684 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 685 | void CellularCapabilityUniversal::InitAPNList() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 686 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 687 | if (!home_provider_) { |
| 688 | return; |
| 689 | } |
| 690 | apn_list_.clear(); |
| 691 | for (int i = 0; i < home_provider_->num_apns; ++i) { |
| 692 | Stringmap props; |
| 693 | mobile_apn *apn = home_provider_->apns[i]; |
| 694 | if (apn->value) { |
| 695 | props[flimflam::kApnProperty] = apn->value; |
| 696 | } |
| 697 | if (apn->username) { |
| 698 | props[flimflam::kApnUsernameProperty] = apn->username; |
| 699 | } |
| 700 | if (apn->password) { |
| 701 | props[flimflam::kApnPasswordProperty] = apn->password; |
| 702 | } |
| 703 | // Find the first localized and non-localized name, if any. |
| 704 | const localized_name *lname = NULL; |
| 705 | const localized_name *name = NULL; |
| 706 | for (int j = 0; j < apn->num_names; ++j) { |
| 707 | if (apn->names[j]->lang) { |
| 708 | if (!lname) { |
| 709 | lname = apn->names[j]; |
| 710 | } |
| 711 | } else if (!name) { |
| 712 | name = apn->names[j]; |
| 713 | } |
| 714 | } |
| 715 | if (name) { |
| 716 | props[flimflam::kApnNameProperty] = name->name; |
| 717 | } |
| 718 | if (lname) { |
| 719 | props[flimflam::kApnLocalizedNameProperty] = lname->name; |
| 720 | props[flimflam::kApnLanguageProperty] = lname->lang; |
| 721 | } |
| 722 | apn_list_.push_back(props); |
| 723 | } |
Darin Petkov | db6083f | 2012-08-16 12:50:23 +0200 | [diff] [blame] | 724 | if (cellular()->adaptor()) { |
| 725 | cellular()->adaptor()->EmitStringmapsChanged( |
| 726 | flimflam::kCellularApnListProperty, apn_list_); |
| 727 | } else { |
| 728 | LOG(ERROR) << "Null RPC service adaptor."; |
| 729 | } |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 730 | } |
| 731 | |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 732 | bool CellularCapabilityUniversal::IsServiceActivationRequired() const { |
| 733 | // If there is no online payment portal information, it's safer to assume |
| 734 | // the service does not require activation. |
| 735 | if (!cellular()->cellular_operator_info()) |
| 736 | return false; |
| 737 | |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 738 | const CellularService::OLP *olp = |
| 739 | cellular()->cellular_operator_info()->GetOLPByMCCMNC(operator_id_); |
| 740 | if (!olp) |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 741 | return false; |
| 742 | |
| 743 | // To avoid false positives, it's safer to assume the service does not |
| 744 | // require activation if MDN is not set. |
| 745 | if (mdn_.empty()) |
| 746 | return false; |
| 747 | |
| 748 | // If MDN contains only zeros ('+' and '-' characters are ignored), |
| 749 | // the service requires activation. |
| 750 | for (size_t i = 0; i < mdn_.size(); ++i) { |
| 751 | if (mdn_[i] != '0' && mdn_[i] != '-' && mdn_[i] != '+') |
| 752 | return false; |
| 753 | } |
| 754 | return true; |
| 755 | } |
| 756 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 757 | // always called from an async context |
| 758 | void CellularCapabilityUniversal::Register(const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 759 | SLOG(Cellular, 2) << __func__ << " \"" << selected_network_ << "\""; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 760 | CHECK(!callback.is_null()); |
| 761 | Error error; |
| 762 | ResultCallback cb = Bind(&CellularCapabilityUniversal::OnRegisterReply, |
| 763 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 764 | modem_3gpp_proxy_->Register(selected_network_, &error, cb, kTimeoutRegister); |
| 765 | if (error.IsFailure()) |
| 766 | callback.Run(error); |
| 767 | } |
| 768 | |
| 769 | void CellularCapabilityUniversal::RegisterOnNetwork( |
| 770 | const string &network_id, |
| 771 | Error *error, |
| 772 | const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 773 | SLOG(Cellular, 2) << __func__ << "(" << network_id << ")"; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 774 | CHECK(error); |
| 775 | desired_network_ = network_id; |
| 776 | ResultCallback cb = Bind(&CellularCapabilityUniversal::OnRegisterReply, |
| 777 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 778 | modem_3gpp_proxy_->Register(network_id, error, cb, kTimeoutRegister); |
| 779 | } |
| 780 | |
| 781 | void CellularCapabilityUniversal::OnRegisterReply( |
| 782 | const ResultCallback &callback, |
| 783 | const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 784 | SLOG(Cellular, 2) << __func__ << "(" << error << ")"; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 785 | |
| 786 | if (error.IsSuccess()) { |
| 787 | selected_network_ = desired_network_; |
| 788 | desired_network_.clear(); |
| 789 | callback.Run(error); |
| 790 | return; |
| 791 | } |
| 792 | // If registration on the desired network failed, |
| 793 | // try to register on the home network. |
| 794 | if (!desired_network_.empty()) { |
| 795 | desired_network_.clear(); |
| 796 | selected_network_.clear(); |
| 797 | LOG(INFO) << "Couldn't register on selected network, trying home network"; |
| 798 | Register(callback); |
| 799 | return; |
| 800 | } |
| 801 | callback.Run(error); |
| 802 | } |
| 803 | |
| 804 | bool CellularCapabilityUniversal::IsRegistered() { |
| 805 | return (registration_state_ == MM_MODEM_3GPP_REGISTRATION_STATE_HOME || |
| 806 | registration_state_ == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING); |
| 807 | } |
| 808 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 809 | void CellularCapabilityUniversal::SetUnregistered(bool searching) { |
| 810 | // If we're already in some non-registered state, don't override that |
| 811 | if (registration_state_ == MM_MODEM_3GPP_REGISTRATION_STATE_HOME || |
| 812 | registration_state_ == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING) { |
| 813 | registration_state_ = |
| 814 | (searching ? MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING : |
| 815 | MM_MODEM_3GPP_REGISTRATION_STATE_IDLE); |
| 816 | } |
| 817 | } |
| 818 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 819 | void CellularCapabilityUniversal::RequirePIN( |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 820 | const string &pin, bool require, |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 821 | Error *error, const ResultCallback &callback) { |
| 822 | CHECK(error); |
| 823 | sim_proxy_->EnablePin(pin, require, error, callback, kTimeoutDefault); |
| 824 | } |
| 825 | |
| 826 | void CellularCapabilityUniversal::EnterPIN(const string &pin, |
| 827 | Error *error, |
| 828 | const ResultCallback &callback) { |
| 829 | CHECK(error); |
| 830 | sim_proxy_->SendPin(pin, error, callback, kTimeoutDefault); |
| 831 | } |
| 832 | |
| 833 | void CellularCapabilityUniversal::UnblockPIN(const string &unblock_code, |
| 834 | const string &pin, |
| 835 | Error *error, |
| 836 | const ResultCallback &callback) { |
| 837 | CHECK(error); |
| 838 | sim_proxy_->SendPuk(unblock_code, pin, error, callback, kTimeoutDefault); |
| 839 | } |
| 840 | |
| 841 | void CellularCapabilityUniversal::ChangePIN( |
| 842 | const string &old_pin, const string &new_pin, |
| 843 | Error *error, const ResultCallback &callback) { |
| 844 | CHECK(error); |
| 845 | sim_proxy_->ChangePin(old_pin, new_pin, error, callback, kTimeoutDefault); |
| 846 | } |
| 847 | |
Ben Chan | 5d0d32c | 2013-01-08 02:05:29 -0800 | [diff] [blame] | 848 | void CellularCapabilityUniversal::Reset(Error *error, |
| 849 | const ResultCallback &callback) { |
| 850 | SLOG(Cellular, 2) << __func__; |
| 851 | CHECK(error); |
| 852 | if (resetting_) { |
| 853 | Error::PopulateAndLog(error, Error::kInProgress, "Already resetting"); |
| 854 | return; |
| 855 | } |
| 856 | ResultCallback cb = Bind(&CellularCapabilityUniversal::OnResetReply, |
| 857 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 858 | modem_proxy_->Reset(error, cb, kTimeoutReset); |
| 859 | if (!error->IsFailure()) { |
| 860 | resetting_ = true; |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | void CellularCapabilityUniversal::OnResetReply(const ResultCallback &callback, |
| 865 | const Error &error) { |
| 866 | SLOG(Cellular, 2) << __func__; |
| 867 | resetting_ = false; |
| 868 | if (!callback.is_null()) |
| 869 | callback.Run(error); |
| 870 | } |
| 871 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 872 | void CellularCapabilityUniversal::Scan(Error *error, |
| 873 | const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 874 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 875 | CHECK(error); |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 876 | if (scanning_) { |
| 877 | Error::PopulateAndLog(error, Error::kInProgress, "Already scanning"); |
| 878 | return; |
| 879 | } |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 880 | DBusPropertyMapsCallback cb = Bind(&CellularCapabilityUniversal::OnScanReply, |
| 881 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 882 | modem_3gpp_proxy_->Scan(error, cb, kTimeoutScan); |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 883 | if (!error->IsFailure()) { |
| 884 | scanning_ = true; |
| 885 | cellular()->adaptor()->EmitBoolChanged(flimflam::kScanningProperty, |
| 886 | scanning_); |
| 887 | } |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | void CellularCapabilityUniversal::OnScanReply(const ResultCallback &callback, |
| 891 | const ScanResults &results, |
| 892 | const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 893 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 894 | |
| 895 | // Error handling is weak. The current expectation is that on any |
| 896 | // error, found_networks_ should be cleared and a property change |
| 897 | // notification sent out. |
| 898 | // |
| 899 | // TODO(jglasgow): fix error handling |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 900 | scanning_ = false; |
| 901 | cellular()->adaptor()->EmitBoolChanged(flimflam::kScanningProperty, |
| 902 | scanning_); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 903 | found_networks_.clear(); |
| 904 | if (!error.IsFailure()) { |
| 905 | for (ScanResults::const_iterator it = results.begin(); |
| 906 | it != results.end(); ++it) { |
| 907 | found_networks_.push_back(ParseScanResult(*it)); |
| 908 | } |
| 909 | } |
| 910 | cellular()->adaptor()->EmitStringmapsChanged(flimflam::kFoundNetworksProperty, |
| 911 | found_networks_); |
Gary Morain | ceba6aa | 2012-05-03 10:28:26 -0700 | [diff] [blame] | 912 | |
| 913 | // TODO(gmorain): This check for is_null() is a work-around because |
| 914 | // Cellular::Scan() passes a null callback. Instead: 1. Have Cellular::Scan() |
| 915 | // pass in a callback. 2. Have Cellular "own" the found_networks_ property |
| 916 | // 3. Have Cellular EmitStingMapsChanged() 4. Share the code between GSM and |
| 917 | // Universal. |
| 918 | if (!callback.is_null()) |
| 919 | callback.Run(error); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | Stringmap CellularCapabilityUniversal::ParseScanResult( |
| 923 | const ScanResult &result) { |
| 924 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 925 | /* ScanResults contain the following keys: |
| 926 | |
| 927 | "status" |
| 928 | A MMModem3gppNetworkAvailability value representing network |
| 929 | availability status, given as an unsigned integer (signature "u"). |
| 930 | This key will always be present. |
| 931 | |
| 932 | "operator-long" |
| 933 | Long-format name of operator, given as a string value (signature |
| 934 | "s"). If the name is unknown, this field should not be present. |
| 935 | |
| 936 | "operator-short" |
| 937 | Short-format name of operator, given as a string value |
| 938 | (signature "s"). If the name is unknown, this field should not |
| 939 | be present. |
| 940 | |
| 941 | "operator-code" |
| 942 | Mobile code of the operator, given as a string value (signature |
| 943 | "s"). Returned in the format "MCCMNC", where MCC is the |
| 944 | three-digit ITU E.212 Mobile Country Code and MNC is the two- or |
| 945 | three-digit GSM Mobile Network Code. e.g. "31026" or "310260". |
| 946 | |
| 947 | "access-technology" |
| 948 | A MMModemAccessTechnology value representing the generic access |
| 949 | technology used by this mobile network, given as an unsigned |
| 950 | integer (signature "u"). |
| 951 | */ |
| 952 | Stringmap parsed; |
| 953 | |
| 954 | uint32 status; |
| 955 | if (DBusProperties::GetUint32(result, kStatusProperty, &status)) { |
| 956 | // numerical values are taken from 3GPP TS 27.007 Section 7.3. |
| 957 | static const char * const kStatusString[] = { |
| 958 | "unknown", // MM_MODEM_3GPP_NETWORK_AVAILABILITY_UNKNOWN |
| 959 | "available", // MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE |
| 960 | "current", // MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT |
| 961 | "forbidden", // MM_MODEM_3GPP_NETWORK_AVAILABILITY_FORBIDDEN |
| 962 | }; |
| 963 | parsed[flimflam::kStatusProperty] = kStatusString[status]; |
| 964 | } |
| 965 | |
| 966 | uint32 tech; // MMModemAccessTechnology |
| 967 | if (DBusProperties::GetUint32(result, kOperatorAccessTechnologyProperty, |
| 968 | &tech)) { |
| 969 | parsed[flimflam::kTechnologyProperty] = AccessTechnologyToString(tech); |
| 970 | } |
| 971 | |
| 972 | string operator_long, operator_short, operator_code; |
| 973 | if (DBusProperties::GetString(result, kOperatorLongProperty, &operator_long)) |
| 974 | parsed[flimflam::kLongNameProperty] = operator_long; |
| 975 | if (DBusProperties::GetString(result, kOperatorShortProperty, |
| 976 | &operator_short)) |
| 977 | parsed[flimflam::kShortNameProperty] = operator_short; |
| 978 | if (DBusProperties::GetString(result, kOperatorCodeProperty, &operator_code)) |
| 979 | parsed[flimflam::kNetworkIdProperty] = operator_code; |
| 980 | |
| 981 | // If the long name is not available but the network ID is, look up the long |
| 982 | // name in the mobile provider database. |
| 983 | if ((!ContainsKey(parsed, flimflam::kLongNameProperty) || |
| 984 | parsed[flimflam::kLongNameProperty].empty()) && |
| 985 | ContainsKey(parsed, flimflam::kNetworkIdProperty)) { |
| 986 | mobile_provider *provider = |
| 987 | mobile_provider_lookup_by_network( |
| 988 | cellular()->provider_db(), |
| 989 | parsed[flimflam::kNetworkIdProperty].c_str()); |
| 990 | if (provider) { |
| 991 | const char *long_name = mobile_provider_get_name(provider); |
| 992 | if (long_name && *long_name) { |
| 993 | parsed[flimflam::kLongNameProperty] = long_name; |
| 994 | } |
| 995 | } |
| 996 | } |
| 997 | return parsed; |
| 998 | } |
| 999 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1000 | string CellularCapabilityUniversal::GetNetworkTechnologyString() const { |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1001 | // Order is important. Return the highest speed technology |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1002 | // TODO(jglasgow): change shill interfaces to a capability model |
| 1003 | |
| 1004 | return AccessTechnologyToString(access_technologies_); |
| 1005 | } |
| 1006 | |
| 1007 | string CellularCapabilityUniversal::GetRoamingStateString() const { |
| 1008 | switch (registration_state_) { |
| 1009 | case MM_MODEM_3GPP_REGISTRATION_STATE_HOME: |
| 1010 | return flimflam::kRoamingStateHome; |
| 1011 | case MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING: |
| 1012 | return flimflam::kRoamingStateRoaming; |
| 1013 | default: |
| 1014 | break; |
| 1015 | } |
| 1016 | return flimflam::kRoamingStateUnknown; |
| 1017 | } |
| 1018 | |
| 1019 | void CellularCapabilityUniversal::GetSignalQuality() { |
Nathan Williams | 218cbcd | 2012-04-17 16:48:44 -0400 | [diff] [blame] | 1020 | // TODO(njw): Switch to asynchronous calls (crosbug.com/17583). |
| 1021 | const DBus::Struct<unsigned int, bool> quality = |
| 1022 | modem_proxy_->SignalQuality(); |
| 1023 | OnSignalQualityChanged(quality._1); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1024 | } |
| 1025 | |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1026 | string CellularCapabilityUniversal::GetTypeString() const { |
| 1027 | return AccessTechnologyToTechnologyFamily(access_technologies_); |
| 1028 | } |
| 1029 | |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 1030 | void CellularCapabilityUniversal::OnModemPropertiesChanged( |
| 1031 | const DBusPropertiesMap &properties, |
| 1032 | const vector<string> &/* invalidated_properties */) { |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 1033 | // This solves a bootstrapping problem: If the modem is not yet |
| 1034 | // enabled, there are no proxy objects associated with the capability |
| 1035 | // object, so modem signals like StateChanged aren't seen. By monitoring |
| 1036 | // changes to the State property via the ModemManager, we're able to |
| 1037 | // get the initialization process started, which will result in the |
| 1038 | // creation of the proxy objects. |
| 1039 | // |
| 1040 | // The first time we see the change to State (when the modem state |
| 1041 | // is Unknown), we simply update the state, and rely on the Manager to |
| 1042 | // enable the device when it is registered with the Manager. On subsequent |
| 1043 | // changes to State, we need to explicitly enable the device ourselves. |
| 1044 | int32 istate; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1045 | if (DBusProperties::GetInt32(properties, MM_MODEM_PROPERTY_STATE, &istate)) { |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 1046 | Cellular::ModemState state = static_cast<Cellular::ModemState>(istate); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1047 | OnModemStateChanged(state); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 1048 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1049 | string string_value; |
Nathan Williams | e984080 | 2012-04-18 18:47:40 -0400 | [diff] [blame] | 1050 | if (DBusProperties::GetObjectPath(properties, |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1051 | MM_MODEM_PROPERTY_SIM, &string_value)) |
| 1052 | OnSimPathChanged(string_value); |
| 1053 | uint32 uint_value; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1054 | if (DBusProperties::GetUint32(properties, |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1055 | MM_MODEM_PROPERTY_MODEMCAPABILITIES, |
| 1056 | &uint_value)) |
| 1057 | OnModemCapabilitesChanged(uint_value); |
| 1058 | if (DBusProperties::GetUint32(properties, |
| 1059 | MM_MODEM_PROPERTY_CURRENTCAPABILITIES, |
| 1060 | &uint_value)) |
| 1061 | OnModemCurrentCapabilitiesChanged(uint_value); |
| 1062 | // not needed: MM_MODEM_PROPERTY_MAXBEARERS |
| 1063 | // not needed: MM_MODEM_PROPERTY_MAXACTIVEBEARERS |
| 1064 | if (DBusProperties::GetString(properties, |
| 1065 | MM_MODEM_PROPERTY_MANUFACTURER, |
| 1066 | &string_value)) |
| 1067 | OnModemManufacturerChanged(string_value); |
| 1068 | if (DBusProperties::GetString(properties, |
| 1069 | MM_MODEM_PROPERTY_MODEL, |
| 1070 | &string_value)) |
| 1071 | OnModemModelChanged(string_value); |
| 1072 | if (DBusProperties::GetString(properties, |
| 1073 | MM_MODEM_PROPERTY_REVISION, |
| 1074 | &string_value)) |
| 1075 | OnModemRevisionChanged(string_value); |
| 1076 | // not needed: MM_MODEM_PROPERTY_DEVICEIDENTIFIER |
| 1077 | // not needed: MM_MODEM_PROPERTY_DEVICE |
| 1078 | // not needed: MM_MODEM_PROPERTY_DRIVER |
| 1079 | // not needed: MM_MODEM_PROPERTY_PLUGIN |
| 1080 | // not needed: MM_MODEM_PROPERTY_EQUIPMENTIDENTIFIER |
Nathan Williams | 218cbcd | 2012-04-17 16:48:44 -0400 | [diff] [blame] | 1081 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1082 | // Unlock required and SimLock |
| 1083 | bool locks_changed = false; |
| 1084 | uint32_t unlock_required; // This is really of type MMModemLock |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1085 | if (DBusProperties::GetUint32(properties, |
| 1086 | MM_MODEM_PROPERTY_UNLOCKREQUIRED, |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1087 | &unlock_required)) { |
| 1088 | locks_changed = true; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1089 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1090 | LockRetryData lock_retries; |
| 1091 | DBusPropertiesMap::const_iterator it = |
| 1092 | properties.find(MM_MODEM_PROPERTY_UNLOCKRETRIES); |
| 1093 | if (it != properties.end()) { |
| 1094 | lock_retries = it->second; |
| 1095 | locks_changed = true; |
| 1096 | } |
| 1097 | if (locks_changed) |
| 1098 | OnLockRetriesChanged(static_cast<MMModemLock>(unlock_required), |
| 1099 | lock_retries); |
| 1100 | if (DBusProperties::GetUint32(properties, |
| 1101 | MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES, |
| 1102 | &uint_value)) |
| 1103 | OnAccessTechnologiesChanged(uint_value); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1104 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1105 | it = properties.find(MM_MODEM_PROPERTY_SIGNALQUALITY); |
| 1106 | if (it != properties.end()) { |
| 1107 | DBus::Struct<unsigned int, bool> quality = it->second; |
| 1108 | OnSignalQualityChanged(quality._1); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1109 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1110 | vector<string> numbers; |
| 1111 | if (DBusProperties::GetStrings(properties, MM_MODEM_PROPERTY_OWNNUMBERS, |
| 1112 | &numbers)) { |
| 1113 | string mdn; |
| 1114 | if (numbers.size() > 0) |
| 1115 | mdn = numbers[0]; |
| 1116 | OnMdnChanged(mdn); |
| 1117 | } |
| 1118 | if (DBusProperties::GetUint32(properties, MM_MODEM_PROPERTY_SUPPORTEDMODES, |
| 1119 | &uint_value)) |
| 1120 | OnSupportedModesChanged(uint_value); |
| 1121 | if (DBusProperties::GetUint32(properties, MM_MODEM_PROPERTY_ALLOWEDMODES, |
| 1122 | &uint_value)) |
| 1123 | OnAllowedModesChanged(uint_value); |
| 1124 | if (DBusProperties::GetUint32(properties, MM_MODEM_PROPERTY_PREFERREDMODE, |
| 1125 | &uint_value)) |
| 1126 | OnPreferredModeChanged(static_cast<MMModemMode>(uint_value)); |
| 1127 | // au: MM_MODEM_PROPERTY_SUPPORTEDBANDS, |
| 1128 | // au: MM_MODEM_PROPERTY_BANDS |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | void CellularCapabilityUniversal::OnDBusPropertiesChanged( |
| 1132 | const string &interface, |
| 1133 | const DBusPropertiesMap &changed_properties, |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 1134 | const vector<string> &invalidated_properties) { |
Jason Glasgow | 7234ec3 | 2012-05-23 16:01:21 -0400 | [diff] [blame] | 1135 | SLOG(Cellular, 2) << __func__ << "(" << interface << ")"; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 1136 | if (interface == MM_DBUS_INTERFACE_MODEM) { |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 1137 | OnModemPropertiesChanged(changed_properties, invalidated_properties); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 1138 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1139 | if (interface == MM_DBUS_INTERFACE_MODEM_MODEM3GPP) { |
| 1140 | OnModem3GPPPropertiesChanged(changed_properties, invalidated_properties); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1141 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1142 | if (interface == MM_DBUS_INTERFACE_SIM) { |
| 1143 | OnSimPropertiesChanged(changed_properties, invalidated_properties); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1144 | } |
| 1145 | } |
| 1146 | |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 1147 | bool CellularCapabilityUniversal::RetriableConnectError( |
| 1148 | const Error &error) const { |
| 1149 | if (error.type() == Error::kInvalidApn) |
| 1150 | return true; |
| 1151 | |
| 1152 | // modemmanager does not ever return kInvalidApn for E362 modems |
| 1153 | // with 1.41 firmware. It remains to be seem if this will change |
| 1154 | // with 3.x firmware. |
| 1155 | if ((model_id_ == kE362ModelId) && (error.type() == Error::kOperationFailed)) |
| 1156 | return true; |
| 1157 | |
| 1158 | return false; |
| 1159 | } |
| 1160 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1161 | void CellularCapabilityUniversal::OnNetworkModeSignal(uint32 /*mode*/) { |
| 1162 | // TODO(petkov): Implement this. |
| 1163 | NOTIMPLEMENTED(); |
| 1164 | } |
| 1165 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1166 | void CellularCapabilityUniversal::OnSimPathChanged( |
| 1167 | const string &sim_path) { |
| 1168 | if (sim_path == sim_path_) |
| 1169 | return; |
| 1170 | |
| 1171 | mm1::SimProxyInterface *proxy = NULL; |
| 1172 | if (!sim_path.empty()) |
| 1173 | proxy = proxy_factory()->CreateSimProxy(sim_path, |
| 1174 | cellular()->dbus_owner()); |
| 1175 | sim_path_ = sim_path; |
| 1176 | sim_proxy_.reset(proxy); |
| 1177 | |
| 1178 | if (sim_path.empty()) { |
| 1179 | // Clear all data about the sim |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 1180 | imsi_ = ""; |
| 1181 | spn_ = ""; |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 1182 | sim_present_ = false; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1183 | OnSimIdentifierChanged(""); |
| 1184 | OnOperatorIdChanged(""); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1185 | } else { |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 1186 | sim_present_ = true; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1187 | scoped_ptr<DBusPropertiesProxyInterface> properties_proxy( |
| 1188 | proxy_factory()->CreateDBusPropertiesProxy(sim_path, |
| 1189 | cellular()->dbus_owner())); |
| 1190 | // TODO(jglasgow): convert to async interface |
| 1191 | DBusPropertiesMap properties( |
| 1192 | properties_proxy->GetAll(MM_DBUS_INTERFACE_SIM)); |
| 1193 | OnSimPropertiesChanged(properties, vector<string>()); |
| 1194 | } |
| 1195 | } |
| 1196 | |
| 1197 | void CellularCapabilityUniversal::OnModemCapabilitesChanged( |
| 1198 | uint32 capabilities) { |
| 1199 | capabilities_ = capabilities; |
| 1200 | } |
| 1201 | |
| 1202 | void CellularCapabilityUniversal::OnModemCurrentCapabilitiesChanged( |
| 1203 | uint32 current_capabilities) { |
| 1204 | current_capabilities_ = current_capabilities; |
| 1205 | } |
| 1206 | |
| 1207 | void CellularCapabilityUniversal::OnMdnChanged( |
| 1208 | const string &mdn) { |
| 1209 | mdn_ = mdn; |
| 1210 | } |
| 1211 | |
| 1212 | void CellularCapabilityUniversal::OnModemManufacturerChanged( |
| 1213 | const string &manufacturer) { |
| 1214 | manufacturer_ = manufacturer; |
| 1215 | } |
| 1216 | |
| 1217 | void CellularCapabilityUniversal::OnModemModelChanged( |
| 1218 | const string &model) { |
| 1219 | model_id_ = model; |
| 1220 | } |
| 1221 | |
| 1222 | void CellularCapabilityUniversal::OnModemRevisionChanged( |
| 1223 | const string &revision) { |
| 1224 | firmware_revision_ = revision; |
| 1225 | } |
| 1226 | |
| 1227 | void CellularCapabilityUniversal::OnModemStateChanged( |
| 1228 | Cellular::ModemState state) { |
| 1229 | Cellular::ModemState prev_modem_state = cellular()->modem_state(); |
| 1230 | bool was_enabled = cellular()->IsUnderlyingDeviceEnabled(); |
| 1231 | if (Cellular::IsEnabledModemState(state)) |
| 1232 | cellular()->set_modem_state(state); |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 1233 | SLOG(Cellular, 2) << __func__ << ": prev_modem_state: " << prev_modem_state |
| 1234 | << " was_enabled: " << was_enabled |
| 1235 | << " cellular state: " |
| 1236 | << cellular()->GetStateString(cellular()->state()); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1237 | if (prev_modem_state != Cellular::kModemStateUnknown && |
| 1238 | prev_modem_state != Cellular::kModemStateEnabling && |
| 1239 | !was_enabled && |
| 1240 | cellular()->state() == Cellular::kStateDisabled && |
| 1241 | cellular()->IsUnderlyingDeviceEnabled()) { |
| 1242 | cellular()->SetEnabled(true); |
| 1243 | } |
| 1244 | } |
| 1245 | |
| 1246 | void CellularCapabilityUniversal::OnAccessTechnologiesChanged( |
| 1247 | uint32 access_technologies) { |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1248 | if (access_technologies_ != access_technologies) { |
Jason Glasgow | bad114b | 2012-05-21 15:24:16 -0400 | [diff] [blame] | 1249 | const string old_type_string(GetTypeString()); |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1250 | access_technologies_ = access_technologies; |
Jason Glasgow | bad114b | 2012-05-21 15:24:16 -0400 | [diff] [blame] | 1251 | const string new_type_string(GetTypeString()); |
| 1252 | if (new_type_string != old_type_string) { |
| 1253 | // TODO(jglasgow): address layering violation of emitting change |
| 1254 | // signal here for a property owned by Cellular. |
| 1255 | cellular()->adaptor()->EmitStringChanged( |
| 1256 | flimflam::kTechnologyFamilyProperty, new_type_string); |
| 1257 | } |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1258 | if (cellular()->service().get()) { |
| 1259 | cellular()->service()->SetNetworkTechnology(GetNetworkTechnologyString()); |
| 1260 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1261 | } |
| 1262 | } |
| 1263 | |
| 1264 | void CellularCapabilityUniversal::OnSupportedModesChanged( |
| 1265 | uint32 supported_modes) { |
| 1266 | supported_modes_ = supported_modes; |
| 1267 | } |
| 1268 | |
| 1269 | void CellularCapabilityUniversal::OnAllowedModesChanged( |
| 1270 | uint32 allowed_modes) { |
| 1271 | allowed_modes_ = allowed_modes; |
| 1272 | } |
| 1273 | |
| 1274 | void CellularCapabilityUniversal::OnPreferredModeChanged( |
| 1275 | MMModemMode preferred_mode) { |
| 1276 | preferred_mode_ = preferred_mode; |
| 1277 | } |
| 1278 | |
| 1279 | void CellularCapabilityUniversal::OnLockRetriesChanged( |
| 1280 | MMModemLock unlock_required, |
| 1281 | const LockRetryData &lock_retries) { |
Jason Glasgow | d4af81d | 2012-05-03 22:25:05 -0400 | [diff] [blame] | 1282 | switch (unlock_required) { |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1283 | case MM_MODEM_LOCK_SIM_PIN: |
| 1284 | sim_lock_status_.lock_type = "sim-pin"; |
| 1285 | break; |
| 1286 | case MM_MODEM_LOCK_SIM_PUK: |
| 1287 | sim_lock_status_.lock_type = "sim-puk"; |
| 1288 | break; |
| 1289 | default: |
| 1290 | sim_lock_status_.lock_type = ""; |
| 1291 | break; |
| 1292 | } |
| 1293 | LockRetryData::const_iterator it = lock_retries.find(unlock_required); |
| 1294 | if (it != lock_retries.end()) { |
| 1295 | sim_lock_status_.retries_left = it->second; |
| 1296 | } else { |
| 1297 | // Unknown, use 999 |
| 1298 | sim_lock_status_.retries_left = 999; |
| 1299 | } |
| 1300 | OnSimLockStatusChanged(); |
| 1301 | } |
| 1302 | |
| 1303 | void CellularCapabilityUniversal::OnSimLockStatusChanged() { |
| 1304 | cellular()->adaptor()->EmitKeyValueStoreChanged( |
| 1305 | flimflam::kSIMLockStatusProperty, SimLockStatusToProperty(NULL)); |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 1306 | |
| 1307 | // If the SIM is currently unlocked, assume that we need to refresh |
| 1308 | // carrier information, since a locked SIM prevents shill from obtaining |
| 1309 | // the necessary data to establish a connection later (e.g. IMSI). |
| 1310 | if (!sim_path_.empty() && sim_lock_status_.lock_type.empty()) { |
| 1311 | scoped_ptr<DBusPropertiesProxyInterface> properties_proxy( |
| 1312 | proxy_factory()->CreateDBusPropertiesProxy(sim_path_, |
| 1313 | cellular()->dbus_owner())); |
| 1314 | DBusPropertiesMap properties( |
| 1315 | properties_proxy->GetAll(MM_DBUS_INTERFACE_SIM)); |
| 1316 | OnSimPropertiesChanged(properties, vector<string>()); |
| 1317 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | void CellularCapabilityUniversal::OnModem3GPPPropertiesChanged( |
| 1321 | const DBusPropertiesMap &properties, |
| 1322 | const vector<string> &/* invalidated_properties */) { |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 1323 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1324 | string imei; |
| 1325 | if (DBusProperties::GetString(properties, |
| 1326 | MM_MODEM_MODEM3GPP_PROPERTY_IMEI, |
| 1327 | &imei)) |
| 1328 | OnImeiChanged(imei); |
| 1329 | |
| 1330 | // Handle registration state changes as a single change |
| 1331 | string operator_code = serving_operator_.GetCode(); |
| 1332 | string operator_name = serving_operator_.GetName(); |
| 1333 | MMModem3gppRegistrationState state = registration_state_; |
| 1334 | bool registration_changed = false; |
| 1335 | uint32 uint_value; |
| 1336 | if (DBusProperties::GetUint32(properties, |
| 1337 | MM_MODEM_MODEM3GPP_PROPERTY_REGISTRATIONSTATE, |
| 1338 | &uint_value)) { |
| 1339 | state = static_cast<MMModem3gppRegistrationState>(uint_value); |
| 1340 | registration_changed = true; |
| 1341 | } |
| 1342 | if (DBusProperties::GetString(properties, |
| 1343 | MM_MODEM_MODEM3GPP_PROPERTY_OPERATORCODE, |
| 1344 | &operator_code)) |
| 1345 | registration_changed = true; |
| 1346 | if (DBusProperties::GetString(properties, |
| 1347 | MM_MODEM_MODEM3GPP_PROPERTY_OPERATORNAME, |
| 1348 | &operator_name)) |
| 1349 | registration_changed = true; |
| 1350 | if (registration_changed) |
| 1351 | On3GPPRegistrationChanged(state, operator_code, operator_name); |
| 1352 | |
| 1353 | uint32 locks = 0; |
| 1354 | if (DBusProperties::GetUint32( |
| 1355 | properties, MM_MODEM_MODEM3GPP_PROPERTY_ENABLEDFACILITYLOCKS, |
| 1356 | &locks)) |
| 1357 | OnFacilityLocksChanged(locks); |
| 1358 | } |
| 1359 | |
| 1360 | void CellularCapabilityUniversal::OnImeiChanged(const string &imei) { |
| 1361 | imei_ = imei; |
| 1362 | } |
| 1363 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1364 | void CellularCapabilityUniversal::On3GPPRegistrationChanged( |
| 1365 | MMModem3gppRegistrationState state, |
| 1366 | const string &operator_code, |
| 1367 | const string &operator_name) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1368 | SLOG(Cellular, 2) << __func__ << ": regstate=" << state |
| 1369 | << ", opercode=" << operator_code |
| 1370 | << ", opername=" << operator_name; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1371 | registration_state_ = state; |
| 1372 | serving_operator_.SetCode(operator_code); |
| 1373 | serving_operator_.SetName(operator_name); |
| 1374 | UpdateOperatorInfo(); |
| 1375 | cellular()->HandleNewRegistrationState(); |
| 1376 | } |
| 1377 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 1378 | void CellularCapabilityUniversal::OnModemStateChangedSignal( |
| 1379 | int32 old_state, int32 new_state, uint32 reason) { |
Eric Shienbrood | 9b1bd7b | 2012-04-20 16:42:26 -0400 | [diff] [blame] | 1380 | SLOG(Cellular, 2) << __func__ << "(" << old_state << ", " << new_state << ", " |
| 1381 | << reason << ")"; |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 1382 | cellular()->OnModemStateChanged(static_cast<Cellular::ModemState>(old_state), |
| 1383 | static_cast<Cellular::ModemState>(new_state), |
| 1384 | reason); |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 1385 | if (!deferred_enable_modem_callback_.is_null() && |
| 1386 | (new_state == Cellular::kModemStateDisabled)) { |
| 1387 | SLOG(Cellular, 2) << "Enabling modem after deferring"; |
| 1388 | deferred_enable_modem_callback_.Run(); |
| 1389 | deferred_enable_modem_callback_.Reset(); |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 1390 | } else if (new_state == Cellular::kModemStateConnected) { |
| 1391 | SLOG(Cellular, 2) << "Updating bearer path to reflect the active bearer."; |
| 1392 | UpdateBearerPath(); |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 1393 | } |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 1394 | } |
| 1395 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1396 | void CellularCapabilityUniversal::OnSignalQualityChanged(uint32 quality) { |
| 1397 | cellular()->HandleNewSignalQuality(quality); |
| 1398 | } |
| 1399 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1400 | void CellularCapabilityUniversal::OnFacilityLocksChanged(uint32 locks) { |
| 1401 | if (sim_lock_status_.enabled != (locks & MM_MODEM_3GPP_FACILITY_SIM)) { |
| 1402 | sim_lock_status_.enabled = locks & MM_MODEM_3GPP_FACILITY_SIM; |
| 1403 | OnSimLockStatusChanged(); |
| 1404 | } |
| 1405 | } |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 1406 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1407 | void CellularCapabilityUniversal::OnSimPropertiesChanged( |
| 1408 | const DBusPropertiesMap &props, |
| 1409 | const vector<string> &/* invalidated_properties */) { |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 1410 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1411 | string value; |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 1412 | bool must_update_home_provider = false; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1413 | if (DBusProperties::GetString(props, MM_SIM_PROPERTY_SIMIDENTIFIER, &value)) |
| 1414 | OnSimIdentifierChanged(value); |
| 1415 | if (DBusProperties::GetString(props, MM_SIM_PROPERTY_OPERATORIDENTIFIER, |
| 1416 | &value)) |
| 1417 | OnOperatorIdChanged(value); |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 1418 | if (DBusProperties::GetString(props, MM_SIM_PROPERTY_OPERATORNAME, &value)) { |
| 1419 | spn_ = value; |
| 1420 | must_update_home_provider = true; |
| 1421 | } |
| 1422 | if (DBusProperties::GetString(props, MM_SIM_PROPERTY_IMSI, &value)) { |
| 1423 | imsi_ = value; |
| 1424 | must_update_home_provider = true; |
| 1425 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1426 | // TODO(jglasgow): May eventually want to get SPDI, etc |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1427 | |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 1428 | if (must_update_home_provider) |
| 1429 | SetHomeProvider(); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | void CellularCapabilityUniversal::OnSimIdentifierChanged(const string &id) { |
| 1433 | sim_identifier_ = id; |
| 1434 | } |
| 1435 | |
| 1436 | void CellularCapabilityUniversal::OnOperatorIdChanged( |
| 1437 | const string &operator_id) { |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 1438 | SLOG(Cellular, 2) << "Operator ID = '" << operator_id << "'"; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1439 | operator_id_ = operator_id; |
| 1440 | } |
| 1441 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1442 | } // namespace shill |