ieee80211_freebsd.h revision 170360
1/*- 2 * Copyright (c) 2003-2007 Sam Leffler, Errno Consulting 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 13 * 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. 24 * 25 * $FreeBSD: head/sys/net80211/ieee80211_freebsd.h 170360 2007-06-06 04:56:04Z sam $ 26 */ 27#ifndef _NET80211_IEEE80211_FREEBSD_H_ 28#define _NET80211_IEEE80211_FREEBSD_H_ 29 30#ifdef _KERNEL 31/* 32 * Beacon locking definitions. 33 */ 34typedef struct mtx ieee80211_beacon_lock_t; 35#define IEEE80211_BEACON_LOCK_INIT(_ic, _name) \ 36 mtx_init(&(_ic)->ic_beaconlock, _name, "802.11 beacon lock", MTX_DEF) 37#define IEEE80211_BEACON_LOCK_DESTROY(_ic) mtx_destroy(&(_ic)->ic_beaconlock) 38#define IEEE80211_BEACON_LOCK(_ic) mtx_lock(&(_ic)->ic_beaconlock) 39#define IEEE80211_BEACON_UNLOCK(_ic) mtx_unlock(&(_ic)->ic_beaconlock) 40#define IEEE80211_BEACON_LOCK_ASSERT(_ic) \ 41 mtx_assert(&(_ic)->ic_beaconlock, MA_OWNED) 42 43/* 44 * Node locking definitions. 45 * NB: MTX_DUPOK is because we don't generate per-interface strings. 46 */ 47typedef struct mtx ieee80211_node_lock_t; 48#define IEEE80211_NODE_LOCK_INIT(_nt, _name) \ 49 mtx_init(&(_nt)->nt_nodelock, _name, "802.11 node table", \ 50 MTX_DEF | MTX_DUPOK) 51#define IEEE80211_NODE_LOCK_DESTROY(_nt) mtx_destroy(&(_nt)->nt_nodelock) 52#define IEEE80211_NODE_LOCK(_nt) mtx_lock(&(_nt)->nt_nodelock) 53#define IEEE80211_NODE_IS_LOCKED(_nt) mtx_owned(&(_nt)->nt_nodelock) 54#define IEEE80211_NODE_UNLOCK(_nt) mtx_unlock(&(_nt)->nt_nodelock) 55#define IEEE80211_NODE_LOCK_ASSERT(_nt) \ 56 mtx_assert(&(_nt)->nt_nodelock, MA_OWNED) 57 58/* 59 * Node table scangen locking definitions. 60 */ 61typedef struct mtx ieee80211_scan_lock_t; 62#define IEEE80211_SCAN_LOCK_INIT(_nt, _name) \ 63 mtx_init(&(_nt)->nt_scanlock, _name, "802.11 scangen", MTX_DEF) 64#define IEEE80211_SCAN_LOCK_DESTROY(_nt) mtx_destroy(&(_nt)->nt_scanlock) 65#define IEEE80211_SCAN_LOCK(_nt) mtx_lock(&(_nt)->nt_scanlock) 66#define IEEE80211_SCAN_UNLOCK(_nt) mtx_unlock(&(_nt)->nt_scanlock) 67#define IEEE80211_SCAN_LOCK_ASSERT(_nt) \ 68 mtx_assert(&(_nt)->nt_scanlock, MA_OWNED) 69 70/* 71 * Per-node power-save queue definitions. 72 */ 73#define IEEE80211_NODE_SAVEQ_INIT(_ni, _name) do { \ 74 mtx_init(&(_ni)->ni_savedq.ifq_mtx, _name, "802.11 ps queue", MTX_DEF);\ 75 (_ni)->ni_savedq.ifq_maxlen = IEEE80211_PS_MAX_QUEUE; \ 76} while (0) 77#define IEEE80211_NODE_SAVEQ_DESTROY(_ni) \ 78 mtx_destroy(&(_ni)->ni_savedq.ifq_mtx) 79#define IEEE80211_NODE_SAVEQ_QLEN(_ni) \ 80 _IF_QLEN(&(_ni)->ni_savedq) 81#define IEEE80211_NODE_SAVEQ_LOCK(_ni) do { \ 82 IF_LOCK(&(_ni)->ni_savedq); \ 83} while (0) 84#define IEEE80211_NODE_SAVEQ_UNLOCK(_ni) do { \ 85 IF_UNLOCK(&(_ni)->ni_savedq); \ 86} while (0) 87#define IEEE80211_NODE_SAVEQ_DEQUEUE(_ni, _m, _qlen) do { \ 88 IEEE80211_NODE_SAVEQ_LOCK(_ni); \ 89 _IF_DEQUEUE(&(_ni)->ni_savedq, _m); \ 90 (_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni); \ 91 IEEE80211_NODE_SAVEQ_UNLOCK(_ni); \ 92} while (0) 93#define IEEE80211_NODE_SAVEQ_DRAIN(_ni, _qlen) do { \ 94 IEEE80211_NODE_SAVEQ_LOCK(_ni); \ 95 (_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni); \ 96 _IF_DRAIN(&(_ni)->ni_savedq); \ 97 IEEE80211_NODE_SAVEQ_UNLOCK(_ni); \ 98} while (0) 99/* XXX could be optimized */ 100#define _IEEE80211_NODE_SAVEQ_DEQUEUE_HEAD(_ni, _m) do { \ 101 _IF_DEQUEUE(&(_ni)->ni_savedq, m); \ 102} while (0) 103#define _IEEE80211_NODE_SAVEQ_ENQUEUE(_ni, _m, _qlen, _age) do {\ 104 (_m)->m_nextpkt = NULL; \ 105 if ((_ni)->ni_savedq.ifq_tail != NULL) { \ 106 _age -= M_AGE_GET((_ni)->ni_savedq.ifq_tail); \ 107 (_ni)->ni_savedq.ifq_tail->m_nextpkt = (_m); \ 108 } else { \ 109 (_ni)->ni_savedq.ifq_head = (_m); \ 110 } \ 111 M_AGE_SET(_m, _age); \ 112 (_ni)->ni_savedq.ifq_tail = (_m); \ 113 (_qlen) = ++(_ni)->ni_savedq.ifq_len; \ 114} while (0) 115 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); \ 123} while (0) 124#define IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do { \ 125 IF_LOCK(ifq); \ 126 _IF_PREPEND_LIST(ifq, mhead, mtail, mcount); \ 127 IF_UNLOCK(ifq); \ 128} while (0) 129#endif /* IF_PREPEND_LIST */ 130 131/* 132 * 802.1x MAC ACL database locking definitions. 133 */ 134typedef struct mtx acl_lock_t; 135#define ACL_LOCK_INIT(_as, _name) \ 136 mtx_init(&(_as)->as_lock, _name, "802.11 ACL", MTX_DEF) 137#define ACL_LOCK_DESTROY(_as) mtx_destroy(&(_as)->as_lock) 138#define ACL_LOCK(_as) mtx_lock(&(_as)->as_lock) 139#define ACL_UNLOCK(_as) mtx_unlock(&(_as)->as_lock) 140#define ACL_LOCK_ASSERT(_as) \ 141 mtx_assert((&(_as)->as_lock), MA_OWNED) 142 143/* 144 * Node reference counting definitions. 145 * 146 * ieee80211_node_initref initialize the reference count to 1 147 * ieee80211_node_incref add a reference 148 * ieee80211_node_decref remove a reference 149 * ieee80211_node_dectestref remove a reference and return 1 if this 150 * is the last reference, otherwise 0 151 * ieee80211_node_refcnt reference count for printing (only) 152 */ 153#include <machine/atomic.h> 154 155#define ieee80211_node_initref(_ni) \ 156 do { ((_ni)->ni_refcnt = 1); } while (0) 157#define ieee80211_node_incref(_ni) \ 158 atomic_add_int(&(_ni)->ni_refcnt, 1) 159#define ieee80211_node_decref(_ni) \ 160 atomic_subtract_int(&(_ni)->ni_refcnt, 1) 161struct ieee80211_node; 162int ieee80211_node_dectestref(struct ieee80211_node *ni); 163#define ieee80211_node_refcnt(_ni) (_ni)->ni_refcnt 164 165struct ifqueue; 166void ieee80211_drain_ifq(struct ifqueue *); 167 168struct mbuf *ieee80211_getmgtframe(u_int8_t **frm, u_int pktlen); 169#define M_LINK0 M_PROTO1 /* WEP requested */ 170#define M_PWR_SAV M_PROTO4 /* bypass PS handling */ 171#define M_MORE_DATA M_PROTO5 /* more data frames to follow */ 172/* 173 * Encode WME access control bits in the PROTO flags. 174 * This is safe since it's passed directly in to the 175 * driver and there's no chance someone else will clobber 176 * them on us. 177 */ 178#define M_WME_AC_MASK (M_PROTO2|M_PROTO3) 179/* XXX 5 is wrong if M_PROTO* are redefined */ 180#define M_WME_AC_SHIFT 5 181 182#define M_WME_SETAC(m, ac) \ 183 ((m)->m_flags = ((m)->m_flags &~ M_WME_AC_MASK) | \ 184 ((ac) << M_WME_AC_SHIFT)) 185#define M_WME_GETAC(m) (((m)->m_flags >> M_WME_AC_SHIFT) & 0x3) 186 187/* 188 * Mbufs on the power save queue are tagged with an age and 189 * timed out. We reuse the hardware checksum field in the 190 * mbuf packet header to store this data. 191 */ 192#define M_AGE_SET(m,v) (m->m_pkthdr.csum_data = v) 193#define M_AGE_GET(m) (m->m_pkthdr.csum_data) 194#define M_AGE_SUB(m,adj) (m->m_pkthdr.csum_data -= adj) 195 196void get_random_bytes(void *, size_t); 197 198struct ieee80211com; 199 200void ieee80211_sysctl_attach(struct ieee80211com *); 201void ieee80211_sysctl_detach(struct ieee80211com *); 202 203void ieee80211_load_module(const char *); 204#endif /* _KERNEL */ 205 206/* XXX this stuff belongs elsewhere */ 207/* 208 * Message formats for messages from the net80211 layer to user 209 * applications via the routing socket. These messages are appended 210 * to an if_announcemsghdr structure. 211 */ 212struct ieee80211_join_event { 213 uint8_t iev_addr[6]; 214}; 215 216struct ieee80211_leave_event { 217 uint8_t iev_addr[6]; 218}; 219 220struct ieee80211_replay_event { 221 uint8_t iev_src[6]; /* src MAC */ 222 uint8_t iev_dst[6]; /* dst MAC */ 223 uint8_t iev_cipher; /* cipher type */ 224 uint8_t iev_keyix; /* key id/index */ 225 uint64_t iev_keyrsc; /* RSC from key */ 226 uint64_t iev_rsc; /* RSC from frame */ 227}; 228 229struct ieee80211_michael_event { 230 uint8_t iev_src[6]; /* src MAC */ 231 uint8_t iev_dst[6]; /* dst MAC */ 232 uint8_t iev_cipher; /* cipher type */ 233 uint8_t iev_keyix; /* key id/index */ 234}; 235 236#define RTM_IEEE80211_ASSOC 100 /* station associate (bss mode) */ 237#define RTM_IEEE80211_REASSOC 101 /* station re-associate (bss mode) */ 238#define RTM_IEEE80211_DISASSOC 102 /* station disassociate (bss mode) */ 239#define RTM_IEEE80211_JOIN 103 /* station join (ap mode) */ 240#define RTM_IEEE80211_LEAVE 104 /* station leave (ap mode) */ 241#define RTM_IEEE80211_SCAN 105 /* scan complete, results available */ 242#define RTM_IEEE80211_REPLAY 106 /* sequence counter replay detected */ 243#define RTM_IEEE80211_MICHAEL 107 /* Michael MIC failure detected */ 244#define RTM_IEEE80211_REJOIN 108 /* station re-associate (ap mode) */ 245 246/* 247 * Structure prepended to raw packets sent through the bpf 248 * interface when set to DLT_IEEE802_11_RADIO. This allows 249 * user applications to specify pretty much everything in 250 * an Atheros tx descriptor. XXX need to generalize. 251 * 252 * XXX cannot be more than 14 bytes as it is copied to a sockaddr's 253 * XXX sa_data area. 254 */ 255struct ieee80211_bpf_params { 256 uint8_t ibp_vers; /* version */ 257#define IEEE80211_BPF_VERSION 0 258 uint8_t ibp_len; /* header length in bytes */ 259 uint8_t ibp_flags; 260#define IEEE80211_BPF_SHORTPRE 0x01 /* tx with short preamble */ 261#define IEEE80211_BPF_NOACK 0x02 /* tx with no ack */ 262#define IEEE80211_BPF_CRYPTO 0x04 /* tx with h/w encryption */ 263#define IEEE80211_BPF_FCS 0x10 /* frame incldues FCS */ 264#define IEEE80211_BPF_DATAPAD 0x20 /* frame includes data padding */ 265#define IEEE80211_BPF_RTS 0x40 /* tx with RTS/CTS */ 266#define IEEE80211_BPF_CTS 0x80 /* tx with CTS only */ 267 uint8_t ibp_pri; /* WME/WMM AC+tx antenna */ 268 uint8_t ibp_try0; /* series 1 try count */ 269 uint8_t ibp_rate0; /* series 1 IEEE tx rate */ 270 uint8_t ibp_power; /* tx power (device units) */ 271 uint8_t ibp_ctsrate; /* IEEE tx rate for CTS */ 272 uint8_t ibp_try1; /* series 2 try count */ 273 uint8_t ibp_rate1; /* series 2 IEEE tx rate */ 274 uint8_t ibp_try2; /* series 3 try count */ 275 uint8_t ibp_rate2; /* series 3 IEEE tx rate */ 276 uint8_t ibp_try3; /* series 4 try count */ 277 uint8_t ibp_rate3; /* series 4 IEEE tx rate */ 278}; 279#endif /* _NET80211_IEEE80211_FREEBSD_H_ */ 280