mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-22 23:09:34 +01:00
scan: Add scan_freq_set utility class
This commit is contained in:
parent
5ae63817b9
commit
b70f5a239d
60
src/scan.c
60
src/scan.c
@ -664,6 +664,66 @@ uint8_t scan_freq_to_channel(uint32_t freq, enum scan_band *out_band)
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct scan_freq_set {
|
||||
uint16_t channels_2ghz;
|
||||
struct l_uintset *channels_5ghz;
|
||||
};
|
||||
|
||||
struct scan_freq_set *scan_freq_set_new(void)
|
||||
{
|
||||
struct scan_freq_set *ret = l_new(struct scan_freq_set, 1);
|
||||
|
||||
/* 802.11-2012, 8.4.2.10 hints that 200 is the largest channel number */
|
||||
ret->channels_5ghz = l_uintset_new_from_range(1, 200);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void scan_freq_set_free(struct scan_freq_set *freqs)
|
||||
{
|
||||
l_free(freqs->channels_5ghz);
|
||||
l_free(freqs);
|
||||
}
|
||||
|
||||
bool scan_freq_set_add(struct scan_freq_set *freqs, uint32_t freq)
|
||||
{
|
||||
enum scan_band band;
|
||||
uint8_t channel;
|
||||
|
||||
channel = scan_freq_to_channel(freq, &band);
|
||||
if (!channel)
|
||||
return false;
|
||||
|
||||
switch (band) {
|
||||
case SCAN_BAND_2_4_GHZ:
|
||||
freqs->channels_2ghz |= 1 << (channel - 1);
|
||||
return true;
|
||||
case SCAN_BAND_5_GHZ:
|
||||
return l_uintset_put(freqs->channels_5ghz, channel);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool scan_freq_set_contains(struct scan_freq_set *freqs, uint32_t freq)
|
||||
{
|
||||
enum scan_band band;
|
||||
uint8_t channel;
|
||||
|
||||
channel = scan_freq_to_channel(freq, &band);
|
||||
if (!channel)
|
||||
return false;
|
||||
|
||||
switch (band) {
|
||||
case SCAN_BAND_2_4_GHZ:
|
||||
return freqs->channels_2ghz & (1 << (channel - 1));
|
||||
case SCAN_BAND_5_GHZ:
|
||||
return l_uintset_contains(freqs->channels_5ghz, channel);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool scan_init(struct l_genl_family *in, scan_notify_func_t func)
|
||||
{
|
||||
nl80211 = in;
|
||||
|
@ -36,6 +36,8 @@ typedef void (*scan_func_t)(struct l_genl_msg *msg, void *user_data);
|
||||
typedef bool (*scan_notify_func_t)(uint32_t wiphy, uint32_t ifindex,
|
||||
struct l_queue *bss_list);
|
||||
|
||||
struct scan_freq_set;
|
||||
|
||||
struct scan_bss {
|
||||
uint8_t addr[6];
|
||||
uint32_t frequency;
|
||||
@ -70,5 +72,10 @@ void bss_get_supported_ciphers(struct scan_bss *bss,
|
||||
|
||||
uint8_t scan_freq_to_channel(uint32_t freq, enum scan_band *out_band);
|
||||
|
||||
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_contains(struct scan_freq_set *freqs, uint32_t freq);
|
||||
|
||||
bool scan_init(struct l_genl_family *in, scan_notify_func_t func);
|
||||
bool scan_free();
|
||||
|
Loading…
Reference in New Issue
Block a user