update for vaps

Supported by:	Hobnob
This commit is contained in:
Sam Leffler 2008-04-20 20:41:47 +00:00
parent a18abc8eeb
commit 525de97e17
3 changed files with 148 additions and 33 deletions

View File

@ -31,7 +31,7 @@
/*
* wlanstats [-i interface]
* (default interface is ath0).
* (default interface is wlan0).
*/
#include <sys/types.h>
@ -39,10 +39,12 @@
#include <net/ethernet.h>
#include <net80211/_ieee80211.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <err.h>
#include <strings.h>
#include "wlanstats.h"
@ -139,7 +141,7 @@ main(int argc, char *argv[])
int allnodes = 0;
int c, mode;
wf = wlanstats_new("ath0", S_DEFAULT);
wf = wlanstats_new("wlan0", S_DEFAULT);
while ((c = getopt(argc, argv, "ai:lm:o:")) != -1) {
switch (c) {
case 'a':

View File

@ -113,7 +113,10 @@ static const struct fmt wlanstats[] = {
"rx w/ unsupported auth alg" },
#define S_RX_AUTH_FAIL AFTER(S_RX_AUTH_UNSUPPORTED)
{ 5, "rx_auth_fail", "auth_fail", "rx sta auth failure" },
#define S_RX_AUTH_COUNTERMEASURES AFTER(S_RX_AUTH_FAIL)
#define S_RX_AUTH_FAIL_CODE AFTER(S_RX_AUTH_FAIL)
{ 5, "rx_auth_fail_code","auth_fail_code",
"last rx auth failure reason" },
#define S_RX_AUTH_COUNTERMEASURES AFTER(S_RX_AUTH_FAIL_CODE)
{ 5, "rx_auth_countermeasures", "auth_countermeasures",
"rx sta auth failure 'cuz of TKIP countermeasures" },
#define S_RX_ASSOC_BSS AFTER(S_RX_AUTH_COUNTERMEASURES)
@ -130,9 +133,16 @@ static const struct fmt wlanstats[] = {
"rx assoc w/ bad WPA IE" },
#define S_RX_DEAUTH AFTER(S_RX_ASSOC_BADWPAIE)
{ 5, "rx_deauth", "deauth", "rx deauthentication" },
#define S_RX_DISASSOC AFTER(S_RX_DEAUTH)
#define S_RX_DEAUTH_CODE AFTER(S_RX_DEAUTH)
{ 5, "rx_deauth_code","deauth_code", "last rx deauth reason" },
#define S_RX_DISASSOC AFTER(S_RX_DEAUTH_CODE)
{ 5, "rx_disassoc", "disassoc", "rx disassociation" },
#define S_RX_BADSUBTYPE AFTER(S_RX_DISASSOC)
#define S_RX_DISASSOC_CODE AFTER(S_RX_DISASSOC)
{ 5, "rx_disassoc_code","disassoc_code",
"last rx disassoc reason" },
#define S_BMISS AFTER(S_RX_DISASSOC_CODE)
{ 5, "bmiss", "bmiss", "beacon miss events handled" },
#define S_RX_BADSUBTYPE AFTER(S_BMISS)
{ 5, "rx_badsubtype", "badsubtype", "rx frame w/ unknown subtype" },
#define S_RX_NOBUF AFTER(S_RX_BADSUBTYPE)
{ 5, "rx_nobuf", "nobuf", "rx failed for lack of mbuf" },
@ -188,7 +198,9 @@ static const struct fmt wlanstats[] = {
{ 5, "scan_active", "scan_active", "active scans started" },
#define S_SCAN_PASSIVE AFTER(S_SCAN_ACTIVE)
{ 5, "scan_passive", "scan_passive", "passive scans started" },
#define S_NODE_TIMEOUT AFTER(S_SCAN_PASSIVE)
#define S_SCAN_BG AFTER(S_SCAN_PASSIVE)
{ 5, "scan_bg", "scan_bg", "background scans started" },
#define S_NODE_TIMEOUT AFTER(S_SCAN_BG)
{ 5, "node_timeout", "node_timeout", "nodes timed out for inactivity" },
#define S_CRYPTO_NOMEM AFTER(S_NODE_TIMEOUT)
{ 5, "crypto_nomem", "crypto_nomem", "cipher context malloc failed" },
@ -446,14 +458,14 @@ wlan_collect(struct wlanstatfoo_p *wf,
wf->ireq.i_data = (caddr_t) &wf->u_info;
wf->ireq.i_len = sizeof(wf->u_info);
if (ioctl(wf->s, SIOCG80211, &wf->ireq) < 0)
err(1, "%s (IEEE80211_IOC_STA_INFO)", wf->ireq.i_name);
warn("%s (IEEE80211_IOC_STA_INFO)", wf->ireq.i_name);
IEEE80211_ADDR_COPY(nstats->is_u.macaddr, wf->mac);
wf->ireq.i_type = IEEE80211_IOC_STA_STATS;
wf->ireq.i_data = (caddr_t) nstats;
wf->ireq.i_len = sizeof(*nstats);
if (ioctl(wf->s, SIOCG80211, &wf->ireq) < 0)
err(1, "%s (IEEE80211_IOC_STA_STATS)", wf->ireq.i_name);
warn("%s (IEEE80211_IOC_STA_STATS)", wf->ireq.i_name);
wf->ifr.ifr_data = (caddr_t) stats;
if (ioctl(wf->s, SIOCG80211STATS, &wf->ifr) < 0)
@ -485,16 +497,89 @@ wlan_update_tot(struct statfoo *sf)
wf->ntotal = wf->ncur;
}
void
setreason(char b[], size_t bs, int v)
{
#define N(a) (sizeof(a)/sizeof(a[0]))
static const char *reasons[] = {
[IEEE80211_REASON_UNSPECIFIED] = "unspecified",
[IEEE80211_REASON_AUTH_EXPIRE] = "auth expire",
[IEEE80211_REASON_AUTH_LEAVE] = "auth leave",
[IEEE80211_REASON_ASSOC_EXPIRE] = "assoc expire",
[IEEE80211_REASON_ASSOC_TOOMANY] = "assoc toomany",
[IEEE80211_REASON_NOT_AUTHED] = "not authed",
[IEEE80211_REASON_NOT_ASSOCED] = "not assoced",
[IEEE80211_REASON_ASSOC_LEAVE] = "assoc leave",
[IEEE80211_REASON_ASSOC_NOT_AUTHED] = "assoc not authed",
[IEEE80211_REASON_DISASSOC_PWRCAP_BAD] = "disassoc pwrcap bad",
[IEEE80211_REASON_DISASSOC_SUPCHAN_BAD] = "disassoc supchan bad",
[IEEE80211_REASON_IE_INVALID] = "ie invalid",
[IEEE80211_REASON_MIC_FAILURE] = "mic failure",
[IEEE80211_REASON_4WAY_HANDSHAKE_TIMEOUT]= "4-way handshake timeout",
[IEEE80211_REASON_GROUP_KEY_UPDATE_TIMEOUT] = "group key update timeout",
[IEEE80211_REASON_IE_IN_4WAY_DIFFERS] = "ie in 4-way differs",
[IEEE80211_REASON_GROUP_CIPHER_INVALID] = "group cipher invalid",
[IEEE80211_REASON_PAIRWISE_CIPHER_INVALID]= "pairwise cipher invalid",
[IEEE80211_REASON_AKMP_INVALID] = "akmp invalid",
[IEEE80211_REASON_UNSUPP_RSN_IE_VERSION]= "unsupported rsn ie version",
[IEEE80211_REASON_INVALID_RSN_IE_CAP] = "invalid rsn ie cap",
[IEEE80211_REASON_802_1X_AUTH_FAILED] = "802.1x auth failed",
[IEEE80211_REASON_CIPHER_SUITE_REJECTED]= "cipher suite rejected",
};
if (v < N(reasons) && reasons[v] != NULL)
snprintf(b, bs, "%s (%u)", reasons[v], v);
else
snprintf(b, bs, "%u", v);
#undef N
}
void
setstatus(char b[], size_t bs, int v)
{
#define N(a) (sizeof(a)/sizeof(a[0]))
static const char *status[] = {
[IEEE80211_STATUS_SUCCESS] = "success",
[IEEE80211_STATUS_UNSPECIFIED] = "unspecified",
[IEEE80211_STATUS_CAPINFO] = "capinfo",
[IEEE80211_STATUS_NOT_ASSOCED] = "not assoced",
[IEEE80211_STATUS_OTHER] = "other",
[IEEE80211_STATUS_ALG] = "algorithm",
[IEEE80211_STATUS_SEQUENCE] = "sequence",
[IEEE80211_STATUS_CHALLENGE] = "challenge",
[IEEE80211_STATUS_TIMEOUT] = "timeout",
[IEEE80211_STATUS_TOOMANY] = "toomany",
[IEEE80211_STATUS_BASIC_RATE] = "basic rate",
[IEEE80211_STATUS_SP_REQUIRED] = "sp required",
[IEEE80211_STATUS_PBCC_REQUIRED] = "pbcc required",
[IEEE80211_STATUS_CA_REQUIRED] = "ca required",
[IEEE80211_STATUS_SPECMGMT_REQUIRED] = "specmgmt required",
[IEEE80211_STATUS_PWRCAP_REQUIRED] = "pwrcap required",
[IEEE80211_STATUS_SUPCHAN_REQUIRED] = "supchan required",
[IEEE80211_STATUS_SHORTSLOT_REQUIRED] = "shortslot required",
[IEEE80211_STATUS_DSSSOFDM_REQUIRED] = "dsssofdm required",
[IEEE80211_STATUS_INVALID_IE] = "invalid ie",
[IEEE80211_STATUS_GROUP_CIPHER_INVALID] = "group cipher invalid",
[IEEE80211_STATUS_PAIRWISE_CIPHER_INVALID]= "pairwise cipher invalid",
[IEEE80211_STATUS_AKMP_INVALID] = "akmp invalid",
[IEEE80211_STATUS_UNSUPP_RSN_IE_VERSION]= "unsupported rsn ie version",
[IEEE80211_STATUS_INVALID_RSN_IE_CAP] = "invalid rsn ie cap",
[IEEE80211_STATUS_CIPHER_SUITE_REJECTED]= "cipher suite rejected",
};
if (v < N(status) && status[v] != NULL)
snprintf(b, bs, "%s (%u)", status[v], v);
else
snprintf(b, bs, "%u", v);
#undef N
}
static int
wlan_getinfo(struct wlanstatfoo_p *wf, int s, char b[], size_t bs)
{
const struct ieee80211req_sta_info *si = &wf->u_info.info.info[0];
uint8_t r;
switch (s) {
case S_RATE:
r = si->isi_rates[si->isi_txrate];
snprintf(b, bs, "%uM", (r &~ 0x80) / 2);
snprintf(b, bs, "%uM", si->isi_txmbps/2);
return 1;
case S_RSSI:
snprintf(b, bs, "%d", si->isi_rssi);
@ -505,6 +590,21 @@ wlan_getinfo(struct wlanstatfoo_p *wf, int s, char b[], size_t bs)
case S_SIGNAL:
snprintf(b, bs, "%d", si->isi_rssi + si->isi_noise);
return 1;
case S_RX_AUTH_FAIL_CODE:
if (wf->cur.is_rx_authfail_code == 0)
break;
setstatus(b, bs, wf->cur.is_rx_authfail_code);
return 1;
case S_RX_DEAUTH_CODE:
if (wf->cur.is_rx_deauth_code == 0)
break;
setreason(b, bs, wf->cur.is_rx_deauth_code);
return 1;
case S_RX_DISASSOC_CODE:
if (wf->cur.is_rx_disassoc_code == 0)
break;
setreason(b, bs, wf->cur.is_rx_disassoc_code);
return 1;
}
b[0] = '\0';
return 0;
@ -555,6 +655,7 @@ wlan_get_curstat(struct statfoo *sf, int s, char b[], size_t bs)
case S_RX_ASSOC_BADWPAIE: STAT(rx_assoc_badwpaie);
case S_RX_DEAUTH: STAT(rx_deauth);
case S_RX_DISASSOC: STAT(rx_disassoc);
case S_BMISS: STAT(beacon_miss);
case S_RX_BADSUBTYPE: STAT(rx_badsubtype);
case S_RX_NOBUF: STAT(rx_nobuf);
case S_RX_DECRYPTCRC: STAT(rx_decryptcrc);
@ -582,6 +683,7 @@ wlan_get_curstat(struct statfoo *sf, int s, char b[], size_t bs)
case S_TX_FRAGS: STAT(tx_frags);
case S_SCAN_ACTIVE: STAT(scan_active);
case S_SCAN_PASSIVE: STAT(scan_passive);
case S_SCAN_BG: STAT(scan_bg);
case S_NODE_TIMEOUT: STAT(node_timeout);
case S_CRYPTO_NOMEM: STAT(crypto_nomem);
case S_CRYPTO_TKIP: STAT(crypto_tkip);
@ -637,6 +739,8 @@ wlan_get_curstat(struct statfoo *sf, int s, char b[], size_t bs)
case S_TX_BADSTATE: STAT(tx_badstate);
case S_TX_NOTASSOC: STAT(tx_notassoc);
case S_TX_CLASSIFY: STAT(tx_classify);
case S_DWDS_MCAST: STAT(dwds_mcast);
case S_DWDS_QDROP: STAT(dwds_qdrop);
case S_HT_ASSOC_NOHTCAP:STAT(ht_assoc_nohtcap);
case S_HT_ASSOC_DOWNGRADE:STAT(ht_assoc_downgrade);
case S_HT_ASSOC_NORATE: STAT(ht_assoc_norate);
@ -695,6 +799,7 @@ wlan_get_totstat(struct statfoo *sf, int s, char b[], size_t bs)
case S_RX_ASSOC_BADWPAIE: STAT(rx_assoc_badwpaie);
case S_RX_DEAUTH: STAT(rx_deauth);
case S_RX_DISASSOC: STAT(rx_disassoc);
case S_BMISS: STAT(beacon_miss);
case S_RX_BADSUBTYPE: STAT(rx_badsubtype);
case S_RX_NOBUF: STAT(rx_nobuf);
case S_RX_DECRYPTCRC: STAT(rx_decryptcrc);
@ -722,6 +827,7 @@ wlan_get_totstat(struct statfoo *sf, int s, char b[], size_t bs)
case S_TX_FRAGS: STAT(tx_frags);
case S_SCAN_ACTIVE: STAT(scan_active);
case S_SCAN_PASSIVE: STAT(scan_passive);
case S_SCAN_BG: STAT(scan_bg);
case S_NODE_TIMEOUT: STAT(node_timeout);
case S_CRYPTO_NOMEM: STAT(crypto_nomem);
case S_CRYPTO_TKIP: STAT(crypto_tkip);
@ -777,6 +883,8 @@ wlan_get_totstat(struct statfoo *sf, int s, char b[], size_t bs)
case S_TX_BADSTATE: STAT(tx_badstate);
case S_TX_NOTASSOC: STAT(tx_notassoc);
case S_TX_CLASSIFY: STAT(tx_classify);
case S_DWDS_MCAST: STAT(dwds_mcast);
case S_DWDS_QDROP: STAT(dwds_qdrop);
case S_HT_ASSOC_NOHTCAP:STAT(ht_assoc_nohtcap);
case S_HT_ASSOC_DOWNGRADE:STAT(ht_assoc_downgrade);
case S_HT_ASSOC_NORATE: STAT(ht_assoc_norate);

View File

@ -80,6 +80,10 @@ const char *progname;
#define IEEE80211_MSG_INACT 0x00000080 /* inactivity handling */
#define IEEE80211_MSG_ROAM 0x00000040 /* sta-mode roaming */
#define IEEE80211_MSG_RATECTL 0x00000020 /* tx rate control */
#define IEEE80211_MSG_ACTION 0x00000010 /* action frame handling */
#define IEEE80211_MSG_WDS 0x00000008 /* WDS handling */
#define IEEE80211_MSG_IOCTL 0x00000004 /* ioctl handling */
#define IEEE80211_MSG_ADDBA 0x00000002 /* ADDBA handling */
static struct {
const char *name;
@ -112,6 +116,10 @@ static struct {
{ "inact", IEEE80211_MSG_INACT },
{ "roam", IEEE80211_MSG_ROAM },
{ "rate", IEEE80211_MSG_RATECTL },
{ "action", IEEE80211_MSG_ACTION },
{ "wds", IEEE80211_MSG_WDS },
{ "ioctl", IEEE80211_MSG_IOCTL },
{ "addba", IEEE80211_MSG_ADDBA },
};
static u_int
@ -148,47 +156,44 @@ usage(void)
exit(-1);
}
static void
setoid(char oid[], size_t oidlen, const char *wlan)
{
#ifdef __linux__
snprintf(oid, oidlen, "net.%s.debug", wlan);
#elif __FreeBSD__
snprintf(oid, oidlen, "net.wlan.%s.debug", wlan+4);
#elif __NetBSD__
snprintf(oid, oidlen, "net.link.ieee80211.%s.debug", wlan+4);
#else
#error "No support for this system"
#endif
}
int
main(int argc, char *argv[])
{
const char *ifname = "ath0";
const char *cp, *tp;
const char *sep;
int op, i, unit;
u_int32_t debug, ndebug;
size_t debuglen, parentlen;
char oid[256], parent[256];
char oid[256];
progname = argv[0];
setoid(oid, sizeof(oid), "wlan0");
if (argc > 1) {
if (strcmp(argv[1], "-i") == 0) {
if (argc < 2)
errx(1, "missing interface name for -i option");
ifname = argv[2];
if (strncmp(argv[2], "wlan", 4) != 0)
errx(1, "expecting a wlan interface name");
setoid(oid, sizeof(oid), argv[2]);
argc -= 2, argv += 2;
} else if (strcmp(argv[1], "-?") == 0)
usage();
}
for (unit = 0; unit < 10; unit++) {
#ifdef __linux__
snprintf(oid, sizeof(oid), "net.wlan%d.%%parent", unit);
#else
snprintf(oid, sizeof(oid), "net.wlan.%d.%%parent", unit);
#endif
parentlen = sizeof(parent);
if (sysctlbyname(oid, parent, &parentlen, NULL, 0) < 0)
continue;
if (strncmp(parent, ifname, parentlen) == 0)
break;
}
if (unit == 10)
errx(1, "%s: cannot locate wlan sysctl node.", ifname);
#ifdef __linux__
snprintf(oid, sizeof(oid), "net.wlan%d.debug", unit);
#else
snprintf(oid, sizeof(oid), "net.wlan.%d.debug", unit);
#endif
debuglen = sizeof(debug);
if (sysctlbyname(oid, &debug, &debuglen, NULL, 0) < 0)
err(1, "sysctl-get(%s)", oid);