bsd: Get rid of printf size_t warnings with 64-bit builds
[wpasupplicant] / hostapd / eapol_sm.c
index cc2c4e7..5491fc4 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "includes.h"
 
-#include "hostapd.h"
+#include "common.h"
 #include "ieee802_1x.h"
 #include "eapol_sm.h"
 #include "eloop.h"
@@ -140,9 +140,14 @@ static void eapol_auth_tx_req(struct eapol_state_machine *sm)
 }
 
 
-/* Port Timers state machine - implemented as a function that will be called
- * once a second as a registered event loop timeout */
-
+/**
+ * eapol_port_timers_tick - Port Timers state machine
+ * @eloop_ctx: struct eapol_state_machine *
+ * @timeout_ctx: Not used
+ *
+ * This statemachine is implemented as a function that will be called
+ * once a second as a registered event loop timeout.
+ */
 static void eapol_port_timers_tick(void *eloop_ctx, void *timeout_ctx)
 {
        struct eapol_state_machine *state = timeout_ctx;
@@ -174,6 +179,15 @@ static void eapol_port_timers_tick(void *eloop_ctx, void *timeout_ctx)
                }
        }
 
+       if (state->eap_if->retransWhile > 0) {
+               state->eap_if->retransWhile--;
+               if (state->eap_if->retransWhile == 0) {
+                       wpa_printf(MSG_DEBUG, "IEEE 802.1X: " MACSTR
+                                  " - (EAP) retransWhile --> 0",
+                                  MAC2STR(state->addr));
+               }
+       }
+
        eapol_sm_step_run(state);
 
        eloop_register_timeout(1, 0, eapol_port_timers_tick, eloop_ctx, state);
