xref: /freebsd/sys/net80211/ieee80211_freebsd.h (revision eabcd1773fa3e4bf12ee053540a90fad79a6f81b)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2003-2008 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  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 #ifndef _NET80211_IEEE80211_FREEBSD_H_
28 #define _NET80211_IEEE80211_FREEBSD_H_
29 
30 #ifdef _KERNEL
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/counter.h>
34 #include <sys/lock.h>
35 #include <sys/mutex.h>
36 #include <sys/rwlock.h>
37 #include <sys/sysctl.h>
38 #include <sys/taskqueue.h>
39 #include <sys/time.h>
40 
41 #include <net/debugnet.h>
42 
43 /*
44  * priv(9) NET80211 checks.
45  */
46 struct ieee80211vap;
47 int ieee80211_priv_check_vap_getkey(u_long, struct ieee80211vap *,
48     struct ifnet *);
49 int ieee80211_priv_check_vap_manage(u_long, struct ieee80211vap *,
50     struct ifnet *);
51 int ieee80211_priv_check_vap_setmac(u_long, struct ieee80211vap *,
52     struct ifnet *);
53 int ieee80211_priv_check_create_vap(u_long, struct ieee80211vap *,
54     struct ifnet *);
55 
56 /*
57  * Common state locking definitions.
58  */
59 typedef struct {
60 	char		name[16];		/* e.g. "ath0_com_lock" */
61 	struct mtx	mtx;
62 } ieee80211_com_lock_t;
63 #define	IEEE80211_LOCK_INIT(_ic, _name) do {				\
64 	ieee80211_com_lock_t *cl = &(_ic)->ic_comlock;			\
65 	snprintf(cl->name, sizeof(cl->name), "%s_com_lock", _name);	\
66 	mtx_init(&cl->mtx, cl->name, NULL, MTX_DEF | MTX_RECURSE);	\
67 } while (0)
68 #define	IEEE80211_LOCK_OBJ(_ic)	(&(_ic)->ic_comlock.mtx)
69 #define	IEEE80211_LOCK_DESTROY(_ic) mtx_destroy(IEEE80211_LOCK_OBJ(_ic))
70 #define	IEEE80211_LOCK(_ic)	   mtx_lock(IEEE80211_LOCK_OBJ(_ic))
71 #define	IEEE80211_UNLOCK(_ic)	   mtx_unlock(IEEE80211_LOCK_OBJ(_ic))
72 #define	IEEE80211_LOCK_ASSERT(_ic) \
73 	mtx_assert(IEEE80211_LOCK_OBJ(_ic), MA_OWNED)
74 #define	IEEE80211_UNLOCK_ASSERT(_ic) \
75 	mtx_assert(IEEE80211_LOCK_OBJ(_ic), MA_NOTOWNED)
76 #define	IEEE80211_IS_LOCKED(_ic) \
77 	mtx_owned(IEEE80211_LOCK_OBJ(_ic))
78 
79 /*
80  * Transmit lock.
81  *
82  * This is a (mostly) temporary lock designed to serialise all of the
83  * transmission operations throughout the stack.
84  */
85 typedef struct {
86 	char		name[16];		/* e.g. "ath0_tx_lock" */
87 	struct mtx	mtx;
88 } ieee80211_tx_lock_t;
89 #define	IEEE80211_TX_LOCK_INIT(_ic, _name) do {				\
90 	ieee80211_tx_lock_t *cl = &(_ic)->ic_txlock;			\
91 	snprintf(cl->name, sizeof(cl->name), "%s_tx_lock", _name);	\
92 	mtx_init(&cl->mtx, cl->name, NULL, MTX_DEF);	\
93 } while (0)
94 #define	IEEE80211_TX_LOCK_OBJ(_ic)	(&(_ic)->ic_txlock.mtx)
95 #define	IEEE80211_TX_LOCK_DESTROY(_ic) mtx_destroy(IEEE80211_TX_LOCK_OBJ(_ic))
96 #define	IEEE80211_TX_LOCK(_ic) do { \
97 	if (!IEEE80211_CONF_SEQNO_OFFLOAD(_ic)) \
98 		mtx_lock(IEEE80211_TX_LOCK_OBJ(_ic)); \
99 	} while (0);
100 #define	IEEE80211_TX_UNLOCK(_ic) do { \
101 	if (!IEEE80211_CONF_SEQNO_OFFLOAD(_ic)) \
102 		mtx_unlock(IEEE80211_TX_LOCK_OBJ(_ic)); \
103 	} while (0);
104 #define	IEEE80211_TX_LOCK_ASSERT(_ic) do { \
105 	if (!IEEE80211_CONF_SEQNO_OFFLOAD(_ic)) \
106 		mtx_assert(IEEE80211_TX_LOCK_OBJ(_ic), MA_OWNED); \
107 	} while (0)
108 #define	IEEE80211_TX_UNLOCK_ASSERT(_ic) { \
109 	if (!IEEE80211_CONF_SEQNO_OFFLOAD(_ic)) \
110 		mtx_assert(IEEE80211_TX_LOCK_OBJ(_ic), MA_NOTOWNED); \
111 	} while (0)
112 
113 /*
114  * Stageq / ni_tx_superg lock
115  */
116 typedef struct {
117 	char		name[16];		/* e.g. "ath0_ff_lock" */
118 	struct mtx	mtx;
119 } ieee80211_ff_lock_t;
120 #define IEEE80211_FF_LOCK_INIT(_ic, _name) do {				\
121 	ieee80211_ff_lock_t *fl = &(_ic)->ic_fflock;			\
122 	snprintf(fl->name, sizeof(fl->name), "%s_ff_lock", _name);	\
123 	mtx_init(&fl->mtx, fl->name, NULL, MTX_DEF);			\
124 } while (0)
125 #define IEEE80211_FF_LOCK_OBJ(_ic)	(&(_ic)->ic_fflock.mtx)
126 #define IEEE80211_FF_LOCK_DESTROY(_ic)	mtx_destroy(IEEE80211_FF_LOCK_OBJ(_ic))
127 #define IEEE80211_FF_LOCK(_ic)		mtx_lock(IEEE80211_FF_LOCK_OBJ(_ic))
128 #define IEEE80211_FF_UNLOCK(_ic)	mtx_unlock(IEEE80211_FF_LOCK_OBJ(_ic))
129 #define IEEE80211_FF_LOCK_ASSERT(_ic) \
130 	mtx_assert(IEEE80211_FF_LOCK_OBJ(_ic), MA_OWNED)
131 
132 /*
133  * Node locking definitions.
134  */
135 typedef struct {
136 	char		name[16];		/* e.g. "ath0_node_lock" */
137 	struct mtx	mtx;
138 } ieee80211_node_lock_t;
139 #define	IEEE80211_NODE_LOCK_INIT(_nt, _name) do {			\
140 	ieee80211_node_lock_t *nl = &(_nt)->nt_nodelock;		\
141 	snprintf(nl->name, sizeof(nl->name), "%s_node_lock", _name);	\
142 	mtx_init(&nl->mtx, nl->name, NULL, MTX_DEF | MTX_RECURSE);	\
143 } while (0)
144 #define	IEEE80211_NODE_LOCK_OBJ(_nt)	(&(_nt)->nt_nodelock.mtx)
145 #define	IEEE80211_NODE_LOCK_DESTROY(_nt) \
146 	mtx_destroy(IEEE80211_NODE_LOCK_OBJ(_nt))
147 #define	IEEE80211_NODE_LOCK(_nt) \
148 	mtx_lock(IEEE80211_NODE_LOCK_OBJ(_nt))
149 #define	IEEE80211_NODE_IS_LOCKED(_nt) \
150 	mtx_owned(IEEE80211_NODE_LOCK_OBJ(_nt))
151 #define	IEEE80211_NODE_UNLOCK(_nt) \
152 	mtx_unlock(IEEE80211_NODE_LOCK_OBJ(_nt))
153 #define	IEEE80211_NODE_LOCK_ASSERT(_nt)	\
154 	mtx_assert(IEEE80211_NODE_LOCK_OBJ(_nt), MA_OWNED)
155 
156 /*
157  * Power-save queue definitions.
158  */
159 typedef struct mtx ieee80211_psq_lock_t;
160 #define	IEEE80211_PSQ_INIT(_psq, _name) \
161 	mtx_init(&(_psq)->psq_lock, _name, "802.11 ps q", MTX_DEF)
162 #define	IEEE80211_PSQ_DESTROY(_psq)	mtx_destroy(&(_psq)->psq_lock)
163 #define	IEEE80211_PSQ_LOCK(_psq)	mtx_lock(&(_psq)->psq_lock)
164 #define	IEEE80211_PSQ_UNLOCK(_psq)	mtx_unlock(&(_psq)->psq_lock)
165 
166 #ifndef IF_PREPEND_LIST
167 #define _IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do {	\
168 	(mtail)->m_nextpkt = (ifq)->ifq_head;			\
169 	if ((ifq)->ifq_tail == NULL)				\
170 		(ifq)->ifq_tail = (mtail);			\
171 	(ifq)->ifq_head = (mhead);				\
172 	(ifq)->ifq_len += (mcount);				\
173 } while (0)
174 #define IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do {		\
175 	IF_LOCK(ifq);						\
176 	_IF_PREPEND_LIST(ifq, mhead, mtail, mcount);		\
177 	IF_UNLOCK(ifq);						\
178 } while (0)
179 #endif /* IF_PREPEND_LIST */
180 
181 /*
182  * Age queue definitions.
183  */
184 typedef struct mtx ieee80211_ageq_lock_t;
185 #define	IEEE80211_AGEQ_INIT(_aq, _name) \
186 	mtx_init(&(_aq)->aq_lock, _name, "802.11 age q", MTX_DEF)
187 #define	IEEE80211_AGEQ_DESTROY(_aq)	mtx_destroy(&(_aq)->aq_lock)
188 #define	IEEE80211_AGEQ_LOCK(_aq)	mtx_lock(&(_aq)->aq_lock)
189 #define	IEEE80211_AGEQ_UNLOCK(_aq)	mtx_unlock(&(_aq)->aq_lock)
190 
191 /*
192  * 802.1x MAC ACL database locking definitions.
193  */
194 typedef struct mtx acl_lock_t;
195 #define	ACL_LOCK_INIT(_as, _name) \
196 	mtx_init(&(_as)->as_lock, _name, "802.11 ACL", MTX_DEF)
197 #define	ACL_LOCK_DESTROY(_as)		mtx_destroy(&(_as)->as_lock)
198 #define	ACL_LOCK(_as)			mtx_lock(&(_as)->as_lock)
199 #define	ACL_UNLOCK(_as)			mtx_unlock(&(_as)->as_lock)
200 #define	ACL_LOCK_ASSERT(_as) \
201 	mtx_assert((&(_as)->as_lock), MA_OWNED)
202 
203 /*
204  * Scan table definitions.
205  */
206 typedef struct mtx ieee80211_scan_table_lock_t;
207 #define	IEEE80211_SCAN_TABLE_LOCK_INIT(_st, _name) \
208 	mtx_init(&(_st)->st_lock, _name, "802.11 scan table", MTX_DEF)
209 #define	IEEE80211_SCAN_TABLE_LOCK_DESTROY(_st)	mtx_destroy(&(_st)->st_lock)
210 #define	IEEE80211_SCAN_TABLE_LOCK(_st)		mtx_lock(&(_st)->st_lock)
211 #define	IEEE80211_SCAN_TABLE_UNLOCK(_st)	mtx_unlock(&(_st)->st_lock)
212 
213 typedef struct mtx ieee80211_scan_iter_lock_t;
214 #define	IEEE80211_SCAN_ITER_LOCK_INIT(_st, _name) \
215 	mtx_init(&(_st)->st_scanlock, _name, "802.11 scangen", MTX_DEF)
216 #define	IEEE80211_SCAN_ITER_LOCK_DESTROY(_st)	mtx_destroy(&(_st)->st_scanlock)
217 #define	IEEE80211_SCAN_ITER_LOCK(_st)		mtx_lock(&(_st)->st_scanlock)
218 #define	IEEE80211_SCAN_ITER_UNLOCK(_st)	mtx_unlock(&(_st)->st_scanlock)
219 
220 /*
221  * Mesh node/routing definitions.
222  */
223 typedef struct mtx ieee80211_rte_lock_t;
224 #define	MESH_RT_ENTRY_LOCK_INIT(_rt, _name) \
225 	mtx_init(&(rt)->rt_lock, _name, "802.11s route entry", MTX_DEF)
226 #define	MESH_RT_ENTRY_LOCK_DESTROY(_rt) \
227 	mtx_destroy(&(_rt)->rt_lock)
228 #define	MESH_RT_ENTRY_LOCK(rt)	mtx_lock(&(rt)->rt_lock)
229 #define	MESH_RT_ENTRY_LOCK_ASSERT(rt) mtx_assert(&(rt)->rt_lock, MA_OWNED)
230 #define	MESH_RT_ENTRY_UNLOCK(rt)	mtx_unlock(&(rt)->rt_lock)
231 
232 typedef struct mtx ieee80211_rt_lock_t;
233 #define	MESH_RT_LOCK(ms)	mtx_lock(&(ms)->ms_rt_lock)
234 #define	MESH_RT_LOCK_ASSERT(ms)	mtx_assert(&(ms)->ms_rt_lock, MA_OWNED)
235 #define	MESH_RT_UNLOCK(ms)	mtx_unlock(&(ms)->ms_rt_lock)
236 #define	MESH_RT_LOCK_INIT(ms, name) \
237 	mtx_init(&(ms)->ms_rt_lock, name, "802.11s routing table", MTX_DEF)
238 #define	MESH_RT_LOCK_DESTROY(ms) \
239 	mtx_destroy(&(ms)->ms_rt_lock)
240 
241 /*
242  * Node reference counting definitions.
243  *
244  * ieee80211_node_initref	initialize the reference count to 1
245  * ieee80211_node_incref	add a reference
246  * ieee80211_node_decref	remove a reference
247  * ieee80211_node_dectestref	remove a reference and return 1 if this
248  *				is the last reference, otherwise 0
249  * ieee80211_node_refcnt	reference count for printing (only)
250  */
251 #include <machine/atomic.h>
252 
253 struct ieee80211vap;
254 int	ieee80211_com_vincref(struct ieee80211vap *);
255 void	ieee80211_com_vdecref(struct ieee80211vap *);
256 void	ieee80211_com_vdetach(struct ieee80211vap *);
257 
258 #define ieee80211_node_initref(_ni) \
259 	do { ((_ni)->ni_refcnt = 1); } while (0)
260 #define ieee80211_node_incref(_ni) \
261 	atomic_add_int(&(_ni)->ni_refcnt, 1)
262 #define	ieee80211_node_decref(_ni) \
263 	atomic_subtract_int(&(_ni)->ni_refcnt, 1)
264 struct ieee80211_node;
265 int	ieee80211_node_dectestref(struct ieee80211_node *ni);
266 #define	ieee80211_node_refcnt(_ni)	(_ni)->ni_refcnt
267 
268 struct ifqueue;
269 void	ieee80211_drain_ifq(struct ifqueue *);
270 void	ieee80211_flush_ifq(struct ifqueue *, struct ieee80211vap *);
271 
272 void	ieee80211_vap_destroy(struct ieee80211vap *);
273 const char *	ieee80211_get_vap_ifname(struct ieee80211vap *);
274 
275 #define	IFNET_IS_UP_RUNNING(_ifp)				\
276 	(((if_getflags(_ifp) & IFF_UP) != 0) &&			\
277 	 ((if_getdrvflags(_ifp) & IFF_DRV_RUNNING) != 0))
278 
279 #define	msecs_to_ticks(ms)	MSEC_2_TICKS(ms)
280 #define	ticks_to_msecs(t)	TICKS_2_MSEC(t)
281 #define	ticks_to_secs(t)	((t) / hz)
282 
283 #define ieee80211_time_after(a,b) 	((int)(b) - (int)(a) < 0)
284 #define ieee80211_time_before(a,b)	ieee80211_time_after(b,a)
285 #define ieee80211_time_after_eq(a,b)	((int)(a) - (int)(b) >= 0)
286 #define ieee80211_time_before_eq(a,b)	ieee80211_time_after_eq(b,a)
287 
288 struct mbuf *ieee80211_getmgtframe(uint8_t **frm, int headroom, int pktlen);
289 
290 /* tx path usage */
291 #define	M_ENCAP		M_PROTO1		/* 802.11 encap done */
292 #define	M_EAPOL		M_PROTO3		/* PAE/EAPOL frame */
293 #define	M_PWR_SAV	M_PROTO4		/* bypass PS handling */
294 #define	M_MORE_DATA	M_PROTO5		/* more data frames to follow */
295 #define	M_FF		M_PROTO6		/* fast frame / A-MSDU */
296 #define	M_TXCB		M_PROTO7		/* do tx complete callback */
297 #define	M_AMPDU_MPDU	M_PROTO8		/* ok for A-MPDU aggregation */
298 #define	M_FRAG		M_PROTO9		/* frame fragmentation */
299 #define	M_FIRSTFRAG	M_PROTO10		/* first frame fragment */
300 #define	M_LASTFRAG	M_PROTO11		/* last frame fragment */
301 
302 #define	M_80211_TX \
303 	(M_ENCAP|M_EAPOL|M_PWR_SAV|M_MORE_DATA|M_FF|M_TXCB| \
304 	 M_AMPDU_MPDU|M_FRAG|M_FIRSTFRAG|M_LASTFRAG)
305 
306 /* rx path usage */
307 #define	M_AMPDU		M_PROTO1		/* A-MPDU subframe */
308 #define	M_WEP		M_PROTO2		/* WEP done by hardware */
309 #if 0
310 #define	M_AMPDU_MPDU	M_PROTO8		/* A-MPDU re-order done */
311 #endif
312 #define	M_80211_RX	(M_AMPDU|M_WEP|M_AMPDU_MPDU)
313 
314 #define	IEEE80211_MBUF_TX_FLAG_BITS \
315 	M_FLAG_BITS \
316 	"\15M_ENCAP\17M_EAPOL\20M_PWR_SAV\21M_MORE_DATA\22M_FF\23M_TXCB" \
317 	"\24M_AMPDU_MPDU\25M_FRAG\26M_FIRSTFRAG\27M_LASTFRAG"
318 
319 #define	IEEE80211_MBUF_RX_FLAG_BITS \
320 	M_FLAG_BITS \
321 	"\15M_AMPDU\16M_WEP\24M_AMPDU_MPDU"
322 
323 /*
324  * Store WME access control bits in the vlan tag.
325  * This is safe since it's done after the packet is classified
326  * (where we use any previous tag) and because it's passed
327  * directly in to the driver and there's no chance someone
328  * else will clobber them on us.
329  */
330 #define	M_WME_SETAC(m, ac) \
331 	((m)->m_pkthdr.ether_vtag = (ac))
332 #define	M_WME_GETAC(m)	((m)->m_pkthdr.ether_vtag)
333 
334 /*
335  * Mbufs on the power save queue are tagged with an age and
336  * timed out.  We reuse the hardware checksum field in the
337  * mbuf packet header to store this data.
338  */
339 #define	M_AGE_SET(m,v)		(m->m_pkthdr.csum_data = v)
340 #define	M_AGE_GET(m)		(m->m_pkthdr.csum_data)
341 #define	M_AGE_SUB(m,adj)	(m->m_pkthdr.csum_data -= adj)
342 
343 /*
344  * Store the sequence number.
345  */
346 #define	M_SEQNO_SET(m, seqno) \
347 	((m)->m_pkthdr.tso_segsz = (seqno))
348 #define	M_SEQNO_GET(m)	((m)->m_pkthdr.tso_segsz)
349 
350 #define	MTAG_ABI_NET80211	1132948340	/* net80211 ABI */
351 
352 struct ieee80211_cb {
353 	void	(*func)(struct ieee80211_node *, void *, int status);
354 	void	*arg;
355 };
356 #define	NET80211_TAG_CALLBACK	0	/* xmit complete callback */
357 int	ieee80211_add_callback(struct mbuf *m,
358 		void (*func)(struct ieee80211_node *, void *, int), void *arg);
359 void	ieee80211_process_callback(struct ieee80211_node *, struct mbuf *, int);
360 
361 #define	NET80211_TAG_XMIT_PARAMS	1
362 /* See below; this is after the bpf_params definition */
363 
364 #define	NET80211_TAG_RECV_PARAMS	2
365 
366 #define	NET80211_TAG_TOA_PARAMS		3
367 
368 struct ieee80211com;
369 int	ieee80211_parent_xmitpkt(struct ieee80211com *, struct mbuf *);
370 int	ieee80211_vap_xmitpkt(struct ieee80211vap *, struct mbuf *);
371 
372 void	net80211_get_random_bytes(void *, size_t);
373 
374 void	ieee80211_sysctl_attach(struct ieee80211com *);
375 void	ieee80211_sysctl_detach(struct ieee80211com *);
376 void	ieee80211_sysctl_vattach(struct ieee80211vap *);
377 void	ieee80211_sysctl_vdetach(struct ieee80211vap *);
378 
379 SYSCTL_DECL(_net_wlan);
380 int	ieee80211_sysctl_msecs_ticks(SYSCTL_HANDLER_ARGS);
381 
382 void	ieee80211_load_module(const char *);
383 
384 /*
385  * A "policy module" is an adjunct module to net80211 that provides
386  * functionality that typically includes policy decisions.  This
387  * modularity enables extensibility and vendor-supplied functionality.
388  */
389 #define	_IEEE80211_POLICY_MODULE(policy, name, version)			\
390 typedef void (*policy##_setup)(int);					\
391 SET_DECLARE(policy##_set, policy##_setup);				\
392 static int								\
393 wlan_##name##_modevent(module_t mod, int type, void *unused)		\
394 {									\
395 	policy##_setup * const *iter, f;				\
396 	switch (type) {							\
397 	case MOD_LOAD:							\
398 		SET_FOREACH(iter, policy##_set) {			\
399 			f = (void*) *iter;				\
400 			f(type);					\
401 		}							\
402 		return 0;						\
403 	case MOD_UNLOAD:						\
404 	case MOD_QUIESCE:						\
405 		if (nrefs) {						\
406 			printf("wlan_" #name ": still in use "		\
407 				"(%u dynamic refs)\n", nrefs);		\
408 			return EBUSY;					\
409 		}							\
410 		if (type == MOD_UNLOAD) {				\
411 			SET_FOREACH(iter, policy##_set) {		\
412 				f = (void*) *iter;			\
413 				f(type);				\
414 			}						\
415 		}							\
416 		return 0;						\
417 	}								\
418 	return EINVAL;							\
419 }									\
420 static moduledata_t name##_mod = {					\
421 	"wlan_" #name,							\
422 	wlan_##name##_modevent,						\
423 	0								\
424 };									\
425 DECLARE_MODULE(wlan_##name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);\
426 MODULE_VERSION(wlan_##name, version);					\
427 MODULE_DEPEND(wlan_##name, wlan, 1, 1, 1)
428 
429 /*
430  * Crypto modules implement cipher support.
431  */
432 #define	IEEE80211_CRYPTO_MODULE_ADD(name)				\
433 static void								\
434 name##_modevent(int type)						\
435 {									\
436 	if (type == MOD_LOAD)						\
437 		ieee80211_crypto_register(&name);			\
438 	else								\
439 		ieee80211_crypto_unregister(&name);			\
440 }									\
441 TEXT_SET(crypto##_set, name##_modevent)
442 
443 #define	IEEE80211_CRYPTO_MODULE(name, version)				\
444 	_IEEE80211_POLICY_MODULE(crypto, name, version);		\
445 	IEEE80211_CRYPTO_MODULE_ADD(name)
446 
447 /*
448  * Scanner modules provide scanning policy.
449  */
450 #define	IEEE80211_SCANNER_MODULE(name, version)				\
451 	_IEEE80211_POLICY_MODULE(scanner, name, version)
452 
453 #define	IEEE80211_SCANNER_ALG(name, alg, v)				\
454 static void								\
455 name##_modevent(int type)						\
456 {									\
457 	if (type == MOD_LOAD)						\
458 		ieee80211_scanner_register(alg, &v);			\
459 	else								\
460 		ieee80211_scanner_unregister(alg, &v);			\
461 }									\
462 TEXT_SET(scanner_set, name##_modevent);					\
463 
464 /*
465  * ACL modules implement acl policy.
466  */
467 #define	IEEE80211_ACL_MODULE(name, alg, version)			\
468 _IEEE80211_POLICY_MODULE(acl, name, version);				\
469 static void								\
470 alg##_modevent(int type)						\
471 {									\
472 	if (type == MOD_LOAD)						\
473 		ieee80211_aclator_register(&alg);			\
474 	else								\
475 		ieee80211_aclator_unregister(&alg);			\
476 }									\
477 TEXT_SET(acl_set, alg##_modevent);					\
478 
479 /*
480  * Authenticator modules handle 802.1x/WPA authentication.
481  */
482 #define	IEEE80211_AUTH_MODULE(name, version)				\
483 	_IEEE80211_POLICY_MODULE(auth, name, version)
484 
485 #define	IEEE80211_AUTH_ALG(name, alg, v)				\
486 static void								\
487 name##_modevent(int type)						\
488 {									\
489 	if (type == MOD_LOAD)						\
490 		ieee80211_authenticator_register(alg, &v);		\
491 	else								\
492 		ieee80211_authenticator_unregister(alg);		\
493 }									\
494 TEXT_SET(auth_set, name##_modevent)
495 
496 /*
497  * Rate control modules provide tx rate control support.
498  */
499 #define	IEEE80211_RATECTL_MODULE(alg, version)				\
500 	_IEEE80211_POLICY_MODULE(ratectl, alg, version);		\
501 
502 #define	IEEE80211_RATECTL_ALG(name, alg, v)				\
503 static void								\
504 alg##_modevent(int type)						\
505 {									\
506 	if (type == MOD_LOAD)						\
507 		ieee80211_ratectl_register(alg, &v);			\
508 	else								\
509 		ieee80211_ratectl_unregister(alg);			\
510 }									\
511 TEXT_SET(ratectl##_set, alg##_modevent)
512 
513 struct ieee80211req;
514 typedef int ieee80211_ioctl_getfunc(struct ieee80211vap *,
515     struct ieee80211req *);
516 SET_DECLARE(ieee80211_ioctl_getset, ieee80211_ioctl_getfunc);
517 #define	IEEE80211_IOCTL_GET(_name, _get) TEXT_SET(ieee80211_ioctl_getset, _get)
518 
519 typedef int ieee80211_ioctl_setfunc(struct ieee80211vap *,
520     struct ieee80211req *);
521 SET_DECLARE(ieee80211_ioctl_setset, ieee80211_ioctl_setfunc);
522 #define	IEEE80211_IOCTL_SET(_name, _set) TEXT_SET(ieee80211_ioctl_setset, _set)
523 
524 #ifdef DEBUGNET
525 typedef void debugnet80211_init_t(struct ieee80211com *, int *nrxr, int *ncl,
526     int *clsize);
527 typedef void debugnet80211_event_t(struct ieee80211com *, enum debugnet_ev);
528 typedef int debugnet80211_poll_t(struct ieee80211com *, int);
529 
530 struct debugnet80211_methods {
531 	debugnet80211_init_t		*dn8_init;
532 	debugnet80211_event_t		*dn8_event;
533 	debugnet80211_poll_t		*dn8_poll;
534 };
535 
536 #define	DEBUGNET80211_DEFINE(driver)					\
537 	static debugnet80211_init_t driver##_debugnet80211_init;		\
538 	static debugnet80211_event_t driver##_debugnet80211_event;	\
539 	static debugnet80211_poll_t driver##_debugnet80211_poll;		\
540 									\
541 	static struct debugnet80211_methods driver##_debugnet80211_methods = { \
542 		.dn8_init = driver##_debugnet80211_init,			\
543 		.dn8_event = driver##_debugnet80211_event,		\
544 		.dn8_poll = driver##_debugnet80211_poll,			\
545 	}
546 #define DEBUGNET80211_SET(ic, driver)					\
547 	(ic)->ic_debugnet_meth = &driver##_debugnet80211_methods
548 #else
549 #define DEBUGNET80211_DEFINE(driver)
550 #define DEBUGNET80211_SET(ic, driver)
551 #endif /* DEBUGNET */
552 
553 void ieee80211_vap_sync_mac_address(struct ieee80211vap *);
554 void ieee80211_vap_copy_mac_address(struct ieee80211vap *);
555 void ieee80211_vap_deliver_data(struct ieee80211vap *, struct mbuf *);
556 bool ieee80211_vap_ifp_check_is_monitor(struct ieee80211vap *);
557 bool ieee80211_vap_ifp_check_is_simplex(struct ieee80211vap *);
558 bool ieee80211_vap_ifp_check_is_running(struct ieee80211vap *);
559 void ieee80211_vap_ifp_set_running_state(struct ieee80211vap *, bool);
560 const uint8_t * ieee80211_vap_get_broadcast_address(struct ieee80211vap *);
561 
562 void	net80211_printf(const char *fmt, ...) __printflike(1, 2);
563 void	net80211_vap_printf(const struct ieee80211vap *, const char *fmt, ...)
564 	    __printflike(2, 3);
565 void	net80211_ic_printf(const struct ieee80211com *, const char *fmt, ...)
566 	    __printflike(2, 3);
567 
568 #endif /* _KERNEL */
569 
570 /* XXX this stuff belongs elsewhere */
571 /*
572  * Message formats for messages from the net80211 layer to user
573  * applications via the routing socket.  These messages are appended
574  * to an if_announcemsghdr structure.
575  */
576 struct ieee80211_join_event {
577 	uint8_t		iev_addr[6];
578 };
579 
580 struct ieee80211_leave_event {
581 	uint8_t		iev_addr[6];
582 };
583 
584 struct ieee80211_replay_event {
585 	uint8_t		iev_src[6];	/* src MAC */
586 	uint8_t		iev_dst[6];	/* dst MAC */
587 	uint8_t		iev_cipher;	/* cipher type */
588 	uint8_t		iev_keyix;	/* key id/index */
589 	uint64_t	iev_keyrsc;	/* RSC from key */
590 	uint64_t	iev_rsc;	/* RSC from frame */
591 };
592 
593 struct ieee80211_michael_event {
594 	uint8_t		iev_src[6];	/* src MAC */
595 	uint8_t		iev_dst[6];	/* dst MAC */
596 	uint8_t		iev_cipher;	/* cipher type */
597 	uint8_t		iev_keyix;	/* key id/index */
598 };
599 
600 struct ieee80211_wds_event {
601 	uint8_t		iev_addr[6];
602 };
603 
604 struct ieee80211_csa_event {
605 	uint32_t	iev_flags;	/* channel flags */
606 	uint16_t	iev_freq;	/* setting in Mhz */
607 	uint8_t		iev_ieee;	/* IEEE channel number */
608 	uint8_t		iev_mode;	/* CSA mode */
609 	uint8_t		iev_count;	/* CSA count */
610 };
611 
612 struct ieee80211_cac_event {
613 	uint32_t	iev_flags;	/* channel flags */
614 	uint16_t	iev_freq;	/* setting in Mhz */
615 	uint8_t		iev_ieee;	/* IEEE channel number */
616 	/* XXX timestamp? */
617 	uint8_t		iev_type;	/* IEEE80211_NOTIFY_CAC_* */
618 };
619 
620 struct ieee80211_radar_event {
621 	uint32_t	iev_flags;	/* channel flags */
622 	uint16_t	iev_freq;	/* setting in Mhz */
623 	uint8_t		iev_ieee;	/* IEEE channel number */
624 	/* XXX timestamp? */
625 };
626 
627 struct ieee80211_auth_event {
628 	uint8_t		iev_addr[6];
629 };
630 
631 struct ieee80211_deauth_event {
632 	uint8_t		iev_addr[6];
633 };
634 
635 struct ieee80211_country_event {
636 	uint8_t		iev_addr[6];
637 	uint8_t		iev_cc[2];	/* ISO country code */
638 };
639 
640 struct ieee80211_radio_event {
641 	uint8_t		iev_state;	/* 1 on, 0 off */
642 };
643 
644 #define	RTM_IEEE80211_ASSOC	100	/* station associate (bss mode) */
645 #define	RTM_IEEE80211_REASSOC	101	/* station re-associate (bss mode) */
646 #define	RTM_IEEE80211_DISASSOC	102	/* station disassociate (bss mode) */
647 #define	RTM_IEEE80211_JOIN	103	/* station join (ap mode) */
648 #define	RTM_IEEE80211_LEAVE	104	/* station leave (ap mode) */
649 #define	RTM_IEEE80211_SCAN	105	/* scan complete, results available */
650 #define	RTM_IEEE80211_REPLAY	106	/* sequence counter replay detected */
651 #define	RTM_IEEE80211_MICHAEL	107	/* Michael MIC failure detected */
652 #define	RTM_IEEE80211_REJOIN	108	/* station re-associate (ap mode) */
653 #define	RTM_IEEE80211_WDS	109	/* WDS discovery (ap mode) */
654 #define	RTM_IEEE80211_CSA	110	/* Channel Switch Announcement event */
655 #define	RTM_IEEE80211_RADAR	111	/* radar event */
656 #define	RTM_IEEE80211_CAC	112	/* Channel Availability Check event */
657 #define	RTM_IEEE80211_DEAUTH	113	/* station deauthenticate */
658 #define	RTM_IEEE80211_AUTH	114	/* station authenticate (ap mode) */
659 #define	RTM_IEEE80211_COUNTRY	115	/* discovered country code (sta mode) */
660 #define	RTM_IEEE80211_RADIO	116	/* RF kill switch state change */
661 
662 /*
663  * Structure prepended to raw packets sent through the bpf
664  * interface when set to DLT_IEEE802_11_RADIO.  This allows
665  * user applications to specify pretty much everything in
666  * an Atheros tx descriptor.  XXX need to generalize.
667  *
668  * XXX cannot be more than 14 bytes as it is copied to a sockaddr's
669  * XXX sa_data area.
670  */
671 struct ieee80211_bpf_params {
672 	uint8_t		ibp_vers;	/* version */
673 #define	IEEE80211_BPF_VERSION	0
674 	uint8_t		ibp_len;	/* header length in bytes */
675 	uint8_t		ibp_flags;
676 #define	IEEE80211_BPF_SHORTPRE	0x01	/* tx with short preamble */
677 #define	IEEE80211_BPF_NOACK	0x02	/* tx with no ack */
678 #define	IEEE80211_BPF_CRYPTO	0x04	/* tx with h/w encryption */
679 #define	IEEE80211_BPF_FCS	0x10	/* frame incldues FCS */
680 #define	IEEE80211_BPF_DATAPAD	0x20	/* frame includes data padding */
681 #define	IEEE80211_BPF_RTS	0x40	/* tx with RTS/CTS */
682 #define	IEEE80211_BPF_CTS	0x80	/* tx with CTS only */
683 	uint8_t		ibp_pri;	/* WME/WMM AC+tx antenna */
684 	uint8_t		ibp_try0;	/* series 1 try count */
685 	uint8_t		ibp_rate0;	/* series 1 IEEE tx rate */
686 	uint8_t		ibp_power;	/* tx power (device units) */
687 	uint8_t		ibp_ctsrate;	/* IEEE tx rate for CTS */
688 	uint8_t		ibp_try1;	/* series 2 try count */
689 	uint8_t		ibp_rate1;	/* series 2 IEEE tx rate */
690 	uint8_t		ibp_try2;	/* series 3 try count */
691 	uint8_t		ibp_rate2;	/* series 3 IEEE tx rate */
692 	uint8_t		ibp_try3;	/* series 4 try count */
693 	uint8_t		ibp_rate3;	/* series 4 IEEE tx rate */
694 };
695 
696 #ifdef _KERNEL
697 struct ieee80211_tx_params {
698 	struct ieee80211_bpf_params params;
699 };
700 int	ieee80211_add_xmit_params(struct mbuf *m,
701 	    const struct ieee80211_bpf_params *);
702 int	ieee80211_get_xmit_params(struct mbuf *m,
703 	    struct ieee80211_bpf_params *);
704 
705 struct ieee80211_rx_params;
706 struct ieee80211_rx_stats;
707 
708 int	ieee80211_add_rx_params(struct mbuf *m,
709 	    const struct ieee80211_rx_stats *rxs);
710 int	ieee80211_get_rx_params(struct mbuf *m,
711 	    struct ieee80211_rx_stats *rxs);
712 const struct ieee80211_rx_stats * ieee80211_get_rx_params_ptr(struct mbuf *m);
713 
714 struct ieee80211_toa_params {
715 	int request_id;
716 };
717 int	ieee80211_add_toa_params(struct mbuf *m,
718 	    const struct ieee80211_toa_params *p);
719 int	ieee80211_get_toa_params(struct mbuf *m,
720 	    struct ieee80211_toa_params *p);
721 
722 #define	IEEE80211_F_SURVEY_TIME		0x00000001
723 #define	IEEE80211_F_SURVEY_TIME_BUSY	0x00000002
724 #define	IEEE80211_F_SURVEY_NOISE_DBM	0x00000004
725 #define	IEEE80211_F_SURVEY_TSC		0x00000008
726 struct ieee80211_channel_survey {
727 	uint32_t s_flags;
728 	uint32_t s_time;
729 	uint32_t s_time_busy;
730 	int32_t s_noise;
731 	uint64_t s_tsc;
732 };
733 
734 #endif /* _KERNEL */
735 
736 /*
737  * Malloc API.  Other BSD operating systems have slightly
738  * different malloc/free namings (eg DragonflyBSD.)
739  */
740 #define	IEEE80211_MALLOC	malloc
741 #define	IEEE80211_FREE		free
742 
743 /* XXX TODO: get rid of WAITOK, fix all the users of it? */
744 #define	IEEE80211_M_NOWAIT	M_NOWAIT
745 #define	IEEE80211_M_WAITOK	M_WAITOK
746 #define	IEEE80211_M_ZERO	M_ZERO
747 
748 /* XXX TODO: the type fields */
749 
750 #endif /* _NET80211_IEEE80211_FREEBSD_H_ */
751