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> |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 9 | #include <base/strings/string_util.h> |
Alex Vakulenko | a41ab51 | 2014-07-23 14:24:23 -0700 | [diff] [blame] | 10 | #include <base/strings/stringprintf.h> |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 11 | #include <chromeos/dbus/service_constants.h> |
Ben Chan | 5c853ef | 2012-10-05 00:05:37 -0700 | [diff] [blame] | 12 | #include <ModemManager/ModemManager.h> |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 13 | |
| 14 | #include <string> |
| 15 | #include <vector> |
| 16 | |
| 17 | #include "shill/adaptor_interfaces.h" |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 18 | #include "shill/cellular_bearer.h" |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 19 | #include "shill/cellular_service.h" |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 20 | #include "shill/dbus_properties_proxy_interface.h" |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 21 | #include "shill/error.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 22 | #include "shill/logging.h" |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 23 | #include "shill/mobile_operator_info.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"; |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 50 | const int64_t |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 51 | CellularCapabilityUniversal::kActivationRegistrationTimeoutMilliseconds = |
| 52 | 20000; |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 53 | const int64_t CellularCapabilityUniversal::kEnterPinTimeoutMilliseconds = 20000; |
| 54 | const int64_t |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 55 | CellularCapabilityUniversal::kRegistrationDroppedUpdateTimeoutMilliseconds = |
| 56 | 15000; |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 57 | const char CellularCapabilityUniversal::kRootPath[] = "/"; |
Jason Glasgow | cd0349c | 2012-05-03 23:32:15 -0400 | [diff] [blame] | 58 | const char CellularCapabilityUniversal::kStatusProperty[] = "status"; |
| 59 | const char CellularCapabilityUniversal::kOperatorLongProperty[] = |
| 60 | "operator-long"; |
| 61 | const char CellularCapabilityUniversal::kOperatorShortProperty[] = |
| 62 | "operator-short"; |
| 63 | const char CellularCapabilityUniversal::kOperatorCodeProperty[] = |
| 64 | "operator-code"; |
| 65 | const char CellularCapabilityUniversal::kOperatorAccessTechnologyProperty[] = |
| 66 | "access-technology"; |
Thieu Le | c466ccb | 2014-06-23 15:24:56 -0700 | [diff] [blame] | 67 | const char CellularCapabilityUniversal::kAltairLTEMMPlugin[] = "Altair LTE"; |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 68 | const char CellularCapabilityUniversal::kE362ModelId[] = "E362 WWAN"; |
Thieu Le | 2cac294 | 2013-03-05 18:41:08 -0800 | [diff] [blame] | 69 | const int CellularCapabilityUniversal::kSetPowerStateTimeoutMilliseconds = |
| 70 | 20000; |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 71 | |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 72 | namespace { |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 73 | |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 74 | const char kPhoneNumber[] = "*99#"; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 75 | |
Prathmesh Prabhu | 3b66bb9 | 2014-05-22 11:15:25 -0700 | [diff] [blame] | 76 | // This identifier is specified in the additional_providers.prototxt file. |
Prathmesh Prabhu | 5089a6e | 2014-05-07 20:49:16 -0700 | [diff] [blame] | 77 | const char kVzwIdentifier[] = "c83d6597-dc91-4d48-a3a7-d86b80123751"; |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 78 | const size_t kVzwMdnLength = 10; |
| 79 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 80 | string AccessTechnologyToString(uint32_t access_technologies) { |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 81 | if (access_technologies & MM_MODEM_ACCESS_TECHNOLOGY_LTE) |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 82 | return kNetworkTechnologyLte; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 83 | if (access_technologies & (MM_MODEM_ACCESS_TECHNOLOGY_EVDO0 | |
| 84 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA | |
| 85 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB)) |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 86 | return kNetworkTechnologyEvdo; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 87 | if (access_technologies & MM_MODEM_ACCESS_TECHNOLOGY_1XRTT) |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 88 | return kNetworkTechnology1Xrtt; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 89 | if (access_technologies & MM_MODEM_ACCESS_TECHNOLOGY_HSPA_PLUS) |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 90 | return kNetworkTechnologyHspaPlus; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 91 | if (access_technologies & (MM_MODEM_ACCESS_TECHNOLOGY_HSPA | |
| 92 | MM_MODEM_ACCESS_TECHNOLOGY_HSUPA | |
| 93 | MM_MODEM_ACCESS_TECHNOLOGY_HSDPA)) |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 94 | return kNetworkTechnologyHspa; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 95 | if (access_technologies & MM_MODEM_ACCESS_TECHNOLOGY_UMTS) |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 96 | return kNetworkTechnologyUmts; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 97 | if (access_technologies & MM_MODEM_ACCESS_TECHNOLOGY_EDGE) |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 98 | return kNetworkTechnologyEdge; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 99 | if (access_technologies & MM_MODEM_ACCESS_TECHNOLOGY_GPRS) |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 100 | return kNetworkTechnologyGprs; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 101 | if (access_technologies & (MM_MODEM_ACCESS_TECHNOLOGY_GSM_COMPACT | |
| 102 | MM_MODEM_ACCESS_TECHNOLOGY_GSM)) |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 103 | return kNetworkTechnologyGsm; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 104 | return ""; |
| 105 | } |
| 106 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 107 | string AccessTechnologyToTechnologyFamily(uint32_t access_technologies) { |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 108 | if (access_technologies & (MM_MODEM_ACCESS_TECHNOLOGY_LTE | |
| 109 | MM_MODEM_ACCESS_TECHNOLOGY_HSPA_PLUS | |
| 110 | MM_MODEM_ACCESS_TECHNOLOGY_HSPA | |
| 111 | MM_MODEM_ACCESS_TECHNOLOGY_HSUPA | |
| 112 | MM_MODEM_ACCESS_TECHNOLOGY_HSDPA | |
| 113 | MM_MODEM_ACCESS_TECHNOLOGY_UMTS | |
| 114 | MM_MODEM_ACCESS_TECHNOLOGY_EDGE | |
| 115 | MM_MODEM_ACCESS_TECHNOLOGY_GPRS | |
| 116 | MM_MODEM_ACCESS_TECHNOLOGY_GSM_COMPACT | |
| 117 | MM_MODEM_ACCESS_TECHNOLOGY_GSM)) |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 118 | return kTechnologyFamilyGsm; |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 119 | if (access_technologies & (MM_MODEM_ACCESS_TECHNOLOGY_EVDO0 | |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 120 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOA | |
| 121 | MM_MODEM_ACCESS_TECHNOLOGY_EVDOB | |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 122 | MM_MODEM_ACCESS_TECHNOLOGY_1XRTT)) |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 123 | return kTechnologyFamilyCdma; |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 124 | return ""; |
| 125 | } |
| 126 | |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 127 | } // namespace |
| 128 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 129 | CellularCapabilityUniversal::CellularCapabilityUniversal( |
| 130 | Cellular *cellular, |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 131 | ProxyFactory *proxy_factory, |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 132 | ModemInfo *modem_info) |
| 133 | : CellularCapability(cellular, proxy_factory, modem_info), |
Prathmesh Prabhu | afe6366 | 2014-05-20 11:03:58 -0700 | [diff] [blame] | 134 | mobile_operator_info_(new MobileOperatorInfo(cellular->dispatcher(), |
| 135 | "ParseScanResult")), |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 136 | weak_ptr_factory_(this), |
| 137 | registration_state_(MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN), |
Darin Petkov | e636c69 | 2012-05-31 10:22:17 +0200 | [diff] [blame] | 138 | current_capabilities_(MM_MODEM_CAPABILITY_NONE), |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 139 | access_technologies_(MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN), |
Ben Chan | 5d0d32c | 2013-01-08 02:05:29 -0800 | [diff] [blame] | 140 | resetting_(false), |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 141 | subscription_state_(kSubscriptionStateUnknown), |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 142 | reset_done_(false), |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 143 | activation_registration_timeout_milliseconds_( |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 144 | kActivationRegistrationTimeoutMilliseconds), |
| 145 | registration_dropped_update_timeout_milliseconds_( |
| 146 | kRegistrationDroppedUpdateTimeoutMilliseconds) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 147 | SLOG(Cellular, 2) << "Cellular capability constructed: Universal"; |
Prathmesh Prabhu | afe6366 | 2014-05-20 11:03:58 -0700 | [diff] [blame] | 148 | mobile_operator_info_->Init(); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 149 | HelpRegisterConstDerivedKeyValueStore( |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 150 | kSIMLockStatusProperty, |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 151 | &CellularCapabilityUniversal::SimLockStatusToProperty); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 152 | } |
| 153 | |
Ben Chan | f98f00e | 2014-02-05 14:48:43 -0800 | [diff] [blame] | 154 | CellularCapabilityUniversal::~CellularCapabilityUniversal() {} |
| 155 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 156 | KeyValueStore CellularCapabilityUniversal::SimLockStatusToProperty( |
| 157 | Error */*error*/) { |
| 158 | KeyValueStore status; |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 159 | string lock_type; |
| 160 | switch (sim_lock_status_.lock_type) { |
| 161 | case MM_MODEM_LOCK_SIM_PIN: |
| 162 | lock_type = "sim-pin"; |
| 163 | break; |
| 164 | case MM_MODEM_LOCK_SIM_PUK: |
| 165 | lock_type = "sim-puk"; |
| 166 | break; |
| 167 | default: |
| 168 | lock_type = ""; |
| 169 | break; |
| 170 | } |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 171 | status.SetBool(kSIMLockEnabledProperty, sim_lock_status_.enabled); |
| 172 | status.SetString(kSIMLockTypeProperty, lock_type); |
| 173 | status.SetUint(kSIMLockRetriesLeftProperty, sim_lock_status_.retries_left); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 174 | return status; |
| 175 | } |
| 176 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 177 | void CellularCapabilityUniversal::HelpRegisterConstDerivedKeyValueStore( |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 178 | const string &name, |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 179 | KeyValueStore(CellularCapabilityUniversal::*get)(Error *error)) { |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 180 | cellular()->mutable_store()->RegisterDerivedKeyValueStore( |
| 181 | name, |
| 182 | KeyValueStoreAccessor( |
| 183 | new CustomAccessor<CellularCapabilityUniversal, KeyValueStore>( |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 184 | this, get, NULL))); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | void CellularCapabilityUniversal::InitProxies() { |
| 188 | modem_3gpp_proxy_.reset( |
| 189 | proxy_factory()->CreateMM1ModemModem3gppProxy(cellular()->dbus_path(), |
| 190 | cellular()->dbus_owner())); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 191 | modem_proxy_.reset( |
| 192 | proxy_factory()->CreateMM1ModemProxy(cellular()->dbus_path(), |
| 193 | cellular()->dbus_owner())); |
| 194 | modem_simple_proxy_.reset( |
| 195 | proxy_factory()->CreateMM1ModemSimpleProxy(cellular()->dbus_path(), |
| 196 | cellular()->dbus_owner())); |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 197 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 198 | modem_proxy_->set_state_changed_callback( |
| 199 | Bind(&CellularCapabilityUniversal::OnModemStateChangedSignal, |
| 200 | weak_ptr_factory_.GetWeakPtr())); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 201 | // Do not create a SIM proxy until the device is enabled because we |
| 202 | // do not yet know the object path of the sim object. |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 203 | // TODO(jglasgow): register callbacks |
| 204 | } |
| 205 | |
| 206 | void CellularCapabilityUniversal::StartModem(Error *error, |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 207 | const ResultCallback &callback) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 208 | SLOG(Cellular, 3) << __func__; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 209 | InitProxies(); |
Ben Chan | 151d447 | 2013-09-06 13:29:46 -0700 | [diff] [blame] | 210 | deferred_enable_modem_callback_.Reset(); |
| 211 | EnableModem(true, error, callback); |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Ben Chan | 151d447 | 2013-09-06 13:29:46 -0700 | [diff] [blame] | 214 | void CellularCapabilityUniversal::EnableModem(bool deferrable, |
| 215 | Error *error, |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 216 | const ResultCallback &callback) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 217 | SLOG(Cellular, 3) << __func__ << "(deferrable=" << deferrable << ")"; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 218 | CHECK(!callback.is_null()); |
Thieu Le | e3b3659 | 2012-08-30 17:50:26 -0700 | [diff] [blame] | 219 | Error local_error(Error::kOperationInitiated); |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 220 | modem_info()->metrics()->NotifyDeviceEnableStarted( |
| 221 | cellular()->interface_index()); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 222 | modem_proxy_->Enable( |
| 223 | true, |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 224 | &local_error, |
Ben Chan | 151d447 | 2013-09-06 13:29:46 -0700 | [diff] [blame] | 225 | Bind(&CellularCapabilityUniversal::EnableModemCompleted, |
| 226 | weak_ptr_factory_.GetWeakPtr(), deferrable, callback), |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 227 | kTimeoutEnable); |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 228 | if (local_error.IsFailure()) { |
| 229 | SLOG(Cellular, 2) << __func__ << "Call to modem_proxy_->Enable() failed"; |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 230 | } |
| 231 | if (error) { |
| 232 | error->CopyFrom(local_error); |
| 233 | } |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 234 | } |
| 235 | |
Ben Chan | 151d447 | 2013-09-06 13:29:46 -0700 | [diff] [blame] | 236 | void CellularCapabilityUniversal::EnableModemCompleted( |
| 237 | bool deferrable, const ResultCallback &callback, const Error &error) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 238 | SLOG(Cellular, 3) << __func__ << "(deferrable=" << deferrable |
Ben Chan | 151d447 | 2013-09-06 13:29:46 -0700 | [diff] [blame] | 239 | << ", error=" << error << ")"; |
Thieu Le | b9c05e0 | 2013-03-04 14:09:32 -0800 | [diff] [blame] | 240 | |
Ben Chan | 151d447 | 2013-09-06 13:29:46 -0700 | [diff] [blame] | 241 | // If the enable operation failed with Error::kWrongState, the modem is not |
| 242 | // in the expected state (i.e. disabled). If |deferrable| indicates that the |
| 243 | // enable operation can be deferred, we defer the operation until the modem |
| 244 | // goes into the expected state (see OnModemStateChangedSignal). |
| 245 | // |
| 246 | // Note that when the SIM is locked, the enable operation also fails with |
| 247 | // Error::kWrongState. The enable operation is deferred until the modem goes |
| 248 | // into the disabled state after the SIM is unlocked. We may choose not to |
| 249 | // defer the enable operation when the SIM is locked, but the UI needs to |
| 250 | // trigger the enable operation after the SIM is unlocked, which is currently |
| 251 | // not the case. |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 252 | if (error.IsFailure()) { |
Ben Chan | 151d447 | 2013-09-06 13:29:46 -0700 | [diff] [blame] | 253 | if (!deferrable || error.type() != Error::kWrongState) { |
| 254 | callback.Run(error); |
| 255 | return; |
| 256 | } |
| 257 | |
| 258 | if (deferred_enable_modem_callback_.is_null()) { |
| 259 | SLOG(Cellular, 2) << "Defer enable operation."; |
| 260 | // The Enable operation to be deferred should not be further deferrable. |
| 261 | deferred_enable_modem_callback_ = |
| 262 | Bind(&CellularCapabilityUniversal::EnableModem, |
| 263 | weak_ptr_factory_.GetWeakPtr(), |
| 264 | false, // non-deferrable |
| 265 | static_cast<Error*>(NULL), |
| 266 | callback); |
| 267 | } |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 268 | return; |
| 269 | } |
| 270 | |
| 271 | // After modem is enabled, it should be possible to get properties |
| 272 | // TODO(jglasgow): handle errors from GetProperties |
| 273 | GetProperties(); |
Thieu Le | 18c1107 | 2013-01-28 17:21:37 -0800 | [diff] [blame] | 274 | // We expect the modem to start scanning after it has been enabled. |
| 275 | // 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] | 276 | modem_info()->metrics()->NotifyDeviceEnableFinished( |
| 277 | cellular()->interface_index()); |
| 278 | modem_info()->metrics()->NotifyDeviceScanStarted( |
| 279 | cellular()->interface_index()); |
Thieu Le | 18c1107 | 2013-01-28 17:21:37 -0800 | [diff] [blame] | 280 | callback.Run(error); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | void CellularCapabilityUniversal::StopModem(Error *error, |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 284 | const ResultCallback &callback) { |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 285 | CHECK(!callback.is_null()); |
| 286 | CHECK(error); |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 287 | // If there is an outstanding registration change, simply ignore it since |
| 288 | // the service will be destroyed anyway. |
| 289 | if (!registration_dropped_update_callback_.IsCancelled()) { |
| 290 | registration_dropped_update_callback_.Cancel(); |
| 291 | SLOG(Cellular, 2) << __func__ << " Cancelled delayed deregister."; |
| 292 | } |
| 293 | |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 294 | // Some modems will implicitly disconnect the bearer when transitioning to |
| 295 | // low power state. For such modems, it's faster to let the modem disconnect |
| 296 | // the bearer. To do that, we just remove the bearer from the list so |
| 297 | // ModemManager doesn't try to disconnect it during disable. |
| 298 | Closure task; |
Thieu Le | c466ccb | 2014-06-23 15:24:56 -0700 | [diff] [blame] | 299 | if (cellular()->mm_plugin() == kAltairLTEMMPlugin) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 300 | task = Bind(&CellularCapabilityUniversal::Stop_DeleteActiveBearer, |
| 301 | weak_ptr_factory_.GetWeakPtr(), |
| 302 | callback); |
| 303 | } else { |
| 304 | task = Bind(&CellularCapabilityUniversal::Stop_Disable, |
| 305 | weak_ptr_factory_.GetWeakPtr(), |
| 306 | callback); |
| 307 | } |
Ben Chan | 9de146f | 2013-09-11 13:11:31 -0700 | [diff] [blame] | 308 | cellular()->dispatcher()->PostTask(task); |
Gary Morain | e285a84 | 2012-08-15 08:23:57 -0700 | [diff] [blame] | 309 | deferred_enable_modem_callback_.Reset(); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 310 | } |
| 311 | |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 312 | void CellularCapabilityUniversal::Stop_DeleteActiveBearer( |
| 313 | const ResultCallback &callback) { |
| 314 | SLOG(Cellular, 3) << __func__; |
Thieu Le | b0074e8 | 2014-04-15 14:28:21 -0700 | [diff] [blame] | 315 | |
| 316 | if (!active_bearer_) { |
| 317 | Stop_Disable(callback); |
| 318 | return; |
| 319 | } |
| 320 | |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 321 | Error error; |
| 322 | modem_proxy_->DeleteBearer( |
| 323 | active_bearer_->dbus_path(), &error, |
| 324 | Bind(&CellularCapabilityUniversal::Stop_DeleteActiveBearerCompleted, |
| 325 | weak_ptr_factory_.GetWeakPtr(), callback), |
| 326 | kTimeoutDefault); |
| 327 | if (error.IsFailure()) |
| 328 | callback.Run(error); |
| 329 | } |
| 330 | |
| 331 | void CellularCapabilityUniversal::Stop_DeleteActiveBearerCompleted( |
| 332 | const ResultCallback &callback, const Error &error) { |
| 333 | SLOG(Cellular, 3) << __func__; |
Thieu Le | b0074e8 | 2014-04-15 14:28:21 -0700 | [diff] [blame] | 334 | // Disregard the error from the bearer deletion since the disable will clean |
| 335 | // up any remaining bearers. |
| 336 | Stop_Disable(callback); |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 339 | void CellularCapabilityUniversal::Stop_Disable(const ResultCallback &callback) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 340 | SLOG(Cellular, 3) << __func__; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 341 | Error error; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 342 | modem_info()->metrics()->NotifyDeviceDisableStarted( |
| 343 | cellular()->interface_index()); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 344 | modem_proxy_->Enable( |
| 345 | false, &error, |
| 346 | Bind(&CellularCapabilityUniversal::Stop_DisableCompleted, |
| 347 | weak_ptr_factory_.GetWeakPtr(), callback), |
Jason Glasgow | 02401cc | 2012-05-16 10:35:37 -0400 | [diff] [blame] | 348 | kTimeoutEnable); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 349 | if (error.IsFailure()) |
| 350 | callback.Run(error); |
| 351 | } |
| 352 | |
| 353 | void CellularCapabilityUniversal::Stop_DisableCompleted( |
| 354 | const ResultCallback &callback, const Error &error) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 355 | SLOG(Cellular, 3) << __func__; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 356 | |
Thieu Le | a2519bf | 2013-01-23 16:51:54 -0800 | [diff] [blame] | 357 | if (error.IsSuccess()) { |
Arman Uguray | ee464d3 | 2013-02-13 17:14:36 -0800 | [diff] [blame] | 358 | // The modem has been successfully disabled, but we still need to power it |
| 359 | // down. |
| 360 | Stop_PowerDown(callback); |
| 361 | } else { |
| 362 | // An error occurred; terminate the disable sequence. |
| 363 | callback.Run(error); |
Thieu Le | a2519bf | 2013-01-23 16:51:54 -0800 | [diff] [blame] | 364 | } |
Arman Uguray | ee464d3 | 2013-02-13 17:14:36 -0800 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | void CellularCapabilityUniversal::Stop_PowerDown( |
| 368 | const ResultCallback &callback) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 369 | SLOG(Cellular, 3) << __func__; |
Arman Uguray | ee464d3 | 2013-02-13 17:14:36 -0800 | [diff] [blame] | 370 | Error error; |
| 371 | modem_proxy_->SetPowerState( |
| 372 | MM_MODEM_POWER_STATE_LOW, |
| 373 | &error, |
| 374 | Bind(&CellularCapabilityUniversal::Stop_PowerDownCompleted, |
| 375 | weak_ptr_factory_.GetWeakPtr(), callback), |
Thieu Le | 2cac294 | 2013-03-05 18:41:08 -0800 | [diff] [blame] | 376 | kSetPowerStateTimeoutMilliseconds); |
Arman Uguray | ee464d3 | 2013-02-13 17:14:36 -0800 | [diff] [blame] | 377 | |
| 378 | if (error.IsFailure()) |
| 379 | // This really shouldn't happen, but if it does, report success, |
| 380 | // because a stop initiated power down is only called if the |
| 381 | // modem was successfully disabled, but the failure of this |
| 382 | // operation should still be propagated up as a successful disable. |
| 383 | Stop_PowerDownCompleted(callback, error); |
| 384 | } |
| 385 | |
mukesh agrawal | 2818551 | 2013-10-18 16:57:09 -0700 | [diff] [blame] | 386 | // Note: if we were in the middle of powering down the modem when the |
| 387 | // system suspended, we might not get this event from |
| 388 | // ModemManager. And we might not even get a timeout from dbus-c++, |
| 389 | // because StartModem re-initializes proxies. |
Arman Uguray | ee464d3 | 2013-02-13 17:14:36 -0800 | [diff] [blame] | 390 | void CellularCapabilityUniversal::Stop_PowerDownCompleted( |
| 391 | const ResultCallback &callback, |
| 392 | const Error &error) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 393 | SLOG(Cellular, 3) << __func__; |
Arman Uguray | ee464d3 | 2013-02-13 17:14:36 -0800 | [diff] [blame] | 394 | |
| 395 | if (error.IsFailure()) |
| 396 | SLOG(Cellular, 2) << "Ignoring error returned by SetPowerState: " << error; |
| 397 | |
| 398 | // Since the disable succeeded, if power down fails, we currently fail |
| 399 | // silently, i.e. we need to report the disable operation as having |
| 400 | // succeeded. |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 401 | modem_info()->metrics()->NotifyDeviceDisableFinished( |
| 402 | cellular()->interface_index()); |
Arman Uguray | ee464d3 | 2013-02-13 17:14:36 -0800 | [diff] [blame] | 403 | ReleaseProxies(); |
| 404 | callback.Run(Error()); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | void CellularCapabilityUniversal::Connect(const DBusPropertiesMap &properties, |
| 408 | Error *error, |
| 409 | const ResultCallback &callback) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 410 | SLOG(Cellular, 3) << __func__; |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 411 | DBusPathCallback cb = Bind(&CellularCapabilityUniversal::OnConnectReply, |
| 412 | weak_ptr_factory_.GetWeakPtr(), |
| 413 | callback); |
| 414 | modem_simple_proxy_->Connect(properties, error, cb, kTimeoutConnect); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | void CellularCapabilityUniversal::Disconnect(Error *error, |
| 418 | const ResultCallback &callback) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 419 | SLOG(Cellular, 3) << __func__; |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 420 | // If a deferred registration loss request exists, process it. |
| 421 | if (!registration_dropped_update_callback_.IsCancelled()) { |
| 422 | registration_dropped_update_callback_.callback().Run(); |
| 423 | DCHECK(cellular()->state() != Cellular::kStateConnected && |
| 424 | cellular()->state() != Cellular::kStateLinked); |
| 425 | SLOG(Cellular, 1) << "Processed deferred registration loss before " |
| 426 | << "disconnect request."; |
| 427 | } |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 428 | if (modem_simple_proxy_.get()) { |
| 429 | SLOG(Cellular, 2) << "Disconnect all bearers."; |
| 430 | // If "/" is passed as the bearer path, ModemManager will disconnect all |
| 431 | // bearers. |
| 432 | modem_simple_proxy_->Disconnect(DBus::Path(kRootPath), |
Thieu Le | 5d6864a | 2012-07-20 11:43:51 -0700 | [diff] [blame] | 433 | error, |
| 434 | callback, |
Thieu Le | 049adb5 | 2012-11-12 17:14:51 -0800 | [diff] [blame] | 435 | kTimeoutDisconnect); |
Thieu Le | 5d6864a | 2012-07-20 11:43:51 -0700 | [diff] [blame] | 436 | } |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 437 | } |
| 438 | |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 439 | void CellularCapabilityUniversal::OnActivationWaitForRegisterTimeout() { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 440 | SLOG(Cellular, 3) << __func__; |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 441 | const string &sim_identifier = cellular()->sim_identifier(); |
| 442 | if (sim_identifier.empty() || |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 443 | modem_info()->pending_activation_store()->GetActivationState( |
| 444 | PendingActivationStore::kIdentifierICCID, |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 445 | sim_identifier) == PendingActivationStore::kStateActivated) { |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 446 | SLOG(Cellular, 2) << "Modem is already scheduled to be reset."; |
| 447 | return; |
| 448 | } |
| 449 | if (IsMdnValid()) { |
| 450 | SLOG(Cellular, 2) << "MDN is valid. Already activated."; |
| 451 | return; |
| 452 | } |
| 453 | if (reset_done_) { |
| 454 | SLOG(Cellular, 2) << "Already done with reset."; |
| 455 | return; |
| 456 | } |
| 457 | |
| 458 | // Still not activated after timeout. Reset the modem. |
| 459 | SLOG(Cellular, 2) << "Still not registered after timeout. Reset directly " |
| 460 | << "to update MDN."; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 461 | modem_info()->pending_activation_store()->SetActivationState( |
| 462 | PendingActivationStore::kIdentifierICCID, |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 463 | sim_identifier, |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 464 | PendingActivationStore::kStatePendingTimeout); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 465 | ResetAfterActivation(); |
| 466 | } |
| 467 | |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 468 | void CellularCapabilityUniversal::CompleteActivation(Error *error) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 469 | SLOG(Cellular, 3) << __func__; |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 470 | |
| 471 | // Persist the ICCID as "Pending Activation". |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 472 | // We're assuming that when this function gets called, |
| 473 | // |cellular()->sim_identifier()| will be non-empty. We still check here that |
| 474 | // is non-empty, though something is wrong if it is empty. |
| 475 | const string &sim_identifier = cellular()->sim_identifier(); |
| 476 | if (sim_identifier.empty()) { |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 477 | SLOG(Cellular, 2) << "SIM identifier not available. Nothing to do."; |
| 478 | return; |
| 479 | } |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 480 | |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 481 | if (IsMdnValid()) { |
| 482 | SLOG(Cellular, 2) << "Already acquired a valid MDN. Already activated."; |
| 483 | return; |
| 484 | } |
| 485 | |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 486 | // There should be a cellular service at this point. |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 487 | if (cellular()->service().get()) { |
| 488 | if (cellular()->service()->activation_state() == kActivationStateActivated) |
| 489 | return; |
| 490 | |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 491 | cellular()->service()->SetActivationState(kActivationStateActivating); |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 492 | } |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 493 | modem_info()->pending_activation_store()->SetActivationState( |
| 494 | PendingActivationStore::kIdentifierICCID, |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 495 | sim_identifier, |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 496 | PendingActivationStore::kStatePending); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 497 | |
| 498 | activation_wait_for_registration_callback_.Reset( |
| 499 | Bind(&CellularCapabilityUniversal::OnActivationWaitForRegisterTimeout, |
| 500 | weak_ptr_factory_.GetWeakPtr())); |
| 501 | cellular()->dispatcher()->PostDelayedTask( |
| 502 | activation_wait_for_registration_callback_.callback(), |
| 503 | activation_registration_timeout_milliseconds_); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | void CellularCapabilityUniversal::ResetAfterActivation() { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 507 | SLOG(Cellular, 3) << __func__; |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 508 | |
| 509 | // Here the initial call to Reset might fail in rare cases. Simply ignore. |
| 510 | Error error; |
| 511 | ResultCallback callback = Bind( |
| 512 | &CellularCapabilityUniversal::OnResetAfterActivationReply, |
| 513 | weak_ptr_factory_.GetWeakPtr()); |
| 514 | Reset(&error, callback); |
| 515 | if (error.IsFailure()) |
| 516 | SLOG(Cellular, 2) << "Failed to reset after activation."; |
| 517 | } |
| 518 | |
| 519 | void CellularCapabilityUniversal::OnResetAfterActivationReply( |
| 520 | const Error &error) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 521 | SLOG(Cellular, 3) << __func__; |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 522 | if (error.IsFailure()) { |
| 523 | SLOG(Cellular, 2) << "Failed to reset after activation. Try again later."; |
| 524 | // TODO(armansito): Maybe post a delayed reset task? |
| 525 | return; |
| 526 | } |
| 527 | reset_done_ = true; |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 528 | activation_wait_for_registration_callback_.Cancel(); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 529 | UpdatePendingActivationState(); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 530 | } |
| 531 | |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 532 | void CellularCapabilityUniversal::UpdatePendingActivationState() { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 533 | SLOG(Cellular, 3) << __func__; |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 534 | |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 535 | const string &sim_identifier = cellular()->sim_identifier(); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 536 | bool registered = |
| 537 | registration_state_ == MM_MODEM_3GPP_REGISTRATION_STATE_HOME; |
| 538 | |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 539 | // We know a service is activated if |subscription_state_| is |
| 540 | // kSubscriptionStateProvisioned / kSubscriptionStateOutOfData |
| 541 | // In the case that |subscription_state_| is kSubscriptionStateUnknown, we |
| 542 | // fallback on checking for a valid MDN. |
| 543 | bool activated = |
| 544 | ((subscription_state_ == kSubscriptionStateProvisioned) || |
| 545 | (subscription_state_ == kSubscriptionStateOutOfData)) || |
| 546 | ((subscription_state_ == kSubscriptionStateUnknown) && IsMdnValid()); |
| 547 | |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 548 | if (activated && !sim_identifier.empty()) |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 549 | modem_info()->pending_activation_store()->RemoveEntry( |
| 550 | PendingActivationStore::kIdentifierICCID, |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 551 | sim_identifier); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 552 | |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 553 | CellularServiceRefPtr service = cellular()->service(); |
| 554 | |
| 555 | if (!service.get()) |
| 556 | return; |
| 557 | |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 558 | if (service->activation_state() == kActivationStateActivated) |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 559 | // Either no service or already activated. Nothing to do. |
| 560 | return; |
| 561 | |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 562 | // Besides the indicators above, a connected service also indicates an |
| 563 | // activated SIM. |
| 564 | if (activated || cellular()->state() == Cellular::kStateConnected || |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 565 | cellular()->state() == Cellular::kStateLinked) { |
| 566 | SLOG(Cellular, 2) << "Marking service as activated."; |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 567 | service->SetActivationState(kActivationStateActivated); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 568 | return; |
| 569 | } |
| 570 | |
| 571 | // If the ICCID is not available, the following logic can be delayed until it |
| 572 | // becomes available. |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 573 | if (sim_identifier.empty()) |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 574 | return; |
| 575 | |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 576 | PendingActivationStore::State state = |
| 577 | modem_info()->pending_activation_store()->GetActivationState( |
| 578 | PendingActivationStore::kIdentifierICCID, |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 579 | sim_identifier); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 580 | switch (state) { |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 581 | case PendingActivationStore::kStatePending: |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 582 | // Always mark the service as activating here, as the ICCID could have |
| 583 | // been unavailable earlier. |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 584 | service->SetActivationState(kActivationStateActivating); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 585 | if (reset_done_) { |
| 586 | SLOG(Cellular, 2) << "Post-payment activation reset complete."; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 587 | modem_info()->pending_activation_store()->SetActivationState( |
| 588 | PendingActivationStore::kIdentifierICCID, |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 589 | sim_identifier, |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 590 | PendingActivationStore::kStateActivated); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 591 | } else if (registered) { |
| 592 | SLOG(Cellular, 2) << "Resetting modem for activation."; |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 593 | activation_wait_for_registration_callback_.Cancel(); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 594 | ResetAfterActivation(); |
| 595 | } |
| 596 | break; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 597 | case PendingActivationStore::kStateActivated: |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 598 | if (registered) { |
| 599 | // Trigger auto connect here. |
| 600 | SLOG(Cellular, 2) << "Modem has been reset at least once, try to " |
| 601 | << "autoconnect to force MDN to update."; |
| 602 | service->AutoConnect(); |
| 603 | } |
| 604 | break; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 605 | case PendingActivationStore::kStatePendingTimeout: |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 606 | SLOG(Cellular, 2) << "Modem failed to register within timeout, but has " |
| 607 | << "been reset at least once."; |
| 608 | if (registered) { |
| 609 | SLOG(Cellular, 2) << "Registered to network, marking as activated."; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 610 | modem_info()->pending_activation_store()->SetActivationState( |
| 611 | PendingActivationStore::kIdentifierICCID, |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 612 | sim_identifier, |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 613 | PendingActivationStore::kStateActivated); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 614 | service->SetActivationState(kActivationStateActivated); |
Arman Uguray | a14941d | 2013-04-12 16:58:26 -0700 | [diff] [blame] | 615 | } |
| 616 | break; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 617 | case PendingActivationStore::kStateUnknown: |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 618 | // No entry exists for this ICCID. Nothing to do. |
| 619 | break; |
| 620 | default: |
| 621 | NOTREACHED(); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 622 | } |
| 623 | } |
| 624 | |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 625 | string CellularCapabilityUniversal::GetMdnForOLP( |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 626 | const MobileOperatorInfo *operator_info) const { |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 627 | // TODO(benchan): This is ugly. Remove carrier specific code once we move |
| 628 | // mobile activation logic to carrier-specifc extensions (crbug.com/260073). |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 629 | const string &mdn = cellular()->mdn(); |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 630 | if (!operator_info->IsMobileNetworkOperatorKnown()) { |
| 631 | // Can't make any carrier specific modifications. |
| 632 | return mdn; |
| 633 | } |
| 634 | |
| 635 | if (operator_info->uuid() == kVzwIdentifier) { |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 636 | // subscription_state_ is the definitive indicator of whether we need |
| 637 | // activation. The OLP expects an all zero MDN in that case. |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 638 | if (subscription_state_ == kSubscriptionStateUnprovisioned || mdn.empty()) { |
Ben Chan | 200591a | 2013-08-07 14:39:04 -0700 | [diff] [blame] | 639 | return string(kVzwMdnLength, '0'); |
| 640 | } |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 641 | if (mdn.length() > kVzwMdnLength) { |
| 642 | return mdn.substr(mdn.length() - kVzwMdnLength); |
Ben Chan | 200591a | 2013-08-07 14:39:04 -0700 | [diff] [blame] | 643 | } |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 644 | } |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 645 | return mdn; |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 646 | } |
| 647 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 648 | void CellularCapabilityUniversal::ReleaseProxies() { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 649 | SLOG(Cellular, 3) << __func__; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 650 | modem_3gpp_proxy_.reset(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 651 | modem_proxy_.reset(); |
| 652 | modem_simple_proxy_.reset(); |
| 653 | sim_proxy_.reset(); |
| 654 | } |
| 655 | |
Thieu Le | 63881a7 | 2014-07-28 17:28:36 -0700 | [diff] [blame] | 656 | bool CellularCapabilityUniversal::AreProxiesInitialized() const { |
| 657 | return (modem_3gpp_proxy_.get() && modem_proxy_.get() && |
| 658 | modem_simple_proxy_.get() && sim_proxy_.get()); |
| 659 | } |
| 660 | |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 661 | void CellularCapabilityUniversal::UpdateServiceActivationState() { |
| 662 | if (!cellular()->service().get()) |
| 663 | return; |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 664 | |
| 665 | const string &sim_identifier = cellular()->sim_identifier(); |
Ben Chan | 3d6de0e | 2012-12-10 12:01:34 -0800 | [diff] [blame] | 666 | bool activation_required = IsServiceActivationRequired(); |
Arman Uguray | 6bb252d | 2013-05-15 14:29:53 -0700 | [diff] [blame] | 667 | string activation_state; |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 668 | PendingActivationStore::State state = |
| 669 | modem_info()->pending_activation_store()->GetActivationState( |
| 670 | PendingActivationStore::kIdentifierICCID, |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 671 | sim_identifier); |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 672 | if ((subscription_state_ == kSubscriptionStateUnknown || |
| 673 | subscription_state_ == kSubscriptionStateUnprovisioned) && |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 674 | !sim_identifier.empty() && |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 675 | (state == PendingActivationStore::kStatePending || |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 676 | state == PendingActivationStore::kStatePendingTimeout)) { |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 677 | activation_state = kActivationStateActivating; |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 678 | } else if (activation_required) { |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 679 | activation_state = kActivationStateNotActivated; |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 680 | } else { |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 681 | activation_state = kActivationStateActivated; |
Arman Uguray | 6bb252d | 2013-05-15 14:29:53 -0700 | [diff] [blame] | 682 | |
| 683 | // Mark an activated service for auto-connect by default. Since data from |
| 684 | // the user profile will be loaded after the call to OnServiceCreated, this |
| 685 | // property will be corrected based on the user data at that time. |
Thieu Le | 247416e | 2014-02-25 18:19:53 -0800 | [diff] [blame] | 686 | // NOTE: This function can be called outside the service initialization |
| 687 | // path so make sure we don't overwrite the auto-connect setting. |
| 688 | if (cellular()->service()->activation_state() != activation_state) |
| 689 | cellular()->service()->SetAutoConnect(true); |
Arman Uguray | 6bb252d | 2013-05-15 14:29:53 -0700 | [diff] [blame] | 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() { |
Thieu Le | 71f81a6 | 2014-07-11 15:17:47 -0700 | [diff] [blame^] | 701 | cellular()->service()->SetActivationType(CellularService::kActivationTypeOTA); |
Arman Uguray | efea6e0 | 2013-02-21 13:28:04 -0800 | [diff] [blame] | 702 | UpdateServiceActivationState(); |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 703 | |
| 704 | // WORKAROUND: |
| 705 | // E362 modems on Verizon network does not properly redirect when a SIM |
| 706 | // runs out of credits, we need to enforce out-of-credits detection. |
Ben Chan | 4ffc03b | 2013-08-07 17:44:53 -0700 | [diff] [blame] | 707 | // |
| 708 | // The out-of-credits detection is also needed on ALT3100 modems until the PCO |
| 709 | // support is ready (crosbug.com/p/20461). |
Thieu Le | 43ce4d4 | 2013-10-04 16:08:55 -0700 | [diff] [blame] | 710 | cellular()->service()->InitOutOfCreditsDetection( |
| 711 | GetOutOfCreditsDetectionType()); |
Arman Uguray | 7af0fac | 2013-03-18 17:35:35 -0700 | [diff] [blame] | 712 | |
| 713 | // Make sure that the network technology is set when the service gets |
| 714 | // created, just in case. |
| 715 | cellular()->service()->SetNetworkTechnology(GetNetworkTechnologyString()); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 716 | } |
| 717 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 718 | // Create the list of APNs to try, in the following order: |
| 719 | // - last APN that resulted in a successful connection attempt on the |
| 720 | // current network (if any) |
| 721 | // - the APN, if any, that was set by the user |
| 722 | // - the list of APNs found in the mobile broadband provider DB for the |
| 723 | // home provider associated with the current SIM |
| 724 | // - as a last resort, attempt to connect with no APN |
| 725 | void CellularCapabilityUniversal::SetupApnTryList() { |
| 726 | apn_try_list_.clear(); |
| 727 | |
| 728 | DCHECK(cellular()->service().get()); |
| 729 | const Stringmap *apn_info = cellular()->service()->GetLastGoodApn(); |
| 730 | if (apn_info) |
| 731 | apn_try_list_.push_back(*apn_info); |
| 732 | |
| 733 | apn_info = cellular()->service()->GetUserSpecifiedApn(); |
| 734 | if (apn_info) |
| 735 | apn_try_list_.push_back(*apn_info); |
| 736 | |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 737 | apn_try_list_.insert(apn_try_list_.end(), |
| 738 | cellular()->apn_list().begin(), |
| 739 | cellular()->apn_list().end()); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | void CellularCapabilityUniversal::SetupConnectProperties( |
| 743 | DBusPropertiesMap *properties) { |
| 744 | SetupApnTryList(); |
| 745 | FillConnectPropertyMap(properties); |
| 746 | } |
| 747 | |
| 748 | void CellularCapabilityUniversal::FillConnectPropertyMap( |
| 749 | DBusPropertiesMap *properties) { |
| 750 | |
| 751 | // TODO(jglasgow): Is this really needed anymore? |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 752 | (*properties)[kConnectNumber].writer().append_string( |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 753 | kPhoneNumber); |
| 754 | |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 755 | (*properties)[kConnectAllowRoaming].writer().append_bool( |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 756 | AllowRoaming()); |
| 757 | |
| 758 | if (!apn_try_list_.empty()) { |
| 759 | // Leave the APN at the front of the list, so that it can be recorded |
| 760 | // if the connect attempt succeeds. |
| 761 | Stringmap apn_info = apn_try_list_.front(); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 762 | SLOG(Cellular, 2) << __func__ << ": Using APN " << apn_info[kApnProperty]; |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 763 | (*properties)[kConnectApn].writer().append_string( |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 764 | apn_info[kApnProperty].c_str()); |
| 765 | if (ContainsKey(apn_info, kApnUsernameProperty)) |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 766 | (*properties)[kConnectUser].writer().append_string( |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 767 | apn_info[kApnUsernameProperty].c_str()); |
| 768 | if (ContainsKey(apn_info, kApnPasswordProperty)) |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 769 | (*properties)[kConnectPassword].writer().append_string( |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 770 | apn_info[kApnPasswordProperty].c_str()); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 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) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 777 | SLOG(Cellular, 3) << __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 | } |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 805 | SLOG(Cellular, 2) << "Connected bearer " << 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() { |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 815 | return cellular()->provider_requires_roaming() || allow_roaming_property(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 816 | } |
| 817 | |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 818 | void CellularCapabilityUniversal::GetProperties() { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 819 | SLOG(Cellular, 3) << __func__; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 820 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 821 | scoped_ptr<DBusPropertiesProxyInterface> properties_proxy( |
| 822 | proxy_factory()->CreateDBusPropertiesProxy(cellular()->dbus_path(), |
| 823 | cellular()->dbus_owner())); |
| 824 | DBusPropertiesMap properties( |
| 825 | properties_proxy->GetAll(MM_DBUS_INTERFACE_MODEM)); |
| 826 | OnModemPropertiesChanged(properties, vector<string>()); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 827 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 828 | properties = properties_proxy->GetAll(MM_DBUS_INTERFACE_MODEM_MODEM3GPP); |
| 829 | OnModem3GPPPropertiesChanged(properties, vector<string>()); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 830 | } |
| 831 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 832 | void CellularCapabilityUniversal::UpdateServiceOLP() { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 833 | SLOG(Cellular, 3) << __func__; |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 834 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 835 | // OLP is based off of the Home Provider. |
| 836 | if (!cellular()->home_provider_info()->IsMobileNetworkOperatorKnown()) { |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 837 | return; |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 838 | } |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 839 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 840 | const vector<MobileOperatorInfo::OnlinePortal> &olp_list = |
| 841 | cellular()->home_provider_info()->olp_list(); |
| 842 | if (olp_list.empty()) { |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 843 | return; |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 844 | } |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 845 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 846 | if (olp_list.size() > 1) { |
| 847 | SLOG(Cellular, 1) << "Found multiple online portals. Choosing the first."; |
| 848 | } |
| 849 | string post_data = olp_list[0].post_data; |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 850 | ReplaceSubstringsAfterOffset(&post_data, 0, "${iccid}", |
| 851 | cellular()->sim_identifier()); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 852 | ReplaceSubstringsAfterOffset(&post_data, 0, "${imei}", cellular()->imei()); |
| 853 | ReplaceSubstringsAfterOffset(&post_data, 0, "${imsi}", cellular()->imsi()); |
Ben Chan | 07193fd | 2013-07-12 22:10:55 -0700 | [diff] [blame] | 854 | ReplaceSubstringsAfterOffset(&post_data, 0, "${mdn}", |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 855 | GetMdnForOLP(cellular()->home_provider_info())); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 856 | ReplaceSubstringsAfterOffset(&post_data, 0, "${min}", cellular()->min()); |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 857 | cellular()->service()->SetOLP(olp_list[0].url, olp_list[0].method, post_data); |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 858 | } |
| 859 | |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 860 | void CellularCapabilityUniversal::UpdateActiveBearer() { |
| 861 | SLOG(Cellular, 3) << __func__; |
| 862 | |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 863 | // Look for the first active bearer and use its path as the connected |
| 864 | // one. Right now, we don't allow more than one active bearer. |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 865 | active_bearer_.reset(); |
Ben Chan | cbef812 | 2014-01-06 17:31:30 -0800 | [diff] [blame] | 866 | for (const auto &path : bearer_paths_) { |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 867 | scoped_ptr<CellularBearer> bearer( |
| 868 | new CellularBearer(proxy_factory(), path, cellular()->dbus_service())); |
| 869 | // The bearer object may have vanished before ModemManager updates the |
| 870 | // 'Bearers' property. |
| 871 | if (!bearer->Init()) |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 872 | continue; |
Ben Chan | 5db1969 | 2013-07-09 23:07:03 -0700 | [diff] [blame] | 873 | |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 874 | if (!bearer->connected()) |
Ben Chan | 5db1969 | 2013-07-09 23:07:03 -0700 | [diff] [blame] | 875 | continue; |
Ben Chan | 5db1969 | 2013-07-09 23:07:03 -0700 | [diff] [blame] | 876 | |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 877 | SLOG(Cellular, 2) << "Found active bearer \"" << path << "\"."; |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 878 | CHECK(!active_bearer_) << "Found more than one active bearer."; |
| 879 | active_bearer_ = bearer.Pass(); |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 880 | } |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 881 | |
| 882 | if (!active_bearer_) |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 883 | SLOG(Cellular, 2) << "No active bearer found."; |
Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [diff] [blame] | 884 | } |
| 885 | |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 886 | bool CellularCapabilityUniversal::IsServiceActivationRequired() const { |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 887 | const string &sim_identifier = cellular()->sim_identifier(); |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 888 | // subscription_state_ is the definitive answer. If that does not work, |
| 889 | // fallback on MDN based logic. |
| 890 | if (subscription_state_ == kSubscriptionStateProvisioned || |
| 891 | subscription_state_ == kSubscriptionStateOutOfData) |
| 892 | return false; |
| 893 | |
| 894 | // We are in the process of activating, ignore all other clues from the |
| 895 | // network and use our own knowledge about the activation state. |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 896 | if (!sim_identifier.empty() && |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 897 | modem_info()->pending_activation_store()->GetActivationState( |
| 898 | PendingActivationStore::kIdentifierICCID, |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 899 | sim_identifier) != PendingActivationStore::kStateUnknown) |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 900 | return false; |
| 901 | |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 902 | // Network notification that the service needs to be activated. |
| 903 | if (subscription_state_ == kSubscriptionStateUnprovisioned) |
| 904 | return true; |
| 905 | |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 906 | // If there is no online payment portal information, it's safer to assume |
| 907 | // the service does not require activation. |
Prathmesh Prabhu | 3ee2f41 | 2014-05-20 17:30:19 -0700 | [diff] [blame] | 908 | if (!cellular()->home_provider_info()->IsMobileNetworkOperatorKnown() || |
| 909 | cellular()->home_provider_info()->olp_list().empty()) { |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 910 | return false; |
Prathmesh Prabhu | 3ee2f41 | 2014-05-20 17:30:19 -0700 | [diff] [blame] | 911 | } |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 912 | |
Ben Chan | 200591a | 2013-08-07 14:39:04 -0700 | [diff] [blame] | 913 | // If the MDN is invalid (i.e. empty or contains only zeros), the service |
| 914 | // requires activation. |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 915 | return !IsMdnValid(); |
| 916 | } |
| 917 | |
| 918 | bool CellularCapabilityUniversal::IsMdnValid() const { |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 919 | const string &mdn = cellular()->mdn(); |
| 920 | // Note that |mdn| is normalized to contain only digits in OnMdnChanged(). |
| 921 | for (size_t i = 0; i < mdn.size(); ++i) { |
| 922 | if (mdn[i] != '0') |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 923 | return true; |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 924 | } |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 925 | return false; |
Ben Chan | 1578603 | 2012-11-04 21:28:02 -0800 | [diff] [blame] | 926 | } |
| 927 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 928 | // always called from an async context |
| 929 | void CellularCapabilityUniversal::Register(const ResultCallback &callback) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 930 | SLOG(Cellular, 3) << __func__ << " \"" << cellular()->selected_network() |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 931 | << "\""; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 932 | CHECK(!callback.is_null()); |
| 933 | Error error; |
| 934 | ResultCallback cb = Bind(&CellularCapabilityUniversal::OnRegisterReply, |
| 935 | weak_ptr_factory_.GetWeakPtr(), callback); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 936 | modem_3gpp_proxy_->Register(cellular()->selected_network(), &error, cb, |
| 937 | kTimeoutRegister); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 938 | if (error.IsFailure()) |
| 939 | callback.Run(error); |
| 940 | } |
| 941 | |
| 942 | void CellularCapabilityUniversal::RegisterOnNetwork( |
| 943 | const string &network_id, |
| 944 | Error *error, |
| 945 | const ResultCallback &callback) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 946 | SLOG(Cellular, 3) << __func__ << "(" << network_id << ")"; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 947 | CHECK(error); |
| 948 | desired_network_ = network_id; |
| 949 | ResultCallback cb = Bind(&CellularCapabilityUniversal::OnRegisterReply, |
| 950 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 951 | modem_3gpp_proxy_->Register(network_id, error, cb, kTimeoutRegister); |
| 952 | } |
| 953 | |
| 954 | void CellularCapabilityUniversal::OnRegisterReply( |
| 955 | const ResultCallback &callback, |
| 956 | const Error &error) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 957 | SLOG(Cellular, 3) << __func__ << "(" << error << ")"; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 958 | |
| 959 | if (error.IsSuccess()) { |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 960 | cellular()->set_selected_network(desired_network_); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 961 | desired_network_.clear(); |
| 962 | callback.Run(error); |
| 963 | return; |
| 964 | } |
| 965 | // If registration on the desired network failed, |
| 966 | // try to register on the home network. |
| 967 | if (!desired_network_.empty()) { |
| 968 | desired_network_.clear(); |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 969 | cellular()->set_selected_network(""); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 970 | LOG(INFO) << "Couldn't register on selected network, trying home network"; |
| 971 | Register(callback); |
| 972 | return; |
| 973 | } |
| 974 | callback.Run(error); |
| 975 | } |
| 976 | |
Ben Chan | 31ce564 | 2013-11-14 13:37:40 -0800 | [diff] [blame] | 977 | bool CellularCapabilityUniversal::IsRegistered() const { |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 978 | return IsRegisteredState(registration_state_); |
| 979 | } |
| 980 | |
| 981 | bool CellularCapabilityUniversal::IsRegisteredState( |
| 982 | MMModem3gppRegistrationState state) { |
| 983 | return (state == MM_MODEM_3GPP_REGISTRATION_STATE_HOME || |
| 984 | state == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 985 | } |
| 986 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 987 | void CellularCapabilityUniversal::SetUnregistered(bool searching) { |
| 988 | // If we're already in some non-registered state, don't override that |
| 989 | if (registration_state_ == MM_MODEM_3GPP_REGISTRATION_STATE_HOME || |
| 990 | registration_state_ == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING) { |
| 991 | registration_state_ = |
| 992 | (searching ? MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING : |
| 993 | MM_MODEM_3GPP_REGISTRATION_STATE_IDLE); |
| 994 | } |
| 995 | } |
| 996 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 997 | void CellularCapabilityUniversal::RequirePIN( |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 998 | const string &pin, bool require, |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 999 | Error *error, const ResultCallback &callback) { |
| 1000 | CHECK(error); |
| 1001 | sim_proxy_->EnablePin(pin, require, error, callback, kTimeoutDefault); |
| 1002 | } |
| 1003 | |
| 1004 | void CellularCapabilityUniversal::EnterPIN(const string &pin, |
| 1005 | Error *error, |
| 1006 | const ResultCallback &callback) { |
| 1007 | CHECK(error); |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 1008 | SLOG(Cellular, 3) << __func__; |
Arman Uguray | f6366ac | 2013-06-12 16:02:28 -0700 | [diff] [blame] | 1009 | sim_proxy_->SendPin(pin, error, callback, kEnterPinTimeoutMilliseconds); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | void CellularCapabilityUniversal::UnblockPIN(const string &unblock_code, |
| 1013 | const string &pin, |
| 1014 | Error *error, |
| 1015 | const ResultCallback &callback) { |
| 1016 | CHECK(error); |
| 1017 | sim_proxy_->SendPuk(unblock_code, pin, error, callback, kTimeoutDefault); |
| 1018 | } |
| 1019 | |
| 1020 | void CellularCapabilityUniversal::ChangePIN( |
| 1021 | const string &old_pin, const string &new_pin, |
| 1022 | Error *error, const ResultCallback &callback) { |
| 1023 | CHECK(error); |
| 1024 | sim_proxy_->ChangePin(old_pin, new_pin, error, callback, kTimeoutDefault); |
| 1025 | } |
| 1026 | |
Ben Chan | 5d0d32c | 2013-01-08 02:05:29 -0800 | [diff] [blame] | 1027 | void CellularCapabilityUniversal::Reset(Error *error, |
| 1028 | const ResultCallback &callback) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 1029 | SLOG(Cellular, 3) << __func__; |
Ben Chan | 5d0d32c | 2013-01-08 02:05:29 -0800 | [diff] [blame] | 1030 | CHECK(error); |
| 1031 | if (resetting_) { |
| 1032 | Error::PopulateAndLog(error, Error::kInProgress, "Already resetting"); |
| 1033 | return; |
| 1034 | } |
| 1035 | ResultCallback cb = Bind(&CellularCapabilityUniversal::OnResetReply, |
| 1036 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 1037 | modem_proxy_->Reset(error, cb, kTimeoutReset); |
| 1038 | if (!error->IsFailure()) { |
| 1039 | resetting_ = true; |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | void CellularCapabilityUniversal::OnResetReply(const ResultCallback &callback, |
| 1044 | const Error &error) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 1045 | SLOG(Cellular, 3) << __func__; |
Ben Chan | 5d0d32c | 2013-01-08 02:05:29 -0800 | [diff] [blame] | 1046 | resetting_ = false; |
| 1047 | if (!callback.is_null()) |
| 1048 | callback.Run(error); |
| 1049 | } |
| 1050 | |
Prathmesh Prabhu | 49ffffd | 2014-01-09 18:28:55 -0800 | [diff] [blame] | 1051 | void CellularCapabilityUniversal::Scan( |
| 1052 | Error *error, |
| 1053 | const ResultStringmapsCallback &callback) { |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1054 | DBusPropertyMapsCallback cb = Bind(&CellularCapabilityUniversal::OnScanReply, |
| 1055 | weak_ptr_factory_.GetWeakPtr(), callback); |
| 1056 | modem_3gpp_proxy_->Scan(error, cb, kTimeoutScan); |
| 1057 | } |
| 1058 | |
Prathmesh Prabhu | 49ffffd | 2014-01-09 18:28:55 -0800 | [diff] [blame] | 1059 | void CellularCapabilityUniversal::OnScanReply( |
| 1060 | const ResultStringmapsCallback &callback, |
| 1061 | const ScanResults &results, |
| 1062 | const Error &error) { |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1063 | Stringmaps found_networks; |
Prathmesh Prabhu | 49ffffd | 2014-01-09 18:28:55 -0800 | [diff] [blame] | 1064 | for (const auto &result : results) |
| 1065 | found_networks.push_back(ParseScanResult(result)); |
| 1066 | callback.Run(found_networks, error); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | Stringmap CellularCapabilityUniversal::ParseScanResult( |
| 1070 | const ScanResult &result) { |
| 1071 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1072 | /* ScanResults contain the following keys: |
| 1073 | |
| 1074 | "status" |
| 1075 | A MMModem3gppNetworkAvailability value representing network |
| 1076 | availability status, given as an unsigned integer (signature "u"). |
| 1077 | This key will always be present. |
| 1078 | |
| 1079 | "operator-long" |
| 1080 | Long-format name of operator, given as a string value (signature |
| 1081 | "s"). If the name is unknown, this field should not be present. |
| 1082 | |
| 1083 | "operator-short" |
| 1084 | Short-format name of operator, given as a string value |
| 1085 | (signature "s"). If the name is unknown, this field should not |
| 1086 | be present. |
| 1087 | |
| 1088 | "operator-code" |
| 1089 | Mobile code of the operator, given as a string value (signature |
| 1090 | "s"). Returned in the format "MCCMNC", where MCC is the |
| 1091 | three-digit ITU E.212 Mobile Country Code and MNC is the two- or |
| 1092 | three-digit GSM Mobile Network Code. e.g. "31026" or "310260". |
| 1093 | |
| 1094 | "access-technology" |
| 1095 | A MMModemAccessTechnology value representing the generic access |
| 1096 | technology used by this mobile network, given as an unsigned |
| 1097 | integer (signature "u"). |
| 1098 | */ |
| 1099 | Stringmap parsed; |
| 1100 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1101 | uint32_t status; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1102 | if (DBusProperties::GetUint32(result, kStatusProperty, &status)) { |
| 1103 | // numerical values are taken from 3GPP TS 27.007 Section 7.3. |
| 1104 | static const char * const kStatusString[] = { |
| 1105 | "unknown", // MM_MODEM_3GPP_NETWORK_AVAILABILITY_UNKNOWN |
| 1106 | "available", // MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE |
| 1107 | "current", // MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT |
| 1108 | "forbidden", // MM_MODEM_3GPP_NETWORK_AVAILABILITY_FORBIDDEN |
| 1109 | }; |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1110 | parsed[kStatusProperty] = kStatusString[status]; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1111 | } |
| 1112 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1113 | uint32_t tech; // MMModemAccessTechnology |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1114 | if (DBusProperties::GetUint32(result, kOperatorAccessTechnologyProperty, |
| 1115 | &tech)) { |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1116 | parsed[kTechnologyProperty] = AccessTechnologyToString(tech); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | string operator_long, operator_short, operator_code; |
| 1120 | if (DBusProperties::GetString(result, kOperatorLongProperty, &operator_long)) |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1121 | parsed[kLongNameProperty] = operator_long; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1122 | if (DBusProperties::GetString(result, kOperatorShortProperty, |
| 1123 | &operator_short)) |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1124 | parsed[kShortNameProperty] = operator_short; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1125 | if (DBusProperties::GetString(result, kOperatorCodeProperty, &operator_code)) |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1126 | parsed[kNetworkIdProperty] = operator_code; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1127 | |
| 1128 | // If the long name is not available but the network ID is, look up the long |
| 1129 | // name in the mobile provider database. |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1130 | if ((!ContainsKey(parsed, kLongNameProperty) || |
| 1131 | parsed[kLongNameProperty].empty()) && |
| 1132 | ContainsKey(parsed, kNetworkIdProperty)) { |
Prathmesh Prabhu | afe6366 | 2014-05-20 11:03:58 -0700 | [diff] [blame] | 1133 | mobile_operator_info_->Reset(); |
| 1134 | mobile_operator_info_->UpdateMCCMNC(parsed[kNetworkIdProperty]); |
| 1135 | if (mobile_operator_info_->IsMobileNetworkOperatorKnown() && |
| 1136 | !mobile_operator_info_->operator_name().empty()) { |
| 1137 | parsed[kLongNameProperty] = mobile_operator_info_->operator_name(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1138 | } |
| 1139 | } |
| 1140 | return parsed; |
| 1141 | } |
| 1142 | |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 1143 | CellularBearer *CellularCapabilityUniversal::GetActiveBearer() const { |
| 1144 | return active_bearer_.get(); |
| 1145 | } |
| 1146 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1147 | string CellularCapabilityUniversal::GetNetworkTechnologyString() const { |
Arman Uguray | 7af0fac | 2013-03-18 17:35:35 -0700 | [diff] [blame] | 1148 | // If we know that the modem is an E362, return LTE here to make sure that |
| 1149 | // Chrome sees LTE as the network technology even if the actual technology is |
| 1150 | // unknown. |
| 1151 | // TODO(armansito): This hack will cause the UI to display LTE even if the |
| 1152 | // modem doesn't support it at a given time. This might be problematic if we |
| 1153 | // ever want to support switching between access technologies (e.g. falling |
| 1154 | // back to 3G when LTE is not available). |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1155 | if (cellular()->model_id() == kE362ModelId) |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1156 | return kNetworkTechnologyLte; |
Arman Uguray | 7af0fac | 2013-03-18 17:35:35 -0700 | [diff] [blame] | 1157 | |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1158 | // Order is important. Return the highest speed technology |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1159 | // TODO(jglasgow): change shill interfaces to a capability model |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1160 | return AccessTechnologyToString(access_technologies_); |
| 1161 | } |
| 1162 | |
| 1163 | string CellularCapabilityUniversal::GetRoamingStateString() const { |
| 1164 | switch (registration_state_) { |
| 1165 | case MM_MODEM_3GPP_REGISTRATION_STATE_HOME: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1166 | return kRoamingStateHome; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1167 | case MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING: |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1168 | return kRoamingStateRoaming; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1169 | default: |
| 1170 | break; |
| 1171 | } |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1172 | return kRoamingStateUnknown; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1173 | } |
| 1174 | |
Arman Uguray | 5d9a852 | 2013-09-10 17:43:13 -0700 | [diff] [blame] | 1175 | // TODO(armansito): Remove this method once cromo is deprecated. |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1176 | void CellularCapabilityUniversal::GetSignalQuality() { |
Arman Uguray | 5d9a852 | 2013-09-10 17:43:13 -0700 | [diff] [blame] | 1177 | // ModemManager always returns the cached value, so there is no need to |
| 1178 | // trigger an update here. The true value is updated through a property |
| 1179 | // change signal. |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1180 | } |
| 1181 | |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1182 | string CellularCapabilityUniversal::GetTypeString() const { |
| 1183 | return AccessTechnologyToTechnologyFamily(access_technologies_); |
| 1184 | } |
| 1185 | |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 1186 | void CellularCapabilityUniversal::OnModemPropertiesChanged( |
| 1187 | const DBusPropertiesMap &properties, |
| 1188 | const vector<string> &/* invalidated_properties */) { |
Ben Chan | cbef812 | 2014-01-06 17:31:30 -0800 | [diff] [blame] | 1189 | |
| 1190 | // Update the bearers property before the modem state property as |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 1191 | // OnModemStateChanged may call UpdateActiveBearer, which reads the bearers |
| 1192 | // property. |
Ben Chan | cbef812 | 2014-01-06 17:31:30 -0800 | [diff] [blame] | 1193 | RpcIdentifiers bearers; |
| 1194 | if (DBusProperties::GetRpcIdentifiers(properties, MM_MODEM_PROPERTY_BEARERS, |
| 1195 | &bearers)) { |
| 1196 | OnBearersChanged(bearers); |
| 1197 | } |
| 1198 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 1199 | // This solves a bootstrapping problem: If the modem is not yet |
| 1200 | // enabled, there are no proxy objects associated with the capability |
| 1201 | // object, so modem signals like StateChanged aren't seen. By monitoring |
| 1202 | // changes to the State property via the ModemManager, we're able to |
| 1203 | // get the initialization process started, which will result in the |
| 1204 | // creation of the proxy objects. |
| 1205 | // |
| 1206 | // The first time we see the change to State (when the modem state |
| 1207 | // is Unknown), we simply update the state, and rely on the Manager to |
| 1208 | // enable the device when it is registered with the Manager. On subsequent |
| 1209 | // changes to State, we need to explicitly enable the device ourselves. |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1210 | int32_t istate; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1211 | if (DBusProperties::GetInt32(properties, MM_MODEM_PROPERTY_STATE, &istate)) { |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 1212 | Cellular::ModemState state = static_cast<Cellular::ModemState>(istate); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1213 | OnModemStateChanged(state); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 1214 | } |
Ben Chan | 0a3a3a5 | 2013-07-10 11:34:07 -0700 | [diff] [blame] | 1215 | DBus::Path object_path_value; |
Nathan Williams | e984080 | 2012-04-18 18:47:40 -0400 | [diff] [blame] | 1216 | if (DBusProperties::GetObjectPath(properties, |
Ben Chan | 0a3a3a5 | 2013-07-10 11:34:07 -0700 | [diff] [blame] | 1217 | MM_MODEM_PROPERTY_SIM, &object_path_value)) |
| 1218 | OnSimPathChanged(object_path_value); |
Ben Chan | 74924d8 | 2013-06-15 17:52:55 -0700 | [diff] [blame] | 1219 | |
| 1220 | DBusPropertiesMap::const_iterator it = |
| 1221 | properties.find(MM_MODEM_PROPERTY_SUPPORTEDCAPABILITIES); |
| 1222 | if (it != properties.end()) { |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1223 | const vector<uint32_t> &supported_capabilities = it->second; |
Ben Chan | 74924d8 | 2013-06-15 17:52:55 -0700 | [diff] [blame] | 1224 | OnSupportedCapabilitesChanged(supported_capabilities); |
| 1225 | } |
| 1226 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1227 | uint32_t uint_value; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1228 | if (DBusProperties::GetUint32(properties, |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1229 | MM_MODEM_PROPERTY_CURRENTCAPABILITIES, |
| 1230 | &uint_value)) |
| 1231 | OnModemCurrentCapabilitiesChanged(uint_value); |
| 1232 | // not needed: MM_MODEM_PROPERTY_MAXBEARERS |
| 1233 | // not needed: MM_MODEM_PROPERTY_MAXACTIVEBEARERS |
Ben Chan | 0a3a3a5 | 2013-07-10 11:34:07 -0700 | [diff] [blame] | 1234 | string string_value; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1235 | if (DBusProperties::GetString(properties, |
| 1236 | MM_MODEM_PROPERTY_MANUFACTURER, |
| 1237 | &string_value)) |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1238 | cellular()->set_manufacturer(string_value); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1239 | if (DBusProperties::GetString(properties, |
| 1240 | MM_MODEM_PROPERTY_MODEL, |
| 1241 | &string_value)) |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1242 | cellular()->set_model_id(string_value); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1243 | if (DBusProperties::GetString(properties, |
Thieu Le | c466ccb | 2014-06-23 15:24:56 -0700 | [diff] [blame] | 1244 | MM_MODEM_PROPERTY_PLUGIN, |
| 1245 | &string_value)) |
| 1246 | cellular()->set_mm_plugin(string_value); |
| 1247 | if (DBusProperties::GetString(properties, |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1248 | MM_MODEM_PROPERTY_REVISION, |
| 1249 | &string_value)) |
| 1250 | OnModemRevisionChanged(string_value); |
| 1251 | // not needed: MM_MODEM_PROPERTY_DEVICEIDENTIFIER |
| 1252 | // not needed: MM_MODEM_PROPERTY_DEVICE |
| 1253 | // not needed: MM_MODEM_PROPERTY_DRIVER |
| 1254 | // not needed: MM_MODEM_PROPERTY_PLUGIN |
| 1255 | // not needed: MM_MODEM_PROPERTY_EQUIPMENTIDENTIFIER |
Nathan Williams | 218cbcd | 2012-04-17 16:48:44 -0400 | [diff] [blame] | 1256 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1257 | // Unlock required and SimLock |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1258 | uint32_t unlock_required; // This is really of type MMModemLock |
Arman Uguray | ea5ff27 | 2013-06-25 10:28:02 -0700 | [diff] [blame] | 1259 | bool lock_status_changed = false; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1260 | if (DBusProperties::GetUint32(properties, |
| 1261 | MM_MODEM_PROPERTY_UNLOCKREQUIRED, |
Arman Uguray | ea5ff27 | 2013-06-25 10:28:02 -0700 | [diff] [blame] | 1262 | &unlock_required)) { |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1263 | OnLockTypeChanged(static_cast<MMModemLock>(unlock_required)); |
Arman Uguray | ea5ff27 | 2013-06-25 10:28:02 -0700 | [diff] [blame] | 1264 | lock_status_changed = true; |
| 1265 | } |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1266 | |
| 1267 | // Unlock retries |
Ben Chan | 74924d8 | 2013-06-15 17:52:55 -0700 | [diff] [blame] | 1268 | it = properties.find(MM_MODEM_PROPERTY_UNLOCKRETRIES); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1269 | if (it != properties.end()) { |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1270 | LockRetryData lock_retries = it->second.operator LockRetryData(); |
| 1271 | OnLockRetriesChanged(lock_retries); |
Arman Uguray | ea5ff27 | 2013-06-25 10:28:02 -0700 | [diff] [blame] | 1272 | lock_status_changed = true; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1273 | } |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1274 | |
Arman Uguray | ea5ff27 | 2013-06-25 10:28:02 -0700 | [diff] [blame] | 1275 | if (lock_status_changed) |
| 1276 | OnSimLockStatusChanged(); |
| 1277 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1278 | if (DBusProperties::GetUint32(properties, |
| 1279 | MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES, |
| 1280 | &uint_value)) |
| 1281 | OnAccessTechnologiesChanged(uint_value); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1282 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1283 | it = properties.find(MM_MODEM_PROPERTY_SIGNALQUALITY); |
| 1284 | if (it != properties.end()) { |
| 1285 | DBus::Struct<unsigned int, bool> quality = it->second; |
| 1286 | OnSignalQualityChanged(quality._1); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1287 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1288 | vector<string> numbers; |
| 1289 | if (DBusProperties::GetStrings(properties, MM_MODEM_PROPERTY_OWNNUMBERS, |
| 1290 | &numbers)) { |
| 1291 | string mdn; |
| 1292 | if (numbers.size() > 0) |
| 1293 | mdn = numbers[0]; |
| 1294 | OnMdnChanged(mdn); |
| 1295 | } |
Ben Chan | 74924d8 | 2013-06-15 17:52:55 -0700 | [diff] [blame] | 1296 | |
| 1297 | it = properties.find(MM_MODEM_PROPERTY_SUPPORTEDMODES); |
| 1298 | if (it != properties.end()) { |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1299 | const vector<DBus::Struct<uint32_t, uint32_t>> &mm_supported_modes = |
| 1300 | it->second; |
Ben Chan | 74924d8 | 2013-06-15 17:52:55 -0700 | [diff] [blame] | 1301 | vector<ModemModes> supported_modes; |
| 1302 | for (const auto &modes : mm_supported_modes) { |
| 1303 | supported_modes.push_back( |
| 1304 | ModemModes(modes._1, static_cast<MMModemMode>(modes._2))); |
| 1305 | } |
| 1306 | OnSupportedModesChanged(supported_modes); |
| 1307 | } |
| 1308 | |
| 1309 | it = properties.find(MM_MODEM_PROPERTY_CURRENTMODES); |
| 1310 | if (it != properties.end()) { |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1311 | const DBus::Struct<uint32_t, uint32_t> ¤t_modes = it->second; |
Ben Chan | 74924d8 | 2013-06-15 17:52:55 -0700 | [diff] [blame] | 1312 | OnCurrentModesChanged(ModemModes( |
| 1313 | current_modes._1, static_cast<MMModemMode>(current_modes._2))); |
| 1314 | } |
| 1315 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1316 | // au: MM_MODEM_PROPERTY_SUPPORTEDBANDS, |
| 1317 | // au: MM_MODEM_PROPERTY_BANDS |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | void CellularCapabilityUniversal::OnDBusPropertiesChanged( |
| 1321 | const string &interface, |
| 1322 | const DBusPropertiesMap &changed_properties, |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 1323 | const vector<string> &invalidated_properties) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 1324 | SLOG(Cellular, 3) << __func__ << "(" << interface << ")"; |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 1325 | if (interface == MM_DBUS_INTERFACE_MODEM) { |
Jason Glasgow | 4c0724a | 2012-04-17 15:47:40 -0400 | [diff] [blame] | 1326 | OnModemPropertiesChanged(changed_properties, invalidated_properties); |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 1327 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1328 | if (interface == MM_DBUS_INTERFACE_MODEM_MODEM3GPP) { |
| 1329 | OnModem3GPPPropertiesChanged(changed_properties, invalidated_properties); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1330 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1331 | if (interface == MM_DBUS_INTERFACE_SIM) { |
| 1332 | OnSimPropertiesChanged(changed_properties, invalidated_properties); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1333 | } |
| 1334 | } |
| 1335 | |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 1336 | bool CellularCapabilityUniversal::RetriableConnectError( |
| 1337 | const Error &error) const { |
| 1338 | if (error.type() == Error::kInvalidApn) |
| 1339 | return true; |
| 1340 | |
| 1341 | // modemmanager does not ever return kInvalidApn for E362 modems |
| 1342 | // with 1.41 firmware. It remains to be seem if this will change |
| 1343 | // with 3.x firmware. |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1344 | if ((cellular()->model_id() == kE362ModelId) && |
| 1345 | (error.type() == Error::kOperationFailed)) |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 1346 | return true; |
| 1347 | |
| 1348 | return false; |
| 1349 | } |
| 1350 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1351 | void CellularCapabilityUniversal::OnNetworkModeSignal(uint32_t /*mode*/) { |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1352 | // TODO(petkov): Implement this. |
| 1353 | NOTIMPLEMENTED(); |
| 1354 | } |
| 1355 | |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 1356 | bool CellularCapabilityUniversal::IsValidSimPath(const string &sim_path) const { |
| 1357 | return !sim_path.empty() && sim_path != kRootPath; |
| 1358 | } |
| 1359 | |
Ben Chan | d759252 | 2013-02-13 16:02:01 -0800 | [diff] [blame] | 1360 | string CellularCapabilityUniversal::NormalizeMdn(const string &mdn) const { |
| 1361 | string normalized_mdn; |
| 1362 | for (size_t i = 0; i < mdn.size(); ++i) { |
| 1363 | if (IsAsciiDigit(mdn[i])) |
| 1364 | normalized_mdn += mdn[i]; |
| 1365 | } |
| 1366 | return normalized_mdn; |
| 1367 | } |
| 1368 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1369 | void CellularCapabilityUniversal::OnSimPathChanged( |
| 1370 | const string &sim_path) { |
| 1371 | if (sim_path == sim_path_) |
| 1372 | return; |
| 1373 | |
| 1374 | mm1::SimProxyInterface *proxy = NULL; |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 1375 | if (IsValidSimPath(sim_path)) |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1376 | proxy = proxy_factory()->CreateSimProxy(sim_path, |
| 1377 | cellular()->dbus_owner()); |
| 1378 | sim_path_ = sim_path; |
| 1379 | sim_proxy_.reset(proxy); |
| 1380 | |
Arman Uguray | 6552f8c | 2013-02-12 15:33:18 -0800 | [diff] [blame] | 1381 | if (!IsValidSimPath(sim_path)) { |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1382 | // Clear all data about the sim |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1383 | cellular()->set_imsi(""); |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 1384 | spn_ = ""; |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1385 | cellular()->set_sim_present(false); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1386 | OnSimIdentifierChanged(""); |
| 1387 | OnOperatorIdChanged(""); |
Prathmesh Prabhu | 8599e05 | 2014-04-25 14:20:22 -0700 | [diff] [blame] | 1388 | cellular()->home_provider_info()->Reset(); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1389 | } else { |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1390 | cellular()->set_sim_present(true); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1391 | scoped_ptr<DBusPropertiesProxyInterface> properties_proxy( |
| 1392 | proxy_factory()->CreateDBusPropertiesProxy(sim_path, |
| 1393 | cellular()->dbus_owner())); |
| 1394 | // TODO(jglasgow): convert to async interface |
| 1395 | DBusPropertiesMap properties( |
| 1396 | properties_proxy->GetAll(MM_DBUS_INTERFACE_SIM)); |
| 1397 | OnSimPropertiesChanged(properties, vector<string>()); |
| 1398 | } |
| 1399 | } |
| 1400 | |
Ben Chan | 74924d8 | 2013-06-15 17:52:55 -0700 | [diff] [blame] | 1401 | void CellularCapabilityUniversal::OnSupportedCapabilitesChanged( |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1402 | const vector<uint32_t> &supported_capabilities) { |
Ben Chan | 74924d8 | 2013-06-15 17:52:55 -0700 | [diff] [blame] | 1403 | supported_capabilities_ = supported_capabilities; |
| 1404 | } |
| 1405 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1406 | void CellularCapabilityUniversal::OnModemCurrentCapabilitiesChanged( |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1407 | uint32_t current_capabilities) { |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1408 | current_capabilities_ = current_capabilities; |
Ben Chan | fcca27b | 2013-01-22 15:03:44 -0800 | [diff] [blame] | 1409 | |
| 1410 | // Only allow network scan when the modem's current capabilities support |
| 1411 | // GSM/UMTS. |
| 1412 | // |
| 1413 | // TODO(benchan): We should consider having the modem plugins in ModemManager |
| 1414 | // reporting whether network scan is supported. |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1415 | cellular()->set_scanning_supported( |
| 1416 | (current_capabilities & MM_MODEM_CAPABILITY_GSM_UMTS) != 0); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | void CellularCapabilityUniversal::OnMdnChanged( |
| 1420 | const string &mdn) { |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1421 | cellular()->set_mdn(NormalizeMdn(mdn)); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1422 | UpdatePendingActivationState(); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1423 | } |
| 1424 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1425 | void CellularCapabilityUniversal::OnModemRevisionChanged( |
| 1426 | const string &revision) { |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1427 | cellular()->set_firmware_revision(revision); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | void CellularCapabilityUniversal::OnModemStateChanged( |
| 1431 | Cellular::ModemState state) { |
Ben Chan | f45b323 | 2013-10-08 20:54:01 -0700 | [diff] [blame] | 1432 | SLOG(Cellular, 3) << __func__ << ": " << Cellular::GetModemStateString(state); |
Arman Uguray | 1ee9391 | 2013-09-24 21:24:10 -0700 | [diff] [blame] | 1433 | |
Ben Chan | 539ab02 | 2014-02-03 16:34:57 -0800 | [diff] [blame] | 1434 | if (state == Cellular::kModemStateConnected) { |
| 1435 | // This assumes that ModemManager updates the Bearers list and the Bearer |
| 1436 | // properties before changing Modem state to Connected. |
| 1437 | SLOG(Cellular, 2) << "Update active bearer."; |
| 1438 | UpdateActiveBearer(); |
| 1439 | } |
| 1440 | |
Arman Uguray | 1ee9391 | 2013-09-24 21:24:10 -0700 | [diff] [blame] | 1441 | cellular()->OnModemStateChanged(state); |
Arman Uguray | 1ee9391 | 2013-09-24 21:24:10 -0700 | [diff] [blame] | 1442 | // TODO(armansito): Move the deferred enable logic to Cellular |
| 1443 | // (See crbug.com/279499). |
| 1444 | if (!deferred_enable_modem_callback_.is_null() && |
| 1445 | state == Cellular::kModemStateDisabled) { |
| 1446 | SLOG(Cellular, 2) << "Enabling modem after deferring."; |
| 1447 | deferred_enable_modem_callback_.Run(); |
| 1448 | deferred_enable_modem_callback_.Reset(); |
mukesh agrawal | 510cc80 | 2013-08-15 18:31:42 -0700 | [diff] [blame] | 1449 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | void CellularCapabilityUniversal::OnAccessTechnologiesChanged( |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1453 | uint32_t access_technologies) { |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1454 | if (access_technologies_ != access_technologies) { |
Jason Glasgow | bad114b | 2012-05-21 15:24:16 -0400 | [diff] [blame] | 1455 | const string old_type_string(GetTypeString()); |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1456 | access_technologies_ = access_technologies; |
Jason Glasgow | bad114b | 2012-05-21 15:24:16 -0400 | [diff] [blame] | 1457 | const string new_type_string(GetTypeString()); |
| 1458 | if (new_type_string != old_type_string) { |
| 1459 | // TODO(jglasgow): address layering violation of emitting change |
| 1460 | // signal here for a property owned by Cellular. |
| 1461 | cellular()->adaptor()->EmitStringChanged( |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1462 | kTechnologyFamilyProperty, new_type_string); |
Jason Glasgow | bad114b | 2012-05-21 15:24:16 -0400 | [diff] [blame] | 1463 | } |
Jason Glasgow | 9f09aef | 2012-05-08 16:26:55 -0400 | [diff] [blame] | 1464 | if (cellular()->service().get()) { |
| 1465 | cellular()->service()->SetNetworkTechnology(GetNetworkTechnologyString()); |
| 1466 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1467 | } |
| 1468 | } |
| 1469 | |
Ben Chan | 74924d8 | 2013-06-15 17:52:55 -0700 | [diff] [blame] | 1470 | void CellularCapabilityUniversal::OnSupportedModesChanged( |
| 1471 | const vector<ModemModes> &supported_modes) { |
| 1472 | supported_modes_ = supported_modes; |
| 1473 | } |
| 1474 | |
| 1475 | void CellularCapabilityUniversal::OnCurrentModesChanged( |
| 1476 | const ModemModes ¤t_modes) { |
| 1477 | current_modes_ = current_modes; |
| 1478 | } |
| 1479 | |
Ben Chan | cbef812 | 2014-01-06 17:31:30 -0800 | [diff] [blame] | 1480 | void CellularCapabilityUniversal::OnBearersChanged( |
| 1481 | const RpcIdentifiers &bearers) { |
| 1482 | bearer_paths_ = bearers; |
| 1483 | } |
| 1484 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1485 | void CellularCapabilityUniversal::OnLockRetriesChanged( |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1486 | const LockRetryData &lock_retries) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 1487 | SLOG(Cellular, 3) << __func__; |
Arman Uguray | 192ad82 | 2013-06-13 19:49:16 -0700 | [diff] [blame] | 1488 | |
Arman Uguray | ea5ff27 | 2013-06-25 10:28:02 -0700 | [diff] [blame] | 1489 | // Look for the retries left for the current lock. Try the obtain the count |
| 1490 | // that matches the current count. If no count for the current lock is |
| 1491 | // available, report the first one in the dictionary. |
| 1492 | LockRetryData::const_iterator it = |
| 1493 | lock_retries.find(sim_lock_status_.lock_type); |
| 1494 | if (it == lock_retries.end()) |
Arman Uguray | 192ad82 | 2013-06-13 19:49:16 -0700 | [diff] [blame] | 1495 | it = lock_retries.begin(); |
| 1496 | if (it != lock_retries.end()) |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1497 | sim_lock_status_.retries_left = it->second; |
Arman Uguray | 192ad82 | 2013-06-13 19:49:16 -0700 | [diff] [blame] | 1498 | else |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1499 | // Unknown, use 999 |
| 1500 | sim_lock_status_.retries_left = 999; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1501 | } |
| 1502 | |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1503 | void CellularCapabilityUniversal::OnLockTypeChanged( |
| 1504 | MMModemLock lock_type) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 1505 | SLOG(Cellular, 3) << __func__ << ": " << lock_type; |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1506 | sim_lock_status_.lock_type = lock_type; |
Arman Uguray | 4ef02fd | 2013-06-13 20:14:20 -0700 | [diff] [blame] | 1507 | |
| 1508 | // If the SIM is in a locked state |sim_lock_status_.enabled| might be false. |
| 1509 | // This is because the corresponding property 'EnabledFacilityLocks' is on |
| 1510 | // the 3GPP interface and the 3GPP interface is not available while the Modem |
| 1511 | // is in the 'LOCKED' state. |
| 1512 | if (lock_type != MM_MODEM_LOCK_NONE && |
| 1513 | lock_type != MM_MODEM_LOCK_UNKNOWN && |
| 1514 | !sim_lock_status_.enabled) |
| 1515 | sim_lock_status_.enabled = true; |
Arman Uguray | c7e63af | 2013-06-13 17:07:32 -0700 | [diff] [blame] | 1516 | } |
| 1517 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1518 | void CellularCapabilityUniversal::OnSimLockStatusChanged() { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 1519 | SLOG(Cellular, 3) << __func__; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1520 | cellular()->adaptor()->EmitKeyValueStoreChanged( |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 1521 | kSIMLockStatusProperty, SimLockStatusToProperty(NULL)); |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 1522 | |
| 1523 | // If the SIM is currently unlocked, assume that we need to refresh |
| 1524 | // carrier information, since a locked SIM prevents shill from obtaining |
| 1525 | // the necessary data to establish a connection later (e.g. IMSI). |
Ben Chan | d3b1874 | 2013-07-12 00:30:25 -0700 | [diff] [blame] | 1526 | if (IsValidSimPath(sim_path_) && |
Arman Uguray | 4ef02fd | 2013-06-13 20:14:20 -0700 | [diff] [blame] | 1527 | (sim_lock_status_.lock_type == MM_MODEM_LOCK_NONE || |
| 1528 | sim_lock_status_.lock_type == MM_MODEM_LOCK_UNKNOWN)) { |
Arman Uguray | ab9364e | 2012-12-19 20:45:25 -0800 | [diff] [blame] | 1529 | scoped_ptr<DBusPropertiesProxyInterface> properties_proxy( |
| 1530 | proxy_factory()->CreateDBusPropertiesProxy(sim_path_, |
| 1531 | cellular()->dbus_owner())); |
| 1532 | DBusPropertiesMap properties( |
| 1533 | properties_proxy->GetAll(MM_DBUS_INTERFACE_SIM)); |
| 1534 | OnSimPropertiesChanged(properties, vector<string>()); |
| 1535 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | void CellularCapabilityUniversal::OnModem3GPPPropertiesChanged( |
| 1539 | const DBusPropertiesMap &properties, |
| 1540 | const vector<string> &/* invalidated_properties */) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 1541 | SLOG(Cellular, 3) << __func__; |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1542 | uint32_t uint_value; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1543 | string imei; |
| 1544 | if (DBusProperties::GetString(properties, |
| 1545 | MM_MODEM_MODEM3GPP_PROPERTY_IMEI, |
| 1546 | &imei)) |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1547 | cellular()->set_imei(imei); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1548 | |
| 1549 | // Handle registration state changes as a single change |
| 1550 | string operator_code = serving_operator_.GetCode(); |
| 1551 | string operator_name = serving_operator_.GetName(); |
| 1552 | MMModem3gppRegistrationState state = registration_state_; |
| 1553 | bool registration_changed = false; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1554 | if (DBusProperties::GetUint32(properties, |
| 1555 | MM_MODEM_MODEM3GPP_PROPERTY_REGISTRATIONSTATE, |
| 1556 | &uint_value)) { |
| 1557 | state = static_cast<MMModem3gppRegistrationState>(uint_value); |
| 1558 | registration_changed = true; |
| 1559 | } |
| 1560 | if (DBusProperties::GetString(properties, |
| 1561 | MM_MODEM_MODEM3GPP_PROPERTY_OPERATORCODE, |
| 1562 | &operator_code)) |
| 1563 | registration_changed = true; |
| 1564 | if (DBusProperties::GetString(properties, |
| 1565 | MM_MODEM_MODEM3GPP_PROPERTY_OPERATORNAME, |
| 1566 | &operator_name)) |
| 1567 | registration_changed = true; |
| 1568 | if (registration_changed) |
| 1569 | On3GPPRegistrationChanged(state, operator_code, operator_name); |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1570 | if (DBusProperties::GetUint32(properties, |
| 1571 | MM_MODEM_MODEM3GPP_PROPERTY_SUBSCRIPTIONSTATE, |
| 1572 | &uint_value)) |
| 1573 | On3GPPSubscriptionStateChanged( |
| 1574 | static_cast<MMModem3gppSubscriptionState>(uint_value)); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1575 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1576 | uint32_t subscription_state; |
Thieu Le | 43ce4d4 | 2013-10-04 16:08:55 -0700 | [diff] [blame] | 1577 | CellularServiceRefPtr service = cellular()->service(); |
| 1578 | if (service.get() && |
| 1579 | DBusProperties::GetUint32(properties, |
| 1580 | MM_MODEM_MODEM3GPP_PROPERTY_SUBSCRIPTIONSTATE, |
| 1581 | &subscription_state)) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 1582 | SLOG(Cellular, 3) << __func__ << ": Subscription state = " |
Thieu Le | 43ce4d4 | 2013-10-04 16:08:55 -0700 | [diff] [blame] | 1583 | << subscription_state; |
| 1584 | service->out_of_credits_detector()->NotifySubscriptionStateChanged( |
| 1585 | subscription_state); |
| 1586 | } |
| 1587 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1588 | uint32_t locks = 0; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1589 | if (DBusProperties::GetUint32( |
| 1590 | properties, MM_MODEM_MODEM3GPP_PROPERTY_ENABLEDFACILITYLOCKS, |
| 1591 | &locks)) |
| 1592 | OnFacilityLocksChanged(locks); |
| 1593 | } |
| 1594 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1595 | void CellularCapabilityUniversal::On3GPPRegistrationChanged( |
| 1596 | MMModem3gppRegistrationState state, |
| 1597 | const string &operator_code, |
| 1598 | const string &operator_name) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 1599 | SLOG(Cellular, 3) << __func__ << ": regstate=" << state |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1600 | << ", opercode=" << operator_code |
| 1601 | << ", opername=" << operator_name; |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 1602 | |
| 1603 | // While the modem is connected, if the state changed from a registered state |
| 1604 | // to a non registered state, defer the state change by 15 seconds. |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 1605 | if (cellular()->modem_state() == Cellular::kModemStateConnected && |
| 1606 | IsRegistered() && !IsRegisteredState(state)) { |
| 1607 | if (!registration_dropped_update_callback_.IsCancelled()) { |
| 1608 | LOG(WARNING) << "Modem reported consecutive 3GPP registration drops. " |
| 1609 | << "Ignoring earlier notifications."; |
| 1610 | registration_dropped_update_callback_.Cancel(); |
Prathmesh Prabhu | 08757aa | 2013-05-15 17:17:33 -0700 | [diff] [blame] | 1611 | } else { |
| 1612 | // This is not a repeated post. So, count this instance of delayed drop |
| 1613 | // posted. |
| 1614 | modem_info()->metrics()->Notify3GPPRegistrationDelayedDropPosted(); |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 1615 | } |
| 1616 | SLOG(Cellular, 2) << "Posted deferred registration state update"; |
| 1617 | registration_dropped_update_callback_.Reset( |
| 1618 | Bind(&CellularCapabilityUniversal::Handle3GPPRegistrationChange, |
| 1619 | weak_ptr_factory_.GetWeakPtr(), |
| 1620 | state, |
| 1621 | operator_code, |
| 1622 | operator_name)); |
| 1623 | cellular()->dispatcher()->PostDelayedTask( |
| 1624 | registration_dropped_update_callback_.callback(), |
| 1625 | registration_dropped_update_timeout_milliseconds_); |
| 1626 | } else { |
| 1627 | if (!registration_dropped_update_callback_.IsCancelled()) { |
| 1628 | SLOG(Cellular, 2) << "Cancelled a deferred registration state update"; |
| 1629 | registration_dropped_update_callback_.Cancel(); |
Prathmesh Prabhu | 08757aa | 2013-05-15 17:17:33 -0700 | [diff] [blame] | 1630 | // If we cancelled the callback here, it means we had flaky network for a |
| 1631 | // small duration. |
| 1632 | modem_info()->metrics()->Notify3GPPRegistrationDelayedDropCanceled(); |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 1633 | } |
| 1634 | Handle3GPPRegistrationChange(state, operator_code, operator_name); |
| 1635 | } |
| 1636 | } |
| 1637 | |
| 1638 | void CellularCapabilityUniversal::Handle3GPPRegistrationChange( |
| 1639 | MMModem3gppRegistrationState updated_state, |
| 1640 | string updated_operator_code, |
| 1641 | string updated_operator_name) { |
| 1642 | // A finished callback does not qualify as a canceled callback. |
| 1643 | // We test for a canceled callback to check for outstanding callbacks. |
| 1644 | // So, explicitly cancel the callback here. |
| 1645 | registration_dropped_update_callback_.Cancel(); |
| 1646 | |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 1647 | SLOG(Cellular, 3) << __func__ << ": regstate=" << updated_state |
Prathmesh Prabhu | 8f6479f | 2013-05-15 12:56:13 -0700 | [diff] [blame] | 1648 | << ", opercode=" << updated_operator_code |
| 1649 | << ", opername=" << updated_operator_name; |
| 1650 | |
| 1651 | registration_state_ = updated_state; |
| 1652 | serving_operator_.SetCode(updated_operator_code); |
| 1653 | serving_operator_.SetName(updated_operator_name); |
Prathmesh Prabhu | 8599e05 | 2014-04-25 14:20:22 -0700 | [diff] [blame] | 1654 | cellular()->serving_operator_info()->UpdateMCCMNC(updated_operator_code); |
| 1655 | cellular()->serving_operator_info()->UpdateOperatorName( |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1656 | updated_operator_name); |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 1657 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1658 | cellular()->HandleNewRegistrationState(); |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 1659 | |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 1660 | // If the modem registered with the network and the current ICCID is pending |
| 1661 | // activation, then reset the modem. |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1662 | UpdatePendingActivationState(); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1663 | } |
| 1664 | |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1665 | void CellularCapabilityUniversal::On3GPPSubscriptionStateChanged( |
| 1666 | MMModem3gppSubscriptionState updated_state) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 1667 | SLOG(Cellular, 3) << __func__ << ": Updated subscription state = " |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1668 | << updated_state; |
| 1669 | |
| 1670 | // A one-to-one enum mapping. |
Thieu Le | 314581f | 2014-02-19 13:02:47 -0800 | [diff] [blame] | 1671 | SubscriptionState new_subscription_state; |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1672 | switch (updated_state) { |
| 1673 | case MM_MODEM_3GPP_SUBSCRIPTION_STATE_UNKNOWN: |
Thieu Le | 314581f | 2014-02-19 13:02:47 -0800 | [diff] [blame] | 1674 | new_subscription_state = kSubscriptionStateUnknown; |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1675 | break; |
| 1676 | case MM_MODEM_3GPP_SUBSCRIPTION_STATE_PROVISIONED: |
Thieu Le | 314581f | 2014-02-19 13:02:47 -0800 | [diff] [blame] | 1677 | new_subscription_state = kSubscriptionStateProvisioned; |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1678 | break; |
| 1679 | case MM_MODEM_3GPP_SUBSCRIPTION_STATE_UNPROVISIONED: |
Thieu Le | 314581f | 2014-02-19 13:02:47 -0800 | [diff] [blame] | 1680 | new_subscription_state = kSubscriptionStateUnprovisioned; |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1681 | break; |
| 1682 | case MM_MODEM_3GPP_SUBSCRIPTION_STATE_OUT_OF_DATA: |
Thieu Le | 314581f | 2014-02-19 13:02:47 -0800 | [diff] [blame] | 1683 | new_subscription_state = kSubscriptionStateOutOfData; |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1684 | break; |
| 1685 | default: |
| 1686 | LOG(ERROR) << "Unrecognized MMModem3gppSubscriptionState: " |
| 1687 | << updated_state; |
Thieu Le | 314581f | 2014-02-19 13:02:47 -0800 | [diff] [blame] | 1688 | new_subscription_state = kSubscriptionStateUnknown; |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1689 | return; |
| 1690 | } |
Thieu Le | 314581f | 2014-02-19 13:02:47 -0800 | [diff] [blame] | 1691 | if (new_subscription_state == subscription_state_) |
| 1692 | return; |
| 1693 | |
| 1694 | subscription_state_ = new_subscription_state; |
Prathmesh Prabhu | 9a0534e | 2013-10-10 16:20:34 -0700 | [diff] [blame] | 1695 | |
| 1696 | UpdateServiceActivationState(); |
| 1697 | UpdatePendingActivationState(); |
| 1698 | } |
| 1699 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 1700 | void CellularCapabilityUniversal::OnModemStateChangedSignal( |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1701 | int32_t old_state, int32_t new_state, uint32_t reason) { |
Ben Chan | f45b323 | 2013-10-08 20:54:01 -0700 | [diff] [blame] | 1702 | Cellular::ModemState old_modem_state = |
| 1703 | static_cast<Cellular::ModemState>(old_state); |
| 1704 | Cellular::ModemState new_modem_state = |
| 1705 | static_cast<Cellular::ModemState>(new_state); |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 1706 | SLOG(Cellular, 3) << __func__ << "(" |
Ben Chan | f45b323 | 2013-10-08 20:54:01 -0700 | [diff] [blame] | 1707 | << Cellular::GetModemStateString(old_modem_state) << ", " |
| 1708 | << Cellular::GetModemStateString(new_modem_state) << ", " |
Eric Shienbrood | 9b1bd7b | 2012-04-20 16:42:26 -0400 | [diff] [blame] | 1709 | << reason << ")"; |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 1710 | } |
| 1711 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1712 | void CellularCapabilityUniversal::OnSignalQualityChanged(uint32_t quality) { |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1713 | cellular()->HandleNewSignalQuality(quality); |
| 1714 | } |
| 1715 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1716 | void CellularCapabilityUniversal::OnFacilityLocksChanged(uint32_t locks) { |
Arman Uguray | 4ef02fd | 2013-06-13 20:14:20 -0700 | [diff] [blame] | 1717 | bool sim_enabled = !!(locks & MM_MODEM_3GPP_FACILITY_SIM); |
| 1718 | if (sim_lock_status_.enabled != sim_enabled) { |
| 1719 | sim_lock_status_.enabled = sim_enabled; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1720 | OnSimLockStatusChanged(); |
| 1721 | } |
| 1722 | } |
Jason Glasgow | ef96556 | 2012-04-10 16:12:35 -0400 | [diff] [blame] | 1723 | |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1724 | void CellularCapabilityUniversal::OnSimPropertiesChanged( |
| 1725 | const DBusPropertiesMap &props, |
| 1726 | const vector<string> &/* invalidated_properties */) { |
Thieu Le | 2849214 | 2014-04-08 16:41:13 -0700 | [diff] [blame] | 1727 | SLOG(Cellular, 3) << __func__; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1728 | string value; |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1729 | if (DBusProperties::GetString(props, MM_SIM_PROPERTY_SIMIDENTIFIER, &value)) |
| 1730 | OnSimIdentifierChanged(value); |
| 1731 | if (DBusProperties::GetString(props, MM_SIM_PROPERTY_OPERATORIDENTIFIER, |
| 1732 | &value)) |
| 1733 | OnOperatorIdChanged(value); |
Arman Uguray | d73783f | 2013-01-31 16:11:21 -0800 | [diff] [blame] | 1734 | if (DBusProperties::GetString(props, MM_SIM_PROPERTY_OPERATORNAME, &value)) |
| 1735 | OnSpnChanged(value); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1736 | if (DBusProperties::GetString(props, MM_SIM_PROPERTY_IMSI, &value)) { |
Prathmesh Prabhu | 9f06c87 | 2013-11-21 14:08:23 -0800 | [diff] [blame] | 1737 | cellular()->set_imsi(value); |
Prathmesh Prabhu | 8599e05 | 2014-04-25 14:20:22 -0700 | [diff] [blame] | 1738 | cellular()->home_provider_info()->UpdateIMSI(value); |
Prathmesh Prabhu | c93b6bc | 2014-07-28 15:20:11 -0700 | [diff] [blame] | 1739 | // We do not obtain IMSI OTA right now. Provide the value from the SIM to |
| 1740 | // serving operator as well, to aid in MVNO identification. |
| 1741 | cellular()->serving_operator_info()->UpdateIMSI(value); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1742 | } |
Arman Uguray | d73783f | 2013-01-31 16:11:21 -0800 | [diff] [blame] | 1743 | } |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1744 | |
Arman Uguray | d73783f | 2013-01-31 16:11:21 -0800 | [diff] [blame] | 1745 | void CellularCapabilityUniversal::OnSpnChanged(const std::string &spn) { |
| 1746 | spn_ = spn; |
Prathmesh Prabhu | 8599e05 | 2014-04-25 14:20:22 -0700 | [diff] [blame] | 1747 | cellular()->home_provider_info()->UpdateOperatorName(spn); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1748 | } |
| 1749 | |
| 1750 | void CellularCapabilityUniversal::OnSimIdentifierChanged(const string &id) { |
Prathmesh Prabhu | 700ff4d | 2014-01-16 15:59:33 -0800 | [diff] [blame] | 1751 | cellular()->set_sim_identifier(id); |
Prathmesh Prabhu | 8599e05 | 2014-04-25 14:20:22 -0700 | [diff] [blame] | 1752 | cellular()->home_provider_info()->UpdateICCID(id); |
Prathmesh Prabhu | c93b6bc | 2014-07-28 15:20:11 -0700 | [diff] [blame] | 1753 | // Provide ICCID to serving operator as well to aid in MVNO identification. |
| 1754 | cellular()->serving_operator_info()->UpdateICCID(id); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 1755 | UpdatePendingActivationState(); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | void CellularCapabilityUniversal::OnOperatorIdChanged( |
| 1759 | const string &operator_id) { |
Ben Chan | 6d0d1e7 | 2012-11-06 21:19:28 -0800 | [diff] [blame] | 1760 | SLOG(Cellular, 2) << "Operator ID = '" << operator_id << "'"; |
Prathmesh Prabhu | 8599e05 | 2014-04-25 14:20:22 -0700 | [diff] [blame] | 1761 | cellular()->home_provider_info()->UpdateMCCMNC(operator_id); |
Jason Glasgow | af58328 | 2012-04-18 15:18:22 -0400 | [diff] [blame] | 1762 | } |
| 1763 | |
Thieu Le | 43ce4d4 | 2013-10-04 16:08:55 -0700 | [diff] [blame] | 1764 | OutOfCreditsDetector::OOCType |
| 1765 | CellularCapabilityUniversal::GetOutOfCreditsDetectionType() const { |
Thieu Le | c466ccb | 2014-06-23 15:24:56 -0700 | [diff] [blame] | 1766 | if (cellular()->mm_plugin() == kAltairLTEMMPlugin) { |
Thieu Le | 43ce4d4 | 2013-10-04 16:08:55 -0700 | [diff] [blame] | 1767 | return OutOfCreditsDetector::OOCTypeSubscriptionState; |
Thieu Le | 43ce4d4 | 2013-10-04 16:08:55 -0700 | [diff] [blame] | 1768 | } else { |
| 1769 | return OutOfCreditsDetector::OOCTypeNone; |
| 1770 | } |
| 1771 | } |
| 1772 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1773 | } // namespace shill |