1  | 
     | 
     | 
    /*	$OpenBSD: net80211.c,v 1.17 2016/08/27 04:13:43 guenther Exp $	*/  | 
    
    
    2  | 
     | 
     | 
     | 
    
    
    3  | 
     | 
     | 
    /*  | 
    
    
    4  | 
     | 
     | 
     * Copyright (c) 2005 Reyk Floeter <reyk@openbsd.org>  | 
    
    
    5  | 
     | 
     | 
     *  | 
    
    
    6  | 
     | 
     | 
     * Permission to use, copy, modify, and distribute this software for any  | 
    
    
    7  | 
     | 
     | 
     * purpose with or without fee is hereby granted, provided that the above  | 
    
    
    8  | 
     | 
     | 
     * copyright notice and this permission notice appear in all copies.  | 
    
    
    9  | 
     | 
     | 
     *  | 
    
    
    10  | 
     | 
     | 
     * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES  | 
    
    
    11  | 
     | 
     | 
     * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF  | 
    
    
    12  | 
     | 
     | 
     * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR  | 
    
    
    13  | 
     | 
     | 
     * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES  | 
    
    
    14  | 
     | 
     | 
     * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN  | 
    
    
    15  | 
     | 
     | 
     * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF  | 
    
    
    16  | 
     | 
     | 
     * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.  | 
    
    
    17  | 
     | 
     | 
     */  | 
    
    
    18  | 
     | 
     | 
     | 
    
    
    19  | 
     | 
     | 
    #include <sys/types.h>  | 
    
    
    20  | 
     | 
     | 
    #include <sys/time.h>  | 
    
    
    21  | 
     | 
     | 
    #include <sys/select.h>  | 
    
    
    22  | 
     | 
     | 
    #include <sys/socket.h>  | 
    
    
    23  | 
     | 
     | 
    #include <sys/file.h>  | 
    
    
    24  | 
     | 
     | 
    #include <sys/ioctl.h>  | 
    
    
    25  | 
     | 
     | 
     | 
    
    
    26  | 
     | 
     | 
    #include <net/if.h>  | 
    
    
    27  | 
     | 
     | 
     | 
    
    
    28  | 
     | 
     | 
    #include <netinet/in.h>  | 
    
    
    29  | 
     | 
     | 
    #include <netinet/if_ether.h>  | 
    
    
    30  | 
     | 
     | 
     | 
    
    
    31  | 
     | 
     | 
    #include <net80211/ieee80211.h>  | 
    
    
    32  | 
     | 
     | 
    #include <net80211/ieee80211_ioctl.h>  | 
    
    
    33  | 
     | 
     | 
     | 
    
    
    34  | 
     | 
     | 
    #include <err.h>  | 
    
    
    35  | 
     | 
     | 
    #include <stdio.h>  | 
    
    
    36  | 
     | 
     | 
    #include <string.h>  | 
    
    
    37  | 
     | 
     | 
    #include <unistd.h>  | 
    
    
    38  | 
     | 
     | 
    #include "netstat.h"  | 
    
    
    39  | 
     | 
     | 
     | 
    
    
    40  | 
     | 
     | 
    /*  | 
    
    
    41  | 
     | 
     | 
     * Dump IEEE802.11 per-interface statistics  | 
    
    
    42  | 
     | 
     | 
     */  | 
    
    
    43  | 
     | 
     | 
    void  | 
    
    
    44  | 
     | 
     | 
    net80211_ifstats(char *ifname)  | 
    
    
    45  | 
     | 
     | 
    { | 
    
    
    46  | 
     | 
     | 
    	struct ifreq ifr;  | 
    
    
    47  | 
     | 
     | 
    	struct ieee80211_stats stats;  | 
    
    
    48  | 
     | 
     | 
    	int s;  | 
    
    
    49  | 
     | 
     | 
     | 
    
    
    50  | 
     | 
     | 
    #define	p(f, m)	printf(m, (unsigned long)stats.f, plural(stats.f))  | 
    
    
    51  | 
     | 
     | 
     | 
    
    
    52  | 
     | 
     | 
    	if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)  | 
    
    
    53  | 
     | 
     | 
    		err(1, "socket(AF_INET)");  | 
    
    
    54  | 
     | 
     | 
     | 
    
    
    55  | 
     | 
     | 
    	ifr.ifr_data = (caddr_t)&stats;  | 
    
    
    56  | 
     | 
     | 
    	strlcpy(ifr.ifr_name, ifname, sizeof ifr.ifr_name);  | 
    
    
    57  | 
     | 
     | 
     | 
    
    
    58  | 
     | 
     | 
    	if (ioctl(s, SIOCG80211STATS, &ifr) < 0)  | 
    
    
    59  | 
     | 
     | 
    		err(1, "ioctl(SIOCG80211STATS)");  | 
    
    
    60  | 
     | 
     | 
     | 
    
    
    61  | 
     | 
     | 
    	printf("ieee80211 on %s:\n", ifr.ifr_name); | 
    
    
    62  | 
     | 
     | 
     | 
    
    
    63  | 
     | 
     | 
    	p(is_rx_badversion, "\t%lu input packet%s with bad version\n");  | 
    
    
    64  | 
     | 
     | 
    	p(is_rx_tooshort, "\t%lu input packet%s too short\n");  | 
    
    
    65  | 
     | 
     | 
    	p(is_rx_wrongbss, "\t%lu input packet%s from wrong bssid\n");  | 
    
    
    66  | 
     | 
     | 
    	p(is_rx_dup, "\t%lu input packet duplicate%s discarded\n");  | 
    
    
    67  | 
     | 
     | 
    	p(is_rx_wrongdir, "\t%lu input packet%s with wrong direction\n");  | 
    
    
    68  | 
     | 
     | 
    	p(is_rx_mcastecho, "\t%lu input multicast echo packet%s discarded\n");  | 
    
    
    69  | 
     | 
     | 
    	p(is_rx_notassoc, "\t%lu input packet%s from unassociated station discarded\n");  | 
    
    
    70  | 
     | 
     | 
    	p(is_rx_nowep, "\t%lu input encrypted packet%s without wep/wpa config discarded\n");  | 
    
    
    71  | 
     | 
     | 
    	p(is_rx_unencrypted, "\t%lu input unencrypted packet%s with wep/wpa config discarded\n");  | 
    
    
    72  | 
     | 
     | 
    	p(is_rx_wepfail, "\t%lu input wep/wpa packet%s processing failed\n");  | 
    
    
    73  | 
     | 
     | 
    	p(is_rx_decap, "\t%lu input packet decapsulation%s failed\n");  | 
    
    
    74  | 
     | 
     | 
    	p(is_rx_mgtdiscard, "\t%lu input management packet%s discarded\n");  | 
    
    
    75  | 
     | 
     | 
    	p(is_rx_ctl, "\t%lu input control packet%s discarded\n");  | 
    
    
    76  | 
     | 
     | 
    	p(is_rx_rstoobig, "\t%lu input packet%s with truncated rate set\n");  | 
    
    
    77  | 
     | 
     | 
    	p(is_rx_elem_missing, "\t%lu input packet%s with missing elements\n");  | 
    
    
    78  | 
     | 
     | 
    	p(is_rx_elem_toobig, "\t%lu input packet%s with elements too big\n");  | 
    
    
    79  | 
     | 
     | 
    	p(is_rx_elem_toosmall, "\t%lu input packet%s with elements too small\n");  | 
    
    
    80  | 
     | 
     | 
    	p(is_rx_badchan, "\t%lu input packet%s with invalid channel\n");  | 
    
    
    81  | 
     | 
     | 
    	p(is_rx_chanmismatch, "\t%lu input packet%s with mismatched channel\n");  | 
    
    
    82  | 
     | 
     | 
    	p(is_rx_nodealloc, "\t%lu node allocation%s failed\n");  | 
    
    
    83  | 
     | 
     | 
    	p(is_rx_ssidmismatch, "\t%lu input packet%s with mismatched ssid\n");  | 
    
    
    84  | 
     | 
     | 
    	p(is_rx_auth_unsupported, "\t%lu input packet%s with unsupported auth algorithm\n");  | 
    
    
    85  | 
     | 
     | 
    	p(is_rx_auth_fail, "\t%lu input authentication%s failed\n");  | 
    
    
    86  | 
     | 
     | 
    	p(is_rx_assoc_bss, "\t%lu input association%s from wrong bssid\n");  | 
    
    
    87  | 
     | 
     | 
    	p(is_rx_assoc_notauth, "\t%lu input association%s without authentication\n");  | 
    
    
    88  | 
     | 
     | 
    	p(is_rx_assoc_capmismatch, "\t%lu input association%s with mismatched capabilities\n");  | 
    
    
    89  | 
     | 
     | 
    	p(is_rx_assoc_norate, "\t%lu input association%s without matching rates\n");  | 
    
    
    90  | 
     | 
     | 
    	p(is_rx_assoc_badrsnie, "\t%lu input association%s with bad rsn ie\n");  | 
    
    
    91  | 
     | 
     | 
    	p(is_rx_deauth, "\t%lu input deauthentication packet%s\n");  | 
    
    
    92  | 
     | 
     | 
    	p(is_rx_disassoc, "\t%lu input disassociation packet%s\n");  | 
    
    
    93  | 
     | 
     | 
    	p(is_rx_badsubtype, "\t%lu input packet%s with unknown subtype\n");  | 
    
    
    94  | 
     | 
     | 
    	p(is_rx_nombuf, "\t%lu input packet%s failed for lack of mbufs\n");  | 
    
    
    95  | 
     | 
     | 
    	p(is_rx_decryptcrc, "\t%lu input decryption%s failed on crc\n");  | 
    
    
    96  | 
     | 
     | 
    	p(is_rx_ahdemo_mgt, "\t%lu input ahdemo management packet%s discarded\n");  | 
    
    
    97  | 
     | 
     | 
    	p(is_rx_bad_auth, "\t%lu input packet%s with bad auth request\n");  | 
    
    
    98  | 
     | 
     | 
    	p(is_rx_eapol_key, "\t%lu input eapol-key packet%s\n");  | 
    
    
    99  | 
     | 
     | 
    	p(is_rx_eapol_badmic, "\t%lu input eapol-key packet%s with bad mic\n");  | 
    
    
    100  | 
     | 
     | 
    	p(is_rx_eapol_replay, "\t%lu input eapol-key packet%s replayed\n");  | 
    
    
    101  | 
     | 
     | 
    	p(is_rx_locmicfail, "\t%lu input packet%s with bad tkip mic\n");  | 
    
    
    102  | 
     | 
     | 
    	p(is_rx_remmicfail, "\t%lu input tkip mic failure notification%s\n");  | 
    
    
    103  | 
     | 
     | 
    	p(is_rx_unauth, "\t%lu input packet%s on unauthenticated port\n");  | 
    
    
    104  | 
     | 
     | 
    	p(is_tx_nombuf, "\t%lu output packet%s failed for lack of mbufs\n");  | 
    
    
    105  | 
     | 
     | 
    	p(is_tx_nonode, "\t%lu output packet%s failed for no nodes\n");  | 
    
    
    106  | 
     | 
     | 
    	p(is_tx_unknownmgt, "\t%lu output packet%s of unknown management type\n");  | 
    
    
    107  | 
     | 
     | 
    	p(is_tx_noauth, "\t%lu output packet%s on unauthenticated port\n");  | 
    
    
    108  | 
     | 
     | 
    	p(is_scan_active, "\t%lu active scan%s started\n");  | 
    
    
    109  | 
     | 
     | 
    	p(is_scan_passive, "\t%lu passive scan%s started\n");  | 
    
    
    110  | 
     | 
     | 
    	p(is_node_timeout, "\t%lu node%s timed out\n");  | 
    
    
    111  | 
     | 
     | 
    	p(is_crypto_nomem, "\t%lu failure%s with no memory for crypto ctx\n");  | 
    
    
    112  | 
     | 
     | 
    	p(is_ccmp_dec_errs, "\t%lu ccmp decryption error%s\n");  | 
    
    
    113  | 
     | 
     | 
    	p(is_ccmp_replays, "\t%lu ccmp replayed frame%s \n");  | 
    
    
    114  | 
     | 
     | 
    	p(is_cmac_icv_errs, "\t%lu cmac icv error%s\n");  | 
    
    
    115  | 
     | 
     | 
    	p(is_cmac_replays, "\t%lu cmac replayed frame%s\n");  | 
    
    
    116  | 
     | 
     | 
    	p(is_tkip_icv_errs, "\t%lu tkip icv error%s\n");  | 
    
    
    117  | 
     | 
     | 
    	p(is_tkip_replays, "\t%lu tkip replay%s\n");  | 
    
    
    118  | 
     | 
     | 
    	p(is_pbac_errs, "\t%lu pbac error%s\n");  | 
    
    
    119  | 
     | 
     | 
    	p(is_ht_nego_no_mandatory_mcs, "\t%lu HT negotiation failure%s because "  | 
    
    
    120  | 
     | 
     | 
    	    "peer does not support MCS 0-7\n");  | 
    
    
    121  | 
     | 
     | 
    	p(is_ht_nego_no_basic_mcs, "\t%lu HT negotiation failure%s because "  | 
    
    
    122  | 
     | 
     | 
    	    "we do not support basic MCS set\n");  | 
    
    
    123  | 
     | 
     | 
    	p(is_ht_nego_bad_crypto,  | 
    
    
    124  | 
     | 
     | 
    	    "\t%lu HT negotiation failure%s because peer uses bad crypto\n");  | 
    
    
    125  | 
     | 
     | 
    	p(is_ht_prot_change, "\t%lu HT protection change%s\n");  | 
    
    
    126  | 
     | 
     | 
    	p(is_ht_rx_ba_agreements, "\t%lu new input block ack agreement%s\n");  | 
    
    
    127  | 
     | 
     | 
    	p(is_ht_tx_ba_agreements, "\t%lu new output block ack agreement%s\n");  | 
    
    
    128  | 
     | 
     | 
    	p(is_ht_rx_frame_below_ba_winstart,  | 
    
    
    129  | 
     | 
     | 
    	    "\t%lu input frame%s below block ack window start\n");  | 
    
    
    130  | 
     | 
     | 
    	p(is_ht_rx_frame_above_ba_winend,  | 
    
    
    131  | 
     | 
     | 
    	    "\t%lu input frame%s above block ack window end\n");  | 
    
    
    132  | 
     | 
     | 
    	p(is_ht_rx_ba_window_slide, "\t%lu input block ack window slide%s\n");  | 
    
    
    133  | 
     | 
     | 
    	p(is_ht_rx_ba_window_jump, "\t%lu input block ack window jump%s\n");  | 
    
    
    134  | 
     | 
     | 
    	p(is_ht_rx_ba_no_buf, "\t%lu duplicate input block ack frame%s\n");  | 
    
    
    135  | 
     | 
     | 
    	p(is_ht_rx_ba_frame_lost,  | 
    
    
    136  | 
     | 
     | 
    	    "\t%lu expected input block ack frame%s never arrived\n");  | 
    
    
    137  | 
     | 
     | 
    	p(is_ht_rx_ba_window_gap_timeout,  | 
    
    
    138  | 
     | 
     | 
    	    "\t%lu input block ack window gap%s timed out\n");  | 
    
    
    139  | 
     | 
     | 
    	p(is_ht_rx_ba_timeout,  | 
    
    
    140  | 
     | 
     | 
    	    "\t%lu input block ack agreement%s timed out\n");  | 
    
    
    141  | 
     | 
     | 
    	p(is_ht_tx_ba_timeout,  | 
    
    
    142  | 
     | 
     | 
    	    "\t%lu output block ack agreement%s timed out\n");  | 
    
    
    143  | 
     | 
     | 
     | 
    
    
    144  | 
     | 
     | 
    	close(s);  | 
    
    
    145  | 
     | 
     | 
     | 
    
    
    146  | 
     | 
     | 
    #undef p  | 
    
    
    147  | 
     | 
     | 
    }  |