All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 1/3] util: add scan_freq_set_copy_bands
@ 2022-08-04 22:02 James Prestwood
  2022-08-04 22:02 ` [PATCH v4 2/3] scan: split full scans by band to enable 6GHz James Prestwood
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: James Prestwood @ 2022-08-04 22:02 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

This creates a new scan_freq_set from an input set which only contains
frequencies from bands included in the mask.
---
 src/util.c | 21 +++++++++++++++++++++
 src/util.h |  2 ++
 2 files changed, 23 insertions(+)

diff --git a/src/util.c b/src/util.c
index ebaff6a0..64d85cbc 100644
--- a/src/util.c
+++ b/src/util.c
@@ -554,3 +554,24 @@ uint32_t *scan_freq_set_to_fixed_array(const struct scan_freq_set *set,
 
 	return freqs;
 }
+
+struct scan_freq_set *scan_freq_set_copy_bands(const struct scan_freq_set *set,
+						uint32_t band_mask)
+{
+	struct scan_freq_set *new = l_new(struct scan_freq_set, 1);
+
+	if (band_mask & BAND_FREQ_2_4_GHZ)
+		new->channels_2ghz = set->channels_2ghz;
+
+	if (band_mask & BAND_FREQ_5_GHZ)
+		new->channels_5ghz = l_uintset_clone(set->channels_5ghz);
+	else
+		new->channels_5ghz = l_uintset_new_from_range(1, 200);
+
+	if (band_mask & BAND_FREQ_6_GHZ)
+		new->channels_6ghz = l_uintset_clone(set->channels_6ghz);
+	else
+		new->channels_6ghz = l_uintset_new_from_range(1, 233);
+
+	return new;
+}
diff --git a/src/util.h b/src/util.h
index 0b7832fb..9d3ec604 100644
--- a/src/util.h
+++ b/src/util.h
@@ -123,5 +123,7 @@ void scan_freq_set_subtract(struct scan_freq_set *set,
 bool scan_freq_set_isempty(const struct scan_freq_set *set);
 uint32_t *scan_freq_set_to_fixed_array(const struct scan_freq_set *set,
 					size_t *len_out);
+struct scan_freq_set *scan_freq_set_copy_bands(const struct scan_freq_set *set,
+						uint32_t band_mask);
 
 #endif /* __UTIL_H */
-- 
2.34.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v4 2/3] scan: split full scans by band to enable 6GHz
  2022-08-04 22:02 [PATCH v4 1/3] util: add scan_freq_set_copy_bands James Prestwood
@ 2022-08-04 22:02 ` James Prestwood
  2022-08-05 17:03   ` Denis Kenzior
  2022-08-04 22:02 ` [PATCH v4 3/3] scan: watch for regdom updates " James Prestwood
  2022-08-05 16:54 ` [PATCH v4 1/3] util: add scan_freq_set_copy_bands Denis Kenzior
  2 siblings, 1 reply; 5+ messages in thread
From: James Prestwood @ 2022-08-04 22:02 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

The kernel's regulatory domain updates after some number of beacons
are processed. This triggers a regulatory domain update (and wiphy
dump) but only after a scan request. This means a full scan started
prior to the regdom being set will not include any 6Ghz BSS's even
if the regdom was unlocked during the scan.

This can be worked around by splitting up a large scan request into
multiple requests allowing one of the first commands to trigger a
regdom update. Once the regdom updates (and wiphy dumps) we are
hopefully still scanning and could append an additional request to
scan 6GHz.
---
 src/scan.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 76 insertions(+), 9 deletions(-)

v4:
 * Use scan_freq_set_copy_bands

diff --git a/src/scan.c b/src/scan.c
index b666ba2e..12c970a7 100644
--- a/src/scan.c
+++ b/src/scan.c
@@ -94,6 +94,8 @@ struct scan_request {
 	 */
 	bool triggered : 1;
 	bool in_callback : 1; /* Scan request complete, re-entrancy guard */
+	/* The request was split anticipating 6GHz will become available */
+	bool split : 1;
 	struct l_queue *cmds;
 	/* The time the current scan was started. Reported in TRIGGER_SCAN */
 	uint64_t start_time_tsf;
@@ -352,9 +354,24 @@ static bool scan_mac_address_randomization_is_disabled(void)
 	return disabled;
 }
 
+static struct scan_freq_set *scan_get_allowed_freqs(struct scan_context *sc)
+{
+	struct scan_freq_set *allowed = scan_freq_set_new();
+
+	scan_freq_set_merge(allowed, wiphy_get_supported_freqs(sc->wiphy));
+
+	if (!wiphy_constrain_freq_set(sc->wiphy, allowed)) {
+		scan_freq_set_free(allowed);
+		allowed = NULL;
+	}
+
+	return allowed;
+}
+
 static struct l_genl_msg *scan_build_cmd(struct scan_context *sc,
 					bool ignore_flush_flag, bool is_passive,
-					const struct scan_parameters *params)
+					const struct scan_parameters *params,
+					const struct scan_freq_set *freqs)
 {
 	struct l_genl_msg *msg;
 	uint32_t flags = 0;
@@ -366,8 +383,8 @@ static struct l_genl_msg *scan_build_cmd(struct scan_context *sc,
 	if (wiphy_get_max_scan_ie_len(sc->wiphy))
 		scan_build_attr_ie(msg, sc, params);
 
-	if (params->freqs)
-		scan_build_attr_scan_frequencies(msg, params->freqs);
+	if (freqs)
+		scan_build_attr_scan_frequencies(msg, freqs);
 
 	if (params->flush && !ignore_flush_flag && wiphy_has_feature(sc->wiphy,
 						NL80211_FEATURE_SCAN_FLUSH))
@@ -524,16 +541,18 @@ static bool scan_cmds_add_hidden(const struct network_info *network,
 		 * of all scans in the batch after the last scan is finished.
 		 */
 		*data->cmd = scan_build_cmd(data->sc, true, false,
-								data->params);
+							data->params,
+							data->params->freqs);
 		l_genl_msg_enter_nested(*data->cmd, NL80211_ATTR_SCAN_SSIDS);
 	}
 
 	return true;
 }
 
-static void scan_cmds_add(struct l_queue *cmds, struct scan_context *sc,
+static void scan_build_next_cmd(struct l_queue *cmds, struct scan_context *sc,
 				bool passive,
-				const struct scan_parameters *params)
+				const struct scan_parameters *params,
+				const struct scan_freq_set *freqs)
 {
 	struct l_genl_msg *cmd;
 	struct scan_cmds_add_data data = {
@@ -544,7 +563,7 @@ static void scan_cmds_add(struct l_queue *cmds, struct scan_context *sc,
 		wiphy_get_max_num_ssids_per_scan(sc->wiphy),
 	};
 
-	cmd = scan_build_cmd(sc, false, passive, params);
+	cmd = scan_build_cmd(sc, false, passive, params, freqs);
 
 	if (passive) {
 		/* passive scan */
@@ -572,6 +591,54 @@ static void scan_cmds_add(struct l_queue *cmds, struct scan_context *sc,
 	l_queue_push_tail(cmds, cmd);
 }
 
+static void scan_cmds_add(struct scan_request *sr, struct scan_context *sc,
+				bool passive,
+				const struct scan_parameters *params)
+{
+	unsigned int i;
+	struct scan_freq_set *subsets[2] = { 0 };
+	struct scan_freq_set *allowed = scan_get_allowed_freqs(sc);
+	const struct scan_freq_set *supported =
+					wiphy_get_supported_freqs(sc->wiphy);
+
+	/*
+	 * If 6GHz is not possible, or already allowed, or the frequencies are
+	 * explicit don't break up the request.
+	 */
+	if (!(scan_freq_set_get_bands(supported) & BAND_FREQ_6_GHZ) ||
+			(scan_freq_set_get_bands(allowed) & BAND_FREQ_6_GHZ) ||
+			params->freqs) {
+		scan_freq_set_free(allowed);
+		scan_build_next_cmd(sr->cmds, sc, passive, params, params->freqs);
+		return;
+	}
+
+	/*
+	 * Otherwise a full spectrum scan will likely open up the 6GHz
+	 * band. The problem is the regdom update occurs after an
+	 * individual scan request so a single request isn't going to
+	 * include potential 6GHz results.
+	 *
+	 * Instead we can break this full scan up into individual bands
+	 * and increase our chances of the regdom updating after one of
+	 * the earlier requests. If it does update to allow 6GHz an
+	 * extra 6GHz-only passive scan can be appended to this request
+	 * at that time.
+	 */
+	subsets[0] = scan_freq_set_copy_bands(allowed, BAND_FREQ_2_4_GHZ);
+	subsets[1] = scan_freq_set_copy_bands(allowed, BAND_FREQ_5_GHZ);
+
+	scan_freq_set_free(allowed);
+
+	for(i = 0; i < L_ARRAY_SIZE(subsets); i++) {
+		scan_build_next_cmd(sr->cmds, sc, passive, params,
+					subsets[i]);
+		scan_freq_set_free(subsets[i]);
+	}
+
+	sr->split = true;
+}
+
 static int scan_request_send_trigger(struct scan_context *sc,
 					struct scan_request *sr)
 {
@@ -649,7 +716,7 @@ static uint32_t scan_common(uint64_t wdev_id, bool passive,
 
 	sr = scan_request_new(sc, passive, trigger, notify, userdata, destroy);
 
-	scan_cmds_add(sr->cmds, sc, passive, params);
+	scan_cmds_add(sr, sc, passive, params);
 
 	/*
 	 * sr->work isn't initialized yet, it will be done by
@@ -743,7 +810,7 @@ static void add_owe_scan_cmd(struct scan_context *sc, struct scan_request *sr,
 	params.ssid_len = bss->owe_trans->ssid_len;
 	params.flush = true;
 
-	cmd = scan_build_cmd(sc, ignore_flush, false, &params);
+	cmd = scan_build_cmd(sc, ignore_flush, false, &params, params.freqs);
 
 	l_genl_msg_enter_nested(cmd, NL80211_ATTR_SCAN_SSIDS);
 	l_genl_msg_append_attr(cmd, 0, params.ssid_len, params.ssid);
-- 
2.34.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v4 3/3] scan: watch for regdom updates to enable 6GHz
  2022-08-04 22:02 [PATCH v4 1/3] util: add scan_freq_set_copy_bands James Prestwood
  2022-08-04 22:02 ` [PATCH v4 2/3] scan: split full scans by band to enable 6GHz James Prestwood
