diff mbox series

[v2,2/4] scan: filter user-disabled bands for periodic scans.

Message ID 20230928124128.3793788-2-prestwoj@gmail.com (mailing list archive)
State Accepted, archived
Headers show
Series [v2,1/4] scan: allow splitting of scans with defined frequencies | expand

Commit Message

James Prestwood Sept. 28, 2023, 12:41 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 | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

v2:
 * Simplified how the freq set is built. Instead just clone based off
   supported and the band mask. This retains any currently disabled
   6ghz frequencies without having to create a new set and merge

Comments

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

On 9/28/23 07:41, 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 | 36 ++++++++++++++++++++++++++++++++++++
>   1 file changed, 36 insertions(+)
> 
> v2:
>   * Simplified how the freq set is built. Instead just clone based off
>     supported and the band mask. This retains any currently disabled
>     6ghz frequencies without having to create a new set and merge
> 

Applied, thanks.

Regards,
-Denis
diff mbox series

Patch

diff --git a/src/scan.c b/src/scan.c
index e6c105c0..93047a6b 100644
--- a/src/scan.c
+++ b/src/scan.c
@@ -987,9 +987,43 @@  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)
+{
+	uint32_t band_mask = 0;
+	struct scan_freq_set *freqs;
+	const struct scan_freq_set *supported =
+					wiphy_get_supported_freqs(sc->wiphy);
+
+	if (RANK_2G_FACTOR)
+		band_mask |= BAND_FREQ_2_4_GHZ;
+	if (RANK_5G_FACTOR)
+		band_mask |= BAND_FREQ_5_GHZ;
+	if (RANK_6G_FACTOR)
+		band_mask |= BAND_FREQ_6_GHZ;
+
+	freqs = scan_freq_set_clone(supported, band_mask);
+	if (scan_freq_set_isempty(freqs)) {
+		scan_freq_set_free(freqs);
+		freqs = NULL;
+	}
+
+	return freqs;
+}
+
 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;
@@ -1007,6 +1041,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;
 }