mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -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 | |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 5 | #include "shill/wifi.h" |
| 6 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 7 | #include <stdio.h> |
mukesh agrawal | c7426a4 | 2011-06-03 13:04:28 -0700 | [diff] [blame] | 8 | #include <string.h> |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 9 | #include <netinet/ether.h> |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 10 | #include <linux/if.h> // Needs definitions from netinet/ether.h |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 11 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 12 | #include <algorithm> |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 13 | #include <map> |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 14 | #include <string> |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 15 | #include <vector> |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 16 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 17 | #include <base/bind.h> |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 18 | #include <base/stringprintf.h> |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 19 | #include <base/string_util.h> |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 20 | #include <chromeos/dbus/service_constants.h> |
mukesh agrawal | 16bc1b8 | 2012-02-09 18:38:26 -0800 | [diff] [blame] | 21 | #include <glib.h> |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 22 | |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 23 | #include "shill/config80211.h" |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 24 | #include "shill/control_interface.h" |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 25 | #include "shill/dbus_adaptor.h" |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 26 | #include "shill/device.h" |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 27 | #include "shill/error.h" |
Gaurav Shah | 6d2c72d | 2012-10-16 16:30:44 -0700 | [diff] [blame] | 28 | #include "shill/geolocation_info.h" |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 29 | #include "shill/ieee80211.h" |
Paul Stewart | 3c508e1 | 2012-08-09 11:40:06 -0700 | [diff] [blame] | 30 | #include "shill/link_monitor.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 31 | #include "shill/logging.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 32 | #include "shill/manager.h" |
Thieu Le | 67370f6 | 2012-02-14 23:01:42 +0000 | [diff] [blame] | 33 | #include "shill/metrics.h" |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 34 | #include "shill/property_accessor.h" |
Darin Petkov | d196726 | 2011-07-18 14:55:18 -0700 | [diff] [blame] | 35 | #include "shill/proxy_factory.h" |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 36 | #include "shill/rtnl_handler.h" |
Paul Stewart | 5581d07 | 2012-12-17 17:30:20 -0800 | [diff] [blame] | 37 | #include "shill/scope_logger.h" |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 38 | #include "shill/shill_time.h" |
Paul Stewart | 735eab5 | 2013-03-29 09:19:23 -0700 | [diff] [blame] | 39 | #include "shill/supplicant_eap_state_handler.h" |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 40 | #include "shill/supplicant_interface_proxy_interface.h" |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 41 | #include "shill/supplicant_network_proxy_interface.h" |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 42 | #include "shill/supplicant_process_proxy_interface.h" |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 43 | #include "shill/technology.h" |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 44 | #include "shill/wifi_endpoint.h" |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 45 | #include "shill/wifi_provider.h" |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 46 | #include "shill/wifi_service.h" |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 47 | #include "shill/wpa_supplicant.h" |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 48 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 49 | using base::Bind; |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 50 | using base::StringPrintf; |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 51 | using std::map; |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 52 | using std::string; |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 53 | using std::vector; |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 54 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 55 | namespace shill { |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 56 | |
| 57 | // statics |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 58 | const char *WiFi::kDefaultBgscanMethod = |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 59 | WPASupplicant::kNetworkBgscanMethodSimple; |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 60 | const uint16 WiFi::kDefaultBgscanShortIntervalSeconds = 30; |
| 61 | const int32 WiFi::kDefaultBgscanSignalThresholdDbm = -50; |
| 62 | const uint16 WiFi::kDefaultScanIntervalSeconds = 180; |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 63 | // Scan interval while connected. |
| 64 | const uint16 WiFi::kBackgroundScanIntervalSeconds = 3601; |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 65 | // Age (in seconds) beyond which a BSS cache entry will not be preserved, |
| 66 | // across a suspend/resume. |
| 67 | const time_t WiFi::kMaxBSSResumeAgeSeconds = 10; |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 68 | const char WiFi::kInterfaceStateUnknown[] = "shill-unknown"; |
mukesh agrawal | f202817 | 2012-03-13 14:20:22 -0700 | [diff] [blame] | 69 | const time_t WiFi::kRescanIntervalSeconds = 1; |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 70 | const int WiFi::kNumFastScanAttempts = 3; |
| 71 | const int WiFi::kFastScanIntervalSeconds = 10; |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 72 | const int WiFi::kPendingTimeoutSeconds = 15; |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 73 | const int WiFi::kReconnectTimeoutSeconds = 10; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 74 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 75 | WiFi::WiFi(ControlInterface *control_interface, |
| 76 | EventDispatcher *dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 77 | Metrics *metrics, |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 78 | Manager *manager, |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 79 | const string& link, |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 80 | const string &address, |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 81 | int interface_index) |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 82 | : Device(control_interface, |
| 83 | dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 84 | metrics, |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 85 | manager, |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 86 | link, |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 87 | address, |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 88 | interface_index, |
| 89 | Technology::kWifi), |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 90 | provider_(manager->wifi_provider()), |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 91 | weak_ptr_factory_(this), |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 92 | proxy_factory_(ProxyFactory::GetInstance()), |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 93 | time_(Time::GetInstance()), |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 94 | supplicant_present_(false), |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 95 | supplicant_state_(kInterfaceStateUnknown), |
| 96 | supplicant_bss_("(unknown)"), |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 97 | need_bss_flush_(false), |
Darin Petkov | e636c69 | 2012-05-31 10:22:17 +0200 | [diff] [blame] | 98 | resumed_at_((struct timeval){0}), |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 99 | fast_scans_remaining_(kNumFastScanAttempts), |
Christopher Wiley | 8f81e2a | 2012-10-17 16:51:32 -0700 | [diff] [blame] | 100 | has_already_completed_(false), |
Paul Stewart | a47c3c6 | 2012-12-18 12:14:29 -0800 | [diff] [blame] | 101 | is_debugging_connection_(false), |
Paul Stewart | 735eab5 | 2013-03-29 09:19:23 -0700 | [diff] [blame] | 102 | eap_state_handler_(new SupplicantEAPStateHandler()), |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 103 | bgscan_short_interval_seconds_(kDefaultBgscanShortIntervalSeconds), |
| 104 | bgscan_signal_threshold_dbm_(kDefaultBgscanSignalThresholdDbm), |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 105 | scan_pending_(false), |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 106 | scan_interval_seconds_(kDefaultScanIntervalSeconds) { |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 107 | PropertyStore *store = this->mutable_store(); |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 108 | store->RegisterDerivedString( |
| 109 | flimflam::kBgscanMethodProperty, |
| 110 | StringAccessor( |
| 111 | // TODO(petkov): CustomMappedAccessor is used for convenience because |
| 112 | // it provides a way to define a custom clearer (unlike |
| 113 | // CustomAccessor). We need to implement a fully custom accessor with |
| 114 | // no extra argument. |
| 115 | new CustomMappedAccessor<WiFi, string, int>(this, |
| 116 | &WiFi::ClearBgscanMethod, |
| 117 | &WiFi::GetBgscanMethod, |
| 118 | &WiFi::SetBgscanMethod, |
| 119 | 0))); // Unused. |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 120 | HelpRegisterDerivedUint16(store, |
| 121 | flimflam::kBgscanShortIntervalProperty, |
| 122 | &WiFi::GetBgscanShortInterval, |
| 123 | &WiFi::SetBgscanShortInterval); |
| 124 | HelpRegisterDerivedInt32(store, |
| 125 | flimflam::kBgscanSignalThresholdProperty, |
| 126 | &WiFi::GetBgscanSignalThreshold, |
| 127 | &WiFi::SetBgscanSignalThreshold); |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 128 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 129 | // TODO(quiche): Decide if scan_pending_ is close enough to |
| 130 | // "currently scanning" that we don't care, or if we want to track |
| 131 | // scan pending/currently scanning/no scan scheduled as a tri-state |
| 132 | // kind of thing. |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 133 | store->RegisterConstBool(flimflam::kScanningProperty, &scan_pending_); |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 134 | HelpRegisterDerivedUint16(store, |
| 135 | flimflam::kScanIntervalProperty, |
| 136 | &WiFi::GetScanInterval, |
| 137 | &WiFi::SetScanInterval); |
Paul Stewart | 5581d07 | 2012-12-17 17:30:20 -0800 | [diff] [blame] | 138 | ScopeLogger::GetInstance()->RegisterScopeEnableChangedCallback( |
| 139 | ScopeLogger::kWiFi, |
| 140 | Bind(&WiFi::OnWiFiDebugScopeChanged, weak_ptr_factory_.GetWeakPtr())); |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 141 | SLOG(WiFi, 2) << "WiFi device " << link_name() << " initialized."; |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 142 | } |
| 143 | |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 144 | WiFi::~WiFi() {} |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 145 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 146 | void WiFi::Start(Error *error, const EnabledStateChangedCallback &callback) { |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 147 | SLOG(WiFi, 2) << "WiFi " << link_name() << " starting."; |
| 148 | if (enabled()) { |
| 149 | return; |
mukesh agrawal | c7426a4 | 2011-06-03 13:04:28 -0700 | [diff] [blame] | 150 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 151 | OnEnabledStateChanged(EnabledStateChangedCallback(), Error()); |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 152 | if (error) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 153 | error->Reset(); // indicate immediate completion |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 154 | } |
| 155 | if (on_supplicant_appear_.IsCancelled()) { |
| 156 | // Registers the WPA supplicant appear/vanish callbacks only once per WiFi |
| 157 | // device instance. |
| 158 | on_supplicant_appear_.Reset( |
| 159 | Bind(&WiFi::OnSupplicantAppear, Unretained(this))); |
| 160 | on_supplicant_vanish_.Reset( |
| 161 | Bind(&WiFi::OnSupplicantVanish, Unretained(this))); |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 162 | manager()->dbus_manager()->WatchName(WPASupplicant::kDBusAddr, |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 163 | on_supplicant_appear_.callback(), |
| 164 | on_supplicant_vanish_.callback()); |
| 165 | } |
| 166 | // Connect to WPA supplicant if it's already present. If not, we'll connect to |
| 167 | // it when it appears. |
| 168 | ConnectToSupplicant(); |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 169 | Config80211 *config80211 = Config80211::GetInstance(); |
| 170 | if (config80211) { |
| 171 | config80211->SetWifiState(Config80211::kWifiUp); |
| 172 | } |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 175 | void WiFi::Stop(Error *error, const EnabledStateChangedCallback &callback) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 176 | SLOG(WiFi, 2) << "WiFi " << link_name() << " stopping."; |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 177 | DropConnection(); |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 178 | StopScanTimer(); |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 179 | for (EndpointMap::iterator it = endpoint_by_rpcid_.begin(); |
| 180 | it != endpoint_by_rpcid_.end(); ++it) { |
| 181 | provider_->OnEndpointRemoved(it->second); |
| 182 | } |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 183 | endpoint_by_rpcid_.clear(); |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 184 | for (ReverseServiceMap::const_iterator it = rpcid_by_service_.begin(); |
| 185 | it != rpcid_by_service_.end(); ++it) { |
| 186 | RemoveNetwork(it->second); |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 187 | } |
Paul Stewart | 549d44c | 2012-07-03 12:40:25 -0700 | [diff] [blame] | 188 | rpcid_by_service_.clear(); |
Paul Stewart | 549d44c | 2012-07-03 12:40:25 -0700 | [diff] [blame] | 189 | supplicant_interface_proxy_.reset(); // breaks a reference cycle |
| 190 | // TODO(quiche): Remove interface from supplicant. |
| 191 | supplicant_process_proxy_.reset(); |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 192 | current_service_ = NULL; // breaks a reference cycle |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 193 | pending_service_ = NULL; // breaks a reference cycle |
Paul Stewart | a47c3c6 | 2012-12-18 12:14:29 -0800 | [diff] [blame] | 194 | is_debugging_connection_ = false; |
Paul Stewart | d2db2b1 | 2013-01-17 13:11:07 -0800 | [diff] [blame] | 195 | SetScanPending(false); |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 196 | StopPendingTimer(); |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 197 | StopReconnectTimer(); |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 198 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 199 | OnEnabledStateChanged(EnabledStateChangedCallback(), Error()); |
| 200 | if (error) |
| 201 | error->Reset(); // indicate immediate completion |
mukesh agrawal | c4f368f | 2012-06-04 19:45:52 -0700 | [diff] [blame] | 202 | weak_ptr_factory_.InvalidateWeakPtrs(); |
mukesh agrawal | 5c4dd0b | 2011-09-14 13:53:14 -0700 | [diff] [blame] | 203 | |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 204 | SLOG(WiFi, 3) << "WiFi " << link_name() << " supplicant_process_proxy_ " |
| 205 | << (supplicant_process_proxy_.get() ? |
| 206 | "is set." : "is not set."); |
| 207 | SLOG(WiFi, 3) << "WiFi " << link_name() << " supplicant_interface_proxy_ " |
| 208 | << (supplicant_interface_proxy_.get() ? |
| 209 | "is set." : "is not set."); |
| 210 | SLOG(WiFi, 3) << "WiFi " << link_name() << " pending_service_ " |
| 211 | << (pending_service_.get() ? "is set." : "is not set."); |
| 212 | SLOG(WiFi, 3) << "WiFi " << link_name() << " has " |
| 213 | << endpoint_by_rpcid_.size() << " EndpointMap entries."; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 214 | } |
| 215 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 216 | void WiFi::Scan(Error */*error*/) { |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 217 | LOG(INFO) << __func__; |
| 218 | |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 219 | // Needs to send a D-Bus message, but may be called from D-Bus |
| 220 | // signal handler context (via Manager::RequestScan). So defer work |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 221 | // to event loop. |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 222 | dispatcher()->PostTask(Bind(&WiFi::ScanTask, weak_ptr_factory_.GetWeakPtr())); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 223 | } |
| 224 | |
mukesh agrawal | b4bc57d | 2011-12-07 01:07:47 +0000 | [diff] [blame] | 225 | void WiFi::BSSAdded(const ::DBus::Path &path, |
| 226 | const map<string, ::DBus::Variant> &properties) { |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 227 | // Called from a D-Bus signal handler, and may need to send a D-Bus |
mukesh agrawal | b4bc57d | 2011-12-07 01:07:47 +0000 | [diff] [blame] | 228 | // message. So defer work to event loop. |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 229 | dispatcher()->PostTask(Bind(&WiFi::BSSAddedTask, |
| 230 | weak_ptr_factory_.GetWeakPtr(), |
| 231 | path, properties)); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | void WiFi::BSSRemoved(const ::DBus::Path &path) { |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 235 | // Called from a D-Bus signal handler, and may need to send a D-Bus |
mukesh agrawal | b4bc57d | 2011-12-07 01:07:47 +0000 | [diff] [blame] | 236 | // message. So defer work to event loop. |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 237 | dispatcher()->PostTask(Bind(&WiFi::BSSRemovedTask, |
| 238 | weak_ptr_factory_.GetWeakPtr(), path)); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 241 | void WiFi::Certification(const map<string, ::DBus::Variant> &properties) { |
| 242 | dispatcher()->PostTask(Bind(&WiFi::CertificationTask, |
| 243 | weak_ptr_factory_.GetWeakPtr(), properties)); |
| 244 | } |
| 245 | |
Paul Stewart | db0f917 | 2012-11-30 16:48:09 -0800 | [diff] [blame] | 246 | void WiFi::EAPEvent(const string &status, const string ¶meter) { |
| 247 | dispatcher()->PostTask(Bind(&WiFi::EAPEventTask, |
| 248 | weak_ptr_factory_.GetWeakPtr(), |
| 249 | status, |
| 250 | parameter)); |
| 251 | } |
| 252 | |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 253 | void WiFi::PropertiesChanged(const map<string, ::DBus::Variant> &properties) { |
Darin Petkov | 9cd7ca1 | 2012-07-03 11:06:40 +0200 | [diff] [blame] | 254 | SLOG(WiFi, 2) << __func__; |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 255 | // Called from D-Bus signal handler, but may need to send a D-Bus |
| 256 | // message. So defer work to event loop. |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 257 | dispatcher()->PostTask(Bind(&WiFi::PropertiesChangedTask, |
| 258 | weak_ptr_factory_.GetWeakPtr(), properties)); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 259 | } |
| 260 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 261 | void WiFi::ScanDone() { |
| 262 | LOG(INFO) << __func__; |
| 263 | |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 264 | // Defer handling of scan result processing, because that processing |
| 265 | // may require the the registration of new D-Bus objects. And such |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 266 | // registration can't be done in the context of a D-Bus signal |
| 267 | // handler. |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 268 | dispatcher()->PostTask(Bind(&WiFi::ScanDoneTask, |
| 269 | weak_ptr_factory_.GetWeakPtr())); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 270 | } |
| 271 | |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 272 | void WiFi::ConnectTo(WiFiService *service, |
mukesh agrawal | 6489632 | 2011-12-01 01:13:10 +0000 | [diff] [blame] | 273 | map<string, DBus::Variant> service_params) { |
mukesh agrawal | e9adda1 | 2012-02-09 18:33:48 -0800 | [diff] [blame] | 274 | CHECK(service) << "Can't connect to NULL service."; |
mukesh agrawal | 445e72c | 2011-06-22 11:13:50 -0700 | [diff] [blame] | 275 | DBus::Path network_path; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 276 | |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 277 | // TODO(quiche): Handle cases where already connected. |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 278 | if (pending_service_ && pending_service_ == service) { |
| 279 | // TODO(quiche): Return an error to the caller. crosbug.com/23832 |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 280 | LOG(INFO) << "WiFi " << link_name() << " ignoring ConnectTo service " |
| 281 | << service->unique_name() |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 282 | << ", which is already pending."; |
| 283 | return; |
| 284 | } |
| 285 | |
| 286 | if (pending_service_ && pending_service_ != service) { |
| 287 | DisconnectFrom(pending_service_); |
| 288 | } |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 289 | |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 290 | Error unused_error; |
| 291 | network_path = FindNetworkRpcidForService(service, &unused_error); |
| 292 | if (network_path.empty()) { |
| 293 | try { |
| 294 | const uint32_t scan_ssid = 1; // "True": Use directed probe. |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 295 | service_params[WPASupplicant::kNetworkPropertyScanSSID].writer(). |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 296 | append_uint32(scan_ssid); |
| 297 | AppendBgscan(service, &service_params); |
| 298 | network_path = supplicant_interface_proxy_->AddNetwork(service_params); |
| 299 | CHECK(!network_path.empty()); // No DBus path should be empty. |
| 300 | rpcid_by_service_[service] = network_path; |
| 301 | } catch (const DBus::Error &e) { // NOLINT |
| 302 | LOG(ERROR) << "exception while adding network: " << e.what(); |
| 303 | return; |
| 304 | } |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 305 | } |
mukesh agrawal | 445e72c | 2011-06-22 11:13:50 -0700 | [diff] [blame] | 306 | |
Paul Stewart | a47c3c6 | 2012-12-18 12:14:29 -0800 | [diff] [blame] | 307 | if (service->HasRecentConnectionIssues()) { |
| 308 | SetConnectionDebugging(true); |
| 309 | } |
mukesh agrawal | 445e72c | 2011-06-22 11:13:50 -0700 | [diff] [blame] | 310 | supplicant_interface_proxy_->SelectNetwork(network_path); |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 311 | SetPendingService(service); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 312 | CHECK(current_service_.get() != pending_service_.get()); |
| 313 | |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 314 | // SelectService here (instead of in LinkEvent, like Ethernet), so |
| 315 | // that, if we fail to bring up L2, we can attribute failure correctly. |
| 316 | // |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 317 | // TODO(quiche): When we add code for dealing with connection failures, |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 318 | // reconsider if this is the right place to change the selected service. |
| 319 | // see discussion in crosbug.com/20191. |
| 320 | SelectService(service); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 321 | } |
| 322 | |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 323 | void WiFi::DisconnectFrom(WiFiService *service) { |
| 324 | if (service != current_service_ && service != pending_service_) { |
| 325 | // TODO(quiche): Once we have asynchronous reply support, we should |
| 326 | // generate a D-Bus error here. (crosbug.com/23832) |
| 327 | LOG(WARNING) << "In " << __func__ << "(): " |
| 328 | << " ignoring request to disconnect from service " |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 329 | << service->unique_name() |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 330 | << " which is neither current nor pending"; |
| 331 | return; |
| 332 | } |
| 333 | |
| 334 | if (pending_service_ && service != pending_service_) { |
| 335 | // TODO(quiche): Once we have asynchronous reply support, we should |
| 336 | // generate a D-Bus error here. (crosbug.com/23832) |
| 337 | LOG(WARNING) << "In " << __func__ << "(): " |
| 338 | << " ignoring request to disconnect from service " |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 339 | << service->unique_name() |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 340 | << " which is not the pending service."; |
| 341 | return; |
| 342 | } |
| 343 | |
| 344 | if (!pending_service_ && service != current_service_) { |
| 345 | // TODO(quiche): Once we have asynchronous reply support, we should |
| 346 | // generate a D-Bus error here. (crosbug.com/23832) |
| 347 | LOG(WARNING) << "In " << __func__ << "(): " |
| 348 | << " ignoring request to disconnect from service " |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 349 | << service->unique_name() |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 350 | << " which is not the current service."; |
| 351 | return; |
| 352 | } |
| 353 | |
Paul Stewart | ff96a84 | 2012-08-13 15:59:10 -0700 | [diff] [blame] | 354 | if (pending_service_) { |
| 355 | // Since wpa_supplicant has not yet set CurrentBSS, we can't depend |
| 356 | // on this to drive the service state back to idle. Do that here. |
| 357 | pending_service_->SetState(Service::kStateIdle); |
| 358 | } |
| 359 | |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 360 | SetPendingService(NULL); |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 361 | StopReconnectTimer(); |
Paul Stewart | 549d44c | 2012-07-03 12:40:25 -0700 | [diff] [blame] | 362 | |
| 363 | if (!supplicant_present_) { |
Christopher Wiley | c618448 | 2012-10-24 15:31:56 -0700 | [diff] [blame] | 364 | LOG(ERROR) << "In " << __func__ << "(): " |
| 365 | << "wpa_supplicant is not present; silently resetting " |
| 366 | << "current_service_."; |
| 367 | if (current_service_ == selected_service()) { |
| 368 | DropConnection(); |
| 369 | } |
Paul Stewart | 549d44c | 2012-07-03 12:40:25 -0700 | [diff] [blame] | 370 | current_service_ = NULL; |
| 371 | return; |
| 372 | } |
| 373 | |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 374 | try { |
| 375 | supplicant_interface_proxy_->Disconnect(); |
| 376 | // We'll call RemoveNetwork and reset |current_service_| after |
| 377 | // supplicant notifies us that the CurrentBSS has changed. |
Ben Chan | 80326f3 | 2012-05-04 17:51:32 -0700 | [diff] [blame] | 378 | } catch (const DBus::Error &e) { // NOLINT |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 379 | // Can't depend on getting a notification of CurrentBSS change. |
Christopher Wiley | c618448 | 2012-10-24 15:31:56 -0700 | [diff] [blame] | 380 | // So effect changes immediately. For instance, this can happen when |
| 381 | // a disconnect is triggered by a BSS going away. |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 382 | Error unused_error; |
| 383 | RemoveNetworkForService(service, &unused_error); |
Christopher Wiley | c618448 | 2012-10-24 15:31:56 -0700 | [diff] [blame] | 384 | if (service == selected_service()) { |
| 385 | DropConnection(); |
| 386 | } |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 387 | current_service_ = NULL; |
| 388 | } |
| 389 | |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 390 | CHECK(current_service_ == NULL || |
| 391 | current_service_.get() != pending_service_.get()); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 392 | } |
| 393 | |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 394 | bool WiFi::DisableNetwork(const ::DBus::Path &network) { |
| 395 | scoped_ptr<SupplicantNetworkProxyInterface> supplicant_network_proxy( |
| 396 | proxy_factory_->CreateSupplicantNetworkProxy( |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 397 | network, WPASupplicant::kDBusAddr)); |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 398 | try { |
| 399 | supplicant_network_proxy->SetEnabled(false); |
| 400 | } catch (const DBus::Error &e) { // NOLINT |
| 401 | LOG(ERROR) << "DisableNetwork for " << network << " failed."; |
| 402 | return false; |
| 403 | } |
| 404 | return true; |
| 405 | } |
| 406 | |
Paul Stewart | 71f6ecd | 2012-09-13 14:52:18 -0700 | [diff] [blame] | 407 | bool WiFi::RemoveNetwork(const ::DBus::Path &network) { |
| 408 | try { |
| 409 | supplicant_interface_proxy_->RemoveNetwork(network); |
| 410 | } catch (const DBus::Error &e) { // NOLINT |
Ben Chan | 381fdcc | 2012-10-14 21:10:36 -0700 | [diff] [blame] | 411 | // RemoveNetwork can fail with three different errors. |
| 412 | // |
| 413 | // If RemoveNetwork fails with a NetworkUnknown error, supplicant has |
| 414 | // already removed the network object, so return true as if |
| 415 | // RemoveNetwork removes the network object successfully. |
| 416 | // |
| 417 | // As shill always passes a valid network object path, RemoveNetwork |
| 418 | // should not fail with an InvalidArgs error. Return false in such case |
| 419 | // as something weird may have happened. Similarly, return false in case |
| 420 | // of an UnknownError. |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 421 | if (strcmp(e.name(), WPASupplicant::kErrorNetworkUnknown) != 0) { |
Ben Chan | 381fdcc | 2012-10-14 21:10:36 -0700 | [diff] [blame] | 422 | return false; |
| 423 | } |
Paul Stewart | 71f6ecd | 2012-09-13 14:52:18 -0700 | [diff] [blame] | 424 | } |
| 425 | return true; |
| 426 | } |
| 427 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 428 | bool WiFi::IsIdle() const { |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 429 | return !current_service_ && !pending_service_; |
| 430 | } |
| 431 | |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 432 | void WiFi::ClearCachedCredentials(const WiFiService *service) { |
| 433 | Error unused_error; |
| 434 | RemoveNetworkForService(service, &unused_error); |
Paul Stewart | 66c8600 | 2012-01-30 18:00:52 -0800 | [diff] [blame] | 435 | } |
| 436 | |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 437 | void WiFi::NotifyEndpointChanged(const WiFiEndpointConstRefPtr &endpoint) { |
Paul Stewart | 0427cc1 | 2013-03-25 13:50:39 -0700 | [diff] [blame] | 438 | provider_->OnEndpointUpdated(endpoint); |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 439 | } |
| 440 | |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 441 | void WiFi::AppendBgscan(WiFiService *service, |
| 442 | map<string, DBus::Variant> *service_params) const { |
| 443 | int scan_interval = kBackgroundScanIntervalSeconds; |
| 444 | string method = bgscan_method_; |
| 445 | if (method.empty()) { |
| 446 | // If multiple APs are detected for this SSID, configure the default method. |
| 447 | // Otherwise, disable background scanning completely. |
| 448 | if (service->GetEndpointCount() > 1) { |
| 449 | method = kDefaultBgscanMethod; |
| 450 | } else { |
| 451 | LOG(INFO) << "Background scan disabled -- single Endpoint for Service."; |
| 452 | return; |
| 453 | } |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 454 | } else if (method.compare(WPASupplicant::kNetworkBgscanMethodNone) == 0) { |
Christopher Wiley | a998df2 | 2012-07-11 15:14:55 -0700 | [diff] [blame] | 455 | LOG(INFO) << "Background scan disabled -- chose None method."; |
| 456 | return; |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 457 | } else { |
| 458 | // If the background scan method was explicitly specified, honor the |
| 459 | // configured background scan interval. |
| 460 | scan_interval = scan_interval_seconds_; |
| 461 | } |
| 462 | DCHECK(!method.empty()); |
| 463 | string config_string = StringPrintf("%s:%d:%d:%d", |
| 464 | method.c_str(), |
| 465 | bgscan_short_interval_seconds_, |
| 466 | bgscan_signal_threshold_dbm_, |
| 467 | scan_interval); |
| 468 | LOG(INFO) << "Background scan: " << config_string; |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 469 | (*service_params)[WPASupplicant::kNetworkPropertyBgscan].writer() |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 470 | .append_string(config_string.c_str()); |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 471 | } |
| 472 | |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 473 | string WiFi::GetBgscanMethod(const int &/*argument*/, Error */* error */) { |
| 474 | return bgscan_method_.empty() ? kDefaultBgscanMethod : bgscan_method_; |
| 475 | } |
| 476 | |
| 477 | void WiFi::SetBgscanMethod( |
| 478 | const int &/*argument*/, const string &method, Error *error) { |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 479 | if (method != WPASupplicant::kNetworkBgscanMethodSimple && |
| 480 | method != WPASupplicant::kNetworkBgscanMethodLearn && |
| 481 | method != WPASupplicant::kNetworkBgscanMethodNone) { |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 482 | const string error_message = |
| 483 | StringPrintf("Unrecognized bgscan method %s", method.c_str()); |
| 484 | LOG(WARNING) << error_message; |
| 485 | error->Populate(Error::kInvalidArguments, error_message); |
| 486 | return; |
| 487 | } |
| 488 | |
| 489 | bgscan_method_ = method; |
| 490 | // We do not update kNetworkPropertyBgscan for |pending_service_| or |
| 491 | // |current_service_|, because supplicant does not allow for |
| 492 | // reconfiguration without disconnect and reconnect. |
| 493 | } |
| 494 | |
| 495 | void WiFi::SetBgscanShortInterval(const uint16 &seconds, Error */*error*/) { |
| 496 | bgscan_short_interval_seconds_ = seconds; |
| 497 | // We do not update kNetworkPropertyBgscan for |pending_service_| or |
| 498 | // |current_service_|, because supplicant does not allow for |
| 499 | // reconfiguration without disconnect and reconnect. |
| 500 | } |
| 501 | |
| 502 | void WiFi::SetBgscanSignalThreshold(const int32 &dbm, Error */*error*/) { |
| 503 | bgscan_signal_threshold_dbm_ = dbm; |
| 504 | // We do not update kNetworkPropertyBgscan for |pending_service_| or |
| 505 | // |current_service_|, because supplicant does not allow for |
| 506 | // reconfiguration without disconnect and reconnect. |
| 507 | } |
| 508 | |
| 509 | void WiFi::SetScanInterval(const uint16 &seconds, Error */*error*/) { |
| 510 | scan_interval_seconds_ = seconds; |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 511 | if (running()) { |
| 512 | StartScanTimer(); |
| 513 | } |
| 514 | // The scan interval affects both foreground scans (handled by |
| 515 | // |scan_timer_callback_|), and background scans (handled by |
| 516 | // supplicant). However, we do not update |pending_service_| or |
| 517 | // |current_service_|, because supplicant does not allow for |
| 518 | // reconfiguration without disconnect and reconnect. |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 519 | } |
| 520 | |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 521 | void WiFi::ClearBgscanMethod(const int &/*argument*/, Error */*error*/) { |
| 522 | bgscan_method_.clear(); |
| 523 | } |
| 524 | |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 525 | void WiFi::CurrentBSSChanged(const ::DBus::Path &new_bss) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 526 | SLOG(WiFi, 3) << "WiFi " << link_name() << " CurrentBSS " |
| 527 | << supplicant_bss_ << " -> " << new_bss; |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 528 | supplicant_bss_ = new_bss; |
Christopher Wiley | 8f81e2a | 2012-10-17 16:51:32 -0700 | [diff] [blame] | 529 | has_already_completed_ = false; |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 530 | |
| 531 | // Any change in CurrentBSS means supplicant is actively changing our |
| 532 | // connectivity. We no longer need to track any previously pending |
| 533 | // reconnect. |
| 534 | StopReconnectTimer(); |
| 535 | |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 536 | if (new_bss == WPASupplicant::kCurrentBSSNull) { |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 537 | HandleDisconnect(); |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 538 | if (!provider_->GetHiddenSSIDList().empty()) { |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 539 | // Before disconnecting, wpa_supplicant probably scanned for |
| 540 | // APs. So, in the normal case, we defer to the timer for the next scan. |
| 541 | // |
| 542 | // However, in the case of hidden SSIDs, supplicant knows about |
| 543 | // at most one of them. (That would be the hidden SSID we were |
| 544 | // connected to, if applicable.) |
| 545 | // |
| 546 | // So, in this case, we initiate an immediate scan. This scan |
| 547 | // will include the hidden SSIDs we know about (up to the limit of |
| 548 | // kScanMAxSSIDsPerScan). |
| 549 | // |
| 550 | // We may want to reconsider this immediate scan, if/when shill |
| 551 | // takes greater responsibility for scanning (vs. letting |
| 552 | // supplicant handle most of it). |
| 553 | Scan(NULL); |
| 554 | } |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 555 | } else { |
| 556 | HandleRoam(new_bss); |
| 557 | } |
| 558 | |
Paul Stewart | 735eab5 | 2013-03-29 09:19:23 -0700 | [diff] [blame] | 559 | // Reset the EAP handler only after calling HandleDisconnect() above |
| 560 | // so our EAP state could be used to detect a failed authentication. |
| 561 | eap_state_handler_->Reset(); |
Paul Stewart | 1369c2b | 2013-01-11 05:41:26 -0800 | [diff] [blame] | 562 | |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 563 | // If we are selecting a new service, or if we're clearing selection |
| 564 | // of a something other than the pending service, call SelectService. |
| 565 | // Otherwise skip SelectService, since this will cause the pending |
| 566 | // service to be marked as Idle. |
| 567 | if (current_service_ || selected_service() != pending_service_) { |
| 568 | SelectService(current_service_); |
| 569 | } |
| 570 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 571 | // Invariant check: a Service can either be current, or pending, but |
| 572 | // not both. |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 573 | CHECK(current_service_.get() != pending_service_.get() || |
| 574 | current_service_.get() == NULL); |
Paul Stewart | a47c3c6 | 2012-12-18 12:14:29 -0800 | [diff] [blame] | 575 | |
| 576 | // If we are no longer debugging a problematic WiFi connection, return |
| 577 | // to the debugging level indicated by the WiFi debugging scope. |
| 578 | if ((!current_service_ || !current_service_->HasRecentConnectionIssues()) && |
| 579 | (!pending_service_ || !pending_service_->HasRecentConnectionIssues())) { |
| 580 | SetConnectionDebugging(false); |
| 581 | } |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | void WiFi::HandleDisconnect() { |
| 585 | // Identify the affected service. We expect to get a disconnect |
| 586 | // event when we fall off a Service that we were connected |
| 587 | // to. However, we also allow for the case where we get a disconnect |
| 588 | // event while attempting to connect from a disconnected state. |
| 589 | WiFiService *affected_service = |
| 590 | current_service_.get() ? current_service_.get() : pending_service_.get(); |
| 591 | |
| 592 | current_service_ = NULL; |
| 593 | if (!affected_service) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 594 | SLOG(WiFi, 2) << "WiFi " << link_name() |
| 595 | << " disconnected while not connected or connecting"; |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 596 | return; |
Christopher Wiley | c618448 | 2012-10-24 15:31:56 -0700 | [diff] [blame] | 597 | } |
| 598 | if (affected_service == selected_service()) { |
Paul Stewart | 20b0a09 | 2012-05-22 20:39:57 -0700 | [diff] [blame] | 599 | // If our selected service has disconnected, destroy IP configuration state. |
Christopher Wiley | c618448 | 2012-10-24 15:31:56 -0700 | [diff] [blame] | 600 | DropConnection(); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 601 | } |
| 602 | |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 603 | Error error; |
| 604 | if (!DisableNetworkForService(affected_service, &error)) { |
| 605 | if (error.type() == Error::kNotFound) { |
| 606 | SLOG(WiFi, 2) << "WiFi " << link_name() << " disconnected from " |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 607 | << " (or failed to connect to) service " |
| 608 | << affected_service->unique_name() << ", " |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 609 | << "but could not find supplicant network to disable."; |
| 610 | } else { |
| 611 | LOG(FATAL) << "DisableNetwork failed."; |
Paul Stewart | 71f6ecd | 2012-09-13 14:52:18 -0700 | [diff] [blame] | 612 | } |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 613 | } |
| 614 | |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 615 | SLOG(WiFi, 2) << "WiFi " << link_name() << " disconnected from " |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 616 | << " (or failed to connect to) service " |
| 617 | << affected_service->unique_name(); |
Paul Stewart | 1369c2b | 2013-01-11 05:41:26 -0800 | [diff] [blame] | 618 | Service::ConnectFailure failure; |
| 619 | if (SuspectCredentials(*affected_service, &failure)) { |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 620 | // If we suspect bad credentials, set failure, to trigger an error |
mukesh agrawal | 56e3220 | 2012-07-26 16:32:11 -0700 | [diff] [blame] | 621 | // mole in Chrome. |
Paul Stewart | 1369c2b | 2013-01-11 05:41:26 -0800 | [diff] [blame] | 622 | affected_service->SetFailure(failure); |
| 623 | LOG(ERROR) << "Connection failure is due to suspect credentials: returning " |
| 624 | << Service::ConnectFailureToString(failure); |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 625 | } else { |
| 626 | affected_service->SetFailureSilent(Service::kFailureUnknown); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 627 | } |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 628 | affected_service->NotifyCurrentEndpoint(NULL); |
Thieu Le | 67370f6 | 2012-02-14 23:01:42 +0000 | [diff] [blame] | 629 | metrics()->NotifyServiceDisconnect(affected_service); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 630 | |
| 631 | if (affected_service == pending_service_.get()) { |
| 632 | // The attempt to connect to |pending_service_| failed. Clear |
| 633 | // |pending_service_|, to indicate we're no longer in the middle |
| 634 | // of a connect request. |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 635 | SetPendingService(NULL); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 636 | } else if (pending_service_.get()) { |
| 637 | // We've attributed the disconnection to what was the |
| 638 | // |current_service_|, rather than the |pending_service_|. |
| 639 | // |
| 640 | // If we're wrong about that (i.e. supplicant reported this |
| 641 | // CurrentBSS change after attempting to connect to |
| 642 | // |pending_service_|), we're depending on supplicant to retry |
| 643 | // connecting to |pending_service_|, and delivering another |
| 644 | // CurrentBSS change signal in the future. |
| 645 | // |
| 646 | // Log this fact, to help us debug (in case our assumptions are |
| 647 | // wrong). |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 648 | SLOG(WiFi, 2) << "WiFi " << link_name() << " pending connection to service " |
| 649 | << pending_service_->unique_name() |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 650 | << " after disconnect"; |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 651 | } |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 652 | |
| 653 | // If we disconnect, initially scan at a faster frequency, to make sure |
| 654 | // we've found all available APs. |
| 655 | RestartFastScanAttempts(); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | // We use the term "Roam" loosely. In particular, we include the case |
| 659 | // where we "Roam" to a BSS from the disconnected state. |
| 660 | void WiFi::HandleRoam(const ::DBus::Path &new_bss) { |
| 661 | EndpointMap::iterator endpoint_it = endpoint_by_rpcid_.find(new_bss); |
| 662 | if (endpoint_it == endpoint_by_rpcid_.end()) { |
| 663 | LOG(WARNING) << "WiFi " << link_name() << " connected to unknown BSS " |
| 664 | << new_bss; |
| 665 | return; |
| 666 | } |
| 667 | |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 668 | const WiFiEndpointConstRefPtr endpoint(endpoint_it->second); |
| 669 | WiFiServiceRefPtr service = provider_->FindServiceForEndpoint(endpoint); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 670 | if (!service.get()) { |
| 671 | LOG(WARNING) << "WiFi " << link_name() |
| 672 | << " could not find Service for Endpoint " |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 673 | << endpoint->bssid_string() |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 674 | << " (service will be unchanged)"; |
| 675 | return; |
| 676 | } |
| 677 | |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 678 | SLOG(WiFi, 2) << "WiFi " << link_name() |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 679 | << " roamed to Endpoint " << endpoint->bssid_string() |
| 680 | << " " << LogSSID(endpoint->ssid_string()); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 681 | |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 682 | service->NotifyCurrentEndpoint(endpoint); |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 683 | |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 684 | if (pending_service_.get() && |
| 685 | service.get() != pending_service_.get()) { |
| 686 | // The Service we've roamed on to is not the one we asked for. |
| 687 | // We assume that this is transient, and that wpa_supplicant |
| 688 | // is trying / will try to connect to |pending_service_|. |
| 689 | // |
| 690 | // If it succeeds, we'll end up back here, but with |service| |
| 691 | // pointing at the same service as |pending_service_|. |
| 692 | // |
| 693 | // If it fails, we'll process things in HandleDisconnect. |
| 694 | // |
| 695 | // So we leave |pending_service_| untouched. |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 696 | SLOG(WiFi, 2) << "WiFi " << link_name() |
| 697 | << " new current Endpoint " |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 698 | << endpoint->bssid_string() |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 699 | << " is not part of pending service " |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 700 | << pending_service_->unique_name(); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 701 | |
| 702 | // Sanity check: if we didn't roam onto |pending_service_|, we |
| 703 | // should still be on |current_service_|. |
| 704 | if (service.get() != current_service_.get()) { |
| 705 | LOG(WARNING) << "WiFi " << link_name() |
| 706 | << " new current Endpoint " |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 707 | << endpoint->bssid_string() |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 708 | << " is neither part of pending service " |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 709 | << pending_service_->unique_name() |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 710 | << " nor part of current service " |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 711 | << (current_service_ ? |
| 712 | current_service_->unique_name() : |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 713 | "(NULL)"); |
| 714 | // Although we didn't expect to get here, we should keep |
| 715 | // |current_service_| in sync with what supplicant has done. |
| 716 | current_service_ = service; |
| 717 | } |
| 718 | return; |
| 719 | } |
| 720 | |
| 721 | if (pending_service_.get()) { |
| 722 | // We assume service.get() == pending_service_.get() here, because |
| 723 | // of the return in the previous if clause. |
| 724 | // |
| 725 | // Boring case: we've connected to the service we asked |
| 726 | // for. Simply update |current_service_| and |pending_service_|. |
| 727 | current_service_ = service; |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 728 | SetPendingService(NULL); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 729 | return; |
| 730 | } |
| 731 | |
| 732 | // |pending_service_| was NULL, so we weren't attempting to connect |
| 733 | // to a new Service. Sanity check that we're still on |
| 734 | // |current_service_|. |
| 735 | if (service.get() != current_service_.get()) { |
| 736 | LOG(WARNING) |
| 737 | << "WiFi " << link_name() |
| 738 | << " new current Endpoint " |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 739 | << endpoint->bssid_string() |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 740 | << (current_service_.get() ? |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 741 | StringPrintf(" is not part of current service %s", |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 742 | current_service_->unique_name().c_str()) : |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 743 | " with no current service"); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 744 | // We didn't expect to be here, but let's cope as well as we |
| 745 | // can. Update |current_service_| to keep it in sync with |
| 746 | // supplicant. |
| 747 | current_service_ = service; |
Paul Stewart | abbe279 | 2012-07-15 07:50:35 -0700 | [diff] [blame] | 748 | |
| 749 | // If this service isn't already marked as actively connecting (likely, |
| 750 | // since this service is a bit of a surprise) set the service as |
| 751 | // associating. |
| 752 | if (!current_service_->IsConnecting()) { |
| 753 | current_service_->SetState(Service::kStateAssociating); |
| 754 | } |
| 755 | |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 756 | return; |
| 757 | } |
| 758 | |
| 759 | // At this point, we know that |pending_service_| was NULL, and that |
| 760 | // we're still on |current_service_|. This is the most boring case |
| 761 | // of all, because there's no state to update here. |
| 762 | return; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 763 | } |
| 764 | |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 765 | string WiFi::FindNetworkRpcidForService( |
| 766 | const WiFiService *service, Error *error) { |
| 767 | ReverseServiceMap::const_iterator rpcid_it = |
| 768 | rpcid_by_service_.find(service); |
| 769 | if (rpcid_it == rpcid_by_service_.end()) { |
| 770 | const string error_message = |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 771 | StringPrintf( |
| 772 | "WiFi %s cannot find supplicant network rpcid for service %s", |
| 773 | link_name().c_str(), service->unique_name().c_str()); |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 774 | // There are contexts where this is not an error, such as when a service |
| 775 | // is clearing whatever cached credentials may not exist. |
| 776 | SLOG(WiFi, 2) << error_message; |
| 777 | if (error) { |
| 778 | error->Populate(Error::kNotFound, error_message); |
| 779 | } |
| 780 | return ""; |
| 781 | } |
| 782 | |
| 783 | return rpcid_it->second; |
| 784 | } |
| 785 | |
| 786 | bool WiFi::DisableNetworkForService(const WiFiService *service, Error *error) { |
| 787 | string rpcid = FindNetworkRpcidForService(service, error); |
| 788 | if (rpcid.empty()) { |
| 789 | // Error is already populated. |
| 790 | return false; |
| 791 | } |
| 792 | |
| 793 | if (!DisableNetwork(rpcid)) { |
| 794 | const string error_message = |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 795 | StringPrintf("WiFi %s cannot disable network for service %s: " |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 796 | "DBus operation failed for rpcid %s.", |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 797 | link_name().c_str(), service->unique_name().c_str(), |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 798 | rpcid.c_str()); |
| 799 | Error::PopulateAndLog(error, Error::kOperationFailed, error_message); |
| 800 | |
| 801 | // Make sure that such errored networks are removed, so problems do not |
| 802 | // propogate to future connection attempts. |
| 803 | RemoveNetwork(rpcid); |
| 804 | rpcid_by_service_.erase(service); |
| 805 | |
| 806 | return false; |
| 807 | } |
| 808 | |
| 809 | return true; |
| 810 | } |
| 811 | |
| 812 | bool WiFi::RemoveNetworkForService(const WiFiService *service, Error *error) { |
| 813 | string rpcid = FindNetworkRpcidForService(service, error); |
| 814 | if (rpcid.empty()) { |
| 815 | // Error is already populated. |
| 816 | return false; |
| 817 | } |
| 818 | |
| 819 | // Erase the rpcid from our tables regardless of failure below, since even |
| 820 | // if in failure, we never want to use this network again. |
| 821 | rpcid_by_service_.erase(service); |
| 822 | |
| 823 | // TODO(quiche): Reconsider giving up immediately. Maybe give |
| 824 | // wpa_supplicant some time to retry, first. |
| 825 | if (!RemoveNetwork(rpcid)) { |
| 826 | const string error_message = |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 827 | StringPrintf("WiFi %s cannot remove network for service %s: " |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 828 | "DBus operation failed for rpcid %s.", |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 829 | link_name().c_str(), service->unique_name().c_str(), |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 830 | rpcid.c_str()); |
| 831 | Error::PopulateAndLog(error, Error::kOperationFailed, error_message); |
| 832 | return false; |
| 833 | } |
| 834 | |
| 835 | return true; |
| 836 | } |
| 837 | |
mukesh agrawal | b4bc57d | 2011-12-07 01:07:47 +0000 | [diff] [blame] | 838 | void WiFi::BSSAddedTask( |
| 839 | const ::DBus::Path &path, |
| 840 | const map<string, ::DBus::Variant> &properties) { |
mukesh agrawal | b4bc57d | 2011-12-07 01:07:47 +0000 | [diff] [blame] | 841 | // Note: we assume that BSSIDs are unique across endpoints. This |
| 842 | // means that if an AP reuses the same BSSID for multiple SSIDs, we |
| 843 | // lose. |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 844 | WiFiEndpointRefPtr endpoint( |
| 845 | new WiFiEndpoint(proxy_factory_, this, path, properties)); |
Wade Guthrie | 592ecd5 | 2012-11-12 13:12:30 -0800 | [diff] [blame] | 846 | SLOG(WiFi, 1) << "Found endpoint. " |
| 847 | << "RPC path: " << path << ", " |
Darin Petkov | 50cb78a | 2013-02-06 16:17:49 +0100 | [diff] [blame] | 848 | << LogSSID(endpoint->ssid_string()) << ", " |
Wade Guthrie | 592ecd5 | 2012-11-12 13:12:30 -0800 | [diff] [blame] | 849 | << "bssid: " << endpoint->bssid_string() << ", " |
| 850 | << "signal: " << endpoint->signal_strength() << ", " |
| 851 | << "security: " << endpoint->security_mode() << ", " |
| 852 | << "frequency: " << endpoint->frequency(); |
mukesh agrawal | b4bc57d | 2011-12-07 01:07:47 +0000 | [diff] [blame] | 853 | |
| 854 | if (endpoint->ssid_string().empty()) { |
| 855 | // Don't bother trying to find or create a Service for an Endpoint |
| 856 | // without an SSID. We wouldn't be able to connect to it anyway. |
| 857 | return; |
| 858 | } |
| 859 | |
mukesh agrawal | b385761 | 2012-01-18 16:23:29 -0800 | [diff] [blame] | 860 | if (endpoint->ssid()[0] == 0) { |
| 861 | // Assume that an SSID starting with NULL is bogus/misconfigured, |
| 862 | // and filter it out. |
| 863 | return; |
| 864 | } |
| 865 | |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 866 | provider_->OnEndpointAdded(endpoint); |
mukesh agrawal | b4bc57d | 2011-12-07 01:07:47 +0000 | [diff] [blame] | 867 | |
mukesh agrawal | e9adda1 | 2012-02-09 18:33:48 -0800 | [diff] [blame] | 868 | // Do this last, to maintain the invariant that any Endpoint we |
| 869 | // know about has a corresponding Service. |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 870 | // |
| 871 | // TODO(quiche): Write test to verify correct behavior in the case |
| 872 | // where we get multiple BSSAdded events for a single endpoint. |
| 873 | // (Old Endpoint's refcount should fall to zero, and old Endpoint |
| 874 | // should be destroyed.) |
mukesh agrawal | e9adda1 | 2012-02-09 18:33:48 -0800 | [diff] [blame] | 875 | endpoint_by_rpcid_[path] = endpoint; |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 876 | endpoint->Start(); |
mukesh agrawal | b4bc57d | 2011-12-07 01:07:47 +0000 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | void WiFi::BSSRemovedTask(const ::DBus::Path &path) { |
| 880 | EndpointMap::iterator i = endpoint_by_rpcid_.find(path); |
| 881 | if (i == endpoint_by_rpcid_.end()) { |
| 882 | LOG(WARNING) << "WiFi " << link_name() |
| 883 | << " could not find BSS " << path |
| 884 | << " to remove."; |
| 885 | return; |
| 886 | } |
| 887 | |
| 888 | WiFiEndpointRefPtr endpoint = i->second; |
| 889 | CHECK(endpoint); |
| 890 | endpoint_by_rpcid_.erase(i); |
| 891 | |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 892 | WiFiServiceRefPtr service = provider_->OnEndpointRemoved(endpoint); |
| 893 | if (!service) { |
| 894 | return; |
| 895 | } |
| 896 | Error unused_error; |
| 897 | RemoveNetworkForService(service, &unused_error); |
mukesh agrawal | b4bc57d | 2011-12-07 01:07:47 +0000 | [diff] [blame] | 898 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 899 | bool disconnect_service = !service->HasEndpoints() && |
| 900 | (service->IsConnecting() || service->IsConnected()); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 901 | |
| 902 | if (disconnect_service) { |
| 903 | DisconnectFrom(service); |
| 904 | } |
mukesh agrawal | b4bc57d | 2011-12-07 01:07:47 +0000 | [diff] [blame] | 905 | } |
| 906 | |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 907 | void WiFi::CertificationTask( |
| 908 | const map<string, ::DBus::Variant> &properties) { |
| 909 | if (!current_service_) { |
| 910 | LOG(ERROR) << "WiFi " << link_name() << " " << __func__ |
| 911 | << " with no current service."; |
| 912 | return; |
| 913 | } |
| 914 | |
Paul Stewart | 735eab5 | 2013-03-29 09:19:23 -0700 | [diff] [blame] | 915 | string subject; |
| 916 | uint32 depth; |
| 917 | if (WPASupplicant::ExtractRemoteCertification(properties, &subject, &depth)) { |
| 918 | current_service_->AddEAPCertification(subject, depth); |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 919 | } |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 920 | } |
| 921 | |
Paul Stewart | db0f917 | 2012-11-30 16:48:09 -0800 | [diff] [blame] | 922 | void WiFi::EAPEventTask(const string &status, const string ¶meter) { |
Paul Stewart | db0f917 | 2012-11-30 16:48:09 -0800 | [diff] [blame] | 923 | if (!current_service_) { |
| 924 | LOG(ERROR) << "WiFi " << link_name() << " " << __func__ |
| 925 | << " with no current service."; |
| 926 | return; |
| 927 | } |
Paul Stewart | 735eab5 | 2013-03-29 09:19:23 -0700 | [diff] [blame] | 928 | Service::ConnectFailure failure = Service::kFailureUnknown; |
| 929 | eap_state_handler_->ParseStatus(status, parameter, &failure); |
Paul Stewart | db0f917 | 2012-11-30 16:48:09 -0800 | [diff] [blame] | 930 | if (failure != Service::kFailureUnknown) { |
Paul Stewart | 735eab5 | 2013-03-29 09:19:23 -0700 | [diff] [blame] | 931 | // Avoid a reporting failure twice by resetting EAP state handler early. |
| 932 | eap_state_handler_->Reset(); |
mukesh agrawal | d4dc083 | 2013-03-25 14:38:26 -0700 | [diff] [blame] | 933 | Error unused_error; |
mukesh agrawal | d4dc083 | 2013-03-25 14:38:26 -0700 | [diff] [blame] | 934 | current_service_->DisconnectWithFailure(failure, &unused_error); |
Paul Stewart | db0f917 | 2012-11-30 16:48:09 -0800 | [diff] [blame] | 935 | } |
| 936 | } |
| 937 | |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 938 | void WiFi::PropertiesChangedTask( |
| 939 | const map<string, ::DBus::Variant> &properties) { |
| 940 | // TODO(quiche): Handle changes in other properties (e.g. signal |
| 941 | // strength). |
| 942 | |
| 943 | // Note that order matters here. In particular, we want to process |
| 944 | // changes in the current BSS before changes in state. This is so |
| 945 | // that we update the state of the correct Endpoint/Service. |
| 946 | |
| 947 | map<string, ::DBus::Variant>::const_iterator properties_it = |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 948 | properties.find(WPASupplicant::kInterfacePropertyCurrentBSS); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 949 | if (properties_it != properties.end()) { |
| 950 | CurrentBSSChanged(properties_it->second.reader().get_path()); |
| 951 | } |
| 952 | |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 953 | properties_it = properties.find(WPASupplicant::kInterfacePropertyState); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 954 | if (properties_it != properties.end()) { |
| 955 | StateChanged(properties_it->second.reader().get_string()); |
| 956 | } |
| 957 | } |
| 958 | |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 959 | void WiFi::ScanDoneTask() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 960 | SLOG(WiFi, 2) << __func__ << " need_bss_flush_ " << need_bss_flush_; |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 961 | if (need_bss_flush_) { |
| 962 | CHECK(supplicant_interface_proxy_ != NULL); |
| 963 | // Compute |max_age| relative to |resumed_at_|, to account for the |
| 964 | // time taken to scan. |
| 965 | struct timeval now; |
| 966 | uint32_t max_age; |
| 967 | time_->GetTimeMonotonic(&now); |
| 968 | max_age = kMaxBSSResumeAgeSeconds + (now.tv_sec - resumed_at_.tv_sec); |
| 969 | supplicant_interface_proxy_->FlushBSS(max_age); |
| 970 | need_bss_flush_ = false; |
| 971 | } |
Paul Stewart | d2db2b1 | 2013-01-17 13:11:07 -0800 | [diff] [blame] | 972 | SetScanPending(false); |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 973 | StartScanTimer(); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 974 | } |
| 975 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 976 | void WiFi::ScanTask() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 977 | SLOG(WiFi, 2) << "WiFi " << link_name() << " scan requested."; |
Paul Stewart | fae4dae | 2012-09-13 07:43:32 -0700 | [diff] [blame] | 978 | if (!enabled()) { |
| 979 | SLOG(WiFi, 2) << "Ignoring scan request while device is not enabled."; |
| 980 | return; |
| 981 | } |
| 982 | if (!supplicant_present_ || !supplicant_interface_proxy_.get()) { |
| 983 | SLOG(WiFi, 2) << "Ignoring scan request while supplicant is not present."; |
| 984 | return; |
| 985 | } |
Christopher Wiley | c68c867 | 2012-11-20 16:52:21 -0800 | [diff] [blame] | 986 | if ((pending_service_.get() && pending_service_->IsConnecting()) || |
| 987 | (current_service_.get() && current_service_->IsConnecting())) { |
| 988 | SLOG(WiFi, 2) << "Ignoring scan request while connecting to an AP."; |
| 989 | return; |
| 990 | } |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 991 | map<string, DBus::Variant> scan_args; |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 992 | scan_args[WPASupplicant::kPropertyScanType].writer(). |
| 993 | append_string(WPASupplicant::kScanTypeActive); |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 994 | |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 995 | ByteArrays hidden_ssids = provider_->GetHiddenSSIDList(); |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 996 | if (!hidden_ssids.empty()) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 997 | // TODO(pstew): Devise a better method for time-sharing with SSIDs that do |
| 998 | // not fit in. |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 999 | if (hidden_ssids.size() >= WPASupplicant::kScanMaxSSIDsPerScan) { |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 1000 | hidden_ssids.erase( |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 1001 | hidden_ssids.begin() + WPASupplicant::kScanMaxSSIDsPerScan - 1, |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 1002 | hidden_ssids.end()); |
| 1003 | } |
| 1004 | // Add Broadcast SSID, signified by an empty ByteArray. If we specify |
| 1005 | // SSIDs to wpa_supplicant, we need to explicitly specify the default |
| 1006 | // behavior of doing a broadcast probe. |
| 1007 | hidden_ssids.push_back(ByteArray()); |
| 1008 | |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 1009 | scan_args[WPASupplicant::kPropertyScanSSIDs] = |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 1010 | DBusAdaptor::ByteArraysToVariant(hidden_ssids); |
| 1011 | } |
| 1012 | |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 1013 | try { |
| 1014 | supplicant_interface_proxy_->Scan(scan_args); |
Paul Stewart | d2db2b1 | 2013-01-17 13:11:07 -0800 | [diff] [blame] | 1015 | SetScanPending(true); |
Ben Chan | 80326f3 | 2012-05-04 17:51:32 -0700 | [diff] [blame] | 1016 | } catch (const DBus::Error &e) { // NOLINT |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 1017 | // A scan may fail if, for example, the wpa_supplicant vanishing |
| 1018 | // notification is posted after this task has already started running. |
| 1019 | LOG(WARNING) << "Scan failed: " << e.what(); |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 1020 | } |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
Paul Stewart | d2db2b1 | 2013-01-17 13:11:07 -0800 | [diff] [blame] | 1023 | void WiFi::SetScanPending(bool pending) { |
| 1024 | if (scan_pending_ != pending) { |
| 1025 | scan_pending_ = pending; |
| 1026 | adaptor()->EmitBoolChanged(flimflam::kScanningProperty, pending); |
| 1027 | } |
| 1028 | } |
| 1029 | |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 1030 | string WiFi::GetServiceLeaseName(const WiFiService &service) { |
| 1031 | return service.GetStorageIdentifier(); |
| 1032 | } |
| 1033 | |
| 1034 | void WiFi::DestroyServiceLease(const WiFiService &service) { |
| 1035 | DestroyIPConfigLease(GetServiceLeaseName(service)); |
| 1036 | } |
| 1037 | |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1038 | void WiFi::StateChanged(const string &new_state) { |
| 1039 | const string old_state = supplicant_state_; |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 1040 | supplicant_state_ = new_state; |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1041 | LOG(INFO) << "WiFi " << link_name() << " " << __func__ << " " |
| 1042 | << old_state << " -> " << new_state; |
| 1043 | |
| 1044 | WiFiService *affected_service; |
| 1045 | // Identify the service to which the state change applies. If |
| 1046 | // |pending_service_| is non-NULL, then the state change applies to |
| 1047 | // |pending_service_|. Otherwise, it applies to |current_service_|. |
| 1048 | // |
| 1049 | // This policy is driven by the fact that the |pending_service_| |
| 1050 | // doesn't become the |current_service_| until wpa_supplicant |
| 1051 | // reports a CurrentBSS change to the |pending_service_|. And the |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 1052 | // CurrentBSS change won't be reported until the |pending_service_| |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 1053 | // reaches the WPASupplicant::kInterfaceStateCompleted state. |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1054 | affected_service = |
| 1055 | pending_service_.get() ? pending_service_.get() : current_service_.get(); |
| 1056 | if (!affected_service) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1057 | SLOG(WiFi, 2) << "WiFi " << link_name() << " " << __func__ |
| 1058 | << " with no service"; |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1059 | return; |
| 1060 | } |
| 1061 | |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 1062 | if (new_state == WPASupplicant::kInterfaceStateCompleted) { |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1063 | if (affected_service->IsConnected()) { |
| 1064 | StopReconnectTimer(); |
Christopher Wiley | 5519e9e | 2013-01-08 16:55:56 -0800 | [diff] [blame] | 1065 | EnableHighBitrates(); |
Christopher Wiley | 8f81e2a | 2012-10-17 16:51:32 -0700 | [diff] [blame] | 1066 | } else if (has_already_completed_) { |
| 1067 | LOG(INFO) << link_name() << " L3 configuration already started."; |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1068 | } else if (AcquireIPConfigWithLeaseName( |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 1069 | GetServiceLeaseName(*affected_service))) { |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 1070 | LOG(INFO) << link_name() << " is up; started L3 configuration."; |
mukesh agrawal | c01f398 | 2012-01-24 13:48:39 -0800 | [diff] [blame] | 1071 | affected_service->SetState(Service::kStateConfiguring); |
| 1072 | } else { |
| 1073 | LOG(ERROR) << "Unable to acquire DHCP config."; |
| 1074 | } |
Christopher Wiley | 8f81e2a | 2012-10-17 16:51:32 -0700 | [diff] [blame] | 1075 | has_already_completed_ = true; |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 1076 | } else if (new_state == WPASupplicant::kInterfaceStateAssociated) { |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1077 | affected_service->SetState(Service::kStateAssociating); |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 1078 | } else if (new_state == WPASupplicant::kInterfaceStateAuthenticating || |
| 1079 | new_state == WPASupplicant::kInterfaceStateAssociating || |
| 1080 | new_state == WPASupplicant::kInterfaceState4WayHandshake || |
| 1081 | new_state == WPASupplicant::kInterfaceStateGroupHandshake) { |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1082 | // Ignore transitions into these states from Completed, to avoid |
| 1083 | // bothering the user when roaming, or re-keying. |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 1084 | if (old_state != WPASupplicant::kInterfaceStateCompleted) |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1085 | affected_service->SetState(Service::kStateAssociating); |
| 1086 | // TOOD(quiche): On backwards transitions, we should probably set |
| 1087 | // a timeout for getting back into the completed state. At present, |
| 1088 | // we depend on wpa_supplicant eventually reporting that CurrentBSS |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1089 | // has changed. But there may be cases where that signal is not sent. |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1090 | // (crosbug.com/23207) |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 1091 | } else if (new_state == WPASupplicant::kInterfaceStateDisconnected && |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1092 | affected_service == current_service_ && |
| 1093 | affected_service->IsConnected()) { |
| 1094 | // This means that wpa_supplicant failed in a re-connect attempt, but |
| 1095 | // may still be reconnecting. Give wpa_supplicant a limited amount of |
| 1096 | // time to transition out this condition by either connecting or changing |
| 1097 | // CurrentBSS. |
| 1098 | StartReconnectTimer(); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 1099 | } else { |
| 1100 | // Other transitions do not affect Service state. |
| 1101 | // |
| 1102 | // Note in particular that we ignore a State change into |
| 1103 | // kInterfaceStateDisconnected, in favor of observing the corresponding |
| 1104 | // change in CurrentBSS. |
| 1105 | } |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 1106 | } |
| 1107 | |
Paul Stewart | 1369c2b | 2013-01-11 05:41:26 -0800 | [diff] [blame] | 1108 | bool WiFi::SuspectCredentials( |
| 1109 | const WiFiService &service, Service::ConnectFailure *failure) const { |
Paul Stewart | 1369c2b | 2013-01-11 05:41:26 -0800 | [diff] [blame] | 1110 | if (service.IsSecurityMatch(flimflam::kSecurityPsk)) { |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 1111 | if (supplicant_state_ == WPASupplicant::kInterfaceState4WayHandshake && |
Paul Stewart | 1369c2b | 2013-01-11 05:41:26 -0800 | [diff] [blame] | 1112 | !service.has_ever_connected()) { |
| 1113 | if (failure) { |
| 1114 | *failure = Service::kFailureBadPassphrase; |
| 1115 | } |
| 1116 | return true; |
| 1117 | } |
| 1118 | } else if (service.IsSecurityMatch(flimflam::kSecurity8021x)) { |
Paul Stewart | 735eab5 | 2013-03-29 09:19:23 -0700 | [diff] [blame] | 1119 | if (eap_state_handler_->is_eap_in_progress() && |
| 1120 | !service.has_ever_connected()) { |
Paul Stewart | 1369c2b | 2013-01-11 05:41:26 -0800 | [diff] [blame] | 1121 | if (failure) { |
| 1122 | *failure = Service::kFailureEAPAuthentication; |
| 1123 | } |
| 1124 | return true; |
| 1125 | } |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
Paul Stewart | 1369c2b | 2013-01-11 05:41:26 -0800 | [diff] [blame] | 1128 | return false; |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 1129 | } |
| 1130 | |
mukesh agrawal | 16bc1b8 | 2012-02-09 18:38:26 -0800 | [diff] [blame] | 1131 | // static |
| 1132 | bool WiFi::SanitizeSSID(string *ssid) { |
| 1133 | CHECK(ssid); |
| 1134 | |
| 1135 | size_t ssid_len = ssid->length(); |
| 1136 | size_t i; |
| 1137 | bool changed = false; |
| 1138 | |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 1139 | for (i = 0; i < ssid_len; ++i) { |
mukesh agrawal | 16bc1b8 | 2012-02-09 18:38:26 -0800 | [diff] [blame] | 1140 | if (!g_ascii_isprint((*ssid)[i])) { |
| 1141 | (*ssid)[i] = '?'; |
| 1142 | changed = true; |
| 1143 | } |
| 1144 | } |
| 1145 | |
| 1146 | return changed; |
| 1147 | } |
| 1148 | |
Darin Petkov | 50cb78a | 2013-02-06 16:17:49 +0100 | [diff] [blame] | 1149 | // static |
| 1150 | string WiFi::LogSSID(const string &ssid) { |
| 1151 | string out; |
| 1152 | for (string::const_iterator it = ssid.begin(); it != ssid.end(); ++it) { |
| 1153 | // Replace '[' and ']' (in addition to non-printable characters) so that |
| 1154 | // it's easy to match the right substring through a non-greedy regex. |
| 1155 | if (*it == '[' || *it == ']' || !g_ascii_isprint(*it)) { |
| 1156 | base::StringAppendF(&out, "\\x%02x", *it); |
| 1157 | } else { |
| 1158 | out += *it; |
| 1159 | } |
| 1160 | } |
| 1161 | return StringPrintf("[SSID=%s]", out.c_str()); |
| 1162 | } |
| 1163 | |
Paul Stewart | 3c508e1 | 2012-08-09 11:40:06 -0700 | [diff] [blame] | 1164 | void WiFi::OnLinkMonitorFailure() { |
| 1165 | // If we have never found the gateway, let's be conservative and not |
| 1166 | // do anything, in case this network topology does not have a gateway. |
| 1167 | if (!link_monitor()->IsGatewayFound()) { |
| 1168 | LOG(INFO) << "In " << __func__ << "(): " |
| 1169 | << "Skipping reassociate since gateway was never found."; |
| 1170 | return; |
| 1171 | } |
| 1172 | |
| 1173 | if (!supplicant_present_) { |
| 1174 | LOG(ERROR) << "In " << __func__ << "(): " |
| 1175 | << "wpa_supplicant is not present. Cannot reassociate."; |
| 1176 | return; |
| 1177 | } |
| 1178 | |
| 1179 | try { |
Christopher Wiley | e0b2a01 | 2012-10-31 13:11:27 -0700 | [diff] [blame] | 1180 | // This will force a transition out of connected, if we are actually |
| 1181 | // connected. |
Paul Stewart | 3c508e1 | 2012-08-09 11:40:06 -0700 | [diff] [blame] | 1182 | supplicant_interface_proxy_->Reassociate(); |
Christopher Wiley | e0b2a01 | 2012-10-31 13:11:27 -0700 | [diff] [blame] | 1183 | // If we don't eventually get a transition back into a connected state, |
| 1184 | // there is something wrong. |
| 1185 | StartReconnectTimer(); |
Paul Stewart | 3c508e1 | 2012-08-09 11:40:06 -0700 | [diff] [blame] | 1186 | LOG(INFO) << "In " << __func__ << "(): Called Reassociate()."; |
| 1187 | } catch (const DBus::Error &e) { // NOLINT |
| 1188 | LOG(ERROR) << "In " << __func__ << "(): failed to call Reassociate()."; |
| 1189 | return; |
| 1190 | } |
| 1191 | } |
| 1192 | |
Arman Uguray | ed8e610 | 2012-11-29 14:47:20 -0800 | [diff] [blame] | 1193 | bool WiFi::ShouldUseArpGateway() const { |
| 1194 | return true; |
| 1195 | } |
| 1196 | |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 1197 | void WiFi::DisassociateFromService(const WiFiServiceRefPtr &service) { |
| 1198 | DisconnectFrom(service); |
| 1199 | if (service == selected_service()) { |
| 1200 | DropConnection(); |
| 1201 | } |
| 1202 | Error unused_error; |
| 1203 | RemoveNetworkForService(service, &unused_error); |
| 1204 | } |
| 1205 | |
Gaurav Shah | 6d2c72d | 2012-10-16 16:30:44 -0700 | [diff] [blame] | 1206 | vector<GeolocationInfo> WiFi::GetGeolocationObjects() const { |
| 1207 | vector<GeolocationInfo> objects; |
| 1208 | for (EndpointMap::const_iterator it = endpoint_by_rpcid_.begin(); |
| 1209 | it != endpoint_by_rpcid_.end(); |
| 1210 | ++it) { |
| 1211 | GeolocationInfo geoinfo; |
| 1212 | WiFiEndpointRefPtr endpoint = it->second; |
| 1213 | geoinfo.AddField(kGeoMacAddressProperty, endpoint->bssid_string()); |
| 1214 | geoinfo.AddField(kGeoSignalStrengthProperty, |
| 1215 | StringPrintf("%d", endpoint->signal_strength())); |
| 1216 | geoinfo.AddField( |
| 1217 | kGeoChannelProperty, |
| 1218 | StringPrintf("%d", |
| 1219 | Metrics::WiFiFrequencyToChannel(endpoint->frequency()))); |
| 1220 | // TODO(gauravsh): Include age field. crosbug.com/35445 |
| 1221 | objects.push_back(geoinfo); |
| 1222 | } |
| 1223 | return objects; |
| 1224 | } |
| 1225 | |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 1226 | void WiFi::HelpRegisterDerivedInt32( |
| 1227 | PropertyStore *store, |
| 1228 | const string &name, |
| 1229 | int32(WiFi::*get)(Error *error), |
| 1230 | void(WiFi::*set)(const int32 &value, Error *error)) { |
| 1231 | store->RegisterDerivedInt32( |
| 1232 | name, |
| 1233 | Int32Accessor(new CustomAccessor<WiFi, int32>(this, get, set))); |
| 1234 | } |
| 1235 | |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 1236 | void WiFi::HelpRegisterDerivedUint16( |
| 1237 | PropertyStore *store, |
| 1238 | const string &name, |
| 1239 | uint16(WiFi::*get)(Error *error), |
| 1240 | void(WiFi::*set)(const uint16 &value, Error *error)) { |
| 1241 | store->RegisterDerivedUint16( |
| 1242 | name, |
| 1243 | Uint16Accessor(new CustomAccessor<WiFi, uint16>(this, get, set))); |
| 1244 | } |
| 1245 | |
mukesh agrawal | 2f9df4e | 2012-08-08 12:29:20 -0700 | [diff] [blame] | 1246 | void WiFi::OnAfterResume() { |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 1247 | LOG(INFO) << __func__; |
mukesh agrawal | 2f9df4e | 2012-08-08 12:29:20 -0700 | [diff] [blame] | 1248 | Device::OnAfterResume(); // May refresh ipconfig_ |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 1249 | |
mukesh agrawal | 2f9df4e | 2012-08-08 12:29:20 -0700 | [diff] [blame] | 1250 | // We want to flush the BSS cache, but we don't want to conflict |
| 1251 | // with a running scan or an active connection attempt. So record |
| 1252 | // the need to flush, and take care of flushing when the next scan |
| 1253 | // completes. |
| 1254 | // |
| 1255 | // Note that supplicant will automatically expire old cache |
| 1256 | // entries (after, e.g., a BSS is not found in two consecutive |
| 1257 | // scans). However, our explicit flush accelerates re-association |
| 1258 | // in cases where a BSS disappeared while we were asleep. (See, |
| 1259 | // e.g. WiFiRoaming.005SuspendRoam.) |
| 1260 | time_->GetTimeMonotonic(&resumed_at_); |
| 1261 | need_bss_flush_ = true; |
| 1262 | |
| 1263 | if (!scan_pending_ && IsIdle()) { |
| 1264 | // Not scanning/connecting/connected, so let's get things rolling. |
| 1265 | Scan(NULL); |
| 1266 | } else { |
| 1267 | SLOG(WiFi, 1) << __func__ |
| 1268 | << " skipping scan, already scanning or connected."; |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 1269 | } |
| 1270 | } |
| 1271 | |
Christopher Wiley | 5519e9e | 2013-01-08 16:55:56 -0800 | [diff] [blame] | 1272 | void WiFi::OnConnected() { |
| 1273 | Device::OnConnected(); |
| 1274 | EnableHighBitrates(); |
| 1275 | } |
| 1276 | |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 1277 | void WiFi::RestartFastScanAttempts() { |
| 1278 | fast_scans_remaining_ = kNumFastScanAttempts; |
| 1279 | StartScanTimer(); |
| 1280 | } |
| 1281 | |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 1282 | void WiFi::StartScanTimer() { |
| 1283 | if (scan_interval_seconds_ == 0) { |
| 1284 | StopScanTimer(); |
| 1285 | return; |
| 1286 | } |
| 1287 | scan_timer_callback_.Reset( |
| 1288 | Bind(&WiFi::ScanTimerHandler, weak_ptr_factory_.GetWeakPtr())); |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 1289 | // Repeat the first few scans after disconnect relatively quickly so we |
| 1290 | // have reasonable trust that no APs we are looking for are present. |
| 1291 | dispatcher()->PostDelayedTask(scan_timer_callback_.callback(), |
| 1292 | fast_scans_remaining_ > 0 ? |
| 1293 | kFastScanIntervalSeconds * 1000 : scan_interval_seconds_ * 1000); |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | void WiFi::StopScanTimer() { |
| 1297 | scan_timer_callback_.Cancel(); |
| 1298 | } |
| 1299 | |
| 1300 | void WiFi::ScanTimerHandler() { |
| 1301 | SLOG(WiFi, 2) << "WiFi Device " << link_name() << ": " << __func__; |
| 1302 | if (IsIdle() && !scan_pending_) { |
| 1303 | Scan(NULL); |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 1304 | if (fast_scans_remaining_ > 0) { |
| 1305 | --fast_scans_remaining_; |
| 1306 | } |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 1307 | } |
| 1308 | StartScanTimer(); |
| 1309 | } |
| 1310 | |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 1311 | void WiFi::StartPendingTimer() { |
| 1312 | pending_timeout_callback_.Reset( |
| 1313 | Bind(&WiFi::PendingTimeoutHandler, weak_ptr_factory_.GetWeakPtr())); |
| 1314 | dispatcher()->PostDelayedTask(pending_timeout_callback_.callback(), |
| 1315 | kPendingTimeoutSeconds * 1000); |
| 1316 | } |
| 1317 | |
| 1318 | void WiFi::StopPendingTimer() { |
| 1319 | pending_timeout_callback_.Cancel(); |
| 1320 | } |
| 1321 | |
| 1322 | void WiFi::SetPendingService(const WiFiServiceRefPtr &service) { |
Paul Stewart | ff96a84 | 2012-08-13 15:59:10 -0700 | [diff] [blame] | 1323 | SLOG(WiFi, 2) << "WiFi " << link_name() << " setting pending service to " |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 1324 | << (service ? service->unique_name(): "NULL"); |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 1325 | if (service) { |
| 1326 | service->SetState(Service::kStateAssociating); |
| 1327 | StartPendingTimer(); |
| 1328 | } else if (pending_service_) { |
| 1329 | StopPendingTimer(); |
| 1330 | } |
| 1331 | pending_service_ = service; |
| 1332 | } |
| 1333 | |
| 1334 | void WiFi::PendingTimeoutHandler() { |
mukesh agrawal | d4dc083 | 2013-03-25 14:38:26 -0700 | [diff] [blame] | 1335 | Error unused_error; |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 1336 | LOG(INFO) << "WiFi Device " << link_name() << ": " << __func__; |
| 1337 | CHECK(pending_service_); |
mukesh agrawal | d4dc083 | 2013-03-25 14:38:26 -0700 | [diff] [blame] | 1338 | pending_service_->DisconnectWithFailure( |
| 1339 | Service::kFailureOutOfRange, &unused_error); |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 1340 | } |
| 1341 | |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1342 | void WiFi::StartReconnectTimer() { |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 1343 | if (!reconnect_timeout_callback_.IsCancelled()) { |
| 1344 | LOG(INFO) << "WiFi Device " << link_name() << ": " << __func__ |
| 1345 | << ": reconnect timer already running."; |
| 1346 | return; |
| 1347 | } |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1348 | LOG(INFO) << "WiFi Device " << link_name() << ": " << __func__; |
| 1349 | reconnect_timeout_callback_.Reset( |
| 1350 | Bind(&WiFi::ReconnectTimeoutHandler, weak_ptr_factory_.GetWeakPtr())); |
| 1351 | dispatcher()->PostDelayedTask(reconnect_timeout_callback_.callback(), |
| 1352 | kReconnectTimeoutSeconds * 1000); |
| 1353 | } |
| 1354 | |
| 1355 | void WiFi::StopReconnectTimer() { |
| 1356 | SLOG(WiFi, 2) << "WiFi Device " << link_name() << ": " << __func__; |
| 1357 | reconnect_timeout_callback_.Cancel(); |
| 1358 | } |
| 1359 | |
| 1360 | void WiFi::ReconnectTimeoutHandler() { |
| 1361 | LOG(INFO) << "WiFi Device " << link_name() << ": " << __func__; |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 1362 | reconnect_timeout_callback_.Cancel(); |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 1363 | CHECK(current_service_); |
| 1364 | current_service_->SetFailureSilent(Service::kFailureConnect); |
| 1365 | DisconnectFrom(current_service_); |
| 1366 | } |
| 1367 | |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 1368 | void WiFi::OnSupplicantAppear(const string &/*owner*/) { |
| 1369 | LOG(INFO) << "WPA supplicant appeared."; |
| 1370 | if (supplicant_present_) { |
Darin Petkov | 9cd7ca1 | 2012-07-03 11:06:40 +0200 | [diff] [blame] | 1371 | // Restart the WiFi device if it's started already. This will reset the |
| 1372 | // state and connect the device to the new WPA supplicant instance. |
| 1373 | if (enabled()) { |
| 1374 | Restart(); |
| 1375 | } |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 1376 | return; |
| 1377 | } |
| 1378 | supplicant_present_ = true; |
| 1379 | ConnectToSupplicant(); |
| 1380 | } |
| 1381 | |
| 1382 | void WiFi::OnSupplicantVanish() { |
| 1383 | LOG(INFO) << "WPA supplicant vanished."; |
| 1384 | if (!supplicant_present_) { |
| 1385 | return; |
| 1386 | } |
| 1387 | supplicant_present_ = false; |
| 1388 | // Restart the WiFi device if it's started already. This will effectively |
| 1389 | // suspend the device until the WPA supplicant reappears. |
| 1390 | if (enabled()) { |
| 1391 | Restart(); |
| 1392 | } |
| 1393 | } |
| 1394 | |
Paul Stewart | 5581d07 | 2012-12-17 17:30:20 -0800 | [diff] [blame] | 1395 | void WiFi::OnWiFiDebugScopeChanged(bool enabled) { |
| 1396 | SLOG(WiFi, 2) << "WiFi debug scope changed; enable is now " << enabled; |
| 1397 | if (!supplicant_process_proxy_.get()) { |
| 1398 | SLOG(WiFi, 2) << "Suplicant process proxy not present."; |
| 1399 | return; |
| 1400 | } |
| 1401 | string current_level; |
| 1402 | try { |
| 1403 | current_level = supplicant_process_proxy_->GetDebugLevel(); |
| 1404 | } catch (const DBus::Error &e) { // NOLINT |
| 1405 | LOG(ERROR) << __func__ << ": Failed to get wpa_supplicant debug level."; |
| 1406 | return; |
| 1407 | } |
| 1408 | |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 1409 | if (current_level != WPASupplicant::kDebugLevelInfo && |
| 1410 | current_level != WPASupplicant::kDebugLevelDebug) { |
Paul Stewart | 5581d07 | 2012-12-17 17:30:20 -0800 | [diff] [blame] | 1411 | SLOG(WiFi, 2) << "WiFi debug level is currently " |
| 1412 | << current_level |
| 1413 | << "; assuming that it is being controlled elsewhere."; |
| 1414 | return; |
| 1415 | } |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 1416 | string new_level = enabled ? WPASupplicant::kDebugLevelDebug : |
| 1417 | WPASupplicant::kDebugLevelInfo; |
Paul Stewart | 5581d07 | 2012-12-17 17:30:20 -0800 | [diff] [blame] | 1418 | |
| 1419 | if (new_level == current_level) { |
| 1420 | SLOG(WiFi, 2) << "WiFi debug level is already the desired level " |
| 1421 | << current_level; |
| 1422 | return; |
| 1423 | } |
| 1424 | |
| 1425 | try { |
| 1426 | supplicant_process_proxy_->SetDebugLevel(new_level); |
| 1427 | } catch (const DBus::Error &e) { // NOLINT |
| 1428 | LOG(ERROR) << __func__ << ": Failed to set wpa_supplicant debug level."; |
| 1429 | } |
| 1430 | } |
| 1431 | |
Paul Stewart | a47c3c6 | 2012-12-18 12:14:29 -0800 | [diff] [blame] | 1432 | void WiFi::SetConnectionDebugging(bool enabled) { |
| 1433 | if (is_debugging_connection_ == enabled) { |
| 1434 | return; |
| 1435 | } |
| 1436 | OnWiFiDebugScopeChanged( |
| 1437 | enabled || |
| 1438 | ScopeLogger::GetInstance()->IsScopeEnabled(ScopeLogger::kWiFi)); |
| 1439 | is_debugging_connection_ = enabled; |
| 1440 | } |
| 1441 | |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 1442 | void WiFi::ConnectToSupplicant() { |
| 1443 | LOG(INFO) << link_name() << ": " << (enabled() ? "enabled" : "disabled") |
| 1444 | << " supplicant: " |
| 1445 | << (supplicant_present_ ? "present" : "absent") |
| 1446 | << " proxy: " |
| 1447 | << (supplicant_process_proxy_.get() ? "non-null" : "null"); |
| 1448 | if (!enabled() || !supplicant_present_ || supplicant_process_proxy_.get()) { |
| 1449 | return; |
| 1450 | } |
| 1451 | supplicant_process_proxy_.reset( |
| 1452 | proxy_factory_->CreateSupplicantProcessProxy( |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 1453 | WPASupplicant::kDBusPath, WPASupplicant::kDBusAddr)); |
Paul Stewart | 5581d07 | 2012-12-17 17:30:20 -0800 | [diff] [blame] | 1454 | OnWiFiDebugScopeChanged( |
| 1455 | ScopeLogger::GetInstance()->IsScopeEnabled(ScopeLogger::kWiFi)); |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 1456 | ::DBus::Path interface_path; |
| 1457 | try { |
| 1458 | map<string, DBus::Variant> create_interface_args; |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 1459 | create_interface_args[WPASupplicant::kInterfacePropertyName].writer(). |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 1460 | append_string(link_name().c_str()); |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 1461 | create_interface_args[WPASupplicant::kInterfacePropertyDriver].writer(). |
| 1462 | append_string(WPASupplicant::kDriverNL80211); |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 1463 | create_interface_args[ |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 1464 | WPASupplicant::kInterfacePropertyConfigFile].writer(). |
Paul Stewart | 196f50f | 2013-03-27 18:02:11 -0700 | [diff] [blame] | 1465 | append_string(WPASupplicant::kSupplicantConfPath); |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 1466 | interface_path = |
| 1467 | supplicant_process_proxy_->CreateInterface(create_interface_args); |
| 1468 | } catch (const DBus::Error &e) { // NOLINT |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 1469 | if (!strcmp(e.name(), WPASupplicant::kErrorInterfaceExists)) { |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 1470 | interface_path = |
| 1471 | supplicant_process_proxy_->GetInterface(link_name()); |
| 1472 | // TODO(quiche): Is it okay to crash here, if device is missing? |
| 1473 | } else { |
Paul Stewart | b80c81c | 2012-06-28 13:05:45 -0700 | [diff] [blame] | 1474 | LOG(ERROR) << __func__ << ": Failed to create interface with supplicant."; |
| 1475 | return; |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | supplicant_interface_proxy_.reset( |
| 1480 | proxy_factory_->CreateSupplicantInterfaceProxy( |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 1481 | this, interface_path, WPASupplicant::kDBusAddr)); |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 1482 | |
| 1483 | RTNLHandler::GetInstance()->SetInterfaceFlags(interface_index(), IFF_UP, |
| 1484 | IFF_UP); |
| 1485 | // TODO(quiche) Set ApScan=1 and BSSExpireAge=190, like flimflam does? |
| 1486 | |
| 1487 | // Clear out any networks that might previously have been configured |
| 1488 | // for this interface. |
| 1489 | supplicant_interface_proxy_->RemoveAllNetworks(); |
| 1490 | |
| 1491 | // Flush interface's BSS cache, so that we get BSSAdded signals for |
| 1492 | // all BSSes (not just new ones since the last scan). |
| 1493 | supplicant_interface_proxy_->FlushBSS(0); |
| 1494 | |
| 1495 | try { |
| 1496 | // TODO(pstew): Disable fast_reauth until supplicant can properly deal |
| 1497 | // with RADIUS servers that respond strangely to such requests. |
| 1498 | // crosbug.com/25630 |
| 1499 | supplicant_interface_proxy_->SetFastReauth(false); |
| 1500 | } catch (const DBus::Error &e) { // NOLINT |
Christopher Wiley | 5519e9e | 2013-01-08 16:55:56 -0800 | [diff] [blame] | 1501 | LOG(ERROR) << "Failed to disable fast_reauth. " |
| 1502 | << "May be running an older version of wpa_supplicant."; |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | try { |
| 1506 | // Helps with passing WiFiRomaing.001SSIDSwitchBack. |
| 1507 | supplicant_interface_proxy_->SetScanInterval(kRescanIntervalSeconds); |
| 1508 | } catch (const DBus::Error &e) { // NOLINT |
Christopher Wiley | 5519e9e | 2013-01-08 16:55:56 -0800 | [diff] [blame] | 1509 | LOG(ERROR) << "Failed to set scan_interval. " |
| 1510 | << "May be running an older version of wpa_supplicant."; |
| 1511 | } |
| 1512 | |
| 1513 | try { |
| 1514 | supplicant_interface_proxy_->SetDisableHighBitrates(true); |
| 1515 | } catch (const DBus::Error &e) { // NOLINT |
| 1516 | LOG(ERROR) << "Failed to disable high bitrates. " |
| 1517 | << "May be running an older version of wpa_supplicant."; |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 1518 | } |
| 1519 | |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 1520 | Scan(NULL); |
| 1521 | StartScanTimer(); |
| 1522 | } |
| 1523 | |
Christopher Wiley | 5519e9e | 2013-01-08 16:55:56 -0800 | [diff] [blame] | 1524 | void WiFi::EnableHighBitrates() { |
| 1525 | LOG(INFO) << "Enabling high bitrates."; |
| 1526 | try { |
| 1527 | supplicant_interface_proxy_->EnableHighBitrates(); |
| 1528 | } catch (const DBus::Error &e) { // NOLINT |
| 1529 | LOG(ERROR) << "exception while enabling high rates: " << e.what(); |
| 1530 | } |
| 1531 | } |
| 1532 | |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 1533 | void WiFi::Restart() { |
| 1534 | LOG(INFO) << link_name() << " restarting."; |
| 1535 | WiFiRefPtr me = this; // Make sure we don't get destructed. |
| 1536 | // Go through the manager rather than starting and stopping the device |
| 1537 | // directly so that the device can be configured with the profile. |
| 1538 | manager()->DeregisterDevice(me); |
| 1539 | manager()->RegisterDevice(me); |
| 1540 | } |
| 1541 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 1542 | } // namespace shill |