Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / net80211 / ieee80211_netbsd.h
blob36ccce8ecb684dc2fd09b750bc040cd7427ea974
1 /* $NetBSD: ieee80211_netbsd.h,v 1.14 2008/02/13 16:04:03 skrll Exp $ */
2 /*-
3 * Copyright (c) 2003-2005 Sam Leffler, Errno Consulting
4 * All rights reserved.
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.
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.
28 * $FreeBSD: src/sys/net80211/ieee80211_freebsd.h,v 1.6 2005/08/08 18:46:36 sam Exp $
30 #ifndef _NET80211_IEEE80211_NETBSD_H_
31 #define _NET80211_IEEE80211_NETBSD_H_
33 #ifdef _KERNEL
34 #define IASSERT(__cond, __complaint) \
35 do { \
36 if (!(__cond)) \
37 panic __complaint ; \
38 } while (/*CONSTCOND*/0)
40 void if_printf(struct ifnet *, const char *, ...)
41 __attribute__((__format__(__printf__,2,3)));
43 #define IEEE80211_LOCK_INIT_IMPL(_ic, _name, _member) \
44 mutex_init(&(_ic)->_member, MUTEX_DEFAULT, IPL_NET)
45 #define IEEE80211_LOCK_IMPL(_ic, _member) \
46 mutex_enter(&(_ic)->_member)
47 #define IEEE80211_IS_LOCKED_IMPL(_ic, _member) \
48 mutex_owned(&(_ic)->_member)
49 #define IEEE80211_UNLOCK_IMPL(_ic, _member) \
50 mutex_exit(&(_ic)->_member)
51 #define IEEE80211_LOCK_ASSERT_IMPL(_ic, _member) \
52 IASSERT(mutex_owned(&(_ic)->_member), \
53 ("%s: IEEE80211_LOCK not held", __func__))
54 #define IEEE80211_LOCK_DESTROY_IMPL(_ic, _member) \
55 mutex_destroy(&(_ic)->_member)
58 * Beacon locking definitions.
60 typedef kmutex_t ieee80211_beacon_lock_t;
61 #define IEEE80211_BEACON_LOCK_INIT(_ic, _name) \
62 IEEE80211_LOCK_INIT_IMPL(_ic, _name, ic_beaconlock)
63 #define IEEE80211_BEACON_LOCK_DESTROY(_ic) \
64 IEEE80211_LOCK_DESTROY_IMPL(_ic, ic_beaconlock)
65 #define IEEE80211_BEACON_LOCK(_ic) \
66 IEEE80211_LOCK_IMPL(_ic, ic_beaconlock)
67 #define IEEE80211_BEACON_UNLOCK(_ic) \
68 IEEE80211_UNLOCK_IMPL(_ic, ic_beaconlock)
69 #define IEEE80211_BEACON_LOCK_ASSERT(_ic) \
70 IEEE80211_LOCK_ASSERT_IMPL(_ic, ic_beaconlock)
73 * Node locking definitions.
74 * NB: MTX_DUPOK is because we don't generate per-interface strings.
76 typedef kmutex_t ieee80211_node_lock_t;
77 #define IEEE80211_NODE_LOCK_INIT(_nt, _name) \
78 IEEE80211_LOCK_INIT_IMPL(_nt, _name, nt_nodelock)
79 #define IEEE80211_NODE_LOCK_DESTROY(_nt) \
80 IEEE80211_LOCK_DESTROY_IMPL(_nt, nt_nodelock)
81 #define IEEE80211_NODE_LOCK(_nt) \
82 IEEE80211_LOCK_IMPL(_nt, nt_nodelock)
83 #define IEEE80211_NODE_IS_LOCKED(_nt) \
84 IEEE80211_IS_LOCKED_IMPL(_nt, nt_nodelock)
85 #define IEEE80211_NODE_UNLOCK(_nt) \
86 IEEE80211_UNLOCK_IMPL(_nt, nt_nodelock)
87 #define IEEE80211_NODE_LOCK_ASSERT(_nt) \
88 IEEE80211_LOCK_ASSERT_IMPL(_nt, nt_nodelock)
91 * Node table scangen locking definitions.
93 typedef kmutex_t ieee80211_scan_lock_t;
94 #define IEEE80211_SCAN_LOCK_INIT(_nt, _name) \
95 IEEE80211_LOCK_INIT_IMPL(_nt, _name, nt_scanlock)
96 #define IEEE80211_SCAN_LOCK_DESTROY(_nt) \
97 IEEE80211_LOCK_DESTROY_IMPL(_nt, nt_scanlock)
98 #define IEEE80211_SCAN_LOCK(_nt) \
99 IEEE80211_LOCK_IMPL(_nt, nt_scanlock)
100 #define IEEE80211_SCAN_UNLOCK(_nt) \
101 IEEE80211_UNLOCK_IMPL(_nt, nt_scanlock)
102 #define IEEE80211_SCAN_LOCK_ASSERT(_nt) \
103 IEEE80211_LOCK_ASSERT_IMPL(_nt, nt_scanlock)
106 * Per-node power-save queue definitions.
108 #define IEEE80211_NODE_SAVEQ_INIT(_ni, _name) do { \
109 (_ni)->ni_savedq.ifq_maxlen = IEEE80211_PS_MAX_QUEUE; \
110 } while (0)
111 #define IEEE80211_NODE_SAVEQ_DESTROY(_ni)
112 #define IEEE80211_NODE_SAVEQ_QLEN(_ni) ((_ni)->ni_savedq.ifq_len)
113 #define IEEE80211_NODE_SAVEQ_LOCK(_ni)
114 #define IEEE80211_NODE_SAVEQ_UNLOCK(_ni)
115 #define IEEE80211_NODE_SAVEQ_DEQUEUE(_ni, _m, _qlen) do { \
116 IEEE80211_NODE_SAVEQ_LOCK(_ni); \
117 IF_DEQUEUE(&(_ni)->ni_savedq, _m); \
118 (_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni); \
119 IEEE80211_NODE_SAVEQ_UNLOCK(_ni); \
120 } while (0)
121 #define IEEE80211_NODE_SAVEQ_DRAIN(_ni, _qlen) do { \
122 IEEE80211_NODE_SAVEQ_LOCK(_ni); \
123 (_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni); \
124 IF_PURGE(&(_ni)->ni_savedq); \
125 IEEE80211_NODE_SAVEQ_UNLOCK(_ni); \
126 } while (0)
127 /* XXX could be optimized */
128 #define _IEEE80211_NODE_SAVEQ_DEQUEUE_HEAD(_ni, _m) do { \
129 IF_DEQUEUE(&(_ni)->ni_savedq, m); \
130 } while (0)
131 #define _IEEE80211_NODE_SAVEQ_ENQUEUE(_ni, _m, _qlen, _age) do {\
132 (_m)->m_nextpkt = NULL; \
133 if ((_ni)->ni_savedq.ifq_tail != NULL) { \
134 _age -= M_AGE_GET((_ni)->ni_savedq.ifq_tail); \
135 (_ni)->ni_savedq.ifq_tail->m_nextpkt = (_m); \
136 } else { \
137 (_ni)->ni_savedq.ifq_head = (_m); \
139 M_AGE_SET(_m, _age); \
140 (_ni)->ni_savedq.ifq_tail = (_m); \
141 (_qlen) = ++(_ni)->ni_savedq.ifq_len; \
142 } while (0)
145 * 802.1x MAC ACL database locking definitions.
147 typedef kmutex_t acl_lock_t;
148 #define ACL_LOCK_INIT(_as, _name) \
149 IEEE80211_LOCK_INIT_IMPL(_as, _name, as_lock)
150 #define ACL_LOCK_DESTROY(_as) \
151 IEEE80211_LOCK_DESTROY_IMPL(_as, as_lock)
152 #define ACL_LOCK(_as) IEEE80211_LOCK_IMPL(_as, as_lock)
153 #define ACL_UNLOCK(_as) IEEE80211_UNLOCK_IMPL(_as, as_lock)
154 #define ACL_LOCK_ASSERT(_as) IEEE80211_LOCK_ASSERT_IMPL(_as, as_lock)
157 * Node reference counting definitions.
159 * ieee80211_node_initref initialize the reference count to 1
160 * ieee80211_node_incref add a reference
161 * ieee80211_node_decref remove a reference
162 * ieee80211_node_dectestref remove a reference and return 1 if this
163 * is the last reference, otherwise 0
164 * ieee80211_node_refcnt reference count for printing (only)
167 #define ieee80211_node_initref(_ni) \
168 do { ((_ni)->ni_refcnt = 1); } while (0)
169 #define ieee80211_node_incref(_ni) \
170 do { (_ni)->ni_refcnt++; } while (0)
171 #define ieee80211_node_decref(_ni) \
172 do { (_ni)->ni_refcnt--; } while (0)
173 struct ieee80211_node;
174 int ieee80211_node_dectestref(struct ieee80211_node *ni);
175 #define ieee80211_node_refcnt(_ni) (_ni)->ni_refcnt
177 struct ifqueue;
178 void ieee80211_drain_ifq(struct ifqueue *);
180 struct mbuf *ieee80211_getmgtframe(u_int8_t **frm, u_int pktlen);
181 #define M_PWR_SAV M_PROTO1 /* bypass PS handling */
182 #define M_MORE_DATA M_LINK3 /* more data frames to follow */
183 #define M_FRAG M_LINK4 /* 802.11 fragment */
184 #define M_FIRSTFRAG M_LINK5 /* first 802.11 fragment */
185 #define M_FF M_LINK6 /* "fast frames" */
187 * Encode WME access control bits in the PROTO flags.
188 * This is safe since it's passed directly in to the
189 * driver and there's no chance someone else will clobber
190 * them on us.
192 #define M_WME_AC_MASK (M_LINK1|M_LINK2)
193 /* XXX 5 is wrong if M_LINK* are redefined */
194 #define M_WME_AC_SHIFT 13
196 #define M_WME_SETAC(m, ac) \
197 ((m)->m_flags = ((m)->m_flags &~ M_WME_AC_MASK) | \
198 ((ac) << M_WME_AC_SHIFT))
199 #define M_WME_GETAC(m) (((m)->m_flags >> M_WME_AC_SHIFT) & 0x3)
202 * Mbufs on the power save queue are tagged with an age and
203 * timed out. We reuse the hardware checksum field in the
204 * mbuf packet header to store this data.
206 #define M_AGE_SET(m,v) (m->m_pkthdr.csum_data = v)
207 #define M_AGE_GET(m) (m->m_pkthdr.csum_data)
208 #define M_AGE_SUB(m,adj) (m->m_pkthdr.csum_data -= adj)
210 struct ieee80211com;
211 #endif /* _KERNEL */
213 /* XXX this stuff belongs elsewhere */
215 * Message formats for messages from the net80211 layer to user
216 * applications via the routing socket. These messages are appended
217 * to an if_announcemsghdr structure.
219 struct ieee80211_join_event {
220 uint8_t iev_addr[6];
223 struct ieee80211_leave_event {
224 uint8_t iev_addr[6];
227 struct ieee80211_replay_event {
228 uint8_t iev_src[6]; /* src MAC */
229 uint8_t iev_dst[6]; /* dst MAC */
230 uint8_t iev_cipher; /* cipher type */
231 uint8_t iev_keyix; /* key id/index */
232 uint64_t iev_keyrsc; /* RSC from key */
233 uint64_t iev_rsc; /* RSC from frame */
236 struct ieee80211_michael_event {
237 uint8_t iev_src[6]; /* src MAC */
238 uint8_t iev_dst[6]; /* dst MAC */
239 uint8_t iev_cipher; /* cipher type */
240 uint8_t iev_keyix; /* key id/index */
243 #define RTM_IEEE80211_ASSOC 100 /* station associate (bss mode) */
244 #define RTM_IEEE80211_REASSOC 101 /* station re-associate (bss mode) */
245 #define RTM_IEEE80211_DISASSOC 102 /* station disassociate (bss mode) */
246 #define RTM_IEEE80211_JOIN 103 /* station join (ap mode) */
247 #define RTM_IEEE80211_LEAVE 104 /* station leave (ap mode) */
248 #define RTM_IEEE80211_SCAN 105 /* scan complete, results available */
249 #define RTM_IEEE80211_REPLAY 106 /* sequence counter replay detected */
250 #define RTM_IEEE80211_MICHAEL 107 /* Michael MIC failure detected */
251 #define RTM_IEEE80211_REJOIN 108 /* station re-associate (ap mode) */
253 #ifdef _KERNEL
254 #define __offsetof offsetof
255 #define ticks hardclock_ticks
256 #define ovbcopy(__src, __dst, __n) ((void)memmove(__dst, __src, __n))
258 void if_printf(struct ifnet *, const char *, ...);
259 void m_align(struct mbuf *, int);
260 int m_append(struct mbuf *, int, const void *);
261 void get_random_bytes(void *, size_t);
263 void ieee80211_sysctl_attach(struct ieee80211com *);
264 void ieee80211_sysctl_detach(struct ieee80211com *);
265 void ieee80211_load_module(const char *);
267 void ieee80211_init(void);
268 #define IEEE80211_CRYPTO_SETUP(name) \
269 static void name(void); \
270 __link_set_add_text(ieee80211_funcs, name); \
271 static void name(void)
272 #endif
274 #endif /* !_NET80211_IEEE80211_NETBSD_H_ */