From 081b0af2d6bcfda7a750c589959199d7e76b2a36 Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Tue, 26 Jul 2022 10:09:17 -0700 Subject: [PATCH] util: add scan_freq_set_subtract 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 --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);