Move hostapd configuration parser into separate file
[libeap.git] / hostapd / hostapd.c
index 0a33b09..fefe066 100644 (file)
@@ -127,7 +127,9 @@ int hostapd_reload_config(struct hostapd_iface *iface)
        struct wpa_auth_config wpa_auth_conf;
        size_t j;
 
-       newconf = hostapd_config_read(iface->config_fname);
+       if (iface->config_read_cb == NULL)
+               return -1;
+       newconf = iface->config_read_cb(iface->config_fname);
        if (newconf == NULL)
                return -1;
 
@@ -204,8 +206,8 @@ static void hostapd_broadcast_key_clear_iface(struct hostapd_data *hapd,
        int i;
 
        for (i = 0; i < NUM_WEP_KEYS; i++) {
-               if (hostapd_set_key(ifname, hapd, WPA_ALG_NONE, NULL, i,
-                                   i == 0 ? 1 : 0, NULL, 0, NULL, 0)) {
+               if (hapd->drv.set_key(ifname, hapd, WPA_ALG_NONE, NULL, i,
+                                     i == 0 ? 1 : 0, NULL, 0, NULL, 0)) {
                        wpa_printf(MSG_DEBUG, "Failed to clear default "
                                   "encryption keys (ifname=%s keyidx=%d)",
                                   ifname, i);
@@ -214,9 +216,9 @@ static void hostapd_broadcast_key_clear_iface(struct hostapd_data *hapd,
 #ifdef CONFIG_IEEE80211W
        if (hapd->conf->ieee80211w) {
                for (i = NUM_WEP_KEYS; i < NUM_WEP_KEYS + 2; i++) {
-                       if (hostapd_set_key(ifname, hapd, WPA_ALG_NONE, NULL,
-                                           i, i == 0 ? 1 : 0, NULL, 0,
-                                           NULL, 0)) {
+                       if (hapd->drv.set_key(ifname, hapd, WPA_ALG_NONE, NULL,
+                                             i, i == 0 ? 1 : 0, NULL, 0,
+                                             NULL, 0)) {
                                wpa_printf(MSG_DEBUG, "Failed to clear "
                                           "default mgmt encryption keys "
                                           "(ifname=%s keyidx=%d)", ifname, i);
@@ -241,9 +243,11 @@ static int hostapd_broadcast_wep_set(struct hostapd_data *hapd)
 
        idx = ssid->wep.idx;
        if (ssid->wep.default_len &&
-           hostapd_set_key(hapd->conf->iface,
-                           hapd, WPA_ALG_WEP, NULL, idx, idx == ssid->wep.idx,
-                           NULL, 0, ssid->wep.key[idx], ssid->wep.len[idx])) {
+           hapd->drv.set_key(hapd->conf->iface,
+                             hapd, WPA_ALG_WEP, NULL, idx,
+                             idx == ssid->wep.idx,
+                             NULL, 0, ssid->wep.key[idx],
+                             ssid->wep.len[idx])) {
                wpa_printf(MSG_WARNING, "Could not set WEP encryption.");
                errors++;
        }
@@ -261,9 +265,9 @@ static int hostapd_broadcast_wep_set(struct hostapd_data *hapd)
                                continue;
 
                        idx = key->idx;
-                       if (hostapd_set_key(ifname, hapd, WPA_ALG_WEP, NULL,
-                                           idx, idx == key->idx, NULL, 0,
-                                           key->key[idx], key->len[idx])) {
+                       if (hapd->drv.set_key(ifname, hapd, WPA_ALG_WEP, NULL,
+                                             idx, idx == key->idx, NULL, 0,
+                                             key->key[idx], key->len[idx])) {
                                wpa_printf(MSG_WARNING, "Could not set "
                                           "dynamic VLAN WEP encryption.");
                                errors++;
@@ -392,15 +396,17 @@ static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd)
 
        hostapd_broadcast_wep_set(hapd);
 
-       if (hapd->conf->ssid.wep.default_len)
+       if (hapd->conf->ssid.wep.default_len) {
+               hostapd_set_privacy(hapd, 1);
                return 0;
+       }
 
        for (i = 0; i < 4; i++) {
                if (hapd->conf->ssid.wep.key[i] &&
-                   hostapd_set_key(iface, hapd, WPA_ALG_WEP, NULL, i,
-                                   i == hapd->conf->ssid.wep.idx, NULL, 0,
-                                   hapd->conf->ssid.wep.key[i],
-                                   hapd->conf->ssid.wep.len[i])) {
+                   hapd->drv.set_key(iface, hapd, WPA_ALG_WEP, NULL, i,
+                                     i == hapd->conf->ssid.wep.idx, NULL, 0,
+                                     hapd->conf->ssid.wep.key[i],
+                                     hapd->conf->ssid.wep.len[i])) {
                        wpa_printf(MSG_WARNING, "Could not set WEP "
                                   "encryption.");
                        return -1;
@@ -472,20 +478,10 @@ static void hostapd_wpa_auth_disconnect(void *ctx, const u8 *addr,
                                        u16 reason)
 {
        struct hostapd_data *hapd = ctx;
-       struct sta_info *sta;
-
        wpa_printf(MSG_DEBUG, "%s: WPA authenticator requests disconnect: "
                   "STA " MACSTR " reason %d",
                   __func__, MAC2STR(addr), reason);
-
-       sta = ap_get_sta(hapd, addr);
-       hostapd_sta_deauth(hapd, addr, reason);
-       if (sta == NULL)
-               return;
-       sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_AUTHORIZED);
-       eloop_cancel_timeout(ap_handle_timer, hapd, sta);
-       eloop_register_timeout(0, 0, ap_handle_timer, hapd, sta);
-       sta->timeout_next = STA_REMOVE;
+       ap_sta_disconnect(hapd, NULL, addr, reason);
 }
 
 
@@ -602,8 +598,8 @@ static int hostapd_wpa_auth_set_key(void *ctx, int vlan_id, wpa_alg alg,
                        return -1;
        }
 
-       return hostapd_set_key(ifname, hapd, alg, addr, idx, 1, NULL, 0,
-                              key, key_len);
+       return hapd->drv.set_key(ifname, hapd, alg, addr, idx, 1, NULL, 0,
+                                key, key_len);
 }
 
 
@@ -620,7 +616,7 @@ static int hostapd_wpa_auth_send_eapol(void *ctx, const u8 *addr,
                                       int encrypt)
 {
        struct hostapd_data *hapd = ctx;
-       return hostapd_send_eapol(hapd, addr, data, data_len, encrypt);
+       return hapd->drv.send_eapol(hapd, addr, data, data_len, encrypt);
 }
 
 
@@ -660,10 +656,12 @@ static int hostapd_wpa_auth_for_each_auth(
        void *ctx, int (*cb)(struct wpa_authenticator *sm, void *ctx),
        void *cb_ctx)
 {
+       struct hostapd_data *hapd = ctx;
        struct wpa_auth_iface_iter_data data;
        data.cb = cb;
        data.cb_ctx = cb_ctx;
-       return hostapd_for_each_interface(wpa_auth_iface_iter, &data);
+       return hostapd_for_each_interface(hapd->iface->interfaces,
+                                         wpa_auth_iface_iter, &data);
 }
 
 
@@ -708,7 +706,7 @@ static int hostapd_wpa_auth_send_ft_action(void *ctx, const u8 *dst,
        os_memcpy(m->bssid, hapd->own_addr, ETH_ALEN);
        os_memcpy(&m->u, data, data_len);
 
-       res = hostapd_send_mgmt_frame(hapd, (u8 *) m, mlen);
+       res = hapd->drv.send_mgmt_frame(hapd, (u8 *) m, mlen);
        os_free(m);
        return res;
 }
@@ -1040,7 +1038,7 @@ 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->conf->iface, hapd->own_addr, hapd)) {
                        wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
                                   MACSTR ")", MAC2STR(hapd->own_addr));
                        return -1;
@@ -1382,6 +1380,7 @@ hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
        if (hapd == NULL)
                return NULL;
 
+       hostapd_set_driver_ops(&hapd->drv);
        hapd->iconf = conf;
        hapd->conf = bss;
        hapd->iface = hapd_iface;