mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [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/wifi_service.h" |
| 6 | |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 7 | #include <algorithm> |
Wade Guthrie | 9ec0806 | 2013-09-25 15:22:24 -0700 | [diff] [blame] | 8 | #include <limits> |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 9 | #include <string> |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 10 | #include <utility> |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 11 | |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 12 | #include <base/strings/stringprintf.h> |
| 13 | #include <base/strings/string_number_conversions.h> |
| 14 | #include <base/strings/string_split.h> |
| 15 | #include <base/strings/string_util.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 16 | #include <chromeos/dbus/service_constants.h> |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 17 | #include <dbus/dbus.h> |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 18 | |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 19 | #include "shill/adaptor_interfaces.h" |
Paul Stewart | 5baebb7 | 2013-03-14 11:43:29 -0700 | [diff] [blame] | 20 | #include "shill/certificate_file.h" |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 21 | #include "shill/control_interface.h" |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 22 | #include "shill/dbus_adaptor.h" |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 23 | #include "shill/device.h" |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 24 | #include "shill/eap_credentials.h" |
mukesh agrawal | 1a05626 | 2011-10-05 14:36:54 -0700 | [diff] [blame] | 25 | #include "shill/error.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 26 | #include "shill/event_dispatcher.h" |
mukesh agrawal | 1a05626 | 2011-10-05 14:36:54 -0700 | [diff] [blame] | 27 | #include "shill/ieee80211.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 28 | #include "shill/logging.h" |
Paul Stewart | 4357f4e | 2012-04-26 17:39:26 -0700 | [diff] [blame] | 29 | #include "shill/manager.h" |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 30 | #include "shill/metrics.h" |
Paul Stewart | ecf4cd1 | 2012-04-17 11:08:39 -0700 | [diff] [blame] | 31 | #include "shill/nss.h" |
Thieu Le | f770945 | 2011-11-15 01:13:19 +0000 | [diff] [blame] | 32 | #include "shill/property_accessor.h" |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 33 | #include "shill/store_interface.h" |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 34 | #include "shill/wifi.h" |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 35 | #include "shill/wifi_endpoint.h" |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 36 | #include "shill/wifi_provider.h" |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 37 | #include "shill/wpa_supplicant.h" |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 38 | |
Paul Stewart | a283e4e | 2013-10-22 20:50:14 -0700 | [diff] [blame] | 39 | using std::map; |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 40 | using std::set; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 41 | using std::string; |
mukesh agrawal | 1a05626 | 2011-10-05 14:36:54 -0700 | [diff] [blame] | 42 | using std::vector; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 43 | |
| 44 | namespace shill { |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 45 | |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 46 | const char WiFiService::kAutoConnNoEndpoint[] = "no endpoints"; |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 47 | const char WiFiService::kAnyDeviceAddress[] = "any"; |
Paul Stewart | bca08f8 | 2013-07-09 16:32:37 -0700 | [diff] [blame] | 48 | const int WiFiService::kSuspectedCredentialFailureThreshold = 3; |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 49 | |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 50 | const char WiFiService::kStorageHiddenSSID[] = "WiFi.HiddenSSID"; |
Paul Stewart | 2706aaf | 2011-12-14 16:44:04 -0800 | [diff] [blame] | 51 | const char WiFiService::kStorageMode[] = "WiFi.Mode"; |
| 52 | const char WiFiService::kStoragePassphrase[] = "Passphrase"; |
| 53 | const char WiFiService::kStorageSecurity[] = "WiFi.Security"; |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 54 | const char WiFiService::kStorageSecurityClass[] = "WiFi.SecurityClass"; |
Paul Stewart | 2706aaf | 2011-12-14 16:44:04 -0800 | [diff] [blame] | 55 | const char WiFiService::kStorageSSID[] = "SSID"; |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 56 | bool WiFiService::logged_signal_warning = false; |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 57 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 58 | WiFiService::WiFiService(ControlInterface *control_interface, |
| 59 | EventDispatcher *dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 60 | Metrics *metrics, |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 61 | Manager *manager, |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 62 | WiFiProvider *provider, |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 63 | const vector<uint8_t> &ssid, |
| 64 | const string &mode, |
| 65 | const string &security, |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 66 | bool hidden_ssid) |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 67 | : Service(control_interface, dispatcher, metrics, manager, |
| 68 | Technology::kWifi), |
Chris Masone | 7561230 | 2011-10-12 16:31:21 -0700 | [diff] [blame] | 69 | need_passphrase_(false), |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 70 | security_(security), |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 71 | mode_(mode), |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 72 | hidden_ssid_(hidden_ssid), |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 73 | frequency_(0), |
mukesh agrawal | f6b3209 | 2013-04-10 15:49:55 -0700 | [diff] [blame] | 74 | physical_mode_(Metrics::kWiFiNetworkPhyModeUndef), |
Paul Stewart | 23b393a | 2012-09-25 21:21:06 -0700 | [diff] [blame] | 75 | raw_signal_strength_(0), |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 76 | cipher_8021x_(kCryptoNone), |
Paul Stewart | bca08f8 | 2013-07-09 16:32:37 -0700 | [diff] [blame] | 77 | suspected_credential_failures_(0), |
Paul Stewart | ecf4cd1 | 2012-04-17 11:08:39 -0700 | [diff] [blame] | 78 | ssid_(ssid), |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 79 | ieee80211w_required_(false), |
Peter Qiu | 4943822 | 2014-03-14 14:21:09 -0700 | [diff] [blame] | 80 | expecting_disconnect_(false), |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 81 | nss_(NSS::GetInstance()), |
Paul Stewart | eb713e8 | 2013-06-28 14:51:54 -0700 | [diff] [blame] | 82 | certificate_file_(new CertificateFile()), |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 83 | provider_(provider) { |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 84 | PropertyStore *store = this->mutable_store(); |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 85 | store->RegisterConstString(kModeProperty, &mode_); |
| 86 | HelpRegisterWriteOnlyDerivedString(kPassphraseProperty, |
mukesh agrawal | 292dc0f | 2012-01-26 18:02:46 -0800 | [diff] [blame] | 87 | &WiFiService::SetPassphrase, |
| 88 | &WiFiService::ClearPassphrase, |
| 89 | NULL); |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 90 | store->RegisterBool(kPassphraseRequiredProperty, &need_passphrase_); |
| 91 | HelpRegisterDerivedString(kSecurityProperty, |
Paul Stewart | 6df20bd | 2013-03-13 19:31:25 -0700 | [diff] [blame] | 92 | &WiFiService::GetSecurity, |
| 93 | NULL); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 94 | |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 95 | store->RegisterConstString(kWifiAuthMode, &auth_mode_); |
| 96 | store->RegisterBool(kWifiHiddenSsid, &hidden_ssid_); |
| 97 | store->RegisterConstUint16(kWifiFrequency, &frequency_); |
mukesh agrawal | e7c7e65 | 2013-06-18 17:19:39 -0700 | [diff] [blame] | 98 | store->RegisterConstUint16s(kWifiFrequencyListProperty, &frequency_list_); |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 99 | store->RegisterConstUint16(kWifiPhyMode, &physical_mode_); |
| 100 | store->RegisterConstString(kWifiBSsid, &bssid_); |
| 101 | store->RegisterConstString(kCountryProperty, &country_code_); |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 102 | store->RegisterConstStringmap(kWifiVendorInformationProperty, |
| 103 | &vendor_information_); |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 104 | store->RegisterConstBool(kWifiProtectedManagementFrameRequiredProperty, |
| 105 | &ieee80211w_required_); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 106 | |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 107 | hex_ssid_ = base::HexEncode(ssid_.data(), ssid_.size()); |
Paul Stewart | 9d95dad | 2013-10-10 12:08:14 -0700 | [diff] [blame] | 108 | store->RegisterConstString(kWifiHexSsid, &hex_ssid_); |
| 109 | |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 110 | string ssid_string( |
| 111 | reinterpret_cast<const char *>(ssid_.data()), ssid_.size()); |
Paul Stewart | 9d95dad | 2013-10-10 12:08:14 -0700 | [diff] [blame] | 112 | WiFi::SanitizeSSID(&ssid_string); |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 113 | set_friendly_name(ssid_string); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 114 | |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 115 | SetEapCredentials(new EapCredentials()); |
| 116 | |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 117 | // TODO(quiche): determine if it is okay to set EAP.KeyManagement for |
| 118 | // a service that is not 802.1x. |
Gaurav Shah | 29d6888 | 2012-01-30 19:06:42 -0800 | [diff] [blame] | 119 | if (Is8021x()) { |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 120 | // Passphrases are not mandatory for 802.1X. |
| 121 | need_passphrase_ = false; |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 122 | } else if (security_ == kSecurityPsk) { |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 123 | SetEAPKeyManagement("WPA-PSK"); |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 124 | } else if (security_ == kSecurityRsn) { |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 125 | SetEAPKeyManagement("WPA-PSK"); |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 126 | } else if (security_ == kSecurityWpa) { |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 127 | SetEAPKeyManagement("WPA-PSK"); |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 128 | } else if (security_ == kSecurityWep) { |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 129 | SetEAPKeyManagement("NONE"); |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 130 | } else if (security_ == kSecurityNone) { |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 131 | SetEAPKeyManagement("NONE"); |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 132 | } else { |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 133 | LOG(ERROR) << "Unsupported security method " << security_; |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 136 | // Until we know better (at Profile load time), use the generic name. |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 137 | storage_identifier_ = GetDefaultStorageIdentifier(); |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 138 | UpdateConnectable(); |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 139 | UpdateSecurity(); |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 140 | |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 141 | IgnoreParameterForConfigure(kModeProperty); |
| 142 | IgnoreParameterForConfigure(kSSIDProperty); |
| 143 | IgnoreParameterForConfigure(kSecurityProperty); |
Paul Stewart | 4539d26 | 2013-10-10 12:56:31 -0700 | [diff] [blame] | 144 | IgnoreParameterForConfigure(kWifiHexSsid); |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 145 | |
mukesh agrawal | 6cfe53f | 2013-08-13 13:39:01 -0700 | [diff] [blame] | 146 | InitializeCustomMetrics(); |
| 147 | |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 148 | // Log the |unique_name| to |friendly_name| mapping for debugging purposes. |
| 149 | // The latter will be tagged for scrubbing. |
| 150 | LOG(INFO) << "Constructed WiFi service " << unique_name() |
| 151 | << " name: " << WiFi::LogSSID(friendly_name()); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Darin Petkov | 9cd7ca1 | 2012-07-03 11:06:40 +0200 | [diff] [blame] | 154 | WiFiService::~WiFiService() {} |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 155 | |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 156 | bool WiFiService::IsAutoConnectable(const char **reason) const { |
| 157 | if (!Service::IsAutoConnectable(reason)) { |
| 158 | return false; |
| 159 | } |
| 160 | |
| 161 | // Only auto-connect to Services which have visible Endpoints. |
| 162 | // (Needed because hidden Services may remain registered with |
| 163 | // Manager even without visible Endpoints.) |
| 164 | if (!HasEndpoints()) { |
| 165 | *reason = kAutoConnNoEndpoint; |
| 166 | return false; |
| 167 | } |
| 168 | |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 169 | CHECK(wifi_) << "We have endpoints but no WiFi device is selected?"; |
| 170 | |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 171 | // Do not preempt an existing connection (whether pending, or |
| 172 | // connected, and whether to this service, or another). |
| 173 | if (!wifi_->IsIdle()) { |
| 174 | *reason = kAutoConnBusy; |
| 175 | return false; |
| 176 | } |
| 177 | |
| 178 | return true; |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 179 | } |
| 180 | |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 181 | void WiFiService::SetEAPKeyManagement(const string &key_management) { |
| 182 | Service::SetEAPKeyManagement(key_management); |
| 183 | UpdateSecurity(); |
| 184 | } |
| 185 | |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 186 | void WiFiService::AddEndpoint(const WiFiEndpointConstRefPtr &endpoint) { |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 187 | DCHECK(endpoint->ssid() == ssid()); |
| 188 | endpoints_.insert(endpoint); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 189 | UpdateFromEndpoints(); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 192 | void WiFiService::RemoveEndpoint(const WiFiEndpointConstRefPtr &endpoint) { |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 193 | set<WiFiEndpointConstRefPtr>::iterator i = endpoints_.find(endpoint); |
| 194 | DCHECK(i != endpoints_.end()); |
| 195 | if (i == endpoints_.end()) { |
| 196 | LOG(WARNING) << "In " << __func__ << "(): " |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 197 | << "ignoring non-existent endpoint " |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 198 | << endpoint->bssid_string(); |
| 199 | return; |
| 200 | } |
| 201 | endpoints_.erase(i); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 202 | if (current_endpoint_ == endpoint) { |
| 203 | current_endpoint_ = NULL; |
| 204 | } |
| 205 | UpdateFromEndpoints(); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 208 | void WiFiService::NotifyCurrentEndpoint( |
| 209 | const WiFiEndpointConstRefPtr &endpoint) { |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 210 | DCHECK(!endpoint || (endpoints_.find(endpoint) != endpoints_.end())); |
| 211 | current_endpoint_ = endpoint; |
| 212 | UpdateFromEndpoints(); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 215 | void WiFiService::NotifyEndpointUpdated( |
| 216 | const WiFiEndpointConstRefPtr &endpoint) { |
| 217 | DCHECK(endpoints_.find(endpoint) != endpoints_.end()); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 218 | UpdateFromEndpoints(); |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 219 | } |
| 220 | |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 221 | string WiFiService::GetStorageIdentifier() const { |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 222 | return storage_identifier_; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 223 | } |
mukesh agrawal | 445e72c | 2011-06-22 11:13:50 -0700 | [diff] [blame] | 224 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 225 | bool WiFiService::SetPassphrase(const string &passphrase, Error *error) { |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 226 | if (security_ == kSecurityWep) { |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 227 | ValidateWEPPassphrase(passphrase, error); |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 228 | } else if (security_ == kSecurityPsk || |
| 229 | security_ == kSecurityWpa || |
| 230 | security_ == kSecurityRsn) { |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 231 | ValidateWPAPassphrase(passphrase, error); |
| 232 | } else { |
| 233 | error->Populate(Error::kNotSupported); |
mukesh agrawal | 1a05626 | 2011-10-05 14:36:54 -0700 | [diff] [blame] | 234 | } |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 235 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 236 | if (!error->IsSuccess()) { |
| 237 | return false; |
| 238 | } |
| 239 | if (passphrase_ == passphrase) { |
| 240 | // After a user logs in, Chrome may reconfigure a Service with the |
| 241 | // same credentials as before login. When that occurs, we don't |
| 242 | // want to bump the user off the network. Hence, we MUST return |
| 243 | // early. (See crbug.com/231456#c17) |
| 244 | return false; |
Paul Stewart | 2706aaf | 2011-12-14 16:44:04 -0800 | [diff] [blame] | 245 | } |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 246 | |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 247 | passphrase_ = passphrase; |
| 248 | ClearCachedCredentials(); |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 249 | UpdateConnectable(); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 250 | return true; |
mukesh agrawal | 1a05626 | 2011-10-05 14:36:54 -0700 | [diff] [blame] | 251 | } |
| 252 | |
mukesh agrawal | 292dc0f | 2012-01-26 18:02:46 -0800 | [diff] [blame] | 253 | // ClearPassphrase is separate from SetPassphrase, because the default |
| 254 | // value for |passphrase_| would not pass validation. |
| 255 | void WiFiService::ClearPassphrase(Error */*error*/) { |
| 256 | passphrase_.clear(); |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 257 | ClearCachedCredentials(); |
mukesh agrawal | 292dc0f | 2012-01-26 18:02:46 -0800 | [diff] [blame] | 258 | UpdateConnectable(); |
| 259 | } |
| 260 | |
Paul Stewart | fa11e28 | 2013-12-02 22:04:25 -0800 | [diff] [blame] | 261 | string WiFiService::GetTethering(Error */*error*/) const { |
| 262 | if (IsConnected() && wifi_ && wifi_->IsConnectedViaTether()) { |
| 263 | return kTetheringConfirmedState; |
| 264 | } |
| 265 | |
| 266 | // Only perform BSSID tests if there is exactly one matching endpoint, |
| 267 | // so we ignore campuses that may use locally administered BSSIDs. |
Paul Stewart | 7f5d9c0 | 2013-12-03 18:26:00 -0800 | [diff] [blame] | 268 | if (endpoints_.size() == 1 && |
Paul Stewart | fa11e28 | 2013-12-02 22:04:25 -0800 | [diff] [blame] | 269 | (*endpoints_.begin())->has_tethering_signature()) { |
| 270 | return kTetheringSuspectedState; |
| 271 | } |
| 272 | |
| 273 | return kTetheringNotDetectedState; |
| 274 | } |
| 275 | |
Paul Stewart | e7de294 | 2013-04-25 17:07:31 -0700 | [diff] [blame] | 276 | string WiFiService::GetLoadableStorageIdentifier( |
| 277 | const StoreInterface &storage) const { |
| 278 | set<string> groups = storage.GetGroupsWithProperties(GetStorageProperties()); |
| 279 | if (groups.empty()) { |
| 280 | LOG(WARNING) << "Configuration for service " |
| 281 | << unique_name() |
| 282 | << " is not available in the persistent store"; |
| 283 | return ""; |
| 284 | } |
| 285 | if (groups.size() > 1) { |
| 286 | LOG(WARNING) << "More than one configuration for service " |
| 287 | << unique_name() |
| 288 | << " is available; choosing the first."; |
| 289 | } |
| 290 | return *groups.begin(); |
| 291 | } |
| 292 | |
| 293 | bool WiFiService::IsLoadableFrom(const StoreInterface &storage) const { |
| 294 | return !storage.GetGroupsWithProperties(GetStorageProperties()).empty(); |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 297 | bool WiFiService::IsVisible() const { |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 298 | // WiFi Services should be displayed only if they are in range (have |
| 299 | // endpoints that have shown up in a scan) or if the service is actively |
| 300 | // being connected. |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 301 | return HasEndpoints() || IsConnected() || IsConnecting(); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 302 | } |
| 303 | |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 304 | bool WiFiService::Load(StoreInterface *storage) { |
Paul Stewart | e7de294 | 2013-04-25 17:07:31 -0700 | [diff] [blame] | 305 | string id = GetLoadableStorageIdentifier(*storage); |
| 306 | if (id.empty()) { |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 307 | return false; |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | // Set our storage identifier to match the storage name in the Profile. |
| 311 | storage_identifier_ = id; |
| 312 | |
| 313 | // Load properties common to all Services. |
| 314 | if (!Service::Load(storage)) { |
| 315 | return false; |
| 316 | } |
| 317 | |
| 318 | // Load properties specific to WiFi services. |
| 319 | storage->GetBool(id, kStorageHiddenSSID, &hidden_ssid_); |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 320 | |
Paul Stewart | 2706aaf | 2011-12-14 16:44:04 -0800 | [diff] [blame] | 321 | // NB: mode, security and ssid parameters are never read in from |
| 322 | // Load() as they are provided from the scan. |
| 323 | |
| 324 | string passphrase; |
| 325 | if (storage->GetCryptedString(id, kStoragePassphrase, &passphrase)) { |
| 326 | Error error; |
| 327 | SetPassphrase(passphrase, &error); |
Paul Stewart | fa013ab | 2013-04-11 07:12:03 -0700 | [diff] [blame] | 328 | if (!error.IsSuccess() && |
| 329 | !(passphrase.empty() && error.type() == Error::kNotSupported)) { |
Paul Stewart | 71b9ed5 | 2014-01-29 08:53:06 -0800 | [diff] [blame] | 330 | LOG(ERROR) << "Passphrase could not be set: " << error; |
Paul Stewart | 2706aaf | 2011-12-14 16:44:04 -0800 | [diff] [blame] | 331 | } |
| 332 | } |
| 333 | |
Peter Qiu | 4943822 | 2014-03-14 14:21:09 -0700 | [diff] [blame] | 334 | expecting_disconnect_ = false; |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 335 | return true; |
| 336 | } |
| 337 | |
| 338 | bool WiFiService::Save(StoreInterface *storage) { |
| 339 | // Save properties common to all Services. |
| 340 | if (!Service::Save(storage)) { |
| 341 | return false; |
| 342 | } |
| 343 | |
| 344 | // Save properties specific to WiFi services. |
| 345 | const string id = GetStorageIdentifier(); |
Paul Stewart | 2706aaf | 2011-12-14 16:44:04 -0800 | [diff] [blame] | 346 | storage->SetBool(id, kStorageHiddenSSID, hidden_ssid_); |
| 347 | storage->SetString(id, kStorageMode, mode_); |
| 348 | storage->SetCryptedString(id, kStoragePassphrase, passphrase_); |
| 349 | storage->SetString(id, kStorageSecurity, security_); |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 350 | storage->SetString(id, kStorageSecurityClass, GetSecurityClass(security_)); |
Paul Stewart | 2706aaf | 2011-12-14 16:44:04 -0800 | [diff] [blame] | 351 | storage->SetString(id, kStorageSSID, hex_ssid_); |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 352 | |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 353 | return true; |
| 354 | } |
| 355 | |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 356 | bool WiFiService::Unload() { |
Peter Qiu | 91b461f | 2014-03-26 10:19:45 -0700 | [diff] [blame] | 357 | // Expect the service to be disconnected if is currently connected or |
| 358 | // in the process of connecting. |
| 359 | if (IsConnected() || IsConnecting()) { |
| 360 | expecting_disconnect_ = true; |
| 361 | } else { |
| 362 | expecting_disconnect_ = false; |
| 363 | } |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 364 | Service::Unload(); |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 365 | if (wifi_) { |
| 366 | wifi_->DestroyServiceLease(*this); |
| 367 | } |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 368 | hidden_ssid_ = false; |
Paul Stewart | bca08f8 | 2013-07-09 16:32:37 -0700 | [diff] [blame] | 369 | ResetSuspectedCredentialFailures(); |
Wade Guthrie | 005bd34 | 2012-05-02 09:37:07 -0700 | [diff] [blame] | 370 | Error unused_error; |
| 371 | ClearPassphrase(&unused_error); |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 372 | return provider_->OnServiceUnloaded(this); |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 373 | } |
| 374 | |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 375 | bool WiFiService::IsSecurityMatch(const string &security) const { |
| 376 | return GetSecurityClass(security) == GetSecurityClass(security_); |
| 377 | } |
| 378 | |
Paul Stewart | bca08f8 | 2013-07-09 16:32:37 -0700 | [diff] [blame] | 379 | bool WiFiService::AddSuspectedCredentialFailure() { |
| 380 | if (!has_ever_connected()) { |
| 381 | return true; |
| 382 | } |
| 383 | ++suspected_credential_failures_; |
| 384 | return suspected_credential_failures_ >= kSuspectedCredentialFailureThreshold; |
| 385 | } |
| 386 | |
| 387 | void WiFiService::ResetSuspectedCredentialFailures() { |
| 388 | suspected_credential_failures_ = 0; |
| 389 | } |
| 390 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 391 | void WiFiService::InitializeCustomMetrics() const { |
mukesh agrawal | 6cfe53f | 2013-08-13 13:39:01 -0700 | [diff] [blame] | 392 | SLOG(Metrics, 2) << __func__ << " for " << unique_name(); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 393 | string histogram = metrics()->GetFullMetricName( |
mukesh agrawal | 132e96f | 2014-04-24 11:49:42 -0700 | [diff] [blame] | 394 | Metrics::kMetricTimeToJoinMillisecondsSuffix, |
mukesh agrawal | 6cfe53f | 2013-08-13 13:39:01 -0700 | [diff] [blame] | 395 | technology()); |
Wade Guthrie | 7ac610b | 2013-10-01 17:48:14 -0700 | [diff] [blame] | 396 | metrics()->AddServiceStateTransitionTimer(*this, |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 397 | histogram, |
| 398 | Service::kStateAssociating, |
| 399 | Service::kStateConfiguring); |
| 400 | } |
| 401 | |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 402 | void WiFiService::SendPostReadyStateMetrics( |
| 403 | int64 time_resume_to_ready_milliseconds) const { |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 404 | metrics()->SendEnumToUMA( |
mukesh agrawal | 132e96f | 2014-04-24 11:49:42 -0700 | [diff] [blame] | 405 | metrics()->GetFullMetricName(Metrics::kMetricNetworkChannelSuffix, |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 406 | technology()), |
| 407 | Metrics::WiFiFrequencyToChannel(frequency_), |
| 408 | Metrics::kMetricNetworkChannelMax); |
Thieu Le | ad1ec2c | 2012-01-05 23:39:48 +0000 | [diff] [blame] | 409 | |
| 410 | DCHECK(physical_mode_ < Metrics::kWiFiNetworkPhyModeMax); |
| 411 | metrics()->SendEnumToUMA( |
mukesh agrawal | 132e96f | 2014-04-24 11:49:42 -0700 | [diff] [blame] | 412 | metrics()->GetFullMetricName(Metrics::kMetricNetworkPhyModeSuffix, |
Thieu Le | ad1ec2c | 2012-01-05 23:39:48 +0000 | [diff] [blame] | 413 | technology()), |
| 414 | static_cast<Metrics::WiFiNetworkPhyMode>(physical_mode_), |
| 415 | Metrics::kWiFiNetworkPhyModeMax); |
| 416 | |
Paul Stewart | 4108db9 | 2013-03-11 12:13:24 -0700 | [diff] [blame] | 417 | string security_mode = security_; |
| 418 | if (current_endpoint_) { |
| 419 | security_mode = current_endpoint_->security_mode(); |
| 420 | } |
Thieu Le | ad1ec2c | 2012-01-05 23:39:48 +0000 | [diff] [blame] | 421 | Metrics::WiFiSecurity security_uma = |
Paul Stewart | 4108db9 | 2013-03-11 12:13:24 -0700 | [diff] [blame] | 422 | Metrics::WiFiSecurityStringToEnum(security_mode); |
Thieu Le | ad1ec2c | 2012-01-05 23:39:48 +0000 | [diff] [blame] | 423 | DCHECK(security_uma != Metrics::kWiFiSecurityUnknown); |
| 424 | metrics()->SendEnumToUMA( |
mukesh agrawal | 132e96f | 2014-04-24 11:49:42 -0700 | [diff] [blame] | 425 | metrics()->GetFullMetricName(Metrics::kMetricNetworkSecuritySuffix, |
Thieu Le | ad1ec2c | 2012-01-05 23:39:48 +0000 | [diff] [blame] | 426 | technology()), |
| 427 | security_uma, |
| 428 | Metrics::kMetricNetworkSecurityMax); |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 429 | |
Paul Stewart | 21f4096 | 2013-03-01 14:27:28 -0800 | [diff] [blame] | 430 | if (Is8021x()) { |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 431 | eap()->OutputConnectionMetrics(metrics(), technology()); |
Paul Stewart | 21f4096 | 2013-03-01 14:27:28 -0800 | [diff] [blame] | 432 | } |
| 433 | |
Paul Stewart | 23b393a | 2012-09-25 21:21:06 -0700 | [diff] [blame] | 434 | // We invert the sign of the signal strength value, since UMA histograms |
| 435 | // cannot represent negative numbers (it stores them but cannot display |
| 436 | // them), and dBm values of interest start at 0 and go negative from there. |
| 437 | metrics()->SendToUMA( |
mukesh agrawal | 132e96f | 2014-04-24 11:49:42 -0700 | [diff] [blame] | 438 | metrics()->GetFullMetricName(Metrics::kMetricNetworkSignalStrengthSuffix, |
Paul Stewart | 23b393a | 2012-09-25 21:21:06 -0700 | [diff] [blame] | 439 | technology()), |
| 440 | -raw_signal_strength_, |
| 441 | Metrics::kMetricNetworkSignalStrengthMin, |
| 442 | Metrics::kMetricNetworkSignalStrengthMax, |
| 443 | Metrics::kMetricNetworkSignalStrengthNumBuckets); |
| 444 | |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 445 | if (time_resume_to_ready_milliseconds > 0) { |
| 446 | metrics()->SendToUMA( |
| 447 | metrics()->GetFullMetricName( |
mukesh agrawal | 132e96f | 2014-04-24 11:49:42 -0700 | [diff] [blame] | 448 | Metrics::kMetricTimeResumeToReadyMillisecondsSuffix, technology()), |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 449 | time_resume_to_ready_milliseconds, |
| 450 | Metrics::kTimerHistogramMillisecondsMin, |
| 451 | Metrics::kTimerHistogramMillisecondsMax, |
| 452 | Metrics::kTimerHistogramNumBuckets); |
| 453 | } |
Paul Stewart | e4cedde | 2013-07-17 08:56:44 -0700 | [diff] [blame] | 454 | |
| 455 | Metrics::WiFiApMode ap_mode_uma = Metrics::WiFiApModeStringToEnum(mode_); |
| 456 | metrics()->SendEnumToUMA( |
mukesh agrawal | 132e96f | 2014-04-24 11:49:42 -0700 | [diff] [blame] | 457 | metrics()->GetFullMetricName(Metrics::kMetricNetworkApModeSuffix, |
| 458 | technology()), |
Paul Stewart | e4cedde | 2013-07-17 08:56:44 -0700 | [diff] [blame] | 459 | ap_mode_uma, |
| 460 | Metrics::kWiFiApModeMax); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 461 | } |
| 462 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 463 | // private methods |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 464 | void WiFiService::HelpRegisterConstDerivedString( |
| 465 | const string &name, |
| 466 | string(WiFiService::*get)(Error *)) { |
| 467 | mutable_store()->RegisterDerivedString( |
| 468 | name, |
| 469 | StringAccessor( |
| 470 | new CustomAccessor<WiFiService, string>(this, get, NULL))); |
| 471 | } |
| 472 | |
Paul Stewart | 6df20bd | 2013-03-13 19:31:25 -0700 | [diff] [blame] | 473 | void WiFiService::HelpRegisterDerivedString( |
| 474 | const string &name, |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 475 | string(WiFiService::*get)(Error *error), |
| 476 | bool(WiFiService::*set)(const string &, Error *)) { |
Paul Stewart | 6df20bd | 2013-03-13 19:31:25 -0700 | [diff] [blame] | 477 | mutable_store()->RegisterDerivedString( |
| 478 | name, |
| 479 | StringAccessor(new CustomAccessor<WiFiService, string>(this, get, set))); |
| 480 | } |
| 481 | |
mukesh agrawal | 292dc0f | 2012-01-26 18:02:46 -0800 | [diff] [blame] | 482 | void WiFiService::HelpRegisterWriteOnlyDerivedString( |
| 483 | const string &name, |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 484 | bool(WiFiService::*set)(const string &, Error *), |
mukesh agrawal | 292dc0f | 2012-01-26 18:02:46 -0800 | [diff] [blame] | 485 | void(WiFiService::*clear)(Error *), |
| 486 | const string *default_value) { |
| 487 | mutable_store()->RegisterDerivedString( |
Thieu Le | f770945 | 2011-11-15 01:13:19 +0000 | [diff] [blame] | 488 | name, |
mukesh agrawal | 292dc0f | 2012-01-26 18:02:46 -0800 | [diff] [blame] | 489 | StringAccessor( |
| 490 | new CustomWriteOnlyAccessor<WiFiService, string>( |
| 491 | this, set, clear, default_value))); |
Thieu Le | f770945 | 2011-11-15 01:13:19 +0000 | [diff] [blame] | 492 | } |
| 493 | |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 494 | void WiFiService::Connect(Error *error, const char *reason) { |
Wade Guthrie | 005bd34 | 2012-05-02 09:37:07 -0700 | [diff] [blame] | 495 | if (!connectable()) { |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 496 | LOG(ERROR) << "Can't connect. Service " << unique_name() |
| 497 | << " is not connectable."; |
Christopher Wiley | 1ce658d | 2012-10-10 10:02:03 -0700 | [diff] [blame] | 498 | Error::PopulateAndLog(error, |
| 499 | Error::kOperationFailed, |
| 500 | Error::GetDefaultMessage(Error::kOperationFailed)); |
| 501 | return; |
| 502 | } |
| 503 | if (IsConnecting() || IsConnected()) { |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 504 | LOG(WARNING) << "Can't connect. Service " << unique_name() |
Christopher Wiley | 1ce658d | 2012-10-10 10:02:03 -0700 | [diff] [blame] | 505 | << " is already connecting or connected."; |
| 506 | Error::PopulateAndLog(error, |
| 507 | Error::kAlreadyConnected, |
| 508 | Error::GetDefaultMessage(Error::kAlreadyConnected)); |
Wade Guthrie | 005bd34 | 2012-05-02 09:37:07 -0700 | [diff] [blame] | 509 | return; |
| 510 | } |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 511 | |
| 512 | WiFiRefPtr wifi = wifi_; |
| 513 | if (!wifi) { |
| 514 | // If this is a hidden service before it has been found in a scan, we |
| 515 | // may need to late-bind to any available WiFi Device. We don't actually |
Wade Guthrie | 9ec0806 | 2013-09-25 15:22:24 -0700 | [diff] [blame] | 516 | // set |wifi_| in this case since we do not yet see any endpoints. This |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 517 | // will mean this service is not disconnectable until an endpoint is |
| 518 | // found. |
| 519 | wifi = ChooseDevice(); |
| 520 | if (!wifi) { |
| 521 | LOG(ERROR) << "Can't connect. Service " << unique_name() |
| 522 | << " cannot find a WiFi device."; |
| 523 | Error::PopulateAndLog(error, |
| 524 | Error::kOperationFailed, |
| 525 | Error::GetDefaultMessage(Error::kOperationFailed)); |
| 526 | return; |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | if (wifi->IsCurrentService(this)) { |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 531 | LOG(WARNING) << "Can't connect. Service " << unique_name() |
Wade Guthrie | 8bc5088 | 2012-10-31 16:23:20 -0700 | [diff] [blame] | 532 | << " is the current service (but, in " << GetStateString() |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 533 | << " state, not connected)."; |
Wade Guthrie | 8bc5088 | 2012-10-31 16:23:20 -0700 | [diff] [blame] | 534 | Error::PopulateAndLog(error, |
| 535 | Error::kInProgress, |
| 536 | Error::GetDefaultMessage(Error::kInProgress)); |
| 537 | return; |
| 538 | } |
Wade Guthrie | 005bd34 | 2012-05-02 09:37:07 -0700 | [diff] [blame] | 539 | |
Peter Qiu | 574996a | 2014-04-04 10:55:47 -0700 | [diff] [blame] | 540 | // Report number of BSSes available for this service. |
| 541 | metrics()->NotifyWifiAvailableBSSes(endpoints_.size()); |
| 542 | |
Paul Stewart | a283e4e | 2013-10-22 20:50:14 -0700 | [diff] [blame] | 543 | if (Is8021x()) { |
| 544 | // If EAP key management is not set, set to a default. |
| 545 | if (GetEAPKeyManagement().empty()) |
| 546 | SetEAPKeyManagement("WPA-EAP"); |
| 547 | ClearEAPCertification(); |
| 548 | } |
| 549 | |
Peter Qiu | 4943822 | 2014-03-14 14:21:09 -0700 | [diff] [blame] | 550 | expecting_disconnect_ = false; |
Paul Stewart | a283e4e | 2013-10-22 20:50:14 -0700 | [diff] [blame] | 551 | Service::Connect(error, reason); |
| 552 | wifi->ConnectTo(this); |
| 553 | } |
| 554 | |
| 555 | DBusPropertiesMap WiFiService::GetSupplicantConfigurationParameters() const { |
| 556 | DBusPropertiesMap params; |
| 557 | DBus::MessageIter writer; |
| 558 | |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 559 | params[WPASupplicant::kNetworkPropertyMode].writer(). |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 560 | append_uint32(WiFiEndpoint::ModeStringToUint(mode_)); |
| 561 | |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 562 | if (mode_ == kModeAdhoc && frequency_ != 0) { |
Wade Guthrie | 9ec0806 | 2013-09-25 15:22:24 -0700 | [diff] [blame] | 563 | // Frequency is required in order to successfully connect to an IBSS |
Paul Stewart | e2d7c50 | 2012-07-16 16:35:10 -0700 | [diff] [blame] | 564 | // with wpa_supplicant. If we have one from our endpoint, insert it |
| 565 | // here. |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 566 | params[WPASupplicant::kNetworkPropertyFrequency].writer(). |
Paul Stewart | e2d7c50 | 2012-07-16 16:35:10 -0700 | [diff] [blame] | 567 | append_int32(frequency_); |
| 568 | } |
| 569 | |
Gaurav Shah | 29d6888 | 2012-01-30 19:06:42 -0800 | [diff] [blame] | 570 | if (Is8021x()) { |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 571 | vector<char> nss_identifier(ssid_.begin(), ssid_.end()); |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 572 | eap()->PopulateSupplicantProperties( |
| 573 | certificate_file_.get(), nss_, nss_identifier, ¶ms); |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 574 | } else if (security_ == kSecurityPsk || |
| 575 | security_ == kSecurityRsn || |
| 576 | security_ == kSecurityWpa) { |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 577 | const string psk_proto = |
| 578 | base::StringPrintf("%s %s", |
| 579 | WPASupplicant::kSecurityModeWPA, |
| 580 | WPASupplicant::kSecurityModeRSN); |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 581 | params[WPASupplicant::kPropertySecurityProtocol].writer(). |
Gaurav Shah | f8721ee | 2011-11-07 09:12:46 -0800 | [diff] [blame] | 582 | append_string(psk_proto.c_str()); |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 583 | params[WPASupplicant::kPropertyPreSharedKey].writer(). |
Gaurav Shah | f8721ee | 2011-11-07 09:12:46 -0800 | [diff] [blame] | 584 | append_string(passphrase_.c_str()); |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 585 | } else if (security_ == kSecurityWep) { |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 586 | params[WPASupplicant::kPropertyAuthAlg].writer(). |
| 587 | append_string(WPASupplicant::kSecurityAuthAlg); |
Paul Stewart | a283e4e | 2013-10-22 20:50:14 -0700 | [diff] [blame] | 588 | Error unused_error; |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 589 | int key_index; |
| 590 | std::vector<uint8> password_bytes; |
Paul Stewart | a283e4e | 2013-10-22 20:50:14 -0700 | [diff] [blame] | 591 | ParseWEPPassphrase(passphrase_, &key_index, &password_bytes, &unused_error); |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 592 | writer = params[WPASupplicant::kPropertyWEPKey + |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 593 | base::IntToString(key_index)].writer(); |
| 594 | writer << password_bytes; |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 595 | params[WPASupplicant::kPropertyWEPTxKeyIndex].writer(). |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 596 | append_uint32(key_index); |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 597 | } else if (security_ == kSecurityNone) { |
Gaurav Shah | f8721ee | 2011-11-07 09:12:46 -0800 | [diff] [blame] | 598 | // Nothing special to do here. |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 599 | } else { |
Paul Stewart | a283e4e | 2013-10-22 20:50:14 -0700 | [diff] [blame] | 600 | NOTIMPLEMENTED() << "Unsupported security method " << security_; |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 601 | } |
| 602 | |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 603 | params[WPASupplicant::kNetworkPropertyEapKeyManagement].writer(). |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 604 | append_string(key_management().c_str()); |
Gaurav Shah | 7ad8e53 | 2011-11-11 17:14:49 -0800 | [diff] [blame] | 605 | |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 606 | if (ieee80211w_required_) { |
| 607 | // TODO(pstew): We should also enable IEEE 802.11w if the user |
| 608 | // explicitly enables support for this through a service / device |
Paul Stewart | ee6b3d7 | 2013-07-12 16:07:51 -0700 | [diff] [blame] | 609 | // property. crbug.com/219950 |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 610 | params[WPASupplicant::kNetworkPropertyIeee80211w].writer(). |
| 611 | append_uint32(WPASupplicant::kNetworkIeee80211wEnabled); |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 612 | } |
| 613 | |
Gaurav Shah | 7ad8e53 | 2011-11-11 17:14:49 -0800 | [diff] [blame] | 614 | // See note in dbus_adaptor.cc on why we need to use a local. |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 615 | writer = params[WPASupplicant::kNetworkPropertySSID].writer(); |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 616 | writer << ssid_; |
| 617 | |
Paul Stewart | a283e4e | 2013-10-22 20:50:14 -0700 | [diff] [blame] | 618 | return params; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Paul Stewart | a283e4e | 2013-10-22 20:50:14 -0700 | [diff] [blame] | 621 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 622 | void WiFiService::Disconnect(Error *error) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 623 | Service::Disconnect(error); |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 624 | if (!wifi_) { |
| 625 | // If we are connecting to a hidden service, but have not yet found |
| 626 | // any endpoints, we could end up with a disconnect request without |
| 627 | // a wifi_ reference. This is not a fatal error. |
| 628 | LOG_IF(ERROR, IsConnecting()) |
| 629 | << "WiFi endpoints do not (yet) exist. Cannot disconnect service " |
| 630 | << unique_name(); |
| 631 | LOG_IF(FATAL, IsConnected()) |
| 632 | << "WiFi device does not exist. Cannot disconnect service " |
| 633 | << unique_name(); |
| 634 | error->Populate(Error::kOperationFailed); |
| 635 | return; |
| 636 | } |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 637 | wifi_->DisconnectFrom(this); |
| 638 | } |
| 639 | |
Paul Stewart | 1cf7eb8 | 2013-12-03 19:34:36 -0800 | [diff] [blame] | 640 | string WiFiService::GetDeviceRpcId(Error *error) const { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 641 | if (!wifi_) { |
| 642 | error->Populate(Error::kNotFound, "Not associated with a device"); |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 643 | return DBusAdaptor::kNullPath; |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 644 | } |
Chris Masone | 95207da | 2011-06-29 16:50:49 -0700 | [diff] [blame] | 645 | return wifi_->GetRpcIdentifier(); |
| 646 | } |
| 647 | |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 648 | void WiFiService::UpdateConnectable() { |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 649 | bool is_connectable = false; |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 650 | if (security_ == kSecurityNone) { |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 651 | DCHECK(passphrase_.empty()); |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 652 | need_passphrase_ = false; |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 653 | is_connectable = true; |
Gaurav Shah | 29d6888 | 2012-01-30 19:06:42 -0800 | [diff] [blame] | 654 | } else if (Is8021x()) { |
| 655 | is_connectable = Is8021xConnectable(); |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 656 | } else if (security_ == kSecurityWep || |
| 657 | security_ == kSecurityWpa || |
| 658 | security_ == kSecurityPsk || |
| 659 | security_ == kSecurityRsn) { |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 660 | need_passphrase_ = passphrase_.empty(); |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 661 | is_connectable = !need_passphrase_; |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 662 | } |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 663 | SetConnectable(is_connectable); |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 664 | } |
| 665 | |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 666 | void WiFiService::UpdateFromEndpoints() { |
| 667 | const WiFiEndpoint *representative_endpoint = NULL; |
| 668 | |
| 669 | if (current_endpoint_) { |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 670 | representative_endpoint = current_endpoint_; |
| 671 | } else { |
| 672 | int16 best_signal = std::numeric_limits<int16>::min(); |
Paul Stewart | 6db7b24 | 2014-05-02 15:34:21 -0700 | [diff] [blame^] | 673 | for (const auto &endpoint : endpoints_) { |
| 674 | if (endpoint->signal_strength() >= best_signal) { |
| 675 | best_signal = endpoint->signal_strength(); |
| 676 | representative_endpoint = endpoint; |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | } |
| 680 | |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 681 | WiFiRefPtr wifi; |
| 682 | if (representative_endpoint) { |
| 683 | wifi = representative_endpoint->device(); |
Paul Stewart | 8653f46 | 2013-02-06 12:21:05 -0800 | [diff] [blame] | 684 | } else if (IsConnected() || IsConnecting()) { |
| 685 | LOG(WARNING) << "Service " << unique_name() |
| 686 | << " will disconnect due to no remaining endpoints."; |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | SetWiFi(wifi); |
| 690 | |
Paul Stewart | 6db7b24 | 2014-05-02 15:34:21 -0700 | [diff] [blame^] | 691 | for (const auto &endpoint : endpoints_) { |
| 692 | if (endpoint->ieee80211w_required()) { |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 693 | // Never reset ieee80211w_required_ to false, so we track whether we have |
| 694 | // ever seen an AP that requires 802.11w. |
| 695 | ieee80211w_required_ = true; |
| 696 | } |
| 697 | } |
| 698 | |
mukesh agrawal | e7c7e65 | 2013-06-18 17:19:39 -0700 | [diff] [blame] | 699 | set<uint16> frequency_set; |
| 700 | for (const auto &endpoint : endpoints_) { |
| 701 | frequency_set.insert(endpoint->frequency()); |
| 702 | } |
| 703 | frequency_list_.assign(frequency_set.begin(), frequency_set.end()); |
| 704 | |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 705 | if (Is8021x()) |
| 706 | cipher_8021x_ = ComputeCipher8021x(endpoints_); |
| 707 | |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 708 | uint16 frequency = 0; |
| 709 | int16 signal = std::numeric_limits<int16>::min(); |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 710 | string bssid; |
Paul Stewart | bdbd3c3 | 2013-04-17 09:47:21 -0700 | [diff] [blame] | 711 | string country_code; |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 712 | Stringmap vendor_information; |
mukesh agrawal | f6b3209 | 2013-04-10 15:49:55 -0700 | [diff] [blame] | 713 | uint16 physical_mode = Metrics::kWiFiNetworkPhyModeUndef; |
Paul Stewart | 23b393a | 2012-09-25 21:21:06 -0700 | [diff] [blame] | 714 | // Represent "unknown raw signal strength" as 0. |
| 715 | raw_signal_strength_ = 0; |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 716 | if (representative_endpoint) { |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 717 | frequency = representative_endpoint->frequency(); |
| 718 | signal = representative_endpoint->signal_strength(); |
Paul Stewart | 23b393a | 2012-09-25 21:21:06 -0700 | [diff] [blame] | 719 | raw_signal_strength_ = signal; |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 720 | bssid = representative_endpoint->bssid_string(); |
Paul Stewart | bdbd3c3 | 2013-04-17 09:47:21 -0700 | [diff] [blame] | 721 | country_code = representative_endpoint->country_code(); |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 722 | vendor_information = representative_endpoint->GetVendorInformation(); |
mukesh agrawal | f6b3209 | 2013-04-10 15:49:55 -0700 | [diff] [blame] | 723 | physical_mode = representative_endpoint->physical_mode(); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | if (frequency_ != frequency) { |
| 727 | frequency_ = frequency; |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 728 | adaptor()->EmitUint16Changed(kWifiFrequency, frequency_); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 729 | } |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 730 | if (bssid_ != bssid) { |
| 731 | bssid_ = bssid; |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 732 | adaptor()->EmitStringChanged(kWifiBSsid, bssid_); |
mukesh agrawal | 923f14f | 2012-06-04 16:46:08 -0700 | [diff] [blame] | 733 | } |
Paul Stewart | bdbd3c3 | 2013-04-17 09:47:21 -0700 | [diff] [blame] | 734 | if (country_code_ != country_code) { |
| 735 | country_code_ = country_code; |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 736 | adaptor()->EmitStringChanged(kCountryProperty, country_code_); |
Paul Stewart | bdbd3c3 | 2013-04-17 09:47:21 -0700 | [diff] [blame] | 737 | } |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 738 | if (vendor_information_ != vendor_information) { |
| 739 | vendor_information_ = vendor_information; |
| 740 | adaptor()->EmitStringmapChanged(kWifiVendorInformationProperty, |
| 741 | vendor_information_); |
| 742 | } |
mukesh agrawal | f6b3209 | 2013-04-10 15:49:55 -0700 | [diff] [blame] | 743 | if (physical_mode_ != physical_mode) { |
| 744 | physical_mode_ = physical_mode; |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 745 | adaptor()->EmitUint16Changed(kWifiPhyMode, physical_mode_); |
mukesh agrawal | f6b3209 | 2013-04-10 15:49:55 -0700 | [diff] [blame] | 746 | } |
mukesh agrawal | e7c7e65 | 2013-06-18 17:19:39 -0700 | [diff] [blame] | 747 | adaptor()->EmitUint16sChanged(kWifiFrequencyListProperty, frequency_list_); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 748 | SetStrength(SignalToStrength(signal)); |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 749 | UpdateSecurity(); |
| 750 | } |
| 751 | |
| 752 | void WiFiService::UpdateSecurity() { |
| 753 | CryptoAlgorithm algorithm = kCryptoNone; |
| 754 | bool key_rotation = false; |
| 755 | bool endpoint_auth = false; |
| 756 | |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 757 | if (security_ == kSecurityNone) { |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 758 | // initial values apply |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 759 | } else if (security_ == kSecurityWep) { |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 760 | algorithm = kCryptoRc4; |
| 761 | key_rotation = Is8021x(); |
| 762 | endpoint_auth = Is8021x(); |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 763 | } else if (security_ == kSecurityPsk || |
| 764 | security_ == kSecurityWpa) { |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 765 | algorithm = kCryptoRc4; |
| 766 | key_rotation = true; |
| 767 | endpoint_auth = false; |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 768 | } else if (security_ == kSecurityRsn) { |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 769 | algorithm = kCryptoAes; |
| 770 | key_rotation = true; |
| 771 | endpoint_auth = false; |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 772 | } else if (security_ == kSecurity8021x) { |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 773 | algorithm = cipher_8021x_; |
| 774 | key_rotation = true; |
| 775 | endpoint_auth = true; |
| 776 | } |
| 777 | SetSecurity(algorithm, key_rotation, endpoint_auth); |
| 778 | } |
| 779 | |
| 780 | // static |
| 781 | Service::CryptoAlgorithm WiFiService::ComputeCipher8021x( |
| 782 | const set<WiFiEndpointConstRefPtr> &endpoints) { |
| 783 | |
| 784 | if (endpoints.empty()) |
| 785 | return kCryptoNone; // Will update after scan results. |
| 786 | |
| 787 | // Find weakest cipher (across endpoints) of the strongest ciphers |
| 788 | // (per endpoint). |
| 789 | Service::CryptoAlgorithm cipher = Service::kCryptoAes; |
Paul Stewart | 6db7b24 | 2014-05-02 15:34:21 -0700 | [diff] [blame^] | 790 | for (const auto &endpoint : endpoints) { |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 791 | Service::CryptoAlgorithm endpoint_cipher; |
Paul Stewart | 6db7b24 | 2014-05-02 15:34:21 -0700 | [diff] [blame^] | 792 | if (endpoint->has_rsn_property()) { |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 793 | endpoint_cipher = Service::kCryptoAes; |
Paul Stewart | 6db7b24 | 2014-05-02 15:34:21 -0700 | [diff] [blame^] | 794 | } else if (endpoint->has_wpa_property()) { |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 795 | endpoint_cipher = Service::kCryptoRc4; |
| 796 | } else { |
| 797 | // We could be in the Dynamic WEP case here. But that's okay, |
| 798 | // because |cipher_8021x_| is not defined in that case. |
| 799 | endpoint_cipher = Service::kCryptoNone; |
| 800 | } |
| 801 | cipher = std::min(cipher, endpoint_cipher); |
| 802 | } |
| 803 | return cipher; |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 804 | } |
| 805 | |
mukesh agrawal | 1a05626 | 2011-10-05 14:36:54 -0700 | [diff] [blame] | 806 | // static |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 807 | void WiFiService::ValidateWEPPassphrase(const std::string &passphrase, |
| 808 | Error *error) { |
| 809 | ParseWEPPassphrase(passphrase, NULL, NULL, error); |
mukesh agrawal | 1a05626 | 2011-10-05 14:36:54 -0700 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | // static |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 813 | void WiFiService::ValidateWPAPassphrase(const std::string &passphrase, |
| 814 | Error *error) { |
mukesh agrawal | 1a05626 | 2011-10-05 14:36:54 -0700 | [diff] [blame] | 815 | unsigned int length = passphrase.length(); |
| 816 | vector<uint8> passphrase_bytes; |
| 817 | |
| 818 | if (base::HexStringToBytes(passphrase, &passphrase_bytes)) { |
| 819 | if (length != IEEE_80211::kWPAHexLen && |
| 820 | (length < IEEE_80211::kWPAAsciiMinLen || |
| 821 | length > IEEE_80211::kWPAAsciiMaxLen)) { |
| 822 | error->Populate(Error::kInvalidPassphrase); |
| 823 | } |
| 824 | } else { |
| 825 | if (length < IEEE_80211::kWPAAsciiMinLen || |
| 826 | length > IEEE_80211::kWPAAsciiMaxLen) { |
| 827 | error->Populate(Error::kInvalidPassphrase); |
| 828 | } |
| 829 | } |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 830 | } |
mukesh agrawal | 1a05626 | 2011-10-05 14:36:54 -0700 | [diff] [blame] | 831 | |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 832 | // static |
| 833 | void WiFiService::ParseWEPPassphrase(const string &passphrase, |
| 834 | int *key_index, |
| 835 | std::vector<uint8> *password_bytes, |
| 836 | Error *error) { |
| 837 | unsigned int length = passphrase.length(); |
| 838 | int key_index_local; |
| 839 | std::string password_text; |
| 840 | bool is_hex = false; |
| 841 | |
| 842 | switch (length) { |
| 843 | case IEEE_80211::kWEP40AsciiLen: |
| 844 | case IEEE_80211::kWEP104AsciiLen: |
| 845 | key_index_local = 0; |
| 846 | password_text = passphrase; |
| 847 | break; |
| 848 | case IEEE_80211::kWEP40AsciiLen + 2: |
| 849 | case IEEE_80211::kWEP104AsciiLen + 2: |
| 850 | if (CheckWEPKeyIndex(passphrase, error)) { |
| 851 | base::StringToInt(passphrase.substr(0,1), &key_index_local); |
| 852 | password_text = passphrase.substr(2); |
| 853 | } |
| 854 | break; |
| 855 | case IEEE_80211::kWEP40HexLen: |
| 856 | case IEEE_80211::kWEP104HexLen: |
| 857 | if (CheckWEPIsHex(passphrase, error)) { |
| 858 | key_index_local = 0; |
| 859 | password_text = passphrase; |
| 860 | is_hex = true; |
| 861 | } |
| 862 | break; |
| 863 | case IEEE_80211::kWEP40HexLen + 2: |
| 864 | case IEEE_80211::kWEP104HexLen + 2: |
| 865 | if(CheckWEPKeyIndex(passphrase, error) && |
| 866 | CheckWEPIsHex(passphrase.substr(2), error)) { |
| 867 | base::StringToInt(passphrase.substr(0,1), &key_index_local); |
| 868 | password_text = passphrase.substr(2); |
| 869 | is_hex = true; |
| 870 | } else if (CheckWEPPrefix(passphrase, error) && |
| 871 | CheckWEPIsHex(passphrase.substr(2), error)) { |
| 872 | key_index_local = 0; |
| 873 | password_text = passphrase.substr(2); |
| 874 | is_hex = true; |
| 875 | } |
| 876 | break; |
| 877 | case IEEE_80211::kWEP40HexLen + 4: |
| 878 | case IEEE_80211::kWEP104HexLen + 4: |
| 879 | if (CheckWEPKeyIndex(passphrase, error) && |
| 880 | CheckWEPPrefix(passphrase.substr(2), error) && |
| 881 | CheckWEPIsHex(passphrase.substr(4), error)) { |
| 882 | base::StringToInt(passphrase.substr(0,1), &key_index_local); |
| 883 | password_text = passphrase.substr(4); |
| 884 | is_hex = true; |
| 885 | } |
| 886 | break; |
| 887 | default: |
| 888 | error->Populate(Error::kInvalidPassphrase); |
| 889 | break; |
| 890 | } |
| 891 | |
mukesh agrawal | 1a05626 | 2011-10-05 14:36:54 -0700 | [diff] [blame] | 892 | if (error->IsSuccess()) { |
Thieu Le | f4cbda9 | 2011-11-10 23:41:24 +0000 | [diff] [blame] | 893 | if (key_index) |
| 894 | *key_index = key_index_local; |
| 895 | if (password_bytes) { |
| 896 | if (is_hex) |
| 897 | base::HexStringToBytes(password_text, password_bytes); |
| 898 | else |
| 899 | password_bytes->insert(password_bytes->end(), |
| 900 | password_text.begin(), |
| 901 | password_text.end()); |
| 902 | } |
mukesh agrawal | 1a05626 | 2011-10-05 14:36:54 -0700 | [diff] [blame] | 903 | } |
| 904 | } |
| 905 | |
| 906 | // static |
| 907 | bool WiFiService::CheckWEPIsHex(const string &passphrase, Error *error) { |
| 908 | vector<uint8> passphrase_bytes; |
| 909 | if (base::HexStringToBytes(passphrase, &passphrase_bytes)) { |
| 910 | return true; |
| 911 | } else { |
| 912 | error->Populate(Error::kInvalidPassphrase); |
| 913 | return false; |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | // static |
| 918 | bool WiFiService::CheckWEPKeyIndex(const string &passphrase, Error *error) { |
| 919 | if (StartsWithASCII(passphrase, "0:", false) || |
| 920 | StartsWithASCII(passphrase, "1:", false) || |
| 921 | StartsWithASCII(passphrase, "2:", false) || |
| 922 | StartsWithASCII(passphrase, "3:", false)) { |
| 923 | return true; |
| 924 | } else { |
| 925 | error->Populate(Error::kInvalidPassphrase); |
| 926 | return false; |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | // static |
| 931 | bool WiFiService::CheckWEPPrefix(const string &passphrase, Error *error) { |
| 932 | if (StartsWithASCII(passphrase, "0x", false)) { |
| 933 | return true; |
| 934 | } else { |
| 935 | error->Populate(Error::kInvalidPassphrase); |
| 936 | return false; |
| 937 | } |
| 938 | } |
| 939 | |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 940 | // static |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 941 | string WiFiService::GetSecurityClass(const string &security) { |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 942 | if (security == kSecurityRsn || |
| 943 | security == kSecurityWpa) { |
| 944 | return kSecurityPsk; |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 945 | } else { |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 946 | return security; |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 947 | } |
| 948 | } |
| 949 | |
Wade Guthrie | 9ec0806 | 2013-09-25 15:22:24 -0700 | [diff] [blame] | 950 | |
| 951 | int16 WiFiService::SignalLevel() const { |
| 952 | return current_endpoint_ ? current_endpoint_->signal_strength() : |
| 953 | std::numeric_limits<int16>::min(); |
| 954 | } |
| 955 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 956 | // static |
| 957 | bool WiFiService::ParseStorageIdentifier(const string &storage_name, |
| 958 | string *address, |
| 959 | string *mode, |
| 960 | string *security) { |
| 961 | vector<string> wifi_parts; |
| 962 | base::SplitString(storage_name, '_', &wifi_parts); |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 963 | if ((wifi_parts.size() != 5 && wifi_parts.size() != 6) || |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 964 | wifi_parts[0] != kTypeWifi) { |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 965 | return false; |
| 966 | } |
| 967 | *address = wifi_parts[1]; |
| 968 | *mode = wifi_parts[3]; |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 969 | if (wifi_parts.size() == 5) { |
| 970 | *security = wifi_parts[4]; |
| 971 | } else { |
| 972 | // Account for security type "802_1x" which got split up above. |
| 973 | *security = wifi_parts[4] + "_" + wifi_parts[5]; |
| 974 | } |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 975 | return true; |
| 976 | } |
| 977 | |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 978 | // static |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 979 | bool WiFiService::FixupServiceEntries(StoreInterface *storage) { |
| 980 | bool fixed_entry = false; |
| 981 | set<string> groups = storage->GetGroups(); |
Paul Stewart | 6db7b24 | 2014-05-02 15:34:21 -0700 | [diff] [blame^] | 982 | for (const auto &id : groups) { |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 983 | string device_address, network_mode, security; |
| 984 | if (!ParseStorageIdentifier(id, &device_address, |
| 985 | &network_mode, &security)) { |
| 986 | continue; |
| 987 | } |
| 988 | if (!storage->GetString(id, kStorageType, NULL)) { |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 989 | storage->SetString(id, kStorageType, kTypeWifi); |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 990 | fixed_entry = true; |
| 991 | } |
| 992 | if (!storage->GetString(id, kStorageMode, NULL)) { |
| 993 | storage->SetString(id, kStorageMode, network_mode); |
| 994 | fixed_entry = true; |
| 995 | } |
| 996 | if (!storage->GetString(id, kStorageSecurity, NULL)) { |
| 997 | storage->SetString(id, kStorageSecurity, security); |
| 998 | fixed_entry = true; |
| 999 | } |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 1000 | if (!storage->GetString(id, kStorageSecurityClass, NULL)) { |
| 1001 | storage->SetString(id, kStorageSecurityClass, GetSecurityClass(security)); |
| 1002 | fixed_entry = true; |
| 1003 | } |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 1004 | } |
| 1005 | return fixed_entry; |
| 1006 | } |
| 1007 | |
| 1008 | // static |
Paul Stewart | d2e1c36 | 2013-03-03 19:06:07 -0800 | [diff] [blame] | 1009 | bool WiFiService::IsValidMode(const string &mode) { |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 1010 | return mode == kModeManaged || mode == kModeAdhoc; |
Paul Stewart | d2e1c36 | 2013-03-03 19:06:07 -0800 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | // static |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 1014 | bool WiFiService::IsValidSecurityMethod(const string &method) { |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 1015 | return method == kSecurityNone || |
| 1016 | method == kSecurityWep || |
| 1017 | method == kSecurityPsk || |
| 1018 | method == kSecurityWpa || |
| 1019 | method == kSecurityRsn || |
| 1020 | method == kSecurity8021x; |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | // static |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1024 | uint8 WiFiService::SignalToStrength(int16 signal_dbm) { |
| 1025 | int16 strength; |
| 1026 | if (signal_dbm > 0) { |
| 1027 | if (!logged_signal_warning) { |
| 1028 | LOG(WARNING) << "Signal strength is suspiciously high. " |
| 1029 | << "Assuming value " << signal_dbm << " is not in dBm."; |
| 1030 | logged_signal_warning = true; |
| 1031 | } |
| 1032 | strength = signal_dbm; |
| 1033 | } else { |
| 1034 | strength = 120 + signal_dbm; // Call -20dBm "perfect". |
| 1035 | } |
| 1036 | |
mukesh agrawal | 8f3f775 | 2012-02-17 19:42:09 -0800 | [diff] [blame] | 1037 | if (strength > kStrengthMax) { |
| 1038 | strength = kStrengthMax; |
| 1039 | } else if (strength < kStrengthMin) { |
| 1040 | strength = kStrengthMin; |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 1041 | } |
| 1042 | return strength; |
| 1043 | } |
| 1044 | |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 1045 | KeyValueStore WiFiService::GetStorageProperties() const { |
| 1046 | KeyValueStore args; |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 1047 | args.SetString(kStorageType, kTypeWifi); |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 1048 | args.SetString(kStorageSSID, hex_ssid_); |
| 1049 | args.SetString(kStorageMode, mode_); |
| 1050 | args.SetString(kStorageSecurityClass, GetSecurityClass(security_)); |
| 1051 | return args; |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 1052 | } |
| 1053 | |
Paul Stewart | 71a4d3b | 2013-01-18 18:12:56 -0800 | [diff] [blame] | 1054 | string WiFiService::GetDefaultStorageIdentifier() const { |
| 1055 | string security = GetSecurityClass(security_); |
| 1056 | return StringToLowerASCII(base::StringPrintf("%s_%s_%s_%s_%s", |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 1057 | kTypeWifi, |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 1058 | kAnyDeviceAddress, |
Paul Stewart | d08f443 | 2011-11-04 07:48:20 -0700 | [diff] [blame] | 1059 | hex_ssid_.c_str(), |
| 1060 | mode_.c_str(), |
| 1061 | security.c_str())); |
| 1062 | } |
| 1063 | |
Paul Stewart | 6df20bd | 2013-03-13 19:31:25 -0700 | [diff] [blame] | 1064 | string WiFiService::GetSecurity(Error */*error*/) { |
| 1065 | if (current_endpoint_) { |
| 1066 | return current_endpoint_->security_mode(); |
| 1067 | } |
| 1068 | return security_; |
| 1069 | } |
| 1070 | |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 1071 | void WiFiService::ClearCachedCredentials() { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 1072 | if (wifi_) { |
| 1073 | wifi_->ClearCachedCredentials(this); |
| 1074 | } |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 1075 | } |
| 1076 | |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 1077 | void WiFiService::OnEapCredentialsChanged() { |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 1078 | ClearCachedCredentials(); |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 1079 | UpdateConnectable(); |
| 1080 | } |
| 1081 | |
Paul Stewart | 4357f4e | 2012-04-26 17:39:26 -0700 | [diff] [blame] | 1082 | void WiFiService::OnProfileConfigured() { |
| 1083 | if (profile() || !hidden_ssid()) { |
| 1084 | return; |
| 1085 | } |
| 1086 | // This situation occurs when a hidden WiFi service created via GetService |
| 1087 | // has been persisted to a profile in Manager::ConfigureService(). Now |
| 1088 | // that configuration is saved, we must join the service with its profile, |
| 1089 | // which will make this SSID eligible for directed probes during scans. |
| 1090 | manager()->RegisterService(this); |
| 1091 | } |
| 1092 | |
Gaurav Shah | 29d6888 | 2012-01-30 19:06:42 -0800 | [diff] [blame] | 1093 | bool WiFiService::Is8021x() const { |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 1094 | if (security_ == kSecurity8021x) |
Gaurav Shah | 29d6888 | 2012-01-30 19:06:42 -0800 | [diff] [blame] | 1095 | return true; |
| 1096 | |
| 1097 | // Dynamic WEP + 802.1x. |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 1098 | if (security_ == kSecurityWep && |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 1099 | GetEAPKeyManagement() == WPASupplicant::kKeyManagementIeee8021X) |
Gaurav Shah | 29d6888 | 2012-01-30 19:06:42 -0800 | [diff] [blame] | 1100 | return true; |
| 1101 | return false; |
| 1102 | } |
| 1103 | |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 1104 | WiFiRefPtr WiFiService::ChooseDevice() { |
Paul Stewart | ee6b3d7 | 2013-07-12 16:07:51 -0700 | [diff] [blame] | 1105 | // TODO(pstew): Style frowns on dynamic_cast. crbug.com/220387 |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 1106 | DeviceRefPtr device = |
| 1107 | manager()->GetEnabledDeviceWithTechnology(Technology::kWifi); |
| 1108 | return dynamic_cast<WiFi *>(device.get()); |
| 1109 | } |
| 1110 | |
| 1111 | void WiFiService::ResetWiFi() { |
| 1112 | SetWiFi(NULL); |
| 1113 | } |
| 1114 | |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1115 | void WiFiService::SetWiFi(const WiFiRefPtr &new_wifi) { |
| 1116 | if (wifi_ == new_wifi) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 1117 | return; |
| 1118 | } |
| 1119 | ClearCachedCredentials(); |
| 1120 | if (wifi_) { |
| 1121 | wifi_->DisassociateFromService(this); |
| 1122 | } |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1123 | if (new_wifi) { |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 1124 | adaptor()->EmitRpcIdentifierChanged(kDeviceProperty, |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1125 | new_wifi->GetRpcIdentifier()); |
| 1126 | } else { |
Ben Chan | f024ef4 | 2013-09-20 14:21:38 -0700 | [diff] [blame] | 1127 | adaptor()->EmitRpcIdentifierChanged(kDeviceProperty, |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1128 | DBusAdaptor::kNullPath); |
| 1129 | } |
| 1130 | wifi_ = new_wifi; |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 1131 | } |
| 1132 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 1133 | } // namespace shill |