ieee80211_netbsd.h revision 1.21.2.4 1 /* $NetBSD: ieee80211_netbsd.h,v 1.21.2.4 2018/07/16 20:11:11 phil Exp $ */
2
3 /*-
4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 *
6 * Copyright (c) 2003-2008 Sam Leffler, Errno Consulting
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * $FreeBSD: ieee80211_freebsd.h$
30 */
31 #ifndef _NET80211_IEEE80211_NETBSD_H_
32 #define _NET80211_IEEE80211_NETBSD_H_
33
34 #ifdef _KERNEL
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/atomic.h>
38 #include <sys/cprng.h>
39 #include <sys/lock.h>
40 #include <sys/mbuf.h>
41 #include <sys/malloc.h>
42 #include <sys/mallocvar.h>
43 #include <sys/mutex.h>
44 #include <sys/rwlock.h>
45 #include <sys/sysctl.h>
46 #include <sys/workqueue.h>
47
48 // #include <net80211/_ieee80211.h>
49
50 #include <net/if.h>
51
52 /*
53 * Defines to make the FreeBSD code work on NetBSD
54 */
55
56 #define PI_NET IPL_NET
57 #define EDOOFUS EINVAL
58 #define IFF_PPROMISC IFF_PROMISC
59
60 #define __offsetof(type, field) __builtin_offsetof(type, field)
61 #define arc4random cprng_fast32
62 #define atomic_subtract_int(var,val) atomic_add_int(var,-(val))
63 #define caddr_t void *
64 #define callout_drain(x) callout_halt(x, NULL)
65 #define m_catpkt(x,y) m_cat(x,y)
66 #define mtx_lock(mtx) mutex_enter(mtx)
67 #define mtx_unlock(mtx) mutex_exit(mtx)
68 #define mtx_owned(mtx) mutex_owned(mtx)
69 #define mtx_destroy(mtx) mutex_destroy(mtx)
70 #define mtx_sleep(a1, a2, a3, a4, a5) /* NNN not sure what it should be. */
71 #define nitems(x) (sizeof((x)) / sizeof((x)[0]))
72 #define ovbcopy(dst,src,size) memmove(dst,src,size)
73 #define ticks hardclock_ticks
74
75 /*
76 * task stuff needs major work NNN!
77 */
78 static __inline int dummy(void);
79 static __inline int dummy(void) { return 0; }
80
81 struct timeout_task { int needsWork; };
82
83 typedef void task_fn_t(void *context, int pending);
84
85 struct task {
86 /* some kind of queue entry? */
87 task_fn_t *t_func;
88 void *t_arg;
89 int t_pri;
90 };
91 #define TASK_INIT(var, pri, func, arg) do { \
92 (var)->t_func = func; \
93 (var)->t_arg = arg; \
94 (var)->t_pri = pri; \
95 } while(0)
96
97 #define taskqueue workqueue
98 #define taskqueue_enqueue(queue,task) /* workqueue_enqueue(queue, task, NULL) */
99 #define taskqueue_drain(queue,task) /* workqueue_wait(queue, task) */
100 #define taskqueue_free(queue) /* workqueue_destroy(queue) */
101 #define taskqueue_block(queue) /* */
102 #define taskqueue_unblock(queue) /* */
103 #define taskqueue_drain_timeout(queue, x) /* */
104 #define taskqueue_enqueue_timeout(queue, x, y) { int __unused zzz = 0; }
105 #define taskqueue_cancel_timeout(queue, x, y) dummy()
106 #define TIMEOUT_TASK_INIT(queue, a2, a3, a4, a5) /* */
107
108 /* Other stuff that needs to be fixed NNN */
109 #define priv_check(x,y) 1
110
111 /* Coult it be this simple? */
112 #define if_addr_rlock(ifp) IFNET_LOCK(ifp)
113 #define if_addr_runlock(x) IFNET_UNLOCK(ifp)
114
115 /* VNET defines to remove them ... NNN may need a lot of work! */
116
117 #define CURVNET_SET(x) /* */
118 #define CURVNET_RESTORE() /* */
119 #define CURVNET_SET_QUIET(x) /* */
120
121 /* counters */
122 typedef uint64_t counter_u64_t;
123 #define counter_u64_free(x) /* */
124 #define counter_u64_fetch(x) x
125 #define counter_u64_alloc(x) 0
126
127 typedef enum {
128 IFCOUNTER_IPACKETS = 0,
129 IFCOUNTER_IERRORS,
130 IFCOUNTER_OPACKETS,
131 IFCOUNTER_OERRORS,
132 IFCOUNTER_COLLISIONS,
133 IFCOUNTER_IBYTES,
134 IFCOUNTER_OBYTES,
135 IFCOUNTER_IMCASTS,
136 IFCOUNTER_OMCASTS,
137 IFCOUNTER_IQDROPS,
138 IFCOUNTER_OQDROPS,
139 IFCOUNTER_NOPROTO,
140 IFCOUNTERS /* Array size. */
141 } ift_counter;
142 void if_inc_counter(struct ifnet *, ift_counter, int64_t);
143
144 #define if_get_counter_default(ipf,cnt) \
145 (cnt == IFCOUNTER_OERRORS ? ipf->if_oerrors : \
146 (cnt == IFCOUNTER_IERRORS ? ipf->if_ierrors : 0 ))
147
148 #define IF_LLADDR(ifp) IFADDR_FIRST(ifp)
149
150 /*
151 * Sysctl support??? BBB
152 */
153
154 #define SYSCTL_INT(a1, a2, a3, a4, a5, a6, a7) /* notyet */
155 #define SYSCTL_PROC(a1, a2, a3, a4, a5, a6, a7, a8, a9) /* notyet */
156 #undef SYSCTL_NODE
157 #define SYSCTL_NODE(a1, a2, a3, a4, a5, a6) int a2 __unused
158
159 /* another unknown macro ... at least notyet */
160 #define SYSINIT(a1, a2, a3, a4, a5) /* notyet */
161 #define TEXT_SET(set, sym) /* notyet ... linker magic, supported? */
162
163 /*
164 * FreeBSD code uses KASSERT but different from NetBSD so ...
165 */
166 #define FBSDKASSERT(_cond, _complaint) \
167 do { \
168 if (!(_cond)) \
169 panic _complaint; \
170 } while (/*CONSTCOND*/0)
171
172 /*
173 * Common state locking definitions.
174 */
175 typedef struct {
176 char name[16]; /* e.g. "ath0_com_lock" */
177 kmutex_t mtx;
178 } ieee80211_com_lock_t;
179 #define IEEE80211_LOCK_INIT(_ic, _name) do { \
180 ieee80211_com_lock_t *cl = &(_ic)->ic_comlock; \
181 snprintf(cl->name, sizeof(cl->name), "%s_com_lock", _name); \
182 mutex_init(&cl->mtx, MUTEX_DEFAULT, IPL_NET); \
183 } while (0)
184 #define IEEE80211_LOCK_OBJ(_ic) (&(_ic)->ic_comlock.mtx)
185 #define IEEE80211_LOCK_DESTROY(_ic) mutex_destroy(IEEE80211_LOCK_OBJ(_ic))
186 #define IEEE80211_LOCK(_ic) mutex_enter(IEEE80211_LOCK_OBJ(_ic))
187 #define IEEE80211_UNLOCK(_ic) mutex_exit(IEEE80211_LOCK_OBJ(_ic))
188 #define IEEE80211_LOCK_ASSERT(_ic) \
189 FBSDKASSERT(mutex_owned(IEEE80211_LOCK_OBJ(_ic)), ("Lock is not owned"))
190 #define IEEE80211_UNLOCK_ASSERT(_ic) \
191 FBSDKASSERT(!mutex_owned(IEEE80211_LOCK_OBJ(_ic)), ("Lock is owned"))
192
193 /*
194 * Transmit lock.
195 *
196 * This is a (mostly) temporary lock designed to serialise all of the
197 * transmission operations throughout the stack.
198 */
199 typedef struct {
200 char name[16]; /* e.g. "ath0_tx_lock" */
201 kmutex_t mtx;
202 } ieee80211_tx_lock_t;
203 #define IEEE80211_TX_LOCK_INIT(_ic, _name) do { \
204 ieee80211_tx_lock_t *cl = &(_ic)->ic_txlock; \
205 snprintf(cl->name, sizeof(cl->name), "%s_tx_lock", _name); \
206 mutex_init(&cl->mtx, MUTEX_DEFAULT, IPL_NET); \
207 } while (0)
208 #define IEEE80211_TX_LOCK_OBJ(_ic) (&(_ic)->ic_txlock.mtx)
209 #define IEEE80211_TX_LOCK_DESTROY(_ic) mutex_destroy(IEEE80211_TX_LOCK_OBJ(_ic))
210 #define IEEE80211_TX_LOCK(_ic) mutex_enter(IEEE80211_TX_LOCK_OBJ(_ic))
211 #define IEEE80211_TX_UNLOCK(_ic) mutex_exit(IEEE80211_TX_LOCK_OBJ(_ic))
212 #define IEEE80211_TX_LOCK_ASSERT(_ic) \
213 FBSDKASSERT(mutex_owned(IEEE80211_TX_LOCK_OBJ(_ic)), ("lock not owned"))
214 #define IEEE80211_TX_UNLOCK_ASSERT(_ic) \
215 FBSDKASSERT(!mutex_owned(IEEE80211_TX_LOCK_OBJ(_ic)), ("lock is owned"))
216
217 /*
218 * Stageq / ni_tx_superg lock
219 */
220 typedef struct {
221 char name[16]; /* e.g. "ath0_ff_lock" */
222 kmutex_t mtx;
223 } ieee80211_ff_lock_t;
224 #define IEEE80211_FF_LOCK_INIT(_ic, _name) do { \
225 ieee80211_ff_lock_t *fl = &(_ic)->ic_fflock; \
226 snprintf(fl->name, sizeof(fl->name), "%s_ff_lock", _name); \
227 mutex_init(&fl->mtx, MUTEX_DEFAULT, IPL_NET); \
228 } while (0)
229 #define IEEE80211_FF_LOCK_OBJ(_ic) (&(_ic)->ic_fflock.mtx)
230 #define IEEE80211_FF_LOCK_DESTROY(_ic) mutex_destroy(IEEE80211_FF_LOCK_OBJ(_ic))
231 #define IEEE80211_FF_LOCK(_ic) mutex_enter(IEEE80211_FF_LOCK_OBJ(_ic))
232 #define IEEE80211_FF_UNLOCK(_ic) mutex_exit(IEEE80211_FF_LOCK_OBJ(_ic))
233 #define IEEE80211_FF_LOCK_ASSERT(_ic) \
234 FBSDKASSERT(mutex_owned(IEEE80211_FF_LOCK_OBJ(_ic)), ("lock not owned"))
235
236 /*
237 * Node locking definitions.
238 */
239 typedef struct {
240 char name[16]; /* e.g. "ath0_node_lock" */
241 kmutex_t mtx;
242 } ieee80211_node_lock_t;
243 #define IEEE80211_NODE_LOCK_INIT(_nt, _name) do { \
244 ieee80211_node_lock_t *nl = &(_nt)->nt_nodelock; \
245 snprintf(nl->name, sizeof(nl->name), "%s_node_lock", _name); \
246 mutex_init(&nl->mtx, MUTEX_DEFAULT, IPL_NET); \
247 } while (0)
248 #define IEEE80211_NODE_LOCK_OBJ(_nt) (&(_nt)->nt_nodelock.mtx)
249 #define IEEE80211_NODE_LOCK_DESTROY(_nt) \
250 mutex_destroy(IEEE80211_NODE_LOCK_OBJ(_nt))
251 #define IEEE80211_NODE_LOCK(_nt) \
252 mutex_enter(IEEE80211_NODE_LOCK_OBJ(_nt))
253 #define IEEE80211_NODE_IS_LOCKED(_nt) \
254 mtx_owned(IEEE80211_NODE_LOCK_OBJ(_nt))
255 #define IEEE80211_NODE_UNLOCK(_nt) \
256 mutex_exit(IEEE80211_NODE_LOCK_OBJ(_nt))
257 #define IEEE80211_NODE_LOCK_ASSERT(_nt) \
258 FBSDKASSERT(mutex_owned(IEEE80211_NODE_LOCK_OBJ(_nt)), ("lock not owned"))
259
260 /*
261 * Power-save queue definitions.
262 */
263 typedef kmutex_t ieee80211_psq_lock_t;
264 #define IEEE80211_PSQ_INIT(_psq, _name) \
265 mutex_init(&(_psq)->psq_lock, MUTEX_DEFAULT, IPL_NET)
266 #define IEEE80211_PSQ_DESTROY(_psq) mutex_destroy(&(_psq)->psq_lock)
267 #define IEEE80211_PSQ_LOCK(_psq) mutex_enter(&(_psq)->psq_lock)
268 #define IEEE80211_PSQ_UNLOCK(_psq) mutex_exit(&(_psq)->psq_lock)
269
270 #ifndef IF_PREPEND_LIST
271 #define _IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do { \
272 (mtail)->m_nextpkt = (ifq)->ifq_head; \
273 if ((ifq)->ifq_tail == NULL) \
274 (ifq)->ifq_tail = (mtail); \
275 (ifq)->ifq_head = (mhead); \
276 (ifq)->ifq_len += (mcount); \
277 } while (0)
278 #define IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do { \
279 IF_LOCK(ifq); \
280 _IF_PREPEND_LIST(ifq, mhead, mtail, mcount); \
281 IF_UNLOCK(ifq); \
282 } while (0)
283 #endif /* IF_PREPEND_LIST */
284
285 /*
286 * Age queue definitions.
287 */
288 typedef kmutex_t ieee80211_ageq_lock_t;
289 #define IEEE80211_AGEQ_INIT(_aq, _name) \
290 mutex_init(&(_aq)->aq_lock, MUTEX_DEFAULT, IPL_NET)
291 #define IEEE80211_AGEQ_DESTROY(_aq) mutex_destroy(&(_aq)->aq_lock)
292 #define IEEE80211_AGEQ_LOCK(_aq) mutex_enter(&(_aq)->aq_lock)
293 #define IEEE80211_AGEQ_UNLOCK(_aq) mutex_exit(&(_aq)->aq_lock)
294
295 /*
296 * 802.1x MAC ACL database locking definitions.
297 */
298 typedef kmutex_t acl_lock_t;
299 #define ACL_LOCK_INIT(_as, _name) \
300 mutex_init(&(_as)->as_lock, MUTEX_DEFAULT, IPL_NET)
301 #define ACL_LOCK_DESTROY(_as) mutex_destroy(&(_as)->as_lock)
302 #define ACL_LOCK(_as) mutex_enter(&(_as)->as_lock)
303 #define ACL_UNLOCK(_as) mutex_exit(&(_as)->as_lock)
304 #define ACL_LOCK_ASSERT(_as) \
305 FBSDKASSERT(mutex_owned((&(_as)->as_lock)), ("lock not owned"))
306
307 /*
308 * Scan table definitions.
309 */
310 typedef kmutex_t ieee80211_scan_table_lock_t;
311 #define IEEE80211_SCAN_TABLE_LOCK_INIT(_st, _name) \
312 mutex_init(&(_st)->st_lock, MUTEX_DEFAULT, IPL_NET)
313 #define IEEE80211_SCAN_TABLE_LOCK_DESTROY(_st) mutex_destroy(&(_st)->st_lock)
314 #define IEEE80211_SCAN_TABLE_LOCK(_st) mutex_enter(&(_st)->st_lock)
315 #define IEEE80211_SCAN_TABLE_UNLOCK(_st) mutex_exit(&(_st)->st_lock)
316
317 typedef kmutex_t ieee80211_scan_iter_lock_t;
318 #define IEEE80211_SCAN_ITER_LOCK_INIT(_st, _name) \
319 mutex_init(&(_st)->st_scanlock, MUTEX_DEFAULT, IPL_NET)
320 #define IEEE80211_SCAN_ITER_LOCK_DESTROY(_st) mutex_destroy(&(_st)->st_scanlock)
321 #define IEEE80211_SCAN_ITER_LOCK(_st) mutex_enter(&(_st)->st_scanlock)
322 #define IEEE80211_SCAN_ITER_UNLOCK(_st) mutex_exit(&(_st)->st_scanlock)
323
324 /*
325 * Mesh node/routing definitions.
326 */
327 typedef kmutex_t ieee80211_rte_lock_t;
328 #define MESH_RT_ENTRY_LOCK_INIT(_rt, _name) \
329 mutex_init(&(rt)->rt_lock, MUTEX_DEFAULT, IPL_NET)
330 #define MESH_RT_ENTRY_LOCK_DESTROY(_rt) \
331 mutex_destroy(&(_rt)->rt_lock)
332 #define MESH_RT_ENTRY_LOCK(rt) mutex_enter(&(rt)->rt_lock)
333 #define MESH_RT_ENTRY_LOCK_ASSERT(rt) \
334 FBSDKASSERT(mutex_owned(&(rt)->rt_lock), ("mutex not owned"))
335 #define MESH_RT_ENTRY_UNLOCK(rt) mutex_exit(&(rt)->rt_lock)
336
337 typedef kmutex_t ieee80211_rt_lock_t;
338 #define MESH_RT_LOCK(ms) mutex_enter(&(ms)->ms_rt_lock)
339 #define MESH_RT_LOCK_ASSERT(ms) \
340 FBSDKASSERT(mutex_owned(&(ms)->ms_rt_lock), ("lock not owned"))
341 #define MESH_RT_UNLOCK(ms) mutex_exit(&(ms)->ms_rt_lock)
342 #define MESH_RT_LOCK_INIT(ms, name) \
343 mutex_init(&(ms)->ms_rt_lock, MUTEX_DEFAULT, IPL_NET)
344 #define MESH_RT_LOCK_DESTROY(ms) \
345 mutex_destroy(&(ms)->ms_rt_lock)
346
347 /*
348 * Node reference counting definitions.
349 *
350 * ieee80211_node_initref initialize the reference count to 1
351 * ieee80211_node_incref add a reference
352 * ieee80211_node_decref remove a reference
353 * ieee80211_node_dectestref remove a reference and return 1 if this
354 * is the last reference, otherwise 0
355 * ieee80211_node_refcnt reference count for printing (only)
356 */
357
358 #define ieee80211_node_initref(_ni) \
359 do { ((_ni)->ni_refcnt = 1); } while (0)
360 #define ieee80211_node_incref(_ni) \
361 atomic_add_int(&(_ni)->ni_refcnt, 1)
362 #define ieee80211_node_decref(_ni) \
363 atomic_subtract_int(&(_ni)->ni_refcnt, 1)
364 struct ieee80211_node;
365 int ieee80211_node_dectestref(struct ieee80211_node *ni);
366 #define ieee80211_node_refcnt(_ni) (_ni)->ni_refcnt
367
368 struct ifqueue;
369 struct ieee80211vap;
370 void ieee80211_drain_ifq(struct ifqueue *);
371 void ieee80211_flush_ifq(struct ifqueue *, struct ieee80211vap *);
372
373 void ieee80211_vap_destroy(struct ieee80211vap *);
374
375 #define IFNET_IS_UP_RUNNING(_ifp) \
376 (((_ifp)->if_flags & IFF_UP) && \
377 ((_ifp)->if_flags & IFF_RUNNING))
378
379 /* XXX TODO: cap these at 1, as hz may not be 1000 */
380 #define msecs_to_ticks(ms) (((ms)*hz)/1000)
381 #define ticks_to_msecs(t) (1000*(t) / hz)
382 #define ticks_to_secs(t) ((t) / hz)
383
384 #define ieee80211_time_after(a,b) ((long)(b) - (long)(a) < 0)
385 #define ieee80211_time_before(a,b) ieee80211_time_after(b,a)
386 #define ieee80211_time_after_eq(a,b) ((long)(a) - (long)(b) >= 0)
387 #define ieee80211_time_before_eq(a,b) ieee80211_time_after_eq(b,a)
388
389 struct mbuf *ieee80211_getmgtframe(uint8_t **frm, int headroom, int pktlen);
390
391 /* tx path usage */
392 #define M_ENCAP M_LINK0 /* 802.11 encap done */
393 #define M_EAPOL M_LINK3 /* PAE/EAPOL frame */
394 #define M_PWR_SAV M_LINK4 /* bypass PS handling */
395 #define M_MORE_DATA M_LINK5 /* more data frames to follow */
396 #define M_FF M_LINK6 /* fast frame / A-MSDU */
397 #define M_TXCB M_LINK7 /* do tx complete callback */
398 #define M_AMPDU_MPDU M_LINK8 /* ok for A-MPDU aggregation */
399 #define M_FRAG M_LINK9 /* frame fragmentation */
400 #define M_FIRSTFRAG M_LINK10 /* first frame fragment */
401 #define M_LASTFRAG M_LINK11 /* last frame fragment */
402
403 #define M_80211_TX \
404 (M_ENCAP|M_EAPOL|M_PWR_SAV|M_MORE_DATA|M_FF|M_TXCB| \
405 M_AMPDU_MPDU|M_FRAG|M_FIRSTFRAG|M_LASTFRAG)
406
407 /* rx path usage */
408 #define M_AMPDU M_LINK1 /* A-MPDU subframe */
409 #define M_WEP M_LINK2 /* WEP done by hardware */
410 #if 0
411 #define M_AMPDU_MPDU M_LINK8 /* A-MPDU re-order done */
412 #endif
413 #define M_80211_RX (M_AMPDU|M_WEP|M_AMPDU_MPDU)
414
415 #define IEEE80211_MBUF_TX_FLAG_BITS \
416 M_FLAG_BITS \
417 "\15M_ENCAP\17M_EAPOL\20M_PWR_SAV\21M_MORE_DATA\22M_FF\23M_TXCB" \
418 "\24M_AMPDU_MPDU\25M_FRAG\26M_FIRSTFRAG\27M_LASTFRAG"
419
420 #define IEEE80211_MBUF_RX_FLAG_BITS \
421 M_FLAG_BITS \
422 "\15M_AMPDU\16M_WEP\24M_AMPDU_MPDU"
423
424 /*
425 * Store WME access control bits in the vlan tag.
426 * This is safe since it's done after the packet is classified
427 * (where we use any previous tag) and because it's passed
428 * directly in to the driver and there's no chance someone
429 * else will clobber them on us.
430 */
431 #define M_WME_SETAC(m, ac) \
432 ((m)->m_pkthdr.ether_vtag = (ac))
433 #define M_WME_GETAC(m) ((m)->m_pkthdr.ether_vtag)
434
435 /*
436 * Mbufs on the power save queue are tagged with an age and
437 * timed out. We reuse the hardware checksum field in the
438 * mbuf packet header to store this data.
439 */
440 #define M_AGE_SET(m,v) (m->m_pkthdr.csum_data = v)
441 #define M_AGE_GET(m) (m->m_pkthdr.csum_data)
442 #define M_AGE_SUB(m,adj) (m->m_pkthdr.csum_data -= adj)
443
444 /*
445 * Store the sequence number. XXX? correct to use segsz?
446 */
447 #define M_SEQNO_SET(m, seqno) \
448 ((m)->m_pkthdr.segsz = (seqno))
449 #define M_SEQNO_GET(m) ((m)->m_pkthdr.segsz)
450
451 #define MTAG_ABI_NET80211 1132948340 /* net80211 ABI */
452
453 struct ieee80211_cb {
454 void (*func)(struct ieee80211_node *, void *, int status);
455 void *arg;
456 };
457 #define NET80211_TAG_CALLBACK 0 /* xmit complete callback */
458 int ieee80211_add_callback(struct mbuf *m,
459 void (*func)(struct ieee80211_node *, void *, int), void *arg);
460 void ieee80211_process_callback(struct ieee80211_node *, struct mbuf *, int);
461
462 #define NET80211_TAG_XMIT_PARAMS 1
463 /* See below; this is after the bpf_params definition */
464
465 #define NET80211_TAG_RECV_PARAMS 2
466
467 #define NET80211_TAG_TOA_PARAMS 3
468
469 struct ieee80211com;
470 int ieee80211_parent_xmitpkt(struct ieee80211com *, struct mbuf *);
471 int ieee80211_vap_xmitpkt(struct ieee80211vap *, struct mbuf *);
472
473 void get_random_bytes(void *, size_t);
474
475 void ieee80211_sysctl_attach(struct ieee80211com *);
476 void ieee80211_sysctl_detach(struct ieee80211com *);
477 void ieee80211_sysctl_vattach(struct ieee80211vap *);
478 void ieee80211_sysctl_vdetach(struct ieee80211vap *);
479
480 #if notyet
481 SYSCTL_DECL(_net_wlan);
482 int ieee80211_sysctl_msecs_ticks(SYSCTL_HANDLER_ARGS);
483 #endif
484
485
486 #ifdef notyet
487
488 /*
489 * A "policy module" is an adjunct module to net80211 that provides
490 * functionality that typically includes policy decisions. This
491 * modularity enables extensibility and vendor-supplied functionality.
492 */
493 #define _IEEE80211_POLICY_MODULE(policy, name, version) \
494 typedef void (*policy##_setup)(int); \
495 SET_DECLARE(policy##_set, policy##_setup); \
496 static int \
497 wlan_##name##_modevent(module_t mod, int type, void *unused) \
498 { \
499 policy##_setup * const *iter, f; \
500 switch (type) { \
501 case MOD_LOAD: \
502 SET_FOREACH(iter, policy##_set) { \
503 f = (void*) *iter; \
504 f(type); \
505 } \
506 return 0; \
507 case MOD_UNLOAD: \
508 case MOD_QUIESCE: \
509 if (nrefs) { \
510 printf("wlan_" #name ": still in use " \
511 "(%u dynamic refs)\n", nrefs); \
512 return EBUSY; \
513 } \
514 if (type == MOD_UNLOAD) { \
515 SET_FOREACH(iter, policy##_set) { \
516 f = (void*) *iter; \
517 f(type); \
518 } \
519 } \
520 return 0; \
521 } \
522 return EINVAL; \
523 } \
524 static moduledata_t name##_mod = { \
525 "wlan_" #name, \
526 wlan_##name##_modevent, \
527 0 \
528 }; \
529 DECLARE_MODULE(wlan_##name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);\
530 MODULE_VERSION(wlan_##name, version); \
531 MODULE_DEPEND(wlan_##name, wlan, 1, 1, 1)
532
533 /*
534 * Crypto modules implement cipher support.
535 */
536 #define IEEE80211_CRYPTO_MODULE(name, version) \
537 _IEEE80211_POLICY_MODULE(crypto, name, version); \
538 static void \
539 name##_modevent(int type) \
540 { \
541 if (type == MOD_LOAD) \
542 ieee80211_crypto_register(&name); \
543 else \
544 ieee80211_crypto_unregister(&name); \
545 } \
546 TEXT_SET(crypto##_set, name##_modevent)
547
548 /*
549 * Scanner modules provide scanning policy.
550 */
551 #define IEEE80211_SCANNER_MODULE(name, version) \
552 _IEEE80211_POLICY_MODULE(scanner, name, version)
553
554 #define IEEE80211_SCANNER_ALG(name, alg, v) \
555 static void \
556 name##_modevent(int type) \
557 { \
558 if (type == MOD_LOAD) \
559 ieee80211_scanner_register(alg, &v); \
560 else \
561 ieee80211_scanner_unregister(alg, &v); \
562 } \
563 TEXT_SET(scanner_set, name##_modevent); \
564
565 /*
566 * ACL modules implement acl policy.
567 */
568 #define IEEE80211_ACL_MODULE(name, alg, version) \
569 _IEEE80211_POLICY_MODULE(acl, name, version); \
570 static void \
571 alg##_modevent(int type) \
572 { \
573 if (type == MOD_LOAD) \
574 ieee80211_aclator_register(&alg); \
575 else \
576 ieee80211_aclator_unregister(&alg); \
577 } \
578 TEXT_SET(acl_set, alg##_modevent); \
579
580 /*
581 * Authenticator modules handle 802.1x/WPA authentication.
582 */
583 #define IEEE80211_AUTH_MODULE(name, version) \
584 _IEEE80211_POLICY_MODULE(auth, name, version)
585
586 #define IEEE80211_AUTH_ALG(name, alg, v) \
587 static void \
588 name##_modevent(int type) \
589 { \
590 if (type == MOD_LOAD) \
591 ieee80211_authenticator_register(alg, &v); \
592 else \
593 ieee80211_authenticator_unregister(alg); \
594 } \
595 TEXT_SET(auth_set, name##_modevent)
596
597 /*
598 * Rate control modules provide tx rate control support.
599 */
600 #define IEEE80211_RATECTL_MODULE(alg, version) \
601 _IEEE80211_POLICY_MODULE(ratectl, alg, version); \
602
603 #define IEEE80211_RATECTL_ALG(name, alg, v) \
604 static void \
605 alg##_modevent(int type) \
606 { \
607 if (type == MOD_LOAD) \
608 ieee80211_ratectl_register(alg, &v); \
609 else \
610 ieee80211_ratectl_unregister(alg); \
611 } \
612 TEXT_SET(ratectl##_set, alg##_modevent)
613
614 #else
615 /* NNN This looks like module load/unload support ... notyet supported */
616 #define _IEEE80211_POLICY_MODULE(policy, name, version) /* unsupported */
617 #define IEEE80211_CRYPTO_MODULE(name, version) /* unsupported */
618 #define IEEE80211_SCANNER_MODULE(name, version) /* unsupported */
619 #define IEEE80211_SCANNER_ALG(name, alg, v) /* unsupported */
620 #define IEEE80211_ACL_MODULE(name, alg, version) const void *const temp = &alg
621 #define IEEE80211_AUTH_MODULE(name, version) /* unsupported */
622 #define IEEE80211_AUTH_ALG(name, alg, v) /* unsupported */
623 #define IEEE80211_RATECTL_MODULE(alg, version) /* unsupported */
624 #define IEEE80211_RATECTL_ALG(name, alg, v) /* unsupported */
625 #endif
626
627 /*
628 * IOCTL support
629 */
630
631 struct ieee80211req;
632
633 typedef int ieee80211_ioctl_getfunc(struct ieee80211vap *, struct ieee80211req *);
634 #if notyet
635 SET_DECLARE(ieee80211_ioctl_getset, ieee80211_ioctl_getfunc);
636 #endif
637 #define IEEE80211_IOCTL_GET(_name, _get) TEXT_SET(ieee80211_ioctl_getset, _get)
638
639 typedef int ieee80211_ioctl_setfunc(struct ieee80211vap *, struct ieee80211req *);
640 #if notyet
641 SET_DECLARE(ieee80211_ioctl_setset, ieee80211_ioctl_setfunc);
642 #endif
643 #define IEEE80211_IOCTL_SET(_name, _set) TEXT_SET(ieee80211_ioctl_setset, _set)
644
645 #endif /* _KERNEL */
646
647 /* XXX this stuff belongs elsewhere */
648 /*
649 * Message formats for messages from the net80211 layer to user
650 * applications via the routing socket. These messages are appended
651 * to an if_announcemsghdr structure.
652 */
653 struct ieee80211_join_event {
654 uint8_t iev_addr[6];
655 };
656
657 struct ieee80211_leave_event {
658 uint8_t iev_addr[6];
659 };
660
661 struct ieee80211_replay_event {
662 uint8_t iev_src[6]; /* src MAC */
663 uint8_t iev_dst[6]; /* dst MAC */
664 uint8_t iev_cipher; /* cipher type */
665 uint8_t iev_keyix; /* key id/index */
666 uint64_t iev_keyrsc; /* RSC from key */
667 uint64_t iev_rsc; /* RSC from frame */
668 };
669
670 struct ieee80211_michael_event {
671 uint8_t iev_src[6]; /* src MAC */
672 uint8_t iev_dst[6]; /* dst MAC */
673 uint8_t iev_cipher; /* cipher type */
674 uint8_t iev_keyix; /* key id/index */
675 };
676
677 struct ieee80211_wds_event {
678 uint8_t iev_addr[6];
679 };
680
681 struct ieee80211_csa_event {
682 uint32_t iev_flags; /* channel flags */
683 uint16_t iev_freq; /* setting in Mhz */
684 uint8_t iev_ieee; /* IEEE channel number */
685 uint8_t iev_mode; /* CSA mode */
686 uint8_t iev_count; /* CSA count */
687 };
688
689 struct ieee80211_cac_event {
690 uint32_t iev_flags; /* channel flags */
691 uint16_t iev_freq; /* setting in Mhz */
692 uint8_t iev_ieee; /* IEEE channel number */
693 /* XXX timestamp? */
694 uint8_t iev_type; /* IEEE80211_NOTIFY_CAC_* */
695 };
696
697 struct ieee80211_radar_event {
698 uint32_t iev_flags; /* channel flags */
699 uint16_t iev_freq; /* setting in Mhz */
700 uint8_t iev_ieee; /* IEEE channel number */
701 /* XXX timestamp? */
702 };
703
704 struct ieee80211_auth_event {
705 uint8_t iev_addr[6];
706 };
707
708 struct ieee80211_deauth_event {
709 uint8_t iev_addr[6];
710 };
711
712 struct ieee80211_country_event {
713 uint8_t iev_addr[6];
714 uint8_t iev_cc[2]; /* ISO country code */
715 };
716
717 struct ieee80211_radio_event {
718 uint8_t iev_state; /* 1 on, 0 off */
719 };
720
721 #define RTM_IEEE80211_ASSOC 100 /* station associate (bss mode) */
722 #define RTM_IEEE80211_REASSOC 101 /* station re-associate (bss mode) */
723 #define RTM_IEEE80211_DISASSOC 102 /* station disassociate (bss mode) */
724 #define RTM_IEEE80211_JOIN 103 /* station join (ap mode) */
725 #define RTM_IEEE80211_LEAVE 104 /* station leave (ap mode) */
726 #define RTM_IEEE80211_SCAN 105 /* scan complete, results available */
727 #define RTM_IEEE80211_REPLAY 106 /* sequence counter replay detected */
728 #define RTM_IEEE80211_MICHAEL 107 /* Michael MIC failure detected */
729 #define RTM_IEEE80211_REJOIN 108 /* station re-associate (ap mode) */
730 #define RTM_IEEE80211_WDS 109 /* WDS discovery (ap mode) */
731 #define RTM_IEEE80211_CSA 110 /* Channel Switch Announcement event */
732 #define RTM_IEEE80211_RADAR 111 /* radar event */
733 #define RTM_IEEE80211_CAC 112 /* Channel Availability Check event */
734 #define RTM_IEEE80211_DEAUTH 113 /* station deauthenticate */
735 #define RTM_IEEE80211_AUTH 114 /* station authenticate (ap mode) */
736 #define RTM_IEEE80211_COUNTRY 115 /* discovered country code (sta mode) */
737 #define RTM_IEEE80211_RADIO 116 /* RF kill switch state change */
738
739 /*
740 * Structure prepended to raw packets sent through the bpf
741 * interface when set to DLT_IEEE802_11_RADIO. This allows
742 * user applications to specify pretty much everything in
743 * an Atheros tx descriptor. XXX need to generalize.
744 *
745 * XXX cannot be more than 14 bytes as it is copied to a sockaddr's
746 * XXX sa_data area.
747 */
748 struct ieee80211_bpf_params {
749 uint8_t ibp_vers; /* version */
750 #define IEEE80211_BPF_VERSION 0
751 uint8_t ibp_len; /* header length in bytes */
752 uint8_t ibp_flags;
753 #define IEEE80211_BPF_SHORTPRE 0x01 /* tx with short preamble */
754 #define IEEE80211_BPF_NOACK 0x02 /* tx with no ack */
755 #define IEEE80211_BPF_CRYPTO 0x04 /* tx with h/w encryption */
756 #define IEEE80211_BPF_FCS 0x10 /* frame incldues FCS */
757 #define IEEE80211_BPF_DATAPAD 0x20 /* frame includes data padding */
758 #define IEEE80211_BPF_RTS 0x40 /* tx with RTS/CTS */
759 #define IEEE80211_BPF_CTS 0x80 /* tx with CTS only */
760 uint8_t ibp_pri; /* WME/WMM AC+tx antenna */
761 uint8_t ibp_try0; /* series 1 try count */
762 uint8_t ibp_rate0; /* series 1 IEEE tx rate */
763 uint8_t ibp_power; /* tx power (device units) */
764 uint8_t ibp_ctsrate; /* IEEE tx rate for CTS */
765 uint8_t ibp_try1; /* series 2 try count */
766 uint8_t ibp_rate1; /* series 2 IEEE tx rate */
767 uint8_t ibp_try2; /* series 3 try count */
768 uint8_t ibp_rate2; /* series 3 IEEE tx rate */
769 uint8_t ibp_try3; /* series 4 try count */
770 uint8_t ibp_rate3; /* series 4 IEEE tx rate */
771 };
772
773 #ifdef _KERNEL
774 struct ieee80211_tx_params {
775 struct ieee80211_bpf_params params;
776 };
777 int ieee80211_add_xmit_params(struct mbuf *m,
778 const struct ieee80211_bpf_params *);
779 int ieee80211_get_xmit_params(struct mbuf *m,
780 struct ieee80211_bpf_params *);
781
782 struct ieee80211_rx_params;
783 struct ieee80211_rx_stats;
784
785 int ieee80211_add_rx_params(struct mbuf *m,
786 const struct ieee80211_rx_stats *rxs);
787 int ieee80211_get_rx_params(struct mbuf *m,
788 struct ieee80211_rx_stats *rxs);
789 const struct ieee80211_rx_stats * ieee80211_get_rx_params_ptr(struct mbuf *m);
790
791 struct ieee80211_toa_params {
792 int request_id;
793 };
794 int ieee80211_add_toa_params(struct mbuf *m,
795 const struct ieee80211_toa_params *p);
796 int ieee80211_get_toa_params(struct mbuf *m,
797 struct ieee80211_toa_params *p);
798
799 #define IEEE80211_F_SURVEY_TIME 0x00000001
800 #define IEEE80211_F_SURVEY_TIME_BUSY 0x00000002
801 #define IEEE80211_F_SURVEY_NOISE_DBM 0x00000004
802 #define IEEE80211_F_SURVEY_TSC 0x00000008
803 struct ieee80211_channel_survey {
804 uint32_t s_flags;
805 uint32_t s_time;
806 uint32_t s_time_busy;
807 int32_t s_noise;
808 uint64_t s_tsc;
809 };
810
811 #endif /* _KERNEL */
812
813 /*
814 * Malloc API. Other BSD operating systems have slightly
815 * different malloc/free namings (eg DragonflyBSD.)
816 */
817 #define IEEE80211_MALLOC malloc
818 #define IEEE80211_FREE free
819
820 /* XXX TODO: get rid of WAITOK, fix all the users of it? */
821 #define IEEE80211_M_NOWAIT M_NOWAIT
822 #define IEEE80211_M_WAITOK M_WAITOK
823 #define IEEE80211_M_ZERO M_ZERO
824
825 /* XXX TODO: the type fields */
826
827 /*
828 * Functions FreeBSD uses that NetBSD doesn't have ...
829 */
830
831 int if_printf(struct ifnet *ifp, const char *fmt, ...) __printflike(2, 3);
832 void m_align(struct mbuf *m, int len);
833 int m_append(struct mbuf *m0, int len, const void *cpv);
834 struct mbuf * m_unshare(struct mbuf *m0, int how);
835
836 static __inline void m_clrprotoflags(struct mbuf *m)
837 {
838 m->m_flags &= ~(M_LINK0|M_LINK1|M_LINK2|M_LINK3|M_LINK4|M_LINK5
839 |M_LINK6|M_LINK7|M_LINK8|M_LINK9|M_LINK10|M_LINK11);
840 }
841
842 /*-
843 * Macro for type conversion: convert mbuf pointer to data pointer of correct
844 * type:
845 *
846 * mtod(m, t) -- Convert mbuf pointer to data pointer of correct type.
847 * mtodo(m, o) -- Same as above but with offset 'o' into data.
848 */
849 #define mtod(m, t) ((t)((m)->m_data))
850 #define mtodo(m, o) ((void *)(((m)->m_data) + (o)))
851
852 /* Berkeley Packet Filter shim */
853
854 #define BPF_MTAP(_ifp,_m) do { \
855 bpf_mtap((_ifp), (_m), BPF_D_INOUT); \
856 } while (0)
857
858 /* Missing define in net/if_ether.h */
859
860 #define ETHER_IS_BROADCAST(addr) \
861 (((addr)[0] & (addr)[1] & (addr)[2] & \
862 (addr)[3] & (addr)[4] & (addr)[5]) == 0xff)
863
864 #endif /* _NET80211_IEEE80211_NETBSD_H_ */
865