hostapd: Call global_init/global_deinit driver_ops
authorJouni Malinen <j@w1.fi>
Sat, 22 Oct 2011 08:59:00 +0000 (11:59 +0300)
committerJouni Malinen <j@w1.fi>
Sat, 22 Oct 2011 09:22:59 +0000 (12:22 +0300)
Now both wpa_supplicant and hostapd allow the driver wrappers to use the
global context similarly.

hostapd/main.c
src/drivers/driver.h
src/drivers/driver_nl80211.c
src/drivers/driver_test.c

index 01ad826..d5a0fd7 100644 (file)
@@ -37,6 +37,16 @@ extern int wpa_debug_level;
 extern int wpa_debug_show_keys;
 extern int wpa_debug_timestamp;
 
+extern struct wpa_driver_ops *wpa_drivers[];
+
+
+struct hapd_global {
+       void **drv_priv;
+       size_t drv_count;
+};
+
+static struct hapd_global global;
+
 
 struct hapd_interfaces {
        size_t count;
@@ -246,6 +256,12 @@ static int hostapd_driver_init(struct hostapd_iface *iface)
                b = NULL;
 
        os_memset(&params, 0, sizeof(params));
+       for (i = 0; wpa_drivers[i]; i++) {
+               if (wpa_drivers[i] == hapd->driver) {
+                       params.global_priv = global.drv_priv[i];
+                       break;
+               }
+       }
        params.bssid = b;
        params.ifname = hapd->conf->iface;
        params.ssid = (const u8 *) hapd->conf->ssid.ssid;
@@ -372,6 +388,10 @@ static void handle_dump_state(int sig, void *signal_ctx)
 static int hostapd_global_init(struct hapd_interfaces *interfaces,
                               const char *entropy_file)
 {
+       int i;
+
+       os_memset(&global, 0, sizeof(global));
+
        hostapd_logger_register_cb(hostapd_logger_cb);
 
        if (eap_server_register_methods()) {
@@ -396,12 +416,42 @@ static int hostapd_global_init(struct hapd_interfaces *interfaces,
        openlog("hostapd", 0, LOG_DAEMON);
 #endif /* CONFIG_NATIVE_WINDOWS */
 
+       for (i = 0; wpa_drivers[i]; i++)
+               global.drv_count++;
+       if (global.drv_count == 0) {
+               wpa_printf(MSG_ERROR, "No drivers enabled");
+               return -1;
+       }
+       global.drv_priv = os_zalloc(global.drv_count * sizeof(void *));
+       if (global.drv_priv == NULL)
+               return -1;
+       for (i = 0; wpa_drivers[i]; i++) {
+               if (!wpa_drivers[i]->global_init)
+                       continue;
+               global.drv_priv[i] = wpa_drivers[i]->global_init();
+               if (global.drv_priv[i] == NULL) {
+                       wpa_printf(MSG_ERROR, "Failed to initialize driver "
+                                  "'%s'", wpa_drivers[i]->name);
+                       return -1;
+               }
+       }
+
        return 0;
 }
 
 
 static void hostapd_global_deinit(const char *pid_file)
 {
+       int i;
+
+       for (i = 0; wpa_drivers[i] && global.drv_priv; i++) {
+               if (!global.drv_priv[i])
+                       continue;
+               wpa_drivers[i]->global_deinit(global.drv_priv[i]);
+       }
+       os_free(global.drv_priv);
+       global.drv_priv = NULL;
+
 #ifdef EAP_SERVER_TNC
        tncs_global_deinit();
 #endif /* EAP_SERVER_TNC */
index 2a926e5..ba24f1d 100644 (file)
@@ -837,6 +837,7 @@ enum wpa_driver_if_type {
 };
 
 struct wpa_init_params {
+       void *global_priv;
        const u8 *bssid;
        const char *ifname;
        const u8 *ssid;
index d77854e..08e6025 100644 (file)
@@ -6377,7 +6377,8 @@ static void *i802_init(struct hostapd_data *hapd,
        int ifindex, br_ifindex;
        int br_added = 0;
 
-       bss = wpa_driver_nl80211_init(hapd, params->ifname, NULL);
+       bss = wpa_driver_nl80211_init(hapd, params->ifname,
+                                     params->global_priv);
        if (bss == NULL)
                return NULL;
 
index a34cc54..8c86685 100644 (file)
@@ -1232,6 +1232,7 @@ static void * test_driver_init(struct hostapd_data *hapd,
                return NULL;
        drv->ap = 1;
        bss = dl_list_first(&drv->bss, struct test_driver_bss, list);
+       drv->global = params->global_priv;
 
        bss->bss_ctx = hapd;
        os_memcpy(bss->bssid, drv->own_addr, ETH_ALEN);