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>
39 #define IF_LOCK(_lock) /* */
40 #define IF_UNLOCK(_lock) /* */
43 * Common state locking definitions.
46 char name[16]; /* e.g. "ath0_com_lock" */
48 } ieee80211_com_lock_t;
49 #define IEEE80211_LOCK_INIT(_ic, _name) do { \
50 ieee80211_com_lock_t *cl = &(_ic)->ic_comlock; \
51 ksnprintf(cl->name, sizeof(cl->name), "%s_com_lock", _name); \
52 lockinit(&cl->lock, cl->name, 0, LK_CANRECURSE); \
54 #define IEEE80211_LOCK_OBJ(_ic) (&(_ic)->ic_comlock.lock)
55 #define IEEE80211_LOCK_DESTROY(_ic) lockuninit(IEEE80211_LOCK_OBJ(_ic))
56 #define IEEE80211_LOCK(_ic) \
57 lockmgr(IEEE80211_LOCK_OBJ(_ic), LK_EXCLUSIVE)
58 #define IEEE80211_UNLOCK(_ic) lockmgr(IEEE80211_LOCK_OBJ(_ic), LK_RELEASE)
59 #define IEEE80211_LOCK_ASSERT(_ic) \
60 KKASSERT(lockstatus(IEEE80211_LOCK_OBJ(_ic), curthread) == LK_EXCLUSIVE)
63 * Node locking definitions.
66 char name[16]; /* e.g. "ath0_node_lock" */
68 } ieee80211_node_lock_t;
69 #define IEEE80211_NODE_LOCK_INIT(_nt, _name) do { \
70 ieee80211_node_lock_t *nl = &(_nt)->nt_nodelock; \
71 ksnprintf(nl->name, sizeof(nl->name), "%s_node_lock", _name); \
72 lockinit(&nl->lock, nl->name, 0, LK_CANRECURSE); \
74 #define IEEE80211_NODE_LOCK_OBJ(_nt) (&(_nt)->nt_nodelock.lock)
75 #define IEEE80211_NODE_LOCK_DESTROY(_nt) \
76 lockuninit(IEEE80211_NODE_LOCK_OBJ(_nt))
77 #define IEEE80211_NODE_LOCK(_nt) \
78 lockmgr(IEEE80211_NODE_LOCK_OBJ(_nt), LK_EXCLUSIVE)
79 #define IEEE80211_NODE_IS_LOCKED(_nt) \
80 (lockstatus(IEEE80211_NODE_LOCK_OBJ(_nt), curthread) == LK_EXCLUSIVE)
81 #define IEEE80211_NODE_UNLOCK(_nt) \
82 lockmgr(IEEE80211_NODE_LOCK_OBJ(_nt), LK_RELEASE)
83 #define IEEE80211_NODE_LOCK_ASSERT(_nt) \
84 KKASSERT(lockstatus(IEEE80211_NODE_LOCK_OBJ(_nt), curthread) \
88 * Node table iteration locking definitions; this protects the
89 * scan generation # used to iterate over the station table
90 * while grabbing+releasing the node lock.
93 char name[16]; /* e.g. "ath0_scan_lock" */
95 } ieee80211_scan_lock_t;
96 #define IEEE80211_NODE_ITERATE_LOCK_INIT(_nt, _name) do { \
97 ieee80211_scan_lock_t *sl = &(_nt)->nt_scanlock; \
98 ksnprintf(sl->name, sizeof(sl->name), "%s_scan_lock", _name); \
99 lockinit(&sl->lock, sl->name, 0, 0); \
101 #define IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt) (&(_nt)->nt_scanlock.lock)
102 #define IEEE80211_NODE_ITERATE_LOCK_DESTROY(_nt) \
103 lockuninit(IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt))
104 #define IEEE80211_NODE_ITERATE_LOCK(_nt) \
105 lockmgr(IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt), LK_EXCLUSIVE)
106 #define IEEE80211_NODE_ITERATE_UNLOCK(_nt) \
107 lockmgr(IEEE80211_NODE_ITERATE_LOCK_OBJ(_nt), LK_RELEASE)
110 * Power-save queue definitions.
112 typedef struct lock ieee80211_psq_lock_t;
113 #define IEEE80211_PSQ_INIT(_psq, _name) \
114 lockinit(&(_psq)->psq_lock, _name, 0, 0)
115 #define IEEE80211_PSQ_DESTROY(_psq) lockuninit(&(_psq)->psq_lock)
116 #define IEEE80211_PSQ_LOCK(_psq) lockmgr(&(_psq)->psq_lock, LK_EXCLUSIVE)
117 #define IEEE80211_PSQ_UNLOCK(_psq) lockmgr(&(_psq)->psq_lock, LK_RELEASE)
119 #ifndef IF_PREPEND_LIST
120 #define _IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do { \
121 (mtail)->m_nextpkt = (ifq)->ifq_head; \
122 if ((ifq)->ifq_tail == NULL) \
123 (ifq)->ifq_tail = (mtail); \
124 (ifq)->ifq_head = (mhead); \
125 (ifq)->ifq_len += (mcount); \
127 #define IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do { \
129 _IF_PREPEND_LIST(ifq, mhead, mtail, mcount); \
132 #endif /* IF_PREPEND_LIST */
135 * Age queue definitions.
137 typedef struct lock ieee80211_ageq_lock_t;
138 #define IEEE80211_AGEQ_INIT(_aq, _name) \
139 lockinit(&(_aq)->aq_lock, _name, 0, 0)
140 #define IEEE80211_AGEQ_DESTROY(_aq) lockuninit(&(_aq)->aq_lock)
141 #define IEEE80211_AGEQ_LOCK(_aq) lockmgr(&(_aq)->aq_lock, LK_EXCLUSIVE)
142 #define IEEE80211_AGEQ_UNLOCK(_aq) lockmgr(&(_aq)->aq_lock, LK_RELEASE)
145 * 802.1x MAC ACL database locking definitions.
147 typedef struct lock acl_lock_t;
148 #define ACL_LOCK_INIT(_as, _name) \
149 lockinit(&(_as)->as_lock, _name, 0, 0)
150 #define ACL_LOCK_DESTROY(_as) lockuninit(&(_as)->as_lock)
151 #define ACL_LOCK(_as) lockmgr(&(_as)->as_lock, LK_EXCLUSIVE)
152 #define ACL_UNLOCK(_as) lockmgr(&(_as)->as_lock, LK_RELEASE)
153 #define ACL_LOCK_ASSERT(_as) \
154 KKASSERT(lockstatus(&(_as)->as_lock, curthread) == LK_EXCLUSIVE)
157 * Node reference counting definitions.
159 * ieee80211_node_initref initialize the reference count to 1
160 * ieee80211_node_incref add a reference
161 * ieee80211_node_decref remove a reference
162 * ieee80211_node_dectestref remove a reference and return 1 if this
163 * is the last reference, otherwise 0
164 * ieee80211_node_refcnt reference count for printing (only)
166 #include <machine/atomic.h>
168 #define ieee80211_node_initref(_ni) \
169 do { ((_ni)->ni_refcnt = 1); } while (0)
170 #define ieee80211_node_incref(_ni) \
171 atomic_add_int(&(_ni)->ni_refcnt, 1)
172 #define ieee80211_node_decref(_ni) \
173 atomic_subtract_int(&(_ni)->ni_refcnt, 1)
174 struct ieee80211_node;
175 int ieee80211_node_dectestref(struct ieee80211_node *ni);
176 #define ieee80211_node_refcnt(_ni) (_ni)->ni_refcnt
180 void ieee80211_drain_ifq(struct ifqueue *);
181 void ieee80211_flush_ifq(struct ifqueue *, struct ieee80211vap *);
183 void ieee80211_vap_destroy(struct ieee80211vap *);
185 #define IFNET_IS_UP_RUNNING(_ifp) \
186 (((_ifp)->if_flags & IFF_UP) && \
187 ((_ifp)->if_flags & IFF_RUNNING))
189 #define msecs_to_ticks(ms) (((ms)*hz)/1000)
190 #define ticks_to_msecs(t) (1000*(t) / hz)
191 #define ticks_to_secs(t) ((t) / hz)
192 #define time_after(a,b) ((long)(b) - (long)(a) < 0)
193 #define time_before(a,b) time_after(b,a)
194 #define time_after_eq(a,b) ((long)(a) - (long)(b) >= 0)
195 #define time_before_eq(a,b) time_after_eq(b,a)
197 struct mbuf *ieee80211_getmgtframe(uint8_t **frm, int headroom, int pktlen);
200 #define M_ENCAP M_PROTO1 /* 802.11 encap done */
201 #define M_EAPOL M_PROTO3 /* PAE/EAPOL frame */
202 #define M_PWR_SAV M_PROTO4 /* bypass PS handling */
203 #define M_MORE_DATA M_PROTO5 /* more data frames to follow */
204 #define M_FF M_PROTO6 /* fast frame */
205 #define M_TXCB M_PROTO7 /* do tx complete callback */
206 #define M_AMPDU_MPDU M_PROTO8 /* ok for A-MPDU aggregation */
208 (M_FRAG|M_FIRSTFRAG|M_LASTFRAG|M_ENCAP|M_EAPOL|M_PWR_SAV|\
209 M_MORE_DATA|M_FF|M_TXCB|M_AMPDU_MPDU)
212 #define M_AMPDU M_PROTO1 /* A-MPDU subframe */
213 #define M_WEP M_PROTO2 /* WEP done by hardware */
215 #define M_AMPDU_MPDU M_PROTO8 /* A-MPDU re-order done */
217 #define M_80211_RX (M_AMPDU|M_WEP|M_AMPDU_MPDU)
219 #define IEEE80211_MBUF_TX_FLAG_BITS \
220 "\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_RDONLY\5M_ENCAP\6M_WEP\7M_EAPOL" \
221 "\10M_PWR_SAV\11M_MORE_DATA\12M_BCAST\13M_MCAST\14M_FRAG\15M_FIRSTFRAG" \
222 "\16M_LASTFRAG\17M_SKIP_FIREWALL\20M_FREELIST\21M_VLANTAG\22M_PROMISC" \
223 "\23M_NOFREE\24M_FF\25M_TXCB\26M_AMPDU_MPDU\27M_FLOWID"
225 #define IEEE80211_MBUF_RX_FLAG_BITS \
226 "\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_RDONLY\5M_AMPDU\6M_WEP\7M_PROTO3" \
227 "\10M_PROTO4\11M_PROTO5\12M_BCAST\13M_MCAST\14M_FRAG\15M_FIRSTFRAG" \
228 "\16M_LASTFRAG\17M_SKIP_FIREWALL\20M_FREELIST\21M_VLANTAG\22M_PROMISC" \
229 "\23M_NOFREE\24M_PROTO6\25M_PROTO7\26M_AMPDU_MPDU\27M_FLOWID"
232 * Store WME access control bits in the vlan tag.
233 * This is safe since it's done after the packet is classified
234 * (where we use any previous tag) and because it's passed
235 * directly in to the driver and there's no chance someone
236 * else will clobber them on us.
238 #define M_WME_SETAC(m, ac) \
239 ((m)->m_pkthdr.ether_vlantag = (ac))
240 #define M_WME_GETAC(m) ((m)->m_pkthdr.ether_vlantag)
243 * Mbufs on the power save queue are tagged with an age and
244 * timed out. We reuse the hardware checksum field in the
245 * mbuf packet header to store this data.
247 #define M_AGE_SET(m,v) (m->m_pkthdr.csum_data = v)
248 #define M_AGE_GET(m) (m->m_pkthdr.csum_data)
249 #define M_AGE_SUB(m,adj) (m->m_pkthdr.csum_data -= adj)
252 * Store the sequence number.
254 #define M_SEQNO_SET(m, seqno) \
255 ((m)->m_pkthdr.wlan_seqno = (seqno))
256 #define M_SEQNO_GET(m) ((m)->m_pkthdr.wlan_seqno)
258 #define MTAG_ABI_NET80211 1132948340 /* net80211 ABI */
260 struct ieee80211_cb {
261 void (*func)(struct ieee80211_node *, void *, int status);
264 #define NET80211_TAG_CALLBACK 0 /* xmit complete callback */
265 int ieee80211_add_callback(struct mbuf *m,
266 void (*func)(struct ieee80211_node *, void *, int), void *arg);
267 void ieee80211_process_callback(struct ieee80211_node *, struct mbuf *, int);
269 void get_random_bytes(void *, size_t);
273 void ieee80211_sysctl_attach(struct ieee80211com *);
274 void ieee80211_sysctl_detach(struct ieee80211com *);
275 void ieee80211_sysctl_vattach(struct ieee80211vap *);
276 void ieee80211_sysctl_vdetach(struct ieee80211vap *);
278 SYSCTL_DECL(_net_wlan);
279 int ieee80211_sysctl_msecs_ticks(SYSCTL_HANDLER_ARGS);
281 void ieee80211_load_module(const char *);
284 * A "policy module" is an adjunct module to net80211 that provides
285 * functionality that typically includes policy decisions. This
286 * modularity enables extensibility and vendor-supplied functionality.
288 #define _IEEE80211_POLICY_MODULE(policy, name, version) \
289 typedef void (*policy##_setup)(int); \
290 SET_DECLARE(policy##_set, policy##_setup); \
292 wlan_##name##_modevent(module_t mod, int type, void *unused) \
294 policy##_setup * const *iter, f; \
297 SET_FOREACH(iter, policy##_set) { \
304 kprintf("wlan_##name: still in use (%u dynamic refs)\n",\
308 if (type == MOD_UNLOAD) { \
309 SET_FOREACH(iter, policy##_set) { \
318 static moduledata_t name##_mod = { \
320 wlan_##name##_modevent, \
323 DECLARE_MODULE(wlan_##name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);\
324 MODULE_VERSION(wlan_##name, version); \
325 MODULE_DEPEND(wlan_##name, wlan, 1, 1, 1)
328 * Crypto modules implement cipher support.
330 #define IEEE80211_CRYPTO_MODULE(name, version) \
331 _IEEE80211_POLICY_MODULE(crypto, name, version); \
333 name##_modevent(int type) \
335 if (type == MOD_LOAD) \
336 ieee80211_crypto_register(&name); \
338 ieee80211_crypto_unregister(&name); \
340 TEXT_SET(crypto##_set, name##_modevent)
343 * Scanner modules provide scanning policy.
345 #define IEEE80211_SCANNER_MODULE(name, version) \
346 _IEEE80211_POLICY_MODULE(scanner, name, version)
348 #define IEEE80211_SCANNER_ALG(name, alg, v) \
350 name##_modevent(int type) \
352 if (type == MOD_LOAD) \
353 ieee80211_scanner_register(alg, &v); \
355 ieee80211_scanner_unregister(alg, &v); \
357 TEXT_SET(scanner_set, name##_modevent); \
360 * ACL modules implement acl policy.
362 #define IEEE80211_ACL_MODULE(name, alg, version) \
363 _IEEE80211_POLICY_MODULE(acl, name, version); \
365 alg##_modevent(int type) \
367 if (type == MOD_LOAD) \
368 ieee80211_aclator_register(&alg); \
370 ieee80211_aclator_unregister(&alg); \
372 TEXT_SET(acl_set, alg##_modevent); \
375 * Authenticator modules handle 802.1x/WPA authentication.
377 #define IEEE80211_AUTH_MODULE(name, version) \
378 _IEEE80211_POLICY_MODULE(auth, name, version)
380 #define IEEE80211_AUTH_ALG(name, alg, v) \
382 name##_modevent(int type) \
384 if (type == MOD_LOAD) \
385 ieee80211_authenticator_register(alg, &v); \
387 ieee80211_authenticator_unregister(alg); \
389 TEXT_SET(auth_set, name##_modevent)
392 * Rate control modules provide tx rate control support.
394 #define IEEE80211_RATE_MODULE(alg, version) \
395 _IEEE80211_POLICY_MODULE(rate, alg, version); \
397 alg##_modevent(int type) \
399 /* XXX nothing to do until the rate control framework arrives */\
401 TEXT_SET(rate##_set, alg##_modevent)
404 typedef int ieee80211_ioctl_getfunc(struct ieee80211vap *,
405 struct ieee80211req *);
406 SET_DECLARE(ieee80211_ioctl_getset, ieee80211_ioctl_getfunc);
407 #define IEEE80211_IOCTL_GET(_name, _get) TEXT_SET(ieee80211_ioctl_getset, _get)
409 typedef int ieee80211_ioctl_setfunc(struct ieee80211vap *,
410 struct ieee80211req *);
411 SET_DECLARE(ieee80211_ioctl_setset, ieee80211_ioctl_setfunc);
412 #define IEEE80211_IOCTL_SET(_name, _set) TEXT_SET(ieee80211_ioctl_setset, _set)
415 /* XXX this stuff belongs elsewhere */
417 * Message formats for messages from the net80211 layer to user
418 * applications via the routing socket. These messages are appended
419 * to an if_announcemsghdr structure.
421 struct ieee80211_join_event {
425 struct ieee80211_leave_event {
429 struct ieee80211_replay_event {
430 uint8_t iev_src[6]; /* src MAC */
431 uint8_t iev_dst[6]; /* dst MAC */
432 uint8_t iev_cipher; /* cipher type */
433 uint8_t iev_keyix; /* key id/index */
434 uint64_t iev_keyrsc; /* RSC from key */
435 uint64_t iev_rsc; /* RSC from frame */
438 struct ieee80211_michael_event {
439 uint8_t iev_src[6]; /* src MAC */
440 uint8_t iev_dst[6]; /* dst MAC */
441 uint8_t iev_cipher; /* cipher type */
442 uint8_t iev_keyix; /* key id/index */
445 struct ieee80211_wds_event {
449 struct ieee80211_csa_event {
450 uint32_t iev_flags; /* channel flags */
451 uint16_t iev_freq; /* setting in Mhz */
452 uint8_t iev_ieee; /* IEEE channel number */
453 uint8_t iev_mode; /* CSA mode */
454 uint8_t iev_count; /* CSA count */
457 struct ieee80211_cac_event {
458 uint32_t iev_flags; /* channel flags */
459 uint16_t iev_freq; /* setting in Mhz */
460 uint8_t iev_ieee; /* IEEE channel number */
462 uint8_t iev_type; /* IEEE80211_NOTIFY_CAC_* */
465 struct ieee80211_radar_event {
466 uint32_t iev_flags; /* channel flags */
467 uint16_t iev_freq; /* setting in Mhz */
468 uint8_t iev_ieee; /* IEEE channel number */
472 struct ieee80211_auth_event {
476 struct ieee80211_deauth_event {
480 struct ieee80211_country_event {
482 uint8_t iev_cc[2]; /* ISO country code */
485 struct ieee80211_radio_event {
486 uint8_t iev_state; /* 1 on, 0 off */
489 #define RTM_IEEE80211_ASSOC 100 /* station associate (bss mode) */
490 #define RTM_IEEE80211_REASSOC 101 /* station re-associate (bss mode) */
491 #define RTM_IEEE80211_DISASSOC 102 /* station disassociate (bss mode) */
492 #define RTM_IEEE80211_JOIN 103 /* station join (ap mode) */
493 #define RTM_IEEE80211_LEAVE 104 /* station leave (ap mode) */
494 #define RTM_IEEE80211_SCAN 105 /* scan complete, results available */
495 #define RTM_IEEE80211_REPLAY 106 /* sequence counter replay detected */
496 #define RTM_IEEE80211_MICHAEL 107 /* Michael MIC failure detected */
497 #define RTM_IEEE80211_REJOIN 108 /* station re-associate (ap mode) */
498 #define RTM_IEEE80211_WDS 109 /* WDS discovery (ap mode) */
499 #define RTM_IEEE80211_CSA 110 /* Channel Switch Announcement event */
500 #define RTM_IEEE80211_RADAR 111 /* radar event */
501 #define RTM_IEEE80211_CAC 112 /* Channel Availability Check event */
502 #define RTM_IEEE80211_DEAUTH 113 /* station deauthenticate */
503 #define RTM_IEEE80211_AUTH 114 /* station authenticate (ap mode) */
504 #define RTM_IEEE80211_COUNTRY 115 /* discovered country code (sta mode) */
505 #define RTM_IEEE80211_RADIO 116 /* RF kill switch state change */
508 * Structure prepended to raw packets sent through the bpf
509 * interface when set to DLT_IEEE802_11_RADIO. This allows
510 * user applications to specify pretty much everything in
511 * an Atheros tx descriptor. XXX need to generalize.
513 * XXX cannot be more than 14 bytes as it is copied to a sockaddr's
516 struct ieee80211_bpf_params {
517 uint8_t ibp_vers; /* version */
518 #define IEEE80211_BPF_VERSION 0
519 uint8_t ibp_len; /* header length in bytes */
521 #define IEEE80211_BPF_SHORTPRE 0x01 /* tx with short preamble */
522 #define IEEE80211_BPF_NOACK 0x02 /* tx with no ack */
523 #define IEEE80211_BPF_CRYPTO 0x04 /* tx with h/w encryption */
524 #define IEEE80211_BPF_FCS 0x10 /* frame incldues FCS */
525 #define IEEE80211_BPF_DATAPAD 0x20 /* frame includes data padding */
526 #define IEEE80211_BPF_RTS 0x40 /* tx with RTS/CTS */
527 #define IEEE80211_BPF_CTS 0x80 /* tx with CTS only */
528 uint8_t ibp_pri; /* WME/WMM AC+tx antenna */
529 uint8_t ibp_try0; /* series 1 try count */
530 uint8_t ibp_rate0; /* series 1 IEEE tx rate */
531 uint8_t ibp_power; /* tx power (device units) */
532 uint8_t ibp_ctsrate; /* IEEE tx rate for CTS */
533 uint8_t ibp_try1; /* series 2 try count */
534 uint8_t ibp_rate1; /* series 2 IEEE tx rate */
535 uint8_t ibp_try2; /* series 3 try count */
536 uint8_t ibp_rate2; /* series 3 IEEE tx rate */
537 uint8_t ibp_try3; /* series 4 try count */
538 uint8_t ibp_rate3; /* series 4 IEEE tx rate */
540 #endif /* _NET80211_IEEE80211_DRAGONFLY_H_ */