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