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