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