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