mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef SHILL_WIFI_ |
| 6 | #define SHILL_WIFI_ |
| 7 | |
Gary Morain | 22601da | 2012-03-16 10:48:39 -0700 | [diff] [blame] | 8 | // 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 Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 45 | // 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 Morain | 22601da | 2012-03-16 10:48:39 -0700 | [diff] [blame] | 53 | // |
| 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 agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 83 | #include <time.h> |
| 84 | |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 85 | #include <map> |
Chris Masone | 46eaaf5 | 2011-05-24 13:08:30 -0700 | [diff] [blame] | 86 | #include <string> |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 87 | #include <vector> |
Chris Masone | 46eaaf5 | 2011-05-24 13:08:30 -0700 | [diff] [blame] | 88 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 89 | #include <base/callback_forward.h> |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 90 | #include <base/cancelable_callback.h> |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 91 | #include <base/memory/weak_ptr.h> |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 92 | #include <dbus-c++/dbus.h> |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 93 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 94 | |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 95 | #include "shill/dbus_manager.h" |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 96 | #include "shill/device.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 97 | #include "shill/event_dispatcher.h" |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 98 | #include "shill/power_manager.h" |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 99 | #include "shill/refptr_types.h" |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 100 | |
| 101 | namespace shill { |
| 102 | |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 103 | class Error; |
Gaurav Shah | 6d2c72d | 2012-10-16 16:30:44 -0700 | [diff] [blame] | 104 | class GeolocationInfo; |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 105 | class KeyValueStore; |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 106 | class ProxyFactory; |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 107 | class SupplicantInterfaceProxyInterface; |
| 108 | class SupplicantProcessProxyInterface; |
mukesh agrawal | 445e72c | 2011-06-22 11:13:50 -0700 | [diff] [blame] | 109 | class WiFiService; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 110 | |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 111 | // WiFi class. Specialization of Device for WiFi. |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 112 | class WiFi : public Device { |
| 113 | public: |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 114 | WiFi(ControlInterface *control_interface, |
| 115 | EventDispatcher *dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 116 | Metrics *metrics, |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 117 | Manager *manager, |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 118 | const std::string &link, |
| 119 | const std::string &address, |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 120 | int interface_index); |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 121 | virtual ~WiFi(); |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 122 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 123 | virtual void Start(Error *error, const EnabledStateChangedCallback &callback); |
| 124 | virtual void Stop(Error *error, const EnabledStateChangedCallback &callback); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 125 | virtual bool Load(StoreInterface *storage); |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 126 | virtual void Scan(Error *error); |
mukesh agrawal | 2f9df4e | 2012-08-08 12:29:20 -0700 | [diff] [blame] | 127 | // Callback for system resume. If this WiFi device is idle, a scan |
| 128 | // is initiated. Additionally, the base class implementation is |
| 129 | // invoked unconditionally. |
| 130 | void OnAfterResume(); |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 131 | |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 132 | // Called by SupplicantInterfaceProxy, in response to events from |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 133 | // wpa_supplicant. |
| 134 | void BSSAdded(const ::DBus::Path &BSS, |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 135 | const std::map<std::string, ::DBus::Variant> &properties); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 136 | void BSSRemoved(const ::DBus::Path &BSS); |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 137 | void Certification(const std::map<std::string, ::DBus::Variant> &properties); |
Paul Stewart | db0f917 | 2012-11-30 16:48:09 -0800 | [diff] [blame] | 138 | void EAPEvent(const std::string &status, const std::string ¶meter); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 139 | void PropertiesChanged( |
| 140 | const std::map<std::string, ::DBus::Variant> &properties); |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 141 | void ScanDone(); |
| 142 | |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 143 | // Called by WiFiService. |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 144 | virtual void ConnectTo( |
| 145 | WiFiService *service, |
mukesh agrawal | 6489632 | 2011-12-01 01:13:10 +0000 | [diff] [blame] | 146 | std::map<std::string, ::DBus::Variant> service_params); |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 147 | // If |service| is connected, initiate the process of disconnecting it. |
| 148 | // Otherwise, if it a pending or current service, discontinue the process |
| 149 | // of connecting and return |service| to the idle state. |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 150 | virtual void DisconnectFrom(WiFiService *service); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 151 | virtual bool IsIdle() const; |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 152 | // Clear any cached credentials wpa_supplicant may be holding for |
| 153 | // |service|. This has a side-effect of disconnecting the service |
| 154 | // if it is connected. |
| 155 | virtual void ClearCachedCredentials(const WiFiService *service); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 156 | |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 157 | // Called by WiFiEndpoint. |
| 158 | virtual void NotifyEndpointChanged(const WiFiEndpoint &endpoint); |
| 159 | |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 160 | // Called by Manager. |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 161 | virtual WiFiServiceRefPtr GetService(const KeyValueStore &args, Error *error); |
| 162 | |
mukesh agrawal | 16bc1b8 | 2012-02-09 18:38:26 -0800 | [diff] [blame] | 163 | // Utility, used by WiFiService and WiFiEndpoint. |
| 164 | // Replace non-ASCII characters with '?'. Return true if one or more |
| 165 | // characters were changed. |
| 166 | static bool SanitizeSSID(std::string *ssid); |
| 167 | |
Paul Stewart | 3c508e1 | 2012-08-09 11:40:06 -0700 | [diff] [blame] | 168 | // Called by Linkmonitor (overriden from Device superclass). |
| 169 | virtual void OnLinkMonitorFailure(); |
| 170 | |
Wade Guthrie | 8bc5088 | 2012-10-31 16:23:20 -0700 | [diff] [blame] | 171 | bool IsCurrentService(const WiFiServiceRefPtr service) { |
| 172 | return service.get() == current_service_.get(); |
| 173 | } |
| 174 | |
Arman Uguray | ed8e610 | 2012-11-29 14:47:20 -0800 | [diff] [blame] | 175 | // Overridden from Device superclass |
Gaurav Shah | 6d2c72d | 2012-10-16 16:30:44 -0700 | [diff] [blame] | 176 | virtual std::vector<GeolocationInfo> GetGeolocationObjects() const; |
| 177 | |
Arman Uguray | ed8e610 | 2012-11-29 14:47:20 -0800 | [diff] [blame] | 178 | // Overridden from Device superclass |
| 179 | virtual bool ShouldUseArpGateway() const; |
| 180 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 181 | private: |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 182 | friend class WiFiObjectTest; // access to supplicant_*_proxy_, link_up_ |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 183 | friend class WiFiTimerTest; // kNumFastScanAttempts, kFastScanIntervalSeconds |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 184 | FRIEND_TEST(WiFiMainTest, AppendBgscan); |
Christopher Wiley | c618448 | 2012-10-24 15:31:56 -0700 | [diff] [blame] | 185 | FRIEND_TEST(WiFiMainTest, DisconnectCurrentServiceWithErrors); |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 186 | FRIEND_TEST(WiFiMainTest, FlushBSSOnResume); // kMaxBSSResumeAgeSeconds |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 187 | FRIEND_TEST(WiFiMainTest, InitialSupplicantState); // kInterfaceStateUnknown |
Paul Stewart | 3c508e1 | 2012-08-09 11:40:06 -0700 | [diff] [blame] | 188 | FRIEND_TEST(WiFiMainTest, LinkMonitorFailure); // set_link_monitor() |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 189 | FRIEND_TEST(WiFiMainTest, ScanResults); // EndpointMap |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 190 | FRIEND_TEST(WiFiMainTest, ScanResultsWithUpdates); // EndpointMap |
mukesh agrawal | c4f368f | 2012-06-04 19:45:52 -0700 | [diff] [blame] | 191 | FRIEND_TEST(WiFiMainTest, Stop); // weak_ptr_factory_ |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 192 | FRIEND_TEST(WiFiMainTest, SuspectCredentialsOpen); // SuspectCredentials |
| 193 | FRIEND_TEST(WiFiMainTest, SuspectCredentialsWPANeverConnected); // as above |
| 194 | FRIEND_TEST(WiFiMainTest, SuspectCredentialsWPAPreviouslyConnected); // "" |
Darin Petkov | 60ceaf3 | 2012-10-18 10:36:01 +0200 | [diff] [blame] | 195 | FRIEND_TEST(WiFiMainTest, VerifyPaths); |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 196 | FRIEND_TEST(WiFiPropertyTest, BgscanMethodProperty); // bgscan_method_ |
Paul Stewart | 1aff730 | 2012-08-04 20:04:47 -0700 | [diff] [blame] | 197 | FRIEND_TEST(WiFiTimerTest, FastRescan); // kFastScanIntervalSeconds |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 198 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 199 | typedef std::map<const std::string, WiFiEndpointRefPtr> EndpointMap; |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 200 | typedef std::map<const WiFiService *, std::string> ReverseServiceMap; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 201 | |
Darin Petkov | 60ceaf3 | 2012-10-18 10:36:01 +0200 | [diff] [blame] | 202 | static const char kSupplicantConfPath[]; |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 203 | static const char *kDefaultBgscanMethod; |
| 204 | static const uint16 kDefaultBgscanShortIntervalSeconds; |
| 205 | static const int32 kDefaultBgscanSignalThresholdDbm; |
| 206 | static const uint16 kDefaultScanIntervalSeconds; |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 207 | static const uint16 kBackgroundScanIntervalSeconds; |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 208 | static const char kManagerErrorSSIDTooLong[]; |
| 209 | static const char kManagerErrorSSIDTooShort[]; |
| 210 | static const char kManagerErrorSSIDRequired[]; |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 211 | static const char kManagerErrorUnsupportedSecurityMode[]; |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 212 | static const char kManagerErrorUnsupportedServiceMode[]; |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 213 | static const time_t kMaxBSSResumeAgeSeconds; |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 214 | static const char kInterfaceStateUnknown[]; |
mukesh agrawal | f202817 | 2012-03-13 14:20:22 -0700 | [diff] [blame] | 215 | // Delay between scans when supplicant finds "No suitable network". |
| 216 | static const time_t kRescanIntervalSeconds; |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 217 | // Number of times to quickly attempt a scan after startup / disconnect. |
| 218 | static const int kNumFastScanAttempts; |
| 219 | static const int kFastScanIntervalSeconds; |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 220 | static const int kPendingTimeoutSeconds; |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 221 | static const int kReconnectTimeoutSeconds; |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 222 | |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 223 | void AppendBgscan(WiFiService *service, |
| 224 | std::map<std::string, DBus::Variant> *service_params) const; |
| 225 | std::string GetBgscanMethod(const int &argument, Error *error); |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 226 | 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 Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 233 | void SetBgscanMethod( |
| 234 | const int &argument, const std::string &method, Error *error); |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 235 | void SetBgscanShortInterval(const uint16 &seconds, Error *error); |
| 236 | void SetBgscanSignalThreshold(const int32 &dbm, Error *error); |
| 237 | void SetScanInterval(const uint16 &seconds, Error *error); |
Darin Petkov | 4a66cc5 | 2012-06-15 10:08:29 +0200 | [diff] [blame] | 238 | void ClearBgscanMethod(const int &argument, Error *error); |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 239 | |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 240 | WiFiServiceRefPtr CreateServiceForEndpoint( |
| 241 | const WiFiEndpoint &endpoint, bool hidden_ssid); |
| 242 | void CurrentBSSChanged(const ::DBus::Path &new_bss); |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 243 | WiFiServiceRefPtr FindService(const std::vector<uint8_t> &ssid, |
| 244 | const std::string &mode, |
| 245 | const std::string &security) const; |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 246 | WiFiServiceRefPtr FindServiceForEndpoint(const WiFiEndpoint &endpoint); |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 247 | // 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 Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 252 | ByteArrays GetHiddenSSIDList(); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 253 | void HandleDisconnect(); |
| 254 | void HandleRoam(const ::DBus::Path &new_bssid); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 255 | // Create services for hidden networks stored in |storage|. Returns true |
| 256 | // if any were found, otherwise returns false. |
| 257 | bool LoadHiddenServices(StoreInterface *storage); |
mukesh agrawal | b4bc57d | 2011-12-07 01:07:47 +0000 | [diff] [blame] | 258 | void BSSAddedTask(const ::DBus::Path &BSS, |
| 259 | const std::map<std::string, ::DBus::Variant> &properties); |
| 260 | void BSSRemovedTask(const ::DBus::Path &BSS); |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 261 | void CertificationTask( |
| 262 | const std::map<std::string, ::DBus::Variant> &properties); |
Paul Stewart | db0f917 | 2012-11-30 16:48:09 -0800 | [diff] [blame] | 263 | void EAPEventTask(const std::string &status, const std::string ¶meter); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 264 | void PropertiesChangedTask( |
| 265 | const std::map<std::string, ::DBus::Variant> &properties); |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 266 | void ScanDoneTask(); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 267 | void ScanTask(); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 268 | void StateChanged(const std::string &new_state); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 269 | // Heuristic check if a connection failure was due to bad credentials. |
| 270 | bool SuspectCredentials(const WiFiService &service) const; |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 271 | void HelpRegisterDerivedInt32( |
| 272 | PropertyStore *store, |
| 273 | const std::string &name, |
| 274 | int32(WiFi::*get)(Error *error), |
| 275 | void(WiFi::*set)(const int32 &value, Error *error)); |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 276 | void HelpRegisterDerivedUint16( |
| 277 | PropertyStore *store, |
| 278 | const std::string &name, |
| 279 | uint16(WiFi::*get)(Error *error), |
| 280 | void(WiFi::*set)(const uint16 &value, Error *error)); |
| 281 | |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 282 | // Disable a network entry in wpa_supplicant, and catch any exception |
| 283 | // that occurs. Returns false if an exception occurred, true otherwise. |
| 284 | bool DisableNetwork(const ::DBus::Path &network); |
| 285 | // Disable the wpa_supplicant network entry associated with |service|. |
| 286 | // Any cached credentials stored in wpa_supplicant related to this |
| 287 | // network entry will be preserved. This will have the side-effect of |
| 288 | // disconnecting this service if it is currently connected. Returns |
| 289 | // true if successful, otherwise returns false and populates |error| |
| 290 | // with the reason for failure. |
| 291 | virtual bool DisableNetworkForService( |
| 292 | const WiFiService *service, Error *error); |
Paul Stewart | 71f6ecd | 2012-09-13 14:52:18 -0700 | [diff] [blame] | 293 | // Remove a network entry from wpa_supplicant, and catch any exception |
| 294 | // that occurs. Returns false if an exception occurred, true otherwise. |
| 295 | bool RemoveNetwork(const ::DBus::Path &network); |
Paul Stewart | 835934a | 2012-12-06 19:27:09 -0800 | [diff] [blame] | 296 | // Remove the wpa_supplicant network entry associated with |service|. |
| 297 | // Any cached credentials stored in wpa_supplicant related to this |
| 298 | // network entry will be removed. This will have the side-effect of |
| 299 | // disconnecting this service if it is currently connected. Returns |
| 300 | // true if successful, otherwise returns false and populates |error| |
| 301 | // with the reason for failure. |
| 302 | virtual bool RemoveNetworkForService( |
| 303 | const WiFiService *service, Error *error); |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 304 | // Restart fast scanning after disconnection. |
| 305 | void RestartFastScanAttempts(); |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 306 | // Schedules a scan attempt at time |scan_interval_seconds_| in the |
| 307 | // future. Cancels any currently pending scan timer. |
| 308 | void StartScanTimer(); |
| 309 | // Cancels any currently pending scan timer. |
| 310 | void StopScanTimer(); |
| 311 | // Initiates a scan, if idle. Reschedules the scan timer regardless. |
| 312 | void ScanTimerHandler(); |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 313 | // Starts a timer in order to limit the length of an attempt to |
| 314 | // connect to a pending network. |
| 315 | void StartPendingTimer(); |
| 316 | // Cancels any currently pending network timer. |
| 317 | void StopPendingTimer(); |
| 318 | // Aborts a pending network that is taking too long to connect. |
| 319 | void PendingTimeoutHandler(); |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 320 | // Starts a timer in order to limit the length of an attempt to |
| 321 | // reconnect to the current network. |
| 322 | void StartReconnectTimer(); |
| 323 | // Stops any pending reconnect timer. |
| 324 | void StopReconnectTimer(); |
| 325 | // Disconnects from the current service that is taking too long |
| 326 | // to reconnect on its own. |
| 327 | void ReconnectTimeoutHandler(); |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 328 | // Sets the current pending service. If the argument is non-NULL, |
| 329 | // the Pending timer is started and the associated service is set |
| 330 | // to "Associating", otherwise it is stopped. |
| 331 | void SetPendingService(const WiFiServiceRefPtr &service); |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 332 | |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 333 | void OnSupplicantAppear(const std::string &owner); |
| 334 | void OnSupplicantVanish(); |
Paul Stewart | 5581d07 | 2012-12-17 17:30:20 -0800 | [diff] [blame] | 335 | // Called by ScopeLogger when WiFi debug scope is enabled/disabled. |
| 336 | void OnWiFiDebugScopeChanged(bool enabled); |
Paul Stewart | a47c3c6 | 2012-12-18 12:14:29 -0800 | [diff] [blame] | 337 | // Enable or disable debugging for the current connection attempt. |
| 338 | void SetConnectionDebugging(bool enabled); |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 339 | |
| 340 | void ConnectToSupplicant(); |
| 341 | |
| 342 | void Restart(); |
| 343 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 344 | base::WeakPtrFactory<WiFi> weak_ptr_factory_; |
| 345 | |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 346 | // Store cached copies of singletons for speed/ease of testing. |
| 347 | ProxyFactory *proxy_factory_; |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 348 | Time *time_; |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 349 | |
Darin Petkov | 2b8e44e | 2012-06-25 15:13:26 +0200 | [diff] [blame] | 350 | DBusManager::CancelableAppearedCallback on_supplicant_appear_; |
| 351 | DBusManager::CancelableVanishedCallback on_supplicant_vanish_; |
| 352 | bool supplicant_present_; |
| 353 | |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 354 | scoped_ptr<SupplicantProcessProxyInterface> supplicant_process_proxy_; |
| 355 | scoped_ptr<SupplicantInterfaceProxyInterface> supplicant_interface_proxy_; |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 356 | // The rpcid used as the key is wpa_supplicant's D-Bus path for the |
| 357 | // Endpoint (BSS, in supplicant parlance). |
| 358 | EndpointMap endpoint_by_rpcid_; |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 359 | // Map from Services to the D-Bus path for the corresponding wpa_supplicant |
| 360 | // Network. |
| 361 | ReverseServiceMap rpcid_by_service_; |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 362 | std::vector<WiFiServiceRefPtr> services_; |
| 363 | // The Service we are presently connected to. May be NULL is we're not |
| 364 | // not connected to any Service. |
| 365 | WiFiServiceRefPtr current_service_; |
| 366 | // The Service we're attempting to connect to. May be NULL if we're |
| 367 | // not attempting to connect to a new Service. If non-NULL, should |
| 368 | // be distinct from |current_service_|. (A service should not |
| 369 | // simultaneously be both pending, and current.) |
| 370 | WiFiServiceRefPtr pending_service_; |
| 371 | std::string supplicant_state_; |
| 372 | std::string supplicant_bss_; |
Paul Stewart | db0f917 | 2012-11-30 16:48:09 -0800 | [diff] [blame] | 373 | std::string supplicant_tls_error_; |
mukesh agrawal | 5c05b29 | 2012-03-07 10:12:52 -0800 | [diff] [blame] | 374 | // Indicates that we should flush supplicant's BSS cache after the |
| 375 | // next scan completes. |
| 376 | bool need_bss_flush_; |
| 377 | struct timeval resumed_at_; |
mukesh agrawal | b66c646 | 2012-05-07 11:45:25 -0700 | [diff] [blame] | 378 | // Executes when the (foreground) scan timer expires. Calls ScanTimerHandler. |
| 379 | base::CancelableClosure scan_timer_callback_; |
Paul Stewart | 2b05e62 | 2012-07-13 20:38:44 -0700 | [diff] [blame] | 380 | // Executes when a pending service connect timer expires. Calls |
| 381 | // PendingTimeoutHandler. |
| 382 | base::CancelableClosure pending_timeout_callback_; |
Paul Stewart | 4466392 | 2012-07-30 11:03:03 -0700 | [diff] [blame] | 383 | // Executes when a reconnecting service timer expires. Calls |
| 384 | // ReconnectTimeoutHandler. |
| 385 | base::CancelableClosure reconnect_timeout_callback_; |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 386 | // Number of remaining fast scans to be done during startup and disconnect. |
| 387 | int fast_scans_remaining_; |
Christopher Wiley | 8f81e2a | 2012-10-17 16:51:32 -0700 | [diff] [blame] | 388 | // Indicates that the current BSS has reached the completed state according |
| 389 | // to supplicant. |
| 390 | bool has_already_completed_; |
Paul Stewart | a47c3c6 | 2012-12-18 12:14:29 -0800 | [diff] [blame] | 391 | // Indicates that we are debugging a problematic connection. |
| 392 | bool is_debugging_connection_; |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 393 | |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 394 | // Properties |
| 395 | std::string bgscan_method_; |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 396 | uint16 bgscan_short_interval_seconds_; |
| 397 | int32 bgscan_signal_threshold_dbm_; |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 398 | bool scan_pending_; |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 399 | uint16 scan_interval_seconds_; |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 400 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 401 | DISALLOW_COPY_AND_ASSIGN(WiFi); |
| 402 | }; |
| 403 | |
| 404 | } // namespace shill |
| 405 | |
| 406 | #endif // SHILL_WIFI_ |