mbuf: revert part of b4e5a1079d852748f03f32aae87ecdda27a538d2
[dragonfly.git] / sys / netproto / 802_11 / ieee80211_dragonfly.h
CommitLineData
32176cfd
RP
1/*-
2 * Copyright (c) 2003-2008 Sam Leffler, Errno Consulting
841ab66c
SZ
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
841ab66c
SZ
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
32176cfd 25 * $FreeBSD: head/sys/net80211/ieee80211_freebsd.h 195618 2009-07-11 15:02:45Z rpaulo $
841ab66c
SZ
26 */
27#ifndef _NET80211_IEEE80211_DRAGONFLY_H_
28#define _NET80211_IEEE80211_DRAGONFLY_H_
29
32176cfd 30#ifdef _KERNEL
26c6f223 31
32176cfd
RP
32#include <sys/param.h>
33#include <sys/types.h>
26c6f223 34#include <sys/serialize.h>
32176cfd 35#include <sys/sysctl.h>
26c6f223 36#include <sys/condvar.h>
32176cfd
RP
37#include <sys/taskqueue.h>
38
26c6f223
MD
39#include <sys/mutex2.h>
40#include <sys/serialize2.h>
32176cfd
RP
41
42#ifndef IF_PREPEND_LIST
26c6f223 43
4cc8caef 44/* XXX all are prepended to normal queue */
68dc1916 45#define _IF_PREPEND_LIST(ifq, mhead, mtail, mcount, bcnt) do { \
4cc8caef
SZ
46 (mtail)->m_nextpkt = (ifq)->ifsq_norm_head; \
47 if ((ifq)->ifsq_norm_tail == NULL) \
48 (ifq)->ifsq_norm_tail = (mtail); \
49 (ifq)->ifsq_norm_head = (mhead); \
b21c2105 50 (ifq)->ifsq_len += (mcount); \
68dc1916 51 (ifq)->ifsq_bcnt += (bcnt); \
841ab66c 52} while (0)
26c6f223 53
68dc1916 54#define IF_PREPEND_LIST(ifq, mhead, mtail, mcount, bcnt) do { \
26c6f223 55 wlan_assert_serialized(); \
68dc1916 56 _IF_PREPEND_LIST(ifq, mhead, mtail, mcount, bcnt); \
841ab66c 57} while (0)
26c6f223 58
32176cfd 59#endif /* IF_PREPEND_LIST */
26c6f223 60
32176cfd 61/*
26c6f223 62 * Global serializer (operates like a non-reentrant lockmgr lock)
32176cfd 63 */
26c6f223 64extern struct lwkt_serialize wlan_global_serializer;
1b196a0c 65extern int ieee80211_force_swcrypto;
26c6f223 66
7fd4e1a1
SW
67#define wlan_serialize_enter() _wlan_serialize_enter(__func__)
68#define wlan_serialize_exit() _wlan_serialize_exit(__func__)
51237956
MD
69void _wlan_serialize_enter(const char *funcname);
70void _wlan_serialize_exit(const char *funcname);
26c6f223
MD
71int wlan_serialize_sleep(void *ident, int flags, const char *wmesg, int timo);
72
73static __inline void
74wlan_assert_serialized(void)
75{
76 ASSERT_SERIALIZED(&wlan_global_serializer);
77}
32176cfd
RP
78
79/*
26c6f223 80 * wlan condition variables. Assume the global serializer is held.
32176cfd 81 */
26c6f223
MD
82void wlan_cv_init(struct cv *cv, const char *desc);
83int wlan_cv_timedwait(struct cv *cv, int ticks);
84void wlan_cv_wait(struct cv *cv);
85void wlan_cv_signal(struct cv *cv, int broadcast);
841ab66c
SZ
86
87/*
88 * Node reference counting definitions.
89 *
90 * ieee80211_node_initref initialize the reference count to 1
91 * ieee80211_node_incref add a reference
92 * ieee80211_node_decref remove a reference
93 * ieee80211_node_dectestref remove a reference and return 1 if this
94 * is the last reference, otherwise 0
95 * ieee80211_node_refcnt reference count for printing (only)
96 */
97#include <machine/atomic.h>
98
99#define ieee80211_node_initref(_ni) \
100 do { ((_ni)->ni_refcnt = 1); } while (0)
101#define ieee80211_node_incref(_ni) \
102 atomic_add_int(&(_ni)->ni_refcnt, 1)
103#define ieee80211_node_decref(_ni) \
104 atomic_subtract_int(&(_ni)->ni_refcnt, 1)
105struct ieee80211_node;
106int ieee80211_node_dectestref(struct ieee80211_node *ni);
107#define ieee80211_node_refcnt(_ni) (_ni)->ni_refcnt
108
32176cfd
RP
109struct ifqueue;
110struct ieee80211vap;
c332e0e8 111void ieee80211_flush_ifq(struct ifaltq *, struct ieee80211vap *);
32176cfd
RP
112
113void ieee80211_vap_destroy(struct ieee80211vap *);
3088f8e9 114int ieee80211_handoff(struct ifnet *, struct mbuf *);
a13825b3 115uint16_t ieee80211_txtime(struct ieee80211_node *, u_int, uint8_t, uint32_t);
32176cfd
RP
116
117#define IFNET_IS_UP_RUNNING(_ifp) \
118 (((_ifp)->if_flags & IFF_UP) && \
34a60cf6 119 ((_ifp)->if_flags & IFF_RUNNING))
32176cfd
RP
120
121#define msecs_to_ticks(ms) (((ms)*hz)/1000)
122#define ticks_to_msecs(t) (1000*(t) / hz)
123#define ticks_to_secs(t) ((t) / hz)
124#define time_after(a,b) ((long)(b) - (long)(a) < 0)
125#define time_before(a,b) time_after(b,a)
126#define time_after_eq(a,b) ((long)(a) - (long)(b) >= 0)
127#define time_before_eq(a,b) time_after_eq(b,a)
4b582d92 128
32176cfd
RP
129struct mbuf *ieee80211_getmgtframe(uint8_t **frm, int headroom, int pktlen);
130
131/* tx path usage */
132#define M_ENCAP M_PROTO1 /* 802.11 encap done */
133#define M_EAPOL M_PROTO3 /* PAE/EAPOL frame */
841ab66c
SZ
134#define M_PWR_SAV M_PROTO4 /* bypass PS handling */
135#define M_MORE_DATA M_PROTO5 /* more data frames to follow */
32176cfd
RP
136#define M_FF M_PROTO6 /* fast frame */
137#define M_TXCB M_PROTO7 /* do tx complete callback */
138#define M_AMPDU_MPDU M_PROTO8 /* ok for A-MPDU aggregation */
139#define M_80211_TX \
140 (M_FRAG|M_FIRSTFRAG|M_LASTFRAG|M_ENCAP|M_EAPOL|M_PWR_SAV|\
141 M_MORE_DATA|M_FF|M_TXCB|M_AMPDU_MPDU)
142
143/* rx path usage */
144#define M_AMPDU M_PROTO1 /* A-MPDU subframe */
145#define M_WEP M_PROTO2 /* WEP done by hardware */
146#if 0
147#define M_AMPDU_MPDU M_PROTO8 /* A-MPDU re-order done */
148#endif
149#define M_80211_RX (M_AMPDU|M_WEP|M_AMPDU_MPDU)
150
151#define IEEE80211_MBUF_TX_FLAG_BITS \
152 "\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_RDONLY\5M_ENCAP\6M_WEP\7M_EAPOL" \
153 "\10M_PWR_SAV\11M_MORE_DATA\12M_BCAST\13M_MCAST\14M_FRAG\15M_FIRSTFRAG" \
154 "\16M_LASTFRAG\17M_SKIP_FIREWALL\20M_FREELIST\21M_VLANTAG\22M_PROMISC" \
155 "\23M_NOFREE\24M_FF\25M_TXCB\26M_AMPDU_MPDU\27M_FLOWID"
841ab66c 156
32176cfd
RP
157#define IEEE80211_MBUF_RX_FLAG_BITS \
158 "\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_RDONLY\5M_AMPDU\6M_WEP\7M_PROTO3" \
159 "\10M_PROTO4\11M_PROTO5\12M_BCAST\13M_MCAST\14M_FRAG\15M_FIRSTFRAG" \
160 "\16M_LASTFRAG\17M_SKIP_FIREWALL\20M_FREELIST\21M_VLANTAG\22M_PROMISC" \
161 "\23M_NOFREE\24M_PROTO6\25M_PROTO7\26M_AMPDU_MPDU\27M_FLOWID"
4b582d92 162
32176cfd
RP
163/*
164 * Store WME access control bits in the vlan tag.
165 * This is safe since it's done after the packet is classified
166 * (where we use any previous tag) and because it's passed
167 * directly in to the driver and there's no chance someone
168 * else will clobber them on us.
169 */
841ab66c 170#define M_WME_SETAC(m, ac) \
32176cfd
RP
171 ((m)->m_pkthdr.ether_vlantag = (ac))
172#define M_WME_GETAC(m) ((m)->m_pkthdr.ether_vlantag)
841ab66c
SZ
173
174/*
175 * Mbufs on the power save queue are tagged with an age and
176 * timed out. We reuse the hardware checksum field in the
177 * mbuf packet header to store this data.
178 */
179#define M_AGE_SET(m,v) (m->m_pkthdr.csum_data = v)
180#define M_AGE_GET(m) (m->m_pkthdr.csum_data)
181#define M_AGE_SUB(m,adj) (m->m_pkthdr.csum_data -= adj)
182
32176cfd
RP
183/*
184 * Store the sequence number.
185 */
186#define M_SEQNO_SET(m, seqno) \
01d73edb
SZ
187 ((m)->m_pkthdr.wlan_seqno = (seqno))
188#define M_SEQNO_GET(m) ((m)->m_pkthdr.wlan_seqno)
32176cfd
RP
189
190#define MTAG_ABI_NET80211 1132948340 /* net80211 ABI */
191
192struct ieee80211_cb {
193 void (*func)(struct ieee80211_node *, void *, int status);
194 void *arg;
195};
196#define NET80211_TAG_CALLBACK 0 /* xmit complete callback */
197int ieee80211_add_callback(struct mbuf *m,
198 void (*func)(struct ieee80211_node *, void *, int), void *arg);
199void ieee80211_process_callback(struct ieee80211_node *, struct mbuf *, int);
200
841ab66c
SZ
201void get_random_bytes(void *, size_t);
202
203struct ieee80211com;
204
205void ieee80211_sysctl_attach(struct ieee80211com *);
206void ieee80211_sysctl_detach(struct ieee80211com *);
32176cfd
RP
207void ieee80211_sysctl_vattach(struct ieee80211vap *);
208void ieee80211_sysctl_vdetach(struct ieee80211vap *);
209
210SYSCTL_DECL(_net_wlan);
211int ieee80211_sysctl_msecs_ticks(SYSCTL_HANDLER_ARGS);
841ab66c
SZ
212
213void ieee80211_load_module(const char *);
32176cfd
RP
214
215/*
216 * A "policy module" is an adjunct module to net80211 that provides
217 * functionality that typically includes policy decisions. This
218 * modularity enables extensibility and vendor-supplied functionality.
219 */
220#define _IEEE80211_POLICY_MODULE(policy, name, version) \
221typedef void (*policy##_setup)(int); \
222SET_DECLARE(policy##_set, policy##_setup); \
223static int \
224wlan_##name##_modevent(module_t mod, int type, void *unused) \
225{ \
226 policy##_setup * const *iter, f; \
47156d48
MD
227 int error; \
228 \
229 wlan_serialize_enter(); \
230 \
32176cfd
RP
231 switch (type) { \
232 case MOD_LOAD: \
233 SET_FOREACH(iter, policy##_set) { \
234 f = (void*) *iter; \
235 f(type); \
236 } \
47156d48
MD
237 error = 0; \
238 break; \
32176cfd 239 case MOD_UNLOAD: \
51237956 240 error = 0; \
32176cfd 241 if (nrefs) { \
47156d48
MD
242 kprintf("wlan_##name: still in use (%u " \
243 "dynamic refs)\n", \
32176cfd 244 nrefs); \
51237956
MD
245 error = EBUSY; \
246 } else if (type == MOD_UNLOAD) { \
32176cfd
RP
247 SET_FOREACH(iter, policy##_set) { \
248 f = (void*) *iter; \
249 f(type); \
250 } \
251 } \
47156d48
MD
252 break; \
253 default: \
254 error = EINVAL; \
255 break; \
32176cfd 256 } \
47156d48
MD
257 \
258 wlan_serialize_exit(); \
259 \
260 return error; \
32176cfd
RP
261} \
262static moduledata_t name##_mod = { \
263 "wlan_" #name, \
264 wlan_##name##_modevent, \
265 0 \
266}; \
267DECLARE_MODULE(wlan_##name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);\
268MODULE_VERSION(wlan_##name, version); \
269MODULE_DEPEND(wlan_##name, wlan, 1, 1, 1)
270
271/*
272 * Crypto modules implement cipher support.
273 */
274#define IEEE80211_CRYPTO_MODULE(name, version) \
275_IEEE80211_POLICY_MODULE(crypto, name, version); \
276static void \
277name##_modevent(int type) \
278{ \
51237956 279 /* wlan already serialized! */ \
32176cfd
RP
280 if (type == MOD_LOAD) \
281 ieee80211_crypto_register(&name); \
282 else \
283 ieee80211_crypto_unregister(&name); \
284} \
285TEXT_SET(crypto##_set, name##_modevent)
286
287/*
288 * Scanner modules provide scanning policy.
289 */
290#define IEEE80211_SCANNER_MODULE(name, version) \
291 _IEEE80211_POLICY_MODULE(scanner, name, version)
292
293#define IEEE80211_SCANNER_ALG(name, alg, v) \
294static void \
295name##_modevent(int type) \
296{ \
51237956 297 /* wlan already serialized! */ \
32176cfd
RP
298 if (type == MOD_LOAD) \
299 ieee80211_scanner_register(alg, &v); \
300 else \
301 ieee80211_scanner_unregister(alg, &v); \
302} \
303TEXT_SET(scanner_set, name##_modevent); \
304
305/*
306 * ACL modules implement acl policy.
307 */
308#define IEEE80211_ACL_MODULE(name, alg, version) \
309_IEEE80211_POLICY_MODULE(acl, name, version); \
310static void \
311alg##_modevent(int type) \
312{ \
51237956 313 /* wlan already serialized! */ \
32176cfd
RP
314 if (type == MOD_LOAD) \
315 ieee80211_aclator_register(&alg); \
316 else \
317 ieee80211_aclator_unregister(&alg); \
318} \
319TEXT_SET(acl_set, alg##_modevent); \
320
321/*
322 * Authenticator modules handle 802.1x/WPA authentication.
323 */
324#define IEEE80211_AUTH_MODULE(name, version) \
325 _IEEE80211_POLICY_MODULE(auth, name, version)
326
327#define IEEE80211_AUTH_ALG(name, alg, v) \
328static void \
329name##_modevent(int type) \
330{ \
51237956 331 /* wlan already serialized! */ \
32176cfd
RP
332 if (type == MOD_LOAD) \
333 ieee80211_authenticator_register(alg, &v); \
334 else \
335 ieee80211_authenticator_unregister(alg); \
336} \
337TEXT_SET(auth_set, name##_modevent)
338
339/*
340 * Rate control modules provide tx rate control support.
341 */
4028af95
RP
342#define IEEE80211_RATECTL_MODULE(alg, version) \
343 _IEEE80211_POLICY_MODULE(ratectl, alg, version); \
344
345#define IEEE80211_RATECTL_ALG(name, alg, v) \
32176cfd
RP
346static void \
347alg##_modevent(int type) \
348{ \
51237956 349 /* wlan already serialized! */ \
4028af95
RP
350 if (type == MOD_LOAD) \
351 ieee80211_ratectl_register(alg, &v); \
352 else \
353 ieee80211_ratectl_unregister(alg); \
32176cfd 354} \
4028af95 355TEXT_SET(ratectl##_set, alg##_modevent)
32176cfd
RP
356
357struct ieee80211req;
358typedef int ieee80211_ioctl_getfunc(struct ieee80211vap *,
359 struct ieee80211req *);
360SET_DECLARE(ieee80211_ioctl_getset, ieee80211_ioctl_getfunc);
361#define IEEE80211_IOCTL_GET(_name, _get) TEXT_SET(ieee80211_ioctl_getset, _get)
362
363typedef int ieee80211_ioctl_setfunc(struct ieee80211vap *,
364 struct ieee80211req *);
365SET_DECLARE(ieee80211_ioctl_setset, ieee80211_ioctl_setfunc);
366#define IEEE80211_IOCTL_SET(_name, _set) TEXT_SET(ieee80211_ioctl_setset, _set)
367#endif /* _KERNEL */
841ab66c
SZ
368
369/* XXX this stuff belongs elsewhere */
370/*
371 * Message formats for messages from the net80211 layer to user
372 * applications via the routing socket. These messages are appended
373 * to an if_announcemsghdr structure.
374 */
375struct ieee80211_join_event {
376 uint8_t iev_addr[6];
377};
378
379struct ieee80211_leave_event {
380 uint8_t iev_addr[6];
381};
382
383struct ieee80211_replay_event {
384 uint8_t iev_src[6]; /* src MAC */
385 uint8_t iev_dst[6]; /* dst MAC */
386 uint8_t iev_cipher; /* cipher type */
387 uint8_t iev_keyix; /* key id/index */
388 uint64_t iev_keyrsc; /* RSC from key */
389 uint64_t iev_rsc; /* RSC from frame */
390};
391
392struct ieee80211_michael_event {
393 uint8_t iev_src[6]; /* src MAC */
394 uint8_t iev_dst[6]; /* dst MAC */
395 uint8_t iev_cipher; /* cipher type */
396 uint8_t iev_keyix; /* key id/index */
397};
398
32176cfd
RP
399struct ieee80211_wds_event {
400 uint8_t iev_addr[6];
401};
402
403struct ieee80211_csa_event {
404 uint32_t iev_flags; /* channel flags */
405 uint16_t iev_freq; /* setting in Mhz */
406 uint8_t iev_ieee; /* IEEE channel number */
407 uint8_t iev_mode; /* CSA mode */
408 uint8_t iev_count; /* CSA count */
409};
410
411struct ieee80211_cac_event {
412 uint32_t iev_flags; /* channel flags */
413 uint16_t iev_freq; /* setting in Mhz */
414 uint8_t iev_ieee; /* IEEE channel number */
415 /* XXX timestamp? */
416 uint8_t iev_type; /* IEEE80211_NOTIFY_CAC_* */
417};
418
419struct ieee80211_radar_event {
420 uint32_t iev_flags; /* channel flags */
421 uint16_t iev_freq; /* setting in Mhz */
422 uint8_t iev_ieee; /* IEEE channel number */
423 /* XXX timestamp? */
424};
425
426struct ieee80211_auth_event {
427 uint8_t iev_addr[6];
428};
429
430struct ieee80211_deauth_event {
431 uint8_t iev_addr[6];
432};
433
434struct ieee80211_country_event {
435 uint8_t iev_addr[6];
436 uint8_t iev_cc[2]; /* ISO country code */
437};
438
439struct ieee80211_radio_event {
440 uint8_t iev_state; /* 1 on, 0 off */
441};
442
841ab66c
SZ
443#define RTM_IEEE80211_ASSOC 100 /* station associate (bss mode) */
444#define RTM_IEEE80211_REASSOC 101 /* station re-associate (bss mode) */
445#define RTM_IEEE80211_DISASSOC 102 /* station disassociate (bss mode) */
446#define RTM_IEEE80211_JOIN 103 /* station join (ap mode) */
447#define RTM_IEEE80211_LEAVE 104 /* station leave (ap mode) */
448#define RTM_IEEE80211_SCAN 105 /* scan complete, results available */
449#define RTM_IEEE80211_REPLAY 106 /* sequence counter replay detected */
450#define RTM_IEEE80211_MICHAEL 107 /* Michael MIC failure detected */
451#define RTM_IEEE80211_REJOIN 108 /* station re-associate (ap mode) */
32176cfd
RP
452#define RTM_IEEE80211_WDS 109 /* WDS discovery (ap mode) */
453#define RTM_IEEE80211_CSA 110 /* Channel Switch Announcement event */
454#define RTM_IEEE80211_RADAR 111 /* radar event */
455#define RTM_IEEE80211_CAC 112 /* Channel Availability Check event */
456#define RTM_IEEE80211_DEAUTH 113 /* station deauthenticate */
457#define RTM_IEEE80211_AUTH 114 /* station authenticate (ap mode) */
458#define RTM_IEEE80211_COUNTRY 115 /* discovered country code (sta mode) */
459#define RTM_IEEE80211_RADIO 116 /* RF kill switch state change */
841ab66c 460
32176cfd
RP
461/*
462 * Structure prepended to raw packets sent through the bpf
463 * interface when set to DLT_IEEE802_11_RADIO. This allows
464 * user applications to specify pretty much everything in
465 * an Atheros tx descriptor. XXX need to generalize.
466 *
467 * XXX cannot be more than 14 bytes as it is copied to a sockaddr's
468 * XXX sa_data area.
469 */
470struct ieee80211_bpf_params {
471 uint8_t ibp_vers; /* version */
472#define IEEE80211_BPF_VERSION 0
473 uint8_t ibp_len; /* header length in bytes */
474 uint8_t ibp_flags;
475#define IEEE80211_BPF_SHORTPRE 0x01 /* tx with short preamble */
476#define IEEE80211_BPF_NOACK 0x02 /* tx with no ack */
477#define IEEE80211_BPF_CRYPTO 0x04 /* tx with h/w encryption */
478#define IEEE80211_BPF_FCS 0x10 /* frame incldues FCS */
479#define IEEE80211_BPF_DATAPAD 0x20 /* frame includes data padding */
480#define IEEE80211_BPF_RTS 0x40 /* tx with RTS/CTS */
481#define IEEE80211_BPF_CTS 0x80 /* tx with CTS only */
482 uint8_t ibp_pri; /* WME/WMM AC+tx antenna */
483 uint8_t ibp_try0; /* series 1 try count */
484 uint8_t ibp_rate0; /* series 1 IEEE tx rate */
485 uint8_t ibp_power; /* tx power (device units) */
486 uint8_t ibp_ctsrate; /* IEEE tx rate for CTS */
487 uint8_t ibp_try1; /* series 2 try count */
488 uint8_t ibp_rate1; /* series 2 IEEE tx rate */
489 uint8_t ibp_try2; /* series 3 try count */
490 uint8_t ibp_rate2; /* series 3 IEEE tx rate */
491 uint8_t ibp_try3; /* series 4 try count */
492 uint8_t ibp_rate3; /* series 4 IEEE tx rate */
493};
841ab66c 494#endif /* _NET80211_IEEE80211_DRAGONFLY_H_ */