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_
32 #include <sys/param.h>
33 #include <sys/types.h>
35 #include <sys/mutex2.h>
36 #include <sys/sysctl.h>
37 #include <sys/taskqueue.h>
40 * Common state locking definitions.
43 char name[16]; /* e.g. "ath0_com_lock" */
45 } ieee80211_com_lock_t;
46 #define IEEE80211_LOCK_INIT(_ic, _name) do { \
47 ieee80211_com_lock_t *cl = &(_ic)->ic_comlock; \
48 ksnprintf(cl->name, sizeof(cl->name), "%s_com_lock", _name); \
49 lockinit(&cl->lock, cl->name, 0, LK_CANRECURSE); \
51 #define IEEE80211_LOCK_OBJ(_ic) (&(_ic)->ic_comlock.lock)
52 #define IEEE80211_LOCK_DESTROY(_ic) lockuninit(IEEE80211_LOCK_OBJ(_ic))
53 #define IEEE80211_LOCK(_ic) \
54 lockmgr(IEEE80211_LOCK_OBJ(_ic), LK_EXCLUSIVE)
55 #define IEEE80211_UNLOCK(_ic) lockmgr(IEEE80211_LOCK_OBJ(_ic), LK_RELEASE)
56 #define IEEE80211_LOCK_ASSERT(_ic) \
57 KKASSERT(lockstatus(IEEE80211_LOCK_OBJ(_ic), curthread) == LK_EXCLUSIVE)
60 * Node locking definitions.
63 char name[16]; /* e.g. "ath0_node_lock" */
65 } ieee80211_node_lock_t;
66 #define IEEE80211_NODE_LOCK_INIT(_nt, _name) do { \
67 ieee80211_node_lock_t *nl = &(_nt)->nt_nodelock; \
68 ksnprintf(nl->name, sizeof(nl->name), "%s_node_lock", _name); \
69 lockinit(&nl->lock, nl->name, 0, LK_CANRECURSE); \
71 #define IEEE80211_NODE_LOCK_OBJ(_nt) (&(_nt)->nt_nodelock.lock)
72 #define IEEE80211_NODE_LOCK_DESTROY(_nt) \
73 lockuninit(IEEE80211_NODE_LOCK_OBJ(_nt))
74 #define IEEE80211_NODE_LOCK(_nt) \
75 lockmgr(IEEE80211_NODE_LOCK_OBJ(_nt), LK_EXCLUSIVE)
76 #define IEEE80211_NODE_IS_LOCKED(_nt) \
77 (lockstatus(IEEE80211_NODE_LOCK_OBJ(_nt), curthread) == LK_EXCLUSIVE)
78 #define IEEE80211_NODE_UNLOCK(_nt) \
79 lockmgr(IEEE80211_NODE_LOCK_OBJ(_nt), LK_RELEASE)
80 #define IEEE80211_NODE_LOCK_ASSERT(_nt) \
81 KKASSERT(lockstatus(IEEE80211_NODE_LOCK_OBJ(_nt), curthread) \
85 * Node table iteration locking definitions; this protects the
86 * scan generation # used to iterate over the station table
87 * while grabbing+releasing the node lock.
90 char name[16]; /* e.g. "ath0_scan_lock" */
92 } ieee80211_scan_lock_t;
93 #define IEEE80211_NODE_ITERATE_LOCK_INIT(_nt, _name) do { \
94 ieee80211_scan_lock_t *sl = &(_nt)->nt_scanlock; \
95 ksnprintf(sl->name, sizeof(sl->name), "%s_scan_lock", _name); \
96 lockinit(&sl->lock, sl->name, 0, 0); \
98 #define IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt) (&(_nt)->nt_scanlock.lock)
99 #define IEEE80211_NODE_ITERATE_LOCK_DESTROY(_nt) \
100 lockuninit(IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt))
101 #define IEEE80211_NODE_ITERATE_LOCK(_nt) \
102 lockmgr(IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt), LK_EXCLUSIVE)
103 #define IEEE80211_NODE_ITERATE_UNLOCK(_nt) \
104 lockmgr(IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt), LK_RELEASE)
107 * Power-save queue definitions.
109 typedef struct lock ieee80211_psq_lock_t;
110 #define IEEE80211_PSQ_INIT(_psq, _name) \
111 lockinit(&(_psq)->psq_lock, _name, 0, 0)
112 #define IEEE80211_PSQ_DESTROY(_psq) lockuninit(&(_psq)->psq_lock)
113 #define IEEE80211_PSQ_LOCK(_psq) lockmgr(&(_psq)->psq_lock, LK_EXCLUSIVE)
114 #define IEEE80211_PSQ_UNLOCK(_psq) lockmgr(&(_psq)->psq_lock, LK_RELEASE)
116 #ifndef IF_PREPEND_LIST
117 #define _IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do { \
118 (mtail)->m_nextpkt = (ifq)->ifq_head; \
119 if ((ifq)->ifq_tail == NULL) \
120 (ifq)->ifq_tail = (mtail); \
121 (ifq)->ifq_head = (mhead); \
122 (ifq)->ifq_len += (mcount); \
124 #define IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do { \
126 _IF_PREPEND_LIST(ifq, mhead, mtail, mcount); \
129 #endif /* IF_PREPEND_LIST */
132 * Age queue definitions.
134 typedef struct lock ieee80211_ageq_lock_t;
135 #define IEEE80211_AGEQ_INIT(_aq, _name) \
136 lockinit(&(_aq)->aq_lock, _name, 0, 0)
137 #define IEEE80211_AGEQ_DESTROY(_aq) lockuninit(&(_aq)->aq_lock)
138 #define IEEE80211_AGEQ_LOCK(_aq) lockmgr(&(_aq)->aq_lock, LK_EXCLUSIVE)
139 #define IEEE80211_AGEQ_UNLOCK(_aq) lockmgr(&(_aq)->aq_lock, LK_RELEASE)
142 * 802.1x MAC ACL database locking definitions.
144 typedef struct lock acl_lock_t;
145 #define ACL_LOCK_INIT(_as, _name) \
146 lockinit(&(_as)->as_lock, _name, 0, 0)
147 #define ACL_LOCK_DESTROY(_as) lockuninit(&(_as)->as_lock)
148 #define ACL_LOCK(_as) lockmgr(&(_as)->as_lock, LK_EXCLUSIVE)
149 #define ACL_UNLOCK(_as) lockmgr(&(_as)->as_lock, LK_RELEASE)
150 #define ACL_LOCK_ASSERT(_as) \
151 KKASSERT(lockstatus(&(_as)->as_lock, curthread) == LK_EXCLUSIVE)
154 * Node reference counting definitions.
156 * ieee80211_node_initref initialize the reference count to 1
157 * ieee80211_node_incref add a reference
158 * ieee80211_node_decref remove a reference
159 * ieee80211_node_dectestref remove a reference and return 1 if this
160 * is the last reference, otherwise 0
161 * ieee80211_node_refcnt reference count for printing (only)
163 #include <machine/atomic.h>
165 #define ieee80211_node_initref(_ni) \
166 do { ((_ni)->ni_refcnt = 1); } while (0)
167 #define ieee80211_node_incref(_ni) \
168 atomic_add_int(&(_ni)->ni_refcnt, 1)
169 #define ieee80211_node_decref(_ni) \
170 atomic_subtract_int(&(_ni)->ni_refcnt, 1)
171 struct ieee80211_node;
172 int ieee80211_node_dectestref(struct ieee80211_node *ni);
173 #define ieee80211_node_refcnt(_ni) (_ni)->ni_refcnt
177 void ieee80211_drain_ifq(struct ifqueue *);
178 void ieee80211_flush_ifq(struct ifqueue *, struct ieee80211vap *);
180 void ieee80211_vap_destroy(struct ieee80211vap *);
182 #define IFNET_IS_UP_RUNNING(_ifp) \
183 (((_ifp)->if_flags & IFF_UP) && \
184 ((_ifp)->if_drv_flags & IFF_DRV_RUNNING))
186 #define msecs_to_ticks(ms) (((ms)*hz)/1000)
187 #define ticks_to_msecs(t) (1000*(t) / hz)
188 #define ticks_to_secs(t) ((t) / hz)
189 #define time_after(a,b) ((long)(b) - (long)(a) < 0)
190 #define time_before(a,b) time_after(b,a)
191 #define time_after_eq(a,b) ((long)(a) - (long)(b) >= 0)
192 #define time_before_eq(a,b) time_after_eq(b,a)
194 struct mbuf *ieee80211_getmgtframe(uint8_t **frm, int headroom, int pktlen);
197 #define M_ENCAP M_PROTO1 /* 802.11 encap done */
198 #define M_EAPOL M_PROTO3 /* PAE/EAPOL frame */
199 #define M_PWR_SAV M_PROTO4 /* bypass PS handling */
200 #define M_MORE_DATA M_PROTO5 /* more data frames to follow */
201 #define M_FF M_PROTO6 /* fast frame */
202 #define M_TXCB M_PROTO7 /* do tx complete callback */
203 #define M_AMPDU_MPDU M_PROTO8 /* ok for A-MPDU aggregation */
205 (M_FRAG|M_FIRSTFRAG|M_LASTFRAG|M_ENCAP|M_EAPOL|M_PWR_SAV|\
206 M_MORE_DATA|M_FF|M_TXCB|M_AMPDU_MPDU)
209 #define M_AMPDU M_PROTO1 /* A-MPDU subframe */
210 #define M_WEP M_PROTO2 /* WEP done by hardware */
212 #define M_AMPDU_MPDU M_PROTO8 /* A-MPDU re-order done */
214 #define M_80211_RX (M_AMPDU|M_WEP|M_AMPDU_MPDU)
216 #define IEEE80211_MBUF_TX_FLAG_BITS \
217 "\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_RDONLY\5M_ENCAP\6M_WEP\7M_EAPOL" \
218 "\10M_PWR_SAV\11M_MORE_DATA\12M_BCAST\13M_MCAST\14M_FRAG\15M_FIRSTFRAG" \
219 "\16M_LASTFRAG\17M_SKIP_FIREWALL\20M_FREELIST\21M_VLANTAG\22M_PROMISC" \
220 "\23M_NOFREE\24M_FF\25M_TXCB\26M_AMPDU_MPDU\27M_FLOWID"
222 #define IEEE80211_MBUF_RX_FLAG_BITS \
223 "\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_RDONLY\5M_AMPDU\6M_WEP\7M_PROTO3" \
224 "\10M_PROTO4\11M_PROTO5\12M_BCAST\13M_MCAST\14M_FRAG\15M_FIRSTFRAG" \
225 "\16M_LASTFRAG\17M_SKIP_FIREWALL\20M_FREELIST\21M_VLANTAG\22M_PROMISC" \
226 "\23M_NOFREE\24M_PROTO6\25M_PROTO7\26M_AMPDU_MPDU\27M_FLOWID"
229 * Store WME access control bits in the vlan tag.
230 * This is safe since it's done after the packet is classified
231 * (where we use any previous tag) and because it's passed
232 * directly in to the driver and there's no chance someone
233 * else will clobber them on us.
235 #define M_WME_SETAC(m, ac) \
236 ((m)->m_pkthdr.ether_vlantag = (ac))
237 #define M_WME_GETAC(m) ((m)->m_pkthdr.ether_vlantag)
240 * Mbufs on the power save queue are tagged with an age and
241 * timed out. We reuse the hardware checksum field in the
242 * mbuf packet header to store this data.
244 #define M_AGE_SET(m,v) (m->m_pkthdr.csum_data = v)
245 #define M_AGE_GET(m) (m->m_pkthdr.csum_data)
246 #define M_AGE_SUB(m,adj) (m->m_pkthdr.csum_data -= adj)
249 * Store the sequence number.
251 #define M_SEQNO_SET(m, seqno) \
252 ((m)->m_pkthdr.tso_segsz = (seqno))
253 #define M_SEQNO_GET(m) ((m)->m_pkthdr.tso_segsz)
255 #define MTAG_ABI_NET80211 1132948340 /* net80211 ABI */
257 struct ieee80211_cb {
258 void (*func)(struct ieee80211_node *, void *, int status);
261 #define NET80211_TAG_CALLBACK 0 /* xmit complete callback */
262 int ieee80211_add_callback(struct mbuf *m,
263 void (*func)(struct ieee80211_node *, void *, int), void *arg);
264 void ieee80211_process_callback(struct ieee80211_node *, struct mbuf *, int);
266 void get_random_bytes(void *, size_t);
270 void ieee80211_sysctl_attach(struct ieee80211com *);
271 void ieee80211_sysctl_detach(struct ieee80211com *);
272 void ieee80211_sysctl_vattach(struct ieee80211vap *);
273 void ieee80211_sysctl_vdetach(struct ieee80211vap *);
275 SYSCTL_DECL(_net_wlan);
276 int ieee80211_sysctl_msecs_ticks(SYSCTL_HANDLER_ARGS);
278 void ieee80211_load_module(const char *);
281 * A "policy module" is an adjunct module to net80211 that provides
282 * functionality that typically includes policy decisions. This
283 * modularity enables extensibility and vendor-supplied functionality.
285 #define _IEEE80211_POLICY_MODULE(policy, name, version) \
286 typedef void (*policy##_setup)(int); \
287 SET_DECLARE(policy##_set, policy##_setup); \
289 wlan_##name##_modevent(module_t mod, int type, void *unused) \
291 policy##_setup * const *iter, f; \
294 SET_FOREACH(iter, policy##_set) { \
301 kprintf("wlan_##name: still in use (%u dynamic refs)\n",\
305 if (type == MOD_UNLOAD) { \
306 SET_FOREACH(iter, policy##_set) { \
315 static moduledata_t name##_mod = { \
317 wlan_##name##_modevent, \
320 DECLARE_MODULE(wlan_##name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);\
321 MODULE_VERSION(wlan_##name, version); \
322 MODULE_DEPEND(wlan_##name, wlan, 1, 1, 1)
325 * Crypto modules implement cipher support.
327 #define IEEE80211_CRYPTO_MODULE(name, version) \
328 _IEEE80211_POLICY_MODULE(crypto, name, version); \
330 name##_modevent(int type) \
332 if (type == MOD_LOAD) \
333 ieee80211_crypto_register(&name); \
335 ieee80211_crypto_unregister(&name); \
337 TEXT_SET(crypto##_set, name##_modevent)
340 * Scanner modules provide scanning policy.
342 #define IEEE80211_SCANNER_MODULE(name, version) \
343 _IEEE80211_POLICY_MODULE(scanner, name, version)
345 #define IEEE80211_SCANNER_ALG(name, alg, v) \
347 name##_modevent(int type) \
349 if (type == MOD_LOAD) \
350 ieee80211_scanner_register(alg, &v); \
352 ieee80211_scanner_unregister(alg, &v); \
354 TEXT_SET(scanner_set, name##_modevent); \
357 * ACL modules implement acl policy.
359 #define IEEE80211_ACL_MODULE(name, alg, version) \
360 _IEEE80211_POLICY_MODULE(acl, name, version); \
362 alg##_modevent(int type) \
364 if (type == MOD_LOAD) \
365 ieee80211_aclator_register(&alg); \
367 ieee80211_aclator_unregister(&alg); \
369 TEXT_SET(acl_set, alg##_modevent); \
372 * Authenticator modules handle 802.1x/WPA authentication.
374 #define IEEE80211_AUTH_MODULE(name, version) \
375 _IEEE80211_POLICY_MODULE(auth, name, version)
377 #define IEEE80211_AUTH_ALG(name, alg, v) \
379 name##_modevent(int type) \
381 if (type == MOD_LOAD) \
382 ieee80211_authenticator_register(alg, &v); \
384 ieee80211_authenticator_unregister(alg); \
386 TEXT_SET(auth_set, name##_modevent)
389 * Rate control modules provide tx rate control support.
391 #define IEEE80211_RATE_MODULE(alg, version) \
392 _IEEE80211_POLICY_MODULE(rate, alg, version); \
394 alg##_modevent(int type) \
396 /* XXX nothing to do until the rate control framework arrives */\
398 TEXT_SET(rate##_set, alg##_modevent)
401 typedef int ieee80211_ioctl_getfunc(struct ieee80211vap *,
402 struct ieee80211req *);
403 SET_DECLARE(ieee80211_ioctl_getset, ieee80211_ioctl_getfunc);
404 #define IEEE80211_IOCTL_GET(_name, _get) TEXT_SET(ieee80211_ioctl_getset, _get)
406 typedef int ieee80211_ioctl_setfunc(struct ieee80211vap *,
407 struct ieee80211req *);
408 SET_DECLARE(ieee80211_ioctl_setset, ieee80211_ioctl_setfunc);
409 #define IEEE80211_IOCTL_SET(_name, _set) TEXT_SET(ieee80211_ioctl_setset, _set)
412 /* XXX this stuff belongs elsewhere */
414 * Message formats for messages from the net80211 layer to user
415 * applications via the routing socket. These messages are appended
416 * to an if_announcemsghdr structure.
418 struct ieee80211_join_event {
422 struct ieee80211_leave_event {
426 struct ieee80211_replay_event {
427 uint8_t iev_src[6]; /* src MAC */
428 uint8_t iev_dst[6]; /* dst MAC */
429 uint8_t iev_cipher; /* cipher type */
430 uint8_t iev_keyix; /* key id/index */
431 uint64_t iev_keyrsc; /* RSC from key */
432 uint64_t iev_rsc; /* RSC from frame */
435 struct ieee80211_michael_event {
436 uint8_t iev_src[6]; /* src MAC */
437 uint8_t iev_dst[6]; /* dst MAC */
438 uint8_t iev_cipher; /* cipher type */
439 uint8_t iev_keyix; /* key id/index */
442 struct ieee80211_wds_event {
446 struct ieee80211_csa_event {
447 uint32_t iev_flags; /* channel flags */
448 uint16_t iev_freq; /* setting in Mhz */
449 uint8_t iev_ieee; /* IEEE channel number */
450 uint8_t iev_mode; /* CSA mode */
451 uint8_t iev_count; /* CSA count */
454 struct ieee80211_cac_event {
455 uint32_t iev_flags; /* channel flags */
456 uint16_t iev_freq; /* setting in Mhz */
457 uint8_t iev_ieee; /* IEEE channel number */
459 uint8_t iev_type; /* IEEE80211_NOTIFY_CAC_* */
462 struct ieee80211_radar_event {
463 uint32_t iev_flags; /* channel flags */
464 uint16_t iev_freq; /* setting in Mhz */
465 uint8_t iev_ieee; /* IEEE channel number */
469 struct ieee80211_auth_event {
473 struct ieee80211_deauth_event {
477 struct ieee80211_country_event {
479 uint8_t iev_cc[2]; /* ISO country code */
482 struct ieee80211_radio_event {
483 uint8_t iev_state; /* 1 on, 0 off */
486 #define RTM_IEEE80211_ASSOC 100 /* station associate (bss mode) */
487 #define RTM_IEEE80211_REASSOC 101 /* station re-associate (bss mode) */
488 #define RTM_IEEE80211_DISASSOC 102 /* station disassociate (bss mode) */
489 #define RTM_IEEE80211_JOIN 103 /* station join (ap mode) */
490 #define RTM_IEEE80211_LEAVE 104 /* station leave (ap mode) */
491 #define RTM_IEEE80211_SCAN 105 /* scan complete, results available */
492 #define RTM_IEEE80211_REPLAY 106 /* sequence counter replay detected */
493 #define RTM_IEEE80211_MICHAEL 107 /* Michael MIC failure detected */
494 #define RTM_IEEE80211_REJOIN 108 /* station re-associate (ap mode) */
495 #define RTM_IEEE80211_WDS 109 /* WDS discovery (ap mode) */
496 #define RTM_IEEE80211_CSA 110 /* Channel Switch Announcement event */
497 #define RTM_IEEE80211_RADAR 111 /* radar event */
498 #define RTM_IEEE80211_CAC 112 /* Channel Availability Check event */
499 #define RTM_IEEE80211_DEAUTH 113 /* station deauthenticate */
500 #define RTM_IEEE80211_AUTH 114 /* station authenticate (ap mode) */
501 #define RTM_IEEE80211_COUNTRY 115 /* discovered country code (sta mode) */
502 #define RTM_IEEE80211_RADIO 116 /* RF kill switch state change */
505 * Structure prepended to raw packets sent through the bpf
506 * interface when set to DLT_IEEE802_11_RADIO. This allows
507 * user applications to specify pretty much everything in
508 * an Atheros tx descriptor. XXX need to generalize.
510 * XXX cannot be more than 14 bytes as it is copied to a sockaddr's
513 struct ieee80211_bpf_params {
514 uint8_t ibp_vers; /* version */
515 #define IEEE80211_BPF_VERSION 0
516 uint8_t ibp_len; /* header length in bytes */
518 #define IEEE80211_BPF_SHORTPRE 0x01 /* tx with short preamble */
519 #define IEEE80211_BPF_NOACK 0x02 /* tx with no ack */
520 #define IEEE80211_BPF_CRYPTO 0x04 /* tx with h/w encryption */
521 #define IEEE80211_BPF_FCS 0x10 /* frame incldues FCS */
522 #define IEEE80211_BPF_DATAPAD 0x20 /* frame includes data padding */
523 #define IEEE80211_BPF_RTS 0x40 /* tx with RTS/CTS */
524 #define IEEE80211_BPF_CTS 0x80 /* tx with CTS only */
525 uint8_t ibp_pri; /* WME/WMM AC+tx antenna */
526 uint8_t ibp_try0; /* series 1 try count */
527 uint8_t ibp_rate0; /* series 1 IEEE tx rate */
528 uint8_t ibp_power; /* tx power (device units) */
529 uint8_t ibp_ctsrate; /* IEEE tx rate for CTS */
530 uint8_t ibp_try1; /* series 2 try count */
531 uint8_t ibp_rate1; /* series 2 IEEE tx rate */
532 uint8_t ibp_try2; /* series 3 try count */
533 uint8_t ibp_rate2; /* series 3 IEEE tx rate */
534 uint8_t ibp_try3; /* series 4 try count */
535 uint8_t ibp_rate3; /* series 4 IEEE tx rate */
537 #endif /* _NET80211_IEEE80211_DRAGONFLY_H_ */