diff mbox series

[6/7] wiphy: track disabled frequencies on multiple dumps

Message ID 20220722163417.1119334-6-prestwoj@gmail.com (mailing list archive)
State Not Applicable, archived
Headers show
Series [1/7] wiphy: fix runtime error from bit shift | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
prestwoj/iwd-ci-gitlint success GitLint

Commit Message

James Prestwood July 22, 2022, 4:34 p.m. UTC
If a frequency is disabled, it should not be added to the supported list which
it previously was. In this case its added to the (new) disabled_freqs list.

Now that wiphy's are dumped on regulatory changes frequencies may be added or
removed from either the supported or disabled frequency list. These changes
are now tracked to keep the lists accurate.
---
 src/wiphy.c | 35 ++++++++++++++++++++++++++++++++---
 src/wiphy.h |  1 +
 2 files changed, 33 insertions(+), 3 deletions(-)

Comments

Denis Kenzior July 22, 2022, 6:08 p.m. UTC | #1
Hi James,

On 7/22/22 11:34, James Prestwood wrote:
> If a frequency is disabled, it should not be added to the supported list which
> it previously was. In this case its added to the (new) disabled_freqs list.
> 
> Now that wiphy's are dumped on regulatory changes frequencies may be added or
> removed from either the supported or disabled frequency list. These changes
> are now tracked to keep the lists accurate.
> ---
>   src/wiphy.c | 35 ++++++++++++++++++++++++++++++++---
>   src/wiphy.h |  1 +
>   2 files changed, 33 insertions(+), 3 deletions(-)
> 

<snip>

> +		/*
> +		 * Wiphy is dumped again on every regulatory domain change which
> +		 * may contain disabled frequencies which were previously
> +		 * allowed. If disabled, remove from supported. If supported,
> +		 * remove from disabled.
> +		 */

I would do this differently and leave 'supported_freqs' alone and only track the 
disabled freqs.

> +		if (disabled) {
> +			scan_freq_set_add(wiphy->disabled_freqs, freq);
> +			scan_freq_set_remove(wiphy->supported_freqs, freq);
> +		} else {
> +			scan_freq_set_add(wiphy->supported_freqs, freq);
> +			scan_freq_set_remove(wiphy->disabled_freqs, freq);
> +		}

Also you can simply clear the 'disabled_freqs' set on reg change, before parsing 
the disabled flags.

Then make sure wiphy_constrain_freq_set() takes everything into account. 
Perhaps we need a new scan_freq_set_* API?


>   	}
>   }
>   

Regards,
-Denis
diff mbox series

Patch

diff --git a/src/wiphy.c b/src/wiphy.c
index 4b9e130a..7d123e0c 100644
--- a/src/wiphy.c
+++ b/src/wiphy.c
@@ -104,6 +104,7 @@  struct wiphy {
 	uint16_t supported_iftypes;
 	uint16_t supported_ciphers;
 	struct scan_freq_set *supported_freqs;
+	struct scan_freq_set *disabled_freqs;
 	struct band *band_2g;
 	struct band *band_5g;
 	struct band *band_6g;
@@ -316,6 +317,7 @@  static struct wiphy *wiphy_new(uint32_t id)
 
 	wiphy->id = id;
 	wiphy->supported_freqs = scan_freq_set_new();
+	wiphy->disabled_freqs = scan_freq_set_new();
 	watchlist_init(&wiphy->state_watches, NULL);
 	wiphy->extended_capabilities[0] = IE_TYPE_EXTENDED_CAPABILITIES;
 	wiphy->extended_capabilities[1] = EXT_CAP_LEN;
@@ -357,6 +359,7 @@  static void wiphy_free(void *data)
 	}
 
 	scan_freq_set_free(wiphy->supported_freqs);
+	scan_freq_set_free(wiphy->disabled_freqs);
 	watchlist_destroy(&wiphy->state_watches);
 	l_free(wiphy->model_str);
 	l_free(wiphy->vendor_str);
@@ -454,6 +457,11 @@  const struct scan_freq_set *wiphy_get_supported_freqs(
 	return wiphy->supported_freqs;
 }
 
+const struct scan_freq_set *wiphy_get_disabled_freqs(const struct wiphy *wiphy)
+{
+	return wiphy->disabled_freqs;
+}
+
 bool wiphy_can_transition_disable(struct wiphy *wiphy)
 {
 	/*
@@ -1208,19 +1216,40 @@  static void parse_supported_frequencies(struct wiphy *wiphy,
 	struct l_genl_attr attr;
 
 	while (l_genl_attr_next(freqs, NULL, NULL, NULL)) {
+		uint32_t freq = 0;
+		bool disabled = false;
+
 		if (!l_genl_attr_recurse(freqs, &attr))
 			continue;
 
 		while (l_genl_attr_next(&attr, &type, &len, &data)) {
-			uint32_t u32;
 
 			switch (type) {
 			case NL80211_FREQUENCY_ATTR_FREQ:
-				u32 = *((uint32_t *) data);
-				scan_freq_set_add(wiphy->supported_freqs, u32);
+				freq = *((uint32_t *) data);
+				break;
+			case NL80211_FREQUENCY_ATTR_DISABLED:
+				disabled = true;
 				break;
 			}
 		}
+
+		if (!freq)
+			continue;
+
+		/*
+		 * Wiphy is dumped again on every regulatory domain change which
+		 * may contain disabled frequencies which were previously
+		 * allowed. If disabled, remove from supported. If supported,
+		 * remove from disabled.
+		 */
+		if (disabled) {
+			scan_freq_set_add(wiphy->disabled_freqs, freq);
+			scan_freq_set_remove(wiphy->supported_freqs, freq);
+		} else {
+			scan_freq_set_add(wiphy->supported_freqs, freq);
+			scan_freq_set_remove(wiphy->disabled_freqs, freq);
+		}
 	}
 }
 
diff --git a/src/wiphy.h b/src/wiphy.h
index acc64193..9a3b96f9 100644
--- a/src/wiphy.h
+++ b/src/wiphy.h
@@ -93,6 +93,7 @@  const char *wiphy_get_path(struct wiphy *wiphy);
 uint32_t wiphy_get_supported_bands(struct wiphy *wiphy);
 const struct scan_freq_set *wiphy_get_supported_freqs(
 						const struct wiphy *wiphy);
+const struct scan_freq_set *wiphy_get_disabled_freqs(const struct wiphy *wiphy);
 bool wiphy_can_transition_disable(struct wiphy *wiphy);
 bool wiphy_can_offload(struct wiphy *wiphy);
 bool wiphy_supports_cmds_auth_assoc(struct wiphy *wiphy);