blob: 89e6f597f36baba1a6e7cb9ba97247c6d17b3ec8 [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:
mukesh agrawalb20776f2012-02-10 16:00:36 -080029 WiFiEndpoint(ProxyFactory *proxy_factory,
30 const WiFiRefPtr &device,
31 const std::string &rpc_id,
32 const std::map<std::string, ::DBus::Variant> &properties);
mukesh agrawalb54601c2011-06-07 17:39:22 -070033 virtual ~WiFiEndpoint();
Chris Masone092df3e2011-08-22 09:41:39 -070034
mukesh agrawalb20776f2012-02-10 16:00:36 -080035 // Set up RPC channel. Broken out from the ctor, so that WiFi can
36 // look over the Endpoint details before commiting to setting up
37 // RPC.
38 virtual void Start();
39
40 // Called by SupplicantBSSProxy, in response to events from
41 // wpa_supplicant.
42 void PropertiesChanged(
43 const std::map<std::string, ::DBus::Variant> &properties);
44
Chris Masone092df3e2011-08-22 09:41:39 -070045 // Maps mode strings from flimflam's nomenclature, as defined
46 // in chromeos/dbus/service_constants.h, to uints used by supplicant
47 static uint32_t ModeStringToUint(const std::string &mode_string);
48
mukesh agrawalb54601c2011-06-07 17:39:22 -070049 const std::vector<uint8_t> &ssid() const;
50 const std::string &ssid_string() const;
51 const std::string &ssid_hex() const;
52 const std::string &bssid_string() const;
53 const std::string &bssid_hex() const;
54 int16_t signal_strength() const;
Thieu Lee41a72d2012-02-06 20:46:51 +000055 uint16 frequency() const;
Thieu Le1df7f4e2012-02-10 15:21:45 -080056 uint16 physical_mode() const;
Chris Masone092df3e2011-08-22 09:41:39 -070057 const std::string &network_mode() const;
mukesh agrawal6e277772011-09-29 15:04:23 -070058 const std::string &security_mode() const;
mukesh agrawalb54601c2011-06-07 17:39:22 -070059
60 private:
mukesh agrawal6e277772011-09-29 15:04:23 -070061 friend class WiFiEndpointTest;
mukesh agrawal8a3188d2011-12-01 20:56:44 +000062 friend class WiFiMainTest; // for MakeOpenEndpoint
63 friend class WiFiServiceTest; // for MakeOpenEndpoint
mukesh agrawal6e277772011-09-29 15:04:23 -070064 // these test cases need access to the KeyManagement enum
65 FRIEND_TEST(WiFiEndpointTest, ParseKeyManagementMethodsEAP);
66 FRIEND_TEST(WiFiEndpointTest, ParseKeyManagementMethodsPSK);
67 FRIEND_TEST(WiFiEndpointTest, ParseKeyManagementMethodsEAPAndPSK);
Thieu Le1df7f4e2012-02-10 15:21:45 -080068 FRIEND_TEST(WiFiEndpointTest, DeterminePhyMode);
mukesh agrawale1d90e92012-02-15 17:36:08 -080069 FRIEND_TEST(WiFiServiceUpdateFromEndpointsTest, EndpointModified);
mukesh agrawalb54601c2011-06-07 17:39:22 -070070
mukesh agrawal6e277772011-09-29 15:04:23 -070071 enum KeyManagement {
72 kKeyManagement802_1x,
73 kKeyManagementPSK
74 };
mukesh agrawalb54601c2011-06-07 17:39:22 -070075
mukesh agrawal8a3188d2011-12-01 20:56:44 +000076 // Build a simple WiFiEndpoint, for testing purposes.
mukesh agrawalb20776f2012-02-10 16:00:36 -080077 static WiFiEndpoint *MakeOpenEndpoint(ProxyFactory *proxy_factory,
78 const WiFiRefPtr &wifi,
79 const std::string &ssid,
mukesh agrawale1d90e92012-02-15 17:36:08 -080080 const std::string &bssid,
81 uint16 frequency,
82 int16 signal_dbm);
Chris Masone092df3e2011-08-22 09:41:39 -070083 // Maps mode strings from supplicant into flimflam's nomenclature, as defined
84 // in chromeos/dbus/service_constants.h
85 static const char *ParseMode(const std::string &mode_string);
mukesh agrawal6e277772011-09-29 15:04:23 -070086 // Parses an Endpoint's properties to identify approprirate flimflam
87 // security property value, as defined in chromeos/dbus/service_constants.h
88 static const char *ParseSecurity(
89 const std::map<std::string, ::DBus::Variant> &properties);
mukesh agrawalb20776f2012-02-10 16:00:36 -080090 // Parses an Endpoint's properties' "RSN" or "WPA" sub-dictionary, to
mukesh agrawal6e277772011-09-29 15:04:23 -070091 // identify supported key management methods (802.1x or PSK).
92 static void ParseKeyManagementMethods(
93 const std::map<std::string, ::DBus::Variant> &security_method_properties,
94 std::set<KeyManagement> *key_management_methods);
Thieu Le1df7f4e2012-02-10 15:21:45 -080095 // Determine the negotiated operating mode for the channel by looking at
96 // the information elements, frequency and data rates. The information
97 // elements and data rates live in |properties|.
98 static Metrics::WiFiNetworkPhyMode DeterminePhyMode(
99 const std::map<std::string, ::DBus::Variant> &properties,
100 uint16 frequency);
101 // Parse information elements to determine the physical mode.
102 static Metrics::WiFiNetworkPhyMode ParseIEsForPhyMode(
103 const std::vector<uint8_t> &ies);
mukesh agrawalb54601c2011-06-07 17:39:22 -0700104
mukesh agrawal6e277772011-09-29 15:04:23 -0700105 // TODO(quiche): make const?
mukesh agrawalb54601c2011-06-07 17:39:22 -0700106 std::vector<uint8_t> ssid_;
107 std::vector<uint8_t> bssid_;
108 std::string ssid_string_;
109 std::string ssid_hex_;
110 std::string bssid_string_;
111 std::string bssid_hex_;
mukesh agrawale1d90e92012-02-15 17:36:08 -0800112 int16 signal_strength_;
Thieu Lee41a72d2012-02-06 20:46:51 +0000113 uint16 frequency_;
Thieu Le1df7f4e2012-02-10 15:21:45 -0800114 uint16 physical_mode_;
mukesh agrawal6e277772011-09-29 15:04:23 -0700115 // network_mode_ and security_mode_ are represented as flimflam names
116 // (not necessarily the same as wpa_supplicant names)
Chris Masone092df3e2011-08-22 09:41:39 -0700117 std::string network_mode_;
mukesh agrawal6e277772011-09-29 15:04:23 -0700118 std::string security_mode_;
mukesh agrawalb54601c2011-06-07 17:39:22 -0700119
mukesh agrawalb20776f2012-02-10 16:00:36 -0800120 ProxyFactory *proxy_factory_;
121 WiFiRefPtr device_;
122 std::string rpc_id_;
123 scoped_ptr<SupplicantBSSProxyInterface> supplicant_bss_proxy_;
124
mukesh agrawalb54601c2011-06-07 17:39:22 -0700125 DISALLOW_COPY_AND_ASSIGN(WiFiEndpoint);
126};
127
128} // namespace shill
129
130#endif // SHILL_WIFI_ENDPOINT_