blob: 21a66ccb02241bc63833a621077a4f266f09c977 [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"
Chris Masone2b105542011-06-22 10:58:09 -070013#include "shill/refptr_types.h"
Paul Stewartb50f0b92011-05-16 16:31:42 -070014#include "shill/shill_event.h"
mukesh agrawalab87ea42011-05-18 11:44:49 -070015#include "shill/supplicant-process.h"
16#include "shill/supplicant-interface.h"
Paul Stewartb50f0b92011-05-16 16:31:42 -070017
18namespace shill {
19
mukesh agrawal445e72c2011-06-22 11:13:50 -070020class WiFiService;
mukesh agrawalb54601c2011-06-07 17:39:22 -070021
mukesh agrawalab87ea42011-05-18 11:44:49 -070022// WiFi class. Specialization of Device for WiFi.
Paul Stewartb50f0b92011-05-16 16:31:42 -070023class WiFi : public Device {
24 public:
Paul Stewartf1ce5d22011-05-19 13:10:20 -070025 WiFi(ControlInterface *control_interface,
26 EventDispatcher *dispatcher,
27 Manager *manager,
Chris Masone3bd3c8c2011-06-13 08:20:26 -070028 const std::string& link,
Paul Stewartf1ce5d22011-05-19 13:10:20 -070029 int interface_index);
mukesh agrawalab87ea42011-05-18 11:44:49 -070030 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 Masonea82b7112011-05-25 15:16:29 -070038 const std::map<std::string, ::DBus::Variant> &properties);
mukesh agrawalab87ea42011-05-18 11:44:49 -070039 void ScanDone();
40
mukesh agrawal445e72c2011-06-22 11:13:50 -070041 // called by WiFiService
42 void ConnectTo(const WiFiService &service);
mukesh agrawalb54601c2011-06-07 17:39:22 -070043
Paul Stewartb50f0b92011-05-16 16:31:42 -070044 private:
mukesh agrawalab87ea42011-05-18 11:44:49 -070045 // 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 Masone2b105542011-06-22 10:58:09 -070073 SupplicantInterfaceProxy(const WiFiRefPtr &wifi,
74 DBus::Connection *bus,
mukesh agrawalab87ea42011-05-18 11:44:49 -070075 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 Masone2b105542011-06-22 10:58:09 -070096 WiFiRefPtr wifi_;
mukesh agrawalab87ea42011-05-18 11:44:49 -070097 };
98
mukesh agrawalb54601c2011-06-07 17:39:22 -070099 typedef std::map<const std::string, WiFiEndpointRefPtr> EndpointMap;
100 typedef std::map<const std::string, ServiceRefPtr> ServiceMap;
101
mukesh agrawalab87ea42011-05-18 11:44:49 -0700102 static const char kSupplicantPath[];
103 static const char kSupplicantDBusAddr[];
104 static const char kSupplicantWiFiDriver[];
mukesh agrawalc7426a42011-06-03 13:04:28 -0700105 static const char kSupplicantErrorInterfaceExists[];
mukesh agrawal445e72c2011-06-22 11:13:50 -0700106 static const char kSupplicantPropertySSID[];
107 static const char kSupplicantPropertyNetworkMode[];
108 static const char kSupplicantPropertyKeyMode[];
mukesh agrawalb54601c2011-06-07 17:39:22 -0700109 static const char kSupplicantKeyModeNone[];
mukesh agrawalab87ea42011-05-18 11:44:49 -0700110
mukesh agrawalb54601c2011-06-07 17:39:22 -0700111 void RealScanDone();
112
113 static unsigned int service_id_serial_;
114 ScopedRunnableMethodFactory<WiFi> task_factory_;
115 ControlInterface *control_interface_;
116 EventDispatcher *dispatcher_;
Chris Masone853b81b2011-06-24 14:11:41 -0700117 scoped_ptr<DBus::Connection> dbus_;
mukesh agrawalab87ea42011-05-18 11:44:49 -0700118 scoped_ptr<SupplicantProcessProxy> supplicant_process_proxy_;
119 scoped_ptr<SupplicantInterfaceProxy> supplicant_interface_proxy_;
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
Chris Masone853b81b2011-06-24 14:11:41 -0700123 // 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 Stewartb50f0b92011-05-16 16:31:42 -0700130 DISALLOW_COPY_AND_ASSIGN(WiFi);
131};
132
133} // namespace shill
134
135#endif // SHILL_WIFI_