[PATCH v2] supplicant: Allow simple bgscan to do btm queries.

greearb at candelatech.com greearb at candelatech.com
Sun Nov 26 10:22:29 PST 2023


From: Ben Greear <greearb at candelatech.com>

Allow doing X bss_transition_mgmt_query calls before falling back to
scan.

Example format to do 4 btm before attempting a scan: bgscan="simple:30:-65:300:4"

Signed-off-by: Ben Greear <greearb at candelatech.com>
---

v2:  Check ext capabilities before trying BTM query
     Schedule new timeout in case we do BTM query.

 wpa_supplicant/bgscan_simple.c     | 38 ++++++++++++++++++++++++++++++
 wpa_supplicant/wpa_supplicant.conf |  5 ++--
 2 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/wpa_supplicant/bgscan_simple.c b/wpa_supplicant/bgscan_simple.c
index f3127980e..cf5dd5773 100644
--- a/wpa_supplicant/bgscan_simple.c
+++ b/wpa_supplicant/bgscan_simple.c
@@ -16,10 +16,15 @@
 #include "driver_i.h"
 #include "scan.h"
 #include "bgscan.h"
+#include "config.h"
+#include "wnm_sta.h"
+#include "bss.h"
 
 struct bgscan_simple_data {
 	struct wpa_supplicant *wpa_s;
 	const struct wpa_ssid *ssid;
+	int use_btm_query;
+	unsigned int scan_action_count;
 	int scan_interval;
 	int signal_threshold;
 	int short_scan_count; /* counter for scans using short scan interval */
@@ -36,6 +41,31 @@ static void bgscan_simple_timeout(void *eloop_ctx, void *timeout_ctx)
 	struct wpa_supplicant *wpa_s = data->wpa_s;
 	struct wpa_driver_scan_params params;
 
+	if (wpa_s->current_bss &&
+	    wpa_bss_ext_capab(wpa_s->current_bss, WLAN_EXT_CAPAB_BSS_TRANSITION) &&
+	    data->use_btm_query && !wpa_s->conf->disable_btm) {
+		int mod;
+
+		/* try BTM x times, scan on x + 1 */
+		data->scan_action_count++;
+		mod = data->scan_action_count % (data->use_btm_query + 1);
+		if (mod < data->use_btm_query) {
+			wpa_printf(MSG_DEBUG, "bgscan simple: Send bss transition mgt query %d/%d",
+				   mod, data->use_btm_query);
+			if (wnm_send_bss_transition_mgmt_query(wpa_s, 6 /* better AP found */, NULL, 0)) {
+				wpa_printf(MSG_DEBUG, "bgscan simple: Failed send bss transition mgt query");
+				/* Fall through and do regular scan */
+			} else {
+				/* start new timeout for next one.  We don't have scan callback to otherwise
+				 * trigger future progress when using BTM path.
+				 */
+				eloop_register_timeout(data->scan_interval, 0,
+						       bgscan_simple_timeout, data, NULL);
+				goto scan_ok;
+			}
+		}
+	}
+
 	os_memset(&params, 0, sizeof(params));
 	params.num_ssids = 1;
 	params.ssids[0].ssid = data->ssid->ssid;
@@ -58,6 +88,7 @@ static void bgscan_simple_timeout(void *eloop_ctx, void *timeout_ctx)
 		eloop_register_timeout(data->scan_interval, 0,
 				       bgscan_simple_timeout, data, NULL);
 	} else {
+	scan_ok:
 		if (data->scan_interval == data->short_interval) {
 			data->short_scan_count++;
 			if (data->short_scan_count >= data->max_short_scans) {
@@ -84,6 +115,8 @@ static int bgscan_simple_get_params(struct bgscan_simple_data *data,
 {
 	const char *pos;
 
+	data->use_btm_query = 0;
+
 	data->short_interval = atoi(params);
 
 	pos = os_strchr(params, ':');
@@ -99,6 +132,11 @@ static int bgscan_simple_get_params(struct bgscan_simple_data *data,
 	}
 	pos++;
 	data->long_interval = atoi(pos);
+	pos = os_strchr(pos, ':');
+	if (pos) {
+		pos++;
+		data->use_btm_query = atoi(pos);
+	}
 
 	return 0;
 }
diff --git a/wpa_supplicant/wpa_supplicant.conf b/wpa_supplicant/wpa_supplicant.conf
index 420a62d4d..4285e95fa 100644
--- a/wpa_supplicant/wpa_supplicant.conf
+++ b/wpa_supplicant/wpa_supplicant.conf
@@ -1029,9 +1029,10 @@ fast_reauth=1
 # parameter uses following format: "<bgscan module name>:<module parameters>"
 # Following bgscan modules are available:
 # simple - Periodic background scans based on signal strength
+# send_btm_query > 0 means do this many BTM queries before attempting a scan.
 # bgscan="simple:<short bgscan interval in seconds>:<signal strength threshold>:
-# <long interval>"
-# bgscan="simple:30:-45:300"
+# <long interval>:<send_btm_query>"
+# bgscan="simple:30:-45:300:3"
 # learn - Learn channels used by the network and try to avoid bgscans on other
 # channels (experimental)
 # bgscan="learn:<short bgscan interval in seconds>:<signal strength threshold>:
-- 
2.40.1




More information about the Hostap mailing list