Add ieee80211_freq_khz_to_channel() so S1G channels with a freq_offset can be derived. Signed-off-by: Lachlan Hodges --- iw.h | 1 + util.c | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/iw.h b/iw.h index 01ef3653f2c2..2155b8d20468 100644 --- a/iw.h +++ b/iw.h @@ -259,6 +259,7 @@ void print_iftype_line(struct nlattr *attr); const char *command_name(enum nl80211_commands cmd); int ieee80211_channel_to_frequency(int chan, enum nl80211_band band); int ieee80211_frequency_to_channel(int freq); +int ieee80211_freq_khz_to_channel(int freq); void print_ssid_escaped(const uint8_t len, const uint8_t *data); diff --git a/util.c b/util.c index 11f8117d5b91..64bec12487e9 100644 --- a/util.c +++ b/util.c @@ -197,10 +197,14 @@ int ieee80211_channel_to_frequency(int chan, enum nl80211_band band) return 0; /* not supported */ } -int ieee80211_frequency_to_channel(int freq) +int ieee80211_freq_khz_to_channel(int freq) { - if (freq < 1000) - return 0; + /* Only US-2020 for S1G currently */ + if (freq < MHZ_TO_KHZ(1000)) + return (freq - 902000) / 500; + + freq = KHZ_TO_MHZ(freq); + /* see 802.11-2007 17.3.8.3.2 and Annex J */ if (freq == 2484) return 14; @@ -222,6 +226,11 @@ int ieee80211_frequency_to_channel(int freq) return 0; } +int ieee80211_frequency_to_channel(int freq) +{ + return ieee80211_freq_khz_to_channel(MHZ_TO_KHZ(freq)); +} + void print_ssid_escaped(const uint8_t len, const uint8_t *data) { int i; -- 2.43.0