Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "shill/cellular_capability_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" |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 24 | #include "shill/pending_activation_store.h" |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 25 | #include "shill/property_accessor.h" |
| 26 | #include "shill/proxy_factory.h" |
| 27 | |
| 28 | #ifdef MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN |
| 29 | #error "Do not include mm-modem.h" |
| 30 | #endif |
| 31 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 32 | using base::Bind; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 33 | using base::Closure; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 34 | using std::string; |
| 35 | using std::vector; |
| 36 | |
| 37 | namespace shill { |
| 38 | |
| 39 | // static |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 40 | const char CellularCapabilityUniversal::kConnectPin[] = "pin"; |
| 41 | const char CellularCapabilityUniversal::kConnectOperatorId[] = "operator-id"; |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 42 | const char CellularCapabilityUniversal::kConnectApn[] = "apn"; |
| 43 | const char CellularCapabilityUniversal::kConnectIPType[] = "ip-type"; |
| 44 | const char CellularCapabilityUniversal::kConnectUser[] = "user"; |
| 45 | const char CellularCapabilityUniversal::kConnectPassword[] = "password"; |
| 46 | const char CellularCapabilityUniversal::kConnectNumber[] = "number"; |
| 47 | const char CellularCapabilityUniversal::kConnectAllowRoaming[] = |
| 48 | "allow-roaming"; |
| 49 | const char CellularCapabilityUniversal::kConnectRMProtocol[] = "rm-protocol"; |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 50 | const int64 |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 51 | CellularCapabilityUniversal::kActivationRegistrationTimeoutMilliseconds = |
| 52 | 20000; |
| 53 | const int64 |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 54 | CellularCapabilityUniversal::kDefaultScanningOrSearchingTimeoutMilliseconds = |
| 55 | 60000; |
Arman Uguray | f6366ac | 2013-06-12 16:02:28 -0700 | [diff] [blame] | 56 | const int64 CellularCapabilityUniversal::kEnterPinTimeoutMilliseconds = 20000; |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 57 | const int64 |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 58 | CellularCapabilityUniversal::kRegistrationDroppedUpdateTimeoutMilliseconds = |
| 59 | 15000; |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 60 | const char CellularCapabilityUniversal::kGenericServiceNamePrefix[] = |
| 61 | "Mobile Network"; |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 62 | const char CellularCapabilityUniversal::kRootPath[] = "/"; |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 63 | const char CellularCapabilityUniversal::kStatusProperty[] = "status"; |
| 64 | const char CellularCapabilityUniversal::kOperatorLongProperty[] = |
| 65 | "operator-long"; |
| 66 | const char CellularCapabilityUniversal::kOperatorShortProperty[] = |
| 67 | "operator-short"; |
| 68 | const char CellularCapabilityUniversal::kOperatorCodeProperty[] = |
| 69 | "operator-code"; |
| 70 | const char CellularCapabilityUniversal::kOperatorAccessTechnologyProperty[] = |
| 71 | "access-technology"; |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 72 | const char CellularCapabilityUniversal::kIpConfigPropertyMethod[] = "method"; |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 73 | const char CellularCapabilityUniversal::kE362ModelId[] = "E362 WWAN"; |
Thieu Le | 2cac294 | 2013-03-05 18:41:08 -0800 | [diff] [blame] | 74 | const int CellularCapabilityUniversal::kSetPowerStateTimeoutMilliseconds = |
| 75 | 20000; |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 76 | unsigned int CellularCapabilityUniversal::friendly_service_name_id_ = 0; |
| 77 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 78 | |
| 79 | static const char kPhoneNumber[] = "*99#"; |
| 80 | |
| 81 | static string AccessTechnologyToString(uint32 access_technologies) { |
| 82 | if (access_technologies & MM_MODEM_ACCESS_TECHNOLOGY_LTE) |
| 83 | return flimflam::kNetworkTechnologyLte; |
| 84 | if (access_technologies & (MM_MODEM_ACCESS_TECHNOLOGY_EVDO0 | |
| 85 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA | |
| 86 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB)) |
| 87 | return flimflam::kNetworkTechnologyEvdo; |
| 88 | if (access_technologies & MM_MODEM_ACCESS_TECHNOLOGY_1XRTT) |
| 89 | return flimflam::kNetworkTechnology1Xrtt; |
| 90 | if (access_technologies & MM_MODEM_ACCESS_TECHNOLOGY_HSPA_PLUS) |
| 91 | return flimflam::kNetworkTechnologyHspaPlus; |
| 92 | if (access_technologies & (MM_MODEM_ACCESS_TECHNOLOGY_HSPA | |
| 93 | MM_MODEM_ACCESS_TECHNOLOGY_HSUPA | |
| 94 | MM_MODEM_ACCESS_TECHNOLOGY_HSDPA)) |
| 95 | return flimflam::kNetworkTechnologyHspa; |
| 96 | if (access_technologies & MM_MODEM_ACCESS_TECHNOLOGY_UMTS) |
| 97 | return flimflam::kNetworkTechnologyUmts; |
| 98 | if (access_technologies & MM_MODEM_ACCESS_TECHNOLOGY_EDGE) |
| 99 | return flimflam::kNetworkTechnologyEdge; |
| 100 | if (access_technologies & MM_MODEM_ACCESS_TECHNOLOGY_GPRS) |
| 101 | return flimflam::kNetworkTechnologyGprs; |
| 102 | if (access_technologies & (MM_MODEM_ACCESS_TECHNOLOGY_GSM_COMPACT | |
| 103 | MM_MODEM_ACCESS_TECHNOLOGY_GSM)) |
| 104 | return flimflam::kNetworkTechnologyGsm; |
| 105 | return ""; |
| 106 | } |
| 107 | |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 108 | static string AccessTechnologyToTechnologyFamily(uint32 access_technologies) { |
| 109 | if (access_technologies & (MM_MODEM_ACCESS_TECHNOLOGY_LTE | |
| 110 | MM_MODEM_ACCESS_TECHNOLOGY_HSPA_PLUS | |
| 111 | MM_MODEM_ACCESS_TECHNOLOGY_HSPA | |
| 112 | MM_MODEM_ACCESS_TECHNOLOGY_HSUPA | |
| 113 | MM_MODEM_ACCESS_TECHNOLOGY_HSDPA | |
| 114 | MM_MODEM_ACCESS_TECHNOLOGY_UMTS | |
| 115 | MM_MODEM_ACCESS_TECHNOLOGY_EDGE | |
| 116 | MM_MODEM_ACCESS_TECHNOLOGY_GPRS | |
| 117 | MM_MODEM_ACCESS_TECHNOLOGY_GSM_COMPACT | |
| 118 | MM_MODEM_ACCESS_TECHNOLOGY_GSM)) |
| 119 | return flimflam::kTechnologyFamilyGsm; |
| 120 | if (access_technologies & (MM_MODEM_ACCESS_TECHNOLOGY_EVDO0 | |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 121 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA | |
| 122 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB | |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 123 | MM_MODEM_ACCESS_TECHNOLOGY_1XRTT)) |
| 124 | return flimflam::kTechnologyFamilyCdma; |
| 125 | return ""; |
| 126 | } |
| 127 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 128 | CellularCapabilityUniversal::CellularCapabilityUniversal( |
| 129 | Cellular *cellular, |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 130 | ProxyFactory *proxy_factory, |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 131 | ModemInfo *modem_info) |
| 132 | : CellularCapability(cellular, proxy_factory, modem_info), |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 133 | weak_ptr_factory_(this), |
| 134 | registration_state_(MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN), |
Darin Petkov | e636c69 | 2012-05-31 10:22:17 +0200 | [diff] [blame] | 135 | current_capabilities_(MM_MODEM_CAPABILITY_NONE), |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 136 | access_technologies_(MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN), |
| 137 | home_provider_(NULL), |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 138 | provider_requires_roaming_(false), |
Ben Chan | 5d0d32c | 2013-01-08 02:05:29 -0800 | [diff] [blame] | 139 | resetting_(false), |
Ben Chan | fcca27b | 2013-01-22 15:03:44 -0800 | [diff] [blame] | 140 | scanning_supported_(false), |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 141 | scanning_(false), |
Ben Chan | 8a2c01e | 2013-01-23 10:09:14 -0800 | [diff] [blame] | 142 | scanning_or_searching_(false), |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 143 | scan_interval_(0), |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 144 | sim_present_(false), |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 145 | reset_done_(false), |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 146 | scanning_or_searching_timeout_milliseconds_( |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 147 | kDefaultScanningOrSearchingTimeoutMilliseconds), |
| 148 | activation_registration_timeout_milliseconds_( |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 149 | kActivationRegistrationTimeoutMilliseconds), |
| 150 | registration_dropped_update_timeout_milliseconds_( |
| 151 | kRegistrationDroppedUpdateTimeoutMilliseconds) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 152 | SLOG(Cellular, 2) << "Cellular capability constructed: Universal"; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 153 | PropertyStore *store = cellular->mutable_store(); |
| 154 | |
| 155 | store->RegisterConstString(flimflam::kCarrierProperty, &carrier_); |
| 156 | store->RegisterConstBool(flimflam::kSupportNetworkScanProperty, |
| 157 | &scanning_supported_); |
| 158 | store->RegisterConstString(flimflam::kEsnProperty, &esn_); |
| 159 | store->RegisterConstString(flimflam::kFirmwareRevisionProperty, |
| 160 | &firmware_revision_); |
| 161 | store->RegisterConstString(flimflam::kHardwareRevisionProperty, |
| 162 | &hardware_revision_); |
| 163 | store->RegisterConstString(flimflam::kImeiProperty, &imei_); |
| 164 | store->RegisterConstString(flimflam::kImsiProperty, &imsi_); |
Ben Chan | a5e2708 | 2012-07-31 14:30:28 -0700 | [diff] [blame] | 165 | store->RegisterConstString(flimflam::kIccidProperty, &sim_identifier_); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 166 | store->RegisterConstString(flimflam::kManufacturerProperty, &manufacturer_); |
| 167 | store->RegisterConstString(flimflam::kMdnProperty, &mdn_); |
| 168 | store->RegisterConstString(flimflam::kMeidProperty, &meid_); |
| 169 | store->RegisterConstString(flimflam::kMinProperty, &min_); |
| 170 | store->RegisterConstString(flimflam::kModelIDProperty, &model_id_); |
| 171 | store->RegisterConstString(flimflam::kSelectedNetworkProperty, |
| 172 | &selected_network_); |
| 173 | store->RegisterConstStringmaps(flimflam::kFoundNetworksProperty, |
| 174 | &found_networks_); |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 175 | store->RegisterConstBool(shill::kProviderRequiresRoamingProperty, |
| 176 | &provider_requires_roaming_); |
Ben Chan | 8a2c01e | 2013-01-23 10:09:14 -0800 | [diff] [blame] | 177 | store->RegisterConstBool(flimflam::kScanningProperty, |
| 178 | &scanning_or_searching_); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 179 | store->RegisterUint16(flimflam::kScanIntervalProperty, &scan_interval_); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 180 | HelpRegisterConstDerivedKeyValueStore( |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 181 | flimflam::kSIMLockStatusProperty, |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 182 | &CellularCapabilityUniversal::SimLockStatusToProperty); |
Thieu Le | 550247c | 2013-04-30 17:16:43 -0700 | [diff] [blame] | 183 | store->RegisterConstString(shill::kSIMOperatorIdProperty, &operator_id_); |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 184 | store->RegisterConstBool(shill::kSIMPresentProperty, &sim_present_); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 185 | store->RegisterConstStringmaps(flimflam::kCellularApnListProperty, |
| 186 | &apn_list_); |
| 187 | } |
| 188 | |
| 189 | KeyValueStore CellularCapabilityUniversal::SimLockStatusToProperty( |
| 190 | Error */*error*/) { |
| 191 | KeyValueStore status; |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 192 | string lock_type; |
| 193 | switch (sim_lock_status_.lock_type) { |
| 194 | case MM_MODEM_LOCK_SIM_PIN: |
| 195 | lock_type = "sim-pin"; |
| 196 | break; |
| 197 | case MM_MODEM_LOCK_SIM_PUK: |
| 198 | lock_type = "sim-puk"; |
| 199 | break; |
| 200 | default: |
| 201 | lock_type = ""; |
| 202 | break; |
| 203 | } |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 204 | status.SetBool(flimflam::kSIMLockEnabledProperty, sim_lock_status_.enabled); |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 205 | status.SetString(flimflam::kSIMLockTypeProperty, lock_type); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 206 | status.SetUint(flimflam::kSIMLockRetriesLeftProperty, |
| 207 | sim_lock_status_.retries_left); |
| 208 | return status; |
| 209 | } |
| 210 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 211 | void CellularCapabilityUniversal::HelpRegisterConstDerivedKeyValueStore( |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 212 | const string &name, |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 213 | KeyValueStore(CellularCapabilityUniversal::*get)(Error *error)) { |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 214 | cellular()->mutable_store()->RegisterDerivedKeyValueStore( |
| 215 | name, |
| 216 | KeyValueStoreAccessor( |
| 217 | new CustomAccessor<CellularCapabilityUniversal, KeyValueStore>( |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 218 | this, get, NULL))); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | void CellularCapabilityUniversal::InitProxies() { |
| 222 | modem_3gpp_proxy_.reset( |
| 223 | proxy_factory()->CreateMM1ModemModem3gppProxy(cellular()->dbus_path(), |
| 224 | cellular()->dbus_owner())); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 225 | modem_proxy_.reset( |
| 226 | proxy_factory()->CreateMM1ModemProxy(cellular()->dbus_path(), |
| 227 | cellular()->dbus_owner())); |
| 228 | modem_simple_proxy_.reset( |
| 229 | proxy_factory()->CreateMM1ModemSimpleProxy(cellular()->dbus_path(), |
| 230 | cellular()->dbus_owner())); |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 231 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 232 | modem_proxy_->set_state_changed_callback( |
| 233 | Bind(&CellularCapabilityUniversal::OnModemStateChangedSignal, |
| 234 | weak_ptr_factory_.GetWeakPtr())); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 235 | // Do not create a SIM proxy until the device is enabled because we |
| 236 | // do not yet know the object path of the sim object. |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 237 | // TODO(jglasgow): register callbacks |
| 238 | } |
| 239 | |
| 240 | void CellularCapabilityUniversal::StartModem(Error *error, |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 241 | const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 242 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 243 | InitProxies(); |
| 244 | |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 245 | // ModemManager must be in the disabled state to accept the Enable command. |
| 246 | Cellular::ModemState state = |
| 247 | static_cast<Cellular::ModemState>(modem_proxy_->State()); |
| 248 | if (state == Cellular::kModemStateDisabled) { |
| 249 | EnableModem(error, callback); |
| 250 | } else if (!cellular()->IsUnderlyingDeviceEnabled()) { |
| 251 | SLOG(Cellular, 2) << "Enabling of modem deferred because state is " |
| 252 | << state; |
| 253 | deferred_enable_modem_callback_ = |
| 254 | Bind(&CellularCapabilityUniversal::EnableModem, |
| 255 | weak_ptr_factory_.GetWeakPtr(), static_cast<Error *>(NULL), |
| 256 | callback); |
| 257 | } else { |
Thieu Le | b9c05e0 | 2013-03-04 14:09:32 -0800 | [diff] [blame] | 258 | // This request cannot be completed synchronously here because a method |
| 259 | // reply requires a continuation tag that is not created until the message |
| 260 | // handler returns, see DBus-C++ ObjectAdapter::handle_message(). |
| 261 | cellular()->dispatcher()->PostTask( |
| 262 | Bind(&CellularCapabilityUniversal::Start_ModemAlreadyEnabled, |
| 263 | weak_ptr_factory_.GetWeakPtr(), callback)); |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
| 267 | void CellularCapabilityUniversal::EnableModem(Error *error, |
| 268 | const ResultCallback &callback) { |
| 269 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 270 | CHECK(!callback.is_null()); |
Thieu Le | e3b3659 | 2012-08-30 17:50:26 -0700 | [diff] [blame] | 271 | Error local_error(Error::kOperationInitiated); |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 272 | modem_info()->metrics()->NotifyDeviceEnableStarted( |
| 273 | cellular()->interface_index()); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 274 | modem_proxy_->Enable( |
| 275 | true, |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 276 | &local_error, |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 277 | Bind(&CellularCapabilityUniversal::Start_EnableModemCompleted, |
| 278 | weak_ptr_factory_.GetWeakPtr(), callback), |
| 279 | kTimeoutEnable); |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 280 | if (local_error.IsFailure()) { |
| 281 | SLOG(Cellular, 2) << __func__ << "Call to modem_proxy_->Enable() failed"; |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 282 | } |
| 283 | if (error) { |
| 284 | error->CopyFrom(local_error); |
| 285 | } |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 286 | } |
| 287 | |
Thieu Le | b9c05e0 | 2013-03-04 14:09:32 -0800 | [diff] [blame] | 288 | void CellularCapabilityUniversal::Start_ModemAlreadyEnabled( |
| 289 | const ResultCallback &callback) { |
| 290 | // Call GetProperties() here to sync up with the modem state |
| 291 | GetProperties(); |
| 292 | callback.Run(Error()); |
| 293 | } |
| 294 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 295 | void CellularCapabilityUniversal::Start_EnableModemCompleted( |
| 296 | const ResultCallback &callback, const Error &error) { |
Eric Shienbrood | 9b1bd7b | 2012-04-20 16:42:26 -0400 | [diff] [blame] | 297 | SLOG(Cellular, 2) << __func__ << ": " << error; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 298 | if (error.IsFailure()) { |
| 299 | callback.Run(error); |
| 300 | return; |
| 301 | } |
| 302 | |
| 303 | // After modem is enabled, it should be possible to get properties |
| 304 | // TODO(jglasgow): handle errors from GetProperties |
| 305 | GetProperties(); |
Thieu Le | 18c1107 | 2013-01-28 17:21:37 -0800 | [diff] [blame] | 306 | // We expect the modem to start scanning after it has been enabled. |
| 307 | // Change this if this behavior is no longer the case in the future. |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 308 | modem_info()->metrics()->NotifyDeviceEnableFinished( |
| 309 | cellular()->interface_index()); |
| 310 | modem_info()->metrics()->NotifyDeviceScanStarted( |
| 311 | cellular()->interface_index()); |
Thieu Le | 18c1107 | 2013-01-28 17:21:37 -0800 | [diff] [blame] | 312 | callback.Run(error); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | void CellularCapabilityUniversal::StopModem(Error *error, |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 316 | const ResultCallback &callback) { |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 317 | CHECK(!callback.is_null()); |
| 318 | CHECK(error); |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 319 | // If there is an outstanding registration change, simply ignore it since |
| 320 | // the service will be destroyed anyway. |
| 321 | if (!registration_dropped_update_callback_.IsCancelled()) { |
| 322 | registration_dropped_update_callback_.Cancel(); |
| 323 | SLOG(Cellular, 2) << __func__ << " Cancelled delayed deregister."; |
| 324 | } |
| 325 | |
Thieu Le | d001205 | 2012-07-25 16:09:09 -0700 | [diff] [blame] | 326 | Cellular::ModemState state = cellular()->modem_state(); |
| 327 | SLOG(Cellular, 2) << __func__ << "(" << state << ")"; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 328 | |
Thieu Le | d001205 | 2012-07-25 16:09:09 -0700 | [diff] [blame] | 329 | if (cellular()->IsModemRegistered()) { |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 330 | string all_bearers("/"); // "/" means all bearers. See Modemanager docs. |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 331 | modem_simple_proxy_->Disconnect( |
| 332 | all_bearers, |
| 333 | error, |
| 334 | Bind(&CellularCapabilityUniversal::Stop_DisconnectCompleted, |
| 335 | weak_ptr_factory_.GetWeakPtr(), callback), |
Thieu Le | 049adb5 | 2012-11-12 17:14:51 -0800 | [diff] [blame] | 336 | kTimeoutDisconnect); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 337 | if (error->IsFailure()) |
| 338 | callback.Run(*error); |
| 339 | } else { |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 340 | Closure task = Bind(&CellularCapabilityUniversal::Stop_Disable, |
| 341 | weak_ptr_factory_.GetWeakPtr(), |
| 342 | callback); |
| 343 | cellular()->dispatcher()->PostTask(task); |
| 344 | } |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 345 | deferred_enable_modem_callback_.Reset(); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | void CellularCapabilityUniversal::Stop_DisconnectCompleted( |
| 349 | const ResultCallback &callback, const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 350 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 351 | |
| 352 | LOG_IF(ERROR, error.IsFailure()) << "Disconnect failed. Ignoring."; |
| 353 | Stop_Disable(callback); |
| 354 | } |
| 355 | |
| 356 | void CellularCapabilityUniversal::Stop_Disable(const ResultCallback &callback) { |
| 357 | Error error; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 358 | modem_info()->metrics()->NotifyDeviceDisableStarted( |
| 359 | cellular()->interface_index()); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 360 | modem_proxy_->Enable( |
| 361 | false, &error, |
| 362 | Bind(&CellularCapabilityUniversal::Stop_DisableCompleted, |
| 363 | weak_ptr_factory_.GetWeakPtr(), callback), |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 364 | kTimeoutEnable); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 365 | if (error.IsFailure()) |
| 366 | callback.Run(error); |
| 367 | } |
| 368 | |
| 369 | void CellularCapabilityUniversal::Stop_DisableCompleted( |
| 370 | const ResultCallback &callback, const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 371 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 372 | |
Thieu Le | a2519bf | 2013-01-23 16:51:54 -0800 | [diff] [blame] | 373 | if (error.IsSuccess()) { |
Arman Uguray | ee464d3 | 2013-02-13 17:14:36 -0800 | [diff] [blame] | 374 | // The modem has been successfully disabled, but we still need to power it |
| 375 | // down. |
| 376 | Stop_PowerDown(callback); |
| 377 | } else { |
| 378 | // An error occurred; terminate the disable sequence. |
| 379 | callback.Run(error); |
Thieu Le | a2519bf | 2013-01-23 16:51:54 -0800 | [diff] [blame] | 380 | } |
Arman Uguray | ee464d3 | 2013-02-13 17:14:36 -0800 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | void CellularCapabilityUniversal::Stop_PowerDown( |
| 384 | const ResultCallback &callback) { |
| 385 | SLOG(Cellular, 2) << __func__; |
| 386 | Error error; |
| 387 | modem_proxy_->SetPowerState( |
| 388 | MM_MODEM_POWER_STATE_LOW, |
| 389 | &error, |
| 390 | Bind(&CellularCapabilityUniversal::Stop_PowerDownCompleted, |
| 391 | weak_ptr_factory_.GetWeakPtr(), callback), |
Thieu Le | 2cac294 | 2013-03-05 18:41:08 -0800 | [diff] [blame] | 392 | kSetPowerStateTimeoutMilliseconds); |
Arman Uguray | ee464d3 | 2013-02-13 17:14:36 -0800 | [diff] [blame] | 393 | |
| 394 | if (error.IsFailure()) |
| 395 | // This really shouldn't happen, but if it does, report success, |
| 396 | // because a stop initiated power down is only called if the |
| 397 | // modem was successfully disabled, but the failure of this |
| 398 | // operation should still be propagated up as a successful disable. |
| 399 | Stop_PowerDownCompleted(callback, error); |
| 400 | } |
| 401 | |
| 402 | void CellularCapabilityUniversal::Stop_PowerDownCompleted( |
| 403 | const ResultCallback &callback, |
| 404 | const Error &error) { |
| 405 | SLOG(Cellular, 2) << __func__; |
| 406 | |
| 407 | if (error.IsFailure()) |
| 408 | SLOG(Cellular, 2) << "Ignoring error returned by SetPowerState: " << error; |
| 409 | |
| 410 | // Since the disable succeeded, if power down fails, we currently fail |
| 411 | // silently, i.e. we need to report the disable operation as having |
| 412 | // succeeded. |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 413 | modem_info()->metrics()->NotifyDeviceDisableFinished( |
| 414 | cellular()->interface_index()); |
Arman Uguray | ee464d3 | 2013-02-13 17:14:36 -0800 | [diff] [blame] | 415 | ReleaseProxies(); |
| 416 | callback.Run(Error()); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | void CellularCapabilityUniversal::Connect(const DBusPropertiesMap &properties, |
| 420 | Error *error, |
| 421 | const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 422 | SLOG(Cellular, 2) << __func__; |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 423 | DBusPathCallback cb = Bind(&CellularCapabilityUniversal::OnConnectReply, |
| 424 | weak_ptr_factory_.GetWeakPtr(), |
| 425 | callback); |
| 426 | modem_simple_proxy_->Connect(properties, error, cb, kTimeoutConnect); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | void CellularCapabilityUniversal::Disconnect(Error *error, |
| 430 | const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 431 | SLOG(Cellular, 2) << __func__; |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 432 | // If a deferred registration loss request exists, process it. |
| 433 | if (!registration_dropped_update_callback_.IsCancelled()) { |
| 434 | registration_dropped_update_callback_.callback().Run(); |
| 435 | DCHECK(cellular()->state() != Cellular::kStateConnected && |
| 436 | cellular()->state() != Cellular::kStateLinked); |
| 437 | SLOG(Cellular, 1) << "Processed deferred registration loss before " |
| 438 | << "disconnect request."; |
| 439 | } |
Thieu Le | 5d6864a | 2012-07-20 11:43:51 -0700 | [diff] [blame] | 440 | if (bearer_path_.empty()) { |
| 441 | LOG(WARNING) << "In " << __func__ << "(): " |
| 442 | << "Ignoring attempt to disconnect without bearer"; |
Thieu Le | 3d27539 | 2012-07-20 15:32:58 -0700 | [diff] [blame] | 443 | } else if (modem_simple_proxy_.get()) { |
Thieu Le | 5d6864a | 2012-07-20 11:43:51 -0700 | [diff] [blame] | 444 | modem_simple_proxy_->Disconnect(bearer_path_, |
| 445 | error, |
| 446 | callback, |
Thieu Le | 049adb5 | 2012-11-12 17:14:51 -0800 | [diff] [blame] | 447 | kTimeoutDisconnect); |
Thieu Le | 5d6864a | 2012-07-20 11:43:51 -0700 | [diff] [blame] | 448 | } |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 449 | } |
| 450 | |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 451 | void CellularCapabilityUniversal::DisconnectCleanup() { |
| 452 | SLOG(Cellular, 2) << __func__; |
| 453 | } |
| 454 | |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 455 | void CellularCapabilityUniversal::Activate(const string &carrier, |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 456 | Error *error, |
| 457 | const ResultCallback &callback) { |
| 458 | OnUnsupportedOperation(__func__, error); |
| 459 | } |
| 460 | |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 461 | void CellularCapabilityUniversal::OnActivationWaitForRegisterTimeout() { |
| 462 | SLOG(Cellular, 2) << __func__; |
| 463 | if (sim_identifier_.empty() || |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 464 | modem_info()->pending_activation_store()->GetActivationState( |
| 465 | PendingActivationStore::kIdentifierICCID, |
| 466 | sim_identifier_) == PendingActivationStore::kStateActivated) { |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 467 | SLOG(Cellular, 2) << "Modem is already scheduled to be reset."; |
| 468 | return; |
| 469 | } |
| 470 | if (IsMdnValid()) { |
| 471 | SLOG(Cellular, 2) << "MDN is valid. Already activated."; |
| 472 | return; |
| 473 | } |
| 474 | if (reset_done_) { |
| 475 | SLOG(Cellular, 2) << "Already done with reset."; |
| 476 | return; |
| 477 | } |
| 478 | |
| 479 | // Still not activated after timeout. Reset the modem. |
| 480 | SLOG(Cellular, 2) << "Still not registered after timeout. Reset directly " |
| 481 | << "to update MDN."; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 482 | modem_info()->pending_activation_store()->SetActivationState( |
| 483 | PendingActivationStore::kIdentifierICCID, |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 484 | sim_identifier_, |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 485 | PendingActivationStore::kStatePendingTimeout); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 486 | ResetAfterActivation(); |
| 487 | } |
| 488 | |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 489 | void CellularCapabilityUniversal::CompleteActivation(Error *error) { |
| 490 | SLOG(Cellular, 2) << __func__; |
| 491 | |
| 492 | // Persist the ICCID as "Pending Activation". |
| 493 | // We're assuming that when this function gets called, |sim_identifier_| will |
| 494 | // be non-empty. We still check here that is non-empty, though something is |
| 495 | // wrong if it is empty. |
| 496 | if (IsMdnValid()) { |
| 497 | SLOG(Cellular, 2) << "Already acquired a valid MDN. Already activated."; |
| 498 | return; |
| 499 | } |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 500 | |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 501 | if (sim_identifier_.empty()) { |
| 502 | SLOG(Cellular, 2) << "SIM identifier not available. Nothing to do."; |
| 503 | return; |
| 504 | } |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 505 | |
| 506 | // There should be a cellular service at this point. |
| 507 | if (cellular()->service().get()) |
| 508 | cellular()->service()->SetActivationState( |
| 509 | flimflam::kActivationStateActivating); |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 510 | modem_info()->pending_activation_store()->SetActivationState( |
| 511 | PendingActivationStore::kIdentifierICCID, |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 512 | sim_identifier_, |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 513 | PendingActivationStore::kStatePending); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 514 | |
| 515 | activation_wait_for_registration_callback_.Reset( |
| 516 | Bind(&CellularCapabilityUniversal::OnActivationWaitForRegisterTimeout, |
| 517 | weak_ptr_factory_.GetWeakPtr())); |
| 518 | cellular()->dispatcher()->PostDelayedTask( |
| 519 | activation_wait_for_registration_callback_.callback(), |
| 520 | activation_registration_timeout_milliseconds_); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | void CellularCapabilityUniversal::ResetAfterActivation() { |
| 524 | SLOG(Cellular, 2) << __func__; |
| 525 | |
| 526 | // Here the initial call to Reset might fail in rare cases. Simply ignore. |
| 527 | Error error; |
| 528 | ResultCallback callback = Bind( |
| 529 | &CellularCapabilityUniversal::OnResetAfterActivationReply, |
| 530 | weak_ptr_factory_.GetWeakPtr()); |
| 531 | Reset(&error, callback); |
| 532 | if (error.IsFailure()) |
| 533 | SLOG(Cellular, 2) << "Failed to reset after activation."; |
| 534 | } |
| 535 | |
| 536 | void CellularCapabilityUniversal::OnResetAfterActivationReply( |
| 537 | const Error &error) { |
| 538 | SLOG(Cellular, 2) << __func__; |
| 539 | if (error.IsFailure()) { |
| 540 | SLOG(Cellular, 2) << "Failed to reset after activation. Try again later."; |
| 541 | // TODO(armansito): Maybe post a delayed reset task? |
| 542 | return; |
| 543 | } |
| 544 | reset_done_ = true; |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 545 | activation_wait_for_registration_callback_.Cancel(); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 546 | UpdatePendingActivationState(); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 547 | } |
| 548 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 549 | void CellularCapabilityUniversal::UpdatePendingActivationState() { |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 550 | SLOG(Cellular, 2) << __func__; |
| 551 | |
| 552 | bool registered = |
| 553 | registration_state_ == MM_MODEM_3GPP_REGISTRATION_STATE_HOME; |
| 554 | |
| 555 | // If we have a valid MDN, the service is activated. Always try to remove |
| 556 | // the ICCID from persistence. |
| 557 | bool got_mdn = IsMdnValid(); |
| 558 | if (got_mdn && !sim_identifier_.empty()) |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 559 | modem_info()->pending_activation_store()->RemoveEntry( |
| 560 | PendingActivationStore::kIdentifierICCID, |
| 561 | sim_identifier_); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 562 | |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 563 | CellularServiceRefPtr service = cellular()->service(); |
| 564 | |
| 565 | if (!service.get()) |
| 566 | return; |
| 567 | |
| 568 | if (service->activation_state() == flimflam::kActivationStateActivated) |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 569 | // Either no service or already activated. Nothing to do. |
| 570 | return; |
| 571 | |
| 572 | // If we have a valid MDN or we can connect to the network, then the service |
| 573 | // is activated. |
| 574 | if (got_mdn || cellular()->state() == Cellular::kStateConnected || |
| 575 | cellular()->state() == Cellular::kStateLinked) { |
| 576 | SLOG(Cellular, 2) << "Marking service as activated."; |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 577 | service->SetActivationState(flimflam::kActivationStateActivated); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 578 | return; |
| 579 | } |
| 580 | |
| 581 | // If the ICCID is not available, the following logic can be delayed until it |
| 582 | // becomes available. |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 583 | if (sim_identifier_.empty()) |
| 584 | return; |
| 585 | |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 586 | PendingActivationStore::State state = |
| 587 | modem_info()->pending_activation_store()->GetActivationState( |
| 588 | PendingActivationStore::kIdentifierICCID, |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 589 | sim_identifier_); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 590 | switch (state) { |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 591 | case PendingActivationStore::kStatePending: |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 592 | // Always mark the service as activating here, as the ICCID could have |
| 593 | // been unavailable earlier. |
| 594 | service->SetActivationState(flimflam::kActivationStateActivating); |
| 595 | if (reset_done_) { |
| 596 | SLOG(Cellular, 2) << "Post-payment activation reset complete."; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 597 | modem_info()->pending_activation_store()->SetActivationState( |
| 598 | PendingActivationStore::kIdentifierICCID, |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 599 | sim_identifier_, |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 600 | PendingActivationStore::kStateActivated); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 601 | } else if (registered) { |
| 602 | SLOG(Cellular, 2) << "Resetting modem for activation."; |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 603 | activation_wait_for_registration_callback_.Cancel(); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 604 | ResetAfterActivation(); |
| 605 | } |
| 606 | break; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 607 | case PendingActivationStore::kStateActivated: |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 608 | if (registered) { |
| 609 | // Trigger auto connect here. |
| 610 | SLOG(Cellular, 2) << "Modem has been reset at least once, try to " |
| 611 | << "autoconnect to force MDN to update."; |
| 612 | service->AutoConnect(); |
| 613 | } |
| 614 | break; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 615 | case PendingActivationStore::kStatePendingTimeout: |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 616 | SLOG(Cellular, 2) << "Modem failed to register within timeout, but has " |
| 617 | << "been reset at least once."; |
| 618 | if (registered) { |
| 619 | SLOG(Cellular, 2) << "Registered to network, marking as activated."; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 620 | modem_info()->pending_activation_store()->SetActivationState( |
| 621 | PendingActivationStore::kIdentifierICCID, |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 622 | sim_identifier_, |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 623 | PendingActivationStore::kStateActivated); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 624 | service->SetActivationState(flimflam::kActivationStateActivated); |
| 625 | } |
| 626 | break; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 627 | case PendingActivationStore::kStateUnknown: |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 628 | // No entry exists for this ICCID. Nothing to do. |
| 629 | break; |
| 630 | default: |
| 631 | NOTREACHED(); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 632 | } |
| 633 | } |
| 634 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 635 | void CellularCapabilityUniversal::ReleaseProxies() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 636 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 637 | modem_3gpp_proxy_.reset(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 638 | modem_proxy_.reset(); |
| 639 | modem_simple_proxy_.reset(); |
| 640 | sim_proxy_.reset(); |
| 641 | } |
| 642 | |
Arman Uguray | c953357 | 2013-01-22 17:34:20 -0800 | [diff] [blame] | 643 | void CellularCapabilityUniversal::UpdateStorageIdentifier() { |
| 644 | if (!cellular()->service().get()) |
| 645 | return; |
| 646 | |
| 647 | // Lookup the unique identifier assigned to the current network and base the |
| 648 | // service's storage identifier on it. |
| 649 | const string prefix = "cellular_" + cellular()->address() + "_"; |
| 650 | string storage_id; |
| 651 | if (!operator_id_.empty()) { |
| 652 | const CellularOperatorInfo::CellularOperator *provider = |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 653 | modem_info()->cellular_operator_info()->GetCellularOperatorByMCCMNC( |
| 654 | operator_id_); |
Arman Uguray | c953357 | 2013-01-22 17:34:20 -0800 | [diff] [blame] | 655 | if (provider && !provider->identifier().empty()) { |
| 656 | storage_id = prefix + provider->identifier(); |
| 657 | } |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 658 | } |
Arman Uguray | c953357 | 2013-01-22 17:34:20 -0800 | [diff] [blame] | 659 | // If the above didn't work, append IMSI, if available. |
| 660 | if (storage_id.empty() && !imsi_.empty()) { |
| 661 | storage_id = prefix + imsi_; |
| 662 | } |
| 663 | if (!storage_id.empty()) { |
| 664 | cellular()->service()->SetStorageIdentifier(storage_id); |
| 665 | } |
| 666 | } |
| 667 | |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 668 | void CellularCapabilityUniversal::UpdateServiceActivationState() { |
| 669 | if (!cellular()->service().get()) |
| 670 | return; |
Ben Chan | 3d6de0e | 2012-12-10 12:01:34 -0800 | [diff] [blame] | 671 | bool activation_required = IsServiceActivationRequired(); |
Arman Uguray | 6bb252d | 2013-05-15 14:29:53 -0700 | [diff] [blame] | 672 | string activation_state; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 673 | PendingActivationStore::State state = |
| 674 | modem_info()->pending_activation_store()->GetActivationState( |
| 675 | PendingActivationStore::kIdentifierICCID, |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 676 | sim_identifier_); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 677 | if (!sim_identifier_.empty() && |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 678 | (state == PendingActivationStore::kStatePending || |
| 679 | state == PendingActivationStore::kStatePendingTimeout)) |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 680 | activation_state = flimflam::kActivationStateActivating; |
| 681 | else if (activation_required) |
| 682 | activation_state = flimflam::kActivationStateNotActivated; |
Arman Uguray | 6bb252d | 2013-05-15 14:29:53 -0700 | [diff] [blame] | 683 | else { |
| 684 | activation_state = flimflam::kActivationStateActivated; |
| 685 | |
| 686 | // Mark an activated service for auto-connect by default. Since data from |
| 687 | // the user profile will be loaded after the call to OnServiceCreated, this |
| 688 | // property will be corrected based on the user data at that time. |
| 689 | cellular()->service()->SetAutoConnect(true); |
| 690 | } |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 691 | cellular()->service()->SetActivationState(activation_state); |
Ben Chan | 3d6de0e | 2012-12-10 12:01:34 -0800 | [diff] [blame] | 692 | // TODO(benchan): For now, assume the cellular service is activated over |
| 693 | // a non-cellular network if service activation is required (i.e. a |
| 694 | // corresponding entry is found in the cellular operator info file). |
| 695 | // We will need to generalize this logic when migrating CDMA support from |
| 696 | // cromo to ModemManager. |
| 697 | cellular()->service()->SetActivateOverNonCellularNetwork(activation_required); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | void CellularCapabilityUniversal::OnServiceCreated() { |
| 701 | UpdateStorageIdentifier(); |
| 702 | UpdateServiceActivationState(); |
Ben Chan | e1e1e56 | 2013-01-26 00:39:01 -0800 | [diff] [blame] | 703 | UpdateScanningProperty(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 704 | UpdateServingOperator(); |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 705 | UpdateOLP(); |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 706 | |
| 707 | // WORKAROUND: |
| 708 | // E362 modems on Verizon network does not properly redirect when a SIM |
| 709 | // runs out of credits, we need to enforce out-of-credits detection. |
| 710 | // TODO(thieule): Remove this workaround (crosbug.com/p/18619). |
| 711 | if (model_id_ == kE362ModelId) |
| 712 | cellular()->service()->set_enforce_out_of_credits_detection(true); |
Arman Uguray | 7af0fac | 2013-03-18 17:35:35 -0700 | [diff] [blame] | 713 | |
| 714 | // Make sure that the network technology is set when the service gets |
| 715 | // created, just in case. |
| 716 | cellular()->service()->SetNetworkTechnology(GetNetworkTechnologyString()); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 717 | } |
| 718 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 719 | // Create the list of APNs to try, in the following order: |
| 720 | // - last APN that resulted in a successful connection attempt on the |
| 721 | // current network (if any) |
| 722 | // - the APN, if any, that was set by the user |
| 723 | // - the list of APNs found in the mobile broadband provider DB for the |
| 724 | // home provider associated with the current SIM |
| 725 | // - as a last resort, attempt to connect with no APN |
| 726 | void CellularCapabilityUniversal::SetupApnTryList() { |
| 727 | apn_try_list_.clear(); |
| 728 | |
| 729 | DCHECK(cellular()->service().get()); |
| 730 | const Stringmap *apn_info = cellular()->service()->GetLastGoodApn(); |
| 731 | if (apn_info) |
| 732 | apn_try_list_.push_back(*apn_info); |
| 733 | |
| 734 | apn_info = cellular()->service()->GetUserSpecifiedApn(); |
| 735 | if (apn_info) |
| 736 | apn_try_list_.push_back(*apn_info); |
| 737 | |
| 738 | apn_try_list_.insert(apn_try_list_.end(), apn_list_.begin(), apn_list_.end()); |
| 739 | } |
| 740 | |
| 741 | void CellularCapabilityUniversal::SetupConnectProperties( |
| 742 | DBusPropertiesMap *properties) { |
| 743 | SetupApnTryList(); |
| 744 | FillConnectPropertyMap(properties); |
| 745 | } |
| 746 | |
| 747 | void CellularCapabilityUniversal::FillConnectPropertyMap( |
| 748 | DBusPropertiesMap *properties) { |
| 749 | |
| 750 | // TODO(jglasgow): Is this really needed anymore? |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 751 | (*properties)[kConnectNumber].writer().append_string( |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 752 | kPhoneNumber); |
| 753 | |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 754 | (*properties)[kConnectAllowRoaming].writer().append_bool( |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 755 | AllowRoaming()); |
| 756 | |
| 757 | if (!apn_try_list_.empty()) { |
| 758 | // Leave the APN at the front of the list, so that it can be recorded |
| 759 | // if the connect attempt succeeds. |
| 760 | Stringmap apn_info = apn_try_list_.front(); |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 761 | SLOG(Cellular, 2) << __func__ << ": Using APN " |
| 762 | << apn_info[flimflam::kApnProperty]; |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 763 | (*properties)[kConnectApn].writer().append_string( |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 764 | apn_info[flimflam::kApnProperty].c_str()); |
| 765 | if (ContainsKey(apn_info, flimflam::kApnUsernameProperty)) |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 766 | (*properties)[kConnectUser].writer().append_string( |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 767 | apn_info[flimflam::kApnUsernameProperty].c_str()); |
| 768 | if (ContainsKey(apn_info, flimflam::kApnPasswordProperty)) |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 769 | (*properties)[kConnectPassword].writer().append_string( |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 770 | apn_info[flimflam::kApnPasswordProperty].c_str()); |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | void CellularCapabilityUniversal::OnConnectReply(const ResultCallback &callback, |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 775 | const DBus::Path &path, |
| 776 | const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 777 | SLOG(Cellular, 2) << __func__ << "(" << error << ")"; |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 778 | |
Jason Glasgow | 7234ec3 | 2012-05-23 16:01:21 -0400 | [diff] [blame] | 779 | CellularServiceRefPtr service = cellular()->service(); |
| 780 | if (!service) { |
| 781 | // The service could have been deleted before our Connect() request |
| 782 | // completes if the modem was enabled and then quickly disabled. |
| 783 | apn_try_list_.clear(); |
| 784 | } else if (error.IsFailure()) { |
| 785 | service->ClearLastGoodApn(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 786 | // The APN that was just tried (and failed) is still at the |
| 787 | // front of the list, about to be removed. If the list is empty |
| 788 | // after that, try one last time without an APN. This may succeed |
| 789 | // with some modems in some cases. |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 790 | if (RetriableConnectError(error) && !apn_try_list_.empty()) { |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 791 | apn_try_list_.pop_front(); |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 792 | SLOG(Cellular, 2) << "Connect failed with invalid APN, " |
| 793 | << apn_try_list_.size() << " remaining APNs to try"; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 794 | DBusPropertiesMap props; |
| 795 | FillConnectPropertyMap(&props); |
| 796 | Error error; |
| 797 | Connect(props, &error, callback); |
| 798 | return; |
| 799 | } |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 800 | } else { |
| 801 | if (!apn_try_list_.empty()) { |
Jason Glasgow | 7234ec3 | 2012-05-23 16:01:21 -0400 | [diff] [blame] | 802 | service->SetLastGoodApn(apn_try_list_.front()); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 803 | apn_try_list_.clear(); |
| 804 | } |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 805 | bearer_path_ = path; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | if (!callback.is_null()) |
| 809 | callback.Run(error); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 810 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 811 | UpdatePendingActivationState(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | bool CellularCapabilityUniversal::AllowRoaming() { |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 815 | return provider_requires_roaming_ || allow_roaming_property(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 816 | } |
| 817 | |
Arman Uguray | f84a424 | 2013-04-09 20:01:07 -0700 | [diff] [blame] | 818 | bool CellularCapabilityUniversal::ShouldDetectOutOfCredit() const { |
Arman Uguray | d42d8ec | 2013-04-08 19:28:21 -0700 | [diff] [blame] | 819 | return model_id_ == kE362ModelId; |
| 820 | } |
| 821 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 822 | void CellularCapabilityUniversal::GetProperties() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 823 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 824 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 825 | scoped_ptr<DBusPropertiesProxyInterface> properties_proxy( |
| 826 | proxy_factory()->CreateDBusPropertiesProxy(cellular()->dbus_path(), |
| 827 | cellular()->dbus_owner())); |
| 828 | DBusPropertiesMap properties( |
| 829 | properties_proxy->GetAll(MM_DBUS_INTERFACE_MODEM)); |
| 830 | OnModemPropertiesChanged(properties, vector<string>()); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 831 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 832 | properties = properties_proxy->GetAll(MM_DBUS_INTERFACE_MODEM_MODEM3GPP); |
| 833 | OnModem3GPPPropertiesChanged(properties, vector<string>()); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 834 | } |
| 835 | |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 836 | // static |
| 837 | string CellularCapabilityUniversal::GenerateNewGenericServiceName() { |
| 838 | return base::StringPrintf("%s %u", |
| 839 | kGenericServiceNamePrefix, |
| 840 | friendly_service_name_id_++); |
| 841 | } |
| 842 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 843 | string CellularCapabilityUniversal::CreateFriendlyServiceName() { |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 844 | SLOG(Cellular, 2) << __func__ << ": " << GetRoamingStateString(); |
Ben Chan | 092b12b | 2012-11-07 22:04:05 -0800 | [diff] [blame] | 845 | |
| 846 | // If |serving_operator_| does not have an operator ID, call |
| 847 | // UpdateOperatorInfo() to use |operator_id_| as a fallback when appropriate. |
| 848 | if (serving_operator_.GetCode().empty()) { |
| 849 | UpdateOperatorInfo(); |
| 850 | } |
| 851 | |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 852 | string name = serving_operator_.GetName(); |
| 853 | string home_provider_name = cellular()->home_provider().GetName(); |
| 854 | if (!name.empty()) { |
| 855 | // If roaming, try to show "<home-provider> | <serving-operator>", per 3GPP |
| 856 | // rules (TS 31.102 and annex A of 122.101). |
| 857 | if (registration_state_ == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING && |
| 858 | !home_provider_name.empty()) { |
| 859 | return home_provider_name + " | " + name; |
| 860 | } |
| 861 | return name; |
| 862 | } |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 863 | if (registration_state_ == MM_MODEM_3GPP_REGISTRATION_STATE_HOME && |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 864 | !home_provider_name.empty()) { |
| 865 | return home_provider_name; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 866 | } |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 867 | if (!serving_operator_.GetCode().empty()) { |
| 868 | return "cellular_" + serving_operator_.GetCode(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 869 | } |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 870 | return GenerateNewGenericServiceName(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | void CellularCapabilityUniversal::SetHomeProvider() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 874 | SLOG(Cellular, 2) << __func__ << "(IMSI: " << imsi_ |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 875 | << " SPN: " << spn_ << ")"; |
Arman Uguray | d73783f | 2013-01-31 16:11:21 -0800 | [diff] [blame] | 876 | |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 877 | if (!modem_info()->provider_db()) |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 878 | return; |
Arman Uguray | d73783f | 2013-01-31 16:11:21 -0800 | [diff] [blame] | 879 | |
| 880 | // MCCMNC can be determined either from IMSI or Operator Code. Use whichever |
| 881 | // one is available. If both were reported by the SIM, use IMSI. |
| 882 | const string &network_id = imsi_.empty() ? operator_id_ : imsi_; |
| 883 | mobile_provider *provider = mobile_provider_lookup_best_match( |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 884 | modem_info()->provider_db(), |
Arman Uguray | d73783f | 2013-01-31 16:11:21 -0800 | [diff] [blame] | 885 | spn_.c_str(), |
| 886 | network_id.c_str()); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 887 | if (!provider) { |
Arman Uguray | d73783f | 2013-01-31 16:11:21 -0800 | [diff] [blame] | 888 | SLOG(Cellular, 2) << "3GPP provider not found."; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 889 | return; |
| 890 | } |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 891 | |
| 892 | // Even if provider is the same as home_provider_, it is possible |
| 893 | // that the spn_ has changed. Run all the code below. |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 894 | home_provider_ = provider; |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 895 | provider_requires_roaming_ = home_provider_->requires_roaming; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 896 | Cellular::Operator oper; |
Arman Uguray | d73783f | 2013-01-31 16:11:21 -0800 | [diff] [blame] | 897 | // If Operator ID is available, use that as network code, otherwise |
| 898 | // use what was returned from the database. |
| 899 | if (!operator_id_.empty()) { |
| 900 | oper.SetCode(operator_id_); |
| 901 | } else if (provider->networks && provider->networks[0]) { |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 902 | oper.SetCode(provider->networks[0]); |
| 903 | } |
| 904 | if (provider->country) { |
| 905 | oper.SetCountry(provider->country); |
| 906 | } |
| 907 | if (spn_.empty()) { |
| 908 | const char *name = mobile_provider_get_name(provider); |
| 909 | if (name) { |
| 910 | oper.SetName(name); |
| 911 | } |
| 912 | } else { |
| 913 | oper.SetName(spn_); |
| 914 | } |
| 915 | cellular()->set_home_provider(oper); |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 916 | SLOG(Cellular, 2) << "Home provider: " << oper.GetCode() << ", " |
Darin Petkov | f508c82 | 2012-09-21 13:43:17 +0200 | [diff] [blame] | 917 | << oper.GetName() << ", " << oper.GetCountry() |
| 918 | << (provider_requires_roaming_ ? ", roaming required" : ""); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 919 | InitAPNList(); |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 920 | UpdateServiceName(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 921 | } |
| 922 | |
Ben Chan | 8a2c01e | 2013-01-23 10:09:14 -0800 | [diff] [blame] | 923 | void CellularCapabilityUniversal::UpdateScanningProperty() { |
| 924 | // Set the Scanning property to true if there is a ongoing network scan |
| 925 | // (i.e. |scanning_| is true) or the modem is enabled but not yet registered |
| 926 | // to a network. |
| 927 | // |
| 928 | // TODO(benchan): As the Device DBus interface currently does not have a |
| 929 | // State property to indicate whether the device is being enabled, set the |
| 930 | // Scanning property to true when the modem is being enabled such that |
| 931 | // the network UI can start showing the initializing/scanning animation as |
| 932 | // soon as the modem is being enabled. |
| 933 | Cellular::ModemState modem_state = cellular()->modem_state(); |
Ben Chan | 40a2f86 | 2013-02-13 17:44:38 -0800 | [diff] [blame] | 934 | bool is_activated_service_waiting_for_registration = |
| 935 | ((modem_state == Cellular::kModemStateEnabled || |
| 936 | modem_state == Cellular::kModemStateSearching) && |
Ben Chan | e1e1e56 | 2013-01-26 00:39:01 -0800 | [diff] [blame] | 937 | !IsServiceActivationRequired()); |
Ben Chan | 8a2c01e | 2013-01-23 10:09:14 -0800 | [diff] [blame] | 938 | bool new_scanning_or_searching = |
Ben Chan | 40a2f86 | 2013-02-13 17:44:38 -0800 | [diff] [blame] | 939 | modem_state == Cellular::kModemStateEnabling || |
| 940 | is_activated_service_waiting_for_registration || |
Ben Chan | 8a2c01e | 2013-01-23 10:09:14 -0800 | [diff] [blame] | 941 | scanning_; |
| 942 | if (new_scanning_or_searching != scanning_or_searching_) { |
| 943 | scanning_or_searching_ = new_scanning_or_searching; |
| 944 | cellular()->adaptor()->EmitBoolChanged(flimflam::kScanningProperty, |
| 945 | new_scanning_or_searching); |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 946 | |
| 947 | if (!scanning_or_searching_) { |
| 948 | SLOG(Cellular, 2) << "Initial network scan ended. Canceling timeout."; |
| 949 | scanning_or_searching_timeout_callback_.Cancel(); |
| 950 | } else if (scanning_or_searching_timeout_callback_.IsCancelled()) { |
| 951 | SLOG(Cellular, 2) << "Initial network scan started. Starting timeout."; |
| 952 | scanning_or_searching_timeout_callback_.Reset( |
| 953 | Bind(&CellularCapabilityUniversal::OnScanningOrSearchingTimeout, |
| 954 | weak_ptr_factory_.GetWeakPtr())); |
| 955 | cellular()->dispatcher()->PostDelayedTask( |
| 956 | scanning_or_searching_timeout_callback_.callback(), |
| 957 | scanning_or_searching_timeout_milliseconds_); |
| 958 | } |
Ben Chan | 8a2c01e | 2013-01-23 10:09:14 -0800 | [diff] [blame] | 959 | } |
| 960 | } |
| 961 | |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 962 | void CellularCapabilityUniversal::OnScanningOrSearchingTimeout() { |
| 963 | SLOG(Cellular, 2) << "Initial network scan timed out. Changing " |
| 964 | << "flimflam::kScanningProperty to |false|."; |
| 965 | scanning_or_searching_ = false; |
| 966 | cellular()->adaptor()->EmitBoolChanged(flimflam::kScanningProperty, false); |
| 967 | } |
| 968 | |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 969 | void CellularCapabilityUniversal::UpdateOLP() { |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 970 | if (!modem_info()->cellular_operator_info()) |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 971 | return; |
| 972 | |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 973 | const CellularService::OLP *result = |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 974 | modem_info()->cellular_operator_info()->GetOLPByMCCMNC(operator_id_); |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 975 | if (!result) |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 976 | return; |
| 977 | |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 978 | CellularService::OLP olp; |
| 979 | olp.CopyFrom(*result); |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 980 | string post_data = olp.GetPostData(); |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 981 | ReplaceSubstringsAfterOffset(&post_data, 0, "${iccid}", sim_identifier_); |
| 982 | ReplaceSubstringsAfterOffset(&post_data, 0, "${imei}", imei_); |
| 983 | ReplaceSubstringsAfterOffset(&post_data, 0, "${imsi}", imsi_); |
| 984 | ReplaceSubstringsAfterOffset(&post_data, 0, "${mdn}", mdn_); |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 985 | ReplaceSubstringsAfterOffset(&post_data, 0, "${min}", min_); |
| 986 | olp.SetPostData(post_data); |
| 987 | cellular()->service()->SetOLP(olp); |
| 988 | } |
| 989 | |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 990 | void CellularCapabilityUniversal::UpdateServiceName() { |
| 991 | if (cellular()->service()) { |
| 992 | cellular()->service()->SetFriendlyName(CreateFriendlyServiceName()); |
| 993 | } |
| 994 | } |
| 995 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 996 | void CellularCapabilityUniversal::UpdateOperatorInfo() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 997 | SLOG(Cellular, 2) << __func__; |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 998 | // TODO(armansito): Use CellularOperatorInfo here instead of |
| 999 | // mobile_provider_db. |
Ben Chan | 092b12b | 2012-11-07 22:04:05 -0800 | [diff] [blame] | 1000 | |
Arman Uguray | 3645c43 | 2013-01-31 15:57:26 -0800 | [diff] [blame] | 1001 | // Sometimes the modem fails to acquire the operator code OTA, in which case |
| 1002 | // |serving_operator_| may not have an operator ID (sometimes due to service |
| 1003 | // activation being required or broken modem firmware). Use |operator_id_| as |
| 1004 | // a fallback when available. |operator_id_| is retrieved from the SIM card. |
| 1005 | if (serving_operator_.GetCode().empty() && !operator_id_.empty()) { |
Ben Chan | 092b12b | 2012-11-07 22:04:05 -0800 | [diff] [blame] | 1006 | SLOG(Cellular, 2) << "Assuming operator '" << operator_id_ |
| 1007 | << "' as serving operator."; |
| 1008 | serving_operator_.SetCode(operator_id_); |
| 1009 | } |
| 1010 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1011 | const string &network_id = serving_operator_.GetCode(); |
| 1012 | if (!network_id.empty()) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1013 | SLOG(Cellular, 2) << "Looking up network id: " << network_id; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1014 | mobile_provider *provider = |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 1015 | mobile_provider_lookup_by_network(modem_info()->provider_db(), |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1016 | network_id.c_str()); |
| 1017 | if (provider) { |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 1018 | if (serving_operator_.GetName().empty()) { |
| 1019 | const char *provider_name = mobile_provider_get_name(provider); |
| 1020 | if (provider_name && *provider_name) { |
| 1021 | serving_operator_.SetName(provider_name); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1022 | } |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1023 | } |
Darin Petkov | a4ca3c3 | 2012-08-17 16:05:24 +0200 | [diff] [blame] | 1024 | if (provider->country && *provider->country) { |
| 1025 | serving_operator_.SetCountry(provider->country); |
| 1026 | } |
| 1027 | SLOG(Cellular, 2) << "Operator name: " << serving_operator_.GetName() |
| 1028 | << ", country: " << serving_operator_.GetCountry(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1029 | } else { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1030 | SLOG(Cellular, 2) << "GSM provider not found."; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1031 | } |
| 1032 | } |
| 1033 | UpdateServingOperator(); |
| 1034 | } |
| 1035 | |
| 1036 | void CellularCapabilityUniversal::UpdateServingOperator() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1037 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1038 | if (cellular()->service().get()) { |
| 1039 | cellular()->service()->SetServingOperator(serving_operator_); |
| 1040 | } |
| 1041 | } |
| 1042 | |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 1043 | void CellularCapabilityUniversal::UpdateBearerPath() { |
| 1044 | SLOG(Cellular, 2) << __func__; |
| 1045 | DBusPathsCallback cb = Bind(&CellularCapabilityUniversal::OnListBearersReply, |
| 1046 | weak_ptr_factory_.GetWeakPtr()); |
| 1047 | Error error; |
| 1048 | modem_proxy_->ListBearers(&error, cb, kTimeoutDefault); |
| 1049 | } |
| 1050 | |
| 1051 | void CellularCapabilityUniversal::OnListBearersReply( |
| 1052 | const std::vector<DBus::Path> &paths, |
| 1053 | const Error &error) { |
| 1054 | SLOG(Cellular, 2) << __func__ << "(" << error << ")"; |
| 1055 | if (error.IsFailure()) { |
| 1056 | SLOG(Cellular, 2) << "ListBearers failed with error: " << error; |
| 1057 | return; |
| 1058 | } |
| 1059 | // Look for the first active bearer and use its path as the connected |
| 1060 | // one. Right now, we don't allow more than one active bearer. |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 1061 | DBus::Path new_bearer_path; |
| 1062 | uint32 ipconfig_method(MM_BEARER_IP_METHOD_UNKNOWN); |
| 1063 | string network_device; |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 1064 | for (size_t i = 0; i < paths.size(); ++i) { |
| 1065 | const DBus::Path &path = paths[i]; |
| 1066 | scoped_ptr<mm1::BearerProxyInterface> bearer_proxy( |
| 1067 | proxy_factory()->CreateBearerProxy(path, cellular()->dbus_owner())); |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 1068 | if (!bearer_proxy->Connected()) { |
| 1069 | continue; |
| 1070 | } |
| 1071 | CHECK(new_bearer_path.empty()) << "Found more than one active bearer."; |
| 1072 | network_device = bearer_proxy->Interface(); |
| 1073 | SLOG(Cellular, 2) << "Found active bearer \"" << path << "\"."; |
| 1074 | SLOG(Cellular, 2) << "Bearer uses interface \"" << network_device << "\"."; |
| 1075 | // TODO(quiche): Add support for scenarios where the bearer is |
| 1076 | // IPv6 only, or where there are conflicting configuration methods |
| 1077 | // for IPv4 and IPv6. crbug.com/248360. |
| 1078 | DBusPropertiesMap bearer_ip4config = bearer_proxy->Ip4Config(); |
| 1079 | if (ContainsKey(bearer_ip4config, kIpConfigPropertyMethod)) { |
| 1080 | ipconfig_method = bearer_ip4config[kIpConfigPropertyMethod].reader(). |
| 1081 | get_uint32(); |
| 1082 | SLOG(Cellular, 2) << "Bearer has IPv4 config method " << ipconfig_method; |
| 1083 | } else { |
| 1084 | SLOG(Cellular, 2) << "Bearer does not specify IPv4 config method."; |
| 1085 | for (const auto &i : bearer_ip4config) { |
| 1086 | SLOG(Cellular, 5) << "Bearer IPv4 config has key \"" |
| 1087 | << i.first |
| 1088 | << "\"."; |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 1089 | } |
| 1090 | } |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 1091 | new_bearer_path = path; |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 1092 | } |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 1093 | bearer_path_ = new_bearer_path; |
| 1094 | if (new_bearer_path.empty()) { |
| 1095 | SLOG(Cellular, 2) << "No active bearer found."; |
| 1096 | return; |
| 1097 | } |
| 1098 | if (ipconfig_method == MM_BEARER_IP_METHOD_PPP) { |
| 1099 | cellular()->StartPPP(network_device); |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 1100 | } |
| 1101 | } |
| 1102 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1103 | void CellularCapabilityUniversal::InitAPNList() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1104 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1105 | if (!home_provider_) { |
| 1106 | return; |
| 1107 | } |
| 1108 | apn_list_.clear(); |
| 1109 | for (int i = 0; i < home_provider_->num_apns; ++i) { |
| 1110 | Stringmap props; |
| 1111 | mobile_apn *apn = home_provider_->apns[i]; |
| 1112 | if (apn->value) { |
| 1113 | props[flimflam::kApnProperty] = apn->value; |
| 1114 | } |
| 1115 | if (apn->username) { |
| 1116 | props[flimflam::kApnUsernameProperty] = apn->username; |
| 1117 | } |
| 1118 | if (apn->password) { |
| 1119 | props[flimflam::kApnPasswordProperty] = apn->password; |
| 1120 | } |
| 1121 | // Find the first localized and non-localized name, if any. |
| 1122 | const localized_name *lname = NULL; |
| 1123 | const localized_name *name = NULL; |
| 1124 | for (int j = 0; j < apn->num_names; ++j) { |
| 1125 | if (apn->names[j]->lang) { |
| 1126 | if (!lname) { |
| 1127 | lname = apn->names[j]; |
| 1128 | } |
| 1129 | } else if (!name) { |
| 1130 | name = apn->names[j]; |
| 1131 | } |
| 1132 | } |
| 1133 | if (name) { |
| 1134 | props[flimflam::kApnNameProperty] = name->name; |
| 1135 | } |
| 1136 | if (lname) { |
| 1137 | props[flimflam::kApnLocalizedNameProperty] = lname->name; |
| 1138 | props[flimflam::kApnLanguageProperty] = lname->lang; |
| 1139 | } |
| 1140 | apn_list_.push_back(props); |
| 1141 | } |
Darin Petkov | db6083f | 2012-08-16 12:50:23 +0200 | [diff] [blame] | 1142 | if (cellular()->adaptor()) { |
| 1143 | cellular()->adaptor()->EmitStringmapsChanged( |
| 1144 | flimflam::kCellularApnListProperty, apn_list_); |
| 1145 | } else { |
| 1146 | LOG(ERROR) << "Null RPC service adaptor."; |
| 1147 | } |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1148 | } |
| 1149 | |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 1150 | bool CellularCapabilityUniversal::IsServiceActivationRequired() const { |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1151 | if (!sim_identifier_.empty() && |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 1152 | modem_info()->pending_activation_store()->GetActivationState( |
| 1153 | PendingActivationStore::kIdentifierICCID, |
| 1154 | sim_identifier_) != PendingActivationStore::kStateUnknown) |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1155 | return false; |
| 1156 | |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 1157 | // If there is no online payment portal information, it's safer to assume |
| 1158 | // the service does not require activation. |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 1159 | if (!modem_info()->cellular_operator_info()) |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 1160 | return false; |
| 1161 | |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 1162 | const CellularService::OLP *olp = |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 1163 | modem_info()->cellular_operator_info()->GetOLPByMCCMNC(operator_id_); |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 1164 | if (!olp) |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 1165 | return false; |
| 1166 | |
| 1167 | // To avoid false positives, it's safer to assume the service does not |
| 1168 | // require activation if MDN is not set. |
| 1169 | if (mdn_.empty()) |
| 1170 | return false; |
| 1171 | |
Ben Chan | d759252 | 2013-02-13 16:02:01 -0800 | [diff] [blame] | 1172 | // If MDN contains only zeros, the service requires activation. |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1173 | return !IsMdnValid(); |
| 1174 | } |
| 1175 | |
| 1176 | bool CellularCapabilityUniversal::IsMdnValid() const { |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 1177 | // Note that |mdn_| is normalized to contain only digits in OnMdnChanged(). |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 1178 | for (size_t i = 0; i < mdn_.size(); ++i) { |
Ben Chan | d759252 | 2013-02-13 16:02:01 -0800 | [diff] [blame] | 1179 | if (mdn_[i] != '0') |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1180 | return true; |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 1181 | } |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1182 | return false; |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 1183 | } |
| 1184 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1185 | // always called from an async context |
| 1186 | void CellularCapabilityUniversal::Register(const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1187 | SLOG(Cellular, 2) << __func__ << " \"" << selected_network_ << "\""; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1188 | CHECK(!callback.is_null()); |
| 1189 | Error error; |
| 1190 | ResultCallback cb = Bind(&CellularCapabilityUniversal::OnRegisterReply, |
| 1191 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 1192 | modem_3gpp_proxy_->Register(selected_network_, &error, cb, kTimeoutRegister); |
| 1193 | if (error.IsFailure()) |
| 1194 | callback.Run(error); |
| 1195 | } |
| 1196 | |
| 1197 | void CellularCapabilityUniversal::RegisterOnNetwork( |
| 1198 | const string &network_id, |
| 1199 | Error *error, |
| 1200 | const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1201 | SLOG(Cellular, 2) << __func__ << "(" << network_id << ")"; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1202 | CHECK(error); |
| 1203 | desired_network_ = network_id; |
| 1204 | ResultCallback cb = Bind(&CellularCapabilityUniversal::OnRegisterReply, |
| 1205 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 1206 | modem_3gpp_proxy_->Register(network_id, error, cb, kTimeoutRegister); |
| 1207 | } |
| 1208 | |
| 1209 | void CellularCapabilityUniversal::OnRegisterReply( |
| 1210 | const ResultCallback &callback, |
| 1211 | const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1212 | SLOG(Cellular, 2) << __func__ << "(" << error << ")"; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1213 | |
| 1214 | if (error.IsSuccess()) { |
| 1215 | selected_network_ = desired_network_; |
| 1216 | desired_network_.clear(); |
| 1217 | callback.Run(error); |
| 1218 | return; |
| 1219 | } |
| 1220 | // If registration on the desired network failed, |
| 1221 | // try to register on the home network. |
| 1222 | if (!desired_network_.empty()) { |
| 1223 | desired_network_.clear(); |
| 1224 | selected_network_.clear(); |
| 1225 | LOG(INFO) << "Couldn't register on selected network, trying home network"; |
| 1226 | Register(callback); |
| 1227 | return; |
| 1228 | } |
| 1229 | callback.Run(error); |
| 1230 | } |
| 1231 | |
| 1232 | bool CellularCapabilityUniversal::IsRegistered() { |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 1233 | return IsRegisteredState(registration_state_); |
| 1234 | } |
| 1235 | |
| 1236 | bool CellularCapabilityUniversal::IsRegisteredState( |
| 1237 | MMModem3gppRegistrationState state) { |
| 1238 | return (state == MM_MODEM_3GPP_REGISTRATION_STATE_HOME || |
| 1239 | state == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1240 | } |
| 1241 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 1242 | void CellularCapabilityUniversal::SetUnregistered(bool searching) { |
| 1243 | // If we're already in some non-registered state, don't override that |
| 1244 | if (registration_state_ == MM_MODEM_3GPP_REGISTRATION_STATE_HOME || |
| 1245 | registration_state_ == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING) { |
| 1246 | registration_state_ = |
| 1247 | (searching ? MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING : |
| 1248 | MM_MODEM_3GPP_REGISTRATION_STATE_IDLE); |
| 1249 | } |
| 1250 | } |
| 1251 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1252 | void CellularCapabilityUniversal::RequirePIN( |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 1253 | const string &pin, bool require, |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1254 | Error *error, const ResultCallback &callback) { |
| 1255 | CHECK(error); |
| 1256 | sim_proxy_->EnablePin(pin, require, error, callback, kTimeoutDefault); |
| 1257 | } |
| 1258 | |
| 1259 | void CellularCapabilityUniversal::EnterPIN(const string &pin, |
| 1260 | Error *error, |
| 1261 | const ResultCallback &callback) { |
| 1262 | CHECK(error); |
Arman Uguray | f6366ac | 2013-06-12 16:02:28 -0700 | [diff] [blame] | 1263 | SLOG(Cellular, 2) << __func__; |
| 1264 | sim_proxy_->SendPin(pin, error, callback, kEnterPinTimeoutMilliseconds); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | void CellularCapabilityUniversal::UnblockPIN(const string &unblock_code, |
| 1268 | const string &pin, |
| 1269 | Error *error, |
| 1270 | const ResultCallback &callback) { |
| 1271 | CHECK(error); |
| 1272 | sim_proxy_->SendPuk(unblock_code, pin, error, callback, kTimeoutDefault); |
| 1273 | } |
| 1274 | |
| 1275 | void CellularCapabilityUniversal::ChangePIN( |
| 1276 | const string &old_pin, const string &new_pin, |
| 1277 | Error *error, const ResultCallback &callback) { |
| 1278 | CHECK(error); |
| 1279 | sim_proxy_->ChangePin(old_pin, new_pin, error, callback, kTimeoutDefault); |
| 1280 | } |
| 1281 | |
Ben Chan | 5d0d32c | 2013-01-08 02:05:29 -0800 | [diff] [blame] | 1282 | void CellularCapabilityUniversal::Reset(Error *error, |
| 1283 | const ResultCallback &callback) { |
| 1284 | SLOG(Cellular, 2) << __func__; |
| 1285 | CHECK(error); |
| 1286 | if (resetting_) { |
| 1287 | Error::PopulateAndLog(error, Error::kInProgress, "Already resetting"); |
| 1288 | return; |
| 1289 | } |
| 1290 | ResultCallback cb = Bind(&CellularCapabilityUniversal::OnResetReply, |
| 1291 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 1292 | modem_proxy_->Reset(error, cb, kTimeoutReset); |
| 1293 | if (!error->IsFailure()) { |
| 1294 | resetting_ = true; |
| 1295 | } |
| 1296 | } |
| 1297 | |
| 1298 | void CellularCapabilityUniversal::OnResetReply(const ResultCallback &callback, |
| 1299 | const Error &error) { |
| 1300 | SLOG(Cellular, 2) << __func__; |
| 1301 | resetting_ = false; |
| 1302 | if (!callback.is_null()) |
| 1303 | callback.Run(error); |
| 1304 | } |
| 1305 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1306 | void CellularCapabilityUniversal::Scan(Error *error, |
| 1307 | const ResultCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1308 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1309 | CHECK(error); |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 1310 | if (scanning_) { |
| 1311 | Error::PopulateAndLog(error, Error::kInProgress, "Already scanning"); |
| 1312 | return; |
| 1313 | } |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1314 | DBusPropertyMapsCallback cb = Bind(&CellularCapabilityUniversal::OnScanReply, |
| 1315 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 1316 | modem_3gpp_proxy_->Scan(error, cb, kTimeoutScan); |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 1317 | if (!error->IsFailure()) { |
| 1318 | scanning_ = true; |
Ben Chan | 8a2c01e | 2013-01-23 10:09:14 -0800 | [diff] [blame] | 1319 | UpdateScanningProperty(); |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 1320 | } |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | void CellularCapabilityUniversal::OnScanReply(const ResultCallback &callback, |
| 1324 | const ScanResults &results, |
| 1325 | const Error &error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1326 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1327 | |
| 1328 | // Error handling is weak. The current expectation is that on any |
| 1329 | // error, found_networks_ should be cleared and a property change |
| 1330 | // notification sent out. |
| 1331 | // |
| 1332 | // TODO(jglasgow): fix error handling |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 1333 | scanning_ = false; |
Ben Chan | 8a2c01e | 2013-01-23 10:09:14 -0800 | [diff] [blame] | 1334 | UpdateScanningProperty(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1335 | found_networks_.clear(); |
| 1336 | if (!error.IsFailure()) { |
| 1337 | for (ScanResults::const_iterator it = results.begin(); |
| 1338 | it != results.end(); ++it) { |
| 1339 | found_networks_.push_back(ParseScanResult(*it)); |
| 1340 | } |
| 1341 | } |
| 1342 | cellular()->adaptor()->EmitStringmapsChanged(flimflam::kFoundNetworksProperty, |
| 1343 | found_networks_); |
Gary Morain | ceba6aa | 2012-05-03 10:28:26 -0700 | [diff] [blame] | 1344 | |
| 1345 | // TODO(gmorain): This check for is_null() is a work-around because |
| 1346 | // Cellular::Scan() passes a null callback. Instead: 1. Have Cellular::Scan() |
| 1347 | // pass in a callback. 2. Have Cellular "own" the found_networks_ property |
| 1348 | // 3. Have Cellular EmitStingMapsChanged() 4. Share the code between GSM and |
| 1349 | // Universal. |
| 1350 | if (!callback.is_null()) |
| 1351 | callback.Run(error); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | Stringmap CellularCapabilityUniversal::ParseScanResult( |
| 1355 | const ScanResult &result) { |
| 1356 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1357 | /* ScanResults contain the following keys: |
| 1358 | |
| 1359 | "status" |
| 1360 | A MMModem3gppNetworkAvailability value representing network |
| 1361 | availability status, given as an unsigned integer (signature "u"). |
| 1362 | This key will always be present. |
| 1363 | |
| 1364 | "operator-long" |
| 1365 | Long-format name of operator, given as a string value (signature |
| 1366 | "s"). If the name is unknown, this field should not be present. |
| 1367 | |
| 1368 | "operator-short" |
| 1369 | Short-format name of operator, given as a string value |
| 1370 | (signature "s"). If the name is unknown, this field should not |
| 1371 | be present. |
| 1372 | |
| 1373 | "operator-code" |
| 1374 | Mobile code of the operator, given as a string value (signature |
| 1375 | "s"). Returned in the format "MCCMNC", where MCC is the |
| 1376 | three-digit ITU E.212 Mobile Country Code and MNC is the two- or |
| 1377 | three-digit GSM Mobile Network Code. e.g. "31026" or "310260". |
| 1378 | |
| 1379 | "access-technology" |
| 1380 | A MMModemAccessTechnology value representing the generic access |
| 1381 | technology used by this mobile network, given as an unsigned |
| 1382 | integer (signature "u"). |
| 1383 | */ |
| 1384 | Stringmap parsed; |
| 1385 | |
| 1386 | uint32 status; |
| 1387 | if (DBusProperties::GetUint32(result, kStatusProperty, &status)) { |
| 1388 | // numerical values are taken from 3GPP TS 27.007 Section 7.3. |
| 1389 | static const char * const kStatusString[] = { |
| 1390 | "unknown", // MM_MODEM_3GPP_NETWORK_AVAILABILITY_UNKNOWN |
| 1391 | "available", // MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE |
| 1392 | "current", // MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT |
| 1393 | "forbidden", // MM_MODEM_3GPP_NETWORK_AVAILABILITY_FORBIDDEN |
| 1394 | }; |
| 1395 | parsed[flimflam::kStatusProperty] = kStatusString[status]; |
| 1396 | } |
| 1397 | |
| 1398 | uint32 tech; // MMModemAccessTechnology |
| 1399 | if (DBusProperties::GetUint32(result, kOperatorAccessTechnologyProperty, |
| 1400 | &tech)) { |
| 1401 | parsed[flimflam::kTechnologyProperty] = AccessTechnologyToString(tech); |
| 1402 | } |
| 1403 | |
| 1404 | string operator_long, operator_short, operator_code; |
| 1405 | if (DBusProperties::GetString(result, kOperatorLongProperty, &operator_long)) |
| 1406 | parsed[flimflam::kLongNameProperty] = operator_long; |
| 1407 | if (DBusProperties::GetString(result, kOperatorShortProperty, |
| 1408 | &operator_short)) |
| 1409 | parsed[flimflam::kShortNameProperty] = operator_short; |
| 1410 | if (DBusProperties::GetString(result, kOperatorCodeProperty, &operator_code)) |
| 1411 | parsed[flimflam::kNetworkIdProperty] = operator_code; |
| 1412 | |
| 1413 | // If the long name is not available but the network ID is, look up the long |
| 1414 | // name in the mobile provider database. |
| 1415 | if ((!ContainsKey(parsed, flimflam::kLongNameProperty) || |
| 1416 | parsed[flimflam::kLongNameProperty].empty()) && |
| 1417 | ContainsKey(parsed, flimflam::kNetworkIdProperty)) { |
| 1418 | mobile_provider *provider = |
| 1419 | mobile_provider_lookup_by_network( |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 1420 | modem_info()->provider_db(), |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1421 | parsed[flimflam::kNetworkIdProperty].c_str()); |
| 1422 | if (provider) { |
| 1423 | const char *long_name = mobile_provider_get_name(provider); |
| 1424 | if (long_name && *long_name) { |
| 1425 | parsed[flimflam::kLongNameProperty] = long_name; |
| 1426 | } |
| 1427 | } |
| 1428 | } |
| 1429 | return parsed; |
| 1430 | } |
| 1431 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1432 | string CellularCapabilityUniversal::GetNetworkTechnologyString() const { |
Arman Uguray | 7af0fac | 2013-03-18 17:35:35 -0700 | [diff] [blame] | 1433 | // If we know that the modem is an E362, return LTE here to make sure that |
| 1434 | // Chrome sees LTE as the network technology even if the actual technology is |
| 1435 | // unknown. |
| 1436 | // TODO(armansito): This hack will cause the UI to display LTE even if the |
| 1437 | // modem doesn't support it at a given time. This might be problematic if we |
| 1438 | // ever want to support switching between access technologies (e.g. falling |
| 1439 | // back to 3G when LTE is not available). |
| 1440 | if (model_id_ == kE362ModelId) |
| 1441 | return flimflam::kNetworkTechnologyLte; |
| 1442 | |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1443 | // Order is important. Return the highest speed technology |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1444 | // TODO(jglasgow): change shill interfaces to a capability model |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1445 | return AccessTechnologyToString(access_technologies_); |
| 1446 | } |
| 1447 | |
| 1448 | string CellularCapabilityUniversal::GetRoamingStateString() const { |
| 1449 | switch (registration_state_) { |
| 1450 | case MM_MODEM_3GPP_REGISTRATION_STATE_HOME: |
| 1451 | return flimflam::kRoamingStateHome; |
| 1452 | case MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING: |
| 1453 | return flimflam::kRoamingStateRoaming; |
| 1454 | default: |
| 1455 | break; |
| 1456 | } |
| 1457 | return flimflam::kRoamingStateUnknown; |
| 1458 | } |
| 1459 | |
| 1460 | void CellularCapabilityUniversal::GetSignalQuality() { |
Nathan Williams | 218cbcd | 2012-04-17 16:48:44 -0400 | [diff] [blame] | 1461 | // TODO(njw): Switch to asynchronous calls (crosbug.com/17583). |
| 1462 | const DBus::Struct<unsigned int, bool> quality = |
| 1463 | modem_proxy_->SignalQuality(); |
| 1464 | OnSignalQualityChanged(quality._1); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1465 | } |
| 1466 | |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1467 | string CellularCapabilityUniversal::GetTypeString() const { |
| 1468 | return AccessTechnologyToTechnologyFamily(access_technologies_); |
| 1469 | } |
| 1470 | |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 1471 | void CellularCapabilityUniversal::OnModemPropertiesChanged( |
| 1472 | const DBusPropertiesMap &properties, |
| 1473 | const vector<string> &/* invalidated_properties */) { |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 1474 | // This solves a bootstrapping problem: If the modem is not yet |
| 1475 | // enabled, there are no proxy objects associated with the capability |
| 1476 | // object, so modem signals like StateChanged aren't seen. By monitoring |
| 1477 | // changes to the State property via the ModemManager, we're able to |
| 1478 | // get the initialization process started, which will result in the |
| 1479 | // creation of the proxy objects. |
| 1480 | // |
| 1481 | // The first time we see the change to State (when the modem state |
| 1482 | // is Unknown), we simply update the state, and rely on the Manager to |
| 1483 | // enable the device when it is registered with the Manager. On subsequent |
| 1484 | // changes to State, we need to explicitly enable the device ourselves. |
| 1485 | int32 istate; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1486 | if (DBusProperties::GetInt32(properties, MM_MODEM_PROPERTY_STATE, &istate)) { |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 1487 | Cellular::ModemState state = static_cast<Cellular::ModemState>(istate); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1488 | OnModemStateChanged(state); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 1489 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1490 | string string_value; |
Nathan Williams | e984080 | 2012-04-18 18:47:40 -0400 | [diff] [blame] | 1491 | if (DBusProperties::GetObjectPath(properties, |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1492 | MM_MODEM_PROPERTY_SIM, &string_value)) |
| 1493 | OnSimPathChanged(string_value); |
Ben Chan | 74924d8 | 2013-06-15 17:52:55 -0700 | [diff] [blame] | 1494 | |
| 1495 | DBusPropertiesMap::const_iterator it = |
| 1496 | properties.find(MM_MODEM_PROPERTY_SUPPORTEDCAPABILITIES); |
| 1497 | if (it != properties.end()) { |
| 1498 | const vector<uint32> &supported_capabilities = it->second; |
| 1499 | OnSupportedCapabilitesChanged(supported_capabilities); |
| 1500 | } |
| 1501 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1502 | uint32 uint_value; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1503 | if (DBusProperties::GetUint32(properties, |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1504 | MM_MODEM_PROPERTY_CURRENTCAPABILITIES, |
| 1505 | &uint_value)) |
| 1506 | OnModemCurrentCapabilitiesChanged(uint_value); |
| 1507 | // not needed: MM_MODEM_PROPERTY_MAXBEARERS |
| 1508 | // not needed: MM_MODEM_PROPERTY_MAXACTIVEBEARERS |
| 1509 | if (DBusProperties::GetString(properties, |
| 1510 | MM_MODEM_PROPERTY_MANUFACTURER, |
| 1511 | &string_value)) |
| 1512 | OnModemManufacturerChanged(string_value); |
| 1513 | if (DBusProperties::GetString(properties, |
| 1514 | MM_MODEM_PROPERTY_MODEL, |
| 1515 | &string_value)) |
| 1516 | OnModemModelChanged(string_value); |
| 1517 | if (DBusProperties::GetString(properties, |
| 1518 | MM_MODEM_PROPERTY_REVISION, |
| 1519 | &string_value)) |
| 1520 | OnModemRevisionChanged(string_value); |
| 1521 | // not needed: MM_MODEM_PROPERTY_DEVICEIDENTIFIER |
| 1522 | // not needed: MM_MODEM_PROPERTY_DEVICE |
| 1523 | // not needed: MM_MODEM_PROPERTY_DRIVER |
| 1524 | // not needed: MM_MODEM_PROPERTY_PLUGIN |
| 1525 | // not needed: MM_MODEM_PROPERTY_EQUIPMENTIDENTIFIER |
Nathan Williams | 218cbcd | 2012-04-17 16:48:44 -0400 | [diff] [blame] | 1526 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1527 | // Unlock required and SimLock |
Ben Chan | 74924d8 | 2013-06-15 17:52:55 -0700 | [diff] [blame] | 1528 | uint32 unlock_required; // This is really of type MMModemLock |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1529 | if (DBusProperties::GetUint32(properties, |
| 1530 | MM_MODEM_PROPERTY_UNLOCKREQUIRED, |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1531 | &unlock_required)) |
| 1532 | OnLockTypeChanged(static_cast<MMModemLock>(unlock_required)); |
| 1533 | |
| 1534 | // Unlock retries |
Ben Chan | 74924d8 | 2013-06-15 17:52:55 -0700 | [diff] [blame] | 1535 | it = properties.find(MM_MODEM_PROPERTY_UNLOCKRETRIES); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1536 | if (it != properties.end()) { |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1537 | LockRetryData lock_retries = it->second.operator LockRetryData(); |
| 1538 | OnLockRetriesChanged(lock_retries); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1539 | } |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1540 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1541 | if (DBusProperties::GetUint32(properties, |
| 1542 | MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES, |
| 1543 | &uint_value)) |
| 1544 | OnAccessTechnologiesChanged(uint_value); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1545 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1546 | it = properties.find(MM_MODEM_PROPERTY_SIGNALQUALITY); |
| 1547 | if (it != properties.end()) { |
| 1548 | DBus::Struct<unsigned int, bool> quality = it->second; |
| 1549 | OnSignalQualityChanged(quality._1); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1550 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1551 | vector<string> numbers; |
| 1552 | if (DBusProperties::GetStrings(properties, MM_MODEM_PROPERTY_OWNNUMBERS, |
| 1553 | &numbers)) { |
| 1554 | string mdn; |
| 1555 | if (numbers.size() > 0) |
| 1556 | mdn = numbers[0]; |
| 1557 | OnMdnChanged(mdn); |
| 1558 | } |
Ben Chan | 74924d8 | 2013-06-15 17:52:55 -0700 | [diff] [blame] | 1559 | |
| 1560 | it = properties.find(MM_MODEM_PROPERTY_SUPPORTEDMODES); |
| 1561 | if (it != properties.end()) { |
| 1562 | const vector<DBus::Struct<uint32, uint32>> &mm_supported_modes = it->second; |
| 1563 | vector<ModemModes> supported_modes; |
| 1564 | for (const auto &modes : mm_supported_modes) { |
| 1565 | supported_modes.push_back( |
| 1566 | ModemModes(modes._1, static_cast<MMModemMode>(modes._2))); |
| 1567 | } |
| 1568 | OnSupportedModesChanged(supported_modes); |
| 1569 | } |
| 1570 | |
| 1571 | it = properties.find(MM_MODEM_PROPERTY_CURRENTMODES); |
| 1572 | if (it != properties.end()) { |
| 1573 | const DBus::Struct<uint32, uint32> ¤t_modes = it->second; |
| 1574 | OnCurrentModesChanged(ModemModes( |
| 1575 | current_modes._1, static_cast<MMModemMode>(current_modes._2))); |
| 1576 | } |
| 1577 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1578 | // au: MM_MODEM_PROPERTY_SUPPORTEDBANDS, |
| 1579 | // au: MM_MODEM_PROPERTY_BANDS |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1580 | } |
| 1581 | |
| 1582 | void CellularCapabilityUniversal::OnDBusPropertiesChanged( |
| 1583 | const string &interface, |
| 1584 | const DBusPropertiesMap &changed_properties, |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 1585 | const vector<string> &invalidated_properties) { |
Jason Glasgow | 7234ec3 | 2012-05-23 16:01:21 -0400 | [diff] [blame] | 1586 | SLOG(Cellular, 2) << __func__ << "(" << interface << ")"; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 1587 | if (interface == MM_DBUS_INTERFACE_MODEM) { |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 1588 | OnModemPropertiesChanged(changed_properties, invalidated_properties); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 1589 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1590 | if (interface == MM_DBUS_INTERFACE_MODEM_MODEM3GPP) { |
| 1591 | OnModem3GPPPropertiesChanged(changed_properties, invalidated_properties); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1592 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1593 | if (interface == MM_DBUS_INTERFACE_SIM) { |
| 1594 | OnSimPropertiesChanged(changed_properties, invalidated_properties); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1595 | } |
| 1596 | } |
| 1597 | |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 1598 | bool CellularCapabilityUniversal::RetriableConnectError( |
| 1599 | const Error &error) const { |
| 1600 | if (error.type() == Error::kInvalidApn) |
| 1601 | return true; |
| 1602 | |
| 1603 | // modemmanager does not ever return kInvalidApn for E362 modems |
| 1604 | // with 1.41 firmware. It remains to be seem if this will change |
| 1605 | // with 3.x firmware. |
| 1606 | if ((model_id_ == kE362ModelId) && (error.type() == Error::kOperationFailed)) |
| 1607 | return true; |
| 1608 | |
| 1609 | return false; |
| 1610 | } |
| 1611 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1612 | void CellularCapabilityUniversal::OnNetworkModeSignal(uint32 /*mode*/) { |
| 1613 | // TODO(petkov): Implement this. |
| 1614 | NOTIMPLEMENTED(); |
| 1615 | } |
| 1616 | |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 1617 | bool CellularCapabilityUniversal::IsValidSimPath(const string &sim_path) const { |
| 1618 | return !sim_path.empty() && sim_path != kRootPath; |
| 1619 | } |
| 1620 | |
Ben Chan | d759252 | 2013-02-13 16:02:01 -0800 | [diff] [blame] | 1621 | string CellularCapabilityUniversal::NormalizeMdn(const string &mdn) const { |
| 1622 | string normalized_mdn; |
| 1623 | for (size_t i = 0; i < mdn.size(); ++i) { |
| 1624 | if (IsAsciiDigit(mdn[i])) |
| 1625 | normalized_mdn += mdn[i]; |
| 1626 | } |
| 1627 | return normalized_mdn; |
| 1628 | } |
| 1629 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1630 | void CellularCapabilityUniversal::OnSimPathChanged( |
| 1631 | const string &sim_path) { |
| 1632 | if (sim_path == sim_path_) |
| 1633 | return; |
| 1634 | |
| 1635 | mm1::SimProxyInterface *proxy = NULL; |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 1636 | if (IsValidSimPath(sim_path)) |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1637 | proxy = proxy_factory()->CreateSimProxy(sim_path, |
| 1638 | cellular()->dbus_owner()); |
| 1639 | sim_path_ = sim_path; |
| 1640 | sim_proxy_.reset(proxy); |
| 1641 | |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 1642 | if (!IsValidSimPath(sim_path)) { |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1643 | // Clear all data about the sim |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 1644 | imsi_ = ""; |
| 1645 | spn_ = ""; |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 1646 | sim_present_ = false; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1647 | OnSimIdentifierChanged(""); |
| 1648 | OnOperatorIdChanged(""); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1649 | } else { |
Ben Chan | bd3aee8 | 2012-10-16 23:52:04 -0700 | [diff] [blame] | 1650 | sim_present_ = true; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1651 | scoped_ptr<DBusPropertiesProxyInterface> properties_proxy( |
| 1652 | proxy_factory()->CreateDBusPropertiesProxy(sim_path, |
| 1653 | cellular()->dbus_owner())); |
| 1654 | // TODO(jglasgow): convert to async interface |
| 1655 | DBusPropertiesMap properties( |
| 1656 | properties_proxy->GetAll(MM_DBUS_INTERFACE_SIM)); |
| 1657 | OnSimPropertiesChanged(properties, vector<string>()); |
| 1658 | } |
| 1659 | } |
| 1660 | |
Ben Chan | 74924d8 | 2013-06-15 17:52:55 -0700 | [diff] [blame] | 1661 | void CellularCapabilityUniversal::OnSupportedCapabilitesChanged( |
| 1662 | const vector<uint32> &supported_capabilities) { |
| 1663 | supported_capabilities_ = supported_capabilities; |
| 1664 | } |
| 1665 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1666 | void CellularCapabilityUniversal::OnModemCurrentCapabilitiesChanged( |
| 1667 | uint32 current_capabilities) { |
| 1668 | current_capabilities_ = current_capabilities; |
Ben Chan | fcca27b | 2013-01-22 15:03:44 -0800 | [diff] [blame] | 1669 | |
| 1670 | // Only allow network scan when the modem's current capabilities support |
| 1671 | // GSM/UMTS. |
| 1672 | // |
| 1673 | // TODO(benchan): We should consider having the modem plugins in ModemManager |
| 1674 | // reporting whether network scan is supported. |
| 1675 | scanning_supported_ = |
| 1676 | (current_capabilities & MM_MODEM_CAPABILITY_GSM_UMTS) != 0; |
| 1677 | if (cellular()->adaptor()) { |
| 1678 | cellular()->adaptor()->EmitBoolChanged( |
| 1679 | flimflam::kSupportNetworkScanProperty, scanning_supported_); |
| 1680 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | void CellularCapabilityUniversal::OnMdnChanged( |
| 1684 | const string &mdn) { |
Ben Chan | d759252 | 2013-02-13 16:02:01 -0800 | [diff] [blame] | 1685 | mdn_ = NormalizeMdn(mdn); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1686 | UpdatePendingActivationState(); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | void CellularCapabilityUniversal::OnModemManufacturerChanged( |
| 1690 | const string &manufacturer) { |
| 1691 | manufacturer_ = manufacturer; |
| 1692 | } |
| 1693 | |
| 1694 | void CellularCapabilityUniversal::OnModemModelChanged( |
| 1695 | const string &model) { |
| 1696 | model_id_ = model; |
| 1697 | } |
| 1698 | |
| 1699 | void CellularCapabilityUniversal::OnModemRevisionChanged( |
| 1700 | const string &revision) { |
| 1701 | firmware_revision_ = revision; |
| 1702 | } |
| 1703 | |
| 1704 | void CellularCapabilityUniversal::OnModemStateChanged( |
| 1705 | Cellular::ModemState state) { |
| 1706 | Cellular::ModemState prev_modem_state = cellular()->modem_state(); |
| 1707 | bool was_enabled = cellular()->IsUnderlyingDeviceEnabled(); |
| 1708 | if (Cellular::IsEnabledModemState(state)) |
| 1709 | cellular()->set_modem_state(state); |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 1710 | SLOG(Cellular, 2) << __func__ << ": prev_modem_state: " << prev_modem_state |
| 1711 | << " was_enabled: " << was_enabled |
| 1712 | << " cellular state: " |
| 1713 | << cellular()->GetStateString(cellular()->state()); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1714 | if (prev_modem_state != Cellular::kModemStateUnknown && |
| 1715 | prev_modem_state != Cellular::kModemStateEnabling && |
| 1716 | !was_enabled && |
| 1717 | cellular()->state() == Cellular::kStateDisabled && |
| 1718 | cellular()->IsUnderlyingDeviceEnabled()) { |
| 1719 | cellular()->SetEnabled(true); |
| 1720 | } |
Ben Chan | 8a2c01e | 2013-01-23 10:09:14 -0800 | [diff] [blame] | 1721 | UpdateScanningProperty(); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1722 | } |
| 1723 | |
| 1724 | void CellularCapabilityUniversal::OnAccessTechnologiesChanged( |
| 1725 | uint32 access_technologies) { |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1726 | if (access_technologies_ != access_technologies) { |
Jason Glasgow | bad114b | 2012-05-21 15:24:16 -0400 | [diff] [blame] | 1727 | const string old_type_string(GetTypeString()); |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1728 | access_technologies_ = access_technologies; |
Jason Glasgow | bad114b | 2012-05-21 15:24:16 -0400 | [diff] [blame] | 1729 | const string new_type_string(GetTypeString()); |
| 1730 | if (new_type_string != old_type_string) { |
| 1731 | // TODO(jglasgow): address layering violation of emitting change |
| 1732 | // signal here for a property owned by Cellular. |
| 1733 | cellular()->adaptor()->EmitStringChanged( |
| 1734 | flimflam::kTechnologyFamilyProperty, new_type_string); |
| 1735 | } |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1736 | if (cellular()->service().get()) { |
| 1737 | cellular()->service()->SetNetworkTechnology(GetNetworkTechnologyString()); |
| 1738 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1739 | } |
| 1740 | } |
| 1741 | |
Ben Chan | 74924d8 | 2013-06-15 17:52:55 -0700 | [diff] [blame] | 1742 | void CellularCapabilityUniversal::OnSupportedModesChanged( |
| 1743 | const vector<ModemModes> &supported_modes) { |
| 1744 | supported_modes_ = supported_modes; |
| 1745 | } |
| 1746 | |
| 1747 | void CellularCapabilityUniversal::OnCurrentModesChanged( |
| 1748 | const ModemModes ¤t_modes) { |
| 1749 | current_modes_ = current_modes; |
| 1750 | } |
| 1751 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1752 | void CellularCapabilityUniversal::OnLockRetriesChanged( |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1753 | const LockRetryData &lock_retries) { |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1754 | SLOG(Cellular, 2) << __func__; |
Arman Uguray | 192ad82 | 2013-06-13 19:49:16 -0700 | [diff] [blame] | 1755 | |
| 1756 | // Look for the retries left for the current lock. If the SIM |
| 1757 | // is not locked, then pick the first available value. |
| 1758 | LockRetryData::const_iterator it; |
| 1759 | if (sim_lock_status_.lock_type != MM_MODEM_LOCK_NONE && |
| 1760 | sim_lock_status_.lock_type != MM_MODEM_LOCK_UNKNOWN) |
| 1761 | it = lock_retries.find(sim_lock_status_.lock_type); |
| 1762 | else |
| 1763 | it = lock_retries.begin(); |
| 1764 | if (it != lock_retries.end()) |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1765 | sim_lock_status_.retries_left = it->second; |
Arman Uguray | 192ad82 | 2013-06-13 19:49:16 -0700 | [diff] [blame] | 1766 | else |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1767 | // Unknown, use 999 |
| 1768 | sim_lock_status_.retries_left = 999; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1769 | OnSimLockStatusChanged(); |
| 1770 | } |
| 1771 | |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1772 | void CellularCapabilityUniversal::OnLockTypeChanged( |
| 1773 | MMModemLock lock_type) { |
| 1774 | SLOG(Cellular, 2) << __func__ << ": " << lock_type; |
| 1775 | sim_lock_status_.lock_type = lock_type; |
Arman Uguray | 4ef02fd | 2013-06-13 20:14:20 -0700 | [diff] [blame] | 1776 | |
| 1777 | // If the SIM is in a locked state |sim_lock_status_.enabled| might be false. |
| 1778 | // This is because the corresponding property 'EnabledFacilityLocks' is on |
| 1779 | // the 3GPP interface and the 3GPP interface is not available while the Modem |
| 1780 | // is in the 'LOCKED' state. |
| 1781 | if (lock_type != MM_MODEM_LOCK_NONE && |
| 1782 | lock_type != MM_MODEM_LOCK_UNKNOWN && |
| 1783 | !sim_lock_status_.enabled) |
| 1784 | sim_lock_status_.enabled = true; |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1785 | OnSimLockStatusChanged(); |
| 1786 | } |
| 1787 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1788 | void CellularCapabilityUniversal::OnSimLockStatusChanged() { |
Arman Uguray | f6366ac | 2013-06-12 16:02:28 -0700 | [diff] [blame] | 1789 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1790 | cellular()->adaptor()->EmitKeyValueStoreChanged( |
| 1791 | flimflam::kSIMLockStatusProperty, SimLockStatusToProperty(NULL)); |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 1792 | |
| 1793 | // If the SIM is currently unlocked, assume that we need to refresh |
| 1794 | // carrier information, since a locked SIM prevents shill from obtaining |
| 1795 | // the necessary data to establish a connection later (e.g. IMSI). |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1796 | if (!sim_path_.empty() && |
Arman Uguray | 4ef02fd | 2013-06-13 20:14:20 -0700 | [diff] [blame] | 1797 | (sim_lock_status_.lock_type == MM_MODEM_LOCK_NONE || |
| 1798 | sim_lock_status_.lock_type == MM_MODEM_LOCK_UNKNOWN)) { |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 1799 | scoped_ptr<DBusPropertiesProxyInterface> properties_proxy( |
| 1800 | proxy_factory()->CreateDBusPropertiesProxy(sim_path_, |
| 1801 | cellular()->dbus_owner())); |
| 1802 | DBusPropertiesMap properties( |
| 1803 | properties_proxy->GetAll(MM_DBUS_INTERFACE_SIM)); |
| 1804 | OnSimPropertiesChanged(properties, vector<string>()); |
| 1805 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | void CellularCapabilityUniversal::OnModem3GPPPropertiesChanged( |
| 1809 | const DBusPropertiesMap &properties, |
| 1810 | const vector<string> &/* invalidated_properties */) { |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 1811 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1812 | string imei; |
| 1813 | if (DBusProperties::GetString(properties, |
| 1814 | MM_MODEM_MODEM3GPP_PROPERTY_IMEI, |
| 1815 | &imei)) |
| 1816 | OnImeiChanged(imei); |
| 1817 | |
| 1818 | // Handle registration state changes as a single change |
| 1819 | string operator_code = serving_operator_.GetCode(); |
| 1820 | string operator_name = serving_operator_.GetName(); |
| 1821 | MMModem3gppRegistrationState state = registration_state_; |
| 1822 | bool registration_changed = false; |
| 1823 | uint32 uint_value; |
| 1824 | if (DBusProperties::GetUint32(properties, |
| 1825 | MM_MODEM_MODEM3GPP_PROPERTY_REGISTRATIONSTATE, |
| 1826 | &uint_value)) { |
| 1827 | state = static_cast<MMModem3gppRegistrationState>(uint_value); |
| 1828 | registration_changed = true; |
| 1829 | } |
| 1830 | if (DBusProperties::GetString(properties, |
| 1831 | MM_MODEM_MODEM3GPP_PROPERTY_OPERATORCODE, |
| 1832 | &operator_code)) |
| 1833 | registration_changed = true; |
| 1834 | if (DBusProperties::GetString(properties, |
| 1835 | MM_MODEM_MODEM3GPP_PROPERTY_OPERATORNAME, |
| 1836 | &operator_name)) |
| 1837 | registration_changed = true; |
| 1838 | if (registration_changed) |
| 1839 | On3GPPRegistrationChanged(state, operator_code, operator_name); |
| 1840 | |
| 1841 | uint32 locks = 0; |
| 1842 | if (DBusProperties::GetUint32( |
| 1843 | properties, MM_MODEM_MODEM3GPP_PROPERTY_ENABLEDFACILITYLOCKS, |
| 1844 | &locks)) |
| 1845 | OnFacilityLocksChanged(locks); |
| 1846 | } |
| 1847 | |
| 1848 | void CellularCapabilityUniversal::OnImeiChanged(const string &imei) { |
| 1849 | imei_ = imei; |
| 1850 | } |
| 1851 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1852 | void CellularCapabilityUniversal::On3GPPRegistrationChanged( |
| 1853 | MMModem3gppRegistrationState state, |
| 1854 | const string &operator_code, |
| 1855 | const string &operator_name) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1856 | SLOG(Cellular, 2) << __func__ << ": regstate=" << state |
| 1857 | << ", opercode=" << operator_code |
| 1858 | << ", opername=" << operator_name; |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 1859 | |
| 1860 | // While the modem is connected, if the state changed from a registered state |
| 1861 | // to a non registered state, defer the state change by 15 seconds. |
| 1862 | // TODO(pprabhu) [crbug.com/241231] Add UMA stat to determine whether this |
| 1863 | // condition is specific to E362. If it is, guard the delayed update by E362 |
| 1864 | // specific flag. |
| 1865 | if (cellular()->modem_state() == Cellular::kModemStateConnected && |
| 1866 | IsRegistered() && !IsRegisteredState(state)) { |
| 1867 | if (!registration_dropped_update_callback_.IsCancelled()) { |
| 1868 | LOG(WARNING) << "Modem reported consecutive 3GPP registration drops. " |
| 1869 | << "Ignoring earlier notifications."; |
| 1870 | registration_dropped_update_callback_.Cancel(); |
| 1871 | } |
| 1872 | SLOG(Cellular, 2) << "Posted deferred registration state update"; |
| 1873 | registration_dropped_update_callback_.Reset( |
| 1874 | Bind(&CellularCapabilityUniversal::Handle3GPPRegistrationChange, |
| 1875 | weak_ptr_factory_.GetWeakPtr(), |
| 1876 | state, |
| 1877 | operator_code, |
| 1878 | operator_name)); |
| 1879 | cellular()->dispatcher()->PostDelayedTask( |
| 1880 | registration_dropped_update_callback_.callback(), |
| 1881 | registration_dropped_update_timeout_milliseconds_); |
| 1882 | } else { |
| 1883 | if (!registration_dropped_update_callback_.IsCancelled()) { |
| 1884 | SLOG(Cellular, 2) << "Cancelled a deferred registration state update"; |
| 1885 | registration_dropped_update_callback_.Cancel(); |
| 1886 | } |
| 1887 | Handle3GPPRegistrationChange(state, operator_code, operator_name); |
| 1888 | } |
| 1889 | } |
| 1890 | |
| 1891 | void CellularCapabilityUniversal::Handle3GPPRegistrationChange( |
| 1892 | MMModem3gppRegistrationState updated_state, |
| 1893 | string updated_operator_code, |
| 1894 | string updated_operator_name) { |
| 1895 | // A finished callback does not qualify as a canceled callback. |
| 1896 | // We test for a canceled callback to check for outstanding callbacks. |
| 1897 | // So, explicitly cancel the callback here. |
| 1898 | registration_dropped_update_callback_.Cancel(); |
| 1899 | |
| 1900 | SLOG(Cellular, 2) << __func__ << ": regstate=" << updated_state |
| 1901 | << ", opercode=" << updated_operator_code |
| 1902 | << ", opername=" << updated_operator_name; |
| 1903 | |
| 1904 | registration_state_ = updated_state; |
| 1905 | serving_operator_.SetCode(updated_operator_code); |
| 1906 | serving_operator_.SetName(updated_operator_name); |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 1907 | |
| 1908 | // Update the carrier name for |serving_operator_|. |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1909 | UpdateOperatorInfo(); |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 1910 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1911 | cellular()->HandleNewRegistrationState(); |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 1912 | |
| 1913 | // Update the user facing name of the cellular service. |
| 1914 | UpdateServiceName(); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1915 | |
| 1916 | // If the modem registered with the network and the current ICCID is pending |
| 1917 | // activation, then reset the modem. |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1918 | UpdatePendingActivationState(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1919 | } |
| 1920 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 1921 | void CellularCapabilityUniversal::OnModemStateChangedSignal( |
| 1922 | int32 old_state, int32 new_state, uint32 reason) { |
Eric Shienbrood | 9b1bd7b | 2012-04-20 16:42:26 -0400 | [diff] [blame] | 1923 | SLOG(Cellular, 2) << __func__ << "(" << old_state << ", " << new_state << ", " |
| 1924 | << reason << ")"; |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 1925 | cellular()->OnModemStateChanged(static_cast<Cellular::ModemState>(old_state), |
| 1926 | static_cast<Cellular::ModemState>(new_state), |
| 1927 | reason); |
Ben Chan | 2e12ccd | 2013-01-24 15:24:27 -0800 | [diff] [blame] | 1928 | UpdateScanningProperty(); |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 1929 | if (!deferred_enable_modem_callback_.is_null() && |
| 1930 | (new_state == Cellular::kModemStateDisabled)) { |
| 1931 | SLOG(Cellular, 2) << "Enabling modem after deferring"; |
| 1932 | deferred_enable_modem_callback_.Run(); |
| 1933 | deferred_enable_modem_callback_.Reset(); |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 1934 | } else if (new_state == Cellular::kModemStateConnected) { |
| 1935 | SLOG(Cellular, 2) << "Updating bearer path to reflect the active bearer."; |
| 1936 | UpdateBearerPath(); |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 1937 | } |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 1938 | } |
| 1939 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1940 | void CellularCapabilityUniversal::OnSignalQualityChanged(uint32 quality) { |
| 1941 | cellular()->HandleNewSignalQuality(quality); |
| 1942 | } |
| 1943 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1944 | void CellularCapabilityUniversal::OnFacilityLocksChanged(uint32 locks) { |
Arman Uguray | 4ef02fd | 2013-06-13 20:14:20 -0700 | [diff] [blame] | 1945 | bool sim_enabled = !!(locks & MM_MODEM_3GPP_FACILITY_SIM); |
| 1946 | if (sim_lock_status_.enabled != sim_enabled) { |
| 1947 | sim_lock_status_.enabled = sim_enabled; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1948 | OnSimLockStatusChanged(); |
| 1949 | } |
| 1950 | } |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 1951 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1952 | void CellularCapabilityUniversal::OnSimPropertiesChanged( |
| 1953 | const DBusPropertiesMap &props, |
| 1954 | const vector<string> &/* invalidated_properties */) { |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 1955 | SLOG(Cellular, 2) << __func__; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1956 | string value; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1957 | if (DBusProperties::GetString(props, MM_SIM_PROPERTY_SIMIDENTIFIER, &value)) |
| 1958 | OnSimIdentifierChanged(value); |
| 1959 | if (DBusProperties::GetString(props, MM_SIM_PROPERTY_OPERATORIDENTIFIER, |
| 1960 | &value)) |
| 1961 | OnOperatorIdChanged(value); |
Arman Uguray | d73783f | 2013-01-31 16:11:21 -0800 | [diff] [blame] | 1962 | if (DBusProperties::GetString(props, MM_SIM_PROPERTY_OPERATORNAME, &value)) |
| 1963 | OnSpnChanged(value); |
| 1964 | if (DBusProperties::GetString(props, MM_SIM_PROPERTY_IMSI, &value)) |
| 1965 | OnImsiChanged(value); |
| 1966 | SetHomeProvider(); |
| 1967 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1968 | |
Arman Uguray | d73783f | 2013-01-31 16:11:21 -0800 | [diff] [blame] | 1969 | // TODO(armansito): The following methods should probably log their argument |
| 1970 | // values. Need to learn if any of them need to be scrubbed. |
| 1971 | void CellularCapabilityUniversal::OnImsiChanged(const std::string &imsi) { |
| 1972 | imsi_ = imsi; |
| 1973 | } |
| 1974 | |
| 1975 | void CellularCapabilityUniversal::OnSpnChanged(const std::string &spn) { |
| 1976 | spn_ = spn; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1977 | } |
| 1978 | |
| 1979 | void CellularCapabilityUniversal::OnSimIdentifierChanged(const string &id) { |
| 1980 | sim_identifier_ = id; |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1981 | UpdatePendingActivationState(); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1982 | } |
| 1983 | |
| 1984 | void CellularCapabilityUniversal::OnOperatorIdChanged( |
| 1985 | const string &operator_id) { |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 1986 | SLOG(Cellular, 2) << "Operator ID = '" << operator_id << "'"; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1987 | operator_id_ = operator_id; |
| 1988 | } |
| 1989 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1990 | } // namespace shill |