Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -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_ENDPOINT_ |
| 6 | #define SHILL_WIFI_ENDPOINT_ |
| 7 | |
| 8 | #include <map> |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 9 | #include <set> |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 10 | #include <string> |
| 11 | #include <vector> |
| 12 | |
| 13 | #include <base/memory/ref_counted.h> |
| 14 | #include <dbus-c++/dbus.h> |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 15 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 16 | |
| 17 | #include "shill/endpoint.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 18 | #include "shill/event_dispatcher.h" |
Thieu Le | 1df7f4e | 2012-02-10 15:21:45 -0800 | [diff] [blame] | 19 | #include "shill/metrics.h" |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 20 | #include "shill/refptr_types.h" |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 21 | |
| 22 | namespace shill { |
| 23 | |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 24 | class ProxyFactory; |
| 25 | class SupplicantBSSProxyInterface; |
| 26 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 27 | class WiFiEndpoint : public Endpoint { |
| 28 | public: |
Paul Stewart | affc055 | 2013-03-25 07:50:15 -0700 | [diff] [blame] | 29 | struct SecurityFlags { |
| 30 | SecurityFlags() |
| 31 | : rsn_8021x(false), |
| 32 | rsn_psk(false), |
| 33 | wpa_8021x(false), |
| 34 | wpa_psk(false), |
| 35 | privacy(false) {} |
| 36 | bool rsn_8021x; |
| 37 | bool rsn_psk; |
| 38 | bool wpa_8021x; |
| 39 | bool wpa_psk; |
| 40 | bool privacy; |
| 41 | }; |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 42 | struct VendorInformation { |
| 43 | std::string wps_manufacturer; |
| 44 | std::string wps_model_name; |
| 45 | std::string wps_model_number; |
| 46 | std::string wps_device_name; |
| 47 | std::set<uint32_t> oui_list; |
| 48 | }; |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 49 | WiFiEndpoint(ProxyFactory *proxy_factory, |
| 50 | const WiFiRefPtr &device, |
| 51 | const std::string &rpc_id, |
| 52 | const std::map<std::string, ::DBus::Variant> &properties); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 53 | virtual ~WiFiEndpoint(); |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 54 | |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 55 | // Set up RPC channel. Broken out from the ctor, so that WiFi can |
| 56 | // look over the Endpoint details before commiting to setting up |
| 57 | // RPC. |
| 58 | virtual void Start(); |
| 59 | |
| 60 | // Called by SupplicantBSSProxy, in response to events from |
| 61 | // wpa_supplicant. |
| 62 | void PropertiesChanged( |
| 63 | const std::map<std::string, ::DBus::Variant> &properties); |
| 64 | |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 65 | // Maps mode strings from flimflam's nomenclature, as defined |
| 66 | // in chromeos/dbus/service_constants.h, to uints used by supplicant |
| 67 | static uint32_t ModeStringToUint(const std::string &mode_string); |
| 68 | |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 69 | // Returns a stringmap containing information gleaned about the |
| 70 | // vendor of this AP. |
| 71 | std::map<std::string, std::string> GetVendorInformation() const; |
| 72 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 73 | const std::vector<uint8_t> &ssid() const; |
| 74 | const std::string &ssid_string() const; |
| 75 | const std::string &ssid_hex() const; |
| 76 | const std::string &bssid_string() const; |
| 77 | const std::string &bssid_hex() const; |
Paul Stewart | bdbd3c3 | 2013-04-17 09:47:21 -0700 | [diff] [blame] | 78 | const std::string &country_code() const; |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 79 | const WiFiRefPtr &device() const; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 80 | int16_t signal_strength() const; |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 81 | uint16 frequency() const; |
Thieu Le | 1df7f4e | 2012-02-10 15:21:45 -0800 | [diff] [blame] | 82 | uint16 physical_mode() const; |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 83 | const std::string &network_mode() const; |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 84 | const std::string &security_mode() const; |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 85 | bool ieee80211w_required() const; |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 86 | bool has_rsn_property() const; |
| 87 | bool has_wpa_property() const; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 88 | |
| 89 | private: |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 90 | friend class WiFiEndpointTest; |
Paul Stewart | e369ece | 2012-05-22 09:11:03 -0700 | [diff] [blame] | 91 | friend class WiFiObjectTest; // for MakeOpenEndpoint |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 92 | friend class WiFiProviderTest; // for MakeOpenEndpoint |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 93 | friend class WiFiServiceTest; // for MakeOpenEndpoint |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 94 | // these test cases need access to the KeyManagement enum |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 95 | FRIEND_TEST(WiFiEndpointTest, DeterminePhyModeFromFrequency); |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 96 | FRIEND_TEST(WiFiEndpointTest, ParseKeyManagementMethodsEAP); |
| 97 | FRIEND_TEST(WiFiEndpointTest, ParseKeyManagementMethodsPSK); |
| 98 | FRIEND_TEST(WiFiEndpointTest, ParseKeyManagementMethodsEAPAndPSK); |
Paul Stewart | 08a54eb | 2013-03-11 12:07:36 -0700 | [diff] [blame] | 99 | FRIEND_TEST(WiFiProviderTest, OnEndpointAddedWithSecurity); |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 100 | FRIEND_TEST(WiFiServiceTest, ConnectTaskWPA80211w); |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 101 | FRIEND_TEST(WiFiServiceUpdateFromEndpointsTest, EndpointModified); |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 102 | FRIEND_TEST(WiFiServiceUpdateFromEndpointsTest, Ieee80211w); |
mukesh agrawal | f6b3209 | 2013-04-10 15:49:55 -0700 | [diff] [blame] | 103 | // for physical_mode_ |
| 104 | FRIEND_TEST(WiFiServiceUpdateFromEndpointsTest, PhysicalMode); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 105 | |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 106 | enum KeyManagement { |
| 107 | kKeyManagement802_1x, |
| 108 | kKeyManagementPSK |
| 109 | }; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 110 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 111 | // Build a simple WiFiEndpoint, for testing purposes. |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 112 | static WiFiEndpoint *MakeEndpoint(ProxyFactory *proxy_factory, |
| 113 | const WiFiRefPtr &wifi, |
| 114 | const std::string &ssid, |
| 115 | const std::string &bssid, |
| 116 | const std::string &network_mode, |
| 117 | uint16 frequency, |
| 118 | int16 signal_dbm, |
| 119 | bool has_wpa_property, |
| 120 | bool has_rsn_property); |
| 121 | // As above, but with the last two parameters false. |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 122 | static WiFiEndpoint *MakeOpenEndpoint(ProxyFactory *proxy_factory, |
| 123 | const WiFiRefPtr &wifi, |
| 124 | const std::string &ssid, |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 125 | const std::string &bssid, |
Paul Stewart | 3c50401 | 2013-01-17 17:49:58 -0800 | [diff] [blame] | 126 | const std::string &network_mode, |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 127 | uint16 frequency, |
| 128 | int16 signal_dbm); |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 129 | // Maps mode strings from supplicant into flimflam's nomenclature, as defined |
Paul Stewart | affc055 | 2013-03-25 07:50:15 -0700 | [diff] [blame] | 130 | // in chromeos/dbus/service_constants.h. |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 131 | static const char *ParseMode(const std::string &mode_string); |
Paul Stewart | affc055 | 2013-03-25 07:50:15 -0700 | [diff] [blame] | 132 | // Parses an Endpoint's properties to identify an approprirate flimflam |
| 133 | // security property value, as defined in chromeos/dbus/service_constants.h. |
| 134 | // The stored data in the |flags| parameter is merged with the provided |
| 135 | // properties, and the security value returned is the result of the |
| 136 | // merger. |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 137 | static const char *ParseSecurity( |
Paul Stewart | affc055 | 2013-03-25 07:50:15 -0700 | [diff] [blame] | 138 | const std::map<std::string, ::DBus::Variant> &properties, |
| 139 | SecurityFlags *flags); |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 140 | // Parses an Endpoint's properties' "RSN" or "WPA" sub-dictionary, to |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 141 | // identify supported key management methods (802.1x or PSK). |
| 142 | static void ParseKeyManagementMethods( |
| 143 | const std::map<std::string, ::DBus::Variant> &security_method_properties, |
| 144 | std::set<KeyManagement> *key_management_methods); |
Thieu Le | 1df7f4e | 2012-02-10 15:21:45 -0800 | [diff] [blame] | 145 | // Determine the negotiated operating mode for the channel by looking at |
| 146 | // the information elements, frequency and data rates. The information |
| 147 | // elements and data rates live in |properties|. |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 148 | static Metrics::WiFiNetworkPhyMode DeterminePhyModeFromFrequency( |
Thieu Le | 1df7f4e | 2012-02-10 15:21:45 -0800 | [diff] [blame] | 149 | const std::map<std::string, ::DBus::Variant> &properties, |
| 150 | uint16 frequency); |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 151 | // Parse information elements to determine the physical mode, vendor |
| 152 | // information and IEEE 802.11w requirement information associated |
| 153 | // with the AP. Returns true if a physical mode was determined from |
| 154 | // the IE elements, false otherwise. |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 155 | static bool ParseIEs(const std::map<std::string, ::DBus::Variant> &properties, |
| 156 | Metrics::WiFiNetworkPhyMode *phy_mode, |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 157 | VendorInformation *vendor_information, |
Paul Stewart | bdbd3c3 | 2013-04-17 09:47:21 -0700 | [diff] [blame] | 158 | bool *ieee80211w_required, std::string *country_code); |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 159 | // Parse a WPA information element and set *|ieee80211w_required| to true |
| 160 | // if IEEE 802.11w is required by this AP. |
| 161 | static void ParseWPACapabilities(std::vector<uint8_t>::const_iterator ie, |
| 162 | std::vector<uint8_t>::const_iterator end, |
| 163 | bool *ieee80211w_required); |
| 164 | // Parse a single vendor information element. If this is a WPA vendor |
| 165 | // element, call ParseWPACapabilites with |ieee80211w_required|. |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 166 | static void ParseVendorIE(std::vector<uint8_t>::const_iterator ie, |
| 167 | std::vector<uint8_t>::const_iterator end, |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 168 | VendorInformation *vendor_information, |
| 169 | bool *ieee80211w_required); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 170 | |
Paul Stewart | 08a54eb | 2013-03-11 12:07:36 -0700 | [diff] [blame] | 171 | // Private setter used in unit tests. |
| 172 | void set_security_mode(const std::string &mode) { security_mode_ = mode; } |
| 173 | |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 174 | // TODO(quiche): make const? |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 175 | std::vector<uint8_t> ssid_; |
| 176 | std::vector<uint8_t> bssid_; |
| 177 | std::string ssid_string_; |
| 178 | std::string ssid_hex_; |
| 179 | std::string bssid_string_; |
| 180 | std::string bssid_hex_; |
Paul Stewart | bdbd3c3 | 2013-04-17 09:47:21 -0700 | [diff] [blame] | 181 | std::string country_code_; |
mukesh agrawal | e1d90e9 | 2012-02-15 17:36:08 -0800 | [diff] [blame] | 182 | int16 signal_strength_; |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 183 | uint16 frequency_; |
Thieu Le | 1df7f4e | 2012-02-10 15:21:45 -0800 | [diff] [blame] | 184 | uint16 physical_mode_; |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 185 | // network_mode_ and security_mode_ are represented as flimflam names |
| 186 | // (not necessarily the same as wpa_supplicant names) |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 187 | std::string network_mode_; |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 188 | std::string security_mode_; |
Paul Stewart | 72b2fdc | 2012-06-02 08:58:51 -0700 | [diff] [blame] | 189 | VendorInformation vendor_information_; |
Paul Stewart | a5e7d5f | 2013-01-09 18:06:15 -0800 | [diff] [blame] | 190 | bool ieee80211w_required_; |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 191 | bool has_rsn_property_; |
| 192 | bool has_wpa_property_; |
Paul Stewart | affc055 | 2013-03-25 07:50:15 -0700 | [diff] [blame] | 193 | SecurityFlags security_flags_; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 194 | |
mukesh agrawal | b20776f | 2012-02-10 16:00:36 -0800 | [diff] [blame] | 195 | ProxyFactory *proxy_factory_; |
| 196 | WiFiRefPtr device_; |
| 197 | std::string rpc_id_; |
| 198 | scoped_ptr<SupplicantBSSProxyInterface> supplicant_bss_proxy_; |
| 199 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 200 | DISALLOW_COPY_AND_ASSIGN(WiFiEndpoint); |
| 201 | }; |
| 202 | |
| 203 | } // namespace shill |
| 204 | |
| 205 | #endif // SHILL_WIFI_ENDPOINT_ |