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 | |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 8 | #include <map> |
Chris Masone | 46eaaf5 | 2011-05-24 13:08:30 -0700 | [diff] [blame] | 9 | #include <string> |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 10 | #include <vector> |
Chris Masone | 46eaaf5 | 2011-05-24 13:08:30 -0700 | [diff] [blame] | 11 | |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 12 | #include <dbus-c++/dbus.h> |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 13 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 14 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 15 | #include "shill/device.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 16 | #include "shill/event_dispatcher.h" |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 17 | #include "shill/refptr_types.h" |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 18 | |
| 19 | namespace shill { |
| 20 | |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 21 | class Error; |
| 22 | class KeyValueStore; |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 23 | class ProxyFactory; |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 24 | class SupplicantInterfaceProxyInterface; |
| 25 | class SupplicantProcessProxyInterface; |
mukesh agrawal | 445e72c | 2011-06-22 11:13:50 -0700 | [diff] [blame] | 26 | class WiFiService; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 27 | |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 28 | // WiFi class. Specialization of Device for WiFi. |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 29 | class WiFi : public Device { |
| 30 | public: |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 31 | WiFi(ControlInterface *control_interface, |
| 32 | EventDispatcher *dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 33 | Metrics *metrics, |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 34 | Manager *manager, |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 35 | const std::string &link, |
| 36 | const std::string &address, |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 37 | int interface_index); |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 38 | virtual ~WiFi(); |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 39 | |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 40 | virtual void Start(); |
| 41 | virtual void Stop(); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 42 | virtual bool Load(StoreInterface *storage); |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 43 | virtual void Scan(Error *error); |
Paul Stewart | fdd1607 | 2011-09-16 12:41:35 -0700 | [diff] [blame] | 44 | virtual bool TechnologyIs(const Technology::Identifier type) const; |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 45 | virtual bool IsConnectingTo(const WiFiService &service) const; |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 46 | |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 47 | // Called by SupplicantInterfaceProxy, in response to events from |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 48 | // wpa_supplicant. |
| 49 | void BSSAdded(const ::DBus::Path &BSS, |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 50 | const std::map<std::string, ::DBus::Variant> &properties); |
mukesh agrawal | 261daca | 2011-12-02 18:56:56 +0000 | [diff] [blame] | 51 | void BSSRemoved(const ::DBus::Path &BSS); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 52 | void PropertiesChanged( |
| 53 | const std::map<std::string, ::DBus::Variant> &properties); |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 54 | void ScanDone(); |
| 55 | |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 56 | // Called by WiFiService. |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 57 | virtual void ConnectTo( |
| 58 | WiFiService *service, |
mukesh agrawal | 6489632 | 2011-12-01 01:13:10 +0000 | [diff] [blame] | 59 | std::map<std::string, ::DBus::Variant> service_params); |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 60 | virtual void DisconnectFrom(WiFiService *service); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 61 | virtual bool IsIdle() const; |
Paul Stewart | 66c8600 | 2012-01-30 18:00:52 -0800 | [diff] [blame] | 62 | virtual void ClearCachedCredentials(); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 63 | |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 64 | // Called by Manager. |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 65 | virtual WiFiServiceRefPtr GetService(const KeyValueStore &args, Error *error); |
| 66 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 67 | private: |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 68 | friend class WiFiMainTest; // access to supplicant_*_proxy_, link_up_ |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 69 | FRIEND_TEST(WiFiMainTest, InitialSupplicantState); // kInterfaceStateUnknown |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame^] | 70 | FRIEND_TEST(WiFiMainTest, ScanResults); // EndpointMap |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 71 | FRIEND_TEST(WiFiMainTest, ScanResultsWithUpdates); // EndpointMap |
mukesh agrawal | 8abd2f6 | 2012-01-30 14:56:14 -0800 | [diff] [blame] | 72 | FRIEND_TEST(WiFiPropertyTest, ClearDerivedProperty); // bgscan_method_ |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 73 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 74 | typedef std::map<const std::string, WiFiEndpointRefPtr> EndpointMap; |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 75 | typedef std::map<WiFiService *, std::string> ReverseServiceMap; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 76 | |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 77 | static const char *kDefaultBgscanMethod; |
| 78 | static const uint16 kDefaultBgscanShortIntervalSeconds; |
| 79 | static const int32 kDefaultBgscanSignalThresholdDbm; |
| 80 | static const uint16 kDefaultScanIntervalSeconds; |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 81 | static const char kManagerErrorPassphraseRequired[]; |
| 82 | static const char kManagerErrorSSIDTooLong[]; |
| 83 | static const char kManagerErrorSSIDTooShort[]; |
| 84 | static const char kManagerErrorSSIDRequired[]; |
| 85 | static const char kManagerErrorTypeRequired[]; |
| 86 | static const char kManagerErrorUnsupportedSecurityMode[]; |
| 87 | static const char kManagerErrorUnsupportedServiceType[]; |
| 88 | static const char kManagerErrorUnsupportedServiceMode[]; |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 89 | static const char kInterfaceStateUnknown[]; |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 90 | |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 91 | std::string CreateBgscanConfigString(); |
| 92 | std::string GetBgscanMethod(Error */* error */) { return bgscan_method_; } |
| 93 | uint16 GetBgscanShortInterval(Error */* error */) { |
| 94 | return bgscan_short_interval_seconds_; |
| 95 | } |
| 96 | int32 GetBgscanSignalThreshold(Error */* error */) { |
| 97 | return bgscan_signal_threshold_dbm_; |
| 98 | } |
| 99 | uint16 GetScanInterval(Error */* error */) { return scan_interval_seconds_; } |
| 100 | void SetBgscanMethod(const std::string &method, Error *error); |
| 101 | void SetBgscanShortInterval(const uint16 &seconds, Error *error); |
| 102 | void SetBgscanSignalThreshold(const int32 &dbm, Error *error); |
| 103 | void SetScanInterval(const uint16 &seconds, Error *error); |
| 104 | |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 105 | WiFiServiceRefPtr CreateServiceForEndpoint( |
| 106 | const WiFiEndpoint &endpoint, bool hidden_ssid); |
| 107 | void CurrentBSSChanged(const ::DBus::Path &new_bss); |
Paul Stewart | 6ab23a9 | 2011-11-09 17:17:47 -0800 | [diff] [blame] | 108 | WiFiServiceRefPtr FindService(const std::vector<uint8_t> &ssid, |
| 109 | const std::string &mode, |
| 110 | const std::string &security) const; |
mukesh agrawal | 165e614 | 2011-11-22 02:22:56 +0000 | [diff] [blame] | 111 | WiFiServiceRefPtr FindServiceForEndpoint(const WiFiEndpoint &endpoint); |
Paul Stewart | ced6a0b | 2011-11-08 15:32:04 -0800 | [diff] [blame] | 112 | ByteArrays GetHiddenSSIDList(); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 113 | void HandleDisconnect(); |
| 114 | void HandleRoam(const ::DBus::Path &new_bssid); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 115 | // Create services for hidden networks stored in |storage|. Returns true |
| 116 | // if any were found, otherwise returns false. |
| 117 | bool LoadHiddenServices(StoreInterface *storage); |
mukesh agrawal | b4bc57d | 2011-12-07 01:07:47 +0000 | [diff] [blame] | 118 | void BSSAddedTask(const ::DBus::Path &BSS, |
| 119 | const std::map<std::string, ::DBus::Variant> &properties); |
| 120 | void BSSRemovedTask(const ::DBus::Path &BSS); |
Paul Stewart | 66c8600 | 2012-01-30 18:00:52 -0800 | [diff] [blame] | 121 | void ClearCachedCredentialsTask(); |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 122 | void PropertiesChangedTask( |
| 123 | const std::map<std::string, ::DBus::Variant> &properties); |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 124 | void ScanDoneTask(); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 125 | void ScanTask(); |
mukesh agrawal | 7ec7131 | 2011-11-10 02:08:26 +0000 | [diff] [blame] | 126 | void StateChanged(const std::string &new_state); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 127 | |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 128 | void HelpRegisterDerivedInt32( |
| 129 | PropertyStore *store, |
| 130 | const std::string &name, |
| 131 | int32(WiFi::*get)(Error *error), |
| 132 | void(WiFi::*set)(const int32 &value, Error *error)); |
| 133 | void HelpRegisterDerivedString( |
| 134 | PropertyStore *store, |
| 135 | const std::string &name, |
| 136 | std::string(WiFi::*get)(Error *error), |
| 137 | void(WiFi::*set)(const std::string &value, Error *error)); |
| 138 | void HelpRegisterDerivedUint16( |
| 139 | PropertyStore *store, |
| 140 | const std::string &name, |
| 141 | uint16(WiFi::*get)(Error *error), |
| 142 | void(WiFi::*set)(const uint16 &value, Error *error)); |
| 143 | |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 144 | // Store cached copies of singletons for speed/ease of testing. |
| 145 | ProxyFactory *proxy_factory_; |
| 146 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 147 | ScopedRunnableMethodFactory<WiFi> task_factory_; |
mukesh agrawal | af57195 | 2011-07-14 14:31:12 -0700 | [diff] [blame] | 148 | scoped_ptr<SupplicantProcessProxyInterface> supplicant_process_proxy_; |
| 149 | scoped_ptr<SupplicantInterfaceProxyInterface> supplicant_interface_proxy_; |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 150 | // The rpcid used as the key is wpa_supplicant's D-Bus path for the |
| 151 | // Endpoint (BSS, in supplicant parlance). |
| 152 | EndpointMap endpoint_by_rpcid_; |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 153 | // Map from Services to the D-Bus path for the corresponding wpa_supplicant |
| 154 | // Network. |
| 155 | ReverseServiceMap rpcid_by_service_; |
mukesh agrawal | 1590839 | 2011-11-16 18:29:25 +0000 | [diff] [blame] | 156 | std::vector<WiFiServiceRefPtr> services_; |
| 157 | // The Service we are presently connected to. May be NULL is we're not |
| 158 | // not connected to any Service. |
| 159 | WiFiServiceRefPtr current_service_; |
| 160 | // The Service we're attempting to connect to. May be NULL if we're |
| 161 | // not attempting to connect to a new Service. If non-NULL, should |
| 162 | // be distinct from |current_service_|. (A service should not |
| 163 | // simultaneously be both pending, and current.) |
| 164 | WiFiServiceRefPtr pending_service_; |
| 165 | std::string supplicant_state_; |
| 166 | std::string supplicant_bss_; |
Paul Stewart | 66c8600 | 2012-01-30 18:00:52 -0800 | [diff] [blame] | 167 | // Signifies that ClearCachedCredentialsTask() is pending. |
| 168 | bool clear_cached_credentials_pending_; |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 169 | |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 170 | // Properties |
| 171 | std::string bgscan_method_; |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 172 | uint16 bgscan_short_interval_seconds_; |
| 173 | int32 bgscan_signal_threshold_dbm_; |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 174 | bool scan_pending_; |
mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 175 | uint16 scan_interval_seconds_; |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame] | 176 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 177 | DISALLOW_COPY_AND_ASSIGN(WiFi); |
| 178 | }; |
| 179 | |
| 180 | } // namespace shill |
| 181 | |
| 182 | #endif // SHILL_WIFI_ |