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 $
28 #ifndef _NET80211_IEEE80211_DRAGONFLY_H_
29 #define _NET80211_IEEE80211_DRAGONFLY_H_
33 #include <sys/param.h>
34 #include <sys/types.h>
35 #include <sys/serialize.h>
36 #include <sys/sysctl.h>
37 #include <sys/condvar.h>
38 #include <sys/taskqueue.h>
40 #include <sys/mutex2.h>
41 #include <sys/serialize2.h>
43 #ifndef IF_PREPEND_LIST
45 #define _IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do { \
46 (mtail)->m_nextpkt = (ifq)->ifq_head; \
47 if ((ifq)->ifq_tail == NULL) \
48 (ifq)->ifq_tail = (mtail); \
49 (ifq)->ifq_head = (mhead); \
50 (ifq)->ifq_len += (mcount); \
53 #define IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do { \
54 wlan_assert_serialized(); \
55 _IF_PREPEND_LIST(ifq, mhead, mtail, mcount); \
58 #endif /* IF_PREPEND_LIST */
61 * Global serializer (operates like a non-reentrant lockmgr lock)
63 extern struct lwkt_serialize wlan_global_serializer;
65 void wlan_serialize_enter(void);
66 void wlan_serialize_exit(void);
67 int wlan_serialize_sleep(void *ident, int flags, const char *wmesg, int timo);
70 wlan_assert_serialized(void)
72 ASSERT_SERIALIZED(&wlan_global_serializer);
76 * wlan condition variables. Assume the global serializer is held.
78 void wlan_cv_init(struct cv *cv, const char *desc);
79 int wlan_cv_timedwait(struct cv *cv, int ticks);
80 void wlan_cv_wait(struct cv *cv);
81 void wlan_cv_signal(struct cv *cv, int broadcast);
84 * Node reference counting definitions.
86 * ieee80211_node_initref initialize the reference count to 1
87 * ieee80211_node_incref add a reference
88 * ieee80211_node_decref remove a reference
89 * ieee80211_node_dectestref remove a reference and return 1 if this
90 * is the last reference, otherwise 0
91 * ieee80211_node_refcnt reference count for printing (only)
93 #include <machine/atomic.h>
95 #define ieee80211_node_initref(_ni) \
96 do { ((_ni)->ni_refcnt = 1); } while (0)
97 #define ieee80211_node_incref(_ni) \
98 atomic_add_int(&(_ni)->ni_refcnt, 1)
99 #define ieee80211_node_decref(_ni) \
100 atomic_subtract_int(&(_ni)->ni_refcnt, 1)
101 struct ieee80211_node;
102 int ieee80211_node_dectestref(struct ieee80211_node *ni);
103 #define ieee80211_node_refcnt(_ni) (_ni)->ni_refcnt
107 void ieee80211_drain_ifq(struct ifqueue *);
108 void ieee80211_flush_ifq(struct ifqueue *, struct ieee80211vap *);
110 void ieee80211_vap_destroy(struct ieee80211vap *);
111 int ieee80211_handoff(struct ifnet *, struct mbuf *);
112 uint16_t ieee80211_txtime(struct ieee80211_node *, u_int, uint8_t, uint32_t);
114 #define IFNET_IS_UP_RUNNING(_ifp) \
115 (((_ifp)->if_flags & IFF_UP) && \
116 ((_ifp)->if_flags & IFF_RUNNING))
118 #define msecs_to_ticks(ms) (((ms)*hz)/1000)
119 #define ticks_to_msecs(t) (1000*(t) / hz)
120 #define ticks_to_secs(t) ((t) / hz)
121 #define time_after(a,b) ((long)(b) - (long)(a) < 0)
122 #define time_before(a,b) time_after(b,a)
123 #define time_after_eq(a,b) ((long)(a) - (long)(b) >= 0)
124 #define time_before_eq(a,b) time_after_eq(b,a)
126 struct mbuf *ieee80211_getmgtframe(uint8_t **frm, int headroom, int pktlen);
129 #define M_ENCAP M_PROTO1 /* 802.11 encap done */
130 #define M_EAPOL M_PROTO3 /* PAE/EAPOL frame */
131 #define M_PWR_SAV M_PROTO4 /* bypass PS handling */
132 #define M_MORE_DATA M_PROTO5 /* more data frames to follow */
133 #define M_FF M_PROTO6 /* fast frame */
134 #define M_TXCB M_PROTO7 /* do tx complete callback */
135 #define M_AMPDU_MPDU M_PROTO8 /* ok for A-MPDU aggregation */
137 (M_FRAG|M_FIRSTFRAG|M_LASTFRAG|M_ENCAP|M_EAPOL|M_PWR_SAV|\
138 M_MORE_DATA|M_FF|M_TXCB|M_AMPDU_MPDU)
141 #define M_AMPDU M_PROTO1 /* A-MPDU subframe */
142 #define M_WEP M_PROTO2 /* WEP done by hardware */
144 #define M_AMPDU_MPDU M_PROTO8 /* A-MPDU re-order done */
146 #define M_80211_RX (M_AMPDU|M_WEP|M_AMPDU_MPDU)
148 #define IEEE80211_MBUF_TX_FLAG_BITS \
149 "\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_RDONLY\5M_ENCAP\6M_WEP\7M_EAPOL" \
150 "\10M_PWR_SAV\11M_MORE_DATA\12M_BCAST\13M_MCAST\14M_FRAG\15M_FIRSTFRAG" \
151 "\16M_LASTFRAG\17M_SKIP_FIREWALL\20M_FREELIST\21M_VLANTAG\22M_PROMISC" \
152 "\23M_NOFREE\24M_FF\25M_TXCB\26M_AMPDU_MPDU\27M_FLOWID"
154 #define IEEE80211_MBUF_RX_FLAG_BITS \
155 "\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_RDONLY\5M_AMPDU\6M_WEP\7M_PROTO3" \
156 "\10M_PROTO4\11M_PROTO5\12M_BCAST\13M_MCAST\14M_FRAG\15M_FIRSTFRAG" \
157 "\16M_LASTFRAG\17M_SKIP_FIREWALL\20M_FREELIST\21M_VLANTAG\22M_PROMISC" \
158 "\23M_NOFREE\24M_PROTO6\25M_PROTO7\26M_AMPDU_MPDU\27M_FLOWID"
161 * Store WME access control bits in the vlan tag.
162 * This is safe since it's done after the packet is classified
163 * (where we use any previous tag) and because it's passed
164 * directly in to the driver and there's no chance someone
165 * else will clobber them on us.
167 #define M_WME_SETAC(m, ac) \
168 ((m)->m_pkthdr.ether_vlantag = (ac))
169 #define M_WME_GETAC(m) ((m)->m_pkthdr.ether_vlantag)
172 * Mbufs on the power save queue are tagged with an age and
173 * timed out. We reuse the hardware checksum field in the
174 * mbuf packet header to store this data.
176 #define M_AGE_SET(m,v) (m->m_pkthdr.csum_data = v)
177 #define M_AGE_GET(m) (m->m_pkthdr.csum_data)
178 #define M_AGE_SUB(m,adj) (m->m_pkthdr.csum_data -= adj)
181 * Store the sequence number.
183 #define M_SEQNO_SET(m, seqno) \
184 ((m)->m_pkthdr.wlan_seqno = (seqno))
185 #define M_SEQNO_GET(m) ((m)->m_pkthdr.wlan_seqno)
187 #define MTAG_ABI_NET80211 1132948340 /* net80211 ABI */
189 struct ieee80211_cb {
190 void (*func)(struct ieee80211_node *, void *, int status);
193 #define NET80211_TAG_CALLBACK 0 /* xmit complete callback */
194 int ieee80211_add_callback(struct mbuf *m,
195 void (*func)(struct ieee80211_node *, void *, int), void *arg);
196 void ieee80211_process_callback(struct ieee80211_node *, struct mbuf *, int);
198 void get_random_bytes(void *, size_t);
202 void ieee80211_sysctl_attach(struct ieee80211com *);
203 void ieee80211_sysctl_detach(struct ieee80211com *);
204 void ieee80211_sysctl_vattach(struct ieee80211vap *);
205 void ieee80211_sysctl_vdetach(struct ieee80211vap *);
207 SYSCTL_DECL(_net_wlan);
208 int ieee80211_sysctl_msecs_ticks(SYSCTL_HANDLER_ARGS);
210 void ieee80211_load_module(const char *);
213 * A "policy module" is an adjunct module to net80211 that provides
214 * functionality that typically includes policy decisions. This
215 * modularity enables extensibility and vendor-supplied functionality.
217 #define _IEEE80211_POLICY_MODULE(policy, name, version) \
218 typedef void (*policy##_setup)(int); \
219 SET_DECLARE(policy##_set, policy##_setup); \
221 wlan_##name##_modevent(module_t mod, int type, void *unused) \
223 policy##_setup * const *iter, f; \
226 SET_FOREACH(iter, policy##_set) { \
233 kprintf("wlan_##name: still in use (%u dynamic refs)\n",\
237 if (type == MOD_UNLOAD) { \
238 SET_FOREACH(iter, policy##_set) { \
247 static moduledata_t name##_mod = { \
249 wlan_##name##_modevent, \
252 DECLARE_MODULE(wlan_##name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);\
253 MODULE_VERSION(wlan_##name, version); \
254 MODULE_DEPEND(wlan_##name, wlan, 1, 1, 1)
257 * Crypto modules implement cipher support.
259 #define IEEE80211_CRYPTO_MODULE(name, version) \
260 _IEEE80211_POLICY_MODULE(crypto, name, version); \
262 name##_modevent(int type) \
264 if (type == MOD_LOAD) \
265 ieee80211_crypto_register(&name); \
267 ieee80211_crypto_unregister(&name); \
269 TEXT_SET(crypto##_set, name##_modevent)
272 * Scanner modules provide scanning policy.
274 #define IEEE80211_SCANNER_MODULE(name, version) \
275 _IEEE80211_POLICY_MODULE(scanner, name, version)
277 #define IEEE80211_SCANNER_ALG(name, alg, v) \
279 name##_modevent(int type) \
281 if (type == MOD_LOAD) \
282 ieee80211_scanner_register(alg, &v); \
284 ieee80211_scanner_unregister(alg, &v); \
286 TEXT_SET(scanner_set, name##_modevent); \
289 * ACL modules implement acl policy.
291 #define IEEE80211_ACL_MODULE(name, alg, version) \
292 _IEEE80211_POLICY_MODULE(acl, name, version); \
294 alg##_modevent(int type) \
296 if (type == MOD_LOAD) \
297 ieee80211_aclator_register(&alg); \
299 ieee80211_aclator_unregister(&alg); \
301 TEXT_SET(acl_set, alg##_modevent); \
304 * Authenticator modules handle 802.1x/WPA authentication.
306 #define IEEE80211_AUTH_MODULE(name, version) \
307 _IEEE80211_POLICY_MODULE(auth, name, version)
309 #define IEEE80211_AUTH_ALG(name, alg, v) \
311 name##_modevent(int type) \
313 if (type == MOD_LOAD) \
314 ieee80211_authenticator_register(alg, &v); \
316 ieee80211_authenticator_unregister(alg); \
318 TEXT_SET(auth_set, name##_modevent)
321 * Rate control modules provide tx rate control support.
323 #define IEEE80211_RATECTL_MODULE(alg, version) \
324 _IEEE80211_POLICY_MODULE(ratectl, alg, version); \
326 #define IEEE80211_RATECTL_ALG(name, alg, v) \
328 alg##_modevent(int type) \
330 if (type == MOD_LOAD) \
331 ieee80211_ratectl_register(alg, &v); \
333 ieee80211_ratectl_unregister(alg); \
335 TEXT_SET(ratectl##_set, alg##_modevent)
338 typedef int ieee80211_ioctl_getfunc(struct ieee80211vap *,
339 struct ieee80211req *);
340 SET_DECLARE(ieee80211_ioctl_getset, ieee80211_ioctl_getfunc);
341 #define IEEE80211_IOCTL_GET(_name, _get) TEXT_SET(ieee80211_ioctl_getset, _get)
343 typedef int ieee80211_ioctl_setfunc(struct ieee80211vap *,
344 struct ieee80211req *);
345 SET_DECLARE(ieee80211_ioctl_setset, ieee80211_ioctl_setfunc);
346 #define IEEE80211_IOCTL_SET(_name, _set) TEXT_SET(ieee80211_ioctl_setset, _set)
349 /* XXX this stuff belongs elsewhere */
351 * Message formats for messages from the net80211 layer to user
352 * applications via the routing socket. These messages are appended
353 * to an if_announcemsghdr structure.
355 struct ieee80211_join_event {
359 struct ieee80211_leave_event {
363 struct ieee80211_replay_event {
364 uint8_t iev_src[6]; /* src MAC */
365 uint8_t iev_dst[6]; /* dst MAC */
366 uint8_t iev_cipher; /* cipher type */
367 uint8_t iev_keyix; /* key id/index */
368 uint64_t iev_keyrsc; /* RSC from key */
369 uint64_t iev_rsc; /* RSC from frame */
372 struct ieee80211_michael_event {
373 uint8_t iev_src[6]; /* src MAC */
374 uint8_t iev_dst[6]; /* dst MAC */
375 uint8_t iev_cipher; /* cipher type */
376 uint8_t iev_keyix; /* key id/index */
379 struct ieee80211_wds_event {
383 struct ieee80211_csa_event {
384 uint32_t iev_flags; /* channel flags */
385 uint16_t iev_freq; /* setting in Mhz */
386 uint8_t iev_ieee; /* IEEE channel number */
387 uint8_t iev_mode; /* CSA mode */
388 uint8_t iev_count; /* CSA count */
391 struct ieee80211_cac_event {
392 uint32_t iev_flags; /* channel flags */
393 uint16_t iev_freq; /* setting in Mhz */
394 uint8_t iev_ieee; /* IEEE channel number */
396 uint8_t iev_type; /* IEEE80211_NOTIFY_CAC_* */
399 struct ieee80211_radar_event {
400 uint32_t iev_flags; /* channel flags */
401 uint16_t iev_freq; /* setting in Mhz */
402 uint8_t iev_ieee; /* IEEE channel number */
406 struct ieee80211_auth_event {
410 struct ieee80211_deauth_event {
414 struct ieee80211_country_event {
416 uint8_t iev_cc[2]; /* ISO country code */
419 struct ieee80211_radio_event {
420 uint8_t iev_state; /* 1 on, 0 off */
423 #define RTM_IEEE80211_ASSOC 100 /* station associate (bss mode) */
424 #define RTM_IEEE80211_REASSOC 101 /* station re-associate (bss mode) */
425 #define RTM_IEEE80211_DISASSOC 102 /* station disassociate (bss mode) */
426 #define RTM_IEEE80211_JOIN 103 /* station join (ap mode) */
427 #define RTM_IEEE80211_LEAVE 104 /* station leave (ap mode) */
428 #define RTM_IEEE80211_SCAN 105 /* scan complete, results available */
429 #define RTM_IEEE80211_REPLAY 106 /* sequence counter replay detected */
430 #define RTM_IEEE80211_MICHAEL 107 /* Michael MIC failure detected */
431 #define RTM_IEEE80211_REJOIN 108 /* station re-associate (ap mode) */
432 #define RTM_IEEE80211_WDS 109 /* WDS discovery (ap mode) */
433 #define RTM_IEEE80211_CSA 110 /* Channel Switch Announcement event */
434 #define RTM_IEEE80211_RADAR 111 /* radar event */
435 #define RTM_IEEE80211_CAC 112 /* Channel Availability Check event */
436 #define RTM_IEEE80211_DEAUTH 113 /* station deauthenticate */
437 #define RTM_IEEE80211_AUTH 114 /* station authenticate (ap mode) */
438 #define RTM_IEEE80211_COUNTRY 115 /* discovered country code (sta mode) */
439 #define RTM_IEEE80211_RADIO 116 /* RF kill switch state change */
442 * Structure prepended to raw packets sent through the bpf
443 * interface when set to DLT_IEEE802_11_RADIO. This allows
444 * user applications to specify pretty much everything in
445 * an Atheros tx descriptor. XXX need to generalize.
447 * XXX cannot be more than 14 bytes as it is copied to a sockaddr's
450 struct ieee80211_bpf_params {
451 uint8_t ibp_vers; /* version */
452 #define IEEE80211_BPF_VERSION 0
453 uint8_t ibp_len; /* header length in bytes */
455 #define IEEE80211_BPF_SHORTPRE 0x01 /* tx with short preamble */
456 #define IEEE80211_BPF_NOACK 0x02 /* tx with no ack */
457 #define IEEE80211_BPF_CRYPTO 0x04 /* tx with h/w encryption */
458 #define IEEE80211_BPF_FCS 0x10 /* frame incldues FCS */
459 #define IEEE80211_BPF_DATAPAD 0x20 /* frame includes data padding */
460 #define IEEE80211_BPF_RTS 0x40 /* tx with RTS/CTS */
461 #define IEEE80211_BPF_CTS 0x80 /* tx with CTS only */
462 uint8_t ibp_pri; /* WME/WMM AC+tx antenna */
463 uint8_t ibp_try0; /* series 1 try count */
464 uint8_t ibp_rate0; /* series 1 IEEE tx rate */
465 uint8_t ibp_power; /* tx power (device units) */
466 uint8_t ibp_ctsrate; /* IEEE tx rate for CTS */
467 uint8_t ibp_try1; /* series 2 try count */
468 uint8_t ibp_rate1; /* series 2 IEEE tx rate */
469 uint8_t ibp_try2; /* series 3 try count */
470 uint8_t ibp_rate2; /* series 3 IEEE tx rate */
471 uint8_t ibp_try3; /* series 4 try count */
472 uint8_t ibp_rate3; /* series 4 IEEE tx rate */
474 #endif /* _NET80211_IEEE80211_DRAGONFLY_H_ */