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