[PATCH 1/5] driver::global_init now takes a pointer to wpa_global wpa_supplicant now stores a pointer from global_init in drv_global which is passed as the third parameter to init2 instead of a pointer to wpa_global.

Roy Marples roy at marples.name
Tue May 26 17:25:14 EDT 2009


This allows drivers to reference the global data for the driver which
in turn can reference the global wpa data.

Signed-off-by: Roy Marples <roy at marples.name>
---
 src/drivers/driver.h              |    3 ++-
 src/drivers/driver_test.c         |    4 +++-
 wpa_supplicant/driver_i.h         |    2 +-
 wpa_supplicant/wpa_supplicant.c   |    8 +++++---
 wpa_supplicant/wpa_supplicant_i.h |    1 +
 5 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/drivers/driver.h b/src/drivers/driver.h
index 943d61c..30bc72e 100644
--- a/src/drivers/driver.h
+++ b/src/drivers/driver.h
@@ -1128,6 +1128,7 @@ struct wpa_driver_ops {
 
 	/**
 	 * global_init - Global driver initialization
+	 * @priv: private pointer to wpa_global
 	 * Returns: Pointer to private data (global), %NULL on failure
 	 *
 	 * This optional function is called to initialize the driver wrapper
@@ -1137,7 +1138,7 @@ struct wpa_driver_ops {
 	 * use init2() function instead of init() to get the pointer to global
 	 * data available to per-interface initializer.
 	 */
-	void * (*global_init)(void);
+	void * (*global_init)(void *priv);
 
 	/**
 	 * global_deinit - Global driver deinitialization
diff --git a/src/drivers/driver_test.c b/src/drivers/driver_test.c
index dbb0edb..11d2a14 100644
--- a/src/drivers/driver_test.c
+++ b/src/drivers/driver_test.c
@@ -79,6 +79,7 @@ struct test_driver_data {
 #else /* HOSTAPD */
 
 struct wpa_driver_test_global {
+	void *global; /* Pointer to wpa_global */
 	int dummy;
 };
 
@@ -2328,11 +2329,12 @@ static int wpa_driver_test_set_probe_req_ie(void *priv, const u8 *ies,
 }
 
 
-static void * wpa_driver_test_global_init(void)
+static void * wpa_driver_test_global_init(void *priv)
 {
 	struct wpa_driver_test_global *global;
 
 	global = os_zalloc(sizeof(*global));
+	global->global = priv;
 	return global;
 }
 
diff --git a/wpa_supplicant/driver_i.h b/wpa_supplicant/driver_i.h
index 4cb5372..0d748d0 100644
--- a/wpa_supplicant/driver_i.h
+++ b/wpa_supplicant/driver_i.h
@@ -22,7 +22,7 @@ static inline void * wpa_drv_init(struct wpa_supplicant *wpa_s,
 				  const char *ifname)
 {
 	if (wpa_s->driver->init2)
-		return wpa_s->driver->init2(wpa_s, ifname, wpa_s->global);
+		return wpa_s->driver->init2(wpa_s, ifname, wpa_s->drv_global);
 	if (wpa_s->driver->init) {
 		return wpa_s->driver->init(wpa_s, ifname);
 	}
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index 723e2ed..8cb3d8a 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -1541,6 +1541,7 @@ static int wpa_supplicant_set_driver(struct wpa_supplicant *wpa_s,
 	if (name == NULL) {
 		/* default to first driver in the list */
 		wpa_s->driver = wpa_drivers[0];
+		wpa_s->drv_global = wpa_s->global->drv_priv[0];
 		return 0;
 	}
 
@@ -1554,6 +1555,7 @@ static int wpa_supplicant_set_driver(struct wpa_supplicant *wpa_s,
 		    os_strncmp(name, wpa_drivers[i]->name, len) ==
 		    0) {
 			wpa_s->driver = wpa_drivers[i];
+			wpa_s->drv_global = wpa_s->global->drv_priv[i];
 			return 0;
 		}
 	}
@@ -2007,6 +2009,8 @@ struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global,
 	if (wpa_s == NULL)
 		return NULL;
 
+	wpa_s->global = global;
+
 	if (wpa_supplicant_init_iface(wpa_s, iface)) {
 		wpa_printf(MSG_DEBUG, "Failed to add interface %s",
 			   iface->ifname);
@@ -2015,8 +2019,6 @@ struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global,
 		return NULL;
 	}
 
-	wpa_s->global = global;
-
 	/* Register the interface with the dbus control interface */
 	if (wpas_dbus_register_iface(wpa_s)) {
 		wpa_supplicant_deinit_iface(wpa_s);
@@ -2184,7 +2186,7 @@ struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
 	for (i = 0; wpa_drivers[i]; i++) {
 		if (!wpa_drivers[i]->global_init)
 			continue;
-		global->drv_priv[i] = wpa_drivers[i]->global_init();
+		global->drv_priv[i] = wpa_drivers[i]->global_init(global);
 		if (global->drv_priv[i] == NULL) {
 			wpa_printf(MSG_ERROR, "Failed to initialize driver "
 				   "'%s'", wpa_drivers[i]->name);
diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h
index 8d131fc..25e5ab2 100644
--- a/wpa_supplicant/wpa_supplicant_i.h
+++ b/wpa_supplicant/wpa_supplicant_i.h
@@ -309,6 +309,7 @@ struct wpa_supplicant {
 	int mgmt_group_cipher;
 
 	void *drv_priv; /* private data used by driver_ops */
+	void *drv_global; /* private global data used by driver_ops */
 
 	struct wpa_ssid *prev_scan_ssid; /* previously scanned SSID;
 					  * NULL = not yet initialized (start
-- 
1.6.2.5



More information about the HostAP mailing list