[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-a3cf2f4a3e73master
parent
999cdff204
commit
22f95cf93c
|
@ -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 := \
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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];
|
||||||
|
|
|
@ -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
|
@ -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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,17 +37,30 @@ 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;
|
||||||
int maclen = 4 + WL_MAX_STA_COUNT * 6;
|
int maclen = 4 + WL_MAX_STA_COUNT * 6;
|
||||||
|
|
||||||
if( (macs = (struct wl_maclist *) malloc(maclen)) != NULL )
|
if ((macs = (struct wl_maclist *) malloc(maclen)) != NULL)
|
||||||
{
|
{
|
||||||
memset(macs, 0, maclen);
|
memset(macs, 0, maclen);
|
||||||
macs->count = WL_MAX_STA_COUNT;
|
macs->count = WL_MAX_STA_COUNT;
|
||||||
|
|
||||||
if( !wl_ioctl(ifname, WLC_GET_ASSOCLIST, macs, maclen) )
|
if (!wl_ioctl(ifname, WLC_GET_ASSOCLIST, macs, maclen))
|
||||||
return macs;
|
return macs;
|
||||||
|
|
||||||
free(macs);
|
free(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)
|
||||||
|
@ -77,20 +87,20 @@ int wl_get_mode(const char *ifname, char *buf)
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int ap, infra, passive;
|
int ap, infra, passive;
|
||||||
|
|
||||||
if( (ret = wl_ioctl(ifname, WLC_GET_AP, &ap, sizeof(ap))) )
|
if ((ret = wl_ioctl(ifname, WLC_GET_AP, &ap, sizeof(ap))))
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if( (ret = wl_ioctl(ifname, WLC_GET_INFRA, &infra, sizeof(infra))) )
|
if ((ret = wl_ioctl(ifname, WLC_GET_INFRA, &infra, sizeof(infra))))
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if( (ret = wl_ioctl(ifname, WLC_GET_PASSIVE, &passive, sizeof(passive))) )
|
if ((ret = wl_ioctl(ifname, WLC_GET_PASSIVE, &passive, sizeof(passive))))
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if( passive )
|
if (passive)
|
||||||
sprintf(buf, "Monitor");
|
sprintf(buf, "Monitor");
|
||||||
else if( !infra )
|
else if (!infra)
|
||||||
sprintf(buf, "Ad-Hoc");
|
sprintf(buf, "Ad-Hoc");
|
||||||
else if( ap )
|
else if (ap)
|
||||||
sprintf(buf, "Master");
|
sprintf(buf, "Master");
|
||||||
else
|
else
|
||||||
sprintf(buf, "Client");
|
sprintf(buf, "Client");
|
||||||
|
@ -103,7 +113,7 @@ int wl_get_ssid(const char *ifname, char *buf)
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
wlc_ssid_t ssid;
|
wlc_ssid_t ssid;
|
||||||
|
|
||||||
if( !(ret = wl_ioctl(ifname, WLC_GET_SSID, &ssid, sizeof(ssid))) )
|
if (!(ret = wl_ioctl(ifname, WLC_GET_SSID, &ssid, sizeof(ssid))))
|
||||||
memcpy(buf, ssid.ssid, ssid.ssid_len);
|
memcpy(buf, ssid.ssid, ssid.ssid_len);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -114,7 +124,7 @@ int wl_get_bssid(const char *ifname, char *buf)
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char bssid[6];
|
char bssid[6];
|
||||||
|
|
||||||
if( !(ret = wl_ioctl(ifname, WLC_GET_BSSID, bssid, 6)) )
|
if (!(ret = wl_ioctl(ifname, WLC_GET_BSSID, bssid, 6)))
|
||||||
sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X",
|
sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X",
|
||||||
(uint8_t)bssid[0], (uint8_t)bssid[1], (uint8_t)bssid[2],
|
(uint8_t)bssid[0], (uint8_t)bssid[1], (uint8_t)bssid[2],
|
||||||
(uint8_t)bssid[3], (uint8_t)bssid[4], (uint8_t)bssid[5]
|
(uint8_t)bssid[3], (uint8_t)bssid[4], (uint8_t)bssid[5]
|
||||||
|
@ -163,7 +173,7 @@ int wl_get_signal(const char *ifname, int *buf)
|
||||||
|
|
||||||
wl_ioctl(ifname, WLC_GET_BSS_INFO, tmp, WLC_IOCTL_MAXLEN);
|
wl_ioctl(ifname, WLC_GET_BSS_INFO, tmp, WLC_IOCTL_MAXLEN);
|
||||||
|
|
||||||
if( !wl_ioctl(ifname, WLC_GET_AP, &ap, sizeof(ap)) && !ap )
|
if (!wl_ioctl(ifname, WLC_GET_AP, &ap, sizeof(ap)) && !ap)
|
||||||
{
|
{
|
||||||
*buf = tmp[WL_BSS_RSSI_OFFSET];
|
*buf = tmp[WL_BSS_RSSI_OFFSET];
|
||||||
}
|
}
|
||||||
|
@ -172,13 +182,13 @@ int wl_get_signal(const char *ifname, int *buf)
|
||||||
rssi = rssi_count = 0;
|
rssi = rssi_count = 0;
|
||||||
|
|
||||||
/* Calculate average rssi from conntected stations */
|
/* Calculate average rssi from conntected stations */
|
||||||
if( (macs = wl_read_assoclist(ifname)) != NULL )
|
if ((macs = wl_read_assoclist(ifname)) != NULL)
|
||||||
{
|
{
|
||||||
for( i = 0; i < macs->count; i++ )
|
for (i = 0; i < macs->count; i++)
|
||||||
{
|
{
|
||||||
memcpy(starssi.mac, &macs->ea[i], 6);
|
memcpy(starssi.mac, &macs->ea[i], 6);
|
||||||
|
|
||||||
if( !wl_ioctl(ifname, WLC_GET_RSSI, &starssi, 12) )
|
if (!wl_ioctl(ifname, WLC_GET_RSSI, &starssi, 12))
|
||||||
{
|
{
|
||||||
rssi -= starssi.rssi;
|
rssi -= starssi.rssi;
|
||||||
rssi_count++;
|
rssi_count++;
|
||||||
|
@ -259,10 +269,10 @@ int wl_get_encryption(const char *ifname, char *buf)
|
||||||
switch(wpa)
|
switch(wpa)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
if( wsec && !wauth )
|
if (wsec && !wauth)
|
||||||
c->auth_algs |= IWINFO_AUTH_OPEN;
|
c->auth_algs |= IWINFO_AUTH_OPEN;
|
||||||
|
|
||||||
else if( wsec && wauth )
|
else if (wsec && wauth)
|
||||||
c->auth_algs |= IWINFO_AUTH_SHARED;
|
c->auth_algs |= IWINFO_AUTH_SHARED;
|
||||||
|
|
||||||
/* ToDo: evaluate WEP key lengths */
|
/* ToDo: evaluate WEP key lengths */
|
||||||
|
@ -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;
|
||||||
|
@ -394,22 +424,25 @@ int wl_get_assoclist(const char *ifname, char *buf, int *len)
|
||||||
wl_ioctl(ifname, WLC_GET_INFRA, &infra, sizeof(infra));
|
wl_ioctl(ifname, WLC_GET_INFRA, &infra, sizeof(infra));
|
||||||
wl_ioctl(ifname, WLC_GET_PASSIVE, &passive, sizeof(passive));
|
wl_ioctl(ifname, WLC_GET_PASSIVE, &passive, sizeof(passive));
|
||||||
|
|
||||||
if( wl_get_noise(ifname, &noise) )
|
if (wl_get_noise(ifname, &noise))
|
||||||
noise = 0;
|
noise = 0;
|
||||||
|
|
||||||
if( (ap || infra || passive) && ((macs = wl_read_assoclist(ifname)) != NULL) )
|
if ((ap || infra || passive) && ((macs = wl_read_assoclist(ifname)) != NULL))
|
||||||
{
|
{
|
||||||
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)))
|
||||||
entry.signal = (rssi.rssi - 0x100);
|
entry.signal = (rssi.rssi - 0x100);
|
||||||
else
|
else
|
||||||
entry.signal = 0;
|
entry.signal = 0;
|
||||||
|
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,13 +450,13 @@ int wl_get_assoclist(const char *ifname, char *buf, int *len)
|
||||||
free(macs);
|
free(macs);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if( (arp = fopen("/proc/net/arp", "r")) != NULL )
|
else if ((arp = fopen("/proc/net/arp", "r")) != NULL)
|
||||||
{
|
{
|
||||||
j = 0;
|
j = 0;
|
||||||
|
|
||||||
while( fgets(line, sizeof(line), arp) != NULL )
|
while (fgets(line, sizeof(line), arp) != NULL)
|
||||||
{
|
{
|
||||||
if( sscanf(line, "%*s 0x%*d 0x%*d %17s %*s %s", macstr, devstr) && !strcmp(devstr, ifname) )
|
if (sscanf(line, "%*s 0x%*d 0x%*d %17s %*s %s", macstr, devstr) && !strcmp(devstr, ifname))
|
||||||
{
|
{
|
||||||
rssi.mac[0] = strtol(&macstr[0], NULL, 16);
|
rssi.mac[0] = strtol(&macstr[0], NULL, 16);
|
||||||
rssi.mac[1] = strtol(&macstr[3], NULL, 16);
|
rssi.mac[1] = strtol(&macstr[3], NULL, 16);
|
||||||
|
@ -432,7 +465,7 @@ int wl_get_assoclist(const char *ifname, char *buf, int *len)
|
||||||
rssi.mac[4] = strtol(&macstr[12], NULL, 16);
|
rssi.mac[4] = strtol(&macstr[12], NULL, 16);
|
||||||
rssi.mac[5] = strtol(&macstr[15], NULL, 16);
|
rssi.mac[5] = strtol(&macstr[15], NULL, 16);
|
||||||
|
|
||||||
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)))
|
||||||
entry.signal = (rssi.rssi - 0x100);
|
entry.signal = (rssi.rssi - 0x100);
|
||||||
else
|
else
|
||||||
entry.signal = 0;
|
entry.signal = 0;
|
||||||
|
@ -460,7 +493,7 @@ int wl_get_txpwrlist(const char *ifname, char *buf, int *len)
|
||||||
uint8_t mw[8] = { 1, 3, 6, 10, 15, 25, 39, 63 };
|
uint8_t mw[8] = { 1, 3, 6, 10, 15, 25, 39, 63 };
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for( i = 0; i < 8; i++ )
|
for (i = 0; i < 8; i++)
|
||||||
{
|
{
|
||||||
entry.dbm = dbm[i];
|
entry.dbm = dbm[i];
|
||||||
entry.mw = mw[i];
|
entry.mw = mw[i];
|
||||||
|
@ -485,14 +518,14 @@ int wl_get_country(const char *ifname, char *buf)
|
||||||
{
|
{
|
||||||
char ccode[WLC_CNTRY_BUF_SZ];
|
char ccode[WLC_CNTRY_BUF_SZ];
|
||||||
|
|
||||||
if( !wl_ioctl(ifname, WLC_GET_COUNTRY, ccode, WLC_CNTRY_BUF_SZ) )
|
if (!wl_ioctl(ifname, WLC_GET_COUNTRY, ccode, WLC_CNTRY_BUF_SZ))
|
||||||
{
|
{
|
||||||
/* IL0 -> World */
|
/* IL0 -> World */
|
||||||
if( !strcmp(ccode, "IL0") )
|
if (!strcmp(ccode, "IL0"))
|
||||||
sprintf(buf, "00");
|
sprintf(buf, "00");
|
||||||
|
|
||||||
/* YU -> RS */
|
/* YU -> RS */
|
||||||
else if( !strcmp(ccode, "YU") )
|
else if (!strcmp(ccode, "YU"))
|
||||||
sprintf(buf, "RS");
|
sprintf(buf, "RS");
|
||||||
|
|
||||||
else
|
else
|
||||||
|
@ -513,19 +546,19 @@ int wl_get_countrylist(const char *ifname, char *buf, int *len)
|
||||||
|
|
||||||
cl->buflen = sizeof(cdata);
|
cl->buflen = sizeof(cdata);
|
||||||
|
|
||||||
if( !wl_ioctl(ifname, WLC_GET_COUNTRY_LIST, cl, cl->buflen) )
|
if (!wl_ioctl(ifname, WLC_GET_COUNTRY_LIST, cl, cl->buflen))
|
||||||
{
|
{
|
||||||
for( i = 0, count = 0; i < cl->count; i++, c++ )
|
for (i = 0, count = 0; i < cl->count; i++, c++)
|
||||||
{
|
{
|
||||||
sprintf(c->ccode, &cl->country_abbrev[i * WLC_CNTRY_BUF_SZ]);
|
sprintf(c->ccode, &cl->country_abbrev[i * WLC_CNTRY_BUF_SZ]);
|
||||||
c->iso3166 = c->ccode[0] * 256 + c->ccode[1];
|
c->iso3166 = c->ccode[0] * 256 + c->ccode[1];
|
||||||
|
|
||||||
/* IL0 -> World */
|
/* IL0 -> World */
|
||||||
if( !strcmp(c->ccode, "IL0") )
|
if (!strcmp(c->ccode, "IL0"))
|
||||||
c->iso3166 = 0x3030;
|
c->iso3166 = 0x3030;
|
||||||
|
|
||||||
/* YU -> RS */
|
/* YU -> RS */
|
||||||
else if( !strcmp(c->ccode, "YU") )
|
else if (!strcmp(c->ccode, "YU"))
|
||||||
c->iso3166 = 0x5253;
|
c->iso3166 = 0x5253;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -546,9 +579,9 @@ int wl_get_mbssid_support(const char *ifname, int *buf)
|
||||||
wlc_rev_info_t revinfo;
|
wlc_rev_info_t revinfo;
|
||||||
|
|
||||||
/* Multi bssid support only works on corerev >= 9 */
|
/* Multi bssid support only works on corerev >= 9 */
|
||||||
if( !wl_ioctl(ifname, WLC_GET_REVINFO, &revinfo, sizeof(revinfo)) )
|
if (!wl_ioctl(ifname, WLC_GET_REVINFO, &revinfo, sizeof(revinfo)))
|
||||||
{
|
{
|
||||||
if( revinfo.corerev >= 9 )
|
if (revinfo.corerev >= 9)
|
||||||
{
|
{
|
||||||
*buf = 1;
|
*buf = 1;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue