S1G channels have a freq_offset component so when the attribute is passed print it correctly. Also print whether the S1G 2MHz primary flag is set. root@MM_buildroot:~$ iw dev phy#1 Interface wlan0 ifindex 4 wdev 0x100000001 addr 0c:bf:74:00:30:fd ssid wifi_halow type AP channel 43 (923.500 MHz), width: 8 MHz, center1: 924 MHz, pri_2mhz: 1 txpower 19.00 dBm multicast TXQ: qsz-byt qsz-pkt flows drops marks overlmt hashcol tx-bytes tx-packets 0 0 174 0 0 0 0 10760 174 Signed-off-by: Lachlan Hodges --- info.c | 12 ++++++----- interface.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++------ phy.c | 12 +++++++++-- 3 files changed, 71 insertions(+), 14 deletions(-) diff --git a/info.c b/info.c index 1d123a23eb1c..ef4e23ae3316 100644 --- a/info.c +++ b/info.c @@ -483,7 +483,8 @@ static int print_phy_handler(struct nl_msg *msg, void *arg) band_had_freq = true; } nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) { - uint32_t freq; + uint32_t freq, freq_offset = 0; + int chan; nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq), nla_len(nl_freq), freq_policy); @@ -491,15 +492,16 @@ static int print_phy_handler(struct nl_msg *msg, void *arg) continue; freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]); if (tb_freq[NL80211_FREQUENCY_ATTR_OFFSET]) { - uint32_t offset = nla_get_u32( + freq_offset = nla_get_u32( tb_freq[NL80211_FREQUENCY_ATTR_OFFSET]); - printf("\t\t\t* %d.%d MHz", freq, offset); + printf("\t\t\t* %d.%d MHz", freq, freq_offset); } else { printf("\t\t\t* %d MHz", freq); } - if (ieee80211_frequency_to_channel(freq)) - printf(" [%d]", ieee80211_frequency_to_channel(freq)); + chan = ieee80211_freq_khz_to_channel(MHZ_TO_KHZ(freq) + freq_offset); + if (chan) + printf(" [%d]", chan); if (tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] && !tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) diff --git a/interface.c b/interface.c index a33d05194551..b641bf01baae 100644 --- a/interface.c +++ b/interface.c @@ -367,24 +367,71 @@ char *channel_width_name(enum nl80211_chan_width width) return "10 MHz"; case NL80211_CHAN_WIDTH_320: return "320 MHz"; + case NL80211_CHAN_WIDTH_1: + return "1 MHz"; + case NL80211_CHAN_WIDTH_2: + return "2 MHz"; + case NL80211_CHAN_WIDTH_4: + return "4 MHz"; + case NL80211_CHAN_WIDTH_8: + return "8 MHz"; + case NL80211_CHAN_WIDTH_16: + return "16 MHz"; default: return "unknown"; } } +static bool is_s1g_width(enum nl80211_chan_width width) +{ + switch (width) { + case NL80211_CHAN_WIDTH_1: + case NL80211_CHAN_WIDTH_2: + case NL80211_CHAN_WIDTH_4: + case NL80211_CHAN_WIDTH_8: + case NL80211_CHAN_WIDTH_16: + return true; + default: + return false; + } +} + static void print_channel(struct nlattr **tb) { uint32_t freq = nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]); + uint32_t freq_offset = 0; + int chan; + + if (tb[NL80211_ATTR_WIPHY_FREQ_OFFSET]) + freq_offset = nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ_OFFSET]); - printf("channel %d (%d MHz)", - ieee80211_frequency_to_channel(freq), freq); + chan = ieee80211_freq_khz_to_channel(MHZ_TO_KHZ(freq) + freq_offset); + + if (freq_offset) + printf("channel %d (%d.%03d MHz)", chan, freq, freq_offset); + else + printf("channel %d (%d MHz)", chan, freq); if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { - printf(", width: %s", - channel_width_name(nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH]))); - if (tb[NL80211_ATTR_CENTER_FREQ1]) - printf(", center1: %d MHz", - nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1])); + enum nl80211_chan_width width = + nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH]); + + printf(", width: %s", channel_width_name(width)); + if (tb[NL80211_ATTR_CENTER_FREQ1]) { + uint32_t cf1 = nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); + uint32_t cf1_offset = 0; + + if (tb[NL80211_ATTR_CENTER_FREQ1_OFFSET]) + cf1_offset = nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1_OFFSET]); + + if (cf1_offset) + printf(", center1: %d.%03d MHz", cf1, cf1_offset); + else + printf(", center1: %d MHz", cf1); + } + if (is_s1g_width(width)) + printf(", pri_2mhz: %d", + !!tb[NL80211_ATTR_S1G_PRIMARY_2MHZ]); if (tb[NL80211_ATTR_CENTER_FREQ2]) printf(", center2: %d MHz", nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2])); diff --git a/phy.c b/phy.c index ab629c6b4eb3..84cd025a3d81 100644 --- a/phy.c +++ b/phy.c @@ -87,14 +87,22 @@ static int print_channels_handler(struct nl_msg *msg, void *arg) if (tb_band[NL80211_BAND_ATTR_FREQS]) { nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) { - uint32_t freq; + uint32_t freq, freq_offset = 0; + int chan; nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq), nla_len(nl_freq), NULL); if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) continue; freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]); - printf("\t* %d MHz [%d] ", freq, ieee80211_frequency_to_channel(freq)); + if (tb_freq[NL80211_FREQUENCY_ATTR_OFFSET]) + freq_offset = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_OFFSET]); + + chan = ieee80211_freq_khz_to_channel(MHZ_TO_KHZ(freq) + freq_offset); + if (freq_offset) + printf("\t* %d.%03d MHz [%d] ", freq, freq_offset, chan); + else + printf("\t* %d MHz [%d] ", freq, chan); if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) { printf("(disabled)\n"); -- 2.43.0