ieee80211_netbsd.h revision 1.14.4.1 1 /* $NetBSD: ieee80211_netbsd.h,v 1.14.4.1 2008/02/22 16:50:25 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.6 2005/08/08 18:46:36 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_IS_LOCKED_IMPL(_ic, _member) \
57 ((_ic)->_member.count != 0)
58 #define IEEE80211_UNLOCK_IMPL(_ic, _member) \
59 do { \
60 if (--(_ic)->_member.count == 0) \
61 splx((_ic)->_member.ipl); \
62 } while (0)
63 #define IEEE80211_LOCK_ASSERT_IMPL(_ic, _member) \
64 IASSERT((_ic)->_member.count > 0, \
65 ("%s: IEEE80211_LOCK not held", __func__));
66
67 /*
68 * Common state locking definitions.
69 */
70 typedef struct ieee80211_lock ieee80211_com_lock_t;
71 #define IEEE80211_LOCK_INIT(_ic, _name) \
72 IEEE80211_LOCK_INIT_IMPL(_ic, _name, ic_comlock)
73 #define IEEE80211_LOCK_DESTROY(_ic)
74 #define IEEE80211_LOCK(_ic) \
75 IEEE80211_LOCK_IMPL(_ic, ic_comlock)
76 #define IEEE80211_UNLOCK(_ic)\
77 IEEE80211_UNLOCK_IMPL(_ic, ic_comlock)
78 #define IEEE80211_LOCK_ASSERT(_ic) \
79 IEEE80211_LOCK_ASSERT_IMPL(_ic, ic_comlock)
80
81 /*
82 * Beacon locking definitions.
83 */
84 typedef struct ieee80211_lock ieee80211_beacon_lock_t;
85 #define IEEE80211_BEACON_LOCK_INIT(_ic, _name) \
86 IEEE80211_LOCK_INIT_IMPL(_ic, _name, ic_beaconlock)
87 #define IEEE80211_BEACON_LOCK_DESTROY(_ic)
88 #define IEEE80211_BEACON_LOCK(_ic) \
89 IEEE80211_LOCK_IMPL(_ic, ic_beaconlock)
90 #define IEEE80211_BEACON_UNLOCK(_ic) \
91 IEEE80211_UNLOCK_IMPL(_ic, ic_beaconlock)
92 #define IEEE80211_BEACON_LOCK_ASSERT(_ic) \
93 IEEE80211_LOCK_ASSERT_IMPL(_ic, ic_beaconlock)
94
95 /*
96 * Node locking definitions.
97 * NB: MTX_DUPOK is because we don't generate per-interface strings.
98 */
99 typedef struct ieee80211_lock ieee80211_node_lock_t;
100 #define IEEE80211_NODE_LOCK_INIT(_nt, _name) \
101 IEEE80211_LOCK_INIT_IMPL(_nt, _name, nt_nodelock)
102 #define IEEE80211_NODE_LOCK_DESTROY(_nt)
103 #define IEEE80211_NODE_LOCK(_nt) \
104 IEEE80211_LOCK_IMPL(_nt, nt_nodelock)
105 #define IEEE80211_NODE_IS_LOCKED(_nt) \
106 IEEE80211_IS_LOCKED_IMPL(_nt, nt_nodelock)
107 #define IEEE80211_NODE_UNLOCK(_nt) \
108 IEEE80211_UNLOCK_IMPL(_nt, nt_nodelock)
109 #define IEEE80211_NODE_LOCK_ASSERT(_nt) \
110 IEEE80211_LOCK_ASSERT_IMPL(_nt, nt_nodelock)
111
112 /*
113 * Node table scangen locking definitions.
114 */
115 typedef struct ieee80211_lock ieee80211_scan_lock_t;
116 #define IEEE80211_SCAN_LOCK_INIT(_nt, _name) \
117 IEEE80211_LOCK_INIT_IMPL(_nt, _name, nt_scanlock)
118 #define IEEE80211_SCAN_LOCK_DESTROY(_nt)
119 #define IEEE80211_SCAN_LOCK(_nt) \
120 IEEE80211_LOCK_IMPL(_nt, nt_scanlock)
121 #define IEEE80211_SCAN_UNLOCK(_nt) \
122 IEEE80211_UNLOCK_IMPL(_nt, nt_scanlock)
123 #define IEEE80211_SCAN_LOCK_ASSERT(_nt) \
124 IEEE80211_LOCK_ASSERT_IMPL(_nt, nt_scanlock)
125
126 /*
127 * Scan table locking definitions.
128 */
129 typedef struct ieee80211_lock ieee80211_scantable_lock_t;
130 #define IEEE80211_SCANTABLE_LOCK_INIT(_st, _name) \
131 IEEE80211_LOCK_INIT_IMPL(_st, _name, st_lock)
132 #define IEEE80211_SCANTABLE_LOCK_DESTROY(_st)
133 #define IEEE80211_SCANTABLE_LOCK(_st) \
134 IEEE80211_LOCK_IMPL(_st, st_lock)
135 #define IEEE80211_SCANTABLE_UNLOCK(_st) \
136 IEEE80211_UNLOCK_IMPL(_st, st_lock)
137 #define IEEE80211_SCANTABLE_LOCK_ASSERT(_st) \
138 IEEE80211_LOCK_ASSERT_IMPL(_st, st_lock)
139
140 /*
141 * Scan table scangen locking definitions.
142 */
143 typedef struct ieee80211_lock ieee80211_scangen_lock_t;
144 #define IEEE80211_SCANGEN_LOCK_INIT(_st, _name) \
145 IEEE80211_LOCK_INIT_IMPL(_st, _name, st_scanlock)
146 #define IEEE80211_SCANGEN_LOCK_DESTROY(_st)
147 #define IEEE80211_SCANGEN_LOCK(_st) \
148 IEEE80211_LOCK_IMPL(_st, st_scanlock)
149 #define IEEE80211_SCANGEN_UNLOCK(_st) \
150 IEEE80211_UNLOCK_IMPL(_st, st_scanlock)
151 #define IEEE80211_SCANGEN_LOCK_ASSERT(_st) \
152 IEEE80211_LOCK_ASSERT_IMPL(_st, st_scanlock)
153
154 /*
155 * Per-node power-save queue definitions.
156 */
157 #define IEEE80211_NODE_SAVEQ_INIT(_ni, _name) do { \
158 (_ni)->ni_savedq.ifq_maxlen = IEEE80211_PS_MAX_QUEUE; \
159 } while (0)
160 #define IEEE80211_NODE_SAVEQ_DESTROY(_ni)
161 #define IEEE80211_NODE_SAVEQ_QLEN(_ni) ((_ni)->ni_savedq.ifq_len)
162 #define IEEE80211_NODE_SAVEQ_LOCK(_ni)
163 #define IEEE80211_NODE_SAVEQ_UNLOCK(_ni)
164 #define IEEE80211_NODE_SAVEQ_DEQUEUE(_ni, _m, _qlen) do { \
165 IEEE80211_NODE_SAVEQ_LOCK(_ni); \
166 IF_DEQUEUE(&(_ni)->ni_savedq, _m); \
167 (_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni); \
168 IEEE80211_NODE_SAVEQ_UNLOCK(_ni); \
169 } while (0)
170 #define IEEE80211_NODE_SAVEQ_DRAIN(_ni, _qlen) do { \
171 IEEE80211_NODE_SAVEQ_LOCK(_ni); \
172 (_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni); \
173 IF_PURGE(&(_ni)->ni_savedq); \
174 IEEE80211_NODE_SAVEQ_UNLOCK(_ni); \
175 } while (0)
176 /* XXX could be optimized */
177 #define _IEEE80211_NODE_SAVEQ_DEQUEUE_HEAD(_ni, _m) do { \
178 IF_DEQUEUE(&(_ni)->ni_savedq, m); \
179 } while (0)
180 #define _IEEE80211_NODE_SAVEQ_ENQUEUE(_ni, _m, _qlen, _age) do {\
181 (_m)->m_nextpkt = NULL; \
182 if ((_ni)->ni_savedq.ifq_tail != NULL) { \
183 _age -= M_AGE_GET((_ni)->ni_savedq.ifq_tail); \
184 (_ni)->ni_savedq.ifq_tail->m_nextpkt = (_m); \
185 } else { \
186 (_ni)->ni_savedq.ifq_head = (_m); \
187 } \
188 M_AGE_SET(_m, _age); \
189 (_ni)->ni_savedq.ifq_tail = (_m); \
190 (_qlen) = ++(_ni)->ni_savedq.ifq_len; \
191 } while (0)
192
193 #define IEEE80211_TAPQ_INIT(_tap) do { \
194 (_tap)->txa_q.ifq_maxlen = IEEE80211_AGGR_BAWMAX; \
195 } while (0)
196 #define IEEE80211_TAPQ_DESTROY(_tap)
197
198 #define IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do { \
199 (mtail)->m_nextpkt = (ifq)->ifq_head; \
200 if ((ifq)->ifq_tail == NULL) \
201 (ifq)->ifq_tail = (mtail); \
202 (ifq)->ifq_head = (mhead); \
203 (ifq)->ifq_len += (mcount); \
204 } while (0)
205
206 /*
207 * 802.1x MAC ACL database locking definitions.
208 */
209 typedef struct ieee80211_lock acl_lock_t;
210 #define ACL_LOCK_INIT(_as, _name) \
211 IEEE80211_LOCK_INIT_IMPL(_as, _name, as_lock)
212 #define ACL_LOCK_DESTROY(_as)
213 #define ACL_LOCK(_as) IEEE80211_LOCK_IMPL(_as, as_lock)
214 #define ACL_UNLOCK(_as) IEEE80211_UNLOCK_IMPL(_as, as_lock)
215 #define ACL_LOCK_ASSERT(_as) IEEE80211_LOCK_ASSERT_IMPL(_as, as_lock)
216
217 /*
218 * Node reference counting definitions.
219 *
220 * ieee80211_node_initref initialize the reference count to 1
221 * ieee80211_node_incref add a reference
222 * ieee80211_node_decref remove a reference
223 * ieee80211_node_dectestref remove a reference and return 1 if this
224 * is the last reference, otherwise 0
225 * ieee80211_node_refcnt reference count for printing (only)
226 */
227
228 #define ieee80211_node_initref(_ni) \
229 do { ((_ni)->ni_refcnt = 1); } while (0)
230 #define ieee80211_node_incref(_ni) \
231 do { (_ni)->ni_refcnt++; } while (0)
232 #define ieee80211_node_decref(_ni) \
233 do { (_ni)->ni_refcnt--; } while (0)
234 struct ieee80211_node;
235 int ieee80211_node_dectestref(struct ieee80211_node *ni);
236 #define ieee80211_node_refcnt(_ni) (_ni)->ni_refcnt
237
238 struct ifqueue;
239 void ieee80211_drain_ifq(struct ifqueue *);
240
241 #define msecs_to_ticks(ms) (((ms)*hz)/1000)
242 #define ticks_to_msecs(t) ((t) / hz)
243 #define time_after(a,b) ((long)(b) - (long)(a) < 0)
244 #define time_before(a,b) time_after(b,a)
245 #define time_after_eq(a,b) ((long)(a) - (long)(b) >= 0)
246 #define time_before_eq(a,b) time_after_eq(b,a)
247
248 struct mbuf *ieee80211_getmgtframe(uint8_t **frm, int, u_int pktlen);
249
250 /* tx path usage */
251 #define M_PWR_SAV M_PROTO1 /* bypass PS handling */
252 #define M_MORE_DATA M_LINK3 /* more data frames to follow */
253 #define M_FRAG M_LINK4 /* 802.11 fragment */
254 #define M_FIRSTFRAG M_LINK5 /* first 802.11 fragment */
255 #define M_FF M_LINK6 /* "fast frames" */
256
257 /* rx path usage */
258 #define M_AMPDU M_PROTO1 /* A-MPDU processing done */
259 #define M_WEP M_LINK3 /* WEP done by hardware */ /* XXXNH */
260 #define M_80211_RX (M_AMPDU|M_WEP)
261
262 #ifdef __FreeBSD__
263 /* tx path usage */
264 #define M_LINK0 M_PROTO1 /* WEP requested */
265 #define M_PWR_SAV M_PROTO4 /* bypass PS handling */
266 #define M_MORE_DATA M_PROTO5 /* more data frames to follow */
267 #define M_FF 0x20000 /* fast frame */
268 #define M_TXCB 0x40000 /* do tx complete callback */
269 #define M_80211_TX (0x60000|M_PROTO1|M_WME_AC_MASK|M_PROTO4|M_PROTO5)
270
271 /* rx path usage */
272 #define M_AMPDU M_PROTO1 /* A-MPDU processing done */
273 #define M_WEP M_PROTO2 /* WEP done by hardware */
274 #define M_80211_RX (M_AMPDU|M_WEP)
275 #endif
276
277 /*
278 * Encode WME access control bits in the PROTO flags.
279 * This is safe since it's passed directly in to the
280 * driver and there's no chance someone else will clobber
281 * them on us.
282 */
283 #define M_WME_AC_MASK (M_LINK1|M_LINK2)
284 /* XXX 5 is wrong if M_LINK* are redefined */
285 #define M_WME_AC_SHIFT 13
286
287 #define M_WME_SETAC(m, ac) \
288 ((m)->m_flags = ((m)->m_flags &~ M_WME_AC_MASK) | \
289 ((ac) << M_WME_AC_SHIFT))
290 #define M_WME_GETAC(m) (((m)->m_flags >> M_WME_AC_SHIFT) & 0x3)
291
292 /*
293 * Mbufs on the power save queue are tagged with an age and
294 * timed out. We reuse the hardware checksum field in the
295 * mbuf packet header to store this data.
296 */
297 #define M_AGE_SET(m,v) (m->m_pkthdr.csum_data = v)
298 #define M_AGE_GET(m) (m->m_pkthdr.csum_data)
299 #define M_AGE_SUB(m,adj) (m->m_pkthdr.csum_data -= adj)
300
301 struct ieee80211_cb {
302 void (*func)(struct ieee80211_node *, void *, int status);
303 void *arg;
304 };
305 #define NET80211_TAG_CALLBACK 0 /* xmit complete callback */
306 int ieee80211_add_callback(struct mbuf *m,
307 void (*func)(struct ieee80211_node *, void *, int), void *arg);
308 void ieee80211_process_callback(struct ieee80211_node *, struct mbuf *, int);
309
310 struct ieee80211com;
311
312 /* XXX this stuff belongs elsewhere */
313 /*
314 * Message formats for messages from the net80211 layer to user
315 * applications via the routing socket. These messages are appended
316 * to an if_announcemsghdr structure.
317 */
318 struct ieee80211_join_event {
319 uint8_t iev_addr[6];
320 };
321
322 struct ieee80211_leave_event {
323 uint8_t iev_addr[6];
324 };
325
326 struct ieee80211_replay_event {
327 uint8_t iev_src[6]; /* src MAC */
328 uint8_t iev_dst[6]; /* dst MAC */
329 uint8_t iev_cipher; /* cipher type */
330 uint8_t iev_keyix; /* key id/index */
331 uint64_t iev_keyrsc; /* RSC from key */
332 uint64_t iev_rsc; /* RSC from frame */
333 };
334
335 struct ieee80211_michael_event {
336 uint8_t iev_src[6]; /* src MAC */
337 uint8_t iev_dst[6]; /* dst MAC */
338 uint8_t iev_cipher; /* cipher type */
339 uint8_t iev_keyix; /* key id/index */
340 };
341
342 #define RTM_IEEE80211_ASSOC 100 /* station associate (bss mode) */
343 #define RTM_IEEE80211_REASSOC 101 /* station re-associate (bss mode) */
344 #define RTM_IEEE80211_DISASSOC 102 /* station disassociate (bss mode) */
345 #define RTM_IEEE80211_JOIN 103 /* station join (ap mode) */
346 #define RTM_IEEE80211_LEAVE 104 /* station leave (ap mode) */
347 #define RTM_IEEE80211_SCAN 105 /* scan complete, results available */
348 #define RTM_IEEE80211_REPLAY 106 /* sequence counter replay detected */
349 #define RTM_IEEE80211_MICHAEL 107 /* Michael MIC failure detected */
350 #define RTM_IEEE80211_REJOIN 108 /* station re-associate (ap mode) */
351
352 #define __offsetof offsetof
353 #define ticks hardclock_ticks
354 #define ovbcopy(__src, __dst, __n) ((void)memmove(__dst, __src, __n))
355
356 #define TAILQ_FOREACH_SAFE(var, head, field, nextvar) \
357 for (var = TAILQ_FIRST(head); \
358 var != NULL && (nextvar = TAILQ_NEXT(var, field), 1); \
359 var = nextvar)
360
361 void if_printf(struct ifnet *, const char *, ...);
362 void m_align(struct mbuf *, int);
363 int m_append(struct mbuf *, int, const void *);
364 void get_random_bytes(void *, size_t);
365
366 void ieee80211_sysctl_attach(struct ieee80211com *);
367 void ieee80211_sysctl_detach(struct ieee80211com *);
368 void ieee80211_load_module(const char *);
369
370 void net80211_init(void);
371 #define IEEE80211_CRYPTO_SETUP(name) \
372 static void name(void); \
373 __link_set_add_text(ieee80211_funcs, name); \
374 static void name(void)
375
376 #endif /* !_NET80211_IEEE80211_NETBSD_H_ */
377