From 0bc44a038b8cd480b5331256fb3bdf0ebcc71d94 Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Thu, 4 Aug 2022 15:02:47 -0700 Subject: [PATCH] util: add scan_freq_set_clone This creates a new scan_freq_set from an input set which only contains frequencies from bands included in the mask. --- src/util.c | 21 +++++++++++++++++++++ src/util.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/src/util.c b/src/util.c index ebaff6a0..dfee77fa 100644 --- a/src/util.c +++ b/src/util.c @@ -554,3 +554,24 @@ uint32_t *scan_freq_set_to_fixed_array(const struct scan_freq_set *set, return freqs; } + +struct scan_freq_set *scan_freq_set_clone(const struct scan_freq_set *set, + uint32_t band_mask) +{ + struct scan_freq_set *new = l_new(struct scan_freq_set, 1); + + if (band_mask & BAND_FREQ_2_4_GHZ) + new->channels_2ghz = set->channels_2ghz; + + if (band_mask & BAND_FREQ_5_GHZ) + new->channels_5ghz = l_uintset_clone(set->channels_5ghz); + else + new->channels_5ghz = l_uintset_new_from_range(1, 200); + + if (band_mask & BAND_FREQ_6_GHZ) + new->channels_6ghz = l_uintset_clone(set->channels_6ghz); + else + new->channels_6ghz = l_uintset_new_from_range(1, 233); + + return new; +} diff --git a/src/util.h b/src/util.h index 6315198a..cc45059f 100644 --- a/src/util.h +++ b/src/util.h @@ -124,6 +124,8 @@ void scan_freq_set_subtract(struct scan_freq_set *set, 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); +struct scan_freq_set *scan_freq_set_clone(const struct scan_freq_set *set, + uint32_t band_mask); DEFINE_CLEANUP_FUNC(scan_freq_set_free);