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