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$ 28 */ 29 #ifndef _NET80211_IEEE80211_FREEBSD_H_ 30 #define _NET80211_IEEE80211_FREEBSD_H_ 31 32 /* 33 * Beacon locking definitions. 34 */ 35 typedef 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 */ 47 typedef 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", MTX_DEF) 50 #define IEEE80211_NODE_LOCK_DESTROY(_nt) mtx_destroy(&(_nt)->nt_nodelock) 51 #define IEEE80211_NODE_LOCK(_nt) mtx_lock(&(_nt)->nt_nodelock) 52 #define IEEE80211_NODE_UNLOCK(_nt) mtx_unlock(&(_nt)->nt_nodelock) 53 #define IEEE80211_NODE_LOCK_ASSERT(_nt) \ 54 mtx_assert(&(_nt)->nt_nodelock, MA_OWNED) 55 56 /* 57 * Node table scangen locking definitions. 58 */ 59 typedef struct mtx ieee80211_scan_lock_t; 60 #define IEEE80211_SCAN_LOCK_INIT(_nt, _name) \ 61 mtx_init(&(_nt)->nt_scanlock, _name, "802.11 scangen", MTX_DEF) 62 #define IEEE80211_SCAN_LOCK_DESTROY(_nt) mtx_destroy(&(_nt)->nt_scanlock) 63 #define IEEE80211_SCAN_LOCK(_nt) mtx_lock(&(_nt)->nt_scanlock) 64 #define IEEE80211_SCAN_UNLOCK(_nt) mtx_unlock(&(_nt)->nt_scanlock) 65 #define IEEE80211_SCAN_LOCK_ASSERT(_nt) \ 66 mtx_assert(&(_nt)->nt_scanlock, MA_OWNED) 67 68 /* 69 * Per-node power-save queue definitions. 70 */ 71 #define IEEE80211_NODE_SAVEQ_INIT(_ni, _name) do { \ 72 mtx_init(&(_ni)->ni_savedq.ifq_mtx, _name, "802.11 ps queue", MTX_DEF);\ 73 (_ni)->ni_savedq.ifq_maxlen = IEEE80211_PS_MAX_QUEUE; \ 74 } while (0) 75 #define IEEE80211_NODE_SAVEQ_DESTROY(_ni) \ 76 mtx_destroy(&(_ni)->ni_savedq.ifq_mtx) 77 #define IEEE80211_NODE_SAVEQ_QLEN(_ni) \ 78 _IF_QLEN(&(_ni)->ni_savedq) 79 #define IEEE80211_NODE_SAVEQ_LOCK(_ni) do { \ 80 IF_LOCK(&(_ni)->ni_savedq); \ 81 } while (0) 82 #define IEEE80211_NODE_SAVEQ_UNLOCK(_ni) do { \ 83 IF_UNLOCK(&(_ni)->ni_savedq); \ 84 } while (0) 85 #define IEEE80211_NODE_SAVEQ_DEQUEUE(_ni, _m, _qlen) do { \ 86 IEEE80211_NODE_SAVEQ_LOCK(_ni); \ 87 _IF_DEQUEUE(&(_ni)->ni_savedq, _m); \ 88 (_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni); \ 89 IEEE80211_NODE_SAVEQ_UNLOCK(_ni); \ 90 } while (0) 91 #define IEEE80211_NODE_SAVEQ_DRAIN(_ni, _qlen) do { \ 92 IEEE80211_NODE_SAVEQ_LOCK(_ni); \ 93 (_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni); \ 94 _IF_DRAIN(&(_ni)->ni_savedq); \ 95 IEEE80211_NODE_SAVEQ_UNLOCK(_ni); \ 96 } while (0) 97 /* XXX could be optimized */ 98 #define _IEEE80211_NODE_SAVEQ_DEQUEUE_HEAD(_ni, _m) do { \ 99 _IF_DEQUEUE(&(_ni)->ni_savedq, m); \ 100 } while (0) 101 #define _IEEE80211_NODE_SAVEQ_ENQUEUE(_ni, _m, _qlen, _age) do {\ 102 (_m)->m_nextpkt = NULL; \ 103 if ((_ni)->ni_savedq.ifq_tail != NULL) { \ 104 _age -= M_AGE_GET((_ni)->ni_savedq.ifq_tail); \ 105 (_ni)->ni_savedq.ifq_tail->m_nextpkt = (_m); \ 106 } else { \ 107 (_ni)->ni_savedq.ifq_head = (_m); \ 108 } \ 109 M_AGE_SET(_m, _age); \ 110 (_ni)->ni_savedq.ifq_tail = (_m); \ 111 (_qlen) = ++(_ni)->ni_savedq.ifq_len; \ 112 } while (0) 113 114 /* 115 * 802.1x MAC ACL database locking definitions. 116 */ 117 typedef struct mtx acl_lock_t; 118 #define ACL_LOCK_INIT(_as, _name) \ 119 mtx_init(&(_as)->as_lock, _name, "802.11 ACL", MTX_DEF) 120 #define ACL_LOCK_DESTROY(_as) mtx_destroy(&(_as)->as_lock) 121 #define ACL_LOCK(_as) mtx_lock(&(_as)->as_lock) 122 #define ACL_UNLOCK(_as) mtx_unlock(&(_as)->as_lock) 123 #define ACL_LOCK_ASSERT(_as) \ 124 mtx_assert((&(_as)->as_lock), MA_OWNED) 125 126 /* 127 * Node reference counting definitions. 128 * 129 * ieee80211_node_initref initialize the reference count to 1 130 * ieee80211_node_incref add a reference 131 * ieee80211_node_decref remove a reference 132 * ieee80211_node_dectestref remove a reference and return 1 if this 133 * is the last reference, otherwise 0 134 * ieee80211_node_refcnt reference count for printing (only) 135 */ 136 #include <machine/atomic.h> 137 138 #define ieee80211_node_initref(_ni) \ 139 do { ((_ni)->ni_refcnt = 1); } while (0) 140 #define ieee80211_node_incref(_ni) \ 141 atomic_add_int(&(_ni)->ni_refcnt, 1) 142 #define ieee80211_node_decref(_ni) \ 143 atomic_subtract_int(&(_ni)->ni_refcnt, 1) 144 struct ieee80211_node; 145 extern int ieee80211_node_dectestref(struct ieee80211_node *ni); 146 #define ieee80211_node_refcnt(_ni) (_ni)->ni_refcnt 147 148 extern struct mbuf *ieee80211_getmgtframe(u_int8_t **frm, u_int pktlen); 149 #define M_LINK0 M_PROTO1 /* WEP requested */ 150 #define M_PWR_SAV M_PROTO4 /* bypass PS handling */ 151 /* 152 * Encode WME access control bits in the PROTO flags. 153 * This is safe since it's passed directly in to the 154 * driver and there's no chance someone else will clobber 155 * them on us. 156 */ 157 #define M_WME_AC_MASK (M_PROTO2|M_PROTO3) 158 /* XXX 5 is wrong if M_PROTO* are redefined */ 159 #define M_WME_AC_SHIFT 5 160 161 #define M_WME_SETAC(m, ac) \ 162 ((m)->m_flags = ((m)->m_flags &~ M_WME_AC_MASK) | \ 163 ((ac) << M_WME_AC_SHIFT)) 164 #define M_WME_GETAC(m) (((m)->m_flags >> M_WME_AC_SHIFT) & 0x3) 165 166 /* 167 * Mbufs on the power save queue are tagged with an age and 168 * timed out. We reuse the hardware checksum field in the 169 * mbuf packet header to store this data. 170 */ 171 #define M_AGE_SET(m,v) (m->m_pkthdr.csum_data = v) 172 #define M_AGE_GET(m) (m->m_pkthdr.csum_data) 173 #define M_AGE_SUB(m,adj) (m->m_pkthdr.csum_data -= adj) 174 175 extern void get_random_bytes(void *, size_t); 176 177 struct ieee80211com; 178 179 void ieee80211_sysctl_attach(struct ieee80211com *); 180 void ieee80211_sysctl_detach(struct ieee80211com *); 181 182 void ieee80211_load_module(const char *); 183 184 /* XXX this stuff belongs elsewhere */ 185 /* 186 * Message formats for messages from the net80211 layer to user 187 * applications via the routing socket. These messages are appended 188 * to an if_announcemsghdr structure. 189 */ 190 struct ieee80211_join_event { 191 uint8_t iev_addr[6]; 192 }; 193 194 struct ieee80211_leave_event { 195 uint8_t iev_addr[6]; 196 }; 197 198 struct ieee80211_replay_event { 199 uint8_t iev_src[6]; /* src MAC */ 200 uint8_t iev_dst[6]; /* dst MAC */ 201 uint8_t iev_cipher; /* cipher type */ 202 uint8_t iev_keyix; /* key id/index */ 203 uint64_t iev_keyrsc; /* RSC from key */ 204 uint64_t iev_rsc; /* RSC from frame */ 205 }; 206 207 struct ieee80211_michael_event { 208 uint8_t iev_src[6]; /* src MAC */ 209 uint8_t iev_dst[6]; /* dst MAC */ 210 uint8_t iev_cipher; /* cipher type */ 211 uint8_t iev_keyix; /* key id/index */ 212 }; 213 214 #define RTM_IEEE80211_ASSOC 100 /* station associate (bss mode) */ 215 #define RTM_IEEE80211_REASSOC 101 /* station re-associate (bss mode) */ 216 #define RTM_IEEE80211_DISASSOC 102 /* station disassociate (bss mode) */ 217 #define RTM_IEEE80211_JOIN 103 /* station join (ap mode) */ 218 #define RTM_IEEE80211_LEAVE 104 /* station leave (ap mode) */ 219 #define RTM_IEEE80211_SCAN 105 /* scan complete, results available */ 220 #define RTM_IEEE80211_REPLAY 106 /* sequence counter replay detected */ 221 #define RTM_IEEE80211_MICHAEL 107 /* Michael MIC failure detected */ 222 223 #endif /* _NET80211_IEEE80211_FREEBSD_H_ */ 224