ieee80211_freebsd.h revision 144618
1178354Ssam/*-
2178354Ssam * Copyright (c) 2003-2005 Sam Leffler, Errno Consulting
3178354Ssam * All rights reserved.
4178354Ssam *
5178354Ssam * Redistribution and use in source and binary forms, with or without
6178354Ssam * modification, are permitted provided that the following conditions
7178354Ssam * are met:
8178354Ssam * 1. Redistributions of source code must retain the above copyright
9178354Ssam *    notice, this list of conditions and the following disclaimer.
10178354Ssam * 2. Redistributions in binary form must reproduce the above copyright
11178354Ssam *    notice, this list of conditions and the following disclaimer in the
12178354Ssam *    documentation and/or other materials provided with the distribution.
13178354Ssam * 3. The name of the author may not be used to endorse or promote products
14178354Ssam *    derived from this software without specific prior written permission.
15178354Ssam *
16178354Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17178354Ssam * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18178354Ssam * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19178354Ssam * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20178354Ssam * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21178354Ssam * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22178354Ssam * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23178354Ssam * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24178354Ssam * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25178354Ssam * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26178354Ssam *
27178354Ssam * $FreeBSD: head/sys/net80211/ieee80211_freebsd.h 144618 2005-04-04 04:27:20Z sam $
28178354Ssam */
29178354Ssam#ifndef _NET80211_IEEE80211_FREEBSD_H_
30178354Ssam#define _NET80211_IEEE80211_FREEBSD_H_
31178354Ssam
32178354Ssam/*
33178354Ssam * Beacon locking definitions.
34178354Ssam */
35178354Ssamtypedef struct mtx ieee80211_beacon_lock_t;
36178354Ssam#define	IEEE80211_BEACON_LOCK_INIT(_ic, _name) \
37178354Ssam	mtx_init(&(_ic)->ic_beaconlock, _name, "802.11 beacon lock", MTX_DEF)
38178354Ssam#define	IEEE80211_BEACON_LOCK_DESTROY(_ic) mtx_destroy(&(_ic)->ic_beaconlock)
39178354Ssam#define	IEEE80211_BEACON_LOCK(_ic)	   mtx_lock(&(_ic)->ic_beaconlock)
40178354Ssam#define	IEEE80211_BEACON_UNLOCK(_ic)	   mtx_unlock(&(_ic)->ic_beaconlock)
41178354Ssam#define	IEEE80211_BEACON_LOCK_ASSERT(_ic) \
42178354Ssam	mtx_assert(&(_ic)->ic_beaconlock, MA_OWNED)
43178354Ssam
44178354Ssam/*
45178354Ssam * Node locking definitions.
46178354Ssam */
47178354Ssamtypedef struct mtx ieee80211_node_lock_t;
48178354Ssam#define	IEEE80211_NODE_LOCK_INIT(_nt, _name) \
49178354Ssam	mtx_init(&(_nt)->nt_nodelock, _name, "802.11 node table", MTX_DEF)
50178354Ssam#define	IEEE80211_NODE_LOCK_DESTROY(_nt)	mtx_destroy(&(_nt)->nt_nodelock)
51178354Ssam#define	IEEE80211_NODE_LOCK(_nt)		mtx_lock(&(_nt)->nt_nodelock)
52178354Ssam#define	IEEE80211_NODE_UNLOCK(_nt)		mtx_unlock(&(_nt)->nt_nodelock)
53178354Ssam#define	IEEE80211_NODE_LOCK_ASSERT(_nt) \
54178354Ssam	mtx_assert(&(_nt)->nt_nodelock, MA_OWNED)
55178354Ssam
56178354Ssam/*
57178354Ssam * Node table scangen locking definitions.
58178354Ssam */
59178354Ssamtypedef struct mtx ieee80211_scan_lock_t;
60178354Ssam#define	IEEE80211_SCAN_LOCK_INIT(_nt, _name) \
61178354Ssam	mtx_init(&(_nt)->nt_scanlock, _name, "802.11 scangen", MTX_DEF)
62178354Ssam#define	IEEE80211_SCAN_LOCK_DESTROY(_nt)	mtx_destroy(&(_nt)->nt_scanlock)
63178354Ssam#define	IEEE80211_SCAN_LOCK(_nt)		mtx_lock(&(_nt)->nt_scanlock)
64178354Ssam#define	IEEE80211_SCAN_UNLOCK(_nt)		mtx_unlock(&(_nt)->nt_scanlock)
65178354Ssam#define	IEEE80211_SCAN_LOCK_ASSERT(_nt) \
66178354Ssam	mtx_assert(&(_nt)->nt_scanlock, MA_OWNED)
67178354Ssam
68178354Ssam/*
69178354Ssam * Per-node power-save queue definitions.
70178354Ssam */
71178354Ssam#define	IEEE80211_NODE_SAVEQ_INIT(_ni, _name) do {		\
72178354Ssam	mtx_init(&(_ni)->ni_savedq.ifq_mtx, _name, "802.11 ps queue", MTX_DEF);\
73178354Ssam	(_ni)->ni_savedq.ifq_maxlen = IEEE80211_PS_MAX_QUEUE;	\
74178354Ssam} while (0)
75178354Ssam#define	IEEE80211_NODE_SAVEQ_DESTROY(_ni) \
76178354Ssam	mtx_destroy(&(_ni)->ni_savedq.ifq_mtx)
77178354Ssam#define	IEEE80211_NODE_SAVEQ_QLEN(_ni) \
78178354Ssam	_IF_QLEN(&(_ni)->ni_savedq)
79178354Ssam#define	IEEE80211_NODE_SAVEQ_LOCK(_ni) do {	\
80178354Ssam	IF_LOCK(&(_ni)->ni_savedq);				\
81178354Ssam} while (0)
82178354Ssam#define	IEEE80211_NODE_SAVEQ_UNLOCK(_ni) do {	\
83178354Ssam	IF_UNLOCK(&(_ni)->ni_savedq);				\
84178354Ssam} while (0)
85178354Ssam#define	IEEE80211_NODE_SAVEQ_DEQUEUE(_ni, _m, _qlen) do {	\
86178354Ssam	IEEE80211_NODE_SAVEQ_LOCK(_ni);				\
87178354Ssam	_IF_DEQUEUE(&(_ni)->ni_savedq, _m);			\
88178354Ssam	(_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni);		\
89178354Ssam	IEEE80211_NODE_SAVEQ_UNLOCK(_ni);			\
90178354Ssam} while (0)
91178354Ssam#define	IEEE80211_NODE_SAVEQ_DRAIN(_ni, _qlen) do {		\
92178354Ssam	IEEE80211_NODE_SAVEQ_LOCK(_ni);				\
93178354Ssam	(_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni);		\
94178354Ssam	_IF_DRAIN(&(_ni)->ni_savedq);				\
95178354Ssam	IEEE80211_NODE_SAVEQ_UNLOCK(_ni);			\
96178354Ssam} while (0)
97178354Ssam/* XXX could be optimized */
98178354Ssam#define	_IEEE80211_NODE_SAVEQ_DEQUEUE_HEAD(_ni, _m) do {	\
99178354Ssam	_IF_DEQUEUE(&(_ni)->ni_savedq, m);			\
100178354Ssam} while (0)
101178354Ssam#define	_IEEE80211_NODE_SAVEQ_ENQUEUE(_ni, _m, _qlen, _age) do {\
102178354Ssam	(_m)->m_nextpkt = NULL;					\
103178354Ssam	if ((_ni)->ni_savedq.ifq_tail != NULL) { 		\
104178354Ssam		_age -= M_AGE_GET((_ni)->ni_savedq.ifq_tail);	\
105178354Ssam		(_ni)->ni_savedq.ifq_tail->m_nextpkt = (_m);	\
106178354Ssam	} else { 						\
107178354Ssam		(_ni)->ni_savedq.ifq_head = (_m); 		\
108178354Ssam	}							\
109178354Ssam	M_AGE_SET(_m, _age);					\
110178354Ssam	(_ni)->ni_savedq.ifq_tail = (_m); 			\
111178354Ssam	(_qlen) = ++(_ni)->ni_savedq.ifq_len; 			\
112178354Ssam} while (0)
113178354Ssam
114178354Ssam/*
115178354Ssam * 802.1x MAC ACL database locking definitions.
116178354Ssam */
117178354Ssamtypedef struct mtx acl_lock_t;
118178354Ssam#define	ACL_LOCK_INIT(_as, _name) \
119178354Ssam	mtx_init(&(_as)->as_lock, _name, "802.11 ACL", MTX_DEF)
120178354Ssam#define	ACL_LOCK_DESTROY(_as)		mtx_destroy(&(_as)->as_lock)
121178354Ssam#define	ACL_LOCK(_as)			mtx_lock(&(_as)->as_lock)
122178354Ssam#define	ACL_UNLOCK(_as)			mtx_unlock(&(_as)->as_lock)
123178354Ssam#define	ACL_LOCK_ASSERT(_as) \
124178354Ssam	mtx_assert((&(_as)->as_lock), MA_OWNED)
125178354Ssam
126178354Ssam/*
127178354Ssam * Node reference counting definitions.
128178354Ssam *
129178354Ssam * ieee80211_node_initref	initialize the reference count to 1
130178354Ssam * ieee80211_node_incref	add a reference
131178354Ssam * ieee80211_node_decref	remove a reference
132178354Ssam * ieee80211_node_dectestref	remove a reference and return 1 if this
133178354Ssam *				is the last reference, otherwise 0
134178354Ssam * ieee80211_node_refcnt	reference count for printing (only)
135178354Ssam */
136178354Ssam#include <machine/atomic.h>
137178354Ssam
138178354Ssam#define ieee80211_node_initref(_ni) \
139178354Ssam	do { ((_ni)->ni_refcnt = 1); } while (0)
140178354Ssam#define ieee80211_node_incref(_ni) \
141178354Ssam	atomic_add_int(&(_ni)->ni_refcnt, 1)
142178354Ssam#define	ieee80211_node_decref(_ni) \
143178354Ssam	atomic_subtract_int(&(_ni)->ni_refcnt, 1)
144178354Ssamstruct ieee80211_node;
145178354Ssamint	ieee80211_node_dectestref(struct ieee80211_node *ni);
146178354Ssam#define	ieee80211_node_refcnt(_ni)	(_ni)->ni_refcnt
147178354Ssam
148178354Ssamstruct mbuf *ieee80211_getmgtframe(u_int8_t **frm, u_int pktlen);
149178354Ssam#define	M_LINK0		M_PROTO1		/* WEP requested */
150178354Ssam#define	M_PWR_SAV	M_PROTO4		/* bypass PS handling */
151178354Ssam/*
152178354Ssam * Encode WME access control bits in the PROTO flags.
153178354Ssam * This is safe since it's passed directly in to the
154178354Ssam * driver and there's no chance someone else will clobber
155178354Ssam * them on us.
156178354Ssam */
157178354Ssam#define	M_WME_AC_MASK	(M_PROTO2|M_PROTO3)
158178354Ssam/* XXX 5 is wrong if M_PROTO* are redefined */
159178354Ssam#define	M_WME_AC_SHIFT	5
160178354Ssam
161178354Ssam#define	M_WME_SETAC(m, ac) \
162178354Ssam	((m)->m_flags = ((m)->m_flags &~ M_WME_AC_MASK) | \
163178354Ssam		((ac) << M_WME_AC_SHIFT))
164178354Ssam#define	M_WME_GETAC(m)	(((m)->m_flags >> M_WME_AC_SHIFT) & 0x3)
165178354Ssam
166178354Ssam/*
167178354Ssam * Mbufs on the power save queue are tagged with an age and
168178354Ssam * timed out.  We reuse the hardware checksum field in the
169178354Ssam * mbuf packet header to store this data.
170178354Ssam */
171178354Ssam#define	M_AGE_SET(m,v)		(m->m_pkthdr.csum_data = v)
172178354Ssam#define	M_AGE_GET(m)		(m->m_pkthdr.csum_data)
173178354Ssam#define	M_AGE_SUB(m,adj)	(m->m_pkthdr.csum_data -= adj)
174178354Ssam
175178354Ssamvoid	get_random_bytes(void *, size_t);
176178354Ssam
177178354Ssamstruct ieee80211com;
178178354Ssam
179178354Ssamvoid	ieee80211_sysctl_attach(struct ieee80211com *);
180178354Ssamvoid	ieee80211_sysctl_detach(struct ieee80211com *);
181178354Ssam
182178354Ssamvoid	ieee80211_load_module(const char *);
183178354Ssam
184178354Ssam/* XXX this stuff belongs elsewhere */
185178354Ssam/*
186178354Ssam * Message formats for messages from the net80211 layer to user
187178354Ssam * applications via the routing socket.  These messages are appended
188178354Ssam * to an if_announcemsghdr structure.
189178354Ssam */
190178354Ssamstruct ieee80211_join_event {
191178354Ssam	uint8_t		iev_addr[6];
192178354Ssam};
193178354Ssam
194178354Ssamstruct ieee80211_leave_event {
195178354Ssam	uint8_t		iev_addr[6];
196178354Ssam};
197178354Ssam
198178354Ssamstruct ieee80211_replay_event {
199178354Ssam	uint8_t		iev_src[6];	/* src MAC */
200178354Ssam	uint8_t		iev_dst[6];	/* dst MAC */
201178354Ssam	uint8_t		iev_cipher;	/* cipher type */
202178354Ssam	uint8_t		iev_keyix;	/* key id/index */
203178354Ssam	uint64_t	iev_keyrsc;	/* RSC from key */
204178354Ssam	uint64_t	iev_rsc;	/* RSC from frame */
205178354Ssam};
206178354Ssam
207178354Ssamstruct ieee80211_michael_event {
208178354Ssam	uint8_t		iev_src[6];	/* src MAC */
209178354Ssam	uint8_t		iev_dst[6];	/* dst MAC */
210178354Ssam	uint8_t		iev_cipher;	/* cipher type */
211178354Ssam	uint8_t		iev_keyix;	/* key id/index */
212178354Ssam};
213178354Ssam
214178354Ssam#define	RTM_IEEE80211_ASSOC	100	/* station associate (bss mode) */
215178354Ssam#define	RTM_IEEE80211_REASSOC	101	/* station re-associate (bss mode) */
216178354Ssam#define	RTM_IEEE80211_DISASSOC	102	/* station disassociate (bss mode) */
217178354Ssam#define	RTM_IEEE80211_JOIN	103	/* station join (ap mode) */
218178354Ssam#define	RTM_IEEE80211_LEAVE	104	/* station leave (ap mode) */
219178354Ssam#define	RTM_IEEE80211_SCAN	105	/* scan complete, results available */
220178354Ssam#define	RTM_IEEE80211_REPLAY	106	/* sequence counter replay detected */
221178354Ssam#define	RTM_IEEE80211_MICHAEL	107	/* Michael MIC failure detected */
222178354Ssam#define	RTM_IEEE80211_REJOIN	108	/* station re-associate (ap mode) */
223178354Ssam
224178354Ssam#endif /* _NET80211_IEEE80211_FREEBSD_H_ */
225178354Ssam