From a29b71242f23d69d00a800cb647eae53e4f804b1 Mon Sep 17 00:00:00 2001 From: Aditya Kumar Singh Date: Sat, 25 Nov 2023 15:12:57 +0530 Subject: [PATCH 2/2] hostapd: MLO: use MLD struct for MLD level info MLD level structure is present to store the MLD level info. Add changes to use MLD structure instead of its own BSS to get the MLD level info. Signed-off-by: Aditya Kumar Singh --- hostapd/ctrl_iface.c | 2 +- hostapd/main.c | 19 +++++++------------ src/ap/authsrv.c | 14 +++++++------- src/ap/ctrl_iface_ap.c | 2 +- src/ap/drv_callbacks.c | 4 ++-- src/ap/hostapd.c | 16 ++++++++-------- src/ap/hostapd.h | 7 +------ src/ap/ieee802_11.c | 16 ++++++++-------- src/ap/ieee802_11_eht.c | 4 ++-- src/ap/ieee802_1x.c | 6 +++--- 10 files changed, 40 insertions(+), 50 deletions(-) --- a/hostapd/ctrl_iface.c +++ b/hostapd/ctrl_iface.c @@ -1928,7 +1928,7 @@ static int hostapd_ctrl_iface_data_test_ #ifdef CONFIG_IEEE80211BE if (hapd->conf->mld_ap) - addr = hapd->mld_addr; + addr = hapd->mld->mld_addr; #endif /* CONFIG_IEEE80211BE */ hapd->l2_test = l2_packet_init(ifname, addr, ETHERTYPE_IP, hostapd_data_test_rx, --- a/hostapd/main.c +++ b/hostapd/main.c @@ -214,20 +214,15 @@ static int hostapd_driver_init(struct ho * is not configured, and otherwise it would be the * configured BSSID. */ - os_memcpy(hapd->mld_addr, h_hapd->mld_addr, ETH_ALEN); if (is_zero_ether_addr(b)) { - os_memcpy(hapd->own_addr, h_hapd->mld_addr, ETH_ALEN); + os_memcpy(hapd->own_addr, h_hapd->mld->mld_addr, ETH_ALEN); random_mac_addr_keep_oui(hapd->own_addr); } else { os_memcpy(hapd->own_addr, b, ETH_ALEN); } - /* - * Mark the interface as a secondary interface, as this - * is needed for the de-initialization flow - */ - hapd->mld_first_bss = h_hapd; - hapd->mld_link_id = hapd->mld_first_bss->mld_next_link_id++; + hapd->mld_link_id = hapd->mld->next_link_id++; + hostapd_mld_add_link(hapd); goto setup_mld; } @@ -294,10 +289,10 @@ static int hostapd_driver_init(struct ho * to this interface. */ if (hapd->conf->mld_ap) { - os_memcpy(hapd->mld_addr, hapd->own_addr, ETH_ALEN); + os_memcpy(hapd->mld->mld_addr, hapd->own_addr, ETH_ALEN); random_mac_addr_keep_oui(hapd->own_addr); - hapd->mld_next_link_id = 0; - hapd->mld_link_id = hapd->mld_next_link_id++; + hapd->mld_link_id = hapd->mld->next_link_id++; + hostapd_mld_add_link(hapd); } setup_mld: @@ -350,7 +345,7 @@ setup_mld: wpa_printf(MSG_DEBUG, "MLD: Set link_id=%u, mld_addr=" MACSTR ", own_addr=" MACSTR, - hapd->mld_link_id, MAC2STR(hapd->mld_addr), + hapd->mld_link_id, MAC2STR(hapd->mld->mld_addr), MAC2STR(hapd->own_addr)); hostapd_drv_link_add(hapd, hapd->mld_link_id, --- a/src/ap/authsrv.c +++ b/src/ap/authsrv.c @@ -107,13 +107,15 @@ static int hostapd_setup_radius_srv(stru struct radius_server_conf srv; struct hostapd_bss_config *conf = hapd->conf; - if (hapd->mld_first_bss) { +#ifdef CONFIG_IEEE80211BE + if (!hostapd_mld_is_first_bss(hapd)) { wpa_printf(MSG_DEBUG, "MLD: Using RADIUS server of the first BSS"); - hapd->radius_srv = hapd->mld_first_bss->radius_srv; + hapd->radius_srv = hostapd_mld_get_first_bss(hapd)->radius_srv; return 0; } +#endif /* CONFIG_IEEE80211BE */ os_memset(&srv, 0, sizeof(srv)); srv.client_file = conf->radius_server_clients; @@ -247,18 +249,20 @@ static struct eap_config * authsrv_eap_c int authsrv_init(struct hostapd_data *hapd) { - if (hapd->mld_first_bss) { +#ifdef CONFIG_IEEE80211BE + if (!hostapd_mld_is_first_bss(hapd)) { wpa_printf(MSG_DEBUG, "MLD: Using auth_serv of the first BSS"); #ifdef EAP_TLS_FUNCS - hapd->ssl_ctx = hapd->mld_first_bss->ssl_ctx; + hapd->ssl_ctx = hostapd_mld_get_first_bss(hapd)->ssl_ctx; #endif /* EAP_TLS_FUNCS */ - hapd->eap_cfg = hapd->mld_first_bss->eap_cfg; + hapd->eap_cfg = hostapd_mld_get_first_bss(hapd)->eap_cfg; #ifdef EAP_SIM_DB - hapd->eap_sim_db_priv = hapd->mld_first_bss->eap_sim_db_priv; + hapd->eap_sim_db_priv = hostapd_mld_get_first_bss(hapd)->eap_sim_db_priv; #endif /* EAP_SIM_DB */ return 0; } +#endif /* CONFIG_IEEE80211BE */ #ifdef EAP_TLS_FUNCS if (hapd->conf->eap_server && @@ -374,7 +378,8 @@ int authsrv_init(struct hostapd_data *ha void authsrv_deinit(struct hostapd_data *hapd) { - if (hapd->mld_first_bss) { +#ifdef CONFIG_IEEE80211BE + if (!hostapd_mld_is_first_bss(hapd)) { wpa_printf(MSG_DEBUG, "MLD: Deinit auth_serv of a non-first BSS"); @@ -388,6 +393,7 @@ void authsrv_deinit(struct hostapd_data #endif /* EAP_TLS_FUNCS */ return; } +#endif /* CONFIG_IEEE80211BE */ #ifdef RADIUS_SERVER radius_server_deinit(hapd->radius_srv); --- a/src/ap/ctrl_iface_ap.c +++ b/src/ap/ctrl_iface_ap.c @@ -1254,7 +1254,7 @@ int hostapd_ctrl_iface_status(struct hos "mld_addr[%d]=" MACSTR "\n" "mld_id[%d]=%d\n" "mld_link_id[%d]=%d\n", - (int) i, MAC2STR(bss->mld_addr), + (int) i, MAC2STR(bss->mld->mld_addr), (int) i, hostapd_get_mld_id(bss), (int) i, bss->mld_link_id); if (os_snprintf_error(buflen - len, ret)) --- a/src/ap/drv_callbacks.c +++ b/src/ap/drv_callbacks.c @@ -1513,7 +1513,7 @@ static int hostapd_mgmt_rx(struct hostap #ifdef CONFIG_IEEE80211BE if (hapd->conf->mld_ap && - os_memcmp(hapd->mld_addr, bssid, ETH_ALEN) == 0) + os_memcmp(hapd->mld->mld_addr, bssid, ETH_ALEN) == 0) is_mld = true; #endif /* CONFIG_IEEE80211BE */ @@ -1585,7 +1585,7 @@ static void hostapd_mgmt_tx_cb(struct ho hapd = tmp_hapd; #ifdef CONFIG_IEEE80211BE } else if (hapd->conf->mld_ap && - os_memcmp(hapd->mld_addr, get_hdr_bssid(hdr, len), + os_memcmp(hapd->mld->mld_addr, get_hdr_bssid(hdr, len), ETH_ALEN) == 0) { /* AP MLD address match - use hapd pointer as-is */ #endif /* CONFIG_IEEE80211BE */ --- a/src/ap/hostapd.c +++ b/src/ap/hostapd.c @@ -476,6 +476,7 @@ static int hostapd_broadcast_wep_set(str static void hostapd_clear_drv_priv(struct hostapd_data *hapd) { +#ifdef CONFIG_IEEE80211BE unsigned int i; for (i = 0; i < hapd->iface->interfaces->count; i++) { @@ -485,9 +486,10 @@ static void hostapd_clear_drv_priv(struc continue; if (iface->bss && iface->bss[0] && - iface->bss[0]->mld_first_bss == hapd) + hostapd_mld_get_first_bss(iface->bss[0]) == hapd) iface->bss[0]->drv_priv = NULL; } +#endif /* CONFIG_IEEE80211BE */ hapd->drv_priv = NULL; } @@ -521,10 +523,14 @@ void hostapd_free_hapd_data(struct hosta vlan_deinit(hapd); hostapd_acl_deinit(hapd); #ifndef CONFIG_NO_RADIUS - if (!hapd->mld_first_bss) { +#ifdef CONFIG_IEEE80211BE + if (hostapd_mld_is_first_bss(hapd)) { +#endif /* CONFIG_IEEE80211BE */ radius_client_deinit(hapd->radius); radius_das_deinit(hapd->radius_das); +#ifdef CONFIG_IEEE80211BE } +#endif /* CONFIG_IEEE80211BE */ hapd->radius = NULL; hapd->radius_das = NULL; #endif /* CONFIG_NO_RADIUS */ @@ -1301,9 +1307,11 @@ static int hostapd_setup_bss(struct host u8 if_addr[ETH_ALEN]; int flush_old_stations = 1; - if (hapd->mld_first_bss) +#ifdef CONFIG_IEEE80211BE + if (!hostapd_mld_is_first_bss(hapd)) wpa_printf(MSG_DEBUG, "MLD: %s: Setting non-first BSS", __func__); +#endif /* CONFIG_IEEE80211BE */ wpa_printf(MSG_DEBUG, "%s(hapd=%p (%s), first=%d)", __func__, hapd, conf->iface, first); @@ -1466,7 +1474,9 @@ static int hostapd_setup_bss(struct host } #endif /* CONFIG_SQLITE */ - if (!hapd->mld_first_bss) { +#ifdef CONFIG_IEEE80211BE + if (hostapd_mld_is_first_bss(hapd)) { +#endif /* CONFIG_IEEE80211BE */ hapd->radius = radius_client_init(hapd, conf->radius); if (!hapd->radius) { wpa_printf(MSG_ERROR, @@ -1499,12 +1509,14 @@ static int hostapd_setup_bss(struct host return -1; } } +#ifdef CONFIG_IEEE80211BE } else { wpa_printf(MSG_DEBUG, "MLD: Using RADIUS client of the first BSS"); - hapd->radius = hapd->mld_first_bss->radius; - hapd->radius_das = hapd->mld_first_bss->radius_das; + hapd->radius = hostapd_mld_get_first_bss(hapd)->radius; + hapd->radius_das = hostapd_mld_get_first_bss(hapd)->radius_das; } +#endif /* CONFIG_IEEE80211BE */ #endif /* CONFIG_NO_RADIUS */ if (hostapd_acl_init(hapd)) { @@ -3153,7 +3165,9 @@ void hostapd_interface_deinit_free(struc wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit", __func__, driver, drv_priv); if (driver && driver->hapd_deinit && drv_priv) { - if (!iface->bss[0]->mld_first_bss) +#ifdef CONFIG_IEEE80211BE + if (hostapd_mld_is_first_bss(iface->bss[0])) +#endif /* CONFIG_IEEE80211BE */ driver->hapd_deinit(drv_priv); hostapd_clear_drv_priv(iface->bss[0]); } @@ -3196,7 +3210,9 @@ static void hostapd_deinit_driver(const wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit", __func__, driver, drv_priv); if (driver && driver->hapd_deinit && drv_priv) { - if (!hapd_iface->bss[0]->mld_first_bss) +#ifdef CONFIG_IEEE80211BE + if (hostapd_mld_is_first_bss(iface->bss[0])) +#endif /* CONFIG_IEEE80211BE */ driver->hapd_deinit(drv_priv); for (j = 0; j < hapd_iface->num_bss; j++) { wpa_printf(MSG_DEBUG, "%s:bss[%d]->drv_priv=%p", --- a/src/ap/hostapd.h +++ b/src/ap/hostapd.h @@ -201,12 +201,6 @@ struct hostapd_data { unsigned int reenable_beacon:1; u8 own_addr[ETH_ALEN]; - u8 mld_addr[ETH_ALEN]; - u8 mld_link_id; - /* Used for mld_link_id assignment - valid on the first MLD BSS only */ - u8 mld_next_link_id; - - struct hostapd_data *mld_first_bss; /* OpenWrt specific statistics */ struct hostapd_openwrt_stats openwrt_stats; @@ -505,6 +499,7 @@ struct hostapd_data { #ifdef CONFIG_IEEE80211BE struct hostapd_mld *mld; struct dl_list link; + u8 mld_link_id; #endif /* CONFIG_IEEE80211BE */ }; --- a/src/ap/ieee802_11.c +++ b/src/ap/ieee802_11.c @@ -416,7 +416,7 @@ static int send_auth_reply(struct hostap * the addresses. */ if (hapd->conf->mld_ap && sta && sta->mld_info.mld_sta) { - sa = hapd->mld_addr; + sa = hapd->mld->mld_addr; ml_resp = hostapd_ml_auth_resp(hapd); if (!ml_resp) @@ -616,7 +616,7 @@ static struct wpabuf * auth_build_sae_co #ifdef CONFIG_IEEE80211BE if (hapd->conf->mld_ap && sta->mld_info.mld_sta) - own_addr = hapd->mld_addr; + own_addr = hapd->mld->mld_addr; #endif /* CONFIG_IEEE80211BE */ if (sta->sae->tmp) { @@ -2919,7 +2919,7 @@ static void handle_auth(struct hostapd_d if (mld_sta && (os_memcmp(sa, hapd->own_addr, ETH_ALEN) == 0 || - os_memcmp(sa, hapd->mld_addr, ETH_ALEN) == 0)) { + os_memcmp(sa, hapd->mld->mld_addr, ETH_ALEN) == 0)) { wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate", MAC2STR(sa)); @@ -3240,7 +3240,7 @@ static void handle_auth(struct hostapd_d */ if (hapd->conf->mld_ap && sta && sta->mld_info.mld_sta) { dst = sta->addr; - bssid = hapd->mld_addr; + bssid = hapd->mld->mld_addr; } #endif /* CONFIG_IEEE80211BE */ @@ -4022,7 +4022,7 @@ static int __check_assoc_ies(struct host wpa_printf(MSG_DEBUG, "MLD: Set ML info in RSN Authenticator"); wpa_auth_set_ml_info(sta->wpa_sm, - hapd->mld_addr, + hapd->mld->mld_addr, sta->mld_assoc_link_id, info); } @@ -4779,7 +4779,7 @@ static u16 send_assoc_resp(struct hostap * MLD MAC address. */ if (hapd->conf->mld_ap && sta && sta->mld_info.mld_sta) - sa = hapd->mld_addr; + sa = hapd->mld->mld_addr; #endif /* CONFIG_IEEE80211BE */ os_memcpy(reply->da, addr, ETH_ALEN); @@ -6144,7 +6144,7 @@ int ieee802_11_mgmt(struct hostapd_data #endif /* CONFIG_MESH */ #ifdef CONFIG_IEEE80211BE !(hapd->conf->mld_ap && - os_memcmp(hapd->mld_addr, mgmt->bssid, ETH_ALEN) == 0) && + os_memcmp(hapd->mld->mld_addr, mgmt->bssid, ETH_ALEN) == 0) && #endif /* CONFIG_IEEE80211BE */ os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) { wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address", @@ -6167,7 +6167,7 @@ int ieee802_11_mgmt(struct hostapd_data stype != WLAN_FC_STYPE_ACTION) && #ifdef CONFIG_IEEE80211BE !(hapd->conf->mld_ap && - os_memcmp(hapd->mld_addr, mgmt->bssid, ETH_ALEN) == 0) && + os_memcmp(hapd->mld->mld_addr, mgmt->bssid, ETH_ALEN) == 0) && #endif /* CONFIG_IEEE80211BE */ os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) { hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, --- a/src/ap/ieee802_11_eht.c +++ b/src/ap/ieee802_11_eht.c @@ -592,7 +592,7 @@ u8 * hostapd_eid_eht_basic_ml(struct hos wpabuf_put_u8(buf, common_info_len); /* Own MLD MAC Address */ - wpabuf_put_data(buf, hapd->mld_addr, ETH_ALEN); + wpabuf_put_data(buf, hapd->mld->mld_addr, ETH_ALEN); /* Own Link ID */ wpabuf_put_u8(buf, hapd->mld_link_id); @@ -762,7 +762,7 @@ struct wpabuf * hostapd_ml_auth_resp(str wpabuf_put_u8(buf, WLAN_EID_EXT_MULTI_LINK); wpabuf_put_le16(buf, MULTI_LINK_CONTROL_TYPE_BASIC); wpabuf_put_u8(buf, ETH_ALEN + 1); - wpabuf_put_data(buf, hapd->mld_addr, ETH_ALEN); + wpabuf_put_data(buf, hapd->mld->mld_addr, ETH_ALEN); return buf; } --- a/src/ap/ieee802_1x.c +++ b/src/ap/ieee802_1x.c @@ -2540,13 +2540,15 @@ int ieee802_1x_init(struct hostapd_data struct eapol_auth_config conf; struct eapol_auth_cb cb; - if (hapd->mld_first_bss) { +#ifdef CONFIG_IEEE80211BE + if (!hostapd_mld_is_first_bss(hapd)) { wpa_printf(MSG_DEBUG, "MLD: Using IEEE 802.1X state machine of the first BSS"); - hapd->eapol_auth = hapd->mld_first_bss->eapol_auth; + hapd->eapol_auth = hostapd_mld_get_first_bss(hapd)->eapol_auth; return 0; } +#endif /* CONFIG_IEEE80211BE */ dl_list_init(&hapd->erp_keys); @@ -2632,13 +2634,15 @@ void ieee802_1x_erp_flush(struct hostapd void ieee802_1x_deinit(struct hostapd_data *hapd) { - if (hapd->mld_first_bss) { +#ifdef CONFIG_IEEE80211BE + if (!hostapd_mld_is_first_bss(hapd)) { wpa_printf(MSG_DEBUG, "MLD: Deinit IEEE 802.1X state machine of a non-first BSS"); hapd->eapol_auth = NULL; return; } +#endif /* CONFIG_IEEE80211BE */ #ifdef CONFIG_WEP eloop_cancel_timeout(ieee802_1x_rekey, hapd, NULL);