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