diff --git a/src/scan.c b/src/scan.c index 873f4bf2..263ba699 100644 --- a/src/scan.c +++ b/src/scan.c @@ -615,6 +615,55 @@ static void scan_notify(struct l_genl_msg *msg, void *user_data) } } +uint8_t scan_freq_to_channel(uint32_t freq, enum scan_band *out_band) +{ + uint32_t channel = 0; + + if (freq >= 2412 && freq <= 2484) { + if (freq == 2484) + channel = 14; + else { + channel = freq - 2407; + + if (channel % 5) + return 0; + + channel /= 5; + } + + if (out_band) + *out_band = SCAN_BAND_2_4_GHZ; + + return channel; + } + + if (freq >= 5005 && freq < 5900) { + if (channel % 5) + return 0; + + channel = (freq - 5000) / 5; + + if (out_band) + *out_band = SCAN_BAND_5_GHZ; + + return channel; + } + + if (freq >= 4905 && freq < 5000) { + if (channel % 5) + return 0; + + channel = (freq - 4000) / 5; + + if (out_band) + *out_band = SCAN_BAND_5_GHZ; + + return channel; + } + + return 0; +} + bool scan_init(struct l_genl_family *in, scan_notify_func_t func) { nl80211 = in; diff --git a/src/scan.h b/src/scan.h index d237b822..76bddd2e 100644 --- a/src/scan.h +++ b/src/scan.h @@ -27,6 +27,11 @@ enum scan_ssid_security { SCAN_SSID_SECURITY_8021X, }; +enum scan_band { + SCAN_BAND_2_4_GHZ, + SCAN_BAND_5_GHZ, +}; + 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); @@ -63,5 +68,7 @@ void bss_get_supported_ciphers(struct scan_bss *bss, uint16_t *pairwise_ciphers, uint16_t *group_ciphers); +uint8_t scan_freq_to_channel(uint32_t freq, enum scan_band *out_band); + bool scan_init(struct l_genl_family *in, scan_notify_func_t func); bool scan_free();