Skip to contentSkip to conversation

scan: allow splitting of scans with defined frequencies

PATCH Applied James Prestwood 2 participants 8 messages Sep 28, 2023 – Sep 29, 2023

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 scan: allow splitting of scans with defined frequencies

Currently the only way a scan can be split is if the request does not specify any frequencies, implying the request should scan the entire spectrum. This allows the scan logic to issue an extra request if 6GHz becomes available during the 2.4 or 5GHz scans. This restriction was somewhat arbitrary and done to let periodic scans pick up 6GHz APs through a single scan request.

But now with the addition of allowing user-disabled bands periodic scans will need to specify a frequency list in case a given band has been disabled. This will break the scan splitting code which is why this prep work is being done.

The main difference now is the original scan frequencies are tracked with the scan request. The reason for this is so if a request comes in with a limited set of 6GHz frequences IWD won't end up scanning the full 6GHz spectrum later on.

---
 src/scan.c | 56 +++++++++++++++++++++---------------------------------
 1 file changed, 22 insertions(+), 34 deletions(-)

v2:
* Use _auto_ for allowed frequencies in scan_cmds_add()

src/scan.c +22 -34
index 915e2875..e6c105c0 100644
@@ -107,6 +107,8 @@ struct scan_request {
 	 * and save these since there may be additional scan commands to run.
 	 */
 	struct scan_freq_set *freqs_scanned;
+	/* Entire list of frequencies to scan */
+	struct scan_freq_set *scan_freqs;
 };
 
 struct scan_context {
@@ -170,6 +172,7 @@ static void scan_request_free(struct wiphy_radio_work_item *item)
 	l_queue_destroy(sr->cmds, (l_queue_destroy_func_t) l_genl_msg_unref);
 
 	scan_freq_set_free(sr->freqs_scanned);
+	scan_freq_set_free(sr->scan_freqs);
 
 	l_free(sr);
 }
