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