Home | History | Annotate | Line # | Download | only in net80211
ieee80211_netbsd.h revision 1.6
      1 /* $NetBSD: ieee80211_netbsd.h,v 1.6 2005/08/18 06:07:30 skrll Exp $ */
      2 /*-
      3  * Copyright (c) 2003-2005 Sam Leffler, Errno Consulting
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. The name of the author may not be used to endorse or promote products
     15  *    derived from this software without specific prior written permission.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  *
     28  * $FreeBSD: src/sys/net80211/ieee80211_freebsd.h,v 1.5 2005/07/06 01:55:17 sam Exp $
     29  */
     30 #ifndef _NET80211_IEEE80211_NETBSD_H_
     31 #define _NET80211_IEEE80211_NETBSD_H_
     32 
     33 #define	IASSERT(__cond, __complaint)	 	\
     34 	do {				 	\
     35 		if (!(__cond))		 	\
     36 			panic __complaint ;	\
     37 	} while (0)
     38 
     39 void if_printf(struct ifnet *, const char *, ...)
     40     __attribute__((__format__(__printf__,2,3)));
     41 
     42 struct ieee80211_lock {
     43 	int count;
     44 	int ipl;
     45 };
     46 #define	IEEE80211_LOCK_INIT_IMPL(_ic, _name, _member)	\
     47 	do {						\
     48 		(_ic)->_member.count = 0;		\
     49 	} while (0)
     50 #define	IEEE80211_LOCK_IMPL(_ic, _member)		\
     51 	do {						\
     52 		int __s = splnet();			\
     53 		if ((_ic)->_member.count++ == 0)	\
     54 			(_ic)->_member.ipl = __s;	\
     55 	} while (0)
     56 #define	IEEE80211_UNLOCK_IMPL(_ic, _member)		\
     57 	do {						\
     58 		if (--(_ic)->_member.count == 0)	\
     59 			splx((_ic)->_member.ipl);	\
     60 	} while (0)
     61 #define	IEEE80211_LOCK_ASSERT_IMPL(_ic, _member)	\
     62 	IASSERT((_ic)->_member.count > 0,		\
     63 	    ("%s: IEEE80211_LOCK not held", __func__));
     64 
     65 /*
     66  * Beacon locking definitions.
     67  */
     68 typedef struct ieee80211_lock ieee80211_beacon_lock_t;
     69 #define	IEEE80211_BEACON_LOCK_INIT(_ic, _name)		\
     70 	IEEE80211_LOCK_INIT_IMPL(_ic, _name, ic_beaconlock)
     71 #define	IEEE80211_BEACON_LOCK_DESTROY(_ic)
     72 #define	IEEE80211_BEACON_LOCK(_ic)			\
     73 	IEEE80211_LOCK_IMPL(_ic, ic_beaconlock)
     74 #define	IEEE80211_BEACON_UNLOCK(_ic)			\
     75 	IEEE80211_UNLOCK_IMPL(_ic, ic_beaconlock)
     76 #define	IEEE80211_BEACON_LOCK_ASSERT(_ic)		\
     77 	IEEE80211_LOCK_ASSERT_IMPL(_ic, ic_beaconlock)
     78 
     79 /*
     80  * Node locking definitions.
     81  */
     82 typedef struct ieee80211_lock ieee80211_node_lock_t;
     83 #define	IEEE80211_NODE_LOCK_INIT(_nt, _name)		\
     84 	IEEE80211_LOCK_INIT_IMPL(_nt, _name, nt_nodelock)
     85 #define	IEEE80211_NODE_LOCK_DESTROY(_nt)
     86 #define	IEEE80211_NODE_LOCK(_nt)			\
     87 	IEEE80211_LOCK_IMPL(_nt, nt_nodelock)
     88 #define	IEEE80211_NODE_UNLOCK(_nt)			\
     89 	IEEE80211_UNLOCK_IMPL(_nt, nt_nodelock)
     90 #define	IEEE80211_NODE_LOCK_ASSERT(_nt)			\
     91 	IEEE80211_LOCK_ASSERT_IMPL(_nt, nt_nodelock)
     92 
     93 /*
     94  * Node table scangen locking definitions.
     95  */
     96 typedef struct ieee80211_lock ieee80211_scan_lock_t;
     97 #define	IEEE80211_SCAN_LOCK_INIT(_nt, _name)		\
     98 	IEEE80211_LOCK_INIT_IMPL(_nt, _name, nt_scanlock)
     99 #define	IEEE80211_SCAN_LOCK_DESTROY(_nt)
    100 #define	IEEE80211_SCAN_LOCK(_nt)			\
    101 	IEEE80211_LOCK_IMPL(_nt, nt_scanlock)
    102 #define	IEEE80211_SCAN_UNLOCK(_nt)			\
    103 	IEEE80211_UNLOCK_IMPL(_nt, nt_scanlock)
    104 #define	IEEE80211_SCAN_LOCK_ASSERT(_nt)			\
    105 	IEEE80211_LOCK_ASSERT_IMPL(_nt, nt_scanlock)
    106 
    107 /*
    108  * Per-node power-save queue definitions.
    109  */
    110 #define	IEEE80211_NODE_SAVEQ_INIT(_ni, _name) do {		\
    111 	(_ni)->ni_savedq.ifq_maxlen = IEEE80211_PS_MAX_QUEUE;	\
    112 } while (0)
    113 #define	IEEE80211_NODE_SAVEQ_DESTROY(_ni)
    114 #define	IEEE80211_NODE_SAVEQ_QLEN(_ni)	((_ni)->ni_savedq.ifq_len)
    115 #define	IEEE80211_NODE_SAVEQ_LOCK(_ni)
    116 #define	IEEE80211_NODE_SAVEQ_UNLOCK(_ni)
    117 #define	IEEE80211_NODE_SAVEQ_DEQUEUE(_ni, _m, _qlen) do {	\
    118 	IEEE80211_NODE_SAVEQ_LOCK(_ni);				\
    119 	IF_DEQUEUE(&(_ni)->ni_savedq, _m);			\
    120 	(_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni);		\
    121 	IEEE80211_NODE_SAVEQ_UNLOCK(_ni);			\
    122 } while (0)
    123 #define	IEEE80211_NODE_SAVEQ_DRAIN(_ni, _qlen) do {		\
    124 	IEEE80211_NODE_SAVEQ_LOCK(_ni);				\
    125 	(_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni);		\
    126 	IF_PURGE(&(_ni)->ni_savedq);				\
    127 	IEEE80211_NODE_SAVEQ_UNLOCK(_ni);			\
    128 } while (0)
    129 /* XXX could be optimized */
    130 #define	_IEEE80211_NODE_SAVEQ_DEQUEUE_HEAD(_ni, _m) do {	\
    131 	IF_DEQUEUE(&(_ni)->ni_savedq, m);			\
    132 } while (0)
    133 #define	_IEEE80211_NODE_SAVEQ_ENQUEUE(_ni, _m, _qlen, _age) do {\
    134 	(_m)->m_nextpkt = NULL;					\
    135 	if ((_ni)->ni_savedq.ifq_tail != NULL) { 		\
    136 		_age -= M_AGE_GET((_ni)->ni_savedq.ifq_tail);	\
    137 		(_ni)->ni_savedq.ifq_tail->m_nextpkt = (_m);	\
    138 	} else { 						\
    139 		(_ni)->ni_savedq.ifq_head = (_m); 		\
    140 	}							\
    141 	M_AGE_SET(_m, _age);					\
    142 	(_ni)->ni_savedq.ifq_tail = (_m); 			\
    143 	(_qlen) = ++(_ni)->ni_savedq.ifq_len; 			\
    144 } while (0)
    145 
    146 /*
    147  * 802.1x MAC ACL database locking definitions.
    148  */
    149 typedef struct ieee80211_lock acl_lock_t;
    150 #define	ACL_LOCK_INIT(_as, _name)	\
    151 	IEEE80211_LOCK_INIT_IMPL(_as, _name, as_lock)
    152 #define	ACL_LOCK_DESTROY(_as)
    153 #define	ACL_LOCK(_as)			IEEE80211_LOCK_IMPL(_as, as_lock)
    154 #define	ACL_UNLOCK(_as)			IEEE80211_UNLOCK_IMPL(_as, as_lock)
    155 #define	ACL_LOCK_ASSERT(_as)		IEEE80211_LOCK_ASSERT_IMPL(_as, as_lock)
    156 
    157 /*
    158  * Node reference counting definitions.
    159  *
    160  * ieee80211_node_initref	initialize the reference count to 1
    161  * ieee80211_node_incref	add a reference
    162  * ieee80211_node_decref	remove a reference
    163  * ieee80211_node_dectestref	remove a reference and return 1 if this
    164  *				is the last reference, otherwise 0
    165  * ieee80211_node_refcnt	reference count for printing (only)
    166  */
    167 
    168 #define ieee80211_node_initref(_ni) \
    169 	do { ((_ni)->ni_refcnt = 1); } while (0)
    170 #define ieee80211_node_incref(_ni) \
    171 	do { (_ni)->ni_refcnt++; } while (0)
    172 #define	ieee80211_node_decref(_ni) \
    173 	do { (_ni)->ni_refcnt--; } while (0)
    174 struct ieee80211_node;
    175 int ieee80211_node_dectestref(struct ieee80211_node *ni);
    176 #define	ieee80211_node_refcnt(_ni)	(_ni)->ni_refcnt
    177 
    178 struct mbuf *ieee80211_getmgtframe(u_int8_t **frm, u_int pktlen);
    179 #define	M_PWR_SAV	M_PROTO1		/* bypass PS handling */
    180 #define	M_MORE_DATA	M_LINK3			/* more data frames to follow */
    181 /*
    182  * Encode WME access control bits in the PROTO flags.
    183  * This is safe since it's passed directly in to the
    184  * driver and there's no chance someone else will clobber
    185  * them on us.
    186  */
    187 #define	M_WME_AC_MASK	(M_LINK1|M_LINK2)
    188 /* XXX 5 is wrong if M_LINK* are redefined */
    189 #define	M_WME_AC_SHIFT	13
    190 
    191 #define	M_WME_SETAC(m, ac) \
    192 	((m)->m_flags = ((m)->m_flags &~ M_WME_AC_MASK) | \
    193 		((ac) << M_WME_AC_SHIFT))
    194 #define	M_WME_GETAC(m)	(((m)->m_flags >> M_WME_AC_SHIFT) & 0x3)
    195 
    196 /*
    197  * Mbufs on the power save queue are tagged with an age and
    198  * timed out.  We reuse the hardware checksum field in the
    199  * mbuf packet header to store this data.
    200  */
    201 #define	M_AGE_SET(m,v)		(m->m_pkthdr.csum_data = v)
    202 #define	M_AGE_GET(m)		(m->m_pkthdr.csum_data)
    203 #define	M_AGE_SUB(m,adj)	(m->m_pkthdr.csum_data -= adj)
    204 
    205 struct ieee80211com;
    206 
    207 /* XXX this stuff belongs elsewhere */
    208 /*
    209  * Message formats for messages from the net80211 layer to user
    210  * applications via the routing socket.  These messages are appended
    211  * to an if_announcemsghdr structure.
    212  */
    213 struct ieee80211_join_event {
    214 	uint8_t		iev_addr[6];
    215 };
    216 
    217 struct ieee80211_leave_event {
    218 	uint8_t		iev_addr[6];
    219 };
    220 
    221 struct ieee80211_replay_event {
    222 	uint8_t		iev_src[6];	/* src MAC */
    223 	uint8_t		iev_dst[6];	/* dst MAC */
    224 	uint8_t		iev_cipher;	/* cipher type */
    225 	uint8_t		iev_keyix;	/* key id/index */
    226 	uint64_t	iev_keyrsc;	/* RSC from key */
    227 	uint64_t	iev_rsc;	/* RSC from frame */
    228 };
    229 
    230 struct ieee80211_michael_event {
    231 	uint8_t		iev_src[6];	/* src MAC */
    232 	uint8_t		iev_dst[6];	/* dst MAC */
    233 	uint8_t		iev_cipher;	/* cipher type */
    234 	uint8_t		iev_keyix;	/* key id/index */
    235 };
    236 
    237 #define	RTM_IEEE80211_ASSOC	100	/* station associate (bss mode) */
    238 #define	RTM_IEEE80211_REASSOC	101	/* station re-associate (bss mode) */
    239 #define	RTM_IEEE80211_DISASSOC	102	/* station disassociate (bss mode) */
    240 #define	RTM_IEEE80211_JOIN	103	/* station join (ap mode) */
    241 #define	RTM_IEEE80211_LEAVE	104	/* station leave (ap mode) */
    242 #define	RTM_IEEE80211_SCAN	105	/* scan complete, results available */
    243 #define	RTM_IEEE80211_REPLAY	106	/* sequence counter replay detected */
    244 #define	RTM_IEEE80211_MICHAEL	107	/* Michael MIC failure detected */
    245 #define	RTM_IEEE80211_REJOIN	108	/* station re-associate (ap mode) */
    246 
    247 #define	__offsetof	offsetof
    248 #define	ticks	hardclock_ticks
    249 #define	ovbcopy(__src, __dst, __n)	((void)memmove(__dst, __src, __n))
    250 
    251 #define TAILQ_FOREACH_SAFE(var, head, field, nextvar)			\
    252 	for (var = TAILQ_FIRST(head);					\
    253 	     var != NULL && (nextvar = TAILQ_NEXT(var, field), 1);	\
    254 	     var = nextvar)
    255 
    256 void	if_printf(struct ifnet *, const char *, ...);
    257 struct mbuf *m_getcl(int, int, int);
    258 int	m_append(struct mbuf *, int, const caddr_t);
    259 void	get_random_bytes(void *, size_t);
    260 
    261 void	ieee80211_sysctl_attach(struct ieee80211com *);
    262 void	ieee80211_sysctl_detach(struct ieee80211com *);
    263 void	ieee80211_load_module(const char *);
    264 
    265 #endif /* _NET80211_IEEE80211_NETBSD_H_ */
    266