diff mbox series

[6/8] scan: filter user-disabled bands for periodic scans.

Message ID 20230925185422.2242494-6-prestwoj@gmail.com (mailing list archive)
State New
Headers show
Series [1/8] scan: add [Rank].BandModifier2_4Ghz | expand

Commit Message

James Prestwood Sept. 25, 2023, 6:54 p.m. UTC
To support user-disabled bands periodic scans need to specify a
frequency list filtered by any bands that are disabled. This was
needed in scan.c since periodic scans don't provide a frequency
list in the scan request.

If no bands are disabled the allowed freqs API should still
result in the same scan behavior as if a frequency list is left
out i.e. IWD just filters the frequencies as opposed to the kernel.
---
 src/scan.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

Comments

Denis Kenzior Sept. 27, 2023, 8:29 p.m. UTC | #1
Hi James,

On 9/25/23 13:54, James Prestwood wrote:
> To support user-disabled bands periodic scans need to specify a
> frequency list filtered by any bands that are disabled. This was
> needed in scan.c since periodic scans don't provide a frequency
> list in the scan request.
> 
> If no bands are disabled the allowed freqs API should still
> result in the same scan behavior as if a frequency list is left
> out i.e. IWD just filters the frequencies as opposed to the kernel.
> ---
>   src/scan.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 46 insertions(+)
> 
> diff --git a/src/scan.c b/src/scan.c
> index 9b1cc30a..84cf0f38 100644
> --- a/src/scan.c
> +++ b/src/scan.c
> @@ -990,9 +990,53 @@ static void scan_periodic_destroy(void *user_data)
>   	sc->sp.id = 0;
>   }
>   
> +static struct scan_freq_set *scan_periodic_get_freqs(struct scan_context *sc)
> +{
> +	struct scan_freq_set *allowed;
> +	struct scan_freq_set *band_6g;
> +	const struct scan_freq_set *supported =
> +					wiphy_get_supported_freqs(sc->wiphy);
> +	uint32_t band_mask = 0;
> +
> +	if (RANK_2G_FACTOR)
> +		band_mask |= BAND_FREQ_2_4_GHZ;
> +	if (RANK_5G_FACTOR)
> +		band_mask |= BAND_FREQ_5_GHZ;
> +

If we're letting the kernel filter allowed frequencies, should this be just a 
clone of supported_freqs with band_mask set appropriately?  Might make the logic 
here a bit simpler.

> +	allowed = wiphy_get_allowed_freqs(sc->wiphy, band_mask);
> +	if (!RANK_6G_FACTOR)
> +		return allowed;
> +
> +	/* 2.4 and 5Ghz are disabled, this is not a workable configuration */
> +	if (!allowed)
> +		return NULL;
> +
> +	/*
> +	 * 6GHz is special because initially its disabled until the regdom is
> +	 * established so (unless user disabled) we should always include those
> +	 * frequencies for periodic scans.
> +	 */
> +	band_6g = scan_freq_set_clone(supported, BAND_FREQ_6_GHZ);
> +	scan_freq_set_merge(allowed, band_6g);
> +	scan_freq_set_free(band_6g);
> +
> +	return allowed;
> +}
> +

Regards,
-Denis
diff mbox series

Patch

diff --git a/src/scan.c b/src/scan.c
index 9b1cc30a..84cf0f38 100644
--- a/src/scan.c
+++ b/src/scan.c
@@ -990,9 +990,53 @@  static void scan_periodic_destroy(void *user_data)
 	sc->sp.id = 0;
 }
 
+static struct scan_freq_set *scan_periodic_get_freqs(struct scan_context *sc)
+{
+	struct scan_freq_set *allowed;
+	struct scan_freq_set *band_6g;
+	const struct scan_freq_set *supported =
+					wiphy_get_supported_freqs(sc->wiphy);
+	uint32_t band_mask = 0;
+
+	if (RANK_2G_FACTOR)
+		band_mask |= BAND_FREQ_2_4_GHZ;
+	if (RANK_5G_FACTOR)
+		band_mask |= BAND_FREQ_5_GHZ;
+
+	allowed = wiphy_get_allowed_freqs(sc->wiphy, band_mask);
+	if (!RANK_6G_FACTOR)
+		return allowed;
+
+	/* 2.4 and 5Ghz are disabled, this is not a workable configuration */
+	if (!allowed)
+		return NULL;
+
+	/*
+	 * 6GHz is special because initially its disabled until the regdom is
+	 * established so (unless user disabled) we should always include those
+	 * frequencies for periodic scans.
+	 */
+	band_6g = scan_freq_set_clone(supported, BAND_FREQ_6_GHZ);
+	scan_freq_set_merge(allowed, band_6g);
+	scan_freq_set_free(band_6g);
+
+	return allowed;
+}
+
 static bool scan_periodic_queue(struct scan_context *sc)
 {
 	struct scan_parameters params = {};
+	struct scan_freq_set *freqs = scan_periodic_get_freqs(sc);
+
+	/*
+	 * If this happens its due to the user disabling all bands. This will
+	 * cause IWD to never issue another periodic scan so warn the user of
+	 * this.
+	 */
+	if (L_WARN_ON(!freqs))
+		return false;
+
+	params.freqs = freqs;
 
 	if (sc->sp.needs_active_scan && known_networks_has_hidden()) {
 		params.randomize_mac_addr_hint = true;
@@ -1010,6 +1054,8 @@  static bool scan_periodic_queue(struct scan_context *sc)
 					scan_periodic_notify, sc,
 					scan_periodic_destroy);
 
+	scan_freq_set_free(freqs);
+
 	return sc->sp.id != 0;
 }