From 23af935e7b48441ae10341f8550b046b9a385609 Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Fri, 18 Aug 2017 14:22:55 +0200 Subject: [PATCH] eapol: Add eapol_sm_set_require_handshake Function to allow netdev.c to explicitly tell eapol.c whether to expect EAP / 4-Way handshake. This is to potentially make the code more descriptive, until now we'd look at sm->handshake->ptk_complete to see if a new PTK was needed. A 4-Way handshake is required on association to an AP except after FT. --- src/eapol.c | 13 ++++++++++++- src/eapol.h | 1 + src/netdev.c | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/eapol.c b/src/eapol.c index 6c048290..bbb4e25b 100644 --- a/src/eapol.c +++ b/src/eapol.c @@ -731,6 +731,7 @@ struct eapol_sm { bool have_replay:1; bool started:1; bool use_eapol_start:1; + bool require_handshake:1; bool eap_exchanged:1; struct eap_state *eap; struct eapol_buffer *early_frame; @@ -764,6 +765,8 @@ struct eapol_sm *eapol_sm_new(struct handshake_state *hs) if (hs->settings_8021x) sm->use_eapol_start = true; + sm->require_handshake = true; + return sm; } @@ -1531,6 +1534,14 @@ void eapol_sm_set_use_eapol_start(struct eapol_sm *sm, bool enabled) sm->use_eapol_start = enabled; } +void eapol_sm_set_require_handshake(struct eapol_sm *sm, bool enabled) +{ + sm->require_handshake = enabled; + + if (!sm->require_handshake) + sm->use_eapol_start = false; +} + static void eapol_rx_packet(struct eapol_sm *sm, const uint8_t *frame, size_t len) { @@ -1651,7 +1662,7 @@ void eapol_register(struct eapol_sm *sm) void eapol_start(struct eapol_sm *sm) { - if (!sm->handshake->ptk_complete && !sm->handshake->have_snonce) + if (sm->require_handshake) sm->timeout = l_timeout_create(2, eapol_timeout, sm, NULL); sm->started = true; diff --git a/src/eapol.h b/src/eapol.h index b531ac0b..cc128abe 100644 --- a/src/eapol.h +++ b/src/eapol.h @@ -180,6 +180,7 @@ void eapol_sm_set_protocol_version(struct eapol_sm *sm, enum eapol_protocol_version protocol_version); void eapol_sm_set_use_eapol_start(struct eapol_sm *sm, bool enabled); +void eapol_sm_set_require_handshake(struct eapol_sm *sm, bool enabled); void eapol_sm_set_user_data(struct eapol_sm *sm, void *user_data); void eapol_sm_set_event_func(struct eapol_sm *sm, eapol_sm_event_func_t func); diff --git a/src/netdev.c b/src/netdev.c index 0083d14f..033dbb10 100644 --- a/src/netdev.c +++ b/src/netdev.c @@ -2414,7 +2414,7 @@ int netdev_fast_transition(struct netdev *netdev, struct scan_bss *target_bss, eapol_sm_free(netdev->sm); netdev->sm = eapol_sm_new(netdev->handshake); - eapol_sm_set_use_eapol_start(netdev->sm, false); + eapol_sm_set_require_handshake(netdev->sm, false); } netdev->operational = false;