16b4cac81SBjoern A. Zeeb /*- 26b4cac81SBjoern A. Zeeb * Copyright (c) 2020-2021 The FreeBSD Foundation 3*086be6a8SBjoern A. Zeeb * Copyright (c) 2020-2022 Bjoern A. Zeeb 46b4cac81SBjoern A. Zeeb * 56b4cac81SBjoern A. Zeeb * This software was developed by Björn Zeeb under sponsorship from 66b4cac81SBjoern A. Zeeb * the FreeBSD Foundation. 76b4cac81SBjoern A. Zeeb * 86b4cac81SBjoern A. Zeeb * Redistribution and use in source and binary forms, with or without 96b4cac81SBjoern A. Zeeb * modification, are permitted provided that the following conditions 106b4cac81SBjoern A. Zeeb * are met: 116b4cac81SBjoern A. Zeeb * 1. Redistributions of source code must retain the above copyright 126b4cac81SBjoern A. Zeeb * notice, this list of conditions and the following disclaimer. 136b4cac81SBjoern A. Zeeb * 2. Redistributions in binary form must reproduce the above copyright 146b4cac81SBjoern A. Zeeb * notice, this list of conditions and the following disclaimer in the 156b4cac81SBjoern A. Zeeb * documentation and/or other materials provided with the distribution. 166b4cac81SBjoern A. Zeeb * 176b4cac81SBjoern A. Zeeb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 186b4cac81SBjoern A. Zeeb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 196b4cac81SBjoern A. Zeeb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 206b4cac81SBjoern A. Zeeb * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 216b4cac81SBjoern A. Zeeb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 226b4cac81SBjoern A. Zeeb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 236b4cac81SBjoern A. Zeeb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 246b4cac81SBjoern A. Zeeb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 256b4cac81SBjoern A. Zeeb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 266b4cac81SBjoern A. Zeeb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 276b4cac81SBjoern A. Zeeb * SUCH DAMAGE. 286b4cac81SBjoern A. Zeeb */ 296b4cac81SBjoern A. Zeeb 306b4cac81SBjoern A. Zeeb /* 316b4cac81SBjoern A. Zeeb * Public functions are called linuxkpi_*(). 326b4cac81SBjoern A. Zeeb * Internal (static) functions are called lkpi_*(). 336b4cac81SBjoern A. Zeeb * 346b4cac81SBjoern A. Zeeb * The internal structures holding metadata over public structures are also 356b4cac81SBjoern A. Zeeb * called lkpi_xxx (usually with a member at the end called xxx). 366b4cac81SBjoern A. Zeeb * Note: we do not replicate the structure names but the general variable names 376b4cac81SBjoern A. Zeeb * for these (e.g., struct hw -> struct lkpi_hw, struct sta -> struct lkpi_sta). 386b4cac81SBjoern A. Zeeb * There are macros to access one from the other. 396b4cac81SBjoern A. Zeeb * We call the internal versions lxxx (e.g., hw -> lhw, sta -> lsta). 406b4cac81SBjoern A. Zeeb */ 416b4cac81SBjoern A. Zeeb 426b4cac81SBjoern A. Zeeb #include <sys/cdefs.h> 436b4cac81SBjoern A. Zeeb __FBSDID("$FreeBSD$"); 446b4cac81SBjoern A. Zeeb 456b4cac81SBjoern A. Zeeb #include <sys/param.h> 466b4cac81SBjoern A. Zeeb #include <sys/types.h> 476b4cac81SBjoern A. Zeeb #include <sys/kernel.h> 486b4cac81SBjoern A. Zeeb #include <sys/errno.h> 496b4cac81SBjoern A. Zeeb #include <sys/malloc.h> 506b4cac81SBjoern A. Zeeb #include <sys/module.h> 516b4cac81SBjoern A. Zeeb #include <sys/mutex.h> 526b4cac81SBjoern A. Zeeb #include <sys/socket.h> 536b4cac81SBjoern A. Zeeb #include <sys/sysctl.h> 546b4cac81SBjoern A. Zeeb #include <sys/queue.h> 556b4cac81SBjoern A. Zeeb #include <sys/taskqueue.h> 566b4cac81SBjoern A. Zeeb 576b4cac81SBjoern A. Zeeb #include <net/if.h> 586b4cac81SBjoern A. Zeeb #include <net/if_var.h> 596b4cac81SBjoern A. Zeeb #include <net/if_media.h> 606b4cac81SBjoern A. Zeeb #include <net/ethernet.h> 616b4cac81SBjoern A. Zeeb 626b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_var.h> 636b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_proto.h> 646b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_ratectl.h> 656b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_radiotap.h> 666b4cac81SBjoern A. Zeeb 676b4cac81SBjoern A. Zeeb #define LINUXKPI_NET80211 686b4cac81SBjoern A. Zeeb #include <net/mac80211.h> 696b4cac81SBjoern A. Zeeb 706b4cac81SBjoern A. Zeeb #include <linux/workqueue.h> 716b4cac81SBjoern A. Zeeb #include "linux_80211.h" 726b4cac81SBjoern A. Zeeb 736b4cac81SBjoern A. Zeeb static MALLOC_DEFINE(M_LKPI80211, "lkpi80211", "Linux KPI 80211 compat"); 746b4cac81SBjoern A. Zeeb 756b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 766b4cac81SBjoern A. Zeeb /* These are unrelated to 802.11 sysctl bug debugging during 802.11 work so * 776b4cac81SBjoern A. Zeeb * keep them here rather than in a more general file. */ 786b4cac81SBjoern A. Zeeb 796b4cac81SBjoern A. Zeeb int debug_skb; 806b4cac81SBjoern A. Zeeb SYSCTL_INT(_compat_linuxkpi, OID_AUTO, debug_skb, CTLFLAG_RWTUN, 816b4cac81SBjoern A. Zeeb &debug_skb, 0, "SKB debug level"); 826b4cac81SBjoern A. Zeeb 836b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 846b4cac81SBjoern A. Zeeb 856b4cac81SBjoern A. Zeeb int debug_80211; 866b4cac81SBjoern A. Zeeb SYSCTL_INT(_compat_linuxkpi, OID_AUTO, debug_80211, CTLFLAG_RWTUN, 876b4cac81SBjoern A. Zeeb &debug_80211, 0, "80211 debug Level"); 886b4cac81SBjoern A. Zeeb 896b4cac81SBjoern A. Zeeb #define LINUXKPI_DEBUG_80211 906b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 916b4cac81SBjoern A. Zeeb #ifndef D80211_TODO 926b4cac81SBjoern A. Zeeb #define D80211_TODO 0x1 936b4cac81SBjoern A. Zeeb #endif 946b4cac81SBjoern A. Zeeb #ifndef D80211_IMPROVE 956b4cac81SBjoern A. Zeeb #define D80211_IMPROVE 0x2 966b4cac81SBjoern A. Zeeb #endif 976b4cac81SBjoern A. Zeeb #define D80211_TRACE 0x10 986b4cac81SBjoern A. Zeeb #define D80211_TRACEOK 0x20 996b4cac81SBjoern A. Zeeb #define D80211_TRACE_TX 0x100 1006b4cac81SBjoern A. Zeeb #define D80211_TRACE_TX_DUMP 0x200 1016b4cac81SBjoern A. Zeeb #define D80211_TRACE_RX 0x1000 1026b4cac81SBjoern A. Zeeb #define D80211_TRACE_RX_DUMP 0x2000 1036b4cac81SBjoern A. Zeeb #define D80211_TRACE_RX_BEACONS 0x4000 1046b4cac81SBjoern A. Zeeb #define D80211_TRACEX (D80211_TRACE_TX|D80211_TRACE_RX) 1056b4cac81SBjoern A. Zeeb #define D80211_TRACEX_DUMP (D80211_TRACE_TX_DUMP|D80211_TRACE_RX_DUMP) 1066b4cac81SBjoern A. Zeeb #define UNIMPLEMENTED if (debug_80211 & D80211_TODO) \ 1076b4cac81SBjoern A. Zeeb printf("XXX-TODO %s:%d: UNIMPLEMENTED\n", __func__, __LINE__) 1086b4cac81SBjoern A. Zeeb #define TRACEOK() if (debug_80211 & D80211_TRACEOK) \ 1096b4cac81SBjoern A. Zeeb printf("XXX-TODO %s:%d: TRACEPOINT\n", __func__, __LINE__) 1106b4cac81SBjoern A. Zeeb #else 1116b4cac81SBjoern A. Zeeb #define UNIMPLEMENTED do { } while (0) 1126b4cac81SBjoern A. Zeeb #define TRACEOK() do { } while (0) 1136b4cac81SBjoern A. Zeeb #endif 1146b4cac81SBjoern A. Zeeb 1156b4cac81SBjoern A. Zeeb /* #define PREP_TX_INFO_DURATION (IEEE80211_TRANS_WAIT * 1000) */ 1166b4cac81SBjoern A. Zeeb #ifndef PREP_TX_INFO_DURATION 1176b4cac81SBjoern A. Zeeb #define PREP_TX_INFO_DURATION 0 /* Let the driver do its thing. */ 1186b4cac81SBjoern A. Zeeb #endif 1196b4cac81SBjoern A. Zeeb 1206b4cac81SBjoern A. Zeeb /* This is DSAP | SSAP | CTRL | ProtoID/OrgCode{3}. */ 1216b4cac81SBjoern A. Zeeb const uint8_t rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; 1226b4cac81SBjoern A. Zeeb 1236b4cac81SBjoern A. Zeeb const struct cfg80211_ops linuxkpi_mac80211cfgops = { 1246b4cac81SBjoern A. Zeeb /* 1256b4cac81SBjoern A. Zeeb * XXX TODO need a "glue layer" to link cfg80211 ops to 1266b4cac81SBjoern A. Zeeb * mac80211 and to the driver or net80211. 1276b4cac81SBjoern A. Zeeb * Can we pass some on 1:1? Need to compare the (*f)(). 1286b4cac81SBjoern A. Zeeb */ 1296b4cac81SBjoern A. Zeeb }; 1306b4cac81SBjoern A. Zeeb 1316b4cac81SBjoern A. Zeeb static struct lkpi_sta *lkpi_find_lsta_by_ni(struct lkpi_vif *, 1326b4cac81SBjoern A. Zeeb struct ieee80211_node *); 1336b4cac81SBjoern A. Zeeb static void lkpi_80211_txq_task(void *, int); 1346b4cac81SBjoern A. Zeeb static void lkpi_ieee80211_free_skb_mbuf(void *); 1356b4cac81SBjoern A. Zeeb 1366b4cac81SBjoern A. Zeeb static enum nl80211_band 1376b4cac81SBjoern A. Zeeb lkpi_net80211_chan_to_nl80211_band(struct ieee80211_channel *c) 1386b4cac81SBjoern A. Zeeb { 1396b4cac81SBjoern A. Zeeb 1406b4cac81SBjoern A. Zeeb if (IEEE80211_IS_CHAN_2GHZ(c)) 1416b4cac81SBjoern A. Zeeb return (NL80211_BAND_2GHZ); 1426b4cac81SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_5GHZ(c)) 1436b4cac81SBjoern A. Zeeb return (NL80211_BAND_5GHZ); 1446b4cac81SBjoern A. Zeeb #ifdef __notyet__ 1456b4cac81SBjoern A. Zeeb else if () 1466b4cac81SBjoern A. Zeeb return (NL80211_BAND_6GHZ); 1476b4cac81SBjoern A. Zeeb else if () 1486b4cac81SBjoern A. Zeeb return (NL80211_BAND_60GHZ); 1496b4cac81SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_GSM(c)) 1506b4cac81SBjoern A. Zeeb return (NL80211_BAND_XXX); 1516b4cac81SBjoern A. Zeeb #endif 1526b4cac81SBjoern A. Zeeb else 1536b4cac81SBjoern A. Zeeb panic("%s: unsupported band. c %p flags %#x\n", 1546b4cac81SBjoern A. Zeeb __func__, c, c->ic_flags); 1556b4cac81SBjoern A. Zeeb } 1566b4cac81SBjoern A. Zeeb 1576b4cac81SBjoern A. Zeeb static uint32_t 1586b4cac81SBjoern A. Zeeb lkpi_nl80211_band_to_net80211_band(enum nl80211_band band) 1596b4cac81SBjoern A. Zeeb { 1606b4cac81SBjoern A. Zeeb 1616b4cac81SBjoern A. Zeeb /* XXX-BZ this is just silly; net80211 is too convoluted. */ 1626b4cac81SBjoern A. Zeeb /* IEEE80211_CHAN_A / _G / .. doesn't really work either. */ 1636b4cac81SBjoern A. Zeeb switch (band) { 1646b4cac81SBjoern A. Zeeb case NL80211_BAND_2GHZ: 1656b4cac81SBjoern A. Zeeb return (IEEE80211_CHAN_2GHZ); 1666b4cac81SBjoern A. Zeeb break; 1676b4cac81SBjoern A. Zeeb case NL80211_BAND_5GHZ: 1686b4cac81SBjoern A. Zeeb return (IEEE80211_CHAN_5GHZ); 1696b4cac81SBjoern A. Zeeb break; 1706b4cac81SBjoern A. Zeeb case NL80211_BAND_60GHZ: 1716b4cac81SBjoern A. Zeeb break; 1726b4cac81SBjoern A. Zeeb case NL80211_BAND_6GHZ: 1736b4cac81SBjoern A. Zeeb break; 1746b4cac81SBjoern A. Zeeb default: 1756b4cac81SBjoern A. Zeeb panic("%s: unsupported band %u\n", __func__, band); 1766b4cac81SBjoern A. Zeeb break; 1776b4cac81SBjoern A. Zeeb } 1786b4cac81SBjoern A. Zeeb 1796b4cac81SBjoern A. Zeeb IMPROVE(); 1806b4cac81SBjoern A. Zeeb return (0x00); 1816b4cac81SBjoern A. Zeeb } 1826b4cac81SBjoern A. Zeeb 1836b4cac81SBjoern A. Zeeb static enum ieee80211_ac_numbers 1846b4cac81SBjoern A. Zeeb lkpi_ac_net_to_l80211(int ac) 1856b4cac81SBjoern A. Zeeb { 1866b4cac81SBjoern A. Zeeb 1876b4cac81SBjoern A. Zeeb switch (ac) { 1886b4cac81SBjoern A. Zeeb case WME_AC_VO: 1896b4cac81SBjoern A. Zeeb return (IEEE80211_AC_VO); 1906b4cac81SBjoern A. Zeeb case WME_AC_VI: 1916b4cac81SBjoern A. Zeeb return (IEEE80211_AC_VI); 1926b4cac81SBjoern A. Zeeb case WME_AC_BE: 1936b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BE); 1946b4cac81SBjoern A. Zeeb case WME_AC_BK: 1956b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BK); 1966b4cac81SBjoern A. Zeeb default: 1976b4cac81SBjoern A. Zeeb printf("%s: invalid WME_AC_* input: ac = %d\n", __func__, ac); 1986b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BE); 1996b4cac81SBjoern A. Zeeb } 2006b4cac81SBjoern A. Zeeb } 2016b4cac81SBjoern A. Zeeb 2026b4cac81SBjoern A. Zeeb static enum nl80211_iftype 2036b4cac81SBjoern A. Zeeb lkpi_opmode_to_vif_type(enum ieee80211_opmode opmode) 2046b4cac81SBjoern A. Zeeb { 2056b4cac81SBjoern A. Zeeb 2066b4cac81SBjoern A. Zeeb switch (opmode) { 2076b4cac81SBjoern A. Zeeb case IEEE80211_M_IBSS: 2086b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_ADHOC); 2096b4cac81SBjoern A. Zeeb break; 2106b4cac81SBjoern A. Zeeb case IEEE80211_M_STA: 2116b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_STATION); 2126b4cac81SBjoern A. Zeeb break; 2136b4cac81SBjoern A. Zeeb case IEEE80211_M_WDS: 2146b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_WDS); 2156b4cac81SBjoern A. Zeeb break; 2166b4cac81SBjoern A. Zeeb case IEEE80211_M_HOSTAP: 2176b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_AP); 2186b4cac81SBjoern A. Zeeb break; 2196b4cac81SBjoern A. Zeeb case IEEE80211_M_MONITOR: 2206b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_MONITOR); 2216b4cac81SBjoern A. Zeeb break; 2226b4cac81SBjoern A. Zeeb case IEEE80211_M_MBSS: 2236b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_MESH_POINT); 2246b4cac81SBjoern A. Zeeb break; 2256b4cac81SBjoern A. Zeeb case IEEE80211_M_AHDEMO: 2266b4cac81SBjoern A. Zeeb /* FALLTHROUGH */ 2276b4cac81SBjoern A. Zeeb default: 2286b4cac81SBjoern A. Zeeb printf("ERROR: %s: unsupported opmode %d\n", __func__, opmode); 2296b4cac81SBjoern A. Zeeb /* FALLTHROUGH */ 2306b4cac81SBjoern A. Zeeb } 2316b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_UNSPECIFIED); 2326b4cac81SBjoern A. Zeeb } 2336b4cac81SBjoern A. Zeeb 2346b4cac81SBjoern A. Zeeb #ifdef __notyet__ 2356b4cac81SBjoern A. Zeeb static uint32_t 2366b4cac81SBjoern A. Zeeb lkpi_l80211_to_net80211_cyphers(uint32_t wlan_cipher_suite) 2376b4cac81SBjoern A. Zeeb { 2386b4cac81SBjoern A. Zeeb 2396b4cac81SBjoern A. Zeeb switch (wlan_cipher_suite) { 2406b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP40: 2416b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_WEP); 2426b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP: 2436b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_TKIP); 2446b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP: 2456b4cac81SBjoern A. Zeeb return (IEEE80211_CIPHER_AES_CCM); 2466b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP104: 2476b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_WEP); 2486b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_AES_CMAC: 2496b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP: 2506b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP_256: 2516b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP_256: 2526b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_128: 2536b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_256: 2546b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_CMAC_256: 2556b4cac81SBjoern A. Zeeb printf("%s: unsupported WLAN Cipher Suite %#08x | %u\n", __func__, 2566b4cac81SBjoern A. Zeeb wlan_cipher_suite >> 8, wlan_cipher_suite & 0xff); 2576b4cac81SBjoern A. Zeeb break; 2586b4cac81SBjoern A. Zeeb default: 2596b4cac81SBjoern A. Zeeb printf("%s: unknown WLAN Cipher Suite %#08x | %u\n", __func__, 2606b4cac81SBjoern A. Zeeb wlan_cipher_suite >> 8, wlan_cipher_suite & 0xff); 2616b4cac81SBjoern A. Zeeb } 2626b4cac81SBjoern A. Zeeb 2636b4cac81SBjoern A. Zeeb return (0); 2646b4cac81SBjoern A. Zeeb } 2656b4cac81SBjoern A. Zeeb #endif 2666b4cac81SBjoern A. Zeeb 2676b4cac81SBjoern A. Zeeb #ifdef TRY_HW_CRYPTO 2686b4cac81SBjoern A. Zeeb static uint32_t 2696b4cac81SBjoern A. Zeeb lkpi_net80211_to_l80211_cipher_suite(uint32_t cipher, uint8_t keylen) 2706b4cac81SBjoern A. Zeeb { 2716b4cac81SBjoern A. Zeeb 2726b4cac81SBjoern A. Zeeb switch (cipher) { 2736b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_TKIP: 2746b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_TKIP); 2756b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_AES_CCM: 2766b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_CCMP); 2776b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_WEP: 2786b4cac81SBjoern A. Zeeb if (keylen < 8) 2796b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_WEP40); 2806b4cac81SBjoern A. Zeeb else 2816b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_WEP104); 2826b4cac81SBjoern A. Zeeb break; 2836b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_AES_OCB: 2846b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_TKIPMIC: 2856b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_CKIP: 2866b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_NONE: 2876b4cac81SBjoern A. Zeeb printf("%s: unsupported cipher %#010x\n", __func__, cipher); 2886b4cac81SBjoern A. Zeeb break; 2896b4cac81SBjoern A. Zeeb default: 2906b4cac81SBjoern A. Zeeb printf("%s: unknown cipher %#010x\n", __func__, cipher); 2916b4cac81SBjoern A. Zeeb }; 2926b4cac81SBjoern A. Zeeb return (0); 2936b4cac81SBjoern A. Zeeb } 2946b4cac81SBjoern A. Zeeb #endif 2956b4cac81SBjoern A. Zeeb 2966b4cac81SBjoern A. Zeeb #ifdef __notyet__ 2976b4cac81SBjoern A. Zeeb static enum ieee80211_sta_state 2986b4cac81SBjoern A. Zeeb lkpi_net80211_state_to_sta_state(enum ieee80211_state state) 2996b4cac81SBjoern A. Zeeb { 3006b4cac81SBjoern A. Zeeb 3016b4cac81SBjoern A. Zeeb /* 3026b4cac81SBjoern A. Zeeb * XXX-BZ The net80211 states are "try to ..", the lkpi8011 states are 3036b4cac81SBjoern A. Zeeb * "done". Also ASSOC/AUTHORIZED are both "RUN" then? 3046b4cac81SBjoern A. Zeeb */ 3056b4cac81SBjoern A. Zeeb switch (state) { 3066b4cac81SBjoern A. Zeeb case IEEE80211_S_INIT: 3076b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NOTEXIST); 3086b4cac81SBjoern A. Zeeb case IEEE80211_S_SCAN: 3096b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NONE); 3106b4cac81SBjoern A. Zeeb case IEEE80211_S_AUTH: 3116b4cac81SBjoern A. Zeeb return (IEEE80211_STA_AUTH); 3126b4cac81SBjoern A. Zeeb case IEEE80211_S_ASSOC: 3136b4cac81SBjoern A. Zeeb return (IEEE80211_STA_ASSOC); 3146b4cac81SBjoern A. Zeeb case IEEE80211_S_RUN: 3156b4cac81SBjoern A. Zeeb return (IEEE80211_STA_AUTHORIZED); 3166b4cac81SBjoern A. Zeeb case IEEE80211_S_CAC: 3176b4cac81SBjoern A. Zeeb case IEEE80211_S_CSA: 3186b4cac81SBjoern A. Zeeb case IEEE80211_S_SLEEP: 3196b4cac81SBjoern A. Zeeb default: 3206b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 3216b4cac81SBjoern A. Zeeb }; 3226b4cac81SBjoern A. Zeeb 3236b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NOTEXIST); 3246b4cac81SBjoern A. Zeeb } 3256b4cac81SBjoern A. Zeeb #endif 3266b4cac81SBjoern A. Zeeb 3276b4cac81SBjoern A. Zeeb static struct linuxkpi_ieee80211_channel * 3286b4cac81SBjoern A. Zeeb lkpi_find_lkpi80211_chan(struct lkpi_hw *lhw, 3296b4cac81SBjoern A. Zeeb struct ieee80211_channel *c) 3306b4cac81SBjoern A. Zeeb { 3316b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 3326b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 3336b4cac81SBjoern A. Zeeb enum nl80211_band band; 3346b4cac81SBjoern A. Zeeb int i, nchans; 3356b4cac81SBjoern A. Zeeb 3366b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 3376b4cac81SBjoern A. Zeeb band = lkpi_net80211_chan_to_nl80211_band(c); 3386b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[band] == NULL) 3396b4cac81SBjoern A. Zeeb return (NULL); 3406b4cac81SBjoern A. Zeeb 3416b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[band]->n_channels; 3426b4cac81SBjoern A. Zeeb if (nchans <= 0) 3436b4cac81SBjoern A. Zeeb return (NULL); 3446b4cac81SBjoern A. Zeeb 3456b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[band]->channels; 3466b4cac81SBjoern A. Zeeb for (i = 0; i < nchans; i++) { 3476b4cac81SBjoern A. Zeeb if (channels[i].hw_value == c->ic_ieee) 3486b4cac81SBjoern A. Zeeb return (&channels[i]); 3496b4cac81SBjoern A. Zeeb } 3506b4cac81SBjoern A. Zeeb 3516b4cac81SBjoern A. Zeeb return (NULL); 3526b4cac81SBjoern A. Zeeb } 3536b4cac81SBjoern A. Zeeb 3546b4cac81SBjoern A. Zeeb static struct linuxkpi_ieee80211_channel * 3556b4cac81SBjoern A. Zeeb lkpi_get_lkpi80211_chan(struct ieee80211com *ic, struct ieee80211_node *ni) 3566b4cac81SBjoern A. Zeeb { 3576b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 3586b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 3596b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 3606b4cac81SBjoern A. Zeeb 3616b4cac81SBjoern A. Zeeb chan = NULL; 3626b4cac81SBjoern A. Zeeb if (ni != NULL && ni->ni_chan != IEEE80211_CHAN_ANYC) 3636b4cac81SBjoern A. Zeeb c = ni->ni_chan; 3646b4cac81SBjoern A. Zeeb else if (ic->ic_bsschan != IEEE80211_CHAN_ANYC) 3656b4cac81SBjoern A. Zeeb c = ic->ic_bsschan; 3666b4cac81SBjoern A. Zeeb else if (ic->ic_curchan != IEEE80211_CHAN_ANYC) 3676b4cac81SBjoern A. Zeeb c = ic->ic_curchan; 3686b4cac81SBjoern A. Zeeb else 3696b4cac81SBjoern A. Zeeb c = NULL; 3706b4cac81SBjoern A. Zeeb 3716b4cac81SBjoern A. Zeeb if (c != NULL && c != IEEE80211_CHAN_ANYC) { 3726b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 3736b4cac81SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, c); 3746b4cac81SBjoern A. Zeeb } 3756b4cac81SBjoern A. Zeeb 3766b4cac81SBjoern A. Zeeb return (chan); 3776b4cac81SBjoern A. Zeeb } 3786b4cac81SBjoern A. Zeeb 3796b4cac81SBjoern A. Zeeb #ifdef TRY_HW_CRYPTO 3806b4cac81SBjoern A. Zeeb static int 3816b4cac81SBjoern A. Zeeb _lkpi_iv_key_set_delete(struct ieee80211vap *vap, const struct ieee80211_key *k, 3826b4cac81SBjoern A. Zeeb enum set_key_cmd cmd) 3836b4cac81SBjoern A. Zeeb { 3846b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 3856b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 3866b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 3876b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 3886b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 3896b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 3906b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 3916b4cac81SBjoern A. Zeeb struct ieee80211_key_conf *kc; 3926b4cac81SBjoern A. Zeeb int error; 3936b4cac81SBjoern A. Zeeb 3946b4cac81SBjoern A. Zeeb /* XXX TODO Check (k->wk_flags & IEEE80211_KEY_SWENCRYPT) and don't upload to driver/hw? */ 3956b4cac81SBjoern A. Zeeb 3966b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 3976b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 3986b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 3996b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 4006b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 4016b4cac81SBjoern A. Zeeb 4026b4cac81SBjoern A. Zeeb memset(&kc, 0, sizeof(kc)); 4036b4cac81SBjoern A. Zeeb kc = malloc(sizeof(*kc) + k->wk_keylen, M_LKPI80211, M_WAITOK | M_ZERO); 4046b4cac81SBjoern A. Zeeb kc->cipher = lkpi_net80211_to_l80211_cipher_suite( 4056b4cac81SBjoern A. Zeeb k->wk_cipher->ic_cipher, k->wk_keylen); 4066b4cac81SBjoern A. Zeeb kc->keyidx = k->wk_keyix; 4076b4cac81SBjoern A. Zeeb #if 0 4086b4cac81SBjoern A. Zeeb kc->hw_key_idx = /* set by hw and needs to be passed for TX */; 4096b4cac81SBjoern A. Zeeb #endif 4106b4cac81SBjoern A. Zeeb atomic64_set(&kc->tx_pn, k->wk_keytsc); 4116b4cac81SBjoern A. Zeeb kc->keylen = k->wk_keylen; 4126b4cac81SBjoern A. Zeeb memcpy(kc->key, k->wk_key, k->wk_keylen); 4136b4cac81SBjoern A. Zeeb 4146b4cac81SBjoern A. Zeeb switch (kc->cipher) { 4156b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP: 4166b4cac81SBjoern A. Zeeb kc->iv_len = k->wk_cipher->ic_header; 4176b4cac81SBjoern A. Zeeb kc->icv_len = k->wk_cipher->ic_trailer; 4186b4cac81SBjoern A. Zeeb break; 4196b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP: 4206b4cac81SBjoern A. Zeeb default: 4216b4cac81SBjoern A. Zeeb IMPROVE(); 4226b4cac81SBjoern A. Zeeb return (0); 4236b4cac81SBjoern A. Zeeb }; 4246b4cac81SBjoern A. Zeeb 4256b4cac81SBjoern A. Zeeb ni = vap->iv_bss; 4266b4cac81SBjoern A. Zeeb sta = ieee80211_find_sta(vif, ni->ni_bssid); 4276b4cac81SBjoern A. Zeeb if (sta != NULL) { 4286b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 4296b4cac81SBjoern A. Zeeb 4306b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 4316b4cac81SBjoern A. Zeeb lsta->kc = kc; 4326b4cac81SBjoern A. Zeeb } 4336b4cac81SBjoern A. Zeeb 4346b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_set_key(hw, cmd, vif, sta, kc); 4356b4cac81SBjoern A. Zeeb if (error != 0) { 4366b4cac81SBjoern A. Zeeb /* XXX-BZ leaking kc currently */ 4376b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: set_key failed: %d\n", __func__, error); 4386b4cac81SBjoern A. Zeeb return (0); 4396b4cac81SBjoern A. Zeeb } else { 4406b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: set_key succeeded: keyidx %u hw_key_idx %u " 4416b4cac81SBjoern A. Zeeb "flags %#10x\n", __func__, 4426b4cac81SBjoern A. Zeeb kc->keyidx, kc->hw_key_idx, kc->flags); 4436b4cac81SBjoern A. Zeeb return (1); 4446b4cac81SBjoern A. Zeeb } 4456b4cac81SBjoern A. Zeeb } 4466b4cac81SBjoern A. Zeeb 4476b4cac81SBjoern A. Zeeb static int 4486b4cac81SBjoern A. Zeeb lkpi_iv_key_delete(struct ieee80211vap *vap, const struct ieee80211_key *k) 4496b4cac81SBjoern A. Zeeb { 4506b4cac81SBjoern A. Zeeb 4516b4cac81SBjoern A. Zeeb /* XXX-BZ one day we should replace this iterating over VIFs, or node list? */ 4526b4cac81SBjoern A. Zeeb return (_lkpi_iv_key_set_delete(vap, k, DISABLE_KEY)); 4536b4cac81SBjoern A. Zeeb } 4546b4cac81SBjoern A. Zeeb static int 4556b4cac81SBjoern A. Zeeb lkpi_iv_key_set(struct ieee80211vap *vap, const struct ieee80211_key *k) 4566b4cac81SBjoern A. Zeeb { 4576b4cac81SBjoern A. Zeeb 4586b4cac81SBjoern A. Zeeb return (_lkpi_iv_key_set_delete(vap, k, SET_KEY)); 4596b4cac81SBjoern A. Zeeb } 4606b4cac81SBjoern A. Zeeb #endif 4616b4cac81SBjoern A. Zeeb 4626b4cac81SBjoern A. Zeeb static u_int 4636b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast_copy(void *arg, struct sockaddr_dl *sdl, u_int cnt) 4646b4cac81SBjoern A. Zeeb { 4656b4cac81SBjoern A. Zeeb struct netdev_hw_addr_list *mc_list; 4666b4cac81SBjoern A. Zeeb struct netdev_hw_addr *addr; 4676b4cac81SBjoern A. Zeeb 4686b4cac81SBjoern A. Zeeb KASSERT(arg != NULL && sdl != NULL, ("%s: arg %p sdl %p cnt %u\n", 4696b4cac81SBjoern A. Zeeb __func__, arg, sdl, cnt)); 4706b4cac81SBjoern A. Zeeb 4716b4cac81SBjoern A. Zeeb mc_list = arg; 4726b4cac81SBjoern A. Zeeb /* If it is on the list already skip it. */ 4736b4cac81SBjoern A. Zeeb netdev_hw_addr_list_for_each(addr, mc_list) { 4746b4cac81SBjoern A. Zeeb if (!memcmp(addr->addr, LLADDR(sdl), sdl->sdl_alen)) 4756b4cac81SBjoern A. Zeeb return (0); 4766b4cac81SBjoern A. Zeeb } 4776b4cac81SBjoern A. Zeeb 4786b4cac81SBjoern A. Zeeb addr = malloc(sizeof(*addr), M_LKPI80211, M_NOWAIT | M_ZERO); 4796b4cac81SBjoern A. Zeeb if (addr == NULL) 4806b4cac81SBjoern A. Zeeb return (0); 4816b4cac81SBjoern A. Zeeb 4826b4cac81SBjoern A. Zeeb INIT_LIST_HEAD(&addr->addr_list); 4836b4cac81SBjoern A. Zeeb memcpy(addr->addr, LLADDR(sdl), sdl->sdl_alen); 4846b4cac81SBjoern A. Zeeb /* XXX this should be a netdev function? */ 4856b4cac81SBjoern A. Zeeb list_add(&addr->addr_list, &mc_list->addr_list); 4866b4cac81SBjoern A. Zeeb mc_list->count++; 4876b4cac81SBjoern A. Zeeb 4886b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE) 4896b4cac81SBjoern A. Zeeb printf("%s:%d: mc_list count %d: added %6D\n", 4906b4cac81SBjoern A. Zeeb __func__, __LINE__, mc_list->count, addr->addr, ":"); 4916b4cac81SBjoern A. Zeeb 4926b4cac81SBjoern A. Zeeb return (1); 4936b4cac81SBjoern A. Zeeb } 4946b4cac81SBjoern A. Zeeb 4956b4cac81SBjoern A. Zeeb static void 4966b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(struct ieee80211com *ic, bool force) 4976b4cac81SBjoern A. Zeeb { 4986b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 4996b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 5006b4cac81SBjoern A. Zeeb struct netdev_hw_addr_list mc_list; 5016b4cac81SBjoern A. Zeeb struct list_head *le, *next; 5026b4cac81SBjoern A. Zeeb struct netdev_hw_addr *addr; 5036b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 5046b4cac81SBjoern A. Zeeb u64 mc; 5056b4cac81SBjoern A. Zeeb unsigned int changed_flags, total_flags; 5066b4cac81SBjoern A. Zeeb 5076b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 5086b4cac81SBjoern A. Zeeb 5096b4cac81SBjoern A. Zeeb if (lhw->ops->prepare_multicast == NULL || 5106b4cac81SBjoern A. Zeeb lhw->ops->configure_filter == NULL) 5116b4cac81SBjoern A. Zeeb return; 5126b4cac81SBjoern A. Zeeb 5136b4cac81SBjoern A. Zeeb if (!lhw->update_mc && !force) 5146b4cac81SBjoern A. Zeeb return; 5156b4cac81SBjoern A. Zeeb 5166b4cac81SBjoern A. Zeeb changed_flags = total_flags = 0; 5176b4cac81SBjoern A. Zeeb mc_list.count = 0; 5186b4cac81SBjoern A. Zeeb INIT_LIST_HEAD(&mc_list.addr_list); 5196b4cac81SBjoern A. Zeeb if (ic->ic_allmulti == 0) { 5206b4cac81SBjoern A. Zeeb TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) 5216b4cac81SBjoern A. Zeeb if_foreach_llmaddr(vap->iv_ifp, 5226b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast_copy, &mc_list); 5236b4cac81SBjoern A. Zeeb } else { 5246b4cac81SBjoern A. Zeeb changed_flags |= FIF_ALLMULTI; 5256b4cac81SBjoern A. Zeeb } 5266b4cac81SBjoern A. Zeeb 5276b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 5286b4cac81SBjoern A. Zeeb mc = lkpi_80211_mo_prepare_multicast(hw, &mc_list); 5296b4cac81SBjoern A. Zeeb /* 5306b4cac81SBjoern A. Zeeb * XXX-BZ make sure to get this sorted what is a change, 5316b4cac81SBjoern A. Zeeb * what gets all set; what was already set? 5326b4cac81SBjoern A. Zeeb */ 5336b4cac81SBjoern A. Zeeb total_flags = changed_flags; 5346b4cac81SBjoern A. Zeeb lkpi_80211_mo_configure_filter(hw, changed_flags, &total_flags, mc); 5356b4cac81SBjoern A. Zeeb 5366b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE) 5376b4cac81SBjoern A. Zeeb printf("%s: changed_flags %#06x count %d total_flags %#010x\n", 5386b4cac81SBjoern A. Zeeb __func__, changed_flags, mc_list.count, total_flags); 5396b4cac81SBjoern A. Zeeb 5406b4cac81SBjoern A. Zeeb if (mc_list.count != 0) { 5416b4cac81SBjoern A. Zeeb list_for_each_safe(le, next, &mc_list.addr_list) { 5426b4cac81SBjoern A. Zeeb addr = list_entry(le, struct netdev_hw_addr, addr_list); 5436b4cac81SBjoern A. Zeeb free(addr, M_LKPI80211); 5446b4cac81SBjoern A. Zeeb mc_list.count--; 5456b4cac81SBjoern A. Zeeb } 5466b4cac81SBjoern A. Zeeb } 5476b4cac81SBjoern A. Zeeb KASSERT(mc_list.count == 0, ("%s: mc_list %p count %d != 0\n", 5486b4cac81SBjoern A. Zeeb __func__, &mc_list, mc_list.count)); 5496b4cac81SBjoern A. Zeeb } 5506b4cac81SBjoern A. Zeeb 5516b4cac81SBjoern A. Zeeb const uint8_t tid_to_mac80211_ac[] = { 5526b4cac81SBjoern A. Zeeb IEEE80211_AC_BE, 5536b4cac81SBjoern A. Zeeb IEEE80211_AC_BK, 5546b4cac81SBjoern A. Zeeb IEEE80211_AC_BK, 5556b4cac81SBjoern A. Zeeb IEEE80211_AC_BE, 5566b4cac81SBjoern A. Zeeb IEEE80211_AC_VI, 5576b4cac81SBjoern A. Zeeb IEEE80211_AC_VI, 5586b4cac81SBjoern A. Zeeb IEEE80211_AC_VO, 5596b4cac81SBjoern A. Zeeb IEEE80211_AC_VO, 5606b4cac81SBjoern A. Zeeb #if 0 5616b4cac81SBjoern A. Zeeb IEEE80211_AC_VO, /* We treat MGMT as TID 8, which is set as AC_VO */ 5626b4cac81SBjoern A. Zeeb #endif 5636b4cac81SBjoern A. Zeeb }; 5646b4cac81SBjoern A. Zeeb 5656b4cac81SBjoern A. Zeeb static void 5666b4cac81SBjoern A. Zeeb lkpi_stop_hw_scan(struct lkpi_hw *lhw, struct ieee80211_vif *vif) 5676b4cac81SBjoern A. Zeeb { 5686b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 5696b4cac81SBjoern A. Zeeb int error; 5706b4cac81SBjoern A. Zeeb 5716b4cac81SBjoern A. Zeeb if ((lhw->scan_flags & LKPI_SCAN_RUNNING) == 0) 5726b4cac81SBjoern A. Zeeb return; 5736b4cac81SBjoern A. Zeeb 5746b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 5756b4cac81SBjoern A. Zeeb 5766b4cac81SBjoern A. Zeeb /* Need to cancel the scan. */ 5776b4cac81SBjoern A. Zeeb lkpi_80211_mo_cancel_hw_scan(hw, vif); 5786b4cac81SBjoern A. Zeeb 5796b4cac81SBjoern A. Zeeb /* Need to make sure we see ieee80211_scan_completed. */ 5806b4cac81SBjoern A. Zeeb error = msleep(lhw, &lhw->mtx, 0, "lhwscanstop", hz/2); 5816b4cac81SBjoern A. Zeeb 5826b4cac81SBjoern A. Zeeb if ((lhw->scan_flags & LKPI_SCAN_RUNNING) != 0) 5836b4cac81SBjoern A. Zeeb ic_printf(lhw->ic, "%s: failed to cancel scan: %d (%p, %p)\n", 5846b4cac81SBjoern A. Zeeb __func__, error, lhw, vif); 5856b4cac81SBjoern A. Zeeb } 5866b4cac81SBjoern A. Zeeb 5876b4cac81SBjoern A. Zeeb static void 588*086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(struct ieee80211_hw *hw, bool new) 589*086be6a8SBjoern A. Zeeb { 590*086be6a8SBjoern A. Zeeb struct lkpi_hw *lhw; 591*086be6a8SBjoern A. Zeeb int error; 592*086be6a8SBjoern A. Zeeb bool old; 593*086be6a8SBjoern A. Zeeb 594*086be6a8SBjoern A. Zeeb old = hw->conf.flags & IEEE80211_CONF_IDLE; 595*086be6a8SBjoern A. Zeeb if (old == new) 596*086be6a8SBjoern A. Zeeb return; 597*086be6a8SBjoern A. Zeeb 598*086be6a8SBjoern A. Zeeb hw->conf.flags ^= IEEE80211_CONF_IDLE; 599*086be6a8SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_IDLE); 600*086be6a8SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) { 601*086be6a8SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 602*086be6a8SBjoern A. Zeeb ic_printf(lhw->ic, "ERROR: %s: config %#0x returned %d\n", 603*086be6a8SBjoern A. Zeeb __func__, IEEE80211_CONF_CHANGE_IDLE, error); 604*086be6a8SBjoern A. Zeeb } 605*086be6a8SBjoern A. Zeeb } 606*086be6a8SBjoern A. Zeeb 607*086be6a8SBjoern A. Zeeb static void 6086b4cac81SBjoern A. Zeeb lkpi_disassoc(struct ieee80211_sta *sta, struct ieee80211_vif *vif, 6096b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw) 6106b4cac81SBjoern A. Zeeb { 6116b4cac81SBjoern A. Zeeb sta->aid = 0; 6126b4cac81SBjoern A. Zeeb if (vif->bss_conf.assoc) { 6136b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 6146b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 6156b4cac81SBjoern A. Zeeb 6166b4cac81SBjoern A. Zeeb lhw->update_mc = true; 6176b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(lhw->ic, true); 6186b4cac81SBjoern A. Zeeb 6196b4cac81SBjoern A. Zeeb changed = 0; 6206b4cac81SBjoern A. Zeeb vif->bss_conf.assoc = false; 6216b4cac81SBjoern A. Zeeb vif->bss_conf.aid = 0; 6226b4cac81SBjoern A. Zeeb changed |= BSS_CHANGED_ASSOC; 6236b4cac81SBjoern A. Zeeb IMPROVE(); 6246b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 6256b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, 6266b4cac81SBjoern A. Zeeb changed); 627*086be6a8SBjoern A. Zeeb 628*086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true); 6296b4cac81SBjoern A. Zeeb } 6306b4cac81SBjoern A. Zeeb } 6316b4cac81SBjoern A. Zeeb 6326b4cac81SBjoern A. Zeeb static void 6336b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(struct ieee80211_hw *hw, struct ieee80211_sta *sta, 6346b4cac81SBjoern A. Zeeb bool dequeue_seen, bool no_emptyq) 6356b4cac81SBjoern A. Zeeb { 6366b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 6376b4cac81SBjoern A. Zeeb int tid; 6386b4cac81SBjoern A. Zeeb 6396b4cac81SBjoern A. Zeeb /* Wake up all queues to know they are allocated in the driver. */ 6406b4cac81SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 6416b4cac81SBjoern A. Zeeb 6426b4cac81SBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) { 6436b4cac81SBjoern A. Zeeb IMPROVE("station specific?"); 6446b4cac81SBjoern A. Zeeb if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ)) 6456b4cac81SBjoern A. Zeeb continue; 6466b4cac81SBjoern A. Zeeb } else if (tid >= hw->queues) 6476b4cac81SBjoern A. Zeeb continue; 6486b4cac81SBjoern A. Zeeb 6496b4cac81SBjoern A. Zeeb if (sta->txq[tid] == NULL) 6506b4cac81SBjoern A. Zeeb continue; 6516b4cac81SBjoern A. Zeeb 6526b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]); 6536b4cac81SBjoern A. Zeeb if (dequeue_seen && !ltxq->seen_dequeue) 6546b4cac81SBjoern A. Zeeb continue; 6556b4cac81SBjoern A. Zeeb 6566b4cac81SBjoern A. Zeeb if (no_emptyq && skb_queue_empty(<xq->skbq)) 6576b4cac81SBjoern A. Zeeb continue; 6586b4cac81SBjoern A. Zeeb 6596b4cac81SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, sta->txq[tid]); 6606b4cac81SBjoern A. Zeeb } 6616b4cac81SBjoern A. Zeeb } 6626b4cac81SBjoern A. Zeeb 6636b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 6646b4cac81SBjoern A. Zeeb 6656b4cac81SBjoern A. Zeeb static int 6666b4cac81SBjoern A. Zeeb lkpi_sta_state_do_nada(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 6676b4cac81SBjoern A. Zeeb { 6686b4cac81SBjoern A. Zeeb 6696b4cac81SBjoern A. Zeeb return (0); 6706b4cac81SBjoern A. Zeeb } 6716b4cac81SBjoern A. Zeeb 6726b4cac81SBjoern A. Zeeb /* lkpi_iv_newstate() handles the stop scan case generally. */ 6736b4cac81SBjoern A. Zeeb #define lkpi_sta_scan_to_init(_v, _n, _a) lkpi_sta_state_do_nada(_v, _n, _a) 6746b4cac81SBjoern A. Zeeb 6756b4cac81SBjoern A. Zeeb static int 6766b4cac81SBjoern A. Zeeb lkpi_sta_scan_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 6776b4cac81SBjoern A. Zeeb { 6786b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 6796b4cac81SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 6806b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 6816b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 6826b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 6836b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 6846b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 6856b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 6866b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 6876b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 6886b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 6896b4cac81SBjoern A. Zeeb uint32_t changed; 6906b4cac81SBjoern A. Zeeb int error; 6916b4cac81SBjoern A. Zeeb 6926b4cac81SBjoern A. Zeeb chan = lkpi_get_lkpi80211_chan(vap->iv_ic, vap->iv_bss); 6936b4cac81SBjoern A. Zeeb if (chan == NULL) { 6946b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: failed to get channel\n", __func__); 6956b4cac81SBjoern A. Zeeb return (ESRCH); 6966b4cac81SBjoern A. Zeeb } 6976b4cac81SBjoern A. Zeeb 6986b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 6996b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 7006b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 7016b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 7026b4cac81SBjoern A. Zeeb 7036b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 7046b4cac81SBjoern A. Zeeb 7056b4cac81SBjoern A. Zeeb /* Add chanctx (or if exists, change it). */ 7066b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 7076b4cac81SBjoern A. Zeeb conf = vif->chanctx_conf; 7086b4cac81SBjoern A. Zeeb IMPROVE("diff changes for changed, working on live copy, rcu"); 7096b4cac81SBjoern A. Zeeb } else { 7106b4cac81SBjoern A. Zeeb /* Keep separate alloc as in Linux this is rcu managed? */ 7116b4cac81SBjoern A. Zeeb conf = malloc(sizeof(*conf) + hw->chanctx_data_size, 7126b4cac81SBjoern A. Zeeb M_LKPI80211, M_WAITOK | M_ZERO); 7136b4cac81SBjoern A. Zeeb } 7146b4cac81SBjoern A. Zeeb 7156b4cac81SBjoern A. Zeeb conf->rx_chains_dynamic = 1; 7166b4cac81SBjoern A. Zeeb conf->rx_chains_static = 1; 7176b4cac81SBjoern A. Zeeb conf->radar_enabled = 7186b4cac81SBjoern A. Zeeb (chan->flags & IEEE80211_CHAN_RADAR) ? true : false; 7196b4cac81SBjoern A. Zeeb conf->def.chan = chan; 7206b4cac81SBjoern A. Zeeb conf->def.width = NL80211_CHAN_WIDTH_20_NOHT; 7216b4cac81SBjoern A. Zeeb conf->def.center_freq1 = chan->center_freq; 7226b4cac81SBjoern A. Zeeb conf->def.center_freq2 = 0; 7236b4cac81SBjoern A. Zeeb /* Responder ... */ 7246b4cac81SBjoern A. Zeeb conf->min_def.chan = chan; 7256b4cac81SBjoern A. Zeeb conf->min_def.width = NL80211_CHAN_WIDTH_20_NOHT; 7266b4cac81SBjoern A. Zeeb conf->min_def.center_freq1 = chan->center_freq; 7276b4cac81SBjoern A. Zeeb conf->min_def.center_freq2 = 0; 7286b4cac81SBjoern A. Zeeb IMPROVE("currently 20_NOHT only"); 7296b4cac81SBjoern A. Zeeb 7306b4cac81SBjoern A. Zeeb ni = NULL; 7316b4cac81SBjoern A. Zeeb error = 0; 7326b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 7336b4cac81SBjoern A. Zeeb changed = IEEE80211_CHANCTX_CHANGE_MIN_WIDTH; 7346b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_RADAR; 7356b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_RX_CHAINS; 7366b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_WIDTH; 7376b4cac81SBjoern A. Zeeb lkpi_80211_mo_change_chanctx(hw, conf, changed); 7386b4cac81SBjoern A. Zeeb } else { 7396b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_add_chanctx(hw, conf); 7406b4cac81SBjoern A. Zeeb if (error == 0 || error == EOPNOTSUPP) { 7416b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.chan = conf->def.chan; 7426b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.width = conf->def.width; 7436b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.center_freq1 = 7446b4cac81SBjoern A. Zeeb conf->def.center_freq1; 7456b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.center_freq2 = 7466b4cac81SBjoern A. Zeeb conf->def.center_freq2; 7476b4cac81SBjoern A. Zeeb } else { 7486b4cac81SBjoern A. Zeeb goto out; 7496b4cac81SBjoern A. Zeeb } 7506b4cac81SBjoern A. Zeeb /* Assign vif chanctx. */ 7516b4cac81SBjoern A. Zeeb if (error == 0) 7526b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_assign_vif_chanctx(hw, vif, conf); 7536b4cac81SBjoern A. Zeeb if (error == EOPNOTSUPP) 7546b4cac81SBjoern A. Zeeb error = 0; 7556b4cac81SBjoern A. Zeeb if (error != 0) { 7566b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 7576b4cac81SBjoern A. Zeeb free(conf, M_LKPI80211); 7586b4cac81SBjoern A. Zeeb goto out; 7596b4cac81SBjoern A. Zeeb } 7606b4cac81SBjoern A. Zeeb } 7616b4cac81SBjoern A. Zeeb IMPROVE("update radiotap chan fields too"); 7626b4cac81SBjoern A. Zeeb 7636b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 7646b4cac81SBjoern A. Zeeb 7656b4cac81SBjoern A. Zeeb /* Set bss info (bss_info_changed). */ 7666b4cac81SBjoern A. Zeeb bss_changed = 0; 7676b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(vif->bss_conf.bssid, ni->ni_bssid); 7686b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 7696b4cac81SBjoern A. Zeeb vif->bss_conf.txpower = ni->ni_txpower; 7706b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_TXPOWER; 7716b4cac81SBjoern A. Zeeb vif->bss_conf.idle = false; 7726b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_IDLE; 7736b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = ni->ni_intval; 7746b4cac81SBjoern A. Zeeb /* iwlwifi FW bug workaround; iwl_mvm_mac_sta_state. */ 7756b4cac81SBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16) 7766b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = 16; 7776b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INT; 7786b4cac81SBjoern A. Zeeb /* Should almost assert it is this. */ 7796b4cac81SBjoern A. Zeeb vif->bss_conf.assoc = false; 7806b4cac81SBjoern A. Zeeb vif->bss_conf.aid = 0; 7816b4cac81SBjoern A. Zeeb /* RATES */ 7826b4cac81SBjoern A. Zeeb IMPROVE("bss info: not all needs to come now and rates are missing"); 7836b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 7846b4cac81SBjoern A. Zeeb 7856b4cac81SBjoern A. Zeeb /* Add (or adjust) sta and change state (from NOTEXIST) to NONE. */ 7866b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 7876b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 7886b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NOTEXIST, ("%s: lsta %p state not " 7896b4cac81SBjoern A. Zeeb "NOTEXIST: %#x\n", __func__, lsta, lsta->state)); 7906b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 7916b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_NONE); 7926b4cac81SBjoern A. Zeeb if (error != 0) { 7936b4cac81SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 7946b4cac81SBjoern A. Zeeb goto out; 7956b4cac81SBjoern A. Zeeb } 7966b4cac81SBjoern A. Zeeb #if 0 7976b4cac81SBjoern A. Zeeb lsta->added_to_drv = true; /* mo manages. */ 7986b4cac81SBjoern A. Zeeb #endif 7996b4cac81SBjoern A. Zeeb 8006b4cac81SBjoern A. Zeeb /* 8016b4cac81SBjoern A. Zeeb * Wakeup all queues now that sta is there so we have as much time to 8026b4cac81SBjoern A. Zeeb * possibly prepare the queue in the driver to be ready for the 1st 8036b4cac81SBjoern A. Zeeb * packet; lkpi_80211_txq_tx_one() still has a workaround as there 8046b4cac81SBjoern A. Zeeb * is no guarantee or way to check. 8056b4cac81SBjoern A. Zeeb */ 8066b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, false, false); 8076b4cac81SBjoern A. Zeeb 8086b4cac81SBjoern A. Zeeb { 8096b4cac81SBjoern A. Zeeb int i, count; 8106b4cac81SBjoern A. Zeeb 811500be2e8SBjoern A. Zeeb for (i = 3 * (hw->queues + 1); i > 0; i--) { 8126b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 8136b4cac81SBjoern A. Zeeb int tid; 8146b4cac81SBjoern A. Zeeb 8156b4cac81SBjoern A. Zeeb count = 0; 8166b4cac81SBjoern A. Zeeb /* Wake up all queues to know they are allocated in the driver. */ 8176b4cac81SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 8186b4cac81SBjoern A. Zeeb 8196b4cac81SBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) { 8206b4cac81SBjoern A. Zeeb IMPROVE("station specific?"); 8216b4cac81SBjoern A. Zeeb if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ)) 8226b4cac81SBjoern A. Zeeb continue; 8236b4cac81SBjoern A. Zeeb } else if (tid >= hw->queues) 8246b4cac81SBjoern A. Zeeb continue; 8256b4cac81SBjoern A. Zeeb 8266b4cac81SBjoern A. Zeeb if (sta->txq[tid] == NULL) 8276b4cac81SBjoern A. Zeeb continue; 8286b4cac81SBjoern A. Zeeb 8296b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]); 8306b4cac81SBjoern A. Zeeb if (!ltxq->seen_dequeue) 8316b4cac81SBjoern A. Zeeb count++; 8326b4cac81SBjoern A. Zeeb } 8336b4cac81SBjoern A. Zeeb if (count == 0) 8346b4cac81SBjoern A. Zeeb break; 8356b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 8366b4cac81SBjoern A. Zeeb if (count > 0) 8376b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: waiting for %d quuees " 8386b4cac81SBjoern A. Zeeb "to be allocated by driver\n", __func__, count); 8396b4cac81SBjoern A. Zeeb #endif 840500be2e8SBjoern A. Zeeb pause("lkpi80211txq", hz/10); 8416b4cac81SBjoern A. Zeeb } 8426b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 8436b4cac81SBjoern A. Zeeb if (count > 0) 8446b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: %d quuees still not " 8456b4cac81SBjoern A. Zeeb "allocated by driver\n", __func__, count); 8466b4cac81SBjoern A. Zeeb #endif 8476b4cac81SBjoern A. Zeeb } 8486b4cac81SBjoern A. Zeeb 8496b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 8506b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 8516b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 8526b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 8536b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 8546b4cac81SBjoern A. Zeeb 8556b4cac81SBjoern A. Zeeb /* 8566b4cac81SBjoern A. Zeeb * What is going to happen next: 8576b4cac81SBjoern A. Zeeb * - <twiddle> .. we should end up in "auth_to_assoc" 8586b4cac81SBjoern A. Zeeb * - event_callback 8596b4cac81SBjoern A. Zeeb * - update sta_state (NONE to AUTH) 8606b4cac81SBjoern A. Zeeb * - mgd_complete_tx 8616b4cac81SBjoern A. Zeeb * (ideally we'd do that on a callback for something else ...) 8626b4cac81SBjoern A. Zeeb */ 8636b4cac81SBjoern A. Zeeb 8646b4cac81SBjoern A. Zeeb out: 8656b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 8666b4cac81SBjoern A. Zeeb if (ni != NULL) 8676b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 8686b4cac81SBjoern A. Zeeb return (error); 8696b4cac81SBjoern A. Zeeb } 8706b4cac81SBjoern A. Zeeb 8716b4cac81SBjoern A. Zeeb static int 8726b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 8736b4cac81SBjoern A. Zeeb { 8746b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 8756b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 8766b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 8776b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 8786b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 8796b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 8806b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 8816b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 8826b4cac81SBjoern A. Zeeb int error; 8836b4cac81SBjoern A. Zeeb 8846b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 8856b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 8866b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 8876b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 8886b4cac81SBjoern A. Zeeb 8896b4cac81SBjoern A. Zeeb /* Keep ni around. */ 8906b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 8916b4cac81SBjoern A. Zeeb 8926b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 8936b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 8946b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 8956b4cac81SBjoern A. Zeeb 8966b4cac81SBjoern A. Zeeb /* flush, drop. */ 8976b4cac81SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 8986b4cac81SBjoern A. Zeeb 8996b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 9006b4cac81SBjoern A. Zeeb 9016b4cac81SBjoern A. Zeeb /* Call iv_newstate first so we get potential deauth packet out. */ 9026b4cac81SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 9036b4cac81SBjoern A. Zeeb if (error != 0) 9046b4cac81SBjoern A. Zeeb goto outni; 9056b4cac81SBjoern A. Zeeb 9066b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 9076b4cac81SBjoern A. Zeeb 9086b4cac81SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 9096b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 9106b4cac81SBjoern A. Zeeb 9116b4cac81SBjoern A. Zeeb /* flush, no drop */ 9126b4cac81SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 9136b4cac81SBjoern A. Zeeb 9146b4cac81SBjoern A. Zeeb /* Take the station and chan ctx down again. */ 9156b4cac81SBjoern A. Zeeb 9166b4cac81SBjoern A. Zeeb IMPROVE("event callback with failure?"); 9176b4cac81SBjoern A. Zeeb 9186b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 9196b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 9206b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 9216b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 9226b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 9236b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 9246b4cac81SBjoern A. Zeeb } 9256b4cac81SBjoern A. Zeeb 9266b4cac81SBjoern A. Zeeb #ifdef __not_yet__ 9276b4cac81SBjoern A. Zeeb /* sync_rx_queues */ 9286b4cac81SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 9296b4cac81SBjoern A. Zeeb 9306b4cac81SBjoern A. Zeeb /* sta_pre_rcu_remove */ 9316b4cac81SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 9326b4cac81SBjoern A. Zeeb #endif 9336b4cac81SBjoern A. Zeeb 9346b4cac81SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 9356b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 9366b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 9376b4cac81SBjoern A. Zeeb "NONE: %#x\n", __func__, lsta, lsta->state)); 9386b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_NOTEXIST); 9396b4cac81SBjoern A. Zeeb if (error != 0) { 9406b4cac81SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 9416b4cac81SBjoern A. Zeeb goto out; 9426b4cac81SBjoern A. Zeeb } 9436b4cac81SBjoern A. Zeeb #if 0 9446b4cac81SBjoern A. Zeeb lsta->added_to_drv = false; /* mo manages. */ 9456b4cac81SBjoern A. Zeeb #endif 9466b4cac81SBjoern A. Zeeb 9476b4cac81SBjoern A. Zeeb IMPROVE("Any bss_info changes to announce?"); 9486b4cac81SBjoern A. Zeeb 9496b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 9506b4cac81SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 9516b4cac81SBjoern A. Zeeb 9526b4cac81SBjoern A. Zeeb conf = vif->chanctx_conf; 9536b4cac81SBjoern A. Zeeb /* Remove vif context. */ 9546b4cac81SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->chanctx_conf); 9556b4cac81SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 9566b4cac81SBjoern A. Zeeb 9576b4cac81SBjoern A. Zeeb /* Remove chan ctx. */ 9586b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 9596b4cac81SBjoern A. Zeeb free(conf, M_LKPI80211); 9606b4cac81SBjoern A. Zeeb } 9616b4cac81SBjoern A. Zeeb 9626b4cac81SBjoern A. Zeeb /* No need to start a scan; ic_scan_start should do. */ 9636b4cac81SBjoern A. Zeeb 9646b4cac81SBjoern A. Zeeb error = EALREADY; 9656b4cac81SBjoern A. Zeeb out: 9666b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 9676b4cac81SBjoern A. Zeeb outni: 9686b4cac81SBjoern A. Zeeb if (ni != NULL) 9696b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 9706b4cac81SBjoern A. Zeeb return (error); 9716b4cac81SBjoern A. Zeeb } 9726b4cac81SBjoern A. Zeeb 9736b4cac81SBjoern A. Zeeb static int 9746b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 9756b4cac81SBjoern A. Zeeb { 9766b4cac81SBjoern A. Zeeb int error; 9776b4cac81SBjoern A. Zeeb 9786b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_scan(vap, nstate, arg); 9796b4cac81SBjoern A. Zeeb if (error == 0) 9806b4cac81SBjoern A. Zeeb error = lkpi_sta_scan_to_init(vap, nstate, arg); 9816b4cac81SBjoern A. Zeeb return (error); 9826b4cac81SBjoern A. Zeeb } 9836b4cac81SBjoern A. Zeeb 9846b4cac81SBjoern A. Zeeb static int 9856b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 9866b4cac81SBjoern A. Zeeb { 9876b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 9886b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 9896b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 9906b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 9916b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 9926b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 9936b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 9946b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 9956b4cac81SBjoern A. Zeeb int error; 9966b4cac81SBjoern A. Zeeb 9976b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 9986b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 9996b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 10006b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 10016b4cac81SBjoern A. Zeeb 10026b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 10036b4cac81SBjoern A. Zeeb ni = NULL; 10046b4cac81SBjoern A. Zeeb 10056b4cac81SBjoern A. Zeeb /* Finish auth. */ 10066b4cac81SBjoern A. Zeeb IMPROVE("event callback"); 10076b4cac81SBjoern A. Zeeb 10086b4cac81SBjoern A. Zeeb /* Update sta_state (NONE to AUTH). */ 10096b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 10106b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 10116b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 10126b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 10136b4cac81SBjoern A. Zeeb "NONE: %#x\n", __func__, lsta, lsta->state)); 10146b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 10156b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_AUTH); 10166b4cac81SBjoern A. Zeeb if (error != 0) 10176b4cac81SBjoern A. Zeeb goto out; 10186b4cac81SBjoern A. Zeeb 10196b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 10206b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 10216b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 10226b4cac81SBjoern A. Zeeb prep_tx_info.success = true; 10236b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 10246b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 10256b4cac81SBjoern A. Zeeb } 10266b4cac81SBjoern A. Zeeb 10276b4cac81SBjoern A. Zeeb /* Now start assoc. */ 10286b4cac81SBjoern A. Zeeb 10296b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 10306b4cac81SBjoern A. Zeeb if (!lsta->in_mgd) { 10316b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 10326b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 10336b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 10346b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 10356b4cac81SBjoern A. Zeeb } 10366b4cac81SBjoern A. Zeeb 10376b4cac81SBjoern A. Zeeb /* Wake tx queue to get packet out. */ 10386b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 10396b4cac81SBjoern A. Zeeb 10406b4cac81SBjoern A. Zeeb /* 10416b4cac81SBjoern A. Zeeb * <twiddle> .. we end up in "assoc_to_run" 10426b4cac81SBjoern A. Zeeb * - update sta_state (AUTH to ASSOC) 10436b4cac81SBjoern A. Zeeb * - conf_tx [all] 10446b4cac81SBjoern A. Zeeb * - bss_info_changed (assoc, aid, ssid, ..) 10456b4cac81SBjoern A. Zeeb * - change_chanctx (if needed) 10466b4cac81SBjoern A. Zeeb * - event_callback 10476b4cac81SBjoern A. Zeeb * - mgd_complete_tx 10486b4cac81SBjoern A. Zeeb */ 10496b4cac81SBjoern A. Zeeb 10506b4cac81SBjoern A. Zeeb out: 10516b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 10526b4cac81SBjoern A. Zeeb if (ni != NULL) 10536b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 10546b4cac81SBjoern A. Zeeb return (error); 10556b4cac81SBjoern A. Zeeb } 10566b4cac81SBjoern A. Zeeb 10576b4cac81SBjoern A. Zeeb /* auth_to_auth, assoc_to_assoc. */ 10586b4cac81SBjoern A. Zeeb static int 10596b4cac81SBjoern A. Zeeb lkpi_sta_a_to_a(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 10606b4cac81SBjoern A. Zeeb { 10616b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 10626b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 10636b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 10646b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 10656b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 10666b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 10676b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 10686b4cac81SBjoern A. Zeeb 10696b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 10706b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 10716b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 10726b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 10736b4cac81SBjoern A. Zeeb 10746b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 10756b4cac81SBjoern A. Zeeb 10766b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 10776b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 10786b4cac81SBjoern A. Zeeb 10796b4cac81SBjoern A. Zeeb IMPROVE("event callback?"); 10806b4cac81SBjoern A. Zeeb 10816b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 10826b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 10836b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 10846b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 10856b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 10866b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 10876b4cac81SBjoern A. Zeeb } 10886b4cac81SBjoern A. Zeeb 10896b4cac81SBjoern A. Zeeb /* Now start assoc. */ 10906b4cac81SBjoern A. Zeeb 10916b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 10926b4cac81SBjoern A. Zeeb if (!lsta->in_mgd) { 10936b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 10946b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 10956b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 10966b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 10976b4cac81SBjoern A. Zeeb } 10986b4cac81SBjoern A. Zeeb 10996b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 11006b4cac81SBjoern A. Zeeb if (ni != NULL) 11016b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 11026b4cac81SBjoern A. Zeeb 11036b4cac81SBjoern A. Zeeb return (0); 11046b4cac81SBjoern A. Zeeb } 11056b4cac81SBjoern A. Zeeb 11066b4cac81SBjoern A. Zeeb static int 11076b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 11086b4cac81SBjoern A. Zeeb { 11096b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 11106b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 11116b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 11126b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 11136b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 11146b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 11156b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 11166b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 11176b4cac81SBjoern A. Zeeb int error; 11186b4cac81SBjoern A. Zeeb 11196b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 11206b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 11216b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 11226b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 11236b4cac81SBjoern A. Zeeb 11246b4cac81SBjoern A. Zeeb /* Keep ni around. */ 11256b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 11266b4cac81SBjoern A. Zeeb 11276b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 11286b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 11296b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 11306b4cac81SBjoern A. Zeeb 11316b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 11326b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 11336b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 11346b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 11356b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 11366b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 11376b4cac81SBjoern A. Zeeb } 11386b4cac81SBjoern A. Zeeb 11396b4cac81SBjoern A. Zeeb /* Update sta and change state (from AUTH) to NONE. */ 11406b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 11416b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 11426b4cac81SBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 11436b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_NONE); 11446b4cac81SBjoern A. Zeeb if (error != 0) 11456b4cac81SBjoern A. Zeeb goto out; 11466b4cac81SBjoern A. Zeeb 11476b4cac81SBjoern A. Zeeb IMPROVE("anything else?"); 11486b4cac81SBjoern A. Zeeb 11496b4cac81SBjoern A. Zeeb out: 11506b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 11516b4cac81SBjoern A. Zeeb if (ni != NULL) 11526b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 11536b4cac81SBjoern A. Zeeb return (error); 11546b4cac81SBjoern A. Zeeb } 11556b4cac81SBjoern A. Zeeb 11566b4cac81SBjoern A. Zeeb static int 11576b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 11586b4cac81SBjoern A. Zeeb { 11596b4cac81SBjoern A. Zeeb int error; 11606b4cac81SBjoern A. Zeeb 11616b4cac81SBjoern A. Zeeb error = lkpi_sta_assoc_to_auth(vap, nstate, arg); 11626b4cac81SBjoern A. Zeeb if (error == 0) 11636b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_scan(vap, nstate, arg); 11646b4cac81SBjoern A. Zeeb return (error); 11656b4cac81SBjoern A. Zeeb } 11666b4cac81SBjoern A. Zeeb 11676b4cac81SBjoern A. Zeeb static int 11686b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 11696b4cac81SBjoern A. Zeeb { 11706b4cac81SBjoern A. Zeeb int error; 11716b4cac81SBjoern A. Zeeb 11726b4cac81SBjoern A. Zeeb error = lkpi_sta_assoc_to_scan(vap, nstate, arg); 11736b4cac81SBjoern A. Zeeb if (error == 0) 11746b4cac81SBjoern A. Zeeb error = lkpi_sta_scan_to_init(vap, nstate, arg); 11756b4cac81SBjoern A. Zeeb return (error); 11766b4cac81SBjoern A. Zeeb } 11776b4cac81SBjoern A. Zeeb 11786b4cac81SBjoern A. Zeeb static int 11796b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 11806b4cac81SBjoern A. Zeeb { 11816b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 11826b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 11836b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 11846b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 11856b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 11866b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 11876b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 11886b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 11896b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 11906b4cac81SBjoern A. Zeeb int error; 11916b4cac81SBjoern A. Zeeb 11926b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 11936b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 11946b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 11956b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 11966b4cac81SBjoern A. Zeeb 11976b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 11986b4cac81SBjoern A. Zeeb ni = NULL; 11996b4cac81SBjoern A. Zeeb 12006b4cac81SBjoern A. Zeeb IMPROVE("ponder some of this moved to ic_newassoc, scan_assoc_success, " 12016b4cac81SBjoern A. Zeeb "and to lesser extend ieee80211_notify_node_join"); 12026b4cac81SBjoern A. Zeeb 12036b4cac81SBjoern A. Zeeb /* Finish assoc. */ 12046b4cac81SBjoern A. Zeeb /* Update sta_state (AUTH to ASSOC) and set aid. */ 12056b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 12066b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 12076b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 12086b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 12096b4cac81SBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 12106b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 12116b4cac81SBjoern A. Zeeb sta->aid = IEEE80211_NODE_AID(ni); 12126b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_ASSOC); 12136b4cac81SBjoern A. Zeeb if (error != 0) 12146b4cac81SBjoern A. Zeeb goto out; 12156b4cac81SBjoern A. Zeeb 12166b4cac81SBjoern A. Zeeb IMPROVE("wme / conf_tx [all]"); 12176b4cac81SBjoern A. Zeeb 12186b4cac81SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 12196b4cac81SBjoern A. Zeeb bss_changed = 0; 12206b4cac81SBjoern A. Zeeb if (!vif->bss_conf.assoc || vif->bss_conf.aid != IEEE80211_NODE_AID(ni)) { 12216b4cac81SBjoern A. Zeeb vif->bss_conf.assoc = true; 12226b4cac81SBjoern A. Zeeb vif->bss_conf.aid = IEEE80211_NODE_AID(ni); 12236b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_ASSOC; 12246b4cac81SBjoern A. Zeeb } 12256b4cac81SBjoern A. Zeeb /* We set SSID but this is not BSSID! */ 12266b4cac81SBjoern A. Zeeb vif->bss_conf.ssid_len = ni->ni_esslen; 12276b4cac81SBjoern A. Zeeb memcpy(vif->bss_conf.ssid, ni->ni_essid, ni->ni_esslen); 12286b4cac81SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_SHPREAMBLE) != 12296b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble) { 12306b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble ^= 1; 12316b4cac81SBjoern A. Zeeb /* bss_changed |= BSS_CHANGED_??? */ 12326b4cac81SBjoern A. Zeeb } 12336b4cac81SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_SHSLOT) != 12346b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot) { 12356b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot ^= 1; 12366b4cac81SBjoern A. Zeeb /* bss_changed |= BSS_CHANGED_??? */ 12376b4cac81SBjoern A. Zeeb } 12386b4cac81SBjoern A. Zeeb if ((ni->ni_flags & IEEE80211_NODE_QOS) != 12396b4cac81SBjoern A. Zeeb vif->bss_conf.qos) { 12406b4cac81SBjoern A. Zeeb vif->bss_conf.qos ^= 1; 12416b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 12426b4cac81SBjoern A. Zeeb } 12436b4cac81SBjoern A. Zeeb if (vif->bss_conf.beacon_int != ni->ni_intval) { 12446b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = ni->ni_intval; 12456b4cac81SBjoern A. Zeeb /* iwlwifi FW bug workaround; iwl_mvm_mac_sta_state. */ 12466b4cac81SBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16) 12476b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = 16; 12486b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INT; 12496b4cac81SBjoern A. Zeeb } 12506b4cac81SBjoern A. Zeeb if (vif->bss_conf.dtim_period != vap->iv_dtim_period && 12516b4cac81SBjoern A. Zeeb vap->iv_dtim_period > 0) { 12526b4cac81SBjoern A. Zeeb vif->bss_conf.dtim_period = vap->iv_dtim_period; 12536b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INFO; 12546b4cac81SBjoern A. Zeeb } 12556b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 12566b4cac81SBjoern A. Zeeb 12576b4cac81SBjoern A. Zeeb /* - change_chanctx (if needed) 12586b4cac81SBjoern A. Zeeb * - event_callback 12596b4cac81SBjoern A. Zeeb */ 12606b4cac81SBjoern A. Zeeb 12616b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 12626b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 12636b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 12646b4cac81SBjoern A. Zeeb prep_tx_info.success = true; 12656b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 12666b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 12676b4cac81SBjoern A. Zeeb } 12686b4cac81SBjoern A. Zeeb 1269*086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, false); 1270*086be6a8SBjoern A. Zeeb 12716b4cac81SBjoern A. Zeeb /* 12726b4cac81SBjoern A. Zeeb * And then: 12736b4cac81SBjoern A. Zeeb * - (more packets)? 12746b4cac81SBjoern A. Zeeb * - set_key 12756b4cac81SBjoern A. Zeeb * - set_default_unicast_key 12766b4cac81SBjoern A. Zeeb * - set_key (?) 12776b4cac81SBjoern A. Zeeb * - ipv6_addr_change (?) 12786b4cac81SBjoern A. Zeeb */ 12796b4cac81SBjoern A. Zeeb /* Prepare_multicast && configure_filter. */ 12806b4cac81SBjoern A. Zeeb lhw->update_mc = true; 12816b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(vap->iv_ic, true); 12826b4cac81SBjoern A. Zeeb 12836b4cac81SBjoern A. Zeeb if (!ieee80211_node_is_authorized(ni)) { 12846b4cac81SBjoern A. Zeeb IMPROVE("net80211 does not consider node authorized"); 12856b4cac81SBjoern A. Zeeb } 12866b4cac81SBjoern A. Zeeb 12876b4cac81SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTHORIZED). */ 12886b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 12896b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 12906b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 12916b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 12926b4cac81SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 12936b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 12946b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_AUTHORIZED); 12956b4cac81SBjoern A. Zeeb if (error != 0) { 12966b4cac81SBjoern A. Zeeb IMPROVE("undo some changes?"); 12976b4cac81SBjoern A. Zeeb goto out; 12986b4cac81SBjoern A. Zeeb } 12996b4cac81SBjoern A. Zeeb 13006b4cac81SBjoern A. Zeeb /* - drv_config (?) 13016b4cac81SBjoern A. Zeeb * - bss_info_changed 13026b4cac81SBjoern A. Zeeb * - set_rekey_data (?) 13036b4cac81SBjoern A. Zeeb * 13046b4cac81SBjoern A. Zeeb * And now we should be passing packets. 13056b4cac81SBjoern A. Zeeb */ 13066b4cac81SBjoern A. Zeeb IMPROVE("Need that bssid setting, and the keys"); 13076b4cac81SBjoern A. Zeeb 13086b4cac81SBjoern A. Zeeb out: 13096b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 13106b4cac81SBjoern A. Zeeb if (ni != NULL) 13116b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 13126b4cac81SBjoern A. Zeeb return (error); 13136b4cac81SBjoern A. Zeeb } 13146b4cac81SBjoern A. Zeeb 13156b4cac81SBjoern A. Zeeb static int 13166b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 13176b4cac81SBjoern A. Zeeb { 13186b4cac81SBjoern A. Zeeb int error; 13196b4cac81SBjoern A. Zeeb 13206b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_assoc(vap, nstate, arg); 13216b4cac81SBjoern A. Zeeb if (error == 0) 13226b4cac81SBjoern A. Zeeb error = lkpi_sta_assoc_to_run(vap, nstate, arg); 13236b4cac81SBjoern A. Zeeb return (error); 13246b4cac81SBjoern A. Zeeb } 13256b4cac81SBjoern A. Zeeb 13266b4cac81SBjoern A. Zeeb static int 13276b4cac81SBjoern A. Zeeb lkpi_sta_run_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 13286b4cac81SBjoern A. Zeeb { 13296b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 13306b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 13316b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 13326b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 13336b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 13346b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 13356b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 13366b4cac81SBjoern A. Zeeb int error; 13376b4cac81SBjoern A. Zeeb 13386b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 13396b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 13406b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 13416b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 13426b4cac81SBjoern A. Zeeb 13436b4cac81SBjoern A. Zeeb /* Keep ni around. */ 13446b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 13456b4cac81SBjoern A. Zeeb 13466b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 13476b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 13486b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 13496b4cac81SBjoern A. Zeeb 13506b4cac81SBjoern A. Zeeb /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */ 13516b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 13526b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not " 13536b4cac81SBjoern A. Zeeb "AUTHORIZED: %#x\n", __func__, lsta, lsta->state)); 13546b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_ASSOC); 13556b4cac81SBjoern A. Zeeb if (error != 0) 13566b4cac81SBjoern A. Zeeb goto out; 13576b4cac81SBjoern A. Zeeb 13586b4cac81SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 13596b4cac81SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw); 13606b4cac81SBjoern A. Zeeb 13616b4cac81SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTH). */ 13626b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 13636b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 13646b4cac81SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 13656b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 13666b4cac81SBjoern A. Zeeb sta->aid = 0; 13676b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_AUTH); 13686b4cac81SBjoern A. Zeeb if (error != 0) 13696b4cac81SBjoern A. Zeeb goto out; 13706b4cac81SBjoern A. Zeeb 13716b4cac81SBjoern A. Zeeb IMPROVE("if ASSOC is final state, prep_tx_info?"); 13726b4cac81SBjoern A. Zeeb 13736b4cac81SBjoern A. Zeeb out: 13746b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 13756b4cac81SBjoern A. Zeeb if (ni != NULL) 13766b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 13776b4cac81SBjoern A. Zeeb return (error); 13786b4cac81SBjoern A. Zeeb } 13796b4cac81SBjoern A. Zeeb 13806b4cac81SBjoern A. Zeeb static int 13816b4cac81SBjoern A. Zeeb lkpi_sta_run_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 13826b4cac81SBjoern A. Zeeb { 13836b4cac81SBjoern A. Zeeb int error; 13846b4cac81SBjoern A. Zeeb 13856b4cac81SBjoern A. Zeeb error = lkpi_sta_run_to_assoc(vap, nstate, arg); 13866b4cac81SBjoern A. Zeeb if (error == 0) 13876b4cac81SBjoern A. Zeeb error = lkpi_sta_assoc_to_auth(vap, nstate, arg); 13886b4cac81SBjoern A. Zeeb return (error); 13896b4cac81SBjoern A. Zeeb } 13906b4cac81SBjoern A. Zeeb 13916b4cac81SBjoern A. Zeeb static int 13926b4cac81SBjoern A. Zeeb lkpi_sta_run_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 13936b4cac81SBjoern A. Zeeb { 13946b4cac81SBjoern A. Zeeb int error; 13956b4cac81SBjoern A. Zeeb 13966b4cac81SBjoern A. Zeeb error = lkpi_sta_run_to_auth(vap, nstate, arg); 13976b4cac81SBjoern A. Zeeb if (error == 0) 13986b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_scan(vap, nstate, arg); 13996b4cac81SBjoern A. Zeeb return (error); 14006b4cac81SBjoern A. Zeeb } 14016b4cac81SBjoern A. Zeeb 14026b4cac81SBjoern A. Zeeb static int 14036b4cac81SBjoern A. Zeeb lkpi_sta_run_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 14046b4cac81SBjoern A. Zeeb { 14056b4cac81SBjoern A. Zeeb int error; 14066b4cac81SBjoern A. Zeeb 14076b4cac81SBjoern A. Zeeb error = lkpi_sta_run_to_scan(vap, nstate, arg); 14086b4cac81SBjoern A. Zeeb if (error == 0) 14096b4cac81SBjoern A. Zeeb error = lkpi_sta_scan_to_init(vap, nstate, arg); 14106b4cac81SBjoern A. Zeeb return (error); 14116b4cac81SBjoern A. Zeeb } 14126b4cac81SBjoern A. Zeeb 14136b4cac81SBjoern A. Zeeb /* 14146b4cac81SBjoern A. Zeeb * The matches the documented state changes in net80211::sta_newstate(). 14156b4cac81SBjoern A. Zeeb * XXX (1) without CSA and SLEEP yet, * XXX (2) not all unhandled cases 14166b4cac81SBjoern A. Zeeb * there are "invalid" (so there is a room for failure here). 14176b4cac81SBjoern A. Zeeb */ 14186b4cac81SBjoern A. Zeeb struct fsm_state { 14196b4cac81SBjoern A. Zeeb /* INIT, SCAN, AUTH, ASSOC, CAC, RUN, CSA, SLEEP */ 14206b4cac81SBjoern A. Zeeb enum ieee80211_state ostate; 14216b4cac81SBjoern A. Zeeb enum ieee80211_state nstate; 14226b4cac81SBjoern A. Zeeb int (*handler)(struct ieee80211vap *, enum ieee80211_state, int); 14236b4cac81SBjoern A. Zeeb } sta_state_fsm[] = { 14246b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, 14256b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, /* scan_to_init */ 14266b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_INIT, lkpi_sta_auth_to_init }, /* not explicitly in sta_newstate() */ 14276b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_INIT, lkpi_sta_assoc_to_init }, 14286b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_INIT, lkpi_sta_run_to_init }, 14296b4cac81SBjoern A. Zeeb 14306b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_SCAN, lkpi_sta_state_do_nada }, 14316b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_SCAN, lkpi_sta_state_do_nada }, 14326b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_SCAN, lkpi_sta_auth_to_scan }, 14336b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_SCAN, lkpi_sta_assoc_to_scan }, 14346b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_SCAN, lkpi_sta_run_to_scan }, 14356b4cac81SBjoern A. Zeeb 14366b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, 14376b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, 14386b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_AUTH, lkpi_sta_a_to_a }, 14396b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_AUTH, lkpi_sta_assoc_to_auth }, 14406b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_AUTH, lkpi_sta_run_to_auth }, 14416b4cac81SBjoern A. Zeeb 14426b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_ASSOC, lkpi_sta_auth_to_assoc }, 14436b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_ASSOC, lkpi_sta_a_to_a }, 14446b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_ASSOC, lkpi_sta_run_to_assoc }, 14456b4cac81SBjoern A. Zeeb 14466b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_RUN, lkpi_sta_auth_to_run }, 14476b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_RUN, lkpi_sta_assoc_to_run }, 14486b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_RUN, lkpi_sta_state_do_nada }, 14496b4cac81SBjoern A. Zeeb 14506b4cac81SBjoern A. Zeeb /* Dummy at the end without handler. */ 14516b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_INIT, NULL }, 14526b4cac81SBjoern A. Zeeb }; 14536b4cac81SBjoern A. Zeeb 14546b4cac81SBjoern A. Zeeb static int 14556b4cac81SBjoern A. Zeeb lkpi_iv_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 14566b4cac81SBjoern A. Zeeb { 14576b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 14586b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 14596b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 14606b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 14616b4cac81SBjoern A. Zeeb struct fsm_state *s; 14626b4cac81SBjoern A. Zeeb enum ieee80211_state ostate; 14636b4cac81SBjoern A. Zeeb int error; 14646b4cac81SBjoern A. Zeeb 14656b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 14666b4cac81SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(ic); 14676b4cac81SBjoern A. Zeeb ostate = vap->iv_state; 14686b4cac81SBjoern A. Zeeb 14696b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE) 14706b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x\n", 14716b4cac81SBjoern A. Zeeb __func__, __LINE__, vap, nstate, arg); 14726b4cac81SBjoern A. Zeeb 14736b4cac81SBjoern A. Zeeb if (vap->iv_opmode == IEEE80211_M_STA) { 14746b4cac81SBjoern A. Zeeb 14756b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 14766b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 14776b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 14786b4cac81SBjoern A. Zeeb 14796b4cac81SBjoern A. Zeeb /* No need to replicate this in most state handlers. */ 14806b4cac81SBjoern A. Zeeb if (ostate == IEEE80211_S_SCAN && nstate != IEEE80211_S_SCAN) 14816b4cac81SBjoern A. Zeeb lkpi_stop_hw_scan(lhw, vif); 14826b4cac81SBjoern A. Zeeb 14836b4cac81SBjoern A. Zeeb s = sta_state_fsm; 14846b4cac81SBjoern A. Zeeb 14856b4cac81SBjoern A. Zeeb } else { 14866b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: only station mode currently supported: " 14876b4cac81SBjoern A. Zeeb "cap %p iv_opmode %d\n", __func__, vap, vap->iv_opmode); 14886b4cac81SBjoern A. Zeeb return (ENOSYS); 14896b4cac81SBjoern A. Zeeb } 14906b4cac81SBjoern A. Zeeb 14916b4cac81SBjoern A. Zeeb error = 0; 14926b4cac81SBjoern A. Zeeb for (; s->handler != NULL; s++) { 14936b4cac81SBjoern A. Zeeb if (ostate == s->ostate && nstate == s->nstate) { 14946b4cac81SBjoern A. Zeeb error = s->handler(vap, nstate, arg); 14956b4cac81SBjoern A. Zeeb break; 14966b4cac81SBjoern A. Zeeb } 14976b4cac81SBjoern A. Zeeb } 14986b4cac81SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(vap->iv_ic); 14996b4cac81SBjoern A. Zeeb 15006b4cac81SBjoern A. Zeeb if (s->handler == NULL) { 15016b4cac81SBjoern A. Zeeb IMPROVE("thurn this into a KASSERT\n"); 15026b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: unsupported state transition " 15036b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s)\n", __func__, 15046b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 15056b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 15066b4cac81SBjoern A. Zeeb return (ENOSYS); 15076b4cac81SBjoern A. Zeeb } 15086b4cac81SBjoern A. Zeeb 15096b4cac81SBjoern A. Zeeb if (error == EALREADY) { 15106b4cac81SBjoern A. Zeeb IMPROVE("make this a debug log later"); 15116b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: error %d during state transition " 15126b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s): iv_newstate already handled.\n", 15136b4cac81SBjoern A. Zeeb __func__, error, 15146b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 15156b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 15166b4cac81SBjoern A. Zeeb return (0); 15176b4cac81SBjoern A. Zeeb } 15186b4cac81SBjoern A. Zeeb 15196b4cac81SBjoern A. Zeeb if (error != 0) { 15206b4cac81SBjoern A. Zeeb /* XXX-BZ currently expected so ignore. */ 15216b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: error %d during state transition " 15226b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s)\n", __func__, error, 15236b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 15246b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 15256b4cac81SBjoern A. Zeeb /* return (error); */ 15266b4cac81SBjoern A. Zeeb } 15276b4cac81SBjoern A. Zeeb 15286b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE) 15296b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x calling net80211 parent\n", 15306b4cac81SBjoern A. Zeeb __func__, __LINE__, vap, nstate, arg); 15316b4cac81SBjoern A. Zeeb 15326b4cac81SBjoern A. Zeeb return (lvif->iv_newstate(vap, nstate, arg)); 15336b4cac81SBjoern A. Zeeb } 15346b4cac81SBjoern A. Zeeb 15356b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 15366b4cac81SBjoern A. Zeeb 15376b4cac81SBjoern A. Zeeb static int 15386b4cac81SBjoern A. Zeeb lkpi_ic_wme_update(struct ieee80211com *ic) 15396b4cac81SBjoern A. Zeeb { 15406b4cac81SBjoern A. Zeeb /* This needs queuing and go at the right moment. */ 15416b4cac81SBjoern A. Zeeb #ifdef WITH_WME_UPDATE 15426b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 15436b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 15446b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 15456b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 15466b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 15476b4cac81SBjoern A. Zeeb struct chanAccParams chp; 15486b4cac81SBjoern A. Zeeb struct wmeParams wmeparr[WME_NUM_AC]; 15496b4cac81SBjoern A. Zeeb struct ieee80211_tx_queue_params txqp; 15506b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 15516b4cac81SBjoern A. Zeeb int error; 15526b4cac81SBjoern A. Zeeb uint16_t ac; 15536b4cac81SBjoern A. Zeeb #endif 15546b4cac81SBjoern A. Zeeb 15556b4cac81SBjoern A. Zeeb IMPROVE(); 15566b4cac81SBjoern A. Zeeb KASSERT(WME_NUM_AC == IEEE80211_NUM_ACS, ("%s: WME_NUM_AC %d != " 15576b4cac81SBjoern A. Zeeb "IEEE80211_NUM_ACS %d\n", __func__, WME_NUM_AC, IEEE80211_NUM_ACS)); 15586b4cac81SBjoern A. Zeeb 15596b4cac81SBjoern A. Zeeb #ifdef WITH_WME_UPDATE 15606b4cac81SBjoern A. Zeeb vap = TAILQ_FIRST(&ic->ic_vaps); 15616b4cac81SBjoern A. Zeeb if (vap == NULL) 15626b4cac81SBjoern A. Zeeb return (0); 15636b4cac81SBjoern A. Zeeb 15646b4cac81SBjoern A. Zeeb /* We should factor this out into per-vap (*wme_update). */ 15656b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 15666b4cac81SBjoern A. Zeeb if (lhw->ops->conf_tx == NULL) 15676b4cac81SBjoern A. Zeeb return (0); 15686b4cac81SBjoern A. Zeeb 15696b4cac81SBjoern A. Zeeb /* XXX-BZ check amount of hw queues */ 15706b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 15716b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 15726b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 15736b4cac81SBjoern A. Zeeb 15746b4cac81SBjoern A. Zeeb ieee80211_wme_ic_getparams(ic, &chp); 15756b4cac81SBjoern A. Zeeb IEEE80211_LOCK(ic); 15766b4cac81SBjoern A. Zeeb for (ac = 0; ac < WME_NUM_AC; ac++) 15776b4cac81SBjoern A. Zeeb wmeparr[ac] = chp.cap_wmeParams[ac]; 15786b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(ic); 15796b4cac81SBjoern A. Zeeb 15806b4cac81SBjoern A. Zeeb /* Configure tx queues (conf_tx) & send BSS_CHANGED_QOS. */ 15816b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 15826b4cac81SBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 15836b4cac81SBjoern A. Zeeb struct wmeParams *wmep; 15846b4cac81SBjoern A. Zeeb 15856b4cac81SBjoern A. Zeeb /* XXX-BZ should keep this in lvif? */ 15866b4cac81SBjoern A. Zeeb wmep = &wmeparr[ac]; 15876b4cac81SBjoern A. Zeeb bzero(&txqp, sizeof(txqp)); 15886b4cac81SBjoern A. Zeeb txqp.cw_min = wmep->wmep_logcwmin; 15896b4cac81SBjoern A. Zeeb txqp.cw_max = wmep->wmep_logcwmax; 15906b4cac81SBjoern A. Zeeb txqp.txop = wmep->wmep_txopLimit; 15916b4cac81SBjoern A. Zeeb txqp.aifs = wmep->wmep_aifsn; 15926b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_conf_tx(hw, vif, ac, &txqp); 15936b4cac81SBjoern A. Zeeb if (error != 0) 15946b4cac81SBjoern A. Zeeb printf("%s: conf_tx ac %u failed %d\n", 15956b4cac81SBjoern A. Zeeb __func__, ac, error); 15966b4cac81SBjoern A. Zeeb } 15976b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 15986b4cac81SBjoern A. Zeeb changed = BSS_CHANGED_QOS; 15996b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 16006b4cac81SBjoern A. Zeeb #endif 16016b4cac81SBjoern A. Zeeb 16026b4cac81SBjoern A. Zeeb return (0); 16036b4cac81SBjoern A. Zeeb } 16046b4cac81SBjoern A. Zeeb 16056b4cac81SBjoern A. Zeeb static struct ieee80211vap * 16066b4cac81SBjoern A. Zeeb lkpi_ic_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], 16076b4cac81SBjoern A. Zeeb int unit, enum ieee80211_opmode opmode, int flags, 16086b4cac81SBjoern A. Zeeb const uint8_t bssid[IEEE80211_ADDR_LEN], 16096b4cac81SBjoern A. Zeeb const uint8_t mac[IEEE80211_ADDR_LEN]) 16106b4cac81SBjoern A. Zeeb { 16116b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 16126b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 16136b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 16146b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 16156b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 16166b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 16176b4cac81SBjoern A. Zeeb size_t len; 16186b4cac81SBjoern A. Zeeb int error; 16196b4cac81SBjoern A. Zeeb 16206b4cac81SBjoern A. Zeeb if (!TAILQ_EMPTY(&ic->ic_vaps)) /* 1 so far. Add <n> once this works. */ 16216b4cac81SBjoern A. Zeeb return (NULL); 16226b4cac81SBjoern A. Zeeb 16236b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 16246b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 16256b4cac81SBjoern A. Zeeb 16266b4cac81SBjoern A. Zeeb len = sizeof(*lvif); 16276b4cac81SBjoern A. Zeeb len += hw->vif_data_size; /* vif->drv_priv */ 16286b4cac81SBjoern A. Zeeb 16296b4cac81SBjoern A. Zeeb lvif = malloc(len, M_80211_VAP, M_WAITOK | M_ZERO); 16306b4cac81SBjoern A. Zeeb mtx_init(&lvif->mtx, "lvif", NULL, MTX_DEF); 16316b4cac81SBjoern A. Zeeb TAILQ_INIT(&lvif->lsta_head); 16326b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 16336b4cac81SBjoern A. Zeeb 16346b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 16356b4cac81SBjoern A. Zeeb memcpy(vif->addr, mac, IEEE80211_ADDR_LEN); 16366b4cac81SBjoern A. Zeeb vif->p2p = false; 16376b4cac81SBjoern A. Zeeb vif->probe_req_reg = false; 16386b4cac81SBjoern A. Zeeb vif->type = lkpi_opmode_to_vif_type(opmode); 16396b4cac81SBjoern A. Zeeb lvif->wdev.iftype = vif->type; 16406b4cac81SBjoern A. Zeeb /* Need to fill in other fields as well. */ 16416b4cac81SBjoern A. Zeeb IMPROVE(); 16426b4cac81SBjoern A. Zeeb 16436b4cac81SBjoern A. Zeeb /* XXX-BZ hardcoded for now! */ 16446b4cac81SBjoern A. Zeeb #if 1 16456b4cac81SBjoern A. Zeeb vif->chanctx_conf = NULL; 16466b4cac81SBjoern A. Zeeb vif->bss_conf.idle = true; 16476b4cac81SBjoern A. Zeeb vif->bss_conf.ps = false; 16486b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.width = NL80211_CHAN_WIDTH_20_NOHT; 16496b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble = false; /* vap->iv_flags IEEE80211_F_SHPREAMBLE */ 16506b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot = false; /* vap->iv_flags IEEE80211_F_SHSLOT */ 16516b4cac81SBjoern A. Zeeb vif->bss_conf.qos = false; 16526b4cac81SBjoern A. Zeeb vif->bss_conf.use_cts_prot = false; /* vap->iv_protmode */ 16536b4cac81SBjoern A. Zeeb vif->bss_conf.ht_operation_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONE; 16546b4cac81SBjoern A. Zeeb vif->bss_conf.assoc = false; 16556b4cac81SBjoern A. Zeeb vif->bss_conf.aid = 0; 16566b4cac81SBjoern A. Zeeb #endif 16576b4cac81SBjoern A. Zeeb #if 0 16586b4cac81SBjoern A. Zeeb vif->bss_conf.dtim_period = 0; /* IEEE80211_DTIM_DEFAULT ; must stay 0. */ 16596b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(vif->bss_conf.bssid, bssid); 16606b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = ic->ic_bintval; 16616b4cac81SBjoern A. Zeeb /* iwlwifi bug. */ 16626b4cac81SBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16) 16636b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = 16; 16646b4cac81SBjoern A. Zeeb #endif 16656b4cac81SBjoern A. Zeeb IMPROVE(); 16666b4cac81SBjoern A. Zeeb 16676b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_start(hw); 16686b4cac81SBjoern A. Zeeb if (error != 0) { 16696b4cac81SBjoern A. Zeeb printf("%s: failed to start hw: %d\n", __func__, error); 16706b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 16716b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 16726b4cac81SBjoern A. Zeeb return (NULL); 16736b4cac81SBjoern A. Zeeb } 16746b4cac81SBjoern A. Zeeb 16756b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_add_interface(hw, vif); 16766b4cac81SBjoern A. Zeeb if (error != 0) { 16776b4cac81SBjoern A. Zeeb IMPROVE(); /* XXX-BZ mo_stop()? */ 16786b4cac81SBjoern A. Zeeb printf("%s: failed to add interface: %d\n", __func__, error); 16796b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 16806b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 16816b4cac81SBjoern A. Zeeb return (NULL); 16826b4cac81SBjoern A. Zeeb } 16836b4cac81SBjoern A. Zeeb 16846b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 16856b4cac81SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lhw->lvif_head, lvif, lvif_entry); 16866b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 16876b4cac81SBjoern A. Zeeb 16886b4cac81SBjoern A. Zeeb /* Set bss_info. */ 16896b4cac81SBjoern A. Zeeb changed = 0; 16906b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 16916b4cac81SBjoern A. Zeeb 16926b4cac81SBjoern A. Zeeb /* conf_tx setup; default WME? */ 16936b4cac81SBjoern A. Zeeb 16946b4cac81SBjoern A. Zeeb /* Force MC init. */ 16956b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(ic, true); 16966b4cac81SBjoern A. Zeeb 16976b4cac81SBjoern A. Zeeb IMPROVE(); 16986b4cac81SBjoern A. Zeeb 16996b4cac81SBjoern A. Zeeb ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid); 17006b4cac81SBjoern A. Zeeb 17016b4cac81SBjoern A. Zeeb /* Override with LinuxKPI method so we can drive mac80211/cfg80211. */ 17026b4cac81SBjoern A. Zeeb lvif->iv_newstate = vap->iv_newstate; 17036b4cac81SBjoern A. Zeeb vap->iv_newstate = lkpi_iv_newstate; 17046b4cac81SBjoern A. Zeeb 17056b4cac81SBjoern A. Zeeb /* Key management. */ 17066b4cac81SBjoern A. Zeeb if (lhw->ops->set_key != NULL) { 17076b4cac81SBjoern A. Zeeb #ifdef TRY_HW_CRYPTO 17086b4cac81SBjoern A. Zeeb vap->iv_key_set = lkpi_iv_key_set; 17096b4cac81SBjoern A. Zeeb vap->iv_key_delete = lkpi_iv_key_delete; 17106b4cac81SBjoern A. Zeeb #endif 17116b4cac81SBjoern A. Zeeb } 17126b4cac81SBjoern A. Zeeb 17136b4cac81SBjoern A. Zeeb ieee80211_ratectl_init(vap); 17146b4cac81SBjoern A. Zeeb 17156b4cac81SBjoern A. Zeeb /* Complete setup. */ 17166b4cac81SBjoern A. Zeeb ieee80211_vap_attach(vap, ieee80211_media_change, 17176b4cac81SBjoern A. Zeeb ieee80211_media_status, mac); 17186b4cac81SBjoern A. Zeeb 17196b4cac81SBjoern A. Zeeb if (hw->max_listen_interval == 0) 17206b4cac81SBjoern A. Zeeb hw->max_listen_interval = 7 * (ic->ic_lintval / ic->ic_bintval); 17216b4cac81SBjoern A. Zeeb hw->conf.listen_interval = hw->max_listen_interval; 17226b4cac81SBjoern A. Zeeb ic->ic_set_channel(ic); 17236b4cac81SBjoern A. Zeeb 17246b4cac81SBjoern A. Zeeb /* XXX-BZ do we need to be able to update these? */ 17256b4cac81SBjoern A. Zeeb hw->wiphy->frag_threshold = vap->iv_fragthreshold; 17266b4cac81SBjoern A. Zeeb lkpi_80211_mo_set_frag_threshold(hw, vap->iv_fragthreshold); 17276b4cac81SBjoern A. Zeeb hw->wiphy->rts_threshold = vap->iv_rtsthreshold; 17286b4cac81SBjoern A. Zeeb lkpi_80211_mo_set_rts_threshold(hw, vap->iv_rtsthreshold); 17296b4cac81SBjoern A. Zeeb /* any others? */ 17306b4cac81SBjoern A. Zeeb IMPROVE(); 17316b4cac81SBjoern A. Zeeb 17326b4cac81SBjoern A. Zeeb return (vap); 17336b4cac81SBjoern A. Zeeb } 17346b4cac81SBjoern A. Zeeb 17356b4cac81SBjoern A. Zeeb static void 17366b4cac81SBjoern A. Zeeb lkpi_ic_vap_delete(struct ieee80211vap *vap) 17376b4cac81SBjoern A. Zeeb { 17386b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 17396b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 17406b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 17416b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 17426b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 17436b4cac81SBjoern A. Zeeb 17446b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 17456b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 17466b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 17476b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 17486b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 17496b4cac81SBjoern A. Zeeb 17506b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 17516b4cac81SBjoern A. Zeeb TAILQ_REMOVE(&lhw->lvif_head, lvif, lvif_entry); 17526b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 17536b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_interface(hw, vif); 17546b4cac81SBjoern A. Zeeb 17556b4cac81SBjoern A. Zeeb ieee80211_ratectl_deinit(vap); 17566b4cac81SBjoern A. Zeeb ieee80211_vap_detach(vap); 17576b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 17586b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 17596b4cac81SBjoern A. Zeeb } 17606b4cac81SBjoern A. Zeeb 17616b4cac81SBjoern A. Zeeb static void 17626b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast(struct ieee80211com *ic) 17636b4cac81SBjoern A. Zeeb { 17646b4cac81SBjoern A. Zeeb 17656b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(ic, false); 17666b4cac81SBjoern A. Zeeb TRACEOK(); 17676b4cac81SBjoern A. Zeeb } 17686b4cac81SBjoern A. Zeeb 17696b4cac81SBjoern A. Zeeb static void 17706b4cac81SBjoern A. Zeeb lkpi_ic_update_promisc(struct ieee80211com *ic) 17716b4cac81SBjoern A. Zeeb { 17726b4cac81SBjoern A. Zeeb 17736b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 17746b4cac81SBjoern A. Zeeb } 17756b4cac81SBjoern A. Zeeb 17766b4cac81SBjoern A. Zeeb static void 17776b4cac81SBjoern A. Zeeb lkpi_ic_update_chw(struct ieee80211com *ic) 17786b4cac81SBjoern A. Zeeb { 17796b4cac81SBjoern A. Zeeb 17806b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 17816b4cac81SBjoern A. Zeeb } 17826b4cac81SBjoern A. Zeeb 17836b4cac81SBjoern A. Zeeb /* Start / stop device. */ 17846b4cac81SBjoern A. Zeeb static void 17856b4cac81SBjoern A. Zeeb lkpi_ic_parent(struct ieee80211com *ic) 17866b4cac81SBjoern A. Zeeb { 17876b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 17886b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 17896b4cac81SBjoern A. Zeeb int error; 17906b4cac81SBjoern A. Zeeb bool start_all; 17916b4cac81SBjoern A. Zeeb 17926b4cac81SBjoern A. Zeeb IMPROVE(); 17936b4cac81SBjoern A. Zeeb 17946b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 17956b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 17966b4cac81SBjoern A. Zeeb start_all = false; 17976b4cac81SBjoern A. Zeeb 17986b4cac81SBjoern A. Zeeb if (ic->ic_nrunning > 0) { 17996b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_start(hw); 18006b4cac81SBjoern A. Zeeb if (error == 0) 18016b4cac81SBjoern A. Zeeb start_all = true; 18026b4cac81SBjoern A. Zeeb } else { 18036b4cac81SBjoern A. Zeeb lkpi_80211_mo_stop(hw); 18046b4cac81SBjoern A. Zeeb } 18056b4cac81SBjoern A. Zeeb 18066b4cac81SBjoern A. Zeeb if (start_all) 18076b4cac81SBjoern A. Zeeb ieee80211_start_all(ic); 18086b4cac81SBjoern A. Zeeb } 18096b4cac81SBjoern A. Zeeb 18106b4cac81SBjoern A. Zeeb bool 18116b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_is_ie_id_in_ie_buf(const u8 ie, const u8 *ie_ids, 18126b4cac81SBjoern A. Zeeb size_t ie_ids_len) 18136b4cac81SBjoern A. Zeeb { 18146b4cac81SBjoern A. Zeeb int i; 18156b4cac81SBjoern A. Zeeb 18166b4cac81SBjoern A. Zeeb for (i = 0; i < ie_ids_len; i++) { 18176b4cac81SBjoern A. Zeeb if (ie == *ie_ids) 18186b4cac81SBjoern A. Zeeb return (true); 18196b4cac81SBjoern A. Zeeb } 18206b4cac81SBjoern A. Zeeb 18216b4cac81SBjoern A. Zeeb return (false); 18226b4cac81SBjoern A. Zeeb } 18236b4cac81SBjoern A. Zeeb 18246b4cac81SBjoern A. Zeeb /* Return true if skipped; false if error. */ 18256b4cac81SBjoern A. Zeeb bool 18266b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ie_advance(size_t *xp, const u8 *ies, size_t ies_len) 18276b4cac81SBjoern A. Zeeb { 18286b4cac81SBjoern A. Zeeb size_t x; 18296b4cac81SBjoern A. Zeeb uint8_t l; 18306b4cac81SBjoern A. Zeeb 18316b4cac81SBjoern A. Zeeb x = *xp; 18326b4cac81SBjoern A. Zeeb 18336b4cac81SBjoern A. Zeeb KASSERT(x < ies_len, ("%s: x %zu ies_len %zu ies %p\n", 18346b4cac81SBjoern A. Zeeb __func__, x, ies_len, ies)); 18356b4cac81SBjoern A. Zeeb l = ies[x + 1]; 18366b4cac81SBjoern A. Zeeb x += 2 + l; 18376b4cac81SBjoern A. Zeeb 18386b4cac81SBjoern A. Zeeb if (x > ies_len) 18396b4cac81SBjoern A. Zeeb return (false); 18406b4cac81SBjoern A. Zeeb 18416b4cac81SBjoern A. Zeeb *xp = x; 18426b4cac81SBjoern A. Zeeb return (true); 18436b4cac81SBjoern A. Zeeb } 18446b4cac81SBjoern A. Zeeb 18456b4cac81SBjoern A. Zeeb static int 18466b4cac81SBjoern A. Zeeb lkpi_ieee80211_probereq_ie_alloc(struct ieee80211vap *vap, 18476b4cac81SBjoern A. Zeeb struct ieee80211com *ic, struct ieee80211_scan_ies *scan_ies, 18486b4cac81SBjoern A. Zeeb const uint8_t *ssid, size_t ssidlen) 18496b4cac81SBjoern A. Zeeb { 18506b4cac81SBjoern A. Zeeb 18516b4cac81SBjoern A. Zeeb return (ieee80211_probereq_ie(vap, ic, 18526b4cac81SBjoern A. Zeeb &scan_ies->common_ies, &scan_ies->common_ie_len, 18536b4cac81SBjoern A. Zeeb ssid, ssidlen, true)); 18546b4cac81SBjoern A. Zeeb } 18556b4cac81SBjoern A. Zeeb 18566b4cac81SBjoern A. Zeeb static void 18576b4cac81SBjoern A. Zeeb lkpi_ic_scan_start(struct ieee80211com *ic) 18586b4cac81SBjoern A. Zeeb { 18596b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 18606b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 18616b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 18626b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 18636b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 18646b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 18656b4cac81SBjoern A. Zeeb int error; 18666b4cac81SBjoern A. Zeeb 18676b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 18686b4cac81SBjoern A. Zeeb if ((lhw->scan_flags & LKPI_SCAN_RUNNING) != 0) { 18696b4cac81SBjoern A. Zeeb /* A scan is still running. */ 18706b4cac81SBjoern A. Zeeb return; 18716b4cac81SBjoern A. Zeeb } 18726b4cac81SBjoern A. Zeeb 18736b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 18746b4cac81SBjoern A. Zeeb vap = ss->ss_vap; 18756b4cac81SBjoern A. Zeeb if (vap->iv_state != IEEE80211_S_SCAN) { 18766b4cac81SBjoern A. Zeeb /* Do not start a scan for now. */ 18776b4cac81SBjoern A. Zeeb return; 18786b4cac81SBjoern A. Zeeb } 18796b4cac81SBjoern A. Zeeb 18806b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 18816b4cac81SBjoern A. Zeeb if ((ic->ic_flags_ext & IEEE80211_FEXT_SCAN_OFFLOAD) == 0) { 18826b4cac81SBjoern A. Zeeb 18836b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 18846b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 1885*086be6a8SBjoern A. Zeeb 1886*086be6a8SBjoern A. Zeeb if (vap->iv_state == IEEE80211_S_SCAN) 1887*086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, false); 1888*086be6a8SBjoern A. Zeeb 18896b4cac81SBjoern A. Zeeb lkpi_80211_mo_sw_scan_start(hw, vif, vif->addr); 18906b4cac81SBjoern A. Zeeb /* net80211::scan_start() handled PS for us. */ 18916b4cac81SBjoern A. Zeeb IMPROVE(); 18926b4cac81SBjoern A. Zeeb /* XXX Also means it is too late to flush queues? 18936b4cac81SBjoern A. Zeeb * need to check iv_sta_ps or overload? */ 18946b4cac81SBjoern A. Zeeb /* XXX want to adjust ss end time/ maxdwell? */ 18956b4cac81SBjoern A. Zeeb 18966b4cac81SBjoern A. Zeeb } else { 18976b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 18986b4cac81SBjoern A. Zeeb struct ieee80211_scan_request *hw_req; 18996b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *lc, **cpp; 19006b4cac81SBjoern A. Zeeb struct cfg80211_ssid *ssids; 19016b4cac81SBjoern A. Zeeb struct cfg80211_scan_6ghz_params *s6gp; 19026b4cac81SBjoern A. Zeeb size_t chan_len, nchan, ssids_len, s6ghzlen; 19036b4cac81SBjoern A. Zeeb int i; 19046b4cac81SBjoern A. Zeeb 19056b4cac81SBjoern A. Zeeb ssids_len = ss->ss_nssid * sizeof(*ssids);; 19066b4cac81SBjoern A. Zeeb s6ghzlen = 0 * (sizeof(*s6gp)); /* XXX-BZ */ 19076b4cac81SBjoern A. Zeeb 19086b4cac81SBjoern A. Zeeb nchan = 0; 19096b4cac81SBjoern A. Zeeb for (i = ss->ss_next; i < ss->ss_last; i++) 19106b4cac81SBjoern A. Zeeb nchan++; 19116b4cac81SBjoern A. Zeeb chan_len = nchan * (sizeof(lc) + sizeof(*lc)); 19126b4cac81SBjoern A. Zeeb 19136b4cac81SBjoern A. Zeeb KASSERT(lhw->hw_req == NULL, ("%s: ic %p lhw %p hw_req %p " 19146b4cac81SBjoern A. Zeeb "!= NULL\n", __func__, ic, lhw, lhw->hw_req)); 19156b4cac81SBjoern A. Zeeb lhw->hw_req = hw_req = malloc(sizeof(*hw_req) + ssids_len + 19166b4cac81SBjoern A. Zeeb s6ghzlen + chan_len, M_LKPI80211, M_WAITOK | M_ZERO); 19176b4cac81SBjoern A. Zeeb 19186b4cac81SBjoern A. Zeeb error = lkpi_ieee80211_probereq_ie_alloc(vap, ic, 19196b4cac81SBjoern A. Zeeb &hw_req->ies, NULL, -1); 19206b4cac81SBjoern A. Zeeb if (error != 0) 19216b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: probereq_ie returned %d\n", 19226b4cac81SBjoern A. Zeeb __func__, error); 19236b4cac81SBjoern A. Zeeb 19246b4cac81SBjoern A. Zeeb hw_req->req.flags = 0; /* XXX ??? */ 19256b4cac81SBjoern A. Zeeb /* hw_req->req.wdev */ 19266b4cac81SBjoern A. Zeeb hw_req->req.wiphy = hw->wiphy; 19276b4cac81SBjoern A. Zeeb hw_req->req.no_cck = false; /* XXX */ 19286b4cac81SBjoern A. Zeeb #if 0 19296b4cac81SBjoern A. Zeeb /* This seems to pessimise default scanning behaviour. */ 19306b4cac81SBjoern A. Zeeb hw_req->req.duration_mandatory = TICKS_2_USEC(ss->ss_mindwell); 19316b4cac81SBjoern A. Zeeb hw_req->req.duration = TICKS_2_USEC(ss->ss_maxdwell); 19326b4cac81SBjoern A. Zeeb #endif 19336b4cac81SBjoern A. Zeeb #ifdef __notyet__ 19346b4cac81SBjoern A. Zeeb hw_req->req.flags |= NL80211_SCAN_FLAG_RANDOM_ADDR; 19356b4cac81SBjoern A. Zeeb memcpy(hw_req->req.mac_addr, xxx, IEEE80211_ADDR_LEN); 19366b4cac81SBjoern A. Zeeb memset(hw_req->req.mac_addr_mask, 0xxx, IEEE80211_ADDR_LEN); 19376b4cac81SBjoern A. Zeeb #endif 19386b4cac81SBjoern A. Zeeb #if 0 19396b4cac81SBjoern A. Zeeb hw_req->req.ie_len = ; 19406b4cac81SBjoern A. Zeeb hw_req->req.ie = ; 19416b4cac81SBjoern A. Zeeb #endif 19426b4cac81SBjoern A. Zeeb 19436b4cac81SBjoern A. Zeeb hw_req->req.n_channels = nchan; 19446b4cac81SBjoern A. Zeeb cpp = (struct linuxkpi_ieee80211_channel **)(hw_req + 1); 19456b4cac81SBjoern A. Zeeb lc = (struct linuxkpi_ieee80211_channel *)(cpp + nchan); 19466b4cac81SBjoern A. Zeeb for (i = 0; i < nchan; i++) { 19476b4cac81SBjoern A. Zeeb *(cpp + i) = 19486b4cac81SBjoern A. Zeeb (struct linuxkpi_ieee80211_channel *)(lc + i); 19496b4cac81SBjoern A. Zeeb } 19506b4cac81SBjoern A. Zeeb for (i = 0; i < nchan; i++) { 19516b4cac81SBjoern A. Zeeb c = ss->ss_chans[ss->ss_next + i]; 19526b4cac81SBjoern A. Zeeb 19536b4cac81SBjoern A. Zeeb lc->hw_value = c->ic_ieee; 19546b4cac81SBjoern A. Zeeb lc->center_freq = c->ic_freq; 19556b4cac81SBjoern A. Zeeb /* lc->flags */ 19566b4cac81SBjoern A. Zeeb lc->band = lkpi_net80211_chan_to_nl80211_band(c); 19576b4cac81SBjoern A. Zeeb lc->max_power = c->ic_maxpower; 19586b4cac81SBjoern A. Zeeb /* lc-> ... */ 19596b4cac81SBjoern A. Zeeb lc++; 19606b4cac81SBjoern A. Zeeb } 19616b4cac81SBjoern A. Zeeb 19626b4cac81SBjoern A. Zeeb hw_req->req.n_ssids = ss->ss_nssid; 19636b4cac81SBjoern A. Zeeb if (hw_req->req.n_ssids > 0) { 19646b4cac81SBjoern A. Zeeb ssids = (struct cfg80211_ssid *)lc; 19656b4cac81SBjoern A. Zeeb hw_req->req.ssids = ssids; 19666b4cac81SBjoern A. Zeeb for (i = 0; i < ss->ss_nssid; i++) { 19676b4cac81SBjoern A. Zeeb ssids->ssid_len = ss->ss_ssid[i].len; 19686b4cac81SBjoern A. Zeeb memcpy(ssids->ssid, ss->ss_ssid[i].ssid, 19696b4cac81SBjoern A. Zeeb ss->ss_ssid[i].len); 19706b4cac81SBjoern A. Zeeb ssids++; 19716b4cac81SBjoern A. Zeeb } 19726b4cac81SBjoern A. Zeeb s6gp = (struct cfg80211_scan_6ghz_params *)ssids; 19736b4cac81SBjoern A. Zeeb } else { 19746b4cac81SBjoern A. Zeeb s6gp = (struct cfg80211_scan_6ghz_params *)lc; 19756b4cac81SBjoern A. Zeeb } 19766b4cac81SBjoern A. Zeeb 19776b4cac81SBjoern A. Zeeb /* 6GHz one day. */ 19786b4cac81SBjoern A. Zeeb hw_req->req.n_6ghz_params = 0; 19796b4cac81SBjoern A. Zeeb hw_req->req.scan_6ghz_params = NULL; 19806b4cac81SBjoern A. Zeeb hw_req->req.scan_6ghz = false; /* Weird boolean; not what you think. */ 19816b4cac81SBjoern A. Zeeb /* s6gp->... */ 19826b4cac81SBjoern A. Zeeb 19836b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 19846b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 19856b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_hw_scan(hw, vif, hw_req); 19866b4cac81SBjoern A. Zeeb if (error != 0) { 19876b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: hw_scan returned %d\n", 19886b4cac81SBjoern A. Zeeb __func__, error); 19896b4cac81SBjoern A. Zeeb ieee80211_cancel_scan(vap); 19906b4cac81SBjoern A. Zeeb free(hw_req->ies.common_ies, M_80211_VAP); 19916b4cac81SBjoern A. Zeeb free(hw_req, M_LKPI80211); 19926b4cac81SBjoern A. Zeeb lhw->hw_req = NULL; 19936b4cac81SBjoern A. Zeeb } 19946b4cac81SBjoern A. Zeeb } 19956b4cac81SBjoern A. Zeeb } 19966b4cac81SBjoern A. Zeeb 19976b4cac81SBjoern A. Zeeb static void 19986b4cac81SBjoern A. Zeeb lkpi_ic_scan_end(struct ieee80211com *ic) 19996b4cac81SBjoern A. Zeeb { 20006b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 20016b4cac81SBjoern A. Zeeb 20026b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 20036b4cac81SBjoern A. Zeeb if ((lhw->scan_flags & LKPI_SCAN_RUNNING) == 0) { 20046b4cac81SBjoern A. Zeeb return; 20056b4cac81SBjoern A. Zeeb } 20066b4cac81SBjoern A. Zeeb 20076b4cac81SBjoern A. Zeeb if (ic->ic_flags_ext & IEEE80211_FEXT_SCAN_OFFLOAD) { 20086b4cac81SBjoern A. Zeeb /* Nothing to do. */ 20096b4cac81SBjoern A. Zeeb } else { 20106b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 20116b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 20126b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 20136b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 20146b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 20156b4cac81SBjoern A. Zeeb 20166b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 20176b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 20186b4cac81SBjoern A. Zeeb vap = ss->ss_vap; 20196b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 20206b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 20216b4cac81SBjoern A. Zeeb lkpi_80211_mo_sw_scan_complete(hw, vif); 20226b4cac81SBjoern A. Zeeb 20236b4cac81SBjoern A. Zeeb /* Send PS to stop buffering if n80211 does not for us? */ 2024*086be6a8SBjoern A. Zeeb 2025*086be6a8SBjoern A. Zeeb if (vap->iv_state == IEEE80211_S_SCAN) 2026*086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true); 20276b4cac81SBjoern A. Zeeb } 20286b4cac81SBjoern A. Zeeb } 20296b4cac81SBjoern A. Zeeb 20306b4cac81SBjoern A. Zeeb static void 20316b4cac81SBjoern A. Zeeb lkpi_ic_scan_curchan_nada(struct ieee80211_scan_state *ss __unused, 20326b4cac81SBjoern A. Zeeb unsigned long maxdwell __unused) 20336b4cac81SBjoern A. Zeeb { 20346b4cac81SBjoern A. Zeeb } 20356b4cac81SBjoern A. Zeeb 20366b4cac81SBjoern A. Zeeb static void 20376b4cac81SBjoern A. Zeeb lkpi_ic_set_channel(struct ieee80211com *ic) 20386b4cac81SBjoern A. Zeeb { 20396b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 20406b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 20416b4cac81SBjoern A. Zeeb int error; 20426b4cac81SBjoern A. Zeeb 20436b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 20446b4cac81SBjoern A. Zeeb #ifdef __no_longer__ 20456b4cac81SBjoern A. Zeeb /* For now only be concerned if scanning. */ 20466b4cac81SBjoern A. Zeeb if ((lhw->scan_flags & LKPI_SCAN_RUNNING) == 0) { 20476b4cac81SBjoern A. Zeeb IMPROVE(); 20486b4cac81SBjoern A. Zeeb return; 20496b4cac81SBjoern A. Zeeb } 20506b4cac81SBjoern A. Zeeb #endif 20516b4cac81SBjoern A. Zeeb 20526b4cac81SBjoern A. Zeeb if (ic->ic_flags_ext & IEEE80211_FEXT_SCAN_OFFLOAD) { 20536b4cac81SBjoern A. Zeeb /* 20546b4cac81SBjoern A. Zeeb * AP scanning is taken care of by firmware, so only switch 20556b4cac81SBjoern A. Zeeb * channels in monitor mode (maybe, maybe not; to be 20566b4cac81SBjoern A. Zeeb * investigated at the right time). 20576b4cac81SBjoern A. Zeeb */ 20586b4cac81SBjoern A. Zeeb if (ic->ic_opmode == IEEE80211_M_MONITOR) { 20596b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 20606b4cac81SBjoern A. Zeeb } 20616b4cac81SBjoern A. Zeeb } else { 20626b4cac81SBjoern A. Zeeb struct ieee80211_channel *c = ic->ic_curchan; 20636b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 20646b4cac81SBjoern A. Zeeb struct cfg80211_chan_def chandef; 20656b4cac81SBjoern A. Zeeb 20666b4cac81SBjoern A. Zeeb if (c == NULL || c == IEEE80211_CHAN_ANYC || 20676b4cac81SBjoern A. Zeeb lhw->ops->config == NULL) { 20686b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: c %p ops->config %p\n", __func__, 20696b4cac81SBjoern A. Zeeb c, lhw->ops->config); 20706b4cac81SBjoern A. Zeeb return; 20716b4cac81SBjoern A. Zeeb } 20726b4cac81SBjoern A. Zeeb 20736b4cac81SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, c); 20746b4cac81SBjoern A. Zeeb if (chan == NULL) { 20756b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: c %p chan %p\n", __func__, 20766b4cac81SBjoern A. Zeeb c, chan); 20776b4cac81SBjoern A. Zeeb return; 20786b4cac81SBjoern A. Zeeb } 20796b4cac81SBjoern A. Zeeb 20806b4cac81SBjoern A. Zeeb memset(&chandef, 0, sizeof(chandef)); 20816b4cac81SBjoern A. Zeeb chandef.chan = chan; 20826b4cac81SBjoern A. Zeeb chandef.width = NL80211_CHAN_WIDTH_20_NOHT; 20836b4cac81SBjoern A. Zeeb chandef.center_freq1 = chandef.chan->center_freq; 20846b4cac81SBjoern A. Zeeb 20856b4cac81SBjoern A. Zeeb /* XXX max power for scanning? */ 20866b4cac81SBjoern A. Zeeb IMPROVE(); 20876b4cac81SBjoern A. Zeeb 20886b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 20896b4cac81SBjoern A. Zeeb hw->conf.chandef = chandef; 20906b4cac81SBjoern A. Zeeb 20916b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_CHANNEL); 20926b4cac81SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) { 20936b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: config %#0x returned %d\n", 20946b4cac81SBjoern A. Zeeb __func__, IEEE80211_CONF_CHANGE_CHANNEL, error); 20956b4cac81SBjoern A. Zeeb /* XXX should we unroll to the previous chandef? */ 20966b4cac81SBjoern A. Zeeb IMPROVE(); 20976b4cac81SBjoern A. Zeeb } else { 20986b4cac81SBjoern A. Zeeb /* Update radiotap channels as well. */ 20996b4cac81SBjoern A. Zeeb lhw->rtap_tx.wt_chan_freq = htole16(c->ic_freq); 21006b4cac81SBjoern A. Zeeb lhw->rtap_tx.wt_chan_flags = htole16(c->ic_flags); 21016b4cac81SBjoern A. Zeeb lhw->rtap_rx.wr_chan_freq = htole16(c->ic_freq); 21026b4cac81SBjoern A. Zeeb lhw->rtap_rx.wr_chan_flags = htole16(c->ic_flags); 21036b4cac81SBjoern A. Zeeb } 21046b4cac81SBjoern A. Zeeb 21056b4cac81SBjoern A. Zeeb /* Currently PS is hard coded off! Not sure it belongs here. */ 21066b4cac81SBjoern A. Zeeb IMPROVE(); 21076b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, SUPPORTS_PS) && 21086b4cac81SBjoern A. Zeeb (hw->conf.flags & IEEE80211_CONF_PS) != 0) { 21096b4cac81SBjoern A. Zeeb hw->conf.flags &= ~IEEE80211_CONF_PS; 21106b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_PS); 21116b4cac81SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) 21126b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: config %#0x returned " 21136b4cac81SBjoern A. Zeeb "%d\n", __func__, IEEE80211_CONF_CHANGE_PS, 21146b4cac81SBjoern A. Zeeb error); 21156b4cac81SBjoern A. Zeeb } 21166b4cac81SBjoern A. Zeeb } 21176b4cac81SBjoern A. Zeeb } 21186b4cac81SBjoern A. Zeeb 21196b4cac81SBjoern A. Zeeb static struct ieee80211_node * 21206b4cac81SBjoern A. Zeeb lkpi_ic_node_alloc(struct ieee80211vap *vap, 21216b4cac81SBjoern A. Zeeb const uint8_t mac[IEEE80211_ADDR_LEN]) 21226b4cac81SBjoern A. Zeeb { 21236b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 21246b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 21256b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 21266b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 21276b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 21286b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 21296b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 21306b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 21316b4cac81SBjoern A. Zeeb int tid; 21326b4cac81SBjoern A. Zeeb 21336b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 21346b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 21356b4cac81SBjoern A. Zeeb 21366b4cac81SBjoern A. Zeeb /* We keep allocations de-coupled so we can deal with the two worlds. */ 21376b4cac81SBjoern A. Zeeb if (lhw->ic_node_alloc != NULL) { 21386b4cac81SBjoern A. Zeeb ni = lhw->ic_node_alloc(vap, mac); 21396b4cac81SBjoern A. Zeeb if (ni == NULL) 21406b4cac81SBjoern A. Zeeb return (NULL); 21416b4cac81SBjoern A. Zeeb } 21426b4cac81SBjoern A. Zeeb 21436b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 21446b4cac81SBjoern A. Zeeb lsta = malloc(sizeof(*lsta) + hw->sta_data_size, M_LKPI80211, 21456b4cac81SBjoern A. Zeeb M_NOWAIT | M_ZERO); 21466b4cac81SBjoern A. Zeeb if (lsta == NULL) { 21476b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL) 21486b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni); 21496b4cac81SBjoern A. Zeeb return (NULL); 21506b4cac81SBjoern A. Zeeb } 21516b4cac81SBjoern A. Zeeb 21526b4cac81SBjoern A. Zeeb lsta->added_to_drv = false; 21536b4cac81SBjoern A. Zeeb lsta->state = IEEE80211_STA_NOTEXIST; 21546b4cac81SBjoern A. Zeeb #if 0 21556b4cac81SBjoern A. Zeeb /* 21566b4cac81SBjoern A. Zeeb * This needs to be done in node_init() as ieee80211_alloc_node() 21576b4cac81SBjoern A. Zeeb * will initialise the refcount after us. 21586b4cac81SBjoern A. Zeeb */ 21596b4cac81SBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 21606b4cac81SBjoern A. Zeeb #endif 21616b4cac81SBjoern A. Zeeb /* The back-pointer "drv_data" to net80211_node let's us get lsta. */ 21626b4cac81SBjoern A. Zeeb ni->ni_drv_data = lsta; 21636b4cac81SBjoern A. Zeeb 21646b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 21656b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 21666b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 21676b4cac81SBjoern A. Zeeb 21686b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->addr, mac); 21696b4cac81SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 21706b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 21716b4cac81SBjoern A. Zeeb 21726b4cac81SBjoern A. Zeeb /* 21736b4cac81SBjoern A. Zeeb * We are neither limiting ourselves to hw.queues here, 21746b4cac81SBjoern A. Zeeb * nor do we check if driver wants IEEE80211_NUM_TIDS queue. 21756b4cac81SBjoern A. Zeeb */ 21766b4cac81SBjoern A. Zeeb 21776b4cac81SBjoern A. Zeeb ltxq = malloc(sizeof(*ltxq) + hw->txq_data_size, 21786b4cac81SBjoern A. Zeeb M_LKPI80211, M_NOWAIT | M_ZERO); 21796b4cac81SBjoern A. Zeeb if (ltxq == NULL) 21806b4cac81SBjoern A. Zeeb goto cleanup; 21816b4cac81SBjoern A. Zeeb ltxq->seen_dequeue = false; 21826b4cac81SBjoern A. Zeeb skb_queue_head_init(<xq->skbq); 21836b4cac81SBjoern A. Zeeb /* iwlwifi//mvm/sta.c::tid_to_mac80211_ac[] */ 21846b4cac81SBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) { 21856b4cac81SBjoern A. Zeeb IMPROVE(); 21866b4cac81SBjoern A. Zeeb ltxq->txq.ac = IEEE80211_AC_VO; 21876b4cac81SBjoern A. Zeeb } else { 21886b4cac81SBjoern A. Zeeb ltxq->txq.ac = tid_to_mac80211_ac[tid & 7]; 21896b4cac81SBjoern A. Zeeb } 21906b4cac81SBjoern A. Zeeb ltxq->txq.tid = tid; 21916b4cac81SBjoern A. Zeeb ltxq->txq.sta = sta; 21926b4cac81SBjoern A. Zeeb ltxq->txq.vif = vif; 21936b4cac81SBjoern A. Zeeb sta->txq[tid] = <xq->txq; 21946b4cac81SBjoern A. Zeeb } 21956b4cac81SBjoern A. Zeeb 21966b4cac81SBjoern A. Zeeb /* Deferred TX path. */ 21976b4cac81SBjoern A. Zeeb mtx_init(&lsta->txq_mtx, "lsta_txq", NULL, MTX_DEF); 21986b4cac81SBjoern A. Zeeb TASK_INIT(&lsta->txq_task, 0, lkpi_80211_txq_task, lsta); 21996b4cac81SBjoern A. Zeeb mbufq_init(&lsta->txq, IFQ_MAXLEN); 22006b4cac81SBjoern A. Zeeb 22016b4cac81SBjoern A. Zeeb return (ni); 22026b4cac81SBjoern A. Zeeb 22036b4cac81SBjoern A. Zeeb cleanup: 22046b4cac81SBjoern A. Zeeb for (; tid >= 0; tid--) 22056b4cac81SBjoern A. Zeeb free(sta->txq[tid], M_LKPI80211); 22066b4cac81SBjoern A. Zeeb free(lsta, M_LKPI80211); 22076b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL) 22086b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni); 22096b4cac81SBjoern A. Zeeb return (NULL); 22106b4cac81SBjoern A. Zeeb } 22116b4cac81SBjoern A. Zeeb 22126b4cac81SBjoern A. Zeeb static int 22136b4cac81SBjoern A. Zeeb lkpi_ic_node_init(struct ieee80211_node *ni) 22146b4cac81SBjoern A. Zeeb { 22156b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 22166b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 22176b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 22186b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 22196b4cac81SBjoern A. Zeeb int error; 22206b4cac81SBjoern A. Zeeb 22216b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 22226b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 22236b4cac81SBjoern A. Zeeb 22246b4cac81SBjoern A. Zeeb if (lhw->ic_node_init != NULL) { 22256b4cac81SBjoern A. Zeeb error = lhw->ic_node_init(ni); 22266b4cac81SBjoern A. Zeeb if (error != 0) 22276b4cac81SBjoern A. Zeeb return (error); 22286b4cac81SBjoern A. Zeeb } 22296b4cac81SBjoern A. Zeeb 22306b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(ni->ni_vap); 22316b4cac81SBjoern A. Zeeb 22326b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 22336b4cac81SBjoern A. Zeeb 22346b4cac81SBjoern A. Zeeb /* Now take the reference before linking it to the table. */ 22356b4cac81SBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 22366b4cac81SBjoern A. Zeeb 22376b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 22386b4cac81SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lvif->lsta_head, lsta, lsta_entry); 22396b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 22406b4cac81SBjoern A. Zeeb 22416b4cac81SBjoern A. Zeeb /* XXX-BZ Sync other state over. */ 22426b4cac81SBjoern A. Zeeb IMPROVE(); 22436b4cac81SBjoern A. Zeeb 22446b4cac81SBjoern A. Zeeb return (0); 22456b4cac81SBjoern A. Zeeb } 22466b4cac81SBjoern A. Zeeb 22476b4cac81SBjoern A. Zeeb static void 22486b4cac81SBjoern A. Zeeb lkpi_ic_node_cleanup(struct ieee80211_node *ni) 22496b4cac81SBjoern A. Zeeb { 22506b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 22516b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 22526b4cac81SBjoern A. Zeeb 22536b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 22546b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 22556b4cac81SBjoern A. Zeeb 22566b4cac81SBjoern A. Zeeb /* XXX-BZ remove from driver, ... */ 22576b4cac81SBjoern A. Zeeb IMPROVE(); 22586b4cac81SBjoern A. Zeeb 22596b4cac81SBjoern A. Zeeb if (lhw->ic_node_cleanup != NULL) 22606b4cac81SBjoern A. Zeeb lhw->ic_node_cleanup(ni); 22616b4cac81SBjoern A. Zeeb } 22626b4cac81SBjoern A. Zeeb 22636b4cac81SBjoern A. Zeeb static void 22646b4cac81SBjoern A. Zeeb lkpi_ic_node_free(struct ieee80211_node *ni) 22656b4cac81SBjoern A. Zeeb { 22666b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 22676b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 22686b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 22696b4cac81SBjoern A. Zeeb 22706b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 22716b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 22726b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 22736b4cac81SBjoern A. Zeeb 22746b4cac81SBjoern A. Zeeb /* XXX-BZ free resources, ... */ 22756b4cac81SBjoern A. Zeeb IMPROVE(); 22766b4cac81SBjoern A. Zeeb 22776b4cac81SBjoern A. Zeeb /* Flush mbufq (make sure to release ni refs!). */ 22786b4cac81SBjoern A. Zeeb #ifdef __notyet__ 22796b4cac81SBjoern A. Zeeb KASSERT(mbufq_len(&lsta->txq) == 0, ("%s: lsta %p has txq len %d != 0\n", 22806b4cac81SBjoern A. Zeeb __func__, lsta, mbufq_len(&lsta->txq))); 22816b4cac81SBjoern A. Zeeb #endif 22826b4cac81SBjoern A. Zeeb /* Drain taskq. */ 22836b4cac81SBjoern A. Zeeb 22846b4cac81SBjoern A. Zeeb /* Drain sta->txq[] */ 22856b4cac81SBjoern A. Zeeb mtx_destroy(&lsta->txq_mtx); 22866b4cac81SBjoern A. Zeeb 22876b4cac81SBjoern A. Zeeb /* Remove lsta if added_to_drv. */ 22886b4cac81SBjoern A. Zeeb /* Remove lsta from vif */ 22896b4cac81SBjoern A. Zeeb 22906b4cac81SBjoern A. Zeeb /* remove ref from lsta node... */ 22916b4cac81SBjoern A. Zeeb 22926b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL) 22936b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni); 22946b4cac81SBjoern A. Zeeb 22956b4cac81SBjoern A. Zeeb /* Free lsta. */ 22966b4cac81SBjoern A. Zeeb } 22976b4cac81SBjoern A. Zeeb 22986b4cac81SBjoern A. Zeeb static int 22996b4cac81SBjoern A. Zeeb lkpi_ic_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, 23006b4cac81SBjoern A. Zeeb const struct ieee80211_bpf_params *params __unused) 23016b4cac81SBjoern A. Zeeb { 23026b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 23036b4cac81SBjoern A. Zeeb 23046b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 23056b4cac81SBjoern A. Zeeb 23066b4cac81SBjoern A. Zeeb /* Queue the packet and enqueue the task to handle it. */ 23076b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_LOCK(lsta); 23086b4cac81SBjoern A. Zeeb mbufq_enqueue(&lsta->txq, m); 23096b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_UNLOCK(lsta); 23106b4cac81SBjoern A. Zeeb 23116b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_TX) 23126b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p ni %p %6D mbuf_qlen %d\n", 23136b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, ni, ni->ni_macaddr, ":", 23146b4cac81SBjoern A. Zeeb mbufq_len(&lsta->txq)); 23156b4cac81SBjoern A. Zeeb 23166b4cac81SBjoern A. Zeeb taskqueue_enqueue(taskqueue_thread, &lsta->txq_task); 23176b4cac81SBjoern A. Zeeb return (0); 23186b4cac81SBjoern A. Zeeb } 23196b4cac81SBjoern A. Zeeb 23206b4cac81SBjoern A. Zeeb static void 23216b4cac81SBjoern A. Zeeb lkpi_80211_txq_tx_one(struct lkpi_sta *lsta, struct mbuf *m) 23226b4cac81SBjoern A. Zeeb { 23236b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 23246b4cac81SBjoern A. Zeeb struct ieee80211_frame *wh; 23256b4cac81SBjoern A. Zeeb struct ieee80211_key *k; 23266b4cac81SBjoern A. Zeeb struct sk_buff *skb; 23276b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 23286b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 23296b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 23306b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 23316b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 23326b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 23336b4cac81SBjoern A. Zeeb struct ieee80211_tx_control control; 23346b4cac81SBjoern A. Zeeb struct ieee80211_tx_info *info; 23356b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 23366b4cac81SBjoern A. Zeeb void *buf; 23376b4cac81SBjoern A. Zeeb int ac; 23386b4cac81SBjoern A. Zeeb 23396b4cac81SBjoern A. Zeeb M_ASSERTPKTHDR(m); 23406b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 23416b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_TX_DUMP) 23426b4cac81SBjoern A. Zeeb hexdump(mtod(m, const void *), m->m_len, "RAW TX (plain) ", 0); 23436b4cac81SBjoern A. Zeeb #endif 23446b4cac81SBjoern A. Zeeb 23456b4cac81SBjoern A. Zeeb ni = lsta->ni; 23466b4cac81SBjoern A. Zeeb #ifndef TRY_HW_CRYPTO 23476b4cac81SBjoern A. Zeeb /* Encrypt the frame if need be; XXX-BZ info->control.hw_key. */ 23486b4cac81SBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame *); 23496b4cac81SBjoern A. Zeeb if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { 23506b4cac81SBjoern A. Zeeb /* Retrieve key for TX && do software encryption. */ 23516b4cac81SBjoern A. Zeeb k = ieee80211_crypto_encap(ni, m); 23526b4cac81SBjoern A. Zeeb if (k == NULL) { 23536b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 23546b4cac81SBjoern A. Zeeb m_freem(m); 23556b4cac81SBjoern A. Zeeb return; 23566b4cac81SBjoern A. Zeeb } 23576b4cac81SBjoern A. Zeeb } 23586b4cac81SBjoern A. Zeeb #endif 23596b4cac81SBjoern A. Zeeb 23606b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 23616b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 23626b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 23636b4cac81SBjoern A. Zeeb c = ni->ni_chan; 23646b4cac81SBjoern A. Zeeb 23656b4cac81SBjoern A. Zeeb if (ieee80211_radiotap_active_vap(ni->ni_vap)) { 23666b4cac81SBjoern A. Zeeb struct lkpi_radiotap_tx_hdr *rtap; 23676b4cac81SBjoern A. Zeeb 23686b4cac81SBjoern A. Zeeb rtap = &lhw->rtap_tx; 23696b4cac81SBjoern A. Zeeb rtap->wt_flags = 0; 23706b4cac81SBjoern A. Zeeb if (k != NULL) 23716b4cac81SBjoern A. Zeeb rtap->wt_flags |= IEEE80211_RADIOTAP_F_WEP; 23726b4cac81SBjoern A. Zeeb if (m->m_flags & M_FRAG) 23736b4cac81SBjoern A. Zeeb rtap->wt_flags |= IEEE80211_RADIOTAP_F_FRAG; 23746b4cac81SBjoern A. Zeeb IMPROVE(); 23756b4cac81SBjoern A. Zeeb rtap->wt_rate = 0; 23766b4cac81SBjoern A. Zeeb if (c != NULL && c != IEEE80211_CHAN_ANYC) { 23776b4cac81SBjoern A. Zeeb rtap->wt_chan_freq = htole16(c->ic_freq); 23786b4cac81SBjoern A. Zeeb rtap->wt_chan_flags = htole16(c->ic_flags); 23796b4cac81SBjoern A. Zeeb } 23806b4cac81SBjoern A. Zeeb 23816b4cac81SBjoern A. Zeeb ieee80211_radiotap_tx(ni->ni_vap, m); 23826b4cac81SBjoern A. Zeeb } 23836b4cac81SBjoern A. Zeeb 23846b4cac81SBjoern A. Zeeb /* 23856b4cac81SBjoern A. Zeeb * net80211 should handle hw->extra_tx_headroom. 23866b4cac81SBjoern A. Zeeb * Though for as long as we are copying we don't mind. 23876b4cac81SBjoern A. Zeeb */ 23886b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + m->m_pkthdr.len); 23896b4cac81SBjoern A. Zeeb if (skb == NULL) { 23906b4cac81SBjoern A. Zeeb printf("XXX ERROR %s: skb alloc failed\n", __func__); 23916b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 23926b4cac81SBjoern A. Zeeb m_freem(m); 23936b4cac81SBjoern A. Zeeb return; 23946b4cac81SBjoern A. Zeeb } 23956b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 23966b4cac81SBjoern A. Zeeb 23976b4cac81SBjoern A. Zeeb /* XXX-BZ we need a SKB version understanding mbuf. */ 23986b4cac81SBjoern A. Zeeb /* Save the mbuf for ieee80211_tx_complete(). */ 23996b4cac81SBjoern A. Zeeb skb->m_free_func = lkpi_ieee80211_free_skb_mbuf; 24006b4cac81SBjoern A. Zeeb skb->m = m; 24016b4cac81SBjoern A. Zeeb #if 0 24026b4cac81SBjoern A. Zeeb skb_put_data(skb, m->m_data, m->m_pkthdr.len); 24036b4cac81SBjoern A. Zeeb #else 24046b4cac81SBjoern A. Zeeb buf = skb_put(skb, m->m_pkthdr.len); 24056b4cac81SBjoern A. Zeeb m_copydata(m, 0, m->m_pkthdr.len, buf); 24066b4cac81SBjoern A. Zeeb #endif 24076b4cac81SBjoern A. Zeeb /* Save the ni. */ 24086b4cac81SBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = ni; 24096b4cac81SBjoern A. Zeeb 24106b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(ni->ni_vap); 24116b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 24126b4cac81SBjoern A. Zeeb 24136b4cac81SBjoern A. Zeeb /* XXX-BZ review this at some point [4] vs. [8] vs. [16](TID). */ 24146b4cac81SBjoern A. Zeeb ac = M_WME_GETAC(m); 24156b4cac81SBjoern A. Zeeb skb->priority = WME_AC_TO_TID(ac); 24166b4cac81SBjoern A. Zeeb ac = lkpi_ac_net_to_l80211(ac); 24176b4cac81SBjoern A. Zeeb skb_set_queue_mapping(skb, ac); 24186b4cac81SBjoern A. Zeeb 24196b4cac81SBjoern A. Zeeb info = IEEE80211_SKB_CB(skb); 24206b4cac81SBjoern A. Zeeb info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; 24216b4cac81SBjoern A. Zeeb /* Slight delay; probably only happens on scanning so fine? */ 24226b4cac81SBjoern A. Zeeb if (c == NULL || c == IEEE80211_CHAN_ANYC) 24236b4cac81SBjoern A. Zeeb c = ic->ic_curchan; 24246b4cac81SBjoern A. Zeeb info->band = lkpi_net80211_chan_to_nl80211_band(c); 24256b4cac81SBjoern A. Zeeb info->hw_queue = ac; /* XXX-BZ is this correct? */ 24266b4cac81SBjoern A. Zeeb if (m->m_flags & M_EAPOL) 24276b4cac81SBjoern A. Zeeb info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO; 24286b4cac81SBjoern A. Zeeb info->control.vif = vif; 24296b4cac81SBjoern A. Zeeb /* XXX-BZ info->control.rates */ 24306b4cac81SBjoern A. Zeeb 24316b4cac81SBjoern A. Zeeb lsta = lkpi_find_lsta_by_ni(lvif, ni); 24326b4cac81SBjoern A. Zeeb if (lsta != NULL) { 24336b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 24346b4cac81SBjoern A. Zeeb #ifdef TRY_HW_CRYPTO 24356b4cac81SBjoern A. Zeeb info->control.hw_key = lsta->kc; 24366b4cac81SBjoern A. Zeeb #endif 24376b4cac81SBjoern A. Zeeb } else { 24386b4cac81SBjoern A. Zeeb sta = NULL; 24396b4cac81SBjoern A. Zeeb } 24406b4cac81SBjoern A. Zeeb 24416b4cac81SBjoern A. Zeeb IMPROVE(); 24426b4cac81SBjoern A. Zeeb 24436b4cac81SBjoern A. Zeeb if (sta != NULL) { 24446b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 24456b4cac81SBjoern A. Zeeb 24466b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[ac]); /* XXX-BZ re-check */ 24476b4cac81SBjoern A. Zeeb /* 24486b4cac81SBjoern A. Zeeb * We currently do not use queues but do direct TX. 24496b4cac81SBjoern A. Zeeb * The exception to the rule is initial packets, as we cannot 24506b4cac81SBjoern A. Zeeb * TX until queues are allocated (at least for iwlwifi). 24516b4cac81SBjoern A. Zeeb * So we wake_tx_queue in newstate and register any dequeue 24526b4cac81SBjoern A. Zeeb * calls. In the time until then we queue packets and 24536b4cac81SBjoern A. Zeeb * let the driver deal with them. 24546b4cac81SBjoern A. Zeeb */ 24556b4cac81SBjoern A. Zeeb if (!ltxq->seen_dequeue) { 24566b4cac81SBjoern A. Zeeb 24576b4cac81SBjoern A. Zeeb /* Prevent an ordering problem, likely other issues. */ 24586b4cac81SBjoern A. Zeeb while (!skb_queue_empty(<xq->skbq)) { 24596b4cac81SBjoern A. Zeeb struct sk_buff *skb2; 24606b4cac81SBjoern A. Zeeb 24616b4cac81SBjoern A. Zeeb skb2 = skb_dequeue(<xq->skbq); 24626b4cac81SBjoern A. Zeeb if (skb2 != NULL) { 24636b4cac81SBjoern A. Zeeb memset(&control, 0, sizeof(control)); 24646b4cac81SBjoern A. Zeeb control.sta = sta; 24656b4cac81SBjoern A. Zeeb lkpi_80211_mo_tx(hw, &control, skb2); 24666b4cac81SBjoern A. Zeeb } 24676b4cac81SBjoern A. Zeeb } 24686b4cac81SBjoern A. Zeeb goto ops_tx; 24696b4cac81SBjoern A. Zeeb } 24706b4cac81SBjoern A. Zeeb if (0 && ltxq->seen_dequeue && skb_queue_empty(<xq->skbq)) 24716b4cac81SBjoern A. Zeeb goto ops_tx; 24726b4cac81SBjoern A. Zeeb 24736b4cac81SBjoern A. Zeeb skb_queue_tail(<xq->skbq, skb); 24746b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_TX) 24756b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p sta %p ni %p %6D skb %p lxtq %p " 24766b4cac81SBjoern A. Zeeb "qlen %u WAKE_TX_Q ac %d prio %u qmap %u\n", 24776b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, sta, ni, 24786b4cac81SBjoern A. Zeeb ni->ni_macaddr, ":", skb, ltxq, 24796b4cac81SBjoern A. Zeeb skb_queue_len(<xq->skbq), ac, 24806b4cac81SBjoern A. Zeeb skb->priority, skb->qmap); 24816b4cac81SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, sta->txq[ac]); /* XXX-BZ */ 24826b4cac81SBjoern A. Zeeb return; 24836b4cac81SBjoern A. Zeeb } 24846b4cac81SBjoern A. Zeeb 24856b4cac81SBjoern A. Zeeb ops_tx: 24866b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_TX) 24876b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p sta %p ni %p %6D skb %p TX ac %d prio %u qmap %u\n", 24886b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, sta, ni, ni->ni_macaddr, ":", 24896b4cac81SBjoern A. Zeeb skb, ac, skb->priority, skb->qmap); 24906b4cac81SBjoern A. Zeeb memset(&control, 0, sizeof(control)); 24916b4cac81SBjoern A. Zeeb control.sta = sta; 24926b4cac81SBjoern A. Zeeb 24936b4cac81SBjoern A. Zeeb lkpi_80211_mo_tx(hw, &control, skb); 24946b4cac81SBjoern A. Zeeb return; 24956b4cac81SBjoern A. Zeeb } 24966b4cac81SBjoern A. Zeeb 24976b4cac81SBjoern A. Zeeb static void 24986b4cac81SBjoern A. Zeeb lkpi_80211_txq_task(void *ctx, int pending) 24996b4cac81SBjoern A. Zeeb { 25006b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 25016b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 25026b4cac81SBjoern A. Zeeb struct mbufq mq; 25036b4cac81SBjoern A. Zeeb struct mbuf *m; 25046b4cac81SBjoern A. Zeeb 25056b4cac81SBjoern A. Zeeb lsta = ctx; 25066b4cac81SBjoern A. Zeeb ni = lsta->ni; 25076b4cac81SBjoern A. Zeeb 25086b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_TX) 25096b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p ni %p %6D pending %d mbuf_qlen %d\n", 25106b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, ni, ni->ni_macaddr, ":", 25116b4cac81SBjoern A. Zeeb pending, mbufq_len(&lsta->txq)); 25126b4cac81SBjoern A. Zeeb 25136b4cac81SBjoern A. Zeeb mbufq_init(&mq, IFQ_MAXLEN); 25146b4cac81SBjoern A. Zeeb 25156b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_LOCK(lsta); 25166b4cac81SBjoern A. Zeeb mbufq_concat(&mq, &lsta->txq); 25176b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_UNLOCK(lsta); 25186b4cac81SBjoern A. Zeeb 25196b4cac81SBjoern A. Zeeb m = mbufq_dequeue(&mq); 25206b4cac81SBjoern A. Zeeb while (m != NULL) { 25216b4cac81SBjoern A. Zeeb lkpi_80211_txq_tx_one(lsta, m); 25226b4cac81SBjoern A. Zeeb m = mbufq_dequeue(&mq); 25236b4cac81SBjoern A. Zeeb } 25246b4cac81SBjoern A. Zeeb } 25256b4cac81SBjoern A. Zeeb 25266b4cac81SBjoern A. Zeeb static int 25276b4cac81SBjoern A. Zeeb lkpi_ic_transmit(struct ieee80211com *ic, struct mbuf *m) 25286b4cac81SBjoern A. Zeeb { 25296b4cac81SBjoern A. Zeeb 25306b4cac81SBjoern A. Zeeb /* XXX TODO */ 25316b4cac81SBjoern A. Zeeb IMPROVE(); 25326b4cac81SBjoern A. Zeeb 25336b4cac81SBjoern A. Zeeb /* Quick and dirty cheating hack. */ 25346b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 25356b4cac81SBjoern A. Zeeb 25366b4cac81SBjoern A. Zeeb ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; 25376b4cac81SBjoern A. Zeeb return (lkpi_ic_raw_xmit(ni, m, NULL)); 25386b4cac81SBjoern A. Zeeb } 25396b4cac81SBjoern A. Zeeb 25406b4cac81SBjoern A. Zeeb static void 25416b4cac81SBjoern A. Zeeb lkpi_ic_getradiocaps(struct ieee80211com *ic, int maxchan, 25426b4cac81SBjoern A. Zeeb int *n, struct ieee80211_channel *c) 25436b4cac81SBjoern A. Zeeb { 25446b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 25456b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 25466b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 25476b4cac81SBjoern A. Zeeb uint8_t bands[IEEE80211_MODE_BYTES]; 25486b4cac81SBjoern A. Zeeb int chan_flags, error, i, nchans; 25496b4cac81SBjoern A. Zeeb 25506b4cac81SBjoern A. Zeeb /* Channels */ 25516b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 25526b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 25536b4cac81SBjoern A. Zeeb 25546b4cac81SBjoern A. Zeeb /* NL80211_BAND_2GHZ */ 25556b4cac81SBjoern A. Zeeb nchans = 0; 25566b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_2GHZ] != NULL) 25576b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[NL80211_BAND_2GHZ]->n_channels; 25586b4cac81SBjoern A. Zeeb if (nchans > 0) { 25596b4cac81SBjoern A. Zeeb memset(bands, 0, sizeof(bands)); 25606b4cac81SBjoern A. Zeeb chan_flags = 0; 25616b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11B); 25626b4cac81SBjoern A. Zeeb /* XXX-BZ unclear how to check for 11g. */ 25636b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11G); 25646b4cac81SBjoern A. Zeeb #ifdef __notyet__ 25656b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_2GHZ]->ht_cap.ht_supported) { 25666b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11NG); 25676b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_HT40; 25686b4cac81SBjoern A. Zeeb } 25696b4cac81SBjoern A. Zeeb #endif 25706b4cac81SBjoern A. Zeeb 25716b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[NL80211_BAND_2GHZ]->channels; 25726b4cac81SBjoern A. Zeeb for (i = 0; i < nchans; i++) { 25736b4cac81SBjoern A. Zeeb uint32_t nflags = 0; 25746b4cac81SBjoern A. Zeeb int cflags = chan_flags; 25756b4cac81SBjoern A. Zeeb 25766b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) { 25776b4cac81SBjoern A. Zeeb printf("%s: %s: Skipping disabled chan " 25786b4cac81SBjoern A. Zeeb "[%u/%u/%#x]\n", ic->ic_name, __func__, 25796b4cac81SBjoern A. Zeeb channels[i].hw_value, 25806b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags); 25816b4cac81SBjoern A. Zeeb continue; 25826b4cac81SBjoern A. Zeeb } 25836b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_IR) 25846b4cac81SBjoern A. Zeeb nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE); 25856b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_RADAR) 25866b4cac81SBjoern A. Zeeb nflags |= IEEE80211_CHAN_DFS; 25876b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ) 25886b4cac81SBjoern A. Zeeb cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80); 25896b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ) 25906b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_VHT80; 25916b4cac81SBjoern A. Zeeb /* XXX how to map the remaining enum ieee80211_channel_flags? */ 25926b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_HT40) 25936b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_HT40; 25946b4cac81SBjoern A. Zeeb 25956b4cac81SBjoern A. Zeeb error = ieee80211_add_channel_cbw(c, maxchan, n, 25966b4cac81SBjoern A. Zeeb channels[i].hw_value, channels[i].center_freq, 25976b4cac81SBjoern A. Zeeb channels[i].max_power, 25986b4cac81SBjoern A. Zeeb nflags, bands, chan_flags); 25996b4cac81SBjoern A. Zeeb if (error != 0) { 26006b4cac81SBjoern A. Zeeb printf("%s: %s: Adding chan %u/%u/%#x/%#x/%#x/%#x " 26016b4cac81SBjoern A. Zeeb "returned error %d\n", ic->ic_name, 26026b4cac81SBjoern A. Zeeb __func__, channels[i].hw_value, 26036b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags, 26046b4cac81SBjoern A. Zeeb nflags, chan_flags, cflags, error); 26056b4cac81SBjoern A. Zeeb break; 26066b4cac81SBjoern A. Zeeb } 26076b4cac81SBjoern A. Zeeb } 26086b4cac81SBjoern A. Zeeb } 26096b4cac81SBjoern A. Zeeb 26106b4cac81SBjoern A. Zeeb /* NL80211_BAND_5GHZ */ 26116b4cac81SBjoern A. Zeeb nchans = 0; 26126b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ] != NULL) 26136b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[NL80211_BAND_5GHZ]->n_channels; 26146b4cac81SBjoern A. Zeeb if (nchans > 0) { 26156b4cac81SBjoern A. Zeeb memset(bands, 0, sizeof(bands)); 26166b4cac81SBjoern A. Zeeb chan_flags = 0; 26176b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11A); 26186b4cac81SBjoern A. Zeeb #ifdef __not_yet__ 26196b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ]->ht_cap.ht_supported) { 26206b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11NA); 26216b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_HT40; 26226b4cac81SBjoern A. Zeeb } 26236b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.vht_supported){ 26246b4cac81SBjoern A. Zeeb 26256b4cac81SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_VHT; 26266b4cac81SBjoern A. Zeeb ic->ic_vhtcaps = 26276b4cac81SBjoern A. Zeeb hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap; 26286b4cac81SBjoern A. Zeeb 26296b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_VHT_5GHZ); 26306b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT80; 26316b4cac81SBjoern A. Zeeb if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160MHZ( 26326b4cac81SBjoern A. Zeeb ic->ic_vhtcaps)) 26336b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT160; 26346b4cac81SBjoern A. Zeeb if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160_80P80MHZ( 26356b4cac81SBjoern A. Zeeb ic->ic_vhtcaps)) 26366b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT80P80; 26376b4cac81SBjoern A. Zeeb } 26386b4cac81SBjoern A. Zeeb #endif 26396b4cac81SBjoern A. Zeeb 26406b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[NL80211_BAND_5GHZ]->channels; 26416b4cac81SBjoern A. Zeeb for (i = 0; i < nchans; i++) { 26426b4cac81SBjoern A. Zeeb uint32_t nflags = 0; 26436b4cac81SBjoern A. Zeeb int cflags = chan_flags; 26446b4cac81SBjoern A. Zeeb 26456b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) { 26466b4cac81SBjoern A. Zeeb printf("%s: %s: Skipping disabled chan " 26476b4cac81SBjoern A. Zeeb "[%u/%u/%#x]\n", ic->ic_name, __func__, 26486b4cac81SBjoern A. Zeeb channels[i].hw_value, 26496b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags); 26506b4cac81SBjoern A. Zeeb continue; 26516b4cac81SBjoern A. Zeeb } 26526b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_IR) 26536b4cac81SBjoern A. Zeeb nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE); 26546b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_RADAR) 26556b4cac81SBjoern A. Zeeb nflags |= IEEE80211_CHAN_DFS; 26566b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ) 26576b4cac81SBjoern A. Zeeb cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80); 26586b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ) 26596b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_VHT80; 26606b4cac81SBjoern A. Zeeb /* XXX hwo to map the remaining enum ieee80211_channel_flags? */ 26616b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_HT40) 26626b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_HT40; 26636b4cac81SBjoern A. Zeeb 26646b4cac81SBjoern A. Zeeb error = ieee80211_add_channel_cbw(c, maxchan, n, 26656b4cac81SBjoern A. Zeeb channels[i].hw_value, channels[i].center_freq, 26666b4cac81SBjoern A. Zeeb channels[i].max_power, 26676b4cac81SBjoern A. Zeeb nflags, bands, chan_flags); 26686b4cac81SBjoern A. Zeeb if (error != 0) { 26696b4cac81SBjoern A. Zeeb printf("%s: %s: Adding chan %u/%u/%#x/%#x/%#x/%#x " 26706b4cac81SBjoern A. Zeeb "returned error %d\n", ic->ic_name, 26716b4cac81SBjoern A. Zeeb __func__, channels[i].hw_value, 26726b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags, 26736b4cac81SBjoern A. Zeeb nflags, chan_flags, cflags, error); 26746b4cac81SBjoern A. Zeeb break; 26756b4cac81SBjoern A. Zeeb } 26766b4cac81SBjoern A. Zeeb } 26776b4cac81SBjoern A. Zeeb } 26786b4cac81SBjoern A. Zeeb } 26796b4cac81SBjoern A. Zeeb 26806b4cac81SBjoern A. Zeeb static void * 26816b4cac81SBjoern A. Zeeb lkpi_ieee80211_ifalloc(void) 26826b4cac81SBjoern A. Zeeb { 26836b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 26846b4cac81SBjoern A. Zeeb 26856b4cac81SBjoern A. Zeeb ic = malloc(sizeof(*ic), M_LKPI80211, M_WAITOK | M_ZERO); 26866b4cac81SBjoern A. Zeeb if (ic == NULL) 26876b4cac81SBjoern A. Zeeb return (NULL); 26886b4cac81SBjoern A. Zeeb 26896b4cac81SBjoern A. Zeeb /* Setting these happens later when we have device information. */ 26906b4cac81SBjoern A. Zeeb ic->ic_softc = NULL; 26916b4cac81SBjoern A. Zeeb ic->ic_name = "linuxkpi"; 26926b4cac81SBjoern A. Zeeb 26936b4cac81SBjoern A. Zeeb return (ic); 26946b4cac81SBjoern A. Zeeb } 26956b4cac81SBjoern A. Zeeb 26966b4cac81SBjoern A. Zeeb struct ieee80211_hw * 26976b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_alloc_hw(size_t priv_len, const struct ieee80211_ops *ops) 26986b4cac81SBjoern A. Zeeb { 26996b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 27006b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 27016b4cac81SBjoern A. Zeeb struct wiphy *wiphy; 27026b4cac81SBjoern A. Zeeb 27036b4cac81SBjoern A. Zeeb /* Get us and the driver data also allocated. */ 27046b4cac81SBjoern A. Zeeb wiphy = wiphy_new(&linuxkpi_mac80211cfgops, sizeof(*lhw) + priv_len); 27056b4cac81SBjoern A. Zeeb if (wiphy == NULL) 27066b4cac81SBjoern A. Zeeb return (NULL); 27076b4cac81SBjoern A. Zeeb 27086b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 27096b4cac81SBjoern A. Zeeb lhw->ops = ops; 27106b4cac81SBjoern A. Zeeb lhw->workq = alloc_ordered_workqueue(wiphy_name(wiphy), 0); 27116b4cac81SBjoern A. Zeeb if (lhw->workq == NULL) { 27126b4cac81SBjoern A. Zeeb wiphy_free(wiphy); 27136b4cac81SBjoern A. Zeeb return (NULL); 27146b4cac81SBjoern A. Zeeb } 27156b4cac81SBjoern A. Zeeb mtx_init(&lhw->mtx, "lhw", NULL, MTX_DEF | MTX_RECURSE); 27166b4cac81SBjoern A. Zeeb TAILQ_INIT(&lhw->lvif_head); 27176b4cac81SBjoern A. Zeeb 27186b4cac81SBjoern A. Zeeb /* 27196b4cac81SBjoern A. Zeeb * XXX-BZ TODO make sure there is a "_null" function to all ops 27206b4cac81SBjoern A. Zeeb * not initialized. 27216b4cac81SBjoern A. Zeeb */ 27226b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 27236b4cac81SBjoern A. Zeeb hw->wiphy = wiphy; 2724*086be6a8SBjoern A. Zeeb hw->conf.flags |= IEEE80211_CONF_IDLE; 27256b4cac81SBjoern A. Zeeb hw->priv = (void *)(lhw + 1); 27266b4cac81SBjoern A. Zeeb 27276b4cac81SBjoern A. Zeeb /* BSD Specific. */ 27286b4cac81SBjoern A. Zeeb lhw->ic = lkpi_ieee80211_ifalloc(); 27296b4cac81SBjoern A. Zeeb if (lhw->ic == NULL) { 27306b4cac81SBjoern A. Zeeb ieee80211_free_hw(hw); 27316b4cac81SBjoern A. Zeeb return (NULL); 27326b4cac81SBjoern A. Zeeb } 27336b4cac81SBjoern A. Zeeb 27346b4cac81SBjoern A. Zeeb IMPROVE(); 27356b4cac81SBjoern A. Zeeb 27366b4cac81SBjoern A. Zeeb return (hw); 27376b4cac81SBjoern A. Zeeb } 27386b4cac81SBjoern A. Zeeb 27396b4cac81SBjoern A. Zeeb void 27406b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iffree(struct ieee80211_hw *hw) 27416b4cac81SBjoern A. Zeeb { 27426b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 27436b4cac81SBjoern A. Zeeb 27446b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 27456b4cac81SBjoern A. Zeeb free(lhw->ic, M_LKPI80211); 27466b4cac81SBjoern A. Zeeb lhw->ic = NULL; 27476b4cac81SBjoern A. Zeeb 27486b4cac81SBjoern A. Zeeb /* Cleanup more of lhw here or in wiphy_free()? */ 27496b4cac81SBjoern A. Zeeb mtx_destroy(&lhw->mtx); 27506b4cac81SBjoern A. Zeeb IMPROVE(); 27516b4cac81SBjoern A. Zeeb } 27526b4cac81SBjoern A. Zeeb 27536b4cac81SBjoern A. Zeeb void 27546b4cac81SBjoern A. Zeeb linuxkpi_set_ieee80211_dev(struct ieee80211_hw *hw, char *name) 27556b4cac81SBjoern A. Zeeb { 27566b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 27576b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 27586b4cac81SBjoern A. Zeeb 27596b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 27606b4cac81SBjoern A. Zeeb ic = lhw->ic; 27616b4cac81SBjoern A. Zeeb 27626b4cac81SBjoern A. Zeeb /* Now set a proper name before ieee80211_ifattach(). */ 27636b4cac81SBjoern A. Zeeb ic->ic_softc = lhw; 27646b4cac81SBjoern A. Zeeb ic->ic_name = name; 27656b4cac81SBjoern A. Zeeb 27666b4cac81SBjoern A. Zeeb /* XXX-BZ do we also need to set wiphy name? */ 27676b4cac81SBjoern A. Zeeb } 27686b4cac81SBjoern A. Zeeb 27696b4cac81SBjoern A. Zeeb struct ieee80211_hw * 27706b4cac81SBjoern A. Zeeb linuxkpi_wiphy_to_ieee80211_hw(struct wiphy *wiphy) 27716b4cac81SBjoern A. Zeeb { 27726b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 27736b4cac81SBjoern A. Zeeb 27746b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 27756b4cac81SBjoern A. Zeeb return (LHW_TO_HW(lhw)); 27766b4cac81SBjoern A. Zeeb } 27776b4cac81SBjoern A. Zeeb 27786b4cac81SBjoern A. Zeeb static void 27796b4cac81SBjoern A. Zeeb lkpi_radiotap_attach(struct lkpi_hw *lhw) 27806b4cac81SBjoern A. Zeeb { 27816b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 27826b4cac81SBjoern A. Zeeb 27836b4cac81SBjoern A. Zeeb ic = lhw->ic; 27846b4cac81SBjoern A. Zeeb ieee80211_radiotap_attach(ic, 27856b4cac81SBjoern A. Zeeb &lhw->rtap_tx.wt_ihdr, sizeof(lhw->rtap_tx), 27866b4cac81SBjoern A. Zeeb LKPI_RTAP_TX_FLAGS_PRESENT, 27876b4cac81SBjoern A. Zeeb &lhw->rtap_rx.wr_ihdr, sizeof(lhw->rtap_rx), 27886b4cac81SBjoern A. Zeeb LKPI_RTAP_RX_FLAGS_PRESENT); 27896b4cac81SBjoern A. Zeeb } 27906b4cac81SBjoern A. Zeeb 27916b4cac81SBjoern A. Zeeb void 27926b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ifattach(struct ieee80211_hw *hw) 27936b4cac81SBjoern A. Zeeb { 27946b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 27956b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 27966b4cac81SBjoern A. Zeeb #ifdef TRY_HW_CRYPTO 27976b4cac81SBjoern A. Zeeb int i; 27986b4cac81SBjoern A. Zeeb #endif 27996b4cac81SBjoern A. Zeeb 28006b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 28016b4cac81SBjoern A. Zeeb ic = lhw->ic; 28026b4cac81SBjoern A. Zeeb 28036b4cac81SBjoern A. Zeeb /* XXX-BZ figure this out how they count his... */ 28046b4cac81SBjoern A. Zeeb if (!is_zero_ether_addr(hw->wiphy->perm_addr)) { 28056b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(ic->ic_macaddr, 28066b4cac81SBjoern A. Zeeb hw->wiphy->perm_addr); 28076b4cac81SBjoern A. Zeeb } else if (hw->wiphy->n_addresses > 0) { 28086b4cac81SBjoern A. Zeeb /* We take the first one. */ 28096b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(ic->ic_macaddr, 28106b4cac81SBjoern A. Zeeb hw->wiphy->addresses[0].addr); 28116b4cac81SBjoern A. Zeeb } else { 28126b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: warning, no hardware address!\n", __func__); 28136b4cac81SBjoern A. Zeeb } 28146b4cac81SBjoern A. Zeeb 28156b4cac81SBjoern A. Zeeb ic->ic_headroom = hw->extra_tx_headroom; 28166b4cac81SBjoern A. Zeeb 28176b4cac81SBjoern A. Zeeb ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ 28186b4cac81SBjoern A. Zeeb ic->ic_opmode = IEEE80211_M_STA; 28196b4cac81SBjoern A. Zeeb 28206b4cac81SBjoern A. Zeeb /* Set device capabilities. */ 28216b4cac81SBjoern A. Zeeb /* XXX-BZ we need to get these from linux80211/drivers and convert. */ 28226b4cac81SBjoern A. Zeeb ic->ic_caps = 28236b4cac81SBjoern A. Zeeb IEEE80211_C_STA | 28246b4cac81SBjoern A. Zeeb IEEE80211_C_MONITOR | 28256b4cac81SBjoern A. Zeeb IEEE80211_C_WPA | /* WPA/RSN */ 28266b4cac81SBjoern A. Zeeb IEEE80211_C_WME | 28276b4cac81SBjoern A. Zeeb #if 0 28286b4cac81SBjoern A. Zeeb IEEE80211_C_PMGT | 28296b4cac81SBjoern A. Zeeb #endif 28306b4cac81SBjoern A. Zeeb IEEE80211_C_SHSLOT | /* short slot time supported */ 28316b4cac81SBjoern A. Zeeb IEEE80211_C_SHPREAMBLE /* short preamble supported */ 28326b4cac81SBjoern A. Zeeb ; 28336b4cac81SBjoern A. Zeeb #if 0 28346b4cac81SBjoern A. Zeeb /* Scanning is a different kind of beast to re-work. */ 28356b4cac81SBjoern A. Zeeb ic->ic_caps |= IEEE80211_C_BGSCAN; 28366b4cac81SBjoern A. Zeeb #endif 28376b4cac81SBjoern A. Zeeb if (lhw->ops->hw_scan && 28386b4cac81SBjoern A. Zeeb ieee80211_hw_check(hw, SINGLE_SCAN_ON_ALL_BANDS)) { 28396b4cac81SBjoern A. Zeeb /* Advertise full-offload scanning */ 28406b4cac81SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_SCAN_OFFLOAD; 28416b4cac81SBjoern A. Zeeb } 28426b4cac81SBjoern A. Zeeb 28436b4cac81SBjoern A. Zeeb #ifdef __notyet__ 28446b4cac81SBjoern A. Zeeb ic->ic_htcaps = IEEE80211_HTC_HT /* HT operation */ 28456b4cac81SBjoern A. Zeeb | IEEE80211_HTC_AMPDU /* A-MPDU tx/rx */ 28466b4cac81SBjoern A. Zeeb | IEEE80211_HTC_AMSDU /* A-MSDU tx/rx */ 28476b4cac81SBjoern A. Zeeb | IEEE80211_HTCAP_MAXAMSDU_3839 28486b4cac81SBjoern A. Zeeb /* max A-MSDU length */ 28496b4cac81SBjoern A. Zeeb | IEEE80211_HTCAP_SMPS_OFF; /* SM power save off */ 28506b4cac81SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_SHORTGI20; 28516b4cac81SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_CHWIDTH40 | IEEE80211_HTCAP_SHORTGI40; 28526b4cac81SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_TXSTBC; 28536b4cac81SBjoern A. Zeeb #endif 28546b4cac81SBjoern A. Zeeb 28556b4cac81SBjoern A. Zeeb ic->ic_cryptocaps = 0; 28566b4cac81SBjoern A. Zeeb #ifdef TRY_HW_CRYPTO 28576b4cac81SBjoern A. Zeeb if (hw->wiphy->n_cipher_suites > 0) { 28586b4cac81SBjoern A. Zeeb for (i = 0; i < hw->wiphy->n_cipher_suites; i++) 28596b4cac81SBjoern A. Zeeb ic->ic_cryptocaps |= lkpi_l80211_to_net80211_cyphers( 28606b4cac81SBjoern A. Zeeb hw->wiphy->cipher_suites[i]); 28616b4cac81SBjoern A. Zeeb } 28626b4cac81SBjoern A. Zeeb #endif 28636b4cac81SBjoern A. Zeeb 28646b4cac81SBjoern A. Zeeb lkpi_ic_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans, 28656b4cac81SBjoern A. Zeeb ic->ic_channels); 28666b4cac81SBjoern A. Zeeb 28676b4cac81SBjoern A. Zeeb ieee80211_ifattach(ic); 28686b4cac81SBjoern A. Zeeb 28696b4cac81SBjoern A. Zeeb ic->ic_update_mcast = lkpi_ic_update_mcast; 28706b4cac81SBjoern A. Zeeb ic->ic_update_promisc = lkpi_ic_update_promisc; 28716b4cac81SBjoern A. Zeeb ic->ic_update_chw = lkpi_ic_update_chw; 28726b4cac81SBjoern A. Zeeb ic->ic_parent = lkpi_ic_parent; 28736b4cac81SBjoern A. Zeeb ic->ic_scan_start = lkpi_ic_scan_start; 28746b4cac81SBjoern A. Zeeb ic->ic_scan_end = lkpi_ic_scan_end; 28756b4cac81SBjoern A. Zeeb if (lhw->ops->hw_scan && 28766b4cac81SBjoern A. Zeeb ieee80211_hw_check(hw, SINGLE_SCAN_ON_ALL_BANDS)) 28776b4cac81SBjoern A. Zeeb ic->ic_scan_curchan = lkpi_ic_scan_curchan_nada; 28786b4cac81SBjoern A. Zeeb ic->ic_set_channel = lkpi_ic_set_channel; 28796b4cac81SBjoern A. Zeeb ic->ic_transmit = lkpi_ic_transmit; 28806b4cac81SBjoern A. Zeeb ic->ic_raw_xmit = lkpi_ic_raw_xmit; 28816b4cac81SBjoern A. Zeeb ic->ic_vap_create = lkpi_ic_vap_create; 28826b4cac81SBjoern A. Zeeb ic->ic_vap_delete = lkpi_ic_vap_delete; 28836b4cac81SBjoern A. Zeeb ic->ic_getradiocaps = lkpi_ic_getradiocaps; 28846b4cac81SBjoern A. Zeeb ic->ic_wme.wme_update = lkpi_ic_wme_update; 28856b4cac81SBjoern A. Zeeb 28866b4cac81SBjoern A. Zeeb lhw->ic_node_alloc = ic->ic_node_alloc; 28876b4cac81SBjoern A. Zeeb ic->ic_node_alloc = lkpi_ic_node_alloc; 28886b4cac81SBjoern A. Zeeb lhw->ic_node_init = ic->ic_node_init; 28896b4cac81SBjoern A. Zeeb ic->ic_node_init = lkpi_ic_node_init; 28906b4cac81SBjoern A. Zeeb lhw->ic_node_cleanup = ic->ic_node_cleanup; 28916b4cac81SBjoern A. Zeeb ic->ic_node_cleanup = lkpi_ic_node_cleanup; 28926b4cac81SBjoern A. Zeeb lhw->ic_node_free = ic->ic_node_free; 28936b4cac81SBjoern A. Zeeb ic->ic_node_free = lkpi_ic_node_free; 28946b4cac81SBjoern A. Zeeb 28956b4cac81SBjoern A. Zeeb lkpi_radiotap_attach(lhw); 28966b4cac81SBjoern A. Zeeb 28976b4cac81SBjoern A. Zeeb if (bootverbose) 28986b4cac81SBjoern A. Zeeb ieee80211_announce(ic); 28996b4cac81SBjoern A. Zeeb } 29006b4cac81SBjoern A. Zeeb 29016b4cac81SBjoern A. Zeeb void 29026b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ifdetach(struct ieee80211_hw *hw) 29036b4cac81SBjoern A. Zeeb { 29046b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 29056b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 29066b4cac81SBjoern A. Zeeb 29076b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 29086b4cac81SBjoern A. Zeeb ic = lhw->ic; 29096b4cac81SBjoern A. Zeeb ieee80211_ifdetach(ic); 29106b4cac81SBjoern A. Zeeb } 29116b4cac81SBjoern A. Zeeb 29126b4cac81SBjoern A. Zeeb void 29136b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_interfaces(struct ieee80211_hw *hw, 29146b4cac81SBjoern A. Zeeb enum ieee80211_iface_iter flags, 29156b4cac81SBjoern A. Zeeb void(*iterfunc)(void *, uint8_t *, struct ieee80211_vif *), 29166b4cac81SBjoern A. Zeeb void *arg) 29176b4cac81SBjoern A. Zeeb { 29186b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 29196b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 29206b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 29216b4cac81SBjoern A. Zeeb bool active, atomic; 29226b4cac81SBjoern A. Zeeb 29236b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 29246b4cac81SBjoern A. Zeeb 29256b4cac81SBjoern A. Zeeb if (flags & ~(IEEE80211_IFACE_ITER_NORMAL| 29266b4cac81SBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL| 29276b4cac81SBjoern A. Zeeb IEEE80211_IFACE_ITER__ACTIVE|IEEE80211_IFACE_ITER__ATOMIC)) { 29286b4cac81SBjoern A. Zeeb ic_printf(lhw->ic, "XXX TODO %s flags(%#x) not yet supported.\n", 29296b4cac81SBjoern A. Zeeb __func__, flags); 29306b4cac81SBjoern A. Zeeb } 29316b4cac81SBjoern A. Zeeb 29326b4cac81SBjoern A. Zeeb active = (flags & IEEE80211_IFACE_ITER__ACTIVE) != 0; 29336b4cac81SBjoern A. Zeeb atomic = (flags & IEEE80211_IFACE_ITER__ATOMIC) != 0; 29346b4cac81SBjoern A. Zeeb 29356b4cac81SBjoern A. Zeeb if (atomic) 29366b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 29376b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 29386b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 29396b4cac81SBjoern A. Zeeb 29406b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 29416b4cac81SBjoern A. Zeeb 29426b4cac81SBjoern A. Zeeb /* 29436b4cac81SBjoern A. Zeeb * If we want "active" interfaces, we need to distinguish on 29446b4cac81SBjoern A. Zeeb * whether the driver knows about them or not to be able to 29456b4cac81SBjoern A. Zeeb * handle the "resume" case correctly. Skip the ones the 29466b4cac81SBjoern A. Zeeb * driver does not know about. 29476b4cac81SBjoern A. Zeeb */ 29486b4cac81SBjoern A. Zeeb if (active && !lvif->added_to_drv && 29496b4cac81SBjoern A. Zeeb (flags & IEEE80211_IFACE_ITER_RESUME_ALL) != 0) 29506b4cac81SBjoern A. Zeeb continue; 29516b4cac81SBjoern A. Zeeb 29526b4cac81SBjoern A. Zeeb /* 29536b4cac81SBjoern A. Zeeb * Run the iterator function if we are either not asking 29546b4cac81SBjoern A. Zeeb * asking for active only or if the VAP is "running". 29556b4cac81SBjoern A. Zeeb */ 29566b4cac81SBjoern A. Zeeb /* XXX-BZ probably should have state in the lvif as well. */ 29576b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 29586b4cac81SBjoern A. Zeeb if (!active || (vap->iv_state != IEEE80211_S_INIT)) 29596b4cac81SBjoern A. Zeeb iterfunc(arg, vif->addr, vif); 29606b4cac81SBjoern A. Zeeb } 29616b4cac81SBjoern A. Zeeb if (atomic) 29626b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 29636b4cac81SBjoern A. Zeeb } 29646b4cac81SBjoern A. Zeeb 29656b4cac81SBjoern A. Zeeb void 29666b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_keys(struct ieee80211_hw *hw, 29676b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif, 29686b4cac81SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_vif *, 29696b4cac81SBjoern A. Zeeb struct ieee80211_sta *, struct ieee80211_key_conf *, void *), 29706b4cac81SBjoern A. Zeeb void *arg) 29716b4cac81SBjoern A. Zeeb { 29726b4cac81SBjoern A. Zeeb 29736b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 29746b4cac81SBjoern A. Zeeb } 29756b4cac81SBjoern A. Zeeb 29766b4cac81SBjoern A. Zeeb void 29776b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_chan_contexts(struct ieee80211_hw *hw, 29786b4cac81SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_chanctx_conf *, 29796b4cac81SBjoern A. Zeeb void *), 29806b4cac81SBjoern A. Zeeb void *arg) 29816b4cac81SBjoern A. Zeeb { 29826b4cac81SBjoern A. Zeeb 29836b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 29846b4cac81SBjoern A. Zeeb } 29856b4cac81SBjoern A. Zeeb 29866b4cac81SBjoern A. Zeeb void 29876b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_stations_atomic(struct ieee80211_hw *hw, 29886b4cac81SBjoern A. Zeeb void (*iterfunc)(void *, struct ieee80211_sta *), void *arg) 29896b4cac81SBjoern A. Zeeb { 29906b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 29916b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 29926b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 29936b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 29946b4cac81SBjoern A. Zeeb 29956b4cac81SBjoern A. Zeeb KASSERT(hw != NULL && iterfunc != NULL, 29966b4cac81SBjoern A. Zeeb ("%s: hw %p iterfunc %p arg %p\n", __func__, hw, iterfunc, arg)); 29976b4cac81SBjoern A. Zeeb 29986b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 29996b4cac81SBjoern A. Zeeb 30006b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 30016b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 30026b4cac81SBjoern A. Zeeb 30036b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 30046b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lsta, &lvif->lsta_head, lsta_entry) { 30056b4cac81SBjoern A. Zeeb if (!lsta->added_to_drv) 30066b4cac81SBjoern A. Zeeb continue; 30076b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 30086b4cac81SBjoern A. Zeeb iterfunc(arg, sta); 30096b4cac81SBjoern A. Zeeb } 30106b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 30116b4cac81SBjoern A. Zeeb } 30126b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 30136b4cac81SBjoern A. Zeeb } 30146b4cac81SBjoern A. Zeeb 30156b4cac81SBjoern A. Zeeb int 30166b4cac81SBjoern A. Zeeb linuxkpi_regulatory_set_wiphy_regd_sync(struct wiphy *wiphy, 30176b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_regdomain *regd) 30186b4cac81SBjoern A. Zeeb { 30196b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 30206b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 30216b4cac81SBjoern A. Zeeb struct ieee80211_regdomain *rd; 30226b4cac81SBjoern A. Zeeb 30236b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 30246b4cac81SBjoern A. Zeeb ic = lhw->ic; 30256b4cac81SBjoern A. Zeeb 30266b4cac81SBjoern A. Zeeb rd = &ic->ic_regdomain; 30276b4cac81SBjoern A. Zeeb if (rd->isocc[0] == '\0') { 30286b4cac81SBjoern A. Zeeb rd->isocc[0] = regd->alpha2[0]; 30296b4cac81SBjoern A. Zeeb rd->isocc[1] = regd->alpha2[1]; 30306b4cac81SBjoern A. Zeeb } 30316b4cac81SBjoern A. Zeeb 30326b4cac81SBjoern A. Zeeb TODO(); 30336b4cac81SBjoern A. Zeeb /* XXX-BZ finish the rest. */ 30346b4cac81SBjoern A. Zeeb 30356b4cac81SBjoern A. Zeeb return (0); 30366b4cac81SBjoern A. Zeeb } 30376b4cac81SBjoern A. Zeeb 30386b4cac81SBjoern A. Zeeb void 30396b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_scan_completed(struct ieee80211_hw *hw, 30406b4cac81SBjoern A. Zeeb struct cfg80211_scan_info *info) 30416b4cac81SBjoern A. Zeeb { 30426b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 30436b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 30446b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 30456b4cac81SBjoern A. Zeeb 30466b4cac81SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 30476b4cac81SBjoern A. Zeeb ic = lhw->ic; 30486b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 30496b4cac81SBjoern A. Zeeb 30506b4cac81SBjoern A. Zeeb ieee80211_scan_done(ss->ss_vap); 30516b4cac81SBjoern A. Zeeb 30526b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 30536b4cac81SBjoern A. Zeeb free(lhw->hw_req->ies.common_ies, M_80211_VAP); 30546b4cac81SBjoern A. Zeeb free(lhw->hw_req, M_LKPI80211); 30556b4cac81SBjoern A. Zeeb lhw->hw_req = NULL; 30566b4cac81SBjoern A. Zeeb lhw->scan_flags &= ~LKPI_SCAN_RUNNING; 30576b4cac81SBjoern A. Zeeb wakeup(lhw); 30586b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 30596b4cac81SBjoern A. Zeeb 30606b4cac81SBjoern A. Zeeb return; 30616b4cac81SBjoern A. Zeeb } 30626b4cac81SBjoern A. Zeeb 30636b4cac81SBjoern A. Zeeb void 30646b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb, 30656b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta, struct napi_struct *napi __unused) 30666b4cac81SBjoern A. Zeeb { 30676b4cac81SBjoern A. Zeeb struct epoch_tracker et; 30686b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 30696b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 30706b4cac81SBjoern A. Zeeb struct mbuf *m; 30716b4cac81SBjoern A. Zeeb struct skb_shared_info *shinfo; 30726b4cac81SBjoern A. Zeeb struct ieee80211_rx_status *rx_status; 30736b4cac81SBjoern A. Zeeb struct ieee80211_rx_stats rx_stats; 30746b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 30756b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 30766b4cac81SBjoern A. Zeeb struct ieee80211_frame_min *wh; 30776b4cac81SBjoern A. Zeeb struct ieee80211_hdr *hdr; 30786b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 30796b4cac81SBjoern A. Zeeb int i, offset, ok, type; 30806b4cac81SBjoern A. Zeeb 30816b4cac81SBjoern A. Zeeb if (skb->len < 2) { 30826b4cac81SBjoern A. Zeeb /* Need 80211 stats here. */ 30836b4cac81SBjoern A. Zeeb IMPROVE(); 30846b4cac81SBjoern A. Zeeb goto err; 30856b4cac81SBjoern A. Zeeb } 30866b4cac81SBjoern A. Zeeb 30876b4cac81SBjoern A. Zeeb /* 30886b4cac81SBjoern A. Zeeb * For now do the data copy; we can later improve things. Might even 30896b4cac81SBjoern A. Zeeb * have an mbuf backing the skb data then? 30906b4cac81SBjoern A. Zeeb */ 30916b4cac81SBjoern A. Zeeb m = m_get2(skb->len, M_NOWAIT, MT_DATA, M_PKTHDR); 30926b4cac81SBjoern A. Zeeb if (m == NULL) 30936b4cac81SBjoern A. Zeeb goto err; 30946b4cac81SBjoern A. Zeeb m_copyback(m, 0, skb->tail - skb->data, skb->data); 30956b4cac81SBjoern A. Zeeb 30966b4cac81SBjoern A. Zeeb shinfo = skb_shinfo(skb); 30976b4cac81SBjoern A. Zeeb offset = m->m_len; 30986b4cac81SBjoern A. Zeeb for (i = 0; i < shinfo->nr_frags; i++) { 30996b4cac81SBjoern A. Zeeb m_copyback(m, offset, shinfo->frags[i].size, 31006b4cac81SBjoern A. Zeeb (uint8_t *)linux_page_address(shinfo->frags[i].page) + 31016b4cac81SBjoern A. Zeeb shinfo->frags[i].offset); 31026b4cac81SBjoern A. Zeeb offset += shinfo->frags[i].size; 31036b4cac81SBjoern A. Zeeb } 31046b4cac81SBjoern A. Zeeb 31056b4cac81SBjoern A. Zeeb rx_status = IEEE80211_SKB_RXCB(skb); 31066b4cac81SBjoern A. Zeeb 31076b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 31086b4cac81SBjoern A. Zeeb hdr = (void *)skb->data; 31096b4cac81SBjoern A. Zeeb if ((debug_80211 & D80211_TRACE_RX_BEACONS) == 0 && 31106b4cac81SBjoern A. Zeeb ieee80211_is_beacon(hdr->frame_control)) 31116b4cac81SBjoern A. Zeeb goto no_trace_beacons; 31126b4cac81SBjoern A. Zeeb 31136b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_RX) 31146b4cac81SBjoern A. Zeeb printf("TRACE-RX: %s: skb %p a/l/d/t-len (%u/%u/%u/%u) " 31156b4cac81SBjoern A. Zeeb "h %p d %p t %p e %p sh %p (%u) m %p plen %u len %u\n", 31166b4cac81SBjoern A. Zeeb __func__, skb, skb->_alloc_len, skb->len, skb->data_len, 31176b4cac81SBjoern A. Zeeb skb->truesize, skb->head, skb->data, skb->tail, skb->end, 31186b4cac81SBjoern A. Zeeb shinfo, shinfo->nr_frags, 31196b4cac81SBjoern A. Zeeb m, m->m_pkthdr.len, m->m_len); 31206b4cac81SBjoern A. Zeeb 31216b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_RX_DUMP) 31226b4cac81SBjoern A. Zeeb hexdump(mtod(m, const void *), m->m_len, "RX (raw) ", 0); 31236b4cac81SBjoern A. Zeeb 31246b4cac81SBjoern A. Zeeb /* Implement a dump_rxcb() !!! */ 31256b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_RX) 31266b4cac81SBjoern A. Zeeb printf("TRACE %s: RXCB: %u %u %u, %#0x, %u, %#0x, %#0x, " 31276b4cac81SBjoern A. Zeeb "%u band %u, %u %u %u %u, %u, %#x %#x %#x %#x %u %u %u\n", 31286b4cac81SBjoern A. Zeeb __func__, 31296b4cac81SBjoern A. Zeeb rx_status->boottime_ns, 31306b4cac81SBjoern A. Zeeb rx_status->mactime, 31316b4cac81SBjoern A. Zeeb rx_status->device_timestamp, 31326b4cac81SBjoern A. Zeeb rx_status->flag, 31336b4cac81SBjoern A. Zeeb rx_status->freq, 31346b4cac81SBjoern A. Zeeb rx_status->bw, 31356b4cac81SBjoern A. Zeeb rx_status->encoding, 31366b4cac81SBjoern A. Zeeb rx_status->ampdu_reference, 31376b4cac81SBjoern A. Zeeb rx_status->band, 31386b4cac81SBjoern A. Zeeb rx_status->chains, 31396b4cac81SBjoern A. Zeeb rx_status->chain_signal[0], 31406b4cac81SBjoern A. Zeeb rx_status->chain_signal[1], 31416b4cac81SBjoern A. Zeeb rx_status->chain_signal[2], 31426b4cac81SBjoern A. Zeeb rx_status->signal, 31436b4cac81SBjoern A. Zeeb rx_status->enc_flags, 31446b4cac81SBjoern A. Zeeb rx_status->he_dcm, 31456b4cac81SBjoern A. Zeeb rx_status->he_gi, 31466b4cac81SBjoern A. Zeeb rx_status->he_ru, 31476b4cac81SBjoern A. Zeeb rx_status->zero_length_psdu_type, 31486b4cac81SBjoern A. Zeeb rx_status->nss, 31496b4cac81SBjoern A. Zeeb rx_status->rate_idx); 31506b4cac81SBjoern A. Zeeb no_trace_beacons: 31516b4cac81SBjoern A. Zeeb #endif 31526b4cac81SBjoern A. Zeeb 31536b4cac81SBjoern A. Zeeb memset(&rx_stats, 0, sizeof(rx_stats)); 31546b4cac81SBjoern A. Zeeb rx_stats.r_flags = IEEE80211_R_NF | IEEE80211_R_RSSI; 31556b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, SIGNAL_DBM) && 31566b4cac81SBjoern A. Zeeb !(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL)) 31576b4cac81SBjoern A. Zeeb rx_stats.c_rssi = rx_status->signal; 31586b4cac81SBjoern A. Zeeb else 31596b4cac81SBjoern A. Zeeb rx_stats.c_rssi = 0; /* XXX */ 31606b4cac81SBjoern A. Zeeb rx_stats.c_nf = -96; /* XXX */ 31616b4cac81SBjoern A. Zeeb rx_stats.r_flags |= IEEE80211_R_BAND; 31626b4cac81SBjoern A. Zeeb rx_stats.c_band = 31636b4cac81SBjoern A. Zeeb lkpi_nl80211_band_to_net80211_band(rx_status->band); 31646b4cac81SBjoern A. Zeeb rx_stats.r_flags |= IEEE80211_R_FREQ | IEEE80211_R_IEEE; 31656b4cac81SBjoern A. Zeeb rx_stats.c_freq = rx_status->freq; 31666b4cac81SBjoern A. Zeeb rx_stats.c_ieee = ieee80211_mhz2ieee(rx_stats.c_freq, rx_stats.c_band); 31676b4cac81SBjoern A. Zeeb 31686b4cac81SBjoern A. Zeeb /* XXX-BZ correct hardcoded rssi and noise floor. */ 31696b4cac81SBjoern A. Zeeb /* XXX (*sta_statistics)() to get to some of that? */ 31706b4cac81SBjoern A. Zeeb /* XXX-BZ dump the FreeBSD version of rx_stats as well! */ 31716b4cac81SBjoern A. Zeeb 31726b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 31736b4cac81SBjoern A. Zeeb ic = lhw->ic; 31746b4cac81SBjoern A. Zeeb 31756b4cac81SBjoern A. Zeeb ok = ieee80211_add_rx_params(m, &rx_stats); 31766b4cac81SBjoern A. Zeeb if (ok == 0) { 31776b4cac81SBjoern A. Zeeb counter_u64_add(ic->ic_ierrors, 1); 31786b4cac81SBjoern A. Zeeb goto err; 31796b4cac81SBjoern A. Zeeb } 31806b4cac81SBjoern A. Zeeb 31816b4cac81SBjoern A. Zeeb if (sta != NULL) { 31826b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 31836b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(lsta->ni); 31846b4cac81SBjoern A. Zeeb } else { 31856b4cac81SBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame_min *); 31866b4cac81SBjoern A. Zeeb ni = ieee80211_find_rxnode(ic, wh); 31876b4cac81SBjoern A. Zeeb if (ni != NULL) 31886b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 31896b4cac81SBjoern A. Zeeb } 31906b4cac81SBjoern A. Zeeb 31916b4cac81SBjoern A. Zeeb if (ni != NULL) 31926b4cac81SBjoern A. Zeeb vap = ni->ni_vap; 31936b4cac81SBjoern A. Zeeb else 31946b4cac81SBjoern A. Zeeb /* 31956b4cac81SBjoern A. Zeeb * XXX-BZ can we improve this by looking at the frame hdr 31966b4cac81SBjoern A. Zeeb * or other meta-data passed up? 31976b4cac81SBjoern A. Zeeb */ 31986b4cac81SBjoern A. Zeeb vap = TAILQ_FIRST(&ic->ic_vaps); 31996b4cac81SBjoern A. Zeeb 32006b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_RX) 32016b4cac81SBjoern A. Zeeb printf("TRACE %s: sta %p lsta %p ni %p vap %p\n", __func__, sta, lsta, ni, vap); 32026b4cac81SBjoern A. Zeeb 32036b4cac81SBjoern A. Zeeb if (vap != NULL && vap->iv_state > IEEE80211_S_INIT && 32046b4cac81SBjoern A. Zeeb ieee80211_radiotap_active_vap(vap)) { 32056b4cac81SBjoern A. Zeeb struct lkpi_radiotap_rx_hdr *rtap; 32066b4cac81SBjoern A. Zeeb 32076b4cac81SBjoern A. Zeeb rtap = &lhw->rtap_rx; 32086b4cac81SBjoern A. Zeeb rtap->wr_tsft = rx_status->device_timestamp; 32096b4cac81SBjoern A. Zeeb rtap->wr_flags = 0; 32106b4cac81SBjoern A. Zeeb if (rx_status->enc_flags & RX_ENC_FLAG_SHORTPRE) 32116b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; 32126b4cac81SBjoern A. Zeeb if (rx_status->enc_flags & RX_ENC_FLAG_SHORT_GI) 32136b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTGI; 32146b4cac81SBjoern A. Zeeb #if 0 /* .. or it does not given we strip it below. */ 32156b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, RX_INCLUDES_FCS)) 32166b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_FCS; 32176b4cac81SBjoern A. Zeeb #endif 32186b4cac81SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_FAILED_FCS_CRC) 32196b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_BADFCS; 32206b4cac81SBjoern A. Zeeb rtap->wr_rate = 0; 32216b4cac81SBjoern A. Zeeb IMPROVE(); 32226b4cac81SBjoern A. Zeeb /* XXX TODO status->encoding / rate_index / bw */ 32236b4cac81SBjoern A. Zeeb rtap->wr_chan_freq = htole16(rx_stats.c_freq); 32246b4cac81SBjoern A. Zeeb if (ic->ic_curchan->ic_ieee == rx_stats.c_ieee) 32256b4cac81SBjoern A. Zeeb rtap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags); 32266b4cac81SBjoern A. Zeeb rtap->wr_dbm_antsignal = rx_stats.c_rssi; 32276b4cac81SBjoern A. Zeeb rtap->wr_dbm_antnoise = rx_stats.c_nf; 32286b4cac81SBjoern A. Zeeb } 32296b4cac81SBjoern A. Zeeb 32306b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, RX_INCLUDES_FCS)) 32316b4cac81SBjoern A. Zeeb m_adj(m, -IEEE80211_CRC_LEN); 32326b4cac81SBjoern A. Zeeb 32336b4cac81SBjoern A. Zeeb NET_EPOCH_ENTER(et); 32346b4cac81SBjoern A. Zeeb if (ni != NULL) { 32356b4cac81SBjoern A. Zeeb type = ieee80211_input_mimo(ni, m); 32366b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 32376b4cac81SBjoern A. Zeeb } else { 32386b4cac81SBjoern A. Zeeb type = ieee80211_input_mimo_all(ic, m); 32396b4cac81SBjoern A. Zeeb } 32406b4cac81SBjoern A. Zeeb NET_EPOCH_EXIT(et); 32416b4cac81SBjoern A. Zeeb 32426b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_RX) 32436b4cac81SBjoern A. Zeeb printf("TRACE %s: handled frame type %#0x\n", __func__, type); 32446b4cac81SBjoern A. Zeeb 32456b4cac81SBjoern A. Zeeb IMPROVE(); 32466b4cac81SBjoern A. Zeeb 32476b4cac81SBjoern A. Zeeb err: 32486b4cac81SBjoern A. Zeeb /* The skb is ours so we can free it :-) */ 32496b4cac81SBjoern A. Zeeb kfree_skb(skb); 32506b4cac81SBjoern A. Zeeb } 32516b4cac81SBjoern A. Zeeb 32526b4cac81SBjoern A. Zeeb uint8_t 32536b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_get_tid(struct ieee80211_hdr *hdr) 32546b4cac81SBjoern A. Zeeb { 32556b4cac81SBjoern A. Zeeb const struct ieee80211_frame *wh; 32566b4cac81SBjoern A. Zeeb 32576b4cac81SBjoern A. Zeeb wh = (const struct ieee80211_frame *)hdr; 32586b4cac81SBjoern A. Zeeb return (ieee80211_gettid(wh)); 32596b4cac81SBjoern A. Zeeb } 32606b4cac81SBjoern A. Zeeb 32616b4cac81SBjoern A. Zeeb struct wiphy * 32626b4cac81SBjoern A. Zeeb linuxkpi_wiphy_new(const struct cfg80211_ops *ops, size_t priv_len) 32636b4cac81SBjoern A. Zeeb { 32646b4cac81SBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 32656b4cac81SBjoern A. Zeeb 32666b4cac81SBjoern A. Zeeb lwiphy = kzalloc(sizeof(*lwiphy) + priv_len, GFP_KERNEL); 32676b4cac81SBjoern A. Zeeb if (lwiphy == NULL) 32686b4cac81SBjoern A. Zeeb return (NULL); 32696b4cac81SBjoern A. Zeeb lwiphy->ops = ops; 32706b4cac81SBjoern A. Zeeb 32716b4cac81SBjoern A. Zeeb /* XXX TODO */ 32726b4cac81SBjoern A. Zeeb return (LWIPHY_TO_WIPHY(lwiphy)); 32736b4cac81SBjoern A. Zeeb } 32746b4cac81SBjoern A. Zeeb 32756b4cac81SBjoern A. Zeeb void 32766b4cac81SBjoern A. Zeeb linuxkpi_wiphy_free(struct wiphy *wiphy) 32776b4cac81SBjoern A. Zeeb { 32786b4cac81SBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 32796b4cac81SBjoern A. Zeeb 32806b4cac81SBjoern A. Zeeb if (wiphy == NULL) 32816b4cac81SBjoern A. Zeeb return; 32826b4cac81SBjoern A. Zeeb 32836b4cac81SBjoern A. Zeeb lwiphy = WIPHY_TO_LWIPHY(wiphy); 32846b4cac81SBjoern A. Zeeb kfree(lwiphy); 32856b4cac81SBjoern A. Zeeb } 32866b4cac81SBjoern A. Zeeb 32876b4cac81SBjoern A. Zeeb uint32_t 32886b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_channel_to_frequency(uint32_t channel, 32896b4cac81SBjoern A. Zeeb enum nl80211_band band) 32906b4cac81SBjoern A. Zeeb { 32916b4cac81SBjoern A. Zeeb 32926b4cac81SBjoern A. Zeeb switch (band) { 32936b4cac81SBjoern A. Zeeb case NL80211_BAND_2GHZ: 32946b4cac81SBjoern A. Zeeb return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_2GHZ)); 32956b4cac81SBjoern A. Zeeb break; 32966b4cac81SBjoern A. Zeeb case NL80211_BAND_5GHZ: 32976b4cac81SBjoern A. Zeeb return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_5GHZ)); 32986b4cac81SBjoern A. Zeeb break; 32996b4cac81SBjoern A. Zeeb default: 33006b4cac81SBjoern A. Zeeb /* XXX abort, retry, error, panic? */ 33016b4cac81SBjoern A. Zeeb break; 33026b4cac81SBjoern A. Zeeb } 33036b4cac81SBjoern A. Zeeb 33046b4cac81SBjoern A. Zeeb return (0); 33056b4cac81SBjoern A. Zeeb } 33066b4cac81SBjoern A. Zeeb 33076b4cac81SBjoern A. Zeeb uint32_t 33086b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_frequency_to_channel(uint32_t freq, uint32_t flags __unused) 33096b4cac81SBjoern A. Zeeb { 33106b4cac81SBjoern A. Zeeb 33116b4cac81SBjoern A. Zeeb return (ieee80211_mhz2ieee(freq, 0)); 33126b4cac81SBjoern A. Zeeb } 33136b4cac81SBjoern A. Zeeb 33146b4cac81SBjoern A. Zeeb static struct lkpi_sta * 33156b4cac81SBjoern A. Zeeb lkpi_find_lsta_by_ni(struct lkpi_vif *lvif, struct ieee80211_node *ni) 33166b4cac81SBjoern A. Zeeb { 33176b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta, *temp; 33186b4cac81SBjoern A. Zeeb 33196b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 33206b4cac81SBjoern A. Zeeb TAILQ_FOREACH_SAFE(lsta, &lvif->lsta_head, lsta_entry, temp) { 33216b4cac81SBjoern A. Zeeb if (lsta->ni == ni) { 33226b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 33236b4cac81SBjoern A. Zeeb return (lsta); 33246b4cac81SBjoern A. Zeeb } 33256b4cac81SBjoern A. Zeeb } 33266b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 33276b4cac81SBjoern A. Zeeb 33286b4cac81SBjoern A. Zeeb return (NULL); 33296b4cac81SBjoern A. Zeeb } 33306b4cac81SBjoern A. Zeeb 33316b4cac81SBjoern A. Zeeb struct ieee80211_sta * 33326b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_find_sta(struct ieee80211_vif *vif, const u8 *peer) 33336b4cac81SBjoern A. Zeeb { 33346b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 33356b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta, *temp; 33366b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 33376b4cac81SBjoern A. Zeeb 33386b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 33396b4cac81SBjoern A. Zeeb 33406b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 33416b4cac81SBjoern A. Zeeb TAILQ_FOREACH_SAFE(lsta, &lvif->lsta_head, lsta_entry, temp) { 33426b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 33436b4cac81SBjoern A. Zeeb if (IEEE80211_ADDR_EQ(sta->addr, peer)) { 33446b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 33456b4cac81SBjoern A. Zeeb return (sta); 33466b4cac81SBjoern A. Zeeb } 33476b4cac81SBjoern A. Zeeb } 33486b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 33496b4cac81SBjoern A. Zeeb return (NULL); 33506b4cac81SBjoern A. Zeeb } 33516b4cac81SBjoern A. Zeeb 33526b4cac81SBjoern A. Zeeb struct ieee80211_sta * 33536b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw, uint8_t *addr, 33546b4cac81SBjoern A. Zeeb uint8_t *ourvifaddr) 33556b4cac81SBjoern A. Zeeb { 33566b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 33576b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 33586b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 33596b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 33606b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 33616b4cac81SBjoern A. Zeeb 33626b4cac81SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 33636b4cac81SBjoern A. Zeeb sta = NULL; 33646b4cac81SBjoern A. Zeeb 33656b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 33666b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 33676b4cac81SBjoern A. Zeeb 33686b4cac81SBjoern A. Zeeb /* XXX-BZ check our address from the vif. */ 33696b4cac81SBjoern A. Zeeb 33706b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 33716b4cac81SBjoern A. Zeeb if (ourvifaddr != NULL && 33726b4cac81SBjoern A. Zeeb !IEEE80211_ADDR_EQ(vif->addr, ourvifaddr)) 33736b4cac81SBjoern A. Zeeb continue; 33746b4cac81SBjoern A. Zeeb sta = linuxkpi_ieee80211_find_sta(vif, addr); 33756b4cac81SBjoern A. Zeeb if (sta != NULL) 33766b4cac81SBjoern A. Zeeb break; 33776b4cac81SBjoern A. Zeeb } 33786b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 33796b4cac81SBjoern A. Zeeb 33806b4cac81SBjoern A. Zeeb if (sta != NULL) { 33816b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 33826b4cac81SBjoern A. Zeeb if (!lsta->added_to_drv) 33836b4cac81SBjoern A. Zeeb return (NULL); 33846b4cac81SBjoern A. Zeeb } 33856b4cac81SBjoern A. Zeeb 33866b4cac81SBjoern A. Zeeb return (sta); 33876b4cac81SBjoern A. Zeeb } 33886b4cac81SBjoern A. Zeeb 33896b4cac81SBjoern A. Zeeb struct sk_buff * 33906b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_tx_dequeue(struct ieee80211_hw *hw, 33916b4cac81SBjoern A. Zeeb struct ieee80211_txq *txq) 33926b4cac81SBjoern A. Zeeb { 33936b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 33946b4cac81SBjoern A. Zeeb struct sk_buff *skb; 33956b4cac81SBjoern A. Zeeb 33966b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 33976b4cac81SBjoern A. Zeeb ltxq->seen_dequeue = true; 33986b4cac81SBjoern A. Zeeb 33996b4cac81SBjoern A. Zeeb skb = skb_dequeue(<xq->skbq); 34006b4cac81SBjoern A. Zeeb 34016b4cac81SBjoern A. Zeeb return (skb); 34026b4cac81SBjoern A. Zeeb } 34036b4cac81SBjoern A. Zeeb 34046b4cac81SBjoern A. Zeeb void 34056b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_txq_get_depth(struct ieee80211_txq *txq, 34066b4cac81SBjoern A. Zeeb uint64_t *frame_cnt, uint64_t *byte_cnt) 34076b4cac81SBjoern A. Zeeb { 34086b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 34096b4cac81SBjoern A. Zeeb struct sk_buff *skb; 34106b4cac81SBjoern A. Zeeb uint64_t fc, bc; 34116b4cac81SBjoern A. Zeeb 34126b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 34136b4cac81SBjoern A. Zeeb 34146b4cac81SBjoern A. Zeeb fc = bc = 0; 34156b4cac81SBjoern A. Zeeb skb_queue_walk(<xq->skbq, skb) { 34166b4cac81SBjoern A. Zeeb fc++; 34176b4cac81SBjoern A. Zeeb bc += skb->len; 34186b4cac81SBjoern A. Zeeb } 34196b4cac81SBjoern A. Zeeb if (frame_cnt) 34206b4cac81SBjoern A. Zeeb *frame_cnt = fc; 34216b4cac81SBjoern A. Zeeb if (byte_cnt) 34226b4cac81SBjoern A. Zeeb *byte_cnt = bc; 34236b4cac81SBjoern A. Zeeb 34246b4cac81SBjoern A. Zeeb /* Validate that this is doing the correct thing. */ 34256b4cac81SBjoern A. Zeeb /* Should we keep track on en/dequeue? */ 34266b4cac81SBjoern A. Zeeb IMPROVE(); 34276b4cac81SBjoern A. Zeeb } 34286b4cac81SBjoern A. Zeeb 34296b4cac81SBjoern A. Zeeb /* 34306b4cac81SBjoern A. Zeeb * We are called from ieee80211_free_txskb() or ieee80211_tx_status(). 34316b4cac81SBjoern A. Zeeb * The latter tries to derive the success status from the info flags 34326b4cac81SBjoern A. Zeeb * passed back from the driver. rawx_mit() saves the ni on the m and the 34336b4cac81SBjoern A. Zeeb * m on the skb for us to be able to give feedback to net80211. 34346b4cac81SBjoern A. Zeeb */ 34356b4cac81SBjoern A. Zeeb void 34366b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb, 34376b4cac81SBjoern A. Zeeb int status) 34386b4cac81SBjoern A. Zeeb { 34396b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 34406b4cac81SBjoern A. Zeeb struct mbuf *m; 34416b4cac81SBjoern A. Zeeb 34426b4cac81SBjoern A. Zeeb m = skb->m; 34436b4cac81SBjoern A. Zeeb skb->m = NULL; 34446b4cac81SBjoern A. Zeeb 34456b4cac81SBjoern A. Zeeb if (m != NULL) { 34466b4cac81SBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 34476b4cac81SBjoern A. Zeeb /* Status: 0 is ok, != 0 is error. */ 34486b4cac81SBjoern A. Zeeb ieee80211_tx_complete(ni, m, status); 34496b4cac81SBjoern A. Zeeb /* ni & mbuf were consumed. */ 34506b4cac81SBjoern A. Zeeb } 34516b4cac81SBjoern A. Zeeb 34526b4cac81SBjoern A. Zeeb kfree_skb(skb); 34536b4cac81SBjoern A. Zeeb } 34546b4cac81SBjoern A. Zeeb 34556b4cac81SBjoern A. Zeeb /* 34566b4cac81SBjoern A. Zeeb * This is an internal bandaid for the moment for the way we glue 34576b4cac81SBjoern A. Zeeb * skbs and mbufs together for TX. Once we have skbs backed by 34586b4cac81SBjoern A. Zeeb * mbufs this should go away. 34596b4cac81SBjoern A. Zeeb * This is a public function but kept on the private KPI (lkpi_) 34606b4cac81SBjoern A. Zeeb * and is not exposed by a header file. 34616b4cac81SBjoern A. Zeeb */ 34626b4cac81SBjoern A. Zeeb static void 34636b4cac81SBjoern A. Zeeb lkpi_ieee80211_free_skb_mbuf(void *p) 34646b4cac81SBjoern A. Zeeb { 34656b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 34666b4cac81SBjoern A. Zeeb struct mbuf *m; 34676b4cac81SBjoern A. Zeeb 34686b4cac81SBjoern A. Zeeb if (p == NULL) 34696b4cac81SBjoern A. Zeeb return; 34706b4cac81SBjoern A. Zeeb 34716b4cac81SBjoern A. Zeeb m = (struct mbuf *)p; 34726b4cac81SBjoern A. Zeeb M_ASSERTPKTHDR(m); 34736b4cac81SBjoern A. Zeeb 34746b4cac81SBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 34756b4cac81SBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = NULL; 34766b4cac81SBjoern A. Zeeb if (ni != NULL) 34776b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 34786b4cac81SBjoern A. Zeeb m_freem(m); 34796b4cac81SBjoern A. Zeeb } 34806b4cac81SBjoern A. Zeeb 34816b4cac81SBjoern A. Zeeb void 34826b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_queue_delayed_work(struct ieee80211_hw *hw, 34836b4cac81SBjoern A. Zeeb struct delayed_work *w, int delay) 34846b4cac81SBjoern A. Zeeb { 34856b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 34866b4cac81SBjoern A. Zeeb 34876b4cac81SBjoern A. Zeeb /* Need to make sure hw is in a stable (non-suspended) state. */ 34886b4cac81SBjoern A. Zeeb IMPROVE(); 34896b4cac81SBjoern A. Zeeb 34906b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 34916b4cac81SBjoern A. Zeeb queue_delayed_work(lhw->workq, w, delay); 34926b4cac81SBjoern A. Zeeb } 34936b4cac81SBjoern A. Zeeb 34946b4cac81SBjoern A. Zeeb void 34956b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_queue_work(struct ieee80211_hw *hw, 34966b4cac81SBjoern A. Zeeb struct work_struct *w) 34976b4cac81SBjoern A. Zeeb { 34986b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 34996b4cac81SBjoern A. Zeeb 35006b4cac81SBjoern A. Zeeb /* Need to make sure hw is in a stable (non-suspended) state. */ 35016b4cac81SBjoern A. Zeeb IMPROVE(); 35026b4cac81SBjoern A. Zeeb 35036b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 35046b4cac81SBjoern A. Zeeb queue_work(lhw->workq, w); 35056b4cac81SBjoern A. Zeeb } 35066b4cac81SBjoern A. Zeeb 35076b4cac81SBjoern A. Zeeb struct sk_buff * 35086b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_pspoll_get(struct ieee80211_hw *hw, 35096b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif) 35106b4cac81SBjoern A. Zeeb { 35116b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 35126b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 35136b4cac81SBjoern A. Zeeb struct sk_buff *skb; 35146b4cac81SBjoern A. Zeeb struct ieee80211_frame_pspoll *psp; 35156b4cac81SBjoern A. Zeeb uint16_t v; 35166b4cac81SBjoern A. Zeeb 35176b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*psp)); 35186b4cac81SBjoern A. Zeeb if (skb == NULL) 35196b4cac81SBjoern A. Zeeb return (NULL); 35206b4cac81SBjoern A. Zeeb 35216b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 35226b4cac81SBjoern A. Zeeb 35236b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 35246b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 35256b4cac81SBjoern A. Zeeb 35266b4cac81SBjoern A. Zeeb psp = skb_put_zero(skb, sizeof(*psp)); 35276b4cac81SBjoern A. Zeeb psp->i_fc[0] = IEEE80211_FC0_VERSION_0; 35286b4cac81SBjoern A. Zeeb psp->i_fc[0] |= IEEE80211_FC0_SUBTYPE_PS_POLL | IEEE80211_FC0_TYPE_CTL; 35296b4cac81SBjoern A. Zeeb v = htole16(vif->bss_conf.aid | 1<<15 | 1<<16); 35306b4cac81SBjoern A. Zeeb memcpy(&psp->i_aid, &v, sizeof(v)); 35316b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(psp->i_bssid, vap->iv_bss->ni_macaddr); 35326b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(psp->i_ta, vif->addr); 35336b4cac81SBjoern A. Zeeb 35346b4cac81SBjoern A. Zeeb return (skb); 35356b4cac81SBjoern A. Zeeb } 35366b4cac81SBjoern A. Zeeb 35376b4cac81SBjoern A. Zeeb struct sk_buff * 35386b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_nullfunc_get(struct ieee80211_hw *hw, 35396b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif, bool qos) 35406b4cac81SBjoern A. Zeeb { 35416b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 35426b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 35436b4cac81SBjoern A. Zeeb struct sk_buff *skb; 35446b4cac81SBjoern A. Zeeb struct ieee80211_frame *nullf; 35456b4cac81SBjoern A. Zeeb 35466b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*nullf)); 35476b4cac81SBjoern A. Zeeb if (skb == NULL) 35486b4cac81SBjoern A. Zeeb return (NULL); 35496b4cac81SBjoern A. Zeeb 35506b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 35516b4cac81SBjoern A. Zeeb 35526b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 35536b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 35546b4cac81SBjoern A. Zeeb 35556b4cac81SBjoern A. Zeeb nullf = skb_put_zero(skb, sizeof(*nullf)); 35566b4cac81SBjoern A. Zeeb nullf->i_fc[0] = IEEE80211_FC0_VERSION_0; 35576b4cac81SBjoern A. Zeeb nullf->i_fc[0] |= IEEE80211_FC0_SUBTYPE_NODATA | IEEE80211_FC0_TYPE_DATA; 35586b4cac81SBjoern A. Zeeb nullf->i_fc[1] = IEEE80211_FC1_DIR_TODS; 35596b4cac81SBjoern A. Zeeb 35606b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr1, vap->iv_bss->ni_bssid); 35616b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr2, vif->addr); 35626b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr3, vap->iv_bss->ni_macaddr); 35636b4cac81SBjoern A. Zeeb 35646b4cac81SBjoern A. Zeeb return (skb); 35656b4cac81SBjoern A. Zeeb } 35666b4cac81SBjoern A. Zeeb 35676b4cac81SBjoern A. Zeeb struct wireless_dev * 35686b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_vif_to_wdev(struct ieee80211_vif *vif) 35696b4cac81SBjoern A. Zeeb { 35706b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 35716b4cac81SBjoern A. Zeeb 35726b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 35736b4cac81SBjoern A. Zeeb return (&lvif->wdev); 35746b4cac81SBjoern A. Zeeb } 35756b4cac81SBjoern A. Zeeb 35766b4cac81SBjoern A. Zeeb void 35776b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_connection_loss(struct ieee80211_vif *vif) 35786b4cac81SBjoern A. Zeeb { 35796b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 35806b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 35816b4cac81SBjoern A. Zeeb enum ieee80211_state nstate; 35826b4cac81SBjoern A. Zeeb int arg; 35836b4cac81SBjoern A. Zeeb 35846b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 35856b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 35866b4cac81SBjoern A. Zeeb 35876b4cac81SBjoern A. Zeeb /* 35886b4cac81SBjoern A. Zeeb * Go to scan; otherwise we need to elaborately check state and 35896b4cac81SBjoern A. Zeeb * handle accordingly, e.g., if in RUN we could call iv_bmiss. 35906b4cac81SBjoern A. Zeeb * Let the statemachine handle all neccessary changes. 35916b4cac81SBjoern A. Zeeb */ 35926b4cac81SBjoern A. Zeeb nstate = IEEE80211_S_SCAN; 35936b4cac81SBjoern A. Zeeb arg = 0; 35946b4cac81SBjoern A. Zeeb 35956b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE) 35966b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: vif %p\n", __func__, vif); 35976b4cac81SBjoern A. Zeeb ieee80211_new_state(vap, nstate, arg); 35986b4cac81SBjoern A. Zeeb } 35996b4cac81SBjoern A. Zeeb 36006b4cac81SBjoern A. Zeeb MODULE_VERSION(linuxkpi_wlan, 1); 36016b4cac81SBjoern A. Zeeb MODULE_DEPEND(linuxkpi_wlan, linuxkpi, 1, 1, 1); 36026b4cac81SBjoern A. Zeeb MODULE_DEPEND(linuxkpi_wlan, wlan, 1, 1, 1); 3603