shill: SupplicantInterfaceProxy: Move Events to delegate
Previously the SupplicantInterfaceProxy sent events directly to a
WiFi device reference. In moving towards using wpa_supplicant on
wired interfaces, create a SupplicantEventDelegateInterface on
which these events are invoked instead. WiFi Devices methods
which accepted supplicant events are now an implementation of
this interface. While here, also move kSupplicantConfPath
to wpa_supplicant (since it isn't WiFi specific) and add a "wired"
driver.
BUG=chromium:224509
TEST=Unit tests + manual association
Change-Id: Id19a70254ad1256e9933a9512ab93e5951582634
Reviewed-on: https://gerrit.chromium.org/gerrit/46726
Reviewed-by: Christopher Wiley <wiley@chromium.org>
Commit-Queue: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/proxy_factory.cc b/proxy_factory.cc
index eb0fcc1..064718a 100644
--- a/proxy_factory.cc
+++ b/proxy_factory.cc
@@ -94,10 +94,10 @@
}
SupplicantInterfaceProxyInterface *ProxyFactory::CreateSupplicantInterfaceProxy(
- const WiFiRefPtr &wifi,
+ SupplicantEventDelegateInterface *delegate,
const DBus::Path &object_path,
const char *dbus_addr) {
- return new SupplicantInterfaceProxy(wifi,
+ return new SupplicantInterfaceProxy(delegate,
connection(),
object_path,
dbus_addr);
diff --git a/proxy_factory.h b/proxy_factory.h
index b66d125..8fd45cb 100644
--- a/proxy_factory.h
+++ b/proxy_factory.h
@@ -31,6 +31,7 @@
class PowerManagerProxyDelegate;
class PowerManagerProxyInterface;
class SupplicantBSSProxyInterface;
+class SupplicantEventDelegateInterface;
class SupplicantInterfaceProxyInterface;
class SupplicantNetworkProxyInterface;
class SupplicantProcessProxyInterface;
@@ -85,7 +86,7 @@
const char *dbus_addr);
virtual SupplicantInterfaceProxyInterface *CreateSupplicantInterfaceProxy(
- const WiFiRefPtr &wifi,
+ SupplicantEventDelegateInterface *delegate,
const DBus::Path &object_path,
const char *dbus_addr);
diff --git a/supplicant_event_delegate_interface.h b/supplicant_event_delegate_interface.h
new file mode 100644
index 0000000..c4b3383
--- /dev/null
+++ b/supplicant_event_delegate_interface.h
@@ -0,0 +1,36 @@
+// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SUPPLICANT_EVENT_DELEGATE_INTERFACE_H_
+#define SUPPLICANT_EVENT_DELEGATE_INTERFACE_H_
+
+#include <map>
+#include <string>
+
+#include <dbus-c++/dbus.h>
+
+namespace shill {
+
+// SupplicantEventDelegateInterface declares the set of methods that
+// a SupplicantInterfaceProxy calls on an interested party when
+// wpa_supplicant events occur on the network interface interface.
+class SupplicantEventDelegateInterface {
+ public:
+ typedef std::map<std::string, ::DBus::Variant> PropertyMap;
+
+ virtual ~SupplicantEventDelegateInterface() {}
+
+ virtual void BSSAdded(const ::DBus::Path &BSS,
+ const PropertyMap &properties) = 0;
+ virtual void BSSRemoved(const ::DBus::Path &BSS) = 0;
+ virtual void Certification(const PropertyMap &properties) = 0;
+ virtual void EAPEvent(const std::string &status,
+ const std::string ¶meter) = 0;
+ virtual void PropertiesChanged(const PropertyMap &properties) = 0;
+ virtual void ScanDone() = 0;
+};
+
+} // namespace shill
+
+#endif // SUPPLICANT_EVENT_DELEGATE_INTERFACE_H_
diff --git a/supplicant_interface_proxy.cc b/supplicant_interface_proxy.cc
index a9d4f1f..e6508c9 100644
--- a/supplicant_interface_proxy.cc
+++ b/supplicant_interface_proxy.cc
@@ -10,7 +10,7 @@
#include <dbus-c++/dbus.h>
#include "shill/logging.h"
-#include "shill/wifi.h"
+#include "shill/supplicant_event_delegate_interface.h"
using std::map;
using std::string;
@@ -18,11 +18,11 @@
namespace shill {
SupplicantInterfaceProxy::SupplicantInterfaceProxy(
- const WiFiRefPtr &wifi,
+ SupplicantEventDelegateInterface *delegate,
DBus::Connection *bus,
const ::DBus::Path &object_path,
const char *dbus_addr)
- : proxy_(wifi, bus, object_path, dbus_addr) {}
+ : proxy_(delegate, bus, object_path, dbus_addr) {}
SupplicantInterfaceProxy::~SupplicantInterfaceProxy() {}
@@ -155,10 +155,10 @@
// definitions for private class SupplicantInterfaceProxy::Proxy
SupplicantInterfaceProxy::Proxy::Proxy(
- const WiFiRefPtr &wifi, DBus::Connection *bus,
+ SupplicantEventDelegateInterface *delegate, DBus::Connection *bus,
const DBus::Path &dbus_path, const char *dbus_addr)
: DBus::ObjectProxy(*bus, dbus_path, dbus_addr),
- wifi_(wifi) {}
+ delegate_(delegate) {}
SupplicantInterfaceProxy::Proxy::~Proxy() {}
@@ -176,25 +176,25 @@
const ::DBus::Path &BSS,
const std::map<string, ::DBus::Variant> &properties) {
SLOG(DBus, 2) << __func__;
- wifi_->BSSAdded(BSS, properties);
+ delegate_->BSSAdded(BSS, properties);
}
void SupplicantInterfaceProxy::Proxy::Certification(
const std::map<string, ::DBus::Variant> &properties) {
SLOG(DBus, 2) << __func__;
- wifi_->Certification(properties);
+ delegate_->Certification(properties);
}
void SupplicantInterfaceProxy::Proxy::EAP(
const string &status, const string ¶meter) {
SLOG(DBus, 2) << __func__ << ": status " << status
<< ", parameter " << parameter;
- wifi_->EAPEvent(status, parameter);
+ delegate_->EAPEvent(status, parameter);
}
void SupplicantInterfaceProxy::Proxy::BSSRemoved(const ::DBus::Path &BSS) {
SLOG(DBus, 2) << __func__;
- wifi_->BSSRemoved(BSS);
+ delegate_->BSSRemoved(BSS);
}
void SupplicantInterfaceProxy::Proxy::NetworkAdded(
@@ -207,7 +207,7 @@
void SupplicantInterfaceProxy::Proxy::NetworkRemoved(
const ::DBus::Path &/*network*/) {
SLOG(DBus, 2) << __func__;
- // TODO(quiche): Pass this up to WiFi, so that it can clean its
+ // TODO(quiche): Pass this up to the delegate, so that it can clean its
// rpcid_by_service_ map. crosbug.com/24699
}
@@ -220,13 +220,13 @@
void SupplicantInterfaceProxy::Proxy::PropertiesChanged(
const std::map<string, ::DBus::Variant> &properties) {
SLOG(DBus, 2) << __func__;
- wifi_->PropertiesChanged(properties);
+ delegate_->PropertiesChanged(properties);
}
void SupplicantInterfaceProxy::Proxy::ScanDone(const bool& success) {
SLOG(DBus, 2) << __func__ << ": " << success;
if (success) {
- wifi_->ScanDone();
+ delegate_->ScanDone();
}
}
diff --git a/supplicant_interface_proxy.h b/supplicant_interface_proxy.h
index eb100da..b959bde 100644
--- a/supplicant_interface_proxy.h
+++ b/supplicant_interface_proxy.h
@@ -16,12 +16,17 @@
namespace shill {
+class SupplicantEventDelegateInterface;
+
// SupplicantInterfaceProxy. provides access to wpa_supplicant's
-// network-interface APIs via D-Bus.
+// network-interface APIs via D-Bus. This takes a delegate, which
+// is an interface that is used to send notifications of supplicant
+// events. This pointer is not owned by SupplicantInterfaceProxy
+// and must outlive the proxy.
class SupplicantInterfaceProxy
: public SupplicantInterfaceProxyInterface {
public:
- SupplicantInterfaceProxy(const WiFiRefPtr &wifi,
+ SupplicantInterfaceProxy(SupplicantEventDelegateInterface *delegate,
DBus::Connection *bus,
const ::DBus::Path &object_path,
const char *dbus_addr);
@@ -46,7 +51,7 @@
class Proxy : public fi::w1::wpa_supplicant1::Interface_proxy,
public ::DBus::ObjectProxy {
public:
- Proxy(const WiFiRefPtr &wifi,
+ Proxy(SupplicantEventDelegateInterface *delegate,
DBus::Connection *bus,
const ::DBus::Path &object_path,
const char *dbus_addr);
@@ -73,7 +78,10 @@
&properties);
virtual void ScanDone(const bool &success);
- WiFiRefPtr wifi_;
+ // This pointer is owned by the object that created |this|. That object
+ // MUST destroy |this| before destroying itself.
+ SupplicantEventDelegateInterface *delegate_;
+
DISALLOW_COPY_AND_ASSIGN(Proxy);
};
diff --git a/wifi.cc b/wifi.cc
index a2be8e5..bc523b2 100644
--- a/wifi.cc
+++ b/wifi.cc
@@ -54,7 +54,6 @@
namespace shill {
// statics
-const char WiFi::kSupplicantConfPath[] = SHIMDIR "/wpa_supplicant.conf";
const char *WiFi::kDefaultBgscanMethod =
WPASupplicant::kNetworkBgscanMethodSimple;
const uint16 WiFi::kDefaultBgscanShortIntervalSeconds = 30;
@@ -1521,7 +1520,7 @@
append_string(WPASupplicant::kDriverNL80211);
create_interface_args[
WPASupplicant::kInterfacePropertyConfigFile].writer().
- append_string(kSupplicantConfPath);
+ append_string(WPASupplicant::kSupplicantConfPath);
interface_path =
supplicant_process_proxy_->CreateInterface(create_interface_args);
} catch (const DBus::Error &e) { // NOLINT
diff --git a/wifi.h b/wifi.h
index fc84c98..66cbaf3 100644
--- a/wifi.h
+++ b/wifi.h
@@ -91,6 +91,7 @@
#include "shill/power_manager.h"
#include "shill/refptr_types.h"
#include "shill/service.h"
+#include "shill/supplicant_event_delegate_interface.h"
namespace shill {
@@ -104,7 +105,7 @@
class WiFiService;
// WiFi class. Specialization of Device for WiFi.
-class WiFi : public Device {
+class WiFi : public Device, public SupplicantEventDelegateInterface {
public:
WiFi(ControlInterface *control_interface,
EventDispatcher *dispatcher,
@@ -125,16 +126,20 @@
// Callback for when a service is configured with an IP.
virtual void OnConnected();
- // Called by SupplicantInterfaceProxy, in response to events from
+ // Implementation of SupplicantEventDelegateInterface. These methods
+ // are called by SupplicantInterfaceProxy, in response to events from
// wpa_supplicant.
- void BSSAdded(const ::DBus::Path &BSS,
- const std::map<std::string, ::DBus::Variant> &properties);
- void BSSRemoved(const ::DBus::Path &BSS);
- void Certification(const std::map<std::string, ::DBus::Variant> &properties);
- void EAPEvent(const std::string &status, const std::string ¶meter);
- void PropertiesChanged(
+ virtual void BSSAdded(
+ const ::DBus::Path &BSS,
const std::map<std::string, ::DBus::Variant> &properties);
- void ScanDone();
+ virtual void BSSRemoved(const ::DBus::Path &BSS);
+ virtual void Certification(
+ const std::map<std::string, ::DBus::Variant> &properties);
+ virtual void EAPEvent(
+ const std::string &status, const std::string ¶meter);
+ virtual void PropertiesChanged(
+ const std::map<std::string, ::DBus::Variant> &properties);
+ virtual void ScanDone();
// Called by WiFiService.
virtual void ConnectTo(
@@ -198,7 +203,6 @@
typedef std::map<const std::string, WiFiEndpointRefPtr> EndpointMap;
typedef std::map<const WiFiService *, std::string> ReverseServiceMap;
- static const char kSupplicantConfPath[];
static const char *kDefaultBgscanMethod;
static const uint16 kDefaultBgscanShortIntervalSeconds;
static const int32 kDefaultBgscanSignalThresholdDbm;
diff --git a/wifi_unittest.cc b/wifi_unittest.cc
index 842811d..c8b33b1 100644
--- a/wifi_unittest.cc
+++ b/wifi_unittest.cc
@@ -284,7 +284,7 @@
}
virtual SupplicantInterfaceProxyInterface *CreateSupplicantInterfaceProxy(
- const WiFiRefPtr &/*wifi*/,
+ SupplicantEventDelegateInterface */*delegate*/,
const DBus::Path &/*object_path*/,
const char */*dbus_addr*/) {
return test_->supplicant_interface_proxy_.release();
@@ -2075,7 +2075,7 @@
}
TEST_F(WiFiMainTest, VerifyPaths) {
- string path = WiFi::kSupplicantConfPath;
+ string path(WPASupplicant::kSupplicantConfPath);
TrimString(path, FilePath::kSeparators, &path);
EXPECT_TRUE(file_util::PathExists(FilePath(SYSROOT).Append(path)));
}
diff --git a/wpa_supplicant.cc b/wpa_supplicant.cc
index 2021155..4a5bce5 100644
--- a/wpa_supplicant.cc
+++ b/wpa_supplicant.cc
@@ -42,6 +42,7 @@
const char WPASupplicant::kDebugLevelMsgDump[] = "msgdump";
const char WPASupplicant::kDebugLevelWarning[] = "warning";
const char WPASupplicant::kDriverNL80211[] = "nl80211";
+const char WPASupplicant::kDriverWired[] = "wired";
const char WPASupplicant::kEAPParameterAlertUnknownCA[] = "unknown CA";
const char WPASupplicant::kEAPParameterFailure[] = "failure";
const char WPASupplicant::kEAPParameterSuccess[] = "success";
@@ -137,6 +138,9 @@
const uint32_t WPASupplicant::kNetworkModeAccessPointInt = 2;
const uint32_t WPASupplicant::kScanMaxSSIDsPerScan = 4;
+const char WPASupplicant::kSupplicantConfPath[] =
+ SHIMDIR "/wpa_supplicant.conf";
+
// static
void WPASupplicant::Populate8021xProperties(
const EapCredentials &eap, CertificateFile *certificate_file,
diff --git a/wpa_supplicant.h b/wpa_supplicant.h
index daccf36..695424d 100644
--- a/wpa_supplicant.h
+++ b/wpa_supplicant.h
@@ -38,6 +38,7 @@
static const char kDebugLevelMsgDump[];
static const char kDebugLevelWarning[];
static const char kDriverNL80211[];
+ static const char kDriverWired[];
static const char kEAPParameterAlertUnknownCA[];
static const char kEAPParameterFailure[];
static const char kEAPParameterSuccess[];
@@ -132,6 +133,8 @@
static const uint32_t kNetworkModeAccessPointInt;
static const uint32_t kScanMaxSSIDsPerScan;
+ static const char kSupplicantConfPath[];
+
// Populate the wpa_supplicant DBus parameter map |params| with the
// credentials in |eap|. To do so, this function may use |certificate_file|
// or |nss| to export CA certificates to be passed to wpa_supplicant.