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 struct ieee80211com; 219 220 void ieee80211_sysctl_attach(struct ieee80211com *); 221 void ieee80211_sysctl_detach(struct ieee80211com *); 222 void ieee80211_sysctl_vattach(struct ieee80211vap *); 223 void ieee80211_sysctl_vdetach(struct ieee80211vap *); 224 225 SYSCTL_DECL(_net_wlan); 226 int ieee80211_sysctl_msecs_ticks(SYSCTL_HANDLER_ARGS); 227 228 void ieee80211_load_module(const char *); 229 230 /* 231 * A "policy module" is an adjunct module to net80211 that provides 232 * functionality that typically includes policy decisions. This 233 * modularity enables extensibility and vendor-supplied functionality. 234 */ 235 #define _IEEE80211_POLICY_MODULE(policy, name, version) \ 236 typedef void (*policy##_setup)(int); \ 237 SET_DECLARE(policy##_set, policy##_setup); \ 238 static int \ 239 wlan_##name##_modevent(module_t mod, int type, void *unused) \ 240 { \ 241 policy##_setup * const *iter, f; \ 242 int error; \ 243 \ 244 switch (type) { \ 245 case MOD_LOAD: \ 246 SET_FOREACH(iter, policy##_set) { \ 247 f = (void*) *iter; \ 248 f(type); \ 249 } \ 250 error = 0; \ 251 break; \ 252 case MOD_UNLOAD: \ 253 error = 0; \ 254 if (nrefs) { \ 255 kprintf("wlan_" #name ": still in use (%u " \ 256 "dynamic refs)\n", \ 257 nrefs); \ 258 error = EBUSY; \ 259 } else if (type == MOD_UNLOAD) { \ 260 SET_FOREACH(iter, policy##_set) { \ 261 f = (void*) *iter; \ 262 f(type); \ 263 } \ 264 } \ 265 break; \ 266 default: \ 267 error = EINVAL; \ 268 break; \ 269 } \ 270 \ 271 return error; \ 272 } \ 273 static moduledata_t name##_mod = { \ 274 "wlan_" #name, \ 275 wlan_##name##_modevent, \ 276 0 \ 277 }; \ 278 DECLARE_MODULE(wlan_##name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);\ 279 MODULE_VERSION(wlan_##name, version); \ 280 MODULE_DEPEND(wlan_##name, wlan, 1, 1, 1) 281 282 /* 283 * Crypto modules implement cipher support. 284 */ 285 #define IEEE80211_CRYPTO_MODULE(name, version) \ 286 _IEEE80211_POLICY_MODULE(crypto, name, version); \ 287 static void \ 288 name##_modevent(int type) \ 289 { \ 290 /* wlan already serialized! */ \ 291 if (type == MOD_LOAD) \ 292 ieee80211_crypto_register(&name); \ 293 else \ 294 ieee80211_crypto_unregister(&name); \ 295 } \ 296 TEXT_SET(crypto##_set, name##_modevent) 297 298 /* 299 * Scanner modules provide scanning policy. 300 */ 301 #define IEEE80211_SCANNER_MODULE(name, version) \ 302 _IEEE80211_POLICY_MODULE(scanner, name, version) 303 304 #define IEEE80211_SCANNER_ALG(name, alg, v) \ 305 static void \ 306 name##_modevent(int type) \ 307 { \ 308 /* wlan already serialized! */ \ 309 if (type == MOD_LOAD) \ 310 ieee80211_scanner_register(alg, &v); \ 311 else \ 312 ieee80211_scanner_unregister(alg, &v); \ 313 } \ 314 TEXT_SET(scanner_set, name##_modevent); \ 315 316 /* 317 * ACL modules implement acl policy. 318 */ 319 #define IEEE80211_ACL_MODULE(name, alg, version) \ 320 _IEEE80211_POLICY_MODULE(acl, name, version); \ 321 static void \ 322 alg##_modevent(int type) \ 323 { \ 324 /* wlan already serialized! */ \ 325 if (type == MOD_LOAD) \ 326 ieee80211_aclator_register(&alg); \ 327 else \ 328 ieee80211_aclator_unregister(&alg); \ 329 } \ 330 TEXT_SET(acl_set, alg##_modevent); \ 331 332 /* 333 * Authenticator modules handle 802.1x/WPA authentication. 334 */ 335 #define IEEE80211_AUTH_MODULE(name, version) \ 336 _IEEE80211_POLICY_MODULE(auth, name, version) 337 338 #define IEEE80211_AUTH_ALG(name, alg, v) \ 339 static void \ 340 name##_modevent(int type) \ 341 { \ 342 /* wlan already serialized! */ \ 343 if (type == MOD_LOAD) \ 344 ieee80211_authenticator_register(alg, &v); \ 345 else \ 346 ieee80211_authenticator_unregister(alg); \ 347 } \ 348 TEXT_SET(auth_set, name##_modevent) 349 350 /* 351 * Rate control modules provide tx rate control support. 352 */ 353 #define IEEE80211_RATECTL_MODULE(alg, version) \ 354 _IEEE80211_POLICY_MODULE(ratectl, alg, version); \ 355 356 #define IEEE80211_RATECTL_ALG(name, alg, v) \ 357 static void \ 358 alg##_modevent(int type) \ 359 { \ 360 /* wlan already serialized! */ \ 361 if (type == MOD_LOAD) \ 362 ieee80211_ratectl_register(alg, &v); \ 363 else \ 364 ieee80211_ratectl_unregister(alg); \ 365 } \ 366 TEXT_SET(ratectl##_set, alg##_modevent) 367 368 struct ieee80211req; 369 typedef int ieee80211_ioctl_getfunc(struct ieee80211vap *, 370 struct ieee80211req *); 371 SET_DECLARE(ieee80211_ioctl_getset, ieee80211_ioctl_getfunc); 372 #define IEEE80211_IOCTL_GET(_name, _get) TEXT_SET(ieee80211_ioctl_getset, _get) 373 374 typedef int ieee80211_ioctl_setfunc(struct ieee80211vap *, 375 struct ieee80211req *); 376 SET_DECLARE(ieee80211_ioctl_setset, ieee80211_ioctl_setfunc); 377 #define IEEE80211_IOCTL_SET(_name, _set) TEXT_SET(ieee80211_ioctl_setset, _set) 378 #endif /* _KERNEL */ 379 380 /* XXX this stuff belongs elsewhere */ 381 /* 382 * Message formats for messages from the net80211 layer to user 383 * applications via the routing socket. These messages are appended 384 * to an if_announcemsghdr structure. 385 */ 386 struct ieee80211_join_event { 387 uint8_t iev_addr[6]; 388 }; 389 390 struct ieee80211_leave_event { 391 uint8_t iev_addr[6]; 392 }; 393 394 struct ieee80211_replay_event { 395 uint8_t iev_src[6]; /* src MAC */ 396 uint8_t iev_dst[6]; /* dst MAC */ 397 uint8_t iev_cipher; /* cipher type */ 398 uint8_t iev_keyix; /* key id/index */ 399 uint64_t iev_keyrsc; /* RSC from key */ 400 uint64_t iev_rsc; /* RSC from frame */ 401 }; 402 403 struct ieee80211_michael_event { 404 uint8_t iev_src[6]; /* src MAC */ 405 uint8_t iev_dst[6]; /* dst MAC */ 406 uint8_t iev_cipher; /* cipher type */ 407 uint8_t iev_keyix; /* key id/index */ 408 }; 409 410 struct ieee80211_wds_event { 411 uint8_t iev_addr[6]; 412 }; 413 414 struct ieee80211_csa_event { 415 uint32_t iev_flags; /* channel flags */ 416 uint16_t iev_freq; /* setting in Mhz */ 417 uint8_t iev_ieee; /* IEEE channel number */ 418 uint8_t iev_mode; /* CSA mode */ 419 uint8_t iev_count; /* CSA count */ 420 }; 421 422 struct ieee80211_cac_event { 423 uint32_t iev_flags; /* channel flags */ 424 uint16_t iev_freq; /* setting in Mhz */ 425 uint8_t iev_ieee; /* IEEE channel number */ 426 /* XXX timestamp? */ 427 uint8_t iev_type; /* IEEE80211_NOTIFY_CAC_* */ 428 }; 429 430 struct ieee80211_radar_event { 431 uint32_t iev_flags; /* channel flags */ 432 uint16_t iev_freq; /* setting in Mhz */ 433 uint8_t iev_ieee; /* IEEE channel number */ 434 /* XXX timestamp? */ 435 }; 436 437 struct ieee80211_auth_event { 438 uint8_t iev_addr[6]; 439 }; 440 441 struct ieee80211_deauth_event { 442 uint8_t iev_addr[6]; 443 }; 444 445 struct ieee80211_country_event { 446 uint8_t iev_addr[6]; 447 uint8_t iev_cc[2]; /* ISO country code */ 448 }; 449 450 struct ieee80211_radio_event { 451 uint8_t iev_state; /* 1 on, 0 off */ 452 }; 453 454 #define RTM_IEEE80211_ASSOC 100 /* station associate (bss mode) */ 455 #define RTM_IEEE80211_REASSOC 101 /* station re-associate (bss mode) */ 456 #define RTM_IEEE80211_DISASSOC 102 /* station disassociate (bss mode) */ 457 #define RTM_IEEE80211_JOIN 103 /* station join (ap mode) */ 458 #define RTM_IEEE80211_LEAVE 104 /* station leave (ap mode) */ 459 #define RTM_IEEE80211_SCAN 105 /* scan complete, results available */ 460 #define RTM_IEEE80211_REPLAY 106 /* sequence counter replay detected */ 461 #define RTM_IEEE80211_MICHAEL 107 /* Michael MIC failure detected */ 462 #define RTM_IEEE80211_REJOIN 108 /* station re-associate (ap mode) */ 463 #define RTM_IEEE80211_WDS 109 /* WDS discovery (ap mode) */ 464 #define RTM_IEEE80211_CSA 110 /* Channel Switch Announcement event */ 465 #define RTM_IEEE80211_RADAR 111 /* radar event */ 466 #define RTM_IEEE80211_CAC 112 /* Channel Availability Check event */ 467 #define RTM_IEEE80211_DEAUTH 113 /* station deauthenticate */ 468 #define RTM_IEEE80211_AUTH 114 /* station authenticate (ap mode) */ 469 #define RTM_IEEE80211_COUNTRY 115 /* discovered country code (sta mode) */ 470 #define RTM_IEEE80211_RADIO 116 /* RF kill switch state change */ 471 472 /* 473 * Structure prepended to raw packets sent through the bpf 474 * interface when set to DLT_IEEE802_11_RADIO. This allows 475 * user applications to specify pretty much everything in 476 * an Atheros tx descriptor. XXX need to generalize. 477 * 478 * XXX cannot be more than 14 bytes as it is copied to a sockaddr's 479 * XXX sa_data area. 480 */ 481 struct ieee80211_bpf_params { 482 uint8_t ibp_vers; /* version */ 483 #define IEEE80211_BPF_VERSION 0 484 uint8_t ibp_len; /* header length in bytes */ 485 uint8_t ibp_flags; 486 #define IEEE80211_BPF_SHORTPRE 0x01 /* tx with short preamble */ 487 #define IEEE80211_BPF_NOACK 0x02 /* tx with no ack */ 488 #define IEEE80211_BPF_CRYPTO 0x04 /* tx with h/w encryption */ 489 #define IEEE80211_BPF_FCS 0x10 /* frame incldues FCS */ 490 #define IEEE80211_BPF_DATAPAD 0x20 /* frame includes data padding */ 491 #define IEEE80211_BPF_RTS 0x40 /* tx with RTS/CTS */ 492 #define IEEE80211_BPF_CTS 0x80 /* tx with CTS only */ 493 uint8_t ibp_pri; /* WME/WMM AC+tx antenna */ 494 uint8_t ibp_try0; /* series 1 try count */ 495 uint8_t ibp_rate0; /* series 1 IEEE tx rate */ 496 uint8_t ibp_power; /* tx power (device units) */ 497 uint8_t ibp_ctsrate; /* IEEE tx rate for CTS */ 498 uint8_t ibp_try1; /* series 2 try count */ 499 uint8_t ibp_rate1; /* series 2 IEEE tx rate */ 500 uint8_t ibp_try2; /* series 3 try count */ 501 uint8_t ibp_rate2; /* series 3 IEEE tx rate */ 502 uint8_t ibp_try3; /* series 4 try count */ 503 uint8_t ibp_rate3; /* series 4 IEEE tx rate */ 504 }; 505 506 #ifdef _KERNEL 507 struct ieee80211_tx_params { 508 struct ieee80211_bpf_params params; 509 }; 510 int ieee80211_add_xmit_params(struct mbuf *m, 511 const struct ieee80211_bpf_params *); 512 int ieee80211_get_xmit_params(struct mbuf *m, 513 struct ieee80211_bpf_params *); 514 515 #define IEEE80211_MAX_CHAINS 3 516 #define IEEE80211_MAX_EVM_PILOTS 6 517 518 #define IEEE80211_R_NF 0x0000001 /* global NF value valid */ 519 #define IEEE80211_R_RSSI 0x0000002 /* global RSSI value valid */ 520 #define IEEE80211_R_C_CHAIN 0x0000004 /* RX chain count valid */ 521 #define IEEE80211_R_C_NF 0x0000008 /* per-chain NF value valid */ 522 #define IEEE80211_R_C_RSSI 0x0000010 /* per-chain RSSI value valid */ 523 #define IEEE80211_R_C_EVM 0x0000020 /* per-chain EVM valid */ 524 #define IEEE80211_R_C_HT40 0x0000040 /* RX'ed packet is 40mhz, pilots 4,5 valid */ 525 #define IEEE80211_R_FREQ 0x0000080 /* Freq value populated, MHz */ 526 #define IEEE80211_R_IEEE 0x0000100 /* IEEE value populated */ 527 #define IEEE80211_R_BAND 0x0000200 /* Frequency band populated */ 528 529 struct ieee80211_rx_stats { 530 uint32_t r_flags; /* IEEE80211_R_* flags */ 531 uint8_t c_chain; /* number of RX chains involved */ 532 int16_t c_nf_ctl[IEEE80211_MAX_CHAINS]; /* per-chain NF */ 533 int16_t c_nf_ext[IEEE80211_MAX_CHAINS]; /* per-chain NF */ 534 int16_t c_rssi_ctl[IEEE80211_MAX_CHAINS]; /* per-chain RSSI */ 535 int16_t c_rssi_ext[IEEE80211_MAX_CHAINS]; /* per-chain RSSI */ 536 uint8_t nf; /* global NF */ 537 uint8_t rssi; /* global RSSI */ 538 uint8_t evm[IEEE80211_MAX_CHAINS][IEEE80211_MAX_EVM_PILOTS]; 539 /* per-chain, per-pilot EVM values */ 540 uint16_t c_freq; 541 uint8_t c_ieee; 542 }; 543 544 struct ieee80211_rx_params { 545 struct ieee80211_rx_stats params; 546 }; 547 int ieee80211_add_rx_params(struct mbuf *m, 548 const struct ieee80211_rx_stats *rxs); 549 int ieee80211_get_rx_params(struct mbuf *m, 550 struct ieee80211_rx_stats *rxs); 551 #endif /* _KERNEL */ 552 553 /* 554 * FreeBSD overrides 555 */ 556 const char *ether_sprintf(const u_char *buf); 557 558 #define V_ifnet ifnet 559 #define IFF_DRV_RUNNING IFF_RUNNING 560 #define if_drv_flags if_flags 561 562 typedef struct lock ieee80211_psq_lock_t; 563 typedef struct lock ieee80211_ageq_lock_t; 564 typedef struct lock ieee80211_node_lock_t; 565 typedef struct lock ieee80211_scan_lock_t; 566 typedef struct lock ieee80211_com_lock_t; 567 typedef struct lock ieee80211_tx_lock_t; 568 typedef struct lock ieee80211_ageq_lock_t; 569 typedef struct lock ieee80211_scan_table_lock_t; 570 typedef struct lock ieee80211_scan_iter_lock_t; 571 typedef struct lock acl_lock_t; 572 typedef struct lock ieee80211_rte_lock_t; 573 typedef struct lock ieee80211_rt_lock_t; 574 575 #define IEEE80211_LOCK_OBJ(ic) (&(ic)->ic_comlock) 576 577 #define IEEE80211_LOCK_INIT(ic, name) lockinit(&(ic)->ic_comlock, name, 0, LK_CANRECURSE) 578 #define IEEE80211_NODE_LOCK_INIT(ic, name) lockinit(&(nt)->nt_nodelock, name, 0, LK_CANRECURSE) 579 #define IEEE80211_NODE_ITERATE_LOCK_INIT(ic, name) lockinit(&(nt)->nt_scanlock, name, 0, LK_CANRECURSE) 580 #define IEEE80211_SCAN_TABLE_LOCK_INIT(st, name) lockinit(&(st)->st_lock, name, 0, LK_CANRECURSE) 581 #define IEEE80211_SCAN_ITER_LOCK_INIT(st, name) lockinit(&(st)->st_scanlock, name, 0, LK_CANRECURSE) 582 #define IEEE80211_TX_LOCK_INIT(ic, name) lockinit(&(ic)->ic_txlock, name, 0, LK_CANRECURSE) 583 #define IEEE80211_AGEQ_LOCK_INIT(aq, name) lockinit(&(aq)->aq_lock, name, 0, LK_CANRECURSE) 584 #define IEEE80211_PSQ_INIT(psq, name) lockinit(&(psq)->psq_lock, name, 0, LK_CANRECURSE) 585 #define ACL_LOCK_INIT(as, name) lockinit(&(as)->as_lock, name, 0, LK_CANRECURSE) 586 #define MESH_RT_ENTRY_LOCK_INIT(st, name) lockinit(&(st)->rt_lock, name, 0, LK_CANRECURSE) 587 #define MESH_RT_LOCK_INIT(ms, name) lockinit(&(ms)->ms_rt_lock, name, 0, LK_CANRECURSE) 588 589 #define IEEE80211_LOCK_DESTROY(ic) lockuninit(&(ic)->ic_comlock) 590 #define IEEE80211_NODE_LOCK_DESTROY(nt) lockuninit(&(nt)->nt_nodelock) 591 #define IEEE80211_NODE_ITERATE_LOCK_DESTROY(nt) lockuninit(&(nt)->nt_scanlock) 592 #define IEEE80211_SCAN_TABLE_LOCK_DESTROY(st) lockuninit(&(st)->st_lock) 593 #define IEEE80211_SCAN_ITER_LOCK_DESTROY(st) lockuninit(&(st)->st_scanlock) 594 #define IEEE80211_TX_LOCK_DESTROY(ic) lockuninit(&(ic)->ic_txlock) 595 #define IEEE80211_AGEQ_LOCK_DESTROY(aq) lockuninit(&(aq)->aq_lock) 596 #define IEEE80211_PSQ_DESTROY(psq) lockuninit(&(psq)->psq_lock) 597 #define ACL_LOCK_DESTROY(as) lockuninit(&(as)->as_lock) 598 #define MESH_RT_ENTRY_LOCK_DESTROY(rt) lockuninit(&(rt)->rt_lock) 599 #define MESH_RT_LOCK_DESTROY(ms) lockuninit(&(ms)->ms_rt_lock) 600 601 #define IEEE80211_LOCK(ic) lockmgr(&(ic)->ic_comlock, LK_EXCLUSIVE) 602 #define IEEE80211_NODE_LOCK(nt) lockmgr(&(nt)->nt_nodelock, LK_EXCLUSIVE) 603 #define IEEE80211_NODE_ITERATE_LOCK(nt) lockmgr(&(nt)->nt_scanlock, LK_EXCLUSIVE) 604 #define IEEE80211_SCAN_TABLE_LOCK(st) lockmgr(&(st)->st_lock, LK_EXCLUSIVE) 605 #define IEEE80211_SCAN_ITER_LOCK(st) lockmgr(&(st)->st_scanlock, LK_EXCLUSIVE) 606 #define IEEE80211_TX_LOCK(ic) lockmgr(&(ic)->ic_txlock, LK_EXCLUSIVE) 607 #define IEEE80211_AGEQ_LOCK(aq) lockmgr(&(aq)->aq_lock, LK_EXCLUSIVE) 608 #define IEEE80211_PSQ_LOCK(psq) lockmgr(&(psq)->psq_lock, LK_EXCLUSIVE) 609 #define ACL_LOCK(as) lockmgr(&(as)->as_lock, LK_EXCLUSIVE) 610 #define MESH_RT_ENTRY_LOCK(rt) lockmgr(&(rt)->rt_lock, LK_EXCLUSIVE) 611 #define MESH_RT_LOCK(ms) lockmgr(&(ms)->ms_rt_lock, LK_EXCLUSIVE) 612 613 #define IEEE80211_UNLOCK(ic) lockmgr(&(ic)->ic_comlock, LK_RELEASE) 614 #define IEEE80211_NODE_UNLOCK(nt) lockmgr(&(nt)->nt_nodelock, LK_RELEASE) 615 #define IEEE80211_NODE_ITERATE_UNLOCK(nt) lockmgr(&(nt)->nt_scanlock, LK_RELEASE) 616 #define IEEE80211_SCAN_TABLE_UNLOCK(nt) lockmgr(&(st)->st_lock, LK_RELEASE) 617 #define IEEE80211_SCAN_ITER_UNLOCK(nt) lockmgr(&(st)->st_scanlock, LK_RELEASE) 618 #define IEEE80211_TX_UNLOCK(ic) lockmgr(&(ic)->ic_txlock, LK_RELEASE) 619 #define IEEE80211_AGEQ_UNLOCK(aq) lockmgr(&(aq)->aq_lock, LK_RELEASE) 620 #define IEEE80211_PSQ_UNLOCK(psq) lockmgr(&(psq)->psq_lock, LK_RELEASE) 621 #define ACL_UNLOCK(as) lockmgr(&(as)->as_lock, LK_RELEASE) 622 #define MESH_RT_ENTRY_UNLOCK(rt) lockmgr(&(rt)->rt_lock, LK_RELEASE) 623 #define MESH_RT_UNLOCK(ms) lockmgr(&(ms)->ms_rt_lock, LK_RELEASE) 624 625 #define IEEE80211_LOCK_ASSERT(ic) \ 626 KKASSERT(lockstatus(&(ic)->ic_comlock, curthread) == LK_EXCLUSIVE) 627 #define IEEE80211_UNLOCK_ASSERT(ic) \ 628 KKASSERT(lockstatus(&(ic)->ic_comlock, curthread) != LK_EXCLUSIVE) 629 #define IEEE80211_NODE_LOCK_ASSERT(nt) \ 630 KKASSERT(lockstatus(&(nt)->nt_nodelock, curthread) == LK_EXCLUSIVE) 631 #define IEEE80211_NODE_ITERATE_LOCK_ASSERT(nt) \ 632 KKASSERT(lockstatus(&(nt)->nt_scanlock, curthread) == LK_EXCLUSIVE) 633 #define IEEE80211_TX_LOCK_ASSERT(ic) \ 634 KKASSERT(lockstatus(&(ic)->ic_txlock, curthread) == LK_EXCLUSIVE) 635 #define IEEE80211_TX_UNLOCK_ASSERT(ic) \ 636 KKASSERT(lockstatus(&(ic)->ic_txlock, curthread) != LK_EXCLUSIVE) 637 #define IEEE80211_AGEQ_LOCK_ASSERT(aq) \ 638 KKASSERT(lockstatus(&(aq)->aq_lock, curthread) == LK_EXCLUSIVE) 639 #define ACL_LOCK_ASSERT(as) \ 640 KKASSERT(lockstatus(&(as)->as_lock, curthread) == LK_EXCLUSIVE) 641 #define MESH_RT_ENTRY_LOCK_ASSERT(rt) \ 642 KKASSERT(lockstatus(&(rt)->rt_lock, curthread) == LK_EXCLUSIVE) 643 #define MESH_RT_LOCK_ASSERT(ms) \ 644 KKASSERT(lockstatus(&(ms)->ms_rt_lock, curthread) == LK_EXCLUSIVE) 645 646 #define IEEE80211_NODE_IS_LOCKED(nt) \ 647 (lockstatus(&(nt)->nt_nodelock, curthread) == LK_EXCLUSIVE) 648 649 #define arc4random karc4random 650 651 #define IEEE80211_AGEQ_INIT(aq, name) 652 #define IEEE80211_AGEQ_DESTROY(aq) 653 #define CURVNET_SET(x) 654 #define CURVNET_RESTORE() 655 #define ifa_free(ifa) 656 657 #define ALIGNED_POINTER(p, t) (((uintptr_t)(p) & (sizeof(t) - 1)) == 0) 658 659 #define osdep_va_list __va_list 660 #define osdep_va_start __va_start 661 #define osdep_va_end __va_end 662 663 /* 664 * DragonFly does not implement _SAFE macros because they are generally not 665 * actually safe in a MP environment, and so it is bad programming practice 666 * to use them. 667 */ 668 #define TAILQ_FOREACH_SAFE(scan, list, next, save) \ 669 for (scan = TAILQ_FIRST(list); (save = scan ? TAILQ_NEXT(scan, next) : NULL), scan; scan = save) \ 670 671 #define callout_init_mtx(callo, lk, flags) \ 672 callout_init_lk(callo, lk) 673 #define callout_schedule_dfly(callo, timo, func, args) \ 674 callout_reset(callo, timo, func, args) 675 676 /* 677 * if_inc macros 678 */ 679 #define ifd_IFCOUNTER_IERRORS ifd_ierrors 680 #define ifd_IFCOUNTER_IPACKETS ifd_ipackets 681 #define ifd_IFCOUNTER_IBYTES ifd_ibytes 682 #define ifd_IFCOUNTER_OERRORS ifd_oerrors 683 #define ifd_IFCOUNTER_OPACKETS ifd_opackets 684 #define ifd_IFCOUNTER_OMCASTS ifd_omcasts 685 #define ifd_IFCOUNTER_OBYTES ifd_obytes 686 687 #define if_inc_counter IFNET_STAT_INC 688 689 #define IEEE80211_FREE(ptr, type) kfree((ptr), (type)) 690 691 #endif /* _NET80211_IEEE80211_DRAGONFLY_H_ */ 692