blob: 00d723e9d1e8b573d2d0beb03e8251e565a62d45 [file] [log] [blame]
Paul Stewartb50f0b92011-05-16 16:31:42 -07001// 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 agrawalab87ea42011-05-18 11:44:49 -07008#include <map>
Chris Masone46eaaf52011-05-24 13:08:30 -07009#include <string>
mukesh agrawalab87ea42011-05-18 11:44:49 -070010#include <vector>
Chris Masone46eaaf52011-05-24 13:08:30 -070011
Paul Stewartb50f0b92011-05-16 16:31:42 -070012#include "shill/device.h"
13#include "shill/shill_event.h"
mukesh agrawalab87ea42011-05-18 11:44:49 -070014#include "shill/supplicant-process.h"
15#include "shill/supplicant-interface.h"
Paul Stewartb50f0b92011-05-16 16:31:42 -070016
17namespace shill {
18
mukesh agrawalb54601c2011-06-07 17:39:22 -070019class WiFiEndpoint;
mukesh agrawal445e72c2011-06-22 11:13:50 -070020class WiFiService;
mukesh agrawalb54601c2011-06-07 17:39:22 -070021typedef scoped_refptr<const WiFiEndpoint> WiFiEndpointConstRefPtr;
22typedef scoped_refptr<WiFiEndpoint> WiFiEndpointRefPtr;
23
mukesh agrawalab87ea42011-05-18 11:44:49 -070024// WiFi class. Specialization of Device for WiFi.
Paul Stewartb50f0b92011-05-16 16:31:42 -070025class WiFi : public Device {
26 public:
Paul Stewartf1ce5d22011-05-19 13:10:20 -070027 WiFi(ControlInterface *control_interface,
28 EventDispatcher *dispatcher,
29 Manager *manager,
Chris Masone3bd3c8c2011-06-13 08:20:26 -070030 const std::string& link,
Paul Stewartf1ce5d22011-05-19 13:10:20 -070031 int interface_index);
mukesh agrawalab87ea42011-05-18 11:44:49 -070032 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 Masonea82b7112011-05-25 15:16:29 -070040 const std::map<std::string, ::DBus::Variant> &properties);
mukesh agrawalab87ea42011-05-18 11:44:49 -070041 void ScanDone();
42
mukesh agrawal445e72c2011-06-22 11:13:50 -070043 // called by WiFiService
44 void ConnectTo(const WiFiService &service);
mukesh agrawalb54601c2011-06-07 17:39:22 -070045
Paul Stewartb50f0b92011-05-16 16:31:42 -070046 private:
mukesh agrawalab87ea42011-05-18 11:44:49 -070047 // 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 agrawalb54601c2011-06-07 17:39:22 -0700100 typedef std::map<const std::string, WiFiEndpointRefPtr> EndpointMap;
101 typedef std::map<const std::string, ServiceRefPtr> ServiceMap;
102
mukesh agrawalab87ea42011-05-18 11:44:49 -0700103 static const char kSupplicantPath[];
104 static const char kSupplicantDBusAddr[];
105 static const char kSupplicantWiFiDriver[];
mukesh agrawalc7426a42011-06-03 13:04:28 -0700106 static const char kSupplicantErrorInterfaceExists[];
mukesh agrawal445e72c2011-06-22 11:13:50 -0700107 static const char kSupplicantPropertySSID[];
108 static const char kSupplicantPropertyNetworkMode[];
109 static const char kSupplicantPropertyKeyMode[];
mukesh agrawalb54601c2011-06-07 17:39:22 -0700110 static const char kSupplicantKeyModeNone[];
mukesh agrawalab87ea42011-05-18 11:44:49 -0700111
mukesh agrawalb54601c2011-06-07 17:39:22 -0700112 void RealScanDone();
113
114 static unsigned int service_id_serial_;
115 ScopedRunnableMethodFactory<WiFi> task_factory_;
116 ControlInterface *control_interface_;
117 EventDispatcher *dispatcher_;
mukesh agrawalab87ea42011-05-18 11:44:49 -0700118 DBus::Connection dbus_;
119 scoped_ptr<SupplicantProcessProxy> supplicant_process_proxy_;
120 scoped_ptr<SupplicantInterfaceProxy> supplicant_interface_proxy_;
121 bool scan_pending_;
mukesh agrawalb54601c2011-06-07 17:39:22 -0700122 EndpointMap endpoint_by_bssid_;
123 ServiceMap service_by_private_id_;
mukesh agrawalab87ea42011-05-18 11:44:49 -0700124
125 // provide WiFiTest access to scan_pending_, so it can determine
126 // if the scan completed, or timed out.
127 friend class WiFiTest;
Paul Stewartb50f0b92011-05-16 16:31:42 -0700128 DISALLOW_COPY_AND_ASSIGN(WiFi);
129};
130
131} // namespace shill
132
133#endif // SHILL_WIFI_