[PATCH v2] wpa_supplicant: Denitialize the driver if the last user went away

Lubomir Rintel lkundrak
Thu Oct 30 01:24:50 PDT 2014


It might be that the underlying infrastrucutre went away and the state is no
longer valid. We ought to reinitialize it once a device appears again.

This is the case when the nl80211 devices disappear and cfg8011 is remoed
afterwards. The netlink handle is no longer valid (returns ENOENT) and a new
one needs to be open if it's loaded back.

Signed-off-by: Lubomir Rintel <lkundrak at v3.sk>
---
Changes since v1:
    - wpa_s->global_drv_priv unset moved to correct place
 wpa_supplicant/wpa_supplicant.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index 5a4d8dc..2099ef8 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -3925,6 +3925,25 @@ static int wpa_supplicant_init_iface(struct wpa_supplicant *wpa_s,
 	return 0;
 }
 
+/* Deinitialize the driver if we're the last user. */
+static void wpa_drv_cleanup(struct wpa_supplicant *wpa_s)
+{
+	struct wpa_global *global = wpa_s->global;
+	struct wpa_supplicant *iface;
+	int i;
+
+	for (iface = global->ifaces; iface; iface = iface->next)
+		if (iface != wpa_s && iface->driver == wpa_s->driver)
+			return;
+
+	for (i = 0; wpa_drivers[i]; i++)
+		if (global->drv_priv[i] == wpa_s->global_drv_priv)
+			global->drv_priv[i] = NULL;
+
+	if (wpa_s->driver->global_deinit)
+		wpa_s->driver->global_deinit (wpa_s->global_drv_priv);
+	wpa_s->global_drv_priv = NULL;
+}
 
 static void wpa_supplicant_deinit_iface(struct wpa_supplicant *wpa_s,
 					int notify, int terminate)
@@ -3967,6 +3986,8 @@ static void wpa_supplicant_deinit_iface(struct wpa_supplicant *wpa_s,
 	if (wpa_s->drv_priv)
 		wpa_drv_deinit(wpa_s);
 
+	wpa_drv_cleanup(wpa_s);
+
 	if (notify)
 		wpas_notify_iface_removed(wpa_s);
 
-- 
1.9.3




More information about the Hostap mailing list