2 * Copyright (c) 2003-2008 Sam Leffler, Errno Consulting
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
25 * $FreeBSD: head/sys/net80211/ieee80211_freebsd.h 195618 2009-07-11 15:02:45Z rpaulo $
27 #ifndef _NET80211_IEEE80211_DRAGONFLY_H_
28 #define _NET80211_IEEE80211_DRAGONFLY_H_
32 #include <sys/param.h>
33 #include <sys/types.h>
34 #include <sys/serialize.h>
35 #include <sys/sysctl.h>
36 #include <sys/condvar.h>
37 #include <sys/taskqueue.h>
39 #include <sys/mutex2.h>
40 #include <sys/serialize2.h>
42 #ifndef IF_PREPEND_LIST
44 #define _IF_PREPEND_LIST(ifq, mhead, mtail, mcount, bcnt) do { \
45 (mtail)->m_nextpkt = (ifq)->ifsq_head; \
46 if ((ifq)->ifsq_tail == NULL) \
47 (ifq)->ifsq_tail = (mtail); \
48 (ifq)->ifsq_head = (mhead); \
49 (ifq)->ifsq_len += (mcount); \
50 (ifq)->ifsq_bcnt += (bcnt); \
53 #define IF_PREPEND_LIST(ifq, mhead, mtail, mcount, bcnt) do { \
54 wlan_assert_serialized(); \
55 _IF_PREPEND_LIST(ifq, mhead, mtail, mcount, bcnt); \
58 #endif /* IF_PREPEND_LIST */
61 * Global serializer (operates like a non-reentrant lockmgr lock)
63 extern struct lwkt_serialize wlan_global_serializer;
64 extern int ieee80211_force_swcrypto;
66 #define wlan_serialize_enter() _wlan_serialize_enter(__func__)
67 #define wlan_serialize_exit() _wlan_serialize_exit(__func__)
68 void _wlan_serialize_enter(const char *funcname);
69 void _wlan_serialize_exit(const char *funcname);
70 int wlan_serialize_sleep(void *ident, int flags, const char *wmesg, int timo);
73 wlan_assert_serialized(void)
75 ASSERT_SERIALIZED(&wlan_global_serializer);
79 * wlan condition variables. Assume the global serializer is held.
81 void wlan_cv_init(struct cv *cv, const char *desc);
82 int wlan_cv_timedwait(struct cv *cv, int ticks);
83 void wlan_cv_wait(struct cv *cv);
84 void wlan_cv_signal(struct cv *cv, int broadcast);
87 * Node reference counting definitions.
89 * ieee80211_node_initref initialize the reference count to 1
90 * ieee80211_node_incref add a reference
91 * ieee80211_node_decref remove a reference
92 * ieee80211_node_dectestref remove a reference and return 1 if this
93 * is the last reference, otherwise 0
94 * ieee80211_node_refcnt reference count for printing (only)
96 #include <machine/atomic.h>
98 #define ieee80211_node_initref(_ni) \
99 do { ((_ni)->ni_refcnt = 1); } while (0)
100 #define ieee80211_node_incref(_ni) \
101 atomic_add_int(&(_ni)->ni_refcnt, 1)
102 #define ieee80211_node_decref(_ni) \
103 atomic_subtract_int(&(_ni)->ni_refcnt, 1)
104 struct ieee80211_node;
105 int ieee80211_node_dectestref(struct ieee80211_node *ni);
106 #define ieee80211_node_refcnt(_ni) (_ni)->ni_refcnt
110 void ieee80211_flush_ifq(struct ifaltq *, struct ieee80211vap *);
112 void ieee80211_vap_destroy(struct ieee80211vap *);
113 int ieee80211_handoff(struct ifnet *, struct mbuf *);
114 uint16_t ieee80211_txtime(struct ieee80211_node *, u_int, uint8_t, uint32_t);
116 #define IFNET_IS_UP_RUNNING(_ifp) \
117 (((_ifp)->if_flags & IFF_UP) && \
118 ((_ifp)->if_flags & IFF_RUNNING))
120 #define msecs_to_ticks(ms) (((ms)*hz)/1000)
121 #define ticks_to_msecs(t) (1000*(t) / hz)
122 #define ticks_to_secs(t) ((t) / hz)
123 #define time_after(a,b) ((long)(b) - (long)(a) < 0)
124 #define time_before(a,b) time_after(b,a)
125 #define time_after_eq(a,b) ((long)(a) - (long)(b) >= 0)
126 #define time_before_eq(a,b) time_after_eq(b,a)
128 struct mbuf *ieee80211_getmgtframe(uint8_t **frm, int headroom, int pktlen);
131 #define M_ENCAP M_PROTO1 /* 802.11 encap done */
132 #define M_EAPOL M_PROTO3 /* PAE/EAPOL frame */
133 #define M_PWR_SAV M_PROTO4 /* bypass PS handling */
134 #define M_MORE_DATA M_PROTO5 /* more data frames to follow */
135 #define M_FF M_PROTO6 /* fast frame */
136 #define M_TXCB M_PROTO7 /* do tx complete callback */
137 #define M_AMPDU_MPDU M_PROTO8 /* ok for A-MPDU aggregation */
139 (M_FRAG|M_FIRSTFRAG|M_LASTFRAG|M_ENCAP|M_EAPOL|M_PWR_SAV|\
140 M_MORE_DATA|M_FF|M_TXCB|M_AMPDU_MPDU)
143 #define M_AMPDU M_PROTO1 /* A-MPDU subframe */
144 #define M_WEP M_PROTO2 /* WEP done by hardware */
146 #define M_AMPDU_MPDU M_PROTO8 /* A-MPDU re-order done */
148 #define M_80211_RX (M_AMPDU|M_WEP|M_AMPDU_MPDU)
150 #define IEEE80211_MBUF_TX_FLAG_BITS \
151 "\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_RDONLY\5M_ENCAP\6M_WEP\7M_EAPOL" \
152 "\10M_PWR_SAV\11M_MORE_DATA\12M_BCAST\13M_MCAST\14M_FRAG\15M_FIRSTFRAG" \
153 "\16M_LASTFRAG\17M_SKIP_FIREWALL\20M_FREELIST\21M_VLANTAG\22M_PROMISC" \
154 "\23M_NOFREE\24M_FF\25M_TXCB\26M_AMPDU_MPDU\27M_FLOWID"
156 #define IEEE80211_MBUF_RX_FLAG_BITS \
157 "\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_RDONLY\5M_AMPDU\6M_WEP\7M_PROTO3" \
158 "\10M_PROTO4\11M_PROTO5\12M_BCAST\13M_MCAST\14M_FRAG\15M_FIRSTFRAG" \
159 "\16M_LASTFRAG\17M_SKIP_FIREWALL\20M_FREELIST\21M_VLANTAG\22M_PROMISC" \
160 "\23M_NOFREE\24M_PROTO6\25M_PROTO7\26M_AMPDU_MPDU\27M_FLOWID"
163 * Store WME access control bits in the vlan tag.
164 * This is safe since it's done after the packet is classified
165 * (where we use any previous tag) and because it's passed
166 * directly in to the driver and there's no chance someone
167 * else will clobber them on us.
169 #define M_WME_SETAC(m, ac) \
170 ((m)->m_pkthdr.ether_vlantag = (ac))
171 #define M_WME_GETAC(m) ((m)->m_pkthdr.ether_vlantag)
174 * Mbufs on the power save queue are tagged with an age and
175 * timed out. We reuse the hardware checksum field in the
176 * mbuf packet header to store this data.
178 #define M_AGE_SET(m,v) (m->m_pkthdr.csum_data = v)
179 #define M_AGE_GET(m) (m->m_pkthdr.csum_data)
180 #define M_AGE_SUB(m,adj) (m->m_pkthdr.csum_data -= adj)
183 * Store the sequence number.
185 #define M_SEQNO_SET(m, seqno) \
186 ((m)->m_pkthdr.wlan_seqno = (seqno))
187 #define M_SEQNO_GET(m) ((m)->m_pkthdr.wlan_seqno)
189 #define MTAG_ABI_NET80211 1132948340 /* net80211 ABI */
191 struct ieee80211_cb {
192 void (*func)(struct ieee80211_node *, void *, int status);
195 #define NET80211_TAG_CALLBACK 0 /* xmit complete callback */
196 int ieee80211_add_callback(struct mbuf *m,
197 void (*func)(struct ieee80211_node *, void *, int), void *arg);
198 void ieee80211_process_callback(struct ieee80211_node *, struct mbuf *, int);
200 void get_random_bytes(void *, size_t);
204 void ieee80211_sysctl_attach(struct ieee80211com *);
205 void ieee80211_sysctl_detach(struct ieee80211com *);
206 void ieee80211_sysctl_vattach(struct ieee80211vap *);
207 void ieee80211_sysctl_vdetach(struct ieee80211vap *);
209 SYSCTL_DECL(_net_wlan);
210 int ieee80211_sysctl_msecs_ticks(SYSCTL_HANDLER_ARGS);
212 void ieee80211_load_module(const char *);
215 * A "policy module" is an adjunct module to net80211 that provides
216 * functionality that typically includes policy decisions. This
217 * modularity enables extensibility and vendor-supplied functionality.
219 #define _IEEE80211_POLICY_MODULE(policy, name, version) \
220 typedef void (*policy##_setup)(int); \
221 SET_DECLARE(policy##_set, policy##_setup); \
223 wlan_##name##_modevent(module_t mod, int type, void *unused) \
225 policy##_setup * const *iter, f; \
228 wlan_serialize_enter(); \
232 SET_FOREACH(iter, policy##_set) { \
241 kprintf("wlan_##name: still in use (%u " \
245 } else if (type == MOD_UNLOAD) { \
246 SET_FOREACH(iter, policy##_set) { \
257 wlan_serialize_exit(); \
261 static moduledata_t name##_mod = { \
263 wlan_##name##_modevent, \
266 DECLARE_MODULE(wlan_##name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);\
267 MODULE_VERSION(wlan_##name, version); \
268 MODULE_DEPEND(wlan_##name, wlan, 1, 1, 1)
271 * Crypto modules implement cipher support.
273 #define IEEE80211_CRYPTO_MODULE(name, version) \
274 _IEEE80211_POLICY_MODULE(crypto, name, version); \
276 name##_modevent(int type) \
278 /* wlan already serialized! */ \
279 if (type == MOD_LOAD) \
280 ieee80211_crypto_register(&name); \
282 ieee80211_crypto_unregister(&name); \
284 TEXT_SET(crypto##_set, name##_modevent)
287 * Scanner modules provide scanning policy.
289 #define IEEE80211_SCANNER_MODULE(name, version) \
290 _IEEE80211_POLICY_MODULE(scanner, name, version)
292 #define IEEE80211_SCANNER_ALG(name, alg, v) \
294 name##_modevent(int type) \
296 /* wlan already serialized! */ \
297 if (type == MOD_LOAD) \
298 ieee80211_scanner_register(alg, &v); \
300 ieee80211_scanner_unregister(alg, &v); \
302 TEXT_SET(scanner_set, name##_modevent); \
305 * ACL modules implement acl policy.
307 #define IEEE80211_ACL_MODULE(name, alg, version) \
308 _IEEE80211_POLICY_MODULE(acl, name, version); \
310 alg##_modevent(int type) \
312 /* wlan already serialized! */ \
313 if (type == MOD_LOAD) \
314 ieee80211_aclator_register(&alg); \
316 ieee80211_aclator_unregister(&alg); \
318 TEXT_SET(acl_set, alg##_modevent); \
321 * Authenticator modules handle 802.1x/WPA authentication.
323 #define IEEE80211_AUTH_MODULE(name, version) \
324 _IEEE80211_POLICY_MODULE(auth, name, version)
326 #define IEEE80211_AUTH_ALG(name, alg, v) \
328 name##_modevent(int type) \
330 /* wlan already serialized! */ \
331 if (type == MOD_LOAD) \
332 ieee80211_authenticator_register(alg, &v); \
334 ieee80211_authenticator_unregister(alg); \
336 TEXT_SET(auth_set, name##_modevent)
339 * Rate control modules provide tx rate control support.
341 #define IEEE80211_RATECTL_MODULE(alg, version) \
342 _IEEE80211_POLICY_MODULE(ratectl, alg, version); \
344 #define IEEE80211_RATECTL_ALG(name, alg, v) \
346 alg##_modevent(int type) \
348 /* wlan already serialized! */ \
349 if (type == MOD_LOAD) \
350 ieee80211_ratectl_register(alg, &v); \
352 ieee80211_ratectl_unregister(alg); \
354 TEXT_SET(ratectl##_set, alg##_modevent)
357 typedef int ieee80211_ioctl_getfunc(struct ieee80211vap *,
358 struct ieee80211req *);
359 SET_DECLARE(ieee80211_ioctl_getset, ieee80211_ioctl_getfunc);
360 #define IEEE80211_IOCTL_GET(_name, _get) TEXT_SET(ieee80211_ioctl_getset, _get)
362 typedef int ieee80211_ioctl_setfunc(struct ieee80211vap *,
363 struct ieee80211req *);
364 SET_DECLARE(ieee80211_ioctl_setset, ieee80211_ioctl_setfunc);
365 #define IEEE80211_IOCTL_SET(_name, _set) TEXT_SET(ieee80211_ioctl_setset, _set)
368 /* XXX this stuff belongs elsewhere */
370 * Message formats for messages from the net80211 layer to user
371 * applications via the routing socket. These messages are appended
372 * to an if_announcemsghdr structure.
374 struct ieee80211_join_event {
378 struct ieee80211_leave_event {
382 struct ieee80211_replay_event {
383 uint8_t iev_src[6]; /* src MAC */
384 uint8_t iev_dst[6]; /* dst MAC */
385 uint8_t iev_cipher; /* cipher type */
386 uint8_t iev_keyix; /* key id/index */
387 uint64_t iev_keyrsc; /* RSC from key */
388 uint64_t iev_rsc; /* RSC from frame */
391 struct ieee80211_michael_event {
392 uint8_t iev_src[6]; /* src MAC */
393 uint8_t iev_dst[6]; /* dst MAC */
394 uint8_t iev_cipher; /* cipher type */
395 uint8_t iev_keyix; /* key id/index */
398 struct ieee80211_wds_event {
402 struct ieee80211_csa_event {
403 uint32_t iev_flags; /* channel flags */
404 uint16_t iev_freq; /* setting in Mhz */
405 uint8_t iev_ieee; /* IEEE channel number */
406 uint8_t iev_mode; /* CSA mode */
407 uint8_t iev_count; /* CSA count */
410 struct ieee80211_cac_event {
411 uint32_t iev_flags; /* channel flags */
412 uint16_t iev_freq; /* setting in Mhz */
413 uint8_t iev_ieee; /* IEEE channel number */
415 uint8_t iev_type; /* IEEE80211_NOTIFY_CAC_* */
418 struct ieee80211_radar_event {
419 uint32_t iev_flags; /* channel flags */
420 uint16_t iev_freq; /* setting in Mhz */
421 uint8_t iev_ieee; /* IEEE channel number */
425 struct ieee80211_auth_event {
429 struct ieee80211_deauth_event {
433 struct ieee80211_country_event {
435 uint8_t iev_cc[2]; /* ISO country code */
438 struct ieee80211_radio_event {
439 uint8_t iev_state; /* 1 on, 0 off */
442 #define RTM_IEEE80211_ASSOC 100 /* station associate (bss mode) */
443 #define RTM_IEEE80211_REASSOC 101 /* station re-associate (bss mode) */
444 #define RTM_IEEE80211_DISASSOC 102 /* station disassociate (bss mode) */
445 #define RTM_IEEE80211_JOIN 103 /* station join (ap mode) */
446 #define RTM_IEEE80211_LEAVE 104 /* station leave (ap mode) */
447 #define RTM_IEEE80211_SCAN 105 /* scan complete, results available */
448 #define RTM_IEEE80211_REPLAY 106 /* sequence counter replay detected */
449 #define RTM_IEEE80211_MICHAEL 107 /* Michael MIC failure detected */
450 #define RTM_IEEE80211_REJOIN 108 /* station re-associate (ap mode) */
451 #define RTM_IEEE80211_WDS 109 /* WDS discovery (ap mode) */
452 #define RTM_IEEE80211_CSA 110 /* Channel Switch Announcement event */
453 #define RTM_IEEE80211_RADAR 111 /* radar event */
454 #define RTM_IEEE80211_CAC 112 /* Channel Availability Check event */
455 #define RTM_IEEE80211_DEAUTH 113 /* station deauthenticate */
456 #define RTM_IEEE80211_AUTH 114 /* station authenticate (ap mode) */
457 #define RTM_IEEE80211_COUNTRY 115 /* discovered country code (sta mode) */
458 #define RTM_IEEE80211_RADIO 116 /* RF kill switch state change */
461 * Structure prepended to raw packets sent through the bpf
462 * interface when set to DLT_IEEE802_11_RADIO. This allows
463 * user applications to specify pretty much everything in
464 * an Atheros tx descriptor. XXX need to generalize.
466 * XXX cannot be more than 14 bytes as it is copied to a sockaddr's
469 struct ieee80211_bpf_params {
470 uint8_t ibp_vers; /* version */
471 #define IEEE80211_BPF_VERSION 0
472 uint8_t ibp_len; /* header length in bytes */
474 #define IEEE80211_BPF_SHORTPRE 0x01 /* tx with short preamble */
475 #define IEEE80211_BPF_NOACK 0x02 /* tx with no ack */
476 #define IEEE80211_BPF_CRYPTO 0x04 /* tx with h/w encryption */
477 #define IEEE80211_BPF_FCS 0x10 /* frame incldues FCS */
478 #define IEEE80211_BPF_DATAPAD 0x20 /* frame includes data padding */
479 #define IEEE80211_BPF_RTS 0x40 /* tx with RTS/CTS */
480 #define IEEE80211_BPF_CTS 0x80 /* tx with CTS only */
481 uint8_t ibp_pri; /* WME/WMM AC+tx antenna */
482 uint8_t ibp_try0; /* series 1 try count */
483 uint8_t ibp_rate0; /* series 1 IEEE tx rate */
484 uint8_t ibp_power; /* tx power (device units) */
485 uint8_t ibp_ctsrate; /* IEEE tx rate for CTS */
486 uint8_t ibp_try1; /* series 2 try count */
487 uint8_t ibp_rate1; /* series 2 IEEE tx rate */
488 uint8_t ibp_try2; /* series 3 try count */
489 uint8_t ibp_rate2; /* series 3 IEEE tx rate */
490 uint8_t ibp_try3; /* series 4 try count */
491 uint8_t ibp_rate3; /* series 4 IEEE tx rate */
493 #endif /* _NET80211_IEEE80211_DRAGONFLY_H_ */