diff options
author | Andre Heider <a.heider@gmail.com> | 2022-11-18 12:12:09 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-12-15 23:42:36 +0100 |
commit | 4ba571370d51d3a5b096403e9234e9e3c371dfd2 (patch) | |
tree | a2e8696dc5eb906e369ca323498e06eeac3eef4b | |
parent | 91b2ada7878e5e4530745a2eb9b20ca47c94249b (diff) | |
download | iwinfo-4ba571370d51d3a5b096403e9234e9e3c371dfd2.tar.gz |
nl80211: properly get available bands for the hwmode
Just use the already provided info instead of mapping frequencies.
Fixes mapping lower frequencies of the 6G band, which starts at 5935MHz.
Signed-off-by: Andre Heider <a.heider@gmail.com>
-rw-r--r-- | iwinfo_nl80211.c | 56 |
1 files changed, 21 insertions, 35 deletions
diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c index b9dbdba..720ba11 100644 --- a/iwinfo_nl80211.c +++ b/iwinfo_nl80211.c @@ -153,6 +153,23 @@ static int nl80211_readstr(const char *path, char *buffer, int length) return rv; } +static int nl80211_get_band(int nla_type) +{ + switch (nla_type) + { + case NL80211_BAND_2GHZ: + return IWINFO_BAND_24; + case NL80211_BAND_5GHZ: + return IWINFO_BAND_5; + case NL80211_BAND_6GHZ: + return IWINFO_BAND_6; + case NL80211_BAND_60GHZ: + return IWINFO_BAND_60; + } + + return 0; +} + static int nl80211_msg_error(struct sockaddr_nl *nla, struct nlmsgerr *err, void *arg) @@ -3169,17 +3186,17 @@ static void nl80211_eval_modelist(struct nl80211_modes *m) static int nl80211_get_modelist_cb(struct nl_msg *msg, void *arg) { struct nl80211_modes *m = arg; - int bands_remain, freqs_remain; + int bands_remain; struct nlattr **attr = nl80211_parse(msg); struct nlattr *bands[NL80211_BAND_ATTR_MAX + 1]; - struct nlattr *freqs[NL80211_FREQUENCY_ATTR_MAX + 1]; - struct nlattr *band, *freq; - uint32_t freq_mhz; + struct nlattr *band; if (attr[NL80211_ATTR_WIPHY_BANDS]) { nla_for_each_nested(band, attr[NL80211_ATTR_WIPHY_BANDS], bands_remain) { + m->bands |= nl80211_get_band(band->nla_type); + nla_parse(bands, NL80211_BAND_ATTR_MAX, nla_data(band), nla_len(band), NULL); @@ -3209,37 +3226,6 @@ static int nl80211_get_modelist_cb(struct nl_msg *msg, void *arg) } } } - - if (bands[NL80211_BAND_ATTR_FREQS]) { - nla_for_each_nested(freq, bands[NL80211_BAND_ATTR_FREQS], - freqs_remain) - { - nla_parse(freqs, NL80211_FREQUENCY_ATTR_MAX, - nla_data(freq), nla_len(freq), NULL); - - if (!freqs[NL80211_FREQUENCY_ATTR_FREQ]) - continue; - - freq_mhz = nla_get_u32(freqs[NL80211_FREQUENCY_ATTR_FREQ]); - - if (freq_mhz > 2400 && freq_mhz < 2485) - { - m->bands |= IWINFO_BAND_24; - } - else if (freq_mhz > 5000 && freq_mhz < 5850) - { - m->bands |= IWINFO_BAND_5; - } - else if (freq_mhz > 6000 && freq_mhz < 7120) - { - m->bands |= IWINFO_BAND_6; - } - else if (freq_mhz >= 56160) - { - m->bands |= IWINFO_BAND_60; - } - } - } } m->ok = 1; |