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