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