Added support for opportunistic key caching (OKC)
[libeap.git] / hostapd / hostapd.c
index 1e6a7bb..f0437fd 100644 (file)
@@ -41,6 +41,7 @@
 #include "tls.h"
 #include "eap_server/eap_sim_db.h"
 #include "eap_server/eap.h"
+#include "eap_server/tncs.h"
 #include "version.h"
 #include "l2_packet/l2_packet.h"
 
@@ -165,17 +166,18 @@ static void hostapd_logger_cb(void *ctx, const u8 *addr, unsigned int module,
 
 static void hostapd_deauth_all_stas(struct hostapd_data *hapd)
 {
-#if 0
        u8 addr[ETH_ALEN];
 
-       os_memset(addr, 0xff, ETH_ALEN);
-       hostapd_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
-#else
        /* New Prism2.5/3 STA firmware versions seem to have issues with this
         * broadcast deauth frame. This gets the firmware in odd state where
-        * nothing works correctly, so let's skip sending this for a while
-        * until the issue has been resolved. */
-#endif
+        * nothing works correctly, so let's skip sending this for the hostap
+        * driver. */
+
+       if (os_strcmp(hapd->driver->name, "hostap") != 0) {
+               os_memset(addr, 0xff, ETH_ALEN);
+               hostapd_sta_deauth(hapd, addr,
+                                  WLAN_REASON_PREV_AUTH_NOT_VALID);
+       }
 }
 
 
@@ -296,6 +298,7 @@ static void hostapd_wpa_auth_conf(struct hostapd_bss_config *conf,
        wconf->eapol_version = conf->eapol_version;
        wconf->peerkey = conf->peerkey;
        wconf->wme_enabled = conf->wme_enabled;
+       wconf->okc = conf->okc;
 #ifdef CONFIG_IEEE80211W
        wconf->ieee80211w = conf->ieee80211w;
 #endif /* CONFIG_IEEE80211W */
@@ -396,7 +399,7 @@ static void hostapd_dump_state(struct hostapd_data *hapd)
                fprintf(f, "\nSTA=" MACSTR "\n", MAC2STR(sta->addr));
 
                fprintf(f,
-                       "  AID=%d flags=0x%x %s%s%s%s%s%s%s%s%s%s\n"
+                       "  AID=%d flags=0x%x %s%s%s%s%s%s%s%s%s%s%s%s\n"
                        "  capability=0x%x listen_interval=%d\n",
                        sta->aid,
                        sta->flags,
@@ -412,6 +415,8 @@ static void hostapd_dump_state(struct hostapd_data *hapd)
                        (sta->flags & WLAN_STA_SHORT_PREAMBLE ?
                         "[SHORT_PREAMBLE]" : ""),
                        (sta->flags & WLAN_STA_PREAUTH ? "[PREAUTH]" : ""),
+                       (sta->flags & WLAN_STA_WME ? "[WME]" : ""),
+                       (sta->flags & WLAN_STA_MFP ? "[MFP]" : ""),
                        (sta->flags & WLAN_STA_NONERP ? "[NonERP]" : ""),
                        sta->capability,
                        sta->listen_interval);
@@ -887,6 +892,26 @@ static int hostapd_wpa_auth_for_each_sta(
 }
 
 
+static int hostapd_wpa_auth_for_each_auth(
+       void *ctx, int (*cb)(struct wpa_authenticator *sm, void *ctx),
+       void *cb_ctx)
+{
+       struct hostapd_data *ohapd;
+       size_t i, j;
+       struct hapd_interfaces *interfaces = eloop_get_user_data();
+
+       for (i = 0; i < interfaces->count; i++) {
+               for (j = 0; j < interfaces->iface[i]->num_bss; j++) {
+                       ohapd = interfaces->iface[i]->bss[j];
+                       if (cb(ohapd->wpa_auth, cb_ctx))
+                               return 1;
+               }
+       }
+
+       return 0;
+}
+
+
 static int hostapd_wpa_auth_send_ether(void *ctx, const u8 *dst, u16 proto,
                                       const u8 *data, size_t data_len)
 {
@@ -1091,6 +1116,7 @@ static int hostapd_setup_wpa(struct hostapd_data *hapd)
        cb.get_seqnum_igtk = hostapd_wpa_auth_get_seqnum_igtk;
        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;
@@ -1139,6 +1165,7 @@ static int hostapd_setup_radius_srv(struct hostapd_data *hapd,
        srv.pac_opaque_encr_key = conf->pac_opaque_encr_key;
        srv.eap_fast_a_id = conf->eap_fast_a_id;
        srv.eap_sim_aka_result_ind = conf->eap_sim_aka_result_ind;
+       srv.tnc = conf->tnc;
        srv.ipv6 = conf->radius_server_ipv6;
        srv.get_eap_user = hostapd_radius_get_eap_user;
 
@@ -1854,7 +1881,7 @@ int main(int argc, char *argv[])
        struct hapd_interfaces interfaces;
        int ret = 1, k;
        size_t i, j;
-       int c, debug = 0, daemonize = 0;
+       int c, debug = 0, daemonize = 0, tnc = 0;
        const char *pid_file = NULL;
 
        hostapd_logger_register_cb(hostapd_logger_cb);
@@ -1940,7 +1967,19 @@ int main(int argc, char *argv[])
                                                    setup_interface_done);
                if (ret)
                        goto out;
+
+               for (k = 0; k < (int) interfaces.iface[i]->num_bss; k++) {
+                       if (interfaces.iface[i]->bss[0]->conf->tnc)
+                               tnc++;
+               }
+       }
+
+#ifdef EAP_TNC
+       if (tnc && tncs_global_init() < 0) {
+               wpa_printf(MSG_ERROR, "Failed to initialize TNCS");
+               goto out;
        }
+#endif /* EAP_TNC */
 
        if (daemonize && os_daemonize(pid_file)) {
                perror("daemon");
@@ -1986,6 +2025,10 @@ int main(int argc, char *argv[])
        }
        os_free(interfaces.iface);
 
+#ifdef EAP_TNC
+       tncs_global_deinit();
+#endif /* EAP_TNC */
+
        eloop_destroy();
 
 #ifndef CONFIG_NATIVE_WINDOWS