blob: a2be8e5e6a8b891f95124fd393dd3aa4006bb480 [file] [log] [blame]
mukesh agrawal8a3188d2011-12-01 20:56:44 +00001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Paul Stewartb50f0b92011-05-16 16:31:42 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Chris Masone2b105542011-06-22 10:58:09 -07005#include "shill/wifi.h"
6
Paul Stewartb50f0b92011-05-16 16:31:42 -07007#include <stdio.h>
mukesh agrawalc7426a42011-06-03 13:04:28 -07008#include <string.h>
mukesh agrawalf2f68a52011-09-01 12:15:48 -07009#include <netinet/ether.h>
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -070010#include <linux/if.h> // Needs definitions from netinet/ether.h
Paul Stewartb50f0b92011-05-16 16:31:42 -070011
mukesh agrawal8a3188d2011-12-01 20:56:44 +000012#include <algorithm>
mukesh agrawalab87ea42011-05-18 11:44:49 -070013#include <map>
Paul Stewartb50f0b92011-05-16 16:31:42 -070014#include <string>
mukesh agrawalab87ea42011-05-18 11:44:49 -070015#include <vector>
Paul Stewartb50f0b92011-05-16 16:31:42 -070016
Eric Shienbrood3e20a232012-02-16 11:35:56 -050017#include <base/bind.h>
mukesh agrawal15908392011-11-16 18:29:25 +000018#include <base/stringprintf.h>
mukesh agrawal7a4e4002011-09-06 11:26:05 -070019#include <base/string_util.h>
Chris Masoneb925cc82011-06-22 15:39:57 -070020#include <chromeos/dbus/service_constants.h>
mukesh agrawal16bc1b82012-02-09 18:38:26 -080021#include <glib.h>
Paul Stewartb50f0b92011-05-16 16:31:42 -070022
Wade Guthried6153612012-08-23 11:36:14 -070023#include "shill/config80211.h"
Paul Stewartb50f0b92011-05-16 16:31:42 -070024#include "shill/control_interface.h"
Paul Stewartced6a0b2011-11-08 15:32:04 -080025#include "shill/dbus_adaptor.h"
Paul Stewartb50f0b92011-05-16 16:31:42 -070026#include "shill/device.h"
mukesh agrawal7a4e4002011-09-06 11:26:05 -070027#include "shill/error.h"
Gaurav Shah6d2c72d2012-10-16 16:30:44 -070028#include "shill/geolocation_info.h"
mukesh agrawal7a4e4002011-09-06 11:26:05 -070029#include "shill/ieee80211.h"
Paul Stewart3c508e12012-08-09 11:40:06 -070030#include "shill/link_monitor.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070031#include "shill/logging.h"
Chris Masone7aa5f902011-07-11 11:13:35 -070032#include "shill/manager.h"
Thieu Le67370f62012-02-14 23:01:42 +000033#include "shill/metrics.h"
mukesh agrawal4d0401c2012-01-06 16:05:31 -080034#include "shill/property_accessor.h"
Darin Petkovd1967262011-07-18 14:55:18 -070035#include "shill/proxy_factory.h"
Eric Shienbrood9a245532012-03-07 14:20:39 -050036#include "shill/rtnl_handler.h"
Paul Stewart5581d072012-12-17 17:30:20 -080037#include "shill/scope_logger.h"
mukesh agrawal5c05b292012-03-07 10:12:52 -080038#include "shill/shill_time.h"
mukesh agrawalaf571952011-07-14 14:31:12 -070039#include "shill/supplicant_interface_proxy_interface.h"
Paul Stewart835934a2012-12-06 19:27:09 -080040#include "shill/supplicant_network_proxy_interface.h"
mukesh agrawalaf571952011-07-14 14:31:12 -070041#include "shill/supplicant_process_proxy_interface.h"
Gaurav Shah435de2c2011-11-17 19:01:07 -080042#include "shill/technology.h"
mukesh agrawalb54601c2011-06-07 17:39:22 -070043#include "shill/wifi_endpoint.h"
Paul Stewart3c504012013-01-17 17:49:58 -080044#include "shill/wifi_provider.h"
mukesh agrawalb54601c2011-06-07 17:39:22 -070045#include "shill/wifi_service.h"
mukesh agrawal6e277772011-09-29 15:04:23 -070046#include "shill/wpa_supplicant.h"
Paul Stewartb50f0b92011-05-16 16:31:42 -070047
Eric Shienbrood3e20a232012-02-16 11:35:56 -050048using base::Bind;
mukesh agrawal15908392011-11-16 18:29:25 +000049using base::StringPrintf;
mukesh agrawal7a4e4002011-09-06 11:26:05 -070050using std::map;
mukesh agrawalab87ea42011-05-18 11:44:49 -070051using std::string;
mukesh agrawal7a4e4002011-09-06 11:26:05 -070052using std::vector;
mukesh agrawalab87ea42011-05-18 11:44:49 -070053
Paul Stewartb50f0b92011-05-16 16:31:42 -070054namespace shill {
mukesh agrawal7a4e4002011-09-06 11:26:05 -070055
56// statics
Darin Petkov60ceaf32012-10-18 10:36:01 +020057const char WiFi::kSupplicantConfPath[] = SHIMDIR "/wpa_supplicant.conf";
mukesh agrawal4d0401c2012-01-06 16:05:31 -080058const char *WiFi::kDefaultBgscanMethod =
Paul Stewart0654ece2013-03-26 15:21:26 -070059 WPASupplicant::kNetworkBgscanMethodSimple;
mukesh agrawal4d0401c2012-01-06 16:05:31 -080060const uint16 WiFi::kDefaultBgscanShortIntervalSeconds = 30;
61const int32 WiFi::kDefaultBgscanSignalThresholdDbm = -50;
62const uint16 WiFi::kDefaultScanIntervalSeconds = 180;
Darin Petkov4a66cc52012-06-15 10:08:29 +020063// Scan interval while connected.
64const uint16 WiFi::kBackgroundScanIntervalSeconds = 3601;
mukesh agrawal5c05b292012-03-07 10:12:52 -080065// Age (in seconds) beyond which a BSS cache entry will not be preserved,
66// across a suspend/resume.
67const time_t WiFi::kMaxBSSResumeAgeSeconds = 10;
mukesh agrawal7ec71312011-11-10 02:08:26 +000068const char WiFi::kInterfaceStateUnknown[] = "shill-unknown";
mukesh agrawalf2028172012-03-13 14:20:22 -070069const time_t WiFi::kRescanIntervalSeconds = 1;
Paul Stewarte369ece2012-05-22 09:11:03 -070070const int WiFi::kNumFastScanAttempts = 3;
71const int WiFi::kFastScanIntervalSeconds = 10;
Paul Stewart2b05e622012-07-13 20:38:44 -070072const int WiFi::kPendingTimeoutSeconds = 15;
Paul Stewart44663922012-07-30 11:03:03 -070073const int WiFi::kReconnectTimeoutSeconds = 10;
mukesh agrawalb54601c2011-06-07 17:39:22 -070074
Paul Stewartb50f0b92011-05-16 16:31:42 -070075WiFi::WiFi(ControlInterface *control_interface,
76 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -080077 Metrics *metrics,
Paul Stewartf1ce5d22011-05-19 13:10:20 -070078 Manager *manager,
Chris Masone3bd3c8c2011-06-13 08:20:26 -070079 const string& link,
Paul Stewarta41e38d2011-11-11 07:47:29 -080080 const string &address,
Paul Stewartb50f0b92011-05-16 16:31:42 -070081 int interface_index)
Chris Masonea82b7112011-05-25 15:16:29 -070082 : Device(control_interface,
83 dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -080084 metrics,
Chris Masonea82b7112011-05-25 15:16:29 -070085 manager,
Chris Masone3bd3c8c2011-06-13 08:20:26 -070086 link,
Chris Masone626719f2011-08-18 16:58:48 -070087 address,
Gaurav Shah435de2c2011-11-17 19:01:07 -080088 interface_index,
89 Technology::kWifi),
Paul Stewart3c504012013-01-17 17:49:58 -080090 provider_(manager->wifi_provider()),
Eric Shienbrood9a245532012-03-07 14:20:39 -050091 weak_ptr_factory_(this),
Darin Petkovab565bb2011-10-06 02:55:51 -070092 proxy_factory_(ProxyFactory::GetInstance()),
mukesh agrawal5c05b292012-03-07 10:12:52 -080093 time_(Time::GetInstance()),
Darin Petkov2b8e44e2012-06-25 15:13:26 +020094 supplicant_present_(false),
mukesh agrawal15908392011-11-16 18:29:25 +000095 supplicant_state_(kInterfaceStateUnknown),
96 supplicant_bss_("(unknown)"),
mukesh agrawal5c05b292012-03-07 10:12:52 -080097 need_bss_flush_(false),
Darin Petkove636c692012-05-31 10:22:17 +020098 resumed_at_((struct timeval){0}),
Paul Stewarte369ece2012-05-22 09:11:03 -070099 fast_scans_remaining_(kNumFastScanAttempts),
Christopher Wiley8f81e2a2012-10-17 16:51:32 -0700100 has_already_completed_(false),
Paul Stewarta47c3c62012-12-18 12:14:29 -0800101 is_debugging_connection_(false),
Paul Stewart1369c2b2013-01-11 05:41:26 -0800102 is_eap_in_progress_(false),
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800103 bgscan_short_interval_seconds_(kDefaultBgscanShortIntervalSeconds),
104 bgscan_signal_threshold_dbm_(kDefaultBgscanSignalThresholdDbm),
Chris Masone853b81b2011-06-24 14:11:41 -0700105 scan_pending_(false),
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800106 scan_interval_seconds_(kDefaultScanIntervalSeconds) {
mukesh agrawalde29fa82011-09-16 16:16:36 -0700107 PropertyStore *store = this->mutable_store();
Darin Petkov4a66cc52012-06-15 10:08:29 +0200108 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 agrawal4d0401c2012-01-06 16:05:31 -0800120 HelpRegisterDerivedUint16(store,
121 flimflam::kBgscanShortIntervalProperty,
122 &WiFi::GetBgscanShortInterval,
123 &WiFi::SetBgscanShortInterval);
124 HelpRegisterDerivedInt32(store,
125 flimflam::kBgscanSignalThresholdProperty,
126 &WiFi::GetBgscanSignalThreshold,
127 &WiFi::SetBgscanSignalThreshold);
Chris Masone853b81b2011-06-24 14:11:41 -0700128
Chris Masoneb925cc82011-06-22 15:39:57 -0700129 // 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 Stewartac4ac002011-08-26 12:04:26 -0700133 store->RegisterConstBool(flimflam::kScanningProperty, &scan_pending_);
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800134 HelpRegisterDerivedUint16(store,
135 flimflam::kScanIntervalProperty,
136 &WiFi::GetScanInterval,
137 &WiFi::SetScanInterval);
Paul Stewart5581d072012-12-17 17:30:20 -0800138 ScopeLogger::GetInstance()->RegisterScopeEnableChangedCallback(
139 ScopeLogger::kWiFi,
140 Bind(&WiFi::OnWiFiDebugScopeChanged, weak_ptr_factory_.GetWeakPtr()));
Ben Chanfad4a0b2012-04-18 15:49:59 -0700141 SLOG(WiFi, 2) << "WiFi device " << link_name() << " initialized.";
Paul Stewartb50f0b92011-05-16 16:31:42 -0700142}
143
mukesh agrawalaf571952011-07-14 14:31:12 -0700144WiFi::~WiFi() {}
Paul Stewartb50f0b92011-05-16 16:31:42 -0700145
Eric Shienbrood9a245532012-03-07 14:20:39 -0500146void WiFi::Start(Error *error, const EnabledStateChangedCallback &callback) {
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200147 SLOG(WiFi, 2) << "WiFi " << link_name() << " starting.";
148 if (enabled()) {
149 return;
mukesh agrawalc7426a42011-06-03 13:04:28 -0700150 }
Eric Shienbrood9a245532012-03-07 14:20:39 -0500151 OnEnabledStateChanged(EnabledStateChangedCallback(), Error());
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200152 if (error) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500153 error->Reset(); // indicate immediate completion
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200154 }
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 Stewart0654ece2013-03-26 15:21:26 -0700162 manager()->dbus_manager()->WatchName(WPASupplicant::kDBusAddr,
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200163 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 Guthried6153612012-08-23 11:36:14 -0700169 Config80211 *config80211 = Config80211::GetInstance();
170 if (config80211) {
171 config80211->SetWifiState(Config80211::kWifiUp);
172 }
mukesh agrawalab87ea42011-05-18 11:44:49 -0700173}
174
Eric Shienbrood9a245532012-03-07 14:20:39 -0500175void WiFi::Stop(Error *error, const EnabledStateChangedCallback &callback) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700176 SLOG(WiFi, 2) << "WiFi " << link_name() << " stopping.";
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200177 DropConnection();
mukesh agrawalb66c6462012-05-07 11:45:25 -0700178 StopScanTimer();
Paul Stewart3c504012013-01-17 17:49:58 -0800179 for (EndpointMap::iterator it = endpoint_by_rpcid_.begin();
180 it != endpoint_by_rpcid_.end(); ++it) {
181 provider_->OnEndpointRemoved(it->second);
182 }
mukesh agrawal15908392011-11-16 18:29:25 +0000183 endpoint_by_rpcid_.clear();
Paul Stewart3c504012013-01-17 17:49:58 -0800184 for (ReverseServiceMap::const_iterator it = rpcid_by_service_.begin();
185 it != rpcid_by_service_.end(); ++it) {
186 RemoveNetwork(it->second);
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700187 }
Paul Stewart549d44c2012-07-03 12:40:25 -0700188 rpcid_by_service_.clear();
Paul Stewart549d44c2012-07-03 12:40:25 -0700189 supplicant_interface_proxy_.reset(); // breaks a reference cycle
190 // TODO(quiche): Remove interface from supplicant.
191 supplicant_process_proxy_.reset();
mukesh agrawalb20776f2012-02-10 16:00:36 -0800192 current_service_ = NULL; // breaks a reference cycle
mukesh agrawal7ec71312011-11-10 02:08:26 +0000193 pending_service_ = NULL; // breaks a reference cycle
Paul Stewarta47c3c62012-12-18 12:14:29 -0800194 is_debugging_connection_ = false;
Paul Stewartd2db2b12013-01-17 13:11:07 -0800195 SetScanPending(false);
Paul Stewart2b05e622012-07-13 20:38:44 -0700196 StopPendingTimer();
Paul Stewart44663922012-07-30 11:03:03 -0700197 StopReconnectTimer();
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700198
Eric Shienbrood9a245532012-03-07 14:20:39 -0500199 OnEnabledStateChanged(EnabledStateChangedCallback(), Error());
200 if (error)
201 error->Reset(); // indicate immediate completion
mukesh agrawalc4f368f2012-06-04 19:45:52 -0700202 weak_ptr_factory_.InvalidateWeakPtrs();
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700203
Ben Chanfad4a0b2012-04-18 15:49:59 -0700204 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 Stewarta41e38d2011-11-11 07:47:29 -0800214}
215
mukesh agrawal1830fa12011-09-26 14:31:40 -0700216void WiFi::Scan(Error */*error*/) {
mukesh agrawal32399322011-09-01 10:53:43 -0700217 LOG(INFO) << __func__;
218
mukesh agrawal7ec71312011-11-10 02:08:26 +0000219 // 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 agrawal32399322011-09-01 10:53:43 -0700221 // to event loop.
Eric Shienbrood9a245532012-03-07 14:20:39 -0500222 dispatcher()->PostTask(Bind(&WiFi::ScanTask, weak_ptr_factory_.GetWeakPtr()));
mukesh agrawal32399322011-09-01 10:53:43 -0700223}
224
mukesh agrawalb4bc57d2011-12-07 01:07:47 +0000225void WiFi::BSSAdded(const ::DBus::Path &path,
226 const map<string, ::DBus::Variant> &properties) {
Eric Shienbrood3e20a232012-02-16 11:35:56 -0500227 // Called from a D-Bus signal handler, and may need to send a D-Bus
mukesh agrawalb4bc57d2011-12-07 01:07:47 +0000228 // message. So defer work to event loop.
Eric Shienbrood9a245532012-03-07 14:20:39 -0500229 dispatcher()->PostTask(Bind(&WiFi::BSSAddedTask,
230 weak_ptr_factory_.GetWeakPtr(),
231 path, properties));
mukesh agrawal261daca2011-12-02 18:56:56 +0000232}
233
234void WiFi::BSSRemoved(const ::DBus::Path &path) {
Eric Shienbrood3e20a232012-02-16 11:35:56 -0500235 // Called from a D-Bus signal handler, and may need to send a D-Bus
mukesh agrawalb4bc57d2011-12-07 01:07:47 +0000236 // message. So defer work to event loop.
Eric Shienbrood9a245532012-03-07 14:20:39 -0500237 dispatcher()->PostTask(Bind(&WiFi::BSSRemovedTask,
238 weak_ptr_factory_.GetWeakPtr(), path));
mukesh agrawalb54601c2011-06-07 17:39:22 -0700239}
240
Paul Stewartbc6e7392012-05-24 07:07:48 -0700241void WiFi::Certification(const map<string, ::DBus::Variant> &properties) {
242 dispatcher()->PostTask(Bind(&WiFi::CertificationTask,
243 weak_ptr_factory_.GetWeakPtr(), properties));
244}
245
Paul Stewartdb0f9172012-11-30 16:48:09 -0800246void WiFi::EAPEvent(const string &status, const string &parameter) {
247 dispatcher()->PostTask(Bind(&WiFi::EAPEventTask,
248 weak_ptr_factory_.GetWeakPtr(),
249 status,
250 parameter));
251}
252
mukesh agrawal7ec71312011-11-10 02:08:26 +0000253void WiFi::PropertiesChanged(const map<string, ::DBus::Variant> &properties) {
Darin Petkov9cd7ca12012-07-03 11:06:40 +0200254 SLOG(WiFi, 2) << __func__;
mukesh agrawal15908392011-11-16 18:29:25 +0000255 // Called from D-Bus signal handler, but may need to send a D-Bus
256 // message. So defer work to event loop.
Eric Shienbrood9a245532012-03-07 14:20:39 -0500257 dispatcher()->PostTask(Bind(&WiFi::PropertiesChangedTask,
258 weak_ptr_factory_.GetWeakPtr(), properties));
mukesh agrawal7ec71312011-11-10 02:08:26 +0000259}
260
mukesh agrawalb54601c2011-06-07 17:39:22 -0700261void WiFi::ScanDone() {
262 LOG(INFO) << __func__;
263
mukesh agrawal7ec71312011-11-10 02:08:26 +0000264 // Defer handling of scan result processing, because that processing
265 // may require the the registration of new D-Bus objects. And such
mukesh agrawalb54601c2011-06-07 17:39:22 -0700266 // registration can't be done in the context of a D-Bus signal
267 // handler.
Eric Shienbrood9a245532012-03-07 14:20:39 -0500268 dispatcher()->PostTask(Bind(&WiFi::ScanDoneTask,
269 weak_ptr_factory_.GetWeakPtr()));
mukesh agrawalb54601c2011-06-07 17:39:22 -0700270}
271
mukesh agrawal6e277772011-09-29 15:04:23 -0700272void WiFi::ConnectTo(WiFiService *service,
mukesh agrawal64896322011-12-01 01:13:10 +0000273 map<string, DBus::Variant> service_params) {
mukesh agrawale9adda12012-02-09 18:33:48 -0800274 CHECK(service) << "Can't connect to NULL service.";
mukesh agrawal445e72c2011-06-22 11:13:50 -0700275 DBus::Path network_path;
mukesh agrawalb54601c2011-06-07 17:39:22 -0700276
mukesh agrawal7ec71312011-11-10 02:08:26 +0000277 // TODO(quiche): Handle cases where already connected.
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000278 if (pending_service_ && pending_service_ == service) {
279 // TODO(quiche): Return an error to the caller. crosbug.com/23832
Darin Petkov457728b2013-01-09 09:49:08 +0100280 LOG(INFO) << "WiFi " << link_name() << " ignoring ConnectTo service "
281 << service->unique_name()
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000282 << ", which is already pending.";
283 return;
284 }
285
286 if (pending_service_ && pending_service_ != service) {
287 DisconnectFrom(pending_service_);
288 }
mukesh agrawal32399322011-09-01 10:53:43 -0700289
Paul Stewart835934a2012-12-06 19:27:09 -0800290 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 Stewart0654ece2013-03-26 15:21:26 -0700295 service_params[WPASupplicant::kNetworkPropertyScanSSID].writer().
Paul Stewart835934a2012-12-06 19:27:09 -0800296 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 agrawal6e277772011-09-29 15:04:23 -0700305 }
mukesh agrawal445e72c2011-06-22 11:13:50 -0700306
Paul Stewarta47c3c62012-12-18 12:14:29 -0800307 if (service->HasRecentConnectionIssues()) {
308 SetConnectionDebugging(true);
309 }
mukesh agrawal445e72c2011-06-22 11:13:50 -0700310 supplicant_interface_proxy_->SelectNetwork(network_path);
Paul Stewart2b05e622012-07-13 20:38:44 -0700311 SetPendingService(service);
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000312 CHECK(current_service_.get() != pending_service_.get());
313
mukesh agrawalf2f68a52011-09-01 12:15:48 -0700314 // 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 agrawal7ec71312011-11-10 02:08:26 +0000317 // TODO(quiche): When we add code for dealing with connection failures,
mukesh agrawalf2f68a52011-09-01 12:15:48 -0700318 // reconsider if this is the right place to change the selected service.
319 // see discussion in crosbug.com/20191.
320 SelectService(service);
mukesh agrawal15908392011-11-16 18:29:25 +0000321}
322
mukesh agrawal0ed0f2e2011-12-05 20:36:17 +0000323void 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 Petkov457728b2013-01-09 09:49:08 +0100329 << service->unique_name()
mukesh agrawal0ed0f2e2011-12-05 20:36:17 +0000330 << " 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 Petkov457728b2013-01-09 09:49:08 +0100339 << service->unique_name()
mukesh agrawal0ed0f2e2011-12-05 20:36:17 +0000340 << " 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 Petkov457728b2013-01-09 09:49:08 +0100349 << service->unique_name()
mukesh agrawal0ed0f2e2011-12-05 20:36:17 +0000350 << " which is not the current service.";
351 return;
352 }
353
Paul Stewartff96a842012-08-13 15:59:10 -0700354 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 Stewart2b05e622012-07-13 20:38:44 -0700360 SetPendingService(NULL);
Paul Stewart44663922012-07-30 11:03:03 -0700361 StopReconnectTimer();
Paul Stewart549d44c2012-07-03 12:40:25 -0700362
363 if (!supplicant_present_) {
Christopher Wileyc6184482012-10-24 15:31:56 -0700364 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 Stewart549d44c2012-07-03 12:40:25 -0700370 current_service_ = NULL;
371 return;
372 }
373
mukesh agrawal0ed0f2e2011-12-05 20:36:17 +0000374 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 Chan80326f32012-05-04 17:51:32 -0700378 } catch (const DBus::Error &e) { // NOLINT
mukesh agrawal0ed0f2e2011-12-05 20:36:17 +0000379 // Can't depend on getting a notification of CurrentBSS change.
Christopher Wileyc6184482012-10-24 15:31:56 -0700380 // So effect changes immediately. For instance, this can happen when
381 // a disconnect is triggered by a BSS going away.
Paul Stewart835934a2012-12-06 19:27:09 -0800382 Error unused_error;
383 RemoveNetworkForService(service, &unused_error);
Christopher Wileyc6184482012-10-24 15:31:56 -0700384 if (service == selected_service()) {
385 DropConnection();
386 }
mukesh agrawal0ed0f2e2011-12-05 20:36:17 +0000387 current_service_ = NULL;
388 }
389
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800390 CHECK(current_service_ == NULL ||
391 current_service_.get() != pending_service_.get());
mukesh agrawal0ed0f2e2011-12-05 20:36:17 +0000392}
393
Paul Stewart835934a2012-12-06 19:27:09 -0800394bool WiFi::DisableNetwork(const ::DBus::Path &network) {
395 scoped_ptr<SupplicantNetworkProxyInterface> supplicant_network_proxy(
396 proxy_factory_->CreateSupplicantNetworkProxy(
Paul Stewart0654ece2013-03-26 15:21:26 -0700397 network, WPASupplicant::kDBusAddr));
Paul Stewart835934a2012-12-06 19:27:09 -0800398 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 Stewart71f6ecd2012-09-13 14:52:18 -0700407bool WiFi::RemoveNetwork(const ::DBus::Path &network) {
408 try {
409 supplicant_interface_proxy_->RemoveNetwork(network);
410 } catch (const DBus::Error &e) { // NOLINT
Ben Chan381fdcc2012-10-14 21:10:36 -0700411 // 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 Stewart0654ece2013-03-26 15:21:26 -0700421 if (strcmp(e.name(), WPASupplicant::kErrorNetworkUnknown) != 0) {
Ben Chan381fdcc2012-10-14 21:10:36 -0700422 return false;
423 }
Paul Stewart71f6ecd2012-09-13 14:52:18 -0700424 }
425 return true;
426}
427
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000428bool WiFi::IsIdle() const {
Paul Stewart3d9bcf52011-12-12 15:02:22 -0800429 return !current_service_ && !pending_service_;
430}
431
Paul Stewart835934a2012-12-06 19:27:09 -0800432void WiFi::ClearCachedCredentials(const WiFiService *service) {
433 Error unused_error;
434 RemoveNetworkForService(service, &unused_error);
Paul Stewart66c86002012-01-30 18:00:52 -0800435}
436
Paul Stewart3c504012013-01-17 17:49:58 -0800437void WiFi::NotifyEndpointChanged(const WiFiEndpointConstRefPtr &endpoint) {
438 WiFiService *service = provider_->FindServiceForEndpoint(endpoint);
mukesh agrawalb20776f2012-02-10 16:00:36 -0800439 DCHECK(service);
440 if (service) {
441 service->NotifyEndpointUpdated(endpoint);
mukesh agrawalb20776f2012-02-10 16:00:36 -0800442 }
443}
444
Darin Petkov4a66cc52012-06-15 10:08:29 +0200445void WiFi::AppendBgscan(WiFiService *service,
446 map<string, DBus::Variant> *service_params) const {
447 int scan_interval = kBackgroundScanIntervalSeconds;
448 string method = bgscan_method_;
449 if (method.empty()) {
450 // If multiple APs are detected for this SSID, configure the default method.
451 // Otherwise, disable background scanning completely.
452 if (service->GetEndpointCount() > 1) {
453 method = kDefaultBgscanMethod;
454 } else {
455 LOG(INFO) << "Background scan disabled -- single Endpoint for Service.";
456 return;
457 }
Paul Stewart0654ece2013-03-26 15:21:26 -0700458 } else if (method.compare(WPASupplicant::kNetworkBgscanMethodNone) == 0) {
Christopher Wileya998df22012-07-11 15:14:55 -0700459 LOG(INFO) << "Background scan disabled -- chose None method.";
460 return;
Darin Petkov4a66cc52012-06-15 10:08:29 +0200461 } else {
462 // If the background scan method was explicitly specified, honor the
463 // configured background scan interval.
464 scan_interval = scan_interval_seconds_;
465 }
466 DCHECK(!method.empty());
467 string config_string = StringPrintf("%s:%d:%d:%d",
468 method.c_str(),
469 bgscan_short_interval_seconds_,
470 bgscan_signal_threshold_dbm_,
471 scan_interval);
472 LOG(INFO) << "Background scan: " << config_string;
Paul Stewart0654ece2013-03-26 15:21:26 -0700473 (*service_params)[WPASupplicant::kNetworkPropertyBgscan].writer()
Darin Petkov4a66cc52012-06-15 10:08:29 +0200474 .append_string(config_string.c_str());
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800475}
476
Darin Petkov4a66cc52012-06-15 10:08:29 +0200477string WiFi::GetBgscanMethod(const int &/*argument*/, Error */* error */) {
478 return bgscan_method_.empty() ? kDefaultBgscanMethod : bgscan_method_;
479}
480
481void WiFi::SetBgscanMethod(
482 const int &/*argument*/, const string &method, Error *error) {
Paul Stewart0654ece2013-03-26 15:21:26 -0700483 if (method != WPASupplicant::kNetworkBgscanMethodSimple &&
484 method != WPASupplicant::kNetworkBgscanMethodLearn &&
485 method != WPASupplicant::kNetworkBgscanMethodNone) {
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800486 const string error_message =
487 StringPrintf("Unrecognized bgscan method %s", method.c_str());
488 LOG(WARNING) << error_message;
489 error->Populate(Error::kInvalidArguments, error_message);
490 return;
491 }
492
493 bgscan_method_ = method;
494 // We do not update kNetworkPropertyBgscan for |pending_service_| or
495 // |current_service_|, because supplicant does not allow for
496 // reconfiguration without disconnect and reconnect.
497}
498
499void WiFi::SetBgscanShortInterval(const uint16 &seconds, Error */*error*/) {
500 bgscan_short_interval_seconds_ = seconds;
501 // We do not update kNetworkPropertyBgscan for |pending_service_| or
502 // |current_service_|, because supplicant does not allow for
503 // reconfiguration without disconnect and reconnect.
504}
505
506void WiFi::SetBgscanSignalThreshold(const int32 &dbm, Error */*error*/) {
507 bgscan_signal_threshold_dbm_ = dbm;
508 // We do not update kNetworkPropertyBgscan for |pending_service_| or
509 // |current_service_|, because supplicant does not allow for
510 // reconfiguration without disconnect and reconnect.
511}
512
513void WiFi::SetScanInterval(const uint16 &seconds, Error */*error*/) {
514 scan_interval_seconds_ = seconds;
mukesh agrawalb66c6462012-05-07 11:45:25 -0700515 if (running()) {
516 StartScanTimer();
517 }
518 // The scan interval affects both foreground scans (handled by
519 // |scan_timer_callback_|), and background scans (handled by
520 // supplicant). However, we do not update |pending_service_| or
521 // |current_service_|, because supplicant does not allow for
522 // reconfiguration without disconnect and reconnect.
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800523}
524
Darin Petkov4a66cc52012-06-15 10:08:29 +0200525void WiFi::ClearBgscanMethod(const int &/*argument*/, Error */*error*/) {
526 bgscan_method_.clear();
527}
528
mukesh agrawal15908392011-11-16 18:29:25 +0000529void WiFi::CurrentBSSChanged(const ::DBus::Path &new_bss) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700530 SLOG(WiFi, 3) << "WiFi " << link_name() << " CurrentBSS "
531 << supplicant_bss_ << " -> " << new_bss;
mukesh agrawal15908392011-11-16 18:29:25 +0000532 supplicant_bss_ = new_bss;
Paul Stewartdb0f9172012-11-30 16:48:09 -0800533 supplicant_tls_error_ = "";
Christopher Wiley8f81e2a2012-10-17 16:51:32 -0700534 has_already_completed_ = false;
Paul Stewart44663922012-07-30 11:03:03 -0700535
536 // Any change in CurrentBSS means supplicant is actively changing our
537 // connectivity. We no longer need to track any previously pending
538 // reconnect.
539 StopReconnectTimer();
540
Paul Stewart0654ece2013-03-26 15:21:26 -0700541 if (new_bss == WPASupplicant::kCurrentBSSNull) {
mukesh agrawal15908392011-11-16 18:29:25 +0000542 HandleDisconnect();
Paul Stewart3c504012013-01-17 17:49:58 -0800543 if (!provider_->GetHiddenSSIDList().empty()) {
mukesh agrawalb66c6462012-05-07 11:45:25 -0700544 // Before disconnecting, wpa_supplicant probably scanned for
545 // APs. So, in the normal case, we defer to the timer for the next scan.
546 //
547 // However, in the case of hidden SSIDs, supplicant knows about
548 // at most one of them. (That would be the hidden SSID we were
549 // connected to, if applicable.)
550 //
551 // So, in this case, we initiate an immediate scan. This scan
552 // will include the hidden SSIDs we know about (up to the limit of
553 // kScanMAxSSIDsPerScan).
554 //
555 // We may want to reconsider this immediate scan, if/when shill
556 // takes greater responsibility for scanning (vs. letting
557 // supplicant handle most of it).
558 Scan(NULL);
559 }
mukesh agrawal15908392011-11-16 18:29:25 +0000560 } else {
561 HandleRoam(new_bss);
562 }
563
Paul Stewart1369c2b2013-01-11 05:41:26 -0800564 // Reset eap_in_progress_ after calling HandleDisconnect() so it can
565 // be used to detect disconnects during EAP authentication.
566 is_eap_in_progress_ = false;
567
Paul Stewart2b05e622012-07-13 20:38:44 -0700568 // If we are selecting a new service, or if we're clearing selection
569 // of a something other than the pending service, call SelectService.
570 // Otherwise skip SelectService, since this will cause the pending
571 // service to be marked as Idle.
572 if (current_service_ || selected_service() != pending_service_) {
573 SelectService(current_service_);
574 }
575
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000576 // Invariant check: a Service can either be current, or pending, but
577 // not both.
mukesh agrawal15908392011-11-16 18:29:25 +0000578 CHECK(current_service_.get() != pending_service_.get() ||
579 current_service_.get() == NULL);
Paul Stewarta47c3c62012-12-18 12:14:29 -0800580
581 // If we are no longer debugging a problematic WiFi connection, return
582 // to the debugging level indicated by the WiFi debugging scope.
583 if ((!current_service_ || !current_service_->HasRecentConnectionIssues()) &&
584 (!pending_service_ || !pending_service_->HasRecentConnectionIssues())) {
585 SetConnectionDebugging(false);
586 }
mukesh agrawal15908392011-11-16 18:29:25 +0000587}
588
589void WiFi::HandleDisconnect() {
590 // Identify the affected service. We expect to get a disconnect
591 // event when we fall off a Service that we were connected
592 // to. However, we also allow for the case where we get a disconnect
593 // event while attempting to connect from a disconnected state.
594 WiFiService *affected_service =
595 current_service_.get() ? current_service_.get() : pending_service_.get();
596
597 current_service_ = NULL;
598 if (!affected_service) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700599 SLOG(WiFi, 2) << "WiFi " << link_name()
600 << " disconnected while not connected or connecting";
mukesh agrawal15908392011-11-16 18:29:25 +0000601 return;
Christopher Wileyc6184482012-10-24 15:31:56 -0700602 }
603 if (affected_service == selected_service()) {
Paul Stewart20b0a092012-05-22 20:39:57 -0700604 // If our selected service has disconnected, destroy IP configuration state.
Christopher Wileyc6184482012-10-24 15:31:56 -0700605 DropConnection();
mukesh agrawal15908392011-11-16 18:29:25 +0000606 }
607
Paul Stewart835934a2012-12-06 19:27:09 -0800608 Error error;
609 if (!DisableNetworkForService(affected_service, &error)) {
610 if (error.type() == Error::kNotFound) {
611 SLOG(WiFi, 2) << "WiFi " << link_name() << " disconnected from "
Darin Petkov457728b2013-01-09 09:49:08 +0100612 << " (or failed to connect to) service "
613 << affected_service->unique_name() << ", "
Paul Stewart835934a2012-12-06 19:27:09 -0800614 << "but could not find supplicant network to disable.";
615 } else {
616 LOG(FATAL) << "DisableNetwork failed.";
Paul Stewart71f6ecd2012-09-13 14:52:18 -0700617 }
mukesh agrawal15908392011-11-16 18:29:25 +0000618 }
619
Ben Chanfad4a0b2012-04-18 15:49:59 -0700620 SLOG(WiFi, 2) << "WiFi " << link_name() << " disconnected from "
Darin Petkov457728b2013-01-09 09:49:08 +0100621 << " (or failed to connect to) service "
622 << affected_service->unique_name();
Paul Stewart1369c2b2013-01-11 05:41:26 -0800623 Service::ConnectFailure failure;
624 if (SuspectCredentials(*affected_service, &failure)) {
mukesh agrawalcf24a242012-05-21 16:46:11 -0700625 // If we suspect bad credentials, set failure, to trigger an error
mukesh agrawal56e32202012-07-26 16:32:11 -0700626 // mole in Chrome.
Paul Stewart1369c2b2013-01-11 05:41:26 -0800627 affected_service->SetFailure(failure);
628 LOG(ERROR) << "Connection failure is due to suspect credentials: returning "
629 << Service::ConnectFailureToString(failure);
Paul Stewartf2d60912012-07-15 08:37:30 -0700630 } else {
631 affected_service->SetFailureSilent(Service::kFailureUnknown);
mukesh agrawalcf24a242012-05-21 16:46:11 -0700632 }
mukesh agrawale1d90e92012-02-15 17:36:08 -0800633 affected_service->NotifyCurrentEndpoint(NULL);
Thieu Le67370f62012-02-14 23:01:42 +0000634 metrics()->NotifyServiceDisconnect(affected_service);
mukesh agrawal15908392011-11-16 18:29:25 +0000635
636 if (affected_service == pending_service_.get()) {
637 // The attempt to connect to |pending_service_| failed. Clear
638 // |pending_service_|, to indicate we're no longer in the middle
639 // of a connect request.
Paul Stewart2b05e622012-07-13 20:38:44 -0700640 SetPendingService(NULL);
mukesh agrawal15908392011-11-16 18:29:25 +0000641 } else if (pending_service_.get()) {
642 // We've attributed the disconnection to what was the
643 // |current_service_|, rather than the |pending_service_|.
644 //
645 // If we're wrong about that (i.e. supplicant reported this
646 // CurrentBSS change after attempting to connect to
647 // |pending_service_|), we're depending on supplicant to retry
648 // connecting to |pending_service_|, and delivering another
649 // CurrentBSS change signal in the future.
650 //
651 // Log this fact, to help us debug (in case our assumptions are
652 // wrong).
Darin Petkov457728b2013-01-09 09:49:08 +0100653 SLOG(WiFi, 2) << "WiFi " << link_name() << " pending connection to service "
654 << pending_service_->unique_name()
Ben Chanfad4a0b2012-04-18 15:49:59 -0700655 << " after disconnect";
mukesh agrawal15908392011-11-16 18:29:25 +0000656 }
Paul Stewarte369ece2012-05-22 09:11:03 -0700657
658 // If we disconnect, initially scan at a faster frequency, to make sure
659 // we've found all available APs.
660 RestartFastScanAttempts();
mukesh agrawal15908392011-11-16 18:29:25 +0000661}
662
663// We use the term "Roam" loosely. In particular, we include the case
664// where we "Roam" to a BSS from the disconnected state.
665void WiFi::HandleRoam(const ::DBus::Path &new_bss) {
666 EndpointMap::iterator endpoint_it = endpoint_by_rpcid_.find(new_bss);
667 if (endpoint_it == endpoint_by_rpcid_.end()) {
668 LOG(WARNING) << "WiFi " << link_name() << " connected to unknown BSS "
669 << new_bss;
670 return;
671 }
672
Paul Stewart3c504012013-01-17 17:49:58 -0800673 const WiFiEndpointConstRefPtr endpoint(endpoint_it->second);
674 WiFiServiceRefPtr service = provider_->FindServiceForEndpoint(endpoint);
mukesh agrawal15908392011-11-16 18:29:25 +0000675 if (!service.get()) {
676 LOG(WARNING) << "WiFi " << link_name()
677 << " could not find Service for Endpoint "
Paul Stewart3c504012013-01-17 17:49:58 -0800678 << endpoint->bssid_string()
mukesh agrawal15908392011-11-16 18:29:25 +0000679 << " (service will be unchanged)";
680 return;
681 }
682
Ben Chanfad4a0b2012-04-18 15:49:59 -0700683 SLOG(WiFi, 2) << "WiFi " << link_name()
Paul Stewart3c504012013-01-17 17:49:58 -0800684 << " roamed to Endpoint " << endpoint->bssid_string()
685 << " " << LogSSID(endpoint->ssid_string());
mukesh agrawal15908392011-11-16 18:29:25 +0000686
Paul Stewart3c504012013-01-17 17:49:58 -0800687 service->NotifyCurrentEndpoint(endpoint);
Thieu Lee41a72d2012-02-06 20:46:51 +0000688
mukesh agrawal15908392011-11-16 18:29:25 +0000689 if (pending_service_.get() &&
690 service.get() != pending_service_.get()) {
691 // The Service we've roamed on to is not the one we asked for.
692 // We assume that this is transient, and that wpa_supplicant
693 // is trying / will try to connect to |pending_service_|.
694 //
695 // If it succeeds, we'll end up back here, but with |service|
696 // pointing at the same service as |pending_service_|.
697 //
698 // If it fails, we'll process things in HandleDisconnect.
699 //
700 // So we leave |pending_service_| untouched.
Ben Chanfad4a0b2012-04-18 15:49:59 -0700701 SLOG(WiFi, 2) << "WiFi " << link_name()
702 << " new current Endpoint "
Paul Stewart3c504012013-01-17 17:49:58 -0800703 << endpoint->bssid_string()
Ben Chanfad4a0b2012-04-18 15:49:59 -0700704 << " is not part of pending service "
Darin Petkov457728b2013-01-09 09:49:08 +0100705 << pending_service_->unique_name();
mukesh agrawal15908392011-11-16 18:29:25 +0000706
707 // Sanity check: if we didn't roam onto |pending_service_|, we
708 // should still be on |current_service_|.
709 if (service.get() != current_service_.get()) {
710 LOG(WARNING) << "WiFi " << link_name()
711 << " new current Endpoint "
Paul Stewart3c504012013-01-17 17:49:58 -0800712 << endpoint->bssid_string()
mukesh agrawal15908392011-11-16 18:29:25 +0000713 << " is neither part of pending service "
Darin Petkov457728b2013-01-09 09:49:08 +0100714 << pending_service_->unique_name()
mukesh agrawal15908392011-11-16 18:29:25 +0000715 << " nor part of current service "
Darin Petkov457728b2013-01-09 09:49:08 +0100716 << (current_service_ ?
717 current_service_->unique_name() :
mukesh agrawal15908392011-11-16 18:29:25 +0000718 "(NULL)");
719 // Although we didn't expect to get here, we should keep
720 // |current_service_| in sync with what supplicant has done.
721 current_service_ = service;
722 }
723 return;
724 }
725
726 if (pending_service_.get()) {
727 // We assume service.get() == pending_service_.get() here, because
728 // of the return in the previous if clause.
729 //
730 // Boring case: we've connected to the service we asked
731 // for. Simply update |current_service_| and |pending_service_|.
732 current_service_ = service;
Paul Stewart2b05e622012-07-13 20:38:44 -0700733 SetPendingService(NULL);
mukesh agrawal15908392011-11-16 18:29:25 +0000734 return;
735 }
736
737 // |pending_service_| was NULL, so we weren't attempting to connect
738 // to a new Service. Sanity check that we're still on
739 // |current_service_|.
740 if (service.get() != current_service_.get()) {
741 LOG(WARNING)
742 << "WiFi " << link_name()
743 << " new current Endpoint "
Paul Stewart3c504012013-01-17 17:49:58 -0800744 << endpoint->bssid_string()
mukesh agrawal15908392011-11-16 18:29:25 +0000745 << (current_service_.get() ?
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000746 StringPrintf(" is not part of current service %s",
Darin Petkov457728b2013-01-09 09:49:08 +0100747 current_service_->unique_name().c_str()) :
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000748 " with no current service");
mukesh agrawal15908392011-11-16 18:29:25 +0000749 // We didn't expect to be here, but let's cope as well as we
750 // can. Update |current_service_| to keep it in sync with
751 // supplicant.
752 current_service_ = service;
Paul Stewartabbe2792012-07-15 07:50:35 -0700753
754 // If this service isn't already marked as actively connecting (likely,
755 // since this service is a bit of a surprise) set the service as
756 // associating.
757 if (!current_service_->IsConnecting()) {
758 current_service_->SetState(Service::kStateAssociating);
759 }
760
mukesh agrawal15908392011-11-16 18:29:25 +0000761 return;
762 }
763
764 // At this point, we know that |pending_service_| was NULL, and that
765 // we're still on |current_service_|. This is the most boring case
766 // of all, because there's no state to update here.
767 return;
mukesh agrawalb54601c2011-06-07 17:39:22 -0700768}
769
Paul Stewart835934a2012-12-06 19:27:09 -0800770string WiFi::FindNetworkRpcidForService(
771 const WiFiService *service, Error *error) {
772 ReverseServiceMap::const_iterator rpcid_it =
773 rpcid_by_service_.find(service);
774 if (rpcid_it == rpcid_by_service_.end()) {
775 const string error_message =
Darin Petkov457728b2013-01-09 09:49:08 +0100776 StringPrintf(
777 "WiFi %s cannot find supplicant network rpcid for service %s",
778 link_name().c_str(), service->unique_name().c_str());
Paul Stewart835934a2012-12-06 19:27:09 -0800779 // There are contexts where this is not an error, such as when a service
780 // is clearing whatever cached credentials may not exist.
781 SLOG(WiFi, 2) << error_message;
782 if (error) {
783 error->Populate(Error::kNotFound, error_message);
784 }
785 return "";
786 }
787
788 return rpcid_it->second;
789}
790
791bool WiFi::DisableNetworkForService(const WiFiService *service, Error *error) {
792 string rpcid = FindNetworkRpcidForService(service, error);
793 if (rpcid.empty()) {
794 // Error is already populated.
795 return false;
796 }
797
798 if (!DisableNetwork(rpcid)) {
799 const string error_message =
Darin Petkov457728b2013-01-09 09:49:08 +0100800 StringPrintf("WiFi %s cannot disable network for service %s: "
Paul Stewart835934a2012-12-06 19:27:09 -0800801 "DBus operation failed for rpcid %s.",
Darin Petkov457728b2013-01-09 09:49:08 +0100802 link_name().c_str(), service->unique_name().c_str(),
Paul Stewart835934a2012-12-06 19:27:09 -0800803 rpcid.c_str());
804 Error::PopulateAndLog(error, Error::kOperationFailed, error_message);
805
806 // Make sure that such errored networks are removed, so problems do not
807 // propogate to future connection attempts.
808 RemoveNetwork(rpcid);
809 rpcid_by_service_.erase(service);
810
811 return false;
812 }
813
814 return true;
815}
816
817bool WiFi::RemoveNetworkForService(const WiFiService *service, Error *error) {
818 string rpcid = FindNetworkRpcidForService(service, error);
819 if (rpcid.empty()) {
820 // Error is already populated.
821 return false;
822 }
823
824 // Erase the rpcid from our tables regardless of failure below, since even
825 // if in failure, we never want to use this network again.
826 rpcid_by_service_.erase(service);
827
828 // TODO(quiche): Reconsider giving up immediately. Maybe give
829 // wpa_supplicant some time to retry, first.
830 if (!RemoveNetwork(rpcid)) {
831 const string error_message =
Darin Petkov457728b2013-01-09 09:49:08 +0100832 StringPrintf("WiFi %s cannot remove network for service %s: "
Paul Stewart835934a2012-12-06 19:27:09 -0800833 "DBus operation failed for rpcid %s.",
Darin Petkov457728b2013-01-09 09:49:08 +0100834 link_name().c_str(), service->unique_name().c_str(),
Paul Stewart835934a2012-12-06 19:27:09 -0800835 rpcid.c_str());
836 Error::PopulateAndLog(error, Error::kOperationFailed, error_message);
837 return false;
838 }
839
840 return true;
841}
842
mukesh agrawalb4bc57d2011-12-07 01:07:47 +0000843void WiFi::BSSAddedTask(
844 const ::DBus::Path &path,
845 const map<string, ::DBus::Variant> &properties) {
mukesh agrawalb4bc57d2011-12-07 01:07:47 +0000846 // Note: we assume that BSSIDs are unique across endpoints. This
847 // means that if an AP reuses the same BSSID for multiple SSIDs, we
848 // lose.
mukesh agrawalb20776f2012-02-10 16:00:36 -0800849 WiFiEndpointRefPtr endpoint(
850 new WiFiEndpoint(proxy_factory_, this, path, properties));
Wade Guthrie592ecd52012-11-12 13:12:30 -0800851 SLOG(WiFi, 1) << "Found endpoint. "
852 << "RPC path: " << path << ", "
Darin Petkov50cb78a2013-02-06 16:17:49 +0100853 << LogSSID(endpoint->ssid_string()) << ", "
Wade Guthrie592ecd52012-11-12 13:12:30 -0800854 << "bssid: " << endpoint->bssid_string() << ", "
855 << "signal: " << endpoint->signal_strength() << ", "
856 << "security: " << endpoint->security_mode() << ", "
857 << "frequency: " << endpoint->frequency();
mukesh agrawalb4bc57d2011-12-07 01:07:47 +0000858
859 if (endpoint->ssid_string().empty()) {
860 // Don't bother trying to find or create a Service for an Endpoint
861 // without an SSID. We wouldn't be able to connect to it anyway.
862 return;
863 }
864
mukesh agrawalb3857612012-01-18 16:23:29 -0800865 if (endpoint->ssid()[0] == 0) {
866 // Assume that an SSID starting with NULL is bogus/misconfigured,
867 // and filter it out.
868 return;
869 }
870
Paul Stewart3c504012013-01-17 17:49:58 -0800871 provider_->OnEndpointAdded(endpoint);
mukesh agrawalb4bc57d2011-12-07 01:07:47 +0000872
mukesh agrawale9adda12012-02-09 18:33:48 -0800873 // Do this last, to maintain the invariant that any Endpoint we
874 // know about has a corresponding Service.
mukesh agrawalb20776f2012-02-10 16:00:36 -0800875 //
876 // TODO(quiche): Write test to verify correct behavior in the case
877 // where we get multiple BSSAdded events for a single endpoint.
878 // (Old Endpoint's refcount should fall to zero, and old Endpoint
879 // should be destroyed.)
mukesh agrawale9adda12012-02-09 18:33:48 -0800880 endpoint_by_rpcid_[path] = endpoint;
mukesh agrawalb20776f2012-02-10 16:00:36 -0800881 endpoint->Start();
mukesh agrawalb4bc57d2011-12-07 01:07:47 +0000882}
883
884void WiFi::BSSRemovedTask(const ::DBus::Path &path) {
885 EndpointMap::iterator i = endpoint_by_rpcid_.find(path);
886 if (i == endpoint_by_rpcid_.end()) {
887 LOG(WARNING) << "WiFi " << link_name()
888 << " could not find BSS " << path
889 << " to remove.";
890 return;
891 }
892
893 WiFiEndpointRefPtr endpoint = i->second;
894 CHECK(endpoint);
895 endpoint_by_rpcid_.erase(i);
896
Paul Stewart3c504012013-01-17 17:49:58 -0800897 WiFiServiceRefPtr service = provider_->OnEndpointRemoved(endpoint);
898 if (!service) {
899 return;
900 }
901 Error unused_error;
902 RemoveNetworkForService(service, &unused_error);
mukesh agrawalb4bc57d2011-12-07 01:07:47 +0000903
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000904 bool disconnect_service = !service->HasEndpoints() &&
905 (service->IsConnecting() || service->IsConnected());
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000906
907 if (disconnect_service) {
908 DisconnectFrom(service);
909 }
mukesh agrawalb4bc57d2011-12-07 01:07:47 +0000910}
911
Paul Stewartbc6e7392012-05-24 07:07:48 -0700912void WiFi::CertificationTask(
913 const map<string, ::DBus::Variant> &properties) {
914 if (!current_service_) {
915 LOG(ERROR) << "WiFi " << link_name() << " " << __func__
916 << " with no current service.";
917 return;
918 }
919
920 map<string, ::DBus::Variant>::const_iterator properties_it =
Paul Stewart0654ece2013-03-26 15:21:26 -0700921 properties.find(WPASupplicant::kInterfacePropertyDepth);
Paul Stewartbc6e7392012-05-24 07:07:48 -0700922 if (properties_it == properties.end()) {
923 LOG(ERROR) << __func__ << " no depth parameter.";
924 return;
925 }
926 uint32 depth = properties_it->second.reader().get_uint32();
Paul Stewart0654ece2013-03-26 15:21:26 -0700927 properties_it = properties.find(WPASupplicant::kInterfacePropertySubject);
Paul Stewartbc6e7392012-05-24 07:07:48 -0700928 if (properties_it == properties.end()) {
929 LOG(ERROR) << __func__ << " no subject parameter.";
930 return;
931 }
932 string subject(properties_it->second.reader().get_string());
933 current_service_->AddEAPCertification(subject, depth);
934}
935
Paul Stewartdb0f9172012-11-30 16:48:09 -0800936void WiFi::EAPEventTask(const string &status, const string &parameter) {
937 Service::ConnectFailure failure = Service::kFailureUnknown;
938
939 if (!current_service_) {
940 LOG(ERROR) << "WiFi " << link_name() << " " << __func__
941 << " with no current service.";
942 return;
943 }
944
Paul Stewart0654ece2013-03-26 15:21:26 -0700945 if (status == WPASupplicant::kEAPStatusAcceptProposedMethod) {
Paul Stewartdb0f9172012-11-30 16:48:09 -0800946 LOG(INFO) << link_name() << ": accepted EAP method " << parameter;
Paul Stewart0654ece2013-03-26 15:21:26 -0700947 } else if (status == WPASupplicant::kEAPStatusCompletion) {
948 if (parameter == WPASupplicant::kEAPParameterSuccess) {
Paul Stewartdb0f9172012-11-30 16:48:09 -0800949 SLOG(WiFi, 2) << link_name() << ": EAP: "
950 << "Completed authentication.";
Paul Stewart1369c2b2013-01-11 05:41:26 -0800951 is_eap_in_progress_ = false;
Paul Stewart0654ece2013-03-26 15:21:26 -0700952 } else if (parameter == WPASupplicant::kEAPParameterFailure) {
Paul Stewartdb0f9172012-11-30 16:48:09 -0800953 // If there was a TLS error, use this instead of the generic failure.
Paul Stewart0654ece2013-03-26 15:21:26 -0700954 if (supplicant_tls_error_ == WPASupplicant::kEAPStatusLocalTLSAlert) {
Paul Stewartdb0f9172012-11-30 16:48:09 -0800955 failure = Service::kFailureEAPLocalTLS;
956 } else if (supplicant_tls_error_ ==
Paul Stewart0654ece2013-03-26 15:21:26 -0700957 WPASupplicant::kEAPStatusRemoteTLSAlert) {
Paul Stewartdb0f9172012-11-30 16:48:09 -0800958 failure = Service::kFailureEAPRemoteTLS;
959 } else {
960 failure = Service::kFailureEAPAuthentication;
961 }
962 } else {
963 LOG(ERROR) << link_name() << ": EAP: "
964 << "Unexpected " << status << " parameter: " << parameter;
965 }
Paul Stewart0654ece2013-03-26 15:21:26 -0700966 } else if (status == WPASupplicant::kEAPStatusLocalTLSAlert ||
967 status == WPASupplicant::kEAPStatusRemoteTLSAlert) {
Paul Stewartdb0f9172012-11-30 16:48:09 -0800968 supplicant_tls_error_ = status;
969 } else if (status ==
Paul Stewart0654ece2013-03-26 15:21:26 -0700970 WPASupplicant::kEAPStatusRemoteCertificateVerification) {
971 if (parameter == WPASupplicant::kEAPParameterSuccess) {
Paul Stewartdb0f9172012-11-30 16:48:09 -0800972 SLOG(WiFi, 2) << link_name() << ": EAP: "
973 << "Completed remote certificate verification.";
974 } else {
975 // wpa_supplicant doesn't currently have a verification failure
976 // message. We will instead get a RemoteTLSAlert above.
977 LOG(ERROR) << link_name() << ": EAP: "
978 << "Unexpected " << status << " parameter: " << parameter;
979 }
Paul Stewart0654ece2013-03-26 15:21:26 -0700980 } else if (status == WPASupplicant::kEAPStatusParameterNeeded) {
Paul Stewart1369c2b2013-01-11 05:41:26 -0800981 LOG(ERROR) << link_name() << ": EAP: "
982 << "Authentication due to missing authentication parameter: "
983 << parameter;
984 failure = Service::kFailureEAPAuthentication;
Paul Stewart0654ece2013-03-26 15:21:26 -0700985 } else if (status == WPASupplicant::kEAPStatusStarted) {
Paul Stewart1369c2b2013-01-11 05:41:26 -0800986 SLOG(WiFi, 2) << link_name() << ": EAP authentication starting.";
987 is_eap_in_progress_ = true;
Paul Stewartdb0f9172012-11-30 16:48:09 -0800988 }
989
990 if (failure != Service::kFailureUnknown) {
Paul Stewart1369c2b2013-01-11 05:41:26 -0800991 // Avoid a reporting failure twice by clearing eap_in_progress_ early.
mukesh agrawald4dc0832013-03-25 14:38:26 -0700992 Error unused_error;
Paul Stewart1369c2b2013-01-11 05:41:26 -0800993 is_eap_in_progress_ = false;
mukesh agrawald4dc0832013-03-25 14:38:26 -0700994 current_service_->DisconnectWithFailure(failure, &unused_error);
Paul Stewartdb0f9172012-11-30 16:48:09 -0800995 }
996}
997
mukesh agrawal15908392011-11-16 18:29:25 +0000998void WiFi::PropertiesChangedTask(
999 const map<string, ::DBus::Variant> &properties) {
1000 // TODO(quiche): Handle changes in other properties (e.g. signal
1001 // strength).
1002
1003 // Note that order matters here. In particular, we want to process
1004 // changes in the current BSS before changes in state. This is so
1005 // that we update the state of the correct Endpoint/Service.
1006
1007 map<string, ::DBus::Variant>::const_iterator properties_it =
Paul Stewart0654ece2013-03-26 15:21:26 -07001008 properties.find(WPASupplicant::kInterfacePropertyCurrentBSS);
mukesh agrawal15908392011-11-16 18:29:25 +00001009 if (properties_it != properties.end()) {
1010 CurrentBSSChanged(properties_it->second.reader().get_path());
1011 }
1012
Paul Stewart0654ece2013-03-26 15:21:26 -07001013 properties_it = properties.find(WPASupplicant::kInterfacePropertyState);
mukesh agrawal15908392011-11-16 18:29:25 +00001014 if (properties_it != properties.end()) {
1015 StateChanged(properties_it->second.reader().get_string());
1016 }
1017}
1018
mukesh agrawaldc42bb32011-07-28 10:40:26 -07001019void WiFi::ScanDoneTask() {
Ben Chanfad4a0b2012-04-18 15:49:59 -07001020 SLOG(WiFi, 2) << __func__ << " need_bss_flush_ " << need_bss_flush_;
mukesh agrawal5c05b292012-03-07 10:12:52 -08001021 if (need_bss_flush_) {
1022 CHECK(supplicant_interface_proxy_ != NULL);
1023 // Compute |max_age| relative to |resumed_at_|, to account for the
1024 // time taken to scan.
1025 struct timeval now;
1026 uint32_t max_age;
1027 time_->GetTimeMonotonic(&now);
1028 max_age = kMaxBSSResumeAgeSeconds + (now.tv_sec - resumed_at_.tv_sec);
1029 supplicant_interface_proxy_->FlushBSS(max_age);
1030 need_bss_flush_ = false;
1031 }
Paul Stewartd2db2b12013-01-17 13:11:07 -08001032 SetScanPending(false);
mukesh agrawalb66c6462012-05-07 11:45:25 -07001033 StartScanTimer();
mukesh agrawalb54601c2011-06-07 17:39:22 -07001034}
1035
mukesh agrawal32399322011-09-01 10:53:43 -07001036void WiFi::ScanTask() {
Ben Chanfad4a0b2012-04-18 15:49:59 -07001037 SLOG(WiFi, 2) << "WiFi " << link_name() << " scan requested.";
Paul Stewartfae4dae2012-09-13 07:43:32 -07001038 if (!enabled()) {
1039 SLOG(WiFi, 2) << "Ignoring scan request while device is not enabled.";
1040 return;
1041 }
1042 if (!supplicant_present_ || !supplicant_interface_proxy_.get()) {
1043 SLOG(WiFi, 2) << "Ignoring scan request while supplicant is not present.";
1044 return;
1045 }
Christopher Wileyc68c8672012-11-20 16:52:21 -08001046 if ((pending_service_.get() && pending_service_->IsConnecting()) ||
1047 (current_service_.get() && current_service_->IsConnecting())) {
1048 SLOG(WiFi, 2) << "Ignoring scan request while connecting to an AP.";
1049 return;
1050 }
Paul Stewarta41e38d2011-11-11 07:47:29 -08001051 map<string, DBus::Variant> scan_args;
Paul Stewart0654ece2013-03-26 15:21:26 -07001052 scan_args[WPASupplicant::kPropertyScanType].writer().
1053 append_string(WPASupplicant::kScanTypeActive);
Paul Stewartced6a0b2011-11-08 15:32:04 -08001054
Paul Stewart3c504012013-01-17 17:49:58 -08001055 ByteArrays hidden_ssids = provider_->GetHiddenSSIDList();
Paul Stewartced6a0b2011-11-08 15:32:04 -08001056 if (!hidden_ssids.empty()) {
Paul Stewart3c504012013-01-17 17:49:58 -08001057 // TODO(pstew): Devise a better method for time-sharing with SSIDs that do
1058 // not fit in.
Paul Stewart0654ece2013-03-26 15:21:26 -07001059 if (hidden_ssids.size() >= WPASupplicant::kScanMaxSSIDsPerScan) {
Paul Stewart3c504012013-01-17 17:49:58 -08001060 hidden_ssids.erase(
Paul Stewart0654ece2013-03-26 15:21:26 -07001061 hidden_ssids.begin() + WPASupplicant::kScanMaxSSIDsPerScan - 1,
Paul Stewart3c504012013-01-17 17:49:58 -08001062 hidden_ssids.end());
1063 }
1064 // Add Broadcast SSID, signified by an empty ByteArray. If we specify
1065 // SSIDs to wpa_supplicant, we need to explicitly specify the default
1066 // behavior of doing a broadcast probe.
1067 hidden_ssids.push_back(ByteArray());
1068
Paul Stewart0654ece2013-03-26 15:21:26 -07001069 scan_args[WPASupplicant::kPropertyScanSSIDs] =
Paul Stewartced6a0b2011-11-08 15:32:04 -08001070 DBusAdaptor::ByteArraysToVariant(hidden_ssids);
1071 }
1072
Gaurav Shah10109f22011-11-11 20:16:22 -08001073 try {
1074 supplicant_interface_proxy_->Scan(scan_args);
Paul Stewartd2db2b12013-01-17 13:11:07 -08001075 SetScanPending(true);
Ben Chan80326f32012-05-04 17:51:32 -07001076 } catch (const DBus::Error &e) { // NOLINT
Darin Petkov2b8e44e2012-06-25 15:13:26 +02001077 // A scan may fail if, for example, the wpa_supplicant vanishing
1078 // notification is posted after this task has already started running.
1079 LOG(WARNING) << "Scan failed: " << e.what();
Gaurav Shah10109f22011-11-11 20:16:22 -08001080 }
mukesh agrawal32399322011-09-01 10:53:43 -07001081}
1082
Paul Stewartd2db2b12013-01-17 13:11:07 -08001083void WiFi::SetScanPending(bool pending) {
1084 if (scan_pending_ != pending) {
1085 scan_pending_ = pending;
1086 adaptor()->EmitBoolChanged(flimflam::kScanningProperty, pending);
1087 }
1088}
1089
Albert Chaulk0e1cdea2013-02-27 15:32:55 -08001090string WiFi::GetServiceLeaseName(const WiFiService &service) {
1091 return service.GetStorageIdentifier();
1092}
1093
1094void WiFi::DestroyServiceLease(const WiFiService &service) {
1095 DestroyIPConfigLease(GetServiceLeaseName(service));
1096}
1097
mukesh agrawal15908392011-11-16 18:29:25 +00001098void WiFi::StateChanged(const string &new_state) {
1099 const string old_state = supplicant_state_;
mukesh agrawal7ec71312011-11-10 02:08:26 +00001100 supplicant_state_ = new_state;
mukesh agrawal15908392011-11-16 18:29:25 +00001101 LOG(INFO) << "WiFi " << link_name() << " " << __func__ << " "
1102 << old_state << " -> " << new_state;
1103
1104 WiFiService *affected_service;
1105 // Identify the service to which the state change applies. If
1106 // |pending_service_| is non-NULL, then the state change applies to
1107 // |pending_service_|. Otherwise, it applies to |current_service_|.
1108 //
1109 // This policy is driven by the fact that the |pending_service_|
1110 // doesn't become the |current_service_| until wpa_supplicant
1111 // reports a CurrentBSS change to the |pending_service_|. And the
mukesh agrawalc01f3982012-01-24 13:48:39 -08001112 // CurrentBSS change won't be reported until the |pending_service_|
Paul Stewart0654ece2013-03-26 15:21:26 -07001113 // reaches the WPASupplicant::kInterfaceStateCompleted state.
mukesh agrawal15908392011-11-16 18:29:25 +00001114 affected_service =
1115 pending_service_.get() ? pending_service_.get() : current_service_.get();
1116 if (!affected_service) {
Ben Chanfad4a0b2012-04-18 15:49:59 -07001117 SLOG(WiFi, 2) << "WiFi " << link_name() << " " << __func__
1118 << " with no service";
mukesh agrawal15908392011-11-16 18:29:25 +00001119 return;
1120 }
1121
Paul Stewart0654ece2013-03-26 15:21:26 -07001122 if (new_state == WPASupplicant::kInterfaceStateCompleted) {
Paul Stewart44663922012-07-30 11:03:03 -07001123 if (affected_service->IsConnected()) {
1124 StopReconnectTimer();
Christopher Wiley5519e9e2013-01-08 16:55:56 -08001125 EnableHighBitrates();
Christopher Wiley8f81e2a2012-10-17 16:51:32 -07001126 } else if (has_already_completed_) {
1127 LOG(INFO) << link_name() << " L3 configuration already started.";
Paul Stewart44663922012-07-30 11:03:03 -07001128 } else if (AcquireIPConfigWithLeaseName(
Albert Chaulk0e1cdea2013-02-27 15:32:55 -08001129 GetServiceLeaseName(*affected_service))) {
Paul Stewartd408fdf2012-05-07 17:15:57 -07001130 LOG(INFO) << link_name() << " is up; started L3 configuration.";
mukesh agrawalc01f3982012-01-24 13:48:39 -08001131 affected_service->SetState(Service::kStateConfiguring);
1132 } else {
1133 LOG(ERROR) << "Unable to acquire DHCP config.";
1134 }
Christopher Wiley8f81e2a2012-10-17 16:51:32 -07001135 has_already_completed_ = true;
Paul Stewart0654ece2013-03-26 15:21:26 -07001136 } else if (new_state == WPASupplicant::kInterfaceStateAssociated) {
mukesh agrawal15908392011-11-16 18:29:25 +00001137 affected_service->SetState(Service::kStateAssociating);
Paul Stewart0654ece2013-03-26 15:21:26 -07001138 } else if (new_state == WPASupplicant::kInterfaceStateAuthenticating ||
1139 new_state == WPASupplicant::kInterfaceStateAssociating ||
1140 new_state == WPASupplicant::kInterfaceState4WayHandshake ||
1141 new_state == WPASupplicant::kInterfaceStateGroupHandshake) {
mukesh agrawal15908392011-11-16 18:29:25 +00001142 // Ignore transitions into these states from Completed, to avoid
1143 // bothering the user when roaming, or re-keying.
Paul Stewart0654ece2013-03-26 15:21:26 -07001144 if (old_state != WPASupplicant::kInterfaceStateCompleted)
mukesh agrawal15908392011-11-16 18:29:25 +00001145 affected_service->SetState(Service::kStateAssociating);
1146 // TOOD(quiche): On backwards transitions, we should probably set
1147 // a timeout for getting back into the completed state. At present,
1148 // we depend on wpa_supplicant eventually reporting that CurrentBSS
mukesh agrawal8a3188d2011-12-01 20:56:44 +00001149 // has changed. But there may be cases where that signal is not sent.
mukesh agrawal15908392011-11-16 18:29:25 +00001150 // (crosbug.com/23207)
Paul Stewart0654ece2013-03-26 15:21:26 -07001151 } else if (new_state == WPASupplicant::kInterfaceStateDisconnected &&
Paul Stewart44663922012-07-30 11:03:03 -07001152 affected_service == current_service_ &&
1153 affected_service->IsConnected()) {
1154 // This means that wpa_supplicant failed in a re-connect attempt, but
1155 // may still be reconnecting. Give wpa_supplicant a limited amount of
1156 // time to transition out this condition by either connecting or changing
1157 // CurrentBSS.
1158 StartReconnectTimer();
mukesh agrawal15908392011-11-16 18:29:25 +00001159 } else {
1160 // Other transitions do not affect Service state.
1161 //
1162 // Note in particular that we ignore a State change into
1163 // kInterfaceStateDisconnected, in favor of observing the corresponding
1164 // change in CurrentBSS.
1165 }
mukesh agrawal7ec71312011-11-10 02:08:26 +00001166}
1167
Paul Stewart1369c2b2013-01-11 05:41:26 -08001168bool WiFi::SuspectCredentials(
1169 const WiFiService &service, Service::ConnectFailure *failure) const {
Paul Stewart1369c2b2013-01-11 05:41:26 -08001170 if (service.IsSecurityMatch(flimflam::kSecurityPsk)) {
Paul Stewart0654ece2013-03-26 15:21:26 -07001171 if (supplicant_state_ == WPASupplicant::kInterfaceState4WayHandshake &&
Paul Stewart1369c2b2013-01-11 05:41:26 -08001172 !service.has_ever_connected()) {
1173 if (failure) {
1174 *failure = Service::kFailureBadPassphrase;
1175 }
1176 return true;
1177 }
1178 } else if (service.IsSecurityMatch(flimflam::kSecurity8021x)) {
1179 if (is_eap_in_progress_ && !service.has_ever_connected()) {
1180 if (failure) {
1181 *failure = Service::kFailureEAPAuthentication;
1182 }
1183 return true;
1184 }
mukesh agrawalcf24a242012-05-21 16:46:11 -07001185 }
1186
Paul Stewart1369c2b2013-01-11 05:41:26 -08001187 return false;
mukesh agrawalcf24a242012-05-21 16:46:11 -07001188}
1189
mukesh agrawal16bc1b82012-02-09 18:38:26 -08001190// static
1191bool WiFi::SanitizeSSID(string *ssid) {
1192 CHECK(ssid);
1193
1194 size_t ssid_len = ssid->length();
1195 size_t i;
1196 bool changed = false;
1197
Gary Morainac1bdb42012-02-16 17:42:29 -08001198 for (i = 0; i < ssid_len; ++i) {
mukesh agrawal16bc1b82012-02-09 18:38:26 -08001199 if (!g_ascii_isprint((*ssid)[i])) {
1200 (*ssid)[i] = '?';
1201 changed = true;
1202 }
1203 }
1204
1205 return changed;
1206}
1207
Darin Petkov50cb78a2013-02-06 16:17:49 +01001208// static
1209string WiFi::LogSSID(const string &ssid) {
1210 string out;
1211 for (string::const_iterator it = ssid.begin(); it != ssid.end(); ++it) {
1212 // Replace '[' and ']' (in addition to non-printable characters) so that
1213 // it's easy to match the right substring through a non-greedy regex.
1214 if (*it == '[' || *it == ']' || !g_ascii_isprint(*it)) {
1215 base::StringAppendF(&out, "\\x%02x", *it);
1216 } else {
1217 out += *it;
1218 }
1219 }
1220 return StringPrintf("[SSID=%s]", out.c_str());
1221}
1222
Paul Stewart3c508e12012-08-09 11:40:06 -07001223void WiFi::OnLinkMonitorFailure() {
1224 // If we have never found the gateway, let's be conservative and not
1225 // do anything, in case this network topology does not have a gateway.
1226 if (!link_monitor()->IsGatewayFound()) {
1227 LOG(INFO) << "In " << __func__ << "(): "
1228 << "Skipping reassociate since gateway was never found.";
1229 return;
1230 }
1231
1232 if (!supplicant_present_) {
1233 LOG(ERROR) << "In " << __func__ << "(): "
1234 << "wpa_supplicant is not present. Cannot reassociate.";
1235 return;
1236 }
1237
1238 try {
Christopher Wileye0b2a012012-10-31 13:11:27 -07001239 // This will force a transition out of connected, if we are actually
1240 // connected.
Paul Stewart3c508e12012-08-09 11:40:06 -07001241 supplicant_interface_proxy_->Reassociate();
Christopher Wileye0b2a012012-10-31 13:11:27 -07001242 // If we don't eventually get a transition back into a connected state,
1243 // there is something wrong.
1244 StartReconnectTimer();
Paul Stewart3c508e12012-08-09 11:40:06 -07001245 LOG(INFO) << "In " << __func__ << "(): Called Reassociate().";
1246 } catch (const DBus::Error &e) { // NOLINT
1247 LOG(ERROR) << "In " << __func__ << "(): failed to call Reassociate().";
1248 return;
1249 }
1250}
1251
Arman Ugurayed8e6102012-11-29 14:47:20 -08001252bool WiFi::ShouldUseArpGateway() const {
1253 return true;
1254}
1255
Paul Stewart3c504012013-01-17 17:49:58 -08001256void WiFi::DisassociateFromService(const WiFiServiceRefPtr &service) {
1257 DisconnectFrom(service);
1258 if (service == selected_service()) {
1259 DropConnection();
1260 }
1261 Error unused_error;
1262 RemoveNetworkForService(service, &unused_error);
1263}
1264
Gaurav Shah6d2c72d2012-10-16 16:30:44 -07001265vector<GeolocationInfo> WiFi::GetGeolocationObjects() const {
1266 vector<GeolocationInfo> objects;
1267 for (EndpointMap::const_iterator it = endpoint_by_rpcid_.begin();
1268 it != endpoint_by_rpcid_.end();
1269 ++it) {
1270 GeolocationInfo geoinfo;
1271 WiFiEndpointRefPtr endpoint = it->second;
1272 geoinfo.AddField(kGeoMacAddressProperty, endpoint->bssid_string());
1273 geoinfo.AddField(kGeoSignalStrengthProperty,
1274 StringPrintf("%d", endpoint->signal_strength()));
1275 geoinfo.AddField(
1276 kGeoChannelProperty,
1277 StringPrintf("%d",
1278 Metrics::WiFiFrequencyToChannel(endpoint->frequency())));
1279 // TODO(gauravsh): Include age field. crosbug.com/35445
1280 objects.push_back(geoinfo);
1281 }
1282 return objects;
1283}
1284
mukesh agrawal4d0401c2012-01-06 16:05:31 -08001285void WiFi::HelpRegisterDerivedInt32(
1286 PropertyStore *store,
1287 const string &name,
1288 int32(WiFi::*get)(Error *error),
1289 void(WiFi::*set)(const int32 &value, Error *error)) {
1290 store->RegisterDerivedInt32(
1291 name,
1292 Int32Accessor(new CustomAccessor<WiFi, int32>(this, get, set)));
1293}
1294
mukesh agrawal4d0401c2012-01-06 16:05:31 -08001295void WiFi::HelpRegisterDerivedUint16(
1296 PropertyStore *store,
1297 const string &name,
1298 uint16(WiFi::*get)(Error *error),
1299 void(WiFi::*set)(const uint16 &value, Error *error)) {
1300 store->RegisterDerivedUint16(
1301 name,
1302 Uint16Accessor(new CustomAccessor<WiFi, uint16>(this, get, set)));
1303}
1304
mukesh agrawal2f9df4e2012-08-08 12:29:20 -07001305void WiFi::OnAfterResume() {
mukesh agrawal5c05b292012-03-07 10:12:52 -08001306 LOG(INFO) << __func__;
mukesh agrawal2f9df4e2012-08-08 12:29:20 -07001307 Device::OnAfterResume(); // May refresh ipconfig_
mukesh agrawal5c05b292012-03-07 10:12:52 -08001308
mukesh agrawal2f9df4e2012-08-08 12:29:20 -07001309 // We want to flush the BSS cache, but we don't want to conflict
1310 // with a running scan or an active connection attempt. So record
1311 // the need to flush, and take care of flushing when the next scan
1312 // completes.
1313 //
1314 // Note that supplicant will automatically expire old cache
1315 // entries (after, e.g., a BSS is not found in two consecutive
1316 // scans). However, our explicit flush accelerates re-association
1317 // in cases where a BSS disappeared while we were asleep. (See,
1318 // e.g. WiFiRoaming.005SuspendRoam.)
1319 time_->GetTimeMonotonic(&resumed_at_);
1320 need_bss_flush_ = true;
1321
1322 if (!scan_pending_ && IsIdle()) {
1323 // Not scanning/connecting/connected, so let's get things rolling.
1324 Scan(NULL);
1325 } else {
1326 SLOG(WiFi, 1) << __func__
1327 << " skipping scan, already scanning or connected.";
Gary Morainac1bdb42012-02-16 17:42:29 -08001328 }
1329}
1330
Christopher Wiley5519e9e2013-01-08 16:55:56 -08001331void WiFi::OnConnected() {
1332 Device::OnConnected();
1333 EnableHighBitrates();
1334}
1335
Paul Stewarte369ece2012-05-22 09:11:03 -07001336void WiFi::RestartFastScanAttempts() {
1337 fast_scans_remaining_ = kNumFastScanAttempts;
1338 StartScanTimer();
1339}
1340
mukesh agrawalb66c6462012-05-07 11:45:25 -07001341void WiFi::StartScanTimer() {
1342 if (scan_interval_seconds_ == 0) {
1343 StopScanTimer();
1344 return;
1345 }
1346 scan_timer_callback_.Reset(
1347 Bind(&WiFi::ScanTimerHandler, weak_ptr_factory_.GetWeakPtr()));
Paul Stewarte369ece2012-05-22 09:11:03 -07001348 // Repeat the first few scans after disconnect relatively quickly so we
1349 // have reasonable trust that no APs we are looking for are present.
1350 dispatcher()->PostDelayedTask(scan_timer_callback_.callback(),
1351 fast_scans_remaining_ > 0 ?
1352 kFastScanIntervalSeconds * 1000 : scan_interval_seconds_ * 1000);
mukesh agrawalb66c6462012-05-07 11:45:25 -07001353}
1354
1355void WiFi::StopScanTimer() {
1356 scan_timer_callback_.Cancel();
1357}
1358
1359void WiFi::ScanTimerHandler() {
1360 SLOG(WiFi, 2) << "WiFi Device " << link_name() << ": " << __func__;
1361 if (IsIdle() && !scan_pending_) {
1362 Scan(NULL);
Paul Stewarte369ece2012-05-22 09:11:03 -07001363 if (fast_scans_remaining_ > 0) {
1364 --fast_scans_remaining_;
1365 }
mukesh agrawalb66c6462012-05-07 11:45:25 -07001366 }
1367 StartScanTimer();
1368}
1369
Paul Stewart2b05e622012-07-13 20:38:44 -07001370void WiFi::StartPendingTimer() {
1371 pending_timeout_callback_.Reset(
1372 Bind(&WiFi::PendingTimeoutHandler, weak_ptr_factory_.GetWeakPtr()));
1373 dispatcher()->PostDelayedTask(pending_timeout_callback_.callback(),
1374 kPendingTimeoutSeconds * 1000);
1375}
1376
1377void WiFi::StopPendingTimer() {
1378 pending_timeout_callback_.Cancel();
1379}
1380
1381void WiFi::SetPendingService(const WiFiServiceRefPtr &service) {
Paul Stewartff96a842012-08-13 15:59:10 -07001382 SLOG(WiFi, 2) << "WiFi " << link_name() << " setting pending service to "
Darin Petkov457728b2013-01-09 09:49:08 +01001383 << (service ? service->unique_name(): "NULL");
Paul Stewart2b05e622012-07-13 20:38:44 -07001384 if (service) {
1385 service->SetState(Service::kStateAssociating);
1386 StartPendingTimer();
1387 } else if (pending_service_) {
1388 StopPendingTimer();
1389 }
1390 pending_service_ = service;
1391}
1392
1393void WiFi::PendingTimeoutHandler() {
mukesh agrawald4dc0832013-03-25 14:38:26 -07001394 Error unused_error;
Paul Stewart2b05e622012-07-13 20:38:44 -07001395 LOG(INFO) << "WiFi Device " << link_name() << ": " << __func__;
1396 CHECK(pending_service_);
mukesh agrawald4dc0832013-03-25 14:38:26 -07001397 pending_service_->DisconnectWithFailure(
1398 Service::kFailureOutOfRange, &unused_error);
Paul Stewart2b05e622012-07-13 20:38:44 -07001399}
1400
Paul Stewart44663922012-07-30 11:03:03 -07001401void WiFi::StartReconnectTimer() {
Paul Stewart1aff7302012-08-04 20:04:47 -07001402 if (!reconnect_timeout_callback_.IsCancelled()) {
1403 LOG(INFO) << "WiFi Device " << link_name() << ": " << __func__
1404 << ": reconnect timer already running.";
1405 return;
1406 }
Paul Stewart44663922012-07-30 11:03:03 -07001407 LOG(INFO) << "WiFi Device " << link_name() << ": " << __func__;
1408 reconnect_timeout_callback_.Reset(
1409 Bind(&WiFi::ReconnectTimeoutHandler, weak_ptr_factory_.GetWeakPtr()));
1410 dispatcher()->PostDelayedTask(reconnect_timeout_callback_.callback(),
1411 kReconnectTimeoutSeconds * 1000);
1412}
1413
1414void WiFi::StopReconnectTimer() {
1415 SLOG(WiFi, 2) << "WiFi Device " << link_name() << ": " << __func__;
1416 reconnect_timeout_callback_.Cancel();
1417}
1418
1419void WiFi::ReconnectTimeoutHandler() {
1420 LOG(INFO) << "WiFi Device " << link_name() << ": " << __func__;
Paul Stewart1aff7302012-08-04 20:04:47 -07001421 reconnect_timeout_callback_.Cancel();
Paul Stewart44663922012-07-30 11:03:03 -07001422 CHECK(current_service_);
1423 current_service_->SetFailureSilent(Service::kFailureConnect);
1424 DisconnectFrom(current_service_);
1425}
1426
Darin Petkov2b8e44e2012-06-25 15:13:26 +02001427void WiFi::OnSupplicantAppear(const string &/*owner*/) {
1428 LOG(INFO) << "WPA supplicant appeared.";
1429 if (supplicant_present_) {
Darin Petkov9cd7ca12012-07-03 11:06:40 +02001430 // Restart the WiFi device if it's started already. This will reset the
1431 // state and connect the device to the new WPA supplicant instance.
1432 if (enabled()) {
1433 Restart();
1434 }
Darin Petkov2b8e44e2012-06-25 15:13:26 +02001435 return;
1436 }
1437 supplicant_present_ = true;
1438 ConnectToSupplicant();
1439}
1440
1441void WiFi::OnSupplicantVanish() {
1442 LOG(INFO) << "WPA supplicant vanished.";
1443 if (!supplicant_present_) {
1444 return;
1445 }
1446 supplicant_present_ = false;
1447 // Restart the WiFi device if it's started already. This will effectively
1448 // suspend the device until the WPA supplicant reappears.
1449 if (enabled()) {
1450 Restart();
1451 }
1452}
1453
Paul Stewart5581d072012-12-17 17:30:20 -08001454void WiFi::OnWiFiDebugScopeChanged(bool enabled) {
1455 SLOG(WiFi, 2) << "WiFi debug scope changed; enable is now " << enabled;
1456 if (!supplicant_process_proxy_.get()) {
1457 SLOG(WiFi, 2) << "Suplicant process proxy not present.";
1458 return;
1459 }
1460 string current_level;
1461 try {
1462 current_level = supplicant_process_proxy_->GetDebugLevel();
1463 } catch (const DBus::Error &e) { // NOLINT
1464 LOG(ERROR) << __func__ << ": Failed to get wpa_supplicant debug level.";
1465 return;
1466 }
1467
Paul Stewart0654ece2013-03-26 15:21:26 -07001468 if (current_level != WPASupplicant::kDebugLevelInfo &&
1469 current_level != WPASupplicant::kDebugLevelDebug) {
Paul Stewart5581d072012-12-17 17:30:20 -08001470 SLOG(WiFi, 2) << "WiFi debug level is currently "
1471 << current_level
1472 << "; assuming that it is being controlled elsewhere.";
1473 return;
1474 }
Paul Stewart0654ece2013-03-26 15:21:26 -07001475 string new_level = enabled ? WPASupplicant::kDebugLevelDebug :
1476 WPASupplicant::kDebugLevelInfo;
Paul Stewart5581d072012-12-17 17:30:20 -08001477
1478 if (new_level == current_level) {
1479 SLOG(WiFi, 2) << "WiFi debug level is already the desired level "
1480 << current_level;
1481 return;
1482 }
1483
1484 try {
1485 supplicant_process_proxy_->SetDebugLevel(new_level);
1486 } catch (const DBus::Error &e) { // NOLINT
1487 LOG(ERROR) << __func__ << ": Failed to set wpa_supplicant debug level.";
1488 }
1489}
1490
Paul Stewarta47c3c62012-12-18 12:14:29 -08001491void WiFi::SetConnectionDebugging(bool enabled) {
1492 if (is_debugging_connection_ == enabled) {
1493 return;
1494 }
1495 OnWiFiDebugScopeChanged(
1496 enabled ||
1497 ScopeLogger::GetInstance()->IsScopeEnabled(ScopeLogger::kWiFi));
1498 is_debugging_connection_ = enabled;
1499}
1500
Darin Petkov2b8e44e2012-06-25 15:13:26 +02001501void WiFi::ConnectToSupplicant() {
1502 LOG(INFO) << link_name() << ": " << (enabled() ? "enabled" : "disabled")
1503 << " supplicant: "
1504 << (supplicant_present_ ? "present" : "absent")
1505 << " proxy: "
1506 << (supplicant_process_proxy_.get() ? "non-null" : "null");
1507 if (!enabled() || !supplicant_present_ || supplicant_process_proxy_.get()) {
1508 return;
1509 }
1510 supplicant_process_proxy_.reset(
1511 proxy_factory_->CreateSupplicantProcessProxy(
Paul Stewart0654ece2013-03-26 15:21:26 -07001512 WPASupplicant::kDBusPath, WPASupplicant::kDBusAddr));
Paul Stewart5581d072012-12-17 17:30:20 -08001513 OnWiFiDebugScopeChanged(
1514 ScopeLogger::GetInstance()->IsScopeEnabled(ScopeLogger::kWiFi));
Darin Petkov2b8e44e2012-06-25 15:13:26 +02001515 ::DBus::Path interface_path;
1516 try {
1517 map<string, DBus::Variant> create_interface_args;
Paul Stewart0654ece2013-03-26 15:21:26 -07001518 create_interface_args[WPASupplicant::kInterfacePropertyName].writer().
Darin Petkov2b8e44e2012-06-25 15:13:26 +02001519 append_string(link_name().c_str());
Paul Stewart0654ece2013-03-26 15:21:26 -07001520 create_interface_args[WPASupplicant::kInterfacePropertyDriver].writer().
1521 append_string(WPASupplicant::kDriverNL80211);
Darin Petkov2b8e44e2012-06-25 15:13:26 +02001522 create_interface_args[
Paul Stewart0654ece2013-03-26 15:21:26 -07001523 WPASupplicant::kInterfacePropertyConfigFile].writer().
Darin Petkov60ceaf32012-10-18 10:36:01 +02001524 append_string(kSupplicantConfPath);
Darin Petkov2b8e44e2012-06-25 15:13:26 +02001525 interface_path =
1526 supplicant_process_proxy_->CreateInterface(create_interface_args);
1527 } catch (const DBus::Error &e) { // NOLINT
Paul Stewart0654ece2013-03-26 15:21:26 -07001528 if (!strcmp(e.name(), WPASupplicant::kErrorInterfaceExists)) {
Darin Petkov2b8e44e2012-06-25 15:13:26 +02001529 interface_path =
1530 supplicant_process_proxy_->GetInterface(link_name());
1531 // TODO(quiche): Is it okay to crash here, if device is missing?
1532 } else {
Paul Stewartb80c81c2012-06-28 13:05:45 -07001533 LOG(ERROR) << __func__ << ": Failed to create interface with supplicant.";
1534 return;
Darin Petkov2b8e44e2012-06-25 15:13:26 +02001535 }
1536 }
1537
1538 supplicant_interface_proxy_.reset(
1539 proxy_factory_->CreateSupplicantInterfaceProxy(
Paul Stewart0654ece2013-03-26 15:21:26 -07001540 this, interface_path, WPASupplicant::kDBusAddr));
Darin Petkov2b8e44e2012-06-25 15:13:26 +02001541
1542 RTNLHandler::GetInstance()->SetInterfaceFlags(interface_index(), IFF_UP,
1543 IFF_UP);
1544 // TODO(quiche) Set ApScan=1 and BSSExpireAge=190, like flimflam does?
1545
1546 // Clear out any networks that might previously have been configured
1547 // for this interface.
1548 supplicant_interface_proxy_->RemoveAllNetworks();
1549
1550 // Flush interface's BSS cache, so that we get BSSAdded signals for
1551 // all BSSes (not just new ones since the last scan).
1552 supplicant_interface_proxy_->FlushBSS(0);
1553
1554 try {
1555 // TODO(pstew): Disable fast_reauth until supplicant can properly deal
1556 // with RADIUS servers that respond strangely to such requests.
1557 // crosbug.com/25630
1558 supplicant_interface_proxy_->SetFastReauth(false);
1559 } catch (const DBus::Error &e) { // NOLINT
Christopher Wiley5519e9e2013-01-08 16:55:56 -08001560 LOG(ERROR) << "Failed to disable fast_reauth. "
1561 << "May be running an older version of wpa_supplicant.";
Darin Petkov2b8e44e2012-06-25 15:13:26 +02001562 }
1563
1564 try {
1565 // Helps with passing WiFiRomaing.001SSIDSwitchBack.
1566 supplicant_interface_proxy_->SetScanInterval(kRescanIntervalSeconds);
1567 } catch (const DBus::Error &e) { // NOLINT
Christopher Wiley5519e9e2013-01-08 16:55:56 -08001568 LOG(ERROR) << "Failed to set scan_interval. "
1569 << "May be running an older version of wpa_supplicant.";
1570 }
1571
1572 try {
1573 supplicant_interface_proxy_->SetDisableHighBitrates(true);
1574 } catch (const DBus::Error &e) { // NOLINT
1575 LOG(ERROR) << "Failed to disable high bitrates. "
1576 << "May be running an older version of wpa_supplicant.";
Darin Petkov2b8e44e2012-06-25 15:13:26 +02001577 }
1578
Darin Petkov2b8e44e2012-06-25 15:13:26 +02001579 Scan(NULL);
1580 StartScanTimer();
1581}
1582
Christopher Wiley5519e9e2013-01-08 16:55:56 -08001583void WiFi::EnableHighBitrates() {
1584 LOG(INFO) << "Enabling high bitrates.";
1585 try {
1586 supplicant_interface_proxy_->EnableHighBitrates();
1587 } catch (const DBus::Error &e) { // NOLINT
1588 LOG(ERROR) << "exception while enabling high rates: " << e.what();
1589 }
1590}
1591
Darin Petkov2b8e44e2012-06-25 15:13:26 +02001592void WiFi::Restart() {
1593 LOG(INFO) << link_name() << " restarting.";
1594 WiFiRefPtr me = this; // Make sure we don't get destructed.
1595 // Go through the manager rather than starting and stopping the device
1596 // directly so that the device can be configured with the profile.
1597 manager()->DeregisterDevice(me);
1598 manager()->RegisterDevice(me);
1599}
1600
Paul Stewartb50f0b92011-05-16 16:31:42 -07001601} // namespace shill