]> git.ipfire.org Git - thirdparty/hostap.git/blobdiff - src/ap/wpa_auth_glue.c
Add testing functionality for resetting PN/IPN for configured keys
[thirdparty/hostap.git] / src / ap / wpa_auth_glue.c
index 8592b90b2d176a71ccb4378c0e6477f4ec3a76cd..d9f917e4a528eafffd478ac73a31d9e56a08a246 100644 (file)
@@ -9,12 +9,17 @@
 #include "utils/includes.h"
 
 #include "utils/common.h"
+#include "utils/eloop.h"
+#include "utils/list.h"
 #include "common/ieee802_11_defs.h"
 #include "common/sae.h"
+#include "common/wpa_ctrl.h"
+#include "crypto/sha1.h"
 #include "eapol_auth/eapol_auth_sm.h"
 #include "eapol_auth/eapol_auth_sm_i.h"
 #include "eap_server/eap.h"
 #include "l2_packet/l2_packet.h"
+#include "eth_p_oui.h"
 #include "hostapd.h"
 #include "ieee802_1x.h"
 #include "preauth_auth.h"
@@ -22,6 +27,7 @@
 #include "tkip_countermeasures.h"
 #include "ap_drv_ops.h"
 #include "ap_config.h"
+#include "pmksa_cache_auth.h"
 #include "wpa_auth.h"
 #include "wpa_auth_glue.h"
 
