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