diff mbox series

[2/7] util: add scan_freq_set_remove

Message ID 20221213203624.1423277-2-prestwoj@gmail.com (mailing list archive)
State Accepted, archived
Headers show
Series [1/7] band: introduce new method of tracking frequencies | expand

Checks

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

Commit Message

James Prestwood Dec. 13, 2022, 8:36 p.m. UTC
Removes one frequency from a scan_freq_set object.
---
 src/util.c | 22 ++++++++++++++++++++++
 src/util.h |  1 +
 2 files changed, 23 insertions(+)

Comments

Denis Kenzior Dec. 14, 2022, 9:37 p.m. UTC | #1
Hi James,

On 12/13/22 14:36, James Prestwood wrote:
> Removes one frequency from a scan_freq_set object.
> ---
>   src/util.c | 22 ++++++++++++++++++++++
>   src/util.h |  1 +
>   2 files changed, 23 insertions(+)
> 

Applied, thanks.

Regards,
-Denis
diff mbox series

Patch

diff --git a/src/util.c b/src/util.c
index d564ebc0..69019dc8 100644
--- a/src/util.c
+++ b/src/util.c
@@ -360,6 +360,28 @@  bool scan_freq_set_add(struct scan_freq_set *freqs, uint32_t freq)
 	return false;
 }
 
+bool scan_freq_set_remove(struct scan_freq_set *freqs, uint32_t freq)
+{
+	enum band_freq band;
+	uint8_t channel;
+
+	channel = band_freq_to_channel(freq, &band);
+	if (!channel)
+		return false;
+
+	switch (band) {
+	case BAND_FREQ_2_4_GHZ:
+		freqs->channels_2ghz &= ~(1 << (channel - 1));
+		return true;
+	case BAND_FREQ_5_GHZ:
+		return l_uintset_take(freqs->channels_5ghz, channel);
+	case BAND_FREQ_6_GHZ:
+		return l_uintset_take(freqs->channels_6ghz, channel);
+	}
+
+	return false;
+}
+
 bool scan_freq_set_contains(const struct scan_freq_set *freqs, uint32_t freq)
 {
 	enum band_freq band;
diff --git a/src/util.h b/src/util.h
index cc45059f..dafa446d 100644
--- a/src/util.h
+++ b/src/util.h
@@ -111,6 +111,7 @@  typedef void (*scan_freq_set_func_t)(uint32_t freq, void *userdata);
 struct scan_freq_set *scan_freq_set_new(void);
 void scan_freq_set_free(struct scan_freq_set *freqs);
 bool scan_freq_set_add(struct scan_freq_set *freqs, uint32_t freq);
+bool scan_freq_set_remove(struct scan_freq_set *freqs, uint32_t freq);
 bool scan_freq_set_contains(const struct scan_freq_set *freqs, uint32_t freq);
 uint32_t scan_freq_set_get_bands(const struct scan_freq_set *freqs);
 void scan_freq_set_foreach(const struct scan_freq_set *freqs,