From e9f75a3520e642c4467068a0321e97ffd4af1433 Mon Sep 17 00:00:00 2001 From: Ilan Peer Date: Mon, 25 Dec 2023 19:42:58 +0200 Subject: [PATCH] AP: Unify code handling deauthentication/disassociation This avoids unnecessary code duplication and adds the sta->wpa_sm deinit calls for deauthentication while it was previously done only in the disassociation case. Signed-off-by: Ilan Peer --- src/ap/sta_info.c | 67 +++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/src/ap/sta_info.c b/src/ap/sta_info.c index 1bd6c07e9..bbea175ab 100644 --- a/src/ap/sta_info.c +++ b/src/ap/sta_info.c @@ -846,32 +846,20 @@ static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx) } -void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta, - u16 reason) +static void ap_sta_disconnect_common(struct hostapd_data *hapd, + struct sta_info *sta, unsigned int timeout) { - wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR, - hapd->conf->iface, MAC2STR(sta->addr)); sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ; - if (hapd->iface->current_mode && - hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) { - /* Skip deauthentication in DMG/IEEE 802.11ad */ - sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | - WLAN_STA_ASSOC_REQ_OK); - sta->timeout_next = STA_REMOVE; - } else { - sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK); - sta->timeout_next = STA_DEAUTH; - } + ap_sta_set_authorized(hapd, sta, 0); hostapd_set_sta_flags(hapd, sta); - wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout " - "for " MACSTR " (%d seconds - " - "AP_MAX_INACTIVITY_AFTER_DISASSOC)", - __func__, MAC2STR(sta->addr), - AP_MAX_INACTIVITY_AFTER_DISASSOC); + + wpa_printf(MSG_DEBUG, + "reschedule ap_handle_timer timeout (%u sec) for " MACSTR, + MAC2STR(sta->addr), timeout); + eloop_cancel_timeout(ap_handle_timer, hapd, sta); - eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0, - ap_handle_timer, hapd, sta); + eloop_register_timeout(timeout, 0, ap_handle_timer, hapd, sta); accounting_sta_stop(hapd, sta); ieee802_1x_free_station(hapd, sta); #ifdef CONFIG_IEEE80211BE @@ -883,6 +871,27 @@ void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta, #endif /* CONFIG_IEEE80211BE */ sta->wpa_sm = NULL; +} + + +void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta, + u16 reason) +{ + wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR, + hapd->conf->iface, MAC2STR(sta->addr)); + + if (hapd->iface->current_mode && + hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) { + /* Skip deauthentication in DMG/IEEE 802.11ad */ + sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | + WLAN_STA_ASSOC_REQ_OK); + sta->timeout_next = STA_REMOVE; + } else { + sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK); + sta->timeout_next = STA_DEAUTH; + } + + ap_sta_disconnect_common(hapd, sta, AP_MAX_INACTIVITY_AFTER_DISASSOC); sta->disassoc_reason = reason; sta->flags |= WLAN_STA_PENDING_DISASSOC_CB; @@ -918,21 +927,11 @@ void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta, wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR, hapd->conf->iface, MAC2STR(sta->addr)); - sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ; + sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK); - ap_sta_set_authorized(hapd, sta, 0); - hostapd_set_sta_flags(hapd, sta); + sta->timeout_next = STA_REMOVE; - wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout " - "for " MACSTR " (%d seconds - " - "AP_MAX_INACTIVITY_AFTER_DEAUTH)", - __func__, MAC2STR(sta->addr), - AP_MAX_INACTIVITY_AFTER_DEAUTH); - eloop_cancel_timeout(ap_handle_timer, hapd, sta); - eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0, - ap_handle_timer, hapd, sta); - accounting_sta_stop(hapd, sta); - ieee802_1x_free_station(hapd, sta); + ap_sta_disconnect_common(hapd, sta, AP_MAX_INACTIVITY_AFTER_DEAUTH); sta->deauth_reason = reason; sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;