Home | History | Annotate | Line # | Download | only in common
ieee80211_20.c revision 1.5
      1 /*	$NetBSD: ieee80211_20.c,v 1.5 2019/03/01 11:06:56 pgoyette Exp $	*/
      2 /*-
      3  * Copyright (c) 2001 Atsushi Onoe
      4  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission.
     17  *
     18  * Alternatively, this software may be distributed under the terms of the
     19  * GNU General Public License ("GPL") version 2 as published by the Free
     20  * Software Foundation.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 #include <sys/cdefs.h>
     35 #ifdef __FreeBSD__
     36 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_ioctl.c,v 1.35 2005/08/30 14:27:47 avatar Exp $");
     37 #endif
     38 #ifdef __NetBSD__
     39 __KERNEL_RCSID(0, "$NetBSD: ieee80211_20.c,v 1.5 2019/03/01 11:06:56 pgoyette Exp $");
     40 #endif
     41 
     42 /*
     43  * IEEE 802.11 ioctl support
     44  */
     45 
     46 #ifdef _KERNEL_OPT
     47 #include "opt_inet.h"
     48 #include "opt_compat_netbsd.h"
     49 #endif
     50 
     51 #include <sys/endian.h>
     52 #include <sys/param.h>
     53 #include <sys/kernel.h>
     54 #include <sys/socket.h>
     55 #include <sys/sockio.h>
     56 #include <sys/systm.h>
     57 #include <sys/proc.h>
     58 #include <sys/kauth.h>
     59 #include <sys/compat_stub.h>
     60 
     61 #include <net/if.h>
     62 #include <net/if_arp.h>
     63 #include <net/if_media.h>
     64 #include <net/if_ether.h>
     65 
     66 #include <net80211/ieee80211_var.h>
     67 #include <net80211/ieee80211_ioctl.h>
     68 
     69 #include <dev/ic/wi_ieee.h>
     70 
     71 #include <compat/common/compat_mod.h>
     72 
     73 #include <compat/sys/sockio.h>
     74 
     75 static void
     76 ieee80211_get_ostats(struct ieee80211_ostats *ostats,
     77     struct ieee80211_stats *stats)
     78 {
     79 #define	COPYSTATS1(__ostats, __nstats, __dstmemb, __srcmemb, __lastmemb)\
     80 	(void)memcpy(&(__ostats)->__dstmemb, &(__nstats)->__srcmemb,	\
     81 	    offsetof(struct ieee80211_stats, __lastmemb) -		\
     82 	    offsetof(struct ieee80211_stats, __srcmemb))
     83 #define	COPYSTATS(__ostats, __nstats, __dstmemb, __lastmemb)		\
     84 	COPYSTATS1(__ostats, __nstats, __dstmemb, __dstmemb, __lastmemb)
     85 
     86 	COPYSTATS(ostats, stats, is_rx_badversion, is_rx_unencrypted);
     87 	COPYSTATS(ostats, stats, is_rx_wepfail, is_rx_beacon);
     88 	COPYSTATS(ostats, stats, is_rx_rstoobig, is_rx_auth_countermeasures);
     89 	COPYSTATS(ostats, stats, is_rx_assoc_bss, is_rx_assoc_badwpaie);
     90 	COPYSTATS(ostats, stats, is_rx_deauth, is_rx_unauth);
     91 	COPYSTATS1(ostats, stats, is_tx_nombuf, is_tx_nobuf, is_tx_badcipher);
     92 	COPYSTATS(ostats, stats, is_scan_active, is_crypto_tkip);
     93 }
     94 
     95 static int
     96 ieee80211_20_ioctl(struct ieee80211com *ic, u_long cmd, void *data)
     97 {
     98 	struct ieee80211_ostats ostats;
     99 	struct ifreq *ifr;
    100 	int s, error;
    101 
    102 	switch (cmd) {
    103 	case OSIOCG80211STATS:
    104 	case OSIOCG80211ZSTATS:
    105 		s = splnet();
    106 		ifr = (struct ifreq *)data;
    107 		ieee80211_get_ostats(&ostats, &ic->ic_stats);
    108 		error = copyout(&ostats, ifr->ifr_data, sizeof(ostats));
    109 		if (error == 0 && cmd == OSIOCG80211ZSTATS)
    110 			(void)memset(&ic->ic_stats, 0, sizeof(ic->ic_stats));
    111 		splx(s);
    112 		return error;
    113 	default:
    114 		return EPASSTHROUGH;
    115 	}
    116 }
    117 
    118 void
    119 ieee80211_20_init(void)
    120 {
    121 
    122 	MODULE_HOOK_SET(ieee80211_ioctl_20_hook, "ieee20", ieee80211_20_ioctl);
    123 }
    124 
    125 void
    126 ieee80211_20_fini(void)
    127 {
    128 
    129 	MODULE_HOOK_UNSET(ieee80211_ioctl_20_hook);
    130 }
    131