diff mbox series

[v4] do not perform CSA on disabled BSS.

Message ID 20240129122617.3605470-1-gasmibal@gmail.com
State New
Headers show
Series [v4] do not perform CSA on disabled BSS. | expand

Commit Message

Baligh Gasmi gasmibal@gmail.com Jan. 29, 2024, 12:26 p.m. UTC
It is useless to perform a channel switch, by announcing the new channel
information: CSA (Channel Switch Announcement), if the BSS is not running.

Signed-off-by: Baligh Gasmi <gasmibal@gmail.com>
---
 hostapd/ctrl_iface.c         |  4 ++--
 src/ap/drv_callbacks.c       |  6 ++++--
 src/drivers/driver_nl80211.c | 25 +++++++++++++++----------
 3 files changed, 21 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
index 2ba9856b4..4001462bb 100644
--- a/hostapd/ctrl_iface.c
+++ b/hostapd/ctrl_iface.c
@@ -2720,14 +2720,14 @@  static int hostapd_ctrl_iface_chan_switch(struct hostapd_iface *iface,
 					   &settings.freq_params);
 
 		ret = hostapd_switch_channel(iface->bss[i], &settings);
-		if (ret) {
+		if (ret && !iface->bss[i]->disabled) {
 			/* FIX: What do we do if CSA fails in the middle of
 			 * submitting multi-BSS CSA requests? */
 			return ret;
 		}
 	}
 
-	return 0;
+	return !hostapd_csa_in_progress(iface);
 #else /* NEED_AP_MLME */
 	return -1;
 #endif /* NEED_AP_MLME */
diff --git a/src/ap/drv_callbacks.c b/src/ap/drv_callbacks.c
index 39deacd3d..e41c2567a 100644
--- a/src/ap/drv_callbacks.c
+++ b/src/ap/drv_callbacks.c
@@ -2493,9 +2493,11 @@  void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
 		}
 		break;
 	case EVENT_INTERFACE_DISABLED:
-		hostapd_free_stas(hapd);
 		wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED);
-		hapd->disabled = 1;
+		if (!hapd->disabled) {
+			hostapd_free_stas(hapd);
+			hapd->disabled = 1;
+		}
 		break;
 #ifdef CONFIG_ACS
 	case EVENT_ACS_CHANNEL_SELECTED:
diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index 70adaca54..5e2d8b207 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -1293,6 +1293,7 @@  static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
 	char ifname[IFNAMSIZ + 1];
 	char extra[100], *pos, *end;
 	int init_failed;
+	struct i802_bss* bss = NULL;
 
 	extra[0] = '\0';
 	pos = extra;
@@ -1343,7 +1344,7 @@  static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
 	if (init_failed)
 		return; /* do not update interface state */
 
-	if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) {
+	if (!(ifi->ifi_flags & IFF_UP)) {
 		namebuf[0] = '\0';
 		if (if_indextoname(ifi->ifi_index, namebuf) &&
 		    linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) {
@@ -1357,14 +1358,16 @@  static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
 		wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)",
 			   namebuf, ifname);
 		if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
-			wpa_printf(MSG_DEBUG,
-				   "nl80211: Not the main interface (%s) - do not indicate interface down",
-				   drv->first_bss->ifname);
+			bss = get_bss_ifindex(drv, ifi->ifi_index);
+			if(bss) {
+				wpa_supplicant_event(bss->ctx, EVENT_INTERFACE_DISABLED,
+						NULL);
+			}
 		} else if (drv->ignore_if_down_event) {
 			wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
 				   "event generated by mode change");
 			drv->ignore_if_down_event = 0;
-		} else {
+		} else if(!drv->if_disabled) {
 			drv->if_disabled = 1;
 			wpa_supplicant_event(drv->ctx,
 					     EVENT_INTERFACE_DISABLED, NULL);
@@ -1381,7 +1384,7 @@  static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
 		}
 	}
 
-	if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) {
+	if (ifi->ifi_flags & IFF_UP) {
 		namebuf[0] = '\0';
 		if (if_indextoname(ifi->ifi_index, namebuf) &&
 		    linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) {
@@ -1393,9 +1396,11 @@  static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
 		wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)",
 			   namebuf, ifname);
 		if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
-			wpa_printf(MSG_DEBUG,
-				   "nl80211: Not the main interface (%s) - do not indicate interface up",
-				   drv->first_bss->ifname);
+			bss = get_bss_ifindex(drv, ifi->ifi_index);
+			if(bss) {
+				wpa_supplicant_event(bss->ctx, EVENT_INTERFACE_ENABLED,
+						NULL);
+			}
 		} else if (if_nametoindex(drv->first_bss->ifname) == 0) {
 			wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
 				   "event since interface %s does not exist",
@@ -1404,7 +1409,7 @@  static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
 			wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
 				   "event since interface %s is marked "
 				   "removed", drv->first_bss->ifname);
-		} else {
+		} else if(drv->if_disabled) {
 			/* Re-read MAC address as it may have changed */
 			nl80211_refresh_mac(drv, ifi->ifi_index, 0);