[PATCH] wpa_supplicant and dbus code separation

Witold Sowa witold.sowa at gmail.com
Tue Oct 13 07:22:52 EDT 2009


This patch completely separates supplicant's code from dbus.
It introduces three new notifications which copes with all
remaining dbus stuff.
wpas_notify_unregister_interface() was renamed to
wpas_notify_iface_removed().
---
 wpa_supplicant/notify.c         |   43 ++++++++++++++++++++++++++++++++------
 wpa_supplicant/notify.h         |    5 +++-
 wpa_supplicant/wpa_supplicant.c |   21 +++++++-----------
 3 files changed, 48 insertions(+), 21 deletions(-)

diff --git a/wpa_supplicant/notify.c b/wpa_supplicant/notify.c
index dd7393b..066f5a9 100644
--- a/wpa_supplicant/notify.c
+++ b/wpa_supplicant/notify.c
@@ -21,6 +21,42 @@
 #include "ctrl_iface_dbus.h"
 #include "notify.h"
 
+int wpas_notify_supplicant_initialized(struct wpa_global *global)
+{
+	if (global->params.dbus_ctrl_interface) {
+		global->dbus_ctrl_iface =
+			wpa_supplicant_dbus_ctrl_iface_init(global);
+		if (global->dbus_ctrl_iface == NULL)
+			return -1;
+	}
+
+	return 0;
+}
+
+
+void wpas_notify_supplicant_deinitialized(struct wpa_global *global)
+{
+	if (global->dbus_ctrl_iface)
+		wpa_supplicant_dbus_ctrl_iface_deinit(global->dbus_ctrl_iface);
+}
+
+
+int wpas_notify_iface_added(struct wpa_supplicant *wpa_s)
+{
+	if (wpas_dbus_register_iface(wpa_s))
+		return -1;
+
+	return 0;
+}
+
+
+
+void wpas_notify_iface_removed(struct wpa_supplicant *wpa_s)
+{
+	/* unregister interface in old DBus ctrl iface */
+	wpas_dbus_unregister_iface(wpa_s);
+}
+
 
 void wpas_notify_state_changed(struct wpa_supplicant *wpa_s,
 			       wpa_states new_state, wpa_states old_state)
@@ -58,13 +94,6 @@ void wpas_notify_network_selected(struct wpa_supplicant *wpa_s,
 }
 
 
-void wpas_notify_unregister_interface(struct wpa_supplicant *wpa_s)
-{
-	/* unregister interface in old DBus ctrl iface */
-	wpas_dbus_unregister_iface(wpa_s);
-}
-
-
 void wpas_notify_scanning(struct wpa_supplicant *wpa_s)
 {
 	/* notify the old DBus API */
diff --git a/wpa_supplicant/notify.h b/wpa_supplicant/notify.h
index d11aa84..b8231aa 100644
--- a/wpa_supplicant/notify.h
+++ b/wpa_supplicant/notify.h
@@ -19,6 +19,10 @@ struct wps_credential;
 struct wps_event_m2d;
 struct wps_event_fail;
 
+int wpas_notify_supplicant_initialized(struct wpa_global *global);
+void wpas_notify_supplicant_deinitialized(struct wpa_global *global);
+int wpas_notify_iface_added(struct wpa_supplicant *wpa_s);
+void wpas_notify_iface_removed(struct wpa_supplicant *wpa_s);
 void wpas_notify_state_changed(struct wpa_supplicant *wpa_s,
 			       wpa_states new_state, wpa_states old_state);
 void wpas_notify_network_changed(struct wpa_supplicant *wpa_s);
@@ -28,7 +32,6 @@ void wpas_notify_network_enabled_changed(struct wpa_supplicant *wpa_s,
 					 struct wpa_ssid *ssid);
 void wpas_notify_network_selected(struct wpa_supplicant *wpa_s,
 				  struct wpa_ssid *ssid);
-void wpas_notify_unregister_interface(struct wpa_supplicant *wpa_s);
 void wpas_notify_scanning(struct wpa_supplicant *wpa_s);
 void wpas_notify_scan_done(struct wpa_supplicant *wpa_s, int success);
 void wpas_notify_scan_results(struct wpa_supplicant *wpa_s);
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index 37a1927..b46fda2 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -29,7 +29,6 @@
 #include "wpa_supplicant_i.h"
 #include "driver_i.h"
 #include "ctrl_iface.h"
-#include "ctrl_iface_dbus.h"
 #include "pcsc_funcs.h"
 #include "version.h"
 #include "preauth.h"
@@ -2218,7 +2217,7 @@ static void wpa_supplicant_deinit_iface(struct wpa_supplicant *wpa_s)
 		wpa_clear_keys(wpa_s, NULL);
 	}
 
-	wpas_notify_unregister_interface(wpa_s);
+	wpas_notify_iface_removed(wpa_s);
 
 	wpa_supplicant_cleanup(wpa_s);
 
@@ -2261,8 +2260,8 @@ struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global,
 
 	wpa_s->global = global;
 
-	/* Register the interface with the dbus control interface */
-	if (wpas_dbus_register_iface(wpa_s)) {
+	/* Notify the control interfaces about new iface */
+	if (wpas_notify_iface_added(wpa_s)) {
 		wpa_supplicant_deinit_iface(wpa_s);
 		os_free(wpa_s);
 		return NULL;
@@ -2404,13 +2403,9 @@ struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
 		return NULL;
 	}
 
-	if (global->params.dbus_ctrl_interface) {
-		global->dbus_ctrl_iface =
-			wpa_supplicant_dbus_ctrl_iface_init(global);
-		if (global->dbus_ctrl_iface == NULL) {
-			wpa_supplicant_deinit(global);
-			return NULL;
-		}
+	if (wpas_notify_supplicant_initialized(global)) {
+		wpa_supplicant_deinit(global);
+		return NULL;
 	}
 
 	for (i = 0; wpa_drivers[i]; i++)
@@ -2493,8 +2488,8 @@ void wpa_supplicant_deinit(struct wpa_global *global)
 
 	if (global->ctrl_iface)
 		wpa_supplicant_global_ctrl_iface_deinit(global->ctrl_iface);
-	if (global->dbus_ctrl_iface)
-		wpa_supplicant_dbus_ctrl_iface_deinit(global->dbus_ctrl_iface);
+
+	wpas_notify_supplicant_deinitialized(global);
 
 	eap_peer_unregister_methods();
 #ifdef CONFIG_AP
-- 
1.6.0.2



More information about the HostAP mailing list