diff options
author | Ansuel Smith <ansuelsmth@gmail.com> | 2020-12-06 02:11:16 +0100 |
---|---|---|
committer | Daniel Golle <daniel@makrotopia.org> | 2021-01-05 22:19:43 +0000 |
commit | 4e22953eb171d432afd394af03423cee70ec8858 (patch) | |
tree | 804e898398d72d0e537f05559a4a4b5d22ceeef5 /iwinfo_nl80211.c | |
parent | ea28dfb5f9578294919ca4087f281cbdd45f68a9 (diff) | |
download | iwinfo-4e22953eb171d432afd394af03423cee70ec8858.tar.gz |
iwinfo: export center_chan info for local wifi
Iwinfo already export the htmode but there is no way to know where the
channel expan in case a 40Mhz+ channel width is used. Export the center
channels used by the driver to better know the channel utilizzation of
the wifi.
Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
Diffstat (limited to 'iwinfo_nl80211.c')
-rw-r--r-- | iwinfo_nl80211.c | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c index 80d29dc..b067fc1 100644 --- a/iwinfo_nl80211.c +++ b/iwinfo_nl80211.c @@ -1262,6 +1262,56 @@ static int nl80211_get_frequency(const char *ifname, int *buf) return (*buf == 0) ? -1 : 0; } +static int nl80211_get_center_freq1_cb(struct nl_msg *msg, void *arg) +{ + int *freq = arg; + struct nlattr **tb = nl80211_parse(msg); + + if (tb[NL80211_ATTR_CENTER_FREQ1]) + *freq = nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); + + return NL_SKIP; +} + +static int nl80211_get_center_freq1(const char *ifname, int *buf) +{ + char *res; + + /* try to find frequency from interface info */ + res = nl80211_phy2ifname(ifname); + *buf = 0; + + nl80211_request(res ? res : ifname, NL80211_CMD_GET_INTERFACE, 0, + nl80211_get_center_freq1_cb, buf); + + return (*buf == 0) ? -1 : 0; +} + +static int nl80211_get_center_freq2_cb(struct nl_msg *msg, void *arg) +{ + int *freq = arg; + struct nlattr **tb = nl80211_parse(msg); + + if (tb[NL80211_ATTR_CENTER_FREQ2]) + *freq = nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); + + return NL_SKIP; +} + +static int nl80211_get_center_freq2(const char *ifname, int *buf) +{ + char *res; + + /* try to find frequency from interface info */ + res = nl80211_phy2ifname(ifname); + *buf = 0; + + nl80211_request(res ? res : ifname, NL80211_CMD_GET_INTERFACE, 0, + nl80211_get_center_freq2_cb, buf); + + return (*buf == 0) ? -1 : 0; +} + static int nl80211_get_channel(const char *ifname, int *buf) { if (!nl80211_get_frequency(ifname, buf)) @@ -1273,6 +1323,28 @@ static int nl80211_get_channel(const char *ifname, int *buf) return -1; } +static int nl80211_get_center_chan1(const char *ifname, int *buf) +{ + if (!nl80211_get_center_freq1(ifname, buf)) + { + *buf = nl80211_freq2channel(*buf); + return 0; + } + + return -1; +} + +static int nl80211_get_center_chan2(const char *ifname, int *buf) +{ + if (!nl80211_get_center_freq2(ifname, buf)) + { + *buf = nl80211_freq2channel(*buf); + return 0; + } + + return -1; +} + static int nl80211_get_txpower_cb(struct nl_msg *msg, void *arg) { int *buf = arg; @@ -3272,5 +3344,7 @@ const struct iwinfo_ops nl80211_ops = { .countrylist = nl80211_get_countrylist, .survey = nl80211_get_survey, .lookup_phy = nl80211_lookup_phyname, - .close = nl80211_close + .close = nl80211_close, + .center_chan1 = nl80211_get_center_chan1, + .center_chan2 = nl80211_get_center_chan2 }; |