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