blob: ed739bfebaf0bcd11e8293d839ac70277afe48ea [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
Paul Stewart735eab52013-03-29 09:19:23 -07005#ifndef SHILL_WIFI_H_
6#define SHILL_WIFI_H_
Paul Stewartb50f0b92011-05-16 16:31:42 -07007
Gary Morain22601da2012-03-16 10:48:39 -07008// A WiFi device represents a wireless network interface implemented as an IEEE
9// 802.11 station. An Access Point (AP) (or, more correctly, a Basic Service
10// Set(BSS)) is represented by a WiFiEndpoint. An AP provides a WiFiService,
11// which is the same concept as Extended Service Set (ESS) in 802.11,
12// identified by an SSID. A WiFiService includes zero or more WiFiEndpoints
13// that provide that service.
14//
15// A WiFi device interacts with a real device through WPA Supplicant.
16// Wifi::Start() creates a connection to WPA Supplicant, represented by
17// |supplicant_interface_proxy_|. [1]
18//
19// A WiFi device becomes aware of WiFiEndpoints through BSSAdded signals from
20// WPA Supplicant, which identifies them by a "path". The WiFi object maintains
21// an EndpointMap in |endpoint_by_rpcid_|, in which the key is the "path" and
22// the value is a pointer to a WiFiEndpoint object. When a WiFiEndpoint is
23// added, it is associated with a WiFiService.
24//
Gary Morain22601da2012-03-16 10:48:39 -070025// The WiFi device connects to a WiFiService, not a WiFiEndpoint, through WPA
26// Supplicant. It is the job of WPA Supplicant to select a BSS (aka
27// WiFiEndpoint) to connect to. The protocol for establishing a connection is
28// as follows:
29//
30// 1. The WiFi device sends AddNetwork to WPA Supplicant, which returns a
31// "network path" when done.
32//
33// 2. The WiFi device sends SelectNetwork, indicating the network path
34// received in 1, to WPA Supplicant, which begins the process of associating
35// with an AP in the ESS. At this point the WiFiService which is being
36// connected is called the |pending_service_|.
37//
Paul Stewartbc6e7392012-05-24 07:07:48 -070038// 3. During association to an EAP-TLS network, WPA Supplicant can send
39// multiple "Certification" events, which provide information about the
40// identity of the remote entity.
41//
42// 4. When association is complete, WPA Supplicant sends a PropertiesChanged
43// signal to the WiFi device, indicating a change in the CurrentBSS. The
44// WiFiService indicated by the new value of CurrentBSS is set as the
45// |current_service_|, and |pending_service_| is (normally) cleared.
Gary Morain22601da2012-03-16 10:48:39 -070046//
47// Some key things to notice are 1) WPA Supplicant does the work of selecting
48// the AP (aka WiFiEndpoint) and it tells the WiFi device which AP it selected.
49// 2) The process of connecting is asynchronous. There is a |current_service_|
50// to which the WiFi device is presently using and a |pending_service_| to which
51// the WiFi device has initiated a connection.
52//
53// A WiFi device is notified that an AP has gone away via the BSSRemoved signal.
54// When the last WiFiEndpoint of a WiFiService is removed, the WiFiService
55// itself is deleted.
56//
57// TODO(gmorain): Add explanation of hidden SSIDs.
58//
59// WPA Supplicant's PropertiesChanged signal communicates changes in the state
60// of WPA Supplicant's current service. This state is stored in
61// |supplicant_state_| and reflects WPA Supplicant's view of the state of the
62// connection to an AP. Changes in this state sometimes cause state changes in
63// the WiFiService to which a WiFi device is connected. For example, when WPA
64// Supplicant signals the new state to be "completed", then the WiFiService
65// state gets changed to "configuring". State change notifications are not
66// reliable because WPA Supplicant may coalesce state changes in quick
67// succession so that only the last of the changes is signaled.
68//
69// Notes:
70//
71// 1. Shill's definition of the interface is described in
72// shill/dbus_bindings/supplicant-interface.xml, and the WPA Supplicant's
73// description of the same interface is in
74// third_party/wpa_supplicant/doc/dbus.doxygen.
75
mukesh agrawal5c05b292012-03-07 10:12:52 -080076#include <time.h>
77
mukesh agrawalab87ea42011-05-18 11:44:49 -070078#include <map>
Wade Guthrie92d06362013-04-25 15:41:30 -070079#include <set>
Chris Masone46eaaf52011-05-24 13:08:30 -070080#include <string>
mukesh agrawalab87ea42011-05-18 11:44:49 -070081#include <vector>
Chris Masone46eaaf52011-05-24 13:08:30 -070082
Eric Shienbrood9a245532012-03-07 14:20:39 -050083#include <base/callback_forward.h>
mukesh agrawalb66c6462012-05-07 11:45:25 -070084#include <base/cancelable_callback.h>
Wade Guthrie2edd58b2013-05-23 11:16:08 -070085#include <base/file_path.h>
Paul Stewart735eab52013-03-29 09:19:23 -070086#include <base/memory/scoped_ptr.h>
Eric Shienbrood9a245532012-03-07 14:20:39 -050087#include <base/memory/weak_ptr.h>
mukesh agrawalaf571952011-07-14 14:31:12 -070088#include <dbus-c++/dbus.h>
Paul Stewart6ab23a92011-11-09 17:17:47 -080089#include <gtest/gtest_prod.h> // for FRIEND_TEST
Wade Guthrie0cf3c982013-05-29 09:11:35 -070090#include <metrics/timer.h>
mukesh agrawalaf571952011-07-14 14:31:12 -070091
Darin Petkov2b8e44e2012-06-25 15:13:26 +020092#include "shill/dbus_manager.h"
Paul Stewartb50f0b92011-05-16 16:31:42 -070093#include "shill/device.h"
Paul Stewart26b327e2011-10-19 11:38:09 -070094#include "shill/event_dispatcher.h"
Wade Guthrieb9e0ee72013-05-31 09:23:30 -070095#include "shill/metrics.h"
Gary Morainac1bdb42012-02-16 17:42:29 -080096#include "shill/power_manager.h"
Chris Masone2b105542011-06-22 10:58:09 -070097#include "shill/refptr_types.h"
Paul Stewart1369c2b2013-01-11 05:41:26 -080098#include "shill/service.h"
Paul Stewart196f50f2013-03-27 18:02:11 -070099#include "shill/supplicant_event_delegate_interface.h"
Paul Stewartb50f0b92011-05-16 16:31:42 -0700100
101namespace shill {
102
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700103class Error;
Gaurav Shah6d2c72d2012-10-16 16:30:44 -0700104class GeolocationInfo;
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700105class KeyValueStore;
Wade Guthriebb9fca22013-04-10 17:21:42 -0700106class NetlinkManager;
Wade Guthrie92d06362013-04-25 15:41:30 -0700107class NetlinkMessage;
Wade Guthrie7347bf22013-04-30 11:21:51 -0700108class Nl80211Message;
Darin Petkovab565bb2011-10-06 02:55:51 -0700109class ProxyFactory;
Wade Guthrie5a4e2ef2013-04-30 12:51:39 -0700110class ScanSession;
Paul Stewart735eab52013-03-29 09:19:23 -0700111class SupplicantEAPStateHandler;
mukesh agrawalaf571952011-07-14 14:31:12 -0700112class SupplicantInterfaceProxyInterface;
113class SupplicantProcessProxyInterface;
Paul Stewart3c504012013-01-17 17:49:58 -0800114class WiFiProvider;
mukesh agrawal445e72c2011-06-22 11:13:50 -0700115class WiFiService;
mukesh agrawalb54601c2011-06-07 17:39:22 -0700116
mukesh agrawalab87ea42011-05-18 11:44:49 -0700117// WiFi class. Specialization of Device for WiFi.
Paul Stewart196f50f2013-03-27 18:02:11 -0700118class WiFi : public Device, public SupplicantEventDelegateInterface {
Paul Stewartb50f0b92011-05-16 16:31:42 -0700119 public:
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700120 WiFi(ControlInterface *control_interface,
121 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -0800122 Metrics *metrics,
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700123 Manager *manager,
Chris Masone626719f2011-08-18 16:58:48 -0700124 const std::string &link,
125 const std::string &address,
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700126 int interface_index);
mukesh agrawalab87ea42011-05-18 11:44:49 -0700127 virtual ~WiFi();
Darin Petkovc0865312011-09-16 15:31:20 -0700128
Eric Shienbrood9a245532012-03-07 14:20:39 -0500129 virtual void Start(Error *error, const EnabledStateChangedCallback &callback);
130 virtual void Stop(Error *error, const EnabledStateChangedCallback &callback);
Wade Guthrie4823f4f2013-07-25 10:03:03 -0700131 virtual void Scan(ScanType scan_type, Error *error,
132 const std::string &reason);
mukesh agrawal2f9df4e2012-08-08 12:29:20 -0700133 // Callback for system resume. If this WiFi device is idle, a scan
134 // is initiated. Additionally, the base class implementation is
135 // invoked unconditionally.
Christopher Wiley5519e9e2013-01-08 16:55:56 -0800136 virtual void OnAfterResume();
137 // Callback for when a service is configured with an IP.
138 virtual void OnConnected();
Paul Stewartf6f96482013-07-12 12:49:15 -0700139 // Callback for when a service fails to configure with an IP.
140 virtual void OnIPConfigFailure() override;
mukesh agrawalab87ea42011-05-18 11:44:49 -0700141
Paul Stewart196f50f2013-03-27 18:02:11 -0700142 // Implementation of SupplicantEventDelegateInterface. These methods
143 // are called by SupplicantInterfaceProxy, in response to events from
mukesh agrawalab87ea42011-05-18 11:44:49 -0700144 // wpa_supplicant.
Paul Stewart196f50f2013-03-27 18:02:11 -0700145 virtual void BSSAdded(
146 const ::DBus::Path &BSS,
mukesh agrawal7ec71312011-11-10 02:08:26 +0000147 const std::map<std::string, ::DBus::Variant> &properties);
Paul Stewart196f50f2013-03-27 18:02:11 -0700148 virtual void BSSRemoved(const ::DBus::Path &BSS);
149 virtual void Certification(
150 const std::map<std::string, ::DBus::Variant> &properties);
151 virtual void EAPEvent(
152 const std::string &status, const std::string &parameter);
153 virtual void PropertiesChanged(
154 const std::map<std::string, ::DBus::Variant> &properties);
155 virtual void ScanDone();
mukesh agrawalab87ea42011-05-18 11:44:49 -0700156
mukesh agrawal15908392011-11-16 18:29:25 +0000157 // Called by WiFiService.
mukesh agrawal6e277772011-09-29 15:04:23 -0700158 virtual void ConnectTo(
159 WiFiService *service,
mukesh agrawal64896322011-12-01 01:13:10 +0000160 std::map<std::string, ::DBus::Variant> service_params);
Paul Stewart835934a2012-12-06 19:27:09 -0800161 // If |service| is connected, initiate the process of disconnecting it.
162 // Otherwise, if it a pending or current service, discontinue the process
163 // of connecting and return |service| to the idle state.
mukesh agrawal0ed0f2e2011-12-05 20:36:17 +0000164 virtual void DisconnectFrom(WiFiService *service);
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000165 virtual bool IsIdle() const;
Paul Stewart835934a2012-12-06 19:27:09 -0800166 // Clear any cached credentials wpa_supplicant may be holding for
167 // |service|. This has a side-effect of disconnecting the service
168 // if it is connected.
169 virtual void ClearCachedCredentials(const WiFiService *service);
mukesh agrawalb54601c2011-06-07 17:39:22 -0700170
mukesh agrawalb20776f2012-02-10 16:00:36 -0800171 // Called by WiFiEndpoint.
Paul Stewart3c504012013-01-17 17:49:58 -0800172 virtual void NotifyEndpointChanged(const WiFiEndpointConstRefPtr &endpoint);
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700173
mukesh agrawal16bc1b82012-02-09 18:38:26 -0800174 // Utility, used by WiFiService and WiFiEndpoint.
175 // Replace non-ASCII characters with '?'. Return true if one or more
176 // characters were changed.
177 static bool SanitizeSSID(std::string *ssid);
178
Darin Petkov50cb78a2013-02-06 16:17:49 +0100179 // Formats |ssid| for logging purposes, to ease scrubbing.
180 static std::string LogSSID(const std::string &ssid);
181
Paul Stewart3c508e12012-08-09 11:40:06 -0700182 // Called by Linkmonitor (overriden from Device superclass).
183 virtual void OnLinkMonitorFailure();
184
Wade Guthrie8bc50882012-10-31 16:23:20 -0700185 bool IsCurrentService(const WiFiServiceRefPtr service) {
186 return service.get() == current_service_.get();
187 }
188
Arman Ugurayed8e6102012-11-29 14:47:20 -0800189 // Overridden from Device superclass
Gaurav Shah6d2c72d2012-10-16 16:30:44 -0700190 virtual std::vector<GeolocationInfo> GetGeolocationObjects() const;
191
Arman Ugurayed8e6102012-11-29 14:47:20 -0800192 // Overridden from Device superclass
193 virtual bool ShouldUseArpGateway() const;
194
Paul Stewart3c504012013-01-17 17:49:58 -0800195 // Called by a WiFiService when it disassociates itself from this Device.
196 virtual void DisassociateFromService(const WiFiServiceRefPtr &service);
197
Albert Chaulk0e1cdea2013-02-27 15:32:55 -0800198 // Called by a WiFiService when it unloads to destroy its lease file.
199 virtual void DestroyServiceLease(const WiFiService &service);
200
Paul Stewartb50f0b92011-05-16 16:31:42 -0700201 private:
Wade Guthrie0cf3c982013-05-29 09:11:35 -0700202 enum ScanMethod {
203 kScanMethodNone,
204 kScanMethodFull,
205 kScanMethodProgressive,
206 kScanMethodProgressiveErrorToFull,
207 kScanMethodProgressiveFinishedToFull
208 };
209 enum ScanState {
210 kScanIdle,
211 kScanScanning,
Paul Stewart3bdd3aa2013-08-20 13:20:54 -0700212 kScanBackgroundScanning,
Wade Guthriedf6d61b2013-07-17 11:43:55 -0700213 kScanTransitionToConnecting,
Wade Guthrie0cf3c982013-05-29 09:11:35 -0700214 kScanConnecting,
215 kScanConnected,
216 kScanFoundNothing
217 };
218
Paul Stewarte369ece2012-05-22 09:11:03 -0700219 friend class WiFiObjectTest; // access to supplicant_*_proxy_, link_up_
Paul Stewart1aff7302012-08-04 20:04:47 -0700220 friend class WiFiTimerTest; // kNumFastScanAttempts, kFastScanIntervalSeconds
Wade Guthrie9f4aa152013-07-29 16:03:14 -0700221 friend class WiFiMainTest; // ScanState, ScanMethod
Darin Petkov4a66cc52012-06-15 10:08:29 +0200222 FRIEND_TEST(WiFiMainTest, AppendBgscan);
Paul Stewart3bdd3aa2013-08-20 13:20:54 -0700223 FRIEND_TEST(WiFiMainTest, BackgroundScan); // ScanMethod, ScanState
Wade Guthriedf6d61b2013-07-17 11:43:55 -0700224 FRIEND_TEST(WiFiMainTest, ConnectToServiceNotPending); // ScanState
225 FRIEND_TEST(WiFiMainTest, ConnectToWithError); // ScanState
226 FRIEND_TEST(WiFiMainTest, ConnectWhileNotScanning); // ScanState
Wade Guthrie0cf3c982013-05-29 09:11:35 -0700227 FRIEND_TEST(WiFiMainTest, CurrentBSSChangedUpdateServiceEndpoint);
Christopher Wileyc6184482012-10-24 15:31:56 -0700228 FRIEND_TEST(WiFiMainTest, DisconnectCurrentServiceWithErrors);
Paul Stewarte369ece2012-05-22 09:11:03 -0700229 FRIEND_TEST(WiFiMainTest, FlushBSSOnResume); // kMaxBSSResumeAgeSeconds
Wade Guthrie0cf3c982013-05-29 09:11:35 -0700230 FRIEND_TEST(WiFiMainTest, FullScanConnecting); // ScanMethod, ScanState
231 FRIEND_TEST(WiFiMainTest, FullScanConnectingToConnected);
232 FRIEND_TEST(WiFiMainTest, FullScanFindsNothing); // ScanMethod, ScanState
mukesh agrawal7ec71312011-11-10 02:08:26 +0000233 FRIEND_TEST(WiFiMainTest, InitialSupplicantState); // kInterfaceStateUnknown
Paul Stewart3c508e12012-08-09 11:40:06 -0700234 FRIEND_TEST(WiFiMainTest, LinkMonitorFailure); // set_link_monitor()
Wade Guthrie0cf3c982013-05-29 09:11:35 -0700235 FRIEND_TEST(WiFiMainTest, ProgressiveScanConnectingToConnected);
Wade Guthriedf6d61b2013-07-17 11:43:55 -0700236 FRIEND_TEST(WiFiMainTest, ProgressiveScanConnectingToNotFound);
Wade Guthrie0cf3c982013-05-29 09:11:35 -0700237 FRIEND_TEST(WiFiMainTest, ProgressiveScanError); // ScanMethod, ScanState
238 FRIEND_TEST(WiFiMainTest, ProgressiveScanFound); // ScanMethod, ScanState
239 FRIEND_TEST(WiFiMainTest, ProgressiveScanNotFound); // ScanMethod, ScanState
Thieu Lee41a72d2012-02-06 20:46:51 +0000240 FRIEND_TEST(WiFiMainTest, ScanResults); // EndpointMap
mukesh agrawal165e6142011-11-22 02:22:56 +0000241 FRIEND_TEST(WiFiMainTest, ScanResultsWithUpdates); // EndpointMap
Wade Guthriedf6d61b2013-07-17 11:43:55 -0700242 FRIEND_TEST(WiFiMainTest, ScanStateHandleDisconnect); // ScanState
243 FRIEND_TEST(WiFiMainTest, ScanStateNotScanningNoUma); // ScanState
Wade Guthrieb9e0ee72013-05-31 09:23:30 -0700244 FRIEND_TEST(WiFiMainTest, ScanStateUma); // ScanState, ScanMethod
mukesh agrawalc4f368f2012-06-04 19:45:52 -0700245 FRIEND_TEST(WiFiMainTest, Stop); // weak_ptr_factory_
Wade Guthrie0cf3c982013-05-29 09:11:35 -0700246 FRIEND_TEST(WiFiMainTest, TimeoutPendingServiceWithEndpoints);
Darin Petkov60ceaf32012-10-18 10:36:01 +0200247 FRIEND_TEST(WiFiMainTest, VerifyPaths);
Darin Petkov4a66cc52012-06-15 10:08:29 +0200248 FRIEND_TEST(WiFiPropertyTest, BgscanMethodProperty); // bgscan_method_
Paul Stewart1aff7302012-08-04 20:04:47 -0700249 FRIEND_TEST(WiFiTimerTest, FastRescan); // kFastScanIntervalSeconds
Paul Stewart7cd45722013-08-12 14:50:14 -0700250 FRIEND_TEST(WiFiTimerTest, RequestStationInfo); // kRequestStationInfoPeriod
Paul Stewart6ab23a92011-11-09 17:17:47 -0800251
mukesh agrawalb54601c2011-06-07 17:39:22 -0700252 typedef std::map<const std::string, WiFiEndpointRefPtr> EndpointMap;
Paul Stewart835934a2012-12-06 19:27:09 -0800253 typedef std::map<const WiFiService *, std::string> ReverseServiceMap;
mukesh agrawalb54601c2011-06-07 17:39:22 -0700254
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800255 static const char *kDefaultBgscanMethod;
256 static const uint16 kDefaultBgscanShortIntervalSeconds;
257 static const int32 kDefaultBgscanSignalThresholdDbm;
258 static const uint16 kDefaultScanIntervalSeconds;
Darin Petkov4a66cc52012-06-15 10:08:29 +0200259 static const uint16 kBackgroundScanIntervalSeconds;
mukesh agrawal5c05b292012-03-07 10:12:52 -0800260 static const time_t kMaxBSSResumeAgeSeconds;
mukesh agrawal7ec71312011-11-10 02:08:26 +0000261 static const char kInterfaceStateUnknown[];
mukesh agrawalf2028172012-03-13 14:20:22 -0700262 // Delay between scans when supplicant finds "No suitable network".
263 static const time_t kRescanIntervalSeconds;
Paul Stewarte369ece2012-05-22 09:11:03 -0700264 // Number of times to quickly attempt a scan after startup / disconnect.
265 static const int kNumFastScanAttempts;
266 static const int kFastScanIntervalSeconds;
Paul Stewart2b05e622012-07-13 20:38:44 -0700267 static const int kPendingTimeoutSeconds;
Paul Stewart44663922012-07-30 11:03:03 -0700268 static const int kReconnectTimeoutSeconds;
Paul Stewart7cd45722013-08-12 14:50:14 -0700269 static const int kRequestStationInfoPeriodSeconds;
Wade Guthrie5a4e2ef2013-04-30 12:51:39 -0700270 static const size_t kMinumumFrequenciesToScan;
Wade Guthrie2edd58b2013-05-23 11:16:08 -0700271 static const float kDefaultFractionPerScan;
Wade Guthrie5a4e2ef2013-04-30 12:51:39 -0700272 static const char kProgressiveScanFlagFile[];
Wade Guthrie2edd58b2013-05-23 11:16:08 -0700273 // TODO(wdg): Remove after progressive scan field trial is over.
274 static const char kProgressiveScanFieldTrialFlagFile[];
mukesh agrawalab87ea42011-05-18 11:44:49 -0700275
Wade Guthrie92d06362013-04-25 15:41:30 -0700276 // Gets the list of frequencies supported by this device.
Wade Guthrie2edd58b2013-05-23 11:16:08 -0700277 // TODO(wdg): Remove after progressive scan field trial is over.
278 void ParseFieldTrialFile(const FilePath &field_trial_file_path);
Wade Guthrie92d06362013-04-25 15:41:30 -0700279 void ConfigureScanFrequencies();
Darin Petkov4a66cc52012-06-15 10:08:29 +0200280 void AppendBgscan(WiFiService *service,
281 std::map<std::string, DBus::Variant> *service_params) const;
282 std::string GetBgscanMethod(const int &argument, Error *error);
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800283 uint16 GetBgscanShortInterval(Error */* error */) {
284 return bgscan_short_interval_seconds_;
285 }
286 int32 GetBgscanSignalThreshold(Error */* error */) {
287 return bgscan_signal_threshold_dbm_;
288 }
289 uint16 GetScanInterval(Error */* error */) { return scan_interval_seconds_; }
Wade Guthrie0cf3c982013-05-29 09:11:35 -0700290 bool GetScanPending(Error */* error */);
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700291 bool SetBgscanMethod(
Darin Petkov4a66cc52012-06-15 10:08:29 +0200292 const int &argument, const std::string &method, Error *error);
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700293 bool SetBgscanShortInterval(const uint16 &seconds, Error *error);
294 bool SetBgscanSignalThreshold(const int32 &dbm, Error *error);
295 bool SetScanInterval(const uint16 &seconds, Error *error);
Darin Petkov4a66cc52012-06-15 10:08:29 +0200296 void ClearBgscanMethod(const int &argument, Error *error);
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800297
mukesh agrawal15908392011-11-16 18:29:25 +0000298 void CurrentBSSChanged(const ::DBus::Path &new_bss);
Paul Stewart835934a2012-12-06 19:27:09 -0800299 // Return the RPC identifier associated with the wpa_supplicant network
300 // entry created for |service|. If one does not exist, an empty string
301 // is returned, and |error| is populated.
302 std::string FindNetworkRpcidForService(const WiFiService *service,
303 Error *error);
mukesh agrawal15908392011-11-16 18:29:25 +0000304 void HandleDisconnect();
305 void HandleRoam(const ::DBus::Path &new_bssid);
mukesh agrawalb4bc57d2011-12-07 01:07:47 +0000306 void BSSAddedTask(const ::DBus::Path &BSS,
307 const std::map<std::string, ::DBus::Variant> &properties);
308 void BSSRemovedTask(const ::DBus::Path &BSS);
Paul Stewartbc6e7392012-05-24 07:07:48 -0700309 void CertificationTask(
310 const std::map<std::string, ::DBus::Variant> &properties);
Paul Stewartdb0f9172012-11-30 16:48:09 -0800311 void EAPEventTask(const std::string &status, const std::string &parameter);
mukesh agrawal15908392011-11-16 18:29:25 +0000312 void PropertiesChangedTask(
313 const std::map<std::string, ::DBus::Variant> &properties);
mukesh agrawaldc42bb32011-07-28 10:40:26 -0700314 void ScanDoneTask();
Wade Guthrie0cf3c982013-05-29 09:11:35 -0700315 // UpdateScanStateAfterScanDone is spawned as a task from ScanDoneTask in
316 // order to guarantee that it is run after the start of any connections that
317 // result from a scan. This works because supplicant sends all BSSAdded
318 // signals to shill before it sends a ScanDone signal. The code that
319 // handles those signals launch tasks such that the tasks have the following
320 // dependencies (an arrow from X->Y indicates X is guaranteed to run before
321 // Y):
322 //
323 // [BSSAdded]-->[BssAddedTask]-->[SortServiceTask (calls ConnectTo)]
324 // | | |
325 // V V V
326 // [ScanDone]-->[ScanDoneTask]-->[UpdateScanStateAfterScanDone]
327 void UpdateScanStateAfterScanDone();
mukesh agrawal32399322011-09-01 10:53:43 -0700328 void ScanTask();
mukesh agrawal7ec71312011-11-10 02:08:26 +0000329 void StateChanged(const std::string &new_state);
mukesh agrawalcf24a242012-05-21 16:46:11 -0700330 // Heuristic check if a connection failure was due to bad credentials.
Paul Stewart1369c2b2013-01-11 05:41:26 -0800331 // Returns true and puts type of failure in |failure| if a credential
332 // problem is detected.
Paul Stewartbca08f82013-07-09 16:32:37 -0700333 bool SuspectCredentials(WiFiServiceRefPtr service,
Paul Stewart1369c2b2013-01-11 05:41:26 -0800334 Service::ConnectFailure *failure) const;
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800335 void HelpRegisterDerivedInt32(
336 PropertyStore *store,
337 const std::string &name,
338 int32(WiFi::*get)(Error *error),
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700339 bool(WiFi::*set)(const int32 &value, Error *error));
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800340 void HelpRegisterDerivedUint16(
341 PropertyStore *store,
342 const std::string &name,
343 uint16(WiFi::*get)(Error *error),
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700344 bool(WiFi::*set)(const uint16 &value, Error *error));
Wade Guthrie0cf3c982013-05-29 09:11:35 -0700345 void HelpRegisterConstDerivedBool(
346 PropertyStore *store,
347 const std::string &name,
348 bool(WiFi::*get)(Error *error));
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800349
Paul Stewart835934a2012-12-06 19:27:09 -0800350 // Disable a network entry in wpa_supplicant, and catch any exception
351 // that occurs. Returns false if an exception occurred, true otherwise.
352 bool DisableNetwork(const ::DBus::Path &network);
353 // Disable the wpa_supplicant network entry associated with |service|.
354 // Any cached credentials stored in wpa_supplicant related to this
355 // network entry will be preserved. This will have the side-effect of
356 // disconnecting this service if it is currently connected. Returns
357 // true if successful, otherwise returns false and populates |error|
358 // with the reason for failure.
359 virtual bool DisableNetworkForService(
360 const WiFiService *service, Error *error);
Paul Stewart71f6ecd2012-09-13 14:52:18 -0700361 // Remove a network entry from wpa_supplicant, and catch any exception
362 // that occurs. Returns false if an exception occurred, true otherwise.
363 bool RemoveNetwork(const ::DBus::Path &network);
Paul Stewart835934a2012-12-06 19:27:09 -0800364 // Remove the wpa_supplicant network entry associated with |service|.
365 // Any cached credentials stored in wpa_supplicant related to this
366 // network entry will be removed. This will have the side-effect of
367 // disconnecting this service if it is currently connected. Returns
368 // true if successful, otherwise returns false and populates |error|
369 // with the reason for failure.
370 virtual bool RemoveNetworkForService(
371 const WiFiService *service, Error *error);
Wade Guthrie5a4e2ef2013-04-30 12:51:39 -0700372 // Perform the next in a series of progressive scans.
373 void ProgressiveScanTask();
374 // Recovers from failed progressive scan.
375 void OnFailedProgressiveScan();
Paul Stewarte369ece2012-05-22 09:11:03 -0700376 // Restart fast scanning after disconnection.
377 void RestartFastScanAttempts();
mukesh agrawalb66c6462012-05-07 11:45:25 -0700378 // Schedules a scan attempt at time |scan_interval_seconds_| in the
379 // future. Cancels any currently pending scan timer.
380 void StartScanTimer();
381 // Cancels any currently pending scan timer.
382 void StopScanTimer();
383 // Initiates a scan, if idle. Reschedules the scan timer regardless.
384 void ScanTimerHandler();
Wade Guthrie0cf3c982013-05-29 09:11:35 -0700385 // Abort any current scan (at the shill-level; let any request that's
386 // already gone out finish).
387 void AbortScan();
Paul Stewart2b05e622012-07-13 20:38:44 -0700388 // Starts a timer in order to limit the length of an attempt to
389 // connect to a pending network.
390 void StartPendingTimer();
391 // Cancels any currently pending network timer.
392 void StopPendingTimer();
393 // Aborts a pending network that is taking too long to connect.
394 void PendingTimeoutHandler();
Paul Stewart44663922012-07-30 11:03:03 -0700395 // Starts a timer in order to limit the length of an attempt to
396 // reconnect to the current network.
397 void StartReconnectTimer();
398 // Stops any pending reconnect timer.
399 void StopReconnectTimer();
400 // Disconnects from the current service that is taking too long
401 // to reconnect on its own.
402 void ReconnectTimeoutHandler();
Paul Stewart2b05e622012-07-13 20:38:44 -0700403 // Sets the current pending service. If the argument is non-NULL,
404 // the Pending timer is started and the associated service is set
405 // to "Associating", otherwise it is stopped.
406 void SetPendingService(const WiFiServiceRefPtr &service);
Gary Morainac1bdb42012-02-16 17:42:29 -0800407
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200408 void OnSupplicantAppear(const std::string &owner);
409 void OnSupplicantVanish();
Paul Stewart5581d072012-12-17 17:30:20 -0800410 // Called by ScopeLogger when WiFi debug scope is enabled/disabled.
411 void OnWiFiDebugScopeChanged(bool enabled);
Paul Stewarta47c3c62012-12-18 12:14:29 -0800412 // Enable or disable debugging for the current connection attempt.
413 void SetConnectionDebugging(bool enabled);
Christopher Wiley5519e9e2013-01-08 16:55:56 -0800414 // Enable high bitrates for the current network. High rates are disabled
415 // on the initial association and every reassociation afterward.
416 void EnableHighBitrates();
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200417
Paul Stewart7cd45722013-08-12 14:50:14 -0700418 // Request and retrieve information about the currently connected station.
419 void RequestStationInfo();
420 void OnReceivedStationInfo(const Nl80211Message &nl80211_message);
421 void StopRequestingStationInfo();
422
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200423 void ConnectToSupplicant();
424
425 void Restart();
426
Albert Chaulk0e1cdea2013-02-27 15:32:55 -0800427 std::string GetServiceLeaseName(const WiFiService &service);
428
Wade Guthrie92d06362013-04-25 15:41:30 -0700429 // Netlink message handler for NL80211_CMD_NEW_WIPHY messages; copies
430 // device's supported frequencies from that message into
431 // |all_scan_frequencies_|.
Wade Guthrie7347bf22013-04-30 11:21:51 -0700432 void OnNewWiphy(const Nl80211Message &nl80211_message);
Wade Guthrie92d06362013-04-25 15:41:30 -0700433
Wade Guthrieb0def9f2013-07-12 13:49:18 -0700434 void SetScanState(ScanState new_state,
435 ScanMethod new_method,
436 const char *reason);
Wade Guthrieb9e0ee72013-05-31 09:23:30 -0700437 void ReportScanResultToUma(ScanState state, ScanMethod method);
Wade Guthrie0cf3c982013-05-29 09:11:35 -0700438 static std::string ScanStateString(ScanState state, ScanMethod type);
439
Paul Stewart3c504012013-01-17 17:49:58 -0800440 // Pointer to the provider object that maintains WiFiService objects.
441 WiFiProvider *provider_;
442
Eric Shienbrood9a245532012-03-07 14:20:39 -0500443 base::WeakPtrFactory<WiFi> weak_ptr_factory_;
444
Darin Petkovab565bb2011-10-06 02:55:51 -0700445 // Store cached copies of singletons for speed/ease of testing.
446 ProxyFactory *proxy_factory_;
mukesh agrawal5c05b292012-03-07 10:12:52 -0800447 Time *time_;
Darin Petkovab565bb2011-10-06 02:55:51 -0700448
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200449 DBusManager::CancelableAppearedCallback on_supplicant_appear_;
450 DBusManager::CancelableVanishedCallback on_supplicant_vanish_;
451 bool supplicant_present_;
452
mukesh agrawalaf571952011-07-14 14:31:12 -0700453 scoped_ptr<SupplicantProcessProxyInterface> supplicant_process_proxy_;
454 scoped_ptr<SupplicantInterfaceProxyInterface> supplicant_interface_proxy_;
mukesh agrawal15908392011-11-16 18:29:25 +0000455 // The rpcid used as the key is wpa_supplicant's D-Bus path for the
456 // Endpoint (BSS, in supplicant parlance).
457 EndpointMap endpoint_by_rpcid_;
mukesh agrawal15908392011-11-16 18:29:25 +0000458 // Map from Services to the D-Bus path for the corresponding wpa_supplicant
459 // Network.
460 ReverseServiceMap rpcid_by_service_;
mukesh agrawal15908392011-11-16 18:29:25 +0000461 // The Service we are presently connected to. May be NULL is we're not
462 // not connected to any Service.
463 WiFiServiceRefPtr current_service_;
464 // The Service we're attempting to connect to. May be NULL if we're
465 // not attempting to connect to a new Service. If non-NULL, should
466 // be distinct from |current_service_|. (A service should not
467 // simultaneously be both pending, and current.)
468 WiFiServiceRefPtr pending_service_;
469 std::string supplicant_state_;
470 std::string supplicant_bss_;
mukesh agrawal5c05b292012-03-07 10:12:52 -0800471 // Indicates that we should flush supplicant's BSS cache after the
472 // next scan completes.
473 bool need_bss_flush_;
474 struct timeval resumed_at_;
mukesh agrawalb66c6462012-05-07 11:45:25 -0700475 // Executes when the (foreground) scan timer expires. Calls ScanTimerHandler.
476 base::CancelableClosure scan_timer_callback_;
Paul Stewart2b05e622012-07-13 20:38:44 -0700477 // Executes when a pending service connect timer expires. Calls
478 // PendingTimeoutHandler.
479 base::CancelableClosure pending_timeout_callback_;
Paul Stewart44663922012-07-30 11:03:03 -0700480 // Executes when a reconnecting service timer expires. Calls
481 // ReconnectTimeoutHandler.
482 base::CancelableClosure reconnect_timeout_callback_;
Paul Stewart7cd45722013-08-12 14:50:14 -0700483 // Executes periodically while a service is connected, to update the
484 // signal strength from the currently connected AP.
485 base::CancelableClosure request_station_info_callback_;
Paul Stewarte369ece2012-05-22 09:11:03 -0700486 // Number of remaining fast scans to be done during startup and disconnect.
487 int fast_scans_remaining_;
Christopher Wiley8f81e2a2012-10-17 16:51:32 -0700488 // Indicates that the current BSS has reached the completed state according
489 // to supplicant.
490 bool has_already_completed_;
Paul Stewarta47c3c62012-12-18 12:14:29 -0800491 // Indicates that we are debugging a problematic connection.
492 bool is_debugging_connection_;
Paul Stewart735eab52013-03-29 09:19:23 -0700493 // Tracks the process of an EAP negotiation.
494 scoped_ptr<SupplicantEAPStateHandler> eap_state_handler_;
mukesh agrawalab87ea42011-05-18 11:44:49 -0700495
Chris Masone853b81b2011-06-24 14:11:41 -0700496 // Properties
497 std::string bgscan_method_;
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800498 uint16 bgscan_short_interval_seconds_;
499 int32 bgscan_signal_threshold_dbm_;
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800500 uint16 scan_interval_seconds_;
Chris Masone853b81b2011-06-24 14:11:41 -0700501
Wade Guthrie5a4e2ef2013-04-30 12:51:39 -0700502 bool progressive_scan_enabled_;
Wade Guthrie04fd0482013-07-25 10:43:01 -0700503 std::string scan_configuration_;
Wade Guthriebb9fca22013-04-10 17:21:42 -0700504 NetlinkManager *netlink_manager_;
Wade Guthrie92d06362013-04-25 15:41:30 -0700505 std::set<uint16_t> all_scan_frequencies_;
Wade Guthrie5a4e2ef2013-04-30 12:51:39 -0700506 scoped_ptr<ScanSession> scan_session_;
507 size_t min_frequencies_to_scan_;
508 size_t max_frequencies_to_scan_;
Wade Guthrie0cf3c982013-05-29 09:11:35 -0700509
Wade Guthrie2edd58b2013-05-23 11:16:08 -0700510 // Fraction of previously seen scan frequencies to include in each
511 // progressive scan batch (since the frequencies are sorted, the sum of the
512 // fraction_per_scan_ over the scans in a session (* 100) is the percentile
513 // of the frequencies that have been scanned).
514 float fraction_per_scan_;
Wade Guthriebee87c22013-03-06 11:00:46 -0800515
Wade Guthrie0cf3c982013-05-29 09:11:35 -0700516 ScanState scan_state_;
517 ScanMethod scan_method_;
518 chromeos_metrics::Timer scan_timer_;
519
Paul Stewartf6f96482013-07-12 12:49:15 -0700520 // Used to compute the number of bytes received since the link went up.
521 uint64 receive_byte_count_at_connect_;
522
Paul Stewartb50f0b92011-05-16 16:31:42 -0700523 DISALLOW_COPY_AND_ASSIGN(WiFi);
524};
525
526} // namespace shill
527
Paul Stewart735eab52013-03-29 09:19:23 -0700528#endif // SHILL_WIFI_H_