[package] iwinfo: add per-station rate and mcs info to assoclist op

git-svn-id: svn://svn.openwrt.org/openwrt/trunk@30682 3c298f89-4303-0410-b956-a3cf2f4a3e73
master
Jo-Philipp Wich 2012-02-22 13:39:16 +00:00
parent 999cdff204
commit 22f95cf93c
10 changed files with 1305 additions and 88 deletions

View File

@ -7,7 +7,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=libiwinfo PKG_NAME:=libiwinfo
PKG_RELEASE:=28 PKG_RELEASE:=29
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
PKG_CONFIG_DEPENDS := \ PKG_CONFIG_DEPENDS := \

View File

@ -49,10 +49,22 @@ extern const char *IWINFO_KMGMT_NAMES[];
extern const char *IWINFO_AUTH_NAMES[]; extern const char *IWINFO_AUTH_NAMES[];
struct iwinfo_rate_entry {
uint16_t rate;
uint8_t mcs;
uint8_t is_40mhz:1;
uint8_t is_short_gi:1;
};
struct iwinfo_assoclist_entry { struct iwinfo_assoclist_entry {
uint8_t mac[6]; uint8_t mac[6];
int8_t signal; int8_t signal;
int8_t noise; int8_t noise;
uint32_t inactive;
uint32_t rx_packets;
uint32_t tx_packets;
struct iwinfo_rate_entry rx_rate;
struct iwinfo_rate_entry tx_rate;
}; };
struct iwinfo_txpwrlist_entry { struct iwinfo_txpwrlist_entry {

View File

@ -64,6 +64,30 @@ typedef struct wl_sta_rssi {
uint16_t foo; uint16_t foo;
} wl_sta_rssi_t; } wl_sta_rssi_t;
#define WL_NUMRATES 255 /* max # of rates in a rateset */
typedef struct wl_rateset {
uint32_t count; /* # rates in this set */
uint8_t rates[WL_NUMRATES]; /* rates in 500kbps units w/hi bit set if basic */
} wl_rateset_t;
typedef struct wl_sta_info {
uint16_t ver; /* version of this struct */
uint16_t len; /* length in bytes of this structure */
uint16_t cap; /* sta's advertised capabilities */
uint32_t flags; /* flags defined below */
uint32_t idle; /* time since data pkt rx'd from sta */
unsigned char ea[6]; /* Station address */
wl_rateset_t rateset; /* rateset in use */
uint32_t in; /* seconds elapsed since associated */
uint32_t listen_interval_inms; /* Min Listen interval in ms for this STA */
uint32_t tx_pkts; /* # of packets transmitted */
uint32_t tx_failures; /* # of packets failed */
uint32_t rx_ucast_pkts; /* # of unicast packets received */
uint32_t rx_mcast_pkts; /* # of multicast packets received */
uint32_t tx_rate; /* Rate of last successful tx frame */
uint32_t rx_rate; /* Rate of last successful rx frame */
} wl_sta_info_t;
typedef struct wlc_ssid { typedef struct wlc_ssid {
uint32_t ssid_len; uint32_t ssid_len;
unsigned char ssid[32]; unsigned char ssid[32];

View File

@ -24,6 +24,8 @@
/* ieee80211.h */ /* ieee80211.h */
#define IEEE80211_ADDR_LEN 6 #define IEEE80211_ADDR_LEN 6
#define IEEE80211_RATE_VAL 0x7f #define IEEE80211_RATE_VAL 0x7f
#define IEEE80211_SEQ_SEQ_MASK 0xfff0
#define IEEE80211_SEQ_SEQ_SHIFT 4
/* ieee80211_crypto.h */ /* ieee80211_crypto.h */

File diff suppressed because it is too large Load Diff

View File

@ -275,6 +275,34 @@ static char * format_hwmodes(int modes)
return buf; return buf;
} }
static char * format_assocrate(struct iwinfo_rate_entry *r)
{
static char buf[40];
char *p = buf;
int l = sizeof(buf);
if (r->rate <= 0)
{
snprintf(buf, sizeof(buf), "unknown");
}
else
{
p += snprintf(p, l, "%s", format_rate(r->rate));
l = sizeof(buf) - (p - buf);
if (r->mcs >= 0)
{
p += snprintf(p, l, ", MCS %d, %dMHz", r->mcs, 20 + r->is_40mhz*20);
l = sizeof(buf) - (p - buf);
if (r->is_short_gi)
p += snprintf(p, l, ", short GI");
}
}
return buf;
}
static const char * print_type(const struct iwinfo_ops *iw, const char *ifname) static const char * print_type(const struct iwinfo_ops *iw, const char *ifname)
{ {
@ -635,11 +663,22 @@ static void print_assoclist(const struct iwinfo_ops *iw, const char *ifname)
{ {
e = (struct iwinfo_assoclist_entry *) &buf[i]; e = (struct iwinfo_assoclist_entry *) &buf[i];
printf("%s %s / %s (SNR %d)\n", printf("%s %s / %s (SNR %d) %d ms ago\n",
format_bssid(e->mac), format_bssid(e->mac),
format_signal(e->signal), format_signal(e->signal),
format_noise(e->noise), format_noise(e->noise),
(e->signal - e->noise)); (e->signal - e->noise),
e->inactive);
printf(" RX: %-38s %8d Pkts.\n",
format_assocrate(&e->rx_rate),
e->rx_packets
);
printf(" TX: %-38s %8d Pkts.\n\n",
format_assocrate(&e->tx_rate),
e->tx_packets
);
} }
} }

View File

@ -265,6 +265,45 @@ static int iwinfo_L_assoclist(lua_State *L, int (*func)(const char *, char *, in
lua_pushnumber(L, e->noise); lua_pushnumber(L, e->noise);
lua_setfield(L, -2, "noise"); lua_setfield(L, -2, "noise");
lua_pushnumber(L, e->inactive);
lua_setfield(L, -2, "inactive");
lua_pushnumber(L, e->rx_packets);
lua_setfield(L, -2, "rx_packets");
lua_pushnumber(L, e->tx_packets);
lua_setfield(L, -2, "tx_packets");
lua_pushnumber(L, e->rx_rate.rate);
lua_setfield(L, -2, "rx_rate");
lua_pushnumber(L, e->tx_rate.rate);
lua_setfield(L, -2, "tx_rate");
if (e->rx_rate.mcs >= 0)
{
lua_pushnumber(L, e->rx_rate.mcs);
lua_setfield(L, -2, "rx_mcs");
lua_pushboolean(L, e->rx_rate.is_40mhz);
lua_setfield(L, -2, "rx_40mhz");
lua_pushboolean(L, e->rx_rate.is_short_gi);
lua_setfield(L, -2, "rx_short_gi");
}
if (e->tx_rate.mcs >= 0)
{
lua_pushnumber(L, e->tx_rate.mcs);
lua_setfield(L, -2, "tx_mcs");
lua_pushboolean(L, e->tx_rate.is_40mhz);
lua_setfield(L, -2, "tx_40mhz");
lua_pushboolean(L, e->tx_rate.is_short_gi);
lua_setfield(L, -2, "tx_short_gi");
}
lua_setfield(L, -2, macstr); lua_setfield(L, -2, macstr);
} }
} }

