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>
This commit is contained in:
parent
ea28dfb5f9
commit
4e22953eb1
3 changed files with 100 additions and 1 deletions
|
@ -282,6 +282,8 @@ struct iwinfo_ops {
|
||||||
int (*survey)(const char *, char *, int *);
|
int (*survey)(const char *, char *, int *);
|
||||||
int (*lookup_phy)(const char *, char *);
|
int (*lookup_phy)(const char *, char *);
|
||||||
void (*close)(void);
|
void (*close)(void);
|
||||||
|
int (*center_chan1)(const char *, int *);
|
||||||
|
int (*center_chan2)(const char *, int *);
|
||||||
};
|
};
|
||||||
|
|
||||||
const char * iwinfo_type(const char *ifname);
|
const char * iwinfo_type(const char *ifname);
|
||||||
|
|
23
iwinfo_cli.c
23
iwinfo_cli.c
|
@ -445,6 +445,24 @@ static char * print_channel(const struct iwinfo_ops *iw, const char *ifname)
|
||||||
return format_channel(ch);
|
return format_channel(ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char * print_center_chan1(const struct iwinfo_ops *iw, const char *ifname)
|
||||||
|
{
|
||||||
|
int ch;
|
||||||
|
if (iw->center_chan1(ifname, &ch))
|
||||||
|
ch = -1;
|
||||||
|
|
||||||
|
return format_channel(ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
static char * print_center_chan2(const struct iwinfo_ops *iw, const char *ifname)
|
||||||
|
{
|
||||||
|
int ch;
|
||||||
|
if (iw->center_chan2(ifname, &ch))
|
||||||
|
ch = -1;
|
||||||
|
|
||||||
|
return format_channel(ch);
|
||||||
|
}
|
||||||
|
|
||||||
static char * print_frequency(const struct iwinfo_ops *iw, const char *ifname)
|
static char * print_frequency(const struct iwinfo_ops *iw, const char *ifname)
|
||||||
{
|
{
|
||||||
int freq;
|
int freq;
|
||||||
|
@ -566,6 +584,11 @@ static void print_info(const struct iwinfo_ops *iw, const char *ifname)
|
||||||
print_mode(iw, ifname),
|
print_mode(iw, ifname),
|
||||||
print_channel(iw, ifname),
|
print_channel(iw, ifname),
|
||||||
print_frequency(iw, ifname));
|
print_frequency(iw, ifname));
|
||||||
|
if (iw->center_chan1 != NULL) {
|
||||||
|
printf(" Center Channel 1: %s",
|
||||||
|
print_center_chan1(iw, ifname));
|
||||||
|
printf(" 2: %s\n", print_center_chan2(iw, ifname));
|
||||||
|
}
|
||||||
printf(" Tx-Power: %s Link Quality: %s/%s\n",
|
printf(" Tx-Power: %s Link Quality: %s/%s\n",
|
||||||
print_txpower(iw, ifname),
|
print_txpower(iw, ifname),
|
||||||
print_quality(iw, ifname),
|
print_quality(iw, ifname),
|
||||||
|
|
|
@ -1262,6 +1262,56 @@ static int nl80211_get_frequency(const char *ifname, int *buf)
|
||||||
return (*buf == 0) ? -1 : 0;
|
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)
|
static int nl80211_get_channel(const char *ifname, int *buf)
|
||||||
{
|
{
|
||||||
if (!nl80211_get_frequency(ifname, buf))
|
if (!nl80211_get_frequency(ifname, buf))
|
||||||
|
@ -1273,6 +1323,28 @@ static int nl80211_get_channel(const char *ifname, int *buf)
|
||||||
return -1;
|
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)
|
static int nl80211_get_txpower_cb(struct nl_msg *msg, void *arg)
|
||||||
{
|
{
|
||||||
int *buf = arg;
|
int *buf = arg;
|
||||||
|
@ -3272,5 +3344,7 @@ const struct iwinfo_ops nl80211_ops = {
|
||||||
.countrylist = nl80211_get_countrylist,
|
.countrylist = nl80211_get_countrylist,
|
||||||
.survey = nl80211_get_survey,
|
.survey = nl80211_get_survey,
|
||||||
.lookup_phy = nl80211_lookup_phyname,
|
.lookup_phy = nl80211_lookup_phyname,
|
||||||
.close = nl80211_close
|
.close = nl80211_close,
|
||||||
|
.center_chan1 = nl80211_get_center_chan1,
|
||||||
|
.center_chan2 = nl80211_get_center_chan2
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue