1 /* $NetBSD: ieee80211_netbsd.h,v 1.3 2005/06/22 22:07:49 martin 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.2 2004/12/31 22:42:38 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 /* 43 * Beacon locking definitions. 44 */ 45 struct ieee80211_lock { 46 int count; 47 int ipl; 48 }; 49 #define IEEE80211_LOCK_INIT_IMPL(_ic, _name, _member) \ 50 do { \ 51 (_ic)->_member.count = 0; \ 52 } while (0) 53 #define IEEE80211_LOCK_IMPL(_ic, _member) \ 54 do { \ 55 int __s = splnet(); \ 56 if ((_ic)->_member.count++ == 0) \ 57 (_ic)->_member.ipl = __s; \ 58 } while (0) 59 #define IEEE80211_UNLOCK_IMPL(_ic, _member) \ 60 do { \ 61 if (--(_ic)->_member.count == 0) \ 62 splx((_ic)->_member.ipl); \ 63 } while (0) 64 #define IEEE80211_LOCK_ASSERT_IMPL(_ic, _member) \ 65 IASSERT((_ic)->_member.count > 0, \ 66 ("%s: IEEE80211_LOCK not held", __func__)); 67 68 typedef struct ieee80211_lock ieee80211_beacon_lock_t; 69 #define IEEE80211_BEACON_LOCK_INIT(_ic, _name) \ 70 IEEE80211_LOCK_INIT_IMPL(_ic, _name, ic_beaconlock) 71 #define IEEE80211_BEACON_LOCK_DESTROY(_ic) 72 #define IEEE80211_BEACON_LOCK(_ic) \ 73 IEEE80211_LOCK_IMPL(_ic, ic_beaconlock) 74 #define IEEE80211_BEACON_UNLOCK(_ic) \ 75 IEEE80211_UNLOCK_IMPL(_ic, ic_beaconlock) 76 #define IEEE80211_BEACON_LOCK_ASSERT(_ic) \ 77 IEEE80211_LOCK_ASSERT_IMPL(_ic, ic_beaconlock) 78 79 /* 80 * Node locking definitions. 81 */ 82 typedef struct ieee80211_lock ieee80211_node_lock_t; 83 #define IEEE80211_NODE_LOCK_INIT(_nt, _name) \ 84 IEEE80211_LOCK_INIT_IMPL(_nt, _name, nt_nodelock) 85 #define IEEE80211_NODE_LOCK_DESTROY(_nt) 86 #define IEEE80211_NODE_LOCK(_nt) \ 87 IEEE80211_LOCK_IMPL(_nt, nt_nodelock) 88 #define IEEE80211_NODE_UNLOCK(_nt) \ 89 IEEE80211_UNLOCK_IMPL(_nt, nt_nodelock) 90 #define IEEE80211_NODE_LOCK_ASSERT(_nt) \ 91 IEEE80211_LOCK_ASSERT_IMPL(_nt, nt_nodelock) 92 93 /* 94 * Node table scangen locking definitions. 95 */ 96 typedef struct ieee80211_lock ieee80211_scan_lock_t; 97 #define IEEE80211_SCAN_LOCK_INIT(_nt, _name) \ 98 IEEE80211_LOCK_INIT_IMPL(_nt, _name, nt_scanlock) 99 #define IEEE80211_SCAN_LOCK_DESTROY(_nt) 100 #define IEEE80211_SCAN_LOCK(_nt) \ 101 IEEE80211_LOCK_IMPL(_nt, nt_scanlock) 102 #define IEEE80211_SCAN_UNLOCK(_nt) \ 103 IEEE80211_UNLOCK_IMPL(_nt, nt_scanlock) 104 #define IEEE80211_SCAN_LOCK_ASSERT(_nt) \ 105 IEEE80211_LOCK_ASSERT_IMPL(_nt, nt_scanlock) 106 107 /* 108 * Per-node power-save queue definitions. 109 */ 110 #define IEEE80211_NODE_SAVEQ_INIT(_ni, _name) do { \ 111 (_ni)->ni_savedq.ifq_maxlen = IEEE80211_PS_MAX_QUEUE; \ 112 } while (0) 113 #define IEEE80211_NODE_SAVEQ_DESTROY(_ni) 114 #define IEEE80211_NODE_SAVEQ_QLEN(_ni) ((_ni)->ni_savedq.ifq_len) 115 #define IEEE80211_NODE_SAVEQ_LOCK(_ni) 116 #define IEEE80211_NODE_SAVEQ_UNLOCK(_ni) 117 #define IEEE80211_NODE_SAVEQ_DEQUEUE(_ni, _m, _qlen) do { \ 118 IEEE80211_NODE_SAVEQ_LOCK(_ni); \ 119 IF_DEQUEUE(&(_ni)->ni_savedq, _m); \ 120 (_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni); \ 121 IEEE80211_NODE_SAVEQ_UNLOCK(_ni); \ 122 } while (0) 123 #define IEEE80211_NODE_SAVEQ_DRAIN(_ni, _qlen) do { \ 124 IEEE80211_NODE_SAVEQ_LOCK(_ni); \ 125 (_qlen) = IEEE80211_NODE_SAVEQ_QLEN(_ni); \ 126 IF_PURGE(&(_ni)->ni_savedq); \ 127 IEEE80211_NODE_SAVEQ_UNLOCK(_ni); \ 128 } while (0) 129 /* XXX could be optimized */ 130 #define _IEEE80211_NODE_SAVEQ_DEQUEUE_HEAD(_ni, _m) do { \ 131 IF_DEQUEUE(&(_ni)->ni_savedq, m); \ 132 } while (0) 133 #define _IEEE80211_NODE_SAVEQ_ENQUEUE(_ni, _m, _qlen, _age) do {\ 134 (_m)->m_nextpkt = NULL; \ 135 if ((_ni)->ni_savedq.ifq_tail != NULL) { \ 136 _age -= M_AGE_GET((_ni)->ni_savedq.ifq_tail); \ 137 (_ni)->ni_savedq.ifq_tail->m_nextpkt = (_m); \ 138 } else { \ 139 (_ni)->ni_savedq.ifq_head = (_m); \ 140 } \ 141 M_AGE_SET(_m, _age); \ 142 (_ni)->ni_savedq.ifq_tail = (_m); \ 143 (_qlen) = ++(_ni)->ni_savedq.ifq_len; \ 144 } while (0) 145 146 /* 147 * 802.1x MAC ACL database locking definitions. 148 */ 149 typedef struct ieee80211_lock acl_lock_t; 150 #define ACL_LOCK_INIT(_as, _name) \ 151 IEEE80211_LOCK_INIT_IMPL(_as, _name, as_lock) 152 #define ACL_LOCK_DESTROY(_as) 153 #define ACL_LOCK(_as) IEEE80211_LOCK_IMPL(_as, as_lock) 154 #define ACL_UNLOCK(_as) IEEE80211_UNLOCK_IMPL(_as, as_lock) 155 #define ACL_LOCK_ASSERT(_as) IEEE80211_LOCK_ASSERT_IMPL(_as, as_lock) 156 157 /* 158 * Node reference counting definitions. 159 * 160 * ieee80211_node_initref initialize the reference count to 1 161 * ieee80211_node_incref add a reference 162 * ieee80211_node_decref remove a reference 163 * ieee80211_node_dectestref remove a reference and return 1 if this 164 * is the last reference, otherwise 0 165 * ieee80211_node_refcnt reference count for printing (only) 166 */ 167 168 #define ieee80211_node_initref(_ni) \ 169 do { ((_ni)->ni_refcnt = 1); } while (0) 170 #define ieee80211_node_incref(_ni) \ 171 do { (_ni)->ni_refcnt++; } while (0) 172 #define ieee80211_node_decref(_ni) \ 173 do { (_ni)->ni_refcnt--; } while (0) 174 struct ieee80211_node; 175 int ieee80211_node_dectestref(struct ieee80211_node *ni); 176 #define ieee80211_node_refcnt(_ni) (_ni)->ni_refcnt 177 178 struct mbuf *ieee80211_getmgtframe(u_int8_t **frm, u_int pktlen); 179 #define M_PWR_SAV M_PROTO1 /* bypass PS handling */ 180 /* 181 * Encode WME access control bits in the PROTO flags. 182 * This is safe since it's passed directly in to the 183 * driver and there's no chance someone else will clobber 184 * them on us. 185 */ 186 #define M_WME_AC_MASK (M_LINK1|M_LINK2) 187 /* XXX 5 is wrong if M_LINK* are redefined */ 188 #define M_WME_AC_SHIFT 13 189 190 #define M_WME_SETAC(m, ac) \ 191 ((m)->m_flags = ((m)->m_flags &~ M_WME_AC_MASK) | \ 192 ((ac) << M_WME_AC_SHIFT)) 193 #define M_WME_GETAC(m) (((m)->m_flags >> M_WME_AC_SHIFT) & 0x3) 194 195 /* 196 * Mbufs on the power save queue are tagged with an age and 197 * timed out. We reuse the hardware checksum field in the 198 * mbuf packet header to store this data. 199 */ 200 #define M_AGE_SET(m,v) (m->m_pkthdr.csum_data = v) 201 #define M_AGE_GET(m) (m->m_pkthdr.csum_data) 202 #define M_AGE_SUB(m,adj) (m->m_pkthdr.csum_data -= adj) 203 204 struct ieee80211com; 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 */ 212 struct ieee80211_join_event { 213 uint8_t iev_addr[6]; 214 }; 215 216 struct ieee80211_leave_event { 217 uint8_t iev_addr[6]; 218 }; 219 220 struct 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 229 struct 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 #define __offsetof offsetof 247 #define ticks hardclock_ticks 248 #define ovbcopy(__src, __dst, __n) ((void)memmove(__dst, __src, __n)) 249 250 #define TAILQ_FOREACH_SAFE(var, head, field, nextvar) \ 251 for (var = TAILQ_FIRST(head); \ 252 var != NULL && (nextvar = TAILQ_NEXT(var, field), 1); \ 253 var = nextvar) 254 255 void if_printf(struct ifnet *, const char *, ...); 256 struct mbuf *m_getcl(int, int, int); 257 int m_append(struct mbuf *, int, const caddr_t); 258 void get_random_bytes(void *, size_t); 259 int m_append(struct mbuf *m0, int, const caddr_t); 260 void ieee80211_sysctl_attach(struct ieee80211com *); 261 void ieee80211_sysctl_detach(struct ieee80211com *); 262 void ieee80211_load_module(const char *); 263 264 #endif /* _NET80211_IEEE80211_NETBSD_H_ */ 265