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 | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 20 | |
| 21 | namespace shill { |
| 22 | |
| 23 | class WiFiEndpoint : public Endpoint { |
| 24 | public: |
| 25 | WiFiEndpoint(const std::map<std::string, ::DBus::Variant> &properties); |
| 26 | virtual ~WiFiEndpoint(); |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 27 | |
| 28 | // Maps mode strings from flimflam's nomenclature, as defined |
| 29 | // in chromeos/dbus/service_constants.h, to uints used by supplicant |
| 30 | static uint32_t ModeStringToUint(const std::string &mode_string); |
| 31 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 32 | const std::vector<uint8_t> &ssid() const; |
| 33 | const std::string &ssid_string() const; |
| 34 | const std::string &ssid_hex() const; |
| 35 | const std::string &bssid_string() const; |
| 36 | const std::string &bssid_hex() const; |
| 37 | int16_t signal_strength() const; |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 38 | uint16 frequency() const; |
Thieu Le | 1df7f4e | 2012-02-10 15:21:45 -0800 | [diff] [blame^] | 39 | uint16 physical_mode() const; |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 40 | const std::string &network_mode() const; |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 41 | const std::string &security_mode() const; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 42 | |
| 43 | private: |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 44 | friend class WiFiEndpointTest; |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 45 | friend class WiFiMainTest; // for MakeOpenEndpoint |
| 46 | friend class WiFiServiceTest; // for MakeOpenEndpoint |
mukesh agrawal | 16bc1b8 | 2012-02-09 18:38:26 -0800 | [diff] [blame] | 47 | FRIEND_TEST(WiFiEndpointTest, SSIDWithNull); // for MakeOpenEndpoint |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 48 | // these test cases need access to the KeyManagement enum |
| 49 | FRIEND_TEST(WiFiEndpointTest, ParseKeyManagementMethodsEAP); |
| 50 | FRIEND_TEST(WiFiEndpointTest, ParseKeyManagementMethodsPSK); |
| 51 | FRIEND_TEST(WiFiEndpointTest, ParseKeyManagementMethodsEAPAndPSK); |
Thieu Le | 1df7f4e | 2012-02-10 15:21:45 -0800 | [diff] [blame^] | 52 | FRIEND_TEST(WiFiEndpointTest, DeterminePhyMode); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 53 | |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 54 | enum KeyManagement { |
| 55 | kKeyManagement802_1x, |
| 56 | kKeyManagementPSK |
| 57 | }; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 58 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 59 | // Build a simple WiFiEndpoint, for testing purposes. |
| 60 | static WiFiEndpoint *MakeOpenEndpoint( |
| 61 | const std::string &ssid, const std::string &bssid); |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 62 | // Maps mode strings from supplicant into flimflam's nomenclature, as defined |
| 63 | // in chromeos/dbus/service_constants.h |
| 64 | static const char *ParseMode(const std::string &mode_string); |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 65 | // Parses an Endpoint's properties to identify approprirate flimflam |
| 66 | // security property value, as defined in chromeos/dbus/service_constants.h |
| 67 | static const char *ParseSecurity( |
| 68 | const std::map<std::string, ::DBus::Variant> &properties); |
| 69 | // Parses and Endpoint's properties' "RSN" or "WPA" sub-dictionary, to |
| 70 | // identify supported key management methods (802.1x or PSK). |
| 71 | static void ParseKeyManagementMethods( |
| 72 | const std::map<std::string, ::DBus::Variant> &security_method_properties, |
| 73 | std::set<KeyManagement> *key_management_methods); |
Thieu Le | 1df7f4e | 2012-02-10 15:21:45 -0800 | [diff] [blame^] | 74 | // Determine the negotiated operating mode for the channel by looking at |
| 75 | // the information elements, frequency and data rates. The information |
| 76 | // elements and data rates live in |properties|. |
| 77 | static Metrics::WiFiNetworkPhyMode DeterminePhyMode( |
| 78 | const std::map<std::string, ::DBus::Variant> &properties, |
| 79 | uint16 frequency); |
| 80 | // Parse information elements to determine the physical mode. |
| 81 | static Metrics::WiFiNetworkPhyMode ParseIEsForPhyMode( |
| 82 | const std::vector<uint8_t> &ies); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 83 | |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 84 | // TODO(quiche): make const? |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 85 | std::vector<uint8_t> ssid_; |
| 86 | std::vector<uint8_t> bssid_; |
| 87 | std::string ssid_string_; |
| 88 | std::string ssid_hex_; |
| 89 | std::string bssid_string_; |
| 90 | std::string bssid_hex_; |
| 91 | int16_t signal_strength_; |
Thieu Le | e41a72d | 2012-02-06 20:46:51 +0000 | [diff] [blame] | 92 | uint16 frequency_; |
Thieu Le | 1df7f4e | 2012-02-10 15:21:45 -0800 | [diff] [blame^] | 93 | uint16 physical_mode_; |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 94 | // network_mode_ and security_mode_ are represented as flimflam names |
| 95 | // (not necessarily the same as wpa_supplicant names) |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 96 | std::string network_mode_; |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 97 | std::string security_mode_; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 98 | |
| 99 | DISALLOW_COPY_AND_ASSIGN(WiFiEndpoint); |
| 100 | }; |
| 101 | |
| 102 | } // namespace shill |
| 103 | |
| 104 | #endif // SHILL_WIFI_ENDPOINT_ |