xref: /openbsd-src/usr.bin/netstat/net80211.c (revision e5eb46169649892e7b8ddf4d26c90222ccaaed3b)
1*e5eb4616Sderaadt /*	$OpenBSD: net80211.c,v 1.20 2021/12/05 22:36:19 deraadt Exp $	*/
29f414a08Sreyk 
39f414a08Sreyk /*
42c56d0d6Sreyk  * Copyright (c) 2005 Reyk Floeter <reyk@openbsd.org>
59f414a08Sreyk  *
69f414a08Sreyk  * Permission to use, copy, modify, and distribute this software for any
79f414a08Sreyk  * purpose with or without fee is hereby granted, provided that the above
89f414a08Sreyk  * copyright notice and this permission notice appear in all copies.
99f414a08Sreyk  *
109f414a08Sreyk  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
119f414a08Sreyk  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
129f414a08Sreyk  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
139f414a08Sreyk  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
149f414a08Sreyk  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
159f414a08Sreyk  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
169f414a08Sreyk  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
179f414a08Sreyk  */
189f414a08Sreyk 
19b9fc9a72Sderaadt #include <sys/types.h>
209f414a08Sreyk #include <sys/socket.h>
219f414a08Sreyk #include <sys/ioctl.h>
229f414a08Sreyk 
239f414a08Sreyk #include <net/if.h>
249f414a08Sreyk 
259f414a08Sreyk #include <netinet/in.h>
269f414a08Sreyk #include <netinet/if_ether.h>
279f414a08Sreyk 
289f414a08Sreyk #include <net80211/ieee80211.h>
299f414a08Sreyk #include <net80211/ieee80211_ioctl.h>
309f414a08Sreyk 
31204b3c37Sray #include <err.h>
329f414a08Sreyk #include <stdio.h>
339f414a08Sreyk #include <string.h>
349f414a08Sreyk #include <unistd.h>
359f414a08Sreyk #include "netstat.h"
369f414a08Sreyk 
379f414a08Sreyk /*
389f414a08Sreyk  * Dump IEEE802.11 per-interface statistics
399f414a08Sreyk  */
409f414a08Sreyk void
net80211_ifstats(char * ifname)419f414a08Sreyk net80211_ifstats(char *ifname)
429f414a08Sreyk {
439f414a08Sreyk 	struct ifreq ifr;
449f414a08Sreyk 	struct ieee80211_stats stats;
459f414a08Sreyk 	int s;
469f414a08Sreyk 
479f414a08Sreyk #define	p(f, m)	printf(m, (unsigned long)stats.f, plural(stats.f))
489f414a08Sreyk 
493aaa63ebSderaadt 	if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
503b6ee7eaSreyk 		err(1, "socket(AF_INET)");
519f414a08Sreyk 
529f414a08Sreyk 	ifr.ifr_data = (caddr_t)&stats;
539f414a08Sreyk 	strlcpy(ifr.ifr_name, ifname, sizeof ifr.ifr_name);
549f414a08Sreyk 
553aaa63ebSderaadt 	if (ioctl(s, SIOCG80211STATS, &ifr) == -1)
563b6ee7eaSreyk 		err(1, "ioctl(SIOCG80211STATS)");
573b6ee7eaSreyk 
583b6ee7eaSreyk 	printf("ieee80211 on %s:\n", ifr.ifr_name);
599f414a08Sreyk 
609f414a08Sreyk 	p(is_rx_badversion, "\t%lu input packet%s with bad version\n");
619f414a08Sreyk 	p(is_rx_tooshort, "\t%lu input packet%s too short\n");
629f414a08Sreyk 	p(is_rx_wrongbss, "\t%lu input packet%s from wrong bssid\n");
639f414a08Sreyk 	p(is_rx_dup, "\t%lu input packet duplicate%s discarded\n");
649f414a08Sreyk 	p(is_rx_wrongdir, "\t%lu input packet%s with wrong direction\n");
659f414a08Sreyk 	p(is_rx_mcastecho, "\t%lu input multicast echo packet%s discarded\n");
669f414a08Sreyk 	p(is_rx_notassoc, "\t%lu input packet%s from unassociated station discarded\n");
6718620a2eSjcs 	p(is_rx_nowep, "\t%lu input encrypted packet%s without wep/wpa config discarded\n");
6818620a2eSjcs 	p(is_rx_unencrypted, "\t%lu input unencrypted packet%s with wep/wpa config discarded\n");
6918620a2eSjcs 	p(is_rx_wepfail, "\t%lu input wep/wpa packet%s processing failed\n");
709f414a08Sreyk 	p(is_rx_decap, "\t%lu input packet decapsulation%s failed\n");
719f414a08Sreyk 	p(is_rx_mgtdiscard, "\t%lu input management packet%s discarded\n");
729f414a08Sreyk 	p(is_rx_ctl, "\t%lu input control packet%s discarded\n");
739f414a08Sreyk 	p(is_rx_rstoobig, "\t%lu input packet%s with truncated rate set\n");
749f414a08Sreyk 	p(is_rx_elem_missing, "\t%lu input packet%s with missing elements\n");
759f414a08Sreyk 	p(is_rx_elem_toobig, "\t%lu input packet%s with elements too big\n");
769f414a08Sreyk 	p(is_rx_elem_toosmall, "\t%lu input packet%s with elements too small\n");
779f414a08Sreyk 	p(is_rx_badchan, "\t%lu input packet%s with invalid channel\n");
789f414a08Sreyk 	p(is_rx_chanmismatch, "\t%lu input packet%s with mismatched channel\n");
7932a5e459Sstsp 	p(is_rx_nodealloc, "\t%lu node allocation%s failed\n");
809f414a08Sreyk 	p(is_rx_ssidmismatch, "\t%lu input packet%s with mismatched ssid\n");
819f414a08Sreyk 	p(is_rx_auth_unsupported, "\t%lu input packet%s with unsupported auth algorithm\n");
829f414a08Sreyk 	p(is_rx_auth_fail, "\t%lu input authentication%s failed\n");
839f414a08Sreyk 	p(is_rx_assoc_bss, "\t%lu input association%s from wrong bssid\n");
849f414a08Sreyk 	p(is_rx_assoc_notauth, "\t%lu input association%s without authentication\n");
859f414a08Sreyk 	p(is_rx_assoc_capmismatch, "\t%lu input association%s with mismatched capabilities\n");
869f414a08Sreyk 	p(is_rx_assoc_norate, "\t%lu input association%s without matching rates\n");
8718620a2eSjcs 	p(is_rx_assoc_badrsnie, "\t%lu input association%s with bad rsn ie\n");
889f414a08Sreyk 	p(is_rx_deauth, "\t%lu input deauthentication packet%s\n");
899f414a08Sreyk 	p(is_rx_disassoc, "\t%lu input disassociation packet%s\n");
909f414a08Sreyk 	p(is_rx_badsubtype, "\t%lu input packet%s with unknown subtype\n");
919f414a08Sreyk 	p(is_rx_nombuf, "\t%lu input packet%s failed for lack of mbufs\n");
929f414a08Sreyk 	p(is_rx_decryptcrc, "\t%lu input decryption%s failed on crc\n");
939f414a08Sreyk 	p(is_rx_ahdemo_mgt, "\t%lu input ahdemo management packet%s discarded\n");
949f414a08Sreyk 	p(is_rx_bad_auth, "\t%lu input packet%s with bad auth request\n");
9518620a2eSjcs 	p(is_rx_eapol_key, "\t%lu input eapol-key packet%s\n");
9618620a2eSjcs 	p(is_rx_eapol_badmic, "\t%lu input eapol-key packet%s with bad mic\n");
9718620a2eSjcs 	p(is_rx_eapol_replay, "\t%lu input eapol-key packet%s replayed\n");
9818620a2eSjcs 	p(is_rx_locmicfail, "\t%lu input packet%s with bad tkip mic\n");
9918620a2eSjcs 	p(is_rx_remmicfail, "\t%lu input tkip mic failure notification%s\n");
10018620a2eSjcs 	p(is_rx_unauth, "\t%lu input packet%s on unauthenticated port\n");
1019f414a08Sreyk 	p(is_tx_nombuf, "\t%lu output packet%s failed for lack of mbufs\n");
1029f414a08Sreyk 	p(is_tx_nonode, "\t%lu output packet%s failed for no nodes\n");
1039f414a08Sreyk 	p(is_tx_unknownmgt, "\t%lu output packet%s of unknown management type\n");
10418620a2eSjcs 	p(is_tx_noauth, "\t%lu output packet%s on unauthenticated port\n");
1059f414a08Sreyk 	p(is_scan_active, "\t%lu active scan%s started\n");
1069f414a08Sreyk 	p(is_scan_passive, "\t%lu passive scan%s started\n");
1079f414a08Sreyk 	p(is_node_timeout, "\t%lu node%s timed out\n");
1089f414a08Sreyk 	p(is_crypto_nomem, "\t%lu failure%s with no memory for crypto ctx\n");
10918620a2eSjcs 	p(is_ccmp_dec_errs, "\t%lu ccmp decryption error%s\n");
11018620a2eSjcs 	p(is_ccmp_replays, "\t%lu ccmp replayed frame%s \n");
11118620a2eSjcs 	p(is_cmac_icv_errs, "\t%lu cmac icv error%s\n");
11218620a2eSjcs 	p(is_cmac_replays, "\t%lu cmac replayed frame%s\n");
11318620a2eSjcs 	p(is_tkip_icv_errs, "\t%lu tkip icv error%s\n");
11418620a2eSjcs 	p(is_tkip_replays, "\t%lu tkip replay%s\n");
11557225449Sstsp 	p(is_pbac_errs, "\t%lu pbac error%s\n");
11657225449Sstsp 	p(is_ht_nego_no_mandatory_mcs, "\t%lu HT negotiation failure%s because "
11757225449Sstsp 	    "peer does not support MCS 0-7\n");
11820e7fdffSstsp 	p(is_ht_nego_no_basic_mcs, "\t%lu HT negotiation failure%s because "
11957225449Sstsp 	    "we do not support basic MCS set\n");
12057225449Sstsp 	p(is_ht_nego_bad_crypto,
12157225449Sstsp 	    "\t%lu HT negotiation failure%s because peer uses bad crypto\n");
12257225449Sstsp 	p(is_ht_prot_change, "\t%lu HT protection change%s\n");
12357225449Sstsp 	p(is_ht_rx_ba_agreements, "\t%lu new input block ack agreement%s\n");
12457225449Sstsp 	p(is_ht_tx_ba_agreements, "\t%lu new output block ack agreement%s\n");
12557225449Sstsp 	p(is_ht_rx_frame_below_ba_winstart,
12657225449Sstsp 	    "\t%lu input frame%s below block ack window start\n");
12757225449Sstsp 	p(is_ht_rx_frame_above_ba_winend,
12857225449Sstsp 	    "\t%lu input frame%s above block ack window end\n");
12983304234Sstsp 	p(is_ht_rx_ba_window_slide, "\t%lu input block ack window slide%s\n");
13057225449Sstsp 	p(is_ht_rx_ba_window_jump, "\t%lu input block ack window jump%s\n");
13157225449Sstsp 	p(is_ht_rx_ba_no_buf, "\t%lu duplicate input block ack frame%s\n");
13257225449Sstsp 	p(is_ht_rx_ba_frame_lost,
13357225449Sstsp 	    "\t%lu expected input block ack frame%s never arrived\n");
13457225449Sstsp 	p(is_ht_rx_ba_window_gap_timeout,
13557225449Sstsp 	    "\t%lu input block ack window gap%s timed out\n");
13657225449Sstsp 	p(is_ht_rx_ba_timeout,
13757225449Sstsp 	    "\t%lu input block ack agreement%s timed out\n");
13857225449Sstsp 	p(is_ht_tx_ba_timeout,
13957225449Sstsp 	    "\t%lu output block ack agreement%s timed out\n");
1409f414a08Sreyk 
1419f414a08Sreyk 	close(s);
1429f414a08Sreyk 
1439f414a08Sreyk #undef p
1449f414a08Sreyk }
145