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