View File

@ -726,9 +726,29 @@ int madwifi_get_assoclist(const char *ifname, char *buf, int *len)
do { do {
si = (struct ieee80211req_sta_info *) cp; si = (struct ieee80211req_sta_info *) cp;
memset(&entry, 0, sizeof(entry));
entry.signal = (si->isi_rssi - 95); entry.signal = (si->isi_rssi - 95);
entry.noise = noise; entry.noise = noise;
memcpy(entry.mac, &si->isi_macaddr, 6); memcpy(entry.mac, &si->isi_macaddr, 6);
entry.inactive = si->isi_inact * 1000;
entry.tx_packets = (si->isi_txseqs[0] & IEEE80211_SEQ_SEQ_MASK)
>> IEEE80211_SEQ_SEQ_SHIFT;
entry.rx_packets = (si->isi_rxseqs[0] & IEEE80211_SEQ_SEQ_MASK)
>> IEEE80211_SEQ_SEQ_SHIFT;
entry.tx_rate.rate =
(si->isi_rates[si->isi_txrate] & IEEE80211_RATE_VAL) * 500;
/* XXX: this is just a guess */
entry.rx_rate.rate = entry.tx_rate.rate;
entry.rx_rate.mcs = -1;
entry.tx_rate.mcs = -1;
memcpy(&buf[bl], &entry, sizeof(struct iwinfo_assoclist_entry)); memcpy(&buf[bl], &entry, sizeof(struct iwinfo_assoclist_entry));
bl += sizeof(struct iwinfo_assoclist_entry); bl += sizeof(struct iwinfo_assoclist_entry);

View File

@ -1052,33 +1052,81 @@ static int nl80211_get_assoclist_cb(struct nl_msg *msg, void *arg)
struct iwinfo_assoclist_entry *e = arr->buf; struct iwinfo_assoclist_entry *e = arr->buf;
struct nlattr **attr = nl80211_parse(msg); struct nlattr **attr = nl80211_parse(msg);
struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1];
struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1];
static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
[NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 },
[NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 },
[NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 },
[NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 },
[NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 },
[NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, [NL80211_STA_INFO_RX_BITRATE] = { .type = NLA_NESTED },
[NL80211_STA_INFO_TX_BITRATE] = { .type = NLA_NESTED }, [NL80211_STA_INFO_TX_BITRATE] = { .type = NLA_NESTED },
[NL80211_STA_INFO_LLID] = { .type = NLA_U16 }, [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 },
[NL80211_STA_INFO_PLID] = { .type = NLA_U16 }, };
[NL80211_STA_INFO_PLINK_STATE] = { .type = NLA_U8 },
static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = {
[NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 },
[NL80211_RATE_INFO_MCS] = { .type = NLA_U8 },
[NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG },
[NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG },
}; };
/* advance to end of array */ /* advance to end of array */
e += arr->count; e += arr->count;
memset(e, 0, sizeof(*e));
if (attr[NL80211_ATTR_MAC]) if (attr[NL80211_ATTR_MAC])
memcpy(e->mac, nla_data(attr[NL80211_ATTR_MAC]), 6); memcpy(e->mac, nla_data(attr[NL80211_ATTR_MAC]), 6);
if (attr[NL80211_ATTR_STA_INFO]) if (attr[NL80211_ATTR_STA_INFO] &&
{ !nla_parse_nested(sinfo, NL80211_STA_INFO_MAX,
if (!nla_parse_nested(sinfo, NL80211_STA_INFO_MAX,
attr[NL80211_ATTR_STA_INFO], stats_policy)) attr[NL80211_ATTR_STA_INFO], stats_policy))
{ {
if (sinfo[NL80211_STA_INFO_SIGNAL]) if (sinfo[NL80211_STA_INFO_SIGNAL])
e->signal = nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); e->signal = nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]);
if (sinfo[NL80211_STA_INFO_INACTIVE_TIME])
e->inactive = nla_get_u32(sinfo[NL80211_STA_INFO_INACTIVE_TIME]);
if (sinfo[NL80211_STA_INFO_RX_PACKETS])
e->rx_packets = nla_get_u32(sinfo[NL80211_STA_INFO_RX_PACKETS]);
if (sinfo[NL80211_STA_INFO_TX_PACKETS])
e->tx_packets = nla_get_u32(sinfo[NL80211_STA_INFO_TX_PACKETS]);
if (sinfo[NL80211_STA_INFO_RX_BITRATE] &&
!nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX,
sinfo[NL80211_STA_INFO_RX_BITRATE], rate_policy))
{
if (rinfo[NL80211_RATE_INFO_BITRATE])
e->rx_rate.rate =
nla_get_u16(rinfo[NL80211_RATE_INFO_BITRATE]) * 100;
if (rinfo[NL80211_RATE_INFO_MCS])
e->rx_rate.mcs = nla_get_u8(rinfo[NL80211_RATE_INFO_MCS]);
if (rinfo[NL80211_RATE_INFO_40_MHZ_WIDTH])
e->rx_rate.is_40mhz = 1;
if (rinfo[NL80211_RATE_INFO_SHORT_GI])
e->rx_rate.is_short_gi = 1;
}
if (sinfo[NL80211_STA_INFO_TX_BITRATE] &&
!nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX,
sinfo[NL80211_STA_INFO_TX_BITRATE], rate_policy))
{
if (rinfo[NL80211_RATE_INFO_BITRATE])
e->tx_rate.rate =
nla_get_u16(rinfo[NL80211_RATE_INFO_BITRATE]) * 100;
if (rinfo[NL80211_RATE_INFO_MCS])
e->tx_rate.mcs = nla_get_u8(rinfo[NL80211_RATE_INFO_MCS]);
if (rinfo[NL80211_RATE_INFO_40_MHZ_WIDTH])
e->tx_rate.is_40mhz = 1;
if (rinfo[NL80211_RATE_INFO_SHORT_GI])
e->tx_rate.is_short_gi = 1;
} }
} }
@ -1113,8 +1161,6 @@ int nl80211_get_assoclist(const char *ifname, char *buf, int *len)
nl80211_send(req, nl80211_get_assoclist_cb, &arr); nl80211_send(req, nl80211_get_assoclist_cb, &arr);
nl80211_free(req); nl80211_free(req);
} }
break;
} }
} }