@@ -356,15 +370,15 @@ SM_STEP(AUTH_PAE)
 {
        if ((sm->portControl == Auto && sm->portMode != sm->portControl) ||
            sm->initialize || !sm->eap_if->portEnabled)
-               SM_ENTER(AUTH_PAE, INITIALIZE);
+               SM_ENTER_GLOBAL(AUTH_PAE, INITIALIZE);
        else if (sm->portControl == ForceAuthorized &&
                 sm->portMode != sm->portControl &&
                 !(sm->initialize || !sm->eap_if->portEnabled))
-               SM_ENTER(AUTH_PAE, FORCE_AUTH);
+               SM_ENTER_GLOBAL(AUTH_PAE, FORCE_AUTH);
        else if (sm->portControl == ForceUnauthorized &&
                 sm->portMode != sm->portControl &&
                 !(sm->initialize || !sm->eap_if->portEnabled))
-               SM_ENTER(AUTH_PAE, FORCE_UNAUTH);
+               SM_ENTER_GLOBAL(AUTH_PAE, FORCE_UNAUTH);
        else {
                switch (sm->auth_pae_state) {
                case AUTH_PAE_INITIALIZE:
@@ -520,7 +534,7 @@ SM_STATE(BE_AUTH, IGNORE)
 SM_STEP(BE_AUTH)
 {
        if (sm->portControl != Auto || sm->initialize || sm->authAbort) {
-               SM_ENTER(BE_AUTH, INITIALIZE);
+               SM_ENTER_GLOBAL(BE_AUTH, INITIALIZE);
                return;
        }
 
@@ -605,7 +619,7 @@ SM_STEP(REAUTH_TIMER)
 {
        if (sm->portControl != Auto || sm->initialize ||
            sm->authPortStatus == Unauthorized || !sm->reAuthEnabled) {
-               SM_ENTER(REAUTH_TIMER, INITIALIZE);
+               SM_ENTER_GLOBAL(REAUTH_TIMER, INITIALIZE);
                return;
        }
 
@@ -643,7 +657,7 @@ SM_STATE(AUTH_KEY_TX, KEY_TRANSMIT)
 SM_STEP(AUTH_KEY_TX)
 {
        if (sm->initialize || sm->portControl != Auto) {
-               SM_ENTER(AUTH_KEY_TX, NO_KEY_TRANSMIT);
+               SM_ENTER_GLOBAL(AUTH_KEY_TX, NO_KEY_TRANSMIT);
                return;
        }
 
@@ -684,7 +698,7 @@ SM_STATE(KEY_RX, KEY_RECEIVE)
 SM_STEP(KEY_RX)
 {
        if (sm->initialize || !sm->eap_if->portEnabled) {
-               SM_ENTER(KEY_RX, NO_KEY_RECEIVE);
+               SM_ENTER_GLOBAL(KEY_RX, NO_KEY_RECEIVE);
                return;
        }
 
@@ -721,7 +735,7 @@ SM_STATE(CTRL_DIR, IN_OR_BOTH)
 SM_STEP(CTRL_DIR)
 {
        if (sm->initialize) {
-               SM_ENTER(CTRL_DIR, IN_OR_BOTH);
+               SM_ENTER_GLOBAL(CTRL_DIR, IN_OR_BOTH);
                return;
        }
 
@@ -790,7 +804,7 @@ eapol_auth_alloc(struct eapol_authenticator *eapol, const u8 *addr,
        sm->portControl = Auto;
 
        if (!eapol->conf.wpa &&
-           (hapd->default_wep_key || eapol->conf.individual_wep_key_len > 0))
+           (eapol->default_wep_key || eapol->conf.individual_wep_key_len > 0))
                sm->keyTxEnabled = TRUE;
        else
                sm->keyTxEnabled = FALSE;
@@ -812,6 +826,8 @@ eapol_auth_alloc(struct eapol_authenticator *eapol, const u8 *addr,
        eap_conf.pac_key_refresh_time = eapol->conf.pac_key_refresh_time;
        eap_conf.eap_sim_aka_result_ind = eapol->conf.eap_sim_aka_result_ind;
        eap_conf.tnc = eapol->conf.tnc;
+       eap_conf.wps = eapol->conf.wps;
+       eap_conf.assoc_wps_ie = sta->wps_ie;
        sm->eap = eap_server_sm_init(sm, &eapol_cb, &eap_conf);
        if (sm->eap == NULL) {
                eapol_auth_free(sm);
@@ -930,6 +946,13 @@ static void eapol_sm_step_cb(void *eloop_ctx, void *timeout_ctx)
 }
 
 
+/**
+ * eapol_auth_step - Advance EAPOL state machines
+ * @sm: EAPOL state machine
+ *
+ * This function is called to advance EAPOL state machines after any change
+ * that could affect their state.
+ */
 void eapol_auth_step(struct eapol_state_machine *sm)
 {
        /*
@@ -1263,6 +1286,7 @@ static int eapol_auth_conf_clone(struct eapol_auth_config *dst,
        dst->pac_key_refresh_time = src->pac_key_refresh_time;
        dst->eap_sim_aka_result_ind = src->eap_sim_aka_result_ind;
        dst->tnc = src->tnc;
+       dst->wps = src->wps;
        return 0;
 }
 
@@ -1294,6 +1318,11 @@ struct eapol_authenticator * eapol_auth_init(struct eapol_auth_config *conf,
                return NULL;
        }
 
+       if (conf->individual_wep_key_len > 0) {
+               /* use key0 in individual key and key1 in broadcast key */
+               eapol->default_wep_key_idx = 1;
+       }
+
        eapol->cb.eapol_send = cb->eapol_send;
        eapol->cb.aaa_send = cb->aaa_send;
        eapol->cb.finished = cb->finished;
@@ -1314,5 +1343,6 @@ void eapol_auth_deinit(struct eapol_authenticator *eapol)
                return;
 
        eapol_auth_conf_free(&eapol->conf);
+       os_free(eapol->default_wep_key);
        os_free(eapol);
 }