ieee80211_netbsd.h revision 1.6 1 1.6 skrll /* $NetBSD: ieee80211_netbsd.h,v 1.6 2005/08/18 06:07:30 skrll 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.5 dyoung * $FreeBSD: src/sys/net80211/ieee80211_freebsd.h,v 1.5 2005/07/06 01:55:17 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.2 dyoung #define IEEE80211_UNLOCK_IMPL(_ic, _member) \
57 1.2 dyoung do { \
58 1.2 dyoung if (--(_ic)->_member.count == 0) \
59 1.2 dyoung splx((_ic)->_member.ipl); \
60 1.2 dyoung } while (0)
61 1.2 dyoung #define IEEE80211_LOCK_ASSERT_IMPL(_ic, _member) \
62 1.2 dyoung IASSERT((_ic)->_member.count > 0, \
63 1.2 dyoung ("%s: IEEE80211_LOCK not held", __func__));
64 1.2 dyoung
65 1.4 dyoung /*
66 1.4 dyoung * Beacon locking definitions.
67 1.4 dyoung */
68 1.2 dyoung typedef struct ieee80211_lock ieee80211_beacon_lock_t;
69 1.2 dyoung #define IEEE80211_BEACON_LOCK_INIT(_ic, _name) \
70 1.2 dyoung IEEE80211_LOCK_INIT_IMPL(_ic, _name, ic_beaconlock)
71 1.2 dyoung #define IEEE80211_BEACON_LOCK_DESTROY(_ic)
72 1.2 dyoung #define IEEE80211_BEACON_LOCK(_ic) \
73 1.2 dyoung IEEE80211_LOCK_IMPL(_ic, ic_beaconlock)
74 1.2 dyoung #define IEEE80211_BEACON_UNLOCK(_ic) \
75 1.2 dyoung IEEE80211_UNLOCK_IMPL(_ic, ic_beaconlock)
76 1.2 dyoung #define IEEE80211_BEACON_LOCK_ASSERT(_ic) \
77 1.2 dyoung IEEE80211_LOCK_ASSERT_IMPL(_ic, ic_beaconlock)
78 1.2 dyoung
79 1.2 dyoung /*
80 1.2 dyoung * Node locking definitions.
81 1.2 dyoung */
82 1.2 dyoung typedef struct ieee80211_lock ieee80211_node_lock_t;
83 1.2 dyoung #define IEEE80211_NODE_LOCK_INIT(_nt, _name) \
84 1.2 dyoung IEEE80211_LOCK_INIT_IMPL(_nt, _name, nt_nodelock)
85 1.2 dyoung #define IEEE80211_NODE_LOCK_DESTROY(_nt)
86 1.2 dyoung #define IEEE80211_NODE_LOCK(_nt) \
87 1.2 dyoung IEEE80211_LOCK_IMPL(_nt, nt_nodelock)
88 1.2 dyoung #define IEEE80211_NODE_UNLOCK(_nt) \
89 1.2 dyoung IEEE80211_UNLOCK_IMPL(_nt, nt_nodelock)
90 1.2 dyoung #define IEEE80211_NODE_LOCK_ASSERT(_nt) \
91 1.2 dyoung IEEE80211_LOCK_ASSERT_IMPL(_nt, nt_nodelock)
92 1.2 dyoung
93 1.2 dyoung /*
94 1.2 dyoung * Node table scangen locking definitions.
95 1.2 dyoung */
96 1.2 dyoung typedef struct ieee80211_lock ieee80211_scan_lock_t;
97 1.2 dyoung #define IEEE80211_SCAN_LOCK_INIT(_nt, _name) \
98 1.2 dyoung IEEE80211_LOCK_INIT_IMPL(_nt, _name, nt_scanlock)
99 1.2 dyoung #define IEEE80211_SCAN_LOCK_DESTROY(_nt)
100 1.2 dyoung #define IEEE80211_SCAN_LOCK(_nt) \
101 1.2 dyoung IEEE80211_LOCK_IMPL(_nt, nt_scanlock)
102 1.2 dyoung #define IEEE80211_SCAN_UNLOCK(_nt) \
103 1.2 dyoung IEEE80211_UNLOCK_IMPL(_nt, nt_scanlock)
104 1.2 dyoung #define IEEE80211_SCAN_LOCK_ASSERT(_nt) \
105 1.2 dyoung IEEE80211_LOCK_ASSERT_IMPL(_nt, nt_scanlock)
106 1.2 dyoung
107 1.2 dyoung /*
108 1.2 dyoung * Per-node power-save queue definitions.
109 1.2 dyoung */
110 1.2 dyoung #define IEEE80211_NODE_SAVEQ_INIT(_ni, _name) do { \
111 1.2 dyoung (_ni)->ni_savedq.ifq_maxlen = IEEE80211_PS_MAX_QUEUE; \
112 1.2 dyoung } while (0)
113 1.2 dyoung #define IEEE80211_NODE_SAVEQ_DESTROY(_ni)
114 1.2 dyoung #define IEEE80211_NODE_SAVEQ_QLEN(_ni) ((_ni)->ni_savedq.ifq_len)
115 1.2 dyoung #define IEEE80211_NODE_SAVEQ_LOCK(_ni)
116 1.2 dyoung #define IEEE80211_NODE_SAVEQ_UNLOCK(_ni)
117 1.2 dyoung #define IEEE80211_NODE_SAVEQ_DEQUEUE(_ni, _m, _qlen) do { \
118 1.2 dyoung IEEE80211_NODE_SAVEQ_LOCK(_ni); \
119 1.2 dyoung IF_DEQUEUE(&(_ni)->ni_savedq, _m); \
120 1.2 dyoung (_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni); \
121 1.2 dyoung IEEE80211_NODE_SAVEQ_UNLOCK(_ni); \
122 1.2 dyoung } while (0)
123 1.2 dyoung #define IEEE80211_NODE_SAVEQ_DRAIN(_ni, _qlen) do { \
124 1.2 dyoung IEEE80211_NODE_SAVEQ_LOCK(_ni); \
125 1.2 dyoung (_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni); \
126 1.2 dyoung IF_PURGE(&(_ni)->ni_savedq); \
127 1.2 dyoung IEEE80211_NODE_SAVEQ_UNLOCK(_ni); \
128 1.2 dyoung } while (0)
129 1.2 dyoung /* XXX could be optimized */
130 1.2 dyoung #define _IEEE80211_NODE_SAVEQ_DEQUEUE_HEAD(_ni, _m) do { \
131 1.2 dyoung IF_DEQUEUE(&(_ni)->ni_savedq, m); \
132 1.2 dyoung } while (0)
133 1.2 dyoung #define _IEEE80211_NODE_SAVEQ_ENQUEUE(_ni, _m, _qlen, _age) do {\
134 1.2 dyoung (_m)->m_nextpkt = NULL; \
135 1.2 dyoung if ((_ni)->ni_savedq.ifq_tail != NULL) { \
136 1.2 dyoung _age -= M_AGE_GET((_ni)->ni_savedq.ifq_tail); \
137 1.2 dyoung (_ni)->ni_savedq.ifq_tail->m_nextpkt = (_m); \
138 1.2 dyoung } else { \
139 1.2 dyoung (_ni)->ni_savedq.ifq_head = (_m); \
140 1.2 dyoung } \
141 1.2 dyoung M_AGE_SET(_m, _age); \
142 1.2 dyoung (_ni)->ni_savedq.ifq_tail = (_m); \
143 1.2 dyoung (_qlen) = ++(_ni)->ni_savedq.ifq_len; \
144 1.2 dyoung } while (0)
145 1.2 dyoung
146 1.2 dyoung /*
147 1.2 dyoung * 802.1x MAC ACL database locking definitions.
148 1.2 dyoung */
149 1.2 dyoung typedef struct ieee80211_lock acl_lock_t;
150 1.2 dyoung #define ACL_LOCK_INIT(_as, _name) \
151 1.2 dyoung IEEE80211_LOCK_INIT_IMPL(_as, _name, as_lock)
152 1.2 dyoung #define ACL_LOCK_DESTROY(_as)
153 1.2 dyoung #define ACL_LOCK(_as) IEEE80211_LOCK_IMPL(_as, as_lock)
154 1.2 dyoung #define ACL_UNLOCK(_as) IEEE80211_UNLOCK_IMPL(_as, as_lock)
155 1.2 dyoung #define ACL_LOCK_ASSERT(_as) IEEE80211_LOCK_ASSERT_IMPL(_as, as_lock)
156 1.2 dyoung
157 1.2 dyoung /*
158 1.2 dyoung * Node reference counting definitions.
159 1.2 dyoung *
160 1.2 dyoung * ieee80211_node_initref initialize the reference count to 1
161 1.2 dyoung * ieee80211_node_incref add a reference
162 1.2 dyoung * ieee80211_node_decref remove a reference
163 1.2 dyoung * ieee80211_node_dectestref remove a reference and return 1 if this
164 1.2 dyoung * is the last reference, otherwise 0
165 1.2 dyoung * ieee80211_node_refcnt reference count for printing (only)
166 1.2 dyoung */
167 1.2 dyoung
168 1.2 dyoung #define ieee80211_node_initref(_ni) \
169 1.2 dyoung do { ((_ni)->ni_refcnt = 1); } while (0)
170 1.2 dyoung #define ieee80211_node_incref(_ni) \
171 1.2 dyoung do { (_ni)->ni_refcnt++; } while (0)
172 1.2 dyoung #define ieee80211_node_decref(_ni) \
173 1.2 dyoung do { (_ni)->ni_refcnt--; } while (0)
174 1.2 dyoung struct ieee80211_node;
175 1.2 dyoung int ieee80211_node_dectestref(struct ieee80211_node *ni);
176 1.2 dyoung #define ieee80211_node_refcnt(_ni) (_ni)->ni_refcnt
177 1.2 dyoung
178 1.2 dyoung struct mbuf *ieee80211_getmgtframe(u_int8_t **frm, u_int pktlen);
179 1.2 dyoung #define M_PWR_SAV M_PROTO1 /* bypass PS handling */
180 1.5 dyoung #define M_MORE_DATA M_LINK3 /* more data frames to follow */
181 1.2 dyoung /*
182 1.2 dyoung * Encode WME access control bits in the PROTO flags.
183 1.2 dyoung * This is safe since it's passed directly in to the
184 1.2 dyoung * driver and there's no chance someone else will clobber
185 1.2 dyoung * them on us.
186 1.2 dyoung */
187 1.2 dyoung #define M_WME_AC_MASK (M_LINK1|M_LINK2)
188 1.2 dyoung /* XXX 5 is wrong if M_LINK* are redefined */
189 1.2 dyoung #define M_WME_AC_SHIFT 13
190 1.2 dyoung
191 1.2 dyoung #define M_WME_SETAC(m, ac) \
192 1.2 dyoung ((m)->m_flags = ((m)->m_flags &~ M_WME_AC_MASK) | \
193 1.2 dyoung ((ac) << M_WME_AC_SHIFT))
194 1.2 dyoung #define M_WME_GETAC(m) (((m)->m_flags >> M_WME_AC_SHIFT) & 0x3)
195 1.2 dyoung
196 1.2 dyoung /*
197 1.2 dyoung * Mbufs on the power save queue are tagged with an age and
198 1.2 dyoung * timed out. We reuse the hardware checksum field in the
199 1.2 dyoung * mbuf packet header to store this data.
200 1.2 dyoung */
201 1.2 dyoung #define M_AGE_SET(m,v) (m->m_pkthdr.csum_data = v)
202 1.2 dyoung #define M_AGE_GET(m) (m->m_pkthdr.csum_data)
203 1.2 dyoung #define M_AGE_SUB(m,adj) (m->m_pkthdr.csum_data -= adj)
204 1.2 dyoung
205 1.2 dyoung struct ieee80211com;
206 1.2 dyoung
207 1.2 dyoung /* XXX this stuff belongs elsewhere */
208 1.2 dyoung /*
209 1.2 dyoung * Message formats for messages from the net80211 layer to user
210 1.2 dyoung * applications via the routing socket. These messages are appended
211 1.2 dyoung * to an if_announcemsghdr structure.
212 1.2 dyoung */
213 1.2 dyoung struct ieee80211_join_event {
214 1.2 dyoung uint8_t iev_addr[6];
215 1.2 dyoung };
216 1.2 dyoung
217 1.2 dyoung struct ieee80211_leave_event {
218 1.2 dyoung uint8_t iev_addr[6];
219 1.2 dyoung };
220 1.2 dyoung
221 1.2 dyoung struct ieee80211_replay_event {
222 1.2 dyoung uint8_t iev_src[6]; /* src MAC */
223 1.2 dyoung uint8_t iev_dst[6]; /* dst MAC */
224 1.2 dyoung uint8_t iev_cipher; /* cipher type */
225 1.2 dyoung uint8_t iev_keyix; /* key id/index */
226 1.2 dyoung uint64_t iev_keyrsc; /* RSC from key */
227 1.2 dyoung uint64_t iev_rsc; /* RSC from frame */
228 1.2 dyoung };
229 1.2 dyoung
230 1.2 dyoung struct ieee80211_michael_event {
231 1.2 dyoung uint8_t iev_src[6]; /* src MAC */
232 1.2 dyoung uint8_t iev_dst[6]; /* dst MAC */
233 1.2 dyoung uint8_t iev_cipher; /* cipher type */
234 1.2 dyoung uint8_t iev_keyix; /* key id/index */
235 1.2 dyoung };
236 1.2 dyoung
237 1.2 dyoung #define RTM_IEEE80211_ASSOC 100 /* station associate (bss mode) */
238 1.2 dyoung #define RTM_IEEE80211_REASSOC 101 /* station re-associate (bss mode) */
239 1.2 dyoung #define RTM_IEEE80211_DISASSOC 102 /* station disassociate (bss mode) */
240 1.2 dyoung #define RTM_IEEE80211_JOIN 103 /* station join (ap mode) */
241 1.2 dyoung #define RTM_IEEE80211_LEAVE 104 /* station leave (ap mode) */
242 1.2 dyoung #define RTM_IEEE80211_SCAN 105 /* scan complete, results available */
243 1.2 dyoung #define RTM_IEEE80211_REPLAY 106 /* sequence counter replay detected */
244 1.2 dyoung #define RTM_IEEE80211_MICHAEL 107 /* Michael MIC failure detected */
245 1.2 dyoung #define RTM_IEEE80211_REJOIN 108 /* station re-associate (ap mode) */
246 1.2 dyoung
247 1.2 dyoung #define __offsetof offsetof
248 1.2 dyoung #define ticks hardclock_ticks
249 1.2 dyoung #define ovbcopy(__src, __dst, __n) ((void)memmove(__dst, __src, __n))
250 1.2 dyoung
251 1.2 dyoung #define TAILQ_FOREACH_SAFE(var, head, field, nextvar) \
252 1.2 dyoung for (var = TAILQ_FIRST(head); \
253 1.2 dyoung var != NULL && (nextvar = TAILQ_NEXT(var, field), 1); \
254 1.2 dyoung var = nextvar)
255 1.2 dyoung
256 1.2 dyoung void if_printf(struct ifnet *, const char *, ...);
257 1.2 dyoung struct mbuf *m_getcl(int, int, int);
258 1.2 dyoung int m_append(struct mbuf *, int, const caddr_t);
259 1.2 dyoung void get_random_bytes(void *, size_t);
260 1.6 skrll
261 1.2 dyoung void ieee80211_sysctl_attach(struct ieee80211com *);
262 1.2 dyoung void ieee80211_sysctl_detach(struct ieee80211com *);
263 1.2 dyoung void ieee80211_load_module(const char *);
264 1.2 dyoung
265 1.2 dyoung #endif /* _NET80211_IEEE80211_NETBSD_H_ */
266