16b4cac81SBjoern A. Zeeb /*- 26b4cac81SBjoern A. Zeeb * Copyright (c) 2020-2021 The FreeBSD Foundation 3086be6a8SBjoern 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 576bec76628SBjoern A. Zeeb IEEE80211_UNLOCK(lhw->ic); 577bec76628SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 5786b4cac81SBjoern A. Zeeb /* Need to cancel the scan. */ 5796b4cac81SBjoern A. Zeeb lkpi_80211_mo_cancel_hw_scan(hw, vif); 5806b4cac81SBjoern A. Zeeb 5816b4cac81SBjoern A. Zeeb /* Need to make sure we see ieee80211_scan_completed. */ 5826b4cac81SBjoern A. Zeeb error = msleep(lhw, &lhw->mtx, 0, "lhwscanstop", hz/2); 583bec76628SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 584bec76628SBjoern A. Zeeb IEEE80211_LOCK(lhw->ic); 5856b4cac81SBjoern A. Zeeb 5866b4cac81SBjoern A. Zeeb if ((lhw->scan_flags & LKPI_SCAN_RUNNING) != 0) 5876b4cac81SBjoern A. Zeeb ic_printf(lhw->ic, "%s: failed to cancel scan: %d (%p, %p)\n", 5886b4cac81SBjoern A. Zeeb __func__, error, lhw, vif); 5896b4cac81SBjoern A. Zeeb } 5906b4cac81SBjoern A. Zeeb 5916b4cac81SBjoern A. Zeeb static void 592086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(struct ieee80211_hw *hw, bool new) 593086be6a8SBjoern A. Zeeb { 594086be6a8SBjoern A. Zeeb struct lkpi_hw *lhw; 595086be6a8SBjoern A. Zeeb int error; 596086be6a8SBjoern A. Zeeb bool old; 597086be6a8SBjoern A. Zeeb 598086be6a8SBjoern A. Zeeb old = hw->conf.flags & IEEE80211_CONF_IDLE; 599086be6a8SBjoern A. Zeeb if (old == new) 600086be6a8SBjoern A. Zeeb return; 601086be6a8SBjoern A. Zeeb 602086be6a8SBjoern A. Zeeb hw->conf.flags ^= IEEE80211_CONF_IDLE; 603086be6a8SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_IDLE); 604086be6a8SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) { 605086be6a8SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 606086be6a8SBjoern A. Zeeb ic_printf(lhw->ic, "ERROR: %s: config %#0x returned %d\n", 607086be6a8SBjoern A. Zeeb __func__, IEEE80211_CONF_CHANGE_IDLE, error); 608086be6a8SBjoern A. Zeeb } 609086be6a8SBjoern A. Zeeb } 610086be6a8SBjoern A. Zeeb 611086be6a8SBjoern A. Zeeb static void 6126b4cac81SBjoern A. Zeeb lkpi_disassoc(struct ieee80211_sta *sta, struct ieee80211_vif *vif, 6136b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw) 6146b4cac81SBjoern A. Zeeb { 6156b4cac81SBjoern A. Zeeb sta->aid = 0; 6166b4cac81SBjoern A. Zeeb if (vif->bss_conf.assoc) { 6176b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 6186b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 6196b4cac81SBjoern A. Zeeb 6206b4cac81SBjoern A. Zeeb lhw->update_mc = true; 6216b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(lhw->ic, true); 6226b4cac81SBjoern A. Zeeb 6236b4cac81SBjoern A. Zeeb changed = 0; 6246b4cac81SBjoern A. Zeeb vif->bss_conf.assoc = false; 6256b4cac81SBjoern A. Zeeb vif->bss_conf.aid = 0; 6266b4cac81SBjoern A. Zeeb changed |= BSS_CHANGED_ASSOC; 6276b4cac81SBjoern A. Zeeb IMPROVE(); 6286b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 6296b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, 6306b4cac81SBjoern A. Zeeb changed); 631086be6a8SBjoern A. Zeeb 632086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true); 6336b4cac81SBjoern A. Zeeb } 6346b4cac81SBjoern A. Zeeb } 6356b4cac81SBjoern A. Zeeb 6366b4cac81SBjoern A. Zeeb static void 6376b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(struct ieee80211_hw *hw, struct ieee80211_sta *sta, 6386b4cac81SBjoern A. Zeeb bool dequeue_seen, bool no_emptyq) 6396b4cac81SBjoern A. Zeeb { 6406b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 6416b4cac81SBjoern A. Zeeb int tid; 6426b4cac81SBjoern A. Zeeb 6436b4cac81SBjoern A. Zeeb /* Wake up all queues to know they are allocated in the driver. */ 6446b4cac81SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 6456b4cac81SBjoern A. Zeeb 6466b4cac81SBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) { 6476b4cac81SBjoern A. Zeeb IMPROVE("station specific?"); 6486b4cac81SBjoern A. Zeeb if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ)) 6496b4cac81SBjoern A. Zeeb continue; 6506b4cac81SBjoern A. Zeeb } else if (tid >= hw->queues) 6516b4cac81SBjoern A. Zeeb continue; 6526b4cac81SBjoern A. Zeeb 6536b4cac81SBjoern A. Zeeb if (sta->txq[tid] == NULL) 6546b4cac81SBjoern A. Zeeb continue; 6556b4cac81SBjoern A. Zeeb 6566b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]); 6576b4cac81SBjoern A. Zeeb if (dequeue_seen && !ltxq->seen_dequeue) 6586b4cac81SBjoern A. Zeeb continue; 6596b4cac81SBjoern A. Zeeb 6606b4cac81SBjoern A. Zeeb if (no_emptyq && skb_queue_empty(<xq->skbq)) 6616b4cac81SBjoern A. Zeeb continue; 6626b4cac81SBjoern A. Zeeb 6636b4cac81SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, sta->txq[tid]); 6646b4cac81SBjoern A. Zeeb } 6656b4cac81SBjoern A. Zeeb } 6666b4cac81SBjoern A. Zeeb 6676b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 6686b4cac81SBjoern A. Zeeb 6696b4cac81SBjoern A. Zeeb static int 6706b4cac81SBjoern A. Zeeb lkpi_sta_state_do_nada(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 6716b4cac81SBjoern A. Zeeb { 6726b4cac81SBjoern A. Zeeb 6736b4cac81SBjoern A. Zeeb return (0); 6746b4cac81SBjoern A. Zeeb } 6756b4cac81SBjoern A. Zeeb 6766b4cac81SBjoern A. Zeeb /* lkpi_iv_newstate() handles the stop scan case generally. */ 6776b4cac81SBjoern A. Zeeb #define lkpi_sta_scan_to_init(_v, _n, _a) lkpi_sta_state_do_nada(_v, _n, _a) 6786b4cac81SBjoern A. Zeeb 6796b4cac81SBjoern A. Zeeb static int 6806b4cac81SBjoern A. Zeeb lkpi_sta_scan_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 6816b4cac81SBjoern A. Zeeb { 6826b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 6836b4cac81SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 6846b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 6856b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 6866b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 6876b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 6886b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 6896b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 6906b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 6916b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 6926b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 6936b4cac81SBjoern A. Zeeb uint32_t changed; 6946b4cac81SBjoern A. Zeeb int error; 6956b4cac81SBjoern A. Zeeb 6966b4cac81SBjoern A. Zeeb chan = lkpi_get_lkpi80211_chan(vap->iv_ic, vap->iv_bss); 6976b4cac81SBjoern A. Zeeb if (chan == NULL) { 6986b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: failed to get channel\n", __func__); 6996b4cac81SBjoern A. Zeeb return (ESRCH); 7006b4cac81SBjoern A. Zeeb } 7016b4cac81SBjoern A. Zeeb 7026b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 7036b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 7046b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 7056b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 7066b4cac81SBjoern A. Zeeb 7076b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 7086b4cac81SBjoern A. Zeeb 7096b4cac81SBjoern A. Zeeb /* Add chanctx (or if exists, change it). */ 7106b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 7116b4cac81SBjoern A. Zeeb conf = vif->chanctx_conf; 7126b4cac81SBjoern A. Zeeb IMPROVE("diff changes for changed, working on live copy, rcu"); 7136b4cac81SBjoern A. Zeeb } else { 7146b4cac81SBjoern A. Zeeb /* Keep separate alloc as in Linux this is rcu managed? */ 7156b4cac81SBjoern A. Zeeb conf = malloc(sizeof(*conf) + hw->chanctx_data_size, 7166b4cac81SBjoern A. Zeeb M_LKPI80211, M_WAITOK | M_ZERO); 7176b4cac81SBjoern A. Zeeb } 7186b4cac81SBjoern A. Zeeb 7196b4cac81SBjoern A. Zeeb conf->rx_chains_dynamic = 1; 7206b4cac81SBjoern A. Zeeb conf->rx_chains_static = 1; 7216b4cac81SBjoern A. Zeeb conf->radar_enabled = 7226b4cac81SBjoern A. Zeeb (chan->flags & IEEE80211_CHAN_RADAR) ? true : false; 7236b4cac81SBjoern A. Zeeb conf->def.chan = chan; 7246b4cac81SBjoern A. Zeeb conf->def.width = NL80211_CHAN_WIDTH_20_NOHT; 7256b4cac81SBjoern A. Zeeb conf->def.center_freq1 = chan->center_freq; 7266b4cac81SBjoern A. Zeeb conf->def.center_freq2 = 0; 7276b4cac81SBjoern A. Zeeb /* Responder ... */ 7286b4cac81SBjoern A. Zeeb conf->min_def.chan = chan; 7296b4cac81SBjoern A. Zeeb conf->min_def.width = NL80211_CHAN_WIDTH_20_NOHT; 7306b4cac81SBjoern A. Zeeb conf->min_def.center_freq1 = chan->center_freq; 7316b4cac81SBjoern A. Zeeb conf->min_def.center_freq2 = 0; 7326b4cac81SBjoern A. Zeeb IMPROVE("currently 20_NOHT only"); 7336b4cac81SBjoern A. Zeeb 7346b4cac81SBjoern A. Zeeb ni = NULL; 7356b4cac81SBjoern A. Zeeb error = 0; 7366b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 7376b4cac81SBjoern A. Zeeb changed = IEEE80211_CHANCTX_CHANGE_MIN_WIDTH; 7386b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_RADAR; 7396b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_RX_CHAINS; 7406b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_WIDTH; 7416b4cac81SBjoern A. Zeeb lkpi_80211_mo_change_chanctx(hw, conf, changed); 7426b4cac81SBjoern A. Zeeb } else { 7436b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_add_chanctx(hw, conf); 7446b4cac81SBjoern A. Zeeb if (error == 0 || error == EOPNOTSUPP) { 7456b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.chan = conf->def.chan; 7466b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.width = conf->def.width; 7476b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.center_freq1 = 7486b4cac81SBjoern A. Zeeb conf->def.center_freq1; 7496b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.center_freq2 = 7506b4cac81SBjoern A. Zeeb conf->def.center_freq2; 7516b4cac81SBjoern A. Zeeb } else { 7526b4cac81SBjoern A. Zeeb goto out; 7536b4cac81SBjoern A. Zeeb } 7546b4cac81SBjoern A. Zeeb /* Assign vif chanctx. */ 7556b4cac81SBjoern A. Zeeb if (error == 0) 7566b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_assign_vif_chanctx(hw, vif, conf); 7576b4cac81SBjoern A. Zeeb if (error == EOPNOTSUPP) 7586b4cac81SBjoern A. Zeeb error = 0; 7596b4cac81SBjoern A. Zeeb if (error != 0) { 7606b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 7616b4cac81SBjoern A. Zeeb free(conf, M_LKPI80211); 7626b4cac81SBjoern A. Zeeb goto out; 7636b4cac81SBjoern A. Zeeb } 7646b4cac81SBjoern A. Zeeb } 7656b4cac81SBjoern A. Zeeb IMPROVE("update radiotap chan fields too"); 7666b4cac81SBjoern A. Zeeb 7676b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 7686b4cac81SBjoern A. Zeeb 7696b4cac81SBjoern A. Zeeb /* Set bss info (bss_info_changed). */ 7706b4cac81SBjoern A. Zeeb bss_changed = 0; 7716b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(vif->bss_conf.bssid, ni->ni_bssid); 7726b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 7736b4cac81SBjoern A. Zeeb vif->bss_conf.txpower = ni->ni_txpower; 7746b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_TXPOWER; 7756b4cac81SBjoern A. Zeeb vif->bss_conf.idle = false; 7766b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_IDLE; 7776b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = ni->ni_intval; 7786b4cac81SBjoern A. Zeeb /* iwlwifi FW bug workaround; iwl_mvm_mac_sta_state. */ 7796b4cac81SBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16) 7806b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = 16; 7816b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INT; 782*c8dafefaSBjoern A. Zeeb vif->bss_conf.dtim_period = vap->iv_dtim_period; 783*c8dafefaSBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INFO; 784*c8dafefaSBjoern A. Zeeb vif->bss_conf.sync_dtim_count = vap->iv_dtim_count; 785*c8dafefaSBjoern A. Zeeb vif->bss_conf.sync_tsf = le64toh(ni->ni_tstamp.tsf); 786*c8dafefaSBjoern A. Zeeb /* vif->bss_conf.sync_device_ts = set in linuxkpi_ieee80211_rx. */ 787*c8dafefaSBjoern A. Zeeb 7886b4cac81SBjoern A. Zeeb /* Should almost assert it is this. */ 7896b4cac81SBjoern A. Zeeb vif->bss_conf.assoc = false; 7906b4cac81SBjoern A. Zeeb vif->bss_conf.aid = 0; 7916b4cac81SBjoern A. Zeeb /* RATES */ 7926b4cac81SBjoern A. Zeeb IMPROVE("bss info: not all needs to come now and rates are missing"); 7936b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 7946b4cac81SBjoern A. Zeeb 7956b4cac81SBjoern A. Zeeb /* Add (or adjust) sta and change state (from NOTEXIST) to NONE. */ 7966b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 7976b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 7986b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NOTEXIST, ("%s: lsta %p state not " 7996b4cac81SBjoern A. Zeeb "NOTEXIST: %#x\n", __func__, lsta, lsta->state)); 8006b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 8016b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_NONE); 8026b4cac81SBjoern A. Zeeb if (error != 0) { 8036b4cac81SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 8046b4cac81SBjoern A. Zeeb goto out; 8056b4cac81SBjoern A. Zeeb } 8066b4cac81SBjoern A. Zeeb #if 0 8076b4cac81SBjoern A. Zeeb lsta->added_to_drv = true; /* mo manages. */ 8086b4cac81SBjoern A. Zeeb #endif 8096b4cac81SBjoern A. Zeeb 8106b4cac81SBjoern A. Zeeb /* 8116b4cac81SBjoern A. Zeeb * Wakeup all queues now that sta is there so we have as much time to 8126b4cac81SBjoern A. Zeeb * possibly prepare the queue in the driver to be ready for the 1st 8136b4cac81SBjoern A. Zeeb * packet; lkpi_80211_txq_tx_one() still has a workaround as there 8146b4cac81SBjoern A. Zeeb * is no guarantee or way to check. 8156b4cac81SBjoern A. Zeeb */ 8166b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, false, false); 8176b4cac81SBjoern A. Zeeb 8186b4cac81SBjoern A. Zeeb { 8196b4cac81SBjoern A. Zeeb int i, count; 8206b4cac81SBjoern A. Zeeb 821500be2e8SBjoern A. Zeeb for (i = 3 * (hw->queues + 1); i > 0; i--) { 8226b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 8236b4cac81SBjoern A. Zeeb int tid; 8246b4cac81SBjoern A. Zeeb 8256b4cac81SBjoern A. Zeeb count = 0; 8266b4cac81SBjoern A. Zeeb /* Wake up all queues to know they are allocated in the driver. */ 8276b4cac81SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 8286b4cac81SBjoern A. Zeeb 8296b4cac81SBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) { 8306b4cac81SBjoern A. Zeeb IMPROVE("station specific?"); 8316b4cac81SBjoern A. Zeeb if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ)) 8326b4cac81SBjoern A. Zeeb continue; 8336b4cac81SBjoern A. Zeeb } else if (tid >= hw->queues) 8346b4cac81SBjoern A. Zeeb continue; 8356b4cac81SBjoern A. Zeeb 8366b4cac81SBjoern A. Zeeb if (sta->txq[tid] == NULL) 8376b4cac81SBjoern A. Zeeb continue; 8386b4cac81SBjoern A. Zeeb 8396b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]); 8406b4cac81SBjoern A. Zeeb if (!ltxq->seen_dequeue) 8416b4cac81SBjoern A. Zeeb count++; 8426b4cac81SBjoern A. Zeeb } 8436b4cac81SBjoern A. Zeeb if (count == 0) 8446b4cac81SBjoern A. Zeeb break; 8456b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 8466b4cac81SBjoern A. Zeeb if (count > 0) 847312ba38aSRuslan Makhmatkhanov ic_printf(vap->iv_ic, "%s: waiting for %d queues " 8486b4cac81SBjoern A. Zeeb "to be allocated by driver\n", __func__, count); 8496b4cac81SBjoern A. Zeeb #endif 850500be2e8SBjoern A. Zeeb pause("lkpi80211txq", hz/10); 8516b4cac81SBjoern A. Zeeb } 8526b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 8536b4cac81SBjoern A. Zeeb if (count > 0) 854312ba38aSRuslan Makhmatkhanov ic_printf(vap->iv_ic, "%s: %d queues still not " 8556b4cac81SBjoern A. Zeeb "allocated by driver\n", __func__, count); 8566b4cac81SBjoern A. Zeeb #endif 8576b4cac81SBjoern A. Zeeb } 8586b4cac81SBjoern A. Zeeb 8596b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 8606b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 8616b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 8626b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 8636b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 8646b4cac81SBjoern A. Zeeb 8656b4cac81SBjoern A. Zeeb /* 8666b4cac81SBjoern A. Zeeb * What is going to happen next: 8676b4cac81SBjoern A. Zeeb * - <twiddle> .. we should end up in "auth_to_assoc" 8686b4cac81SBjoern A. Zeeb * - event_callback 8696b4cac81SBjoern A. Zeeb * - update sta_state (NONE to AUTH) 8706b4cac81SBjoern A. Zeeb * - mgd_complete_tx 8716b4cac81SBjoern A. Zeeb * (ideally we'd do that on a callback for something else ...) 8726b4cac81SBjoern A. Zeeb */ 8736b4cac81SBjoern A. Zeeb 8746b4cac81SBjoern A. Zeeb out: 8756b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 8766b4cac81SBjoern A. Zeeb if (ni != NULL) 8776b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 8786b4cac81SBjoern A. Zeeb return (error); 8796b4cac81SBjoern A. Zeeb } 8806b4cac81SBjoern A. Zeeb 8816b4cac81SBjoern A. Zeeb static int 8826b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 8836b4cac81SBjoern A. Zeeb { 8846b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 8856b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 8866b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 8876b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 8886b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 8896b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 8906b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 8916b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 8926b4cac81SBjoern A. Zeeb int error; 8936b4cac81SBjoern A. Zeeb 8946b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 8956b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 8966b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 8976b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 8986b4cac81SBjoern A. Zeeb 8996b4cac81SBjoern A. Zeeb /* Keep ni around. */ 9006b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 9016b4cac81SBjoern A. Zeeb 9026b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 9036b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 9046b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 9056b4cac81SBjoern A. Zeeb 9066b4cac81SBjoern A. Zeeb /* flush, drop. */ 9076b4cac81SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 9086b4cac81SBjoern A. Zeeb 9096b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 9106b4cac81SBjoern A. Zeeb 9116b4cac81SBjoern A. Zeeb /* Call iv_newstate first so we get potential deauth packet out. */ 9126b4cac81SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 9136b4cac81SBjoern A. Zeeb if (error != 0) 9146b4cac81SBjoern A. Zeeb goto outni; 9156b4cac81SBjoern A. Zeeb 9166b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 9176b4cac81SBjoern A. Zeeb 9186b4cac81SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 9196b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 9206b4cac81SBjoern A. Zeeb 9216b4cac81SBjoern A. Zeeb /* flush, no drop */ 9226b4cac81SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 9236b4cac81SBjoern A. Zeeb 9246b4cac81SBjoern A. Zeeb /* Take the station and chan ctx down again. */ 9256b4cac81SBjoern A. Zeeb 9266b4cac81SBjoern A. Zeeb IMPROVE("event callback with failure?"); 9276b4cac81SBjoern A. Zeeb 9286b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 9296b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 9306b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 9316b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 9326b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 9336b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 9346b4cac81SBjoern A. Zeeb } 9356b4cac81SBjoern A. Zeeb 9366b4cac81SBjoern A. Zeeb #ifdef __not_yet__ 9376b4cac81SBjoern A. Zeeb /* sync_rx_queues */ 9386b4cac81SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 9396b4cac81SBjoern A. Zeeb 9406b4cac81SBjoern A. Zeeb /* sta_pre_rcu_remove */ 9416b4cac81SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 9426b4cac81SBjoern A. Zeeb #endif 9436b4cac81SBjoern A. Zeeb 9446b4cac81SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 9456b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 9466b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 9476b4cac81SBjoern A. Zeeb "NONE: %#x\n", __func__, lsta, lsta->state)); 9486b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_NOTEXIST); 9496b4cac81SBjoern A. Zeeb if (error != 0) { 9506b4cac81SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 9516b4cac81SBjoern A. Zeeb goto out; 9526b4cac81SBjoern A. Zeeb } 9536b4cac81SBjoern A. Zeeb #if 0 9546b4cac81SBjoern A. Zeeb lsta->added_to_drv = false; /* mo manages. */ 9556b4cac81SBjoern A. Zeeb #endif 9566b4cac81SBjoern A. Zeeb 9576b4cac81SBjoern A. Zeeb IMPROVE("Any bss_info changes to announce?"); 9586b4cac81SBjoern A. Zeeb 9596b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 9606b4cac81SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 9616b4cac81SBjoern A. Zeeb 9626b4cac81SBjoern A. Zeeb conf = vif->chanctx_conf; 9636b4cac81SBjoern A. Zeeb /* Remove vif context. */ 9646b4cac81SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->chanctx_conf); 9656b4cac81SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 9666b4cac81SBjoern A. Zeeb 9676b4cac81SBjoern A. Zeeb /* Remove chan ctx. */ 9686b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 9696b4cac81SBjoern A. Zeeb free(conf, M_LKPI80211); 9706b4cac81SBjoern A. Zeeb } 9716b4cac81SBjoern A. Zeeb 9726b4cac81SBjoern A. Zeeb /* No need to start a scan; ic_scan_start should do. */ 9736b4cac81SBjoern A. Zeeb 9746b4cac81SBjoern A. Zeeb error = EALREADY; 9756b4cac81SBjoern A. Zeeb out: 9766b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 9776b4cac81SBjoern A. Zeeb outni: 9786b4cac81SBjoern A. Zeeb if (ni != NULL) 9796b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 9806b4cac81SBjoern A. Zeeb return (error); 9816b4cac81SBjoern A. Zeeb } 9826b4cac81SBjoern A. Zeeb 9836b4cac81SBjoern A. Zeeb static int 9846b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 9856b4cac81SBjoern A. Zeeb { 9866b4cac81SBjoern A. Zeeb int error; 9876b4cac81SBjoern A. Zeeb 9886b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_scan(vap, nstate, arg); 9896b4cac81SBjoern A. Zeeb if (error == 0) 9906b4cac81SBjoern A. Zeeb error = lkpi_sta_scan_to_init(vap, nstate, arg); 9916b4cac81SBjoern A. Zeeb return (error); 9926b4cac81SBjoern A. Zeeb } 9936b4cac81SBjoern A. Zeeb 9946b4cac81SBjoern A. Zeeb static int 9956b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 9966b4cac81SBjoern A. Zeeb { 9976b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 9986b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 9996b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 10006b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 10016b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 10026b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 10036b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 10046b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 10056b4cac81SBjoern A. Zeeb int error; 10066b4cac81SBjoern A. Zeeb 10076b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 10086b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 10096b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 10106b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 10116b4cac81SBjoern A. Zeeb 10126b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 10136b4cac81SBjoern A. Zeeb ni = NULL; 10146b4cac81SBjoern A. Zeeb 10156b4cac81SBjoern A. Zeeb /* Finish auth. */ 10166b4cac81SBjoern A. Zeeb IMPROVE("event callback"); 10176b4cac81SBjoern A. Zeeb 10186b4cac81SBjoern A. Zeeb /* Update sta_state (NONE to AUTH). */ 10196b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 10206b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 10216b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 10226b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 10236b4cac81SBjoern A. Zeeb "NONE: %#x\n", __func__, lsta, lsta->state)); 10246b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 10256b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_AUTH); 10266b4cac81SBjoern A. Zeeb if (error != 0) 10276b4cac81SBjoern A. Zeeb goto out; 10286b4cac81SBjoern A. Zeeb 10296b4cac81SBjoern A. Zeeb /* End mgd_complete_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.success = true; 10336b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 10346b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 10356b4cac81SBjoern A. Zeeb } 10366b4cac81SBjoern A. Zeeb 10376b4cac81SBjoern A. Zeeb /* Now start assoc. */ 10386b4cac81SBjoern A. Zeeb 10396b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 10406b4cac81SBjoern A. Zeeb if (!lsta->in_mgd) { 10416b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 10426b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 10436b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 10446b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 10456b4cac81SBjoern A. Zeeb } 10466b4cac81SBjoern A. Zeeb 10476b4cac81SBjoern A. Zeeb /* Wake tx queue to get packet out. */ 10486b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 10496b4cac81SBjoern A. Zeeb 10506b4cac81SBjoern A. Zeeb /* 10516b4cac81SBjoern A. Zeeb * <twiddle> .. we end up in "assoc_to_run" 10526b4cac81SBjoern A. Zeeb * - update sta_state (AUTH to ASSOC) 10536b4cac81SBjoern A. Zeeb * - conf_tx [all] 10546b4cac81SBjoern A. Zeeb * - bss_info_changed (assoc, aid, ssid, ..) 10556b4cac81SBjoern A. Zeeb * - change_chanctx (if needed) 10566b4cac81SBjoern A. Zeeb * - event_callback 10576b4cac81SBjoern A. Zeeb * - mgd_complete_tx 10586b4cac81SBjoern A. Zeeb */ 10596b4cac81SBjoern A. Zeeb 10606b4cac81SBjoern A. Zeeb out: 10616b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 10626b4cac81SBjoern A. Zeeb if (ni != NULL) 10636b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 10646b4cac81SBjoern A. Zeeb return (error); 10656b4cac81SBjoern A. Zeeb } 10666b4cac81SBjoern A. Zeeb 10676b4cac81SBjoern A. Zeeb /* auth_to_auth, assoc_to_assoc. */ 10686b4cac81SBjoern A. Zeeb static int 10696b4cac81SBjoern A. Zeeb lkpi_sta_a_to_a(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 10706b4cac81SBjoern A. Zeeb { 10716b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 10726b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 10736b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 10746b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 10756b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 10766b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 10776b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 10786b4cac81SBjoern A. Zeeb 10796b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 10806b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 10816b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 10826b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 10836b4cac81SBjoern A. Zeeb 10846b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 10856b4cac81SBjoern A. Zeeb 10866b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 10876b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 10886b4cac81SBjoern A. Zeeb 10896b4cac81SBjoern A. Zeeb IMPROVE("event callback?"); 10906b4cac81SBjoern A. Zeeb 10916b4cac81SBjoern A. Zeeb /* End mgd_complete_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.success = false; 10956b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 10966b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 10976b4cac81SBjoern A. Zeeb } 10986b4cac81SBjoern A. Zeeb 10996b4cac81SBjoern A. Zeeb /* Now start assoc. */ 11006b4cac81SBjoern A. Zeeb 11016b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 11026b4cac81SBjoern A. Zeeb if (!lsta->in_mgd) { 11036b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 11046b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 11056b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 11066b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 11076b4cac81SBjoern A. Zeeb } 11086b4cac81SBjoern A. Zeeb 11096b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 11106b4cac81SBjoern A. Zeeb if (ni != NULL) 11116b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 11126b4cac81SBjoern A. Zeeb 11136b4cac81SBjoern A. Zeeb return (0); 11146b4cac81SBjoern A. Zeeb } 11156b4cac81SBjoern A. Zeeb 11166b4cac81SBjoern A. Zeeb static int 11176b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 11186b4cac81SBjoern A. Zeeb { 11196b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 11206b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 11216b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 11226b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 11236b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 11246b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 11256b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 11266b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 11276b4cac81SBjoern A. Zeeb int error; 11286b4cac81SBjoern A. Zeeb 11296b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 11306b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 11316b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 11326b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 11336b4cac81SBjoern A. Zeeb 11346b4cac81SBjoern A. Zeeb /* Keep ni around. */ 11356b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 11366b4cac81SBjoern A. Zeeb 11376b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 11386b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 11396b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 11406b4cac81SBjoern A. Zeeb 11416b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 11426b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 11436b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 11446b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 11456b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 11466b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 11476b4cac81SBjoern A. Zeeb } 11486b4cac81SBjoern A. Zeeb 11496b4cac81SBjoern A. Zeeb /* Update sta and change state (from AUTH) to NONE. */ 11506b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 11516b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 11526b4cac81SBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 11536b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_NONE); 11546b4cac81SBjoern A. Zeeb if (error != 0) 11556b4cac81SBjoern A. Zeeb goto out; 11566b4cac81SBjoern A. Zeeb 11576b4cac81SBjoern A. Zeeb IMPROVE("anything else?"); 11586b4cac81SBjoern A. Zeeb 11596b4cac81SBjoern A. Zeeb out: 11606b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 11616b4cac81SBjoern A. Zeeb if (ni != NULL) 11626b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 11636b4cac81SBjoern A. Zeeb return (error); 11646b4cac81SBjoern A. Zeeb } 11656b4cac81SBjoern A. Zeeb 11666b4cac81SBjoern A. Zeeb static int 11676b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 11686b4cac81SBjoern A. Zeeb { 11696b4cac81SBjoern A. Zeeb int error; 11706b4cac81SBjoern A. Zeeb 11716b4cac81SBjoern A. Zeeb error = lkpi_sta_assoc_to_auth(vap, nstate, arg); 11726b4cac81SBjoern A. Zeeb if (error == 0) 11736b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_scan(vap, nstate, arg); 11746b4cac81SBjoern A. Zeeb return (error); 11756b4cac81SBjoern A. Zeeb } 11766b4cac81SBjoern A. Zeeb 11776b4cac81SBjoern A. Zeeb static int 11786b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 11796b4cac81SBjoern A. Zeeb { 11806b4cac81SBjoern A. Zeeb int error; 11816b4cac81SBjoern A. Zeeb 11826b4cac81SBjoern A. Zeeb error = lkpi_sta_assoc_to_scan(vap, nstate, arg); 11836b4cac81SBjoern A. Zeeb if (error == 0) 11846b4cac81SBjoern A. Zeeb error = lkpi_sta_scan_to_init(vap, nstate, arg); 11856b4cac81SBjoern A. Zeeb return (error); 11866b4cac81SBjoern A. Zeeb } 11876b4cac81SBjoern A. Zeeb 11886b4cac81SBjoern A. Zeeb static int 11896b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 11906b4cac81SBjoern A. Zeeb { 11916b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 11926b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 11936b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 11946b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 11956b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 11966b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 11976b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 11986b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 11996b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 12006b4cac81SBjoern A. Zeeb int error; 12016b4cac81SBjoern A. Zeeb 12026b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 12036b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 12046b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 12056b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 12066b4cac81SBjoern A. Zeeb 12076b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 12086b4cac81SBjoern A. Zeeb ni = NULL; 12096b4cac81SBjoern A. Zeeb 12106b4cac81SBjoern A. Zeeb IMPROVE("ponder some of this moved to ic_newassoc, scan_assoc_success, " 12116b4cac81SBjoern A. Zeeb "and to lesser extend ieee80211_notify_node_join"); 12126b4cac81SBjoern A. Zeeb 12136b4cac81SBjoern A. Zeeb /* Finish assoc. */ 12146b4cac81SBjoern A. Zeeb /* Update sta_state (AUTH to ASSOC) and set aid. */ 12156b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 12166b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 12176b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 12186b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 12196b4cac81SBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 12206b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 12216b4cac81SBjoern A. Zeeb sta->aid = IEEE80211_NODE_AID(ni); 12226b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_ASSOC); 12236b4cac81SBjoern A. Zeeb if (error != 0) 12246b4cac81SBjoern A. Zeeb goto out; 12256b4cac81SBjoern A. Zeeb 12266b4cac81SBjoern A. Zeeb IMPROVE("wme / conf_tx [all]"); 12276b4cac81SBjoern A. Zeeb 12286b4cac81SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 12296b4cac81SBjoern A. Zeeb bss_changed = 0; 12306b4cac81SBjoern A. Zeeb if (!vif->bss_conf.assoc || vif->bss_conf.aid != IEEE80211_NODE_AID(ni)) { 12316b4cac81SBjoern A. Zeeb vif->bss_conf.assoc = true; 12326b4cac81SBjoern A. Zeeb vif->bss_conf.aid = IEEE80211_NODE_AID(ni); 12336b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_ASSOC; 12346b4cac81SBjoern A. Zeeb } 12356b4cac81SBjoern A. Zeeb /* We set SSID but this is not BSSID! */ 12366b4cac81SBjoern A. Zeeb vif->bss_conf.ssid_len = ni->ni_esslen; 12376b4cac81SBjoern A. Zeeb memcpy(vif->bss_conf.ssid, ni->ni_essid, ni->ni_esslen); 12386b4cac81SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_SHPREAMBLE) != 12396b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble) { 12406b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble ^= 1; 12416b4cac81SBjoern A. Zeeb /* bss_changed |= BSS_CHANGED_??? */ 12426b4cac81SBjoern A. Zeeb } 12436b4cac81SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_SHSLOT) != 12446b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot) { 12456b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot ^= 1; 12466b4cac81SBjoern A. Zeeb /* bss_changed |= BSS_CHANGED_??? */ 12476b4cac81SBjoern A. Zeeb } 12486b4cac81SBjoern A. Zeeb if ((ni->ni_flags & IEEE80211_NODE_QOS) != 12496b4cac81SBjoern A. Zeeb vif->bss_conf.qos) { 12506b4cac81SBjoern A. Zeeb vif->bss_conf.qos ^= 1; 12516b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 12526b4cac81SBjoern A. Zeeb } 12536b4cac81SBjoern A. Zeeb if (vif->bss_conf.beacon_int != ni->ni_intval) { 12546b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = ni->ni_intval; 12556b4cac81SBjoern A. Zeeb /* iwlwifi FW bug workaround; iwl_mvm_mac_sta_state. */ 12566b4cac81SBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16) 12576b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = 16; 12586b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INT; 12596b4cac81SBjoern A. Zeeb } 12606b4cac81SBjoern A. Zeeb if (vif->bss_conf.dtim_period != vap->iv_dtim_period && 12616b4cac81SBjoern A. Zeeb vap->iv_dtim_period > 0) { 12626b4cac81SBjoern A. Zeeb vif->bss_conf.dtim_period = vap->iv_dtim_period; 12636b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INFO; 12646b4cac81SBjoern A. Zeeb } 12656b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 12666b4cac81SBjoern A. Zeeb 12676b4cac81SBjoern A. Zeeb /* - change_chanctx (if needed) 12686b4cac81SBjoern A. Zeeb * - event_callback 12696b4cac81SBjoern A. Zeeb */ 12706b4cac81SBjoern A. Zeeb 12716b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 12726b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 12736b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 12746b4cac81SBjoern A. Zeeb prep_tx_info.success = true; 12756b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 12766b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 12776b4cac81SBjoern A. Zeeb } 12786b4cac81SBjoern A. Zeeb 1279086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, false); 1280086be6a8SBjoern A. Zeeb 12816b4cac81SBjoern A. Zeeb /* 12826b4cac81SBjoern A. Zeeb * And then: 12836b4cac81SBjoern A. Zeeb * - (more packets)? 12846b4cac81SBjoern A. Zeeb * - set_key 12856b4cac81SBjoern A. Zeeb * - set_default_unicast_key 12866b4cac81SBjoern A. Zeeb * - set_key (?) 12876b4cac81SBjoern A. Zeeb * - ipv6_addr_change (?) 12886b4cac81SBjoern A. Zeeb */ 12896b4cac81SBjoern A. Zeeb /* Prepare_multicast && configure_filter. */ 12906b4cac81SBjoern A. Zeeb lhw->update_mc = true; 12916b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(vap->iv_ic, true); 12926b4cac81SBjoern A. Zeeb 12936b4cac81SBjoern A. Zeeb if (!ieee80211_node_is_authorized(ni)) { 12946b4cac81SBjoern A. Zeeb IMPROVE("net80211 does not consider node authorized"); 12956b4cac81SBjoern A. Zeeb } 12966b4cac81SBjoern A. Zeeb 12976b4cac81SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTHORIZED). */ 12986b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 12996b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 13006b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 13016b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 13026b4cac81SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 13036b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 13046b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_AUTHORIZED); 13056b4cac81SBjoern A. Zeeb if (error != 0) { 13066b4cac81SBjoern A. Zeeb IMPROVE("undo some changes?"); 13076b4cac81SBjoern A. Zeeb goto out; 13086b4cac81SBjoern A. Zeeb } 13096b4cac81SBjoern A. Zeeb 13106b4cac81SBjoern A. Zeeb /* - drv_config (?) 13116b4cac81SBjoern A. Zeeb * - bss_info_changed 13126b4cac81SBjoern A. Zeeb * - set_rekey_data (?) 13136b4cac81SBjoern A. Zeeb * 13146b4cac81SBjoern A. Zeeb * And now we should be passing packets. 13156b4cac81SBjoern A. Zeeb */ 13166b4cac81SBjoern A. Zeeb IMPROVE("Need that bssid setting, and the keys"); 13176b4cac81SBjoern A. Zeeb 13186b4cac81SBjoern A. Zeeb out: 13196b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 13206b4cac81SBjoern A. Zeeb if (ni != NULL) 13216b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 13226b4cac81SBjoern A. Zeeb return (error); 13236b4cac81SBjoern A. Zeeb } 13246b4cac81SBjoern A. Zeeb 13256b4cac81SBjoern A. Zeeb static int 13266b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 13276b4cac81SBjoern A. Zeeb { 13286b4cac81SBjoern A. Zeeb int error; 13296b4cac81SBjoern A. Zeeb 13306b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_assoc(vap, nstate, arg); 13316b4cac81SBjoern A. Zeeb if (error == 0) 13326b4cac81SBjoern A. Zeeb error = lkpi_sta_assoc_to_run(vap, nstate, arg); 13336b4cac81SBjoern A. Zeeb return (error); 13346b4cac81SBjoern A. Zeeb } 13356b4cac81SBjoern A. Zeeb 13366b4cac81SBjoern A. Zeeb static int 13376b4cac81SBjoern A. Zeeb lkpi_sta_run_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 13386b4cac81SBjoern A. Zeeb { 13396b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 13406b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 13416b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 13426b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 13436b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 13446b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 13456b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 13466b4cac81SBjoern A. Zeeb int error; 13476b4cac81SBjoern A. Zeeb 13486b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 13496b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 13506b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 13516b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 13526b4cac81SBjoern A. Zeeb 13536b4cac81SBjoern A. Zeeb /* Keep ni around. */ 13546b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 13556b4cac81SBjoern A. Zeeb 13566b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 13576b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 13586b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 13596b4cac81SBjoern A. Zeeb 13606b4cac81SBjoern A. Zeeb /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */ 13616b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 13626b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not " 13636b4cac81SBjoern A. Zeeb "AUTHORIZED: %#x\n", __func__, lsta, lsta->state)); 13646b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_ASSOC); 13656b4cac81SBjoern A. Zeeb if (error != 0) 13666b4cac81SBjoern A. Zeeb goto out; 13676b4cac81SBjoern A. Zeeb 13686b4cac81SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 13696b4cac81SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw); 13706b4cac81SBjoern A. Zeeb 13716b4cac81SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTH). */ 13726b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 13736b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 13746b4cac81SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 13756b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 13766b4cac81SBjoern A. Zeeb sta->aid = 0; 13776b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_AUTH); 13786b4cac81SBjoern A. Zeeb if (error != 0) 13796b4cac81SBjoern A. Zeeb goto out; 13806b4cac81SBjoern A. Zeeb 13816b4cac81SBjoern A. Zeeb IMPROVE("if ASSOC is final state, prep_tx_info?"); 13826b4cac81SBjoern A. Zeeb 13836b4cac81SBjoern A. Zeeb out: 13846b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 13856b4cac81SBjoern A. Zeeb if (ni != NULL) 13866b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 13876b4cac81SBjoern A. Zeeb return (error); 13886b4cac81SBjoern A. Zeeb } 13896b4cac81SBjoern A. Zeeb 13906b4cac81SBjoern A. Zeeb static int 13916b4cac81SBjoern A. Zeeb lkpi_sta_run_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 13926b4cac81SBjoern A. Zeeb { 13936b4cac81SBjoern A. Zeeb int error; 13946b4cac81SBjoern A. Zeeb 13956b4cac81SBjoern A. Zeeb error = lkpi_sta_run_to_assoc(vap, nstate, arg); 13966b4cac81SBjoern A. Zeeb if (error == 0) 13976b4cac81SBjoern A. Zeeb error = lkpi_sta_assoc_to_auth(vap, nstate, arg); 13986b4cac81SBjoern A. Zeeb return (error); 13996b4cac81SBjoern A. Zeeb } 14006b4cac81SBjoern A. Zeeb 14016b4cac81SBjoern A. Zeeb static int 14026b4cac81SBjoern A. Zeeb lkpi_sta_run_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 14036b4cac81SBjoern A. Zeeb { 14046b4cac81SBjoern A. Zeeb int error; 14056b4cac81SBjoern A. Zeeb 14066b4cac81SBjoern A. Zeeb error = lkpi_sta_run_to_auth(vap, nstate, arg); 14076b4cac81SBjoern A. Zeeb if (error == 0) 14086b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_scan(vap, nstate, arg); 14096b4cac81SBjoern A. Zeeb return (error); 14106b4cac81SBjoern A. Zeeb } 14116b4cac81SBjoern A. Zeeb 14126b4cac81SBjoern A. Zeeb static int 14136b4cac81SBjoern A. Zeeb lkpi_sta_run_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 14146b4cac81SBjoern A. Zeeb { 14156b4cac81SBjoern A. Zeeb int error; 14166b4cac81SBjoern A. Zeeb 14176b4cac81SBjoern A. Zeeb error = lkpi_sta_run_to_scan(vap, nstate, arg); 14186b4cac81SBjoern A. Zeeb if (error == 0) 14196b4cac81SBjoern A. Zeeb error = lkpi_sta_scan_to_init(vap, nstate, arg); 14206b4cac81SBjoern A. Zeeb return (error); 14216b4cac81SBjoern A. Zeeb } 14226b4cac81SBjoern A. Zeeb 14236b4cac81SBjoern A. Zeeb /* 14246b4cac81SBjoern A. Zeeb * The matches the documented state changes in net80211::sta_newstate(). 14256b4cac81SBjoern A. Zeeb * XXX (1) without CSA and SLEEP yet, * XXX (2) not all unhandled cases 14266b4cac81SBjoern A. Zeeb * there are "invalid" (so there is a room for failure here). 14276b4cac81SBjoern A. Zeeb */ 14286b4cac81SBjoern A. Zeeb struct fsm_state { 14296b4cac81SBjoern A. Zeeb /* INIT, SCAN, AUTH, ASSOC, CAC, RUN, CSA, SLEEP */ 14306b4cac81SBjoern A. Zeeb enum ieee80211_state ostate; 14316b4cac81SBjoern A. Zeeb enum ieee80211_state nstate; 14326b4cac81SBjoern A. Zeeb int (*handler)(struct ieee80211vap *, enum ieee80211_state, int); 14336b4cac81SBjoern A. Zeeb } sta_state_fsm[] = { 14346b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, 14356b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, /* scan_to_init */ 14366b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_INIT, lkpi_sta_auth_to_init }, /* not explicitly in sta_newstate() */ 14376b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_INIT, lkpi_sta_assoc_to_init }, 14386b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_INIT, lkpi_sta_run_to_init }, 14396b4cac81SBjoern A. Zeeb 14406b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_SCAN, lkpi_sta_state_do_nada }, 14416b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_SCAN, lkpi_sta_state_do_nada }, 14426b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_SCAN, lkpi_sta_auth_to_scan }, 14436b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_SCAN, lkpi_sta_assoc_to_scan }, 14446b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_SCAN, lkpi_sta_run_to_scan }, 14456b4cac81SBjoern A. Zeeb 14466b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, 14476b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, 14486b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_AUTH, lkpi_sta_a_to_a }, 14496b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_AUTH, lkpi_sta_assoc_to_auth }, 14506b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_AUTH, lkpi_sta_run_to_auth }, 14516b4cac81SBjoern A. Zeeb 14526b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_ASSOC, lkpi_sta_auth_to_assoc }, 14536b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_ASSOC, lkpi_sta_a_to_a }, 14546b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_ASSOC, lkpi_sta_run_to_assoc }, 14556b4cac81SBjoern A. Zeeb 14566b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_RUN, lkpi_sta_auth_to_run }, 14576b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_RUN, lkpi_sta_assoc_to_run }, 14586b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_RUN, lkpi_sta_state_do_nada }, 14596b4cac81SBjoern A. Zeeb 14606b4cac81SBjoern A. Zeeb /* Dummy at the end without handler. */ 14616b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_INIT, NULL }, 14626b4cac81SBjoern A. Zeeb }; 14636b4cac81SBjoern A. Zeeb 14646b4cac81SBjoern A. Zeeb static int 14656b4cac81SBjoern A. Zeeb lkpi_iv_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 14666b4cac81SBjoern A. Zeeb { 14676b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 14686b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 14696b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 14706b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 14716b4cac81SBjoern A. Zeeb struct fsm_state *s; 14726b4cac81SBjoern A. Zeeb enum ieee80211_state ostate; 14736b4cac81SBjoern A. Zeeb int error; 14746b4cac81SBjoern A. Zeeb 14756b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 14766b4cac81SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(ic); 14776b4cac81SBjoern A. Zeeb ostate = vap->iv_state; 14786b4cac81SBjoern A. Zeeb 14796b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE) 14806b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x\n", 14816b4cac81SBjoern A. Zeeb __func__, __LINE__, vap, nstate, arg); 14826b4cac81SBjoern A. Zeeb 14836b4cac81SBjoern A. Zeeb if (vap->iv_opmode == IEEE80211_M_STA) { 14846b4cac81SBjoern A. Zeeb 14856b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 14866b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 14876b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 14886b4cac81SBjoern A. Zeeb 14896b4cac81SBjoern A. Zeeb /* No need to replicate this in most state handlers. */ 14906b4cac81SBjoern A. Zeeb if (ostate == IEEE80211_S_SCAN && nstate != IEEE80211_S_SCAN) 14916b4cac81SBjoern A. Zeeb lkpi_stop_hw_scan(lhw, vif); 14926b4cac81SBjoern A. Zeeb 14936b4cac81SBjoern A. Zeeb s = sta_state_fsm; 14946b4cac81SBjoern A. Zeeb 14956b4cac81SBjoern A. Zeeb } else { 14966b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: only station mode currently supported: " 14976b4cac81SBjoern A. Zeeb "cap %p iv_opmode %d\n", __func__, vap, vap->iv_opmode); 14986b4cac81SBjoern A. Zeeb return (ENOSYS); 14996b4cac81SBjoern A. Zeeb } 15006b4cac81SBjoern A. Zeeb 15016b4cac81SBjoern A. Zeeb error = 0; 15026b4cac81SBjoern A. Zeeb for (; s->handler != NULL; s++) { 15036b4cac81SBjoern A. Zeeb if (ostate == s->ostate && nstate == s->nstate) { 15046b4cac81SBjoern A. Zeeb error = s->handler(vap, nstate, arg); 15056b4cac81SBjoern A. Zeeb break; 15066b4cac81SBjoern A. Zeeb } 15076b4cac81SBjoern A. Zeeb } 15086b4cac81SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(vap->iv_ic); 15096b4cac81SBjoern A. Zeeb 15106b4cac81SBjoern A. Zeeb if (s->handler == NULL) { 15116b4cac81SBjoern A. Zeeb IMPROVE("thurn this into a KASSERT\n"); 15126b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: unsupported state transition " 15136b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s)\n", __func__, 15146b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 15156b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 15166b4cac81SBjoern A. Zeeb return (ENOSYS); 15176b4cac81SBjoern A. Zeeb } 15186b4cac81SBjoern A. Zeeb 15196b4cac81SBjoern A. Zeeb if (error == EALREADY) { 15206b4cac81SBjoern A. Zeeb IMPROVE("make this a debug log later"); 15216b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: error %d during state transition " 15226b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s): iv_newstate already handled.\n", 15236b4cac81SBjoern A. Zeeb __func__, error, 15246b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 15256b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 15266b4cac81SBjoern A. Zeeb return (0); 15276b4cac81SBjoern A. Zeeb } 15286b4cac81SBjoern A. Zeeb 15296b4cac81SBjoern A. Zeeb if (error != 0) { 15306b4cac81SBjoern A. Zeeb /* XXX-BZ currently expected so ignore. */ 15316b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: error %d during state transition " 15326b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s)\n", __func__, error, 15336b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 15346b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 15356b4cac81SBjoern A. Zeeb /* return (error); */ 15366b4cac81SBjoern A. Zeeb } 15376b4cac81SBjoern A. Zeeb 15386b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE) 15396b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x calling net80211 parent\n", 15406b4cac81SBjoern A. Zeeb __func__, __LINE__, vap, nstate, arg); 15416b4cac81SBjoern A. Zeeb 15426b4cac81SBjoern A. Zeeb return (lvif->iv_newstate(vap, nstate, arg)); 15436b4cac81SBjoern A. Zeeb } 15446b4cac81SBjoern A. Zeeb 15456b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 15466b4cac81SBjoern A. Zeeb 15476b4cac81SBjoern A. Zeeb static int 15486b4cac81SBjoern A. Zeeb lkpi_ic_wme_update(struct ieee80211com *ic) 15496b4cac81SBjoern A. Zeeb { 15506b4cac81SBjoern A. Zeeb /* This needs queuing and go at the right moment. */ 15516b4cac81SBjoern A. Zeeb #ifdef WITH_WME_UPDATE 15526b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 15536b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 15546b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 15556b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 15566b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 15576b4cac81SBjoern A. Zeeb struct chanAccParams chp; 15586b4cac81SBjoern A. Zeeb struct wmeParams wmeparr[WME_NUM_AC]; 15596b4cac81SBjoern A. Zeeb struct ieee80211_tx_queue_params txqp; 15606b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 15616b4cac81SBjoern A. Zeeb int error; 15626b4cac81SBjoern A. Zeeb uint16_t ac; 15636b4cac81SBjoern A. Zeeb #endif 15646b4cac81SBjoern A. Zeeb 15656b4cac81SBjoern A. Zeeb IMPROVE(); 15666b4cac81SBjoern A. Zeeb KASSERT(WME_NUM_AC == IEEE80211_NUM_ACS, ("%s: WME_NUM_AC %d != " 15676b4cac81SBjoern A. Zeeb "IEEE80211_NUM_ACS %d\n", __func__, WME_NUM_AC, IEEE80211_NUM_ACS)); 15686b4cac81SBjoern A. Zeeb 15696b4cac81SBjoern A. Zeeb #ifdef WITH_WME_UPDATE 15706b4cac81SBjoern A. Zeeb vap = TAILQ_FIRST(&ic->ic_vaps); 15716b4cac81SBjoern A. Zeeb if (vap == NULL) 15726b4cac81SBjoern A. Zeeb return (0); 15736b4cac81SBjoern A. Zeeb 15746b4cac81SBjoern A. Zeeb /* We should factor this out into per-vap (*wme_update). */ 15756b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 15766b4cac81SBjoern A. Zeeb if (lhw->ops->conf_tx == NULL) 15776b4cac81SBjoern A. Zeeb return (0); 15786b4cac81SBjoern A. Zeeb 15796b4cac81SBjoern A. Zeeb /* XXX-BZ check amount of hw queues */ 15806b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 15816b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 15826b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 15836b4cac81SBjoern A. Zeeb 15846b4cac81SBjoern A. Zeeb ieee80211_wme_ic_getparams(ic, &chp); 15856b4cac81SBjoern A. Zeeb IEEE80211_LOCK(ic); 15866b4cac81SBjoern A. Zeeb for (ac = 0; ac < WME_NUM_AC; ac++) 15876b4cac81SBjoern A. Zeeb wmeparr[ac] = chp.cap_wmeParams[ac]; 15886b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(ic); 15896b4cac81SBjoern A. Zeeb 15906b4cac81SBjoern A. Zeeb /* Configure tx queues (conf_tx) & send BSS_CHANGED_QOS. */ 15916b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 15926b4cac81SBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 15936b4cac81SBjoern A. Zeeb struct wmeParams *wmep; 15946b4cac81SBjoern A. Zeeb 15956b4cac81SBjoern A. Zeeb /* XXX-BZ should keep this in lvif? */ 15966b4cac81SBjoern A. Zeeb wmep = &wmeparr[ac]; 15976b4cac81SBjoern A. Zeeb bzero(&txqp, sizeof(txqp)); 15986b4cac81SBjoern A. Zeeb txqp.cw_min = wmep->wmep_logcwmin; 15996b4cac81SBjoern A. Zeeb txqp.cw_max = wmep->wmep_logcwmax; 16006b4cac81SBjoern A. Zeeb txqp.txop = wmep->wmep_txopLimit; 16016b4cac81SBjoern A. Zeeb txqp.aifs = wmep->wmep_aifsn; 16026b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_conf_tx(hw, vif, ac, &txqp); 16036b4cac81SBjoern A. Zeeb if (error != 0) 16046b4cac81SBjoern A. Zeeb printf("%s: conf_tx ac %u failed %d\n", 16056b4cac81SBjoern A. Zeeb __func__, ac, error); 16066b4cac81SBjoern A. Zeeb } 16076b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 16086b4cac81SBjoern A. Zeeb changed = BSS_CHANGED_QOS; 16096b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 16106b4cac81SBjoern A. Zeeb #endif 16116b4cac81SBjoern A. Zeeb 16126b4cac81SBjoern A. Zeeb return (0); 16136b4cac81SBjoern A. Zeeb } 16146b4cac81SBjoern A. Zeeb 16156b4cac81SBjoern A. Zeeb static struct ieee80211vap * 16166b4cac81SBjoern A. Zeeb lkpi_ic_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], 16176b4cac81SBjoern A. Zeeb int unit, enum ieee80211_opmode opmode, int flags, 16186b4cac81SBjoern A. Zeeb const uint8_t bssid[IEEE80211_ADDR_LEN], 16196b4cac81SBjoern A. Zeeb const uint8_t mac[IEEE80211_ADDR_LEN]) 16206b4cac81SBjoern A. Zeeb { 16216b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 16226b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 16236b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 16246b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 16256b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 16266b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 16276b4cac81SBjoern A. Zeeb size_t len; 16286b4cac81SBjoern A. Zeeb int error; 16296b4cac81SBjoern A. Zeeb 16306b4cac81SBjoern A. Zeeb if (!TAILQ_EMPTY(&ic->ic_vaps)) /* 1 so far. Add <n> once this works. */ 16316b4cac81SBjoern A. Zeeb return (NULL); 16326b4cac81SBjoern A. Zeeb 16336b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 16346b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 16356b4cac81SBjoern A. Zeeb 16366b4cac81SBjoern A. Zeeb len = sizeof(*lvif); 16376b4cac81SBjoern A. Zeeb len += hw->vif_data_size; /* vif->drv_priv */ 16386b4cac81SBjoern A. Zeeb 16396b4cac81SBjoern A. Zeeb lvif = malloc(len, M_80211_VAP, M_WAITOK | M_ZERO); 16406b4cac81SBjoern A. Zeeb mtx_init(&lvif->mtx, "lvif", NULL, MTX_DEF); 16416b4cac81SBjoern A. Zeeb TAILQ_INIT(&lvif->lsta_head); 16426b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 16436b4cac81SBjoern A. Zeeb 16446b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 16456b4cac81SBjoern A. Zeeb memcpy(vif->addr, mac, IEEE80211_ADDR_LEN); 16466b4cac81SBjoern A. Zeeb vif->p2p = false; 16476b4cac81SBjoern A. Zeeb vif->probe_req_reg = false; 16486b4cac81SBjoern A. Zeeb vif->type = lkpi_opmode_to_vif_type(opmode); 16496b4cac81SBjoern A. Zeeb lvif->wdev.iftype = vif->type; 16506b4cac81SBjoern A. Zeeb /* Need to fill in other fields as well. */ 16516b4cac81SBjoern A. Zeeb IMPROVE(); 16526b4cac81SBjoern A. Zeeb 16536b4cac81SBjoern A. Zeeb /* XXX-BZ hardcoded for now! */ 16546b4cac81SBjoern A. Zeeb #if 1 16556b4cac81SBjoern A. Zeeb vif->chanctx_conf = NULL; 16566b4cac81SBjoern A. Zeeb vif->bss_conf.idle = true; 16576b4cac81SBjoern A. Zeeb vif->bss_conf.ps = false; 16586b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.width = NL80211_CHAN_WIDTH_20_NOHT; 16596b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble = false; /* vap->iv_flags IEEE80211_F_SHPREAMBLE */ 16606b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot = false; /* vap->iv_flags IEEE80211_F_SHSLOT */ 16616b4cac81SBjoern A. Zeeb vif->bss_conf.qos = false; 16626b4cac81SBjoern A. Zeeb vif->bss_conf.use_cts_prot = false; /* vap->iv_protmode */ 16636b4cac81SBjoern A. Zeeb vif->bss_conf.ht_operation_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONE; 16646b4cac81SBjoern A. Zeeb vif->bss_conf.assoc = false; 16656b4cac81SBjoern A. Zeeb vif->bss_conf.aid = 0; 16666b4cac81SBjoern A. Zeeb #endif 16676b4cac81SBjoern A. Zeeb #if 0 16686b4cac81SBjoern A. Zeeb vif->bss_conf.dtim_period = 0; /* IEEE80211_DTIM_DEFAULT ; must stay 0. */ 16696b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(vif->bss_conf.bssid, bssid); 16706b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = ic->ic_bintval; 16716b4cac81SBjoern A. Zeeb /* iwlwifi bug. */ 16726b4cac81SBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16) 16736b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = 16; 16746b4cac81SBjoern A. Zeeb #endif 16756b4cac81SBjoern A. Zeeb IMPROVE(); 16766b4cac81SBjoern A. Zeeb 16776b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_start(hw); 16786b4cac81SBjoern A. Zeeb if (error != 0) { 16796b4cac81SBjoern A. Zeeb printf("%s: failed to start hw: %d\n", __func__, error); 16806b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 16816b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 16826b4cac81SBjoern A. Zeeb return (NULL); 16836b4cac81SBjoern A. Zeeb } 16846b4cac81SBjoern A. Zeeb 16856b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_add_interface(hw, vif); 16866b4cac81SBjoern A. Zeeb if (error != 0) { 16876b4cac81SBjoern A. Zeeb IMPROVE(); /* XXX-BZ mo_stop()? */ 16886b4cac81SBjoern A. Zeeb printf("%s: failed to add interface: %d\n", __func__, error); 16896b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 16906b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 16916b4cac81SBjoern A. Zeeb return (NULL); 16926b4cac81SBjoern A. Zeeb } 16936b4cac81SBjoern A. Zeeb 16946b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 16956b4cac81SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lhw->lvif_head, lvif, lvif_entry); 16966b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 16976b4cac81SBjoern A. Zeeb 16986b4cac81SBjoern A. Zeeb /* Set bss_info. */ 16996b4cac81SBjoern A. Zeeb changed = 0; 17006b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 17016b4cac81SBjoern A. Zeeb 17026b4cac81SBjoern A. Zeeb /* conf_tx setup; default WME? */ 17036b4cac81SBjoern A. Zeeb 17046b4cac81SBjoern A. Zeeb /* Force MC init. */ 17056b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(ic, true); 17066b4cac81SBjoern A. Zeeb 17076b4cac81SBjoern A. Zeeb IMPROVE(); 17086b4cac81SBjoern A. Zeeb 17096b4cac81SBjoern A. Zeeb ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid); 17106b4cac81SBjoern A. Zeeb 17116b4cac81SBjoern A. Zeeb /* Override with LinuxKPI method so we can drive mac80211/cfg80211. */ 17126b4cac81SBjoern A. Zeeb lvif->iv_newstate = vap->iv_newstate; 17136b4cac81SBjoern A. Zeeb vap->iv_newstate = lkpi_iv_newstate; 17146b4cac81SBjoern A. Zeeb 17156b4cac81SBjoern A. Zeeb /* Key management. */ 17166b4cac81SBjoern A. Zeeb if (lhw->ops->set_key != NULL) { 17176b4cac81SBjoern A. Zeeb #ifdef TRY_HW_CRYPTO 17186b4cac81SBjoern A. Zeeb vap->iv_key_set = lkpi_iv_key_set; 17196b4cac81SBjoern A. Zeeb vap->iv_key_delete = lkpi_iv_key_delete; 17206b4cac81SBjoern A. Zeeb #endif 17216b4cac81SBjoern A. Zeeb } 17226b4cac81SBjoern A. Zeeb 17236b4cac81SBjoern A. Zeeb ieee80211_ratectl_init(vap); 17246b4cac81SBjoern A. Zeeb 17256b4cac81SBjoern A. Zeeb /* Complete setup. */ 17266b4cac81SBjoern A. Zeeb ieee80211_vap_attach(vap, ieee80211_media_change, 17276b4cac81SBjoern A. Zeeb ieee80211_media_status, mac); 17286b4cac81SBjoern A. Zeeb 17296b4cac81SBjoern A. Zeeb if (hw->max_listen_interval == 0) 17306b4cac81SBjoern A. Zeeb hw->max_listen_interval = 7 * (ic->ic_lintval / ic->ic_bintval); 17316b4cac81SBjoern A. Zeeb hw->conf.listen_interval = hw->max_listen_interval; 17326b4cac81SBjoern A. Zeeb ic->ic_set_channel(ic); 17336b4cac81SBjoern A. Zeeb 17346b4cac81SBjoern A. Zeeb /* XXX-BZ do we need to be able to update these? */ 17356b4cac81SBjoern A. Zeeb hw->wiphy->frag_threshold = vap->iv_fragthreshold; 17366b4cac81SBjoern A. Zeeb lkpi_80211_mo_set_frag_threshold(hw, vap->iv_fragthreshold); 17376b4cac81SBjoern A. Zeeb hw->wiphy->rts_threshold = vap->iv_rtsthreshold; 17386b4cac81SBjoern A. Zeeb lkpi_80211_mo_set_rts_threshold(hw, vap->iv_rtsthreshold); 17396b4cac81SBjoern A. Zeeb /* any others? */ 17406b4cac81SBjoern A. Zeeb IMPROVE(); 17416b4cac81SBjoern A. Zeeb 17426b4cac81SBjoern A. Zeeb return (vap); 17436b4cac81SBjoern A. Zeeb } 17446b4cac81SBjoern A. Zeeb 17456b4cac81SBjoern A. Zeeb static void 17466b4cac81SBjoern A. Zeeb lkpi_ic_vap_delete(struct ieee80211vap *vap) 17476b4cac81SBjoern A. Zeeb { 17486b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 17496b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 17506b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 17516b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 17526b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 17536b4cac81SBjoern A. Zeeb 17546b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 17556b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 17566b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 17576b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 17586b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 17596b4cac81SBjoern A. Zeeb 17606b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 17616b4cac81SBjoern A. Zeeb TAILQ_REMOVE(&lhw->lvif_head, lvif, lvif_entry); 17626b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 17636b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_interface(hw, vif); 17646b4cac81SBjoern A. Zeeb 17656b4cac81SBjoern A. Zeeb ieee80211_ratectl_deinit(vap); 17666b4cac81SBjoern A. Zeeb ieee80211_vap_detach(vap); 17676b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 17686b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 17696b4cac81SBjoern A. Zeeb } 17706b4cac81SBjoern A. Zeeb 17716b4cac81SBjoern A. Zeeb static void 17726b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast(struct ieee80211com *ic) 17736b4cac81SBjoern A. Zeeb { 17746b4cac81SBjoern A. Zeeb 17756b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(ic, false); 17766b4cac81SBjoern A. Zeeb TRACEOK(); 17776b4cac81SBjoern A. Zeeb } 17786b4cac81SBjoern A. Zeeb 17796b4cac81SBjoern A. Zeeb static void 17806b4cac81SBjoern A. Zeeb lkpi_ic_update_promisc(struct ieee80211com *ic) 17816b4cac81SBjoern A. Zeeb { 17826b4cac81SBjoern A. Zeeb 17836b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 17846b4cac81SBjoern A. Zeeb } 17856b4cac81SBjoern A. Zeeb 17866b4cac81SBjoern A. Zeeb static void 17876b4cac81SBjoern A. Zeeb lkpi_ic_update_chw(struct ieee80211com *ic) 17886b4cac81SBjoern A. Zeeb { 17896b4cac81SBjoern A. Zeeb 17906b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 17916b4cac81SBjoern A. Zeeb } 17926b4cac81SBjoern A. Zeeb 17936b4cac81SBjoern A. Zeeb /* Start / stop device. */ 17946b4cac81SBjoern A. Zeeb static void 17956b4cac81SBjoern A. Zeeb lkpi_ic_parent(struct ieee80211com *ic) 17966b4cac81SBjoern A. Zeeb { 17976b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 17986b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 17996b4cac81SBjoern A. Zeeb int error; 18006b4cac81SBjoern A. Zeeb bool start_all; 18016b4cac81SBjoern A. Zeeb 18026b4cac81SBjoern A. Zeeb IMPROVE(); 18036b4cac81SBjoern A. Zeeb 18046b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 18056b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 18066b4cac81SBjoern A. Zeeb start_all = false; 18076b4cac81SBjoern A. Zeeb 18086b4cac81SBjoern A. Zeeb if (ic->ic_nrunning > 0) { 18096b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_start(hw); 18106b4cac81SBjoern A. Zeeb if (error == 0) 18116b4cac81SBjoern A. Zeeb start_all = true; 18126b4cac81SBjoern A. Zeeb } else { 18136b4cac81SBjoern A. Zeeb lkpi_80211_mo_stop(hw); 18146b4cac81SBjoern A. Zeeb } 18156b4cac81SBjoern A. Zeeb 18166b4cac81SBjoern A. Zeeb if (start_all) 18176b4cac81SBjoern A. Zeeb ieee80211_start_all(ic); 18186b4cac81SBjoern A. Zeeb } 18196b4cac81SBjoern A. Zeeb 18206b4cac81SBjoern A. Zeeb bool 18216b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_is_ie_id_in_ie_buf(const u8 ie, const u8 *ie_ids, 18226b4cac81SBjoern A. Zeeb size_t ie_ids_len) 18236b4cac81SBjoern A. Zeeb { 18246b4cac81SBjoern A. Zeeb int i; 18256b4cac81SBjoern A. Zeeb 18266b4cac81SBjoern A. Zeeb for (i = 0; i < ie_ids_len; i++) { 18276b4cac81SBjoern A. Zeeb if (ie == *ie_ids) 18286b4cac81SBjoern A. Zeeb return (true); 18296b4cac81SBjoern A. Zeeb } 18306b4cac81SBjoern A. Zeeb 18316b4cac81SBjoern A. Zeeb return (false); 18326b4cac81SBjoern A. Zeeb } 18336b4cac81SBjoern A. Zeeb 18346b4cac81SBjoern A. Zeeb /* Return true if skipped; false if error. */ 18356b4cac81SBjoern A. Zeeb bool 18366b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ie_advance(size_t *xp, const u8 *ies, size_t ies_len) 18376b4cac81SBjoern A. Zeeb { 18386b4cac81SBjoern A. Zeeb size_t x; 18396b4cac81SBjoern A. Zeeb uint8_t l; 18406b4cac81SBjoern A. Zeeb 18416b4cac81SBjoern A. Zeeb x = *xp; 18426b4cac81SBjoern A. Zeeb 18436b4cac81SBjoern A. Zeeb KASSERT(x < ies_len, ("%s: x %zu ies_len %zu ies %p\n", 18446b4cac81SBjoern A. Zeeb __func__, x, ies_len, ies)); 18456b4cac81SBjoern A. Zeeb l = ies[x + 1]; 18466b4cac81SBjoern A. Zeeb x += 2 + l; 18476b4cac81SBjoern A. Zeeb 18486b4cac81SBjoern A. Zeeb if (x > ies_len) 18496b4cac81SBjoern A. Zeeb return (false); 18506b4cac81SBjoern A. Zeeb 18516b4cac81SBjoern A. Zeeb *xp = x; 18526b4cac81SBjoern A. Zeeb return (true); 18536b4cac81SBjoern A. Zeeb } 18546b4cac81SBjoern A. Zeeb 18556b4cac81SBjoern A. Zeeb static int 18566b4cac81SBjoern A. Zeeb lkpi_ieee80211_probereq_ie_alloc(struct ieee80211vap *vap, 18576b4cac81SBjoern A. Zeeb struct ieee80211com *ic, struct ieee80211_scan_ies *scan_ies, 18586b4cac81SBjoern A. Zeeb const uint8_t *ssid, size_t ssidlen) 18596b4cac81SBjoern A. Zeeb { 18606b4cac81SBjoern A. Zeeb 18616b4cac81SBjoern A. Zeeb return (ieee80211_probereq_ie(vap, ic, 18626b4cac81SBjoern A. Zeeb &scan_ies->common_ies, &scan_ies->common_ie_len, 18636b4cac81SBjoern A. Zeeb ssid, ssidlen, true)); 18646b4cac81SBjoern A. Zeeb } 18656b4cac81SBjoern A. Zeeb 18666b4cac81SBjoern A. Zeeb static void 18676b4cac81SBjoern A. Zeeb lkpi_ic_scan_start(struct ieee80211com *ic) 18686b4cac81SBjoern A. Zeeb { 18696b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 18706b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 18716b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 18726b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 18736b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 18746b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 18756b4cac81SBjoern A. Zeeb int error; 18766b4cac81SBjoern A. Zeeb 18776b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 18786b4cac81SBjoern A. Zeeb if ((lhw->scan_flags & LKPI_SCAN_RUNNING) != 0) { 18796b4cac81SBjoern A. Zeeb /* A scan is still running. */ 18806b4cac81SBjoern A. Zeeb return; 18816b4cac81SBjoern A. Zeeb } 18826b4cac81SBjoern A. Zeeb 18836b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 18846b4cac81SBjoern A. Zeeb vap = ss->ss_vap; 18856b4cac81SBjoern A. Zeeb if (vap->iv_state != IEEE80211_S_SCAN) { 18866b4cac81SBjoern A. Zeeb /* Do not start a scan for now. */ 18876b4cac81SBjoern A. Zeeb return; 18886b4cac81SBjoern A. Zeeb } 18896b4cac81SBjoern A. Zeeb 18906b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 18916b4cac81SBjoern A. Zeeb if ((ic->ic_flags_ext & IEEE80211_FEXT_SCAN_OFFLOAD) == 0) { 18926b4cac81SBjoern A. Zeeb 18936b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 18946b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 1895086be6a8SBjoern A. Zeeb 1896086be6a8SBjoern A. Zeeb if (vap->iv_state == IEEE80211_S_SCAN) 1897086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, false); 1898086be6a8SBjoern A. Zeeb 18996b4cac81SBjoern A. Zeeb lkpi_80211_mo_sw_scan_start(hw, vif, vif->addr); 19006b4cac81SBjoern A. Zeeb /* net80211::scan_start() handled PS for us. */ 19016b4cac81SBjoern A. Zeeb IMPROVE(); 19026b4cac81SBjoern A. Zeeb /* XXX Also means it is too late to flush queues? 19036b4cac81SBjoern A. Zeeb * need to check iv_sta_ps or overload? */ 19046b4cac81SBjoern A. Zeeb /* XXX want to adjust ss end time/ maxdwell? */ 19056b4cac81SBjoern A. Zeeb 19066b4cac81SBjoern A. Zeeb } else { 19076b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 19086b4cac81SBjoern A. Zeeb struct ieee80211_scan_request *hw_req; 19096b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *lc, **cpp; 19106b4cac81SBjoern A. Zeeb struct cfg80211_ssid *ssids; 19116b4cac81SBjoern A. Zeeb struct cfg80211_scan_6ghz_params *s6gp; 19126b4cac81SBjoern A. Zeeb size_t chan_len, nchan, ssids_len, s6ghzlen; 19136b4cac81SBjoern A. Zeeb int i; 19146b4cac81SBjoern A. Zeeb 19156b4cac81SBjoern A. Zeeb ssids_len = ss->ss_nssid * sizeof(*ssids);; 19166b4cac81SBjoern A. Zeeb s6ghzlen = 0 * (sizeof(*s6gp)); /* XXX-BZ */ 19176b4cac81SBjoern A. Zeeb 19186b4cac81SBjoern A. Zeeb nchan = 0; 19196b4cac81SBjoern A. Zeeb for (i = ss->ss_next; i < ss->ss_last; i++) 19206b4cac81SBjoern A. Zeeb nchan++; 19216b4cac81SBjoern A. Zeeb chan_len = nchan * (sizeof(lc) + sizeof(*lc)); 19226b4cac81SBjoern A. Zeeb 19236b4cac81SBjoern A. Zeeb KASSERT(lhw->hw_req == NULL, ("%s: ic %p lhw %p hw_req %p " 19246b4cac81SBjoern A. Zeeb "!= NULL\n", __func__, ic, lhw, lhw->hw_req)); 19256b4cac81SBjoern A. Zeeb lhw->hw_req = hw_req = malloc(sizeof(*hw_req) + ssids_len + 19266b4cac81SBjoern A. Zeeb s6ghzlen + chan_len, M_LKPI80211, M_WAITOK | M_ZERO); 19276b4cac81SBjoern A. Zeeb 19286b4cac81SBjoern A. Zeeb error = lkpi_ieee80211_probereq_ie_alloc(vap, ic, 19296b4cac81SBjoern A. Zeeb &hw_req->ies, NULL, -1); 19306b4cac81SBjoern A. Zeeb if (error != 0) 19316b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: probereq_ie returned %d\n", 19326b4cac81SBjoern A. Zeeb __func__, error); 19336b4cac81SBjoern A. Zeeb 19346b4cac81SBjoern A. Zeeb hw_req->req.flags = 0; /* XXX ??? */ 19356b4cac81SBjoern A. Zeeb /* hw_req->req.wdev */ 19366b4cac81SBjoern A. Zeeb hw_req->req.wiphy = hw->wiphy; 19376b4cac81SBjoern A. Zeeb hw_req->req.no_cck = false; /* XXX */ 19386b4cac81SBjoern A. Zeeb #if 0 19396b4cac81SBjoern A. Zeeb /* This seems to pessimise default scanning behaviour. */ 19406b4cac81SBjoern A. Zeeb hw_req->req.duration_mandatory = TICKS_2_USEC(ss->ss_mindwell); 19416b4cac81SBjoern A. Zeeb hw_req->req.duration = TICKS_2_USEC(ss->ss_maxdwell); 19426b4cac81SBjoern A. Zeeb #endif 19436b4cac81SBjoern A. Zeeb #ifdef __notyet__ 19446b4cac81SBjoern A. Zeeb hw_req->req.flags |= NL80211_SCAN_FLAG_RANDOM_ADDR; 19456b4cac81SBjoern A. Zeeb memcpy(hw_req->req.mac_addr, xxx, IEEE80211_ADDR_LEN); 19466b4cac81SBjoern A. Zeeb memset(hw_req->req.mac_addr_mask, 0xxx, IEEE80211_ADDR_LEN); 19476b4cac81SBjoern A. Zeeb #endif 19486b4cac81SBjoern A. Zeeb #if 0 19496b4cac81SBjoern A. Zeeb hw_req->req.ie_len = ; 19506b4cac81SBjoern A. Zeeb hw_req->req.ie = ; 19516b4cac81SBjoern A. Zeeb #endif 19526b4cac81SBjoern A. Zeeb 19536b4cac81SBjoern A. Zeeb hw_req->req.n_channels = nchan; 19546b4cac81SBjoern A. Zeeb cpp = (struct linuxkpi_ieee80211_channel **)(hw_req + 1); 19556b4cac81SBjoern A. Zeeb lc = (struct linuxkpi_ieee80211_channel *)(cpp + nchan); 19566b4cac81SBjoern A. Zeeb for (i = 0; i < nchan; i++) { 19576b4cac81SBjoern A. Zeeb *(cpp + i) = 19586b4cac81SBjoern A. Zeeb (struct linuxkpi_ieee80211_channel *)(lc + i); 19596b4cac81SBjoern A. Zeeb } 19606b4cac81SBjoern A. Zeeb for (i = 0; i < nchan; i++) { 19616b4cac81SBjoern A. Zeeb c = ss->ss_chans[ss->ss_next + i]; 19626b4cac81SBjoern A. Zeeb 19636b4cac81SBjoern A. Zeeb lc->hw_value = c->ic_ieee; 19646b4cac81SBjoern A. Zeeb lc->center_freq = c->ic_freq; 19656b4cac81SBjoern A. Zeeb /* lc->flags */ 19666b4cac81SBjoern A. Zeeb lc->band = lkpi_net80211_chan_to_nl80211_band(c); 19676b4cac81SBjoern A. Zeeb lc->max_power = c->ic_maxpower; 19686b4cac81SBjoern A. Zeeb /* lc-> ... */ 19696b4cac81SBjoern A. Zeeb lc++; 19706b4cac81SBjoern A. Zeeb } 19716b4cac81SBjoern A. Zeeb 19726b4cac81SBjoern A. Zeeb hw_req->req.n_ssids = ss->ss_nssid; 19736b4cac81SBjoern A. Zeeb if (hw_req->req.n_ssids > 0) { 19746b4cac81SBjoern A. Zeeb ssids = (struct cfg80211_ssid *)lc; 19756b4cac81SBjoern A. Zeeb hw_req->req.ssids = ssids; 19766b4cac81SBjoern A. Zeeb for (i = 0; i < ss->ss_nssid; i++) { 19776b4cac81SBjoern A. Zeeb ssids->ssid_len = ss->ss_ssid[i].len; 19786b4cac81SBjoern A. Zeeb memcpy(ssids->ssid, ss->ss_ssid[i].ssid, 19796b4cac81SBjoern A. Zeeb ss->ss_ssid[i].len); 19806b4cac81SBjoern A. Zeeb ssids++; 19816b4cac81SBjoern A. Zeeb } 19826b4cac81SBjoern A. Zeeb s6gp = (struct cfg80211_scan_6ghz_params *)ssids; 19836b4cac81SBjoern A. Zeeb } else { 19846b4cac81SBjoern A. Zeeb s6gp = (struct cfg80211_scan_6ghz_params *)lc; 19856b4cac81SBjoern A. Zeeb } 19866b4cac81SBjoern A. Zeeb 19876b4cac81SBjoern A. Zeeb /* 6GHz one day. */ 19886b4cac81SBjoern A. Zeeb hw_req->req.n_6ghz_params = 0; 19896b4cac81SBjoern A. Zeeb hw_req->req.scan_6ghz_params = NULL; 19906b4cac81SBjoern A. Zeeb hw_req->req.scan_6ghz = false; /* Weird boolean; not what you think. */ 19916b4cac81SBjoern A. Zeeb /* s6gp->... */ 19926b4cac81SBjoern A. Zeeb 19936b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 19946b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 19956b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_hw_scan(hw, vif, hw_req); 19966b4cac81SBjoern A. Zeeb if (error != 0) { 19976b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: hw_scan returned %d\n", 19986b4cac81SBjoern A. Zeeb __func__, error); 19996b4cac81SBjoern A. Zeeb ieee80211_cancel_scan(vap); 20006b4cac81SBjoern A. Zeeb free(hw_req->ies.common_ies, M_80211_VAP); 20016b4cac81SBjoern A. Zeeb free(hw_req, M_LKPI80211); 20026b4cac81SBjoern A. Zeeb lhw->hw_req = NULL; 20036b4cac81SBjoern A. Zeeb } 20046b4cac81SBjoern A. Zeeb } 20056b4cac81SBjoern A. Zeeb } 20066b4cac81SBjoern A. Zeeb 20076b4cac81SBjoern A. Zeeb static void 20086b4cac81SBjoern A. Zeeb lkpi_ic_scan_end(struct ieee80211com *ic) 20096b4cac81SBjoern A. Zeeb { 20106b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 20116b4cac81SBjoern A. Zeeb 20126b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 20136b4cac81SBjoern A. Zeeb if ((lhw->scan_flags & LKPI_SCAN_RUNNING) == 0) { 20146b4cac81SBjoern A. Zeeb return; 20156b4cac81SBjoern A. Zeeb } 20166b4cac81SBjoern A. Zeeb 20176b4cac81SBjoern A. Zeeb if (ic->ic_flags_ext & IEEE80211_FEXT_SCAN_OFFLOAD) { 20186b4cac81SBjoern A. Zeeb /* Nothing to do. */ 20196b4cac81SBjoern A. Zeeb } else { 20206b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 20216b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 20226b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 20236b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 20246b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 20256b4cac81SBjoern A. Zeeb 20266b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 20276b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 20286b4cac81SBjoern A. Zeeb vap = ss->ss_vap; 20296b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 20306b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 20316b4cac81SBjoern A. Zeeb lkpi_80211_mo_sw_scan_complete(hw, vif); 20326b4cac81SBjoern A. Zeeb 20336b4cac81SBjoern A. Zeeb /* Send PS to stop buffering if n80211 does not for us? */ 2034086be6a8SBjoern A. Zeeb 2035086be6a8SBjoern A. Zeeb if (vap->iv_state == IEEE80211_S_SCAN) 2036086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true); 20376b4cac81SBjoern A. Zeeb } 20386b4cac81SBjoern A. Zeeb } 20396b4cac81SBjoern A. Zeeb 20406b4cac81SBjoern A. Zeeb static void 20416b4cac81SBjoern A. Zeeb lkpi_ic_scan_curchan_nada(struct ieee80211_scan_state *ss __unused, 20426b4cac81SBjoern A. Zeeb unsigned long maxdwell __unused) 20436b4cac81SBjoern A. Zeeb { 20446b4cac81SBjoern A. Zeeb } 20456b4cac81SBjoern A. Zeeb 20466b4cac81SBjoern A. Zeeb static void 20476b4cac81SBjoern A. Zeeb lkpi_ic_set_channel(struct ieee80211com *ic) 20486b4cac81SBjoern A. Zeeb { 20496b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 20506b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 20516b4cac81SBjoern A. Zeeb int error; 20526b4cac81SBjoern A. Zeeb 20536b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 20546b4cac81SBjoern A. Zeeb #ifdef __no_longer__ 20556b4cac81SBjoern A. Zeeb /* For now only be concerned if scanning. */ 20566b4cac81SBjoern A. Zeeb if ((lhw->scan_flags & LKPI_SCAN_RUNNING) == 0) { 20576b4cac81SBjoern A. Zeeb IMPROVE(); 20586b4cac81SBjoern A. Zeeb return; 20596b4cac81SBjoern A. Zeeb } 20606b4cac81SBjoern A. Zeeb #endif 20616b4cac81SBjoern A. Zeeb 20626b4cac81SBjoern A. Zeeb if (ic->ic_flags_ext & IEEE80211_FEXT_SCAN_OFFLOAD) { 20636b4cac81SBjoern A. Zeeb /* 20646b4cac81SBjoern A. Zeeb * AP scanning is taken care of by firmware, so only switch 20656b4cac81SBjoern A. Zeeb * channels in monitor mode (maybe, maybe not; to be 20666b4cac81SBjoern A. Zeeb * investigated at the right time). 20676b4cac81SBjoern A. Zeeb */ 20686b4cac81SBjoern A. Zeeb if (ic->ic_opmode == IEEE80211_M_MONITOR) { 20696b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 20706b4cac81SBjoern A. Zeeb } 20716b4cac81SBjoern A. Zeeb } else { 20726b4cac81SBjoern A. Zeeb struct ieee80211_channel *c = ic->ic_curchan; 20736b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 20746b4cac81SBjoern A. Zeeb struct cfg80211_chan_def chandef; 20756b4cac81SBjoern A. Zeeb 20766b4cac81SBjoern A. Zeeb if (c == NULL || c == IEEE80211_CHAN_ANYC || 20776b4cac81SBjoern A. Zeeb lhw->ops->config == NULL) { 20786b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: c %p ops->config %p\n", __func__, 20796b4cac81SBjoern A. Zeeb c, lhw->ops->config); 20806b4cac81SBjoern A. Zeeb return; 20816b4cac81SBjoern A. Zeeb } 20826b4cac81SBjoern A. Zeeb 20836b4cac81SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, c); 20846b4cac81SBjoern A. Zeeb if (chan == NULL) { 20856b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: c %p chan %p\n", __func__, 20866b4cac81SBjoern A. Zeeb c, chan); 20876b4cac81SBjoern A. Zeeb return; 20886b4cac81SBjoern A. Zeeb } 20896b4cac81SBjoern A. Zeeb 20906b4cac81SBjoern A. Zeeb memset(&chandef, 0, sizeof(chandef)); 20916b4cac81SBjoern A. Zeeb chandef.chan = chan; 20926b4cac81SBjoern A. Zeeb chandef.width = NL80211_CHAN_WIDTH_20_NOHT; 20936b4cac81SBjoern A. Zeeb chandef.center_freq1 = chandef.chan->center_freq; 20946b4cac81SBjoern A. Zeeb 20956b4cac81SBjoern A. Zeeb /* XXX max power for scanning? */ 20966b4cac81SBjoern A. Zeeb IMPROVE(); 20976b4cac81SBjoern A. Zeeb 20986b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 20996b4cac81SBjoern A. Zeeb hw->conf.chandef = chandef; 21006b4cac81SBjoern A. Zeeb 21016b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_CHANNEL); 21026b4cac81SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) { 21036b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: config %#0x returned %d\n", 21046b4cac81SBjoern A. Zeeb __func__, IEEE80211_CONF_CHANGE_CHANNEL, error); 21056b4cac81SBjoern A. Zeeb /* XXX should we unroll to the previous chandef? */ 21066b4cac81SBjoern A. Zeeb IMPROVE(); 21076b4cac81SBjoern A. Zeeb } else { 21086b4cac81SBjoern A. Zeeb /* Update radiotap channels as well. */ 21096b4cac81SBjoern A. Zeeb lhw->rtap_tx.wt_chan_freq = htole16(c->ic_freq); 21106b4cac81SBjoern A. Zeeb lhw->rtap_tx.wt_chan_flags = htole16(c->ic_flags); 21116b4cac81SBjoern A. Zeeb lhw->rtap_rx.wr_chan_freq = htole16(c->ic_freq); 21126b4cac81SBjoern A. Zeeb lhw->rtap_rx.wr_chan_flags = htole16(c->ic_flags); 21136b4cac81SBjoern A. Zeeb } 21146b4cac81SBjoern A. Zeeb 21156b4cac81SBjoern A. Zeeb /* Currently PS is hard coded off! Not sure it belongs here. */ 21166b4cac81SBjoern A. Zeeb IMPROVE(); 21176b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, SUPPORTS_PS) && 21186b4cac81SBjoern A. Zeeb (hw->conf.flags & IEEE80211_CONF_PS) != 0) { 21196b4cac81SBjoern A. Zeeb hw->conf.flags &= ~IEEE80211_CONF_PS; 21206b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_PS); 21216b4cac81SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) 21226b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: config %#0x returned " 21236b4cac81SBjoern A. Zeeb "%d\n", __func__, IEEE80211_CONF_CHANGE_PS, 21246b4cac81SBjoern A. Zeeb error); 21256b4cac81SBjoern A. Zeeb } 21266b4cac81SBjoern A. Zeeb } 21276b4cac81SBjoern A. Zeeb } 21286b4cac81SBjoern A. Zeeb 21296b4cac81SBjoern A. Zeeb static struct ieee80211_node * 21306b4cac81SBjoern A. Zeeb lkpi_ic_node_alloc(struct ieee80211vap *vap, 21316b4cac81SBjoern A. Zeeb const uint8_t mac[IEEE80211_ADDR_LEN]) 21326b4cac81SBjoern A. Zeeb { 21336b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 21346b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 21356b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 21366b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 21376b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 21386b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 21396b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 21406b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 21416b4cac81SBjoern A. Zeeb int tid; 21426b4cac81SBjoern A. Zeeb 21436b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 21446b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 21456b4cac81SBjoern A. Zeeb 21466b4cac81SBjoern A. Zeeb /* We keep allocations de-coupled so we can deal with the two worlds. */ 21476b4cac81SBjoern A. Zeeb if (lhw->ic_node_alloc != NULL) { 21486b4cac81SBjoern A. Zeeb ni = lhw->ic_node_alloc(vap, mac); 21496b4cac81SBjoern A. Zeeb if (ni == NULL) 21506b4cac81SBjoern A. Zeeb return (NULL); 21516b4cac81SBjoern A. Zeeb } 21526b4cac81SBjoern A. Zeeb 21536b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 21546b4cac81SBjoern A. Zeeb lsta = malloc(sizeof(*lsta) + hw->sta_data_size, M_LKPI80211, 21556b4cac81SBjoern A. Zeeb M_NOWAIT | M_ZERO); 21566b4cac81SBjoern A. Zeeb if (lsta == NULL) { 21576b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL) 21586b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni); 21596b4cac81SBjoern A. Zeeb return (NULL); 21606b4cac81SBjoern A. Zeeb } 21616b4cac81SBjoern A. Zeeb 21626b4cac81SBjoern A. Zeeb lsta->added_to_drv = false; 21636b4cac81SBjoern A. Zeeb lsta->state = IEEE80211_STA_NOTEXIST; 21646b4cac81SBjoern A. Zeeb #if 0 21656b4cac81SBjoern A. Zeeb /* 21666b4cac81SBjoern A. Zeeb * This needs to be done in node_init() as ieee80211_alloc_node() 21676b4cac81SBjoern A. Zeeb * will initialise the refcount after us. 21686b4cac81SBjoern A. Zeeb */ 21696b4cac81SBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 21706b4cac81SBjoern A. Zeeb #endif 21716b4cac81SBjoern A. Zeeb /* The back-pointer "drv_data" to net80211_node let's us get lsta. */ 21726b4cac81SBjoern A. Zeeb ni->ni_drv_data = lsta; 21736b4cac81SBjoern A. Zeeb 21746b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 21756b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 21766b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 21776b4cac81SBjoern A. Zeeb 21786b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->addr, mac); 21796b4cac81SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 21806b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 21816b4cac81SBjoern A. Zeeb 21826b4cac81SBjoern A. Zeeb /* 21836b4cac81SBjoern A. Zeeb * We are neither limiting ourselves to hw.queues here, 21846b4cac81SBjoern A. Zeeb * nor do we check if driver wants IEEE80211_NUM_TIDS queue. 21856b4cac81SBjoern A. Zeeb */ 21866b4cac81SBjoern A. Zeeb 21876b4cac81SBjoern A. Zeeb ltxq = malloc(sizeof(*ltxq) + hw->txq_data_size, 21886b4cac81SBjoern A. Zeeb M_LKPI80211, M_NOWAIT | M_ZERO); 21896b4cac81SBjoern A. Zeeb if (ltxq == NULL) 21906b4cac81SBjoern A. Zeeb goto cleanup; 21916b4cac81SBjoern A. Zeeb ltxq->seen_dequeue = false; 21926b4cac81SBjoern A. Zeeb skb_queue_head_init(<xq->skbq); 21936b4cac81SBjoern A. Zeeb /* iwlwifi//mvm/sta.c::tid_to_mac80211_ac[] */ 21946b4cac81SBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) { 21956b4cac81SBjoern A. Zeeb IMPROVE(); 21966b4cac81SBjoern A. Zeeb ltxq->txq.ac = IEEE80211_AC_VO; 21976b4cac81SBjoern A. Zeeb } else { 21986b4cac81SBjoern A. Zeeb ltxq->txq.ac = tid_to_mac80211_ac[tid & 7]; 21996b4cac81SBjoern A. Zeeb } 22006b4cac81SBjoern A. Zeeb ltxq->txq.tid = tid; 22016b4cac81SBjoern A. Zeeb ltxq->txq.sta = sta; 22026b4cac81SBjoern A. Zeeb ltxq->txq.vif = vif; 22036b4cac81SBjoern A. Zeeb sta->txq[tid] = <xq->txq; 22046b4cac81SBjoern A. Zeeb } 22056b4cac81SBjoern A. Zeeb 22066b4cac81SBjoern A. Zeeb /* Deferred TX path. */ 22076b4cac81SBjoern A. Zeeb mtx_init(&lsta->txq_mtx, "lsta_txq", NULL, MTX_DEF); 22086b4cac81SBjoern A. Zeeb TASK_INIT(&lsta->txq_task, 0, lkpi_80211_txq_task, lsta); 22096b4cac81SBjoern A. Zeeb mbufq_init(&lsta->txq, IFQ_MAXLEN); 22106b4cac81SBjoern A. Zeeb 22116b4cac81SBjoern A. Zeeb return (ni); 22126b4cac81SBjoern A. Zeeb 22136b4cac81SBjoern A. Zeeb cleanup: 22146b4cac81SBjoern A. Zeeb for (; tid >= 0; tid--) 22156b4cac81SBjoern A. Zeeb free(sta->txq[tid], M_LKPI80211); 22166b4cac81SBjoern A. Zeeb free(lsta, M_LKPI80211); 22176b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL) 22186b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni); 22196b4cac81SBjoern A. Zeeb return (NULL); 22206b4cac81SBjoern A. Zeeb } 22216b4cac81SBjoern A. Zeeb 22226b4cac81SBjoern A. Zeeb static int 22236b4cac81SBjoern A. Zeeb lkpi_ic_node_init(struct ieee80211_node *ni) 22246b4cac81SBjoern A. Zeeb { 22256b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 22266b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 22276b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 22286b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 22296b4cac81SBjoern A. Zeeb int error; 22306b4cac81SBjoern A. Zeeb 22316b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 22326b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 22336b4cac81SBjoern A. Zeeb 22346b4cac81SBjoern A. Zeeb if (lhw->ic_node_init != NULL) { 22356b4cac81SBjoern A. Zeeb error = lhw->ic_node_init(ni); 22366b4cac81SBjoern A. Zeeb if (error != 0) 22376b4cac81SBjoern A. Zeeb return (error); 22386b4cac81SBjoern A. Zeeb } 22396b4cac81SBjoern A. Zeeb 22406b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(ni->ni_vap); 22416b4cac81SBjoern A. Zeeb 22426b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 22436b4cac81SBjoern A. Zeeb 22446b4cac81SBjoern A. Zeeb /* Now take the reference before linking it to the table. */ 22456b4cac81SBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 22466b4cac81SBjoern A. Zeeb 22476b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 22486b4cac81SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lvif->lsta_head, lsta, lsta_entry); 22496b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 22506b4cac81SBjoern A. Zeeb 22516b4cac81SBjoern A. Zeeb /* XXX-BZ Sync other state over. */ 22526b4cac81SBjoern A. Zeeb IMPROVE(); 22536b4cac81SBjoern A. Zeeb 22546b4cac81SBjoern A. Zeeb return (0); 22556b4cac81SBjoern A. Zeeb } 22566b4cac81SBjoern A. Zeeb 22576b4cac81SBjoern A. Zeeb static void 22586b4cac81SBjoern A. Zeeb lkpi_ic_node_cleanup(struct ieee80211_node *ni) 22596b4cac81SBjoern A. Zeeb { 22606b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 22616b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 22626b4cac81SBjoern A. Zeeb 22636b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 22646b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 22656b4cac81SBjoern A. Zeeb 22666b4cac81SBjoern A. Zeeb /* XXX-BZ remove from driver, ... */ 22676b4cac81SBjoern A. Zeeb IMPROVE(); 22686b4cac81SBjoern A. Zeeb 22696b4cac81SBjoern A. Zeeb if (lhw->ic_node_cleanup != NULL) 22706b4cac81SBjoern A. Zeeb lhw->ic_node_cleanup(ni); 22716b4cac81SBjoern A. Zeeb } 22726b4cac81SBjoern A. Zeeb 22736b4cac81SBjoern A. Zeeb static void 22746b4cac81SBjoern A. Zeeb lkpi_ic_node_free(struct ieee80211_node *ni) 22756b4cac81SBjoern A. Zeeb { 22766b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 22776b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 22786b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 22796b4cac81SBjoern A. Zeeb 22806b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 22816b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 22826b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 22836b4cac81SBjoern A. Zeeb 22846b4cac81SBjoern A. Zeeb /* XXX-BZ free resources, ... */ 22856b4cac81SBjoern A. Zeeb IMPROVE(); 22866b4cac81SBjoern A. Zeeb 22876b4cac81SBjoern A. Zeeb /* Flush mbufq (make sure to release ni refs!). */ 22886b4cac81SBjoern A. Zeeb #ifdef __notyet__ 22896b4cac81SBjoern A. Zeeb KASSERT(mbufq_len(&lsta->txq) == 0, ("%s: lsta %p has txq len %d != 0\n", 22906b4cac81SBjoern A. Zeeb __func__, lsta, mbufq_len(&lsta->txq))); 22916b4cac81SBjoern A. Zeeb #endif 22926b4cac81SBjoern A. Zeeb /* Drain taskq. */ 22936b4cac81SBjoern A. Zeeb 22946b4cac81SBjoern A. Zeeb /* Drain sta->txq[] */ 22956b4cac81SBjoern A. Zeeb mtx_destroy(&lsta->txq_mtx); 22966b4cac81SBjoern A. Zeeb 22976b4cac81SBjoern A. Zeeb /* Remove lsta if added_to_drv. */ 22986b4cac81SBjoern A. Zeeb /* Remove lsta from vif */ 22996b4cac81SBjoern A. Zeeb 23006b4cac81SBjoern A. Zeeb /* remove ref from lsta node... */ 23016b4cac81SBjoern A. Zeeb 23026b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL) 23036b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni); 23046b4cac81SBjoern A. Zeeb 23056b4cac81SBjoern A. Zeeb /* Free lsta. */ 23066b4cac81SBjoern A. Zeeb } 23076b4cac81SBjoern A. Zeeb 23086b4cac81SBjoern A. Zeeb static int 23096b4cac81SBjoern A. Zeeb lkpi_ic_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, 23106b4cac81SBjoern A. Zeeb const struct ieee80211_bpf_params *params __unused) 23116b4cac81SBjoern A. Zeeb { 23126b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 23136b4cac81SBjoern A. Zeeb 23146b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 23156b4cac81SBjoern A. Zeeb 23166b4cac81SBjoern A. Zeeb /* Queue the packet and enqueue the task to handle it. */ 23176b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_LOCK(lsta); 23186b4cac81SBjoern A. Zeeb mbufq_enqueue(&lsta->txq, m); 23196b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_UNLOCK(lsta); 23206b4cac81SBjoern A. Zeeb 23216b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_TX) 23226b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p ni %p %6D mbuf_qlen %d\n", 23236b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, ni, ni->ni_macaddr, ":", 23246b4cac81SBjoern A. Zeeb mbufq_len(&lsta->txq)); 23256b4cac81SBjoern A. Zeeb 23266b4cac81SBjoern A. Zeeb taskqueue_enqueue(taskqueue_thread, &lsta->txq_task); 23276b4cac81SBjoern A. Zeeb return (0); 23286b4cac81SBjoern A. Zeeb } 23296b4cac81SBjoern A. Zeeb 23306b4cac81SBjoern A. Zeeb static void 23316b4cac81SBjoern A. Zeeb lkpi_80211_txq_tx_one(struct lkpi_sta *lsta, struct mbuf *m) 23326b4cac81SBjoern A. Zeeb { 23336b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 23346b4cac81SBjoern A. Zeeb struct ieee80211_frame *wh; 23356b4cac81SBjoern A. Zeeb struct ieee80211_key *k; 23366b4cac81SBjoern A. Zeeb struct sk_buff *skb; 23376b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 23386b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 23396b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 23406b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 23416b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 23426b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 23436b4cac81SBjoern A. Zeeb struct ieee80211_tx_control control; 23446b4cac81SBjoern A. Zeeb struct ieee80211_tx_info *info; 23456b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 23466b4cac81SBjoern A. Zeeb void *buf; 23476b4cac81SBjoern A. Zeeb int ac; 23486b4cac81SBjoern A. Zeeb 23496b4cac81SBjoern A. Zeeb M_ASSERTPKTHDR(m); 23506b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 23516b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_TX_DUMP) 23526b4cac81SBjoern A. Zeeb hexdump(mtod(m, const void *), m->m_len, "RAW TX (plain) ", 0); 23536b4cac81SBjoern A. Zeeb #endif 23546b4cac81SBjoern A. Zeeb 23556b4cac81SBjoern A. Zeeb ni = lsta->ni; 23566b4cac81SBjoern A. Zeeb #ifndef TRY_HW_CRYPTO 23576b4cac81SBjoern A. Zeeb /* Encrypt the frame if need be; XXX-BZ info->control.hw_key. */ 23586b4cac81SBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame *); 23596b4cac81SBjoern A. Zeeb if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { 23606b4cac81SBjoern A. Zeeb /* Retrieve key for TX && do software encryption. */ 23616b4cac81SBjoern A. Zeeb k = ieee80211_crypto_encap(ni, m); 23626b4cac81SBjoern A. Zeeb if (k == NULL) { 23636b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 23646b4cac81SBjoern A. Zeeb m_freem(m); 23656b4cac81SBjoern A. Zeeb return; 23666b4cac81SBjoern A. Zeeb } 23676b4cac81SBjoern A. Zeeb } 23686b4cac81SBjoern A. Zeeb #endif 23696b4cac81SBjoern A. Zeeb 23706b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 23716b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 23726b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 23736b4cac81SBjoern A. Zeeb c = ni->ni_chan; 23746b4cac81SBjoern A. Zeeb 23756b4cac81SBjoern A. Zeeb if (ieee80211_radiotap_active_vap(ni->ni_vap)) { 23766b4cac81SBjoern A. Zeeb struct lkpi_radiotap_tx_hdr *rtap; 23776b4cac81SBjoern A. Zeeb 23786b4cac81SBjoern A. Zeeb rtap = &lhw->rtap_tx; 23796b4cac81SBjoern A. Zeeb rtap->wt_flags = 0; 23806b4cac81SBjoern A. Zeeb if (k != NULL) 23816b4cac81SBjoern A. Zeeb rtap->wt_flags |= IEEE80211_RADIOTAP_F_WEP; 23826b4cac81SBjoern A. Zeeb if (m->m_flags & M_FRAG) 23836b4cac81SBjoern A. Zeeb rtap->wt_flags |= IEEE80211_RADIOTAP_F_FRAG; 23846b4cac81SBjoern A. Zeeb IMPROVE(); 23856b4cac81SBjoern A. Zeeb rtap->wt_rate = 0; 23866b4cac81SBjoern A. Zeeb if (c != NULL && c != IEEE80211_CHAN_ANYC) { 23876b4cac81SBjoern A. Zeeb rtap->wt_chan_freq = htole16(c->ic_freq); 23886b4cac81SBjoern A. Zeeb rtap->wt_chan_flags = htole16(c->ic_flags); 23896b4cac81SBjoern A. Zeeb } 23906b4cac81SBjoern A. Zeeb 23916b4cac81SBjoern A. Zeeb ieee80211_radiotap_tx(ni->ni_vap, m); 23926b4cac81SBjoern A. Zeeb } 23936b4cac81SBjoern A. Zeeb 23946b4cac81SBjoern A. Zeeb /* 23956b4cac81SBjoern A. Zeeb * net80211 should handle hw->extra_tx_headroom. 23966b4cac81SBjoern A. Zeeb * Though for as long as we are copying we don't mind. 23976b4cac81SBjoern A. Zeeb */ 23986b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + m->m_pkthdr.len); 23996b4cac81SBjoern A. Zeeb if (skb == NULL) { 24006b4cac81SBjoern A. Zeeb printf("XXX ERROR %s: skb alloc failed\n", __func__); 24016b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 24026b4cac81SBjoern A. Zeeb m_freem(m); 24036b4cac81SBjoern A. Zeeb return; 24046b4cac81SBjoern A. Zeeb } 24056b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 24066b4cac81SBjoern A. Zeeb 24076b4cac81SBjoern A. Zeeb /* XXX-BZ we need a SKB version understanding mbuf. */ 24086b4cac81SBjoern A. Zeeb /* Save the mbuf for ieee80211_tx_complete(). */ 24096b4cac81SBjoern A. Zeeb skb->m_free_func = lkpi_ieee80211_free_skb_mbuf; 24106b4cac81SBjoern A. Zeeb skb->m = m; 24116b4cac81SBjoern A. Zeeb #if 0 24126b4cac81SBjoern A. Zeeb skb_put_data(skb, m->m_data, m->m_pkthdr.len); 24136b4cac81SBjoern A. Zeeb #else 24146b4cac81SBjoern A. Zeeb buf = skb_put(skb, m->m_pkthdr.len); 24156b4cac81SBjoern A. Zeeb m_copydata(m, 0, m->m_pkthdr.len, buf); 24166b4cac81SBjoern A. Zeeb #endif 24176b4cac81SBjoern A. Zeeb /* Save the ni. */ 24186b4cac81SBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = ni; 24196b4cac81SBjoern A. Zeeb 24206b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(ni->ni_vap); 24216b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 24226b4cac81SBjoern A. Zeeb 24236b4cac81SBjoern A. Zeeb /* XXX-BZ review this at some point [4] vs. [8] vs. [16](TID). */ 24246b4cac81SBjoern A. Zeeb ac = M_WME_GETAC(m); 24256b4cac81SBjoern A. Zeeb skb->priority = WME_AC_TO_TID(ac); 24266b4cac81SBjoern A. Zeeb ac = lkpi_ac_net_to_l80211(ac); 24276b4cac81SBjoern A. Zeeb skb_set_queue_mapping(skb, ac); 24286b4cac81SBjoern A. Zeeb 24296b4cac81SBjoern A. Zeeb info = IEEE80211_SKB_CB(skb); 24306b4cac81SBjoern A. Zeeb info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; 24316b4cac81SBjoern A. Zeeb /* Slight delay; probably only happens on scanning so fine? */ 24326b4cac81SBjoern A. Zeeb if (c == NULL || c == IEEE80211_CHAN_ANYC) 24336b4cac81SBjoern A. Zeeb c = ic->ic_curchan; 24346b4cac81SBjoern A. Zeeb info->band = lkpi_net80211_chan_to_nl80211_band(c); 24356b4cac81SBjoern A. Zeeb info->hw_queue = ac; /* XXX-BZ is this correct? */ 24366b4cac81SBjoern A. Zeeb if (m->m_flags & M_EAPOL) 24376b4cac81SBjoern A. Zeeb info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO; 24386b4cac81SBjoern A. Zeeb info->control.vif = vif; 24396b4cac81SBjoern A. Zeeb /* XXX-BZ info->control.rates */ 24406b4cac81SBjoern A. Zeeb 24416b4cac81SBjoern A. Zeeb lsta = lkpi_find_lsta_by_ni(lvif, ni); 24426b4cac81SBjoern A. Zeeb if (lsta != NULL) { 24436b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 24446b4cac81SBjoern A. Zeeb #ifdef TRY_HW_CRYPTO 24456b4cac81SBjoern A. Zeeb info->control.hw_key = lsta->kc; 24466b4cac81SBjoern A. Zeeb #endif 24476b4cac81SBjoern A. Zeeb } else { 24486b4cac81SBjoern A. Zeeb sta = NULL; 24496b4cac81SBjoern A. Zeeb } 24506b4cac81SBjoern A. Zeeb 24516b4cac81SBjoern A. Zeeb IMPROVE(); 24526b4cac81SBjoern A. Zeeb 24536b4cac81SBjoern A. Zeeb if (sta != NULL) { 24546b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 24556b4cac81SBjoern A. Zeeb 24566b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[ac]); /* XXX-BZ re-check */ 24576b4cac81SBjoern A. Zeeb /* 24586b4cac81SBjoern A. Zeeb * We currently do not use queues but do direct TX. 24596b4cac81SBjoern A. Zeeb * The exception to the rule is initial packets, as we cannot 24606b4cac81SBjoern A. Zeeb * TX until queues are allocated (at least for iwlwifi). 24616b4cac81SBjoern A. Zeeb * So we wake_tx_queue in newstate and register any dequeue 24626b4cac81SBjoern A. Zeeb * calls. In the time until then we queue packets and 24636b4cac81SBjoern A. Zeeb * let the driver deal with them. 24646b4cac81SBjoern A. Zeeb */ 24656b4cac81SBjoern A. Zeeb if (!ltxq->seen_dequeue) { 24666b4cac81SBjoern A. Zeeb 24676b4cac81SBjoern A. Zeeb /* Prevent an ordering problem, likely other issues. */ 24686b4cac81SBjoern A. Zeeb while (!skb_queue_empty(<xq->skbq)) { 24696b4cac81SBjoern A. Zeeb struct sk_buff *skb2; 24706b4cac81SBjoern A. Zeeb 24716b4cac81SBjoern A. Zeeb skb2 = skb_dequeue(<xq->skbq); 24726b4cac81SBjoern A. Zeeb if (skb2 != NULL) { 24736b4cac81SBjoern A. Zeeb memset(&control, 0, sizeof(control)); 24746b4cac81SBjoern A. Zeeb control.sta = sta; 24756b4cac81SBjoern A. Zeeb lkpi_80211_mo_tx(hw, &control, skb2); 24766b4cac81SBjoern A. Zeeb } 24776b4cac81SBjoern A. Zeeb } 24786b4cac81SBjoern A. Zeeb goto ops_tx; 24796b4cac81SBjoern A. Zeeb } 24806b4cac81SBjoern A. Zeeb if (0 && ltxq->seen_dequeue && skb_queue_empty(<xq->skbq)) 24816b4cac81SBjoern A. Zeeb goto ops_tx; 24826b4cac81SBjoern A. Zeeb 24836b4cac81SBjoern A. Zeeb skb_queue_tail(<xq->skbq, skb); 24846b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_TX) 24856b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p sta %p ni %p %6D skb %p lxtq %p " 24866b4cac81SBjoern A. Zeeb "qlen %u WAKE_TX_Q ac %d prio %u qmap %u\n", 24876b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, sta, ni, 24886b4cac81SBjoern A. Zeeb ni->ni_macaddr, ":", skb, ltxq, 24896b4cac81SBjoern A. Zeeb skb_queue_len(<xq->skbq), ac, 24906b4cac81SBjoern A. Zeeb skb->priority, skb->qmap); 24916b4cac81SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, sta->txq[ac]); /* XXX-BZ */ 24926b4cac81SBjoern A. Zeeb return; 24936b4cac81SBjoern A. Zeeb } 24946b4cac81SBjoern A. Zeeb 24956b4cac81SBjoern A. Zeeb ops_tx: 24966b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_TX) 24976b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p sta %p ni %p %6D skb %p TX ac %d prio %u qmap %u\n", 24986b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, sta, ni, ni->ni_macaddr, ":", 24996b4cac81SBjoern A. Zeeb skb, ac, skb->priority, skb->qmap); 25006b4cac81SBjoern A. Zeeb memset(&control, 0, sizeof(control)); 25016b4cac81SBjoern A. Zeeb control.sta = sta; 25026b4cac81SBjoern A. Zeeb 25036b4cac81SBjoern A. Zeeb lkpi_80211_mo_tx(hw, &control, skb); 25046b4cac81SBjoern A. Zeeb return; 25056b4cac81SBjoern A. Zeeb } 25066b4cac81SBjoern A. Zeeb 25076b4cac81SBjoern A. Zeeb static void 25086b4cac81SBjoern A. Zeeb lkpi_80211_txq_task(void *ctx, int pending) 25096b4cac81SBjoern A. Zeeb { 25106b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 25116b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 25126b4cac81SBjoern A. Zeeb struct mbufq mq; 25136b4cac81SBjoern A. Zeeb struct mbuf *m; 25146b4cac81SBjoern A. Zeeb 25156b4cac81SBjoern A. Zeeb lsta = ctx; 25166b4cac81SBjoern A. Zeeb ni = lsta->ni; 25176b4cac81SBjoern A. Zeeb 25186b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_TX) 25196b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p ni %p %6D pending %d mbuf_qlen %d\n", 25206b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, ni, ni->ni_macaddr, ":", 25216b4cac81SBjoern A. Zeeb pending, mbufq_len(&lsta->txq)); 25226b4cac81SBjoern A. Zeeb 25236b4cac81SBjoern A. Zeeb mbufq_init(&mq, IFQ_MAXLEN); 25246b4cac81SBjoern A. Zeeb 25256b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_LOCK(lsta); 25266b4cac81SBjoern A. Zeeb mbufq_concat(&mq, &lsta->txq); 25276b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_UNLOCK(lsta); 25286b4cac81SBjoern A. Zeeb 25296b4cac81SBjoern A. Zeeb m = mbufq_dequeue(&mq); 25306b4cac81SBjoern A. Zeeb while (m != NULL) { 25316b4cac81SBjoern A. Zeeb lkpi_80211_txq_tx_one(lsta, m); 25326b4cac81SBjoern A. Zeeb m = mbufq_dequeue(&mq); 25336b4cac81SBjoern A. Zeeb } 25346b4cac81SBjoern A. Zeeb } 25356b4cac81SBjoern A. Zeeb 25366b4cac81SBjoern A. Zeeb static int 25376b4cac81SBjoern A. Zeeb lkpi_ic_transmit(struct ieee80211com *ic, struct mbuf *m) 25386b4cac81SBjoern A. Zeeb { 25396b4cac81SBjoern A. Zeeb 25406b4cac81SBjoern A. Zeeb /* XXX TODO */ 25416b4cac81SBjoern A. Zeeb IMPROVE(); 25426b4cac81SBjoern A. Zeeb 25436b4cac81SBjoern A. Zeeb /* Quick and dirty cheating hack. */ 25446b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 25456b4cac81SBjoern A. Zeeb 25466b4cac81SBjoern A. Zeeb ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; 25476b4cac81SBjoern A. Zeeb return (lkpi_ic_raw_xmit(ni, m, NULL)); 25486b4cac81SBjoern A. Zeeb } 25496b4cac81SBjoern A. Zeeb 25506b4cac81SBjoern A. Zeeb static void 25516b4cac81SBjoern A. Zeeb lkpi_ic_getradiocaps(struct ieee80211com *ic, int maxchan, 25526b4cac81SBjoern A. Zeeb int *n, struct ieee80211_channel *c) 25536b4cac81SBjoern A. Zeeb { 25546b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 25556b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 25566b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 25576b4cac81SBjoern A. Zeeb uint8_t bands[IEEE80211_MODE_BYTES]; 25586b4cac81SBjoern A. Zeeb int chan_flags, error, i, nchans; 25596b4cac81SBjoern A. Zeeb 25606b4cac81SBjoern A. Zeeb /* Channels */ 25616b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 25626b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 25636b4cac81SBjoern A. Zeeb 25646b4cac81SBjoern A. Zeeb /* NL80211_BAND_2GHZ */ 25656b4cac81SBjoern A. Zeeb nchans = 0; 25666b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_2GHZ] != NULL) 25676b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[NL80211_BAND_2GHZ]->n_channels; 25686b4cac81SBjoern A. Zeeb if (nchans > 0) { 25696b4cac81SBjoern A. Zeeb memset(bands, 0, sizeof(bands)); 25706b4cac81SBjoern A. Zeeb chan_flags = 0; 25716b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11B); 25726b4cac81SBjoern A. Zeeb /* XXX-BZ unclear how to check for 11g. */ 25736b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11G); 25746b4cac81SBjoern A. Zeeb #ifdef __notyet__ 25756b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_2GHZ]->ht_cap.ht_supported) { 25766b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11NG); 25776b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_HT40; 25786b4cac81SBjoern A. Zeeb } 25796b4cac81SBjoern A. Zeeb #endif 25806b4cac81SBjoern A. Zeeb 25816b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[NL80211_BAND_2GHZ]->channels; 25826b4cac81SBjoern A. Zeeb for (i = 0; i < nchans; i++) { 25836b4cac81SBjoern A. Zeeb uint32_t nflags = 0; 25846b4cac81SBjoern A. Zeeb int cflags = chan_flags; 25856b4cac81SBjoern A. Zeeb 25866b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) { 25876b4cac81SBjoern A. Zeeb printf("%s: %s: Skipping disabled chan " 25886b4cac81SBjoern A. Zeeb "[%u/%u/%#x]\n", ic->ic_name, __func__, 25896b4cac81SBjoern A. Zeeb channels[i].hw_value, 25906b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags); 25916b4cac81SBjoern A. Zeeb continue; 25926b4cac81SBjoern A. Zeeb } 25936b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_IR) 25946b4cac81SBjoern A. Zeeb nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE); 25956b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_RADAR) 25966b4cac81SBjoern A. Zeeb nflags |= IEEE80211_CHAN_DFS; 25976b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ) 25986b4cac81SBjoern A. Zeeb cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80); 25996b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ) 26006b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_VHT80; 26016b4cac81SBjoern A. Zeeb /* XXX how to map the remaining enum ieee80211_channel_flags? */ 26026b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_HT40) 26036b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_HT40; 26046b4cac81SBjoern A. Zeeb 26056b4cac81SBjoern A. Zeeb error = ieee80211_add_channel_cbw(c, maxchan, n, 26066b4cac81SBjoern A. Zeeb channels[i].hw_value, channels[i].center_freq, 26076b4cac81SBjoern A. Zeeb channels[i].max_power, 26086b4cac81SBjoern A. Zeeb nflags, bands, chan_flags); 26096b4cac81SBjoern A. Zeeb if (error != 0) { 26106b4cac81SBjoern A. Zeeb printf("%s: %s: Adding chan %u/%u/%#x/%#x/%#x/%#x " 26116b4cac81SBjoern A. Zeeb "returned error %d\n", ic->ic_name, 26126b4cac81SBjoern A. Zeeb __func__, channels[i].hw_value, 26136b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags, 26146b4cac81SBjoern A. Zeeb nflags, chan_flags, cflags, error); 26156b4cac81SBjoern A. Zeeb break; 26166b4cac81SBjoern A. Zeeb } 26176b4cac81SBjoern A. Zeeb } 26186b4cac81SBjoern A. Zeeb } 26196b4cac81SBjoern A. Zeeb 26206b4cac81SBjoern A. Zeeb /* NL80211_BAND_5GHZ */ 26216b4cac81SBjoern A. Zeeb nchans = 0; 26226b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ] != NULL) 26236b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[NL80211_BAND_5GHZ]->n_channels; 26246b4cac81SBjoern A. Zeeb if (nchans > 0) { 26256b4cac81SBjoern A. Zeeb memset(bands, 0, sizeof(bands)); 26266b4cac81SBjoern A. Zeeb chan_flags = 0; 26276b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11A); 26286b4cac81SBjoern A. Zeeb #ifdef __not_yet__ 26296b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ]->ht_cap.ht_supported) { 26306b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11NA); 26316b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_HT40; 26326b4cac81SBjoern A. Zeeb } 26336b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.vht_supported){ 26346b4cac81SBjoern A. Zeeb 26356b4cac81SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_VHT; 26366b4cac81SBjoern A. Zeeb ic->ic_vhtcaps = 26376b4cac81SBjoern A. Zeeb hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap; 26386b4cac81SBjoern A. Zeeb 26396b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_VHT_5GHZ); 26406b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT80; 26416b4cac81SBjoern A. Zeeb if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160MHZ( 26426b4cac81SBjoern A. Zeeb ic->ic_vhtcaps)) 26436b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT160; 26446b4cac81SBjoern A. Zeeb if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160_80P80MHZ( 26456b4cac81SBjoern A. Zeeb ic->ic_vhtcaps)) 26466b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT80P80; 26476b4cac81SBjoern A. Zeeb } 26486b4cac81SBjoern A. Zeeb #endif 26496b4cac81SBjoern A. Zeeb 26506b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[NL80211_BAND_5GHZ]->channels; 26516b4cac81SBjoern A. Zeeb for (i = 0; i < nchans; i++) { 26526b4cac81SBjoern A. Zeeb uint32_t nflags = 0; 26536b4cac81SBjoern A. Zeeb int cflags = chan_flags; 26546b4cac81SBjoern A. Zeeb 26556b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) { 26566b4cac81SBjoern A. Zeeb printf("%s: %s: Skipping disabled chan " 26576b4cac81SBjoern A. Zeeb "[%u/%u/%#x]\n", ic->ic_name, __func__, 26586b4cac81SBjoern A. Zeeb channels[i].hw_value, 26596b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags); 26606b4cac81SBjoern A. Zeeb continue; 26616b4cac81SBjoern A. Zeeb } 26626b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_IR) 26636b4cac81SBjoern A. Zeeb nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE); 26646b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_RADAR) 26656b4cac81SBjoern A. Zeeb nflags |= IEEE80211_CHAN_DFS; 26666b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ) 26676b4cac81SBjoern A. Zeeb cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80); 26686b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ) 26696b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_VHT80; 26706b4cac81SBjoern A. Zeeb /* XXX hwo to map the remaining enum ieee80211_channel_flags? */ 26716b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_HT40) 26726b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_HT40; 26736b4cac81SBjoern A. Zeeb 26746b4cac81SBjoern A. Zeeb error = ieee80211_add_channel_cbw(c, maxchan, n, 26756b4cac81SBjoern A. Zeeb channels[i].hw_value, channels[i].center_freq, 26766b4cac81SBjoern A. Zeeb channels[i].max_power, 26776b4cac81SBjoern A. Zeeb nflags, bands, chan_flags); 26786b4cac81SBjoern A. Zeeb if (error != 0) { 26796b4cac81SBjoern A. Zeeb printf("%s: %s: Adding chan %u/%u/%#x/%#x/%#x/%#x " 26806b4cac81SBjoern A. Zeeb "returned error %d\n", ic->ic_name, 26816b4cac81SBjoern A. Zeeb __func__, channels[i].hw_value, 26826b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags, 26836b4cac81SBjoern A. Zeeb nflags, chan_flags, cflags, error); 26846b4cac81SBjoern A. Zeeb break; 26856b4cac81SBjoern A. Zeeb } 26866b4cac81SBjoern A. Zeeb } 26876b4cac81SBjoern A. Zeeb } 26886b4cac81SBjoern A. Zeeb } 26896b4cac81SBjoern A. Zeeb 26906b4cac81SBjoern A. Zeeb static void * 26916b4cac81SBjoern A. Zeeb lkpi_ieee80211_ifalloc(void) 26926b4cac81SBjoern A. Zeeb { 26936b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 26946b4cac81SBjoern A. Zeeb 26956b4cac81SBjoern A. Zeeb ic = malloc(sizeof(*ic), M_LKPI80211, M_WAITOK | M_ZERO); 26966b4cac81SBjoern A. Zeeb if (ic == NULL) 26976b4cac81SBjoern A. Zeeb return (NULL); 26986b4cac81SBjoern A. Zeeb 26996b4cac81SBjoern A. Zeeb /* Setting these happens later when we have device information. */ 27006b4cac81SBjoern A. Zeeb ic->ic_softc = NULL; 27016b4cac81SBjoern A. Zeeb ic->ic_name = "linuxkpi"; 27026b4cac81SBjoern A. Zeeb 27036b4cac81SBjoern A. Zeeb return (ic); 27046b4cac81SBjoern A. Zeeb } 27056b4cac81SBjoern A. Zeeb 27066b4cac81SBjoern A. Zeeb struct ieee80211_hw * 27076b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_alloc_hw(size_t priv_len, const struct ieee80211_ops *ops) 27086b4cac81SBjoern A. Zeeb { 27096b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 27106b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 27116b4cac81SBjoern A. Zeeb struct wiphy *wiphy; 27126b4cac81SBjoern A. Zeeb 27136b4cac81SBjoern A. Zeeb /* Get us and the driver data also allocated. */ 27146b4cac81SBjoern A. Zeeb wiphy = wiphy_new(&linuxkpi_mac80211cfgops, sizeof(*lhw) + priv_len); 27156b4cac81SBjoern A. Zeeb if (wiphy == NULL) 27166b4cac81SBjoern A. Zeeb return (NULL); 27176b4cac81SBjoern A. Zeeb 27186b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 27196b4cac81SBjoern A. Zeeb lhw->ops = ops; 27206b4cac81SBjoern A. Zeeb lhw->workq = alloc_ordered_workqueue(wiphy_name(wiphy), 0); 27216b4cac81SBjoern A. Zeeb if (lhw->workq == NULL) { 27226b4cac81SBjoern A. Zeeb wiphy_free(wiphy); 27236b4cac81SBjoern A. Zeeb return (NULL); 27246b4cac81SBjoern A. Zeeb } 27256b4cac81SBjoern A. Zeeb mtx_init(&lhw->mtx, "lhw", NULL, MTX_DEF | MTX_RECURSE); 27266b4cac81SBjoern A. Zeeb TAILQ_INIT(&lhw->lvif_head); 27276b4cac81SBjoern A. Zeeb 27286b4cac81SBjoern A. Zeeb /* 27296b4cac81SBjoern A. Zeeb * XXX-BZ TODO make sure there is a "_null" function to all ops 27306b4cac81SBjoern A. Zeeb * not initialized. 27316b4cac81SBjoern A. Zeeb */ 27326b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 27336b4cac81SBjoern A. Zeeb hw->wiphy = wiphy; 2734086be6a8SBjoern A. Zeeb hw->conf.flags |= IEEE80211_CONF_IDLE; 27356b4cac81SBjoern A. Zeeb hw->priv = (void *)(lhw + 1); 27366b4cac81SBjoern A. Zeeb 27376b4cac81SBjoern A. Zeeb /* BSD Specific. */ 27386b4cac81SBjoern A. Zeeb lhw->ic = lkpi_ieee80211_ifalloc(); 27396b4cac81SBjoern A. Zeeb if (lhw->ic == NULL) { 27406b4cac81SBjoern A. Zeeb ieee80211_free_hw(hw); 27416b4cac81SBjoern A. Zeeb return (NULL); 27426b4cac81SBjoern A. Zeeb } 27436b4cac81SBjoern A. Zeeb 27446b4cac81SBjoern A. Zeeb IMPROVE(); 27456b4cac81SBjoern A. Zeeb 27466b4cac81SBjoern A. Zeeb return (hw); 27476b4cac81SBjoern A. Zeeb } 27486b4cac81SBjoern A. Zeeb 27496b4cac81SBjoern A. Zeeb void 27506b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iffree(struct ieee80211_hw *hw) 27516b4cac81SBjoern A. Zeeb { 27526b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 27536b4cac81SBjoern A. Zeeb 27546b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 27556b4cac81SBjoern A. Zeeb free(lhw->ic, M_LKPI80211); 27566b4cac81SBjoern A. Zeeb lhw->ic = NULL; 27576b4cac81SBjoern A. Zeeb 27586b4cac81SBjoern A. Zeeb /* Cleanup more of lhw here or in wiphy_free()? */ 27596b4cac81SBjoern A. Zeeb mtx_destroy(&lhw->mtx); 27606b4cac81SBjoern A. Zeeb IMPROVE(); 27616b4cac81SBjoern A. Zeeb } 27626b4cac81SBjoern A. Zeeb 27636b4cac81SBjoern A. Zeeb void 27646b4cac81SBjoern A. Zeeb linuxkpi_set_ieee80211_dev(struct ieee80211_hw *hw, char *name) 27656b4cac81SBjoern A. Zeeb { 27666b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 27676b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 27686b4cac81SBjoern A. Zeeb 27696b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 27706b4cac81SBjoern A. Zeeb ic = lhw->ic; 27716b4cac81SBjoern A. Zeeb 27726b4cac81SBjoern A. Zeeb /* Now set a proper name before ieee80211_ifattach(). */ 27736b4cac81SBjoern A. Zeeb ic->ic_softc = lhw; 27746b4cac81SBjoern A. Zeeb ic->ic_name = name; 27756b4cac81SBjoern A. Zeeb 27766b4cac81SBjoern A. Zeeb /* XXX-BZ do we also need to set wiphy name? */ 27776b4cac81SBjoern A. Zeeb } 27786b4cac81SBjoern A. Zeeb 27796b4cac81SBjoern A. Zeeb struct ieee80211_hw * 27806b4cac81SBjoern A. Zeeb linuxkpi_wiphy_to_ieee80211_hw(struct wiphy *wiphy) 27816b4cac81SBjoern A. Zeeb { 27826b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 27836b4cac81SBjoern A. Zeeb 27846b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 27856b4cac81SBjoern A. Zeeb return (LHW_TO_HW(lhw)); 27866b4cac81SBjoern A. Zeeb } 27876b4cac81SBjoern A. Zeeb 27886b4cac81SBjoern A. Zeeb static void 27896b4cac81SBjoern A. Zeeb lkpi_radiotap_attach(struct lkpi_hw *lhw) 27906b4cac81SBjoern A. Zeeb { 27916b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 27926b4cac81SBjoern A. Zeeb 27936b4cac81SBjoern A. Zeeb ic = lhw->ic; 27946b4cac81SBjoern A. Zeeb ieee80211_radiotap_attach(ic, 27956b4cac81SBjoern A. Zeeb &lhw->rtap_tx.wt_ihdr, sizeof(lhw->rtap_tx), 27966b4cac81SBjoern A. Zeeb LKPI_RTAP_TX_FLAGS_PRESENT, 27976b4cac81SBjoern A. Zeeb &lhw->rtap_rx.wr_ihdr, sizeof(lhw->rtap_rx), 27986b4cac81SBjoern A. Zeeb LKPI_RTAP_RX_FLAGS_PRESENT); 27996b4cac81SBjoern A. Zeeb } 28006b4cac81SBjoern A. Zeeb 28016b4cac81SBjoern A. Zeeb void 28026b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ifattach(struct ieee80211_hw *hw) 28036b4cac81SBjoern A. Zeeb { 28046b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 28056b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 28066b4cac81SBjoern A. Zeeb #ifdef TRY_HW_CRYPTO 28076b4cac81SBjoern A. Zeeb int i; 28086b4cac81SBjoern A. Zeeb #endif 28096b4cac81SBjoern A. Zeeb 28106b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 28116b4cac81SBjoern A. Zeeb ic = lhw->ic; 28126b4cac81SBjoern A. Zeeb 28136b4cac81SBjoern A. Zeeb /* XXX-BZ figure this out how they count his... */ 28146b4cac81SBjoern A. Zeeb if (!is_zero_ether_addr(hw->wiphy->perm_addr)) { 28156b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(ic->ic_macaddr, 28166b4cac81SBjoern A. Zeeb hw->wiphy->perm_addr); 28176b4cac81SBjoern A. Zeeb } else if (hw->wiphy->n_addresses > 0) { 28186b4cac81SBjoern A. Zeeb /* We take the first one. */ 28196b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(ic->ic_macaddr, 28206b4cac81SBjoern A. Zeeb hw->wiphy->addresses[0].addr); 28216b4cac81SBjoern A. Zeeb } else { 28226b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: warning, no hardware address!\n", __func__); 28236b4cac81SBjoern A. Zeeb } 28246b4cac81SBjoern A. Zeeb 28256b4cac81SBjoern A. Zeeb ic->ic_headroom = hw->extra_tx_headroom; 28266b4cac81SBjoern A. Zeeb 28276b4cac81SBjoern A. Zeeb ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ 28286b4cac81SBjoern A. Zeeb ic->ic_opmode = IEEE80211_M_STA; 28296b4cac81SBjoern A. Zeeb 28306b4cac81SBjoern A. Zeeb /* Set device capabilities. */ 28316b4cac81SBjoern A. Zeeb /* XXX-BZ we need to get these from linux80211/drivers and convert. */ 28326b4cac81SBjoern A. Zeeb ic->ic_caps = 28336b4cac81SBjoern A. Zeeb IEEE80211_C_STA | 28346b4cac81SBjoern A. Zeeb IEEE80211_C_MONITOR | 28356b4cac81SBjoern A. Zeeb IEEE80211_C_WPA | /* WPA/RSN */ 28366b4cac81SBjoern A. Zeeb IEEE80211_C_WME | 28376b4cac81SBjoern A. Zeeb #if 0 28386b4cac81SBjoern A. Zeeb IEEE80211_C_PMGT | 28396b4cac81SBjoern A. Zeeb #endif 28406b4cac81SBjoern A. Zeeb IEEE80211_C_SHSLOT | /* short slot time supported */ 28416b4cac81SBjoern A. Zeeb IEEE80211_C_SHPREAMBLE /* short preamble supported */ 28426b4cac81SBjoern A. Zeeb ; 28436b4cac81SBjoern A. Zeeb #if 0 28446b4cac81SBjoern A. Zeeb /* Scanning is a different kind of beast to re-work. */ 28456b4cac81SBjoern A. Zeeb ic->ic_caps |= IEEE80211_C_BGSCAN; 28466b4cac81SBjoern A. Zeeb #endif 28476b4cac81SBjoern A. Zeeb if (lhw->ops->hw_scan && 28486b4cac81SBjoern A. Zeeb ieee80211_hw_check(hw, SINGLE_SCAN_ON_ALL_BANDS)) { 28496b4cac81SBjoern A. Zeeb /* Advertise full-offload scanning */ 28506b4cac81SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_SCAN_OFFLOAD; 28516b4cac81SBjoern A. Zeeb } 28526b4cac81SBjoern A. Zeeb 28536b4cac81SBjoern A. Zeeb #ifdef __notyet__ 28546b4cac81SBjoern A. Zeeb ic->ic_htcaps = IEEE80211_HTC_HT /* HT operation */ 28556b4cac81SBjoern A. Zeeb | IEEE80211_HTC_AMPDU /* A-MPDU tx/rx */ 28566b4cac81SBjoern A. Zeeb | IEEE80211_HTC_AMSDU /* A-MSDU tx/rx */ 28576b4cac81SBjoern A. Zeeb | IEEE80211_HTCAP_MAXAMSDU_3839 28586b4cac81SBjoern A. Zeeb /* max A-MSDU length */ 28596b4cac81SBjoern A. Zeeb | IEEE80211_HTCAP_SMPS_OFF; /* SM power save off */ 28606b4cac81SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_SHORTGI20; 28616b4cac81SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_CHWIDTH40 | IEEE80211_HTCAP_SHORTGI40; 28626b4cac81SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_TXSTBC; 28636b4cac81SBjoern A. Zeeb #endif 28646b4cac81SBjoern A. Zeeb 28656b4cac81SBjoern A. Zeeb ic->ic_cryptocaps = 0; 28666b4cac81SBjoern A. Zeeb #ifdef TRY_HW_CRYPTO 28676b4cac81SBjoern A. Zeeb if (hw->wiphy->n_cipher_suites > 0) { 28686b4cac81SBjoern A. Zeeb for (i = 0; i < hw->wiphy->n_cipher_suites; i++) 28696b4cac81SBjoern A. Zeeb ic->ic_cryptocaps |= lkpi_l80211_to_net80211_cyphers( 28706b4cac81SBjoern A. Zeeb hw->wiphy->cipher_suites[i]); 28716b4cac81SBjoern A. Zeeb } 28726b4cac81SBjoern A. Zeeb #endif 28736b4cac81SBjoern A. Zeeb 28746b4cac81SBjoern A. Zeeb lkpi_ic_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans, 28756b4cac81SBjoern A. Zeeb ic->ic_channels); 28766b4cac81SBjoern A. Zeeb 28776b4cac81SBjoern A. Zeeb ieee80211_ifattach(ic); 28786b4cac81SBjoern A. Zeeb 28796b4cac81SBjoern A. Zeeb ic->ic_update_mcast = lkpi_ic_update_mcast; 28806b4cac81SBjoern A. Zeeb ic->ic_update_promisc = lkpi_ic_update_promisc; 28816b4cac81SBjoern A. Zeeb ic->ic_update_chw = lkpi_ic_update_chw; 28826b4cac81SBjoern A. Zeeb ic->ic_parent = lkpi_ic_parent; 28836b4cac81SBjoern A. Zeeb ic->ic_scan_start = lkpi_ic_scan_start; 28846b4cac81SBjoern A. Zeeb ic->ic_scan_end = lkpi_ic_scan_end; 28856b4cac81SBjoern A. Zeeb if (lhw->ops->hw_scan && 28866b4cac81SBjoern A. Zeeb ieee80211_hw_check(hw, SINGLE_SCAN_ON_ALL_BANDS)) 28876b4cac81SBjoern A. Zeeb ic->ic_scan_curchan = lkpi_ic_scan_curchan_nada; 28886b4cac81SBjoern A. Zeeb ic->ic_set_channel = lkpi_ic_set_channel; 28896b4cac81SBjoern A. Zeeb ic->ic_transmit = lkpi_ic_transmit; 28906b4cac81SBjoern A. Zeeb ic->ic_raw_xmit = lkpi_ic_raw_xmit; 28916b4cac81SBjoern A. Zeeb ic->ic_vap_create = lkpi_ic_vap_create; 28926b4cac81SBjoern A. Zeeb ic->ic_vap_delete = lkpi_ic_vap_delete; 28936b4cac81SBjoern A. Zeeb ic->ic_getradiocaps = lkpi_ic_getradiocaps; 28946b4cac81SBjoern A. Zeeb ic->ic_wme.wme_update = lkpi_ic_wme_update; 28956b4cac81SBjoern A. Zeeb 28966b4cac81SBjoern A. Zeeb lhw->ic_node_alloc = ic->ic_node_alloc; 28976b4cac81SBjoern A. Zeeb ic->ic_node_alloc = lkpi_ic_node_alloc; 28986b4cac81SBjoern A. Zeeb lhw->ic_node_init = ic->ic_node_init; 28996b4cac81SBjoern A. Zeeb ic->ic_node_init = lkpi_ic_node_init; 29006b4cac81SBjoern A. Zeeb lhw->ic_node_cleanup = ic->ic_node_cleanup; 29016b4cac81SBjoern A. Zeeb ic->ic_node_cleanup = lkpi_ic_node_cleanup; 29026b4cac81SBjoern A. Zeeb lhw->ic_node_free = ic->ic_node_free; 29036b4cac81SBjoern A. Zeeb ic->ic_node_free = lkpi_ic_node_free; 29046b4cac81SBjoern A. Zeeb 29056b4cac81SBjoern A. Zeeb lkpi_radiotap_attach(lhw); 29066b4cac81SBjoern A. Zeeb 29076b4cac81SBjoern A. Zeeb if (bootverbose) 29086b4cac81SBjoern A. Zeeb ieee80211_announce(ic); 29096b4cac81SBjoern A. Zeeb } 29106b4cac81SBjoern A. Zeeb 29116b4cac81SBjoern A. Zeeb void 29126b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ifdetach(struct ieee80211_hw *hw) 29136b4cac81SBjoern A. Zeeb { 29146b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 29156b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 29166b4cac81SBjoern A. Zeeb 29176b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 29186b4cac81SBjoern A. Zeeb ic = lhw->ic; 29196b4cac81SBjoern A. Zeeb ieee80211_ifdetach(ic); 29206b4cac81SBjoern A. Zeeb } 29216b4cac81SBjoern A. Zeeb 29226b4cac81SBjoern A. Zeeb void 29236b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_interfaces(struct ieee80211_hw *hw, 29246b4cac81SBjoern A. Zeeb enum ieee80211_iface_iter flags, 29256b4cac81SBjoern A. Zeeb void(*iterfunc)(void *, uint8_t *, struct ieee80211_vif *), 29266b4cac81SBjoern A. Zeeb void *arg) 29276b4cac81SBjoern A. Zeeb { 29286b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 29296b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 29306b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 29316b4cac81SBjoern A. Zeeb bool active, atomic; 29326b4cac81SBjoern A. Zeeb 29336b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 29346b4cac81SBjoern A. Zeeb 29356b4cac81SBjoern A. Zeeb if (flags & ~(IEEE80211_IFACE_ITER_NORMAL| 29366b4cac81SBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL| 29376b4cac81SBjoern A. Zeeb IEEE80211_IFACE_ITER__ACTIVE|IEEE80211_IFACE_ITER__ATOMIC)) { 29386b4cac81SBjoern A. Zeeb ic_printf(lhw->ic, "XXX TODO %s flags(%#x) not yet supported.\n", 29396b4cac81SBjoern A. Zeeb __func__, flags); 29406b4cac81SBjoern A. Zeeb } 29416b4cac81SBjoern A. Zeeb 29426b4cac81SBjoern A. Zeeb active = (flags & IEEE80211_IFACE_ITER__ACTIVE) != 0; 29436b4cac81SBjoern A. Zeeb atomic = (flags & IEEE80211_IFACE_ITER__ATOMIC) != 0; 29446b4cac81SBjoern A. Zeeb 29456b4cac81SBjoern A. Zeeb if (atomic) 29466b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 29476b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 29486b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 29496b4cac81SBjoern A. Zeeb 29506b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 29516b4cac81SBjoern A. Zeeb 29526b4cac81SBjoern A. Zeeb /* 29536b4cac81SBjoern A. Zeeb * If we want "active" interfaces, we need to distinguish on 29546b4cac81SBjoern A. Zeeb * whether the driver knows about them or not to be able to 29556b4cac81SBjoern A. Zeeb * handle the "resume" case correctly. Skip the ones the 29566b4cac81SBjoern A. Zeeb * driver does not know about. 29576b4cac81SBjoern A. Zeeb */ 29586b4cac81SBjoern A. Zeeb if (active && !lvif->added_to_drv && 29596b4cac81SBjoern A. Zeeb (flags & IEEE80211_IFACE_ITER_RESUME_ALL) != 0) 29606b4cac81SBjoern A. Zeeb continue; 29616b4cac81SBjoern A. Zeeb 29626b4cac81SBjoern A. Zeeb /* 29636b4cac81SBjoern A. Zeeb * Run the iterator function if we are either not asking 29646b4cac81SBjoern A. Zeeb * asking for active only or if the VAP is "running". 29656b4cac81SBjoern A. Zeeb */ 29666b4cac81SBjoern A. Zeeb /* XXX-BZ probably should have state in the lvif as well. */ 29676b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 29686b4cac81SBjoern A. Zeeb if (!active || (vap->iv_state != IEEE80211_S_INIT)) 29696b4cac81SBjoern A. Zeeb iterfunc(arg, vif->addr, vif); 29706b4cac81SBjoern A. Zeeb } 29716b4cac81SBjoern A. Zeeb if (atomic) 29726b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 29736b4cac81SBjoern A. Zeeb } 29746b4cac81SBjoern A. Zeeb 29756b4cac81SBjoern A. Zeeb void 29766b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_keys(struct ieee80211_hw *hw, 29776b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif, 29786b4cac81SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_vif *, 29796b4cac81SBjoern A. Zeeb struct ieee80211_sta *, struct ieee80211_key_conf *, 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_chan_contexts(struct ieee80211_hw *hw, 29886b4cac81SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_chanctx_conf *, 29896b4cac81SBjoern A. Zeeb void *), 29906b4cac81SBjoern A. Zeeb void *arg) 29916b4cac81SBjoern A. Zeeb { 29926b4cac81SBjoern A. Zeeb 29936b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 29946b4cac81SBjoern A. Zeeb } 29956b4cac81SBjoern A. Zeeb 29966b4cac81SBjoern A. Zeeb void 29976b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_stations_atomic(struct ieee80211_hw *hw, 29986b4cac81SBjoern A. Zeeb void (*iterfunc)(void *, struct ieee80211_sta *), void *arg) 29996b4cac81SBjoern A. Zeeb { 30006b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 30016b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 30026b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 30036b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 30046b4cac81SBjoern A. Zeeb 30056b4cac81SBjoern A. Zeeb KASSERT(hw != NULL && iterfunc != NULL, 30066b4cac81SBjoern A. Zeeb ("%s: hw %p iterfunc %p arg %p\n", __func__, hw, iterfunc, arg)); 30076b4cac81SBjoern A. Zeeb 30086b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 30096b4cac81SBjoern A. Zeeb 30106b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 30116b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 30126b4cac81SBjoern A. Zeeb 30136b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 30146b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lsta, &lvif->lsta_head, lsta_entry) { 30156b4cac81SBjoern A. Zeeb if (!lsta->added_to_drv) 30166b4cac81SBjoern A. Zeeb continue; 30176b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 30186b4cac81SBjoern A. Zeeb iterfunc(arg, sta); 30196b4cac81SBjoern A. Zeeb } 30206b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 30216b4cac81SBjoern A. Zeeb } 30226b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 30236b4cac81SBjoern A. Zeeb } 30246b4cac81SBjoern A. Zeeb 30256b4cac81SBjoern A. Zeeb int 30266b4cac81SBjoern A. Zeeb linuxkpi_regulatory_set_wiphy_regd_sync(struct wiphy *wiphy, 30276b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_regdomain *regd) 30286b4cac81SBjoern A. Zeeb { 30296b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 30306b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 30316b4cac81SBjoern A. Zeeb struct ieee80211_regdomain *rd; 30326b4cac81SBjoern A. Zeeb 30336b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 30346b4cac81SBjoern A. Zeeb ic = lhw->ic; 30356b4cac81SBjoern A. Zeeb 30366b4cac81SBjoern A. Zeeb rd = &ic->ic_regdomain; 30376b4cac81SBjoern A. Zeeb if (rd->isocc[0] == '\0') { 30386b4cac81SBjoern A. Zeeb rd->isocc[0] = regd->alpha2[0]; 30396b4cac81SBjoern A. Zeeb rd->isocc[1] = regd->alpha2[1]; 30406b4cac81SBjoern A. Zeeb } 30416b4cac81SBjoern A. Zeeb 30426b4cac81SBjoern A. Zeeb TODO(); 30436b4cac81SBjoern A. Zeeb /* XXX-BZ finish the rest. */ 30446b4cac81SBjoern A. Zeeb 30456b4cac81SBjoern A. Zeeb return (0); 30466b4cac81SBjoern A. Zeeb } 30476b4cac81SBjoern A. Zeeb 30486b4cac81SBjoern A. Zeeb void 30496b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_scan_completed(struct ieee80211_hw *hw, 30506b4cac81SBjoern A. Zeeb struct cfg80211_scan_info *info) 30516b4cac81SBjoern A. Zeeb { 30526b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 30536b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 30546b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 30556b4cac81SBjoern A. Zeeb 30566b4cac81SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 30576b4cac81SBjoern A. Zeeb ic = lhw->ic; 30586b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 30596b4cac81SBjoern A. Zeeb 30606b4cac81SBjoern A. Zeeb ieee80211_scan_done(ss->ss_vap); 30616b4cac81SBjoern A. Zeeb 30626b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 30636b4cac81SBjoern A. Zeeb free(lhw->hw_req->ies.common_ies, M_80211_VAP); 30646b4cac81SBjoern A. Zeeb free(lhw->hw_req, M_LKPI80211); 30656b4cac81SBjoern A. Zeeb lhw->hw_req = NULL; 30666b4cac81SBjoern A. Zeeb lhw->scan_flags &= ~LKPI_SCAN_RUNNING; 30676b4cac81SBjoern A. Zeeb wakeup(lhw); 30686b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 30696b4cac81SBjoern A. Zeeb 30706b4cac81SBjoern A. Zeeb return; 30716b4cac81SBjoern A. Zeeb } 30726b4cac81SBjoern A. Zeeb 30736b4cac81SBjoern A. Zeeb void 30746b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb, 30756b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta, struct napi_struct *napi __unused) 30766b4cac81SBjoern A. Zeeb { 30776b4cac81SBjoern A. Zeeb struct epoch_tracker et; 30786b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 30796b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 30806b4cac81SBjoern A. Zeeb struct mbuf *m; 30816b4cac81SBjoern A. Zeeb struct skb_shared_info *shinfo; 30826b4cac81SBjoern A. Zeeb struct ieee80211_rx_status *rx_status; 30836b4cac81SBjoern A. Zeeb struct ieee80211_rx_stats rx_stats; 30846b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 30856b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 30866b4cac81SBjoern A. Zeeb struct ieee80211_hdr *hdr; 30876b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 30886b4cac81SBjoern A. Zeeb int i, offset, ok, type; 30896b4cac81SBjoern A. Zeeb 30906b4cac81SBjoern A. Zeeb if (skb->len < 2) { 30916b4cac81SBjoern A. Zeeb /* Need 80211 stats here. */ 30926b4cac81SBjoern A. Zeeb IMPROVE(); 30936b4cac81SBjoern A. Zeeb goto err; 30946b4cac81SBjoern A. Zeeb } 30956b4cac81SBjoern A. Zeeb 30966b4cac81SBjoern A. Zeeb /* 30976b4cac81SBjoern A. Zeeb * For now do the data copy; we can later improve things. Might even 30986b4cac81SBjoern A. Zeeb * have an mbuf backing the skb data then? 30996b4cac81SBjoern A. Zeeb */ 31006b4cac81SBjoern A. Zeeb m = m_get2(skb->len, M_NOWAIT, MT_DATA, M_PKTHDR); 31016b4cac81SBjoern A. Zeeb if (m == NULL) 31026b4cac81SBjoern A. Zeeb goto err; 31036b4cac81SBjoern A. Zeeb m_copyback(m, 0, skb->tail - skb->data, skb->data); 31046b4cac81SBjoern A. Zeeb 31056b4cac81SBjoern A. Zeeb shinfo = skb_shinfo(skb); 31066b4cac81SBjoern A. Zeeb offset = m->m_len; 31076b4cac81SBjoern A. Zeeb for (i = 0; i < shinfo->nr_frags; i++) { 31086b4cac81SBjoern A. Zeeb m_copyback(m, offset, shinfo->frags[i].size, 31096b4cac81SBjoern A. Zeeb (uint8_t *)linux_page_address(shinfo->frags[i].page) + 31106b4cac81SBjoern A. Zeeb shinfo->frags[i].offset); 31116b4cac81SBjoern A. Zeeb offset += shinfo->frags[i].size; 31126b4cac81SBjoern A. Zeeb } 31136b4cac81SBjoern A. Zeeb 31146b4cac81SBjoern A. Zeeb rx_status = IEEE80211_SKB_RXCB(skb); 31156b4cac81SBjoern A. Zeeb 31166b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 31176b4cac81SBjoern A. Zeeb hdr = (void *)skb->data; 31186b4cac81SBjoern A. Zeeb if ((debug_80211 & D80211_TRACE_RX_BEACONS) == 0 && 31196b4cac81SBjoern A. Zeeb ieee80211_is_beacon(hdr->frame_control)) 31206b4cac81SBjoern A. Zeeb goto no_trace_beacons; 31216b4cac81SBjoern A. Zeeb 31226b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_RX) 31236b4cac81SBjoern A. Zeeb printf("TRACE-RX: %s: skb %p a/l/d/t-len (%u/%u/%u/%u) " 31246b4cac81SBjoern A. Zeeb "h %p d %p t %p e %p sh %p (%u) m %p plen %u len %u\n", 31256b4cac81SBjoern A. Zeeb __func__, skb, skb->_alloc_len, skb->len, skb->data_len, 31266b4cac81SBjoern A. Zeeb skb->truesize, skb->head, skb->data, skb->tail, skb->end, 31276b4cac81SBjoern A. Zeeb shinfo, shinfo->nr_frags, 31286b4cac81SBjoern A. Zeeb m, m->m_pkthdr.len, m->m_len); 31296b4cac81SBjoern A. Zeeb 31306b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_RX_DUMP) 31316b4cac81SBjoern A. Zeeb hexdump(mtod(m, const void *), m->m_len, "RX (raw) ", 0); 31326b4cac81SBjoern A. Zeeb 31336b4cac81SBjoern A. Zeeb /* Implement a dump_rxcb() !!! */ 31346b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_RX) 3135*c8dafefaSBjoern A. Zeeb printf("TRACE %s: RXCB: %ju %ju %u, %#0x, %u, %#0x, %#0x, " 31366b4cac81SBjoern A. Zeeb "%u band %u, %u %u %u %u, %u, %#x %#x %#x %#x %u %u %u\n", 31376b4cac81SBjoern A. Zeeb __func__, 3138*c8dafefaSBjoern A. Zeeb (uintmax_t)rx_status->boottime_ns, 3139*c8dafefaSBjoern A. Zeeb (uintmax_t)rx_status->mactime, 31406b4cac81SBjoern A. Zeeb rx_status->device_timestamp, 31416b4cac81SBjoern A. Zeeb rx_status->flag, 31426b4cac81SBjoern A. Zeeb rx_status->freq, 31436b4cac81SBjoern A. Zeeb rx_status->bw, 31446b4cac81SBjoern A. Zeeb rx_status->encoding, 31456b4cac81SBjoern A. Zeeb rx_status->ampdu_reference, 31466b4cac81SBjoern A. Zeeb rx_status->band, 31476b4cac81SBjoern A. Zeeb rx_status->chains, 31486b4cac81SBjoern A. Zeeb rx_status->chain_signal[0], 31496b4cac81SBjoern A. Zeeb rx_status->chain_signal[1], 31506b4cac81SBjoern A. Zeeb rx_status->chain_signal[2], 31516b4cac81SBjoern A. Zeeb rx_status->signal, 31526b4cac81SBjoern A. Zeeb rx_status->enc_flags, 31536b4cac81SBjoern A. Zeeb rx_status->he_dcm, 31546b4cac81SBjoern A. Zeeb rx_status->he_gi, 31556b4cac81SBjoern A. Zeeb rx_status->he_ru, 31566b4cac81SBjoern A. Zeeb rx_status->zero_length_psdu_type, 31576b4cac81SBjoern A. Zeeb rx_status->nss, 31586b4cac81SBjoern A. Zeeb rx_status->rate_idx); 31596b4cac81SBjoern A. Zeeb no_trace_beacons: 31606b4cac81SBjoern A. Zeeb #endif 31616b4cac81SBjoern A. Zeeb 31626b4cac81SBjoern A. Zeeb memset(&rx_stats, 0, sizeof(rx_stats)); 31636b4cac81SBjoern A. Zeeb rx_stats.r_flags = IEEE80211_R_NF | IEEE80211_R_RSSI; 31646b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, SIGNAL_DBM) && 31656b4cac81SBjoern A. Zeeb !(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL)) 31666b4cac81SBjoern A. Zeeb rx_stats.c_rssi = rx_status->signal; 31676b4cac81SBjoern A. Zeeb else 31686b4cac81SBjoern A. Zeeb rx_stats.c_rssi = 0; /* XXX */ 31696b4cac81SBjoern A. Zeeb rx_stats.c_nf = -96; /* XXX */ 31706b4cac81SBjoern A. Zeeb rx_stats.r_flags |= IEEE80211_R_BAND; 31716b4cac81SBjoern A. Zeeb rx_stats.c_band = 31726b4cac81SBjoern A. Zeeb lkpi_nl80211_band_to_net80211_band(rx_status->band); 31736b4cac81SBjoern A. Zeeb rx_stats.r_flags |= IEEE80211_R_FREQ | IEEE80211_R_IEEE; 31746b4cac81SBjoern A. Zeeb rx_stats.c_freq = rx_status->freq; 31756b4cac81SBjoern A. Zeeb rx_stats.c_ieee = ieee80211_mhz2ieee(rx_stats.c_freq, rx_stats.c_band); 31766b4cac81SBjoern A. Zeeb 31776b4cac81SBjoern A. Zeeb /* XXX-BZ correct hardcoded rssi and noise floor. */ 31786b4cac81SBjoern A. Zeeb /* XXX (*sta_statistics)() to get to some of that? */ 31796b4cac81SBjoern A. Zeeb /* XXX-BZ dump the FreeBSD version of rx_stats as well! */ 31806b4cac81SBjoern A. Zeeb 31816b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 31826b4cac81SBjoern A. Zeeb ic = lhw->ic; 31836b4cac81SBjoern A. Zeeb 31846b4cac81SBjoern A. Zeeb ok = ieee80211_add_rx_params(m, &rx_stats); 31856b4cac81SBjoern A. Zeeb if (ok == 0) { 31866b4cac81SBjoern A. Zeeb counter_u64_add(ic->ic_ierrors, 1); 31876b4cac81SBjoern A. Zeeb goto err; 31886b4cac81SBjoern A. Zeeb } 31896b4cac81SBjoern A. Zeeb 31906b4cac81SBjoern A. Zeeb if (sta != NULL) { 31916b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 31926b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(lsta->ni); 31936b4cac81SBjoern A. Zeeb } else { 3194*c8dafefaSBjoern A. Zeeb struct ieee80211_frame_min *wh; 3195*c8dafefaSBjoern A. Zeeb 31966b4cac81SBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame_min *); 31976b4cac81SBjoern A. Zeeb ni = ieee80211_find_rxnode(ic, wh); 31986b4cac81SBjoern A. Zeeb if (ni != NULL) 31996b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 32006b4cac81SBjoern A. Zeeb } 32016b4cac81SBjoern A. Zeeb 32026b4cac81SBjoern A. Zeeb if (ni != NULL) 32036b4cac81SBjoern A. Zeeb vap = ni->ni_vap; 32046b4cac81SBjoern A. Zeeb else 32056b4cac81SBjoern A. Zeeb /* 32066b4cac81SBjoern A. Zeeb * XXX-BZ can we improve this by looking at the frame hdr 32076b4cac81SBjoern A. Zeeb * or other meta-data passed up? 32086b4cac81SBjoern A. Zeeb */ 32096b4cac81SBjoern A. Zeeb vap = TAILQ_FIRST(&ic->ic_vaps); 32106b4cac81SBjoern A. Zeeb 32116b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_RX) 32126b4cac81SBjoern A. Zeeb printf("TRACE %s: sta %p lsta %p ni %p vap %p\n", __func__, sta, lsta, ni, vap); 32136b4cac81SBjoern A. Zeeb 3214*c8dafefaSBjoern A. Zeeb if (ni != NULL && vap != NULL && 3215*c8dafefaSBjoern A. Zeeb ieee80211_is_beacon(hdr->frame_control) && 3216*c8dafefaSBjoern A. Zeeb rx_status->device_timestamp > 0 && 3217*c8dafefaSBjoern A. Zeeb m->m_pkthdr.len >= sizeof(struct ieee80211_frame)) { 3218*c8dafefaSBjoern A. Zeeb struct lkpi_vif *lvif; 3219*c8dafefaSBjoern A. Zeeb struct ieee80211_vif *vif; 3220*c8dafefaSBjoern A. Zeeb struct ieee80211_frame *wh; 3221*c8dafefaSBjoern A. Zeeb 3222*c8dafefaSBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame *); 3223*c8dafefaSBjoern A. Zeeb if (!IEEE80211_ADDR_EQ(wh->i_addr2, ni->ni_bssid)) 3224*c8dafefaSBjoern A. Zeeb goto skip_device_ts; 3225*c8dafefaSBjoern A. Zeeb 3226*c8dafefaSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 3227*c8dafefaSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 3228*c8dafefaSBjoern A. Zeeb 3229*c8dafefaSBjoern A. Zeeb IMPROVE("TIMING_BEACON_ONLY?"); 3230*c8dafefaSBjoern A. Zeeb /* mac80211 specific (not net80211) so keep it here. */ 3231*c8dafefaSBjoern A. Zeeb vif->bss_conf.sync_device_ts = rx_status->device_timestamp; 3232*c8dafefaSBjoern A. Zeeb /* 3233*c8dafefaSBjoern A. Zeeb * net80211 should take care of the other information (sync_tsf, 3234*c8dafefaSBjoern A. Zeeb * sync_dtim_count) as otherwise we need to parse the beacon. 3235*c8dafefaSBjoern A. Zeeb */ 3236*c8dafefaSBjoern A. Zeeb } 3237*c8dafefaSBjoern A. Zeeb skip_device_ts: 3238*c8dafefaSBjoern A. Zeeb 32396b4cac81SBjoern A. Zeeb if (vap != NULL && vap->iv_state > IEEE80211_S_INIT && 32406b4cac81SBjoern A. Zeeb ieee80211_radiotap_active_vap(vap)) { 32416b4cac81SBjoern A. Zeeb struct lkpi_radiotap_rx_hdr *rtap; 32426b4cac81SBjoern A. Zeeb 32436b4cac81SBjoern A. Zeeb rtap = &lhw->rtap_rx; 32446b4cac81SBjoern A. Zeeb rtap->wr_tsft = rx_status->device_timestamp; 32456b4cac81SBjoern A. Zeeb rtap->wr_flags = 0; 32466b4cac81SBjoern A. Zeeb if (rx_status->enc_flags & RX_ENC_FLAG_SHORTPRE) 32476b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; 32486b4cac81SBjoern A. Zeeb if (rx_status->enc_flags & RX_ENC_FLAG_SHORT_GI) 32496b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTGI; 32506b4cac81SBjoern A. Zeeb #if 0 /* .. or it does not given we strip it below. */ 32516b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, RX_INCLUDES_FCS)) 32526b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_FCS; 32536b4cac81SBjoern A. Zeeb #endif 32546b4cac81SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_FAILED_FCS_CRC) 32556b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_BADFCS; 32566b4cac81SBjoern A. Zeeb rtap->wr_rate = 0; 32576b4cac81SBjoern A. Zeeb IMPROVE(); 32586b4cac81SBjoern A. Zeeb /* XXX TODO status->encoding / rate_index / bw */ 32596b4cac81SBjoern A. Zeeb rtap->wr_chan_freq = htole16(rx_stats.c_freq); 32606b4cac81SBjoern A. Zeeb if (ic->ic_curchan->ic_ieee == rx_stats.c_ieee) 32616b4cac81SBjoern A. Zeeb rtap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags); 32626b4cac81SBjoern A. Zeeb rtap->wr_dbm_antsignal = rx_stats.c_rssi; 32636b4cac81SBjoern A. Zeeb rtap->wr_dbm_antnoise = rx_stats.c_nf; 32646b4cac81SBjoern A. Zeeb } 32656b4cac81SBjoern A. Zeeb 32666b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, RX_INCLUDES_FCS)) 32676b4cac81SBjoern A. Zeeb m_adj(m, -IEEE80211_CRC_LEN); 32686b4cac81SBjoern A. Zeeb 32696b4cac81SBjoern A. Zeeb NET_EPOCH_ENTER(et); 32706b4cac81SBjoern A. Zeeb if (ni != NULL) { 32716b4cac81SBjoern A. Zeeb type = ieee80211_input_mimo(ni, m); 32726b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 32736b4cac81SBjoern A. Zeeb } else { 32746b4cac81SBjoern A. Zeeb type = ieee80211_input_mimo_all(ic, m); 32756b4cac81SBjoern A. Zeeb } 32766b4cac81SBjoern A. Zeeb NET_EPOCH_EXIT(et); 32776b4cac81SBjoern A. Zeeb 32786b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_RX) 32796b4cac81SBjoern A. Zeeb printf("TRACE %s: handled frame type %#0x\n", __func__, type); 32806b4cac81SBjoern A. Zeeb 32816b4cac81SBjoern A. Zeeb IMPROVE(); 32826b4cac81SBjoern A. Zeeb 32836b4cac81SBjoern A. Zeeb err: 32846b4cac81SBjoern A. Zeeb /* The skb is ours so we can free it :-) */ 32856b4cac81SBjoern A. Zeeb kfree_skb(skb); 32866b4cac81SBjoern A. Zeeb } 32876b4cac81SBjoern A. Zeeb 32886b4cac81SBjoern A. Zeeb uint8_t 32896b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_get_tid(struct ieee80211_hdr *hdr) 32906b4cac81SBjoern A. Zeeb { 32916b4cac81SBjoern A. Zeeb const struct ieee80211_frame *wh; 32926b4cac81SBjoern A. Zeeb 32936b4cac81SBjoern A. Zeeb wh = (const struct ieee80211_frame *)hdr; 32946b4cac81SBjoern A. Zeeb return (ieee80211_gettid(wh)); 32956b4cac81SBjoern A. Zeeb } 32966b4cac81SBjoern A. Zeeb 32976b4cac81SBjoern A. Zeeb struct wiphy * 32986b4cac81SBjoern A. Zeeb linuxkpi_wiphy_new(const struct cfg80211_ops *ops, size_t priv_len) 32996b4cac81SBjoern A. Zeeb { 33006b4cac81SBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 33016b4cac81SBjoern A. Zeeb 33026b4cac81SBjoern A. Zeeb lwiphy = kzalloc(sizeof(*lwiphy) + priv_len, GFP_KERNEL); 33036b4cac81SBjoern A. Zeeb if (lwiphy == NULL) 33046b4cac81SBjoern A. Zeeb return (NULL); 33056b4cac81SBjoern A. Zeeb lwiphy->ops = ops; 33066b4cac81SBjoern A. Zeeb 33076b4cac81SBjoern A. Zeeb /* XXX TODO */ 33086b4cac81SBjoern A. Zeeb return (LWIPHY_TO_WIPHY(lwiphy)); 33096b4cac81SBjoern A. Zeeb } 33106b4cac81SBjoern A. Zeeb 33116b4cac81SBjoern A. Zeeb void 33126b4cac81SBjoern A. Zeeb linuxkpi_wiphy_free(struct wiphy *wiphy) 33136b4cac81SBjoern A. Zeeb { 33146b4cac81SBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 33156b4cac81SBjoern A. Zeeb 33166b4cac81SBjoern A. Zeeb if (wiphy == NULL) 33176b4cac81SBjoern A. Zeeb return; 33186b4cac81SBjoern A. Zeeb 33196b4cac81SBjoern A. Zeeb lwiphy = WIPHY_TO_LWIPHY(wiphy); 33206b4cac81SBjoern A. Zeeb kfree(lwiphy); 33216b4cac81SBjoern A. Zeeb } 33226b4cac81SBjoern A. Zeeb 33236b4cac81SBjoern A. Zeeb uint32_t 33246b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_channel_to_frequency(uint32_t channel, 33256b4cac81SBjoern A. Zeeb enum nl80211_band band) 33266b4cac81SBjoern A. Zeeb { 33276b4cac81SBjoern A. Zeeb 33286b4cac81SBjoern A. Zeeb switch (band) { 33296b4cac81SBjoern A. Zeeb case NL80211_BAND_2GHZ: 33306b4cac81SBjoern A. Zeeb return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_2GHZ)); 33316b4cac81SBjoern A. Zeeb break; 33326b4cac81SBjoern A. Zeeb case NL80211_BAND_5GHZ: 33336b4cac81SBjoern A. Zeeb return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_5GHZ)); 33346b4cac81SBjoern A. Zeeb break; 33356b4cac81SBjoern A. Zeeb default: 33366b4cac81SBjoern A. Zeeb /* XXX abort, retry, error, panic? */ 33376b4cac81SBjoern A. Zeeb break; 33386b4cac81SBjoern A. Zeeb } 33396b4cac81SBjoern A. Zeeb 33406b4cac81SBjoern A. Zeeb return (0); 33416b4cac81SBjoern A. Zeeb } 33426b4cac81SBjoern A. Zeeb 33436b4cac81SBjoern A. Zeeb uint32_t 33446b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_frequency_to_channel(uint32_t freq, uint32_t flags __unused) 33456b4cac81SBjoern A. Zeeb { 33466b4cac81SBjoern A. Zeeb 33476b4cac81SBjoern A. Zeeb return (ieee80211_mhz2ieee(freq, 0)); 33486b4cac81SBjoern A. Zeeb } 33496b4cac81SBjoern A. Zeeb 33506b4cac81SBjoern A. Zeeb static struct lkpi_sta * 33516b4cac81SBjoern A. Zeeb lkpi_find_lsta_by_ni(struct lkpi_vif *lvif, struct ieee80211_node *ni) 33526b4cac81SBjoern A. Zeeb { 33536b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta, *temp; 33546b4cac81SBjoern A. Zeeb 33556b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 33566b4cac81SBjoern A. Zeeb TAILQ_FOREACH_SAFE(lsta, &lvif->lsta_head, lsta_entry, temp) { 33576b4cac81SBjoern A. Zeeb if (lsta->ni == ni) { 33586b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 33596b4cac81SBjoern A. Zeeb return (lsta); 33606b4cac81SBjoern A. Zeeb } 33616b4cac81SBjoern A. Zeeb } 33626b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 33636b4cac81SBjoern A. Zeeb 33646b4cac81SBjoern A. Zeeb return (NULL); 33656b4cac81SBjoern A. Zeeb } 33666b4cac81SBjoern A. Zeeb 33676b4cac81SBjoern A. Zeeb struct ieee80211_sta * 33686b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_find_sta(struct ieee80211_vif *vif, const u8 *peer) 33696b4cac81SBjoern A. Zeeb { 33706b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 33716b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta, *temp; 33726b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 33736b4cac81SBjoern A. Zeeb 33746b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 33756b4cac81SBjoern A. Zeeb 33766b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 33776b4cac81SBjoern A. Zeeb TAILQ_FOREACH_SAFE(lsta, &lvif->lsta_head, lsta_entry, temp) { 33786b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 33796b4cac81SBjoern A. Zeeb if (IEEE80211_ADDR_EQ(sta->addr, peer)) { 33806b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 33816b4cac81SBjoern A. Zeeb return (sta); 33826b4cac81SBjoern A. Zeeb } 33836b4cac81SBjoern A. Zeeb } 33846b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 33856b4cac81SBjoern A. Zeeb return (NULL); 33866b4cac81SBjoern A. Zeeb } 33876b4cac81SBjoern A. Zeeb 33886b4cac81SBjoern A. Zeeb struct ieee80211_sta * 33896b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw, uint8_t *addr, 33906b4cac81SBjoern A. Zeeb uint8_t *ourvifaddr) 33916b4cac81SBjoern A. Zeeb { 33926b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 33936b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 33946b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 33956b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 33966b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 33976b4cac81SBjoern A. Zeeb 33986b4cac81SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 33996b4cac81SBjoern A. Zeeb sta = NULL; 34006b4cac81SBjoern A. Zeeb 34016b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 34026b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 34036b4cac81SBjoern A. Zeeb 34046b4cac81SBjoern A. Zeeb /* XXX-BZ check our address from the vif. */ 34056b4cac81SBjoern A. Zeeb 34066b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 34076b4cac81SBjoern A. Zeeb if (ourvifaddr != NULL && 34086b4cac81SBjoern A. Zeeb !IEEE80211_ADDR_EQ(vif->addr, ourvifaddr)) 34096b4cac81SBjoern A. Zeeb continue; 34106b4cac81SBjoern A. Zeeb sta = linuxkpi_ieee80211_find_sta(vif, addr); 34116b4cac81SBjoern A. Zeeb if (sta != NULL) 34126b4cac81SBjoern A. Zeeb break; 34136b4cac81SBjoern A. Zeeb } 34146b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 34156b4cac81SBjoern A. Zeeb 34166b4cac81SBjoern A. Zeeb if (sta != NULL) { 34176b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 34186b4cac81SBjoern A. Zeeb if (!lsta->added_to_drv) 34196b4cac81SBjoern A. Zeeb return (NULL); 34206b4cac81SBjoern A. Zeeb } 34216b4cac81SBjoern A. Zeeb 34226b4cac81SBjoern A. Zeeb return (sta); 34236b4cac81SBjoern A. Zeeb } 34246b4cac81SBjoern A. Zeeb 34256b4cac81SBjoern A. Zeeb struct sk_buff * 34266b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_tx_dequeue(struct ieee80211_hw *hw, 34276b4cac81SBjoern A. Zeeb struct ieee80211_txq *txq) 34286b4cac81SBjoern A. Zeeb { 34296b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 34306b4cac81SBjoern A. Zeeb struct sk_buff *skb; 34316b4cac81SBjoern A. Zeeb 34326b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 34336b4cac81SBjoern A. Zeeb ltxq->seen_dequeue = true; 34346b4cac81SBjoern A. Zeeb 34356b4cac81SBjoern A. Zeeb skb = skb_dequeue(<xq->skbq); 34366b4cac81SBjoern A. Zeeb 34376b4cac81SBjoern A. Zeeb return (skb); 34386b4cac81SBjoern A. Zeeb } 34396b4cac81SBjoern A. Zeeb 34406b4cac81SBjoern A. Zeeb void 34416b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_txq_get_depth(struct ieee80211_txq *txq, 34426b4cac81SBjoern A. Zeeb uint64_t *frame_cnt, uint64_t *byte_cnt) 34436b4cac81SBjoern A. Zeeb { 34446b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 34456b4cac81SBjoern A. Zeeb struct sk_buff *skb; 34466b4cac81SBjoern A. Zeeb uint64_t fc, bc; 34476b4cac81SBjoern A. Zeeb 34486b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 34496b4cac81SBjoern A. Zeeb 34506b4cac81SBjoern A. Zeeb fc = bc = 0; 34516b4cac81SBjoern A. Zeeb skb_queue_walk(<xq->skbq, skb) { 34526b4cac81SBjoern A. Zeeb fc++; 34536b4cac81SBjoern A. Zeeb bc += skb->len; 34546b4cac81SBjoern A. Zeeb } 34556b4cac81SBjoern A. Zeeb if (frame_cnt) 34566b4cac81SBjoern A. Zeeb *frame_cnt = fc; 34576b4cac81SBjoern A. Zeeb if (byte_cnt) 34586b4cac81SBjoern A. Zeeb *byte_cnt = bc; 34596b4cac81SBjoern A. Zeeb 34606b4cac81SBjoern A. Zeeb /* Validate that this is doing the correct thing. */ 34616b4cac81SBjoern A. Zeeb /* Should we keep track on en/dequeue? */ 34626b4cac81SBjoern A. Zeeb IMPROVE(); 34636b4cac81SBjoern A. Zeeb } 34646b4cac81SBjoern A. Zeeb 34656b4cac81SBjoern A. Zeeb /* 34666b4cac81SBjoern A. Zeeb * We are called from ieee80211_free_txskb() or ieee80211_tx_status(). 34676b4cac81SBjoern A. Zeeb * The latter tries to derive the success status from the info flags 34686b4cac81SBjoern A. Zeeb * passed back from the driver. rawx_mit() saves the ni on the m and the 34696b4cac81SBjoern A. Zeeb * m on the skb for us to be able to give feedback to net80211. 34706b4cac81SBjoern A. Zeeb */ 34716b4cac81SBjoern A. Zeeb void 34726b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb, 34736b4cac81SBjoern A. Zeeb int status) 34746b4cac81SBjoern A. Zeeb { 34756b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 34766b4cac81SBjoern A. Zeeb struct mbuf *m; 34776b4cac81SBjoern A. Zeeb 34786b4cac81SBjoern A. Zeeb m = skb->m; 34796b4cac81SBjoern A. Zeeb skb->m = NULL; 34806b4cac81SBjoern A. Zeeb 34816b4cac81SBjoern A. Zeeb if (m != NULL) { 34826b4cac81SBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 34836b4cac81SBjoern A. Zeeb /* Status: 0 is ok, != 0 is error. */ 34846b4cac81SBjoern A. Zeeb ieee80211_tx_complete(ni, m, status); 34856b4cac81SBjoern A. Zeeb /* ni & mbuf were consumed. */ 34866b4cac81SBjoern A. Zeeb } 34876b4cac81SBjoern A. Zeeb 34886b4cac81SBjoern A. Zeeb kfree_skb(skb); 34896b4cac81SBjoern A. Zeeb } 34906b4cac81SBjoern A. Zeeb 34916b4cac81SBjoern A. Zeeb /* 34926b4cac81SBjoern A. Zeeb * This is an internal bandaid for the moment for the way we glue 34936b4cac81SBjoern A. Zeeb * skbs and mbufs together for TX. Once we have skbs backed by 34946b4cac81SBjoern A. Zeeb * mbufs this should go away. 34956b4cac81SBjoern A. Zeeb * This is a public function but kept on the private KPI (lkpi_) 34966b4cac81SBjoern A. Zeeb * and is not exposed by a header file. 34976b4cac81SBjoern A. Zeeb */ 34986b4cac81SBjoern A. Zeeb static void 34996b4cac81SBjoern A. Zeeb lkpi_ieee80211_free_skb_mbuf(void *p) 35006b4cac81SBjoern A. Zeeb { 35016b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 35026b4cac81SBjoern A. Zeeb struct mbuf *m; 35036b4cac81SBjoern A. Zeeb 35046b4cac81SBjoern A. Zeeb if (p == NULL) 35056b4cac81SBjoern A. Zeeb return; 35066b4cac81SBjoern A. Zeeb 35076b4cac81SBjoern A. Zeeb m = (struct mbuf *)p; 35086b4cac81SBjoern A. Zeeb M_ASSERTPKTHDR(m); 35096b4cac81SBjoern A. Zeeb 35106b4cac81SBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 35116b4cac81SBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = NULL; 35126b4cac81SBjoern A. Zeeb if (ni != NULL) 35136b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 35146b4cac81SBjoern A. Zeeb m_freem(m); 35156b4cac81SBjoern A. Zeeb } 35166b4cac81SBjoern A. Zeeb 35176b4cac81SBjoern A. Zeeb void 35186b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_queue_delayed_work(struct ieee80211_hw *hw, 35196b4cac81SBjoern A. Zeeb struct delayed_work *w, int delay) 35206b4cac81SBjoern A. Zeeb { 35216b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 35226b4cac81SBjoern A. Zeeb 35236b4cac81SBjoern A. Zeeb /* Need to make sure hw is in a stable (non-suspended) state. */ 35246b4cac81SBjoern A. Zeeb IMPROVE(); 35256b4cac81SBjoern A. Zeeb 35266b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 35276b4cac81SBjoern A. Zeeb queue_delayed_work(lhw->workq, w, delay); 35286b4cac81SBjoern A. Zeeb } 35296b4cac81SBjoern A. Zeeb 35306b4cac81SBjoern A. Zeeb void 35316b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_queue_work(struct ieee80211_hw *hw, 35326b4cac81SBjoern A. Zeeb struct work_struct *w) 35336b4cac81SBjoern A. Zeeb { 35346b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 35356b4cac81SBjoern A. Zeeb 35366b4cac81SBjoern A. Zeeb /* Need to make sure hw is in a stable (non-suspended) state. */ 35376b4cac81SBjoern A. Zeeb IMPROVE(); 35386b4cac81SBjoern A. Zeeb 35396b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 35406b4cac81SBjoern A. Zeeb queue_work(lhw->workq, w); 35416b4cac81SBjoern A. Zeeb } 35426b4cac81SBjoern A. Zeeb 35436b4cac81SBjoern A. Zeeb struct sk_buff * 35446b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_pspoll_get(struct ieee80211_hw *hw, 35456b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif) 35466b4cac81SBjoern A. Zeeb { 35476b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 35486b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 35496b4cac81SBjoern A. Zeeb struct sk_buff *skb; 35506b4cac81SBjoern A. Zeeb struct ieee80211_frame_pspoll *psp; 35516b4cac81SBjoern A. Zeeb uint16_t v; 35526b4cac81SBjoern A. Zeeb 35536b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*psp)); 35546b4cac81SBjoern A. Zeeb if (skb == NULL) 35556b4cac81SBjoern A. Zeeb return (NULL); 35566b4cac81SBjoern A. Zeeb 35576b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 35586b4cac81SBjoern A. Zeeb 35596b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 35606b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 35616b4cac81SBjoern A. Zeeb 35626b4cac81SBjoern A. Zeeb psp = skb_put_zero(skb, sizeof(*psp)); 35636b4cac81SBjoern A. Zeeb psp->i_fc[0] = IEEE80211_FC0_VERSION_0; 35646b4cac81SBjoern A. Zeeb psp->i_fc[0] |= IEEE80211_FC0_SUBTYPE_PS_POLL | IEEE80211_FC0_TYPE_CTL; 35656b4cac81SBjoern A. Zeeb v = htole16(vif->bss_conf.aid | 1<<15 | 1<<16); 35666b4cac81SBjoern A. Zeeb memcpy(&psp->i_aid, &v, sizeof(v)); 35676b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(psp->i_bssid, vap->iv_bss->ni_macaddr); 35686b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(psp->i_ta, vif->addr); 35696b4cac81SBjoern A. Zeeb 35706b4cac81SBjoern A. Zeeb return (skb); 35716b4cac81SBjoern A. Zeeb } 35726b4cac81SBjoern A. Zeeb 35736b4cac81SBjoern A. Zeeb struct sk_buff * 35746b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_nullfunc_get(struct ieee80211_hw *hw, 35756b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif, bool qos) 35766b4cac81SBjoern A. Zeeb { 35776b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 35786b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 35796b4cac81SBjoern A. Zeeb struct sk_buff *skb; 35806b4cac81SBjoern A. Zeeb struct ieee80211_frame *nullf; 35816b4cac81SBjoern A. Zeeb 35826b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*nullf)); 35836b4cac81SBjoern A. Zeeb if (skb == NULL) 35846b4cac81SBjoern A. Zeeb return (NULL); 35856b4cac81SBjoern A. Zeeb 35866b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 35876b4cac81SBjoern A. Zeeb 35886b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 35896b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 35906b4cac81SBjoern A. Zeeb 35916b4cac81SBjoern A. Zeeb nullf = skb_put_zero(skb, sizeof(*nullf)); 35926b4cac81SBjoern A. Zeeb nullf->i_fc[0] = IEEE80211_FC0_VERSION_0; 35936b4cac81SBjoern A. Zeeb nullf->i_fc[0] |= IEEE80211_FC0_SUBTYPE_NODATA | IEEE80211_FC0_TYPE_DATA; 35946b4cac81SBjoern A. Zeeb nullf->i_fc[1] = IEEE80211_FC1_DIR_TODS; 35956b4cac81SBjoern A. Zeeb 35966b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr1, vap->iv_bss->ni_bssid); 35976b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr2, vif->addr); 35986b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr3, vap->iv_bss->ni_macaddr); 35996b4cac81SBjoern A. Zeeb 36006b4cac81SBjoern A. Zeeb return (skb); 36016b4cac81SBjoern A. Zeeb } 36026b4cac81SBjoern A. Zeeb 36036b4cac81SBjoern A. Zeeb struct wireless_dev * 36046b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_vif_to_wdev(struct ieee80211_vif *vif) 36056b4cac81SBjoern A. Zeeb { 36066b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 36076b4cac81SBjoern A. Zeeb 36086b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 36096b4cac81SBjoern A. Zeeb return (&lvif->wdev); 36106b4cac81SBjoern A. Zeeb } 36116b4cac81SBjoern A. Zeeb 36126b4cac81SBjoern A. Zeeb void 36136b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_connection_loss(struct ieee80211_vif *vif) 36146b4cac81SBjoern A. Zeeb { 36156b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 36166b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 36176b4cac81SBjoern A. Zeeb enum ieee80211_state nstate; 36186b4cac81SBjoern A. Zeeb int arg; 36196b4cac81SBjoern A. Zeeb 36206b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 36216b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 36226b4cac81SBjoern A. Zeeb 36236b4cac81SBjoern A. Zeeb /* 3624f3229b62SBjoern A. Zeeb * Go to init; otherwise we need to elaborately check state and 36256b4cac81SBjoern A. Zeeb * handle accordingly, e.g., if in RUN we could call iv_bmiss. 36266b4cac81SBjoern A. Zeeb * Let the statemachine handle all neccessary changes. 36276b4cac81SBjoern A. Zeeb */ 3628f3229b62SBjoern A. Zeeb nstate = IEEE80211_S_INIT; 36296b4cac81SBjoern A. Zeeb arg = 0; 36306b4cac81SBjoern A. Zeeb 36316b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE) 36326b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: vif %p\n", __func__, vif); 36336b4cac81SBjoern A. Zeeb ieee80211_new_state(vap, nstate, arg); 36346b4cac81SBjoern A. Zeeb } 36356b4cac81SBjoern A. Zeeb 36366b4cac81SBjoern A. Zeeb MODULE_VERSION(linuxkpi_wlan, 1); 36376b4cac81SBjoern A. Zeeb MODULE_DEPEND(linuxkpi_wlan, linuxkpi, 1, 1, 1); 36386b4cac81SBjoern A. Zeeb MODULE_DEPEND(linuxkpi_wlan, wlan, 1, 1, 1); 3639