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