blob: 5eee94e36d776e2ea5b14a63aad058b30cd222f7 [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
5#ifndef SHILL_WIFI_
6#define SHILL_WIFI_
7
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//
25// A WiFi device becomes aware of a WiFiService in three different ways. 1)
26// When a WiFiEndpoint is added through the BSSAdded signal, the WiFiEndpoint is
27// providing a service, and if that service is unknown to the WiFi device, it is
28// added at that point. 2) The Manager can add a WiFiService by calling
29// WiFi::GetService(). 3) Services are loaded from the profile through a call
30// to WiFi::Load().
31//
32// The WiFi device connects to a WiFiService, not a WiFiEndpoint, through WPA
33// Supplicant. It is the job of WPA Supplicant to select a BSS (aka
34// WiFiEndpoint) to connect to. The protocol for establishing a connection is
35// as follows:
36//
37// 1. The WiFi device sends AddNetwork to WPA Supplicant, which returns a
38// "network path" when done.
39//
40// 2. The WiFi device sends SelectNetwork, indicating the network path
41// received in 1, to WPA Supplicant, which begins the process of associating
42// with an AP in the ESS. At this point the WiFiService which is being
43// connected is called the |pending_service_|.
44//
Paul Stewartbc6e7392012-05-24 07:07:48 -070045// 3. During association to an EAP-TLS network, WPA Supplicant can send
46// multiple "Certification" events, which provide information about the
47// identity of the remote entity.
48//
49// 4. When association is complete, WPA Supplicant sends a PropertiesChanged
50// signal to the WiFi device, indicating a change in the CurrentBSS. The
51// WiFiService indicated by the new value of CurrentBSS is set as the
52// |current_service_|, and |pending_service_| is (normally) cleared.
Gary Morain22601da2012-03-16 10:48:39 -070053//
54// Some key things to notice are 1) WPA Supplicant does the work of selecting
55// the AP (aka WiFiEndpoint) and it tells the WiFi device which AP it selected.
56// 2) The process of connecting is asynchronous. There is a |current_service_|
57// to which the WiFi device is presently using and a |pending_service_| to which
58// the WiFi device has initiated a connection.
59//
60// A WiFi device is notified that an AP has gone away via the BSSRemoved signal.
61// When the last WiFiEndpoint of a WiFiService is removed, the WiFiService
62// itself is deleted.
63//
64// TODO(gmorain): Add explanation of hidden SSIDs.
65//
66// WPA Supplicant's PropertiesChanged signal communicates changes in the state
67// of WPA Supplicant's current service. This state is stored in
68// |supplicant_state_| and reflects WPA Supplicant's view of the state of the
69// connection to an AP. Changes in this state sometimes cause state changes in
70// the WiFiService to which a WiFi device is connected. For example, when WPA
71// Supplicant signals the new state to be "completed", then the WiFiService
72// state gets changed to "configuring". State change notifications are not
73// reliable because WPA Supplicant may coalesce state changes in quick
74// succession so that only the last of the changes is signaled.
75//
76// Notes:
77//
78// 1. Shill's definition of the interface is described in
79// shill/dbus_bindings/supplicant-interface.xml, and the WPA Supplicant's
80// description of the same interface is in
81// third_party/wpa_supplicant/doc/dbus.doxygen.
82
mukesh agrawal5c05b292012-03-07 10:12:52 -080083#include <time.h>
84
mukesh agrawalab87ea42011-05-18 11:44:49 -070085#include <map>
Chris Masone46eaaf52011-05-24 13:08:30 -070086#include <string>
mukesh agrawalab87ea42011-05-18 11:44:49 -070087#include <vector>
Chris Masone46eaaf52011-05-24 13:08:30 -070088
Eric Shienbrood9a245532012-03-07 14:20:39 -050089#include <base/callback_forward.h>
mukesh agrawalb66c6462012-05-07 11:45:25 -070090#include <base/cancelable_callback.h>
Eric Shienbrood9a245532012-03-07 14:20:39 -050091#include <base/memory/weak_ptr.h>
mukesh agrawalaf571952011-07-14 14:31:12 -070092#include <dbus-c++/dbus.h>
Paul Stewart6ab23a92011-11-09 17:17:47 -080093#include <gtest/gtest_prod.h> // for FRIEND_TEST
mukesh agrawalaf571952011-07-14 14:31:12 -070094
Darin Petkov2b8e44e2012-06-25 15:13:26 +020095#include "shill/dbus_manager.h"
Paul Stewartb50f0b92011-05-16 16:31:42 -070096#include "shill/device.h"
Paul Stewart26b327e2011-10-19 11:38:09 -070097#include "shill/event_dispatcher.h"
Gary Morainac1bdb42012-02-16 17:42:29 -080098#include "shill/power_manager.h"
Chris Masone2b105542011-06-22 10:58:09 -070099#include "shill/refptr_types.h"
Paul Stewart1369c2b2013-01-11 05:41:26 -0800100#include "shill/service.h"
Paul Stewartb50f0b92011-05-16 16:31:42 -0700101
102namespace shill {
103
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700104class Error;
Gaurav Shah6d2c72d2012-10-16 16:30:44 -0700105class GeolocationInfo;
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700106class KeyValueStore;
Darin Petkovab565bb2011-10-06 02:55:51 -0700107class ProxyFactory;
mukesh agrawalaf571952011-07-14 14:31:12 -0700108class SupplicantInterfaceProxyInterface;
109class SupplicantProcessProxyInterface;
mukesh agrawal445e72c2011-06-22 11:13:50 -0700110class WiFiService;
mukesh agrawalb54601c2011-06-07 17:39:22 -0700111
mukesh agrawalab87ea42011-05-18 11:44:49 -0700112// WiFi class. Specialization of Device for WiFi.
Paul Stewartb50f0b92011-05-16 16:31:42 -0700113class WiFi : public Device {
114 public:
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700115 WiFi(ControlInterface *control_interface,
116 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -0800117 Metrics *metrics,
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700118 Manager *manager,
Chris Masone626719f2011-08-18 16:58:48 -0700119 const std::string &link,
120 const std::string &address,
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700121 int interface_index);
mukesh agrawalab87ea42011-05-18 11:44:49 -0700122 virtual ~WiFi();
Darin Petkovc0865312011-09-16 15:31:20 -0700123
Eric Shienbrood9a245532012-03-07 14:20:39 -0500124 virtual void Start(Error *error, const EnabledStateChangedCallback &callback);
125 virtual void Stop(Error *error, const EnabledStateChangedCallback &callback);
Paul Stewarta41e38d2011-11-11 07:47:29 -0800126 virtual bool Load(StoreInterface *storage);
Darin Petkovc0865312011-09-16 15:31:20 -0700127 virtual void Scan(Error *error);
mukesh agrawal2f9df4e2012-08-08 12:29:20 -0700128 // Callback for system resume. If this WiFi device is idle, a scan
129 // is initiated. Additionally, the base class implementation is
130 // invoked unconditionally.
Christopher Wiley5519e9e2013-01-08 16:55:56 -0800131 virtual void OnAfterResume();
132 // Callback for when a service is configured with an IP.
133 virtual void OnConnected();
mukesh agrawalab87ea42011-05-18 11:44:49 -0700134
mukesh agrawal15908392011-11-16 18:29:25 +0000135 // Called by SupplicantInterfaceProxy, in response to events from
mukesh agrawalab87ea42011-05-18 11:44:49 -0700136 // wpa_supplicant.
137 void BSSAdded(const ::DBus::Path &BSS,
Chris Masonea82b7112011-05-25 15:16:29 -0700138 const std::map<std::string, ::DBus::Variant> &properties);
mukesh agrawal261daca2011-12-02 18:56:56 +0000139 void BSSRemoved(const ::DBus::Path &BSS);
Paul Stewartbc6e7392012-05-24 07:07:48 -0700140 void Certification(const std::map<std::string, ::DBus::Variant> &properties);
Paul Stewartdb0f9172012-11-30 16:48:09 -0800141 void EAPEvent(const std::string &status, const std::string &parameter);
mukesh agrawal7ec71312011-11-10 02:08:26 +0000142 void PropertiesChanged(
143 const std::map<std::string, ::DBus::Variant> &properties);
mukesh agrawalab87ea42011-05-18 11:44:49 -0700144 void ScanDone();
145
mukesh agrawal15908392011-11-16 18:29:25 +0000146 // Called by WiFiService.
mukesh agrawal6e277772011-09-29 15:04:23 -0700147 virtual void ConnectTo(
148 WiFiService *service,
mukesh agrawal64896322011-12-01 01:13:10 +0000149 std::map<std::string, ::DBus::Variant> service_params);
Paul Stewart835934a2012-12-06 19:27:09 -0800150 // If |service| is connected, initiate the process of disconnecting it.
151 // Otherwise, if it a pending or current service, discontinue the process
152 // of connecting and return |service| to the idle state.
mukesh agrawal0ed0f2e2011-12-05 20:36:17 +0000153 virtual void DisconnectFrom(WiFiService *service);
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000154 virtual bool IsIdle() const;
Paul Stewart835934a2012-12-06 19:27:09 -0800155 // Clear any cached credentials wpa_supplicant may be holding for
156 // |service|. This has a side-effect of disconnecting the service
157 // if it is connected.
158 virtual void ClearCachedCredentials(const WiFiService *service);
mukesh agrawalb54601c2011-06-07 17:39:22 -0700159
mukesh agrawalb20776f2012-02-10 16:00:36 -0800160 // Called by WiFiEndpoint.
161 virtual void NotifyEndpointChanged(const WiFiEndpoint &endpoint);
162
mukesh agrawal15908392011-11-16 18:29:25 +0000163 // Called by Manager.
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700164 virtual WiFiServiceRefPtr GetService(const KeyValueStore &args, Error *error);
165
mukesh agrawal16bc1b82012-02-09 18:38:26 -0800166 // Utility, used by WiFiService and WiFiEndpoint.
167 // Replace non-ASCII characters with '?'. Return true if one or more
168 // characters were changed.
169 static bool SanitizeSSID(std::string *ssid);
170
Paul Stewart3c508e12012-08-09 11:40:06 -0700171 // Called by Linkmonitor (overriden from Device superclass).
172 virtual void OnLinkMonitorFailure();
173
Wade Guthrie8bc50882012-10-31 16:23:20 -0700174 bool IsCurrentService(const WiFiServiceRefPtr service) {
175 return service.get() == current_service_.get();
176 }
177
Arman Ugurayed8e6102012-11-29 14:47:20 -0800178 // Overridden from Device superclass
Gaurav Shah6d2c72d2012-10-16 16:30:44 -0700179 virtual std::vector<GeolocationInfo> GetGeolocationObjects() const;
180
Arman Ugurayed8e6102012-11-29 14:47:20 -0800181 // Overridden from Device superclass
182 virtual bool ShouldUseArpGateway() const;
183
Paul Stewartb50f0b92011-05-16 16:31:42 -0700184 private:
Paul Stewarte369ece2012-05-22 09:11:03 -0700185 friend class WiFiObjectTest; // access to supplicant_*_proxy_, link_up_
Paul Stewart1aff7302012-08-04 20:04:47 -0700186 friend class WiFiTimerTest; // kNumFastScanAttempts, kFastScanIntervalSeconds
Darin Petkov4a66cc52012-06-15 10:08:29 +0200187 FRIEND_TEST(WiFiMainTest, AppendBgscan);
Christopher Wileyc6184482012-10-24 15:31:56 -0700188 FRIEND_TEST(WiFiMainTest, DisconnectCurrentServiceWithErrors);
Paul Stewarte369ece2012-05-22 09:11:03 -0700189 FRIEND_TEST(WiFiMainTest, FlushBSSOnResume); // kMaxBSSResumeAgeSeconds
mukesh agrawal7ec71312011-11-10 02:08:26 +0000190 FRIEND_TEST(WiFiMainTest, InitialSupplicantState); // kInterfaceStateUnknown
Paul Stewart3c508e12012-08-09 11:40:06 -0700191 FRIEND_TEST(WiFiMainTest, LinkMonitorFailure); // set_link_monitor()
Thieu Lee41a72d2012-02-06 20:46:51 +0000192 FRIEND_TEST(WiFiMainTest, ScanResults); // EndpointMap
mukesh agrawal165e6142011-11-22 02:22:56 +0000193 FRIEND_TEST(WiFiMainTest, ScanResultsWithUpdates); // EndpointMap
mukesh agrawalc4f368f2012-06-04 19:45:52 -0700194 FRIEND_TEST(WiFiMainTest, Stop); // weak_ptr_factory_
Darin Petkov60ceaf32012-10-18 10:36:01 +0200195 FRIEND_TEST(WiFiMainTest, VerifyPaths);
Darin Petkov4a66cc52012-06-15 10:08:29 +0200196 FRIEND_TEST(WiFiPropertyTest, BgscanMethodProperty); // bgscan_method_
Paul Stewart1aff7302012-08-04 20:04:47 -0700197 FRIEND_TEST(WiFiTimerTest, FastRescan); // kFastScanIntervalSeconds
Paul Stewart6ab23a92011-11-09 17:17:47 -0800198
mukesh agrawalb54601c2011-06-07 17:39:22 -0700199 typedef std::map<const std::string, WiFiEndpointRefPtr> EndpointMap;
Paul Stewart835934a2012-12-06 19:27:09 -0800200 typedef std::map<const WiFiService *, std::string> ReverseServiceMap;
mukesh agrawalb54601c2011-06-07 17:39:22 -0700201
Darin Petkov60ceaf32012-10-18 10:36:01 +0200202 static const char kSupplicantConfPath[];
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800203 static const char *kDefaultBgscanMethod;
204 static const uint16 kDefaultBgscanShortIntervalSeconds;
205 static const int32 kDefaultBgscanSignalThresholdDbm;
206 static const uint16 kDefaultScanIntervalSeconds;
Darin Petkov4a66cc52012-06-15 10:08:29 +0200207 static const uint16 kBackgroundScanIntervalSeconds;
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700208 static const char kManagerErrorSSIDTooLong[];
209 static const char kManagerErrorSSIDTooShort[];
210 static const char kManagerErrorSSIDRequired[];
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700211 static const char kManagerErrorUnsupportedSecurityMode[];
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700212 static const char kManagerErrorUnsupportedServiceMode[];
mukesh agrawal5c05b292012-03-07 10:12:52 -0800213 static const time_t kMaxBSSResumeAgeSeconds;
mukesh agrawal7ec71312011-11-10 02:08:26 +0000214 static const char kInterfaceStateUnknown[];
mukesh agrawalf2028172012-03-13 14:20:22 -0700215 // Delay between scans when supplicant finds "No suitable network".
216 static const time_t kRescanIntervalSeconds;
Paul Stewarte369ece2012-05-22 09:11:03 -0700217 // Number of times to quickly attempt a scan after startup / disconnect.
218 static const int kNumFastScanAttempts;
219 static const int kFastScanIntervalSeconds;
Paul Stewart2b05e622012-07-13 20:38:44 -0700220 static const int kPendingTimeoutSeconds;
Paul Stewart44663922012-07-30 11:03:03 -0700221 static const int kReconnectTimeoutSeconds;
mukesh agrawalab87ea42011-05-18 11:44:49 -0700222
Darin Petkov4a66cc52012-06-15 10:08:29 +0200223 void AppendBgscan(WiFiService *service,
224 std::map<std::string, DBus::Variant> *service_params) const;
225 std::string GetBgscanMethod(const int &argument, Error *error);
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800226 uint16 GetBgscanShortInterval(Error */* error */) {
227 return bgscan_short_interval_seconds_;
228 }
229 int32 GetBgscanSignalThreshold(Error */* error */) {
230 return bgscan_signal_threshold_dbm_;
231 }
232 uint16 GetScanInterval(Error */* error */) { return scan_interval_seconds_; }
Darin Petkov4a66cc52012-06-15 10:08:29 +0200233 void SetBgscanMethod(
234 const int &argument, const std::string &method, Error *error);
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800235 void SetBgscanShortInterval(const uint16 &seconds, Error *error);
236 void SetBgscanSignalThreshold(const int32 &dbm, Error *error);
237 void SetScanInterval(const uint16 &seconds, Error *error);
Darin Petkov4a66cc52012-06-15 10:08:29 +0200238 void ClearBgscanMethod(const int &argument, Error *error);
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800239
mukesh agrawal15908392011-11-16 18:29:25 +0000240 WiFiServiceRefPtr CreateServiceForEndpoint(
241 const WiFiEndpoint &endpoint, bool hidden_ssid);
242 void CurrentBSSChanged(const ::DBus::Path &new_bss);
Paul Stewart6ab23a92011-11-09 17:17:47 -0800243 WiFiServiceRefPtr FindService(const std::vector<uint8_t> &ssid,
244 const std::string &mode,
245 const std::string &security) const;
mukesh agrawal165e6142011-11-22 02:22:56 +0000246 WiFiServiceRefPtr FindServiceForEndpoint(const WiFiEndpoint &endpoint);
Paul Stewart835934a2012-12-06 19:27:09 -0800247 // Return the RPC identifier associated with the wpa_supplicant network
248 // entry created for |service|. If one does not exist, an empty string
249 // is returned, and |error| is populated.
250 std::string FindNetworkRpcidForService(const WiFiService *service,
251 Error *error);
Paul Stewartced6a0b2011-11-08 15:32:04 -0800252 ByteArrays GetHiddenSSIDList();
mukesh agrawal15908392011-11-16 18:29:25 +0000253 void HandleDisconnect();
254 void HandleRoam(const ::DBus::Path &new_bssid);
Paul Stewarta41e38d2011-11-11 07:47:29 -0800255 // Create services for hidden networks stored in |storage|. Returns true
256 // if any were found, otherwise returns false.
257 bool LoadHiddenServices(StoreInterface *storage);
mukesh agrawalb4bc57d2011-12-07 01:07:47 +0000258 void BSSAddedTask(const ::DBus::Path &BSS,
259 const std::map<std::string, ::DBus::Variant> &properties);
260 void BSSRemovedTask(const ::DBus::Path &BSS);
Paul Stewartbc6e7392012-05-24 07:07:48 -0700261 void CertificationTask(
262 const std::map<std::string, ::DBus::Variant> &properties);
Paul Stewartdb0f9172012-11-30 16:48:09 -0800263 void EAPEventTask(const std::string &status, const std::string &parameter);
mukesh agrawal15908392011-11-16 18:29:25 +0000264 void PropertiesChangedTask(
265 const std::map<std::string, ::DBus::Variant> &properties);
mukesh agrawaldc42bb32011-07-28 10:40:26 -0700266 void ScanDoneTask();
mukesh agrawal32399322011-09-01 10:53:43 -0700267 void ScanTask();
Paul Stewartd2db2b12013-01-17 13:11:07 -0800268 void SetScanPending(bool pending);
mukesh agrawal7ec71312011-11-10 02:08:26 +0000269 void StateChanged(const std::string &new_state);
mukesh agrawalcf24a242012-05-21 16:46:11 -0700270 // Heuristic check if a connection failure was due to bad credentials.
Paul Stewart1369c2b2013-01-11 05:41:26 -0800271 // Returns true and puts type of failure in |failure| if a credential
272 // problem is detected.
273 bool SuspectCredentials(const WiFiService &service,
274 Service::ConnectFailure *failure) const;
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800275 void HelpRegisterDerivedInt32(
276 PropertyStore *store,
277 const std::string &name,
278 int32(WiFi::*get)(Error *error),
279 void(WiFi::*set)(const int32 &value, Error *error));
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800280 void HelpRegisterDerivedUint16(
281 PropertyStore *store,
282 const std::string &name,
283 uint16(WiFi::*get)(Error *error),
284 void(WiFi::*set)(const uint16 &value, Error *error));
285
Paul Stewart835934a2012-12-06 19:27:09 -0800286 // Disable a network entry in wpa_supplicant, and catch any exception
287 // that occurs. Returns false if an exception occurred, true otherwise.
288 bool DisableNetwork(const ::DBus::Path &network);
289 // Disable the wpa_supplicant network entry associated with |service|.
290 // Any cached credentials stored in wpa_supplicant related to this
291 // network entry will be preserved. This will have the side-effect of
292 // disconnecting this service if it is currently connected. Returns
293 // true if successful, otherwise returns false and populates |error|
294 // with the reason for failure.
295 virtual bool DisableNetworkForService(
296 const WiFiService *service, Error *error);
Paul Stewart71f6ecd2012-09-13 14:52:18 -0700297 // Remove a network entry from wpa_supplicant, and catch any exception
298 // that occurs. Returns false if an exception occurred, true otherwise.
299 bool RemoveNetwork(const ::DBus::Path &network);
Paul Stewart835934a2012-12-06 19:27:09 -0800300 // Remove the wpa_supplicant network entry associated with |service|.
301 // Any cached credentials stored in wpa_supplicant related to this
302 // network entry will be removed. This will have the side-effect of
303 // disconnecting this service if it is currently connected. Returns
304 // true if successful, otherwise returns false and populates |error|
305 // with the reason for failure.
306 virtual bool RemoveNetworkForService(
307 const WiFiService *service, Error *error);
Paul Stewarte369ece2012-05-22 09:11:03 -0700308 // Restart fast scanning after disconnection.
309 void RestartFastScanAttempts();
mukesh agrawalb66c6462012-05-07 11:45:25 -0700310 // Schedules a scan attempt at time |scan_interval_seconds_| in the
311 // future. Cancels any currently pending scan timer.
312 void StartScanTimer();
313 // Cancels any currently pending scan timer.
314 void StopScanTimer();
315 // Initiates a scan, if idle. Reschedules the scan timer regardless.
316 void ScanTimerHandler();
Paul Stewart2b05e622012-07-13 20:38:44 -0700317 // Starts a timer in order to limit the length of an attempt to
318 // connect to a pending network.
319 void StartPendingTimer();
320 // Cancels any currently pending network timer.
321 void StopPendingTimer();
322 // Aborts a pending network that is taking too long to connect.
323 void PendingTimeoutHandler();
Paul Stewart44663922012-07-30 11:03:03 -0700324 // Starts a timer in order to limit the length of an attempt to
325 // reconnect to the current network.
326 void StartReconnectTimer();
327 // Stops any pending reconnect timer.
328 void StopReconnectTimer();
329 // Disconnects from the current service that is taking too long
330 // to reconnect on its own.
331 void ReconnectTimeoutHandler();
Paul Stewart2b05e622012-07-13 20:38:44 -0700332 // Sets the current pending service. If the argument is non-NULL,
333 // the Pending timer is started and the associated service is set
334 // to "Associating", otherwise it is stopped.
335 void SetPendingService(const WiFiServiceRefPtr &service);
Gary Morainac1bdb42012-02-16 17:42:29 -0800336
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200337 void OnSupplicantAppear(const std::string &owner);
338 void OnSupplicantVanish();
Paul Stewart5581d072012-12-17 17:30:20 -0800339 // Called by ScopeLogger when WiFi debug scope is enabled/disabled.
340 void OnWiFiDebugScopeChanged(bool enabled);
Paul Stewarta47c3c62012-12-18 12:14:29 -0800341 // Enable or disable debugging for the current connection attempt.
342 void SetConnectionDebugging(bool enabled);
Christopher Wiley5519e9e2013-01-08 16:55:56 -0800343 // Enable high bitrates for the current network. High rates are disabled
344 // on the initial association and every reassociation afterward.
345 void EnableHighBitrates();
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200346
347 void ConnectToSupplicant();
348
349 void Restart();
350
Eric Shienbrood9a245532012-03-07 14:20:39 -0500351 base::WeakPtrFactory<WiFi> weak_ptr_factory_;
352
Darin Petkovab565bb2011-10-06 02:55:51 -0700353 // Store cached copies of singletons for speed/ease of testing.
354 ProxyFactory *proxy_factory_;
mukesh agrawal5c05b292012-03-07 10:12:52 -0800355 Time *time_;
Darin Petkovab565bb2011-10-06 02:55:51 -0700356
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200357 DBusManager::CancelableAppearedCallback on_supplicant_appear_;
358 DBusManager::CancelableVanishedCallback on_supplicant_vanish_;
359 bool supplicant_present_;
360
mukesh agrawalaf571952011-07-14 14:31:12 -0700361 scoped_ptr<SupplicantProcessProxyInterface> supplicant_process_proxy_;
362 scoped_ptr<SupplicantInterfaceProxyInterface> supplicant_interface_proxy_;
mukesh agrawal15908392011-11-16 18:29:25 +0000363 // The rpcid used as the key is wpa_supplicant's D-Bus path for the
364 // Endpoint (BSS, in supplicant parlance).
365 EndpointMap endpoint_by_rpcid_;
mukesh agrawal15908392011-11-16 18:29:25 +0000366 // Map from Services to the D-Bus path for the corresponding wpa_supplicant
367 // Network.
368 ReverseServiceMap rpcid_by_service_;
mukesh agrawal15908392011-11-16 18:29:25 +0000369 std::vector<WiFiServiceRefPtr> services_;
370 // The Service we are presently connected to. May be NULL is we're not
371 // not connected to any Service.
372 WiFiServiceRefPtr current_service_;
373 // The Service we're attempting to connect to. May be NULL if we're
374 // not attempting to connect to a new Service. If non-NULL, should
375 // be distinct from |current_service_|. (A service should not
376 // simultaneously be both pending, and current.)
377 WiFiServiceRefPtr pending_service_;
378 std::string supplicant_state_;
379 std::string supplicant_bss_;
Paul Stewartdb0f9172012-11-30 16:48:09 -0800380 std::string supplicant_tls_error_;
mukesh agrawal5c05b292012-03-07 10:12:52 -0800381 // Indicates that we should flush supplicant's BSS cache after the
382 // next scan completes.
383 bool need_bss_flush_;
384 struct timeval resumed_at_;
mukesh agrawalb66c6462012-05-07 11:45:25 -0700385 // Executes when the (foreground) scan timer expires. Calls ScanTimerHandler.
386 base::CancelableClosure scan_timer_callback_;
Paul Stewart2b05e622012-07-13 20:38:44 -0700387 // Executes when a pending service connect timer expires. Calls
388 // PendingTimeoutHandler.
389 base::CancelableClosure pending_timeout_callback_;
Paul Stewart44663922012-07-30 11:03:03 -0700390 // Executes when a reconnecting service timer expires. Calls
391 // ReconnectTimeoutHandler.
392 base::CancelableClosure reconnect_timeout_callback_;
Paul Stewarte369ece2012-05-22 09:11:03 -0700393 // Number of remaining fast scans to be done during startup and disconnect.
394 int fast_scans_remaining_;
Christopher Wiley8f81e2a2012-10-17 16:51:32 -0700395 // Indicates that the current BSS has reached the completed state according
396 // to supplicant.
397 bool has_already_completed_;
Paul Stewarta47c3c62012-12-18 12:14:29 -0800398 // Indicates that we are debugging a problematic connection.
399 bool is_debugging_connection_;
Paul Stewart1369c2b2013-01-11 05:41:26 -0800400 // Indicates that we are in the middle of EAP authentication.
401 bool is_eap_in_progress_;
mukesh agrawalab87ea42011-05-18 11:44:49 -0700402
Chris Masone853b81b2011-06-24 14:11:41 -0700403 // Properties
404 std::string bgscan_method_;
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800405 uint16 bgscan_short_interval_seconds_;
406 int32 bgscan_signal_threshold_dbm_;
Chris Masone853b81b2011-06-24 14:11:41 -0700407 bool scan_pending_;
mukesh agrawal4d0401c2012-01-06 16:05:31 -0800408 uint16 scan_interval_seconds_;
Chris Masone853b81b2011-06-24 14:11:41 -0700409
Paul Stewartb50f0b92011-05-16 16:31:42 -0700410 DISALLOW_COPY_AND_ASSIGN(WiFi);
411};
412
413} // namespace shill
414
415#endif // SHILL_WIFI_