From e83070e074aa0b29f53dd87b2d2b86b3183ccbea Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Thu, 28 Sep 2023 05:41:26 -0700 Subject: [PATCH] scan: filter user-disabled bands for periodic scans. 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(+) 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; }