From 2cbcc3a710c538966a1572463bf73189d14c36cf Mon Sep 17 00:00:00 2001 From: Sriram R Date: Tue, 21 Nov 2023 11:01:27 +0530 Subject: [PATCH 2/2] hostapd: Handle interface up/down for MLD When the interface is brought down, the kernel stops all the link bss and removes the link. This change adds support for hostapd to free all sta and make change to all hapd state. Similarly, on reenabling the interface we need to add all links and reenable the beacon back. Signed-off-by: Sriram R Co-developed-by: Aditya Kumar Singh Signed-off-by: Aditya Kumar Singh --- src/ap/drv_callbacks.c | 107 ++++++++++++++++++++++++++++++++--------- 1 file changed, 84 insertions(+), 23 deletions(-) --- a/src/ap/drv_callbacks.c +++ b/src/ap/drv_callbacks.c @@ -2091,6 +2091,84 @@ static void hostapd_eapol_tx_status(stru ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack); } +static void hostpad_if_disable(struct hostapd_data *hapd) +{ + hostapd_free_stas(hapd); + wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED); + hapd->disabled = 1; +} + + +static void hostpad_if_enable(struct hostapd_data *hapd) +{ + wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED); + if (hapd->disabled && hapd->started) { + hapd->disabled = 0; + /* + * Try to re-enable interface if the driver stopped it + * when the interface got disabled. + */ + hostapd_reconfig_wpa(hapd); + if (hapd->wpa_auth) + wpa_auth_reconfig_group_keys(hapd->wpa_auth); + else + hostapd_reconfig_encryption(hapd); + hapd->reenable_beacon = 1; + ieee802_11_set_beacon(hapd); +#ifdef NEED_AP_MLME + } else if (hapd->disabled && hapd->iface->cac_started) { + wpa_printf(MSG_DEBUG, "DFS: restarting pending CAC"); + hostapd_handle_dfs(hapd->iface); +#endif /* NEED_AP_MLME */ + } +} + + +static void hostapd_mld_if_disable(struct hostapd_data *hapd) +{ + struct hostapd_data *link_bss; + + for_each_partner_bss(link_bss, hapd) + hostpad_if_disable(link_bss); +} + + +static void hostapd_mld_if_enable(struct hostapd_data *hapd) +{ + struct hostapd_data *first_link, *link_bss; + + first_link = hostapd_mld_is_first_bss(hapd) ? hapd : + hostapd_mld_get_first_bss(hapd); + + /* Links are removed at this stage. Re-add all links and enable them. + * But enable first link BSS first. + */ + if (hostapd_drv_link_add(first_link, first_link->mld_link_id, + first_link->own_addr)) { + wpa_printf(MSG_ERROR, "MLD: Failed to re-add link %d in MLD %s", + first_link->mld_link_id, first_link->conf->iface); + return; + } + + hostpad_if_enable(first_link); + + /* add partners */ + for_each_partner_bss(link_bss, first_link) { + if (link_bss == first_link) + continue; + + if (hostapd_drv_link_add(link_bss, link_bss->mld_link_id, + link_bss->own_addr)) { + wpa_printf(MSG_ERROR, "MLD: Failed to re-add link %d in MLD %s", + link_bss->mld_link_id, link_bss->conf->iface); + continue; + } + + hostpad_if_enable(link_bss); + } +} + + void hostapd_wpa_event(void *ctx, enum wpa_event_type event, union wpa_event_data *data) { @@ -2301,31 +2379,16 @@ void hostapd_wpa_event(void *ctx, enum w break; #endif /* NEED_AP_MLME */ case EVENT_INTERFACE_ENABLED: - wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED); - if (hapd->disabled && hapd->started) { - hapd->disabled = 0; - /* - * Try to re-enable interface if the driver stopped it - * when the interface got disabled. - */ - hostapd_reconfig_wpa(hapd); - if (hapd->wpa_auth) - wpa_auth_reconfig_group_keys(hapd->wpa_auth); - else - hostapd_reconfig_encryption(hapd); - hapd->reenable_beacon = 1; - ieee802_11_set_beacon(hapd); -#ifdef NEED_AP_MLME - } else if (hapd->disabled && hapd->iface->cac_started) { - wpa_printf(MSG_DEBUG, "DFS: restarting pending CAC"); - hostapd_handle_dfs(hapd->iface); -#endif /* NEED_AP_MLME */ - } + if (hapd->conf->mld_ap) + hostapd_mld_if_enable(hapd); + else + hostpad_if_enable(hapd); break; case EVENT_INTERFACE_DISABLED: - hostapd_free_stas(hapd); - wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED); - hapd->disabled = 1; + if (hapd->conf->mld_ap) + hostapd_mld_if_disable(hapd); + else + hostpad_if_disable(hapd); break; #ifdef CONFIG_ACS case EVENT_ACS_CHANNEL_SELECTED: