ieee80211_freebsd.h revision 171022
1138568Ssam/*- 2170360Ssam * Copyright (c) 2003-2007 Sam Leffler, Errno Consulting 3138568Ssam * All rights reserved. 4138568Ssam * 5138568Ssam * Redistribution and use in source and binary forms, with or without 6138568Ssam * modification, are permitted provided that the following conditions 7138568Ssam * are met: 8138568Ssam * 1. Redistributions of source code must retain the above copyright 9138568Ssam * notice, this list of conditions and the following disclaimer. 10138568Ssam * 2. Redistributions in binary form must reproduce the above copyright 11138568Ssam * notice, this list of conditions and the following disclaimer in the 12138568Ssam * documentation and/or other materials provided with the distribution. 13138568Ssam * 14138568Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15138568Ssam * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16138568Ssam * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17138568Ssam * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18138568Ssam * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19138568Ssam * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20138568Ssam * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21138568Ssam * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22138568Ssam * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23138568Ssam * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24138568Ssam * 25138568Ssam * $FreeBSD: head/sys/net80211/ieee80211_freebsd.h 171022 2007-06-25 03:26:10Z sam $ 26138568Ssam */ 27138568Ssam#ifndef _NET80211_IEEE80211_FREEBSD_H_ 28138568Ssam#define _NET80211_IEEE80211_FREEBSD_H_ 29138568Ssam 30165911Ssam#ifdef _KERNEL 31138568Ssam/* 32170530Ssam * Common state locking definitions. 33170530Ssam */ 34170530Ssamtypedef struct mtx ieee80211_com_lock_t; 35170530Ssam#define IEEE80211_LOCK_INIT(_ic, _name) \ 36170530Ssam mtx_init(&(_ic)->ic_comlock, _name, "802.11 com lock", MTX_DEF) 37170530Ssam#define IEEE80211_LOCK_DESTROY(_ic) mtx_destroy(&(_ic)->ic_comlock) 38170530Ssam#define IEEE80211_LOCK(_ic) mtx_lock(&(_ic)->ic_comlock) 39170530Ssam#define IEEE80211_UNLOCK(_ic) mtx_unlock(&(_ic)->ic_comlock) 40170530Ssam#define IEEE80211_LOCK_ASSERT(_ic) \ 41170530Ssam mtx_assert(&(_ic)->ic_comlock, MA_OWNED) 42170530Ssam 43170530Ssam/* 44138568Ssam * Beacon locking definitions. 45138568Ssam */ 46138568Ssamtypedef struct mtx ieee80211_beacon_lock_t; 47138568Ssam#define IEEE80211_BEACON_LOCK_INIT(_ic, _name) \ 48138568Ssam mtx_init(&(_ic)->ic_beaconlock, _name, "802.11 beacon lock", MTX_DEF) 49138568Ssam#define IEEE80211_BEACON_LOCK_DESTROY(_ic) mtx_destroy(&(_ic)->ic_beaconlock) 50138568Ssam#define IEEE80211_BEACON_LOCK(_ic) mtx_lock(&(_ic)->ic_beaconlock) 51138568Ssam#define IEEE80211_BEACON_UNLOCK(_ic) mtx_unlock(&(_ic)->ic_beaconlock) 52138568Ssam#define IEEE80211_BEACON_LOCK_ASSERT(_ic) \ 53138568Ssam mtx_assert(&(_ic)->ic_beaconlock, MA_OWNED) 54138568Ssam 55138568Ssam/* 56138568Ssam * Node locking definitions. 57148863Ssam * NB: MTX_DUPOK is because we don't generate per-interface strings. 58138568Ssam */ 59138568Ssamtypedef struct mtx ieee80211_node_lock_t; 60138568Ssam#define IEEE80211_NODE_LOCK_INIT(_nt, _name) \ 61148863Ssam mtx_init(&(_nt)->nt_nodelock, _name, "802.11 node table", \ 62148863Ssam MTX_DEF | MTX_DUPOK) 63138568Ssam#define IEEE80211_NODE_LOCK_DESTROY(_nt) mtx_destroy(&(_nt)->nt_nodelock) 64138568Ssam#define IEEE80211_NODE_LOCK(_nt) mtx_lock(&(_nt)->nt_nodelock) 65148863Ssam#define IEEE80211_NODE_IS_LOCKED(_nt) mtx_owned(&(_nt)->nt_nodelock) 66138568Ssam#define IEEE80211_NODE_UNLOCK(_nt) mtx_unlock(&(_nt)->nt_nodelock) 67138568Ssam#define IEEE80211_NODE_LOCK_ASSERT(_nt) \ 68138568Ssam mtx_assert(&(_nt)->nt_nodelock, MA_OWNED) 69138568Ssam 70138568Ssam/* 71138568Ssam * Node table scangen locking definitions. 72138568Ssam */ 73138568Ssamtypedef struct mtx ieee80211_scan_lock_t; 74138568Ssam#define IEEE80211_SCAN_LOCK_INIT(_nt, _name) \ 75170530Ssam mtx_init(&(_nt)->nt_scanlock, _name, "802.11 node scangen", MTX_DEF) 76138568Ssam#define IEEE80211_SCAN_LOCK_DESTROY(_nt) mtx_destroy(&(_nt)->nt_scanlock) 77138568Ssam#define IEEE80211_SCAN_LOCK(_nt) mtx_lock(&(_nt)->nt_scanlock) 78138568Ssam#define IEEE80211_SCAN_UNLOCK(_nt) mtx_unlock(&(_nt)->nt_scanlock) 79138568Ssam#define IEEE80211_SCAN_LOCK_ASSERT(_nt) \ 80138568Ssam mtx_assert(&(_nt)->nt_scanlock, MA_OWNED) 81138568Ssam 82138568Ssam/* 83138568Ssam * Per-node power-save queue definitions. 84138568Ssam */ 85138568Ssam#define IEEE80211_NODE_SAVEQ_INIT(_ni, _name) do { \ 86138568Ssam mtx_init(&(_ni)->ni_savedq.ifq_mtx, _name, "802.11 ps queue", MTX_DEF);\ 87138568Ssam (_ni)->ni_savedq.ifq_maxlen = IEEE80211_PS_MAX_QUEUE; \ 88138568Ssam} while (0) 89138568Ssam#define IEEE80211_NODE_SAVEQ_DESTROY(_ni) \ 90138568Ssam mtx_destroy(&(_ni)->ni_savedq.ifq_mtx) 91138568Ssam#define IEEE80211_NODE_SAVEQ_QLEN(_ni) \ 92138568Ssam _IF_QLEN(&(_ni)->ni_savedq) 93138568Ssam#define IEEE80211_NODE_SAVEQ_LOCK(_ni) do { \ 94138568Ssam IF_LOCK(&(_ni)->ni_savedq); \ 95138568Ssam} while (0) 96138568Ssam#define IEEE80211_NODE_SAVEQ_UNLOCK(_ni) do { \ 97138568Ssam IF_UNLOCK(&(_ni)->ni_savedq); \ 98138568Ssam} while (0) 99138568Ssam#define IEEE80211_NODE_SAVEQ_DEQUEUE(_ni, _m, _qlen) do { \ 100138568Ssam IEEE80211_NODE_SAVEQ_LOCK(_ni); \ 101138568Ssam _IF_DEQUEUE(&(_ni)->ni_savedq, _m); \ 102138568Ssam (_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni); \ 103138568Ssam IEEE80211_NODE_SAVEQ_UNLOCK(_ni); \ 104138568Ssam} while (0) 105138568Ssam#define IEEE80211_NODE_SAVEQ_DRAIN(_ni, _qlen) do { \ 106138568Ssam IEEE80211_NODE_SAVEQ_LOCK(_ni); \ 107138568Ssam (_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni); \ 108138568Ssam _IF_DRAIN(&(_ni)->ni_savedq); \ 109138568Ssam IEEE80211_NODE_SAVEQ_UNLOCK(_ni); \ 110138568Ssam} while (0) 111138568Ssam/* XXX could be optimized */ 112138568Ssam#define _IEEE80211_NODE_SAVEQ_DEQUEUE_HEAD(_ni, _m) do { \ 113138568Ssam _IF_DEQUEUE(&(_ni)->ni_savedq, m); \ 114138568Ssam} while (0) 115138568Ssam#define _IEEE80211_NODE_SAVEQ_ENQUEUE(_ni, _m, _qlen, _age) do {\ 116138568Ssam (_m)->m_nextpkt = NULL; \ 117138568Ssam if ((_ni)->ni_savedq.ifq_tail != NULL) { \ 118138568Ssam _age -= M_AGE_GET((_ni)->ni_savedq.ifq_tail); \ 119138568Ssam (_ni)->ni_savedq.ifq_tail->m_nextpkt = (_m); \ 120138568Ssam } else { \ 121138568Ssam (_ni)->ni_savedq.ifq_head = (_m); \ 122138568Ssam } \ 123138568Ssam M_AGE_SET(_m, _age); \ 124138568Ssam (_ni)->ni_savedq.ifq_tail = (_m); \ 125138568Ssam (_qlen) = ++(_ni)->ni_savedq.ifq_len; \ 126138568Ssam} while (0) 127138568Ssam 128167284Ssam#ifndef IF_PREPEND_LIST 129167284Ssam#define _IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do { \ 130167284Ssam (mtail)->m_nextpkt = (ifq)->ifq_head; \ 131167284Ssam if ((ifq)->ifq_tail == NULL) \ 132167284Ssam (ifq)->ifq_tail = (mtail); \ 133167284Ssam (ifq)->ifq_head = (mhead); \ 134167284Ssam (ifq)->ifq_len += (mcount); \ 135167284Ssam} while (0) 136167284Ssam#define IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do { \ 137167284Ssam IF_LOCK(ifq); \ 138167284Ssam _IF_PREPEND_LIST(ifq, mhead, mtail, mcount); \ 139167284Ssam IF_UNLOCK(ifq); \ 140167284Ssam} while (0) 141167284Ssam#endif /* IF_PREPEND_LIST */ 142167284Ssam 143138568Ssam/* 144138568Ssam * 802.1x MAC ACL database locking definitions. 145138568Ssam */ 146138568Ssamtypedef struct mtx acl_lock_t; 147138568Ssam#define ACL_LOCK_INIT(_as, _name) \ 148138568Ssam mtx_init(&(_as)->as_lock, _name, "802.11 ACL", MTX_DEF) 149138568Ssam#define ACL_LOCK_DESTROY(_as) mtx_destroy(&(_as)->as_lock) 150138568Ssam#define ACL_LOCK(_as) mtx_lock(&(_as)->as_lock) 151138568Ssam#define ACL_UNLOCK(_as) mtx_unlock(&(_as)->as_lock) 152138568Ssam#define ACL_LOCK_ASSERT(_as) \ 153138568Ssam mtx_assert((&(_as)->as_lock), MA_OWNED) 154138568Ssam 155138568Ssam/* 156138568Ssam * Node reference counting definitions. 157138568Ssam * 158138568Ssam * ieee80211_node_initref initialize the reference count to 1 159138568Ssam * ieee80211_node_incref add a reference 160138568Ssam * ieee80211_node_decref remove a reference 161138568Ssam * ieee80211_node_dectestref remove a reference and return 1 if this 162138568Ssam * is the last reference, otherwise 0 163138568Ssam * ieee80211_node_refcnt reference count for printing (only) 164138568Ssam */ 165138568Ssam#include <machine/atomic.h> 166138568Ssam 167138568Ssam#define ieee80211_node_initref(_ni) \ 168138568Ssam do { ((_ni)->ni_refcnt = 1); } while (0) 169138568Ssam#define ieee80211_node_incref(_ni) \ 170138568Ssam atomic_add_int(&(_ni)->ni_refcnt, 1) 171138568Ssam#define ieee80211_node_decref(_ni) \ 172138568Ssam atomic_subtract_int(&(_ni)->ni_refcnt, 1) 173138568Ssamstruct ieee80211_node; 174144618Ssamint ieee80211_node_dectestref(struct ieee80211_node *ni); 175138568Ssam#define ieee80211_node_refcnt(_ni) (_ni)->ni_refcnt 176138568Ssam 177165904Ssamstruct ifqueue; 178165894Ssamvoid ieee80211_drain_ifq(struct ifqueue *); 179165894Ssam 180171022Ssam#define msecs_to_ticks(ms) (((ms)*hz)/1000) 181170530Ssam#define time_after(a,b) ((long)(b) - (long)(a) < 0) 182170530Ssam#define time_before(a,b) time_after(b,a) 183170530Ssam#define time_after_eq(a,b) ((long)(a) - (long)(b) >= 0) 184170530Ssam#define time_before_eq(a,b) time_after_eq(b,a) 185170530Ssam 186170530Ssamstruct mbuf *ieee80211_getmgtframe(uint8_t **frm, int headroom, int pktlen); 187170530Ssam/* tx path usage */ 188138568Ssam#define M_LINK0 M_PROTO1 /* WEP requested */ 189138568Ssam#define M_PWR_SAV M_PROTO4 /* bypass PS handling */ 190147789Ssam#define M_MORE_DATA M_PROTO5 /* more data frames to follow */ 191170530Ssam#define M_FF 0x20000 /* fast frame */ 192170530Ssam#define M_TXCB 0x40000 /* do tx complete callback */ 193170530Ssam/* rx path usage */ 194170530Ssam#define M_AMPDU M_PROTO1 /* A-MPDU processing done */ 195138568Ssam/* 196138568Ssam * Encode WME access control bits in the PROTO flags. 197138568Ssam * This is safe since it's passed directly in to the 198138568Ssam * driver and there's no chance someone else will clobber 199138568Ssam * them on us. 200138568Ssam */ 201138568Ssam#define M_WME_AC_MASK (M_PROTO2|M_PROTO3) 202138568Ssam/* XXX 5 is wrong if M_PROTO* are redefined */ 203138568Ssam#define M_WME_AC_SHIFT 5 204138568Ssam 205138568Ssam#define M_WME_SETAC(m, ac) \ 206138568Ssam ((m)->m_flags = ((m)->m_flags &~ M_WME_AC_MASK) | \ 207138568Ssam ((ac) << M_WME_AC_SHIFT)) 208138568Ssam#define M_WME_GETAC(m) (((m)->m_flags >> M_WME_AC_SHIFT) & 0x3) 209138568Ssam 210138568Ssam/* 211138568Ssam * Mbufs on the power save queue are tagged with an age and 212138568Ssam * timed out. We reuse the hardware checksum field in the 213138568Ssam * mbuf packet header to store this data. 214138568Ssam */ 215138568Ssam#define M_AGE_SET(m,v) (m->m_pkthdr.csum_data = v) 216138568Ssam#define M_AGE_GET(m) (m->m_pkthdr.csum_data) 217138568Ssam#define M_AGE_SUB(m,adj) (m->m_pkthdr.csum_data -= adj) 218138568Ssam 219170530Ssam#define MTAG_ABI_NET80211 1132948340 /* net80211 ABI */ 220170530Ssam 221170530Ssamstruct ieee80211_cb { 222170530Ssam void (*func)(struct ieee80211_node *, void *, int status); 223170530Ssam void *arg; 224170530Ssam}; 225170530Ssam#define NET80211_TAG_CALLBACK 0 /* xmit complete callback */ 226170530Ssamint ieee80211_add_callback(struct mbuf *m, 227170530Ssam void (*func)(struct ieee80211_node *, void *, int), void *arg); 228170530Ssamvoid ieee80211_process_callback(struct ieee80211_node *, struct mbuf *, int); 229170530Ssam 230144618Ssamvoid get_random_bytes(void *, size_t); 231138568Ssam 232138568Ssamstruct ieee80211com; 233138568Ssam 234138568Ssamvoid ieee80211_sysctl_attach(struct ieee80211com *); 235138568Ssamvoid ieee80211_sysctl_detach(struct ieee80211com *); 236138568Ssam 237138568Ssamvoid ieee80211_load_module(const char *); 238170530Ssam 239170530Ssam#define IEEE80211_CRYPTO_MODULE(name, version) \ 240170530Ssamstatic int \ 241170530Ssamname##_modevent(module_t mod, int type, void *unused) \ 242170530Ssam{ \ 243170530Ssam switch (type) { \ 244170530Ssam case MOD_LOAD: \ 245170530Ssam ieee80211_crypto_register(&name); \ 246170530Ssam return 0; \ 247170530Ssam case MOD_UNLOAD: \ 248170530Ssam case MOD_QUIESCE: \ 249170530Ssam if (nrefs) { \ 250170530Ssam printf("wlan_##name: still in use (%u dynamic refs)\n",\ 251170530Ssam nrefs); \ 252170530Ssam return EBUSY; \ 253170530Ssam } \ 254170530Ssam if (type == MOD_UNLOAD) \ 255170530Ssam ieee80211_crypto_unregister(&name); \ 256170530Ssam return 0; \ 257170530Ssam } \ 258170530Ssam return EINVAL; \ 259170530Ssam} \ 260170530Ssamstatic moduledata_t name##_mod = { \ 261170530Ssam "wlan_" #name, \ 262170530Ssam name##_modevent, \ 263170530Ssam 0 \ 264170530Ssam}; \ 265170530SsamDECLARE_MODULE(wlan_##name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);\ 266170530SsamMODULE_VERSION(wlan_##name, version); \ 267170530SsamMODULE_DEPEND(wlan_##name, wlan, 1, 1, 1) 268165911Ssam#endif /* _KERNEL */ 269138568Ssam 270138568Ssam/* XXX this stuff belongs elsewhere */ 271138568Ssam/* 272138568Ssam * Message formats for messages from the net80211 layer to user 273138568Ssam * applications via the routing socket. These messages are appended 274138568Ssam * to an if_announcemsghdr structure. 275138568Ssam */ 276138568Ssamstruct ieee80211_join_event { 277138568Ssam uint8_t iev_addr[6]; 278138568Ssam}; 279138568Ssam 280138568Ssamstruct ieee80211_leave_event { 281138568Ssam uint8_t iev_addr[6]; 282138568Ssam}; 283138568Ssam 284138568Ssamstruct ieee80211_replay_event { 285138568Ssam uint8_t iev_src[6]; /* src MAC */ 286138568Ssam uint8_t iev_dst[6]; /* dst MAC */ 287138568Ssam uint8_t iev_cipher; /* cipher type */ 288138568Ssam uint8_t iev_keyix; /* key id/index */ 289138568Ssam uint64_t iev_keyrsc; /* RSC from key */ 290138568Ssam uint64_t iev_rsc; /* RSC from frame */ 291138568Ssam}; 292138568Ssam 293138568Ssamstruct ieee80211_michael_event { 294138568Ssam uint8_t iev_src[6]; /* src MAC */ 295138568Ssam uint8_t iev_dst[6]; /* dst MAC */ 296138568Ssam uint8_t iev_cipher; /* cipher type */ 297138568Ssam uint8_t iev_keyix; /* key id/index */ 298138568Ssam}; 299138568Ssam 300138568Ssam#define RTM_IEEE80211_ASSOC 100 /* station associate (bss mode) */ 301138568Ssam#define RTM_IEEE80211_REASSOC 101 /* station re-associate (bss mode) */ 302138568Ssam#define RTM_IEEE80211_DISASSOC 102 /* station disassociate (bss mode) */ 303138568Ssam#define RTM_IEEE80211_JOIN 103 /* station join (ap mode) */ 304138568Ssam#define RTM_IEEE80211_LEAVE 104 /* station leave (ap mode) */ 305138568Ssam#define RTM_IEEE80211_SCAN 105 /* scan complete, results available */ 306138568Ssam#define RTM_IEEE80211_REPLAY 106 /* sequence counter replay detected */ 307138568Ssam#define RTM_IEEE80211_MICHAEL 107 /* Michael MIC failure detected */ 308144302Ssam#define RTM_IEEE80211_REJOIN 108 /* station re-associate (ap mode) */ 309138568Ssam 310160690Ssam/* 311160690Ssam * Structure prepended to raw packets sent through the bpf 312160690Ssam * interface when set to DLT_IEEE802_11_RADIO. This allows 313160690Ssam * user applications to specify pretty much everything in 314160690Ssam * an Atheros tx descriptor. XXX need to generalize. 315160690Ssam * 316160690Ssam * XXX cannot be more than 14 bytes as it is copied to a sockaddr's 317160690Ssam * XXX sa_data area. 318160690Ssam */ 319160690Ssamstruct ieee80211_bpf_params { 320160690Ssam uint8_t ibp_vers; /* version */ 321160690Ssam#define IEEE80211_BPF_VERSION 0 322160690Ssam uint8_t ibp_len; /* header length in bytes */ 323160690Ssam uint8_t ibp_flags; 324160690Ssam#define IEEE80211_BPF_SHORTPRE 0x01 /* tx with short preamble */ 325160690Ssam#define IEEE80211_BPF_NOACK 0x02 /* tx with no ack */ 326160690Ssam#define IEEE80211_BPF_CRYPTO 0x04 /* tx with h/w encryption */ 327160690Ssam#define IEEE80211_BPF_FCS 0x10 /* frame incldues FCS */ 328160690Ssam#define IEEE80211_BPF_DATAPAD 0x20 /* frame includes data padding */ 329160690Ssam#define IEEE80211_BPF_RTS 0x40 /* tx with RTS/CTS */ 330160690Ssam#define IEEE80211_BPF_CTS 0x80 /* tx with CTS only */ 331160690Ssam uint8_t ibp_pri; /* WME/WMM AC+tx antenna */ 332160690Ssam uint8_t ibp_try0; /* series 1 try count */ 333160690Ssam uint8_t ibp_rate0; /* series 1 IEEE tx rate */ 334160690Ssam uint8_t ibp_power; /* tx power (device units) */ 335160690Ssam uint8_t ibp_ctsrate; /* IEEE tx rate for CTS */ 336160690Ssam uint8_t ibp_try1; /* series 2 try count */ 337160690Ssam uint8_t ibp_rate1; /* series 2 IEEE tx rate */ 338160690Ssam uint8_t ibp_try2; /* series 3 try count */ 339160690Ssam uint8_t ibp_rate2; /* series 3 IEEE tx rate */ 340160690Ssam uint8_t ibp_try3; /* series 4 try count */ 341160690Ssam uint8_t ibp_rate3; /* series 4 IEEE tx rate */ 342160690Ssam}; 343138568Ssam#endif /* _NET80211_IEEE80211_FREEBSD_H_ */ 344