1 /* $NetBSD: ieee80211_netbsd.h,v 1.10 2006/03/02 03:38:48 dyoung Exp $ */ 2 /*- 3 * Copyright (c) 2003-2005 Sam Leffler, Errno Consulting 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * $FreeBSD: src/sys/net80211/ieee80211_freebsd.h,v 1.6 2005/08/08 18:46:36 sam Exp $ 29 */ 30 #ifndef _NET80211_IEEE80211_NETBSD_H_ 31 #define _NET80211_IEEE80211_NETBSD_H_ 32 33 #define IASSERT(__cond, __complaint) \ 34 do { \ 35 if (!(__cond)) \ 36 panic __complaint ; \ 37 } while (0) 38 39 void if_printf(struct ifnet *, const char *, ...) 40 __attribute__((__format__(__printf__,2,3))); 41 42 struct ieee80211_lock { 43 int count; 44 int ipl; 45 }; 46 #define IEEE80211_LOCK_INIT_IMPL(_ic, _name, _member) \ 47 do { \ 48 (_ic)->_member.count = 0; \ 49 } while (0) 50 #define IEEE80211_LOCK_IMPL(_ic, _member) \ 51 do { \ 52 int __s = splnet(); \ 53 if ((_ic)->_member.count++ == 0) \ 54 (_ic)->_member.ipl = __s; \ 55 } while (0) 56 #define IEEE80211_IS_LOCKED_IMPL(_ic, _member) \ 57 ((_ic)->_member.count != 0) 58 #define IEEE80211_UNLOCK_IMPL(_ic, _member) \ 59 do { \ 60 if (--(_ic)->_member.count == 0) \ 61 splx((_ic)->_member.ipl); \ 62 } while (0) 63 #define IEEE80211_LOCK_ASSERT_IMPL(_ic, _member) \ 64 IASSERT((_ic)->_member.count > 0, \ 65 ("%s: IEEE80211_LOCK not held", __func__)); 66 67 /* 68 * Beacon locking definitions. 69 */ 70 typedef struct ieee80211_lock ieee80211_beacon_lock_t; 71 #define IEEE80211_BEACON_LOCK_INIT(_ic, _name) \ 72 IEEE80211_LOCK_INIT_IMPL(_ic, _name, ic_beaconlock) 73 #define IEEE80211_BEACON_LOCK_DESTROY(_ic) 74 #define IEEE80211_BEACON_LOCK(_ic) \ 75 IEEE80211_LOCK_IMPL(_ic, ic_beaconlock) 76 #define IEEE80211_BEACON_UNLOCK(_ic) \ 77 IEEE80211_UNLOCK_IMPL(_ic, ic_beaconlock) 78 #define IEEE80211_BEACON_LOCK_ASSERT(_ic) \ 79 IEEE80211_LOCK_ASSERT_IMPL(_ic, ic_beaconlock) 80 81 /* 82 * Node locking definitions. 83 * NB: MTX_DUPOK is because we don't generate per-interface strings. 84 */ 85 typedef struct ieee80211_lock ieee80211_node_lock_t; 86 #define IEEE80211_NODE_LOCK_INIT(_nt, _name) \ 87 IEEE80211_LOCK_INIT_IMPL(_nt, _name, nt_nodelock) 88 #define IEEE80211_NODE_LOCK_DESTROY(_nt) 89 #define IEEE80211_NODE_LOCK(_nt) \ 90 IEEE80211_LOCK_IMPL(_nt, nt_nodelock) 91 #define IEEE80211_NODE_IS_LOCKED(_nt) \ 92 IEEE80211_IS_LOCKED_IMPL(_nt, nt_nodelock) 93 #define IEEE80211_NODE_UNLOCK(_nt) \ 94 IEEE80211_UNLOCK_IMPL(_nt, nt_nodelock) 95 #define IEEE80211_NODE_LOCK_ASSERT(_nt) \ 96 IEEE80211_LOCK_ASSERT_IMPL(_nt, nt_nodelock) 97 98 /* 99 * Node table scangen locking definitions. 100 */ 101 typedef struct ieee80211_lock ieee80211_scan_lock_t; 102 #define IEEE80211_SCAN_LOCK_INIT(_nt, _name) \ 103 IEEE80211_LOCK_INIT_IMPL(_nt, _name, nt_scanlock) 104 #define IEEE80211_SCAN_LOCK_DESTROY(_nt) 105 #define IEEE80211_SCAN_LOCK(_nt) \ 106 IEEE80211_LOCK_IMPL(_nt, nt_scanlock) 107 #define IEEE80211_SCAN_UNLOCK(_nt) \ 108 IEEE80211_UNLOCK_IMPL(_nt, nt_scanlock) 109 #define IEEE80211_SCAN_LOCK_ASSERT(_nt) \ 110 IEEE80211_LOCK_ASSERT_IMPL(_nt, nt_scanlock) 111 112 /* 113 * Per-node power-save queue definitions. 114 */ 115 #define IEEE80211_NODE_SAVEQ_INIT(_ni, _name) do { \ 116 (_ni)->ni_savedq.ifq_maxlen = IEEE80211_PS_MAX_QUEUE; \ 117 } while (0) 118 #define IEEE80211_NODE_SAVEQ_DESTROY(_ni) 119 #define IEEE80211_NODE_SAVEQ_QLEN(_ni) ((_ni)->ni_savedq.ifq_len) 120 #define IEEE80211_NODE_SAVEQ_LOCK(_ni) 121 #define IEEE80211_NODE_SAVEQ_UNLOCK(_ni) 122 #define IEEE80211_NODE_SAVEQ_DEQUEUE(_ni, _m, _qlen) do { \ 123 IEEE80211_NODE_SAVEQ_LOCK(_ni); \ 124 IF_DEQUEUE(&(_ni)->ni_savedq, _m); \ 125 (_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni); \ 126 IEEE80211_NODE_SAVEQ_UNLOCK(_ni); \ 127 } while (0) 128 #define IEEE80211_NODE_SAVEQ_DRAIN(_ni, _qlen) do { \ 129 IEEE80211_NODE_SAVEQ_LOCK(_ni); \ 130 (_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni); \ 131 IF_PURGE(&(_ni)->ni_savedq); \ 132 IEEE80211_NODE_SAVEQ_UNLOCK(_ni); \ 133 } while (0) 134 /* XXX could be optimized */ 135 #define _IEEE80211_NODE_SAVEQ_DEQUEUE_HEAD(_ni, _m) do { \ 136 IF_DEQUEUE(&(_ni)->ni_savedq, m); \ 137 } while (0) 138 #define _IEEE80211_NODE_SAVEQ_ENQUEUE(_ni, _m, _qlen, _age) do {\ 139 (_m)->m_nextpkt = NULL; \ 140 if ((_ni)->ni_savedq.ifq_tail != NULL) { \ 141 _age -= M_AGE_GET((_ni)->ni_savedq.ifq_tail); \ 142 (_ni)->ni_savedq.ifq_tail->m_nextpkt = (_m); \ 143 } else { \ 144 (_ni)->ni_savedq.ifq_head = (_m); \ 145 } \ 146 M_AGE_SET(_m, _age); \ 147 (_ni)->ni_savedq.ifq_tail = (_m); \ 148 (_qlen) = ++(_ni)->ni_savedq.ifq_len; \ 149 } while (0) 150 151 /* 152 * 802.1x MAC ACL database locking definitions. 153 */ 154 typedef struct ieee80211_lock acl_lock_t; 155 #define ACL_LOCK_INIT(_as, _name) \ 156 IEEE80211_LOCK_INIT_IMPL(_as, _name, as_lock) 157 #define ACL_LOCK_DESTROY(_as) 158 #define ACL_LOCK(_as) IEEE80211_LOCK_IMPL(_as, as_lock) 159 #define ACL_UNLOCK(_as) IEEE80211_UNLOCK_IMPL(_as, as_lock) 160 #define ACL_LOCK_ASSERT(_as) IEEE80211_LOCK_ASSERT_IMPL(_as, as_lock) 161 162 /* 163 * Node reference counting definitions. 164 * 165 * ieee80211_node_initref initialize the reference count to 1 166 * ieee80211_node_incref add a reference 167 * ieee80211_node_decref remove a reference 168 * ieee80211_node_dectestref remove a reference and return 1 if this 169 * is the last reference, otherwise 0 170 * ieee80211_node_refcnt reference count for printing (only) 171 */ 172 173 #define ieee80211_node_initref(_ni) \ 174 do { ((_ni)->ni_refcnt = 1); } while (0) 175 #define ieee80211_node_incref(_ni) \ 176 do { (_ni)->ni_refcnt++; } while (0) 177 #define ieee80211_node_decref(_ni) \ 178 do { (_ni)->ni_refcnt--; } while (0) 179 struct ieee80211_node; 180 int ieee80211_node_dectestref(struct ieee80211_node *ni); 181 #define ieee80211_node_refcnt(_ni) (_ni)->ni_refcnt 182 183 struct mbuf *ieee80211_getmgtframe(u_int8_t **frm, u_int pktlen); 184 #define M_PWR_SAV M_PROTO1 /* bypass PS handling */ 185 #define M_MORE_DATA M_LINK3 /* more data frames to follow */ 186 #define M_FRAG M_LINK4 /* 802.11 fragment */ 187 #define M_FIRSTFRAG M_LINK5 /* first 802.11 fragment */ 188 #define M_FF M_LINK6 /* "fast frames" */ 189 /* 190 * Encode WME access control bits in the PROTO flags. 191 * This is safe since it's passed directly in to the 192 * driver and there's no chance someone else will clobber 193 * them on us. 194 */ 195 #define M_WME_AC_MASK (M_LINK1|M_LINK2) 196 /* XXX 5 is wrong if M_LINK* are redefined */ 197 #define M_WME_AC_SHIFT 13 198 199 #define M_WME_SETAC(m, ac) \ 200 ((m)->m_flags = ((m)->m_flags &~ M_WME_AC_MASK) | \ 201 ((ac) << M_WME_AC_SHIFT)) 202 #define M_WME_GETAC(m) (((m)->m_flags >> M_WME_AC_SHIFT) & 0x3) 203 204 /* 205 * Mbufs on the power save queue are tagged with an age and 206 * timed out. We reuse the hardware checksum field in the 207 * mbuf packet header to store this data. 208 */ 209 #define M_AGE_SET(m,v) (m->m_pkthdr.csum_data = v) 210 #define M_AGE_GET(m) (m->m_pkthdr.csum_data) 211 #define M_AGE_SUB(m,adj) (m->m_pkthdr.csum_data -= adj) 212 213 struct ieee80211com; 214 215 /* XXX this stuff belongs elsewhere */ 216 /* 217 * Message formats for messages from the net80211 layer to user 218 * applications via the routing socket. These messages are appended 219 * to an if_announcemsghdr structure. 220 */ 221 struct ieee80211_join_event { 222 uint8_t iev_addr[6]; 223 }; 224 225 struct ieee80211_leave_event { 226 uint8_t iev_addr[6]; 227 }; 228 229 struct ieee80211_replay_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 uint64_t iev_keyrsc; /* RSC from key */ 235 uint64_t iev_rsc; /* RSC from frame */ 236 }; 237 238 struct ieee80211_michael_event { 239 uint8_t iev_src[6]; /* src MAC */ 240 uint8_t iev_dst[6]; /* dst MAC */ 241 uint8_t iev_cipher; /* cipher type */ 242 uint8_t iev_keyix; /* key id/index */ 243 }; 244 245 #define RTM_IEEE80211_ASSOC 100 /* station associate (bss mode) */ 246 #define RTM_IEEE80211_REASSOC 101 /* station re-associate (bss mode) */ 247 #define RTM_IEEE80211_DISASSOC 102 /* station disassociate (bss mode) */ 248 #define RTM_IEEE80211_JOIN 103 /* station join (ap mode) */ 249 #define RTM_IEEE80211_LEAVE 104 /* station leave (ap mode) */ 250 #define RTM_IEEE80211_SCAN 105 /* scan complete, results available */ 251 #define RTM_IEEE80211_REPLAY 106 /* sequence counter replay detected */ 252 #define RTM_IEEE80211_MICHAEL 107 /* Michael MIC failure detected */ 253 #define RTM_IEEE80211_REJOIN 108 /* station re-associate (ap mode) */ 254 255 #define __offsetof offsetof 256 #define ticks hardclock_ticks 257 #define ovbcopy(__src, __dst, __n) ((void)memmove(__dst, __src, __n)) 258 259 #define TAILQ_FOREACH_SAFE(var, head, field, nextvar) \ 260 for (var = TAILQ_FIRST(head); \ 261 var != NULL && (nextvar = TAILQ_NEXT(var, field), 1); \ 262 var = nextvar) 263 264 void if_printf(struct ifnet *, const char *, ...); 265 void m_align(struct mbuf *, int); 266 int m_append(struct mbuf *, int, const caddr_t); 267 void get_random_bytes(void *, size_t); 268 269 void ieee80211_sysctl_attach(struct ieee80211com *); 270 void ieee80211_sysctl_detach(struct ieee80211com *); 271 void ieee80211_load_module(const char *); 272 273 void ieee80211_init(void); 274 #define IEEE80211_CRYPTO_SETUP(name) \ 275 static void name(void); \ 276 __link_set_add_text(ieee80211_funcs, name); \ 277 static void name(void) 278 279 #endif /* !_NET80211_IEEE80211_NETBSD_H_ */ 280