@@ -39,10 +45,11 @@ static void hostapd_wpa_auth_conf(struct hostapd_bss_config *conf,
        wconf->wpa_strict_rekey = conf->wpa_strict_rekey;
        wconf->wpa_gmk_rekey = conf->wpa_gmk_rekey;
        wconf->wpa_ptk_rekey = conf->wpa_ptk_rekey;
+       wconf->wpa_group_update_count = conf->wpa_group_update_count;
+       wconf->wpa_pairwise_update_count = conf->wpa_pairwise_update_count;
        wconf->rsn_pairwise = conf->rsn_pairwise;
        wconf->rsn_preauth = conf->rsn_preauth;
        wconf->eapol_version = conf->eapol_version;
-       wconf->peerkey = conf->peerkey;
        wconf->wmm_enabled = conf->wmm_enabled;
        wconf->wmm_uapsd = conf->wmm_uapsd;
        wconf->disable_pmksa_caching = conf->disable_pmksa_caching;
@@ -51,10 +58,10 @@ static void hostapd_wpa_auth_conf(struct hostapd_bss_config *conf,
        wconf->ieee80211w = conf->ieee80211w;
        wconf->group_mgmt_cipher = conf->group_mgmt_cipher;
 #endif /* CONFIG_IEEE80211W */
-#ifdef CONFIG_IEEE80211R
+#ifdef CONFIG_IEEE80211R_AP
        wconf->ssid_len = conf->ssid.ssid_len;
-       if (wconf->ssid_len > SSID_LEN)
-               wconf->ssid_len = SSID_LEN;
+       if (wconf->ssid_len > SSID_MAX_LEN)
+               wconf->ssid_len = SSID_MAX_LEN;
        os_memcpy(wconf->ssid, conf->ssid.ssid, wconf->ssid_len);
        os_memcpy(wconf->mobility_domain, conf->mobility_domain,
                  MOBILITY_DOMAIN_ID_LEN);
@@ -67,11 +74,16 @@ static void hostapd_wpa_auth_conf(struct hostapd_bss_config *conf,
        os_memcpy(wconf->r1_key_holder, conf->r1_key_holder, FT_R1KH_ID_LEN);
        wconf->r0_key_lifetime = conf->r0_key_lifetime;
        wconf->reassociation_deadline = conf->reassociation_deadline;
-       wconf->r0kh_list = conf->r0kh_list;
-       wconf->r1kh_list = conf->r1kh_list;
+       wconf->rkh_pos_timeout = conf->rkh_pos_timeout;
+       wconf->rkh_neg_timeout = conf->rkh_neg_timeout;
+       wconf->rkh_pull_timeout = conf->rkh_pull_timeout;
+       wconf->rkh_pull_retries = conf->rkh_pull_retries;
+       wconf->r0kh_list = &conf->r0kh_list;
+       wconf->r1kh_list = &conf->r1kh_list;
        wconf->pmk_r1_push = conf->pmk_r1_push;
        wconf->ft_over_ds = conf->ft_over_ds;
-#endif /* CONFIG_IEEE80211R */
+       wconf->ft_psk_generate_local = conf->ft_psk_generate_local;
+#endif /* CONFIG_IEEE80211R_AP */
 #ifdef CONFIG_HS20
        wconf->disable_gtk = conf->disable_dgaf;
        if (conf->osen) {
@@ -91,6 +103,13 @@ static void hostapd_wpa_auth_conf(struct hostapd_bss_config *conf,
 #ifdef CONFIG_TESTING_OPTIONS
        wconf->corrupt_gtk_rekey_mic_probability =
                iconf->corrupt_gtk_rekey_mic_probability;
+       if (conf->own_ie_override &&
+           wpabuf_len(conf->own_ie_override) <= MAX_OWN_IE_OVERRIDE) {
+               wconf->own_ie_override_len = wpabuf_len(conf->own_ie_override);
+               os_memcpy(wconf->own_ie_override,
+                         wpabuf_head(conf->own_ie_override),
+                         wconf->own_ie_override_len);
+       }
 #endif /* CONFIG_TESTING_OPTIONS */
 #ifdef CONFIG_P2P
        os_memcpy(wconf->ip_addr_go, conf->ip_addr_go, 4);
@@ -98,6 +117,11 @@ static void hostapd_wpa_auth_conf(struct hostapd_bss_config *conf,
        os_memcpy(wconf->ip_addr_start, conf->ip_addr_start, 4);
        os_memcpy(wconf->ip_addr_end, conf->ip_addr_end, 4);
 #endif /* CONFIG_P2P */
+#ifdef CONFIG_FILS
+       wconf->fils_cache_id_set = conf->fils_cache_id_set;
+       os_memcpy(wconf->fils_cache_id, conf->fils_cache_id,
+                 FILS_CACHE_ID_LEN);
+#endif /* CONFIG_FILS */
 }
 
 
@@ -144,6 +168,14 @@ static int hostapd_wpa_auth_mic_failure_report(void *ctx, const u8 *addr)
 }
 
 
+static void hostapd_wpa_auth_psk_failure_report(void *ctx, const u8 *addr)
+{
+       struct hostapd_data *hapd = ctx;
+       wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
+               MAC2STR(addr));
+}
+
+
 static void hostapd_wpa_auth_set_eapol(void *ctx, const u8 *addr,
                                       wpa_eapol_variable var, int value)
 {
@@ -206,20 +238,47 @@ static int hostapd_wpa_auth_get_eapol(void *ctx, const u8 *addr,
 
 static const u8 * hostapd_wpa_auth_get_psk(void *ctx, const u8 *addr,
                                           const u8 *p2p_dev_addr,
-                                          const u8 *prev_psk)
+                                          const u8 *prev_psk, size_t *psk_len)
 {
        struct hostapd_data *hapd = ctx;
        struct sta_info *sta = ap_get_sta(hapd, addr);
        const u8 *psk;
 
+       if (psk_len)
+               *psk_len = PMK_LEN;
+
 #ifdef CONFIG_SAE
        if (sta && sta->auth_alg == WLAN_AUTH_SAE) {
                if (!sta->sae || prev_psk)
                        return NULL;
                return sta->sae->pmk;
        }
+       if (sta && wpa_auth_uses_sae(sta->wpa_sm)) {
+               wpa_printf(MSG_DEBUG,
+                          "No PSK for STA trying to use SAE with PMKSA caching");
+               return NULL;
+       }
 #endif /* CONFIG_SAE */
 
+#ifdef CONFIG_OWE
+       if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
+           sta && sta->owe_pmk) {
+               if (psk_len)
+                       *psk_len = sta->owe_pmk_len;
+               return sta->owe_pmk;
+       }
+       if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) && sta) {
+               struct rsn_pmksa_cache_entry *sa;
+
+               sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
+               if (sa && sa->akmp == WPA_KEY_MGMT_OWE) {
+                       if (psk_len)
+                               *psk_len = sa->pmk_len;
+                       return sa->pmk;
+               }
+       }
+#endif /* CONFIG_OWE */
+
        psk = hostapd_get_psk(hapd->conf, addr, p2p_dev_addr, prev_psk);
        /*
         * This is about to iterate over all psks, prev_psk gives the last
@@ -230,6 +289,13 @@ static const u8 * hostapd_wpa_auth_get_psk(void *ctx, const u8 *addr,
                struct hostapd_sta_wpa_psk_short *pos;
                psk = sta->psk->psk;
                for (pos = sta->psk; pos; pos = pos->next) {
+                       if (pos->is_passphrase) {
+                               pbkdf2_sha1(pos->passphrase,
+                                           hapd->conf->ssid.ssid,
+                                           hapd->conf->ssid.ssid_len, 4096,
+                                           pos->psk, PMK_LEN);
+                               pos->is_passphrase = 0;
+                       }
                        if (pos->psk == prev_psk) {
                                psk = pos->next ? pos->next->psk : NULL;
                                break;
@@ -249,12 +315,17 @@ static int hostapd_wpa_auth_get_msk(void *ctx, const u8 *addr, u8 *msk,
        struct sta_info *sta;
 
        sta = ap_get_sta(hapd, addr);
-       if (sta == NULL)
+       if (sta == NULL) {
+               wpa_printf(MSG_DEBUG, "AUTH_GET_MSK: Cannot find STA");
                return -1;
+       }
 
        key = ieee802_1x_get_key(sta->eapol_sm, &keylen);
-       if (key == NULL)
+       if (key == NULL) {
+               wpa_printf(MSG_DEBUG, "AUTH_GET_MSK: Key is null, eapol_sm: %p",
+                          sta->eapol_sm);
                return -1;
+       }
 
        if (keylen > *len)
                keylen = *len;
@@ -278,6 +349,37 @@ static int hostapd_wpa_auth_set_key(void *ctx, int vlan_id, enum wpa_alg alg,
                        return -1;
        }
 
+#ifdef CONFIG_TESTING_OPTIONS
+       if (addr && !is_broadcast_ether_addr(addr)) {
+               struct sta_info *sta;
+
+               sta = ap_get_sta(hapd, addr);
+               if (sta) {
+                       sta->last_tk_alg = alg;
+                       sta->last_tk_key_idx = idx;
+                       if (key)
+                               os_memcpy(sta->last_tk, key, key_len);
+                       sta->last_tk_len = key_len;
+               }
+#ifdef CONFIG_IEEE80211W
+       } else if (alg == WPA_CIPHER_AES_128_CMAC ||
+                  alg == WPA_CIPHER_BIP_GMAC_128 ||
+                  alg == WPA_CIPHER_BIP_GMAC_256 ||
+                  alg == WPA_CIPHER_BIP_CMAC_256) {
+               hapd->last_igtk_alg = alg;
+               hapd->last_igtk_key_idx = idx;
+               if (key)
+                       os_memcpy(hapd->last_igtk, key, key_len);
+               hapd->last_igtk_len = key_len;
+#endif /* CONFIG_IEEE80211W */
+       } else {
+               hapd->last_gtk_alg = alg;
+               hapd->last_gtk_key_idx = idx;
+               if (key)
+                       os_memcpy(hapd->last_gtk, key, key_len);
+               hapd->last_gtk_len = key_len;
+       }
+#endif /* CONFIG_TESTING_OPTIONS */
        return hostapd_drv_set_key(ifname, hapd, alg, addr, idx, 1, NULL, 0,
                                   key, key_len);
 }
