]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
AP: Move deauthentication/disassociation steps into helper functions
authorIlan Peer <ilan.peer@intel.com>
Mon, 22 May 2023 19:33:48 +0000 (22:33 +0300)
committerJouni Malinen <j@w1.fi>
Mon, 12 Jun 2023 10:45:41 +0000 (13:45 +0300)
This is a step towards handling of deauthentication/disassociation from
an MLD AP.

Signed-off-by: Ilan Peer <ilan.peer@intel.com>
Signed-off-by: Andrei Otcheretianski <andrei.otcheretianski@intel.com>
src/ap/ieee802_11.c

index 9e2aad8a06e00bf9fa74280b2fa4582cf211f0b8..f4d638df0f8bd32e4a57c3d49e1f0dab060fb80f 100644 (file)
@@ -5507,28 +5507,38 @@ static void handle_assoc(struct hostapd_data *hapd,
 }
 
 
-static void handle_disassoc(struct hostapd_data *hapd,
-                           const struct ieee80211_mgmt *mgmt, size_t len)
+static void hostapd_deauth_sta(struct hostapd_data *hapd,
+                              struct sta_info *sta,
+                              const struct ieee80211_mgmt *mgmt)
 {
-       struct sta_info *sta;
+       wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
+               " reason_code=%d",
+               MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
+
+       ap_sta_set_authorized(hapd, sta, 0);
+       sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
+       sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
+                       WLAN_STA_ASSOC_REQ_OK);
+       hostapd_set_sta_flags(hapd, sta);
+       wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
+       hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
+                      HOSTAPD_LEVEL_DEBUG, "deauthenticated");
+       mlme_deauthenticate_indication(
+               hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
+       sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
+       ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
+       ap_free_sta(hapd, sta);
+}
 
-       if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
-               wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
-                          (unsigned long) len);
-               return;
-       }
 
+static void hostapd_disassoc_sta(struct hostapd_data *hapd,
+                                struct sta_info *sta,
+                                const struct ieee80211_mgmt *mgmt)
+{
        wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
                   MAC2STR(mgmt->sa),
                   le_to_host16(mgmt->u.disassoc.reason_code));
 
-       sta = ap_get_sta(hapd, mgmt->sa);
-       if (sta == NULL) {
-               wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
-                          MAC2STR(mgmt->sa));
-               return;
-       }
-
        ap_sta_set_authorized(hapd, sta, 0);
        sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
        sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
@@ -5572,6 +5582,29 @@ static void handle_disassoc(struct hostapd_data *hapd,
 }
 
 
+static void handle_disassoc(struct hostapd_data *hapd,
+                           const struct ieee80211_mgmt *mgmt, size_t len)
+{
+       struct sta_info *sta;
+
+       if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
+               wpa_printf(MSG_INFO,
+                          "handle_disassoc - too short payload (len=%lu)",
+                          (unsigned long) len);
+               return;
+       }
+
+       sta = ap_get_sta(hapd, mgmt->sa);
+       if (sta == NULL) {
+               wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
+                          MAC2STR(mgmt->sa));
+               return;
+       }
+
+       hostapd_disassoc_sta(hapd, sta, mgmt);
+}
+
+
 static void handle_deauth(struct hostapd_data *hapd,
                          const struct ieee80211_mgmt *mgmt, size_t len)
 {
@@ -5583,10 +5616,6 @@ static void handle_deauth(struct hostapd_data *hapd,
                return;
        }
 
-       wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
-               " reason_code=%d",
-               MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
-
        /* Clear the PTKSA cache entries for PASN */
        ptksa_cache_flush(hapd->ptksa, mgmt->sa, WPA_CIPHER_NONE);
 
@@ -5598,19 +5627,7 @@ static void handle_deauth(struct hostapd_data *hapd,
                return;
        }
 
-       ap_sta_set_authorized(hapd, sta, 0);
-       sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
-       sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
-                       WLAN_STA_ASSOC_REQ_OK);
-       hostapd_set_sta_flags(hapd, sta);
-       wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
-       hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
-                      HOSTAPD_LEVEL_DEBUG, "deauthenticated");
-       mlme_deauthenticate_indication(
-               hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
-       sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
-       ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
-       ap_free_sta(hapd, sta);
+       hostapd_deauth_sta(hapd, sta, mgmt);
 }