Simplify driver_ops for virtual interface add/remove
[libeap.git] / src / ap / hostapd.c
index e6151d5..35ac468 100644 (file)
@@ -18,6 +18,7 @@
 #include "utils/eloop.h"
 #include "common/ieee802_11_defs.h"
 #include "radius/radius_client.h"
+#include "drivers/driver.h"
 #include "hostapd.h"
 #include "authsrv.h"
 #include "sta_info.h"
@@ -31,9 +32,9 @@
 #include "wpa_auth.h"
 #include "wps_hostapd.h"
 #include "hw_features.h"
-#include "driver_i.h"
 #include "wpa_auth_glue.h"
 #include "ap_drv_ops.h"
+#include "ap_config.h"
 
 
 static int hostapd_flush_old_stations(struct hostapd_data *hapd);
@@ -79,13 +80,20 @@ int hostapd_reload_config(struct hostapd_iface *iface)
 
        if (hapd->conf->wpa && hapd->wpa_auth == NULL)
                hostapd_setup_wpa(hapd);
-       else if (hapd->conf->wpa)
+       else if (hapd->conf->wpa) {
+               const u8 *wpa_ie;
+               size_t wpa_ie_len;
                hostapd_reconfig_wpa(hapd);
-       else if (hapd->wpa_auth) {
+               wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
+               if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len))
+                       wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
+                                  "the kernel driver.");
+       } else if (hapd->wpa_auth) {
                wpa_deinit(hapd->wpa_auth);
                hapd->wpa_auth = NULL;
                hostapd_set_privacy(hapd, 0);
                hostapd_setup_encryption(hapd->conf->iface, hapd);
+               hostapd_set_generic_elem(hapd, (u8 *) "", 0);
        }
 
        ieee802_11_set_beacon(hapd);
@@ -298,7 +306,7 @@ static int hostapd_flush_old_stations(struct hostapd_data *hapd)
 {
        int ret = 0;
 
-       if (hostapd_drv_none(hapd))
+       if (hostapd_drv_none(hapd) || hapd->drv_priv == NULL)
                return 0;
 
        wpa_printf(MSG_DEBUG, "Flushing old station entries");
@@ -460,6 +468,8 @@ static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
        struct hostapd_bss_config *conf = hapd->conf;
        u8 ssid[HOSTAPD_MAX_SSID_LEN + 1];
        int ssid_len, set_ssid;
+       char force_ifname[IFNAMSIZ];
+       u8 if_addr[ETH_ALEN];
 
        if (!first) {
                if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0) {
@@ -483,7 +493,8 @@ static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
 
                hapd->interface_added = 1;
                if (hostapd_if_add(hapd->iface->bss[0], WPA_IF_AP_BSS,
-                                  hapd->conf->iface, hapd->own_addr, hapd)) {
+                                  hapd->conf->iface, hapd->own_addr, hapd,
+                                  &hapd->drv_priv, force_ifname, if_addr)) {
                        wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
                                   MACSTR ")", MAC2STR(hapd->own_addr));
                        return -1;
@@ -563,6 +574,9 @@ static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
        if (hostapd_init_wps(hapd, conf))
                return -1;
 
+       if (authsrv_init(hapd) < 0)
+               return -1;
+
        if (ieee802_1x_init(hapd)) {
                wpa_printf(MSG_ERROR, "IEEE 802.1X initialization failed.");
                return -1;
@@ -596,9 +610,6 @@ static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
 
        ieee802_11_set_beacon(hapd);
 
-       if (authsrv_init(hapd) < 0)
-               return -1;
-
        return 0;
 }
 
@@ -821,6 +832,12 @@ void hostapd_interface_deinit(struct hostapd_iface *iface)
                hostapd_flush_old_stations(hapd);
                hostapd_cleanup(hapd);
        }
+}
+
+
+void hostapd_interface_free(struct hostapd_iface *iface)
+{
+       size_t j;
        for (j = 0; j < iface->num_bss; j++)
                os_free(iface->bss[j]);
        hostapd_cleanup_iface(iface);