@@ -341,20 +344,6 @@ 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,
@@ -582,22 +571,28 @@ static void scan_cmds_add(struct scan_request *sr, struct scan_context *sc,
 				bool passive,
 				const struct scan_parameters *params)
 {
+	uint32_t bands = BAND_FREQ_2_4_GHZ | BAND_FREQ_5_GHZ | BAND_FREQ_6_GHZ;
 	unsigned int i;
 	struct scan_freq_set *subsets[2] = { 0 };
-	struct scan_freq_set *allowed = scan_get_allowed_freqs(sc);
+	_auto_(scan_freq_set_free) struct scan_freq_set *allowed =
+				wiphy_get_allowed_freqs(sc->wiphy, bands);
 	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.
+	 * No frequencies, just include the entire supported list and let the
+	 * kernel filter out any disabled frequencies
 	 */
+	if (!params->freqs)
+		sr->scan_freqs = scan_freq_set_clone(supported, bands);
+	else
+		sr->scan_freqs = scan_freq_set_clone(params->freqs, bands);
+
+	/* If 6GHz is not possible or already allowed don't split 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_freq_set_get_bands(allowed) & BAND_FREQ_6_GHZ)) {
 		scan_build_next_cmd(sr->cmds, sc, passive,
-						params, params->freqs);
+						params, sr->scan_freqs);
 		return;
 	}
 
@@ -613,10 +608,8 @@ static void scan_cmds_add(struct scan_request *sr, struct scan_context *sc,
 	 * extra 6GHz-only passive scan can be appended to this request
 	 * at that time.
 	 */
-	subsets[0] = scan_freq_set_clone(allowed, BAND_FREQ_2_4_GHZ);
-	subsets[1] = scan_freq_set_clone(allowed, BAND_FREQ_5_GHZ);
-
-	scan_freq_set_free(allowed);
+	subsets[0] = scan_freq_set_clone(sr->scan_freqs, BAND_FREQ_2_4_GHZ);
+	subsets[1] = scan_freq_set_clone(sr->scan_freqs, BAND_FREQ_5_GHZ);
 
 	for(i = 0; i < L_ARRAY_SIZE(subsets); i++) {
 		if (!scan_freq_set_isempty(subsets[i]))
@@ -1918,9 +1911,8 @@ static void scan_wiphy_watch(struct wiphy *wiphy,
 	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;
+	_auto_(scan_freq_set_free) struct scan_freq_set *freqs_6ghz = NULL;
 
 	/* Only care about completed regulatory dumps */
 	if (event != WIPHY_STATE_WATCH_EVENT_REGDOM_DONE)
@@ -1934,14 +1926,14 @@ static void scan_wiphy_watch(struct wiphy *wiphy,
 	if (!sr)
 		return;
 
-	allowed = scan_get_allowed_freqs(sc);
-	allow_6g = scan_freq_set_get_bands(allowed) & BAND_FREQ_6_GHZ;
+	allowed = wiphy_get_allowed_freqs(sc->wiphy, BAND_FREQ_6_GHZ);
+	freqs_6ghz = scan_freq_set_clone(sr->scan_freqs, 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) {
+	if (!allowed || scan_freq_set_isempty(freqs_6ghz) || !sr->split) {
 		scan_get_results(sc, sr, sr->freqs_scanned);
 		goto free_allowed;
 	}
@@ -1951,13 +1943,9 @@ static void scan_wiphy_watch(struct wiphy *wiphy,
 	 * Create a new 6GHz passive scan request and append to the
 	 * command list
 	 */
-	freqs_6ghz = scan_freq_set_clone(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.
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 2/4 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(+)

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

src/scan.c +36 -0
index e6c105c0..93047a6b 100644
@@ -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;
 }
 
Signature · 1 line
2.25.1
#2 lore raw

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

Hi James,

Quoted 8 lines · James Prestwood

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.

Quoted 9 lines
---
  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

#3 lore raw

PATCH v2 3/4 station: support user-disabled bands

In reply to James Prestwood

This adds support to allow users to disable entire bands, preventing scanning and connecting on those frequencies. If the [Rank].BandModifier* options are set to 0.0 it will imply those bands should not be used for scanning, connecting or roaming. This now applies to autoconnect, quick, hidden, roam, and dbus scans.

This is a station only feature meaning other modules like RRM, DPP, WSC or P2P may still utilize those bands. Trying to limit bands in those modules may sometimes conflict with the spec which is why it was not added there. In addition modules like DPP/WSC are only used in limited capacity for connecting so there is little benefit gained to disallowing those bands.

---
 src/station.c | 120 ++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 97 insertions(+), 23 deletions(-)

v2:
* Compute an allowed band mask in station_init rather than separate bools
* Let all scan paths include frequencies which may be disabled but supported. This opens up the potential for 6ghz to be unlocked, and if a frequency is disabled the kernel filters it anyways.
* Optimized the dbus scan subset creation. Clone the 5/6ghz sets based on supported freqs rather than foreach.
* Added a warning after computing the subsets if none were created

src/station.c +97 -23
index 9e4ee69a..12823142 100644
@@ -73,6 +73,7 @@ static bool supports_arp_evict_nocarrier;
 static bool supports_ndisc_evict_nocarrier;
 static struct watchlist event_watches;
 static uint32_t known_networks_watch;
+static uint32_t allowed_bands;
 
 struct station {
 	enum station_state state;
@@ -1326,6 +1327,21 @@ static bool station_needs_hidden_network_scan(struct station *station)
 	return !l_queue_isempty(station->hidden_bss_list_sorted);
 }
 
+static struct scan_freq_set *station_get_allowed_freqs(struct station *station)
+{
+	const struct scan_freq_set *supported =
+				wiphy_get_supported_freqs(station->wiphy);
+	struct scan_freq_set *allowed = scan_freq_set_clone(supported,
+							allowed_bands);
+
+	if (scan_freq_set_isempty(allowed)) {
+		scan_freq_set_free(allowed);
+		allowed = NULL;
+	}
+
+	return allowed;
+}
+
 static uint32_t station_scan_trigger(struct station *station,
 					struct scan_freq_set *freqs,
 					scan_trigger_func_t triggered,
@@ -1411,6 +1427,7 @@ static void station_quick_scan_destroy(void *userdata)
 static int station_quick_scan_trigger(struct station *station)
 {
 	_auto_(scan_freq_set_free) struct scan_freq_set *known_freq_set = NULL;
+	_auto_(scan_freq_set_free) struct scan_freq_set *allowed = NULL;
 	bool known_6ghz;
 
 	if (wiphy_regdom_is_updating(station->wiphy)) {
@@ -1440,9 +1457,14 @@ static int station_quick_scan_trigger(struct station *station)
 			known_6ghz)
 		return -ENOTSUP;
 
-	if (!wiphy_constrain_freq_set(station->wiphy, known_freq_set)) {
+	allowed = station_get_allowed_freqs(station);
+	if (L_WARN_ON(!allowed))
+		return -ENOTSUP;
+
+	scan_freq_set_constrain(known_freq_set, allowed);
+
+	if (scan_freq_set_isempty(known_freq_set))
 		return -ENOTSUP;
-	}
 
 	station->quick_scan_id = station_scan_trigger(station,
 						known_freq_set,
@@ -2656,6 +2678,11 @@ static int station_roam_scan(struct station *station,
 				struct scan_freq_set *freq_set)
 {
 	struct scan_parameters params = { .freqs = freq_set, .flush = true };
+	_auto_(scan_freq_set_free) struct scan_freq_set *allowed =
+					station_get_allowed_freqs(station);
+
+	if (L_WARN_ON(!allowed))
+		return -ENOTSUP;
 
 	l_debug("ifindex: %u", netdev_get_ifindex(station->netdev));
 
@@ -2666,8 +2693,14 @@ static int station_roam_scan(struct station *station,
 		params.ssid_len = strlen(ssid);
 	}
 
-	if (!freq_set)
+	if (!freq_set) {
 		station->roam_scan_full = true;
+		params.freqs = allowed;
+	} else
+		scan_freq_set_constrain(freq_set, allowed);
+
+	if (L_WARN_ON(scan_freq_set_isempty(params.freqs)))
+		return -ENOTSUP;
 
 	station->roam_scan_id =
 		scan_active_full(netdev_get_wdev_id(station->netdev), &params,
@@ -3597,6 +3630,7 @@ static struct l_dbus_message *station_dbus_connect_hidden_network(
 	};
 	const char *ssid;
 	struct network *network;
+	_auto_(scan_freq_set_free) struct scan_freq_set *allowed = NULL;
 
 	l_debug("");
 
@@ -3647,6 +3681,11 @@ not_hidden:
 		return dbus_error_not_hidden(message);
 	}
 
+	allowed = station_get_allowed_freqs(station);
+	if (L_WARN_ON(!allowed))
+		return dbus_error_not_supported(message);
+
+	params.freqs = allowed;
 	params.ssid = (const uint8_t *)ssid;
 	params.ssid_len = strlen(ssid);
 
@@ -4268,39 +4307,67 @@ int station_hide_network(struct station *station, struct network *network)
 	return 0;
 }
 
-static void station_add_one_freq(uint32_t freq, void *user_data)
+static void station_add_2_4ghz_freq(uint32_t freq, void *user_data)
 {
-	struct station *station = user_data;
+	struct scan_freq_set *set = user_data;
 
-	if (freq > 3000)
-		scan_freq_set_add(station->scan_freqs_order[1], freq);
-	else if (!scan_freq_set_contains(station->scan_freqs_order[0], freq))
-		scan_freq_set_add(station->scan_freqs_order[2], freq);
+	/* exclude social channels added in initial scan request */
+	if (freq < 3000 && freq != 2412 && freq != 2437 && freq != 2462)
+		scan_freq_set_add(set, freq);
 }
 
 static void station_fill_scan_freq_subsets(struct station *station)
 {
 	const struct scan_freq_set *supported =
-		wiphy_get_supported_freqs(station->wiphy);
+				wiphy_get_supported_freqs(station->wiphy);
+	unsigned int subset_idx = 0;
 
 	/*
 	 * Scan the 2.4GHz "social channels" first, 5GHz second, if supported,
 	 * all other 2.4GHz channels last.  To be refined as needed.
 	 */
-	station->scan_freqs_order[0] = scan_freq_set_new();
-	scan_freq_set_add(station->scan_freqs_order[0], 2412);
-	scan_freq_set_add(station->scan_freqs_order[0], 2437);
-	scan_freq_set_add(station->scan_freqs_order[0], 2462);
-
-	station->scan_freqs_order[1] = scan_freq_set_new();
-	station->scan_freqs_order[2] = scan_freq_set_new();
-	scan_freq_set_foreach(supported, station_add_one_freq, station);
-
-	if (scan_freq_set_isempty(station->scan_freqs_order[1])) {
-		scan_freq_set_free(station->scan_freqs_order[1]);
-		station->scan_freqs_order[1] = station->scan_freqs_order[2];
-		station->scan_freqs_order[2] = NULL;
+	if (allowed_bands & BAND_FREQ_2_4_GHZ) {
+		station->scan_freqs_order[subset_idx] = scan_freq_set_new();
+		scan_freq_set_add(station->scan_freqs_order[subset_idx], 2412);
+		scan_freq_set_add(station->scan_freqs_order[subset_idx], 2437);
+		scan_freq_set_add(station->scan_freqs_order[subset_idx], 2462);
+		subset_idx++;
+	}
+
+	/*
+	 * TODO: It may might sense to split up 5 and 6ghz into separate subsets
+	 *       since the channel set is so large.
+	 */
+	if (allowed_bands & (BAND_FREQ_5_GHZ | BAND_FREQ_6_GHZ)) {
+		uint32_t mask = allowed_bands &
+					(BAND_FREQ_5_GHZ | BAND_FREQ_6_GHZ);
+		struct scan_freq_set *set = scan_freq_set_clone(supported,
+								mask);
+
+		/* 5/6ghz didn't add any frequencies */
+		if (scan_freq_set_isempty(set)) {
+			scan_freq_set_free(set);
+		} else
+			station->scan_freqs_order[subset_idx++] = set;
 	}
+
+	/* Add remaining 2.4ghz channels to subset */
+	if (allowed_bands & BAND_FREQ_2_4_GHZ) {
+		station->scan_freqs_order[subset_idx] = scan_freq_set_new();
+		scan_freq_set_foreach(supported, station_add_2_4ghz_freq,
+					station->scan_freqs_order[subset_idx]);
+	}
+
+	/*
+	 * This has the unintended consequence of allowing DBus scans to
+	 * scan the entire spectrum rather than cause IWD to be completely
+	 * non-functional. Rather than prevent DBus scans from working at all
+	 * print a warning here.
+	 */
+	if (station->scan_freqs_order[0] == NULL)
+		l_warn("All supported bands were disabled by user! IWD will not"
+			" function as expected");
+
 }
 
 static void station_wiphy_watch(struct wiphy *wiphy,
@@ -5194,6 +5261,13 @@ static int station_init(void)
 						station_known_networks_changed,
 						NULL, NULL);
 
+	if (scan_get_band_rank_modifier(BAND_FREQ_2_4_GHZ))
+		allowed_bands |= BAND_FREQ_2_4_GHZ;
+	if (scan_get_band_rank_modifier(BAND_FREQ_5_GHZ))
+		allowed_bands |= BAND_FREQ_5_GHZ;
+	if (scan_get_band_rank_modifier(BAND_FREQ_6_GHZ))
+		allowed_bands |= BAND_FREQ_6_GHZ;
+
 	return 0;
 }
 
Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH v2 3/4] station: support user-disabled bands

Hi James,

Quoted 16 lines · James Prestwood

This adds support to allow users to disable entire bands, preventing scanning and connecting on those frequencies. If the [Rank].BandModifier* options are set to 0.0 it will imply those bands should not be used for scanning, connecting or roaming. This now applies to autoconnect, quick, hidden, roam, and dbus scans.

This is a station only feature meaning other modules like RRM, DPP, WSC or P2P may still utilize those bands. Trying to limit bands in those modules may sometimes conflict with the spec which is why it was not added there. In addition modules like DPP/WSC are only used in limited capacity for connecting so there is little benefit gained to disallowing those bands.

---
  src/station.c | 120 ++++++++++++++++++++++++++++++++++++++++----------
  1 file changed, 97 insertions(+), 23 deletions(-)
Quoted 9 lines

v2:
* Compute an allowed band mask in station_init rather than separate bools
* Let all scan paths include frequencies which may be disabled but supported. This opens up the potential for 6ghz to be unlocked, and if a frequency is disabled the kernel filters it anyways.
* Optimized the dbus scan subset creation. Clone the 5/6ghz sets based on supported freqs rather than foreach.
* Added a warning after computing the subsets if none were created

I went ahead and applied this and 4/4. Couple of comments:

Quoted 6 lines
src/station.c +5 -0
+static struct scan_freq_set *station_get_allowed_freqs(struct station *station)
+{
+	const struct scan_freq_set *supported =
+				wiphy_get_supported_freqs(station->wiphy);
+	struct scan_freq_set *allowed = scan_freq_set_clone(supported,

src/station.c static bool station_needs_hidden_network_scan(struct station *station) · line 1344

Quoted 10 lines
src/station.c +10 -0
+							allowed_bands);
+
+	if (scan_freq_set_isempty(allowed)) {
+		scan_freq_set_free(allowed);
+		allowed = NULL;
+	}
+
+	return allowed;
+}
+

This is almost identical to the function in scan.c. Maybe consider using a shared implementation?

src/station.c static int station_quick_scan_trigger(struct station *station) · line 1462

Quoted 8 lines
src/station.c +3 -1
@@ -1440,9 +1457,14 @@ static int station_quick_scan_trigger(struct station *station)
  			known_6ghz)
  		return -ENOTSUP;
 
-	if (!wiphy_constrain_freq_set(station->wiphy, known_freq_set)) {
+	allowed = station_get_allowed_freqs(station);
+	if (L_WARN_ON(!allowed))
+		return -ENOTSUP;

You have a lot of this handling sprinkled about. I think this is fine, since someone can still disable the single band their hardware supports or something. But maybe its worth checking the really bizarre cases and fail initialization early?

Somewhere in station_init or scan_init? Sanitize that at least a single band is enabled, or at least one of 2.4/5G if 6G is also enabled?

Regards,
-Denis

#5 lore raw

Re: [PATCH v2 3/4] station: support user-disabled bands

Hi Denis,

Quoted 61 lines · Denis Kenzior

Hi James,

Quoted 16 lines · James Prestwood

This adds support to allow users to disable entire bands, preventing scanning and connecting on those frequencies. If the [Rank].BandModifier* options are set to 0.0 it will imply those bands should not be used for scanning, connecting or roaming. This now applies to autoconnect, quick, hidden, roam, and dbus scans.

This is a station only feature meaning other modules like RRM, DPP, WSC or P2P may still utilize those bands. Trying to limit bands in those modules may sometimes conflict with the spec which is why it was not added there. In addition modules like DPP/WSC are only used in limited capacity for connecting so there is little benefit gained to disallowing those bands.
---
  src/station.c | 120 ++++++++++++++++++++++++++++++++++++++++----------

  1 file changed, 97 insertions(+), 23 deletions(-)
Quoted 9 lines

v2:
  * Compute an allowed band mask in station_init rather than separate bools
  * Let all scan paths include frequencies which may be disabled but supported. This opens up the potential for 6ghz to be unlocked, and if a frequency is disabled the kernel filters it anyways.
  * Optimized the dbus scan subset creation. Clone the 5/6ghz sets based on supported freqs rather than foreach.
  * Added a warning after computing the subsets if none were created

I went ahead and applied this and 4/4.  Couple of comments:

Quoted 6 lines

+static struct scan_freq_set *station_get_allowed_freqs(struct station *station)

src/station.c +4 -0
+{
+    const struct scan_freq_set *supported =
+                wiphy_get_supported_freqs(station->wiphy);
+    struct scan_freq_set *allowed = scan_freq_set_clone(supported,

src/station.c static bool station_needs_hidden_network_scan(struct station *station) · line 1344

Quoted 10 lines
src/station.c +10 -0
+                            allowed_bands);
+
+    if (scan_freq_set_isempty(allowed)) {
+        scan_freq_set_free(allowed);
+        allowed = NULL;
+    }
+
+    return allowed;
+}
+

This is almost identical to the function in scan.c.  Maybe consider using a shared implementation?

src/station.c static int station_quick_scan_trigger(struct · line 1462

Quoted 8 lines
src/station.c +3 -1
@@ -1440,9 +1457,14 @@ static int station_quick_scan_trigger(struct 
 station *station)
               known_6ghz)
           return -ENOTSUP;
-    if (!wiphy_constrain_freq_set(station->wiphy, known_freq_set)) {
+    allowed = station_get_allowed_freqs(station);
+    if (L_WARN_ON(!allowed))
+        return -ENOTSUP;

You have a lot of this handling sprinkled about.  I think this is fine, since someone can still disable the single band their hardware supports or something. But maybe its worth checking the really bizarre cases and fail initialization early?

Quoted 1 line

Somewhere in station_init or scan_init?  Sanitize that at least a single band is enabled, or at least one of 2.4/5G if 6G is also enabled?

Yeah I thought about that. If all bands are disabled IWD will still start, but just hang since it can't do anything. But maybe it is best to actually fail init, that would make it more clear since someone is likely just checking systemctl to see why they don't have wifi.

I'll send a follow up for this.

Quoted 4 lines

Regards,
-Denis

#6 lore raw

PATCH v2 4/4 doc: document disabling bands with a 0.0 modifier

In reply to James Prestwood
---
 src/iwd.config.rst | 9 +++++++++
 1 file changed, 9 insertions(+)
src/iwd.config.rst +9 -0
index 294e4c7b..be2fd18c 100644
@@ -297,6 +297,9 @@ autoconnect purposes.
        Increase or decrease the preference for 2.4GHz access points by
        increasing or decreasing the value of this modifier.
 
+       A value of 0.0 will disable the 2.4GHz band and prevent scanning or
+       connecting on those frequencies.
+
    * - BandModifier5Ghz
      - Values: floating point value (default: **1.0**)
 
@@ -306,6 +309,9 @@ autoconnect purposes.
        networks are highly RSSI sensitive, so it is still possible for IWD to
        prefer 2.4Ghz APs in certain circumstances.
 
+       A value of 0.0 will disable the 5GHz band and prevent scanning or
+       connecting on those frequencies.
+
    * - BandModifier6Ghz
      - Values: floating point value (default: **1.0**)
 
@@ -313,6 +319,9 @@ autoconnect purposes.
        or decreasing the value of this modifier.  Since 6GHz networks are highly
        RSSI sensitive, this gives an option to prefer 6GHz APs over 5GHz APs.
 
+       A value of 0.0 will disable the 6GHz band and prevent scanning or
+       connecting on those frequencies.
+
 Scan
 ----
 
Signature · 1 line
2.25.1
#7 lore raw
In reply to James Prestwood

Hi James,

Quoted 16 lines · James Prestwood

Currently the only way a scan can be split is if the request does not specify any frequencies, implying the request should scan the entire spectrum. This allows the scan logic to issue an extra request if 6GHz becomes available during the 2.4 or 5GHz scans. This restriction was somewhat arbitrary and done to let periodic scans pick up 6GHz APs through a single scan request.

But now with the addition of allowing user-disabled bands periodic scans will need to specify a frequency list in case a given band has been disabled. This will break the scan splitting code which is why this prep work is being done.

The main difference now is the original scan frequencies are tracked with the scan request. The reason for this is so if a request comes in with a limited set of 6GHz frequences IWD won't end up scanning the full 6GHz spectrum later on.

Quoted 7 lines
---
  src/scan.c | 56 +++++++++++++++++++++---------------------------------
  1 file changed, 22 insertions(+), 34 deletions(-)

v2:
* Use _auto_ for allowed frequencies in scan_cmds_add()

I went ahead and applied, but a quick comment:

Quoted 20 lines
src/scan.c +6 -3
@@ -582,22 +571,28 @@ static void scan_cmds_add(struct scan_request *sr, struct scan_context *sc,
  				bool passive,
  				const struct scan_parameters *params)
  {
+	uint32_t bands = BAND_FREQ_2_4_GHZ | BAND_FREQ_5_GHZ | BAND_FREQ_6_GHZ;
  	unsigned int i;
  	struct scan_freq_set *subsets[2] = { 0 };
-	struct scan_freq_set *allowed = scan_get_allowed_freqs(sc);
+	_auto_(scan_freq_set_free) struct scan_freq_set *allowed =
+				wiphy_get_allowed_freqs(sc->wiphy, bands);
  	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.
+	 * No frequencies, just include the entire supported list and let the
+	 * kernel filter out any disabled frequencies
  	 */
+	if (!params->freqs)

src/scan.c static void scan_cmds_add(struct scan_request *sr, struct scan_context *sc, · line 593

Quoted 10 lines
src/scan.c +6 -3
+		sr->scan_freqs = scan_freq_set_clone(supported, bands);
+	else
+		sr->scan_freqs = scan_freq_set_clone(params->freqs, bands);
+
+	/* If 6GHz is not possible or already allowed don't split 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_freq_set_get_bands(allowed) & BAND_FREQ_6_GHZ)) {

You're using allowed here for the sole purpose of checking whether 6G was allowed by the regdom. This is sort of an expensive operation and we should really just have a getter for this. Would make the code easier to understand as well.

Maybe consider using something like wiphy_band_is_disabled() instead?

Quoted 31 lines
src/scan.c +4 -7
  		scan_build_next_cmd(sr->cmds, sc, passive,
-						params, params->freqs);
+						params, sr->scan_freqs);
  		return;
  	}
 
@@ -613,10 +608,8 @@ static void scan_cmds_add(struct scan_request *sr, struct scan_context *sc,
  	 * extra 6GHz-only passive scan can be appended to this request
  	 * at that time.
  	 */
-	subsets[0] = scan_freq_set_clone(allowed, BAND_FREQ_2_4_GHZ);
-	subsets[1] = scan_freq_set_clone(allowed, BAND_FREQ_5_GHZ);
-
-	scan_freq_set_free(allowed);
+	subsets[0] = scan_freq_set_clone(sr->scan_freqs, BAND_FREQ_2_4_GHZ);
+	subsets[1] = scan_freq_set_clone(sr->scan_freqs, BAND_FREQ_5_GHZ);
 
  	for(i = 0; i < L_ARRAY_SIZE(subsets); i++) {
  		if (!scan_freq_set_isempty(subsets[i]))
@@ -1918,9 +1911,8 @@ static void scan_wiphy_watch(struct wiphy *wiphy,
  	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;
+	_auto_(scan_freq_set_free) struct scan_freq_set *freqs_6ghz = NULL;
 
  	/* Only care about completed regulatory dumps */
  	if (event != WIPHY_STATE_WATCH_EVENT_REGDOM_DONE)

src/scan.c static void scan_wiphy_watch(struct wiphy *wiphy, · line 1930

Quoted 7 lines
src/scan.c +2 -2
@@ -1934,14 +1926,14 @@ static void scan_wiphy_watch(struct wiphy *wiphy,
  	if (!sr)
  		return;
 
-	allowed = scan_get_allowed_freqs(sc);
-	allow_6g = scan_freq_set_get_bands(allowed) & BAND_FREQ_6_GHZ;
+	allowed = wiphy_get_allowed_freqs(sc->wiphy, BAND_FREQ_6_GHZ);
+	freqs_6ghz = scan_freq_set_clone(sr->scan_freqs, BAND_FREQ_6_GHZ);

Same situation here, you're not really using allowed / freqs_6ghz for anything.

src/scan.c static void scan_wiphy_watch(struct wiphy *wiphy, · line 1939

Quoted 10 lines
src/scan.c +1 -1
  	/*
  	 * 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) {
+	if (!allowed || scan_freq_set_isempty(freqs_6ghz) || !sr->split) {
  		scan_get_results(sc, sr, sr->freqs_scanned);
  		goto free_allowed;
  	}

Regards,
-Denis