From 5090eb33e0623cc8c1659d0df76ae558eba1b25f Mon Sep 17 00:00:00 2001 From: Ramanathan Choodamani Date: Thu, 20 Jul 2023 21:10:51 -0700 Subject: [PATCH] hostapd: Add bcast deauth before deinit The AP has to ideally send deauth frames to notify the associated STA about disconnection. If the AP fails to send deauth and goes down, STA still thinks it is associated with STA, until it sees a beacon miss. Adding this change makes the process little more efficient as we cannot rely only on STA to notice the missed beacon Signed-off-by: Ramanathan Choodamani --- hostapd/main.c | 2 ++ src/ap/hostapd.c | 26 ++++++++++++++++++++++++++ src/ap/hostapd.h | 1 + 3 files changed, 29 insertions(+) diff --git a/hostapd/main.c b/hostapd/main.c index bfd3039..b2cbf52 100644 --- a/hostapd/main.c +++ b/hostapd/main.c @@ -913,6 +913,8 @@ int main(int argc, char *argv[]) out: hostapd_ubus_free(&interfaces); hostapd_global_ctrl_iface_deinit(&interfaces); + /* Sending deauth to all stations before deinit */ + hostapd_deauthenticate_stations(&interfaces); /* Deinitialize all interfaces */ for (i = 0; i < interfaces.count; i++) { if (!interfaces.iface[i]) diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c index 2e0c89a..6770ea5 100644 --- a/src/ap/hostapd.c +++ b/src/ap/hostapd.c @@ -2901,6 +2901,32 @@ void hostapd_interface_deinit_free(struct hostapd_iface *iface) hostapd_interface_free(iface); } +void hostapd_deauthenticate_stations(struct hapd_interfaces *interfaces) +{ + int i, j; + struct hostapd_iface *iface; + struct hostapd_data *hapd; + u8 addr[ETH_ALEN]; + int reason = WLAN_REASON_DEAUTH_LEAVING; + + for (i = 0; i < interfaces->count; i++) { + if (!interfaces->iface[i]) + continue; + + iface = interfaces->iface[i]; + os_memset(addr, 0xff, ETH_ALEN); + for (j = 0; j < iface->num_bss; j++) { + hapd = iface->bss[j]; + if (!hapd) + continue; + wpa_dbg(hapd->msg_ctx, MSG_DEBUG, + "Sending deauth frame sa=" MACSTR "da=" MACSTR "reason=%d", + MAC2STR(hapd->own_addr), MAC2STR(addr), reason); + hostapd_drv_sta_deauth(hapd, addr, reason); + } + + } +} static void hostapd_deinit_driver(const struct wpa_driver_ops *driver, void *drv_priv, diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h index 1edb5de..0669f00 100644 --- a/src/ap/hostapd.h +++ b/src/ap/hostapd.h @@ -705,6 +705,7 @@ hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy, void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta, int reassoc); void hostapd_interface_deinit_free(struct hostapd_iface *iface); +void hostapd_deauthenticate_stations(struct hapd_interfaces *interfaces); int hostapd_enable_iface(struct hostapd_iface *hapd_iface); int hostapd_reload_iface(struct hostapd_iface *hapd_iface); int hostapd_reload_bss_only(struct hostapd_data *bss);