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