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