]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
AP MLD: Use a helper function to check if a STA is a non-AP MLD
authorJouni Malinen <j@w1.fi>
Sun, 21 Jan 2024 16:45:28 +0000 (18:45 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 21 Jan 2024 17:08:08 +0000 (19:08 +0200)
This makes it easier to change the struct sta_info design for MLD by
reducing the number of direct references.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/ap/ap_drv_ops.c
src/ap/drv_callbacks.c
src/ap/hostapd.c
src/ap/ieee802_11.c
src/ap/ieee802_11_eht.c
src/ap/ieee802_11_shared.c
src/ap/sta_info.c
src/ap/sta_info.h
src/ap/wnm_ap.c
src/ap/wpa_auth_glue.c

index 3dec6eca68bb1708be82f1cdc35ef7af1b0e2ba3..856340cb0028a62b6f8a4a429b96c43616fff913 100644 (file)
@@ -269,7 +269,7 @@ static bool hostapd_sta_is_link_sta(struct hostapd_data *hapd,
                                    struct sta_info *sta)
 {
 #ifdef CONFIG_IEEE80211BE
-       if (hapd->conf->mld_ap && sta->mld_info.mld_sta &&
+       if (ap_sta_is_mld(hapd, sta) &&
            sta->mld_assoc_link_id != hapd->mld_link_id)
                return true;
 #endif /* CONFIG_IEEE80211BE */
@@ -839,7 +839,7 @@ int hostapd_drv_sta_deauth(struct hostapd_data *hapd,
                struct sta_info *sta = ap_get_sta(hapd, addr);
 
                link_id = hapd->mld_link_id;
-               if (sta && sta->mld_info.mld_sta)
+               if (ap_sta_is_mld(hapd, sta))
                        own_addr = hapd->mld_addr;
        }
 #endif /* CONFIG_IEEE80211BE */
@@ -860,7 +860,7 @@ int hostapd_drv_sta_disassoc(struct hostapd_data *hapd,
        if (hapd->conf->mld_ap) {
                struct sta_info *sta = ap_get_sta(hapd, addr);
 
-               if (sta && sta->mld_info.mld_sta)
+               if (ap_sta_is_mld(hapd, sta))
                        own_addr = hapd->mld_addr;
        }
 #endif /* CONFIG_IEEE80211BE */
@@ -918,7 +918,7 @@ static int hapd_drv_send_action(struct hostapd_data *hapd, unsigned int freq,
        } else if (hapd->conf->mld_ap) {
                sta = ap_get_sta(hapd, dst);
 
-               if (sta && sta->mld_info.mld_sta) {
+               if (ap_sta_is_mld(hapd, sta)) {
                        own_addr = hapd->mld_addr;
                        bssid = own_addr;
                }
index 15baa7bbe6d463103144bb7c261541239b6ab29e..5ceb084a1ce90b6e239d9b33a2341a601ba7e826 100644 (file)
@@ -513,7 +513,7 @@ int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
                        return -1;
                }
 #ifdef CONFIG_IEEE80211BE
-               if (sta->mld_info.mld_sta) {
+               if (ap_sta_is_mld(hapd, sta)) {
                        wpa_printf(MSG_DEBUG,
                                   "MLD: Set ML info in RSN Authenticator");
                        wpa_auth_set_ml_info(sta->wpa_sm, hapd->mld_addr,
index c2cb8afdaf356b09e6d204f3949659fa27714ad2..dfea07570658fd57766a497d7963e7160bf9b3ed 100644 (file)
@@ -3599,7 +3599,7 @@ void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
        }
 
 #ifdef CONFIG_IEEE80211BE
-       if (hapd->conf->mld_ap && sta->mld_info.mld_sta &&
+       if (ap_sta_is_mld(hapd, sta) &&
            sta->mld_assoc_link_id != hapd->mld_link_id)
                return;
 #endif /* CONFIG_IEEE80211BE */
index 2c57eb6352b6d14cd059d2b2e79e3d9c2ffd4219..c1299c90da2df612edbba72f107a4b783f87140a 100644 (file)
@@ -407,7 +407,7 @@ static int send_auth_reply(struct hostapd_data *hapd, struct sta_info *sta,
         * the MLD MAC address. Thus, use the MLD address instead of translating
         * the addresses.
         */
-       if (hapd->conf->mld_ap && sta && sta->mld_info.mld_sta) {
+       if (ap_sta_is_mld(hapd, sta)) {
                sa = hapd->mld_addr;
 
                ml_resp = hostapd_ml_auth_resp(hapd);
@@ -608,7 +608,7 @@ static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd,
        const u8 *own_addr = hapd->own_addr;
 
 #ifdef CONFIG_IEEE80211BE
-       if (hapd->conf->mld_ap && sta->mld_info.mld_sta)
+       if (ap_sta_is_mld(hapd, sta))
                own_addr = hapd->mld_addr;
 #endif /* CONFIG_IEEE80211BE */
 
@@ -877,7 +877,7 @@ static void sae_sme_send_external_auth_status(struct hostapd_data *hapd,
        params.status = status;
 
 #ifdef CONFIG_IEEE80211BE
-       if (sta->mld_info.mld_sta)
+       if (ap_sta_is_mld(hapd, sta))
                params.bssid =
                        sta->mld_info.links[sta->mld_assoc_link_id].peer_addr;
 #endif /* CONFIG_IEEE80211BE */
@@ -3246,7 +3246,7 @@ static void handle_auth(struct hostapd_data *hapd,
          * the MLD MAC address. It is the responsibility of the driver to
          * handle the translations.
          */
-       if (hapd->conf->mld_ap && sta && sta->mld_info.mld_sta) {
+       if (ap_sta_is_mld(hapd, sta)) {
                dst = sta->addr;
                bssid = hapd->mld_addr;
        }
@@ -3737,7 +3737,7 @@ u16 owe_process_rsn_ie(struct hostapd_data *hapd,
                goto end;
        }
 #ifdef CONFIG_IEEE80211BE
-       if (sta->mld_info.mld_sta)
+       if (ap_sta_is_mld(hapd, sta))
                wpa_auth_set_ml_info(sta->wpa_sm, hapd->mld_addr,
                                     sta->mld_assoc_link_id, &sta->mld_info);
 #endif /* CONFIG_IEEE80211BE */
@@ -4019,7 +4019,7 @@ static int __check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
                        }
 
 #ifdef CONFIG_IEEE80211BE
-                       if (info->mld_sta) {
+                       if (ap_sta_is_mld(hapd, sta)) {
                                wpa_printf(MSG_DEBUG,
                                           "MLD: Set ML info in RSN Authenticator");
                                wpa_auth_set_ml_info(sta->wpa_sm,
@@ -4608,7 +4608,7 @@ static int add_associated_sta(struct hostapd_data *hapd,
        bool mld_link_sta = false;
 
 #ifdef CONFIG_IEEE80211BE
-       if (hapd->conf->mld_ap && sta->mld_info.mld_sta) {
+       if (ap_sta_is_mld(hapd, sta)) {
                u8 mld_link_id = hapd->mld_link_id;
 
                mld_link_sta = sta->mld_assoc_link_id != mld_link_id;
@@ -4769,8 +4769,7 @@ static u16 send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
         * Once a non-AP MLD is added to the driver, the addressing should use
         * MLD MAC address.
         */
-       if (hapd->conf->mld_ap && sta && sta->mld_info.mld_sta &&
-           allow_mld_addr_trans)
+       if (ap_sta_is_mld(hapd, sta) && allow_mld_addr_trans)
                sa = hapd->mld_addr;
 #endif /* CONFIG_IEEE80211BE */
 
@@ -6440,7 +6439,7 @@ static void handle_assoc_cb(struct hostapd_data *hapd,
        }
 
 #ifdef CONFIG_IEEE80211BE
-       if (hapd->conf->mld_ap && sta->mld_info.mld_sta &&
+       if (ap_sta_is_mld(hapd, sta) &&
            hapd->mld_link_id != sta->mld_assoc_link_id) {
                /* See ieee80211_ml_link_sta_assoc_cb() for the MLD case */
                wpa_printf(MSG_DEBUG,
index f1cfd18a995f7a4befcbd4c5da569272e3431b94..8dbf66a9caa58a67b2a2eade8cd3709039724397 100644 (file)
@@ -779,7 +779,7 @@ u8 * hostapd_eid_eht_ml_beacon(struct hostapd_data *hapd,
 u8 * hostapd_eid_eht_ml_assoc(struct hostapd_data *hapd, struct sta_info *info,
                              u8 *eid)
 {
-       if (!info || !info->mld_info.mld_sta)
+       if (!ap_sta_is_mld(hapd, info))
                return eid;
 
        eid = hostapd_eid_eht_basic_ml_common(hapd, eid, &info->mld_info,
@@ -1012,11 +1012,12 @@ const u8 * hostapd_process_ml_auth(struct hostapd_data *hapd,
 
 
 static int hostapd_mld_validate_assoc_info(struct hostapd_data *hapd,
-                                          struct mld_info *info)
+                                          struct sta_info *sta)
 {
        u8 i, link_id;
+       struct mld_info *info = &sta->mld_info;
 
-       if (!info->mld_sta) {
+       if (!ap_sta_is_mld(hapd, sta)) {
                wpa_printf(MSG_DEBUG, "MLD: Not a non-AP MLD");
                return 0;
        }
@@ -1390,7 +1391,7 @@ u16 hostapd_process_ml_assoc_req(struct hostapd_data *hapd,
                goto out;
        }
 
-       ret = hostapd_mld_validate_assoc_info(hapd, info);
+       ret = hostapd_mld_validate_assoc_info(hapd, sta);
 out:
        wpabuf_free(mlbuf);
        if (ret) {
index 0cd6f9503aa83dcca850eb6ea27221eed1adb0ac..0c38483a98c155e63c2cb3cb66aaf750f7a52de6 100644 (file)
@@ -120,7 +120,7 @@ void ieee802_11_send_sa_query_req(struct hostapd_data *hapd,
        }
 
 #ifdef CONFIG_IEEE80211BE
-       if (hapd->conf->mld_ap && sta && sta->mld_info.mld_sta)
+       if (ap_sta_is_mld(hapd, sta))
                own_addr = hapd->mld_addr;
 #endif /* CONFIG_IEEE80211BE */
 
@@ -218,7 +218,7 @@ static void ieee802_11_send_sa_query_resp(struct hostapd_data *hapd,
                   MACSTR, MAC2STR(sa));
 
 #ifdef CONFIG_IEEE80211BE
-       if (hapd->conf->mld_ap && sta->mld_info.mld_sta)
+       if (ap_sta_is_mld(hapd, sta))
                own_addr = hapd->mld_addr;
 #endif /* CONFIG_IEEE80211BE */
 
@@ -1169,7 +1169,7 @@ struct sta_info * hostapd_ml_get_assoc_sta(struct hostapd_data *hapd,
        struct hostapd_data *other_hapd = NULL;
        struct sta_info *tmp_sta;
 
-       if (!sta->mld_info.mld_sta)
+       if (!ap_sta_is_mld(hapd, sta))
                return NULL;
 
        *assoc_hapd = hapd;
index 0da24fc41b38b1e479a697878e38c8ced2734bf6..3003b201d65e9d971c37ec4992de4ae56c0bd3fe 100644 (file)
@@ -303,7 +303,7 @@ void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
        ieee802_1x_free_station(hapd, sta);
 
 #ifdef CONFIG_IEEE80211BE
-       if (!hapd->conf->mld_ap || !sta->mld_info.mld_sta ||
+       if (!ap_sta_is_mld(hapd, sta) ||
            hapd->mld_link_id == sta->mld_assoc_link_id)
                wpa_auth_sta_deinit(sta->wpa_sm);
 #else
@@ -1400,7 +1400,7 @@ bool ap_sta_set_authorized_flag(struct hostapd_data *hapd, struct sta_info *sta,
                int mld_assoc_link_id = -1;
 
 #ifdef CONFIG_IEEE80211BE
-               if (hapd->conf->mld_ap && sta->mld_info.mld_sta) {
+               if (ap_sta_is_mld(hapd, sta)) {
                        if (sta->mld_assoc_link_id == hapd->mld_link_id)
                                mld_assoc_link_id = sta->mld_assoc_link_id;
                        else
@@ -1757,7 +1757,7 @@ int ap_sta_re_add(struct hostapd_data *hapd, struct sta_info *sta)
         */
 
 #ifdef CONFIG_IEEE80211BE
-       if (hapd->conf->mld_ap && sta->mld_info.mld_sta) {
+       if (ap_sta_is_mld(hapd, sta)) {
                u8 mld_link_id = hapd->mld_link_id;
 
                mld_link_sta = sta->mld_assoc_link_id != mld_link_id;
index 64a1308ddff1dda510579981424f2978e734a2d0..ef60734813458cd5c3acb33f48f95cda63a770fb 100644 (file)
@@ -17,6 +17,7 @@
 #include "common/sae.h"
 #include "crypto/sha384.h"
 #include "pasn/pasn_common.h"
+#include "hostapd.h"
 
 /* STA flags */
 #define WLAN_STA_AUTH BIT(0)
@@ -419,4 +420,14 @@ int ap_sta_re_add(struct hostapd_data *hapd, struct sta_info *sta);
 
 void ap_free_sta_pasn(struct hostapd_data *hapd, struct sta_info *sta);
 
+static inline bool ap_sta_is_mld(struct hostapd_data *hapd,
+                                struct sta_info *sta)
+{
+#ifdef CONFIG_IEEE80211BE
+       return hapd->conf->mld_ap && sta && sta->mld_info.mld_sta;
+#else /* CONFIG_IEEE80211BE */
+       return false;
+#endif /* CONFIG_IEEE80211BE */
+}
+
 #endif /* STA_INFO_H */
index b5ce1d5ee688abb860e8e1dae4b752b0c11692db..b77e21bd15e34234e040ee166bff2b71b7455d6b 100644 (file)
@@ -50,7 +50,7 @@ static const u8 * wnm_ap_get_own_addr(struct hostapd_data *hapd,
        const u8 *own_addr = hapd->own_addr;
 
 #ifdef CONFIG_IEEE80211BE
-       if (hapd->conf->mld_ap && (!sta || sta->mld_info.mld_sta))
+       if (hapd->conf->mld_ap && (!sta || ap_sta_is_mld(hapd, sta)))
                own_addr = hapd->mld_addr;
 #endif /* CONFIG_IEEE80211BE */
 
@@ -1030,7 +1030,7 @@ int wnm_send_bss_tm_req(struct hostapd_data *hapd, struct sta_info *sta,
 
        if (disassoc_timer) {
 #ifdef CONFIG_IEEE80211BE
-               if (hapd->conf->mld_ap && sta->mld_info.mld_sta) {
+               if (ap_sta_is_mld(hapd, sta)) {
                        int i;
                        unsigned int links = 0;
 
index 5737ab8dced22884dc0d3c101ad6c4c7d4eb74b8..9ce58f24611aee6aa4c4c86aa1e37c46108352fe 100644 (file)
@@ -560,7 +560,8 @@ int hostapd_wpa_auth_send_eapol(void *ctx, const u8 *addr,
        if (sta) {
                flags = hostapd_sta_flags_to_drv(sta->flags);
 #ifdef CONFIG_IEEE80211BE
-               if (sta->mld_info.mld_sta && (sta->flags & WLAN_STA_AUTHORIZED))
+               if (ap_sta_is_mld(hapd, sta) &&
+                   (sta->flags & WLAN_STA_AUTHORIZED))
                        link_id = -1;
 #endif /* CONFIG_IEEE80211BE */
        }