mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2025-01-03 02:02:33 +01:00
scan: Optimize frequency set foreach logic
This commit is contained in:
parent
ef06f06cfb
commit
4b9abde3e5
35
src/scan.c
35
src/scan.c
@ -1672,25 +1672,44 @@ uint32_t scan_freq_set_get_bands(struct scan_freq_set *freqs)
|
|||||||
return bands;
|
return bands;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct channels_5ghz_foreach_data {
|
||||||
|
scan_freq_set_func_t func;
|
||||||
|
void *user_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void scan_channels_5ghz_frequency(uint32_t freq, void *user_data)
|
||||||
|
{
|
||||||
|
const struct channels_5ghz_foreach_data *channels_5ghz_data = user_data;
|
||||||
|
|
||||||
|
channels_5ghz_data->func(freq, channels_5ghz_data->user_data);
|
||||||
|
}
|
||||||
|
|
||||||
void scan_freq_set_foreach(struct scan_freq_set *freqs,
|
void scan_freq_set_foreach(struct scan_freq_set *freqs,
|
||||||
scan_freq_set_func_t func, void *user_data)
|
scan_freq_set_func_t func, void *user_data)
|
||||||
{
|
{
|
||||||
|
struct channels_5ghz_foreach_data data = { };
|
||||||
uint8_t channel;
|
uint8_t channel;
|
||||||
uint32_t freq;
|
uint32_t freq;
|
||||||
|
|
||||||
for (channel = 1; channel <= 14; channel++)
|
if (unlikely(!freqs || !func))
|
||||||
|
return;
|
||||||
|
|
||||||
|
data.func = func;
|
||||||
|
data.user_data = user_data;
|
||||||
|
|
||||||
|
l_uintset_foreach(freqs->channels_5ghz, scan_channels_5ghz_frequency,
|
||||||
|
&data);
|
||||||
|
|
||||||
|
if (!freqs->channels_2ghz)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (channel = 1; channel <= 14; channel++) {
|
||||||
if (freqs->channels_2ghz & (1 << (channel - 1))) {
|
if (freqs->channels_2ghz & (1 << (channel - 1))) {
|
||||||
freq = scan_channel_to_freq(channel, SCAN_BAND_2_4_GHZ);
|
freq = scan_channel_to_freq(channel, SCAN_BAND_2_4_GHZ);
|
||||||
|
|
||||||
func(freq, user_data);
|
func(freq, user_data);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for (channel = 1; channel <= 200; channel++)
|
|
||||||
if (l_uintset_contains(freqs->channels_5ghz, channel)) {
|
|
||||||
freq = scan_channel_to_freq(channel, SCAN_BAND_5_GHZ);
|
|
||||||
|
|
||||||
func(freq, user_data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool scan_init(struct l_genl_family *in)
|
bool scan_init(struct l_genl_family *in)
|
||||||
|
Loading…
Reference in New Issue
Block a user