blob: b302ed9549ab1ccff09d4cfb9d2f5ca1154ee215 [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 agrawalab87ea42011-05-18 11:44:49 -070019// WiFi class. Specialization of Device for WiFi.
Paul Stewartb50f0b92011-05-16 16:31:42 -070020class WiFi : public Device {
21 public:
Paul Stewartf1ce5d22011-05-19 13:10:20 -070022 WiFi(ControlInterface *control_interface,
23 EventDispatcher *dispatcher,
24 Manager *manager,
25 const std::string& link_name,
26 int interface_index);
mukesh agrawalab87ea42011-05-18 11:44:49 -070027 virtual ~WiFi();
28 virtual void Start();
29 virtual void Stop();
30 virtual bool TechnologyIs(const Technology type);
31
32 // called by SupplicantInterfaceProxy, in response to events from
33 // wpa_supplicant.
34 void BSSAdded(const ::DBus::Path &BSS,
Chris Masonea82b7112011-05-25 15:16:29 -070035 const std::map<std::string, ::DBus::Variant> &properties);
mukesh agrawalab87ea42011-05-18 11:44:49 -070036 void ScanDone();
37
Paul Stewartb50f0b92011-05-16 16:31:42 -070038 private:
mukesh agrawalab87ea42011-05-18 11:44:49 -070039 // SupplicantProcessProxy. provides access to wpa_supplicant's
40 // process-level D-Bus APIs.
41 class SupplicantProcessProxy :
42 public fi::w1::wpa_supplicant1_proxy,
43 private ::DBus::ObjectProxy // used by dbus-c++, not WiFi
44 {
45 public:
46 explicit SupplicantProcessProxy(DBus::Connection *bus);
47
48 private:
49 // called by dbus-c++, via wpa_supplicant1_proxy interface,
50 // in response to signals from wpa_supplicant. not exposed
51 // to WiFi.
52 virtual void InterfaceAdded(
53 const ::DBus::Path &path,
54 const std::map<std::string, ::DBus::Variant> &properties);
55 virtual void InterfaceRemoved(const ::DBus::Path &path);
56 virtual void PropertiesChanged(
57 const std::map<std::string, ::DBus::Variant> &properties);
58 };
59
60 // SupplicantInterfaceProxy. provides access to wpa_supplicant's
61 // network-interface D-Bus APIs.
62 class SupplicantInterfaceProxy :
63 public fi::w1::wpa_supplicant1::Interface_proxy,
64 private ::DBus::ObjectProxy // used by dbus-c++, not WiFi
65 {
66 public:
67 SupplicantInterfaceProxy(WiFi *wifi, DBus::Connection *bus,
68 const ::DBus::Path &object_path);
69
70 private:
71 // called by dbus-c++, via Interface_proxy interface,
72 // in response to signals from wpa_supplicant. not exposed
73 // to WiFi.
74 virtual void ScanDone(const bool &success);
75 virtual void BSSAdded(const ::DBus::Path &BSS,
76 const std::map<std::string, ::DBus::Variant>
77 &properties);
78 virtual void BSSRemoved(const ::DBus::Path &BSS);
79 virtual void BlobAdded(const std::string &blobname);
80 virtual void BlobRemoved(const std::string &blobname);
81 virtual void NetworkAdded(const ::DBus::Path &network,
82 const std::map<std::string, ::DBus::Variant>
83 &properties);
84 virtual void NetworkRemoved(const ::DBus::Path &network);
85 virtual void NetworkSelected(const ::DBus::Path &network);
86 virtual void PropertiesChanged(const std::map<std::string, ::DBus::Variant>
87 &properties);
88
89 WiFi &wifi_;
90 };
91
92 static const char kSupplicantPath[];
93 static const char kSupplicantDBusAddr[];
94 static const char kSupplicantWiFiDriver[];
95
96 DBus::Connection dbus_;
97 scoped_ptr<SupplicantProcessProxy> supplicant_process_proxy_;
98 scoped_ptr<SupplicantInterfaceProxy> supplicant_interface_proxy_;
99 bool scan_pending_;
100 std::vector<std::string> ssids_;
101
102 // provide WiFiTest access to scan_pending_, so it can determine
103 // if the scan completed, or timed out.
104 friend class WiFiTest;
Paul Stewartb50f0b92011-05-16 16:31:42 -0700105 DISALLOW_COPY_AND_ASSIGN(WiFi);
106};
107
108} // namespace shill
109
110#endif // SHILL_WIFI_