@ 2022-08-04 22:02 ` James Prestwood
  2022-08-05 16:54 ` [PATCH v4 1/3] util: add scan_freq_set_copy_bands Denis Kenzior
  2 siblings, 0 replies; 5+ messages in thread
From: James Prestwood @ 2022-08-04 22:02 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

This functionality works around the kernel's behavior of allowing
6GHz only after a regulatory domain update. If the regdom updates
scan.c needs to be aware in order to split up periodic scans, or
insert 6GHz frequencies into an ongoing periodic scan. Doing this
allows any 6GHz BSS's to show up in the scan results rather than
needing to issue an entirely new scan to see these BSS's.
---
 src/scan.c | 146 +++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 114 insertions(+), 32 deletions(-)

v4:
 * Remove wait_for_regdom/expect_6ghz flags. This reduced the complexity
   and avoided the need to even check for the STARTED regdom event.
 * Fixed issue where a periodic scan waiting on the regdom wasn't parsing
   the NEW_SCAN_RESULT frequencies before bailing out of the notify callback
 * Fixed issue where a periodic scan was not finished if a new scan command
   was not appended.

diff --git a/src/scan.c b/src/scan.c
index 12c970a7..d044e80c 100644
--- a/src/scan.c
+++ b/src/scan.c
@@ -110,6 +110,7 @@ struct scan_request {
 
 struct scan_context {
 	uint64_t wdev_id;
+	uint32_t wiphy_watch_id;
 	/*
 	 * Tells us whether a scan, our own or external, is running.
 	 * Set when scan gets triggered, cleared when scan done and
@@ -186,24 +187,6 @@ static void scan_request_failed(struct scan_context *sc,
 	wiphy_radio_work_done(sc->wiphy, sr->work.id);
 }
 
-static struct scan_context *scan_context_new(uint64_t wdev_id)
-{
-	struct wiphy *wiphy = wiphy_find_by_wdev(wdev_id);
-	struct scan_context *sc;
-
-	if (!wiphy)
-		return NULL;
-
-	sc = l_new(struct scan_context, 1);
-
-	sc->wdev_id = wdev_id;
-	sc->wiphy = wiphy;
-	sc->state = SCAN_STATE_NOT_RUNNING;
-	sc->requests = l_queue_new();
-
-	return sc;
-}
-
 static void scan_request_cancel(void *data)
 {
 	struct scan_request *sr = data;
@@ -229,6 +212,8 @@ static void scan_context_free(struct scan_context *sc)
 	if (sc->get_fw_scan_cmd_id && nl80211)
 		l_genl_family_cancel(nl80211, sc->get_fw_scan_cmd_id);
 
+	wiphy_state_watch_remove(sc->wiphy, sc->wiphy_watch_id);
+
 	l_free(sc);
 }
 
@@ -2006,6 +1991,108 @@ static void get_scan_done(void *user)
 	l_free(results);
 }
 
+static void scan_get_results(struct scan_context *sc, struct scan_request *sr)
+{
+	struct scan_results *results;
+	struct l_genl_msg *scan_msg;
+
+	results = l_new(struct scan_results, 1);
+	results->sc = sc;
+	results->time_stamp = l_time_now();
+	results->sr = sr;
+	results->bss_list = l_queue_new();
+
+	scan_msg = l_genl_msg_new_sized(NL80211_CMD_GET_SCAN, 8);
+
+	l_genl_msg_append_attr(scan_msg, NL80211_ATTR_WDEV, 8,
+					&sc->wdev_id);
+	sc->get_scan_cmd_id = l_genl_family_dump(nl80211, scan_msg,
+						get_scan_callback,
+						results, get_scan_done);
+}
+
+static void scan_wiphy_watch(struct wiphy *wiphy,
+				enum wiphy_state_watch_event event,
+				void *user_data)
+{
+	struct scan_context *sc = user_data;
+	struct scan_request *sr = NULL;
+	struct l_genl_msg *msg = NULL;
+	struct scan_parameters params = { 0 };
+	struct scan_freq_set *freqs_6ghz;
+	struct scan_freq_set *allowed;
+	bool allow_6g;
+	const struct scan_freq_set *supported =
+					wiphy_get_supported_freqs(wiphy);
+
+	/* Only care about regulatory events, and if 6GHz capable */
+	if (event != WIPHY_STATE_WATCH_EVENT_REGDOM_DONE ||
+			!(scan_freq_set_get_bands(supported) & BAND_FREQ_6_GHZ))
+		return;
+
+	if (!sc->sp.id)
+		return;
+
+	sr = l_queue_find(sc->requests, scan_request_match,
+						L_UINT_TO_PTR(sc->sp.id));
+	if (!sr)
+		return;
+
+	allowed = scan_get_allowed_freqs(sc);
+	allow_6g = scan_freq_set_get_bands(allowed) & BAND_FREQ_6_GHZ;
+
+	/*
+	 * This update did not allow 6GHz, or the original request was
+	 * not expecting 6GHz. The periodic scan should now be ended.
+	 */
+	if (!allow_6g || !sr->split) {
+		scan_get_results(sc, sr);
+		goto free_allowed;
+	}
+
+	/*
+	 * At this point we know there is an ongoing periodic scan.
+	 * Create a new 6GHz passive scan request and append to the
+	 * command list
+	 */
+	freqs_6ghz = scan_freq_set_copy_bands(allowed, BAND_FREQ_6_GHZ);
+
+	msg = scan_build_cmd(sc, false, true, &params, freqs_6ghz);
+	l_queue_push_tail(sr->cmds, msg);
+
+	scan_freq_set_free(freqs_6ghz);
+
+	/*
+	 * If this periodic scan is at the top of the queue, continue
+	 * running it.
+	 */
+	if (l_queue_peek_head(sc->requests) == sr)
+		start_next_scan_request(&sr->work);
+
+free_allowed:
+	scan_freq_set_free(allowed);
+}
+
+static struct scan_context *scan_context_new(uint64_t wdev_id)
+{
+	struct wiphy *wiphy = wiphy_find_by_wdev(wdev_id);
+	struct scan_context *sc;
+
+	if (!wiphy)
+		return NULL;
+
+	sc = l_new(struct scan_context, 1);
+
+	sc->wdev_id = wdev_id;
+	sc->wiphy = wiphy;
+	sc->state = SCAN_STATE_NOT_RUNNING;
+	sc->requests = l_queue_new();
+	sc->wiphy_watch_id = wiphy_state_watch_add(wiphy, scan_wiphy_watch,
+							sc, NULL);
+
+	return sc;
+}
+
 static bool scan_parse_flush_flag_from_msg(struct l_genl_msg *msg)
 {
 	struct l_genl_attr attr;
@@ -2094,8 +2181,6 @@ static void scan_notify(struct l_genl_msg *msg, void *user_data)
 	switch (cmd) {
 	case NL80211_CMD_NEW_SCAN_RESULTS:
 	{
-		struct l_genl_msg *scan_msg;
-		struct scan_results *results;
 		bool send_next = false;
 		bool retry = false;
 		bool get_results = false;
@@ -2106,6 +2191,14 @@ static void scan_notify(struct l_genl_msg *msg, void *user_data)
 		if (sr && sr->triggered) {
 			sr->triggered = false;
 
+			/* Regdom changed during a periodic scan */
+			if (sc->sp.id == sr->work.id &&
+					wiphy_regdom_is_updating(sc->wiphy)) {
+				scan_parse_result_frequencies(msg,
+							sr->freqs_scanned);
+				return;
+			}
+
 			if (!sr->callback) {
 				scan_finished(sc, -ECANCELED, NULL, NULL, sr);
 				break;
@@ -2162,20 +2255,9 @@ static void scan_notify(struct l_genl_msg *msg, void *user_data)
 		if (!get_results)
 			break;
 
-		results = l_new(struct scan_results, 1);
-		results->sc = sc;
-		results->time_stamp = l_time_now();
-		results->sr = sr;
-		results->bss_list = l_queue_new();
-
 		scan_parse_result_frequencies(msg, sr->freqs_scanned);
 
-		scan_msg = l_genl_msg_new_sized(NL80211_CMD_GET_SCAN, 8);
-		l_genl_msg_append_attr(scan_msg, NL80211_ATTR_WDEV, 8,
-					&sc->wdev_id);
-		sc->get_scan_cmd_id = l_genl_family_dump(nl80211, scan_msg,
-							get_scan_callback,
-							results, get_scan_done);
+		scan_get_results(sc, sr);
 
 		break;
 	}
-- 
2.34.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 1/3] util: add scan_freq_set_copy_bands
  2022-08-04 22:02 [PATCH v4 1/3] util: add scan_freq_set_copy_bands James Prestwood
  2022-08-04 22:02 ` [PATCH v4 2/3] scan: split full scans by band to enable 6GHz James Prestwood
  2022-08-04 22:02 ` [PATCH v4 3/3] scan: watch for regdom updates " James Prestwood
@ 2022-08-05 16:54 ` Denis Kenzior
  2 siblings, 0 replies; 5+ messages in thread
From: Denis Kenzior @ 2022-08-05 16:54 UTC (permalink / raw)
  To: James Prestwood, iwd

Hi James,

On 8/4/22 17:02, James Prestwood wrote:
> This creates a new scan_freq_set from an input set which only contains
> frequencies from bands included in the mask.
> ---
>   src/util.c | 21 +++++++++++++++++++++
>   src/util.h |  2 ++
>   2 files changed, 23 insertions(+)

<snip>

> +struct scan_freq_set *scan_freq_set_copy_bands(const struct scan_freq_set *set,
> +						uint32_t band_mask);

I renamed this scan_freq_set_clone() and applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 2/3] scan: split full scans by band to enable 6GHz
  2022-08-04 22:02 ` [PATCH v4 2/3] scan: split full scans by band to enable 6GHz James Prestwood
@ 2022-08-05 17:03   ` Denis Kenzior
  0 siblings, 0 replies; 5+ messages in thread
From: Denis Kenzior @ 2022-08-05 17:03 UTC (permalink / raw)
  To: James Prestwood, iwd

Hi James,

On 8/4/22 17:02, James Prestwood wrote:
> The kernel's regulatory domain updates after some number of beacons
> are processed. This triggers a regulatory domain update (and wiphy
> dump) but only after a scan request. This means a full scan started
> prior to the regdom being set will not include any 6Ghz BSS's even
> if the regdom was unlocked during the scan.
> 
> This can be worked around by splitting up a large scan request into
> multiple requests allowing one of the first commands to trigger a
> regdom update. Once the regdom updates (and wiphy dumps) we are
> hopefully still scanning and could append an additional request to
> scan 6GHz.
> ---
>   src/scan.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++------
>   1 file changed, 76 insertions(+), 9 deletions(-)
> 

<snip>

> +	/*
> +	 * Otherwise a full spectrum scan will likely open up the 6GHz
> +	 * band. The problem is the regdom update occurs after an
> +	 * individual scan request so a single request isn't going to
> +	 * include potential 6GHz results.
> +	 *
> +	 * Instead we can break this full scan up into individual bands
> +	 * and increase our chances of the regdom updating after one of
> +	 * the earlier requests. If it does update to allow 6GHz an
> +	 * extra 6GHz-only passive scan can be appended to this request
> +	 * at that time.
> +	 */
> +	subsets[0] = scan_freq_set_copy_bands(allowed, BAND_FREQ_2_4_GHZ);
> +	subsets[1] = scan_freq_set_copy_bands(allowed, BAND_FREQ_5_GHZ);

I updated these to use _clone() and ...

> +
> +	scan_freq_set_free(allowed);
> +
> +	for(i = 0; i < L_ARRAY_SIZE(subsets); i++) {
> +		scan_build_next_cmd(sr->cmds, sc, passive, params,
> +					subsets[i]);

added a scan_freq_set_isempty() check here to skip building the command in the 
unlikely event that the set is empty.

> +		scan_freq_set_free(subsets[i]);
> +	}
> +
> +	sr->split = true;
> +}
> +
>   static int scan_request_send_trigger(struct scan_context *sc,
>   					struct scan_request *sr)
>   {

Applied, thanks!

Regards,
-Denis

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-08-05 17:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-04 22:02 [PATCH v4 1/3] util: add scan_freq_set_copy_bands James Prestwood
2022-08-04 22:02 ` [PATCH v4 2/3] scan: split full scans by band to enable 6GHz James Prestwood
2022-08-05 17:03   ` Denis Kenzior
2022-08-04 22:02 ` [PATCH v4 3/3] scan: watch for regdom updates " James Prestwood
2022-08-05 16:54 ` [PATCH v4 1/3] util: add scan_freq_set_copy_bands Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.