diff mbox series

[4/7] util: add scan_freq_set_max

Message ID 20220722163417.1119334-4-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
Finds the maximum frequency in the set
---
 src/util.c | 19 +++++++++++++++++++
 src/util.h |  1 +
 2 files changed, 20 insertions(+)

Comments

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

On 7/22/22 11:34, James Prestwood wrote:
> Finds the maximum frequency in the set
> ---
>   src/util.c | 19 +++++++++++++++++++
>   src/util.h |  1 +
>   2 files changed, 20 insertions(+)
> 

Do you really need this, or is scan_freq_set_get_bands() enough?

Regards,
-Denis
James Prestwood July 22, 2022, 6:19 p.m. UTC | #2
On Fri, 2022-07-22 at 12:41 -0500, Denis Kenzior wrote:
> Hi James,
> 
> On 7/22/22 11:34, James Prestwood wrote:
> > Finds the maximum frequency in the set
> > ---
> >   src/util.c | 19 +++++++++++++++++++
> >   src/util.h |  1 +
> >   2 files changed, 20 insertions(+)
> > 
> 
> Do you really need this, or is scan_freq_set_get_bands() enough?

I think so, because if some known frequency is in the 6G band but not
even supported (e.g. if the card changes) we shouldn't bother doing the
full scan. Somewhat of a corner case though.

> 
> Regards,
> -Denis
>
diff mbox series

Patch

diff --git a/src/util.c b/src/util.c
index 8fdb7f17..2563184e 100644
--- a/src/util.c
+++ b/src/util.c
@@ -379,6 +379,25 @@  bool scan_freq_set_remove(struct scan_freq_set *freqs, uint32_t freq)
 	return false;
 }
 
+uint32_t scan_freq_set_max(struct scan_freq_set *freqs)
+{
+	uint32_t channel;
+
+	if (!l_uintset_isempty(freqs->channels_6ghz)) {
+		channel = l_uintset_find_max(freqs->channels_6ghz);
+		return band_channel_to_freq(channel, BAND_FREQ_6_GHZ);
+	}
+
+	if (!l_uintset_isempty(freqs->channels_5ghz)) {
+		channel = l_uintset_find_max(freqs->channels_5ghz);
+		return band_channel_to_freq(channel, BAND_FREQ_5_GHZ);
+	}
+
+	channel = __builtin_popcount(freqs->channels_2ghz);
+
+	return band_channel_to_freq(channel, BAND_FREQ_2_4_GHZ);
+}
+
 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 ff5211ed..964f6500 100644
--- a/src/util.h
+++ b/src/util.h
@@ -122,5 +122,6 @@  void scan_freq_set_constrain(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);
+uint32_t scan_freq_set_max(struct scan_freq_set *freqs);
 
 #endif /* __UTIL_H */