From 6d0f2b487abf16ee4e949f3f31b61376ee64d595 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 7 Jan 2019 19:25:39 -0500 Subject: [PATCH] freebsd_wlan: Update Haiku-specific code. Now that we use SYSINIT for the "module" code instead of manually maintaining lists, we have to make the static library slightly differently. See inline comment. --- src/libs/compat/freebsd_wlan/net80211/Jamfile | 16 ++- .../freebsd_wlan/net80211/ieee80211_haiku.cpp | 48 +++++-- .../freebsd_wlan/net80211/ieee80211_haiku.h | 135 +++++++----------- 3 files changed, 96 insertions(+), 103 deletions(-) diff --git a/src/libs/compat/freebsd_wlan/net80211/Jamfile b/src/libs/compat/freebsd_wlan/net80211/Jamfile index c28aff6b69..a5086aed36 100644 --- a/src/libs/compat/freebsd_wlan/net80211/Jamfile +++ b/src/libs/compat/freebsd_wlan/net80211/Jamfile @@ -13,12 +13,17 @@ Includes [ FGristFiles kernel_c++_structs.h ] SubDirCcFlags [ FDefines _KERNEL=1 FBSD_DRIVER=1 ] -Wno-format -Wno-unused -Wno-uninitialized ; -SubDirC++Flags [ FDefines _KERNEL=1 FBSD_DRIVER=1 ] - -Wno-format -Wno-unused -Wno-uninitialized ; +SubDirC++Flags [ FDefines _KERNEL=1 FBSD_DRIVER=1 ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) .. crypto rijndael ] ; -KernelStaticLibrary freebsd_wlan.a : +# The reason we use a KernelMergeObject followed by KernelStaticLibrary +# instead of KernelStaticLibrary directly is to force all objects, +# not just the ones the driver links against, to be linked into +# the final binary. Otherwise, certain objects which export no symbols +# save SYSINIT() would not be linked at all, and in order for this +# module to function properly, they must be. +KernelMergeObject freebsd_wlan.o : ieee80211.c ieee80211_action.c ieee80211_adhoc.c @@ -50,7 +55,9 @@ KernelStaticLibrary freebsd_wlan.a : ieee80211_scan_sta.c ieee80211_scan_sw.c ieee80211_sta.c + ieee80211_vht.c ieee80211_wds.c + ieee80211_xauth.c # Rijndael (aka AES) cryptographic support for crypto_ccmp rijndael-alg-fst.c @@ -62,5 +69,6 @@ KernelStaticLibrary freebsd_wlan.a : # NOT SUPPORTED YET ieee80211_mesh.c # NOT SUPPORTED YET ieee80211_superg.c # NOT SUPPORTED YET ieee80211_tdma.c - ieee80211_xauth.c ; +KernelStaticLibraryObjects freebsd_wlan.a : + freebsd_wlan.o ; diff --git a/src/libs/compat/freebsd_wlan/net80211/ieee80211_haiku.cpp b/src/libs/compat/freebsd_wlan/net80211/ieee80211_haiku.cpp index 180f9245fa..b433f36807 100644 --- a/src/libs/compat/freebsd_wlan/net80211/ieee80211_haiku.cpp +++ b/src/libs/compat/freebsd_wlan/net80211/ieee80211_haiku.cpp @@ -96,11 +96,6 @@ get_ifnet(device_t device, int& i) status_t init_wlan_stack(void) { - mtx_init(&ic_list_mtx, "ieee80211com list", NULL, MTX_DEF); - ieee80211_phy_init(); - ieee80211_auth_setup(); - ieee80211_ht_init(); - get_module(NET_NOTIFICATIONS_MODULE_NAME, (module_info**)&sNotificationModule); @@ -111,8 +106,6 @@ init_wlan_stack(void) void uninit_wlan_stack(void) { - mtx_destroy(&ic_list_mtx); - if (sNotificationModule != NULL) put_module(NET_NOTIFICATIONS_MODULE_NAME); } @@ -220,7 +213,7 @@ wlan_control(void* cookie, uint32 op, void* arg, size_t length) else if (request.i_type == IEEE80211_IOC_HAIKU_COMPAT_WLAN_DOWN) return wlan_close(cookie); - TRACE("wlan_control: %ld, %d\n", op, request.i_type); + TRACE("wlan_control: %" B_PRIu32 ", %d\n", op, request.i_type); status_t status = ifp->if_ioctl(ifp, op, (caddr_t)&request); if (status != B_OK) return status; @@ -257,18 +250,28 @@ get_random_bytes(void* p, size_t n) } -struct mbuf* -ieee80211_getmgtframe(uint8_t** frm, int headroom, int pktlen) +struct mbuf * +ieee80211_getmgtframe(uint8_t **frm, int headroom, int pktlen) { - struct mbuf* m; + struct mbuf *m; u_int len; + /* + * NB: we know the mbuf routines will align the data area + * so we don't need to do anything special. + */ len = roundup2(headroom + pktlen, 4); KASSERT(len <= MCLBYTES, ("802.11 mgt frame too large: %u", len)); if (len < MINCLSIZE) { m = m_gethdr(M_NOWAIT, MT_DATA); + /* + * Align the data in case additional headers are added. + * This should only happen when a WEP header is added + * which only happens for shared key authentication mgt + * frames which all fit in MHLEN. + */ if (m != NULL) - MH_ALIGN(m, len); + M_ALIGN(m, len); } else { m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); if (m != NULL) @@ -498,6 +501,21 @@ ieee80211_get_rx_params(struct mbuf *m, struct ieee80211_rx_stats *rxs) } +const struct ieee80211_rx_stats * +ieee80211_get_rx_params_ptr(struct mbuf *m) +{ + struct m_tag *mtag; + struct ieee80211_rx_params *rx; + + mtag = m_tag_locate(m, MTAG_ABI_NET80211, NET80211_TAG_RECV_PARAMS, + NULL); + if (mtag == NULL) + return (NULL); + rx = (struct ieee80211_rx_params *)(mtag + 1); + return (&rx->params); +} + + /* * Transmit a frame to the parent interface. */ @@ -580,7 +598,9 @@ ieee80211_vap_destroy(struct ieee80211vap* vap) void ieee80211_load_module(const char* modname) { +#if 0 dprintf("%s not implemented, yet: modname %s\n", __func__, modname); +#endif } @@ -590,11 +610,11 @@ ieee80211_notify_node_join(struct ieee80211_node* ni, int newassoc) struct ieee80211vap* vap = ni->ni_vap; struct ifnet* ifp = vap->iv_ifp; + TRACE("%s\n", __FUNCTION__); + if (ni == vap->iv_bss) if_link_state_change(ifp, LINK_STATE_UP); - TRACE("%s\n", __FUNCTION__); - if (sNotificationModule != NULL) { char messageBuffer[512]; KMessage message; diff --git a/src/libs/compat/freebsd_wlan/net80211/ieee80211_haiku.h b/src/libs/compat/freebsd_wlan/net80211/ieee80211_haiku.h index 4e8b3437aa..e370ffcf2c 100644 --- a/src/libs/compat/freebsd_wlan/net80211/ieee80211_haiku.h +++ b/src/libs/compat/freebsd_wlan/net80211/ieee80211_haiku.h @@ -1,3 +1,8 @@ +/* + * Copyright 2009, Colin Günther, coling@gmx.de. All rights reserved. + * Copyright 2018, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ /*- * Copyright (c) 2003-2008 Sam Leffler, Errno Consulting * All rights reserved. @@ -21,8 +26,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef _FBSD_COMPAT_NET80211_IEEE80211_HAIKU_H_ #define _FBSD_COMPAT_NET80211_IEEE80211_HAIKU_H_ @@ -46,20 +49,6 @@ extern "C" { #include -#define IEEE80211_CRYPTO_MODULE(name, version) \ - void \ - ieee80211_crypto_##name##_load() { \ - ieee80211_crypto_register(&name); \ - } \ -\ -\ - void \ - ieee80211_crypto_##name##_unload() \ - { \ - ieee80211_crypto_unregister(&name); \ - } - - /* * Common state locking definitions. */ @@ -276,9 +265,11 @@ void ieee80211_vap_destroy(struct ieee80211vap *); (((_ifp)->if_flags & IFF_UP) && \ ((_ifp)->if_drv_flags & IFF_DRV_RUNNING)) +/* XXX TODO: cap these at 1, as hz may not be 1000 */ #define msecs_to_ticks(ms) (((ms)*hz)/1000) #define ticks_to_msecs(t) (1000*(t) / hz) #define ticks_to_secs(t) ((t) / hz) + #define ieee80211_time_after(a,b) ((long)(b) - (long)(a) < 0) #define ieee80211_time_before(a,b) ieee80211_time_after(b,a) #define ieee80211_time_after_eq(a,b) ((long)(a) - (long)(b) >= 0) @@ -291,15 +282,16 @@ struct mbuf *ieee80211_getmgtframe(uint8_t **frm, int headroom, int pktlen); #define M_EAPOL M_PROTO3 /* PAE/EAPOL frame */ #define M_PWR_SAV M_PROTO4 /* bypass PS handling */ #define M_MORE_DATA M_PROTO5 /* more data frames to follow */ -#define M_FF M_PROTO6 /* fast frame */ +#define M_FF M_PROTO6 /* fast frame / A-MSDU */ #define M_TXCB M_PROTO7 /* do tx complete callback */ #define M_AMPDU_MPDU M_PROTO8 /* ok for A-MPDU aggregation */ #define M_FRAG M_PROTO9 /* frame fragmentation */ #define M_FIRSTFRAG M_PROTO10 /* first frame fragment */ #define M_LASTFRAG M_PROTO11 /* last frame fragment */ + #define M_80211_TX \ - (M_FRAG|M_FIRSTFRAG|M_LASTFRAG|M_ENCAP|M_EAPOL|M_PWR_SAV|\ - M_MORE_DATA|M_FF|M_TXCB|M_AMPDU_MPDU) + (M_ENCAP|M_EAPOL|M_PWR_SAV|M_MORE_DATA|M_FF|M_TXCB| \ + M_AMPDU_MPDU|M_FRAG|M_FIRSTFRAG|M_LASTFRAG) /* rx path usage */ #define M_AMPDU M_PROTO1 /* A-MPDU subframe */ @@ -309,6 +301,15 @@ struct mbuf *ieee80211_getmgtframe(uint8_t **frm, int headroom, int pktlen); #endif #define M_80211_RX (M_AMPDU|M_WEP|M_AMPDU_MPDU) +#define IEEE80211_MBUF_TX_FLAG_BITS \ + M_FLAG_BITS \ + "\15M_ENCAP\17M_EAPOL\20M_PWR_SAV\21M_MORE_DATA\22M_FF\23M_TXCB" \ + "\24M_AMPDU_MPDU\25M_FRAG\26M_FIRSTFRAG\27M_LASTFRAG" + +#define IEEE80211_MBUF_RX_FLAG_BITS \ + M_FLAG_BITS \ + "\15M_AMPDU\16M_WEP\24M_AMPDU_MPDU" + /* * Store WME access control bits in the vlan tag. * This is safe since it's done after the packet is classified @@ -369,55 +370,48 @@ void ieee80211_load_module(const char *); * functionality that typically includes policy decisions. This * modularity enables extensibility and vendor-supplied functionality. */ -#define _IEEE80211_POLICY_MODULE(policy, name, version) \ -typedef void (*policy##_setup)(int); \ -SET_DECLARE(policy##_set, policy##_setup); +#define _IEEE80211_POLICY_MODULE(policy, name, version, load, unload) \ + static void ieee80211_##policy##_##name##_load() { load; } \ + static void ieee80211_##policy##_##name##_unload() { unload; } \ + SYSINIT(ieee80211_##policy##_##name, SI_SUB_DRIVERS, SI_ORDER_ANY, \ + ieee80211_##policy##_##name##_load, NULL); \ + SYSUNINIT(ieee80211_##policy##_##name, SI_SUB_DRIVERS, SI_ORDER_ANY, \ + ieee80211_##policy##_##name##_unload, NULL) /* * Authenticator modules handle 802.1x/WPA authentication. */ -#define IEEE80211_AUTH_MODULE(name, version) \ - _IEEE80211_POLICY_MODULE(auth, name, version) +#define IEEE80211_AUTH_MODULE(name, version) +#define IEEE80211_AUTH_ALG(name, alg, v) \ + _IEEE80211_POLICY_MODULE(auth, alg, v, \ + ieee80211_authenticator_register(alg, &v), \ + ieee80211_authenticator_unregister(alg)) -#define IEEE80211_AUTH_ALG(name, alg, v) \ -static void \ -name##_modevent(int type) \ -{ \ - if (type == MOD_LOAD) \ - ieee80211_authenticator_register(alg, &v); \ - else \ - ieee80211_authenticator_unregister(alg); \ -} \ -TEXT_SET(auth_set, name##_modevent) +/* + * Crypto modules implement cipher support. + */ +#define IEEE80211_CRYPTO_MODULE(name, version) \ + _IEEE80211_POLICY_MODULE(crypto, name, version, \ + ieee80211_crypto_register(&name), \ + ieee80211_crypto_unregister(&name)) /* * Scanner modules provide scanning policy. */ #define IEEE80211_SCANNER_MODULE(name, version) -#define IEEE80211_SCANNER_ALG(name, alg, v) - - -void ieee80211_scan_sta_init(void); -void ieee80211_scan_sta_uninit(void); - +#define IEEE80211_SCANNER_ALG(name, alg, v) \ + _IEEE80211_POLICY_MODULE(scan, alg, v, \ + ieee80211_scanner_register(alg, &v), \ + ieee80211_scanner_unregister(alg, &v)) /* * Rate control modules provide tx rate control support. */ -#define IEEE80211_RATECTL_MODULE(alg, version) \ - _IEEE80211_POLICY_MODULE(ratectl, alg, version); \ - +#define IEEE80211_RATECTL_MODULE(alg, version) #define IEEE80211_RATECTL_ALG(name, alg, v) \ - void \ - ieee80211_ratectl_##name##_load() { \ - ieee80211_ratectl_register(alg, &v); \ - } \ -\ -\ - void \ - ieee80211_ratectl_##name##_unload() { \ - ieee80211_ratectl_unregister(alg); \ - } + _IEEE80211_POLICY_MODULE(ratectl, alg, v, \ + ieee80211_ratectl_register(alg, &v), \ + ieee80211_ratectl_unregister(alg)) struct ieee80211req; @@ -468,45 +462,16 @@ struct ieee80211_bpf_params { int ieee80211_add_xmit_params(struct mbuf *m, const struct ieee80211_bpf_params *params); int ieee80211_get_xmit_params(struct mbuf *m, struct ieee80211_bpf_params *params); -#define IEEE80211_MAX_CHAINS 3 -#define IEEE80211_MAX_EVM_PILOTS 6 - struct ieee80211_tx_params { struct ieee80211_bpf_params params; }; -#define IEEE80211_R_NF 0x0000001 /* global NF value valid */ -#define IEEE80211_R_RSSI 0x0000002 /* global RSSI value valid */ -#define IEEE80211_R_C_CHAIN 0x0000004 /* RX chain count valid */ -#define IEEE80211_R_C_NF 0x0000008 /* per-chain NF value valid */ -#define IEEE80211_R_C_RSSI 0x0000010 /* per-chain RSSI value valid */ -#define IEEE80211_R_C_EVM 0x0000020 /* per-chain EVM valid */ -#define IEEE80211_R_C_HT40 0x0000040 /* RX'ed packet is 40mhz, pilots 4,5 valid */ -#define IEEE80211_R_FREQ 0x0000080 /* Freq value populated, MHz */ -#define IEEE80211_R_IEEE 0x0000100 /* IEEE value populated */ -#define IEEE80211_R_BAND 0x0000200 /* Frequency band populated */ - -struct ieee80211_rx_stats { - uint32_t r_flags; /* IEEE80211_R_* flags */ - uint8_t c_chain; /* number of RX chains involved */ - int16_t c_nf_ctl[IEEE80211_MAX_CHAINS]; /* per-chain NF */ - int16_t c_nf_ext[IEEE80211_MAX_CHAINS]; /* per-chain NF */ - int16_t c_rssi_ctl[IEEE80211_MAX_CHAINS]; /* per-chain RSSI */ - int16_t c_rssi_ext[IEEE80211_MAX_CHAINS]; /* per-chain RSSI */ - uint8_t nf; /* global NF */ - uint8_t rssi; /* global RSSI */ - uint8_t evm[IEEE80211_MAX_CHAINS][IEEE80211_MAX_EVM_PILOTS]; - /* per-chain, per-pilot EVM values */ - uint16_t c_freq; - uint8_t c_ieee; -}; - -struct ieee80211_rx_params { - struct ieee80211_rx_stats params; -}; +struct ieee80211_rx_params; +struct ieee80211_rx_stats; int ieee80211_add_rx_params(struct mbuf *m, const struct ieee80211_rx_stats *rxs); int ieee80211_get_rx_params(struct mbuf *m, struct ieee80211_rx_stats *rxs); +const struct ieee80211_rx_stats * ieee80211_get_rx_params_ptr(struct mbuf *m); #ifdef __cplusplus }