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