blob: b6cdcbe958b52615e4fe31a7b9b8d4d0b36c21fb [file] [log] [blame]
Thieu Lee41a72d2012-02-06 20:46:51 +00001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
mukesh agrawalb54601c2011-06-07 17:39:22 -07002// 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 agrawal6e277772011-09-29 15:04:23 -07009#include <set>
mukesh agrawalb54601c2011-06-07 17:39:22 -070010#include <string>
11#include <vector>
12
13#include <base/memory/ref_counted.h>
14#include <dbus-c++/dbus.h>
mukesh agrawal6e277772011-09-29 15:04:23 -070015#include <gtest/gtest_prod.h> // for FRIEND_TEST
mukesh agrawalb54601c2011-06-07 17:39:22 -070016
17#include "shill/endpoint.h"
Paul Stewart26b327e2011-10-19 11:38:09 -070018#include "shill/event_dispatcher.h"
Thieu Le1df7f4e2012-02-10 15:21:45 -080019#include "shill/metrics.h"
mukesh agrawalb20776f2012-02-10 16:00:36 -080020#include "shill/refptr_types.h"
mukesh agrawalb54601c2011-06-07 17:39:22 -070021
22namespace shill {
23
mukesh agrawalb20776f2012-02-10 16:00:36 -080024class ProxyFactory;
25class SupplicantBSSProxyInterface;
26
mukesh agrawalb54601c2011-06-07 17:39:22 -070027class WiFiEndpoint : public Endpoint {
28 public:
Paul Stewart72b2fdc2012-06-02 08:58:51 -070029 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 agrawalb20776f2012-02-10 16:00:36 -080036 WiFiEndpoint(ProxyFactory *proxy_factory,
37 const WiFiRefPtr &device,
38 const std::string &rpc_id,
39 const std::map<std::string, ::DBus::Variant> &properties);
mukesh agrawalb54601c2011-06-07 17:39:22 -070040 virtual ~WiFiEndpoint();
Chris Masone092df3e2011-08-22 09:41:39 -070041
mukesh agrawalb20776f2012-02-10 16:00:36 -080042 // 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 Masone092df3e2011-08-22 09:41:39 -070052 // 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 Stewart72b2fdc2012-06-02 08:58:51 -070056 // Returns a stringmap containing information gleaned about the
57 // vendor of this AP.
58 std::map<std::string, std::string> GetVendorInformation() const;
59
mukesh agrawalb54601c2011-06-07 17:39:22 -070060 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;
65 int16_t signal_strength() const;
Thieu Lee41a72d2012-02-06 20:46:51 +000066 uint16 frequency() const;
Thieu Le1df7f4e2012-02-10 15:21:45 -080067 uint16 physical_mode() const;
Chris Masone092df3e2011-08-22 09:41:39 -070068 const std::string &network_mode() const;
mukesh agrawal6e277772011-09-29 15:04:23 -070069 const std::string &security_mode() const;
Paul Stewarta5e7d5f2013-01-09 18:06:15 -080070 bool ieee80211w_required() const;
mukesh agrawalb54601c2011-06-07 17:39:22 -070071
72 private:
mukesh agrawal6e277772011-09-29 15:04:23 -070073 friend class WiFiEndpointTest;
Paul Stewarte369ece2012-05-22 09:11:03 -070074 friend class WiFiObjectTest; // for MakeOpenEndpoint
mukesh agrawal8a3188d2011-12-01 20:56:44 +000075 friend class WiFiServiceTest; // for MakeOpenEndpoint
mukesh agrawal6e277772011-09-29 15:04:23 -070076 // these test cases need access to the KeyManagement enum
Paul Stewart72b2fdc2012-06-02 08:58:51 -070077 FRIEND_TEST(WiFiEndpointTest, DeterminePhyModeFromFrequency);
78 FRIEND_TEST(WiFiEndpointTest, ParseIEs);
mukesh agrawal6e277772011-09-29 15:04:23 -070079 FRIEND_TEST(WiFiEndpointTest, ParseKeyManagementMethodsEAP);
80 FRIEND_TEST(WiFiEndpointTest, ParseKeyManagementMethodsPSK);
81 FRIEND_TEST(WiFiEndpointTest, ParseKeyManagementMethodsEAPAndPSK);
Paul Stewart72b2fdc2012-06-02 08:58:51 -070082 FRIEND_TEST(WiFiEndpointTest, ParseVendorIEs);
Paul Stewarta5e7d5f2013-01-09 18:06:15 -080083 FRIEND_TEST(WiFiEndpointTest, ParseWPACapabilities);
84 FRIEND_TEST(WiFiServiceTest, ConnectTaskWPA80211w);
mukesh agrawale1d90e92012-02-15 17:36:08 -080085 FRIEND_TEST(WiFiServiceUpdateFromEndpointsTest, EndpointModified);
Paul Stewarta5e7d5f2013-01-09 18:06:15 -080086 FRIEND_TEST(WiFiServiceUpdateFromEndpointsTest, Ieee80211w);
mukesh agrawalb54601c2011-06-07 17:39:22 -070087
mukesh agrawal6e277772011-09-29 15:04:23 -070088 enum KeyManagement {
89 kKeyManagement802_1x,
90 kKeyManagementPSK
91 };
mukesh agrawalb54601c2011-06-07 17:39:22 -070092
mukesh agrawal8a3188d2011-12-01 20:56:44 +000093 // Build a simple WiFiEndpoint, for testing purposes.
mukesh agrawalb20776f2012-02-10 16:00:36 -080094 static WiFiEndpoint *MakeOpenEndpoint(ProxyFactory *proxy_factory,
95 const WiFiRefPtr &wifi,
96 const std::string &ssid,
mukesh agrawale1d90e92012-02-15 17:36:08 -080097 const std::string &bssid,
98 uint16 frequency,
99 int16 signal_dbm);
Chris Masone092df3e2011-08-22 09:41:39 -0700100 // Maps mode strings from supplicant into flimflam's nomenclature, as defined
101 // in chromeos/dbus/service_constants.h
102 static const char *ParseMode(const std::string &mode_string);
mukesh agrawal6e277772011-09-29 15:04:23 -0700103 // Parses an Endpoint's properties to identify approprirate flimflam
104 // security property value, as defined in chromeos/dbus/service_constants.h
105 static const char *ParseSecurity(
106 const std::map<std::string, ::DBus::Variant> &properties);
mukesh agrawalb20776f2012-02-10 16:00:36 -0800107 // Parses an Endpoint's properties' "RSN" or "WPA" sub-dictionary, to
mukesh agrawal6e277772011-09-29 15:04:23 -0700108 // identify supported key management methods (802.1x or PSK).
109 static void ParseKeyManagementMethods(
110 const std::map<std::string, ::DBus::Variant> &security_method_properties,
111 std::set<KeyManagement> *key_management_methods);
Thieu Le1df7f4e2012-02-10 15:21:45 -0800112 // Determine the negotiated operating mode for the channel by looking at
113 // the information elements, frequency and data rates. The information
114 // elements and data rates live in |properties|.
Paul Stewart72b2fdc2012-06-02 08:58:51 -0700115 static Metrics::WiFiNetworkPhyMode DeterminePhyModeFromFrequency(
Thieu Le1df7f4e2012-02-10 15:21:45 -0800116 const std::map<std::string, ::DBus::Variant> &properties,
117 uint16 frequency);
Paul Stewarta5e7d5f2013-01-09 18:06:15 -0800118 // Parse information elements to determine the physical mode, vendor
119 // information and IEEE 802.11w requirement information associated
120 // with the AP. Returns true if a physical mode was determined from
121 // the IE elements, false otherwise.
Paul Stewart72b2fdc2012-06-02 08:58:51 -0700122 static bool ParseIEs(const std::map<std::string, ::DBus::Variant> &properties,
123 Metrics::WiFiNetworkPhyMode *phy_mode,
Paul Stewarta5e7d5f2013-01-09 18:06:15 -0800124 VendorInformation *vendor_information,
125 bool *ieee80211w_required);
126 // Parse a WPA information element and set *|ieee80211w_required| to true
127 // if IEEE 802.11w is required by this AP.
128 static void ParseWPACapabilities(std::vector<uint8_t>::const_iterator ie,
129 std::vector<uint8_t>::const_iterator end,
130 bool *ieee80211w_required);
131 // Parse a single vendor information element. If this is a WPA vendor
132 // element, call ParseWPACapabilites with |ieee80211w_required|.
Paul Stewart72b2fdc2012-06-02 08:58:51 -0700133 static void ParseVendorIE(std::vector<uint8_t>::const_iterator ie,
134 std::vector<uint8_t>::const_iterator end,
Paul Stewarta5e7d5f2013-01-09 18:06:15 -0800135 VendorInformation *vendor_information,
136 bool *ieee80211w_required);
mukesh agrawalb54601c2011-06-07 17:39:22 -0700137
mukesh agrawal6e277772011-09-29 15:04:23 -0700138 // TODO(quiche): make const?
mukesh agrawalb54601c2011-06-07 17:39:22 -0700139 std::vector<uint8_t> ssid_;
140 std::vector<uint8_t> bssid_;
141 std::string ssid_string_;
142 std::string ssid_hex_;
143 std::string bssid_string_;
144 std::string bssid_hex_;
mukesh agrawale1d90e92012-02-15 17:36:08 -0800145 int16 signal_strength_;
Thieu Lee41a72d2012-02-06 20:46:51 +0000146 uint16 frequency_;
Thieu Le1df7f4e2012-02-10 15:21:45 -0800147 uint16 physical_mode_;
mukesh agrawal6e277772011-09-29 15:04:23 -0700148 // network_mode_ and security_mode_ are represented as flimflam names
149 // (not necessarily the same as wpa_supplicant names)
Chris Masone092df3e2011-08-22 09:41:39 -0700150 std::string network_mode_;
mukesh agrawal6e277772011-09-29 15:04:23 -0700151 std::string security_mode_;
Paul Stewart72b2fdc2012-06-02 08:58:51 -0700152 VendorInformation vendor_information_;
Paul Stewarta5e7d5f2013-01-09 18:06:15 -0800153 bool ieee80211w_required_;
mukesh agrawalb54601c2011-06-07 17:39:22 -0700154
mukesh agrawalb20776f2012-02-10 16:00:36 -0800155 ProxyFactory *proxy_factory_;
156 WiFiRefPtr device_;
157 std::string rpc_id_;
158 scoped_ptr<SupplicantBSSProxyInterface> supplicant_bss_proxy_;
159
mukesh agrawalb54601c2011-06-07 17:39:22 -0700160 DISALLOW_COPY_AND_ASSIGN(WiFiEndpoint);
161};
162
163} // namespace shill
164
165#endif // SHILL_WIFI_ENDPOINT_