blob: f7e851aac946319f89c5b5e542f9861813a06260 [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;
20typedef scoped_refptr<const WiFiEndpoint> WiFiEndpointConstRefPtr;
21typedef scoped_refptr<WiFiEndpoint> WiFiEndpointRefPtr;
22
mukesh agrawalab87ea42011-05-18 11:44:49 -070023// WiFi class. Specialization of Device for WiFi.
Paul Stewartb50f0b92011-05-16 16:31:42 -070024class WiFi : public Device {
25 public:
Paul Stewartf1ce5d22011-05-19 13:10:20 -070026 WiFi(ControlInterface *control_interface,
27 EventDispatcher *dispatcher,
28 Manager *manager,
29 const std::string& link_name,
30 int interface_index);
mukesh agrawalab87ea42011-05-18 11:44:49 -070031 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 Masonea82b7112011-05-25 15:16:29 -070039 const std::map<std::string, ::DBus::Variant> &properties);
mukesh agrawalab87ea42011-05-18 11:44:49 -070040 void ScanDone();
41
mukesh agrawalb54601c2011-06-07 17:39:22 -070042 // 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 Stewartb50f0b92011-05-16 16:31:42 -070047 private:
mukesh agrawalab87ea42011-05-18 11:44:49 -070048 // 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 agrawalb54601c2011-06-07 17:39:22 -0700101 typedef std::map<const std::string, WiFiEndpointRefPtr> EndpointMap;
102 typedef std::map<const std::string, ServiceRefPtr> ServiceMap;
103
mukesh agrawalab87ea42011-05-18 11:44:49 -0700104 static const char kSupplicantPath[];
105 static const char kSupplicantDBusAddr[];
106 static const char kSupplicantWiFiDriver[];
mukesh agrawalc7426a42011-06-03 13:04:28 -0700107 static const char kSupplicantErrorInterfaceExists[];
mukesh agrawalb54601c2011-06-07 17:39:22 -0700108 static const char kSupplicantKeyModeNone[];
mukesh agrawalab87ea42011-05-18 11:44:49 -0700109
mukesh agrawalb54601c2011-06-07 17:39:22 -0700110 void RealScanDone();
111
112 static unsigned int service_id_serial_;
113 ScopedRunnableMethodFactory<WiFi> task_factory_;
114 ControlInterface *control_interface_;
115 EventDispatcher *dispatcher_;
mukesh agrawalab87ea42011-05-18 11:44:49 -0700116 DBus::Connection dbus_;
117 scoped_ptr<SupplicantProcessProxy> supplicant_process_proxy_;
118 scoped_ptr<SupplicantInterfaceProxy> supplicant_interface_proxy_;
119 bool scan_pending_;
mukesh agrawalb54601c2011-06-07 17:39:22 -0700120 EndpointMap endpoint_by_bssid_;
121 ServiceMap service_by_private_id_;
mukesh agrawalab87ea42011-05-18 11:44:49 -0700122
123 // provide WiFiTest access to scan_pending_, so it can determine
124 // if the scan completed, or timed out.
125 friend class WiFiTest;
Paul Stewartb50f0b92011-05-16 16:31:42 -0700126 DISALLOW_COPY_AND_ASSIGN(WiFi);
127};
128
129} // namespace shill
130
131#endif // SHILL_WIFI_