Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 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_ |
| 6 | #define SHILL_WIFI_ |
| 7 | |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 8 | #include <map> |
Chris Masone | 46eaaf5 | 2011-05-24 13:08:30 -0700 | [diff] [blame] | 9 | #include <string> |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 10 | #include <vector> |
Chris Masone | 46eaaf5 | 2011-05-24 13:08:30 -0700 | [diff] [blame] | 11 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 12 | #include "shill/device.h" |
| 13 | #include "shill/shill_event.h" |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 14 | #include "shill/supplicant-process.h" |
| 15 | #include "shill/supplicant-interface.h" |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 16 | |
| 17 | namespace shill { |
| 18 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 19 | class WiFiEndpoint; |
mukesh agrawal | 445e72c | 2011-06-22 11:13:50 -0700 | [diff] [blame] | 20 | class WiFiService; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 21 | typedef scoped_refptr<const WiFiEndpoint> WiFiEndpointConstRefPtr; |
| 22 | typedef scoped_refptr<WiFiEndpoint> WiFiEndpointRefPtr; |
| 23 | |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 24 | // WiFi class. Specialization of Device for WiFi. |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 25 | class WiFi : public Device { |
| 26 | public: |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 27 | WiFi(ControlInterface *control_interface, |
| 28 | EventDispatcher *dispatcher, |
| 29 | Manager *manager, |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 30 | const std::string& link, |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 31 | int interface_index); |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 32 | virtual ~WiFi(); |
| 33 | virtual void Start(); |
| 34 | virtual void Stop(); |
| 35 | virtual bool TechnologyIs(const Technology type); |
| 36 | |
| 37 | // called by SupplicantInterfaceProxy, in response to events from |
| 38 | // wpa_supplicant. |
| 39 | void BSSAdded(const ::DBus::Path &BSS, |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 40 | const std::map<std::string, ::DBus::Variant> &properties); |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 41 | void ScanDone(); |
| 42 | |
mukesh agrawal | 445e72c | 2011-06-22 11:13:50 -0700 | [diff] [blame] | 43 | // called by WiFiService |
| 44 | void ConnectTo(const WiFiService &service); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 45 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 46 | private: |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 47 | // SupplicantProcessProxy. provides access to wpa_supplicant's |
| 48 | // process-level D-Bus APIs. |
| 49 | class SupplicantProcessProxy : |
| 50 | public fi::w1::wpa_supplicant1_proxy, |
| 51 | private ::DBus::ObjectProxy // used by dbus-c++, not WiFi |
| 52 | { |
| 53 | public: |
| 54 | explicit SupplicantProcessProxy(DBus::Connection *bus); |
| 55 | |
| 56 | private: |
| 57 | // called by dbus-c++, via wpa_supplicant1_proxy interface, |
| 58 | // in response to signals from wpa_supplicant. not exposed |
| 59 | // to WiFi. |
| 60 | virtual void InterfaceAdded( |
| 61 | const ::DBus::Path &path, |
| 62 | const std::map<std::string, ::DBus::Variant> &properties); |
| 63 | virtual void InterfaceRemoved(const ::DBus::Path &path); |
| 64 | virtual void PropertiesChanged( |
| 65 | const std::map<std::string, ::DBus::Variant> &properties); |
| 66 | }; |
| 67 | |
| 68 | // SupplicantInterfaceProxy. provides access to wpa_supplicant's |
| 69 | // network-interface D-Bus APIs. |
| 70 | class SupplicantInterfaceProxy : |
| 71 | public fi::w1::wpa_supplicant1::Interface_proxy, |
| 72 | private ::DBus::ObjectProxy // used by dbus-c++, not WiFi |
| 73 | { |
| 74 | public: |
| 75 | SupplicantInterfaceProxy(WiFi *wifi, DBus::Connection *bus, |
| 76 | const ::DBus::Path &object_path); |
| 77 | |
| 78 | private: |
| 79 | // called by dbus-c++, via Interface_proxy interface, |
| 80 | // in response to signals from wpa_supplicant. not exposed |
| 81 | // to WiFi. |
| 82 | virtual void ScanDone(const bool &success); |
| 83 | virtual void BSSAdded(const ::DBus::Path &BSS, |
| 84 | const std::map<std::string, ::DBus::Variant> |
| 85 | &properties); |
| 86 | virtual void BSSRemoved(const ::DBus::Path &BSS); |
| 87 | virtual void BlobAdded(const std::string &blobname); |
| 88 | virtual void BlobRemoved(const std::string &blobname); |
| 89 | virtual void NetworkAdded(const ::DBus::Path &network, |
| 90 | const std::map<std::string, ::DBus::Variant> |
| 91 | &properties); |
| 92 | virtual void NetworkRemoved(const ::DBus::Path &network); |
| 93 | virtual void NetworkSelected(const ::DBus::Path &network); |
| 94 | virtual void PropertiesChanged(const std::map<std::string, ::DBus::Variant> |
| 95 | &properties); |
| 96 | |
| 97 | WiFi &wifi_; |
| 98 | }; |
| 99 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 100 | typedef std::map<const std::string, WiFiEndpointRefPtr> EndpointMap; |
| 101 | typedef std::map<const std::string, ServiceRefPtr> ServiceMap; |
| 102 | |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 103 | static const char kSupplicantPath[]; |
| 104 | static const char kSupplicantDBusAddr[]; |
| 105 | static const char kSupplicantWiFiDriver[]; |
mukesh agrawal | c7426a4 | 2011-06-03 13:04:28 -0700 | [diff] [blame] | 106 | static const char kSupplicantErrorInterfaceExists[]; |
mukesh agrawal | 445e72c | 2011-06-22 11:13:50 -0700 | [diff] [blame] | 107 | static const char kSupplicantPropertySSID[]; |
| 108 | static const char kSupplicantPropertyNetworkMode[]; |
| 109 | static const char kSupplicantPropertyKeyMode[]; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 110 | static const char kSupplicantKeyModeNone[]; |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 111 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 112 | void RealScanDone(); |
| 113 | |
| 114 | static unsigned int service_id_serial_; |
| 115 | ScopedRunnableMethodFactory<WiFi> task_factory_; |
| 116 | ControlInterface *control_interface_; |
| 117 | EventDispatcher *dispatcher_; |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame^] | 118 | scoped_ptr<DBus::Connection> dbus_; |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 119 | scoped_ptr<SupplicantProcessProxy> supplicant_process_proxy_; |
| 120 | scoped_ptr<SupplicantInterfaceProxy> supplicant_interface_proxy_; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 121 | EndpointMap endpoint_by_bssid_; |
| 122 | ServiceMap service_by_private_id_; |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame] | 123 | |
Chris Masone | 853b81b | 2011-06-24 14:11:41 -0700 | [diff] [blame^] | 124 | // Properties |
| 125 | std::string bgscan_method_; |
| 126 | uint16 bgscan_short_interval_; |
| 127 | int32 bgscan_signal_threshold_; |
| 128 | bool scan_pending_; |
| 129 | uint16 scan_interval_; |
| 130 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 131 | DISALLOW_COPY_AND_ASSIGN(WiFi); |
| 132 | }; |
| 133 | |
| 134 | } // namespace shill |
| 135 | |
| 136 | #endif // SHILL_WIFI_ |