hostapd: Fix internal crypto build without TLS
[wpasupplicant] / wpa_supplicant / wpas_glue.c
index d5e31eb..c2eb131 100644 (file)
 #include "l2_packet/l2_packet.h"
 #include "wpa_common.h"
 #include "wpa_supplicant_i.h"
+#include "driver_i.h"
 #include "pmksa_cache.h"
 #include "mlme.h"
+#include "sme.h"
 #include "ieee802_11_defs.h"
 #include "wpa_ctrl.h"
 #include "wpas_glue.h"
+#include "wps_supplicant.h"
 
 
 #ifndef CONFIG_NO_CONFIG_BLOBS
@@ -228,6 +231,9 @@ static void wpa_supplicant_eapol_cb(struct eapol_sm *eapol, int success,
        wpa_printf(MSG_DEBUG, "EAPOL authentication completed %ssuccessfully",
                   success ? "" : "un");
 
+       if (wpas_wps_eapol_cb(wpa_s) > 0)
+               return;
+
        if (!success) {
                /*
                 * Make sure we do not get stuck here waiting for long EAPOL
@@ -237,7 +243,7 @@ static void wpa_supplicant_eapol_cb(struct eapol_sm *eapol, int success,
                wpa_supplicant_req_auth_timeout(wpa_s, 2, 0);
        }
 
-       if (!success || !wpa_s->driver_4way_handshake)
+       if (!success || !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE))
                return;
 
        if (!wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt))
@@ -398,7 +404,7 @@ static void _wpa_supplicant_disassociate(void *wpa_s, int reason_code)
 {
        wpa_supplicant_disassociate(wpa_s, reason_code);
        /* Schedule a scan to make sure we continue looking for networks */
-       wpa_supplicant_req_scan(wpa_s, 0, 0);
+       wpa_supplicant_req_scan(wpa_s, 5, 0);
 }
 
 
@@ -406,7 +412,7 @@ static void _wpa_supplicant_deauthenticate(void *wpa_s, int reason_code)
 {
        wpa_supplicant_deauthenticate(wpa_s, reason_code);
        /* Schedule a scan to make sure we continue looking for networks */
-       wpa_supplicant_req_scan(wpa_s, 0, 0);
+       wpa_supplicant_req_scan(wpa_s, 5, 0);
 }
 
 
@@ -419,7 +425,7 @@ static void * wpa_supplicant_get_network_ctx(void *wpa_s)
 static int wpa_supplicant_get_bssid(void *ctx, u8 *bssid)
 {
        struct wpa_supplicant *wpa_s = ctx;
-       if (wpa_s->use_client_mlme) {
+       if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) {
                os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
                return 0;
        }
@@ -427,11 +433,16 @@ static int wpa_supplicant_get_bssid(void *ctx, u8 *bssid)
 }
 
 
-static int wpa_supplicant_set_key(void *wpa_s, wpa_alg alg,
+static int wpa_supplicant_set_key(void *_wpa_s, wpa_alg alg,
                                  const u8 *addr, int key_idx, int set_tx,
                                  const u8 *seq, size_t seq_len,
                                  const u8 *key, size_t key_len)
 {
+       struct wpa_supplicant *wpa_s = _wpa_s;
+       if (alg == WPA_ALG_TKIP && key_idx == 0 && key_len == 32) {
+               /* Clear the MIC error counter when setting a new PTK. */
+               wpa_s->mic_errors_seen = 0;
+       }
        return wpa_drv_set_key(wpa_s, alg, addr, key_idx, set_tx, seq, seq_len,
                               key, key_len);
 }
@@ -465,8 +476,10 @@ static int wpa_supplicant_update_ft_ies(void *ctx, const u8 *md,
                                        const u8 *ies, size_t ies_len)
 {
        struct wpa_supplicant *wpa_s = ctx;
-       if (wpa_s->use_client_mlme)
+       if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
                return ieee80211_sta_update_ft_ies(wpa_s, md, ies, ies_len);
+       if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
+               return sme_update_ft_ies(wpa_s, md, ies, ies_len);
        return wpa_drv_update_ft_ies(wpa_s, md, ies, ies_len);
 }
 
@@ -476,7 +489,7 @@ static int wpa_supplicant_send_ft_action(void *ctx, u8 action,
                                         const u8 *ies, size_t ies_len)
 {
        struct wpa_supplicant *wpa_s = ctx;
-       if (wpa_s->use_client_mlme)
+       if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
                return ieee80211_sta_send_ft_action(wpa_s, action, target_ap,
                                                    ies, ies_len);
        return wpa_drv_send_ft_action(wpa_s, action, target_ap, ies, ies_len);
@@ -524,6 +537,15 @@ static void wpa_supplicant_eap_param_needed(void *ctx, const char *field,
 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
 
 
+static void wpa_supplicant_port_cb(void *ctx, int authorized)
+{
+       struct wpa_supplicant *wpa_s = ctx;
+       wpa_printf(MSG_DEBUG, "EAPOL: Supplicant port status: %s",
+                  authorized ? "Authorized" : "Unauthorized");
+       wpa_drv_set_supp_port(wpa_s, authorized);
+}
+
+
 int wpa_supplicant_init_eapol(struct wpa_supplicant *wpa_s)
 {
 #ifdef IEEE8021X_EAPOL
@@ -549,7 +571,9 @@ int wpa_supplicant_init_eapol(struct wpa_supplicant *wpa_s)
        ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
        ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
 #endif /* EAP_TLS_OPENSSL */
+       ctx->wps = wpa_s->wps;
        ctx->eap_param_needed = wpa_supplicant_eap_param_needed;
+       ctx->port_cb = wpa_supplicant_port_cb;
        ctx->cb = wpa_supplicant_eapol_cb;
        ctx->cb_ctx = wpa_s;
        wpa_s->eapol = eapol_sm_init(ctx);
@@ -576,6 +600,7 @@ int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s)
        }
 
        ctx->ctx = wpa_s;
+       ctx->msg_ctx = wpa_s;
        ctx->set_state = _wpa_supplicant_set_state;
        ctx->get_state = _wpa_supplicant_get_state;
        ctx->deauthenticate = _wpa_supplicant_deauthenticate;