View File

@ -37,6 +37,19 @@ static int wl_ioctl(const char *name, int cmd, void *buf, int len)
return iwinfo_ioctl(SIOCDEVPRIVATE, &ifr); return iwinfo_ioctl(SIOCDEVPRIVATE, &ifr);
} }
static int wl_iovar(const char *name, const char *cmd, const char *arg,
int arglen, void *buf, int buflen)
{
int cmdlen = strlen(cmd) + 1;
memcpy(buf, cmd, cmdlen);
if (arg && arglen > 0)
memcpy(buf + cmdlen, arg, arglen);
return wl_ioctl(name, WLC_GET_VAR, buf, buflen);
}
static struct wl_maclist * wl_read_assoclist(const char *ifname) static struct wl_maclist * wl_read_assoclist(const char *ifname)
{ {
struct wl_maclist *macs; struct wl_maclist *macs;
@ -60,11 +73,8 @@ static struct wl_maclist * wl_read_assoclist(const char *ifname)
int wl_probe(const char *ifname) int wl_probe(const char *ifname)
{ {
int magic; int magic;
return (!wl_ioctl(ifname, WLC_GET_MAGIC, &magic, sizeof(magic)) &&
if( !wl_ioctl(ifname, WLC_GET_MAGIC, &magic, sizeof(magic)) && (magic == WLC_IOCTL_MAGIC)) (magic == WLC_IOCTL_MAGIC));
return 1;
return 0;
} }
void wl_close(void) void wl_close(void)
@ -376,6 +386,26 @@ int wl_get_enctype(const char *ifname, char *buf)
return 0; return 0;
} }
static void wl_get_assoclist_cb(const char *ifname,
struct iwinfo_assoclist_entry *e)
{
wl_sta_info_t sta = { 0 };
if (!wl_iovar(ifname, "sta_info", e->mac, 6, &sta, sizeof(sta)) &&
(sta.ver >= 2))
{
e->inactive = sta.idle * 1000;
e->rx_packets = sta.rx_ucast_pkts;
e->tx_packets = sta.tx_pkts;
e->rx_rate.rate = sta.rx_rate;
e->tx_rate.rate = sta.tx_rate;
/* ToDo: 11n */
e.rx_rate.mcs = -1;
e.tx_rate.mcs = -1;
}
}
int wl_get_assoclist(const char *ifname, char *buf, int *len) int wl_get_assoclist(const char *ifname, char *buf, int *len)
{ {
int i, j, noise; int i, j, noise;
@ -401,6 +431,7 @@ int wl_get_assoclist(const char *ifname, char *buf, int *len)
{ {
for (i = 0, j = 0; i < macs->count; i++, j += sizeof(struct iwinfo_assoclist_entry)) for (i = 0, j = 0; i < macs->count; i++, j += sizeof(struct iwinfo_assoclist_entry))
{ {
memset(&entry, 0, sizeof(entry));
memcpy(rssi.mac, &macs->ea[i], 6); memcpy(rssi.mac, &macs->ea[i], 6);
if (!wl_ioctl(ifname, WLC_GET_RSSI, &rssi, sizeof(struct wl_sta_rssi))) if (!wl_ioctl(ifname, WLC_GET_RSSI, &rssi, sizeof(struct wl_sta_rssi)))
@ -410,6 +441,8 @@ int wl_get_assoclist(const char *ifname, char *buf, int *len)
entry.noise = noise; entry.noise = noise;
memcpy(entry.mac, &macs->ea[i], 6); memcpy(entry.mac, &macs->ea[i], 6);
wl_get_assoclist_cb(ifname, &entry);
memcpy(&buf[j], &entry, sizeof(entry)); memcpy(&buf[j], &entry, sizeof(entry));
} }