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