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