Move hostapd driver initialization away from hostapd.c
authorJouni Malinen <j@w1.fi>
Fri, 25 Dec 2009 10:21:11 +0000 (12:21 +0200)
committerJouni Malinen <j@w1.fi>
Fri, 25 Dec 2009 10:21:11 +0000 (12:21 +0200)
This makes it easier to customize AP mode initialization for
wpa_supplicant.

hostapd/driver_i.h
hostapd/hostapd.c
hostapd/main.c
wpa_supplicant/ap.c

index 3d80ad7..64e8c90 100644 (file)
 #include "drivers/driver.h"
 #include "ap/config.h"
 
-static inline void *
-hostapd_driver_init(struct hostapd_data *hapd, const u8 *bssid)
-{
-       struct wpa_init_params params;
-       void *ret;
-       size_t i;
-
-       if (hapd->driver == NULL || hapd->driver->hapd_init == NULL)
-               return NULL;
-
-       os_memset(&params, 0, sizeof(params));
-       params.bssid = bssid;
-       params.ifname = hapd->conf->iface;
-       params.ssid = (const u8 *) hapd->conf->ssid.ssid;
-       params.ssid_len = hapd->conf->ssid.ssid_len;
-       params.test_socket = hapd->conf->test_socket;
-       params.use_pae_group_addr = hapd->conf->use_pae_group_addr;
-
-       params.num_bridge = hapd->iface->num_bss;
-       params.bridge = os_zalloc(hapd->iface->num_bss * sizeof(char *));
-       if (params.bridge == NULL)
-               return NULL;
-       for (i = 0; i < hapd->iface->num_bss; i++) {
-               struct hostapd_data *bss = hapd->iface->bss[i];
-               if (bss->conf->bridge[0])
-                       params.bridge[i] = bss->conf->bridge;
-       }
-
-       params.own_addr = hapd->own_addr;
-
-       ret = hapd->driver->hapd_init(hapd, &params);
-       os_free(params.bridge);
-
-       return ret;
-}
-
 static inline void
 hostapd_driver_deinit(struct hostapd_data *hapd)
 {
index 7a6ca41..6ce9240 100644 (file)
@@ -1199,26 +1199,14 @@ static void hostapd_tx_queue_params(struct hostapd_iface *iface)
 static int setup_interface(struct hostapd_iface *iface)
 {
        struct hostapd_data *hapd = iface->bss[0];
-       struct hostapd_bss_config *conf = hapd->conf;
        size_t i;
        char country[4];
-       u8 *b = conf->bssid;
 
        /*
-        * Initialize the driver interface and make sure that all BSSes get
-        * configured with a pointer to this driver interface.
+        * Make sure that all BSSes get configured with a pointer to the same
+        * driver interface.
         */
-       if (!(b[0] | b[1] | b[2] | b[3] | b[4] | b[5]))
-               b = NULL;
-       hapd->drv_priv = hostapd_driver_init(hapd, b);
-
-       if (hapd->drv_priv == NULL) {
-               wpa_printf(MSG_ERROR, "%s driver initialization failed.",
-                          hapd->driver ? hapd->driver->name : "Unknown");
-               hapd->driver = NULL;
-               return -1;
-       }
-       for (i = 0; i < iface->num_bss; i++) {
+       for (i = 1; i < iface->num_bss; i++) {
                iface->bss[i]->driver = hapd->driver;
                iface->bss[i]->drv_priv = hapd->drv_priv;
        }
index a08da3a..9fd6649 100644 (file)
@@ -21,6 +21,7 @@
 #include "eloop.h"
 #include "crypto/tls.h"
 #include "common/version.h"
+#include "drivers/driver.h"
 #include "eap_server/eap.h"
 #include "eap_server/tncs.h"
 #include "ap/hostapd.h"
@@ -224,6 +225,56 @@ fail:
 }
 
 
+static int hostapd_driver_init(struct hostapd_iface *iface)
+{
+       struct wpa_init_params params;
+       size_t i;
+       struct hostapd_data *hapd = iface->bss[0];
+       struct hostapd_bss_config *conf = hapd->conf;
+       u8 *b = conf->bssid;
+
+       if (hapd->driver == NULL || hapd->driver->hapd_init == NULL) {
+               wpa_printf(MSG_ERROR, "No hostapd driver wrapper available");
+               return -1;
+       }
+
+       /* Initialize the driver interface */
+       if (!(b[0] | b[1] | b[2] | b[3] | b[4] | b[5]))
+               b = NULL;
+
+       os_memset(&params, 0, sizeof(params));
+       params.bssid = b;
+       params.ifname = hapd->conf->iface;
+       params.ssid = (const u8 *) hapd->conf->ssid.ssid;
+       params.ssid_len = hapd->conf->ssid.ssid_len;
+       params.test_socket = hapd->conf->test_socket;
+       params.use_pae_group_addr = hapd->conf->use_pae_group_addr;
+
+       params.num_bridge = hapd->iface->num_bss;
+       params.bridge = os_zalloc(hapd->iface->num_bss * sizeof(char *));
+       if (params.bridge == NULL)
+               return -1;
+       for (i = 0; i < hapd->iface->num_bss; i++) {
+               struct hostapd_data *bss = hapd->iface->bss[i];
+               if (bss->conf->bridge[0])
+                       params.bridge[i] = bss->conf->bridge;
+       }
+
+       params.own_addr = hapd->own_addr;
+
+       hapd->drv_priv = hapd->driver->hapd_init(hapd, &params);
+       os_free(params.bridge);
+       if (hapd->drv_priv == NULL) {
+               wpa_printf(MSG_ERROR, "%s driver initialization failed.",
+                          hapd->driver->name);
+               hapd->driver = NULL;
+               return -1;
+       }
+
+       return 0;
+}
+
+
 static struct hostapd_iface *
 hostapd_interface_init(struct hapd_interfaces *interfaces,
                       const char *config_fname, int debug)
@@ -242,7 +293,8 @@ hostapd_interface_init(struct hapd_interfaces *interfaces,
                        iface->bss[0]->conf->logger_stdout_level--;
        }
 
-       if (hostapd_setup_interface(iface)) {
+       if (hostapd_driver_init(iface) ||
+           hostapd_setup_interface(iface)) {
                hostapd_interface_deinit(iface);
                return NULL;
        }
index 19a1aca..ce9c54c 100644 (file)
@@ -402,6 +402,40 @@ static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
 }
 
 
+static int hostapd_driver_init(struct hostapd_iface *iface)
+{
+       struct wpa_init_params params;
+       struct hostapd_data *hapd = iface->bss[0];
+
+       if (hapd->driver == NULL || hapd->driver->hapd_init == NULL) {
+               wpa_printf(MSG_ERROR, "No hostapd driver wrapper available");
+               return -1;
+       }
+
+       os_memset(&params, 0, sizeof(params));
+       params.ifname = hapd->conf->iface;
+       params.ssid = (const u8 *) hapd->conf->ssid.ssid;
+       params.ssid_len = hapd->conf->ssid.ssid_len;
+
+       params.num_bridge = hapd->iface->num_bss;
+       params.bridge = os_zalloc(hapd->iface->num_bss * sizeof(char *));
+       if (params.bridge == NULL)
+               return -1;
+       params.own_addr = hapd->own_addr;
+
+       hapd->drv_priv = hapd->driver->hapd_init(hapd, &params);
+       os_free(params.bridge);
+       if (hapd->drv_priv == NULL) {
+               wpa_printf(MSG_ERROR, "%s driver initialization failed.",
+                          hapd->driver->name);
+               hapd->driver = NULL;
+               return -1;
+       }
+
+       return 0;
+}
+
+
 int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
                             struct wpa_ssid *ssid)
 {
@@ -468,7 +502,8 @@ int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
                hapd_iface->bss[i]->msg_ctx = wpa_s;
        }
 
-       if (hostapd_setup_interface(wpa_s->ap_iface)) {
+       if (hostapd_driver_init(wpa_s->ap_iface) ||
+           hostapd_setup_interface(wpa_s->ap_iface)) {
                wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
                wpa_supplicant_ap_deinit(wpa_s);
                return -1;