1 /*- 2 * Copyright (c) 2003-2008 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$ 26 */ 27 #ifndef _NET80211_IEEE80211_FREEBSD_H_ 28 #define _NET80211_IEEE80211_FREEBSD_H_ 29 30 #ifdef _KERNEL 31 #include <sys/param.h> 32 #include <sys/systm.h> 33 #include <sys/counter.h> 34 #include <sys/lock.h> 35 #include <sys/mutex.h> 36 #include <sys/rwlock.h> 37 #include <sys/sysctl.h> 38 #include <sys/taskqueue.h> 39 40 /* 41 * Common state locking definitions. 42 */ 43 typedef struct { 44 char name[16]; /* e.g. "ath0_com_lock" */ 45 struct mtx mtx; 46 } ieee80211_com_lock_t; 47 #define IEEE80211_LOCK_INIT(_ic, _name) do { \ 48 ieee80211_com_lock_t *cl = &(_ic)->ic_comlock; \ 49 snprintf(cl->name, sizeof(cl->name), "%s_com_lock", _name); \ 50 mtx_init(&cl->mtx, cl->name, NULL, MTX_DEF | MTX_RECURSE); \ 51 } while (0) 52 #define IEEE80211_LOCK_OBJ(_ic) (&(_ic)->ic_comlock.mtx) 53 #define IEEE80211_LOCK_DESTROY(_ic) mtx_destroy(IEEE80211_LOCK_OBJ(_ic)) 54 #define IEEE80211_LOCK(_ic) mtx_lock(IEEE80211_LOCK_OBJ(_ic)) 55 #define IEEE80211_UNLOCK(_ic) mtx_unlock(IEEE80211_LOCK_OBJ(_ic)) 56 #define IEEE80211_LOCK_ASSERT(_ic) \ 57 mtx_assert(IEEE80211_LOCK_OBJ(_ic), MA_OWNED) 58 #define IEEE80211_UNLOCK_ASSERT(_ic) \ 59 mtx_assert(IEEE80211_LOCK_OBJ(_ic), MA_NOTOWNED) 60 61 /* 62 * Transmit lock. 63 * 64 * This is a (mostly) temporary lock designed to serialise all of the 65 * transmission operations throughout the stack. 66 */ 67 typedef struct { 68 char name[16]; /* e.g. "ath0_tx_lock" */ 69 struct mtx mtx; 70 } ieee80211_tx_lock_t; 71 #define IEEE80211_TX_LOCK_INIT(_ic, _name) do { \ 72 ieee80211_tx_lock_t *cl = &(_ic)->ic_txlock; \ 73 snprintf(cl->name, sizeof(cl->name), "%s_tx_lock", _name); \ 74 mtx_init(&cl->mtx, cl->name, NULL, MTX_DEF); \ 75 } while (0) 76 #define IEEE80211_TX_LOCK_OBJ(_ic) (&(_ic)->ic_txlock.mtx) 77 #define IEEE80211_TX_LOCK_DESTROY(_ic) mtx_destroy(IEEE80211_TX_LOCK_OBJ(_ic)) 78 #define IEEE80211_TX_LOCK(_ic) mtx_lock(IEEE80211_TX_LOCK_OBJ(_ic)) 79 #define IEEE80211_TX_UNLOCK(_ic) mtx_unlock(IEEE80211_TX_LOCK_OBJ(_ic)) 80 #define IEEE80211_TX_LOCK_ASSERT(_ic) \ 81 mtx_assert(IEEE80211_TX_LOCK_OBJ(_ic), MA_OWNED) 82 #define IEEE80211_TX_UNLOCK_ASSERT(_ic) \ 83 mtx_assert(IEEE80211_TX_LOCK_OBJ(_ic), MA_NOTOWNED) 84 85 /* 86 * Stageq / ni_tx_superg lock 87 */ 88 typedef struct { 89 char name[16]; /* e.g. "ath0_ff_lock" */ 90 struct mtx mtx; 91 } ieee80211_ff_lock_t; 92 #define IEEE80211_FF_LOCK_INIT(_ic, _name) do { \ 93 ieee80211_ff_lock_t *fl = &(_ic)->ic_fflock; \ 94 snprintf(fl->name, sizeof(fl->name), "%s_ff_lock", _name); \ 95 mtx_init(&fl->mtx, fl->name, NULL, MTX_DEF); \ 96 } while (0) 97 #define IEEE80211_FF_LOCK_OBJ(_ic) (&(_ic)->ic_fflock.mtx) 98 #define IEEE80211_FF_LOCK_DESTROY(_ic) mtx_destroy(IEEE80211_FF_LOCK_OBJ(_ic)) 99 #define IEEE80211_FF_LOCK(_ic) mtx_lock(IEEE80211_FF_LOCK_OBJ(_ic)) 100 #define IEEE80211_FF_UNLOCK(_ic) mtx_unlock(IEEE80211_FF_LOCK_OBJ(_ic)) 101 #define IEEE80211_FF_LOCK_ASSERT(_ic) \ 102 mtx_assert(IEEE80211_FF_LOCK_OBJ(_ic), MA_OWNED) 103 104 /* 105 * Node locking definitions. 106 */ 107 typedef struct { 108 char name[16]; /* e.g. "ath0_node_lock" */ 109 struct mtx mtx; 110 } ieee80211_node_lock_t; 111 #define IEEE80211_NODE_LOCK_INIT(_nt, _name) do { \ 112 ieee80211_node_lock_t *nl = &(_nt)->nt_nodelock; \ 113 snprintf(nl->name, sizeof(nl->name), "%s_node_lock", _name); \ 114 mtx_init(&nl->mtx, nl->name, NULL, MTX_DEF | MTX_RECURSE); \ 115 } while (0) 116 #define IEEE80211_NODE_LOCK_OBJ(_nt) (&(_nt)->nt_nodelock.mtx) 117 #define IEEE80211_NODE_LOCK_DESTROY(_nt) \ 118 mtx_destroy(IEEE80211_NODE_LOCK_OBJ(_nt)) 119 #define IEEE80211_NODE_LOCK(_nt) \ 120 mtx_lock(IEEE80211_NODE_LOCK_OBJ(_nt)) 121 #define IEEE80211_NODE_IS_LOCKED(_nt) \ 122 mtx_owned(IEEE80211_NODE_LOCK_OBJ(_nt)) 123 #define IEEE80211_NODE_UNLOCK(_nt) \ 124 mtx_unlock(IEEE80211_NODE_LOCK_OBJ(_nt)) 125 #define IEEE80211_NODE_LOCK_ASSERT(_nt) \ 126 mtx_assert(IEEE80211_NODE_LOCK_OBJ(_nt), MA_OWNED) 127 128 /* 129 * Power-save queue definitions. 130 */ 131 typedef struct mtx ieee80211_psq_lock_t; 132 #define IEEE80211_PSQ_INIT(_psq, _name) \ 133 mtx_init(&(_psq)->psq_lock, _name, "802.11 ps q", MTX_DEF) 134 #define IEEE80211_PSQ_DESTROY(_psq) mtx_destroy(&(_psq)->psq_lock) 135 #define IEEE80211_PSQ_LOCK(_psq) mtx_lock(&(_psq)->psq_lock) 136 #define IEEE80211_PSQ_UNLOCK(_psq) mtx_unlock(&(_psq)->psq_lock) 137 138 #ifndef IF_PREPEND_LIST 139 #define _IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do { \ 140 (mtail)->m_nextpkt = (ifq)->ifq_head; \ 141 if ((ifq)->ifq_tail == NULL) \ 142 (ifq)->ifq_tail = (mtail); \ 143 (ifq)->ifq_head = (mhead); \ 144 (ifq)->ifq_len += (mcount); \ 145 } while (0) 146 #define IF_PREPEND_LIST(ifq, mhead, mtail, mcount) do { \ 147 IF_LOCK(ifq); \ 148 _IF_PREPEND_LIST(ifq, mhead, mtail, mcount); \ 149 IF_UNLOCK(ifq); \ 150 } while (0) 151 #endif /* IF_PREPEND_LIST */ 152 153 /* 154 * Age queue definitions. 155 */ 156 typedef struct mtx ieee80211_ageq_lock_t; 157 #define IEEE80211_AGEQ_INIT(_aq, _name) \ 158 mtx_init(&(_aq)->aq_lock, _name, "802.11 age q", MTX_DEF) 159 #define IEEE80211_AGEQ_DESTROY(_aq) mtx_destroy(&(_aq)->aq_lock) 160 #define IEEE80211_AGEQ_LOCK(_aq) mtx_lock(&(_aq)->aq_lock) 161 #define IEEE80211_AGEQ_UNLOCK(_aq) mtx_unlock(&(_aq)->aq_lock) 162 163 /* 164 * 802.1x MAC ACL database locking definitions. 165 */ 166 typedef struct mtx acl_lock_t; 167 #define ACL_LOCK_INIT(_as, _name) \ 168 mtx_init(&(_as)->as_lock, _name, "802.11 ACL", MTX_DEF) 169 #define ACL_LOCK_DESTROY(_as) mtx_destroy(&(_as)->as_lock) 170 #define ACL_LOCK(_as) mtx_lock(&(_as)->as_lock) 171 #define ACL_UNLOCK(_as) mtx_unlock(&(_as)->as_lock) 172 #define ACL_LOCK_ASSERT(_as) \ 173 mtx_assert((&(_as)->as_lock), MA_OWNED) 174 175 /* 176 * Scan table definitions. 177 */ 178 typedef struct mtx ieee80211_scan_table_lock_t; 179 #define IEEE80211_SCAN_TABLE_LOCK_INIT(_st, _name) \ 180 mtx_init(&(_st)->st_lock, _name, "802.11 scan table", MTX_DEF) 181 #define IEEE80211_SCAN_TABLE_LOCK_DESTROY(_st) mtx_destroy(&(_st)->st_lock) 182 #define IEEE80211_SCAN_TABLE_LOCK(_st) mtx_lock(&(_st)->st_lock) 183 #define IEEE80211_SCAN_TABLE_UNLOCK(_st) mtx_unlock(&(_st)->st_lock) 184 185 typedef struct mtx ieee80211_scan_iter_lock_t; 186 #define IEEE80211_SCAN_ITER_LOCK_INIT(_st, _name) \ 187 mtx_init(&(_st)->st_scanlock, _name, "802.11 scangen", MTX_DEF) 188 #define IEEE80211_SCAN_ITER_LOCK_DESTROY(_st) mtx_destroy(&(_st)->st_scanlock) 189 #define IEEE80211_SCAN_ITER_LOCK(_st) mtx_lock(&(_st)->st_scanlock) 190 #define IEEE80211_SCAN_ITER_UNLOCK(_st) mtx_unlock(&(_st)->st_scanlock) 191 192 /* 193 * Mesh node/routing definitions. 194 */ 195 typedef struct mtx ieee80211_rte_lock_t; 196 #define MESH_RT_ENTRY_LOCK_INIT(_rt, _name) \ 197 mtx_init(&(rt)->rt_lock, _name, "802.11s route entry", MTX_DEF) 198 #define MESH_RT_ENTRY_LOCK_DESTROY(_rt) \ 199 mtx_destroy(&(_rt)->rt_lock) 200 #define MESH_RT_ENTRY_LOCK(rt) mtx_lock(&(rt)->rt_lock) 201 #define MESH_RT_ENTRY_LOCK_ASSERT(rt) mtx_assert(&(rt)->rt_lock, MA_OWNED) 202 #define MESH_RT_ENTRY_UNLOCK(rt) mtx_unlock(&(rt)->rt_lock) 203 204 typedef struct mtx ieee80211_rt_lock_t; 205 #define MESH_RT_LOCK(ms) mtx_lock(&(ms)->ms_rt_lock) 206 #define MESH_RT_LOCK_ASSERT(ms) mtx_assert(&(ms)->ms_rt_lock, MA_OWNED) 207 #define MESH_RT_UNLOCK(ms) mtx_unlock(&(ms)->ms_rt_lock) 208 #define MESH_RT_LOCK_INIT(ms, name) \ 209 mtx_init(&(ms)->ms_rt_lock, name, "802.11s routing table", MTX_DEF) 210 #define MESH_RT_LOCK_DESTROY(ms) \ 211 mtx_destroy(&(ms)->ms_rt_lock) 212 213 /* 214 * Node reference counting definitions. 215 * 216 * ieee80211_node_initref initialize the reference count to 1 217 * ieee80211_node_incref add a reference 218 * ieee80211_node_decref remove a reference 219 * ieee80211_node_dectestref remove a reference and return 1 if this 220 * is the last reference, otherwise 0 221 * ieee80211_node_refcnt reference count for printing (only) 222 */ 223 #include <machine/atomic.h> 224 225 #define ieee80211_node_initref(_ni) \ 226 do { ((_ni)->ni_refcnt = 1); } while (0) 227 #define ieee80211_node_incref(_ni) \ 228 atomic_add_int(&(_ni)->ni_refcnt, 1) 229 #define ieee80211_node_decref(_ni) \ 230 atomic_subtract_int(&(_ni)->ni_refcnt, 1) 231 struct ieee80211_node; 232 int ieee80211_node_dectestref(struct ieee80211_node *ni); 233 #define ieee80211_node_refcnt(_ni) (_ni)->ni_refcnt 234 235 struct ifqueue; 236 struct ieee80211vap; 237 void ieee80211_drain_ifq(struct ifqueue *); 238 void ieee80211_flush_ifq(struct ifqueue *, struct ieee80211vap *); 239 240 void ieee80211_vap_destroy(struct ieee80211vap *); 241 242 #define IFNET_IS_UP_RUNNING(_ifp) \ 243 (((_ifp)->if_flags & IFF_UP) && \ 244 ((_ifp)->if_drv_flags & IFF_DRV_RUNNING)) 245 246 /* XXX TODO: cap these at 1, as hz may not be 1000 */ 247 #define msecs_to_ticks(ms) (((ms)*hz)/1000) 248 #define ticks_to_msecs(t) (1000*(t) / hz) 249 #define ticks_to_secs(t) ((t) / hz) 250 251 #define ieee80211_time_after(a,b) ((long)(b) - (long)(a) < 0) 252 #define ieee80211_time_before(a,b) ieee80211_time_after(b,a) 253 #define ieee80211_time_after_eq(a,b) ((long)(a) - (long)(b) >= 0) 254 #define ieee80211_time_before_eq(a,b) ieee80211_time_after_eq(b,a) 255 256 struct mbuf *ieee80211_getmgtframe(uint8_t **frm, int headroom, int pktlen); 257 258 /* tx path usage */ 259 #define M_ENCAP M_PROTO1 /* 802.11 encap done */ 260 #define M_EAPOL M_PROTO3 /* PAE/EAPOL frame */ 261 #define M_PWR_SAV M_PROTO4 /* bypass PS handling */ 262 #define M_MORE_DATA M_PROTO5 /* more data frames to follow */ 263 #define M_FF M_PROTO6 /* fast frame / A-MSDU */ 264 #define M_TXCB M_PROTO7 /* do tx complete callback */ 265 #define M_AMPDU_MPDU M_PROTO8 /* ok for A-MPDU aggregation */ 266 #define M_FRAG M_PROTO9 /* frame fragmentation */ 267 #define M_FIRSTFRAG M_PROTO10 /* first frame fragment */ 268 #define M_LASTFRAG M_PROTO11 /* last frame fragment */ 269 270 #define M_80211_TX \ 271 (M_ENCAP|M_EAPOL|M_PWR_SAV|M_MORE_DATA|M_FF|M_TXCB| \ 272 M_AMPDU_MPDU|M_FRAG|M_FIRSTFRAG|M_LASTFRAG) 273 274 /* rx path usage */ 275 #define M_AMPDU M_PROTO1 /* A-MPDU subframe */ 276 #define M_WEP M_PROTO2 /* WEP done by hardware */ 277 #if 0 278 #define M_AMPDU_MPDU M_PROTO8 /* A-MPDU re-order done */ 279 #endif 280 #define M_80211_RX (M_AMPDU|M_WEP|M_AMPDU_MPDU) 281 282 #define IEEE80211_MBUF_TX_FLAG_BITS \ 283 M_FLAG_BITS \ 284 "\15M_ENCAP\17M_EAPOL\20M_PWR_SAV\21M_MORE_DATA\22M_FF\23M_TXCB" \ 285 "\24M_AMPDU_MPDU\25M_FRAG\26M_FIRSTFRAG\27M_LASTFRAG" 286 287 #define IEEE80211_MBUF_RX_FLAG_BITS \ 288 M_FLAG_BITS \ 289 "\15M_AMPDU\16M_WEP\24M_AMPDU_MPDU" 290 291 /* 292 * Store WME access control bits in the vlan tag. 293 * This is safe since it's done after the packet is classified 294 * (where we use any previous tag) and because it's passed 295 * directly in to the driver and there's no chance someone 296 * else will clobber them on us. 297 */ 298 #define M_WME_SETAC(m, ac) \ 299 ((m)->m_pkthdr.ether_vtag = (ac)) 300 #define M_WME_GETAC(m) ((m)->m_pkthdr.ether_vtag) 301 302 /* 303 * Mbufs on the power save queue are tagged with an age and 304 * timed out. We reuse the hardware checksum field in the 305 * mbuf packet header to store this data. 306 */ 307 #define M_AGE_SET(m,v) (m->m_pkthdr.csum_data = v) 308 #define M_AGE_GET(m) (m->m_pkthdr.csum_data) 309 #define M_AGE_SUB(m,adj) (m->m_pkthdr.csum_data -= adj) 310 311 /* 312 * Store the sequence number. 313 */ 314 #define M_SEQNO_SET(m, seqno) \ 315 ((m)->m_pkthdr.tso_segsz = (seqno)) 316 #define M_SEQNO_GET(m) ((m)->m_pkthdr.tso_segsz) 317 318 #define MTAG_ABI_NET80211 1132948340 /* net80211 ABI */ 319 320 struct ieee80211_cb { 321 void (*func)(struct ieee80211_node *, void *, int status); 322 void *arg; 323 }; 324 #define NET80211_TAG_CALLBACK 0 /* xmit complete callback */ 325 int ieee80211_add_callback(struct mbuf *m, 326 void (*func)(struct ieee80211_node *, void *, int), void *arg); 327 void ieee80211_process_callback(struct ieee80211_node *, struct mbuf *, int); 328 329 #define NET80211_TAG_XMIT_PARAMS 1 330 /* See below; this is after the bpf_params definition */ 331 332 #define NET80211_TAG_RECV_PARAMS 2 333 334 #define NET80211_TAG_TOA_PARAMS 3 335 336 struct ieee80211com; 337 int ieee80211_parent_xmitpkt(struct ieee80211com *, struct mbuf *); 338 int ieee80211_vap_xmitpkt(struct ieee80211vap *, struct mbuf *); 339 340 void get_random_bytes(void *, size_t); 341 342 void ieee80211_sysctl_attach(struct ieee80211com *); 343 void ieee80211_sysctl_detach(struct ieee80211com *); 344 void ieee80211_sysctl_vattach(struct ieee80211vap *); 345 void ieee80211_sysctl_vdetach(struct ieee80211vap *); 346 347 SYSCTL_DECL(_net_wlan); 348 int ieee80211_sysctl_msecs_ticks(SYSCTL_HANDLER_ARGS); 349 350 void ieee80211_load_module(const char *); 351 352 /* 353 * A "policy module" is an adjunct module to net80211 that provides 354 * functionality that typically includes policy decisions. This 355 * modularity enables extensibility and vendor-supplied functionality. 356 */ 357 #define _IEEE80211_POLICY_MODULE(policy, name, version) \ 358 typedef void (*policy##_setup)(int); \ 359 SET_DECLARE(policy##_set, policy##_setup); \ 360 static int \ 361 wlan_##name##_modevent(module_t mod, int type, void *unused) \ 362 { \ 363 policy##_setup * const *iter, f; \ 364 switch (type) { \ 365 case MOD_LOAD: \ 366 SET_FOREACH(iter, policy##_set) { \ 367 f = (void*) *iter; \ 368 f(type); \ 369 } \ 370 return 0; \ 371 case MOD_UNLOAD: \ 372 case MOD_QUIESCE: \ 373 if (nrefs) { \ 374 printf("wlan_" #name ": still in use " \ 375 "(%u dynamic refs)\n", nrefs); \ 376 return EBUSY; \ 377 } \ 378 if (type == MOD_UNLOAD) { \ 379 SET_FOREACH(iter, policy##_set) { \ 380 f = (void*) *iter; \ 381 f(type); \ 382 } \ 383 } \ 384 return 0; \ 385 } \ 386 return EINVAL; \ 387 } \ 388 static moduledata_t name##_mod = { \ 389 "wlan_" #name, \ 390 wlan_##name##_modevent, \ 391 0 \ 392 }; \ 393 DECLARE_MODULE(wlan_##name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);\ 394 MODULE_VERSION(wlan_##name, version); \ 395 MODULE_DEPEND(wlan_##name, wlan, 1, 1, 1) 396 397 /* 398 * Crypto modules implement cipher support. 399 */ 400 #define IEEE80211_CRYPTO_MODULE(name, version) \ 401 _IEEE80211_POLICY_MODULE(crypto, name, version); \ 402 static void \ 403 name##_modevent(int type) \ 404 { \ 405 if (type == MOD_LOAD) \ 406 ieee80211_crypto_register(&name); \ 407 else \ 408 ieee80211_crypto_unregister(&name); \ 409 } \ 410 TEXT_SET(crypto##_set, name##_modevent) 411 412 /* 413 * Scanner modules provide scanning policy. 414 */ 415 #define IEEE80211_SCANNER_MODULE(name, version) \ 416 _IEEE80211_POLICY_MODULE(scanner, name, version) 417 418 #define IEEE80211_SCANNER_ALG(name, alg, v) \ 419 static void \ 420 name##_modevent(int type) \ 421 { \ 422 if (type == MOD_LOAD) \ 423 ieee80211_scanner_register(alg, &v); \ 424 else \ 425 ieee80211_scanner_unregister(alg, &v); \ 426 } \ 427 TEXT_SET(scanner_set, name##_modevent); \ 428 429 /* 430 * ACL modules implement acl policy. 431 */ 432 #define IEEE80211_ACL_MODULE(name, alg, version) \ 433 _IEEE80211_POLICY_MODULE(acl, name, version); \ 434 static void \ 435 alg##_modevent(int type) \ 436 { \ 437 if (type == MOD_LOAD) \ 438 ieee80211_aclator_register(&alg); \ 439 else \ 440 ieee80211_aclator_unregister(&alg); \ 441 } \ 442 TEXT_SET(acl_set, alg##_modevent); \ 443 444 /* 445 * Authenticator modules handle 802.1x/WPA authentication. 446 */ 447 #define IEEE80211_AUTH_MODULE(name, version) \ 448 _IEEE80211_POLICY_MODULE(auth, name, version) 449 450 #define IEEE80211_AUTH_ALG(name, alg, v) \ 451 static void \ 452 name##_modevent(int type) \ 453 { \ 454 if (type == MOD_LOAD) \ 455 ieee80211_authenticator_register(alg, &v); \ 456 else \ 457 ieee80211_authenticator_unregister(alg); \ 458 } \ 459 TEXT_SET(auth_set, name##_modevent) 460 461 /* 462 * Rate control modules provide tx rate control support. 463 */ 464 #define IEEE80211_RATECTL_MODULE(alg, version) \ 465 _IEEE80211_POLICY_MODULE(ratectl, alg, version); \ 466 467 #define IEEE80211_RATECTL_ALG(name, alg, v) \ 468 static void \ 469 alg##_modevent(int type) \ 470 { \ 471 if (type == MOD_LOAD) \ 472 ieee80211_ratectl_register(alg, &v); \ 473 else \ 474 ieee80211_ratectl_unregister(alg); \ 475 } \ 476 TEXT_SET(ratectl##_set, alg##_modevent) 477 478 struct ieee80211req; 479 typedef int ieee80211_ioctl_getfunc(struct ieee80211vap *, 480 struct ieee80211req *); 481 SET_DECLARE(ieee80211_ioctl_getset, ieee80211_ioctl_getfunc); 482 #define IEEE80211_IOCTL_GET(_name, _get) TEXT_SET(ieee80211_ioctl_getset, _get) 483 484 typedef int ieee80211_ioctl_setfunc(struct ieee80211vap *, 485 struct ieee80211req *); 486 SET_DECLARE(ieee80211_ioctl_setset, ieee80211_ioctl_setfunc); 487 #define IEEE80211_IOCTL_SET(_name, _set) TEXT_SET(ieee80211_ioctl_setset, _set) 488 #endif /* _KERNEL */ 489 490 /* XXX this stuff belongs elsewhere */ 491 /* 492 * Message formats for messages from the net80211 layer to user 493 * applications via the routing socket. These messages are appended 494 * to an if_announcemsghdr structure. 495 */ 496 struct ieee80211_join_event { 497 uint8_t iev_addr[6]; 498 }; 499 500 struct ieee80211_leave_event { 501 uint8_t iev_addr[6]; 502 }; 503 504 struct ieee80211_replay_event { 505 uint8_t iev_src[6]; /* src MAC */ 506 uint8_t iev_dst[6]; /* dst MAC */ 507 uint8_t iev_cipher; /* cipher type */ 508 uint8_t iev_keyix; /* key id/index */ 509 uint64_t iev_keyrsc; /* RSC from key */ 510 uint64_t iev_rsc; /* RSC from frame */ 511 }; 512 513 struct ieee80211_michael_event { 514 uint8_t iev_src[6]; /* src MAC */ 515 uint8_t iev_dst[6]; /* dst MAC */ 516 uint8_t iev_cipher; /* cipher type */ 517 uint8_t iev_keyix; /* key id/index */ 518 }; 519 520 struct ieee80211_wds_event { 521 uint8_t iev_addr[6]; 522 }; 523 524 struct ieee80211_csa_event { 525 uint32_t iev_flags; /* channel flags */ 526 uint16_t iev_freq; /* setting in Mhz */ 527 uint8_t iev_ieee; /* IEEE channel number */ 528 uint8_t iev_mode; /* CSA mode */ 529 uint8_t iev_count; /* CSA count */ 530 }; 531 532 struct ieee80211_cac_event { 533 uint32_t iev_flags; /* channel flags */ 534 uint16_t iev_freq; /* setting in Mhz */ 535 uint8_t iev_ieee; /* IEEE channel number */ 536 /* XXX timestamp? */ 537 uint8_t iev_type; /* IEEE80211_NOTIFY_CAC_* */ 538 }; 539 540 struct ieee80211_radar_event { 541 uint32_t iev_flags; /* channel flags */ 542 uint16_t iev_freq; /* setting in Mhz */ 543 uint8_t iev_ieee; /* IEEE channel number */ 544 /* XXX timestamp? */ 545 }; 546 547 struct ieee80211_auth_event { 548 uint8_t iev_addr[6]; 549 }; 550 551 struct ieee80211_deauth_event { 552 uint8_t iev_addr[6]; 553 }; 554 555 struct ieee80211_country_event { 556 uint8_t iev_addr[6]; 557 uint8_t iev_cc[2]; /* ISO country code */ 558 }; 559 560 struct ieee80211_radio_event { 561 uint8_t iev_state; /* 1 on, 0 off */ 562 }; 563 564 #define RTM_IEEE80211_ASSOC 100 /* station associate (bss mode) */ 565 #define RTM_IEEE80211_REASSOC 101 /* station re-associate (bss mode) */ 566 #define RTM_IEEE80211_DISASSOC 102 /* station disassociate (bss mode) */ 567 #define RTM_IEEE80211_JOIN 103 /* station join (ap mode) */ 568 #define RTM_IEEE80211_LEAVE 104 /* station leave (ap mode) */ 569 #define RTM_IEEE80211_SCAN 105 /* scan complete, results available */ 570 #define RTM_IEEE80211_REPLAY 106 /* sequence counter replay detected */ 571 #define RTM_IEEE80211_MICHAEL 107 /* Michael MIC failure detected */ 572 #define RTM_IEEE80211_REJOIN 108 /* station re-associate (ap mode) */ 573 #define RTM_IEEE80211_WDS 109 /* WDS discovery (ap mode) */ 574 #define RTM_IEEE80211_CSA 110 /* Channel Switch Announcement event */ 575 #define RTM_IEEE80211_RADAR 111 /* radar event */ 576 #define RTM_IEEE80211_CAC 112 /* Channel Availability Check event */ 577 #define RTM_IEEE80211_DEAUTH 113 /* station deauthenticate */ 578 #define RTM_IEEE80211_AUTH 114 /* station authenticate (ap mode) */ 579 #define RTM_IEEE80211_COUNTRY 115 /* discovered country code (sta mode) */ 580 #define RTM_IEEE80211_RADIO 116 /* RF kill switch state change */ 581 582 /* 583 * Structure prepended to raw packets sent through the bpf 584 * interface when set to DLT_IEEE802_11_RADIO. This allows 585 * user applications to specify pretty much everything in 586 * an Atheros tx descriptor. XXX need to generalize. 587 * 588 * XXX cannot be more than 14 bytes as it is copied to a sockaddr's 589 * XXX sa_data area. 590 */ 591 struct ieee80211_bpf_params { 592 uint8_t ibp_vers; /* version */ 593 #define IEEE80211_BPF_VERSION 0 594 uint8_t ibp_len; /* header length in bytes */ 595 uint8_t ibp_flags; 596 #define IEEE80211_BPF_SHORTPRE 0x01 /* tx with short preamble */ 597 #define IEEE80211_BPF_NOACK 0x02 /* tx with no ack */ 598 #define IEEE80211_BPF_CRYPTO 0x04 /* tx with h/w encryption */ 599 #define IEEE80211_BPF_FCS 0x10 /* frame incldues FCS */ 600 #define IEEE80211_BPF_DATAPAD 0x20 /* frame includes data padding */ 601 #define IEEE80211_BPF_RTS 0x40 /* tx with RTS/CTS */ 602 #define IEEE80211_BPF_CTS 0x80 /* tx with CTS only */ 603 uint8_t ibp_pri; /* WME/WMM AC+tx antenna */ 604 uint8_t ibp_try0; /* series 1 try count */ 605 uint8_t ibp_rate0; /* series 1 IEEE tx rate */ 606 uint8_t ibp_power; /* tx power (device units) */ 607 uint8_t ibp_ctsrate; /* IEEE tx rate for CTS */ 608 uint8_t ibp_try1; /* series 2 try count */ 609 uint8_t ibp_rate1; /* series 2 IEEE tx rate */ 610 uint8_t ibp_try2; /* series 3 try count */ 611 uint8_t ibp_rate2; /* series 3 IEEE tx rate */ 612 uint8_t ibp_try3; /* series 4 try count */ 613 uint8_t ibp_rate3; /* series 4 IEEE tx rate */ 614 }; 615 616 #ifdef _KERNEL 617 struct ieee80211_tx_params { 618 struct ieee80211_bpf_params params; 619 }; 620 int ieee80211_add_xmit_params(struct mbuf *m, 621 const struct ieee80211_bpf_params *); 622 int ieee80211_get_xmit_params(struct mbuf *m, 623 struct ieee80211_bpf_params *); 624 625 /* 626 * Note: this is fine for 3x3 (and 4x4) 11n HT40; 627 * but getting EVM information for VHT80, VHT160 628 * will involve more than 6 EVM pilots. 629 */ 630 #define IEEE80211_MAX_CHAINS 4 631 #define IEEE80211_MAX_EVM_PILOTS 6 632 633 #define IEEE80211_R_NF 0x00000001 /* global NF value valid */ 634 #define IEEE80211_R_RSSI 0x00000002 /* global RSSI value valid */ 635 #define IEEE80211_R_C_CHAIN 0x00000004 /* RX chain count valid */ 636 #define IEEE80211_R_C_NF 0x00000008 /* per-chain NF value valid */ 637 #define IEEE80211_R_C_RSSI 0x00000010 /* per-chain RSSI value valid */ 638 #define IEEE80211_R_C_EVM 0x00000020 /* per-chain EVM valid */ 639 #define IEEE80211_R_C_HT40 0x00000040 /* RX'ed packet is 40mhz, pilots 4,5 valid */ 640 #define IEEE80211_R_FREQ 0x00000080 /* Freq value populated, MHz */ 641 #define IEEE80211_R_IEEE 0x00000100 /* IEEE value populated */ 642 #define IEEE80211_R_BAND 0x00000200 /* Frequency band populated */ 643 #define IEEE80211_R_TSF32 0x00004000 /* 32 bit TSF */ 644 #define IEEE80211_R_TSF64 0x00008000 /* 64 bit TSF */ 645 #define IEEE80211_R_TSF_START 0x00010000 /* TSF is sampled at start of frame */ 646 #define IEEE80211_R_TSF_END 0x00020000 /* TSF is sampled at end of frame */ 647 648 /* RX packet flags - describe the kind of frame */ 649 #define IEEE80211_RX_F_STBC 0x00000001 650 #define IEEE80211_RX_F_LDPC 0x00000002 651 #define IEEE80211_RX_F_AMSDU 0x00000004 /* This is the start of an decap AMSDU list */ 652 #define IEEE80211_RX_F_AMSDU_MORE 0x00000008 /* This is another decap AMSDU frame in the batch */ 653 #define IEEE80211_RX_F_AMPDU 0x00000010 /* This is the start of an decap AMPDU list */ 654 #define IEEE80211_RX_F_AMPDU_MORE 0x00000020 /* This is another decap AMPDU frame in the batch */ 655 #define IEEE80211_RX_F_FAIL_FCSCRC 0x00000040 /* Failed CRC/FCS */ 656 #define IEEE80211_RX_F_FAIL_MIC 0x00000080 /* Failed MIC check */ 657 #define IEEE80211_RX_F_DECRYPTED 0x00000100 /* Hardware decrypted */ 658 #define IEEE80211_RX_F_IV_STRIP 0x00000200 /* Decrypted; IV stripped */ 659 #define IEEE80211_RX_F_MMIC_STRIP 0x00000400 /* Decrypted; MMIC stripped */ 660 #define IEEE80211_RX_F_SHORTGI 0x00000800 /* This is a short-GI frame */ 661 662 /* Channel width */ 663 #define IEEE80211_RX_FW_20MHZ 1 664 #define IEEE80211_RX_FW_40MHZ 2 665 #define IEEE80211_RX_FW_80MHZ 3 666 667 /* PHY type */ 668 #define IEEE80211_RX_FP_11B 1 669 #define IEEE80211_RX_FP_11G 2 670 #define IEEE80211_RX_FP_11A 3 671 #define IEEE80211_RX_FP_11NA 4 672 #define IEEE80211_RX_FP_11NG 5 673 674 struct ieee80211_rx_stats { 675 uint32_t r_flags; /* IEEE80211_R_* flags */ 676 uint32_t c_pktflags; /* IEEE80211_RX_F_* flags */ 677 678 uint64_t c_rx_tsf; /* 32 or 64 bit TSF */ 679 680 /* All DWORD aligned */ 681 int16_t c_nf_ctl[IEEE80211_MAX_CHAINS]; /* per-chain NF */ 682 int16_t c_nf_ext[IEEE80211_MAX_CHAINS]; /* per-chain NF */ 683 int16_t c_rssi_ctl[IEEE80211_MAX_CHAINS]; /* per-chain RSSI */ 684 int16_t c_rssi_ext[IEEE80211_MAX_CHAINS]; /* per-chain RSSI */ 685 686 /* 32 bits */ 687 uint8_t c_nf; /* global NF */ 688 uint8_t c_rssi; /* global RSSI */ 689 uint8_t c_chain; /* number of RX chains involved */ 690 uint8_t c_rate; /* legacy + 11n rate code */ 691 692 /* 32 bits */ 693 uint16_t c_freq; /* Frequency, MHz */ 694 uint8_t c_ieee; /* Channel */ 695 uint8_t c_width; /* channel width, FW flags above */ 696 697 /* Force alignment to DWORD */ 698 union { 699 uint8_t evm[IEEE80211_MAX_CHAINS][IEEE80211_MAX_EVM_PILOTS]; 700 /* per-chain, per-pilot EVM values */ 701 uint32_t __aln[8]; 702 } evm; 703 704 /* 32 bits */ 705 uint8_t c_phytype; /* PHY type, FW flags above */ 706 uint8_t c_pad2[3]; 707 }; 708 709 struct ieee80211_rx_params { 710 struct ieee80211_rx_stats params; 711 }; 712 int ieee80211_add_rx_params(struct mbuf *m, 713 const struct ieee80211_rx_stats *rxs); 714 int ieee80211_get_rx_params(struct mbuf *m, 715 struct ieee80211_rx_stats *rxs); 716 const struct ieee80211_rx_stats * ieee80211_get_rx_params_ptr(struct mbuf *m); 717 718 struct ieee80211_toa_params { 719 int request_id; 720 }; 721 int ieee80211_add_toa_params(struct mbuf *m, 722 const struct ieee80211_toa_params *p); 723 int ieee80211_get_toa_params(struct mbuf *m, 724 struct ieee80211_toa_params *p); 725 #endif /* _KERNEL */ 726 727 /* 728 * Malloc API. Other BSD operating systems have slightly 729 * different malloc/free namings (eg DragonflyBSD.) 730 */ 731 #define IEEE80211_MALLOC malloc 732 #define IEEE80211_FREE free 733 734 /* XXX TODO: get rid of WAITOK, fix all the users of it? */ 735 #define IEEE80211_M_NOWAIT M_NOWAIT 736 #define IEEE80211_M_WAITOK M_WAITOK 737 #define IEEE80211_M_ZERO M_ZERO 738 739 /* XXX TODO: the type fields */ 740 741 #endif /* _NET80211_IEEE80211_FREEBSD_H_ */ 742