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