diff mbox series

[07/10] util: add scan_freq_set_subtract

Message ID 20220726170920.15929-7-prestwoj@gmail.com (mailing list archive)
State Accepted, archived
Headers show
Series [01/10] manager: unregister nl80211 config watch | expand

Checks

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

Commit Message

James Prestwood July 26, 2022, 5:09 p.m. UTC
Removes any frequencies from one set that are found in the other.
---
 src/util.c | 22 ++++++++++++++++++++++
 src/util.h |  2 ++
 2 files changed, 24 insertions(+)
diff mbox series

Patch

diff --git a/src/util.c b/src/util.c
index 3c6e2b1b..ebaff6a0 100644
--- a/src/util.c
+++ b/src/util.c
@@ -499,6 +499,28 @@  void scan_freq_set_constrain(struct scan_freq_set *set,
 	set->channels_2ghz &= constraint->channels_2ghz;
 }
 
+void scan_freq_set_subtract(struct scan_freq_set *set,
+					const struct scan_freq_set *subtract)
+{
+	struct l_uintset *sub;
+
+	sub = l_uintset_subtract(set->channels_6ghz, subtract->channels_6ghz);
+	if (L_WARN_ON(!sub))
+		return;
+
+	l_uintset_free(set->channels_6ghz);
+	set->channels_6ghz = sub;
+
+	sub = l_uintset_subtract(set->channels_5ghz, subtract->channels_5ghz);
+	if (L_WARN_ON(!sub))
+		return;
+
+	l_uintset_free(set->channels_5ghz);
+	set->channels_5ghz = sub;
+
+	set->channels_2ghz &= ~subtract->channels_2ghz;
+}
+
 static void add_foreach(uint32_t freq, void *user_data)
 {
 	uint32_t **list = user_data;
diff --git a/src/util.h b/src/util.h
index f61e3575..0b7832fb 100644
--- a/src/util.h
+++ b/src/util.h
@@ -118,6 +118,8 @@  void scan_freq_set_merge(struct scan_freq_set *to,
 					const struct scan_freq_set *from);
 void scan_freq_set_constrain(struct scan_freq_set *set,
 					const struct scan_freq_set *constraint);
+void scan_freq_set_subtract(struct scan_freq_set *set,
+					const struct scan_freq_set *subtract);
 bool scan_freq_set_isempty(const struct scan_freq_set *set);
 uint32_t *scan_freq_set_to_fixed_array(const struct scan_freq_set *set,
 					size_t *len_out);