@@ -372,7 +474,32 @@ static int hostapd_wpa_auth_for_each_auth(
 }
 
 
-#ifdef CONFIG_IEEE80211R
+#ifdef CONFIG_IEEE80211R_AP
+
+struct wpa_ft_rrb_rx_later_data {
+       struct dl_list list;
+       u8 addr[ETH_ALEN];
+       size_t data_len;
+       /* followed by data_len octets of data */
+};
+
+static void hostapd_wpa_ft_rrb_rx_later(void *eloop_ctx, void *timeout_ctx)
+{
+       struct hostapd_data *hapd = eloop_ctx;
+       struct wpa_ft_rrb_rx_later_data *data, *n;
+
+       dl_list_for_each_safe(data, n, &hapd->l2_queue,
+                             struct wpa_ft_rrb_rx_later_data, list) {
+               if (hapd->wpa_auth) {
+                       wpa_ft_rrb_rx(hapd->wpa_auth, data->addr,
+                                     (const u8 *) (data + 1),
+                                     data->data_len);
+               }
+               dl_list_del(&data->list);
+               os_free(data);
+       }
+}
+
 
 struct wpa_auth_ft_iface_iter_data {
        struct hostapd_data *src_hapd;
@@ -385,31 +512,54 @@ struct wpa_auth_ft_iface_iter_data {
 static int hostapd_wpa_auth_ft_iter(struct hostapd_iface *iface, void *ctx)
 {
        struct wpa_auth_ft_iface_iter_data *idata = ctx;
+       struct wpa_ft_rrb_rx_later_data *data;
        struct hostapd_data *hapd;
        size_t j;
 
        for (j = 0; j < iface->num_bss; j++) {
                hapd = iface->bss[j];
-               if (hapd == idata->src_hapd)
+               if (hapd == idata->src_hapd ||
+                   !hapd->wpa_auth ||
+                   os_memcmp(hapd->own_addr, idata->dst, ETH_ALEN) != 0)
                        continue;
-               if (os_memcmp(hapd->own_addr, idata->dst, ETH_ALEN) == 0) {
-                       wpa_printf(MSG_DEBUG, "FT: Send RRB data directly to "
-                                  "locally managed BSS " MACSTR "@%s -> "
-                                  MACSTR "@%s",
-                                  MAC2STR(idata->src_hapd->own_addr),
-                                  idata->src_hapd->conf->iface,
-                                  MAC2STR(hapd->own_addr), hapd->conf->iface);
-                       wpa_ft_rrb_rx(hapd->wpa_auth,
-                                     idata->src_hapd->own_addr,
-                                     idata->data, idata->data_len);
+
+               wpa_printf(MSG_DEBUG,
+                          "FT: Send RRB data directly to locally managed BSS "
+                          MACSTR "@%s -> " MACSTR "@%s",
+                          MAC2STR(idata->src_hapd->own_addr),
+                          idata->src_hapd->conf->iface,
+                          MAC2STR(hapd->own_addr), hapd->conf->iface);
+
+               /* Defer wpa_ft_rrb_rx() until next eloop step as this is
+                * when it would be triggered when reading from a socket.
+                * This avoids
+                * hapd0:send -> hapd1:recv -> hapd1:send -> hapd0:recv,
+                * that is calling hapd0:recv handler from within
+                * hapd0:send directly.
+                */
+               data = os_zalloc(sizeof(*data) + idata->data_len);
+               if (!data)
                        return 1;
-               }
+
+               os_memcpy(data->addr, idata->src_hapd->own_addr, ETH_ALEN);
+               os_memcpy(data + 1, idata->data, idata->data_len);
+               data->data_len = idata->data_len;
+
+               dl_list_add(&hapd->l2_queue, &data->list);
+
+               if (!eloop_is_timeout_registered(hostapd_wpa_ft_rrb_rx_later,
+                                                hapd, NULL))
+                       eloop_register_timeout(0, 0,
+                                              hostapd_wpa_ft_rrb_rx_later,
+                                              hapd, NULL);
+
+               return 1;
        }
 
        return 0;
 }
 
-#endif /* CONFIG_IEEE80211R */
+#endif /* CONFIG_IEEE80211R_AP */
 
 
 static int hostapd_wpa_auth_send_ether(void *ctx, const u8 *dst, u16 proto,
@@ -434,7 +584,7 @@ static int hostapd_wpa_auth_send_ether(void *ctx, const u8 *dst, u16 proto,
        }
 #endif /* CONFIG_TESTING_OPTIONS */
 
-#ifdef CONFIG_IEEE80211R
+#ifdef CONFIG_IEEE80211R_AP
        if (proto == ETH_P_RRB && hapd->iface->interfaces &&
            hapd->iface->interfaces->for_each_interface) {
                int res;
@@ -449,7 +599,7 @@ static int hostapd_wpa_auth_send_ether(void *ctx, const u8 *dst, u16 proto,
                if (res == 1)
                        return data_len;
        }
-#endif /* CONFIG_IEEE80211R */
+#endif /* CONFIG_IEEE80211R_AP */
 
        if (hapd->driver && hapd->driver->send_ether)
                return hapd->driver->send_ether(hapd->drv_priv, dst,
@@ -472,7 +622,157 @@ static int hostapd_wpa_auth_send_ether(void *ctx, const u8 *dst, u16 proto,
 }
 
 
-#ifdef CONFIG_IEEE80211R
+#ifdef CONFIG_ETH_P_OUI
+static struct eth_p_oui_ctx * hostapd_wpa_get_oui(struct hostapd_data *hapd,
+                                                 u8 oui_suffix)
+{
+       switch (oui_suffix) {
+#ifdef CONFIG_IEEE80211R_AP
+       case FT_PACKET_R0KH_R1KH_PULL:
+               return hapd->oui_pull;
+       case FT_PACKET_R0KH_R1KH_RESP:
+               return hapd->oui_resp;
+       case FT_PACKET_R0KH_R1KH_PUSH:
+               return hapd->oui_push;
+       case FT_PACKET_R0KH_R1KH_SEQ_REQ:
+               return hapd->oui_sreq;
+       case FT_PACKET_R0KH_R1KH_SEQ_RESP:
+               return hapd->oui_sresp;
+#endif /* CONFIG_IEEE80211R_AP */
+       default:
+               return NULL;
+       }
+}
+#endif /* CONFIG_ETH_P_OUI */
+
+
+#ifdef CONFIG_IEEE80211R_AP
+
+struct oui_deliver_later_data {
+       struct dl_list list;
+       u8 src_addr[ETH_ALEN];
+       u8 dst_addr[ETH_ALEN];
+       size_t data_len;
+       u8 oui_suffix;
+       /* followed by data_len octets of data */
+};
+
+static void hostapd_oui_deliver_later(void *eloop_ctx, void *timeout_ctx)
+{
+       struct hostapd_data *hapd = eloop_ctx;
+       struct oui_deliver_later_data *data, *n;
+       struct eth_p_oui_ctx *oui_ctx;
+
+       dl_list_for_each_safe(data, n, &hapd->l2_oui_queue,
+                             struct oui_deliver_later_data, list) {
+               oui_ctx = hostapd_wpa_get_oui(hapd, data->oui_suffix);
+               if (hapd->wpa_auth && oui_ctx) {
+                       eth_p_oui_deliver(oui_ctx, data->src_addr,
+                                         data->dst_addr,
+                                         (const u8 *) (data + 1),
+                                         data->data_len);
+               }
+               dl_list_del(&data->list);
+               os_free(data);
+       }
+}
+
+
+struct wpa_auth_oui_iface_iter_data {
+       struct hostapd_data *src_hapd;
+       const u8 *dst_addr;
+       const u8 *data;
+       size_t data_len;
+       u8 oui_suffix;
+};
+
+static int hostapd_wpa_auth_oui_iter(struct hostapd_iface *iface, void *ctx)
+{
+       struct wpa_auth_oui_iface_iter_data *idata = ctx;
+       struct oui_deliver_later_data *data;
+       struct hostapd_data *hapd;
+       size_t j;
+
+       for (j = 0; j < iface->num_bss; j++) {
+               hapd = iface->bss[j];
+               if (hapd == idata->src_hapd)
+                       continue;
+               if (!is_multicast_ether_addr(idata->dst_addr) &&
+                   os_memcmp(hapd->own_addr, idata->dst_addr, ETH_ALEN) != 0)
+                       continue;
+
+               /* defer eth_p_oui_deliver until next eloop step as this is
+                * when it would be triggerd from reading from sock
+                * This avoids
+                * hapd0:send -> hapd1:recv -> hapd1:send -> hapd0:recv,
+                * that is calling hapd0:recv handler from within
+                * hapd0:send directly.
+                */
+               data = os_zalloc(sizeof(*data) + idata->data_len);
+               if (!data)
+                       return 1;
+
+               os_memcpy(data->src_addr, idata->src_hapd->own_addr, ETH_ALEN);
+               os_memcpy(data->dst_addr, idata->dst_addr, ETH_ALEN);
+               os_memcpy(data + 1, idata->data, idata->data_len);
+               data->data_len = idata->data_len;
+               data->oui_suffix = idata->oui_suffix;
+
+               dl_list_add(&hapd->l2_oui_queue, &data->list);
+
+               if (!eloop_is_timeout_registered(hostapd_oui_deliver_later,
+                                                hapd, NULL))
+                       eloop_register_timeout(0, 0,
+                                              hostapd_oui_deliver_later,
+                                              hapd, NULL);
+
+               return 1;
+       }
+
+       return 0;
+}
+
+#endif /* CONFIG_IEEE80211R_AP */
+
+
+static int hostapd_wpa_auth_send_oui(void *ctx, const u8 *dst, u8 oui_suffix,
+                                    const u8 *data, size_t data_len)
+{
+#ifdef CONFIG_ETH_P_OUI
+       struct hostapd_data *hapd = ctx;
+       struct eth_p_oui_ctx *oui_ctx;
+
+#ifdef CONFIG_IEEE80211R_AP
+       if (hapd->iface->interfaces &&
+           hapd->iface->interfaces->for_each_interface) {
+               struct wpa_auth_oui_iface_iter_data idata;
+               int res;
+
+               idata.src_hapd = hapd;
+               idata.dst_addr = dst;
+               idata.data = data;
+               idata.data_len = data_len;
+               idata.oui_suffix = oui_suffix;
+               res = hapd->iface->interfaces->for_each_interface(
+                       hapd->iface->interfaces, hostapd_wpa_auth_oui_iter,
+                       &idata);
+               if (res == 1)
+                       return data_len;
+       }
+#endif /* CONFIG_IEEE80211R_AP */
+
+       oui_ctx = hostapd_wpa_get_oui(hapd, oui_suffix);
+       if (!oui_ctx)
+               return -1;
+
+       return eth_p_oui_send(oui_ctx, hapd->own_addr, dst, data, data_len);
+#else /* CONFIG_ETH_P_OUI */
+       return -1;
+#endif /* CONFIG_ETH_P_OUI */
+}
+
+
+#ifdef CONFIG_IEEE80211R_AP
 
 static int hostapd_wpa_auth_send_ft_action(void *ctx, const u8 *dst,
                                           const u8 *data, size_t data_len)
@@ -542,11 +842,30 @@ static void hostapd_rrb_receive(void *ctx, const u8 *src_addr, const u8 *buf,
        ethhdr = (struct l2_ethhdr *) buf;
        wpa_printf(MSG_DEBUG, "FT: RRB received packet " MACSTR " -> "
                   MACSTR, MAC2STR(ethhdr->h_source), MAC2STR(ethhdr->h_dest));
+       if (!is_multicast_ether_addr(ethhdr->h_dest) &&
+           os_memcmp(hapd->own_addr, ethhdr->h_dest, ETH_ALEN) != 0)
+               return;
        wpa_ft_rrb_rx(hapd->wpa_auth, ethhdr->h_source, buf + sizeof(*ethhdr),
                      len - sizeof(*ethhdr));
 }
 
 
+static void hostapd_rrb_oui_receive(void *ctx, const u8 *src_addr,
+                                   const u8 *dst_addr, u8 oui_suffix,
+                                   const u8 *buf, size_t len)
+{
+       struct hostapd_data *hapd = ctx;
+
+       wpa_printf(MSG_DEBUG, "FT: RRB received packet " MACSTR " -> "
+                  MACSTR, MAC2STR(src_addr), MAC2STR(dst_addr));
+       if (!is_multicast_ether_addr(dst_addr) &&
+           os_memcmp(hapd->own_addr, dst_addr, ETH_ALEN) != 0)
+               return;
+       wpa_ft_rrb_oui_rx(hapd->wpa_auth, src_addr, dst_addr, oui_suffix, buf,
+                         len);
+}
+
+
 static int hostapd_wpa_auth_add_tspec(void *ctx, const u8 *sta_addr,
                                      u8 *tspec_ie, size_t tspec_ielen)
 {
@@ -554,13 +873,86 @@ static int hostapd_wpa_auth_add_tspec(void *ctx, const u8 *sta_addr,
        return hostapd_add_tspec(hapd, sta_addr, tspec_ie, tspec_ielen);
 }
 
-#endif /* CONFIG_IEEE80211R */
+
+
+static int hostapd_wpa_register_ft_oui(struct hostapd_data *hapd,
+                                      const char *ft_iface)
+{
+       hapd->oui_pull = eth_p_oui_register(hapd, ft_iface,
+                                           FT_PACKET_R0KH_R1KH_PULL,
+                                           hostapd_rrb_oui_receive, hapd);
+       if (!hapd->oui_pull)
+               return -1;
+
+       hapd->oui_resp = eth_p_oui_register(hapd, ft_iface,
+                                           FT_PACKET_R0KH_R1KH_RESP,
+                                           hostapd_rrb_oui_receive, hapd);
+       if (!hapd->oui_resp)
+               return -1;
+
+       hapd->oui_push = eth_p_oui_register(hapd, ft_iface,
+                                           FT_PACKET_R0KH_R1KH_PUSH,
+                                           hostapd_rrb_oui_receive, hapd);
+       if (!hapd->oui_push)
+               return -1;
+
+       hapd->oui_sreq = eth_p_oui_register(hapd, ft_iface,
+                                           FT_PACKET_R0KH_R1KH_SEQ_REQ,
+                                           hostapd_rrb_oui_receive, hapd);
+       if (!hapd->oui_sreq)
+               return -1;
+
+       hapd->oui_sresp = eth_p_oui_register(hapd, ft_iface,
+                                            FT_PACKET_R0KH_R1KH_SEQ_RESP,
+                                            hostapd_rrb_oui_receive, hapd);
+       if (!hapd->oui_sresp)
+               return -1;
+
+       return 0;
+}
+
+
+static void hostapd_wpa_unregister_ft_oui(struct hostapd_data *hapd)
+{
+       eth_p_oui_unregister(hapd->oui_pull);
+       hapd->oui_pull = NULL;
+       eth_p_oui_unregister(hapd->oui_resp);
+       hapd->oui_resp = NULL;
+       eth_p_oui_unregister(hapd->oui_push);
+       hapd->oui_push = NULL;
+       eth_p_oui_unregister(hapd->oui_sreq);
+       hapd->oui_sreq = NULL;
+       eth_p_oui_unregister(hapd->oui_sresp);
+       hapd->oui_sresp = NULL;
+}
+#endif /* CONFIG_IEEE80211R_AP */
 
 
 int hostapd_setup_wpa(struct hostapd_data *hapd)
 {
        struct wpa_auth_config _conf;
-       struct wpa_auth_callbacks cb;
+       static const struct wpa_auth_callbacks cb = {
+               .logger = hostapd_wpa_auth_logger,
+               .disconnect = hostapd_wpa_auth_disconnect,
+               .mic_failure_report = hostapd_wpa_auth_mic_failure_report,
+               .psk_failure_report = hostapd_wpa_auth_psk_failure_report,
+               .set_eapol = hostapd_wpa_auth_set_eapol,
+               .get_eapol = hostapd_wpa_auth_get_eapol,
+               .get_psk = hostapd_wpa_auth_get_psk,
+               .get_msk = hostapd_wpa_auth_get_msk,
+               .set_key = hostapd_wpa_auth_set_key,
+               .get_seqnum = hostapd_wpa_auth_get_seqnum,
+               .send_eapol = hostapd_wpa_auth_send_eapol,
+               .for_each_sta = hostapd_wpa_auth_for_each_sta,
+               .for_each_auth = hostapd_wpa_auth_for_each_auth,
+               .send_ether = hostapd_wpa_auth_send_ether,
+               .send_oui = hostapd_wpa_auth_send_oui,
+#ifdef CONFIG_IEEE80211R_AP
+               .send_ft_action = hostapd_wpa_auth_send_ft_action,
+               .add_sta = hostapd_wpa_auth_add_sta,
+               .add_tspec = hostapd_wpa_auth_add_tspec,
+#endif /* CONFIG_IEEE80211R_AP */
+       };
        const u8 *wpa_ie;
        size_t wpa_ie_len;
 
@@ -569,27 +961,7 @@ int hostapd_setup_wpa(struct hostapd_data *hapd)
                _conf.tx_status = 1;
        if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_MLME)
                _conf.ap_mlme = 1;
-       os_memset(&cb, 0, sizeof(cb));
-       cb.ctx = hapd;
-       cb.logger = hostapd_wpa_auth_logger;
-       cb.disconnect = hostapd_wpa_auth_disconnect;
-       cb.mic_failure_report = hostapd_wpa_auth_mic_failure_report;
-       cb.set_eapol = hostapd_wpa_auth_set_eapol;
-       cb.get_eapol = hostapd_wpa_auth_get_eapol;
-       cb.get_psk = hostapd_wpa_auth_get_psk;
-       cb.get_msk = hostapd_wpa_auth_get_msk;
-       cb.set_key = hostapd_wpa_auth_set_key;
-       cb.get_seqnum = hostapd_wpa_auth_get_seqnum;
-       cb.send_eapol = hostapd_wpa_auth_send_eapol;
-       cb.for_each_sta = hostapd_wpa_auth_for_each_sta;
-       cb.for_each_auth = hostapd_wpa_auth_for_each_auth;
-       cb.send_ether = hostapd_wpa_auth_send_ether;
-#ifdef CONFIG_IEEE80211R
-       cb.send_ft_action = hostapd_wpa_auth_send_ft_action;
-       cb.add_sta = hostapd_wpa_auth_add_sta;
-       cb.add_tspec = hostapd_wpa_auth_add_tspec;
-#endif /* CONFIG_IEEE80211R */
-       hapd->wpa_auth = wpa_init(hapd->own_addr, &_conf, &cb);
+       hapd->wpa_auth = wpa_init(hapd->own_addr, &_conf, &cb, hapd);
        if (hapd->wpa_auth == NULL) {
                wpa_printf(MSG_ERROR, "WPA initialization failed.");
                return -1;
@@ -614,11 +986,14 @@ int hostapd_setup_wpa(struct hostapd_data *hapd)
                return -1;
        }
 
-#ifdef CONFIG_IEEE80211R
-       if (!hostapd_drv_none(hapd)) {
-               hapd->l2 = l2_packet_init(hapd->conf->bridge[0] ?
-                                         hapd->conf->bridge :
-                                         hapd->conf->iface, NULL, ETH_P_RRB,
+#ifdef CONFIG_IEEE80211R_AP
+       if (!hostapd_drv_none(hapd) &&
+           wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt)) {
+               const char *ft_iface;
+
+               ft_iface = hapd->conf->bridge[0] ? hapd->conf->bridge :
+                          hapd->conf->iface;
+               hapd->l2 = l2_packet_init(ft_iface, NULL, ETH_P_RRB,
                                          hostapd_rrb_receive, hapd, 1);
                if (hapd->l2 == NULL &&
                    (hapd->driver == NULL ||
@@ -627,8 +1002,14 @@ int hostapd_setup_wpa(struct hostapd_data *hapd)
                                   "interface");
                        return -1;
                }
+
+               if (hostapd_wpa_register_ft_oui(hapd, ft_iface)) {
+                       wpa_printf(MSG_ERROR,
+                                  "Failed to open ETH_P_OUI interface");
+                       return -1;
+               }
        }
-#endif /* CONFIG_IEEE80211R */
+#endif /* CONFIG_IEEE80211R_AP */
 
        return 0;
 
@@ -651,13 +1032,14 @@ void hostapd_deinit_wpa(struct hostapd_data *hapd)
                wpa_deinit(hapd->wpa_auth);
                hapd->wpa_auth = NULL;
 
-               if (hostapd_set_privacy(hapd, 0)) {
+               if (hapd->drv_priv && hostapd_set_privacy(hapd, 0)) {
                        wpa_printf(MSG_DEBUG, "Could not disable "
                                   "PrivacyInvoked for interface %s",
                                   hapd->conf->iface);
                }
 
-               if (hostapd_set_generic_elem(hapd, (u8 *) "", 0)) {
+               if (hapd->drv_priv &&
+                   hostapd_set_generic_elem(hapd, (u8 *) "", 0)) {
                        wpa_printf(MSG_DEBUG, "Could not remove generic "
                                   "information element from interface %s",
                                   hapd->conf->iface);
@@ -665,8 +1047,13 @@ void hostapd_deinit_wpa(struct hostapd_data *hapd)
        }
        ieee802_1x_deinit(hapd);
 
-#ifdef CONFIG_IEEE80211R
+#ifdef CONFIG_IEEE80211R_AP
+       eloop_cancel_timeout(hostapd_wpa_ft_rrb_rx_later, hapd, ELOOP_ALL_CTX);
+       hostapd_wpa_ft_rrb_rx_later(hapd, NULL); /* flush without delivering */
+       eloop_cancel_timeout(hostapd_oui_deliver_later, hapd, ELOOP_ALL_CTX);
+       hostapd_oui_deliver_later(hapd, NULL); /* flush without delivering */
        l2_packet_deinit(hapd->l2);
        hapd->l2 = NULL;
-#endif /* CONFIG_IEEE80211R */
+       hostapd_wpa_unregister_ft_oui(hapd);
+#endif /* CONFIG_IEEE80211R_AP */
 }