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: head/sys/net80211/ieee80211_freebsd.h 195618 2009-07-11 15:02:45Z rpaulo $ 26 */ 27 #ifndef _NET80211_IEEE80211_DRAGONFLY_H_ 28 #define _NET80211_IEEE80211_DRAGONFLY_H_ 29 30 #ifdef _KERNEL 31 32 #include <sys/param.h> 33 #include <sys/types.h> 34 #include <sys/serialize.h> 35 #include <sys/sysctl.h> 36 #include <sys/condvar.h> 37 #include <sys/lock.h> 38 #include <sys/taskqueue.h> 39 40 #include <sys/mutex2.h> 41 #include <sys/serialize2.h> 42 43 #ifndef IF_PREPEND_LIST 44 45 /* XXX all are prepended to normal queue */ 46 #define _IF_PREPEND_LIST(ifq, mhead, mtail, mcount, bcnt) do { \ 47 (mtail)->m_nextpkt = (ifq)->ifsq_norm_head; \ 48 if ((ifq)->ifsq_norm_tail == NULL) \ 49 (ifq)->ifsq_norm_tail = (mtail); \ 50 (ifq)->ifsq_norm_head = (mhead); \ 51 (ifq)->ifsq_len += (mcount); \ 52 (ifq)->ifsq_bcnt += (bcnt); \ 53 } while (0) 54 55 #define IF_PREPEND_LIST(ifq, mhead, mtail, mcount, bcnt) do { \ 56 wlan_assert_serialized(); \ 57 _IF_PREPEND_LIST(ifq, mhead, mtail, mcount, bcnt); \ 58 } while (0) 59 60 #endif /* IF_PREPEND_LIST */ 61 62 /* 63 * Global serializer (operates like a non-reentrant lockmgr lock) 64 */ 65 extern struct lwkt_serialize wlan_global_serializer; 66 extern int ieee80211_force_swcrypto; 67 68 #define wlan_serialize_enter() _wlan_serialize_enter(__func__) 69 #define wlan_serialize_exit() _wlan_serialize_exit(__func__) 70 #define wlan_serialize_push() _wlan_serialize_push(__func__) 71 #define wlan_serialize_pop(wst) _wlan_serialize_pop(__func__, wst) 72 #define wlan_is_serialized() _wlan_is_serialized() 73 void _wlan_serialize_enter(const char *funcname); 74 void _wlan_serialize_exit(const char *funcname); 75 int _wlan_serialize_push(const char *funcname); 76 void _wlan_serialize_pop(const char *funcname, int wst); 77 int _wlan_is_serialized(void); 78 int wlan_serialize_sleep(void *ident, int flags, const char *wmesg, int timo); 79 80 static __inline void 81 wlan_assert_serialized(void) 82 { 83 ASSERT_SERIALIZED(&wlan_global_serializer); 84 } 85 86 static __inline void 87 wlan_assert_notserialized(void) 88 { 89 ASSERT_NOT_SERIALIZED(&wlan_global_serializer); 90 } 91 92 /* 93 * Node reference counting definitions. 94 * 95 * ieee80211_node_initref initialize the reference count to 1 96 * ieee80211_node_incref add a reference 97 * ieee80211_node_decref remove a reference 98 * ieee80211_node_dectestref remove a reference and return 1 if this 99 * is the last reference, otherwise 0 100 * ieee80211_node_refcnt reference count for printing (only) 101 */ 102 #include <machine/atomic.h> 103 104 #define ieee80211_node_initref(_ni) \ 105 do { ((_ni)->ni_refcnt = 1); } while (0) 106 #define ieee80211_node_incref(_ni) \ 107 atomic_add_int(&(_ni)->ni_refcnt, 1) 108 #define ieee80211_node_decref(_ni) \ 109 atomic_subtract_int(&(_ni)->ni_refcnt, 1) 110 struct ieee80211_node; 111 int ieee80211_node_dectestref(struct ieee80211_node *ni); 112 #define ieee80211_node_refcnt(_ni) (_ni)->ni_refcnt 113 114 struct ifqueue; 115 struct ieee80211vap; 116 struct ieee80211com; 117 void ieee80211_flush_ifq(struct ifaltq *, struct ieee80211vap *); 118 119 void ieee80211_vap_destroy(struct ieee80211vap *); 120 int ieee80211_vap_xmitpkt(struct ieee80211vap *vap, struct mbuf *m); 121 int ieee80211_parent_xmitpkt(struct ieee80211com *ic, struct mbuf *m); 122 int ieee80211_handoff(struct ifnet *, struct mbuf *); 123 uint16_t ieee80211_txtime(struct ieee80211_node *, u_int, uint8_t, uint32_t); 124 125 #define IFNET_IS_UP_RUNNING(_ifp) \ 126 (((_ifp)->if_flags & IFF_UP) && \ 127 ((_ifp)->if_flags & IFF_RUNNING)) 128 129 /* XXX TODO: cap these at 1, as hz may not be 1000 */ 130 #define msecs_to_ticks(ms) (((ms)*hz)/1000) 131 #define ticks_to_msecs(t) (1000*(t) / hz) 132 #define ticks_to_secs(t) ((t) / hz) 133 134 #define ieee80211_time_after(a,b) ((long)(b) - (long)(a) < 0) 135 #define ieee80211_time_before(a,b) ieee80211_time_after(b,a) 136 #define ieee80211_time_after_eq(a,b) ((long)(a) - (long)(b) >= 0) 137 #define ieee80211_time_before_eq(a,b) ieee80211_time_after_eq(b,a) 138 139 struct mbuf *ieee80211_getmgtframe(uint8_t **frm, int headroom, int pktlen); 140 141 /* tx path usage */ 142 #define M_ENCAP M_PROTO1 /* 802.11 encap done */ 143 #define M_EAPOL M_PROTO3 /* PAE/EAPOL frame */ 144 #define M_PWR_SAV M_PROTO4 /* bypass PS handling */ 145 #define M_MORE_DATA M_PROTO5 /* more data frames to follow */ 146 #define M_FF M_PROTO6 /* fast frame / A-MSDU */ 147 #define M_TXCB M_PROTO7 /* do tx complete callback */ 148 #define M_AMPDU_MPDU M_PROTO8 /* ok for A-MPDU aggregation */ 149 #define M_80211_TX \ 150 (M_FRAG|M_FIRSTFRAG|M_LASTFRAG|M_ENCAP|M_EAPOL|M_PWR_SAV|\ 151 M_MORE_DATA|M_FF|M_TXCB|M_AMPDU_MPDU) 152 153 /* rx path usage */ 154 #define M_AMPDU M_PROTO1 /* A-MPDU subframe */ 155 #define M_WEP M_PROTO2 /* WEP done by hardware */ 156 #if 0 157 #define M_AMPDU_MPDU M_PROTO8 /* A-MPDU re-order done */ 158 #endif 159 #define M_80211_RX (M_AMPDU|M_WEP|M_AMPDU_MPDU) 160 161 #define IEEE80211_MBUF_TX_FLAG_BITS \ 162 "\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_RDONLY\5M_ENCAP\6M_WEP\7M_EAPOL" \ 163 "\10M_PWR_SAV\11M_MORE_DATA\12M_BCAST\13M_MCAST\14M_FRAG\15M_FIRSTFRAG" \ 164 "\16M_LASTFRAG\17M_SKIP_FIREWALL\20M_FREELIST\21M_VLANTAG\22M_PROMISC" \ 165 "\23M_NOFREE\24M_FF\25M_TXCB\26M_AMPDU_MPDU\27M_FLOWID" 166 167 #define IEEE80211_MBUF_RX_FLAG_BITS \ 168 "\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_RDONLY\5M_AMPDU\6M_WEP\7M_PROTO3" \ 169 "\10M_PROTO4\11M_PROTO5\12M_BCAST\13M_MCAST\14M_FRAG\15M_FIRSTFRAG" \ 170 "\16M_LASTFRAG\17M_SKIP_FIREWALL\20M_FREELIST\21M_VLANTAG\22M_PROMISC" \ 171 "\23M_NOFREE\24M_PROTO6\25M_PROTO7\26M_AMPDU_MPDU\27M_FLOWID" 172 173 /* 174 * Store WME access control bits in the vlan tag. 175 * This is safe since it's done after the packet is classified 176 * (where we use any previous tag) and because it's passed 177 * directly in to the driver and there's no chance someone 178 * else will clobber them on us. 179 */ 180 #define M_WME_SETAC(m, ac) \ 181 ((m)->m_pkthdr.ether_vlantag = (ac)) 182 #define M_WME_GETAC(m) ((m)->m_pkthdr.ether_vlantag) 183 184 /* 185 * Mbufs on the power save queue are tagged with an age and 186 * timed out. We reuse the hardware checksum field in the 187 * mbuf packet header to store this data. 188 */ 189 #define M_AGE_SET(m,v) (m->m_pkthdr.csum_data = v) 190 #define M_AGE_GET(m) (m->m_pkthdr.csum_data) 191 #define M_AGE_SUB(m,adj) (m->m_pkthdr.csum_data -= adj) 192 193 /* 194 * Store the sequence number. 195 */ 196 #define M_SEQNO_SET(m, seqno) \ 197 ((m)->m_pkthdr.wlan_seqno = (seqno)) 198 #define M_SEQNO_GET(m) ((m)->m_pkthdr.wlan_seqno) 199 200 #define MTAG_ABI_NET80211 1132948340 /* net80211 ABI */ 201 202 struct ieee80211_cb { 203 void (*func)(struct ieee80211_node *, void *, int status); 204 void *arg; 205 }; 206 #define NET80211_TAG_CALLBACK 0 /* xmit complete callback */ 207 int ieee80211_add_callback(struct mbuf *m, 208 void (*func)(struct ieee80211_node *, void *, int), void *arg); 209 void ieee80211_process_callback(struct ieee80211_node *, struct mbuf *, int); 210 211 #define NET80211_TAG_XMIT_PARAMS 1 212 /* See below; this is after the bpf_params definition */ 213 214 void get_random_bytes(void *, size_t); 215 216 #define NET80211_TAG_RECV_PARAMS 2 217 218 void ieee80211_sysctl_attach(struct ieee80211com *); 219 void ieee80211_sysctl_detach(struct ieee80211com *); 220 void ieee80211_sysctl_vattach(struct ieee80211vap *); 221 void ieee80211_sysctl_vdetach(struct ieee80211vap *); 222 223 SYSCTL_DECL(_net_wlan); 224 int ieee80211_sysctl_msecs_ticks(SYSCTL_HANDLER_ARGS); 225 226 void ieee80211_load_module(const char *); 227 228 /* 229 * A "policy module" is an adjunct module to net80211 that provides 230 * functionality that typically includes policy decisions. This 231 * modularity enables extensibility and vendor-supplied functionality. 232 */ 233 #define _IEEE80211_POLICY_MODULE(policy, name, version) \ 234 typedef void (*policy##_setup)(int); \ 235 SET_DECLARE(policy##_set, policy##_setup); \ 236 static int \ 237 wlan_##name##_modevent(module_t mod, int type, void *unused) \ 238 { \ 239 policy##_setup * const *iter, f; \ 240 int error; \ 241 \ 242 switch (type) { \ 243 case MOD_LOAD: \ 244 SET_FOREACH(iter, policy##_set) { \ 245 f = (void*) *iter; \ 246 f(type); \ 247 } \ 248 error = 0; \ 249 break; \ 250 case MOD_UNLOAD: \ 251 error = 0; \ 252 if (nrefs) { \ 253 kprintf("wlan_" #name ": still in use (%u " \ 254 "dynamic refs)\n", \ 255 nrefs); \ 256 error = EBUSY; \ 257 } else if (type == MOD_UNLOAD) { \ 258 SET_FOREACH(iter, policy##_set) { \ 259 f = (void*) *iter; \ 260 f(type); \ 261 } \ 262 } \ 263 break; \ 264 default: \ 265 error = EINVAL; \ 266 break; \ 267 } \ 268 \ 269 return error; \ 270 } \ 271 static moduledata_t name##_mod = { \ 272 "wlan_" #name, \ 273 wlan_##name##_modevent, \ 274 0 \ 275 }; \ 276 DECLARE_MODULE(wlan_##name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);\ 277 MODULE_VERSION(wlan_##name, version); \ 278 MODULE_DEPEND(wlan_##name, wlan, 1, 1, 1) 279 280 /* 281 * Crypto modules implement cipher support. 282 */ 283 #define IEEE80211_CRYPTO_MODULE(name, version) \ 284 _IEEE80211_POLICY_MODULE(crypto, name, version); \ 285 static void \ 286 name##_modevent(int type) \ 287 { \ 288 /* wlan already serialized! */ \ 289 if (type == MOD_LOAD) \ 290 ieee80211_crypto_register(&name); \ 291 else \ 292 ieee80211_crypto_unregister(&name); \ 293 } \ 294 TEXT_SET(crypto##_set, name##_modevent) 295 296 /* 297 * Scanner modules provide scanning policy. 298 */ 299 #define IEEE80211_SCANNER_MODULE(name, version) \ 300 _IEEE80211_POLICY_MODULE(scanner, name, version) 301 302 #define IEEE80211_SCANNER_ALG(name, alg, v) \ 303 static void \ 304 name##_modevent(int type) \ 305 { \ 306 /* wlan already serialized! */ \ 307 if (type == MOD_LOAD) \ 308 ieee80211_scanner_register(alg, &v); \ 309 else \ 310 ieee80211_scanner_unregister(alg, &v); \ 311 } \ 312 TEXT_SET(scanner_set, name##_modevent); \ 313 314 /* 315 * ACL modules implement acl policy. 316 */ 317 #define IEEE80211_ACL_MODULE(name, alg, version) \ 318 _IEEE80211_POLICY_MODULE(acl, name, version); \ 319 static void \ 320 alg##_modevent(int type) \ 321 { \ 322 /* wlan already serialized! */ \ 323 if (type == MOD_LOAD) \ 324 ieee80211_aclator_register(&alg); \ 325 else \ 326 ieee80211_aclator_unregister(&alg); \ 327 } \ 328 TEXT_SET(acl_set, alg##_modevent); \ 329 330 /* 331 * Authenticator modules handle 802.1x/WPA authentication. 332 */ 333 #define IEEE80211_AUTH_MODULE(name, version) \ 334 _IEEE80211_POLICY_MODULE(auth, name, version) 335 336 #define IEEE80211_AUTH_ALG(name, alg, v) \ 337 static void \ 338 name##_modevent(int type) \ 339 { \ 340 /* wlan already serialized! */ \ 341 if (type == MOD_LOAD) \ 342 ieee80211_authenticator_register(alg, &v); \ 343 else \ 344 ieee80211_authenticator_unregister(alg); \ 345 } \ 346 TEXT_SET(auth_set, name##_modevent) 347 348 /* 349 * Rate control modules provide tx rate control support. 350 */ 351 #define IEEE80211_RATECTL_MODULE(alg, version) \ 352 _IEEE80211_POLICY_MODULE(ratectl, alg, version); \ 353 354 #define IEEE80211_RATECTL_ALG(name, alg, v) \ 355 static void \ 356 alg##_modevent(int type) \ 357 { \ 358 /* wlan already serialized! */ \ 359 if (type == MOD_LOAD) \ 360 ieee80211_ratectl_register(alg, &v); \ 361 else \ 362 ieee80211_ratectl_unregister(alg); \ 363 } \ 364 TEXT_SET(ratectl##_set, alg##_modevent) 365 366 struct ieee80211req; 367 typedef int ieee80211_ioctl_getfunc(struct ieee80211vap *, 368 struct ieee80211req *); 369 SET_DECLARE(ieee80211_ioctl_getset, ieee80211_ioctl_getfunc); 370 #define IEEE80211_IOCTL_GET(_name, _get) TEXT_SET(ieee80211_ioctl_getset, _get) 371 372 typedef int ieee80211_ioctl_setfunc(struct ieee80211vap *, 373 struct ieee80211req *); 374 SET_DECLARE(ieee80211_ioctl_setset, ieee80211_ioctl_setfunc); 375 #define IEEE80211_IOCTL_SET(_name, _set) TEXT_SET(ieee80211_ioctl_setset, _set) 376 #endif /* _KERNEL */ 377 378 /* XXX this stuff belongs elsewhere */ 379 /* 380 * Message formats for messages from the net80211 layer to user 381 * applications via the routing socket. These messages are appended 382 * to an if_announcemsghdr structure. 383 */ 384 struct ieee80211_join_event { 385 uint8_t iev_addr[6]; 386 }; 387 388 struct ieee80211_leave_event { 389 uint8_t iev_addr[6]; 390 }; 391 392 struct ieee80211_replay_event { 393 uint8_t iev_src[6]; /* src MAC */ 394 uint8_t iev_dst[6]; /* dst MAC */ 395 uint8_t iev_cipher; /* cipher type */ 396 uint8_t iev_keyix; /* key id/index */ 397 uint64_t iev_keyrsc; /* RSC from key */ 398 uint64_t iev_rsc; /* RSC from frame */ 399 }; 400 401 struct ieee80211_michael_event { 402 uint8_t iev_src[6]; /* src MAC */ 403 uint8_t iev_dst[6]; /* dst MAC */ 404 uint8_t iev_cipher; /* cipher type */ 405 uint8_t iev_keyix; /* key id/index */ 406 }; 407 408 struct ieee80211_wds_event { 409 uint8_t iev_addr[6]; 410 }; 411 412 struct ieee80211_csa_event { 413 uint32_t iev_flags; /* channel flags */ 414 uint16_t iev_freq; /* setting in Mhz */ 415 uint8_t iev_ieee; /* IEEE channel number */ 416 uint8_t iev_mode; /* CSA mode */ 417 uint8_t iev_count; /* CSA count */ 418 }; 419 420 struct ieee80211_cac_event { 421 uint32_t iev_flags; /* channel flags */ 422 uint16_t iev_freq; /* setting in Mhz */ 423 uint8_t iev_ieee; /* IEEE channel number */ 424 /* XXX timestamp? */ 425 uint8_t iev_type; /* IEEE80211_NOTIFY_CAC_* */ 426 }; 427 428 struct ieee80211_radar_event { 429 uint32_t iev_flags; /* channel flags */ 430 uint16_t iev_freq; /* setting in Mhz */ 431 uint8_t iev_ieee; /* IEEE channel number */ 432 /* XXX timestamp? */ 433 }; 434 435 struct ieee80211_auth_event { 436 uint8_t iev_addr[6]; 437 }; 438 439 struct ieee80211_deauth_event { 440 uint8_t iev_addr[6]; 441 }; 442 443 struct ieee80211_country_event { 444 uint8_t iev_addr[6]; 445 uint8_t iev_cc[2]; /* ISO country code */ 446 }; 447 448 struct ieee80211_radio_event { 449 uint8_t iev_state; /* 1 on, 0 off */ 450 }; 451 452 #define RTM_IEEE80211_ASSOC 100 /* station associate (bss mode) */ 453 #define RTM_IEEE80211_REASSOC 101 /* station re-associate (bss mode) */ 454 #define RTM_IEEE80211_DISASSOC 102 /* station disassociate (bss mode) */ 455 #define RTM_IEEE80211_JOIN 103 /* station join (ap mode) */ 456 #define RTM_IEEE80211_LEAVE 104 /* station leave (ap mode) */ 457 #define RTM_IEEE80211_SCAN 105 /* scan complete, results available */ 458 #define RTM_IEEE80211_REPLAY 106 /* sequence counter replay detected */ 459 #define RTM_IEEE80211_MICHAEL 107 /* Michael MIC failure detected */ 460 #define RTM_IEEE80211_REJOIN 108 /* station re-associate (ap mode) */ 461 #define RTM_IEEE80211_WDS 109 /* WDS discovery (ap mode) */ 462 #define RTM_IEEE80211_CSA 110 /* Channel Switch Announcement event */ 463 #define RTM_IEEE80211_RADAR 111 /* radar event */ 464 #define RTM_IEEE80211_CAC 112 /* Channel Availability Check event */ 465 #define RTM_IEEE80211_DEAUTH 113 /* station deauthenticate */ 466 #define RTM_IEEE80211_AUTH 114 /* station authenticate (ap mode) */ 467 #define RTM_IEEE80211_COUNTRY 115 /* discovered country code (sta mode) */ 468 #define RTM_IEEE80211_RADIO 116 /* RF kill switch state change */ 469 470 /* 471 * Structure prepended to raw packets sent through the bpf 472 * interface when set to DLT_IEEE802_11_RADIO. This allows 473 * user applications to specify pretty much everything in 474 * an Atheros tx descriptor. XXX need to generalize. 475 * 476 * XXX cannot be more than 14 bytes as it is copied to a sockaddr's 477 * XXX sa_data area. 478 */ 479 struct ieee80211_bpf_params { 480 uint8_t ibp_vers; /* version */ 481 #define IEEE80211_BPF_VERSION 0 482 uint8_t ibp_len; /* header length in bytes */ 483 uint8_t ibp_flags; 484 #define IEEE80211_BPF_SHORTPRE 0x01 /* tx with short preamble */ 485 #define IEEE80211_BPF_NOACK 0x02 /* tx with no ack */ 486 #define IEEE80211_BPF_CRYPTO 0x04 /* tx with h/w encryption */ 487 #define IEEE80211_BPF_FCS 0x10 /* frame incldues FCS */ 488 #define IEEE80211_BPF_DATAPAD 0x20 /* frame includes data padding */ 489 #define IEEE80211_BPF_RTS 0x40 /* tx with RTS/CTS */ 490 #define IEEE80211_BPF_CTS 0x80 /* tx with CTS only */ 491 uint8_t ibp_pri; /* WME/WMM AC+tx antenna */ 492 uint8_t ibp_try0; /* series 1 try count */ 493 uint8_t ibp_rate0; /* series 1 IEEE tx rate */ 494 uint8_t ibp_power; /* tx power (device units) */ 495 uint8_t ibp_ctsrate; /* IEEE tx rate for CTS */ 496 uint8_t ibp_try1; /* series 2 try count */ 497 uint8_t ibp_rate1; /* series 2 IEEE tx rate */ 498 uint8_t ibp_try2; /* series 3 try count */ 499 uint8_t ibp_rate2; /* series 3 IEEE tx rate */ 500 uint8_t ibp_try3; /* series 4 try count */ 501 uint8_t ibp_rate3; /* series 4 IEEE tx rate */ 502 }; 503 504 #ifdef _KERNEL 505 struct ieee80211_tx_params { 506 struct ieee80211_bpf_params params; 507 }; 508 int ieee80211_add_xmit_params(struct mbuf *m, 509 const struct ieee80211_bpf_params *); 510 int ieee80211_get_xmit_params(struct mbuf *m, 511 struct ieee80211_bpf_params *); 512 513 #define IEEE80211_MAX_CHAINS 3 514 #define IEEE80211_MAX_EVM_PILOTS 6 515 516 #define IEEE80211_R_NF 0x0000001 /* global NF value valid */ 517 #define IEEE80211_R_RSSI 0x0000002 /* global RSSI value valid */ 518 #define IEEE80211_R_C_CHAIN 0x0000004 /* RX chain count valid */ 519 #define IEEE80211_R_C_NF 0x0000008 /* per-chain NF value valid */ 520 #define IEEE80211_R_C_RSSI 0x0000010 /* per-chain RSSI value valid */ 521 #define IEEE80211_R_C_EVM 0x0000020 /* per-chain EVM valid */ 522 #define IEEE80211_R_C_HT40 0x0000040 /* RX'ed packet is 40mhz, pilots 4,5 valid */ 523 #define IEEE80211_R_FREQ 0x0000080 /* Freq value populated, MHz */ 524 #define IEEE80211_R_IEEE 0x0000100 /* IEEE value populated */ 525 #define IEEE80211_R_BAND 0x0000200 /* Frequency band populated */ 526 527 struct ieee80211_rx_stats { 528 uint32_t r_flags; /* IEEE80211_R_* flags */ 529 uint8_t c_chain; /* number of RX chains involved */ 530 int16_t c_nf_ctl[IEEE80211_MAX_CHAINS]; /* per-chain NF */ 531 int16_t c_nf_ext[IEEE80211_MAX_CHAINS]; /* per-chain NF */ 532 int16_t c_rssi_ctl[IEEE80211_MAX_CHAINS]; /* per-chain RSSI */ 533 int16_t c_rssi_ext[IEEE80211_MAX_CHAINS]; /* per-chain RSSI */ 534 uint8_t c_nf; /* global NF */ 535 uint8_t c_rssi; /* global RSSI */ 536 uint8_t evm[IEEE80211_MAX_CHAINS][IEEE80211_MAX_EVM_PILOTS]; 537 /* per-chain, per-pilot EVM values */ 538 uint16_t c_freq; 539 uint8_t c_ieee; 540 }; 541 542 struct ieee80211_rx_params { 543 struct ieee80211_rx_stats params; 544 }; 545 int ieee80211_add_rx_params(struct mbuf *m, 546 const struct ieee80211_rx_stats *rxs); 547 int ieee80211_get_rx_params(struct mbuf *m, 548 struct ieee80211_rx_stats *rxs); 549 #endif /* _KERNEL */ 550 551 /* 552 * FreeBSD overrides 553 */ 554 const char *ether_sprintf(const u_char *buf); 555 556 #define V_ifnet ifnet 557 #define IFF_DRV_RUNNING IFF_RUNNING 558 #define if_drv_flags if_flags 559 560 typedef struct lock ieee80211_psq_lock_t; 561 typedef struct lock ieee80211_ageq_lock_t; 562 typedef struct lock ieee80211_node_lock_t; 563 typedef struct lock ieee80211_scan_lock_t; 564 typedef struct lock ieee80211_com_lock_t; 565 typedef struct lock ieee80211_tx_lock_t; 566 typedef struct lock ieee80211_scan_table_lock_t; 567 typedef struct lock ieee80211_scan_iter_lock_t; 568 typedef struct lock acl_lock_t; 569 typedef struct lock ieee80211_rte_lock_t; 570 typedef struct lock ieee80211_rt_lock_t; 571 572 #define IEEE80211_LOCK_OBJ(ic) (&(ic)->ic_comlock) 573 574 #define IEEE80211_LOCK_INIT(ic, name) lockinit(&(ic)->ic_comlock, name, 0, LK_CANRECURSE) 575 #define IEEE80211_NODE_LOCK_INIT(ic, name) lockinit(&(nt)->nt_nodelock, name, 0, LK_CANRECURSE) 576 #define IEEE80211_NODE_ITERATE_LOCK_INIT(ic, name) lockinit(&(nt)->nt_scanlock, name, 0, LK_CANRECURSE) 577 #define IEEE80211_SCAN_TABLE_LOCK_INIT(st, name) lockinit(&(st)->st_lock, name, 0, LK_CANRECURSE) 578 #define IEEE80211_SCAN_ITER_LOCK_INIT(st, name) lockinit(&(st)->st_scanlock, name, 0, LK_CANRECURSE) 579 #define IEEE80211_TX_LOCK_INIT(ic, name) lockinit(&(ic)->ic_txlock, name, 0, LK_CANRECURSE) 580 #define IEEE80211_AGEQ_LOCK_INIT(aq, name) lockinit(&(aq)->aq_lock, name, 0, LK_CANRECURSE) 581 #define IEEE80211_PSQ_INIT(psq, name) lockinit(&(psq)->psq_lock, name, 0, LK_CANRECURSE) 582 #define ACL_LOCK_INIT(as, name) lockinit(&(as)->as_lock, name, 0, LK_CANRECURSE) 583 #define MESH_RT_ENTRY_LOCK_INIT(st, name) lockinit(&(st)->rt_lock, name, 0, LK_CANRECURSE) 584 #define MESH_RT_LOCK_INIT(ms, name) lockinit(&(ms)->ms_rt_lock, name, 0, LK_CANRECURSE) 585 586 #define IEEE80211_LOCK_DESTROY(ic) lockuninit(&(ic)->ic_comlock) 587 #define IEEE80211_NODE_LOCK_DESTROY(nt) lockuninit(&(nt)->nt_nodelock) 588 #define IEEE80211_NODE_ITERATE_LOCK_DESTROY(nt) lockuninit(&(nt)->nt_scanlock) 589 #define IEEE80211_SCAN_TABLE_LOCK_DESTROY(st) lockuninit(&(st)->st_lock) 590 #define IEEE80211_SCAN_ITER_LOCK_DESTROY(st) lockuninit(&(st)->st_scanlock) 591 #define IEEE80211_TX_LOCK_DESTROY(ic) lockuninit(&(ic)->ic_txlock) 592 #define IEEE80211_AGEQ_LOCK_DESTROY(aq) lockuninit(&(aq)->aq_lock) 593 #define IEEE80211_PSQ_DESTROY(psq) lockuninit(&(psq)->psq_lock) 594 #define ACL_LOCK_DESTROY(as) lockuninit(&(as)->as_lock) 595 #define MESH_RT_ENTRY_LOCK_DESTROY(rt) lockuninit(&(rt)->rt_lock) 596 #define MESH_RT_LOCK_DESTROY(ms) lockuninit(&(ms)->ms_rt_lock) 597 598 #define IEEE80211_LOCK(ic) lockmgr(&(ic)->ic_comlock, LK_EXCLUSIVE) 599 #define IEEE80211_NODE_LOCK(nt) lockmgr(&(nt)->nt_nodelock, LK_EXCLUSIVE) 600 #define IEEE80211_NODE_ITERATE_LOCK(nt) lockmgr(&(nt)->nt_scanlock, LK_EXCLUSIVE) 601 #define IEEE80211_SCAN_TABLE_LOCK(st) lockmgr(&(st)->st_lock, LK_EXCLUSIVE) 602 #define IEEE80211_SCAN_ITER_LOCK(st) lockmgr(&(st)->st_scanlock, LK_EXCLUSIVE) 603 #define IEEE80211_TX_LOCK(ic) lockmgr(&(ic)->ic_txlock, LK_EXCLUSIVE) 604 #define IEEE80211_AGEQ_LOCK(aq) lockmgr(&(aq)->aq_lock, LK_EXCLUSIVE) 605 #define IEEE80211_PSQ_LOCK(psq) lockmgr(&(psq)->psq_lock, LK_EXCLUSIVE) 606 #define ACL_LOCK(as) lockmgr(&(as)->as_lock, LK_EXCLUSIVE) 607 #define MESH_RT_ENTRY_LOCK(rt) lockmgr(&(rt)->rt_lock, LK_EXCLUSIVE) 608 #define MESH_RT_LOCK(ms) lockmgr(&(ms)->ms_rt_lock, LK_EXCLUSIVE) 609 610 #define IEEE80211_UNLOCK(ic) lockmgr(&(ic)->ic_comlock, LK_RELEASE) 611 #define IEEE80211_NODE_UNLOCK(nt) lockmgr(&(nt)->nt_nodelock, LK_RELEASE) 612 #define IEEE80211_NODE_ITERATE_UNLOCK(nt) lockmgr(&(nt)->nt_scanlock, LK_RELEASE) 613 #define IEEE80211_SCAN_TABLE_UNLOCK(nt) lockmgr(&(st)->st_lock, LK_RELEASE) 614 #define IEEE80211_SCAN_ITER_UNLOCK(nt) lockmgr(&(st)->st_scanlock, LK_RELEASE) 615 #define IEEE80211_TX_UNLOCK(ic) lockmgr(&(ic)->ic_txlock, LK_RELEASE) 616 #define IEEE80211_AGEQ_UNLOCK(aq) lockmgr(&(aq)->aq_lock, LK_RELEASE) 617 #define IEEE80211_PSQ_UNLOCK(psq) lockmgr(&(psq)->psq_lock, LK_RELEASE) 618 #define ACL_UNLOCK(as) lockmgr(&(as)->as_lock, LK_RELEASE) 619 #define MESH_RT_ENTRY_UNLOCK(rt) lockmgr(&(rt)->rt_lock, LK_RELEASE) 620 #define MESH_RT_UNLOCK(ms) lockmgr(&(ms)->ms_rt_lock, LK_RELEASE) 621 622 #define IEEE80211_LOCK_ASSERT(ic) \ 623 KKASSERT(lockstatus(&(ic)->ic_comlock, curthread) == LK_EXCLUSIVE) 624 #define IEEE80211_UNLOCK_ASSERT(ic) \ 625 KKASSERT(lockstatus(&(ic)->ic_comlock, curthread) != LK_EXCLUSIVE) 626 #define IEEE80211_NODE_LOCK_ASSERT(nt) \ 627 KKASSERT(lockstatus(&(nt)->nt_nodelock, curthread) == LK_EXCLUSIVE) 628 #define IEEE80211_NODE_ITERATE_LOCK_ASSERT(nt) \ 629 KKASSERT(lockstatus(&(nt)->nt_scanlock, curthread) == LK_EXCLUSIVE) 630 #define IEEE80211_TX_LOCK_ASSERT(ic) \ 631 KKASSERT(lockstatus(&(ic)->ic_txlock, curthread) == LK_EXCLUSIVE) 632 #define IEEE80211_TX_UNLOCK_ASSERT(ic) \ 633 KKASSERT(lockstatus(&(ic)->ic_txlock, curthread) != LK_EXCLUSIVE) 634 #define IEEE80211_AGEQ_LOCK_ASSERT(aq) \ 635 KKASSERT(lockstatus(&(aq)->aq_lock, curthread) == LK_EXCLUSIVE) 636 #define ACL_LOCK_ASSERT(as) \ 637 KKASSERT(lockstatus(&(as)->as_lock, curthread) == LK_EXCLUSIVE) 638 #define MESH_RT_ENTRY_LOCK_ASSERT(rt) \ 639 KKASSERT(lockstatus(&(rt)->rt_lock, curthread) == LK_EXCLUSIVE) 640 #define MESH_RT_LOCK_ASSERT(ms) \ 641 KKASSERT(lockstatus(&(ms)->ms_rt_lock, curthread) == LK_EXCLUSIVE) 642 643 #define IEEE80211_NODE_IS_LOCKED(nt) \ 644 (lockstatus(&(nt)->nt_nodelock, curthread) == LK_EXCLUSIVE) 645 646 #define arc4random karc4random 647 648 #define IEEE80211_AGEQ_INIT(aq, name) 649 #define IEEE80211_AGEQ_DESTROY(aq) 650 #define CURVNET_SET(x) 651 #define CURVNET_RESTORE() 652 #define ifa_free(ifa) 653 654 #define ALIGNED_POINTER(p, t) (((uintptr_t)(p) & (sizeof(t) - 1)) == 0) 655 656 #define osdep_va_list __va_list 657 #define osdep_va_start __va_start 658 #define osdep_va_end __va_end 659 660 /* 661 * DragonFly does not implement _SAFE macros because they are generally not 662 * actually safe in a MP environment, and so it is bad programming practice 663 * to use them. 664 */ 665 #define TAILQ_FOREACH_SAFE(scan, list, next, save) \ 666 for (scan = TAILQ_FIRST(list); (save = scan ? TAILQ_NEXT(scan, next) : NULL), scan; scan = save) \ 667 668 #define callout_init_mtx(callo, lk, flags) \ 669 callout_init_lk(callo, lk) 670 #define callout_schedule_dfly(callo, timo, func, args) \ 671 callout_reset(callo, timo, func, args) 672 673 /* 674 * if_inc macros 675 */ 676 #define ifd_IFCOUNTER_IERRORS ifd_ierrors 677 #define ifd_IFCOUNTER_IPACKETS ifd_ipackets 678 #define ifd_IFCOUNTER_IBYTES ifd_ibytes 679 #define ifd_IFCOUNTER_OERRORS ifd_oerrors 680 #define ifd_IFCOUNTER_OPACKETS ifd_opackets 681 #define ifd_IFCOUNTER_OMCASTS ifd_omcasts 682 #define ifd_IFCOUNTER_OBYTES ifd_obytes 683 684 #define if_inc_counter IFNET_STAT_INC 685 686 #define IEEE80211_FREE(ptr, type) kfree((ptr), (type)) 687 688 #endif /* _NET80211_IEEE80211_DRAGONFLY_H_ */ 689