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