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