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