ieee80211_netbsd.h revision 1.21.2.3 1 /* $NetBSD: ieee80211_netbsd.h,v 1.21.2.3 2018/07/12 16:35:34 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 __caddr_t
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 void ieee80211_load_module(const char *);
486
487 #ifdef notyet
488
489 /*
490 * A "policy module" is an adjunct module to net80211 that provides
491 * functionality that typically includes policy decisions. This
492 * modularity enables extensibility and vendor-supplied functionality.
493 */
494 #define _IEEE80211_POLICY_MODULE(policy, name, version) \
495 typedef void (*policy##_setup)(int); \
496 SET_DECLARE(policy##_set, policy##_setup); \
497 static int \
498 wlan_##name##_modevent(module_t mod, int type, void *unused) \
499 { \
500 policy##_setup * const *iter, f; \
501 switch (type) { \
502 case MOD_LOAD: \
503 SET_FOREACH(iter, policy##_set) { \
504 f = (void*) *iter; \
505 f(type); \
506 } \
507 return 0; \
508 case MOD_UNLOAD: \
509 case MOD_QUIESCE: \
510 if (nrefs) { \
511 printf("wlan_" #name ": still in use " \
512 "(%u dynamic refs)\n", nrefs); \
513 return EBUSY; \
514 } \
515 if (type == MOD_UNLOAD) { \
516 SET_FOREACH(iter, policy##_set) { \
517 f = (void*) *iter; \
518 f(type); \
519 } \
520 } \
521 return 0; \
522 } \
523 return EINVAL; \
524 } \
525 static moduledata_t name##_mod = { \
526 "wlan_" #name, \
527 wlan_##name##_modevent, \
528 0 \
529 }; \
530 DECLARE_MODULE(wlan_##name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);\
531 MODULE_VERSION(wlan_##name, version); \
532 MODULE_DEPEND(wlan_##name, wlan, 1, 1, 1)
533
534 /*
535 * Crypto modules implement cipher support.
536 */
537 #define IEEE80211_CRYPTO_MODULE(name, version) \
538 _IEEE80211_POLICY_MODULE(crypto, name, version); \
539 static void \
540 name##_modevent(int type) \
541 { \
542 if (type == MOD_LOAD) \
543 ieee80211_crypto_register(&name); \
544 else \
545 ieee80211_crypto_unregister(&name); \
546 } \
547 TEXT_SET(crypto##_set, name##_modevent)
548
549 /*
550 * Scanner modules provide scanning policy.
551 */
552 #define IEEE80211_SCANNER_MODULE(name, version) \
553 _IEEE80211_POLICY_MODULE(scanner, name, version)
554
555 #define IEEE80211_SCANNER_ALG(name, alg, v) \
556 static void \
557 name##_modevent(int type) \
558 { \
559 if (type == MOD_LOAD) \
560 ieee80211_scanner_register(alg, &v); \
561 else \
562 ieee80211_scanner_unregister(alg, &v); \
563 } \
564 TEXT_SET(scanner_set, name##_modevent); \
565
566 /*
567 * ACL modules implement acl policy.
568 */
569 #define IEEE80211_ACL_MODULE(name, alg, version) \
570 _IEEE80211_POLICY_MODULE(acl, name, version); \
571 static void \
572 alg##_modevent(int type) \
573 { \
574 if (type == MOD_LOAD) \
575 ieee80211_aclator_register(&alg); \
576 else \
577 ieee80211_aclator_unregister(&alg); \
578 } \
579 TEXT_SET(acl_set, alg##_modevent); \
580
581 /*
582 * Authenticator modules handle 802.1x/WPA authentication.
583 */
584 #define IEEE80211_AUTH_MODULE(name, version) \
585 _IEEE80211_POLICY_MODULE(auth, name, version)
586
587 #define IEEE80211_AUTH_ALG(name, alg, v) \
588 static void \
589 name##_modevent(int type) \
590 { \
591 if (type == MOD_LOAD) \
592 ieee80211_authenticator_register(alg, &v); \
593 else \
594 ieee80211_authenticator_unregister(alg); \
595 } \
596 TEXT_SET(auth_set, name##_modevent)
597
598 /*
599 * Rate control modules provide tx rate control support.
600 */
601 #define IEEE80211_RATECTL_MODULE(alg, version) \
602 _IEEE80211_POLICY_MODULE(ratectl, alg, version); \
603
604 #define IEEE80211_RATECTL_ALG(name, alg, v) \
605 static void \
606 alg##_modevent(int type) \
607 { \
608 if (type == MOD_LOAD) \
609 ieee80211_ratectl_register(alg, &v); \
610 else \
611 ieee80211_ratectl_unregister(alg); \
612 } \
613 TEXT_SET(ratectl##_set, alg##_modevent)
614
615 #else
616 /* NNN This looks like module load/unload support ... notyet supported */
617 #define _IEEE80211_POLICY_MODULE(policy, name, version) /* unsupported */
618 #define IEEE80211_CRYPTO_MODULE(name, version) /* unsupported */
619 #define IEEE80211_SCANNER_MODULE(name, version) /* unsupported */
620 #define IEEE80211_SCANNER_ALG(name, alg, v) /* unsupported */
621 #define IEEE80211_ACL_MODULE(name, alg, version) const void *const temp = &alg
622 #define IEEE80211_AUTH_MODULE(name, version) /* unsupported */
623 #define IEEE80211_AUTH_ALG(name, alg, v) /* unsupported */
624 #define IEEE80211_RATECTL_MODULE(alg, version) /* unsupported */
625 #define IEEE80211_RATECTL_ALG(name, alg, v) /* unsupported */
626 #endif
627
628 /*
629 * IOCTL support
630 */
631
632 struct ieee80211req;
633
634 typedef int ieee80211_ioctl_getfunc(struct ieee80211vap *, struct ieee80211req *);
635 #if notyet
636 SET_DECLARE(ieee80211_ioctl_getset, ieee80211_ioctl_getfunc);
637 #endif
638 #define IEEE80211_IOCTL_GET(_name, _get) TEXT_SET(ieee80211_ioctl_getset, _get)
639
640 typedef int ieee80211_ioctl_setfunc(struct ieee80211vap *, struct ieee80211req *);
641 #if notyet
642 SET_DECLARE(ieee80211_ioctl_setset, ieee80211_ioctl_setfunc);
643 #endif
644 #define IEEE80211_IOCTL_SET(_name, _set) TEXT_SET(ieee80211_ioctl_setset, _set)
645
646 #endif /* _KERNEL */
647
648 /* XXX this stuff belongs elsewhere */
649 /*
650 * Message formats for messages from the net80211 layer to user
651 * applications via the routing socket. These messages are appended
652 * to an if_announcemsghdr structure.
653 */
654 struct ieee80211_join_event {
655 uint8_t iev_addr[6];
656 };
657
658 struct ieee80211_leave_event {
659 uint8_t iev_addr[6];
660 };
661
662 struct ieee80211_replay_event {
663 uint8_t iev_src[6]; /* src MAC */
664 uint8_t iev_dst[6]; /* dst MAC */
665 uint8_t iev_cipher; /* cipher type */
666 uint8_t iev_keyix; /* key id/index */
667 uint64_t iev_keyrsc; /* RSC from key */
668 uint64_t iev_rsc; /* RSC from frame */
669 };
670
671 struct ieee80211_michael_event {
672 uint8_t iev_src[6]; /* src MAC */
673 uint8_t iev_dst[6]; /* dst MAC */
674 uint8_t iev_cipher; /* cipher type */
675 uint8_t iev_keyix; /* key id/index */
676 };
677
678 struct ieee80211_wds_event {
679 uint8_t iev_addr[6];
680 };
681
682 struct ieee80211_csa_event {
683 uint32_t iev_flags; /* channel flags */
684 uint16_t iev_freq; /* setting in Mhz */
685 uint8_t iev_ieee; /* IEEE channel number */
686 uint8_t iev_mode; /* CSA mode */
687 uint8_t iev_count; /* CSA count */
688 };
689
690 struct ieee80211_cac_event {
691 uint32_t iev_flags; /* channel flags */
692 uint16_t iev_freq; /* setting in Mhz */
693 uint8_t iev_ieee; /* IEEE channel number */
694 /* XXX timestamp? */
695 uint8_t iev_type; /* IEEE80211_NOTIFY_CAC_* */
696 };
697
698 struct ieee80211_radar_event {
699 uint32_t iev_flags; /* channel flags */
700 uint16_t iev_freq; /* setting in Mhz */
701 uint8_t iev_ieee; /* IEEE channel number */
702 /* XXX timestamp? */
703 };
704
705 struct ieee80211_auth_event {
706 uint8_t iev_addr[6];
707 };
708
709 struct ieee80211_deauth_event {
710 uint8_t iev_addr[6];
711 };
712
713 struct ieee80211_country_event {
714 uint8_t iev_addr[6];
715 uint8_t iev_cc[2]; /* ISO country code */
716 };
717
718 struct ieee80211_radio_event {
719 uint8_t iev_state; /* 1 on, 0 off */
720 };
721
722 #define RTM_IEEE80211_ASSOC 100 /* station associate (bss mode) */
723 #define RTM_IEEE80211_REASSOC 101 /* station re-associate (bss mode) */
724 #define RTM_IEEE80211_DISASSOC 102 /* station disassociate (bss mode) */
725 #define RTM_IEEE80211_JOIN 103 /* station join (ap mode) */
726 #define RTM_IEEE80211_LEAVE 104 /* station leave (ap mode) */
727 #define RTM_IEEE80211_SCAN 105 /* scan complete, results available */
728 #define RTM_IEEE80211_REPLAY 106 /* sequence counter replay detected */
729 #define RTM_IEEE80211_MICHAEL 107 /* Michael MIC failure detected */
730 #define RTM_IEEE80211_REJOIN 108 /* station re-associate (ap mode) */
731 #define RTM_IEEE80211_WDS 109 /* WDS discovery (ap mode) */
732 #define RTM_IEEE80211_CSA 110 /* Channel Switch Announcement event */
733 #define RTM_IEEE80211_RADAR 111 /* radar event */
734 #define RTM_IEEE80211_CAC 112 /* Channel Availability Check event */
735 #define RTM_IEEE80211_DEAUTH 113 /* station deauthenticate */
736 #define RTM_IEEE80211_AUTH 114 /* station authenticate (ap mode) */
737 #define RTM_IEEE80211_COUNTRY 115 /* discovered country code (sta mode) */
738 #define RTM_IEEE80211_RADIO 116 /* RF kill switch state change */
739
740 /*
741 * Structure prepended to raw packets sent through the bpf
742 * interface when set to DLT_IEEE802_11_RADIO. This allows
743 * user applications to specify pretty much everything in
744 * an Atheros tx descriptor. XXX need to generalize.
745 *
746 * XXX cannot be more than 14 bytes as it is copied to a sockaddr's
747 * XXX sa_data area.
748 */
749 struct ieee80211_bpf_params {
750 uint8_t ibp_vers; /* version */
751 #define IEEE80211_BPF_VERSION 0
752 uint8_t ibp_len; /* header length in bytes */
753 uint8_t ibp_flags;
754 #define IEEE80211_BPF_SHORTPRE 0x01 /* tx with short preamble */
755 #define IEEE80211_BPF_NOACK 0x02 /* tx with no ack */
756 #define IEEE80211_BPF_CRYPTO 0x04 /* tx with h/w encryption */
757 #define IEEE80211_BPF_FCS 0x10 /* frame incldues FCS */
758 #define IEEE80211_BPF_DATAPAD 0x20 /* frame includes data padding */
759 #define IEEE80211_BPF_RTS 0x40 /* tx with RTS/CTS */
760 #define IEEE80211_BPF_CTS 0x80 /* tx with CTS only */
761 uint8_t ibp_pri; /* WME/WMM AC+tx antenna */
762 uint8_t ibp_try0; /* series 1 try count */
763 uint8_t ibp_rate0; /* series 1 IEEE tx rate */
764 uint8_t ibp_power; /* tx power (device units) */
765 uint8_t ibp_ctsrate; /* IEEE tx rate for CTS */
766 uint8_t ibp_try1; /* series 2 try count */
767 uint8_t ibp_rate1; /* series 2 IEEE tx rate */
768 uint8_t ibp_try2; /* series 3 try count */
769 uint8_t ibp_rate2; /* series 3 IEEE tx rate */
770 uint8_t ibp_try3; /* series 4 try count */
771 uint8_t ibp_rate3; /* series 4 IEEE tx rate */
772 };
773
774 #ifdef _KERNEL
775 struct ieee80211_tx_params {
776 struct ieee80211_bpf_params params;
777 };
778 int ieee80211_add_xmit_params(struct mbuf *m,
779 const struct ieee80211_bpf_params *);
780 int ieee80211_get_xmit_params(struct mbuf *m,
781 struct ieee80211_bpf_params *);
782
783 struct ieee80211_rx_params;
784 struct ieee80211_rx_stats;
785
786 int ieee80211_add_rx_params(struct mbuf *m,
787 const struct ieee80211_rx_stats *rxs);
788 int ieee80211_get_rx_params(struct mbuf *m,
789 struct ieee80211_rx_stats *rxs);
790 const struct ieee80211_rx_stats * ieee80211_get_rx_params_ptr(struct mbuf *m);
791
792 struct ieee80211_toa_params {
793 int request_id;
794 };
795 int ieee80211_add_toa_params(struct mbuf *m,
796 const struct ieee80211_toa_params *p);
797 int ieee80211_get_toa_params(struct mbuf *m,
798 struct ieee80211_toa_params *p);
799
800 #define IEEE80211_F_SURVEY_TIME 0x00000001
801 #define IEEE80211_F_SURVEY_TIME_BUSY 0x00000002
802 #define IEEE80211_F_SURVEY_NOISE_DBM 0x00000004
803 #define IEEE80211_F_SURVEY_TSC 0x00000008
804 struct ieee80211_channel_survey {
805 uint32_t s_flags;
806 uint32_t s_time;
807 uint32_t s_time_busy;
808 int32_t s_noise;
809 uint64_t s_tsc;
810 };
811
812 #endif /* _KERNEL */
813
814 /*
815 * Malloc API. Other BSD operating systems have slightly
816 * different malloc/free namings (eg DragonflyBSD.)
817 */
818 #define IEEE80211_MALLOC malloc
819 #define IEEE80211_FREE free
820
821 /* XXX TODO: get rid of WAITOK, fix all the users of it? */
822 #define IEEE80211_M_NOWAIT M_NOWAIT
823 #define IEEE80211_M_WAITOK M_WAITOK
824 #define IEEE80211_M_ZERO M_ZERO
825
826 /* XXX TODO: the type fields */
827
828 /*
829 * Functions FreeBSD uses that NetBSD doesn't have ...
830 */
831
832 int if_printf(struct ifnet *ifp, const char *fmt, ...) __printflike(2, 3);
833 void m_align(struct mbuf *m, int len);
834 int m_append(struct mbuf *m0, int len, const void *cpv);
835 struct mbuf * m_unshare(struct mbuf *m0, int how);
836
837 static __inline void m_clrprotoflags(struct mbuf *m)
838 {
839 m->m_flags &= ~(M_LINK0|M_LINK1|M_LINK2|M_LINK3|M_LINK4|M_LINK5
840 |M_LINK6|M_LINK7|M_LINK8|M_LINK9|M_LINK10|M_LINK11);
841 }
842
843 /*-
844 * Macro for type conversion: convert mbuf pointer to data pointer of correct
845 * type:
846 *
847 * mtod(m, t) -- Convert mbuf pointer to data pointer of correct type.
848 * mtodo(m, o) -- Same as above but with offset 'o' into data.
849 */
850 #define mtod(m, t) ((t)((m)->m_data))
851 #define mtodo(m, o) ((void *)(((m)->m_data) + (o)))
852
853 /* Berkeley Packet Filter shim */
854
855 #define BPF_MTAP(_ifp,_m) do { \
856 bpf_mtap((_ifp), (_m), BPF_D_INOUT); \
857 } while (0)
858
859 /* Missing define in net/if_ether.h */
860
861 #define ETHER_IS_BROADCAST(addr) \
862 (((addr)[0] & (addr)[1] & (addr)[2] & \
863 (addr)[3] & (addr)[4] & (addr)[5]) == 0xff)
864
865 #endif /* _NET80211_IEEE80211_NETBSD_H_ */
866