16b4cac81SBjoern A. Zeeb /*- 2ec6185c5SBjoern A. Zeeb * Copyright (c) 2020-2025 The FreeBSD Foundation 3c272abc5SBjoern A. Zeeb * Copyright (c) 2020-2025 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 4211db70b6SBjoern A. Zeeb /* 4311db70b6SBjoern A. Zeeb * TODO: 4411db70b6SBjoern A. Zeeb * - lots :) 4511db70b6SBjoern A. Zeeb * - HW_CRYPTO: we need a "keystore" and an ordered list for suspend/resume. 4611db70b6SBjoern A. Zeeb */ 4711db70b6SBjoern A. Zeeb 486b4cac81SBjoern A. Zeeb #include <sys/param.h> 496b4cac81SBjoern A. Zeeb #include <sys/types.h> 506b4cac81SBjoern A. Zeeb #include <sys/kernel.h> 516b4cac81SBjoern A. Zeeb #include <sys/errno.h> 526b4cac81SBjoern A. Zeeb #include <sys/malloc.h> 536b4cac81SBjoern A. Zeeb #include <sys/module.h> 546b4cac81SBjoern A. Zeeb #include <sys/mutex.h> 5540839418SBjoern A. Zeeb #include <sys/sbuf.h> 566b4cac81SBjoern A. Zeeb #include <sys/socket.h> 576b4cac81SBjoern A. Zeeb #include <sys/sysctl.h> 586b4cac81SBjoern A. Zeeb #include <sys/queue.h> 596b4cac81SBjoern A. Zeeb #include <sys/taskqueue.h> 60527687a9SBjoern A. Zeeb #include <sys/libkern.h> 616b4cac81SBjoern A. Zeeb 626b4cac81SBjoern A. Zeeb #include <net/if.h> 636b4cac81SBjoern A. Zeeb #include <net/if_var.h> 646b4cac81SBjoern A. Zeeb #include <net/if_media.h> 656b4cac81SBjoern A. Zeeb #include <net/ethernet.h> 666b4cac81SBjoern A. Zeeb 676b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_var.h> 686b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_proto.h> 696b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_ratectl.h> 706b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_radiotap.h> 719fb91463SBjoern A. Zeeb #include <net80211/ieee80211_vht.h> 726b4cac81SBjoern A. Zeeb 736b4cac81SBjoern A. Zeeb #define LINUXKPI_NET80211 746b4cac81SBjoern A. Zeeb #include <net/mac80211.h> 756b4cac81SBjoern A. Zeeb 766b4cac81SBjoern A. Zeeb #include <linux/workqueue.h> 77a8f735a6SBjoern A. Zeeb #include <linux/rculist.h> 786b4cac81SBjoern A. Zeeb #include "linux_80211.h" 796b4cac81SBjoern A. Zeeb 804a67f1dfSBjoern A. Zeeb #define LKPI_80211_WME 8111db70b6SBjoern A. Zeeb #define LKPI_80211_HW_CRYPTO 829fb91463SBjoern A. Zeeb /* #define LKPI_80211_HT */ 8311db70b6SBjoern A. Zeeb /* #define LKPI_80211_VHT */ 8411db70b6SBjoern A. Zeeb 859fb91463SBjoern A. Zeeb #if defined(LKPI_80211_VHT) && !defined(LKPI_80211_HT) 869fb91463SBjoern A. Zeeb #define LKPI_80211_HT 879fb91463SBjoern A. Zeeb #endif 8811db70b6SBjoern A. Zeeb #if defined(LKPI_80211_HT) && !defined(LKPI_80211_HW_CRYPTO) 8911db70b6SBjoern A. Zeeb #define LKPI_80211_HW_CRYPTO 9011db70b6SBjoern A. Zeeb #endif 91b35f6cd0SBjoern A. Zeeb 926b4cac81SBjoern A. Zeeb static MALLOC_DEFINE(M_LKPI80211, "lkpi80211", "LinuxKPI 80211 compat"); 936b4cac81SBjoern A. Zeeb 945a9a0d78SBjoern A. Zeeb /* XXX-BZ really want this and others in queue.h */ 955a9a0d78SBjoern A. Zeeb #define TAILQ_ELEM_INIT(elm, field) do { \ 965a9a0d78SBjoern A. Zeeb (elm)->field.tqe_next = NULL; \ 975a9a0d78SBjoern A. Zeeb (elm)->field.tqe_prev = NULL; \ 985a9a0d78SBjoern A. Zeeb } while (0) 995a9a0d78SBjoern A. Zeeb 1006b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 1016b4cac81SBjoern A. Zeeb 1029d9ba2b7SBjoern A. Zeeb SYSCTL_DECL(_compat_linuxkpi); 1039d9ba2b7SBjoern A. Zeeb SYSCTL_NODE(_compat_linuxkpi, OID_AUTO, 80211, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 1049d9ba2b7SBjoern A. Zeeb "LinuxKPI 802.11 compatibility layer"); 1059d9ba2b7SBjoern A. Zeeb 10611db70b6SBjoern A. Zeeb #if defined(LKPI_80211_HW_CRYPTO) 10711db70b6SBjoern A. Zeeb static bool lkpi_hwcrypto = false; 10811db70b6SBjoern A. Zeeb SYSCTL_BOOL(_compat_linuxkpi_80211, OID_AUTO, hw_crypto, CTLFLAG_RDTUN, 10911db70b6SBjoern A. Zeeb &lkpi_hwcrypto, 0, "Enable LinuxKPI 802.11 hardware crypto offload"); 11011db70b6SBjoern A. Zeeb #endif 11111db70b6SBjoern A. Zeeb 11240839418SBjoern A. Zeeb /* Keep public for as long as header files are using it too. */ 11340839418SBjoern A. Zeeb int linuxkpi_debug_80211; 11440839418SBjoern A. Zeeb 11540839418SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 1169d9ba2b7SBjoern A. Zeeb SYSCTL_INT(_compat_linuxkpi_80211, OID_AUTO, debug, CTLFLAG_RWTUN, 1179d9ba2b7SBjoern A. Zeeb &linuxkpi_debug_80211, 0, "LinuxKPI 802.11 debug level"); 1189d9ba2b7SBjoern A. Zeeb 1199d9ba2b7SBjoern A. Zeeb #define UNIMPLEMENTED if (linuxkpi_debug_80211 & D80211_TODO) \ 1206b4cac81SBjoern A. Zeeb printf("XXX-TODO %s:%d: UNIMPLEMENTED\n", __func__, __LINE__) 1219d9ba2b7SBjoern A. Zeeb #define TRACEOK() if (linuxkpi_debug_80211 & D80211_TRACEOK) \ 1226b4cac81SBjoern A. Zeeb printf("XXX-TODO %s:%d: TRACEPOINT\n", __func__, __LINE__) 1236b4cac81SBjoern A. Zeeb #else 1246b4cac81SBjoern A. Zeeb #define UNIMPLEMENTED do { } while (0) 1256b4cac81SBjoern A. Zeeb #define TRACEOK() do { } while (0) 1266b4cac81SBjoern A. Zeeb #endif 1276b4cac81SBjoern A. Zeeb 1286b4cac81SBjoern A. Zeeb /* #define PREP_TX_INFO_DURATION (IEEE80211_TRANS_WAIT * 1000) */ 1296b4cac81SBjoern A. Zeeb #ifndef PREP_TX_INFO_DURATION 1306b4cac81SBjoern A. Zeeb #define PREP_TX_INFO_DURATION 0 /* Let the driver do its thing. */ 1316b4cac81SBjoern A. Zeeb #endif 1326b4cac81SBjoern A. Zeeb 1336b4cac81SBjoern A. Zeeb /* This is DSAP | SSAP | CTRL | ProtoID/OrgCode{3}. */ 1346b4cac81SBjoern A. Zeeb const uint8_t rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; 1356b4cac81SBjoern A. Zeeb 136b0f73768SBjoern A. Zeeb /* IEEE 802.11-05/0257r1 */ 137b0f73768SBjoern A. Zeeb const uint8_t bridge_tunnel_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; 138b0f73768SBjoern A. Zeeb 139fb3c249eSBjoern A. Zeeb /* IEEE 802.11e Table 20i-UP-to-AC mappings. */ 140fb3c249eSBjoern A. Zeeb static const uint8_t ieee80211e_up_to_ac[] = { 1414f61ef8bSBjoern A. Zeeb IEEE80211_AC_BE, 1424f61ef8bSBjoern A. Zeeb IEEE80211_AC_BK, 1434f61ef8bSBjoern A. Zeeb IEEE80211_AC_BK, 1444f61ef8bSBjoern A. Zeeb IEEE80211_AC_BE, 1454f61ef8bSBjoern A. Zeeb IEEE80211_AC_VI, 1464f61ef8bSBjoern A. Zeeb IEEE80211_AC_VI, 1474f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO, 1484f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO, 1494f61ef8bSBjoern A. Zeeb #if 0 1504f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO, /* We treat MGMT as TID 8, which is set as AC_VO */ 1514f61ef8bSBjoern A. Zeeb #endif 1524f61ef8bSBjoern A. Zeeb }; 1534f61ef8bSBjoern A. Zeeb 1546b4cac81SBjoern A. Zeeb const struct cfg80211_ops linuxkpi_mac80211cfgops = { 1556b4cac81SBjoern A. Zeeb /* 1566b4cac81SBjoern A. Zeeb * XXX TODO need a "glue layer" to link cfg80211 ops to 1576b4cac81SBjoern A. Zeeb * mac80211 and to the driver or net80211. 1586b4cac81SBjoern A. Zeeb * Can we pass some on 1:1? Need to compare the (*f)(). 1596b4cac81SBjoern A. Zeeb */ 1606b4cac81SBjoern A. Zeeb }; 1616b4cac81SBjoern A. Zeeb 162ac867c20SBjoern A. Zeeb #if 0 1636b4cac81SBjoern A. Zeeb static struct lkpi_sta *lkpi_find_lsta_by_ni(struct lkpi_vif *, 1646b4cac81SBjoern A. Zeeb struct ieee80211_node *); 165ac867c20SBjoern A. Zeeb #endif 16688665349SBjoern A. Zeeb static void lkpi_80211_txq_tx_one(struct lkpi_sta *, struct mbuf *); 1676b4cac81SBjoern A. Zeeb static void lkpi_80211_txq_task(void *, int); 168759a996dSBjoern A. Zeeb static void lkpi_80211_lhw_rxq_task(void *, int); 1696b4cac81SBjoern A. Zeeb static void lkpi_ieee80211_free_skb_mbuf(void *); 1704a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 1714a67f1dfSBjoern A. Zeeb static int lkpi_wme_update(struct lkpi_hw *, struct ieee80211vap *, bool); 1724a67f1dfSBjoern A. Zeeb #endif 1736b4cac81SBjoern A. Zeeb 17440839418SBjoern A. Zeeb static const char * 17540839418SBjoern A. Zeeb lkpi_rate_info_bw_to_str(enum rate_info_bw bw) 17640839418SBjoern A. Zeeb { 17740839418SBjoern A. Zeeb 17840839418SBjoern A. Zeeb switch (bw) { 17940839418SBjoern A. Zeeb 18040839418SBjoern A. Zeeb case RATE_INFO_BW_20: 18140839418SBjoern A. Zeeb return ("20"); 18240839418SBjoern A. Zeeb break; 18340839418SBjoern A. Zeeb case RATE_INFO_BW_5: 18440839418SBjoern A. Zeeb return ("5"); 18540839418SBjoern A. Zeeb break; 18640839418SBjoern A. Zeeb case RATE_INFO_BW_10: 18740839418SBjoern A. Zeeb return ("10"); 18840839418SBjoern A. Zeeb break; 18940839418SBjoern A. Zeeb case RATE_INFO_BW_40: 19040839418SBjoern A. Zeeb return ("40"); 19140839418SBjoern A. Zeeb break; 19240839418SBjoern A. Zeeb case RATE_INFO_BW_80: 19340839418SBjoern A. Zeeb return ("80"); 19440839418SBjoern A. Zeeb break; 19540839418SBjoern A. Zeeb case RATE_INFO_BW_160: 19640839418SBjoern A. Zeeb return ("160"); 19740839418SBjoern A. Zeeb break; 19840839418SBjoern A. Zeeb case RATE_INFO_BW_HE_RU: 19940839418SBjoern A. Zeeb IMPROVE("nl80211_he_ru_alloc"); 20040839418SBjoern A. Zeeb return ("HE_RU"); 20140839418SBjoern A. Zeeb break; 20240839418SBjoern A. Zeeb case RATE_INFO_BW_320: 20340839418SBjoern A. Zeeb return ("320"); 20440839418SBjoern A. Zeeb break; 20540839418SBjoern A. Zeeb case RATE_INFO_BW_EHT_RU: 20640839418SBjoern A. Zeeb IMPROVE("nl80211_eht_ru_alloc"); 20740839418SBjoern A. Zeeb return ("EHT_RU"); 20840839418SBjoern A. Zeeb break; 20940839418SBjoern A. Zeeb default: 21040839418SBjoern A. Zeeb return ("?"); 21140839418SBjoern A. Zeeb break; 21240839418SBjoern A. Zeeb } 21340839418SBjoern A. Zeeb } 21440839418SBjoern A. Zeeb 21540839418SBjoern A. Zeeb static void 21640839418SBjoern A. Zeeb lkpi_nl80211_sta_info_to_str(struct sbuf *s, const char *prefix, 21740839418SBjoern A. Zeeb const uint64_t flags) 21840839418SBjoern A. Zeeb { 21940839418SBjoern A. Zeeb int bit, i; 22040839418SBjoern A. Zeeb 22140839418SBjoern A. Zeeb sbuf_printf(s, "%s %#010jx", prefix, flags); 22240839418SBjoern A. Zeeb 22340839418SBjoern A. Zeeb i = 0; 22440839418SBjoern A. Zeeb for (bit = 0; bit < BITS_PER_TYPE(flags); bit++) { 22540839418SBjoern A. Zeeb 22640839418SBjoern A. Zeeb if ((flags & BIT_ULL(bit)) == 0) 22740839418SBjoern A. Zeeb continue; 22840839418SBjoern A. Zeeb 22940839418SBjoern A. Zeeb #define EXPAND_CASE(_flag) \ 23040839418SBjoern A. Zeeb case NL80211_STA_INFO_ ## _flag: \ 23140839418SBjoern A. Zeeb sbuf_printf(s, "%c%s", (i == 0) ? '<' : ',', #_flag); \ 23240839418SBjoern A. Zeeb i++; \ 23340839418SBjoern A. Zeeb break; 23440839418SBjoern A. Zeeb 23540839418SBjoern A. Zeeb switch (bit) { 23640839418SBjoern A. Zeeb EXPAND_CASE(BEACON_RX) 23740839418SBjoern A. Zeeb EXPAND_CASE(BEACON_SIGNAL_AVG) 23840839418SBjoern A. Zeeb EXPAND_CASE(BSS_PARAM) 23940839418SBjoern A. Zeeb EXPAND_CASE(CHAIN_SIGNAL) 24040839418SBjoern A. Zeeb EXPAND_CASE(CHAIN_SIGNAL_AVG) 24140839418SBjoern A. Zeeb EXPAND_CASE(CONNECTED_TIME) 24240839418SBjoern A. Zeeb EXPAND_CASE(INACTIVE_TIME) 24340839418SBjoern A. Zeeb EXPAND_CASE(SIGNAL) 24440839418SBjoern A. Zeeb EXPAND_CASE(SIGNAL_AVG) 24540839418SBjoern A. Zeeb EXPAND_CASE(STA_FLAGS) 24640839418SBjoern A. Zeeb EXPAND_CASE(RX_BITRATE) 24740839418SBjoern A. Zeeb EXPAND_CASE(RX_PACKETS) 24840839418SBjoern A. Zeeb EXPAND_CASE(RX_BYTES) 24940839418SBjoern A. Zeeb EXPAND_CASE(RX_DROP_MISC) 25040839418SBjoern A. Zeeb EXPAND_CASE(TX_BITRATE) 25140839418SBjoern A. Zeeb EXPAND_CASE(TX_PACKETS) 25240839418SBjoern A. Zeeb EXPAND_CASE(TX_BYTES) 25340839418SBjoern A. Zeeb EXPAND_CASE(TX_BYTES64) 25440839418SBjoern A. Zeeb EXPAND_CASE(RX_BYTES64) 25540839418SBjoern A. Zeeb EXPAND_CASE(TX_FAILED) 25640839418SBjoern A. Zeeb EXPAND_CASE(TX_RETRIES) 25740839418SBjoern A. Zeeb EXPAND_CASE(RX_DURATION) 25840839418SBjoern A. Zeeb EXPAND_CASE(TX_DURATION) 25940839418SBjoern A. Zeeb EXPAND_CASE(ACK_SIGNAL) 26040839418SBjoern A. Zeeb EXPAND_CASE(ACK_SIGNAL_AVG) 26140839418SBjoern A. Zeeb default: 26240839418SBjoern A. Zeeb sbuf_printf(s, "%c?%d", (i == 0) ? '<' : ',', bit); 26340839418SBjoern A. Zeeb break; 26440839418SBjoern A. Zeeb } 26540839418SBjoern A. Zeeb } 26640839418SBjoern A. Zeeb #undef EXPAND_CASE 26740839418SBjoern A. Zeeb if (i > 0) 26840839418SBjoern A. Zeeb sbuf_printf(s, ">"); 26940839418SBjoern A. Zeeb sbuf_printf(s, "\n"); 27040839418SBjoern A. Zeeb } 27140839418SBjoern A. Zeeb 27240839418SBjoern A. Zeeb static int 27340839418SBjoern A. Zeeb lkpi_80211_dump_stas(SYSCTL_HANDLER_ARGS) 27440839418SBjoern A. Zeeb { 27540839418SBjoern A. Zeeb struct lkpi_hw *lhw; 27640839418SBjoern A. Zeeb struct ieee80211_hw *hw; 27740839418SBjoern A. Zeeb struct ieee80211vap *vap; 27840839418SBjoern A. Zeeb struct lkpi_vif *lvif; 27940839418SBjoern A. Zeeb struct ieee80211_vif *vif; 28040839418SBjoern A. Zeeb struct lkpi_sta *lsta; 28140839418SBjoern A. Zeeb struct ieee80211_sta *sta; 28240839418SBjoern A. Zeeb struct station_info sinfo; 28340839418SBjoern A. Zeeb struct sbuf s; 28440839418SBjoern A. Zeeb int error; 28540839418SBjoern A. Zeeb 28640839418SBjoern A. Zeeb if (req->newptr) 28740839418SBjoern A. Zeeb return (EPERM); 28840839418SBjoern A. Zeeb 28940839418SBjoern A. Zeeb lvif = (struct lkpi_vif *)arg1; 29040839418SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 29140839418SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 29240839418SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 29340839418SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 29440839418SBjoern A. Zeeb 29540839418SBjoern A. Zeeb sbuf_new_for_sysctl(&s, NULL, 1024, req); 29640839418SBjoern A. Zeeb 29740839418SBjoern A. Zeeb wiphy_lock(hw->wiphy); 298a8f735a6SBjoern A. Zeeb list_for_each_entry(lsta, &lvif->lsta_list, lsta_list) { 29940839418SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 30040839418SBjoern A. Zeeb 30140839418SBjoern A. Zeeb sbuf_putc(&s, '\n'); 30240839418SBjoern A. Zeeb sbuf_printf(&s, "lsta %p sta %p added_to_drv %d\n", lsta, sta, lsta->added_to_drv); 30340839418SBjoern A. Zeeb 30440839418SBjoern A. Zeeb memset(&sinfo, 0, sizeof(sinfo)); 30540839418SBjoern A. Zeeb error = lkpi_80211_mo_sta_statistics(hw, vif, sta, &sinfo); 30640839418SBjoern A. Zeeb if (error == EEXIST) /* Not added to driver. */ 30740839418SBjoern A. Zeeb continue; 30840839418SBjoern A. Zeeb if (error == ENOTSUPP) { 30940839418SBjoern A. Zeeb sbuf_printf(&s, " sta_statistics not supported\n"); 31040839418SBjoern A. Zeeb continue; 31140839418SBjoern A. Zeeb } 31240839418SBjoern A. Zeeb if (error != 0) { 31340839418SBjoern A. Zeeb sbuf_printf(&s, " sta_statistics failed: %d\n", error); 31440839418SBjoern A. Zeeb continue; 31540839418SBjoern A. Zeeb } 31640839418SBjoern A. Zeeb 31740839418SBjoern A. Zeeb lkpi_nl80211_sta_info_to_str(&s, " nl80211_sta_info (valid fields)", sinfo.filled); 31840839418SBjoern A. Zeeb sbuf_printf(&s, " connected_time %u inactive_time %u\n", 31940839418SBjoern A. Zeeb sinfo.connected_time, sinfo.inactive_time); 32040839418SBjoern A. Zeeb sbuf_printf(&s, " rx_bytes %ju rx_packets %u rx_dropped_misc %u\n", 32140839418SBjoern A. Zeeb (uintmax_t)sinfo.rx_bytes, sinfo.rx_packets, sinfo.rx_dropped_misc); 32240839418SBjoern A. Zeeb sbuf_printf(&s, " rx_duration %ju rx_beacon %u rx_beacon_signal_avg %d\n", 32340839418SBjoern A. Zeeb (uintmax_t)sinfo.rx_duration, sinfo.rx_beacon, (int8_t)sinfo.rx_beacon_signal_avg); 32440839418SBjoern A. Zeeb 32540839418SBjoern A. Zeeb sbuf_printf(&s, " tx_bytes %ju tx_packets %u tx_failed %u\n", 32640839418SBjoern A. Zeeb (uintmax_t)sinfo.tx_bytes, sinfo.tx_packets, sinfo.tx_failed); 32740839418SBjoern A. Zeeb sbuf_printf(&s, " tx_duration %ju tx_retries %u\n", 32840839418SBjoern A. Zeeb (uintmax_t)sinfo.tx_duration, sinfo.tx_retries); 32940839418SBjoern A. Zeeb 33040839418SBjoern A. Zeeb sbuf_printf(&s, " signal %d signal_avg %d ack_signal %d avg_ack_signal %d\n", 33140839418SBjoern A. Zeeb sinfo.signal, sinfo.signal_avg, sinfo.ack_signal, sinfo.avg_ack_signal); 33240839418SBjoern A. Zeeb 33340839418SBjoern A. Zeeb sbuf_printf(&s, " generation %d assoc_req_ies_len %zu chains %d\n", 33440839418SBjoern A. Zeeb sinfo.generation, sinfo.assoc_req_ies_len, sinfo.chains); 33540839418SBjoern A. Zeeb 33640839418SBjoern A. Zeeb for (int i = 0; i < sinfo.chains && i < IEEE80211_MAX_CHAINS; i++) { 33740839418SBjoern A. Zeeb sbuf_printf(&s, " chain[%d] signal %d signal_avg %d\n", 33840839418SBjoern A. Zeeb i, (int8_t)sinfo.chain_signal[i], (int8_t)sinfo.chain_signal_avg[i]); 33940839418SBjoern A. Zeeb } 34040839418SBjoern A. Zeeb 34140839418SBjoern A. Zeeb /* assoc_req_ies, bss_param, sta_flags */ 34240839418SBjoern A. Zeeb 34340839418SBjoern A. Zeeb sbuf_printf(&s, " rxrate: flags %b bw %u(%s) legacy %u kbit/s mcs %u nss %u\n", 34440839418SBjoern A. Zeeb sinfo.rxrate.flags, CFG80211_RATE_INFO_FLAGS_BITS, 34540839418SBjoern A. Zeeb sinfo.rxrate.bw, lkpi_rate_info_bw_to_str(sinfo.rxrate.bw), 34640839418SBjoern A. Zeeb sinfo.rxrate.legacy * 100, 34740839418SBjoern A. Zeeb sinfo.rxrate.mcs, sinfo.rxrate.nss); 34840839418SBjoern A. Zeeb sbuf_printf(&s, " he_dcm %u he_gi %u he_ru_alloc %u eht_gi %u\n", 34940839418SBjoern A. Zeeb sinfo.rxrate.he_dcm, sinfo.rxrate.he_gi, sinfo.rxrate.he_ru_alloc, 35040839418SBjoern A. Zeeb sinfo.rxrate.eht_gi); 35140839418SBjoern A. Zeeb sbuf_printf(&s, " txrate: flags %b bw %u(%s) legacy %u kbit/s mcs %u nss %u\n", 35240839418SBjoern A. Zeeb sinfo.txrate.flags, CFG80211_RATE_INFO_FLAGS_BITS, 35340839418SBjoern A. Zeeb sinfo.txrate.bw, lkpi_rate_info_bw_to_str(sinfo.txrate.bw), 35440839418SBjoern A. Zeeb sinfo.txrate.legacy * 100, 35540839418SBjoern A. Zeeb sinfo.txrate.mcs, sinfo.txrate.nss); 35640839418SBjoern A. Zeeb sbuf_printf(&s, " he_dcm %u he_gi %u he_ru_alloc %u eht_gi %u\n", 35740839418SBjoern A. Zeeb sinfo.txrate.he_dcm, sinfo.txrate.he_gi, sinfo.txrate.he_ru_alloc, 35840839418SBjoern A. Zeeb sinfo.txrate.eht_gi); 35940839418SBjoern A. Zeeb } 36040839418SBjoern A. Zeeb wiphy_unlock(hw->wiphy); 36140839418SBjoern A. Zeeb 36240839418SBjoern A. Zeeb sbuf_finish(&s); 36340839418SBjoern A. Zeeb sbuf_delete(&s); 36440839418SBjoern A. Zeeb 36540839418SBjoern A. Zeeb return (0); 36640839418SBjoern A. Zeeb } 36740839418SBjoern A. Zeeb 3689fb91463SBjoern A. Zeeb #if defined(LKPI_80211_HT) 3699fb91463SBjoern A. Zeeb static void 370*f9c7a07dSBjoern A. Zeeb lkpi_sta_sync_ht_from_ni(struct ieee80211_sta *sta, struct ieee80211_node *ni) 3719fb91463SBjoern A. Zeeb { 3729fb91463SBjoern A. Zeeb struct ieee80211vap *vap; 3739fb91463SBjoern A. Zeeb uint8_t *ie; 3749fb91463SBjoern A. Zeeb struct ieee80211_ht_cap *htcap; 3759fb91463SBjoern A. Zeeb int i, rx_nss; 3769fb91463SBjoern A. Zeeb 377*f9c7a07dSBjoern A. Zeeb if ((ni->ni_flags & IEEE80211_NODE_HT) == 0) { 378*f9c7a07dSBjoern A. Zeeb sta->deflink.ht_cap.ht_supported = false; 3799fb91463SBjoern A. Zeeb return; 380*f9c7a07dSBjoern A. Zeeb } 3819fb91463SBjoern A. Zeeb 3829fb91463SBjoern A. Zeeb sta->deflink.ht_cap.ht_supported = true; 3839fb91463SBjoern A. Zeeb 3849fb91463SBjoern A. Zeeb /* htcap->ampdu_params_info */ 3859fb91463SBjoern A. Zeeb vap = ni->ni_vap; 3869fb91463SBjoern A. Zeeb sta->deflink.ht_cap.ampdu_density = _IEEE80211_MASKSHIFT(ni->ni_htparam, IEEE80211_HTCAP_MPDUDENSITY); 3879fb91463SBjoern A. Zeeb if (sta->deflink.ht_cap.ampdu_density > vap->iv_ampdu_density) 3889fb91463SBjoern A. Zeeb sta->deflink.ht_cap.ampdu_density = vap->iv_ampdu_density; 3899fb91463SBjoern A. Zeeb sta->deflink.ht_cap.ampdu_factor = _IEEE80211_MASKSHIFT(ni->ni_htparam, IEEE80211_HTCAP_MAXRXAMPDU); 3909fb91463SBjoern A. Zeeb if (sta->deflink.ht_cap.ampdu_factor > vap->iv_ampdu_rxmax) 3919fb91463SBjoern A. Zeeb sta->deflink.ht_cap.ampdu_factor = vap->iv_ampdu_rxmax; 3929fb91463SBjoern A. Zeeb 3939fb91463SBjoern A. Zeeb ie = ni->ni_ies.htcap_ie; 3949fb91463SBjoern A. Zeeb KASSERT(ie != NULL, ("%s: HT but no htcap_ie on ni %p\n", __func__, ni)); 3959fb91463SBjoern A. Zeeb if (ie[0] == IEEE80211_ELEMID_VENDOR) 3969fb91463SBjoern A. Zeeb ie += 4; 3979fb91463SBjoern A. Zeeb ie += 2; 3989fb91463SBjoern A. Zeeb htcap = (struct ieee80211_ht_cap *)ie; 3999fb91463SBjoern A. Zeeb sta->deflink.ht_cap.cap = htcap->cap_info; 4009fb91463SBjoern A. Zeeb sta->deflink.ht_cap.mcs = htcap->mcs; 4019fb91463SBjoern A. Zeeb 402*f9c7a07dSBjoern A. Zeeb if ((sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) != 0) 403*f9c7a07dSBjoern A. Zeeb sta->deflink.bandwidth = IEEE80211_STA_RX_BW_40; 404*f9c7a07dSBjoern A. Zeeb 405*f9c7a07dSBjoern A. Zeeb /* 406*f9c7a07dSBjoern A. Zeeb * 802.11n-2009 20.6 Parameters for HT MCSs gives the mandatory/ 407*f9c7a07dSBjoern A. Zeeb * optional MCS for Nss=1..4. We need to check the first four 408*f9c7a07dSBjoern A. Zeeb * MCS sets from the Rx MCS Bitmask; then there is MCS 32 and 409*f9c7a07dSBjoern A. Zeeb * MCS33.. is UEQM. 410*f9c7a07dSBjoern A. Zeeb */ 4119fb91463SBjoern A. Zeeb rx_nss = 0; 412*f9c7a07dSBjoern A. Zeeb for (i = 0; i < 4; i++) { 4139fb91463SBjoern A. Zeeb if (htcap->mcs.rx_mask[i]) 4149fb91463SBjoern A. Zeeb rx_nss++; 4159fb91463SBjoern A. Zeeb } 416*f9c7a07dSBjoern A. Zeeb if (rx_nss > 0) 417*f9c7a07dSBjoern A. Zeeb sta->deflink.rx_nss = rx_nss; 4189fb91463SBjoern A. Zeeb 419*f9c7a07dSBjoern A. Zeeb IMPROVE("sta->wme"); 420*f9c7a07dSBjoern A. Zeeb 421*f9c7a07dSBjoern A. Zeeb if (sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_MAX_AMSDU) 422*f9c7a07dSBjoern A. Zeeb sta->deflink.agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_HT_7935; 423*f9c7a07dSBjoern A. Zeeb else 424*f9c7a07dSBjoern A. Zeeb sta->deflink.agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_HT_3839; 425*f9c7a07dSBjoern A. Zeeb sta->deflink.agg.max_rc_amsdu_len = IEEE80211_MAX_MPDU_LEN_HT_BA; 426*f9c7a07dSBjoern A. Zeeb #ifdef __handled_by_driver__ /* iwlwifi only? actually unused? */ 427*f9c7a07dSBjoern A. Zeeb for (i = 0; i < nitems(sta.deflink.agg.max_tid_amsdu_len); i++) { 428*f9c7a07dSBjoern A. Zeeb sta->deflink.agg.max_tid_amsdu_len[j] = ; 429*f9c7a07dSBjoern A. Zeeb } 430*f9c7a07dSBjoern A. Zeeb #endif 4319fb91463SBjoern A. Zeeb } 4329fb91463SBjoern A. Zeeb #endif 4339fb91463SBjoern A. Zeeb 4349fb91463SBjoern A. Zeeb #if defined(LKPI_80211_VHT) 4359fb91463SBjoern A. Zeeb static void 436*f9c7a07dSBjoern A. Zeeb lkpi_sta_sync_vht_from_ni(struct ieee80211_sta *sta, struct ieee80211_node *ni) 4379fb91463SBjoern A. Zeeb { 438*f9c7a07dSBjoern A. Zeeb uint32_t width; 439*f9c7a07dSBjoern A. Zeeb int rx_nss; 440*f9c7a07dSBjoern A. Zeeb uint16_t rx_mcs_map; 441*f9c7a07dSBjoern A. Zeeb uint8_t mcs; 4429fb91463SBjoern A. Zeeb 443*f9c7a07dSBjoern A. Zeeb if ((ni->ni_flags & IEEE80211_NODE_VHT) == 0) { 444*f9c7a07dSBjoern A. Zeeb sta->deflink.vht_cap.vht_supported = false; 4459fb91463SBjoern A. Zeeb return; 446*f9c7a07dSBjoern A. Zeeb } 4479fb91463SBjoern A. Zeeb 448*f9c7a07dSBjoern A. Zeeb sta->deflink.vht_cap.vht_supported = true; 449*f9c7a07dSBjoern A. Zeeb 450*f9c7a07dSBjoern A. Zeeb sta->deflink.vht_cap.cap = ni->ni_vhtcap; 451*f9c7a07dSBjoern A. Zeeb sta->deflink.vht_cap.vht_mcs = ni->ni_vht_mcsinfo; 452*f9c7a07dSBjoern A. Zeeb 453*f9c7a07dSBjoern A. Zeeb width = (sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK); 454*f9c7a07dSBjoern A. Zeeb switch (width) { 455*f9c7a07dSBjoern A. Zeeb #if 0 456*f9c7a07dSBjoern A. Zeeb case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ: 457*f9c7a07dSBjoern A. Zeeb case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ: 4589fb91463SBjoern A. Zeeb sta->deflink.bandwidth = IEEE80211_STA_RX_BW_160; 459*f9c7a07dSBjoern A. Zeeb break; 460*f9c7a07dSBjoern A. Zeeb #endif 461*f9c7a07dSBjoern A. Zeeb default: 462*f9c7a07dSBjoern A. Zeeb /* Check if we do support 160Mhz somehow after all. */ 463*f9c7a07dSBjoern A. Zeeb #if 0 464*f9c7a07dSBjoern A. Zeeb if ((sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_EXT_NSS_BW_MASK) != 0) 465*f9c7a07dSBjoern A. Zeeb sta->deflink.bandwidth = IEEE80211_STA_RX_BW_160; 466*f9c7a07dSBjoern A. Zeeb else 467*f9c7a07dSBjoern A. Zeeb #endif 4689fb91463SBjoern A. Zeeb sta->deflink.bandwidth = IEEE80211_STA_RX_BW_80; 4699fb91463SBjoern A. Zeeb } 4709fb91463SBjoern A. Zeeb 471*f9c7a07dSBjoern A. Zeeb 472*f9c7a07dSBjoern A. Zeeb rx_nss = 0; 473*f9c7a07dSBjoern A. Zeeb rx_mcs_map = sta->deflink.vht_cap.vht_mcs.rx_mcs_map; 474*f9c7a07dSBjoern A. Zeeb for (int i = 7; i >= 0; i--) { 475*f9c7a07dSBjoern A. Zeeb mcs = rx_mcs_map >> (2 * i); 476*f9c7a07dSBjoern A. Zeeb mcs &= 0x3; 477*f9c7a07dSBjoern A. Zeeb if (mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) { 478*f9c7a07dSBjoern A. Zeeb rx_nss = i + 1; 479*f9c7a07dSBjoern A. Zeeb break; 480*f9c7a07dSBjoern A. Zeeb } 481*f9c7a07dSBjoern A. Zeeb } 482*f9c7a07dSBjoern A. Zeeb if (rx_nss > 0) 483*f9c7a07dSBjoern A. Zeeb sta->deflink.rx_nss = rx_nss; 484*f9c7a07dSBjoern A. Zeeb 485*f9c7a07dSBjoern A. Zeeb switch (sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_MAX_MPDU_MASK) { 486*f9c7a07dSBjoern A. Zeeb case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454: 487*f9c7a07dSBjoern A. Zeeb sta->deflink.agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_11454; 488*f9c7a07dSBjoern A. Zeeb break; 489*f9c7a07dSBjoern A. Zeeb case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991: 490*f9c7a07dSBjoern A. Zeeb sta->deflink.agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_7991; 491*f9c7a07dSBjoern A. Zeeb break; 492*f9c7a07dSBjoern A. Zeeb case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895: 493*f9c7a07dSBjoern A. Zeeb default: 494*f9c7a07dSBjoern A. Zeeb sta->deflink.agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_3895; 495*f9c7a07dSBjoern A. Zeeb break; 496*f9c7a07dSBjoern A. Zeeb } 4979fb91463SBjoern A. Zeeb } 4989fb91463SBjoern A. Zeeb #endif 4999fb91463SBjoern A. Zeeb 500d9f59799SBjoern A. Zeeb static void 501*f9c7a07dSBjoern A. Zeeb lkpi_sta_sync_from_ni(struct ieee80211_sta *sta, struct ieee80211_node *ni) 502*f9c7a07dSBjoern A. Zeeb { 503*f9c7a07dSBjoern A. Zeeb 504*f9c7a07dSBjoern A. Zeeb #if defined(LKPI_80211_HT) 505*f9c7a07dSBjoern A. Zeeb lkpi_sta_sync_ht_from_ni(sta, ni); 506*f9c7a07dSBjoern A. Zeeb #endif 507*f9c7a07dSBjoern A. Zeeb #if defined(LKPI_80211_VHT) 508*f9c7a07dSBjoern A. Zeeb lkpi_sta_sync_vht_from_ni(sta, ni); 509*f9c7a07dSBjoern A. Zeeb #endif 510*f9c7a07dSBjoern A. Zeeb } 511*f9c7a07dSBjoern A. Zeeb 512*f9c7a07dSBjoern A. Zeeb static void 51367674c1cSBjoern A. Zeeb lkpi_lsta_dump(struct lkpi_sta *lsta, struct ieee80211_node *ni, 51467674c1cSBjoern A. Zeeb const char *_f, int _l) 515d9f59799SBjoern A. Zeeb { 516d9f59799SBjoern A. Zeeb 5179d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 5189d9ba2b7SBjoern A. Zeeb if ((linuxkpi_debug_80211 & D80211_TRACE_STA) == 0) 519d9f59799SBjoern A. Zeeb return; 520d9f59799SBjoern A. Zeeb if (lsta == NULL) 521d9f59799SBjoern A. Zeeb return; 522d9f59799SBjoern A. Zeeb 523d9f59799SBjoern A. Zeeb printf("%s:%d lsta %p ni %p sta %p\n", 52467674c1cSBjoern A. Zeeb _f, _l, lsta, ni, &lsta->sta); 52567674c1cSBjoern A. Zeeb if (ni != NULL) 52667674c1cSBjoern A. Zeeb ieee80211_dump_node(NULL, ni); 527d9f59799SBjoern A. Zeeb printf("\ttxq_task txq len %d mtx\n", mbufq_len(&lsta->txq)); 528d9f59799SBjoern A. Zeeb printf("\tkc %p state %d added_to_drv %d in_mgd %d\n", 52911db70b6SBjoern A. Zeeb &lsta->kc[0], lsta->state, lsta->added_to_drv, lsta->in_mgd); 5309d9ba2b7SBjoern A. Zeeb #endif 531d9f59799SBjoern A. Zeeb } 532d9f59799SBjoern A. Zeeb 533d9f59799SBjoern A. Zeeb static void 534d9f59799SBjoern A. Zeeb lkpi_lsta_remove(struct lkpi_sta *lsta, struct lkpi_vif *lvif) 535d9f59799SBjoern A. Zeeb { 536d9f59799SBjoern A. Zeeb 537d9f59799SBjoern A. Zeeb 538a8f735a6SBjoern A. Zeeb wiphy_lock(lsta->hw->wiphy); 539a8f735a6SBjoern A. Zeeb KASSERT(!list_empty(&lsta->lsta_list), 540a8f735a6SBjoern A. Zeeb ("%s: lsta %p ni %p\n", __func__, lsta, lsta->ni)); 541a8f735a6SBjoern A. Zeeb list_del_init(&lsta->lsta_list); 542a8f735a6SBjoern A. Zeeb wiphy_unlock(lsta->hw->wiphy); 543d9f59799SBjoern A. Zeeb } 544d9f59799SBjoern A. Zeeb 5454f61ef8bSBjoern A. Zeeb static struct lkpi_sta * 5464f61ef8bSBjoern A. Zeeb lkpi_lsta_alloc(struct ieee80211vap *vap, const uint8_t mac[IEEE80211_ADDR_LEN], 5474f61ef8bSBjoern A. Zeeb struct ieee80211_hw *hw, struct ieee80211_node *ni) 5484f61ef8bSBjoern A. Zeeb { 5494f61ef8bSBjoern A. Zeeb struct lkpi_sta *lsta; 5504f61ef8bSBjoern A. Zeeb struct lkpi_vif *lvif; 5514f61ef8bSBjoern A. Zeeb struct ieee80211_vif *vif; 5524f61ef8bSBjoern A. Zeeb struct ieee80211_sta *sta; 553b6b352e4SBjoern A. Zeeb int band, i, tid; 5544f61ef8bSBjoern A. Zeeb 5554f61ef8bSBjoern A. Zeeb lsta = malloc(sizeof(*lsta) + hw->sta_data_size, M_LKPI80211, 5564f61ef8bSBjoern A. Zeeb M_NOWAIT | M_ZERO); 5574f61ef8bSBjoern A. Zeeb if (lsta == NULL) 5584f61ef8bSBjoern A. Zeeb return (NULL); 5594f61ef8bSBjoern A. Zeeb 560a8f735a6SBjoern A. Zeeb lsta->hw = hw; 5614f61ef8bSBjoern A. Zeeb lsta->added_to_drv = false; 5624f61ef8bSBjoern A. Zeeb lsta->state = IEEE80211_STA_NOTEXIST; 5634f61ef8bSBjoern A. Zeeb /* 5640936c648SBjoern A. Zeeb * Link the ni to the lsta here without taking a reference. 5650936c648SBjoern A. Zeeb * For one we would have to take the reference in node_init() 5660936c648SBjoern A. Zeeb * as ieee80211_alloc_node() will initialise the refcount after us. 5670936c648SBjoern A. Zeeb * For the other a ni and an lsta are 1:1 mapped and always together 5680936c648SBjoern A. Zeeb * from [ic_]node_alloc() to [ic_]node_free() so we are essentally 5690936c648SBjoern A. Zeeb * using the ni references for the lsta as well despite it being 5700936c648SBjoern A. Zeeb * two separate allocations. 5714f61ef8bSBjoern A. Zeeb */ 5720936c648SBjoern A. Zeeb lsta->ni = ni; 5734f61ef8bSBjoern A. Zeeb /* The back-pointer "drv_data" to net80211_node let's us get lsta. */ 5744f61ef8bSBjoern A. Zeeb ni->ni_drv_data = lsta; 5754f61ef8bSBjoern A. Zeeb 5764f61ef8bSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 5774f61ef8bSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 5784f61ef8bSBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 5794f61ef8bSBjoern A. Zeeb 5804f61ef8bSBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->addr, mac); 581b6b352e4SBjoern A. Zeeb 582b6b352e4SBjoern A. Zeeb /* TXQ */ 5834f61ef8bSBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 5844f61ef8bSBjoern A. Zeeb struct lkpi_txq *ltxq; 5854f61ef8bSBjoern A. Zeeb 586d0d29110SBjoern A. Zeeb /* We are not limiting ourselves to hw.queues here. */ 5874f61ef8bSBjoern A. Zeeb ltxq = malloc(sizeof(*ltxq) + hw->txq_data_size, 5884f61ef8bSBjoern A. Zeeb M_LKPI80211, M_NOWAIT | M_ZERO); 5894f61ef8bSBjoern A. Zeeb if (ltxq == NULL) 5904f61ef8bSBjoern A. Zeeb goto cleanup; 5914f61ef8bSBjoern A. Zeeb /* iwlwifi//mvm/sta.c::tid_to_mac80211_ac[] */ 5924f61ef8bSBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) { 593d0d29110SBjoern A. Zeeb if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ)) { 594d0d29110SBjoern A. Zeeb free(ltxq, M_LKPI80211); 595d0d29110SBjoern A. Zeeb continue; 596d0d29110SBjoern A. Zeeb } 597d0d29110SBjoern A. Zeeb IMPROVE("AP/if we support non-STA here too"); 5984f61ef8bSBjoern A. Zeeb ltxq->txq.ac = IEEE80211_AC_VO; 5994f61ef8bSBjoern A. Zeeb } else { 600fb3c249eSBjoern A. Zeeb ltxq->txq.ac = ieee80211e_up_to_ac[tid & 7]; 6014f61ef8bSBjoern A. Zeeb } 602d0d29110SBjoern A. Zeeb ltxq->seen_dequeue = false; 6030cbcfa19SBjoern A. Zeeb ltxq->stopped = false; 604d0d29110SBjoern A. Zeeb ltxq->txq.vif = vif; 6054f61ef8bSBjoern A. Zeeb ltxq->txq.tid = tid; 6064f61ef8bSBjoern A. Zeeb ltxq->txq.sta = sta; 6070cbcfa19SBjoern A. Zeeb TAILQ_ELEM_INIT(ltxq, txq_entry); 608d0d29110SBjoern A. Zeeb skb_queue_head_init(<xq->skbq); 609eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_LOCK_INIT(ltxq); 6104f61ef8bSBjoern A. Zeeb sta->txq[tid] = <xq->txq; 6114f61ef8bSBjoern A. Zeeb } 6124f61ef8bSBjoern A. Zeeb 613b6b352e4SBjoern A. Zeeb /* Deflink information. */ 614b6b352e4SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 615b6b352e4SBjoern A. Zeeb struct ieee80211_supported_band *supband; 616b6b352e4SBjoern A. Zeeb 617b6b352e4SBjoern A. Zeeb supband = hw->wiphy->bands[band]; 618b6b352e4SBjoern A. Zeeb if (supband == NULL) 619b6b352e4SBjoern A. Zeeb continue; 620b6b352e4SBjoern A. Zeeb 621b6b352e4SBjoern A. Zeeb for (i = 0; i < supband->n_bitrates; i++) { 62273cd1c5dSBjoern A. Zeeb switch (band) { 62373cd1c5dSBjoern A. Zeeb case NL80211_BAND_2GHZ: 62473cd1c5dSBjoern A. Zeeb switch (supband->bitrates[i].bitrate) { 62573cd1c5dSBjoern A. Zeeb case 240: /* 11g only */ 62673cd1c5dSBjoern A. Zeeb case 120: /* 11g only */ 62773cd1c5dSBjoern A. Zeeb case 110: 62873cd1c5dSBjoern A. Zeeb case 60: /* 11g only */ 62973cd1c5dSBjoern A. Zeeb case 55: 63073cd1c5dSBjoern A. Zeeb case 20: 63173cd1c5dSBjoern A. Zeeb case 10: 632b6b352e4SBjoern A. Zeeb sta->deflink.supp_rates[band] |= BIT(i); 63373cd1c5dSBjoern A. Zeeb break; 63473cd1c5dSBjoern A. Zeeb } 63573cd1c5dSBjoern A. Zeeb break; 63673cd1c5dSBjoern A. Zeeb case NL80211_BAND_5GHZ: 63773cd1c5dSBjoern A. Zeeb switch (supband->bitrates[i].bitrate) { 63873cd1c5dSBjoern A. Zeeb case 240: 63973cd1c5dSBjoern A. Zeeb case 120: 64073cd1c5dSBjoern A. Zeeb case 60: 64173cd1c5dSBjoern A. Zeeb sta->deflink.supp_rates[band] |= BIT(i); 64273cd1c5dSBjoern A. Zeeb break; 64373cd1c5dSBjoern A. Zeeb } 64473cd1c5dSBjoern A. Zeeb break; 64573cd1c5dSBjoern A. Zeeb } 646b6b352e4SBjoern A. Zeeb } 647b6b352e4SBjoern A. Zeeb } 6489fb91463SBjoern A. Zeeb 6496ffb7bd4SBjoern A. Zeeb sta->deflink.smps_mode = IEEE80211_SMPS_OFF; 6509fb91463SBjoern A. Zeeb sta->deflink.bandwidth = IEEE80211_STA_RX_BW_20; 651f5a58c2dSMikhail Pchelin sta->deflink.rx_nss = 1; 6529fb91463SBjoern A. Zeeb 653*f9c7a07dSBjoern A. Zeeb lkpi_sta_sync_from_ni(sta, ni); 6549fb91463SBjoern A. Zeeb 655*f9c7a07dSBjoern A. Zeeb IMPROVE("he, eht, bw_320, ... smps_mode, .."); 656b6b352e4SBjoern A. Zeeb 6576ffb7bd4SBjoern A. Zeeb /* Link configuration. */ 6586ffb7bd4SBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->deflink.addr, sta->addr); 6596ffb7bd4SBjoern A. Zeeb sta->link[0] = &sta->deflink; 6606ffb7bd4SBjoern A. Zeeb for (i = 1; i < nitems(sta->link); i++) { 6616ffb7bd4SBjoern A. Zeeb IMPROVE("more links; only link[0] = deflink currently."); 6626ffb7bd4SBjoern A. Zeeb } 6636ffb7bd4SBjoern A. Zeeb 6644f61ef8bSBjoern A. Zeeb /* Deferred TX path. */ 665fa4e4257SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_LOCK_INIT(lsta); 6664f61ef8bSBjoern A. Zeeb TASK_INIT(&lsta->txq_task, 0, lkpi_80211_txq_task, lsta); 6674f61ef8bSBjoern A. Zeeb mbufq_init(&lsta->txq, IFQ_MAXLEN); 6680936c648SBjoern A. Zeeb lsta->txq_ready = true; 6694f61ef8bSBjoern A. Zeeb 6704f61ef8bSBjoern A. Zeeb return (lsta); 6714f61ef8bSBjoern A. Zeeb 6724f61ef8bSBjoern A. Zeeb cleanup: 673eac3646fSBjoern A. Zeeb for (; tid >= 0; tid--) { 674eac3646fSBjoern A. Zeeb struct lkpi_txq *ltxq; 675eac3646fSBjoern A. Zeeb 676eac3646fSBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]); 677eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_LOCK_DESTROY(ltxq); 6784f61ef8bSBjoern A. Zeeb free(sta->txq[tid], M_LKPI80211); 679eac3646fSBjoern A. Zeeb } 6804f61ef8bSBjoern A. Zeeb free(lsta, M_LKPI80211); 6814f61ef8bSBjoern A. Zeeb return (NULL); 6824f61ef8bSBjoern A. Zeeb } 6834f61ef8bSBjoern A. Zeeb 6840936c648SBjoern A. Zeeb static void 6850936c648SBjoern A. Zeeb lkpi_lsta_free(struct lkpi_sta *lsta, struct ieee80211_node *ni) 6860936c648SBjoern A. Zeeb { 6870936c648SBjoern A. Zeeb struct mbuf *m; 6880936c648SBjoern A. Zeeb 6890936c648SBjoern A. Zeeb if (lsta->added_to_drv) 6900936c648SBjoern A. Zeeb panic("%s: Trying to free an lsta still known to firmware: " 6910936c648SBjoern A. Zeeb "lsta %p ni %p added_to_drv %d\n", 6920936c648SBjoern A. Zeeb __func__, lsta, ni, lsta->added_to_drv); 6930936c648SBjoern A. Zeeb 6940936c648SBjoern A. Zeeb /* XXX-BZ free resources, ... */ 6950936c648SBjoern A. Zeeb IMPROVE(); 6960936c648SBjoern A. Zeeb 697fa4e4257SBjoern A. Zeeb /* Drain sta->txq[] */ 698fa4e4257SBjoern A. Zeeb 699fa4e4257SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_LOCK(lsta); 7000936c648SBjoern A. Zeeb lsta->txq_ready = false; 701fa4e4257SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_UNLOCK(lsta); 7020936c648SBjoern A. Zeeb 7030936c648SBjoern A. Zeeb /* Drain taskq, won't be restarted until added_to_drv is set again. */ 7040936c648SBjoern A. Zeeb while (taskqueue_cancel(taskqueue_thread, &lsta->txq_task, NULL) != 0) 7050936c648SBjoern A. Zeeb taskqueue_drain(taskqueue_thread, &lsta->txq_task); 7060936c648SBjoern A. Zeeb 7070936c648SBjoern A. Zeeb /* Flush mbufq (make sure to release ni refs!). */ 7080936c648SBjoern A. Zeeb m = mbufq_dequeue(&lsta->txq); 7090936c648SBjoern A. Zeeb while (m != NULL) { 7100936c648SBjoern A. Zeeb struct ieee80211_node *nim; 7110936c648SBjoern A. Zeeb 7120936c648SBjoern A. Zeeb nim = (struct ieee80211_node *)m->m_pkthdr.rcvif; 7130936c648SBjoern A. Zeeb if (nim != NULL) 7140936c648SBjoern A. Zeeb ieee80211_free_node(nim); 7150936c648SBjoern A. Zeeb m_freem(m); 7160936c648SBjoern A. Zeeb m = mbufq_dequeue(&lsta->txq); 7170936c648SBjoern A. Zeeb } 7180936c648SBjoern A. Zeeb KASSERT(mbufq_empty(&lsta->txq), ("%s: lsta %p has txq len %d != 0\n", 7190936c648SBjoern A. Zeeb __func__, lsta, mbufq_len(&lsta->txq))); 720fa4e4257SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_LOCK_DESTROY(lsta); 7210936c648SBjoern A. Zeeb 7220936c648SBjoern A. Zeeb /* Remove lsta from vif; that is done by the state machine. Should assert it? */ 7230936c648SBjoern A. Zeeb 7240936c648SBjoern A. Zeeb IMPROVE("Make sure everything is cleaned up."); 7250936c648SBjoern A. Zeeb 7260936c648SBjoern A. Zeeb /* Free lsta. */ 7270936c648SBjoern A. Zeeb lsta->ni = NULL; 7280936c648SBjoern A. Zeeb ni->ni_drv_data = NULL; 7290936c648SBjoern A. Zeeb free(lsta, M_LKPI80211); 7300936c648SBjoern A. Zeeb } 7310936c648SBjoern A. Zeeb 7320936c648SBjoern A. Zeeb 7336b4cac81SBjoern A. Zeeb static enum nl80211_band 7346b4cac81SBjoern A. Zeeb lkpi_net80211_chan_to_nl80211_band(struct ieee80211_channel *c) 7356b4cac81SBjoern A. Zeeb { 7366b4cac81SBjoern A. Zeeb 7376b4cac81SBjoern A. Zeeb if (IEEE80211_IS_CHAN_2GHZ(c)) 7386b4cac81SBjoern A. Zeeb return (NL80211_BAND_2GHZ); 7396b4cac81SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_5GHZ(c)) 7406b4cac81SBjoern A. Zeeb return (NL80211_BAND_5GHZ); 7416b4cac81SBjoern A. Zeeb #ifdef __notyet__ 7426b4cac81SBjoern A. Zeeb else if () 7436b4cac81SBjoern A. Zeeb return (NL80211_BAND_6GHZ); 7446b4cac81SBjoern A. Zeeb else if () 7456b4cac81SBjoern A. Zeeb return (NL80211_BAND_60GHZ); 7466b4cac81SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_GSM(c)) 7476b4cac81SBjoern A. Zeeb return (NL80211_BAND_XXX); 7486b4cac81SBjoern A. Zeeb #endif 7496b4cac81SBjoern A. Zeeb else 7506b4cac81SBjoern A. Zeeb panic("%s: unsupported band. c %p flags %#x\n", 7516b4cac81SBjoern A. Zeeb __func__, c, c->ic_flags); 7526b4cac81SBjoern A. Zeeb } 7536b4cac81SBjoern A. Zeeb 7546b4cac81SBjoern A. Zeeb static uint32_t 7556b4cac81SBjoern A. Zeeb lkpi_nl80211_band_to_net80211_band(enum nl80211_band band) 7566b4cac81SBjoern A. Zeeb { 7576b4cac81SBjoern A. Zeeb 7586b4cac81SBjoern A. Zeeb /* XXX-BZ this is just silly; net80211 is too convoluted. */ 7596b4cac81SBjoern A. Zeeb /* IEEE80211_CHAN_A / _G / .. doesn't really work either. */ 7606b4cac81SBjoern A. Zeeb switch (band) { 7616b4cac81SBjoern A. Zeeb case NL80211_BAND_2GHZ: 7626b4cac81SBjoern A. Zeeb return (IEEE80211_CHAN_2GHZ); 7636b4cac81SBjoern A. Zeeb break; 7646b4cac81SBjoern A. Zeeb case NL80211_BAND_5GHZ: 7656b4cac81SBjoern A. Zeeb return (IEEE80211_CHAN_5GHZ); 7666b4cac81SBjoern A. Zeeb break; 7676b4cac81SBjoern A. Zeeb case NL80211_BAND_60GHZ: 7686b4cac81SBjoern A. Zeeb break; 7696b4cac81SBjoern A. Zeeb case NL80211_BAND_6GHZ: 7706b4cac81SBjoern A. Zeeb break; 7716b4cac81SBjoern A. Zeeb default: 7726b4cac81SBjoern A. Zeeb panic("%s: unsupported band %u\n", __func__, band); 7736b4cac81SBjoern A. Zeeb break; 7746b4cac81SBjoern A. Zeeb } 7756b4cac81SBjoern A. Zeeb 7766b4cac81SBjoern A. Zeeb IMPROVE(); 7776b4cac81SBjoern A. Zeeb return (0x00); 7786b4cac81SBjoern A. Zeeb } 7796b4cac81SBjoern A. Zeeb 780e3a0b120SBjoern A. Zeeb #if 0 7816b4cac81SBjoern A. Zeeb static enum ieee80211_ac_numbers 7826b4cac81SBjoern A. Zeeb lkpi_ac_net_to_l80211(int ac) 7836b4cac81SBjoern A. Zeeb { 7846b4cac81SBjoern A. Zeeb 7856b4cac81SBjoern A. Zeeb switch (ac) { 7866b4cac81SBjoern A. Zeeb case WME_AC_VO: 7876b4cac81SBjoern A. Zeeb return (IEEE80211_AC_VO); 7886b4cac81SBjoern A. Zeeb case WME_AC_VI: 7896b4cac81SBjoern A. Zeeb return (IEEE80211_AC_VI); 7906b4cac81SBjoern A. Zeeb case WME_AC_BE: 7916b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BE); 7926b4cac81SBjoern A. Zeeb case WME_AC_BK: 7936b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BK); 7946b4cac81SBjoern A. Zeeb default: 7956b4cac81SBjoern A. Zeeb printf("%s: invalid WME_AC_* input: ac = %d\n", __func__, ac); 7966b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BE); 7976b4cac81SBjoern A. Zeeb } 7986b4cac81SBjoern A. Zeeb } 799e3a0b120SBjoern A. Zeeb #endif 8006b4cac81SBjoern A. Zeeb 8016b4cac81SBjoern A. Zeeb static enum nl80211_iftype 8026b4cac81SBjoern A. Zeeb lkpi_opmode_to_vif_type(enum ieee80211_opmode opmode) 8036b4cac81SBjoern A. Zeeb { 8046b4cac81SBjoern A. Zeeb 8056b4cac81SBjoern A. Zeeb switch (opmode) { 8066b4cac81SBjoern A. Zeeb case IEEE80211_M_IBSS: 8076b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_ADHOC); 8086b4cac81SBjoern A. Zeeb break; 8096b4cac81SBjoern A. Zeeb case IEEE80211_M_STA: 8106b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_STATION); 8116b4cac81SBjoern A. Zeeb break; 8126b4cac81SBjoern A. Zeeb case IEEE80211_M_WDS: 8136b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_WDS); 8146b4cac81SBjoern A. Zeeb break; 8156b4cac81SBjoern A. Zeeb case IEEE80211_M_HOSTAP: 8166b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_AP); 8176b4cac81SBjoern A. Zeeb break; 8186b4cac81SBjoern A. Zeeb case IEEE80211_M_MONITOR: 8196b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_MONITOR); 8206b4cac81SBjoern A. Zeeb break; 8216b4cac81SBjoern A. Zeeb case IEEE80211_M_MBSS: 8226b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_MESH_POINT); 8236b4cac81SBjoern A. Zeeb break; 8246b4cac81SBjoern A. Zeeb case IEEE80211_M_AHDEMO: 8256b4cac81SBjoern A. Zeeb /* FALLTHROUGH */ 8266b4cac81SBjoern A. Zeeb default: 8276b4cac81SBjoern A. Zeeb printf("ERROR: %s: unsupported opmode %d\n", __func__, opmode); 8286b4cac81SBjoern A. Zeeb /* FALLTHROUGH */ 8296b4cac81SBjoern A. Zeeb } 8306b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_UNSPECIFIED); 8316b4cac81SBjoern A. Zeeb } 8326b4cac81SBjoern A. Zeeb 833b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 83412a511c8SBjoern A. Zeeb static const char * 83512a511c8SBjoern A. Zeeb lkpi_cipher_suite_to_name(uint32_t wlan_cipher_suite) 83612a511c8SBjoern A. Zeeb { 83712a511c8SBjoern A. Zeeb 83812a511c8SBjoern A. Zeeb switch (wlan_cipher_suite) { 83912a511c8SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP40: 84012a511c8SBjoern A. Zeeb return ("WEP40"); 84112a511c8SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP: 84212a511c8SBjoern A. Zeeb return ("TKIP"); 84312a511c8SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP: 84412a511c8SBjoern A. Zeeb return ("CCMP"); 84512a511c8SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP104: 84612a511c8SBjoern A. Zeeb return ("WEP104"); 84712a511c8SBjoern A. Zeeb case WLAN_CIPHER_SUITE_AES_CMAC: 84812a511c8SBjoern A. Zeeb return ("AES_CMAC"); 84912a511c8SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP: 85012a511c8SBjoern A. Zeeb return ("GCMP"); 85112a511c8SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP_256: 85212a511c8SBjoern A. Zeeb return ("GCMP_256"); 85312a511c8SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP_256: 85412a511c8SBjoern A. Zeeb return ("CCMP_256"); 85512a511c8SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_128: 85612a511c8SBjoern A. Zeeb return ("BIP_GMAC_128"); 85712a511c8SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_256: 85812a511c8SBjoern A. Zeeb return ("BIP_GMAC_256"); 85912a511c8SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_CMAC_256: 86012a511c8SBjoern A. Zeeb return ("BIP_CMAC_256"); 86112a511c8SBjoern A. Zeeb default: 86212a511c8SBjoern A. Zeeb return ("??"); 86312a511c8SBjoern A. Zeeb } 86412a511c8SBjoern A. Zeeb } 86512a511c8SBjoern A. Zeeb 8666b4cac81SBjoern A. Zeeb static uint32_t 8676b4cac81SBjoern A. Zeeb lkpi_l80211_to_net80211_cyphers(uint32_t wlan_cipher_suite) 8686b4cac81SBjoern A. Zeeb { 8696b4cac81SBjoern A. Zeeb 8706b4cac81SBjoern A. Zeeb switch (wlan_cipher_suite) { 8716b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP40: 8726b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_WEP); 8736b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP: 8746b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_TKIP); 8756b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP: 876906521f8SBjoern A. Zeeb return (IEEE80211_CRYPTO_AES_CCM); 8776b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP104: 8786b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_WEP); 8796b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_AES_CMAC: 8806b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP: 8816b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP_256: 8826b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP_256: 8836b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_128: 8846b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_256: 8856b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_CMAC_256: 88612a511c8SBjoern A. Zeeb printf("%s: unsupported WLAN Cipher Suite %#08x | %u (%s)\n", 88712a511c8SBjoern A. Zeeb __func__, 88812a511c8SBjoern A. Zeeb wlan_cipher_suite >> 8, wlan_cipher_suite & 0xff, 88912a511c8SBjoern A. Zeeb lkpi_cipher_suite_to_name(wlan_cipher_suite)); 8906b4cac81SBjoern A. Zeeb break; 8916b4cac81SBjoern A. Zeeb default: 89212a511c8SBjoern A. Zeeb printf("%s: unknown WLAN Cipher Suite %#08x | %u (%s)\n", 89312a511c8SBjoern A. Zeeb __func__, 89412a511c8SBjoern A. Zeeb wlan_cipher_suite >> 8, wlan_cipher_suite & 0xff, 89512a511c8SBjoern A. Zeeb lkpi_cipher_suite_to_name(wlan_cipher_suite)); 8966b4cac81SBjoern A. Zeeb } 8976b4cac81SBjoern A. Zeeb 8986b4cac81SBjoern A. Zeeb return (0); 8996b4cac81SBjoern A. Zeeb } 9006b4cac81SBjoern A. Zeeb 9016b4cac81SBjoern A. Zeeb static uint32_t 9026b4cac81SBjoern A. Zeeb lkpi_net80211_to_l80211_cipher_suite(uint32_t cipher, uint8_t keylen) 9036b4cac81SBjoern A. Zeeb { 9046b4cac81SBjoern A. Zeeb 9056b4cac81SBjoern A. Zeeb switch (cipher) { 9066b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_TKIP: 9076b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_TKIP); 9086b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_AES_CCM: 9096b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_CCMP); 9106b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_WEP: 9116b4cac81SBjoern A. Zeeb if (keylen < 8) 9126b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_WEP40); 9136b4cac81SBjoern A. Zeeb else 9146b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_WEP104); 9156b4cac81SBjoern A. Zeeb break; 9166b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_AES_OCB: 9176b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_TKIPMIC: 9186b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_CKIP: 9196b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_NONE: 9206b4cac81SBjoern A. Zeeb printf("%s: unsupported cipher %#010x\n", __func__, cipher); 9216b4cac81SBjoern A. Zeeb break; 9226b4cac81SBjoern A. Zeeb default: 9236b4cac81SBjoern A. Zeeb printf("%s: unknown cipher %#010x\n", __func__, cipher); 9246b4cac81SBjoern A. Zeeb }; 9256b4cac81SBjoern A. Zeeb return (0); 9266b4cac81SBjoern A. Zeeb } 9276b4cac81SBjoern A. Zeeb #endif 9286b4cac81SBjoern A. Zeeb 9296b4cac81SBjoern A. Zeeb #ifdef __notyet__ 9306b4cac81SBjoern A. Zeeb static enum ieee80211_sta_state 9316b4cac81SBjoern A. Zeeb lkpi_net80211_state_to_sta_state(enum ieee80211_state state) 9326b4cac81SBjoern A. Zeeb { 9336b4cac81SBjoern A. Zeeb 9346b4cac81SBjoern A. Zeeb /* 9356b4cac81SBjoern A. Zeeb * XXX-BZ The net80211 states are "try to ..", the lkpi8011 states are 9366b4cac81SBjoern A. Zeeb * "done". Also ASSOC/AUTHORIZED are both "RUN" then? 9376b4cac81SBjoern A. Zeeb */ 9386b4cac81SBjoern A. Zeeb switch (state) { 9396b4cac81SBjoern A. Zeeb case IEEE80211_S_INIT: 9406b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NOTEXIST); 9416b4cac81SBjoern A. Zeeb case IEEE80211_S_SCAN: 9426b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NONE); 9436b4cac81SBjoern A. Zeeb case IEEE80211_S_AUTH: 9446b4cac81SBjoern A. Zeeb return (IEEE80211_STA_AUTH); 9456b4cac81SBjoern A. Zeeb case IEEE80211_S_ASSOC: 9466b4cac81SBjoern A. Zeeb return (IEEE80211_STA_ASSOC); 9476b4cac81SBjoern A. Zeeb case IEEE80211_S_RUN: 9486b4cac81SBjoern A. Zeeb return (IEEE80211_STA_AUTHORIZED); 9496b4cac81SBjoern A. Zeeb case IEEE80211_S_CAC: 9506b4cac81SBjoern A. Zeeb case IEEE80211_S_CSA: 9516b4cac81SBjoern A. Zeeb case IEEE80211_S_SLEEP: 9526b4cac81SBjoern A. Zeeb default: 9536b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 9546b4cac81SBjoern A. Zeeb }; 9556b4cac81SBjoern A. Zeeb 9566b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NOTEXIST); 9576b4cac81SBjoern A. Zeeb } 9586b4cac81SBjoern A. Zeeb #endif 9596b4cac81SBjoern A. Zeeb 9606b4cac81SBjoern A. Zeeb static struct linuxkpi_ieee80211_channel * 9616b4cac81SBjoern A. Zeeb lkpi_find_lkpi80211_chan(struct lkpi_hw *lhw, 9626b4cac81SBjoern A. Zeeb struct ieee80211_channel *c) 9636b4cac81SBjoern A. Zeeb { 9646b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 9656b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 9666b4cac81SBjoern A. Zeeb enum nl80211_band band; 9676b4cac81SBjoern A. Zeeb int i, nchans; 9686b4cac81SBjoern A. Zeeb 9696b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 9706b4cac81SBjoern A. Zeeb band = lkpi_net80211_chan_to_nl80211_band(c); 9716b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[band] == NULL) 9726b4cac81SBjoern A. Zeeb return (NULL); 9736b4cac81SBjoern A. Zeeb 9746b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[band]->n_channels; 9756b4cac81SBjoern A. Zeeb if (nchans <= 0) 9766b4cac81SBjoern A. Zeeb return (NULL); 9776b4cac81SBjoern A. Zeeb 9786b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[band]->channels; 9796b4cac81SBjoern A. Zeeb for (i = 0; i < nchans; i++) { 9806b4cac81SBjoern A. Zeeb if (channels[i].hw_value == c->ic_ieee) 9816b4cac81SBjoern A. Zeeb return (&channels[i]); 9826b4cac81SBjoern A. Zeeb } 9836b4cac81SBjoern A. Zeeb 9846b4cac81SBjoern A. Zeeb return (NULL); 9856b4cac81SBjoern A. Zeeb } 9866b4cac81SBjoern A. Zeeb 9872ac8a218SBjoern A. Zeeb #if 0 9886b4cac81SBjoern A. Zeeb static struct linuxkpi_ieee80211_channel * 9896b4cac81SBjoern A. Zeeb lkpi_get_lkpi80211_chan(struct ieee80211com *ic, struct ieee80211_node *ni) 9906b4cac81SBjoern A. Zeeb { 9916b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 9926b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 9936b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 9946b4cac81SBjoern A. Zeeb 9956b4cac81SBjoern A. Zeeb chan = NULL; 9966b4cac81SBjoern A. Zeeb if (ni != NULL && ni->ni_chan != IEEE80211_CHAN_ANYC) 9976b4cac81SBjoern A. Zeeb c = ni->ni_chan; 9986b4cac81SBjoern A. Zeeb else if (ic->ic_bsschan != IEEE80211_CHAN_ANYC) 9996b4cac81SBjoern A. Zeeb c = ic->ic_bsschan; 10006b4cac81SBjoern A. Zeeb else if (ic->ic_curchan != IEEE80211_CHAN_ANYC) 10016b4cac81SBjoern A. Zeeb c = ic->ic_curchan; 10026b4cac81SBjoern A. Zeeb else 10036b4cac81SBjoern A. Zeeb c = NULL; 10046b4cac81SBjoern A. Zeeb 10056b4cac81SBjoern A. Zeeb if (c != NULL && c != IEEE80211_CHAN_ANYC) { 10066b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 10076b4cac81SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, c); 10086b4cac81SBjoern A. Zeeb } 10096b4cac81SBjoern A. Zeeb 10106b4cac81SBjoern A. Zeeb return (chan); 10116b4cac81SBjoern A. Zeeb } 10122ac8a218SBjoern A. Zeeb #endif 10136b4cac81SBjoern A. Zeeb 10142e183d99SBjoern A. Zeeb struct linuxkpi_ieee80211_channel * 10152e183d99SBjoern A. Zeeb linuxkpi_ieee80211_get_channel(struct wiphy *wiphy, uint32_t freq) 10162e183d99SBjoern A. Zeeb { 10172e183d99SBjoern A. Zeeb enum nl80211_band band; 10182e183d99SBjoern A. Zeeb 10192e183d99SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 10202e183d99SBjoern A. Zeeb struct ieee80211_supported_band *supband; 10212e183d99SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 10222e183d99SBjoern A. Zeeb int i; 10232e183d99SBjoern A. Zeeb 10242e183d99SBjoern A. Zeeb supband = wiphy->bands[band]; 10252e183d99SBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 10262e183d99SBjoern A. Zeeb continue; 10272e183d99SBjoern A. Zeeb 10282e183d99SBjoern A. Zeeb channels = supband->channels; 10292e183d99SBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 10302e183d99SBjoern A. Zeeb if (channels[i].center_freq == freq) 10312e183d99SBjoern A. Zeeb return (&channels[i]); 10322e183d99SBjoern A. Zeeb } 10332e183d99SBjoern A. Zeeb } 10342e183d99SBjoern A. Zeeb 10352e183d99SBjoern A. Zeeb return (NULL); 10362e183d99SBjoern A. Zeeb } 10372e183d99SBjoern A. Zeeb 1038b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 10396b4cac81SBjoern A. Zeeb static int 104011db70b6SBjoern A. Zeeb lkpi_sta_del_keys(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 104111db70b6SBjoern A. Zeeb struct lkpi_sta *lsta) 104211db70b6SBjoern A. Zeeb { 104311db70b6SBjoern A. Zeeb int error; 104411db70b6SBjoern A. Zeeb 104511db70b6SBjoern A. Zeeb if (!lkpi_hwcrypto) 104611db70b6SBjoern A. Zeeb return (0); 104711db70b6SBjoern A. Zeeb 104811db70b6SBjoern A. Zeeb lockdep_assert_wiphy(hw->wiphy); 104911db70b6SBjoern A. Zeeb ieee80211_ref_node(lsta->ni); 105011db70b6SBjoern A. Zeeb 105111db70b6SBjoern A. Zeeb error = 0; 105211db70b6SBjoern A. Zeeb for (ieee80211_keyix keyix = 0; keyix < nitems(lsta->kc); keyix++) { 105311db70b6SBjoern A. Zeeb struct ieee80211_key_conf *kc; 105411db70b6SBjoern A. Zeeb int err; 105511db70b6SBjoern A. Zeeb 105611db70b6SBjoern A. Zeeb if (lsta->kc[keyix] == NULL) 105711db70b6SBjoern A. Zeeb continue; 105811db70b6SBjoern A. Zeeb kc = lsta->kc[keyix]; 105911db70b6SBjoern A. Zeeb 106011db70b6SBjoern A. Zeeb err = lkpi_80211_mo_set_key(hw, DISABLE_KEY, vif, 106111db70b6SBjoern A. Zeeb LSTA_TO_STA(lsta), kc); 106211db70b6SBjoern A. Zeeb if (err != 0) { 106311db70b6SBjoern A. Zeeb ic_printf(lsta->ni->ni_ic, "%s: set_key cmd %d(%s) for " 106411db70b6SBjoern A. Zeeb "sta %6D failed: %d\n", __func__, DISABLE_KEY, 106511db70b6SBjoern A. Zeeb "DISABLE", lsta->sta.addr, ":", err); 106611db70b6SBjoern A. Zeeb error++; 106711db70b6SBjoern A. Zeeb 106811db70b6SBjoern A. Zeeb /* 106911db70b6SBjoern A. Zeeb * If we free the key here we will never be able to get it 107011db70b6SBjoern A. Zeeb * removed from the driver/fw which will likely make us 107111db70b6SBjoern A. Zeeb * crash (firmware). 107211db70b6SBjoern A. Zeeb */ 107311db70b6SBjoern A. Zeeb continue; 107411db70b6SBjoern A. Zeeb } 107511db70b6SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 107611db70b6SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO) 107711db70b6SBjoern A. Zeeb ic_printf(lsta->ni->ni_ic, "%s: set_key cmd %d(%s) for " 107811db70b6SBjoern A. Zeeb "sta %6D succeeded: keyidx %u hw_key_idx %u flags %#10x\n", 107911db70b6SBjoern A. Zeeb __func__, DISABLE_KEY, "DISABLE", lsta->sta.addr, ":", 108011db70b6SBjoern A. Zeeb kc->keyidx, kc->hw_key_idx, kc->flags); 108111db70b6SBjoern A. Zeeb #endif 108211db70b6SBjoern A. Zeeb 108311db70b6SBjoern A. Zeeb lsta->kc[keyix] = NULL; 108411db70b6SBjoern A. Zeeb free(kc, M_LKPI80211); 108511db70b6SBjoern A. Zeeb } 108611db70b6SBjoern A. Zeeb ieee80211_free_node(lsta->ni); 108711db70b6SBjoern A. Zeeb return (error); 108811db70b6SBjoern A. Zeeb } 108911db70b6SBjoern A. Zeeb 109011db70b6SBjoern A. Zeeb static int 109111db70b6SBjoern A. Zeeb _lkpi_iv_key_delete(struct ieee80211vap *vap, const struct ieee80211_key *k) 10926b4cac81SBjoern A. Zeeb { 10936b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 10946b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 10956b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 10966b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 109711db70b6SBjoern A. Zeeb struct lkpi_sta *lsta; 10986b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 10996b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 11006b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 11016b4cac81SBjoern A. Zeeb struct ieee80211_key_conf *kc; 110211db70b6SBjoern A. Zeeb struct ieee80211_node_table *nt; 11036b4cac81SBjoern A. Zeeb int error; 110411db70b6SBjoern A. Zeeb bool islocked; 11056b4cac81SBjoern A. Zeeb 11066b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 11076b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 11086b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 11096b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 11106b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 11116b4cac81SBjoern A. Zeeb 111211db70b6SBjoern A. Zeeb if (vap->iv_bss == NULL) { 111311db70b6SBjoern A. Zeeb ic_printf(ic, "%s: iv_bss %p for vap %p is NULL\n", 111411db70b6SBjoern A. Zeeb __func__, vap->iv_bss, vap); 111511db70b6SBjoern A. Zeeb return (0); 111611db70b6SBjoern A. Zeeb } 111711db70b6SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 111811db70b6SBjoern A. Zeeb lsta = ni->ni_drv_data; 111911db70b6SBjoern A. Zeeb if (lsta == NULL) { 112011db70b6SBjoern A. Zeeb ic_printf(ic, "%s: ni %p (%6D) with lsta NULL\n", 112111db70b6SBjoern A. Zeeb __func__, ni, ni->ni_bssid, ":"); 112211db70b6SBjoern A. Zeeb ieee80211_free_node(ni); 112311db70b6SBjoern A. Zeeb return (0); 112411db70b6SBjoern A. Zeeb } 112511db70b6SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 112611db70b6SBjoern A. Zeeb 112711db70b6SBjoern A. Zeeb if (lsta->kc[k->wk_keyix] == NULL) { 112811db70b6SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 112911db70b6SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO) 113011db70b6SBjoern A. Zeeb ic_printf(ic, "%s: sta %6D and no key information, " 113111db70b6SBjoern A. Zeeb "keyidx %u wk_macaddr %6D; returning success\n", 113211db70b6SBjoern A. Zeeb __func__, sta->addr, ":", 113311db70b6SBjoern A. Zeeb k->wk_keyix, k->wk_macaddr, ":"); 113411db70b6SBjoern A. Zeeb #endif 113511db70b6SBjoern A. Zeeb ieee80211_free_node(ni); 113611db70b6SBjoern A. Zeeb return (1); 113711db70b6SBjoern A. Zeeb } 113811db70b6SBjoern A. Zeeb 113911db70b6SBjoern A. Zeeb /* This is inconsistent net80211 locking to be fixed one day. */ 114011db70b6SBjoern A. Zeeb nt = &ic->ic_sta; 114111db70b6SBjoern A. Zeeb islocked = IEEE80211_NODE_IS_LOCKED(nt); 114211db70b6SBjoern A. Zeeb if (islocked) 114311db70b6SBjoern A. Zeeb IEEE80211_NODE_UNLOCK(nt); 114411db70b6SBjoern A. Zeeb 114511db70b6SBjoern A. Zeeb wiphy_lock(hw->wiphy); 114611db70b6SBjoern A. Zeeb kc = lsta->kc[k->wk_keyix]; 114711db70b6SBjoern A. Zeeb /* Re-check under lock. */ 114811db70b6SBjoern A. Zeeb if (kc == NULL) { 114911db70b6SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 115011db70b6SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO) 115111db70b6SBjoern A. Zeeb ic_printf(ic, "%s: sta %6D and key information vanished, " 115211db70b6SBjoern A. Zeeb "returning success\n", __func__, sta->addr, ":"); 115311db70b6SBjoern A. Zeeb #endif 115411db70b6SBjoern A. Zeeb error = 1; 115511db70b6SBjoern A. Zeeb goto out; 115611db70b6SBjoern A. Zeeb } 115711db70b6SBjoern A. Zeeb 115811db70b6SBjoern A. Zeeb error = lkpi_80211_mo_set_key(hw, DISABLE_KEY, vif, sta, kc); 115911db70b6SBjoern A. Zeeb if (error != 0) { 116011db70b6SBjoern A. Zeeb ic_printf(ic, "%s: set_key cmd %d(%s) for sta %6D failed: %d\n", 116111db70b6SBjoern A. Zeeb __func__, DISABLE_KEY, "DISABLE", sta->addr, ":", error); 116211db70b6SBjoern A. Zeeb error = 0; 116311db70b6SBjoern A. Zeeb goto out; 116411db70b6SBjoern A. Zeeb } 116511db70b6SBjoern A. Zeeb 116611db70b6SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 116711db70b6SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO) 116811db70b6SBjoern A. Zeeb ic_printf(ic, "%s: set_key cmd %d(%s) for sta %6D succeeded: " 116911db70b6SBjoern A. Zeeb "keyidx %u hw_key_idx %u flags %#10x\n", __func__, 117011db70b6SBjoern A. Zeeb DISABLE_KEY, "DISABLE", sta->addr, ":", 117111db70b6SBjoern A. Zeeb kc->keyidx, kc->hw_key_idx, kc->flags); 117211db70b6SBjoern A. Zeeb #endif 117311db70b6SBjoern A. Zeeb lsta->kc[k->wk_keyix] = NULL; 117411db70b6SBjoern A. Zeeb free(kc, M_LKPI80211); 117511db70b6SBjoern A. Zeeb error = 1; 117611db70b6SBjoern A. Zeeb out: 117711db70b6SBjoern A. Zeeb wiphy_unlock(hw->wiphy); 117811db70b6SBjoern A. Zeeb if (islocked) 117911db70b6SBjoern A. Zeeb IEEE80211_NODE_LOCK(nt); 118011db70b6SBjoern A. Zeeb ieee80211_free_node(ni); 118111db70b6SBjoern A. Zeeb return (error); 118211db70b6SBjoern A. Zeeb } 118311db70b6SBjoern A. Zeeb 118411db70b6SBjoern A. Zeeb static int 118511db70b6SBjoern A. Zeeb lkpi_iv_key_delete(struct ieee80211vap *vap, const struct ieee80211_key *k) 118611db70b6SBjoern A. Zeeb { 118711db70b6SBjoern A. Zeeb 118811db70b6SBjoern A. Zeeb /* XXX-BZ one day we should replace this iterating over VIFs, or node list? */ 118911db70b6SBjoern A. Zeeb /* See also lkpi_sta_del_keys() these days. */ 119011db70b6SBjoern A. Zeeb return (_lkpi_iv_key_delete(vap, k)); 119111db70b6SBjoern A. Zeeb } 119211db70b6SBjoern A. Zeeb 119311db70b6SBjoern A. Zeeb static int 119411db70b6SBjoern A. Zeeb _lkpi_iv_key_set(struct ieee80211vap *vap, const struct ieee80211_key *k) 119511db70b6SBjoern A. Zeeb { 119611db70b6SBjoern A. Zeeb struct ieee80211com *ic; 119711db70b6SBjoern A. Zeeb struct lkpi_hw *lhw; 119811db70b6SBjoern A. Zeeb struct ieee80211_hw *hw; 119911db70b6SBjoern A. Zeeb struct lkpi_vif *lvif; 120011db70b6SBjoern A. Zeeb struct lkpi_sta *lsta; 120111db70b6SBjoern A. Zeeb struct ieee80211_vif *vif; 120211db70b6SBjoern A. Zeeb struct ieee80211_sta *sta; 120311db70b6SBjoern A. Zeeb struct ieee80211_node *ni; 120411db70b6SBjoern A. Zeeb struct ieee80211_key_conf *kc; 120511db70b6SBjoern A. Zeeb uint32_t lcipher; 120611db70b6SBjoern A. Zeeb int error; 120711db70b6SBjoern A. Zeeb 120811db70b6SBjoern A. Zeeb ic = vap->iv_ic; 120911db70b6SBjoern A. Zeeb lhw = ic->ic_softc; 121011db70b6SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 121111db70b6SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 121211db70b6SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 121311db70b6SBjoern A. Zeeb 121411db70b6SBjoern A. Zeeb if (vap->iv_bss == NULL) { 121511db70b6SBjoern A. Zeeb ic_printf(ic, "%s: iv_bss %p for vap %p is NULL\n", 121611db70b6SBjoern A. Zeeb __func__, vap->iv_bss, vap); 121711db70b6SBjoern A. Zeeb return (0); 121811db70b6SBjoern A. Zeeb } 121911db70b6SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 122011db70b6SBjoern A. Zeeb lsta = ni->ni_drv_data; 122111db70b6SBjoern A. Zeeb if (lsta == NULL) { 122211db70b6SBjoern A. Zeeb ic_printf(ic, "%s: ni %p (%6D) with lsta NULL\n", 122311db70b6SBjoern A. Zeeb __func__, ni, ni->ni_bssid, ":"); 122411db70b6SBjoern A. Zeeb ieee80211_free_node(ni); 122511db70b6SBjoern A. Zeeb return (0); 122611db70b6SBjoern A. Zeeb } 122711db70b6SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 122811db70b6SBjoern A. Zeeb 122911db70b6SBjoern A. Zeeb wiphy_lock(hw->wiphy); 123011db70b6SBjoern A. Zeeb if (lsta->kc[k->wk_keyix] != NULL) { 123111db70b6SBjoern A. Zeeb IMPROVE("Still in firmware? Del first. Can we assert this cannot happen?"); 123211db70b6SBjoern A. Zeeb ic_printf(ic, "%s: sta %6D found with key information\n", 123311db70b6SBjoern A. Zeeb __func__, sta->addr, ":"); 123411db70b6SBjoern A. Zeeb kc = lsta->kc[k->wk_keyix]; 123511db70b6SBjoern A. Zeeb lsta->kc[k->wk_keyix] = NULL; 123611db70b6SBjoern A. Zeeb free(kc, M_LKPI80211); 123711db70b6SBjoern A. Zeeb kc = NULL; /* safeguard */ 123811db70b6SBjoern A. Zeeb } 123911db70b6SBjoern A. Zeeb 124011db70b6SBjoern A. Zeeb lcipher = lkpi_net80211_to_l80211_cipher_suite( 12416b4cac81SBjoern A. Zeeb k->wk_cipher->ic_cipher, k->wk_keylen); 124211db70b6SBjoern A. Zeeb switch (lcipher) { 124311db70b6SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP: 124411db70b6SBjoern A. Zeeb break; 124511db70b6SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP: 124611db70b6SBjoern A. Zeeb default: 124712a511c8SBjoern A. Zeeb ic_printf(ic, "%s: CIPHER SUITE %#x (%s) not supported\n", 124812a511c8SBjoern A. Zeeb __func__, lcipher, lkpi_cipher_suite_to_name(lcipher)); 124911db70b6SBjoern A. Zeeb IMPROVE(); 125011db70b6SBjoern A. Zeeb wiphy_unlock(hw->wiphy); 125111db70b6SBjoern A. Zeeb ieee80211_free_node(ni); 125211db70b6SBjoern A. Zeeb return (0); 125311db70b6SBjoern A. Zeeb } 125411db70b6SBjoern A. Zeeb 125511db70b6SBjoern A. Zeeb kc = malloc(sizeof(*kc) + k->wk_keylen, M_LKPI80211, M_WAITOK | M_ZERO); 125611db70b6SBjoern A. Zeeb kc->_k = k; /* Save the pointer to net80211. */ 125711db70b6SBjoern A. Zeeb atomic64_set(&kc->tx_pn, k->wk_keytsc); 125811db70b6SBjoern A. Zeeb kc->cipher = lcipher; 12596b4cac81SBjoern A. Zeeb kc->keyidx = k->wk_keyix; 12606b4cac81SBjoern A. Zeeb #if 0 12616b4cac81SBjoern A. Zeeb kc->hw_key_idx = /* set by hw and needs to be passed for TX */; 12626b4cac81SBjoern A. Zeeb #endif 12636b4cac81SBjoern A. Zeeb atomic64_set(&kc->tx_pn, k->wk_keytsc); 12646b4cac81SBjoern A. Zeeb kc->keylen = k->wk_keylen; 12656b4cac81SBjoern A. Zeeb memcpy(kc->key, k->wk_key, k->wk_keylen); 12666b4cac81SBjoern A. Zeeb 126711db70b6SBjoern A. Zeeb if (k->wk_flags & (IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV)) 126811db70b6SBjoern A. Zeeb kc->flags |= IEEE80211_KEY_FLAG_PAIRWISE; 126911db70b6SBjoern A. Zeeb if (k->wk_flags & IEEE80211_KEY_GROUP) 127011db70b6SBjoern A. Zeeb kc->flags &= ~IEEE80211_KEY_FLAG_PAIRWISE; 127111db70b6SBjoern A. Zeeb 12726b4cac81SBjoern A. Zeeb switch (kc->cipher) { 12736b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP: 12746b4cac81SBjoern A. Zeeb kc->iv_len = k->wk_cipher->ic_header; 12756b4cac81SBjoern A. Zeeb kc->icv_len = k->wk_cipher->ic_trailer; 12766b4cac81SBjoern A. Zeeb break; 12776b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP: 12786b4cac81SBjoern A. Zeeb default: 127911db70b6SBjoern A. Zeeb /* currently UNREACH */ 12806b4cac81SBjoern A. Zeeb IMPROVE(); 128111db70b6SBjoern A. Zeeb break; 12826b4cac81SBjoern A. Zeeb }; 128311db70b6SBjoern A. Zeeb lsta->kc[k->wk_keyix] = kc; 12846b4cac81SBjoern A. Zeeb 128511db70b6SBjoern A. Zeeb error = lkpi_80211_mo_set_key(hw, SET_KEY, vif, sta, kc); 128611db70b6SBjoern A. Zeeb if (error != 0) { 128711db70b6SBjoern A. Zeeb ic_printf(ic, "%s: set_key cmd %d(%s) for sta %6D failed: %d\n", 128811db70b6SBjoern A. Zeeb __func__, SET_KEY, "SET", sta->addr, ":", error); 128911db70b6SBjoern A. Zeeb lsta->kc[k->wk_keyix] = NULL; 129011db70b6SBjoern A. Zeeb free(kc, M_LKPI80211); 129111db70b6SBjoern A. Zeeb wiphy_unlock(hw->wiphy); 129211db70b6SBjoern A. Zeeb ieee80211_free_node(ni); 129311db70b6SBjoern A. Zeeb return (0); 12946b4cac81SBjoern A. Zeeb } 12956b4cac81SBjoern A. Zeeb 129611db70b6SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 129711db70b6SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO) 129811db70b6SBjoern A. Zeeb ic_printf(ic, "%s: set_key cmd %d(%s) for sta %6D succeeded: " 129911db70b6SBjoern A. Zeeb "kc %p keyidx %u hw_key_idx %u flags %#010x\n", __func__, 130011db70b6SBjoern A. Zeeb SET_KEY, "SET", sta->addr, ":", 130111db70b6SBjoern A. Zeeb kc, kc->keyidx, kc->hw_key_idx, kc->flags); 130211db70b6SBjoern A. Zeeb #endif 130311db70b6SBjoern A. Zeeb 130411db70b6SBjoern A. Zeeb wiphy_unlock(hw->wiphy); 130511db70b6SBjoern A. Zeeb ieee80211_free_node(ni); 13066b4cac81SBjoern A. Zeeb return (1); 13076b4cac81SBjoern A. Zeeb } 13086b4cac81SBjoern A. Zeeb 13096b4cac81SBjoern A. Zeeb static int 13106b4cac81SBjoern A. Zeeb lkpi_iv_key_set(struct ieee80211vap *vap, const struct ieee80211_key *k) 13116b4cac81SBjoern A. Zeeb { 13126b4cac81SBjoern A. Zeeb 131311db70b6SBjoern A. Zeeb return (_lkpi_iv_key_set(vap, k)); 13146b4cac81SBjoern A. Zeeb } 13156b4cac81SBjoern A. Zeeb #endif 13166b4cac81SBjoern A. Zeeb 13176b4cac81SBjoern A. Zeeb static u_int 13186b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast_copy(void *arg, struct sockaddr_dl *sdl, u_int cnt) 13196b4cac81SBjoern A. Zeeb { 13206b4cac81SBjoern A. Zeeb struct netdev_hw_addr_list *mc_list; 13216b4cac81SBjoern A. Zeeb struct netdev_hw_addr *addr; 13226b4cac81SBjoern A. Zeeb 13236b4cac81SBjoern A. Zeeb KASSERT(arg != NULL && sdl != NULL, ("%s: arg %p sdl %p cnt %u\n", 13246b4cac81SBjoern A. Zeeb __func__, arg, sdl, cnt)); 13256b4cac81SBjoern A. Zeeb 13266b4cac81SBjoern A. Zeeb mc_list = arg; 13276b4cac81SBjoern A. Zeeb /* If it is on the list already skip it. */ 13286b4cac81SBjoern A. Zeeb netdev_hw_addr_list_for_each(addr, mc_list) { 13296b4cac81SBjoern A. Zeeb if (!memcmp(addr->addr, LLADDR(sdl), sdl->sdl_alen)) 13306b4cac81SBjoern A. Zeeb return (0); 13316b4cac81SBjoern A. Zeeb } 13326b4cac81SBjoern A. Zeeb 13336b4cac81SBjoern A. Zeeb addr = malloc(sizeof(*addr), M_LKPI80211, M_NOWAIT | M_ZERO); 13346b4cac81SBjoern A. Zeeb if (addr == NULL) 13356b4cac81SBjoern A. Zeeb return (0); 13366b4cac81SBjoern A. Zeeb 13376b4cac81SBjoern A. Zeeb INIT_LIST_HEAD(&addr->addr_list); 13386b4cac81SBjoern A. Zeeb memcpy(addr->addr, LLADDR(sdl), sdl->sdl_alen); 13396b4cac81SBjoern A. Zeeb /* XXX this should be a netdev function? */ 13406b4cac81SBjoern A. Zeeb list_add(&addr->addr_list, &mc_list->addr_list); 13416b4cac81SBjoern A. Zeeb mc_list->count++; 13426b4cac81SBjoern A. Zeeb 13439d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 13449d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 13456b4cac81SBjoern A. Zeeb printf("%s:%d: mc_list count %d: added %6D\n", 13466b4cac81SBjoern A. Zeeb __func__, __LINE__, mc_list->count, addr->addr, ":"); 13479d9ba2b7SBjoern A. Zeeb #endif 13486b4cac81SBjoern A. Zeeb 13496b4cac81SBjoern A. Zeeb return (1); 13506b4cac81SBjoern A. Zeeb } 13516b4cac81SBjoern A. Zeeb 13526b4cac81SBjoern A. Zeeb static void 13536b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(struct ieee80211com *ic, bool force) 13546b4cac81SBjoern A. Zeeb { 13556b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 13566b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 13576b4cac81SBjoern A. Zeeb struct netdev_hw_addr_list mc_list; 13586b4cac81SBjoern A. Zeeb struct list_head *le, *next; 13596b4cac81SBjoern A. Zeeb struct netdev_hw_addr *addr; 13606b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 13616b4cac81SBjoern A. Zeeb u64 mc; 13626b4cac81SBjoern A. Zeeb unsigned int changed_flags, total_flags; 13636b4cac81SBjoern A. Zeeb 13646b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 13656b4cac81SBjoern A. Zeeb 13666b4cac81SBjoern A. Zeeb if (lhw->ops->prepare_multicast == NULL || 13676b4cac81SBjoern A. Zeeb lhw->ops->configure_filter == NULL) 13686b4cac81SBjoern A. Zeeb return; 13696b4cac81SBjoern A. Zeeb 13706b4cac81SBjoern A. Zeeb if (!lhw->update_mc && !force) 13716b4cac81SBjoern A. Zeeb return; 13726b4cac81SBjoern A. Zeeb 13736b4cac81SBjoern A. Zeeb changed_flags = total_flags = 0; 13746b4cac81SBjoern A. Zeeb mc_list.count = 0; 13756b4cac81SBjoern A. Zeeb INIT_LIST_HEAD(&mc_list.addr_list); 13766b4cac81SBjoern A. Zeeb if (ic->ic_allmulti == 0) { 13776b4cac81SBjoern A. Zeeb TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) 13786b4cac81SBjoern A. Zeeb if_foreach_llmaddr(vap->iv_ifp, 13796b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast_copy, &mc_list); 13806b4cac81SBjoern A. Zeeb } else { 13816b4cac81SBjoern A. Zeeb changed_flags |= FIF_ALLMULTI; 13826b4cac81SBjoern A. Zeeb } 13836b4cac81SBjoern A. Zeeb 13846b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 13856b4cac81SBjoern A. Zeeb mc = lkpi_80211_mo_prepare_multicast(hw, &mc_list); 13866b4cac81SBjoern A. Zeeb /* 13876b4cac81SBjoern A. Zeeb * XXX-BZ make sure to get this sorted what is a change, 13886b4cac81SBjoern A. Zeeb * what gets all set; what was already set? 13896b4cac81SBjoern A. Zeeb */ 13906b4cac81SBjoern A. Zeeb total_flags = changed_flags; 13916b4cac81SBjoern A. Zeeb lkpi_80211_mo_configure_filter(hw, changed_flags, &total_flags, mc); 13926b4cac81SBjoern A. Zeeb 13939d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 13949d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 13956b4cac81SBjoern A. Zeeb printf("%s: changed_flags %#06x count %d total_flags %#010x\n", 13966b4cac81SBjoern A. Zeeb __func__, changed_flags, mc_list.count, total_flags); 13979d9ba2b7SBjoern A. Zeeb #endif 13986b4cac81SBjoern A. Zeeb 13996b4cac81SBjoern A. Zeeb if (mc_list.count != 0) { 14006b4cac81SBjoern A. Zeeb list_for_each_safe(le, next, &mc_list.addr_list) { 14016b4cac81SBjoern A. Zeeb addr = list_entry(le, struct netdev_hw_addr, addr_list); 14026b4cac81SBjoern A. Zeeb free(addr, M_LKPI80211); 14036b4cac81SBjoern A. Zeeb mc_list.count--; 14046b4cac81SBjoern A. Zeeb } 14056b4cac81SBjoern A. Zeeb } 14066b4cac81SBjoern A. Zeeb KASSERT(mc_list.count == 0, ("%s: mc_list %p count %d != 0\n", 14076b4cac81SBjoern A. Zeeb __func__, &mc_list, mc_list.count)); 14086b4cac81SBjoern A. Zeeb } 14096b4cac81SBjoern A. Zeeb 1410fa8f007dSBjoern A. Zeeb static enum ieee80211_bss_changed 1411fa8f007dSBjoern A. Zeeb lkpi_update_dtim_tsf(struct ieee80211_vif *vif, struct ieee80211_node *ni, 1412fa8f007dSBjoern A. Zeeb struct ieee80211vap *vap, const char *_f, int _l) 1413fa8f007dSBjoern A. Zeeb { 1414fa8f007dSBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 1415fa8f007dSBjoern A. Zeeb 1416fa8f007dSBjoern A. Zeeb bss_changed = 0; 1417fa8f007dSBjoern A. Zeeb 14189d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 14199d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 1420fa8f007dSBjoern A. Zeeb printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u " 1421fa8f007dSBjoern A. Zeeb "dtim_period %u sync_dtim_count %u sync_tsf %ju " 1422ac1d519cSBjoern A. Zeeb "sync_device_ts %u bss_changed %#010jx\n", 1423fa8f007dSBjoern A. Zeeb __func__, __LINE__, _f, _l, 1424616e1330SBjoern A. Zeeb vif->cfg.assoc, vif->cfg.aid, 1425fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int, vif->bss_conf.dtim_period, 1426fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count, 1427fa8f007dSBjoern A. Zeeb (uintmax_t)vif->bss_conf.sync_tsf, 1428fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_device_ts, 1429ac1d519cSBjoern A. Zeeb (uintmax_t)bss_changed); 14309d9ba2b7SBjoern A. Zeeb #endif 1431fa8f007dSBjoern A. Zeeb 1432fa8f007dSBjoern A. Zeeb if (vif->bss_conf.beacon_int != ni->ni_intval) { 1433fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int = ni->ni_intval; 1434fa8f007dSBjoern A. Zeeb /* iwlwifi FW bug workaround; iwl_mvm_mac_sta_state. */ 1435fa8f007dSBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16) 1436fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int = 16; 1437fa8f007dSBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INT; 1438fa8f007dSBjoern A. Zeeb } 1439fa8f007dSBjoern A. Zeeb if (vif->bss_conf.dtim_period != vap->iv_dtim_period && 1440fa8f007dSBjoern A. Zeeb vap->iv_dtim_period > 0) { 1441fa8f007dSBjoern A. Zeeb vif->bss_conf.dtim_period = vap->iv_dtim_period; 1442fa8f007dSBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INFO; 1443fa8f007dSBjoern A. Zeeb } 1444fa8f007dSBjoern A. Zeeb 1445fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count = vap->iv_dtim_count; 1446fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_tsf = le64toh(ni->ni_tstamp.tsf); 1447fa8f007dSBjoern A. Zeeb /* vif->bss_conf.sync_device_ts = set in linuxkpi_ieee80211_rx. */ 1448fa8f007dSBjoern A. Zeeb 14499d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 14509d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 1451fa8f007dSBjoern A. Zeeb printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u " 1452fa8f007dSBjoern A. Zeeb "dtim_period %u sync_dtim_count %u sync_tsf %ju " 1453ac1d519cSBjoern A. Zeeb "sync_device_ts %u bss_changed %#010jx\n", 1454fa8f007dSBjoern A. Zeeb __func__, __LINE__, _f, _l, 1455616e1330SBjoern A. Zeeb vif->cfg.assoc, vif->cfg.aid, 1456fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int, vif->bss_conf.dtim_period, 1457fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count, 1458fa8f007dSBjoern A. Zeeb (uintmax_t)vif->bss_conf.sync_tsf, 1459fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_device_ts, 1460ac1d519cSBjoern A. Zeeb (uintmax_t)bss_changed); 14619d9ba2b7SBjoern A. Zeeb #endif 1462fa8f007dSBjoern A. Zeeb 1463fa8f007dSBjoern A. Zeeb return (bss_changed); 1464fa8f007dSBjoern A. Zeeb } 1465fa8f007dSBjoern A. Zeeb 14666b4cac81SBjoern A. Zeeb static void 14676b4cac81SBjoern A. Zeeb lkpi_stop_hw_scan(struct lkpi_hw *lhw, struct ieee80211_vif *vif) 14686b4cac81SBjoern A. Zeeb { 14696b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 14706b4cac81SBjoern A. Zeeb int error; 14718ac540d3SBjoern A. Zeeb bool cancel; 14726b4cac81SBjoern A. Zeeb 14738ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 14748ac540d3SBjoern A. Zeeb cancel = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0; 14758ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 14768ac540d3SBjoern A. Zeeb if (!cancel) 14776b4cac81SBjoern A. Zeeb return; 14786b4cac81SBjoern A. Zeeb 14796b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 14806b4cac81SBjoern A. Zeeb 1481bec76628SBjoern A. Zeeb IEEE80211_UNLOCK(lhw->ic); 1482bec76628SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 14836b4cac81SBjoern A. Zeeb /* Need to cancel the scan. */ 14846b4cac81SBjoern A. Zeeb lkpi_80211_mo_cancel_hw_scan(hw, vif); 14858ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 14866b4cac81SBjoern A. Zeeb 14876b4cac81SBjoern A. Zeeb /* Need to make sure we see ieee80211_scan_completed. */ 14888ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 14898ac540d3SBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) 14908ac540d3SBjoern A. Zeeb error = msleep(lhw, &lhw->scan_mtx, 0, "lhwscanstop", hz/2); 14918ac540d3SBjoern A. Zeeb cancel = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0; 14928ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 14938ac540d3SBjoern A. Zeeb 1494bec76628SBjoern A. Zeeb IEEE80211_LOCK(lhw->ic); 14956b4cac81SBjoern A. Zeeb 14968ac540d3SBjoern A. Zeeb if (cancel) 14976b4cac81SBjoern A. Zeeb ic_printf(lhw->ic, "%s: failed to cancel scan: %d (%p, %p)\n", 14986b4cac81SBjoern A. Zeeb __func__, error, lhw, vif); 14996b4cac81SBjoern A. Zeeb } 15006b4cac81SBjoern A. Zeeb 15016b4cac81SBjoern A. Zeeb static void 1502086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(struct ieee80211_hw *hw, bool new) 1503086be6a8SBjoern A. Zeeb { 1504086be6a8SBjoern A. Zeeb struct lkpi_hw *lhw; 1505086be6a8SBjoern A. Zeeb int error; 1506086be6a8SBjoern A. Zeeb bool old; 1507086be6a8SBjoern A. Zeeb 1508086be6a8SBjoern A. Zeeb old = hw->conf.flags & IEEE80211_CONF_IDLE; 1509086be6a8SBjoern A. Zeeb if (old == new) 1510086be6a8SBjoern A. Zeeb return; 1511086be6a8SBjoern A. Zeeb 1512086be6a8SBjoern A. Zeeb hw->conf.flags ^= IEEE80211_CONF_IDLE; 1513086be6a8SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_IDLE); 1514086be6a8SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) { 1515086be6a8SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 1516086be6a8SBjoern A. Zeeb ic_printf(lhw->ic, "ERROR: %s: config %#0x returned %d\n", 1517086be6a8SBjoern A. Zeeb __func__, IEEE80211_CONF_CHANGE_IDLE, error); 1518086be6a8SBjoern A. Zeeb } 1519086be6a8SBjoern A. Zeeb } 1520086be6a8SBjoern A. Zeeb 15215a4d2461SBjoern A. Zeeb static enum ieee80211_bss_changed 15226b4cac81SBjoern A. Zeeb lkpi_disassoc(struct ieee80211_sta *sta, struct ieee80211_vif *vif, 15236b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw) 15246b4cac81SBjoern A. Zeeb { 15255a4d2461SBjoern A. Zeeb enum ieee80211_bss_changed changed; 15265a4d2461SBjoern A. Zeeb 15275a4d2461SBjoern A. Zeeb changed = 0; 15286b4cac81SBjoern A. Zeeb sta->aid = 0; 1529616e1330SBjoern A. Zeeb if (vif->cfg.assoc) { 15306b4cac81SBjoern A. Zeeb 15316b4cac81SBjoern A. Zeeb lhw->update_mc = true; 15326b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(lhw->ic, true); 15336b4cac81SBjoern A. Zeeb 1534616e1330SBjoern A. Zeeb vif->cfg.assoc = false; 1535616e1330SBjoern A. Zeeb vif->cfg.aid = 0; 15366b4cac81SBjoern A. Zeeb changed |= BSS_CHANGED_ASSOC; 15376b4cac81SBjoern A. Zeeb IMPROVE(); 1538086be6a8SBjoern A. Zeeb 15395a4d2461SBjoern A. Zeeb /* 15405a4d2461SBjoern A. Zeeb * Executing the bss_info_changed(BSS_CHANGED_ASSOC) with 15415a4d2461SBjoern A. Zeeb * assoc = false right away here will remove the sta from 15425a4d2461SBjoern A. Zeeb * firmware for iwlwifi. 15435a4d2461SBjoern A. Zeeb * We no longer do this but only return the BSS_CHNAGED value. 15445a4d2461SBjoern A. Zeeb * The caller is responsible for removing the sta gong to 15455a4d2461SBjoern A. Zeeb * IEEE80211_STA_NOTEXIST and then executing the 15465a4d2461SBjoern A. Zeeb * bss_info_changed() update. 15475a4d2461SBjoern A. Zeeb * See lkpi_sta_run_to_init() for more detailed comment. 15485a4d2461SBjoern A. Zeeb */ 15496b4cac81SBjoern A. Zeeb } 15505a4d2461SBjoern A. Zeeb 15515a4d2461SBjoern A. Zeeb return (changed); 15526b4cac81SBjoern A. Zeeb } 15536b4cac81SBjoern A. Zeeb 15546b4cac81SBjoern A. Zeeb static void 15556b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(struct ieee80211_hw *hw, struct ieee80211_sta *sta, 15566b4cac81SBjoern A. Zeeb bool dequeue_seen, bool no_emptyq) 15576b4cac81SBjoern A. Zeeb { 15586b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 15596b4cac81SBjoern A. Zeeb int tid; 1560eac3646fSBjoern A. Zeeb bool ltxq_empty; 15616b4cac81SBjoern A. Zeeb 15626b4cac81SBjoern A. Zeeb /* Wake up all queues to know they are allocated in the driver. */ 15636b4cac81SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 15646b4cac81SBjoern A. Zeeb 15656b4cac81SBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) { 15666b4cac81SBjoern A. Zeeb IMPROVE("station specific?"); 15676b4cac81SBjoern A. Zeeb if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ)) 15686b4cac81SBjoern A. Zeeb continue; 15696b4cac81SBjoern A. Zeeb } else if (tid >= hw->queues) 15706b4cac81SBjoern A. Zeeb continue; 15716b4cac81SBjoern A. Zeeb 15726b4cac81SBjoern A. Zeeb if (sta->txq[tid] == NULL) 15736b4cac81SBjoern A. Zeeb continue; 15746b4cac81SBjoern A. Zeeb 15756b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]); 15766b4cac81SBjoern A. Zeeb if (dequeue_seen && !ltxq->seen_dequeue) 15776b4cac81SBjoern A. Zeeb continue; 15786b4cac81SBjoern A. Zeeb 1579eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_LOCK(ltxq); 1580eac3646fSBjoern A. Zeeb ltxq_empty = skb_queue_empty(<xq->skbq); 1581eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_UNLOCK(ltxq); 1582eac3646fSBjoern A. Zeeb if (no_emptyq && ltxq_empty) 15836b4cac81SBjoern A. Zeeb continue; 15846b4cac81SBjoern A. Zeeb 15856b4cac81SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, sta->txq[tid]); 15866b4cac81SBjoern A. Zeeb } 15876b4cac81SBjoern A. Zeeb } 15886b4cac81SBjoern A. Zeeb 158988665349SBjoern A. Zeeb /* 159088665349SBjoern A. Zeeb * On the way down from RUN -> ASSOC -> AUTH we may send a DISASSOC or DEAUTH 159188665349SBjoern A. Zeeb * packet. The problem is that the state machine functions tend to hold the 159288665349SBjoern A. Zeeb * LHW lock which will prevent lkpi_80211_txq_tx_one() from sending the packet. 159388665349SBjoern A. Zeeb * We call this after dropping the ic lock and before acquiring the LHW lock. 159488665349SBjoern A. Zeeb * we make sure no further packets are queued and if they are queued the task 159588665349SBjoern A. Zeeb * will finish or be cancelled. At the end if a packet is left we manually 159688665349SBjoern A. Zeeb * send it. scan_to_auth() would re-enable sending if the lsta would be 159788665349SBjoern A. Zeeb * re-used. 159888665349SBjoern A. Zeeb */ 159988665349SBjoern A. Zeeb static void 160088665349SBjoern A. Zeeb lkpi_80211_flush_tx(struct lkpi_hw *lhw, struct lkpi_sta *lsta) 160188665349SBjoern A. Zeeb { 160288665349SBjoern A. Zeeb struct mbufq mq; 160388665349SBjoern A. Zeeb struct mbuf *m; 160488665349SBjoern A. Zeeb int len; 160588665349SBjoern A. Zeeb 160688665349SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK_ASSERT(lhw); 160788665349SBjoern A. Zeeb 160888665349SBjoern A. Zeeb /* Do not accept any new packets until scan_to_auth or lsta_free(). */ 160988665349SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_LOCK(lsta); 161088665349SBjoern A. Zeeb lsta->txq_ready = false; 161188665349SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_UNLOCK(lsta); 161288665349SBjoern A. Zeeb 161388665349SBjoern A. Zeeb while (taskqueue_cancel(taskqueue_thread, &lsta->txq_task, NULL) != 0) 161488665349SBjoern A. Zeeb taskqueue_drain(taskqueue_thread, &lsta->txq_task); 161588665349SBjoern A. Zeeb 161688665349SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_LOCK(lsta); 161788665349SBjoern A. Zeeb len = mbufq_len(&lsta->txq); 161888665349SBjoern A. Zeeb if (len <= 0) { 161988665349SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_UNLOCK(lsta); 162088665349SBjoern A. Zeeb return; 162188665349SBjoern A. Zeeb } 162288665349SBjoern A. Zeeb 162388665349SBjoern A. Zeeb mbufq_init(&mq, IFQ_MAXLEN); 162488665349SBjoern A. Zeeb mbufq_concat(&mq, &lsta->txq); 162588665349SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_UNLOCK(lsta); 162688665349SBjoern A. Zeeb 162788665349SBjoern A. Zeeb m = mbufq_dequeue(&mq); 162888665349SBjoern A. Zeeb while (m != NULL) { 162988665349SBjoern A. Zeeb lkpi_80211_txq_tx_one(lsta, m); 163088665349SBjoern A. Zeeb m = mbufq_dequeue(&mq); 163188665349SBjoern A. Zeeb } 163288665349SBjoern A. Zeeb } 163388665349SBjoern A. Zeeb 16346b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 16356b4cac81SBjoern A. Zeeb 16366b4cac81SBjoern A. Zeeb static int 16376b4cac81SBjoern A. Zeeb lkpi_sta_state_do_nada(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 16386b4cac81SBjoern A. Zeeb { 16396b4cac81SBjoern A. Zeeb 16406b4cac81SBjoern A. Zeeb return (0); 16416b4cac81SBjoern A. Zeeb } 16426b4cac81SBjoern A. Zeeb 16436b4cac81SBjoern A. Zeeb /* lkpi_iv_newstate() handles the stop scan case generally. */ 16446b4cac81SBjoern A. Zeeb #define lkpi_sta_scan_to_init(_v, _n, _a) lkpi_sta_state_do_nada(_v, _n, _a) 16456b4cac81SBjoern A. Zeeb 16466b4cac81SBjoern A. Zeeb static int 16476b4cac81SBjoern A. Zeeb lkpi_sta_scan_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 16486b4cac81SBjoern A. Zeeb { 16496b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 1650c5e25798SBjoern A. Zeeb struct lkpi_chanctx *lchanctx; 1651d1af434dSBjoern A. Zeeb struct ieee80211_chanctx_conf *chanctx_conf; 16526b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 16536b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 16546b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 16556b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 16566b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 16576b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 16586b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 16596b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 16606b4cac81SBjoern A. Zeeb uint32_t changed; 16616b4cac81SBjoern A. Zeeb int error; 16626b4cac81SBjoern A. Zeeb 16632ac8a218SBjoern A. Zeeb /* 16642ac8a218SBjoern A. Zeeb * In here we use vap->iv_bss until lvif->lvif_bss is set. 16652ac8a218SBjoern A. Zeeb * For all later (STATE >= AUTH) functions we need to use the lvif 16662ac8a218SBjoern A. Zeeb * cache which will be tracked even through (*iv_update_bss)(). 16672ac8a218SBjoern A. Zeeb */ 16682ac8a218SBjoern A. Zeeb 16692ac8a218SBjoern A. Zeeb if (vap->iv_bss == NULL) { 16702ac8a218SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: no iv_bss for vap %p\n", __func__, vap); 16712ac8a218SBjoern A. Zeeb return (EINVAL); 16722ac8a218SBjoern A. Zeeb } 16730936c648SBjoern A. Zeeb /* 16740936c648SBjoern A. Zeeb * Keep the ni alive locally. In theory (and practice) iv_bss can change 16750936c648SBjoern A. Zeeb * once we unlock here. This is due to net80211 allowing state changes 16760936c648SBjoern A. Zeeb * and new join1() despite having an active node as well as due to 16770936c648SBjoern A. Zeeb * the fact that the iv_bss can be swapped under the hood in (*iv_update_bss). 16780936c648SBjoern A. Zeeb */ 16792ac8a218SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 16802ac8a218SBjoern A. Zeeb if (ni->ni_chan == NULL || ni->ni_chan == IEEE80211_CHAN_ANYC) { 16812ac8a218SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: no channel set for iv_bss ni %p " 16822ac8a218SBjoern A. Zeeb "on vap %p\n", __func__, ni, vap); 16830936c648SBjoern A. Zeeb ieee80211_free_node(ni); /* Error handling for the local ni. */ 16842ac8a218SBjoern A. Zeeb return (EINVAL); 16856b4cac81SBjoern A. Zeeb } 16866b4cac81SBjoern A. Zeeb 16876b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 16882ac8a218SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, ni->ni_chan); 16892ac8a218SBjoern A. Zeeb if (chan == NULL) { 16902ac8a218SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: failed to get LKPI channel from " 16912ac8a218SBjoern A. Zeeb "iv_bss ni %p on vap %p\n", __func__, ni, vap); 16920936c648SBjoern A. Zeeb ieee80211_free_node(ni); /* Error handling for the local ni. */ 16932ac8a218SBjoern A. Zeeb return (ESRCH); 16942ac8a218SBjoern A. Zeeb } 16952ac8a218SBjoern A. Zeeb 16966b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 16976b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 16986b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 16996b4cac81SBjoern A. Zeeb 17000936c648SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 17010936c648SBjoern A. Zeeb /* XXX-BZ KASSERT later? */ 17020936c648SBjoern A. Zeeb if (lvif->lvif_bss_synched || lvif->lvif_bss != NULL) { 17030936c648SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p " 17040936c648SBjoern A. Zeeb "lvif_bss->ni %p synched %d\n", __func__, __LINE__, 17050936c648SBjoern A. Zeeb lvif, vap, vap->iv_bss, lvif->lvif_bss, 17060936c648SBjoern A. Zeeb (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL, 17070936c648SBjoern A. Zeeb lvif->lvif_bss_synched); 170892690579SMark Johnston LKPI_80211_LVIF_UNLOCK(lvif); 170992690579SMark Johnston ieee80211_free_node(ni); /* Error handling for the local ni. */ 17100936c648SBjoern A. Zeeb return (EBUSY); 17110936c648SBjoern A. Zeeb } 17120936c648SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 17130936c648SBjoern A. Zeeb 17146b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 17158ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 17166b4cac81SBjoern A. Zeeb 17176b4cac81SBjoern A. Zeeb /* Add chanctx (or if exists, change it). */ 17186b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 1719d1af434dSBjoern A. Zeeb chanctx_conf = vif->chanctx_conf; 1720d1af434dSBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(chanctx_conf); 17216b4cac81SBjoern A. Zeeb IMPROVE("diff changes for changed, working on live copy, rcu"); 17226b4cac81SBjoern A. Zeeb } else { 17236b4cac81SBjoern A. Zeeb /* Keep separate alloc as in Linux this is rcu managed? */ 1724c5e25798SBjoern A. Zeeb lchanctx = malloc(sizeof(*lchanctx) + hw->chanctx_data_size, 17256b4cac81SBjoern A. Zeeb M_LKPI80211, M_WAITOK | M_ZERO); 1726d1af434dSBjoern A. Zeeb chanctx_conf = &lchanctx->chanctx_conf; 17276b4cac81SBjoern A. Zeeb } 17286b4cac81SBjoern A. Zeeb 1729d1af434dSBjoern A. Zeeb chanctx_conf->rx_chains_dynamic = 1; 1730d1af434dSBjoern A. Zeeb chanctx_conf->rx_chains_static = 1; 1731d1af434dSBjoern A. Zeeb chanctx_conf->radar_enabled = 17326b4cac81SBjoern A. Zeeb (chan->flags & IEEE80211_CHAN_RADAR) ? true : false; 1733d1af434dSBjoern A. Zeeb chanctx_conf->def.chan = chan; 1734d1af434dSBjoern A. Zeeb chanctx_conf->def.width = NL80211_CHAN_WIDTH_20_NOHT; 1735d1af434dSBjoern A. Zeeb chanctx_conf->def.center_freq1 = chan->center_freq; 1736d1af434dSBjoern A. Zeeb chanctx_conf->def.center_freq2 = 0; 17379fb91463SBjoern A. Zeeb IMPROVE("Check vht_cap from band not just chan?"); 17382ac8a218SBjoern A. Zeeb KASSERT(ni->ni_chan != NULL && ni->ni_chan != IEEE80211_CHAN_ANYC, 17392ac8a218SBjoern A. Zeeb ("%s:%d: ni %p ni_chan %p\n", __func__, __LINE__, ni, ni->ni_chan)); 17409fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 17419fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_HT(ni->ni_chan)) { 17429fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_HT40(ni->ni_chan)) { 1743d1af434dSBjoern A. Zeeb chanctx_conf->def.width = NL80211_CHAN_WIDTH_40; 17449fb91463SBjoern A. Zeeb } else 1745d1af434dSBjoern A. Zeeb chanctx_conf->def.width = NL80211_CHAN_WIDTH_20; 17469fb91463SBjoern A. Zeeb } 17479fb91463SBjoern A. Zeeb #endif 17489fb91463SBjoern A. Zeeb #ifdef LKPI_80211_VHT 17499fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_VHT(ni->ni_chan)) { 17509fb91463SBjoern A. Zeeb #ifdef __notyet__ 17519fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_VHT80P80(ni->ni_chan)) { 1752d1af434dSBjoern A. Zeeb chanctx_conf->def.width = NL80211_CHAN_WIDTH_80P80; 1753d1af434dSBjoern A. Zeeb chanctx_conf->def.center_freq2 = 0; /* XXX */ 17549fb91463SBjoern A. Zeeb } else 17559fb91463SBjoern A. Zeeb #endif 17569fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_VHT160(ni->ni_chan)) 1757d1af434dSBjoern A. Zeeb chanctx_conf->def.width = NL80211_CHAN_WIDTH_160; 17589fb91463SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_VHT80(ni->ni_chan)) 1759d1af434dSBjoern A. Zeeb chanctx_conf->def.width = NL80211_CHAN_WIDTH_80; 17609fb91463SBjoern A. Zeeb } 17619fb91463SBjoern A. Zeeb #endif 17626b4cac81SBjoern A. Zeeb /* Responder ... */ 1763d1af434dSBjoern A. Zeeb chanctx_conf->min_def.chan = chan; 1764d1af434dSBjoern A. Zeeb chanctx_conf->min_def.width = NL80211_CHAN_WIDTH_20_NOHT; 1765d1af434dSBjoern A. Zeeb chanctx_conf->min_def.center_freq1 = chan->center_freq; 1766d1af434dSBjoern A. Zeeb chanctx_conf->min_def.center_freq2 = 0; 17679fb91463SBjoern A. Zeeb IMPROVE("currently 20_NOHT min_def only"); 17686b4cac81SBjoern A. Zeeb 17696ffb7bd4SBjoern A. Zeeb /* Set bss info (bss_info_changed). */ 17706ffb7bd4SBjoern A. Zeeb bss_changed = 0; 17716ffb7bd4SBjoern A. Zeeb vif->bss_conf.bssid = ni->ni_bssid; 17726ffb7bd4SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 17736ffb7bd4SBjoern A. Zeeb vif->bss_conf.txpower = ni->ni_txpower; 17746ffb7bd4SBjoern A. Zeeb bss_changed |= BSS_CHANGED_TXPOWER; 17756ffb7bd4SBjoern A. Zeeb vif->cfg.idle = false; 17766ffb7bd4SBjoern A. Zeeb bss_changed |= BSS_CHANGED_IDLE; 17776ffb7bd4SBjoern A. Zeeb 17786ffb7bd4SBjoern A. Zeeb /* vif->bss_conf.basic_rates ? Where exactly? */ 17796ffb7bd4SBjoern A. Zeeb 17806ffb7bd4SBjoern A. Zeeb /* Should almost assert it is this. */ 17816ffb7bd4SBjoern A. Zeeb vif->cfg.assoc = false; 17826ffb7bd4SBjoern A. Zeeb vif->cfg.aid = 0; 17836ffb7bd4SBjoern A. Zeeb 17846ffb7bd4SBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 17856ffb7bd4SBjoern A. Zeeb 17866b4cac81SBjoern A. Zeeb error = 0; 17876b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 17886b4cac81SBjoern A. Zeeb changed = IEEE80211_CHANCTX_CHANGE_MIN_WIDTH; 17896b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_RADAR; 17906b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_RX_CHAINS; 17916b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_WIDTH; 1792d1af434dSBjoern A. Zeeb lkpi_80211_mo_change_chanctx(hw, chanctx_conf, changed); 17936b4cac81SBjoern A. Zeeb } else { 1794d1af434dSBjoern A. Zeeb error = lkpi_80211_mo_add_chanctx(hw, chanctx_conf); 17956b4cac81SBjoern A. Zeeb if (error == 0 || error == EOPNOTSUPP) { 17967b43f4d0SBjoern A. Zeeb vif->bss_conf.chanreq.oper.chan = chanctx_conf->def.chan; 17977b43f4d0SBjoern A. Zeeb vif->bss_conf.chanreq.oper.width = chanctx_conf->def.width; 17987b43f4d0SBjoern A. Zeeb vif->bss_conf.chanreq.oper.center_freq1 = 1799d1af434dSBjoern A. Zeeb chanctx_conf->def.center_freq1; 18009fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 1801943a19c6SBjoern A. Zeeb if (vif->bss_conf.chanreq.oper.width == NL80211_CHAN_WIDTH_40) { 18029fb91463SBjoern A. Zeeb /* Note: it is 10 not 20. */ 18039fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_HT40U(ni->ni_chan)) 1804943a19c6SBjoern A. Zeeb vif->bss_conf.chanreq.oper.center_freq1 += 10; 18059fb91463SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_HT40D(ni->ni_chan)) 1806943a19c6SBjoern A. Zeeb vif->bss_conf.chanreq.oper.center_freq1 -= 10; 18079fb91463SBjoern A. Zeeb } 18089fb91463SBjoern A. Zeeb #endif 18097b43f4d0SBjoern A. Zeeb vif->bss_conf.chanreq.oper.center_freq2 = 1810d1af434dSBjoern A. Zeeb chanctx_conf->def.center_freq2; 18116b4cac81SBjoern A. Zeeb } else { 1812018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_add_chanctx " 1813018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 18146b4cac81SBjoern A. Zeeb goto out; 18156b4cac81SBjoern A. Zeeb } 18166ffb7bd4SBjoern A. Zeeb 1817d1af434dSBjoern A. Zeeb vif->bss_conf.chanctx_conf = chanctx_conf; 18186ffb7bd4SBjoern A. Zeeb 18196b4cac81SBjoern A. Zeeb /* Assign vif chanctx. */ 18206b4cac81SBjoern A. Zeeb if (error == 0) 182168541546SBjoern A. Zeeb error = lkpi_80211_mo_assign_vif_chanctx(hw, vif, 1822d1af434dSBjoern A. Zeeb &vif->bss_conf, chanctx_conf); 18236b4cac81SBjoern A. Zeeb if (error == EOPNOTSUPP) 18246b4cac81SBjoern A. Zeeb error = 0; 18256b4cac81SBjoern A. Zeeb if (error != 0) { 1826018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_assign_vif_chanctx " 1827018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 1828d1af434dSBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, chanctx_conf); 1829d1af434dSBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(chanctx_conf); 1830c5e25798SBjoern A. Zeeb free(lchanctx, M_LKPI80211); 18316b4cac81SBjoern A. Zeeb goto out; 18326b4cac81SBjoern A. Zeeb } 18336b4cac81SBjoern A. Zeeb } 18346b4cac81SBjoern A. Zeeb IMPROVE("update radiotap chan fields too"); 18356b4cac81SBjoern A. Zeeb 18366b4cac81SBjoern A. Zeeb /* RATES */ 18376b4cac81SBjoern A. Zeeb IMPROVE("bss info: not all needs to come now and rates are missing"); 18386b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 18396b4cac81SBjoern A. Zeeb 1840d9f59799SBjoern A. Zeeb /* 18410936c648SBjoern A. Zeeb * Given ni and lsta are 1:1 from alloc to free we can assert that 18420936c648SBjoern A. Zeeb * ni always has lsta data attach despite net80211 node swapping 18430936c648SBjoern A. Zeeb * under the hoods. 1844d9f59799SBjoern A. Zeeb */ 18450936c648SBjoern A. Zeeb KASSERT(ni->ni_drv_data != NULL, ("%s: ni %p ni_drv_data %p\n", 18460936c648SBjoern A. Zeeb __func__, ni, ni->ni_drv_data)); 18476b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 1848e24e8103SBjoern A. Zeeb 184988665349SBjoern A. Zeeb /* 185088665349SBjoern A. Zeeb * Make sure in case the sta did not change and we re-add it, 185188665349SBjoern A. Zeeb * that we can tx again. 185288665349SBjoern A. Zeeb */ 185388665349SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_LOCK(lsta); 185488665349SBjoern A. Zeeb lsta->txq_ready = true; 185588665349SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_UNLOCK(lsta); 185688665349SBjoern A. Zeeb 1857a8f735a6SBjoern A. Zeeb wiphy_lock(hw->wiphy); 18582ac8a218SBjoern A. Zeeb /* Insert the [l]sta into the list of known stations. */ 1859a8f735a6SBjoern A. Zeeb list_add_tail(&lsta->lsta_list, &lvif->lsta_list); 1860a8f735a6SBjoern A. Zeeb wiphy_unlock(hw->wiphy); 1861e24e8103SBjoern A. Zeeb 1862d9f59799SBjoern A. Zeeb /* Add (or adjust) sta and change state (from NOTEXIST) to NONE. */ 18636b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 18646b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NOTEXIST, ("%s: lsta %p state not " 18656b4cac81SBjoern A. Zeeb "NOTEXIST: %#x\n", __func__, lsta, lsta->state)); 1866e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE); 18676b4cac81SBjoern A. Zeeb if (error != 0) { 18686b4cac81SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 1869018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NONE) " 1870018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 18716b4cac81SBjoern A. Zeeb goto out; 18726b4cac81SBjoern A. Zeeb } 18736b4cac81SBjoern A. Zeeb #if 0 18746b4cac81SBjoern A. Zeeb lsta->added_to_drv = true; /* mo manages. */ 18756b4cac81SBjoern A. Zeeb #endif 18766b4cac81SBjoern A. Zeeb 18779d9ba2b7SBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 18789d9ba2b7SBjoern A. Zeeb 18791665ef97SBjoern A. Zeeb #if 0 18806b4cac81SBjoern A. Zeeb /* 18816b4cac81SBjoern A. Zeeb * Wakeup all queues now that sta is there so we have as much time to 18826b4cac81SBjoern A. Zeeb * possibly prepare the queue in the driver to be ready for the 1st 18836b4cac81SBjoern A. Zeeb * packet; lkpi_80211_txq_tx_one() still has a workaround as there 18846b4cac81SBjoern A. Zeeb * is no guarantee or way to check. 1885d9f59799SBjoern A. Zeeb * XXX-BZ and by now we know that this does not work on all drivers 1886d9f59799SBjoern A. Zeeb * for all queues. 18876b4cac81SBjoern A. Zeeb */ 1888e7fe0373SBjoern A. Zeeb lkpi_wake_tx_queues(hw, LSTA_TO_STA(lsta), false, false); 18891665ef97SBjoern A. Zeeb #endif 18906b4cac81SBjoern A. Zeeb 18916b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 18926b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 18936b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 18946b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 18956b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 18966b4cac81SBjoern A. Zeeb 18976b4cac81SBjoern A. Zeeb /* 18986b4cac81SBjoern A. Zeeb * What is going to happen next: 18996b4cac81SBjoern A. Zeeb * - <twiddle> .. we should end up in "auth_to_assoc" 19006b4cac81SBjoern A. Zeeb * - event_callback 19016b4cac81SBjoern A. Zeeb * - update sta_state (NONE to AUTH) 19026b4cac81SBjoern A. Zeeb * - mgd_complete_tx 19036b4cac81SBjoern A. Zeeb * (ideally we'd do that on a callback for something else ...) 19046b4cac81SBjoern A. Zeeb */ 19056b4cac81SBjoern A. Zeeb 1906105b9df2SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 1907105b9df2SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1908105b9df2SBjoern A. Zeeb 1909105b9df2SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 1910105b9df2SBjoern A. Zeeb /* Re-check given (*iv_update_bss) could have happened while we were unlocked. */ 1911105b9df2SBjoern A. Zeeb if (lvif->lvif_bss_synched || lvif->lvif_bss != NULL || 1912105b9df2SBjoern A. Zeeb lsta->ni != vap->iv_bss) 1913105b9df2SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p " 1914105b9df2SBjoern A. Zeeb "lvif_bss->ni %p synched %d, ni %p lsta %p\n", __func__, __LINE__, 1915105b9df2SBjoern A. Zeeb lvif, vap, vap->iv_bss, lvif->lvif_bss, 1916105b9df2SBjoern A. Zeeb (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL, 1917105b9df2SBjoern A. Zeeb lvif->lvif_bss_synched, ni, lsta); 1918105b9df2SBjoern A. Zeeb 1919105b9df2SBjoern A. Zeeb /* 1920105b9df2SBjoern A. Zeeb * Reference the "ni" for caching the lsta/ni in lvif->lvif_bss. 1921105b9df2SBjoern A. Zeeb * Given we cache lsta we use lsta->ni instead of ni here (even though 1922105b9df2SBjoern A. Zeeb * lsta->ni == ni) to be distinct from the rest of the code where we do 1923105b9df2SBjoern A. Zeeb * assume that ni == vap->iv_bss which it may or may not be. 1924105b9df2SBjoern A. Zeeb * So do NOT use iv_bss here anymore as that may have diverged from our 1925105b9df2SBjoern A. Zeeb * function local ni already while ic was unlocked and would lead to 1926105b9df2SBjoern A. Zeeb * inconsistencies. Go and see if we lost a race and do not update 1927105b9df2SBjoern A. Zeeb * lvif_bss_synched in that case. 1928105b9df2SBjoern A. Zeeb */ 1929105b9df2SBjoern A. Zeeb ieee80211_ref_node(lsta->ni); 1930105b9df2SBjoern A. Zeeb lvif->lvif_bss = lsta; 1931105b9df2SBjoern A. Zeeb if (lsta->ni == vap->iv_bss) { 1932105b9df2SBjoern A. Zeeb lvif->lvif_bss_synched = true; 1933105b9df2SBjoern A. Zeeb } else { 1934105b9df2SBjoern A. Zeeb /* Set to un-synched no matter what. */ 1935105b9df2SBjoern A. Zeeb lvif->lvif_bss_synched = false; 1936105b9df2SBjoern A. Zeeb /* 1937105b9df2SBjoern A. Zeeb * We do not error as someone has to take us down. 1938105b9df2SBjoern A. Zeeb * If we are followed by a 2nd, new net80211::join1() going to 1939105b9df2SBjoern A. Zeeb * AUTH lkpi_sta_a_to_a() will error, lkpi_sta_auth_to_{scan,init}() 1940105b9df2SBjoern A. Zeeb * will take the lvif->lvif_bss node down eventually. 1941105b9df2SBjoern A. Zeeb * What happens with the vap->iv_bss node will entirely be up 1942105b9df2SBjoern A. Zeeb * to net80211 as we never used the node beyond alloc()/free() 1943105b9df2SBjoern A. Zeeb * and we do not hold an extra reference for that anymore given 1944105b9df2SBjoern A. Zeeb * ni : lsta == 1:1. 1945105b9df2SBjoern A. Zeeb */ 1946105b9df2SBjoern A. Zeeb } 1947105b9df2SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 1948105b9df2SBjoern A. Zeeb goto out_relocked; 1949105b9df2SBjoern A. Zeeb 19506b4cac81SBjoern A. Zeeb out: 19518ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 19526b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1953105b9df2SBjoern A. Zeeb out_relocked: 19540936c648SBjoern A. Zeeb /* 1955105b9df2SBjoern A. Zeeb * Release the reference that kept the ni stable locally 19560936c648SBjoern A. Zeeb * during the work of this function. 19570936c648SBjoern A. Zeeb */ 19586b4cac81SBjoern A. Zeeb if (ni != NULL) 19596b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 19606b4cac81SBjoern A. Zeeb return (error); 19616b4cac81SBjoern A. Zeeb } 19626b4cac81SBjoern A. Zeeb 19636b4cac81SBjoern A. Zeeb static int 19646b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 19656b4cac81SBjoern A. Zeeb { 19666b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 19676b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 19686b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 19696b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 19706b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 19716b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 19726b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 19736b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 19746b4cac81SBjoern A. Zeeb int error; 19756b4cac81SBjoern A. Zeeb 19766b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 19776b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 19786b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 19796b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 19806b4cac81SBjoern A. Zeeb 19812ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 19822ac8a218SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 19832ac8a218SBjoern A. Zeeb /* XXX-BZ KASSERT later; state going down so no action. */ 19842ac8a218SBjoern A. Zeeb if (lvif->lvif_bss == NULL) 19852ac8a218SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p " 19862ac8a218SBjoern A. Zeeb "lvif_bss->ni %p synched %d\n", __func__, __LINE__, 19872ac8a218SBjoern A. Zeeb lvif, vap, vap->iv_bss, lvif->lvif_bss, 19882ac8a218SBjoern A. Zeeb (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL, 19892ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched); 19902ac8a218SBjoern A. Zeeb #endif 19912ac8a218SBjoern A. Zeeb 19922ac8a218SBjoern A. Zeeb lsta = lvif->lvif_bss; 19932ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 19942ac8a218SBjoern A. Zeeb KASSERT(lsta != NULL && lsta->ni != NULL, ("%s: lsta %p ni %p " 19952ac8a218SBjoern A. Zeeb "lvif %p vap %p\n", __func__, 19962ac8a218SBjoern A. Zeeb lsta, (lsta != NULL) ? lsta->ni : NULL, lvif, vap)); 19972ac8a218SBjoern A. Zeeb ni = lsta->ni; /* Reference held for lvif_bss. */ 19986b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 19996b4cac81SBjoern A. Zeeb 200067674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 20016b4cac81SBjoern A. Zeeb 20026b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 20038ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 20046b4cac81SBjoern A. Zeeb 2005d9f59799SBjoern A. Zeeb /* flush, drop. */ 2006d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 2007d9f59799SBjoern A. Zeeb 20086b4cac81SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 200988665349SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, false, true); 20106b4cac81SBjoern A. Zeeb 20116b4cac81SBjoern A. Zeeb /* flush, no drop */ 20126b4cac81SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 20136b4cac81SBjoern A. Zeeb 20146b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 20156b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 20166b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 20176b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 20186b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 20196b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 20206b4cac81SBjoern A. Zeeb } 20216b4cac81SBjoern A. Zeeb 20226b4cac81SBjoern A. Zeeb /* sync_rx_queues */ 20236b4cac81SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 20246b4cac81SBjoern A. Zeeb 20256b4cac81SBjoern A. Zeeb /* sta_pre_rcu_remove */ 20266b4cac81SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 2027d9f59799SBjoern A. Zeeb 2028d9f59799SBjoern A. Zeeb /* Take the station down. */ 20296b4cac81SBjoern A. Zeeb 20306b4cac81SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 20316b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 20326b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 2033d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg)); 2034e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST); 20356b4cac81SBjoern A. Zeeb if (error != 0) { 20366b4cac81SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 2037018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NOTEXIST) " 2038018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 20396b4cac81SBjoern A. Zeeb goto out; 20406b4cac81SBjoern A. Zeeb } 20416b4cac81SBjoern A. Zeeb #if 0 20426b4cac81SBjoern A. Zeeb lsta->added_to_drv = false; /* mo manages. */ 20436b4cac81SBjoern A. Zeeb #endif 20446b4cac81SBjoern A. Zeeb 204567674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 20466b4cac81SBjoern A. Zeeb 20472ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 20482ac8a218SBjoern A. Zeeb /* Remove ni reference for this cache of lsta. */ 20492ac8a218SBjoern A. Zeeb lvif->lvif_bss = NULL; 20502ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched = false; 20512ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 2052d9f59799SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif); 20530936c648SBjoern A. Zeeb /* 20540936c648SBjoern A. Zeeb * The very last release the reference on the ni for the ni/lsta on 20550936c648SBjoern A. Zeeb * lvif->lvif_bss. Upon return from this both ni and lsta are invalid 20560936c648SBjoern A. Zeeb * and potentially freed. 20570936c648SBjoern A. Zeeb */ 20580936c648SBjoern A. Zeeb ieee80211_free_node(ni); 2059d9f59799SBjoern A. Zeeb 2060d9f59799SBjoern A. Zeeb /* conf_tx */ 2061d9f59799SBjoern A. Zeeb 2062d9f59799SBjoern A. Zeeb /* Take the chan ctx down. */ 20636b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 2064c5e25798SBjoern A. Zeeb struct lkpi_chanctx *lchanctx; 2065d1af434dSBjoern A. Zeeb struct ieee80211_chanctx_conf *chanctx_conf; 20666b4cac81SBjoern A. Zeeb 2067d1af434dSBjoern A. Zeeb chanctx_conf = vif->chanctx_conf; 20686b4cac81SBjoern A. Zeeb /* Remove vif context. */ 206968541546SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->bss_conf, &vif->chanctx_conf); 20706b4cac81SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 20716b4cac81SBjoern A. Zeeb 20725a4d2461SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true); 20735a4d2461SBjoern A. Zeeb 20746b4cac81SBjoern A. Zeeb /* Remove chan ctx. */ 2075d1af434dSBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, chanctx_conf); 2076d1af434dSBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(chanctx_conf); 2077c5e25798SBjoern A. Zeeb free(lchanctx, M_LKPI80211); 20786b4cac81SBjoern A. Zeeb } 20796b4cac81SBjoern A. Zeeb 20806b4cac81SBjoern A. Zeeb out: 20818ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 20826b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 20836b4cac81SBjoern A. Zeeb return (error); 20846b4cac81SBjoern A. Zeeb } 20856b4cac81SBjoern A. Zeeb 20866b4cac81SBjoern A. Zeeb static int 20876b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 20886b4cac81SBjoern A. Zeeb { 20896b4cac81SBjoern A. Zeeb int error; 20906b4cac81SBjoern A. Zeeb 20916b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_scan(vap, nstate, arg); 20926b4cac81SBjoern A. Zeeb if (error == 0) 20936b4cac81SBjoern A. Zeeb error = lkpi_sta_scan_to_init(vap, nstate, arg); 20946b4cac81SBjoern A. Zeeb return (error); 20956b4cac81SBjoern A. Zeeb } 20966b4cac81SBjoern A. Zeeb 20976b4cac81SBjoern A. Zeeb static int 20986b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 20996b4cac81SBjoern A. Zeeb { 21006b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 21016b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 21026b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 21036b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 21046b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 21056b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 21066b4cac81SBjoern A. Zeeb int error; 21076b4cac81SBjoern A. Zeeb 21086b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 21096b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 21106b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 21116b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 21126b4cac81SBjoern A. Zeeb 21136b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 21148ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 21152ac8a218SBjoern A. Zeeb 21162ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 21172ac8a218SBjoern A. Zeeb /* XXX-BZ KASSERT later? */ 21182ac8a218SBjoern A. Zeeb if (!lvif->lvif_bss_synched || lvif->lvif_bss == NULL) { 21192ac8a218SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 21202ac8a218SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p " 21212ac8a218SBjoern A. Zeeb "lvif_bss->ni %p synched %d\n", __func__, __LINE__, 21222ac8a218SBjoern A. Zeeb lvif, vap, vap->iv_bss, lvif->lvif_bss, 21232ac8a218SBjoern A. Zeeb (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL, 21242ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched); 21252ac8a218SBjoern A. Zeeb #endif 21262ac8a218SBjoern A. Zeeb error = ENOTRECOVERABLE; 21272ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 21282ac8a218SBjoern A. Zeeb goto out; 21292ac8a218SBjoern A. Zeeb } 21302ac8a218SBjoern A. Zeeb lsta = lvif->lvif_bss; 21312ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 21322ac8a218SBjoern A. Zeeb 21332ac8a218SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: lsta %p\n", __func__, lsta)); 21346b4cac81SBjoern A. Zeeb 21356b4cac81SBjoern A. Zeeb /* Finish auth. */ 21366b4cac81SBjoern A. Zeeb IMPROVE("event callback"); 21376b4cac81SBjoern A. Zeeb 21386b4cac81SBjoern A. Zeeb /* Update sta_state (NONE to AUTH). */ 21396b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 21406b4cac81SBjoern A. Zeeb "NONE: %#x\n", __func__, lsta, lsta->state)); 2141e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH); 2142018d93ecSBjoern A. Zeeb if (error != 0) { 2143018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTH) " 2144018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 21456b4cac81SBjoern A. Zeeb goto out; 2146018d93ecSBjoern A. Zeeb } 21476b4cac81SBjoern A. Zeeb 21486b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 21496b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 21506b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 21516b4cac81SBjoern A. Zeeb prep_tx_info.success = true; 21526b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 21536b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 21546b4cac81SBjoern A. Zeeb } 21556b4cac81SBjoern A. Zeeb 21566b4cac81SBjoern A. Zeeb /* Now start assoc. */ 21576b4cac81SBjoern A. Zeeb 21586b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 21596b4cac81SBjoern A. Zeeb if (!lsta->in_mgd) { 21606b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 21616b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 21626b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 21636b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 21646b4cac81SBjoern A. Zeeb } 21656b4cac81SBjoern A. Zeeb 21666b4cac81SBjoern A. Zeeb /* Wake tx queue to get packet out. */ 216788665349SBjoern A. Zeeb lkpi_wake_tx_queues(hw, LSTA_TO_STA(lsta), false, true); 21686b4cac81SBjoern A. Zeeb 21696b4cac81SBjoern A. Zeeb /* 21706b4cac81SBjoern A. Zeeb * <twiddle> .. we end up in "assoc_to_run" 21716b4cac81SBjoern A. Zeeb * - update sta_state (AUTH to ASSOC) 21726b4cac81SBjoern A. Zeeb * - conf_tx [all] 21736b4cac81SBjoern A. Zeeb * - bss_info_changed (assoc, aid, ssid, ..) 21746b4cac81SBjoern A. Zeeb * - change_chanctx (if needed) 21756b4cac81SBjoern A. Zeeb * - event_callback 21766b4cac81SBjoern A. Zeeb * - mgd_complete_tx 21776b4cac81SBjoern A. Zeeb */ 21786b4cac81SBjoern A. Zeeb 21796b4cac81SBjoern A. Zeeb out: 21808ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 21816b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 21826b4cac81SBjoern A. Zeeb return (error); 21836b4cac81SBjoern A. Zeeb } 21846b4cac81SBjoern A. Zeeb 21856b4cac81SBjoern A. Zeeb /* auth_to_auth, assoc_to_assoc. */ 21866b4cac81SBjoern A. Zeeb static int 21876b4cac81SBjoern A. Zeeb lkpi_sta_a_to_a(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 21886b4cac81SBjoern A. Zeeb { 21896b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 21906b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 21916b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 21926b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 21936b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 21946b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 21952ac8a218SBjoern A. Zeeb int error; 21966b4cac81SBjoern A. Zeeb 21976b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 21986b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 21996b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 22006b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 22016b4cac81SBjoern A. Zeeb 22026b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 22038ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 22042ac8a218SBjoern A. Zeeb 22052ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 22062ac8a218SBjoern A. Zeeb /* XXX-BZ KASSERT later? */ 22072ac8a218SBjoern A. Zeeb if (!lvif->lvif_bss_synched || lvif->lvif_bss == NULL) { 22082ac8a218SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 22092ac8a218SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p " 22102ac8a218SBjoern A. Zeeb "lvif_bss->ni %p synched %d\n", __func__, __LINE__, 22112ac8a218SBjoern A. Zeeb lvif, vap, vap->iv_bss, lvif->lvif_bss, 22122ac8a218SBjoern A. Zeeb (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL, 22132ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched); 22142ac8a218SBjoern A. Zeeb #endif 22152ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 22162ac8a218SBjoern A. Zeeb error = ENOTRECOVERABLE; 22172ac8a218SBjoern A. Zeeb goto out; 22182ac8a218SBjoern A. Zeeb } 22192ac8a218SBjoern A. Zeeb lsta = lvif->lvif_bss; 22202ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 22212ac8a218SBjoern A. Zeeb 22222ac8a218SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: lsta %p! lvif %p vap %p\n", __func__, 22232ac8a218SBjoern A. Zeeb lsta, lvif, vap)); 22246b4cac81SBjoern A. Zeeb 22256b4cac81SBjoern A. Zeeb IMPROVE("event callback?"); 22266b4cac81SBjoern A. Zeeb 22276b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 22286b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 22296b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 22306b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 22316b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 22326b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 22336b4cac81SBjoern A. Zeeb } 22346b4cac81SBjoern A. Zeeb 22356b4cac81SBjoern A. Zeeb /* Now start assoc. */ 22366b4cac81SBjoern A. Zeeb 22376b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 22386b4cac81SBjoern A. Zeeb if (!lsta->in_mgd) { 22396b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 22406b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 22416b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 22426b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 22436b4cac81SBjoern A. Zeeb } 22446b4cac81SBjoern A. Zeeb 22452ac8a218SBjoern A. Zeeb error = 0; 22462ac8a218SBjoern A. Zeeb out: 22478ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 22486b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 22496b4cac81SBjoern A. Zeeb 22502ac8a218SBjoern A. Zeeb return (error); 22516b4cac81SBjoern A. Zeeb } 22526b4cac81SBjoern A. Zeeb 22536b4cac81SBjoern A. Zeeb static int 2254d9f59799SBjoern A. Zeeb _lkpi_sta_assoc_to_down(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 22556b4cac81SBjoern A. Zeeb { 22566b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 22576b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 22586b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 22596b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 22606b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 22616b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 22626b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 22636b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 2264d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 22656b4cac81SBjoern A. Zeeb int error; 22666b4cac81SBjoern A. Zeeb 22676b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 22686b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 22696b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 22706b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 22716b4cac81SBjoern A. Zeeb 22722ac8a218SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 22732ac8a218SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 22742ac8a218SBjoern A. Zeeb 22752ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 22762ac8a218SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 22772ac8a218SBjoern A. Zeeb /* XXX-BZ KASSERT later; state going down so no action. */ 22782ac8a218SBjoern A. Zeeb if (lvif->lvif_bss == NULL) 22792ac8a218SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p " 22802ac8a218SBjoern A. Zeeb "lvif_bss->ni %p synched %d\n", __func__, __LINE__, 22812ac8a218SBjoern A. Zeeb lvif, vap, vap->iv_bss, lvif->lvif_bss, 22822ac8a218SBjoern A. Zeeb (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL, 22832ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched); 22842ac8a218SBjoern A. Zeeb #endif 22852ac8a218SBjoern A. Zeeb lsta = lvif->lvif_bss; 22862ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 22872ac8a218SBjoern A. Zeeb KASSERT(lsta != NULL && lsta->ni != NULL, ("%s: lsta %p ni %p " 22882ac8a218SBjoern A. Zeeb "lvif %p vap %p\n", __func__, 22892ac8a218SBjoern A. Zeeb lsta, (lsta != NULL) ? lsta->ni : NULL, lvif, vap)); 22902ac8a218SBjoern A. Zeeb 22912ac8a218SBjoern A. Zeeb ni = lsta->ni; /* Reference held for lvif_bss. */ 22926b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 22936b4cac81SBjoern A. Zeeb 229467674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 2295d9f59799SBjoern A. Zeeb 2296d9f59799SBjoern A. Zeeb /* flush, drop. */ 2297d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 2298d9f59799SBjoern A. Zeeb 2299d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?"); 2300d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) && 2301d9f59799SBjoern A. Zeeb !lsta->in_mgd) { 2302d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 2303d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 2304ac1d519cSBjoern A. Zeeb prep_tx_info.was_assoc = true; 2305d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 2306d9f59799SBjoern A. Zeeb lsta->in_mgd = true; 2307d9f59799SBjoern A. Zeeb } 2308d9f59799SBjoern A. Zeeb 23098ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 2310d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 2311d9f59799SBjoern A. Zeeb 231288665349SBjoern A. Zeeb /* Call iv_newstate first so we get potential DEAUTH packet out. */ 2313d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 2314018d93ecSBjoern A. Zeeb if (error != 0) { 2315018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: iv_newstate(%p, %d, %d) " 2316018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, vap, nstate, arg, error); 2317d9f59799SBjoern A. Zeeb goto outni; 2318018d93ecSBjoern A. Zeeb } 2319d9f59799SBjoern A. Zeeb 2320d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 232188665349SBjoern A. Zeeb 232288665349SBjoern A. Zeeb /* Ensure the packets get out. */ 232388665349SBjoern A. Zeeb lkpi_80211_flush_tx(lhw, lsta); 232488665349SBjoern A. Zeeb 23258ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 2326d9f59799SBjoern A. Zeeb 232767674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 2328d9f59799SBjoern A. Zeeb 2329d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 233088665349SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, false, true); 2331d9f59799SBjoern A. Zeeb 2332d9f59799SBjoern A. Zeeb /* flush, no drop */ 2333d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 2334d9f59799SBjoern A. Zeeb 23356b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 23366b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 23376b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 23386b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 2339ac1d519cSBjoern A. Zeeb prep_tx_info.was_assoc = true; 23406b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 23416b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 23426b4cac81SBjoern A. Zeeb } 23436b4cac81SBjoern A. Zeeb 2344d9f59799SBjoern A. Zeeb /* sync_rx_queues */ 2345d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 2346d9f59799SBjoern A. Zeeb 2347d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */ 2348d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 2349d9f59799SBjoern A. Zeeb 2350d9f59799SBjoern A. Zeeb /* Take the station down. */ 2351d9f59799SBjoern A. Zeeb 23526b4cac81SBjoern A. Zeeb /* Update sta and change state (from AUTH) to NONE. */ 23536b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 23546b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 23556b4cac81SBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 2356e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE); 2357018d93ecSBjoern A. Zeeb if (error != 0) { 2358018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NONE) " 2359018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 23606b4cac81SBjoern A. Zeeb goto out; 2361018d93ecSBjoern A. Zeeb } 23626b4cac81SBjoern A. Zeeb 23635a4d2461SBjoern A. Zeeb /* See comment in lkpi_sta_run_to_init(). */ 23645a4d2461SBjoern A. Zeeb bss_changed = 0; 23655a4d2461SBjoern A. Zeeb bss_changed |= lkpi_disassoc(sta, vif, lhw); 23666b4cac81SBjoern A. Zeeb 23675a4d2461SBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 236816e688b2SBjoern A. Zeeb 2369d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 2370d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 2371d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 2372d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg)); 2373e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST); 2374d9f59799SBjoern A. Zeeb if (error != 0) { 2375d9f59799SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 2376018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NOTEXIST) " 2377018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 2378d9f59799SBjoern A. Zeeb goto out; 2379d9f59799SBjoern A. Zeeb } 2380d9f59799SBjoern A. Zeeb 238116e688b2SBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); /* sta no longer save to use. */ 2382d9f59799SBjoern A. Zeeb 2383d9f59799SBjoern A. Zeeb IMPROVE("Any bss_info changes to announce?"); 2384d9f59799SBjoern A. Zeeb vif->bss_conf.qos = 0; 2385d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 2386616e1330SBjoern A. Zeeb vif->cfg.ssid_len = 0; 2387616e1330SBjoern A. Zeeb memset(vif->cfg.ssid, '\0', sizeof(vif->cfg.ssid)); 2388d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 2389d9f59799SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 2390d9f59799SBjoern A. Zeeb 23912ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 23922ac8a218SBjoern A. Zeeb /* Remove ni reference for this cache of lsta. */ 23932ac8a218SBjoern A. Zeeb lvif->lvif_bss = NULL; 23942ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched = false; 23952ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 2396d9f59799SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif); 23970936c648SBjoern A. Zeeb /* 23980936c648SBjoern A. Zeeb * The very last release the reference on the ni for the ni/lsta on 23990936c648SBjoern A. Zeeb * lvif->lvif_bss. Upon return from this both ni and lsta are invalid 24000936c648SBjoern A. Zeeb * and potentially freed. 24010936c648SBjoern A. Zeeb */ 24020936c648SBjoern A. Zeeb ieee80211_free_node(ni); 2403d9f59799SBjoern A. Zeeb 2404d9f59799SBjoern A. Zeeb /* conf_tx */ 2405d9f59799SBjoern A. Zeeb 2406d9f59799SBjoern A. Zeeb /* Take the chan ctx down. */ 2407d9f59799SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 2408c5e25798SBjoern A. Zeeb struct lkpi_chanctx *lchanctx; 2409d1af434dSBjoern A. Zeeb struct ieee80211_chanctx_conf *chanctx_conf; 2410d9f59799SBjoern A. Zeeb 2411d1af434dSBjoern A. Zeeb chanctx_conf = vif->chanctx_conf; 2412d9f59799SBjoern A. Zeeb /* Remove vif context. */ 241368541546SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->bss_conf, &vif->chanctx_conf); 2414d9f59799SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 2415d9f59799SBjoern A. Zeeb 24165a4d2461SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true); 24175a4d2461SBjoern A. Zeeb 2418d9f59799SBjoern A. Zeeb /* Remove chan ctx. */ 2419d1af434dSBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, chanctx_conf); 2420d1af434dSBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(chanctx_conf); 2421c5e25798SBjoern A. Zeeb free(lchanctx, M_LKPI80211); 2422d9f59799SBjoern A. Zeeb } 2423d9f59799SBjoern A. Zeeb 2424d9f59799SBjoern A. Zeeb error = EALREADY; 24256b4cac81SBjoern A. Zeeb out: 24268ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 24276b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 2428d9f59799SBjoern A. Zeeb outni: 24296b4cac81SBjoern A. Zeeb return (error); 24306b4cac81SBjoern A. Zeeb } 24316b4cac81SBjoern A. Zeeb 24326b4cac81SBjoern A. Zeeb static int 2433d9f59799SBjoern A. Zeeb lkpi_sta_assoc_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 2434d9f59799SBjoern A. Zeeb { 2435d9f59799SBjoern A. Zeeb int error; 2436d9f59799SBjoern A. Zeeb 2437d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg); 2438d9f59799SBjoern A. Zeeb if (error != 0 && error != EALREADY) 2439d9f59799SBjoern A. Zeeb return (error); 2440d9f59799SBjoern A. Zeeb 2441d9f59799SBjoern A. Zeeb /* At this point iv_bss is long a new node! */ 2442d9f59799SBjoern A. Zeeb 2443d9f59799SBjoern A. Zeeb error |= lkpi_sta_scan_to_auth(vap, nstate, 0); 2444d9f59799SBjoern A. Zeeb return (error); 2445d9f59799SBjoern A. Zeeb } 2446d9f59799SBjoern A. Zeeb 2447d9f59799SBjoern A. Zeeb static int 24486b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 24496b4cac81SBjoern A. Zeeb { 24506b4cac81SBjoern A. Zeeb int error; 24516b4cac81SBjoern A. Zeeb 2452d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg); 24536b4cac81SBjoern A. Zeeb return (error); 24546b4cac81SBjoern A. Zeeb } 24556b4cac81SBjoern A. Zeeb 24566b4cac81SBjoern A. Zeeb static int 24576b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 24586b4cac81SBjoern A. Zeeb { 24596b4cac81SBjoern A. Zeeb int error; 24606b4cac81SBjoern A. Zeeb 2461d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg); 24626b4cac81SBjoern A. Zeeb return (error); 24636b4cac81SBjoern A. Zeeb } 24646b4cac81SBjoern A. Zeeb 24656b4cac81SBjoern A. Zeeb static int 24666b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 24676b4cac81SBjoern A. Zeeb { 24686b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 24696b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 24706b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 24716b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 24726b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 24736b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 24746b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 24756b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 24766b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 24776b4cac81SBjoern A. Zeeb int error; 24786b4cac81SBjoern A. Zeeb 24796b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 24806b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 24816b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 24826b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 24836b4cac81SBjoern A. Zeeb 24846b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 24858ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 24862ac8a218SBjoern A. Zeeb 24872ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 24882ac8a218SBjoern A. Zeeb /* XXX-BZ KASSERT later? */ 24892ac8a218SBjoern A. Zeeb if (!lvif->lvif_bss_synched || lvif->lvif_bss == NULL) { 24902ac8a218SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 24912ac8a218SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p " 24922ac8a218SBjoern A. Zeeb "lvif_bss->ni %p synched %d\n", __func__, __LINE__, 24932ac8a218SBjoern A. Zeeb lvif, vap, vap->iv_bss, lvif->lvif_bss, 24942ac8a218SBjoern A. Zeeb (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL, 24952ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched); 24962ac8a218SBjoern A. Zeeb #endif 24972ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 24982ac8a218SBjoern A. Zeeb error = ENOTRECOVERABLE; 24992ac8a218SBjoern A. Zeeb goto out; 25002ac8a218SBjoern A. Zeeb } 25012ac8a218SBjoern A. Zeeb lsta = lvif->lvif_bss; 25022ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 25032ac8a218SBjoern A. Zeeb KASSERT(lsta != NULL && lsta->ni != NULL, ("%s: lsta %p ni %p " 25042ac8a218SBjoern A. Zeeb "lvif %p vap %p\n", __func__, 25052ac8a218SBjoern A. Zeeb lsta, (lsta != NULL) ? lsta->ni : NULL, lvif, vap)); 25062ac8a218SBjoern A. Zeeb 25072ac8a218SBjoern A. Zeeb ni = lsta->ni; /* Reference held for lvif_bss. */ 25086b4cac81SBjoern A. Zeeb 25096b4cac81SBjoern A. Zeeb IMPROVE("ponder some of this moved to ic_newassoc, scan_assoc_success, " 25106b4cac81SBjoern A. Zeeb "and to lesser extend ieee80211_notify_node_join"); 25116b4cac81SBjoern A. Zeeb 25129597f7cbSBjoern A. Zeeb /* Finish assoc. */ 25139597f7cbSBjoern A. Zeeb /* Update sta_state (AUTH to ASSOC) and set aid. */ 25149597f7cbSBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 25159597f7cbSBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 25166b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 25179597f7cbSBjoern A. Zeeb sta->aid = IEEE80211_NODE_AID(ni); 25184a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 25194a67f1dfSBjoern A. Zeeb if (vap->iv_flags & IEEE80211_F_WME) 25204a67f1dfSBjoern A. Zeeb sta->wme = true; 25214a67f1dfSBjoern A. Zeeb #endif 2522e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC); 2523018d93ecSBjoern A. Zeeb if (error != 0) { 2524018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(ASSOC) " 2525018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 25269597f7cbSBjoern A. Zeeb goto out; 2527018d93ecSBjoern A. Zeeb } 25286b4cac81SBjoern A. Zeeb 25296b4cac81SBjoern A. Zeeb IMPROVE("wme / conf_tx [all]"); 25306b4cac81SBjoern A. Zeeb 25316b4cac81SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 25326b4cac81SBjoern A. Zeeb bss_changed = 0; 25334a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 25344a67f1dfSBjoern A. Zeeb bss_changed |= lkpi_wme_update(lhw, vap, true); 25354a67f1dfSBjoern A. Zeeb #endif 2536616e1330SBjoern A. Zeeb if (!vif->cfg.assoc || vif->cfg.aid != IEEE80211_NODE_AID(ni)) { 2537616e1330SBjoern A. Zeeb vif->cfg.assoc = true; 2538616e1330SBjoern A. Zeeb vif->cfg.aid = IEEE80211_NODE_AID(ni); 25396b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_ASSOC; 25406b4cac81SBjoern A. Zeeb } 25416b4cac81SBjoern A. Zeeb /* We set SSID but this is not BSSID! */ 2542616e1330SBjoern A. Zeeb vif->cfg.ssid_len = ni->ni_esslen; 2543616e1330SBjoern A. Zeeb memcpy(vif->cfg.ssid, ni->ni_essid, ni->ni_esslen); 25446b4cac81SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_SHPREAMBLE) != 25456b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble) { 25466b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble ^= 1; 25476b4cac81SBjoern A. Zeeb /* bss_changed |= BSS_CHANGED_??? */ 25486b4cac81SBjoern A. Zeeb } 25496b4cac81SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_SHSLOT) != 25506b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot) { 25516b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot ^= 1; 25526b4cac81SBjoern A. Zeeb /* bss_changed |= BSS_CHANGED_??? */ 25536b4cac81SBjoern A. Zeeb } 25546b4cac81SBjoern A. Zeeb if ((ni->ni_flags & IEEE80211_NODE_QOS) != 25556b4cac81SBjoern A. Zeeb vif->bss_conf.qos) { 25566b4cac81SBjoern A. Zeeb vif->bss_conf.qos ^= 1; 25576b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 25586b4cac81SBjoern A. Zeeb } 2559fa8f007dSBjoern A. Zeeb 2560fa8f007dSBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 2561fa8f007dSBjoern A. Zeeb 25626b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 25636b4cac81SBjoern A. Zeeb 25646b4cac81SBjoern A. Zeeb /* - change_chanctx (if needed) 25656b4cac81SBjoern A. Zeeb * - event_callback 25666b4cac81SBjoern A. Zeeb */ 25676b4cac81SBjoern A. Zeeb 25686b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 25696b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 25706b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 25716b4cac81SBjoern A. Zeeb prep_tx_info.success = true; 25726b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 25736b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 25746b4cac81SBjoern A. Zeeb } 25756b4cac81SBjoern A. Zeeb 2576086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, false); 2577086be6a8SBjoern A. Zeeb 25786b4cac81SBjoern A. Zeeb /* 25796b4cac81SBjoern A. Zeeb * And then: 25806b4cac81SBjoern A. Zeeb * - (more packets)? 25816b4cac81SBjoern A. Zeeb * - set_key 25826b4cac81SBjoern A. Zeeb * - set_default_unicast_key 25836b4cac81SBjoern A. Zeeb * - set_key (?) 25846b4cac81SBjoern A. Zeeb * - ipv6_addr_change (?) 25856b4cac81SBjoern A. Zeeb */ 25866b4cac81SBjoern A. Zeeb /* Prepare_multicast && configure_filter. */ 25876b4cac81SBjoern A. Zeeb lhw->update_mc = true; 25886b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(vap->iv_ic, true); 25896b4cac81SBjoern A. Zeeb 25906b4cac81SBjoern A. Zeeb if (!ieee80211_node_is_authorized(ni)) { 25916b4cac81SBjoern A. Zeeb IMPROVE("net80211 does not consider node authorized"); 25926b4cac81SBjoern A. Zeeb } 25936b4cac81SBjoern A. Zeeb 2594*f9c7a07dSBjoern A. Zeeb sta->deflink.rx_nss = MAX(1, sta->deflink.rx_nss); 25959fb91463SBjoern A. Zeeb IMPROVE("Is this the right spot, has net80211 done all updates already?"); 2596*f9c7a07dSBjoern A. Zeeb lkpi_sta_sync_from_ni(sta, ni); 25979fb91463SBjoern A. Zeeb 25986b4cac81SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTHORIZED). */ 25996b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 26006b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 26016b4cac81SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 2602e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTHORIZED); 26036b4cac81SBjoern A. Zeeb if (error != 0) { 26046b4cac81SBjoern A. Zeeb IMPROVE("undo some changes?"); 2605018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTHORIZED) " 2606018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 26076b4cac81SBjoern A. Zeeb goto out; 26086b4cac81SBjoern A. Zeeb } 26096b4cac81SBjoern A. Zeeb 26106b4cac81SBjoern A. Zeeb /* - drv_config (?) 26116b4cac81SBjoern A. Zeeb * - bss_info_changed 26126b4cac81SBjoern A. Zeeb * - set_rekey_data (?) 26136b4cac81SBjoern A. Zeeb * 26146b4cac81SBjoern A. Zeeb * And now we should be passing packets. 26156b4cac81SBjoern A. Zeeb */ 26166b4cac81SBjoern A. Zeeb IMPROVE("Need that bssid setting, and the keys"); 26176b4cac81SBjoern A. Zeeb 2618fa8f007dSBjoern A. Zeeb bss_changed = 0; 2619fa8f007dSBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 2620fa8f007dSBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 2621fa8f007dSBjoern A. Zeeb 26226b4cac81SBjoern A. Zeeb out: 26238ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 26246b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 26256b4cac81SBjoern A. Zeeb return (error); 26266b4cac81SBjoern A. Zeeb } 26276b4cac81SBjoern A. Zeeb 26286b4cac81SBjoern A. Zeeb static int 26296b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 26306b4cac81SBjoern A. Zeeb { 26316b4cac81SBjoern A. Zeeb int error; 26326b4cac81SBjoern A. Zeeb 26336b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_assoc(vap, nstate, arg); 26346b4cac81SBjoern A. Zeeb if (error == 0) 26356b4cac81SBjoern A. Zeeb error = lkpi_sta_assoc_to_run(vap, nstate, arg); 26366b4cac81SBjoern A. Zeeb return (error); 26376b4cac81SBjoern A. Zeeb } 26386b4cac81SBjoern A. Zeeb 26396b4cac81SBjoern A. Zeeb static int 26406b4cac81SBjoern A. Zeeb lkpi_sta_run_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 26416b4cac81SBjoern A. Zeeb { 26426b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 26436b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 26446b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 26456b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 26466b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 26476b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 26486b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 2649d9f59799SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 2650d9f59799SBjoern A. Zeeb #if 0 2651d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 2652d9f59799SBjoern A. Zeeb #endif 26536b4cac81SBjoern A. Zeeb int error; 26546b4cac81SBjoern A. Zeeb 26556b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 26566b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 26576b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 26586b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 26596b4cac81SBjoern A. Zeeb 26602ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 26612ac8a218SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 26622ac8a218SBjoern A. Zeeb /* XXX-BZ KASSERT later; state going down so no action. */ 26632ac8a218SBjoern A. Zeeb if (lvif->lvif_bss == NULL) 26642ac8a218SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p " 26652ac8a218SBjoern A. Zeeb "lvif_bss->ni %p synched %d\n", __func__, __LINE__, 26662ac8a218SBjoern A. Zeeb lvif, vap, vap->iv_bss, lvif->lvif_bss, 26672ac8a218SBjoern A. Zeeb (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL, 26682ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched); 26692ac8a218SBjoern A. Zeeb #endif 26702ac8a218SBjoern A. Zeeb lsta = lvif->lvif_bss; 26712ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 26722ac8a218SBjoern A. Zeeb KASSERT(lsta != NULL && lsta->ni != NULL, ("%s: lsta %p ni %p " 26732ac8a218SBjoern A. Zeeb "lvif %p vap %p\n", __func__, 26742ac8a218SBjoern A. Zeeb lsta, (lsta != NULL) ? lsta->ni : NULL, lvif, vap)); 26752ac8a218SBjoern A. Zeeb 26762ac8a218SBjoern A. Zeeb ni = lsta->ni; /* Reference held for lvif_bss. */ 26776b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 26786b4cac81SBjoern A. Zeeb 267967674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 2680d9f59799SBjoern A. Zeeb 2681d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 26828ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 2683d9f59799SBjoern A. Zeeb 2684d9f59799SBjoern A. Zeeb /* flush, drop. */ 2685d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 2686d9f59799SBjoern A. Zeeb 2687d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?"); 2688d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) && 2689d9f59799SBjoern A. Zeeb !lsta->in_mgd) { 2690d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 2691d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 2692ac1d519cSBjoern A. Zeeb prep_tx_info.was_assoc = true; 2693d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 2694d9f59799SBjoern A. Zeeb lsta->in_mgd = true; 2695d9f59799SBjoern A. Zeeb } 2696d9f59799SBjoern A. Zeeb 26978ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 2698d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 2699d9f59799SBjoern A. Zeeb 2700d9f59799SBjoern A. Zeeb /* Call iv_newstate first so we get potential DISASSOC packet out. */ 2701d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 2702018d93ecSBjoern A. Zeeb if (error != 0) { 2703018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: iv_newstate(%p, %d, %d) " 2704018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, vap, nstate, arg, error); 2705d9f59799SBjoern A. Zeeb goto outni; 2706018d93ecSBjoern A. Zeeb } 2707d9f59799SBjoern A. Zeeb 2708d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 270988665349SBjoern A. Zeeb 271088665349SBjoern A. Zeeb /* Ensure the packets get out. */ 271188665349SBjoern A. Zeeb lkpi_80211_flush_tx(lhw, lsta); 271288665349SBjoern A. Zeeb 27138ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 2714d9f59799SBjoern A. Zeeb 271567674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 2716d9f59799SBjoern A. Zeeb 2717d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 271888665349SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, false, true); 2719d9f59799SBjoern A. Zeeb 2720d9f59799SBjoern A. Zeeb /* flush, no drop */ 2721d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 2722d9f59799SBjoern A. Zeeb 2723d9f59799SBjoern A. Zeeb /* End mgd_complete_tx. */ 2724d9f59799SBjoern A. Zeeb if (lsta->in_mgd) { 2725d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 2726d9f59799SBjoern A. Zeeb prep_tx_info.success = false; 2727ac1d519cSBjoern A. Zeeb prep_tx_info.was_assoc = true; 2728d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 2729d9f59799SBjoern A. Zeeb lsta->in_mgd = false; 2730d9f59799SBjoern A. Zeeb } 2731d9f59799SBjoern A. Zeeb 2732d9f59799SBjoern A. Zeeb #if 0 2733d9f59799SBjoern A. Zeeb /* sync_rx_queues */ 2734d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 2735d9f59799SBjoern A. Zeeb 2736d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */ 2737d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 2738d9f59799SBjoern A. Zeeb #endif 2739d9f59799SBjoern A. Zeeb 2740d9f59799SBjoern A. Zeeb /* Take the station down. */ 2741d9f59799SBjoern A. Zeeb 27426b4cac81SBjoern A. Zeeb /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */ 27436b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 27446b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not " 27456b4cac81SBjoern A. Zeeb "AUTHORIZED: %#x\n", __func__, lsta, lsta->state)); 2746e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC); 2747018d93ecSBjoern A. Zeeb if (error != 0) { 2748018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(ASSOC) " 2749018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 27506b4cac81SBjoern A. Zeeb goto out; 2751018d93ecSBjoern A. Zeeb } 27526b4cac81SBjoern A. Zeeb 275367674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 27546b4cac81SBjoern A. Zeeb 275511db70b6SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 275611db70b6SBjoern A. Zeeb if (lkpi_hwcrypto) { 275711db70b6SBjoern A. Zeeb wiphy_lock(hw->wiphy); 275811db70b6SBjoern A. Zeeb error = lkpi_sta_del_keys(hw, vif, lsta); 275911db70b6SBjoern A. Zeeb wiphy_unlock(hw->wiphy); 276011db70b6SBjoern A. Zeeb if (error != 0) { 276111db70b6SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lkpi_sta_del_keys " 276211db70b6SBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 276311db70b6SBjoern A. Zeeb /* 276411db70b6SBjoern A. Zeeb * Either drv/fw will crash or cleanup itself, 276511db70b6SBjoern A. Zeeb * otherwise net80211 will delete the keys (at a 276611db70b6SBjoern A. Zeeb * less appropriate time). 276711db70b6SBjoern A. Zeeb */ 276811db70b6SBjoern A. Zeeb /* goto out; */ 276911db70b6SBjoern A. Zeeb } 277011db70b6SBjoern A. Zeeb } 277111db70b6SBjoern A. Zeeb #endif 277211db70b6SBjoern A. Zeeb 27736b4cac81SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTH). */ 27746b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 27756b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 27766b4cac81SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 2777e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH); 2778018d93ecSBjoern A. Zeeb if (error != 0) { 2779018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTH) " 2780018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 27816b4cac81SBjoern A. Zeeb goto out; 2782018d93ecSBjoern A. Zeeb } 27836b4cac81SBjoern A. Zeeb 278467674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 27856b4cac81SBjoern A. Zeeb 2786d9f59799SBjoern A. Zeeb #if 0 2787d9f59799SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 2788d9f59799SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw); 2789d9f59799SBjoern A. Zeeb #endif 2790d9f59799SBjoern A. Zeeb 2791d9f59799SBjoern A. Zeeb error = EALREADY; 27926b4cac81SBjoern A. Zeeb out: 27938ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 27946b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 2795d9f59799SBjoern A. Zeeb outni: 27966b4cac81SBjoern A. Zeeb return (error); 27976b4cac81SBjoern A. Zeeb } 27986b4cac81SBjoern A. Zeeb 27996b4cac81SBjoern A. Zeeb static int 2800d9f59799SBjoern A. Zeeb lkpi_sta_run_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 2801d9f59799SBjoern A. Zeeb { 2802d9f59799SBjoern A. Zeeb struct lkpi_hw *lhw; 2803d9f59799SBjoern A. Zeeb struct ieee80211_hw *hw; 2804d9f59799SBjoern A. Zeeb struct lkpi_vif *lvif; 2805d9f59799SBjoern A. Zeeb struct ieee80211_vif *vif; 2806d9f59799SBjoern A. Zeeb struct ieee80211_node *ni; 2807d9f59799SBjoern A. Zeeb struct lkpi_sta *lsta; 2808d9f59799SBjoern A. Zeeb struct ieee80211_sta *sta; 2809d9f59799SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 2810d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 2811d9f59799SBjoern A. Zeeb int error; 2812d9f59799SBjoern A. Zeeb 2813d9f59799SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 2814d9f59799SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 2815d9f59799SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 2816d9f59799SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 2817d9f59799SBjoern A. Zeeb 28182ac8a218SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 28192ac8a218SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 28202ac8a218SBjoern A. Zeeb 28212ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 28222ac8a218SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 28232ac8a218SBjoern A. Zeeb /* XXX-BZ KASSERT later; state going down so no action. */ 28242ac8a218SBjoern A. Zeeb if (lvif->lvif_bss == NULL) 28252ac8a218SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p " 28262ac8a218SBjoern A. Zeeb "lvif_bss->ni %p synched %d\n", __func__, __LINE__, 28272ac8a218SBjoern A. Zeeb lvif, vap, vap->iv_bss, lvif->lvif_bss, 28282ac8a218SBjoern A. Zeeb (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL, 28292ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched); 28302ac8a218SBjoern A. Zeeb #endif 28312ac8a218SBjoern A. Zeeb lsta = lvif->lvif_bss; 28322ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 28332ac8a218SBjoern A. Zeeb KASSERT(lsta != NULL && lsta->ni != NULL, ("%s: lsta %p ni %p " 28342ac8a218SBjoern A. Zeeb "lvif %p vap %p\n", __func__, 28352ac8a218SBjoern A. Zeeb lsta, (lsta != NULL) ? lsta->ni : NULL, lvif, vap)); 28362ac8a218SBjoern A. Zeeb 28372ac8a218SBjoern A. Zeeb ni = lsta->ni; /* Reference held for lvif_bss. */ 2838d9f59799SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 2839d9f59799SBjoern A. Zeeb 284067674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 2841d9f59799SBjoern A. Zeeb 2842d9f59799SBjoern A. Zeeb /* flush, drop. */ 2843d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 2844d9f59799SBjoern A. Zeeb 2845d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?"); 2846d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) && 2847d9f59799SBjoern A. Zeeb !lsta->in_mgd) { 2848d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 2849d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 2850ac1d519cSBjoern A. Zeeb prep_tx_info.was_assoc = true; 2851d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 2852d9f59799SBjoern A. Zeeb lsta->in_mgd = true; 2853d9f59799SBjoern A. Zeeb } 2854d9f59799SBjoern A. Zeeb 28558ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 2856d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 2857d9f59799SBjoern A. Zeeb 2858d9f59799SBjoern A. Zeeb /* Call iv_newstate first so we get potential DISASSOC packet out. */ 2859d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 2860018d93ecSBjoern A. Zeeb if (error != 0) { 2861018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: iv_newstate(%p, %d, %d) " 2862018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, vap, nstate, arg, error); 2863d9f59799SBjoern A. Zeeb goto outni; 2864018d93ecSBjoern A. Zeeb } 2865d9f59799SBjoern A. Zeeb 2866d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 286788665349SBjoern A. Zeeb 286888665349SBjoern A. Zeeb /* Ensure the packets get out. */ 286988665349SBjoern A. Zeeb lkpi_80211_flush_tx(lhw, lsta); 287088665349SBjoern A. Zeeb 28718ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 2872d9f59799SBjoern A. Zeeb 287367674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 2874d9f59799SBjoern A. Zeeb 2875d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 287688665349SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, false, true); 2877d9f59799SBjoern A. Zeeb 2878d9f59799SBjoern A. Zeeb /* flush, no drop */ 2879d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 2880d9f59799SBjoern A. Zeeb 2881d9f59799SBjoern A. Zeeb /* End mgd_complete_tx. */ 2882d9f59799SBjoern A. Zeeb if (lsta->in_mgd) { 2883d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 2884d9f59799SBjoern A. Zeeb prep_tx_info.success = false; 2885ac1d519cSBjoern A. Zeeb prep_tx_info.was_assoc = true; 2886d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 2887d9f59799SBjoern A. Zeeb lsta->in_mgd = false; 2888d9f59799SBjoern A. Zeeb } 2889d9f59799SBjoern A. Zeeb 2890d9f59799SBjoern A. Zeeb /* sync_rx_queues */ 2891d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 2892d9f59799SBjoern A. Zeeb 2893d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */ 2894d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 2895d9f59799SBjoern A. Zeeb 2896d9f59799SBjoern A. Zeeb /* Take the station down. */ 2897d9f59799SBjoern A. Zeeb 2898d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */ 2899d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 2900d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not " 2901d9f59799SBjoern A. Zeeb "AUTHORIZED: %#x\n", __func__, lsta, lsta->state)); 2902e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC); 2903018d93ecSBjoern A. Zeeb if (error != 0) { 2904018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(ASSOC) " 2905018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 2906d9f59799SBjoern A. Zeeb goto out; 2907018d93ecSBjoern A. Zeeb } 2908d9f59799SBjoern A. Zeeb 290967674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 2910d9f59799SBjoern A. Zeeb 291111db70b6SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 291211db70b6SBjoern A. Zeeb if (lkpi_hwcrypto) { 291311db70b6SBjoern A. Zeeb wiphy_lock(hw->wiphy); 291411db70b6SBjoern A. Zeeb error = lkpi_sta_del_keys(hw, vif, lsta); 291511db70b6SBjoern A. Zeeb wiphy_unlock(hw->wiphy); 291611db70b6SBjoern A. Zeeb if (error != 0) { 291711db70b6SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lkpi_sta_del_keys " 291811db70b6SBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 291911db70b6SBjoern A. Zeeb /* 292011db70b6SBjoern A. Zeeb * Either drv/fw will crash or cleanup itself, 292111db70b6SBjoern A. Zeeb * otherwise net80211 will delete the keys (at a 292211db70b6SBjoern A. Zeeb * less appropriate time). 292311db70b6SBjoern A. Zeeb */ 292411db70b6SBjoern A. Zeeb /* goto out; */ 292511db70b6SBjoern A. Zeeb } 292611db70b6SBjoern A. Zeeb } 292711db70b6SBjoern A. Zeeb #endif 292811db70b6SBjoern A. Zeeb 2929d9f59799SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTH). */ 2930d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 2931d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 2932d9f59799SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 2933e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH); 2934018d93ecSBjoern A. Zeeb if (error != 0) { 2935018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTH) " 2936018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 2937d9f59799SBjoern A. Zeeb goto out; 2938018d93ecSBjoern A. Zeeb } 2939d9f59799SBjoern A. Zeeb 294067674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 2941d9f59799SBjoern A. Zeeb 2942d9f59799SBjoern A. Zeeb /* Update sta and change state (from AUTH) to NONE. */ 2943d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 2944d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 2945d9f59799SBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 2946e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE); 2947018d93ecSBjoern A. Zeeb if (error != 0) { 2948018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NONE) " 2949018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 2950d9f59799SBjoern A. Zeeb goto out; 2951018d93ecSBjoern A. Zeeb } 2952d9f59799SBjoern A. Zeeb 29535a4d2461SBjoern A. Zeeb bss_changed = 0; 295416e688b2SBjoern A. Zeeb /* 29555a4d2461SBjoern A. Zeeb * Start updating bss info (bss_info_changed) (assoc, aid, ..). 29565a4d2461SBjoern A. Zeeb * 295716e688b2SBjoern A. Zeeb * One would expect this to happen when going off AUTHORIZED. 29585a4d2461SBjoern A. Zeeb * See comment there; removes the sta from fw if not careful 29595a4d2461SBjoern A. Zeeb * (bss_info_changed() change is executed right away). 29605a4d2461SBjoern A. Zeeb * 29615a4d2461SBjoern A. Zeeb * We need to do this now, before sta changes to IEEE80211_STA_NOTEXIST 29625a4d2461SBjoern A. Zeeb * as otherwise drivers (iwlwifi at least) will silently not remove 29635a4d2461SBjoern A. Zeeb * the sta from the firmware and when we will add a new one trigger 29645a4d2461SBjoern A. Zeeb * a fw assert. 29655a4d2461SBjoern A. Zeeb * 29665a4d2461SBjoern A. Zeeb * The order which works best so far avoiding early removal or silent 29675a4d2461SBjoern A. Zeeb * non-removal seems to be (for iwlwifi::mld-mac80211.c cases; 29685a4d2461SBjoern A. Zeeb * the iwlwifi:mac80211.c case still to be tested): 29695a4d2461SBjoern A. Zeeb * 1) lkpi_disassoc(): set vif->cfg.assoc = false (aid=0 side effect here) 29705a4d2461SBjoern A. Zeeb * 2) call the last sta_state update -> IEEE80211_STA_NOTEXIST 29715a4d2461SBjoern A. Zeeb * (removes the sta given assoc is false) 29725a4d2461SBjoern A. Zeeb * 3) add the remaining BSS_CHANGED changes and call bss_info_changed() 29735a4d2461SBjoern A. Zeeb * 4) call unassign_vif_chanctx 29745a4d2461SBjoern A. Zeeb * 5) call lkpi_hw_conf_idle 29755a4d2461SBjoern A. Zeeb * 6) call remove_chanctx 297616e688b2SBjoern A. Zeeb */ 29775a4d2461SBjoern A. Zeeb bss_changed |= lkpi_disassoc(sta, vif, lhw); 29785a4d2461SBjoern A. Zeeb 29795a4d2461SBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 298016e688b2SBjoern A. Zeeb 2981d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 2982d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 2983d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 2984d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg)); 2985e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST); 2986d9f59799SBjoern A. Zeeb if (error != 0) { 2987d9f59799SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 2988018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NOTEXIST) " 2989018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 2990d9f59799SBjoern A. Zeeb goto out; 2991d9f59799SBjoern A. Zeeb } 2992d9f59799SBjoern A. Zeeb 29935a4d2461SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif); 29945a4d2461SBjoern A. Zeeb 299516e688b2SBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); /* sta no longer save to use. */ 2996d9f59799SBjoern A. Zeeb 2997d9f59799SBjoern A. Zeeb IMPROVE("Any bss_info changes to announce?"); 2998d9f59799SBjoern A. Zeeb vif->bss_conf.qos = 0; 2999d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 3000616e1330SBjoern A. Zeeb vif->cfg.ssid_len = 0; 3001616e1330SBjoern A. Zeeb memset(vif->cfg.ssid, '\0', sizeof(vif->cfg.ssid)); 3002d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 30035a4d2461SBjoern A. Zeeb vif->bss_conf.use_short_preamble = false; 30045a4d2461SBjoern A. Zeeb vif->bss_conf.qos = false; 30055a4d2461SBjoern A. Zeeb /* XXX BSS_CHANGED_???? */ 3006d9f59799SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 3007d9f59799SBjoern A. Zeeb 30082ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 30092ac8a218SBjoern A. Zeeb /* Remove ni reference for this cache of lsta. */ 30102ac8a218SBjoern A. Zeeb lvif->lvif_bss = NULL; 30112ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched = false; 30122ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 30130936c648SBjoern A. Zeeb /* 30140936c648SBjoern A. Zeeb * The very last release the reference on the ni for the ni/lsta on 30150936c648SBjoern A. Zeeb * lvif->lvif_bss. Upon return from this both ni and lsta are invalid 30160936c648SBjoern A. Zeeb * and potentially freed. 30170936c648SBjoern A. Zeeb */ 30180936c648SBjoern A. Zeeb ieee80211_free_node(ni); 3019d9f59799SBjoern A. Zeeb 3020d9f59799SBjoern A. Zeeb /* conf_tx */ 3021d9f59799SBjoern A. Zeeb 3022d9f59799SBjoern A. Zeeb /* Take the chan ctx down. */ 3023d9f59799SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 3024c5e25798SBjoern A. Zeeb struct lkpi_chanctx *lchanctx; 3025d1af434dSBjoern A. Zeeb struct ieee80211_chanctx_conf *chanctx_conf; 3026d9f59799SBjoern A. Zeeb 3027d1af434dSBjoern A. Zeeb chanctx_conf = vif->chanctx_conf; 3028d9f59799SBjoern A. Zeeb /* Remove vif context. */ 302968541546SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->bss_conf, &vif->chanctx_conf); 3030d9f59799SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 3031d9f59799SBjoern A. Zeeb 30325a4d2461SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true); 30335a4d2461SBjoern A. Zeeb 3034d9f59799SBjoern A. Zeeb /* Remove chan ctx. */ 3035d1af434dSBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, chanctx_conf); 3036d1af434dSBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(chanctx_conf); 3037c5e25798SBjoern A. Zeeb free(lchanctx, M_LKPI80211); 3038d9f59799SBjoern A. Zeeb } 3039d9f59799SBjoern A. Zeeb 3040d9f59799SBjoern A. Zeeb error = EALREADY; 3041d9f59799SBjoern A. Zeeb out: 30428ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 3043d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 3044d9f59799SBjoern A. Zeeb outni: 3045d9f59799SBjoern A. Zeeb return (error); 3046d9f59799SBjoern A. Zeeb } 3047d9f59799SBjoern A. Zeeb 3048d9f59799SBjoern A. Zeeb static int 3049d9f59799SBjoern A. Zeeb lkpi_sta_run_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 3050d9f59799SBjoern A. Zeeb { 3051d9f59799SBjoern A. Zeeb 3052d9f59799SBjoern A. Zeeb return (lkpi_sta_run_to_init(vap, nstate, arg)); 3053d9f59799SBjoern A. Zeeb } 3054d9f59799SBjoern A. Zeeb 3055d9f59799SBjoern A. Zeeb static int 30566b4cac81SBjoern A. Zeeb lkpi_sta_run_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 30576b4cac81SBjoern A. Zeeb { 30586b4cac81SBjoern A. Zeeb int error; 30596b4cac81SBjoern A. Zeeb 3060d9f59799SBjoern A. Zeeb error = lkpi_sta_run_to_init(vap, nstate, arg); 3061d9f59799SBjoern A. Zeeb if (error != 0 && error != EALREADY) 3062d9f59799SBjoern A. Zeeb return (error); 3063d9f59799SBjoern A. Zeeb 3064d9f59799SBjoern A. Zeeb /* At this point iv_bss is long a new node! */ 3065d9f59799SBjoern A. Zeeb 3066d9f59799SBjoern A. Zeeb error |= lkpi_sta_scan_to_auth(vap, nstate, 0); 30676b4cac81SBjoern A. Zeeb return (error); 30686b4cac81SBjoern A. Zeeb } 30696b4cac81SBjoern A. Zeeb 3070d9f59799SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 30716b4cac81SBjoern A. Zeeb 30726b4cac81SBjoern A. Zeeb /* 30736b4cac81SBjoern A. Zeeb * The matches the documented state changes in net80211::sta_newstate(). 30746b4cac81SBjoern A. Zeeb * XXX (1) without CSA and SLEEP yet, * XXX (2) not all unhandled cases 30756b4cac81SBjoern A. Zeeb * there are "invalid" (so there is a room for failure here). 30766b4cac81SBjoern A. Zeeb */ 30776b4cac81SBjoern A. Zeeb struct fsm_state { 30786b4cac81SBjoern A. Zeeb /* INIT, SCAN, AUTH, ASSOC, CAC, RUN, CSA, SLEEP */ 30796b4cac81SBjoern A. Zeeb enum ieee80211_state ostate; 30806b4cac81SBjoern A. Zeeb enum ieee80211_state nstate; 30816b4cac81SBjoern A. Zeeb int (*handler)(struct ieee80211vap *, enum ieee80211_state, int); 30826b4cac81SBjoern A. Zeeb } sta_state_fsm[] = { 30836b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, 30846b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, /* scan_to_init */ 30856b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_INIT, lkpi_sta_auth_to_init }, /* not explicitly in sta_newstate() */ 3086d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_INIT, lkpi_sta_assoc_to_init }, /* Send DEAUTH. */ 3087d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_INIT, lkpi_sta_run_to_init }, /* Send DISASSOC. */ 30886b4cac81SBjoern A. Zeeb 30896b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_SCAN, lkpi_sta_state_do_nada }, 30906b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_SCAN, lkpi_sta_state_do_nada }, 30916b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_SCAN, lkpi_sta_auth_to_scan }, 30926b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_SCAN, lkpi_sta_assoc_to_scan }, 3093d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_SCAN, lkpi_sta_run_to_scan }, /* Beacon miss. */ 30946b4cac81SBjoern A. Zeeb 3095d9f59799SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, /* Send AUTH. */ 3096d9f59799SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, /* Send AUTH. */ 3097d9f59799SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_AUTH, lkpi_sta_a_to_a }, /* Send ?AUTH. */ 3098d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_AUTH, lkpi_sta_assoc_to_auth }, /* Send ?AUTH. */ 3099d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_AUTH, lkpi_sta_run_to_auth }, /* Send ?AUTH. */ 31006b4cac81SBjoern A. Zeeb 3101d9f59799SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_ASSOC, lkpi_sta_auth_to_assoc }, /* Send ASSOCREQ. */ 3102d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_ASSOC, lkpi_sta_a_to_a }, /* Send ASSOCREQ. */ 3103d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_ASSOC, lkpi_sta_run_to_assoc }, /* Send ASSOCREQ/REASSOCREQ. */ 31046b4cac81SBjoern A. Zeeb 31056b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_RUN, lkpi_sta_auth_to_run }, 31066b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_RUN, lkpi_sta_assoc_to_run }, 31076b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_RUN, lkpi_sta_state_do_nada }, 31086b4cac81SBjoern A. Zeeb 31096b4cac81SBjoern A. Zeeb /* Dummy at the end without handler. */ 31106b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_INIT, NULL }, 31116b4cac81SBjoern A. Zeeb }; 31126b4cac81SBjoern A. Zeeb 31136b4cac81SBjoern A. Zeeb static int 31146b4cac81SBjoern A. Zeeb lkpi_iv_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 31156b4cac81SBjoern A. Zeeb { 31166b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 31176b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 31186b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 31196b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 31206b4cac81SBjoern A. Zeeb struct fsm_state *s; 31216b4cac81SBjoern A. Zeeb enum ieee80211_state ostate; 31226b4cac81SBjoern A. Zeeb int error; 31236b4cac81SBjoern A. Zeeb 31246b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 31256b4cac81SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(ic); 31266b4cac81SBjoern A. Zeeb ostate = vap->iv_state; 31276b4cac81SBjoern A. Zeeb 31289d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 31299d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 31306b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x\n", 31316b4cac81SBjoern A. Zeeb __func__, __LINE__, vap, nstate, arg); 31329d9ba2b7SBjoern A. Zeeb #endif 31336b4cac81SBjoern A. Zeeb 31346b4cac81SBjoern A. Zeeb if (vap->iv_opmode == IEEE80211_M_STA) { 31356b4cac81SBjoern A. Zeeb 31366b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 31376b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 31386b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 31396b4cac81SBjoern A. Zeeb 31406b4cac81SBjoern A. Zeeb /* No need to replicate this in most state handlers. */ 31416b4cac81SBjoern A. Zeeb if (ostate == IEEE80211_S_SCAN && nstate != IEEE80211_S_SCAN) 31426b4cac81SBjoern A. Zeeb lkpi_stop_hw_scan(lhw, vif); 31436b4cac81SBjoern A. Zeeb 31446b4cac81SBjoern A. Zeeb s = sta_state_fsm; 31456b4cac81SBjoern A. Zeeb 31466b4cac81SBjoern A. Zeeb } else { 31476b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: only station mode currently supported: " 31486b4cac81SBjoern A. Zeeb "cap %p iv_opmode %d\n", __func__, vap, vap->iv_opmode); 31496b4cac81SBjoern A. Zeeb return (ENOSYS); 31506b4cac81SBjoern A. Zeeb } 31516b4cac81SBjoern A. Zeeb 31526b4cac81SBjoern A. Zeeb error = 0; 31536b4cac81SBjoern A. Zeeb for (; s->handler != NULL; s++) { 31546b4cac81SBjoern A. Zeeb if (ostate == s->ostate && nstate == s->nstate) { 31559d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 31569d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 3157d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: new state %d (%s) ->" 3158d9f59799SBjoern A. Zeeb " %d (%s): arg %d.\n", __func__, 3159d9f59799SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 3160d9f59799SBjoern A. Zeeb nstate, ieee80211_state_name[nstate], arg); 31619d9ba2b7SBjoern A. Zeeb #endif 31626b4cac81SBjoern A. Zeeb error = s->handler(vap, nstate, arg); 31636b4cac81SBjoern A. Zeeb break; 31646b4cac81SBjoern A. Zeeb } 31656b4cac81SBjoern A. Zeeb } 31666b4cac81SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(vap->iv_ic); 31676b4cac81SBjoern A. Zeeb 31686b4cac81SBjoern A. Zeeb if (s->handler == NULL) { 3169d9f59799SBjoern A. Zeeb IMPROVE("turn this into a KASSERT\n"); 31706b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: unsupported state transition " 31716b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s)\n", __func__, 31726b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 31736b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 31746b4cac81SBjoern A. Zeeb return (ENOSYS); 31756b4cac81SBjoern A. Zeeb } 31766b4cac81SBjoern A. Zeeb 31776b4cac81SBjoern A. Zeeb if (error == EALREADY) { 31789d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 31799d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 3180d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: state transition %d (%s) -> " 3181d9f59799SBjoern A. Zeeb "%d (%s): iv_newstate already handled: %d.\n", 3182d9f59799SBjoern A. Zeeb __func__, ostate, ieee80211_state_name[ostate], 3183d9f59799SBjoern A. Zeeb nstate, ieee80211_state_name[nstate], error); 31849d9ba2b7SBjoern A. Zeeb #endif 31856b4cac81SBjoern A. Zeeb return (0); 31866b4cac81SBjoern A. Zeeb } 31876b4cac81SBjoern A. Zeeb 31886b4cac81SBjoern A. Zeeb if (error != 0) { 31896b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: error %d during state transition " 31906b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s)\n", __func__, error, 31916b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 31926b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 319345c27ad5SBjoern A. Zeeb return (error); 31946b4cac81SBjoern A. Zeeb } 31956b4cac81SBjoern A. Zeeb 31969d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 31979d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 3198d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x " 3199d9f59799SBjoern A. Zeeb "calling net80211 parent\n", 32006b4cac81SBjoern A. Zeeb __func__, __LINE__, vap, nstate, arg); 32019d9ba2b7SBjoern A. Zeeb #endif 32026b4cac81SBjoern A. Zeeb 32036b4cac81SBjoern A. Zeeb return (lvif->iv_newstate(vap, nstate, arg)); 32046b4cac81SBjoern A. Zeeb } 32056b4cac81SBjoern A. Zeeb 32066b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 32076b4cac81SBjoern A. Zeeb 3208d9f59799SBjoern A. Zeeb /* 3209d9f59799SBjoern A. Zeeb * We overload (*iv_update_bss) as otherwise we have cases in, e.g., 3210d9f59799SBjoern A. Zeeb * net80211::ieee80211_sta_join1() where vap->iv_bss gets replaced by a 3211d9f59799SBjoern A. Zeeb * new node without us knowing and thus our ni/lsta are out of sync. 3212d9f59799SBjoern A. Zeeb */ 3213d9f59799SBjoern A. Zeeb static struct ieee80211_node * 3214d9f59799SBjoern A. Zeeb lkpi_iv_update_bss(struct ieee80211vap *vap, struct ieee80211_node *ni) 3215d9f59799SBjoern A. Zeeb { 3216d9f59799SBjoern A. Zeeb struct lkpi_vif *lvif; 32172ac8a218SBjoern A. Zeeb struct ieee80211_node *rni; 3218d9f59799SBjoern A. Zeeb 32192ac8a218SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(vap->iv_ic); 3220d9f59799SBjoern A. Zeeb 3221ed3ef56bSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 32222ac8a218SBjoern A. Zeeb 32232ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 32242ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched = false; 32252ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 32262ac8a218SBjoern A. Zeeb 32272ac8a218SBjoern A. Zeeb rni = lvif->iv_update_bss(vap, ni); 32282ac8a218SBjoern A. Zeeb return (rni); 3229d9f59799SBjoern A. Zeeb } 3230d9f59799SBjoern A. Zeeb 32314a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 32326b4cac81SBjoern A. Zeeb static int 32334a67f1dfSBjoern A. Zeeb lkpi_wme_update(struct lkpi_hw *lhw, struct ieee80211vap *vap, bool planned) 32346b4cac81SBjoern A. Zeeb { 32354a67f1dfSBjoern A. Zeeb struct ieee80211com *ic; 32366b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 32376b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 32386b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 32396b4cac81SBjoern A. Zeeb struct chanAccParams chp; 32406b4cac81SBjoern A. Zeeb struct wmeParams wmeparr[WME_NUM_AC]; 32416b4cac81SBjoern A. Zeeb struct ieee80211_tx_queue_params txqp; 32426b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 32436b4cac81SBjoern A. Zeeb int error; 32446b4cac81SBjoern A. Zeeb uint16_t ac; 32456b4cac81SBjoern A. Zeeb 32466b4cac81SBjoern A. Zeeb IMPROVE(); 32476b4cac81SBjoern A. Zeeb KASSERT(WME_NUM_AC == IEEE80211_NUM_ACS, ("%s: WME_NUM_AC %d != " 32486b4cac81SBjoern A. Zeeb "IEEE80211_NUM_ACS %d\n", __func__, WME_NUM_AC, IEEE80211_NUM_ACS)); 32496b4cac81SBjoern A. Zeeb 32506b4cac81SBjoern A. Zeeb if (vap == NULL) 32516b4cac81SBjoern A. Zeeb return (0); 32526b4cac81SBjoern A. Zeeb 32534a67f1dfSBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WME) == 0) 32544a67f1dfSBjoern A. Zeeb return (0); 32554a67f1dfSBjoern A. Zeeb 32566b4cac81SBjoern A. Zeeb if (lhw->ops->conf_tx == NULL) 32576b4cac81SBjoern A. Zeeb return (0); 32586b4cac81SBjoern A. Zeeb 32594a67f1dfSBjoern A. Zeeb if (!planned && (vap->iv_state != IEEE80211_S_RUN)) { 32604a67f1dfSBjoern A. Zeeb lhw->update_wme = true; 32614a67f1dfSBjoern A. Zeeb return (0); 32624a67f1dfSBjoern A. Zeeb } 32634a67f1dfSBjoern A. Zeeb lhw->update_wme = false; 32646b4cac81SBjoern A. Zeeb 32654a67f1dfSBjoern A. Zeeb ic = lhw->ic; 32666b4cac81SBjoern A. Zeeb ieee80211_wme_ic_getparams(ic, &chp); 32676b4cac81SBjoern A. Zeeb IEEE80211_LOCK(ic); 32686b4cac81SBjoern A. Zeeb for (ac = 0; ac < WME_NUM_AC; ac++) 32696b4cac81SBjoern A. Zeeb wmeparr[ac] = chp.cap_wmeParams[ac]; 32706b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(ic); 32716b4cac81SBjoern A. Zeeb 32724a67f1dfSBjoern A. Zeeb hw = LHW_TO_HW(lhw); 32734a67f1dfSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 32744a67f1dfSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 32754a67f1dfSBjoern A. Zeeb 32766b4cac81SBjoern A. Zeeb /* Configure tx queues (conf_tx) & send BSS_CHANGED_QOS. */ 32776b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 32786b4cac81SBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 32796b4cac81SBjoern A. Zeeb struct wmeParams *wmep; 32806b4cac81SBjoern A. Zeeb 32816b4cac81SBjoern A. Zeeb wmep = &wmeparr[ac]; 32826b4cac81SBjoern A. Zeeb bzero(&txqp, sizeof(txqp)); 32836b4cac81SBjoern A. Zeeb txqp.cw_min = wmep->wmep_logcwmin; 32846b4cac81SBjoern A. Zeeb txqp.cw_max = wmep->wmep_logcwmax; 32856b4cac81SBjoern A. Zeeb txqp.txop = wmep->wmep_txopLimit; 32866b4cac81SBjoern A. Zeeb txqp.aifs = wmep->wmep_aifsn; 328768541546SBjoern A. Zeeb error = lkpi_80211_mo_conf_tx(hw, vif, /* link_id */0, ac, &txqp); 32886b4cac81SBjoern A. Zeeb if (error != 0) 32893f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: conf_tx ac %u failed %d\n", 32906b4cac81SBjoern A. Zeeb __func__, ac, error); 32916b4cac81SBjoern A. Zeeb } 32926b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 32936b4cac81SBjoern A. Zeeb changed = BSS_CHANGED_QOS; 32944a67f1dfSBjoern A. Zeeb if (!planned) 32956b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 32964a67f1dfSBjoern A. Zeeb 32974a67f1dfSBjoern A. Zeeb return (changed); 32984a67f1dfSBjoern A. Zeeb } 32996b4cac81SBjoern A. Zeeb #endif 33006b4cac81SBjoern A. Zeeb 33014a67f1dfSBjoern A. Zeeb static int 33024a67f1dfSBjoern A. Zeeb lkpi_ic_wme_update(struct ieee80211com *ic) 33034a67f1dfSBjoern A. Zeeb { 33044a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 33054a67f1dfSBjoern A. Zeeb struct ieee80211vap *vap; 33064a67f1dfSBjoern A. Zeeb struct lkpi_hw *lhw; 33074a67f1dfSBjoern A. Zeeb 33084a67f1dfSBjoern A. Zeeb IMPROVE("Use the per-VAP callback in net80211."); 33094a67f1dfSBjoern A. Zeeb vap = TAILQ_FIRST(&ic->ic_vaps); 33104a67f1dfSBjoern A. Zeeb if (vap == NULL) 33116b4cac81SBjoern A. Zeeb return (0); 33124a67f1dfSBjoern A. Zeeb 33134a67f1dfSBjoern A. Zeeb lhw = ic->ic_softc; 33144a67f1dfSBjoern A. Zeeb 33154a67f1dfSBjoern A. Zeeb lkpi_wme_update(lhw, vap, false); 33164a67f1dfSBjoern A. Zeeb #endif 33174a67f1dfSBjoern A. Zeeb return (0); /* unused */ 33186b4cac81SBjoern A. Zeeb } 33196b4cac81SBjoern A. Zeeb 33204aff4048SBjoern A. Zeeb /* 33214aff4048SBjoern A. Zeeb * Change link-layer address on the vif (if the vap is not started/"UP"). 33224aff4048SBjoern A. Zeeb * This can happen if a user changes 'ether' using ifconfig. 33234aff4048SBjoern A. Zeeb * The code is based on net80211/ieee80211_freebsd.c::wlan_iflladdr() but 33244aff4048SBjoern A. Zeeb * we do use a per-[l]vif event handler to be sure we exist as we 33254aff4048SBjoern A. Zeeb * cannot assume that from every vap derives a vif and we have a hard 33264aff4048SBjoern A. Zeeb * time checking based on net80211 information. 3327edab5a28SBjoern A. Zeeb * Should this ever become a real problem we could add a callback function 3328edab5a28SBjoern A. Zeeb * to wlan_iflladdr() to be set optionally but that would be for a 3329edab5a28SBjoern A. Zeeb * single-consumer (or needs a list) -- was just too complicated for an 3330edab5a28SBjoern A. Zeeb * otherwise perfect mechanism FreeBSD already provides. 33314aff4048SBjoern A. Zeeb */ 33324aff4048SBjoern A. Zeeb static void 33334aff4048SBjoern A. Zeeb lkpi_vif_iflladdr(void *arg, struct ifnet *ifp) 33344aff4048SBjoern A. Zeeb { 33354aff4048SBjoern A. Zeeb struct epoch_tracker et; 33364aff4048SBjoern A. Zeeb struct ieee80211_vif *vif; 33374aff4048SBjoern A. Zeeb 33384aff4048SBjoern A. Zeeb NET_EPOCH_ENTER(et); 3339edab5a28SBjoern A. Zeeb /* NB: identify vap's by if_transmit; left as an extra check. */ 3340edab5a28SBjoern A. Zeeb if (if_gettransmitfn(ifp) != ieee80211_vap_transmit || 3341edab5a28SBjoern A. Zeeb (if_getflags(ifp) & IFF_UP) != 0) { 33424aff4048SBjoern A. Zeeb NET_EPOCH_EXIT(et); 33434aff4048SBjoern A. Zeeb return; 33444aff4048SBjoern A. Zeeb } 33454aff4048SBjoern A. Zeeb 33464aff4048SBjoern A. Zeeb vif = arg; 334757609cb2SJustin Hibbits IEEE80211_ADDR_COPY(vif->bss_conf.addr, if_getlladdr(ifp)); 33484aff4048SBjoern A. Zeeb NET_EPOCH_EXIT(et); 33494aff4048SBjoern A. Zeeb } 33504aff4048SBjoern A. Zeeb 33516b4cac81SBjoern A. Zeeb static struct ieee80211vap * 33526b4cac81SBjoern A. Zeeb lkpi_ic_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], 33536b4cac81SBjoern A. Zeeb int unit, enum ieee80211_opmode opmode, int flags, 33546b4cac81SBjoern A. Zeeb const uint8_t bssid[IEEE80211_ADDR_LEN], 33556b4cac81SBjoern A. Zeeb const uint8_t mac[IEEE80211_ADDR_LEN]) 33566b4cac81SBjoern A. Zeeb { 33576b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 33586b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 33596b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 33606b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 33616b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 3362a6042e17SBjoern A. Zeeb struct ieee80211_tx_queue_params txqp; 33636b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 336440839418SBjoern A. Zeeb struct sysctl_oid *node; 33656b4cac81SBjoern A. Zeeb size_t len; 3366e3a0b120SBjoern A. Zeeb int error, i; 3367a6042e17SBjoern A. Zeeb uint16_t ac; 33686b4cac81SBjoern A. Zeeb 33696b4cac81SBjoern A. Zeeb if (!TAILQ_EMPTY(&ic->ic_vaps)) /* 1 so far. Add <n> once this works. */ 33706b4cac81SBjoern A. Zeeb return (NULL); 33716b4cac81SBjoern A. Zeeb 33726b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 33736b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 33746b4cac81SBjoern A. Zeeb 33756b4cac81SBjoern A. Zeeb len = sizeof(*lvif); 33766b4cac81SBjoern A. Zeeb len += hw->vif_data_size; /* vif->drv_priv */ 33776b4cac81SBjoern A. Zeeb 33786b4cac81SBjoern A. Zeeb lvif = malloc(len, M_80211_VAP, M_WAITOK | M_ZERO); 33796b4cac81SBjoern A. Zeeb mtx_init(&lvif->mtx, "lvif", NULL, MTX_DEF); 3380a8f735a6SBjoern A. Zeeb INIT_LIST_HEAD(&lvif->lsta_list); 33812ac8a218SBjoern A. Zeeb lvif->lvif_bss = NULL; 33822ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched = false; 33836b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 33846b4cac81SBjoern A. Zeeb 33856b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 33866b4cac81SBjoern A. Zeeb memcpy(vif->addr, mac, IEEE80211_ADDR_LEN); 33876b4cac81SBjoern A. Zeeb vif->p2p = false; 33886b4cac81SBjoern A. Zeeb vif->probe_req_reg = false; 33896b4cac81SBjoern A. Zeeb vif->type = lkpi_opmode_to_vif_type(opmode); 33906b4cac81SBjoern A. Zeeb lvif->wdev.iftype = vif->type; 33916b4cac81SBjoern A. Zeeb /* Need to fill in other fields as well. */ 33926b4cac81SBjoern A. Zeeb IMPROVE(); 33936b4cac81SBjoern A. Zeeb 33946b4cac81SBjoern A. Zeeb /* XXX-BZ hardcoded for now! */ 33956b4cac81SBjoern A. Zeeb #if 1 33966b4cac81SBjoern A. Zeeb vif->chanctx_conf = NULL; 3397adff403fSBjoern A. Zeeb vif->bss_conf.vif = vif; 33986ffb7bd4SBjoern A. Zeeb /* vap->iv_myaddr is not set until net80211::vap_setup or vap_attach. */ 33996ffb7bd4SBjoern A. Zeeb IEEE80211_ADDR_COPY(vif->bss_conf.addr, mac); 34004aff4048SBjoern A. Zeeb lvif->lvif_ifllevent = EVENTHANDLER_REGISTER(iflladdr_event, 34014aff4048SBjoern A. Zeeb lkpi_vif_iflladdr, vif, EVENTHANDLER_PRI_ANY); 34026ffb7bd4SBjoern A. Zeeb vif->bss_conf.link_id = 0; /* Non-MLO operation. */ 34037b43f4d0SBjoern A. Zeeb vif->bss_conf.chanreq.oper.width = NL80211_CHAN_WIDTH_20_NOHT; 34046b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble = false; /* vap->iv_flags IEEE80211_F_SHPREAMBLE */ 34056b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot = false; /* vap->iv_flags IEEE80211_F_SHSLOT */ 34066b4cac81SBjoern A. Zeeb vif->bss_conf.qos = false; 34076b4cac81SBjoern A. Zeeb vif->bss_conf.use_cts_prot = false; /* vap->iv_protmode */ 34086b4cac81SBjoern A. Zeeb vif->bss_conf.ht_operation_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONE; 3409616e1330SBjoern A. Zeeb vif->cfg.aid = 0; 3410616e1330SBjoern A. Zeeb vif->cfg.assoc = false; 3411616e1330SBjoern A. Zeeb vif->cfg.idle = true; 3412616e1330SBjoern A. Zeeb vif->cfg.ps = false; 34136ffb7bd4SBjoern A. Zeeb IMPROVE("Check other fields and then figure out whats is left elsewhere of them"); 3414caaa79c3SBjoern A. Zeeb /* 3415caaa79c3SBjoern A. Zeeb * We need to initialize it to something as the bss_info_changed call 3416caaa79c3SBjoern A. Zeeb * will try to copy from it in iwlwifi and NULL is a panic. 3417caaa79c3SBjoern A. Zeeb * We will set the proper one in scan_to_auth() before being assoc. 3418caaa79c3SBjoern A. Zeeb */ 34196ffb7bd4SBjoern A. Zeeb vif->bss_conf.bssid = ieee80211broadcastaddr; 34206b4cac81SBjoern A. Zeeb #endif 34216b4cac81SBjoern A. Zeeb #if 0 34226b4cac81SBjoern A. Zeeb vif->bss_conf.dtim_period = 0; /* IEEE80211_DTIM_DEFAULT ; must stay 0. */ 34236b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(vif->bss_conf.bssid, bssid); 34246b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = ic->ic_bintval; 34256b4cac81SBjoern A. Zeeb /* iwlwifi bug. */ 34266b4cac81SBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16) 34276b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = 16; 34286b4cac81SBjoern A. Zeeb #endif 3429e3a0b120SBjoern A. Zeeb 34306ffb7bd4SBjoern A. Zeeb /* Link Config */ 34316ffb7bd4SBjoern A. Zeeb vif->link_conf[0] = &vif->bss_conf; 34326ffb7bd4SBjoern A. Zeeb for (i = 0; i < nitems(vif->link_conf); i++) { 34336ffb7bd4SBjoern A. Zeeb IMPROVE("more than 1 link one day"); 34346ffb7bd4SBjoern A. Zeeb } 34356ffb7bd4SBjoern A. Zeeb 3436e3a0b120SBjoern A. Zeeb /* Setup queue defaults; driver may override in (*add_interface). */ 3437e3a0b120SBjoern A. Zeeb for (i = 0; i < IEEE80211_NUM_ACS; i++) { 3438e3a0b120SBjoern A. Zeeb if (ieee80211_hw_check(hw, QUEUE_CONTROL)) 3439e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = IEEE80211_INVAL_HW_QUEUE; 3440e3a0b120SBjoern A. Zeeb else if (hw->queues >= IEEE80211_NUM_ACS) 3441e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = i; 3442e3a0b120SBjoern A. Zeeb else 3443e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = 0; 34440cbcfa19SBjoern A. Zeeb 34450cbcfa19SBjoern A. Zeeb /* Initialize the queue to running. Stopped? */ 34460cbcfa19SBjoern A. Zeeb lvif->hw_queue_stopped[i] = false; 3447e3a0b120SBjoern A. Zeeb } 3448e3a0b120SBjoern A. Zeeb vif->cab_queue = IEEE80211_INVAL_HW_QUEUE; 3449e3a0b120SBjoern A. Zeeb 34506b4cac81SBjoern A. Zeeb IMPROVE(); 34516b4cac81SBjoern A. Zeeb 34526b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_start(hw); 34536b4cac81SBjoern A. Zeeb if (error != 0) { 34543f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: failed to start hw: %d\n", __func__, error); 34556b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 34566b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 34576b4cac81SBjoern A. Zeeb return (NULL); 34586b4cac81SBjoern A. Zeeb } 34596b4cac81SBjoern A. Zeeb 34606b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_add_interface(hw, vif); 34616b4cac81SBjoern A. Zeeb if (error != 0) { 34626b4cac81SBjoern A. Zeeb IMPROVE(); /* XXX-BZ mo_stop()? */ 34633f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: failed to add interface: %d\n", __func__, error); 34646b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 34656b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 34666b4cac81SBjoern A. Zeeb return (NULL); 34676b4cac81SBjoern A. Zeeb } 34686b4cac81SBjoern A. Zeeb 34698891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 34706b4cac81SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lhw->lvif_head, lvif, lvif_entry); 34718891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 34726b4cac81SBjoern A. Zeeb 34736b4cac81SBjoern A. Zeeb /* Set bss_info. */ 34746b4cac81SBjoern A. Zeeb changed = 0; 34756b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 34766b4cac81SBjoern A. Zeeb 3477a6042e17SBjoern A. Zeeb /* Configure tx queues (conf_tx), default WME & send BSS_CHANGED_QOS. */ 3478a6042e17SBjoern A. Zeeb IMPROVE("Hardcoded values; to fix see 802.11-2016, 9.4.2.29 EDCA Parameter Set element"); 3479a6042e17SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 3480a6042e17SBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 3481a6042e17SBjoern A. Zeeb 3482a6042e17SBjoern A. Zeeb bzero(&txqp, sizeof(txqp)); 3483a6042e17SBjoern A. Zeeb txqp.cw_min = 15; 3484a6042e17SBjoern A. Zeeb txqp.cw_max = 1023; 3485a6042e17SBjoern A. Zeeb txqp.txop = 0; 3486a6042e17SBjoern A. Zeeb txqp.aifs = 2; 3487a6042e17SBjoern A. Zeeb error = lkpi_80211_mo_conf_tx(hw, vif, /* link_id */0, ac, &txqp); 3488a6042e17SBjoern A. Zeeb if (error != 0) 3489a6042e17SBjoern A. Zeeb ic_printf(ic, "%s: conf_tx ac %u failed %d\n", 3490a6042e17SBjoern A. Zeeb __func__, ac, error); 3491a6042e17SBjoern A. Zeeb } 3492a6042e17SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 3493a6042e17SBjoern A. Zeeb changed = BSS_CHANGED_QOS; 3494a6042e17SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 34956b4cac81SBjoern A. Zeeb 34966b4cac81SBjoern A. Zeeb /* Force MC init. */ 34976b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(ic, true); 34986b4cac81SBjoern A. Zeeb 34996b4cac81SBjoern A. Zeeb IMPROVE(); 35006b4cac81SBjoern A. Zeeb 35016b4cac81SBjoern A. Zeeb ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid); 35026b4cac81SBjoern A. Zeeb 35036b4cac81SBjoern A. Zeeb /* Override with LinuxKPI method so we can drive mac80211/cfg80211. */ 35046b4cac81SBjoern A. Zeeb lvif->iv_newstate = vap->iv_newstate; 35056b4cac81SBjoern A. Zeeb vap->iv_newstate = lkpi_iv_newstate; 3506d9f59799SBjoern A. Zeeb lvif->iv_update_bss = vap->iv_update_bss; 3507d9f59799SBjoern A. Zeeb vap->iv_update_bss = lkpi_iv_update_bss; 35086b4cac81SBjoern A. Zeeb 3509b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 351011db70b6SBjoern A. Zeeb /* Key management. */ 351111db70b6SBjoern A. Zeeb if (lkpi_hwcrypto && lhw->ops->set_key != NULL) { 35126b4cac81SBjoern A. Zeeb vap->iv_key_set = lkpi_iv_key_set; 35136b4cac81SBjoern A. Zeeb vap->iv_key_delete = lkpi_iv_key_delete; 35146b4cac81SBjoern A. Zeeb } 351511db70b6SBjoern A. Zeeb #endif 35166b4cac81SBjoern A. Zeeb 35179fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 35189fb91463SBjoern A. Zeeb /* Stay with the iv_ampdu_rxmax,limit / iv_ampdu_density defaults until later. */ 35199fb91463SBjoern A. Zeeb #endif 35209fb91463SBjoern A. Zeeb 35216b4cac81SBjoern A. Zeeb ieee80211_ratectl_init(vap); 35226b4cac81SBjoern A. Zeeb 35236b4cac81SBjoern A. Zeeb /* Complete setup. */ 35246b4cac81SBjoern A. Zeeb ieee80211_vap_attach(vap, ieee80211_media_change, 35256b4cac81SBjoern A. Zeeb ieee80211_media_status, mac); 35266b4cac81SBjoern A. Zeeb 352711db70b6SBjoern A. Zeeb #ifdef LKPI_80211_HT 352811db70b6SBjoern A. Zeeb /* 352911db70b6SBjoern A. Zeeb * Modern chipset/fw/drv will do A-MPDU in drv/fw and fail 353011db70b6SBjoern A. Zeeb * to do so if they cannot do the crypto too. 353111db70b6SBjoern A. Zeeb */ 353211db70b6SBjoern A. Zeeb if (!lkpi_hwcrypto && ieee80211_hw_check(hw, AMPDU_AGGREGATION)) 353311db70b6SBjoern A. Zeeb vap->iv_flags_ht &= ~IEEE80211_FHT_AMPDU_RX; 353411db70b6SBjoern A. Zeeb #endif 353511db70b6SBjoern A. Zeeb 35366b4cac81SBjoern A. Zeeb if (hw->max_listen_interval == 0) 35376b4cac81SBjoern A. Zeeb hw->max_listen_interval = 7 * (ic->ic_lintval / ic->ic_bintval); 35386b4cac81SBjoern A. Zeeb hw->conf.listen_interval = hw->max_listen_interval; 35396b4cac81SBjoern A. Zeeb ic->ic_set_channel(ic); 35406b4cac81SBjoern A. Zeeb 35416b4cac81SBjoern A. Zeeb /* XXX-BZ do we need to be able to update these? */ 35426b4cac81SBjoern A. Zeeb hw->wiphy->frag_threshold = vap->iv_fragthreshold; 35436b4cac81SBjoern A. Zeeb lkpi_80211_mo_set_frag_threshold(hw, vap->iv_fragthreshold); 35446b4cac81SBjoern A. Zeeb hw->wiphy->rts_threshold = vap->iv_rtsthreshold; 35456b4cac81SBjoern A. Zeeb lkpi_80211_mo_set_rts_threshold(hw, vap->iv_rtsthreshold); 35466b4cac81SBjoern A. Zeeb /* any others? */ 354740839418SBjoern A. Zeeb 354840839418SBjoern A. Zeeb /* Add per-VIF/VAP sysctls. */ 354940839418SBjoern A. Zeeb sysctl_ctx_init(&lvif->sysctl_ctx); 355040839418SBjoern A. Zeeb 355140839418SBjoern A. Zeeb node = SYSCTL_ADD_NODE(&lvif->sysctl_ctx, 355240839418SBjoern A. Zeeb SYSCTL_CHILDREN(&sysctl___compat_linuxkpi_80211), 355340839418SBjoern A. Zeeb OID_AUTO, if_name(vap->iv_ifp), 355440839418SBjoern A. Zeeb CTLFLAG_RD | CTLFLAG_SKIP | CTLFLAG_MPSAFE, NULL, "VIF Information"); 355540839418SBjoern A. Zeeb 355640839418SBjoern A. Zeeb SYSCTL_ADD_PROC(&lvif->sysctl_ctx, 355740839418SBjoern A. Zeeb SYSCTL_CHILDREN(node), OID_AUTO, "dump_stas", 355840839418SBjoern A. Zeeb CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, lvif, 0, 355940839418SBjoern A. Zeeb lkpi_80211_dump_stas, "A", "Dump sta statistics of this vif"); 356040839418SBjoern A. Zeeb 35616b4cac81SBjoern A. Zeeb IMPROVE(); 35626b4cac81SBjoern A. Zeeb 35636b4cac81SBjoern A. Zeeb return (vap); 35646b4cac81SBjoern A. Zeeb } 35656b4cac81SBjoern A. Zeeb 35664b0af114SBjoern A. Zeeb void 35674b0af114SBjoern A. Zeeb linuxkpi_ieee80211_unregister_hw(struct ieee80211_hw *hw) 35684b0af114SBjoern A. Zeeb { 35694b0af114SBjoern A. Zeeb 35704b0af114SBjoern A. Zeeb wiphy_unregister(hw->wiphy); 35714b0af114SBjoern A. Zeeb linuxkpi_ieee80211_ifdetach(hw); 35724b0af114SBjoern A. Zeeb 35734b0af114SBjoern A. Zeeb IMPROVE(); 35744b0af114SBjoern A. Zeeb } 35754b0af114SBjoern A. Zeeb 35764b0af114SBjoern A. Zeeb void 35774b0af114SBjoern A. Zeeb linuxkpi_ieee80211_restart_hw(struct ieee80211_hw *hw) 35784b0af114SBjoern A. Zeeb { 35794b0af114SBjoern A. Zeeb 35804b0af114SBjoern A. Zeeb TODO(); 35814b0af114SBjoern A. Zeeb } 35824b0af114SBjoern A. Zeeb 35836b4cac81SBjoern A. Zeeb static void 35846b4cac81SBjoern A. Zeeb lkpi_ic_vap_delete(struct ieee80211vap *vap) 35856b4cac81SBjoern A. Zeeb { 35866b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 35876b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 35886b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 35896b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 35906b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 35916b4cac81SBjoern A. Zeeb 35926b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 35936b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 35946b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 35956b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 35966b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 35976b4cac81SBjoern A. Zeeb 35984aff4048SBjoern A. Zeeb EVENTHANDLER_DEREGISTER(iflladdr_event, lvif->lvif_ifllevent); 35994aff4048SBjoern A. Zeeb 360040839418SBjoern A. Zeeb /* Clear up per-VIF/VAP sysctls. */ 360140839418SBjoern A. Zeeb sysctl_ctx_free(&lvif->sysctl_ctx); 360240839418SBjoern A. Zeeb 36038891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 36046b4cac81SBjoern A. Zeeb TAILQ_REMOVE(&lhw->lvif_head, lvif, lvif_entry); 36058891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 36066b4cac81SBjoern A. Zeeb 36076b4cac81SBjoern A. Zeeb ieee80211_ratectl_deinit(vap); 36086b4cac81SBjoern A. Zeeb ieee80211_vap_detach(vap); 3609dbf76919SBjoern A. Zeeb 3610dbf76919SBjoern A. Zeeb IMPROVE("clear up other bits in this state"); 3611dbf76919SBjoern A. Zeeb 3612dbf76919SBjoern A. Zeeb lkpi_80211_mo_remove_interface(hw, vif); 3613dbf76919SBjoern A. Zeeb 36146c38c6b1SBjoern A. Zeeb /* Single VAP, so we can do this here. */ 36157b43f4d0SBjoern A. Zeeb lkpi_80211_mo_stop(hw, false); /* XXX SUSPEND */ 36166c38c6b1SBjoern A. Zeeb 36176b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 36186b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 36196b4cac81SBjoern A. Zeeb } 36206b4cac81SBjoern A. Zeeb 36216b4cac81SBjoern A. Zeeb static void 36226b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast(struct ieee80211com *ic) 36236b4cac81SBjoern A. Zeeb { 36246b4cac81SBjoern A. Zeeb 36256b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(ic, false); 36266b4cac81SBjoern A. Zeeb TRACEOK(); 36276b4cac81SBjoern A. Zeeb } 36286b4cac81SBjoern A. Zeeb 36296b4cac81SBjoern A. Zeeb static void 36306b4cac81SBjoern A. Zeeb lkpi_ic_update_promisc(struct ieee80211com *ic) 36316b4cac81SBjoern A. Zeeb { 36326b4cac81SBjoern A. Zeeb 36336b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 36346b4cac81SBjoern A. Zeeb } 36356b4cac81SBjoern A. Zeeb 36366b4cac81SBjoern A. Zeeb static void 36376b4cac81SBjoern A. Zeeb lkpi_ic_update_chw(struct ieee80211com *ic) 36386b4cac81SBjoern A. Zeeb { 36396b4cac81SBjoern A. Zeeb 36406b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 36416b4cac81SBjoern A. Zeeb } 36426b4cac81SBjoern A. Zeeb 36436b4cac81SBjoern A. Zeeb /* Start / stop device. */ 36446b4cac81SBjoern A. Zeeb static void 36456b4cac81SBjoern A. Zeeb lkpi_ic_parent(struct ieee80211com *ic) 36466b4cac81SBjoern A. Zeeb { 36476b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 36488d58a057SBjoern A. Zeeb #ifdef HW_START_STOP 36496b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 36506b4cac81SBjoern A. Zeeb int error; 36518d58a057SBjoern A. Zeeb #endif 36526b4cac81SBjoern A. Zeeb bool start_all; 36536b4cac81SBjoern A. Zeeb 36546b4cac81SBjoern A. Zeeb IMPROVE(); 36556b4cac81SBjoern A. Zeeb 36566b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 36578d58a057SBjoern A. Zeeb #ifdef HW_START_STOP 36586b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 36598d58a057SBjoern A. Zeeb #endif 36606b4cac81SBjoern A. Zeeb start_all = false; 36616b4cac81SBjoern A. Zeeb 36628ac540d3SBjoern A. Zeeb /* IEEE80211_UNLOCK(ic); */ 36638ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 36646b4cac81SBjoern A. Zeeb if (ic->ic_nrunning > 0) { 36658d58a057SBjoern A. Zeeb #ifdef HW_START_STOP 36666b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_start(hw); 36676b4cac81SBjoern A. Zeeb if (error == 0) 36688d58a057SBjoern A. Zeeb #endif 36696b4cac81SBjoern A. Zeeb start_all = true; 36706b4cac81SBjoern A. Zeeb } else { 36718d58a057SBjoern A. Zeeb #ifdef HW_START_STOP 36727b43f4d0SBjoern A. Zeeb lkpi_80211_mo_stop(hw, false); /* XXX SUSPEND */ 36738d58a057SBjoern A. Zeeb #endif 36746b4cac81SBjoern A. Zeeb } 36758ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 36768ac540d3SBjoern A. Zeeb /* IEEE80211_LOCK(ic); */ 36776b4cac81SBjoern A. Zeeb 36786b4cac81SBjoern A. Zeeb if (start_all) 36796b4cac81SBjoern A. Zeeb ieee80211_start_all(ic); 36806b4cac81SBjoern A. Zeeb } 36816b4cac81SBjoern A. Zeeb 36826b4cac81SBjoern A. Zeeb bool 36836b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_is_ie_id_in_ie_buf(const u8 ie, const u8 *ie_ids, 36846b4cac81SBjoern A. Zeeb size_t ie_ids_len) 36856b4cac81SBjoern A. Zeeb { 36866b4cac81SBjoern A. Zeeb int i; 36876b4cac81SBjoern A. Zeeb 36886b4cac81SBjoern A. Zeeb for (i = 0; i < ie_ids_len; i++) { 36896b4cac81SBjoern A. Zeeb if (ie == *ie_ids) 36906b4cac81SBjoern A. Zeeb return (true); 36916b4cac81SBjoern A. Zeeb } 36926b4cac81SBjoern A. Zeeb 36936b4cac81SBjoern A. Zeeb return (false); 36946b4cac81SBjoern A. Zeeb } 36956b4cac81SBjoern A. Zeeb 36966b4cac81SBjoern A. Zeeb /* Return true if skipped; false if error. */ 36976b4cac81SBjoern A. Zeeb bool 36986b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ie_advance(size_t *xp, const u8 *ies, size_t ies_len) 36996b4cac81SBjoern A. Zeeb { 37006b4cac81SBjoern A. Zeeb size_t x; 37016b4cac81SBjoern A. Zeeb uint8_t l; 37026b4cac81SBjoern A. Zeeb 37036b4cac81SBjoern A. Zeeb x = *xp; 37046b4cac81SBjoern A. Zeeb 37056b4cac81SBjoern A. Zeeb KASSERT(x < ies_len, ("%s: x %zu ies_len %zu ies %p\n", 37066b4cac81SBjoern A. Zeeb __func__, x, ies_len, ies)); 37076b4cac81SBjoern A. Zeeb l = ies[x + 1]; 37086b4cac81SBjoern A. Zeeb x += 2 + l; 37096b4cac81SBjoern A. Zeeb 37106b4cac81SBjoern A. Zeeb if (x > ies_len) 37116b4cac81SBjoern A. Zeeb return (false); 37126b4cac81SBjoern A. Zeeb 37136b4cac81SBjoern A. Zeeb *xp = x; 37146b4cac81SBjoern A. Zeeb return (true); 37156b4cac81SBjoern A. Zeeb } 37166b4cac81SBjoern A. Zeeb 3717d9945d78SBjoern A. Zeeb static uint8_t * 3718d9945d78SBjoern A. Zeeb lkpi_scan_ies_add(uint8_t *p, struct ieee80211_scan_ies *scan_ies, 3719d9945d78SBjoern A. Zeeb uint32_t band_mask, struct ieee80211vap *vap, struct ieee80211_hw *hw) 37206b4cac81SBjoern A. Zeeb { 3721d9945d78SBjoern A. Zeeb struct ieee80211_supported_band *supband; 3722d9945d78SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 37233dd98026SBjoern A. Zeeb struct ieee80211com *ic; 3724d9945d78SBjoern A. Zeeb const struct ieee80211_channel *chan; 3725d9945d78SBjoern A. Zeeb const struct ieee80211_rateset *rs; 3726d9945d78SBjoern A. Zeeb uint8_t *pb; 3727d9945d78SBjoern A. Zeeb int band, i; 37286b4cac81SBjoern A. Zeeb 37293dd98026SBjoern A. Zeeb ic = vap->iv_ic; 3730d9945d78SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 3731d9945d78SBjoern A. Zeeb if ((band_mask & (1 << band)) == 0) 3732d9945d78SBjoern A. Zeeb continue; 3733d9945d78SBjoern A. Zeeb 3734d9945d78SBjoern A. Zeeb supband = hw->wiphy->bands[band]; 3735d9945d78SBjoern A. Zeeb /* 3736d9945d78SBjoern A. Zeeb * This should not happen; 3737d9945d78SBjoern A. Zeeb * band_mask is a bitmask of valid bands to scan on. 3738d9945d78SBjoern A. Zeeb */ 3739d9945d78SBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 3740d9945d78SBjoern A. Zeeb continue; 3741d9945d78SBjoern A. Zeeb 3742d9945d78SBjoern A. Zeeb /* Find a first channel to get the mode and rates from. */ 3743d9945d78SBjoern A. Zeeb channels = supband->channels; 3744d9945d78SBjoern A. Zeeb chan = NULL; 3745d9945d78SBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 3746d9945d78SBjoern A. Zeeb 3747d9945d78SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) 3748d9945d78SBjoern A. Zeeb continue; 3749d9945d78SBjoern A. Zeeb 37503dd98026SBjoern A. Zeeb chan = ieee80211_find_channel(ic, 3751d9945d78SBjoern A. Zeeb channels[i].center_freq, 0); 3752d9945d78SBjoern A. Zeeb if (chan != NULL) 3753d9945d78SBjoern A. Zeeb break; 3754d9945d78SBjoern A. Zeeb } 3755d9945d78SBjoern A. Zeeb 3756d9945d78SBjoern A. Zeeb /* This really should not happen. */ 3757d9945d78SBjoern A. Zeeb if (chan == NULL) 3758d9945d78SBjoern A. Zeeb continue; 3759d9945d78SBjoern A. Zeeb 3760d9945d78SBjoern A. Zeeb pb = p; 37613dd98026SBjoern A. Zeeb rs = ieee80211_get_suprates(ic, chan); /* calls chan2mode */ 3762d9945d78SBjoern A. Zeeb p = ieee80211_add_rates(p, rs); 3763d9945d78SBjoern A. Zeeb p = ieee80211_add_xrates(p, rs); 3764d9945d78SBjoern A. Zeeb 37653dd98026SBjoern A. Zeeb #if defined(LKPI_80211_HT) 37663dd98026SBjoern A. Zeeb if ((vap->iv_flags_ht & IEEE80211_FHT_HT) != 0) { 37673dd98026SBjoern A. Zeeb struct ieee80211_channel *c; 37683dd98026SBjoern A. Zeeb 37693dd98026SBjoern A. Zeeb c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan, 37703dd98026SBjoern A. Zeeb vap->iv_flags_ht); 37713dd98026SBjoern A. Zeeb p = ieee80211_add_htcap_ch(p, vap, c); 37723dd98026SBjoern A. Zeeb } 37733dd98026SBjoern A. Zeeb #endif 37743dd98026SBjoern A. Zeeb #if defined(LKPI_80211_VHT) 37753dd98026SBjoern A. Zeeb if ((vap->iv_vht_flags & IEEE80211_FVHT_VHT) != 0) { 37763dd98026SBjoern A. Zeeb struct ieee80211_channel *c; 37773dd98026SBjoern A. Zeeb 37783dd98026SBjoern A. Zeeb c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan, 37793dd98026SBjoern A. Zeeb vap->iv_flags_ht); 37803dd98026SBjoern A. Zeeb c = ieee80211_vht_adjust_channel(ic, c, 37813dd98026SBjoern A. Zeeb vap->iv_vht_flags); 37823dd98026SBjoern A. Zeeb p = ieee80211_add_vhtcap_ch(p, vap, c); 37833dd98026SBjoern A. Zeeb } 37843dd98026SBjoern A. Zeeb #endif 37853dd98026SBjoern A. Zeeb 3786d9945d78SBjoern A. Zeeb scan_ies->ies[band] = pb; 3787d9945d78SBjoern A. Zeeb scan_ies->len[band] = p - pb; 3788d9945d78SBjoern A. Zeeb } 3789d9945d78SBjoern A. Zeeb 3790d9945d78SBjoern A. Zeeb /* Add common_ies */ 3791d9945d78SBjoern A. Zeeb pb = p; 3792d9945d78SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WPA1) != 0 && 3793d9945d78SBjoern A. Zeeb vap->iv_wpa_ie != NULL) { 3794d9945d78SBjoern A. Zeeb memcpy(p, vap->iv_wpa_ie, 2 + vap->iv_wpa_ie[1]); 3795d9945d78SBjoern A. Zeeb p += 2 + vap->iv_wpa_ie[1]; 3796d9945d78SBjoern A. Zeeb } 3797d9945d78SBjoern A. Zeeb if (vap->iv_appie_probereq != NULL) { 3798d9945d78SBjoern A. Zeeb memcpy(p, vap->iv_appie_probereq->ie_data, 3799d9945d78SBjoern A. Zeeb vap->iv_appie_probereq->ie_len); 3800d9945d78SBjoern A. Zeeb p += vap->iv_appie_probereq->ie_len; 3801d9945d78SBjoern A. Zeeb } 3802d9945d78SBjoern A. Zeeb scan_ies->common_ies = pb; 3803d9945d78SBjoern A. Zeeb scan_ies->common_ie_len = p - pb; 3804d9945d78SBjoern A. Zeeb 3805d9945d78SBjoern A. Zeeb return (p); 38066b4cac81SBjoern A. Zeeb } 38076b4cac81SBjoern A. Zeeb 38086b4cac81SBjoern A. Zeeb static void 38096b4cac81SBjoern A. Zeeb lkpi_ic_scan_start(struct ieee80211com *ic) 38106b4cac81SBjoern A. Zeeb { 38116b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 38126b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 38136b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 38146b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 38156b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 38166b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 38176b4cac81SBjoern A. Zeeb int error; 38188ac540d3SBjoern A. Zeeb bool is_hw_scan; 38196b4cac81SBjoern A. Zeeb 38206b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 38218ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 3822a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) { 38236b4cac81SBjoern A. Zeeb /* A scan is still running. */ 38248ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 38256b4cac81SBjoern A. Zeeb return; 38266b4cac81SBjoern A. Zeeb } 38278ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 38288ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 38296b4cac81SBjoern A. Zeeb 38306b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 38316b4cac81SBjoern A. Zeeb vap = ss->ss_vap; 38326b4cac81SBjoern A. Zeeb if (vap->iv_state != IEEE80211_S_SCAN) { 3833d3ef7fb4SBjoern A. Zeeb IMPROVE("We need to be able to scan if not in S_SCAN"); 38346b4cac81SBjoern A. Zeeb return; 38356b4cac81SBjoern A. Zeeb } 38366b4cac81SBjoern A. Zeeb 38376b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 38388ac540d3SBjoern A. Zeeb if (!is_hw_scan) { 3839a486fbbdSBjoern A. Zeeb /* If hw_scan is cleared clear FEXT_SCAN_OFFLOAD too. */ 3840a486fbbdSBjoern A. Zeeb vap->iv_flags_ext &= ~IEEE80211_FEXT_SCAN_OFFLOAD; 3841d3ef7fb4SBjoern A. Zeeb sw_scan: 38426b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 38436b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 3844086be6a8SBjoern A. Zeeb 3845086be6a8SBjoern A. Zeeb if (vap->iv_state == IEEE80211_S_SCAN) 3846086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, false); 3847086be6a8SBjoern A. Zeeb 38486b4cac81SBjoern A. Zeeb lkpi_80211_mo_sw_scan_start(hw, vif, vif->addr); 38496b4cac81SBjoern A. Zeeb /* net80211::scan_start() handled PS for us. */ 38506b4cac81SBjoern A. Zeeb IMPROVE(); 38516b4cac81SBjoern A. Zeeb /* XXX Also means it is too late to flush queues? 38526b4cac81SBjoern A. Zeeb * need to check iv_sta_ps or overload? */ 38536b4cac81SBjoern A. Zeeb /* XXX want to adjust ss end time/ maxdwell? */ 38546b4cac81SBjoern A. Zeeb 38556b4cac81SBjoern A. Zeeb } else { 38566b4cac81SBjoern A. Zeeb struct ieee80211_scan_request *hw_req; 38576b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *lc, **cpp; 38586b4cac81SBjoern A. Zeeb struct cfg80211_ssid *ssids; 38596b4cac81SBjoern A. Zeeb struct cfg80211_scan_6ghz_params *s6gp; 38606b4cac81SBjoern A. Zeeb size_t chan_len, nchan, ssids_len, s6ghzlen; 3861d9945d78SBjoern A. Zeeb int band, i, ssid_count, common_ie_len; 3862d9945d78SBjoern A. Zeeb uint32_t band_mask; 3863d9945d78SBjoern A. Zeeb uint8_t *ie, *ieend; 38643206587aSBjoern A. Zeeb bool running; 3865d9945d78SBjoern A. Zeeb 3866d9945d78SBjoern A. Zeeb ssid_count = min(ss->ss_nssid, hw->wiphy->max_scan_ssids); 3867d9945d78SBjoern A. Zeeb ssids_len = ssid_count * sizeof(*ssids); 38686b4cac81SBjoern A. Zeeb s6ghzlen = 0 * (sizeof(*s6gp)); /* XXX-BZ */ 38696b4cac81SBjoern A. Zeeb 3870d9945d78SBjoern A. Zeeb band_mask = 0; 38716b4cac81SBjoern A. Zeeb nchan = 0; 3872c272abc5SBjoern A. Zeeb if (ieee80211_hw_check(hw, SINGLE_SCAN_ON_ALL_BANDS)) { 3873c272abc5SBjoern A. Zeeb #if 0 /* Avoid net80211 scan lists until it has proper scan offload support. */ 3874d9945d78SBjoern A. Zeeb for (i = ss->ss_next; i < ss->ss_last; i++) { 38756b4cac81SBjoern A. Zeeb nchan++; 3876d9945d78SBjoern A. Zeeb band = lkpi_net80211_chan_to_nl80211_band( 3877d9945d78SBjoern A. Zeeb ss->ss_chans[ss->ss_next + i]); 3878d9945d78SBjoern A. Zeeb band_mask |= (1 << band); 3879d9945d78SBjoern A. Zeeb } 3880c272abc5SBjoern A. Zeeb #else 3881c272abc5SBjoern A. Zeeb /* Instead we scan for all channels all the time. */ 3882c272abc5SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 3883c272abc5SBjoern A. Zeeb switch (band) { 3884c272abc5SBjoern A. Zeeb case NL80211_BAND_2GHZ: 3885c272abc5SBjoern A. Zeeb case NL80211_BAND_5GHZ: 3886c272abc5SBjoern A. Zeeb break; 3887c272abc5SBjoern A. Zeeb default: 3888c272abc5SBjoern A. Zeeb continue; 3889c272abc5SBjoern A. Zeeb } 3890c272abc5SBjoern A. Zeeb if (hw->wiphy->bands[band] != NULL) { 3891c272abc5SBjoern A. Zeeb nchan += hw->wiphy->bands[band]->n_channels; 3892c272abc5SBjoern A. Zeeb band_mask |= (1 << band); 3893c272abc5SBjoern A. Zeeb } 3894c272abc5SBjoern A. Zeeb } 3895c272abc5SBjoern A. Zeeb #endif 3896c272abc5SBjoern A. Zeeb } else { 38973206587aSBjoern A. Zeeb IMPROVE("individual band scans not yet supported, only scanning first band"); 38983206587aSBjoern A. Zeeb /* In theory net80211 should drive this. */ 38993206587aSBjoern A. Zeeb /* Probably we need to add local logic for now; 39003206587aSBjoern A. Zeeb * need to deal with scan_complete 39013206587aSBjoern A. Zeeb * and cancel_scan and keep local state. 39023206587aSBjoern A. Zeeb * Also cut the nchan down above. 39033206587aSBjoern A. Zeeb */ 39043206587aSBjoern A. Zeeb /* XXX-BZ ath10k does not set this but still does it? &$%^ */ 39053206587aSBjoern A. Zeeb } 39063206587aSBjoern A. Zeeb 39076b4cac81SBjoern A. Zeeb chan_len = nchan * (sizeof(lc) + sizeof(*lc)); 39086b4cac81SBjoern A. Zeeb 3909d9945d78SBjoern A. Zeeb common_ie_len = 0; 3910d9945d78SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WPA1) != 0 && 3911d9945d78SBjoern A. Zeeb vap->iv_wpa_ie != NULL) 3912d9945d78SBjoern A. Zeeb common_ie_len += vap->iv_wpa_ie[1]; 3913d9945d78SBjoern A. Zeeb if (vap->iv_appie_probereq != NULL) 3914d9945d78SBjoern A. Zeeb common_ie_len += vap->iv_appie_probereq->ie_len; 3915d9945d78SBjoern A. Zeeb 3916d9945d78SBjoern A. Zeeb /* We would love to check this at an earlier stage... */ 3917d9945d78SBjoern A. Zeeb if (common_ie_len > hw->wiphy->max_scan_ie_len) { 3918d9945d78SBjoern A. Zeeb ic_printf(ic, "WARNING: %s: common_ie_len %d > " 3919d9945d78SBjoern A. Zeeb "wiphy->max_scan_ie_len %d\n", __func__, 3920d9945d78SBjoern A. Zeeb common_ie_len, hw->wiphy->max_scan_ie_len); 3921d9945d78SBjoern A. Zeeb } 3922d9945d78SBjoern A. Zeeb 39233206587aSBjoern A. Zeeb hw_req = malloc(sizeof(*hw_req) + ssids_len + 3924d9945d78SBjoern A. Zeeb s6ghzlen + chan_len + lhw->supbands * lhw->scan_ie_len + 3925d9945d78SBjoern A. Zeeb common_ie_len, M_LKPI80211, M_WAITOK | M_ZERO); 39266b4cac81SBjoern A. Zeeb 39276b4cac81SBjoern A. Zeeb hw_req->req.flags = 0; /* XXX ??? */ 39286b4cac81SBjoern A. Zeeb /* hw_req->req.wdev */ 39296b4cac81SBjoern A. Zeeb hw_req->req.wiphy = hw->wiphy; 39306b4cac81SBjoern A. Zeeb hw_req->req.no_cck = false; /* XXX */ 39316b4cac81SBjoern A. Zeeb #if 0 39326b4cac81SBjoern A. Zeeb /* This seems to pessimise default scanning behaviour. */ 39336b4cac81SBjoern A. Zeeb hw_req->req.duration_mandatory = TICKS_2_USEC(ss->ss_mindwell); 39346b4cac81SBjoern A. Zeeb hw_req->req.duration = TICKS_2_USEC(ss->ss_maxdwell); 39356b4cac81SBjoern A. Zeeb #endif 39366b4cac81SBjoern A. Zeeb #ifdef __notyet__ 39376b4cac81SBjoern A. Zeeb hw_req->req.flags |= NL80211_SCAN_FLAG_RANDOM_ADDR; 39386b4cac81SBjoern A. Zeeb memcpy(hw_req->req.mac_addr, xxx, IEEE80211_ADDR_LEN); 39396b4cac81SBjoern A. Zeeb memset(hw_req->req.mac_addr_mask, 0xxx, IEEE80211_ADDR_LEN); 39406b4cac81SBjoern A. Zeeb #endif 3941e1e90be0SBjoern A. Zeeb eth_broadcast_addr(hw_req->req.bssid); 39426b4cac81SBjoern A. Zeeb 39436b4cac81SBjoern A. Zeeb hw_req->req.n_channels = nchan; 39446b4cac81SBjoern A. Zeeb cpp = (struct linuxkpi_ieee80211_channel **)(hw_req + 1); 39456b4cac81SBjoern A. Zeeb lc = (struct linuxkpi_ieee80211_channel *)(cpp + nchan); 39466b4cac81SBjoern A. Zeeb for (i = 0; i < nchan; i++) { 39476b4cac81SBjoern A. Zeeb *(cpp + i) = 39486b4cac81SBjoern A. Zeeb (struct linuxkpi_ieee80211_channel *)(lc + i); 39496b4cac81SBjoern A. Zeeb } 3950c272abc5SBjoern A. Zeeb #if 0 /* Avoid net80211 scan lists until it has proper scan offload support. */ 39516b4cac81SBjoern A. Zeeb for (i = 0; i < nchan; i++) { 3952c272abc5SBjoern A. Zeeb struct ieee80211_channel *c; 39536b4cac81SBjoern A. Zeeb 3954c272abc5SBjoern A. Zeeb c = ss->ss_chans[ss->ss_next + i]; 39556b4cac81SBjoern A. Zeeb lc->hw_value = c->ic_ieee; 39563206587aSBjoern A. Zeeb lc->center_freq = c->ic_freq; /* XXX */ 39576b4cac81SBjoern A. Zeeb /* lc->flags */ 39586b4cac81SBjoern A. Zeeb lc->band = lkpi_net80211_chan_to_nl80211_band(c); 39596b4cac81SBjoern A. Zeeb lc->max_power = c->ic_maxpower; 39606b4cac81SBjoern A. Zeeb /* lc-> ... */ 39616b4cac81SBjoern A. Zeeb lc++; 39626b4cac81SBjoern A. Zeeb } 3963c272abc5SBjoern A. Zeeb #else 3964c272abc5SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 3965c272abc5SBjoern A. Zeeb struct ieee80211_supported_band *supband; 3966c272abc5SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 3967c272abc5SBjoern A. Zeeb 3968c272abc5SBjoern A. Zeeb /* Band disabled for scanning? */ 3969c272abc5SBjoern A. Zeeb if ((band_mask & (1 << band)) == 0) 3970c272abc5SBjoern A. Zeeb continue; 3971c272abc5SBjoern A. Zeeb 3972c272abc5SBjoern A. Zeeb /* Nothing to scan in band? */ 3973c272abc5SBjoern A. Zeeb supband = hw->wiphy->bands[band]; 3974c272abc5SBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 3975c272abc5SBjoern A. Zeeb continue; 3976c272abc5SBjoern A. Zeeb 3977c272abc5SBjoern A. Zeeb channels = supband->channels; 3978c272abc5SBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 3979c272abc5SBjoern A. Zeeb *lc = channels[i]; 3980c272abc5SBjoern A. Zeeb lc++; 3981c272abc5SBjoern A. Zeeb } 3982c272abc5SBjoern A. Zeeb } 3983c272abc5SBjoern A. Zeeb #endif 39846b4cac81SBjoern A. Zeeb 3985d9945d78SBjoern A. Zeeb hw_req->req.n_ssids = ssid_count; 39866b4cac81SBjoern A. Zeeb if (hw_req->req.n_ssids > 0) { 39876b4cac81SBjoern A. Zeeb ssids = (struct cfg80211_ssid *)lc; 39886b4cac81SBjoern A. Zeeb hw_req->req.ssids = ssids; 3989d9945d78SBjoern A. Zeeb for (i = 0; i < ssid_count; i++) { 39906b4cac81SBjoern A. Zeeb ssids->ssid_len = ss->ss_ssid[i].len; 39916b4cac81SBjoern A. Zeeb memcpy(ssids->ssid, ss->ss_ssid[i].ssid, 39926b4cac81SBjoern A. Zeeb ss->ss_ssid[i].len); 39936b4cac81SBjoern A. Zeeb ssids++; 39946b4cac81SBjoern A. Zeeb } 39956b4cac81SBjoern A. Zeeb s6gp = (struct cfg80211_scan_6ghz_params *)ssids; 39966b4cac81SBjoern A. Zeeb } else { 39976b4cac81SBjoern A. Zeeb s6gp = (struct cfg80211_scan_6ghz_params *)lc; 39986b4cac81SBjoern A. Zeeb } 39996b4cac81SBjoern A. Zeeb 40006b4cac81SBjoern A. Zeeb /* 6GHz one day. */ 40016b4cac81SBjoern A. Zeeb hw_req->req.n_6ghz_params = 0; 40026b4cac81SBjoern A. Zeeb hw_req->req.scan_6ghz_params = NULL; 40036b4cac81SBjoern A. Zeeb hw_req->req.scan_6ghz = false; /* Weird boolean; not what you think. */ 40046b4cac81SBjoern A. Zeeb /* s6gp->... */ 40056b4cac81SBjoern A. Zeeb 4006d9945d78SBjoern A. Zeeb ie = ieend = (uint8_t *)s6gp; 4007d9945d78SBjoern A. Zeeb /* Copy per-band IEs, copy common IEs */ 4008d9945d78SBjoern A. Zeeb ieend = lkpi_scan_ies_add(ie, &hw_req->ies, band_mask, vap, hw); 4009d9945d78SBjoern A. Zeeb hw_req->req.ie = ie; 4010d9945d78SBjoern A. Zeeb hw_req->req.ie_len = ieend - ie; 4011d9945d78SBjoern A. Zeeb 40126b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 40136b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 40143206587aSBjoern A. Zeeb 40153206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 40163206587aSBjoern A. Zeeb /* Re-check under lock. */ 40173206587aSBjoern A. Zeeb running = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0; 40183206587aSBjoern A. Zeeb if (!running) { 40193206587aSBjoern A. Zeeb KASSERT(lhw->hw_req == NULL, ("%s: ic %p lhw %p hw_req %p " 40203206587aSBjoern A. Zeeb "!= NULL\n", __func__, ic, lhw, lhw->hw_req)); 40213206587aSBjoern A. Zeeb 40223206587aSBjoern A. Zeeb lhw->scan_flags |= LKPI_LHW_SCAN_RUNNING; 40233206587aSBjoern A. Zeeb lhw->hw_req = hw_req; 40243206587aSBjoern A. Zeeb } 40253206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 40263206587aSBjoern A. Zeeb if (running) { 40273206587aSBjoern A. Zeeb free(hw_req, M_LKPI80211); 40283206587aSBjoern A. Zeeb return; 40293206587aSBjoern A. Zeeb } 40303206587aSBjoern A. Zeeb 40316b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_hw_scan(hw, vif, hw_req); 40326b4cac81SBjoern A. Zeeb if (error != 0) { 4033d9945d78SBjoern A. Zeeb ieee80211_cancel_scan(vap); 4034d9945d78SBjoern A. Zeeb 40353206587aSBjoern A. Zeeb /* 40363206587aSBjoern A. Zeeb * ieee80211_scan_completed must be called in either 40373206587aSBjoern A. Zeeb * case of error or none. So let the free happen there 40383206587aSBjoern A. Zeeb * and only there. 40393206587aSBjoern A. Zeeb * That would be fine in theory but in practice drivers 40403206587aSBjoern A. Zeeb * behave differently: 40413206587aSBjoern A. Zeeb * ath10k does not return hw_scan until after scan_complete 40423206587aSBjoern A. Zeeb * and can then still return an error. 40433206587aSBjoern A. Zeeb * rtw88 can return 1 or -EBUSY without scan_complete 40443206587aSBjoern A. Zeeb * iwlwifi can return various errors before scan starts 40453206587aSBjoern A. Zeeb * ... 40463206587aSBjoern A. Zeeb * So we cannot rely on that behaviour and have to check 40473206587aSBjoern A. Zeeb * and balance between both code paths. 40483206587aSBjoern A. Zeeb */ 40493206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 40503206587aSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) { 40513206587aSBjoern A. Zeeb free(lhw->hw_req, M_LKPI80211); 40526b4cac81SBjoern A. Zeeb lhw->hw_req = NULL; 40533206587aSBjoern A. Zeeb lhw->scan_flags &= ~LKPI_LHW_SCAN_RUNNING; 40543206587aSBjoern A. Zeeb } 40553206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 4056d3ef7fb4SBjoern A. Zeeb 4057d3ef7fb4SBjoern A. Zeeb /* 4058d3ef7fb4SBjoern A. Zeeb * XXX-SIGH magic number. 4059d3ef7fb4SBjoern A. Zeeb * rtw88 has a magic "return 1" if offloading scan is 4060d3ef7fb4SBjoern A. Zeeb * not possible. Fall back to sw scan in that case. 4061d3ef7fb4SBjoern A. Zeeb */ 4062196cfd0bSBjoern A. Zeeb if (error == 1) { 40638ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 4064a486fbbdSBjoern A. Zeeb lhw->scan_flags &= ~LKPI_LHW_SCAN_HW; 40658ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 40663206587aSBjoern A. Zeeb /* 40673206587aSBjoern A. Zeeb * XXX If we clear this now and later a driver 40683206587aSBjoern A. Zeeb * thinks it * can do a hw_scan again, we will 40693206587aSBjoern A. Zeeb * currently not re-enable it? 40703206587aSBjoern A. Zeeb */ 40713206587aSBjoern A. Zeeb vap->iv_flags_ext &= ~IEEE80211_FEXT_SCAN_OFFLOAD; 4072196cfd0bSBjoern A. Zeeb ieee80211_start_scan(vap, 4073196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_ACTIVE | 4074196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_NOPICK | 4075196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_ONCE, 4076196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_FOREVER, 4077196cfd0bSBjoern A. Zeeb ss->ss_mindwell ? ss->ss_mindwell : msecs_to_ticks(20), 4078196cfd0bSBjoern A. Zeeb ss->ss_maxdwell ? ss->ss_maxdwell : msecs_to_ticks(200), 4079196cfd0bSBjoern A. Zeeb vap->iv_des_nssid, vap->iv_des_ssid); 4080d3ef7fb4SBjoern A. Zeeb goto sw_scan; 4081196cfd0bSBjoern A. Zeeb } 4082d3ef7fb4SBjoern A. Zeeb 4083d3ef7fb4SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: hw_scan returned %d\n", 4084d3ef7fb4SBjoern A. Zeeb __func__, error); 40856b4cac81SBjoern A. Zeeb } 40866b4cac81SBjoern A. Zeeb } 40876b4cac81SBjoern A. Zeeb } 40886b4cac81SBjoern A. Zeeb 40896b4cac81SBjoern A. Zeeb static void 40906b4cac81SBjoern A. Zeeb lkpi_ic_scan_end(struct ieee80211com *ic) 40916b4cac81SBjoern A. Zeeb { 40926b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 40938ac540d3SBjoern A. Zeeb bool is_hw_scan; 40946b4cac81SBjoern A. Zeeb 40956b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 40968ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 4097a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) == 0) { 40988ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 40996b4cac81SBjoern A. Zeeb return; 41006b4cac81SBjoern A. Zeeb } 41018ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 41028ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 41036b4cac81SBjoern A. Zeeb 41048ac540d3SBjoern A. Zeeb if (!is_hw_scan) { 4105a486fbbdSBjoern A. Zeeb struct ieee80211_scan_state *ss; 4106a486fbbdSBjoern A. Zeeb struct ieee80211vap *vap; 41076b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 41086b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 41096b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 41106b4cac81SBjoern A. Zeeb 4111a486fbbdSBjoern A. Zeeb ss = ic->ic_scan; 4112a486fbbdSBjoern A. Zeeb vap = ss->ss_vap; 41136b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 41146b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 41156b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 4116a486fbbdSBjoern A. Zeeb 41176b4cac81SBjoern A. Zeeb lkpi_80211_mo_sw_scan_complete(hw, vif); 41186b4cac81SBjoern A. Zeeb 41196b4cac81SBjoern A. Zeeb /* Send PS to stop buffering if n80211 does not for us? */ 4120086be6a8SBjoern A. Zeeb 4121086be6a8SBjoern A. Zeeb if (vap->iv_state == IEEE80211_S_SCAN) 4122086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true); 41236b4cac81SBjoern A. Zeeb } 41246b4cac81SBjoern A. Zeeb } 41256b4cac81SBjoern A. Zeeb 41266b4cac81SBjoern A. Zeeb static void 4127a486fbbdSBjoern A. Zeeb lkpi_ic_scan_curchan(struct ieee80211_scan_state *ss, 4128a486fbbdSBjoern A. Zeeb unsigned long maxdwell) 4129a486fbbdSBjoern A. Zeeb { 4130a486fbbdSBjoern A. Zeeb struct lkpi_hw *lhw; 41318ac540d3SBjoern A. Zeeb bool is_hw_scan; 4132a486fbbdSBjoern A. Zeeb 4133a486fbbdSBjoern A. Zeeb lhw = ss->ss_ic->ic_softc; 41348ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 41358ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 41368ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 41378ac540d3SBjoern A. Zeeb if (!is_hw_scan) 4138a486fbbdSBjoern A. Zeeb lhw->ic_scan_curchan(ss, maxdwell); 4139a486fbbdSBjoern A. Zeeb } 4140a486fbbdSBjoern A. Zeeb 4141a486fbbdSBjoern A. Zeeb static void 4142a486fbbdSBjoern A. Zeeb lkpi_ic_scan_mindwell(struct ieee80211_scan_state *ss) 4143a486fbbdSBjoern A. Zeeb { 4144a486fbbdSBjoern A. Zeeb struct lkpi_hw *lhw; 41458ac540d3SBjoern A. Zeeb bool is_hw_scan; 4146a486fbbdSBjoern A. Zeeb 4147a486fbbdSBjoern A. Zeeb lhw = ss->ss_ic->ic_softc; 41488ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 41498ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 41508ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 41518ac540d3SBjoern A. Zeeb if (!is_hw_scan) 4152a486fbbdSBjoern A. Zeeb lhw->ic_scan_mindwell(ss); 4153a486fbbdSBjoern A. Zeeb } 4154a486fbbdSBjoern A. Zeeb 4155a486fbbdSBjoern A. Zeeb static void 41566b4cac81SBjoern A. Zeeb lkpi_ic_set_channel(struct ieee80211com *ic) 41576b4cac81SBjoern A. Zeeb { 41586b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 41596b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 4160b2cf3c21SBjoern A. Zeeb struct ieee80211_channel *c; 4161b2cf3c21SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 41626b4cac81SBjoern A. Zeeb int error; 41638ac540d3SBjoern A. Zeeb bool hw_scan_running; 41646b4cac81SBjoern A. Zeeb 41656b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 4166b2cf3c21SBjoern A. Zeeb 4167b2cf3c21SBjoern A. Zeeb /* If we do not support (*config)() save us the work. */ 4168b2cf3c21SBjoern A. Zeeb if (lhw->ops->config == NULL) 41696b4cac81SBjoern A. Zeeb return; 41706b4cac81SBjoern A. Zeeb 4171a486fbbdSBjoern A. Zeeb /* If we have a hw_scan running do not switch channels. */ 41728ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 41738ac540d3SBjoern A. Zeeb hw_scan_running = 41748ac540d3SBjoern A. Zeeb (lhw->scan_flags & (LKPI_LHW_SCAN_RUNNING|LKPI_LHW_SCAN_HW)) == 41758ac540d3SBjoern A. Zeeb (LKPI_LHW_SCAN_RUNNING|LKPI_LHW_SCAN_HW); 41768ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 41778ac540d3SBjoern A. Zeeb if (hw_scan_running) 4178a486fbbdSBjoern A. Zeeb return; 4179a486fbbdSBjoern A. Zeeb 4180b2cf3c21SBjoern A. Zeeb c = ic->ic_curchan; 4181b2cf3c21SBjoern A. Zeeb if (c == NULL || c == IEEE80211_CHAN_ANYC) { 41826b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: c %p ops->config %p\n", __func__, 41836b4cac81SBjoern A. Zeeb c, lhw->ops->config); 41846b4cac81SBjoern A. Zeeb return; 41856b4cac81SBjoern A. Zeeb } 41866b4cac81SBjoern A. Zeeb 41876b4cac81SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, c); 41886b4cac81SBjoern A. Zeeb if (chan == NULL) { 41896b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: c %p chan %p\n", __func__, 41906b4cac81SBjoern A. Zeeb c, chan); 41916b4cac81SBjoern A. Zeeb return; 41926b4cac81SBjoern A. Zeeb } 41936b4cac81SBjoern A. Zeeb 41946b4cac81SBjoern A. Zeeb /* XXX max power for scanning? */ 41956b4cac81SBjoern A. Zeeb IMPROVE(); 41966b4cac81SBjoern A. Zeeb 41976b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 41984a07abdeSBjoern A. Zeeb cfg80211_chandef_create(&hw->conf.chandef, chan, 41999fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 420011450726SBjoern A. Zeeb (ic->ic_flags_ht & IEEE80211_FHT_HT) ? NL80211_CHAN_HT20 : 42019fb91463SBjoern A. Zeeb #endif 42024a07abdeSBjoern A. Zeeb NL80211_CHAN_NO_HT); 42036b4cac81SBjoern A. Zeeb 42046b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_CHANNEL); 42056b4cac81SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) { 42066b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: config %#0x returned %d\n", 42076b4cac81SBjoern A. Zeeb __func__, IEEE80211_CONF_CHANGE_CHANNEL, error); 42086b4cac81SBjoern A. Zeeb /* XXX should we unroll to the previous chandef? */ 42096b4cac81SBjoern A. Zeeb IMPROVE(); 42106b4cac81SBjoern A. Zeeb } else { 42116b4cac81SBjoern A. Zeeb /* Update radiotap channels as well. */ 42126b4cac81SBjoern A. Zeeb lhw->rtap_tx.wt_chan_freq = htole16(c->ic_freq); 42136b4cac81SBjoern A. Zeeb lhw->rtap_tx.wt_chan_flags = htole16(c->ic_flags); 42146b4cac81SBjoern A. Zeeb lhw->rtap_rx.wr_chan_freq = htole16(c->ic_freq); 42156b4cac81SBjoern A. Zeeb lhw->rtap_rx.wr_chan_flags = htole16(c->ic_flags); 42166b4cac81SBjoern A. Zeeb } 42176b4cac81SBjoern A. Zeeb 42186b4cac81SBjoern A. Zeeb /* Currently PS is hard coded off! Not sure it belongs here. */ 42196b4cac81SBjoern A. Zeeb IMPROVE(); 42206b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, SUPPORTS_PS) && 42216b4cac81SBjoern A. Zeeb (hw->conf.flags & IEEE80211_CONF_PS) != 0) { 42226b4cac81SBjoern A. Zeeb hw->conf.flags &= ~IEEE80211_CONF_PS; 42236b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_PS); 42246b4cac81SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) 42256b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: config %#0x returned " 42266b4cac81SBjoern A. Zeeb "%d\n", __func__, IEEE80211_CONF_CHANGE_PS, 42276b4cac81SBjoern A. Zeeb error); 42286b4cac81SBjoern A. Zeeb } 42296b4cac81SBjoern A. Zeeb } 42306b4cac81SBjoern A. Zeeb 42316b4cac81SBjoern A. Zeeb static struct ieee80211_node * 42326b4cac81SBjoern A. Zeeb lkpi_ic_node_alloc(struct ieee80211vap *vap, 42336b4cac81SBjoern A. Zeeb const uint8_t mac[IEEE80211_ADDR_LEN]) 42346b4cac81SBjoern A. Zeeb { 42356b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 42366b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 42374f61ef8bSBjoern A. Zeeb struct ieee80211_node *ni; 42386b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 42396b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 42406b4cac81SBjoern A. Zeeb 42416b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 42426b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 42436b4cac81SBjoern A. Zeeb 42446b4cac81SBjoern A. Zeeb /* We keep allocations de-coupled so we can deal with the two worlds. */ 42454f61ef8bSBjoern A. Zeeb if (lhw->ic_node_alloc == NULL) 42464f61ef8bSBjoern A. Zeeb return (NULL); 42474f61ef8bSBjoern A. Zeeb 42486b4cac81SBjoern A. Zeeb ni = lhw->ic_node_alloc(vap, mac); 42496b4cac81SBjoern A. Zeeb if (ni == NULL) 42506b4cac81SBjoern A. Zeeb return (NULL); 42516b4cac81SBjoern A. Zeeb 42526b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 42534f61ef8bSBjoern A. Zeeb lsta = lkpi_lsta_alloc(vap, mac, hw, ni); 42546b4cac81SBjoern A. Zeeb if (lsta == NULL) { 42556b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL) 42566b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni); 42576b4cac81SBjoern A. Zeeb return (NULL); 42586b4cac81SBjoern A. Zeeb } 42596b4cac81SBjoern A. Zeeb 42606b4cac81SBjoern A. Zeeb return (ni); 42616b4cac81SBjoern A. Zeeb } 42626b4cac81SBjoern A. Zeeb 42636b4cac81SBjoern A. Zeeb static int 42646b4cac81SBjoern A. Zeeb lkpi_ic_node_init(struct ieee80211_node *ni) 42656b4cac81SBjoern A. Zeeb { 42666b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 42676b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 42686b4cac81SBjoern A. Zeeb int error; 42696b4cac81SBjoern A. Zeeb 42706b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 42716b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 42726b4cac81SBjoern A. Zeeb 42736b4cac81SBjoern A. Zeeb if (lhw->ic_node_init != NULL) { 42746b4cac81SBjoern A. Zeeb error = lhw->ic_node_init(ni); 42756b4cac81SBjoern A. Zeeb if (error != 0) 42766b4cac81SBjoern A. Zeeb return (error); 42776b4cac81SBjoern A. Zeeb } 42786b4cac81SBjoern A. Zeeb 42796b4cac81SBjoern A. Zeeb /* XXX-BZ Sync other state over. */ 42806b4cac81SBjoern A. Zeeb IMPROVE(); 42816b4cac81SBjoern A. Zeeb 42826b4cac81SBjoern A. Zeeb return (0); 42836b4cac81SBjoern A. Zeeb } 42846b4cac81SBjoern A. Zeeb 42856b4cac81SBjoern A. Zeeb static void 42866b4cac81SBjoern A. Zeeb lkpi_ic_node_cleanup(struct ieee80211_node *ni) 42876b4cac81SBjoern A. Zeeb { 42886b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 42896b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 42906b4cac81SBjoern A. Zeeb 42916b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 42926b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 42936b4cac81SBjoern A. Zeeb 42946b4cac81SBjoern A. Zeeb /* XXX-BZ remove from driver, ... */ 42956b4cac81SBjoern A. Zeeb IMPROVE(); 42966b4cac81SBjoern A. Zeeb 42976b4cac81SBjoern A. Zeeb if (lhw->ic_node_cleanup != NULL) 42986b4cac81SBjoern A. Zeeb lhw->ic_node_cleanup(ni); 42996b4cac81SBjoern A. Zeeb } 43006b4cac81SBjoern A. Zeeb 43016b4cac81SBjoern A. Zeeb static void 43026b4cac81SBjoern A. Zeeb lkpi_ic_node_free(struct ieee80211_node *ni) 43036b4cac81SBjoern A. Zeeb { 43046b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 43056b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 43066b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 43076b4cac81SBjoern A. Zeeb 43086b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 43096b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 43106b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 43116b4cac81SBjoern A. Zeeb 43120936c648SBjoern A. Zeeb /* KASSERT lsta is not NULL here. Print ni/ni__refcnt. */ 43136b4cac81SBjoern A. Zeeb 43140936c648SBjoern A. Zeeb /* 43150936c648SBjoern A. Zeeb * Pass in the original ni just in case of error we could check that 43160936c648SBjoern A. Zeeb * it is the same as lsta->ni. 43170936c648SBjoern A. Zeeb */ 43180936c648SBjoern A. Zeeb lkpi_lsta_free(lsta, ni); 43196b4cac81SBjoern A. Zeeb 43206b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL) 43216b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni); 43226b4cac81SBjoern A. Zeeb } 43236b4cac81SBjoern A. Zeeb 43246b4cac81SBjoern A. Zeeb static int 43256b4cac81SBjoern A. Zeeb lkpi_ic_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, 43266b4cac81SBjoern A. Zeeb const struct ieee80211_bpf_params *params __unused) 43276b4cac81SBjoern A. Zeeb { 43286b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 43296b4cac81SBjoern A. Zeeb 43306b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 4331fa4e4257SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_LOCK(lsta); 43322372f8ccSBjoern A. Zeeb #if 0 433388665349SBjoern A. Zeeb if (!lsta->added_to_drv || !lsta->txq_ready) { 43342372f8ccSBjoern A. Zeeb #else 43352372f8ccSBjoern A. Zeeb /* 43362372f8ccSBjoern A. Zeeb * Backout this part of 886653492945f which breaks rtw88 or 43372372f8ccSBjoern A. Zeeb * in general drivers without (*sta_state)() but only the 43382372f8ccSBjoern A. Zeeb * legacy fallback to (*sta_add)(). 43392372f8ccSBjoern A. Zeeb */ 43402372f8ccSBjoern A. Zeeb if (!lsta->txq_ready) { 43412372f8ccSBjoern A. Zeeb #endif 4342fa4e4257SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_UNLOCK(lsta); 4343fa4e4257SBjoern A. Zeeb /* 4344fa4e4257SBjoern A. Zeeb * Free the mbuf (do NOT release ni ref for the m_pkthdr.rcvif! 4345fa4e4257SBjoern A. Zeeb * ieee80211_raw_output() does that in case of error). 4346fa4e4257SBjoern A. Zeeb */ 43470936c648SBjoern A. Zeeb m_free(m); 43480936c648SBjoern A. Zeeb return (ENETDOWN); 43490936c648SBjoern A. Zeeb } 43506b4cac81SBjoern A. Zeeb 43516b4cac81SBjoern A. Zeeb /* Queue the packet and enqueue the task to handle it. */ 43526b4cac81SBjoern A. Zeeb mbufq_enqueue(&lsta->txq, m); 4353fa4e4257SBjoern A. Zeeb taskqueue_enqueue(taskqueue_thread, &lsta->txq_task); 4354fa4e4257SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_UNLOCK(lsta); 43556b4cac81SBjoern A. Zeeb 43569d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 43579d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 43586b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p ni %p %6D mbuf_qlen %d\n", 43596b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, ni, ni->ni_macaddr, ":", 43606b4cac81SBjoern A. Zeeb mbufq_len(&lsta->txq)); 43619d9ba2b7SBjoern A. Zeeb #endif 43626b4cac81SBjoern A. Zeeb 43636b4cac81SBjoern A. Zeeb return (0); 43646b4cac81SBjoern A. Zeeb } 43656b4cac81SBjoern A. Zeeb 436611db70b6SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 436711db70b6SBjoern A. Zeeb static int 436811db70b6SBjoern A. Zeeb lkpi_hw_crypto_prepare(struct lkpi_sta *lsta, struct ieee80211_key *k, 436911db70b6SBjoern A. Zeeb struct sk_buff *skb) 437011db70b6SBjoern A. Zeeb { 437111db70b6SBjoern A. Zeeb struct ieee80211_tx_info *info; 437211db70b6SBjoern A. Zeeb struct ieee80211_key_conf *kc; 437311db70b6SBjoern A. Zeeb struct ieee80211_hdr *hdr; 437411db70b6SBjoern A. Zeeb uint32_t hlen, hdrlen; 437511db70b6SBjoern A. Zeeb uint8_t *p; 437611db70b6SBjoern A. Zeeb 437711db70b6SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: lsta is NULL", __func__)); 437811db70b6SBjoern A. Zeeb KASSERT(k != NULL, ("%s: key is NULL", __func__)); 437911db70b6SBjoern A. Zeeb KASSERT(skb != NULL, ("%s: skb is NULL", __func__)); 438011db70b6SBjoern A. Zeeb 438111db70b6SBjoern A. Zeeb kc = lsta->kc[k->wk_keyix]; 438211db70b6SBjoern A. Zeeb 438311db70b6SBjoern A. Zeeb info = IEEE80211_SKB_CB(skb); 438411db70b6SBjoern A. Zeeb info->control.hw_key = kc; 438511db70b6SBjoern A. Zeeb 438611db70b6SBjoern A. Zeeb /* MUST NOT happen. KASSERT? */ 438711db70b6SBjoern A. Zeeb if (kc == NULL) { 438811db70b6SBjoern A. Zeeb ic_printf(lsta->ni->ni_ic, "%s: lsta %p k %p skb %p, " 438911db70b6SBjoern A. Zeeb "kc is NULL on hw crypto offload\n", __func__, lsta, k, skb); 439011db70b6SBjoern A. Zeeb return (ENXIO); 439111db70b6SBjoern A. Zeeb } 439211db70b6SBjoern A. Zeeb 439311db70b6SBjoern A. Zeeb 439411db70b6SBjoern A. Zeeb IMPROVE("the following should be WLAN_CIPHER_SUITE specific"); 439511db70b6SBjoern A. Zeeb /* We currently only support CCMP so we hardcode things here. */ 439611db70b6SBjoern A. Zeeb 439711db70b6SBjoern A. Zeeb hdr = (void *)skb->data; 439811db70b6SBjoern A. Zeeb 439911db70b6SBjoern A. Zeeb /* 440011db70b6SBjoern A. Zeeb * Check if we have anythig to do as requested by driver 440111db70b6SBjoern A. Zeeb * or if we are done? 440211db70b6SBjoern A. Zeeb */ 440311db70b6SBjoern A. Zeeb if ((kc->flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE) == 0 && 440411db70b6SBjoern A. Zeeb (kc->flags & IEEE80211_KEY_FLAG_GENERATE_IV) == 0 && 440511db70b6SBjoern A. Zeeb /* MFP */ 440611db70b6SBjoern A. Zeeb !((kc->flags & IEEE80211_KEY_FLAG_GENERATE_IV_MGMT) != 0 && 440711db70b6SBjoern A. Zeeb ieee80211_is_mgmt(hdr->frame_control))) 440811db70b6SBjoern A. Zeeb return (0); 440911db70b6SBjoern A. Zeeb 441011db70b6SBjoern A. Zeeb hlen = k->wk_cipher->ic_header; 441111db70b6SBjoern A. Zeeb if (skb_headroom(skb) < hlen) 441211db70b6SBjoern A. Zeeb return (ENOSPC); 441311db70b6SBjoern A. Zeeb 441411db70b6SBjoern A. Zeeb hdrlen = ieee80211_hdrlen(hdr->frame_control); 441511db70b6SBjoern A. Zeeb p = skb_push(skb, hlen); 441611db70b6SBjoern A. Zeeb memmove(p, p + hlen, hdrlen); 441711db70b6SBjoern A. Zeeb 441811db70b6SBjoern A. Zeeb /* If driver request space only we are done. */ 441911db70b6SBjoern A. Zeeb if ((kc->flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE) != 0) 442011db70b6SBjoern A. Zeeb return (0); 442111db70b6SBjoern A. Zeeb 442211db70b6SBjoern A. Zeeb p += hdrlen; 442311db70b6SBjoern A. Zeeb k->wk_cipher->ic_setiv(k, p); 442411db70b6SBjoern A. Zeeb 442511db70b6SBjoern A. Zeeb return (0); 442611db70b6SBjoern A. Zeeb } 442711db70b6SBjoern A. Zeeb #endif 442811db70b6SBjoern A. Zeeb 44296b4cac81SBjoern A. Zeeb static void 44306b4cac81SBjoern A. Zeeb lkpi_80211_txq_tx_one(struct lkpi_sta *lsta, struct mbuf *m) 44316b4cac81SBjoern A. Zeeb { 44326b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 44336b4cac81SBjoern A. Zeeb struct ieee80211_frame *wh; 44346b4cac81SBjoern A. Zeeb struct ieee80211_key *k; 44356b4cac81SBjoern A. Zeeb struct sk_buff *skb; 44366b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 44376b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 44386b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 44396b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 44406b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 44416b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 44426b4cac81SBjoern A. Zeeb struct ieee80211_tx_control control; 44436b4cac81SBjoern A. Zeeb struct ieee80211_tx_info *info; 44446b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 4445e3a0b120SBjoern A. Zeeb struct ieee80211_hdr *hdr; 4446ac867c20SBjoern A. Zeeb struct lkpi_txq *ltxq; 44476b4cac81SBjoern A. Zeeb void *buf; 444811db70b6SBjoern A. Zeeb ieee80211_keyix keyix; 4449e3a0b120SBjoern A. Zeeb uint8_t ac, tid; 44506b4cac81SBjoern A. Zeeb 44516b4cac81SBjoern A. Zeeb M_ASSERTPKTHDR(m); 44526b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 44539d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX_DUMP) 44546b4cac81SBjoern A. Zeeb hexdump(mtod(m, const void *), m->m_len, "RAW TX (plain) ", 0); 44556b4cac81SBjoern A. Zeeb #endif 44566b4cac81SBjoern A. Zeeb 44576b4cac81SBjoern A. Zeeb ni = lsta->ni; 4458b35f6cd0SBjoern A. Zeeb k = NULL; 445911db70b6SBjoern A. Zeeb keyix = IEEE80211_KEYIX_NONE; 44606b4cac81SBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame *); 44616b4cac81SBjoern A. Zeeb if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { 446211db70b6SBjoern A. Zeeb 446311db70b6SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 446411db70b6SBjoern A. Zeeb if (lkpi_hwcrypto) { 446511db70b6SBjoern A. Zeeb k = ieee80211_crypto_get_txkey(ni, m); 446611db70b6SBjoern A. Zeeb if (k != NULL && lsta->kc[k->wk_keyix] != NULL) 446711db70b6SBjoern A. Zeeb keyix = k->wk_keyix; 446811db70b6SBjoern A. Zeeb } 446911db70b6SBjoern A. Zeeb #endif 447011db70b6SBjoern A. Zeeb 447111db70b6SBjoern A. Zeeb /* Encrypt the frame if need be. */ 447211db70b6SBjoern A. Zeeb if (keyix == IEEE80211_KEYIX_NONE) { 44736b4cac81SBjoern A. Zeeb /* Retrieve key for TX && do software encryption. */ 44746b4cac81SBjoern A. Zeeb k = ieee80211_crypto_encap(ni, m); 44756b4cac81SBjoern A. Zeeb if (k == NULL) { 44766b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 44776b4cac81SBjoern A. Zeeb m_freem(m); 44786b4cac81SBjoern A. Zeeb return; 44796b4cac81SBjoern A. Zeeb } 44806b4cac81SBjoern A. Zeeb } 448111db70b6SBjoern A. Zeeb } 44826b4cac81SBjoern A. Zeeb 44836b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 44846b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 44856b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 44866b4cac81SBjoern A. Zeeb c = ni->ni_chan; 44876b4cac81SBjoern A. Zeeb 44886b4cac81SBjoern A. Zeeb if (ieee80211_radiotap_active_vap(ni->ni_vap)) { 44896b4cac81SBjoern A. Zeeb struct lkpi_radiotap_tx_hdr *rtap; 44906b4cac81SBjoern A. Zeeb 44916b4cac81SBjoern A. Zeeb rtap = &lhw->rtap_tx; 44926b4cac81SBjoern A. Zeeb rtap->wt_flags = 0; 44936b4cac81SBjoern A. Zeeb if (k != NULL) 44946b4cac81SBjoern A. Zeeb rtap->wt_flags |= IEEE80211_RADIOTAP_F_WEP; 44956b4cac81SBjoern A. Zeeb if (m->m_flags & M_FRAG) 44966b4cac81SBjoern A. Zeeb rtap->wt_flags |= IEEE80211_RADIOTAP_F_FRAG; 44976b4cac81SBjoern A. Zeeb IMPROVE(); 44986b4cac81SBjoern A. Zeeb rtap->wt_rate = 0; 44996b4cac81SBjoern A. Zeeb if (c != NULL && c != IEEE80211_CHAN_ANYC) { 45006b4cac81SBjoern A. Zeeb rtap->wt_chan_freq = htole16(c->ic_freq); 45016b4cac81SBjoern A. Zeeb rtap->wt_chan_flags = htole16(c->ic_flags); 45026b4cac81SBjoern A. Zeeb } 45036b4cac81SBjoern A. Zeeb 45046b4cac81SBjoern A. Zeeb ieee80211_radiotap_tx(ni->ni_vap, m); 45056b4cac81SBjoern A. Zeeb } 45066b4cac81SBjoern A. Zeeb 45076b4cac81SBjoern A. Zeeb /* 45086b4cac81SBjoern A. Zeeb * net80211 should handle hw->extra_tx_headroom. 45096b4cac81SBjoern A. Zeeb * Though for as long as we are copying we don't mind. 45103d09d310SBjoern A. Zeeb * XXX-BZ rtw88 asks for too much headroom for ipv6+tcp: 45113d09d310SBjoern A. Zeeb * https://lists.freebsd.org/archives/freebsd-transport/2022-February/000012.html 45126b4cac81SBjoern A. Zeeb */ 45136b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + m->m_pkthdr.len); 45146b4cac81SBjoern A. Zeeb if (skb == NULL) { 4515bcf1d8eeSBjoern A. Zeeb static uint8_t skb_alloc_failures = 0; 4516bcf1d8eeSBjoern A. Zeeb 4517bcf1d8eeSBjoern A. Zeeb if (skb_alloc_failures++ == 0) { 4518bcf1d8eeSBjoern A. Zeeb int tid; 4519bcf1d8eeSBjoern A. Zeeb 4520bcf1d8eeSBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 4521bcf1d8eeSBjoern A. Zeeb ic_printf(ic, "ERROR %s: skb alloc failed %d + %d, lsta %p sta %p ni %p\n", 4522bcf1d8eeSBjoern A. Zeeb __func__, hw->extra_tx_headroom, m->m_pkthdr.len, lsta, sta, ni); 4523bcf1d8eeSBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 4524bcf1d8eeSBjoern A. Zeeb if (sta->txq[tid] == NULL) 4525bcf1d8eeSBjoern A. Zeeb continue; 4526bcf1d8eeSBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]); 4527bcf1d8eeSBjoern A. Zeeb ic_printf(ic, " tid %d ltxq %p seen_dequeue %d stopped %d skb_queue_len %u\n", 4528bcf1d8eeSBjoern A. Zeeb tid, ltxq, ltxq->seen_dequeue, ltxq->stopped, skb_queue_len(<xq->skbq)); 4529bcf1d8eeSBjoern A. Zeeb } 4530bcf1d8eeSBjoern A. Zeeb } 45316b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 45326b4cac81SBjoern A. Zeeb m_freem(m); 45336b4cac81SBjoern A. Zeeb return; 45346b4cac81SBjoern A. Zeeb } 45356b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 45366b4cac81SBjoern A. Zeeb 45376b4cac81SBjoern A. Zeeb /* XXX-BZ we need a SKB version understanding mbuf. */ 45386b4cac81SBjoern A. Zeeb /* Save the mbuf for ieee80211_tx_complete(). */ 45396b4cac81SBjoern A. Zeeb skb->m_free_func = lkpi_ieee80211_free_skb_mbuf; 45406b4cac81SBjoern A. Zeeb skb->m = m; 45416b4cac81SBjoern A. Zeeb #if 0 45426b4cac81SBjoern A. Zeeb skb_put_data(skb, m->m_data, m->m_pkthdr.len); 45436b4cac81SBjoern A. Zeeb #else 45446b4cac81SBjoern A. Zeeb buf = skb_put(skb, m->m_pkthdr.len); 45456b4cac81SBjoern A. Zeeb m_copydata(m, 0, m->m_pkthdr.len, buf); 45466b4cac81SBjoern A. Zeeb #endif 45476b4cac81SBjoern A. Zeeb /* Save the ni. */ 45486b4cac81SBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = ni; 45496b4cac81SBjoern A. Zeeb 45506b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(ni->ni_vap); 45516b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 45526b4cac81SBjoern A. Zeeb 4553e3a0b120SBjoern A. Zeeb hdr = (void *)skb->data; 4554e3a0b120SBjoern A. Zeeb tid = linuxkpi_ieee80211_get_tid(hdr, true); 4555e3a0b120SBjoern A. Zeeb if (tid == IEEE80211_NONQOS_TID) { /* == IEEE80211_NUM_TIDS */ 45561665ef97SBjoern A. Zeeb if (!ieee80211_is_data(hdr->frame_control)) { 45571665ef97SBjoern A. Zeeb /* MGMT and CTRL frames go on TID 7/VO. */ 45581665ef97SBjoern A. Zeeb skb->priority = 7; 45591665ef97SBjoern A. Zeeb ac = IEEE80211_AC_VO; 45601665ef97SBjoern A. Zeeb } else { 45611665ef97SBjoern A. Zeeb /* Other non-QOS traffic goes to BE. */ 45621665ef97SBjoern A. Zeeb /* Contrary to net80211 we MUST NOT promote M_EAPOL. */ 4563e3a0b120SBjoern A. Zeeb skb->priority = 0; 4564e3a0b120SBjoern A. Zeeb ac = IEEE80211_AC_BE; 45651665ef97SBjoern A. Zeeb } 4566e3a0b120SBjoern A. Zeeb } else { 4567e3a0b120SBjoern A. Zeeb skb->priority = tid & IEEE80211_QOS_CTL_TID_MASK; 4568fb3c249eSBjoern A. Zeeb ac = ieee80211e_up_to_ac[tid & 7]; 4569e3a0b120SBjoern A. Zeeb } 45706b4cac81SBjoern A. Zeeb skb_set_queue_mapping(skb, ac); 45716b4cac81SBjoern A. Zeeb 45726b4cac81SBjoern A. Zeeb info = IEEE80211_SKB_CB(skb); 45736b4cac81SBjoern A. Zeeb info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; 45746b4cac81SBjoern A. Zeeb /* Slight delay; probably only happens on scanning so fine? */ 45756b4cac81SBjoern A. Zeeb if (c == NULL || c == IEEE80211_CHAN_ANYC) 45766b4cac81SBjoern A. Zeeb c = ic->ic_curchan; 45776b4cac81SBjoern A. Zeeb info->band = lkpi_net80211_chan_to_nl80211_band(c); 4578e3a0b120SBjoern A. Zeeb info->hw_queue = vif->hw_queue[ac]; 45796b4cac81SBjoern A. Zeeb if (m->m_flags & M_EAPOL) 45806b4cac81SBjoern A. Zeeb info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO; 45816b4cac81SBjoern A. Zeeb info->control.vif = vif; 45826b4cac81SBjoern A. Zeeb /* XXX-BZ info->control.rates */ 45839fb91463SBjoern A. Zeeb #ifdef __notyet__ 45849fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 45859fb91463SBjoern A. Zeeb info->control.rts_cts_rate_idx= 45869fb91463SBjoern A. Zeeb info->control.use_rts= /* RTS */ 45879fb91463SBjoern A. Zeeb info->control.use_cts_prot= /* RTS/CTS*/ 45889fb91463SBjoern A. Zeeb #endif 45899fb91463SBjoern A. Zeeb #endif 45906b4cac81SBjoern A. Zeeb 45916b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 4592b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 459311db70b6SBjoern A. Zeeb if (lkpi_hwcrypto && keyix != IEEE80211_KEYIX_NONE) { 459411db70b6SBjoern A. Zeeb int error; 459511db70b6SBjoern A. Zeeb 459611db70b6SBjoern A. Zeeb error = lkpi_hw_crypto_prepare(lsta, k, skb); 459711db70b6SBjoern A. Zeeb if (error != 0) { 459811db70b6SBjoern A. Zeeb /* 459911db70b6SBjoern A. Zeeb * We only have to free the skb which will free the 460011db70b6SBjoern A. Zeeb * mbuf and release the reference on the ni. 460111db70b6SBjoern A. Zeeb */ 460211db70b6SBjoern A. Zeeb dev_kfree_skb(skb); 460311db70b6SBjoern A. Zeeb return; 460411db70b6SBjoern A. Zeeb } 460511db70b6SBjoern A. Zeeb } 46066b4cac81SBjoern A. Zeeb #endif 46076b4cac81SBjoern A. Zeeb 46086b4cac81SBjoern A. Zeeb IMPROVE(); 46096b4cac81SBjoern A. Zeeb 4610e3a0b120SBjoern A. Zeeb ltxq = NULL; 4611e3a0b120SBjoern A. Zeeb if (!ieee80211_is_data_present(hdr->frame_control)) { 4612e3a0b120SBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_STATION && 4613e3a0b120SBjoern A. Zeeb lsta->added_to_drv && 4614e3a0b120SBjoern A. Zeeb sta->txq[IEEE80211_NUM_TIDS] != NULL) 4615d0d29110SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[IEEE80211_NUM_TIDS]); 4616e3a0b120SBjoern A. Zeeb } else if (lsta->added_to_drv && 4617e3a0b120SBjoern A. Zeeb sta->txq[skb->priority] != NULL) { 4618e3a0b120SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[skb->priority]); 4619e3a0b120SBjoern A. Zeeb } 4620e3a0b120SBjoern A. Zeeb if (ltxq == NULL) 4621d0d29110SBjoern A. Zeeb goto ops_tx; 4622e3a0b120SBjoern A. Zeeb 4623d0d29110SBjoern A. Zeeb KASSERT(ltxq != NULL, ("%s: lsta %p sta %p m %p skb %p " 4624d0d29110SBjoern A. Zeeb "ltxq %p != NULL\n", __func__, lsta, sta, m, skb, ltxq)); 4625d0d29110SBjoern A. Zeeb 4626eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_LOCK(ltxq); 46276b4cac81SBjoern A. Zeeb skb_queue_tail(<xq->skbq, skb); 46289d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 46299d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 4630d0d29110SBjoern A. Zeeb printf("%s:%d mo_wake_tx_queue :: %d %u lsta %p sta %p " 4631d0d29110SBjoern A. Zeeb "ni %p %6D skb %p lxtq %p { qlen %u, ac %d tid %u } " 4632d0d29110SBjoern A. Zeeb "WAKE_TX_Q ac %d prio %u qmap %u\n", 4633fb6eaf74SBjoern A. Zeeb __func__, __LINE__, 4634d0d29110SBjoern A. Zeeb curthread->td_tid, (unsigned int)ticks, 4635d0d29110SBjoern A. Zeeb lsta, sta, ni, ni->ni_macaddr, ":", skb, ltxq, 4636d0d29110SBjoern A. Zeeb skb_queue_len(<xq->skbq), ltxq->txq.ac, 4637d0d29110SBjoern A. Zeeb ltxq->txq.tid, ac, skb->priority, skb->qmap); 46389d9ba2b7SBjoern A. Zeeb #endif 4639eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_UNLOCK(ltxq); 464045bce6faSBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 4641d0d29110SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, <xq->txq); 464245bce6faSBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 46436b4cac81SBjoern A. Zeeb return; 46446b4cac81SBjoern A. Zeeb 46456b4cac81SBjoern A. Zeeb ops_tx: 46469d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 46479d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 4648d0d29110SBjoern A. Zeeb printf("%s:%d mo_tx :: lsta %p sta %p ni %p %6D skb %p " 4649d0d29110SBjoern A. Zeeb "TX ac %d prio %u qmap %u\n", 46506b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, sta, ni, ni->ni_macaddr, ":", 46516b4cac81SBjoern A. Zeeb skb, ac, skb->priority, skb->qmap); 46529d9ba2b7SBjoern A. Zeeb #endif 46536b4cac81SBjoern A. Zeeb memset(&control, 0, sizeof(control)); 46546b4cac81SBjoern A. Zeeb control.sta = sta; 465545bce6faSBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 46566b4cac81SBjoern A. Zeeb lkpi_80211_mo_tx(hw, &control, skb); 465745bce6faSBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 46586b4cac81SBjoern A. Zeeb } 46596b4cac81SBjoern A. Zeeb 46606b4cac81SBjoern A. Zeeb static void 46616b4cac81SBjoern A. Zeeb lkpi_80211_txq_task(void *ctx, int pending) 46626b4cac81SBjoern A. Zeeb { 46636b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 46646b4cac81SBjoern A. Zeeb struct mbufq mq; 46656b4cac81SBjoern A. Zeeb struct mbuf *m; 466688665349SBjoern A. Zeeb bool shall_tx; 46676b4cac81SBjoern A. Zeeb 46686b4cac81SBjoern A. Zeeb lsta = ctx; 46696b4cac81SBjoern A. Zeeb 46709d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 46719d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 46726b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p ni %p %6D pending %d mbuf_qlen %d\n", 46739d9ba2b7SBjoern A. Zeeb __func__, __LINE__, lsta, lsta->ni, lsta->ni->ni_macaddr, ":", 46746b4cac81SBjoern A. Zeeb pending, mbufq_len(&lsta->txq)); 46759d9ba2b7SBjoern A. Zeeb #endif 46766b4cac81SBjoern A. Zeeb 46776b4cac81SBjoern A. Zeeb mbufq_init(&mq, IFQ_MAXLEN); 46786b4cac81SBjoern A. Zeeb 4679fa4e4257SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_LOCK(lsta); 4680fa4e4257SBjoern A. Zeeb /* 4681fa4e4257SBjoern A. Zeeb * Do not re-check lsta->txq_ready here; we may have a pending 468288665349SBjoern A. Zeeb * disassoc/deauth frame still. On the contrary if txq_ready is 468388665349SBjoern A. Zeeb * false we do not have a valid sta anymore in the firmware so no 468488665349SBjoern A. Zeeb * point to try to TX. 468588665349SBjoern A. Zeeb * We also use txq_ready as a semaphore and will drain the txq manually 468688665349SBjoern A. Zeeb * if needed on our way towards SCAN/INIT in the state machine. 4687fa4e4257SBjoern A. Zeeb */ 46882372f8ccSBjoern A. Zeeb #if 0 468988665349SBjoern A. Zeeb shall_tx = lsta->added_to_drv && lsta->txq_ready; 46902372f8ccSBjoern A. Zeeb #else 46912372f8ccSBjoern A. Zeeb /* 46922372f8ccSBjoern A. Zeeb * Backout this part of 886653492945f which breaks rtw88 or 46932372f8ccSBjoern A. Zeeb * in general drivers without (*sta_state)() but only the 46942372f8ccSBjoern A. Zeeb * legacy fallback to (*sta_add)(). 46952372f8ccSBjoern A. Zeeb */ 46962372f8ccSBjoern A. Zeeb shall_tx = lsta->txq_ready; 46972372f8ccSBjoern A. Zeeb #endif 469888665349SBjoern A. Zeeb if (__predict_true(shall_tx)) 46996b4cac81SBjoern A. Zeeb mbufq_concat(&mq, &lsta->txq); 470088665349SBjoern A. Zeeb /* 470188665349SBjoern A. Zeeb * else a state change will push the packets out manually or 470288665349SBjoern A. Zeeb * lkpi_lsta_free() will drain the lsta->txq and free the mbufs. 470388665349SBjoern A. Zeeb */ 4704fa4e4257SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_UNLOCK(lsta); 47056b4cac81SBjoern A. Zeeb 47066b4cac81SBjoern A. Zeeb m = mbufq_dequeue(&mq); 47076b4cac81SBjoern A. Zeeb while (m != NULL) { 47086b4cac81SBjoern A. Zeeb lkpi_80211_txq_tx_one(lsta, m); 47096b4cac81SBjoern A. Zeeb m = mbufq_dequeue(&mq); 47106b4cac81SBjoern A. Zeeb } 47116b4cac81SBjoern A. Zeeb } 47126b4cac81SBjoern A. Zeeb 47136b4cac81SBjoern A. Zeeb static int 47146b4cac81SBjoern A. Zeeb lkpi_ic_transmit(struct ieee80211com *ic, struct mbuf *m) 47156b4cac81SBjoern A. Zeeb { 47166b4cac81SBjoern A. Zeeb 47176b4cac81SBjoern A. Zeeb /* XXX TODO */ 47186b4cac81SBjoern A. Zeeb IMPROVE(); 47196b4cac81SBjoern A. Zeeb 47206b4cac81SBjoern A. Zeeb /* Quick and dirty cheating hack. */ 47216b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 47226b4cac81SBjoern A. Zeeb 47236b4cac81SBjoern A. Zeeb ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; 47246b4cac81SBjoern A. Zeeb return (lkpi_ic_raw_xmit(ni, m, NULL)); 47256b4cac81SBjoern A. Zeeb } 47266b4cac81SBjoern A. Zeeb 47279fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 47289fb91463SBjoern A. Zeeb static int 47299fb91463SBjoern A. Zeeb lkpi_ic_recv_action(struct ieee80211_node *ni, const struct ieee80211_frame *wh, 47309fb91463SBjoern A. Zeeb const uint8_t *frm, const uint8_t *efrm) 47319fb91463SBjoern A. Zeeb { 47329fb91463SBjoern A. Zeeb struct ieee80211com *ic; 47339fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 47349fb91463SBjoern A. Zeeb 47359fb91463SBjoern A. Zeeb ic = ni->ni_ic; 47369fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 47379fb91463SBjoern A. Zeeb 4738310743c4SBjoern A. Zeeb IMPROVE_HT("recv_action called; nothing to do in lkpi; make debugging"); 47399fb91463SBjoern A. Zeeb 47409fb91463SBjoern A. Zeeb return (lhw->ic_recv_action(ni, wh, frm, efrm)); 47419fb91463SBjoern A. Zeeb } 47429fb91463SBjoern A. Zeeb 47439fb91463SBjoern A. Zeeb static int 47449fb91463SBjoern A. Zeeb lkpi_ic_send_action(struct ieee80211_node *ni, int category, int action, void *sa) 47459fb91463SBjoern A. Zeeb { 47469fb91463SBjoern A. Zeeb struct ieee80211com *ic; 47479fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 47489fb91463SBjoern A. Zeeb 47499fb91463SBjoern A. Zeeb ic = ni->ni_ic; 47509fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 47519fb91463SBjoern A. Zeeb 4752310743c4SBjoern A. Zeeb IMPROVE_HT("send_action called; nothing to do in lkpi; make debugging"); 47539fb91463SBjoern A. Zeeb 47549fb91463SBjoern A. Zeeb return (lhw->ic_send_action(ni, category, action, sa)); 47559fb91463SBjoern A. Zeeb } 47569fb91463SBjoern A. Zeeb 47579fb91463SBjoern A. Zeeb 47589fb91463SBjoern A. Zeeb static int 47599fb91463SBjoern A. Zeeb lkpi_ic_ampdu_enable(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap) 47609fb91463SBjoern A. Zeeb { 47619fb91463SBjoern A. Zeeb struct ieee80211com *ic; 47629fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 47639fb91463SBjoern A. Zeeb 47649fb91463SBjoern A. Zeeb ic = ni->ni_ic; 47659fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 47669fb91463SBjoern A. Zeeb 4767310743c4SBjoern A. Zeeb IMPROVE_HT("ieee80211_ampdu_enable called; nothing to do in lkpi for now; make debugging"); 47689fb91463SBjoern A. Zeeb 47699fb91463SBjoern A. Zeeb return (lhw->ic_ampdu_enable(ni, tap)); 47709fb91463SBjoern A. Zeeb } 47719fb91463SBjoern A. Zeeb 4772310743c4SBjoern A. Zeeb /* 4773310743c4SBjoern A. Zeeb * (*ic_addba_request)() is called by ieee80211_ampdu_request() before 4774310743c4SBjoern A. Zeeb * calling send_action(CAT_BA, BA_ADDBA_REQUEST). 4775310743c4SBjoern A. Zeeb * 4776310743c4SBjoern A. Zeeb * NB: returns 0 on ERROR! 4777310743c4SBjoern A. Zeeb */ 47789fb91463SBjoern A. Zeeb static int 47799fb91463SBjoern A. Zeeb lkpi_ic_addba_request(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 47809fb91463SBjoern A. Zeeb int dialogtoken, int baparamset, int batimeout) 47819fb91463SBjoern A. Zeeb { 47829fb91463SBjoern A. Zeeb struct ieee80211com *ic; 47839fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 4784310743c4SBjoern A. Zeeb struct ieee80211_hw *hw; 4785310743c4SBjoern A. Zeeb struct ieee80211vap *vap; 4786310743c4SBjoern A. Zeeb struct lkpi_vif *lvif; 4787310743c4SBjoern A. Zeeb struct ieee80211_vif *vif; 4788310743c4SBjoern A. Zeeb struct lkpi_sta *lsta; 4789310743c4SBjoern A. Zeeb struct ieee80211_sta *sta; 4790310743c4SBjoern A. Zeeb struct ieee80211_ampdu_params params = { }; 4791310743c4SBjoern A. Zeeb int error; 47929fb91463SBjoern A. Zeeb 47939fb91463SBjoern A. Zeeb ic = ni->ni_ic; 47949fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 4795310743c4SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 4796310743c4SBjoern A. Zeeb vap = ni->ni_vap; 4797310743c4SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 4798310743c4SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 4799310743c4SBjoern A. Zeeb lsta = ni->ni_drv_data; 4800310743c4SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 48019fb91463SBjoern A. Zeeb 4802310743c4SBjoern A. Zeeb if (!lsta->added_to_drv) { 4803310743c4SBjoern A. Zeeb ic_printf(ic, "%s: lsta %p ni %p, sta %p not added to firmware\n", 4804310743c4SBjoern A. Zeeb __func__, lsta, ni, sta); 4805310743c4SBjoern A. Zeeb return (0); 4806310743c4SBjoern A. Zeeb } 4807310743c4SBjoern A. Zeeb 4808310743c4SBjoern A. Zeeb params.sta = sta; 4809310743c4SBjoern A. Zeeb params.action = IEEE80211_AMPDU_TX_START; 4810310743c4SBjoern A. Zeeb /* Keep 0 here! */ 4811310743c4SBjoern A. Zeeb params.buf_size = 0; 4812310743c4SBjoern A. Zeeb params.timeout = 0; 4813310743c4SBjoern A. Zeeb params.ssn = tap->txa_start & (IEEE80211_SEQ_RANGE-1); 4814310743c4SBjoern A. Zeeb params.tid = tap->txa_tid; 4815310743c4SBjoern A. Zeeb params.amsdu = false; 4816310743c4SBjoern A. Zeeb 4817310743c4SBjoern A. Zeeb IEEE80211_UNLOCK(ic); 4818310743c4SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 4819310743c4SBjoern A. Zeeb error = lkpi_80211_mo_ampdu_action(hw, vif, ¶ms); 4820310743c4SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 4821310743c4SBjoern A. Zeeb IEEE80211_LOCK(ic); 4822310743c4SBjoern A. Zeeb if (error != 0) { 4823310743c4SBjoern A. Zeeb ic_printf(ic, "%s: mo_ampdu_action returned %d. ni %p tap %p\n", 4824310743c4SBjoern A. Zeeb __func__, error, ni, tap); 4825310743c4SBjoern A. Zeeb return (0); 4826310743c4SBjoern A. Zeeb } 48279fb91463SBjoern A. Zeeb 48289fb91463SBjoern A. Zeeb return (lhw->ic_addba_request(ni, tap, dialogtoken, baparamset, batimeout)); 48299fb91463SBjoern A. Zeeb } 48309fb91463SBjoern A. Zeeb 4831310743c4SBjoern A. Zeeb /* 4832310743c4SBjoern A. Zeeb * (*ic_addba_response)() is called from ht_recv_action_ba_addba_response() 4833310743c4SBjoern A. Zeeb * and calls the default ieee80211_addba_response() which always returns 1. 4834310743c4SBjoern A. Zeeb * 4835310743c4SBjoern A. Zeeb * NB: No error checking in net80211! 4836310743c4SBjoern A. Zeeb * Staying with 0 is an error. 4837310743c4SBjoern A. Zeeb */ 48389fb91463SBjoern A. Zeeb static int 48399fb91463SBjoern A. Zeeb lkpi_ic_addba_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 48409fb91463SBjoern A. Zeeb int status, int baparamset, int batimeout) 48419fb91463SBjoern A. Zeeb { 48429fb91463SBjoern A. Zeeb struct ieee80211com *ic; 48439fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 4844310743c4SBjoern A. Zeeb struct ieee80211_hw *hw; 4845310743c4SBjoern A. Zeeb struct ieee80211vap *vap; 4846310743c4SBjoern A. Zeeb struct lkpi_vif *lvif; 4847310743c4SBjoern A. Zeeb struct ieee80211_vif *vif; 4848310743c4SBjoern A. Zeeb struct lkpi_sta *lsta; 4849310743c4SBjoern A. Zeeb struct ieee80211_sta *sta; 4850310743c4SBjoern A. Zeeb struct ieee80211_ampdu_params params = { }; 4851310743c4SBjoern A. Zeeb int error; 48529fb91463SBjoern A. Zeeb 48539fb91463SBjoern A. Zeeb ic = ni->ni_ic; 48549fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 4855310743c4SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 4856310743c4SBjoern A. Zeeb vap = ni->ni_vap; 4857310743c4SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 4858310743c4SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 4859310743c4SBjoern A. Zeeb lsta = ni->ni_drv_data; 4860310743c4SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 48619fb91463SBjoern A. Zeeb 4862310743c4SBjoern A. Zeeb if (!lsta->added_to_drv) { 4863310743c4SBjoern A. Zeeb ic_printf(ic, "%s: lsta %p ni %p, sta %p not added to firmware\n", 4864310743c4SBjoern A. Zeeb __func__, lsta, ni, sta); 4865310743c4SBjoern A. Zeeb return (0); 4866310743c4SBjoern A. Zeeb } 4867310743c4SBjoern A. Zeeb 4868310743c4SBjoern A. Zeeb if (status == IEEE80211_STATUS_SUCCESS) { 4869310743c4SBjoern A. Zeeb params.sta = sta; 4870310743c4SBjoern A. Zeeb params.action = IEEE80211_AMPDU_TX_OPERATIONAL; 4871310743c4SBjoern A. Zeeb params.buf_size = tap->txa_wnd; 4872310743c4SBjoern A. Zeeb params.timeout = 0; 4873310743c4SBjoern A. Zeeb params.ssn = 0; 4874310743c4SBjoern A. Zeeb params.tid = tap->txa_tid; 4875310743c4SBjoern A. Zeeb if ((tap->txa_flags & IEEE80211_AGGR_AMSDU) != 0) 4876310743c4SBjoern A. Zeeb params.amsdu = true; 4877310743c4SBjoern A. Zeeb else 4878310743c4SBjoern A. Zeeb params.amsdu = false; 4879310743c4SBjoern A. Zeeb } else { 4880310743c4SBjoern A. Zeeb /* We need to free the allocated resources. */ 4881310743c4SBjoern A. Zeeb params.sta = sta; 4882310743c4SBjoern A. Zeeb switch (status) { 4883310743c4SBjoern A. Zeeb /* params.action = FLUSH, FLUSH_CONT */ 4884310743c4SBjoern A. Zeeb default: 4885310743c4SBjoern A. Zeeb params.action = IEEE80211_AMPDU_TX_STOP_CONT; 4886310743c4SBjoern A. Zeeb break; 4887310743c4SBjoern A. Zeeb } 4888310743c4SBjoern A. Zeeb params.buf_size = 0; 4889310743c4SBjoern A. Zeeb params.timeout = 0; 4890310743c4SBjoern A. Zeeb params.ssn = 0; 4891310743c4SBjoern A. Zeeb params.tid = tap->txa_tid; 4892310743c4SBjoern A. Zeeb params.amsdu = false; 4893310743c4SBjoern A. Zeeb } 4894310743c4SBjoern A. Zeeb 4895310743c4SBjoern A. Zeeb IEEE80211_UNLOCK(ic); 4896310743c4SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 4897310743c4SBjoern A. Zeeb error = lkpi_80211_mo_ampdu_action(hw, vif, ¶ms); 4898310743c4SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 4899310743c4SBjoern A. Zeeb IEEE80211_LOCK(ic); 4900310743c4SBjoern A. Zeeb if (error != 0) { 4901310743c4SBjoern A. Zeeb ic_printf(ic, "%s: mo_ampdu_action returned %d. ni %p tap %p\n", 4902310743c4SBjoern A. Zeeb __func__, error, ni, tap); 4903310743c4SBjoern A. Zeeb return (0); 4904310743c4SBjoern A. Zeeb } 4905310743c4SBjoern A. Zeeb 4906310743c4SBjoern A. Zeeb IMPROVE_HT("who unleashes the TXQ? and when?, do we need to ni->ni_txseqs[tid] = tap->txa_start & 0xfff;"); 49079fb91463SBjoern A. Zeeb 49089fb91463SBjoern A. Zeeb return (lhw->ic_addba_response(ni, tap, status, baparamset, batimeout)); 49099fb91463SBjoern A. Zeeb } 49109fb91463SBjoern A. Zeeb 4911310743c4SBjoern A. Zeeb /* 4912310743c4SBjoern A. Zeeb * (*ic_addba_stop)() is called from ampdu_tx_stop(), ht_recv_action_ba_delba(), 4913310743c4SBjoern A. Zeeb * and ieee80211_ampdu_stop() and calls the default ieee80211_addba_stop(). 4914310743c4SBjoern A. Zeeb */ 49159fb91463SBjoern A. Zeeb static void 49169fb91463SBjoern A. Zeeb lkpi_ic_addba_stop(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap) 49179fb91463SBjoern A. Zeeb { 49189fb91463SBjoern A. Zeeb struct ieee80211com *ic; 49199fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 4920310743c4SBjoern A. Zeeb struct ieee80211_hw *hw; 4921310743c4SBjoern A. Zeeb struct ieee80211vap *vap; 4922310743c4SBjoern A. Zeeb struct lkpi_vif *lvif; 4923310743c4SBjoern A. Zeeb struct ieee80211_vif *vif; 4924310743c4SBjoern A. Zeeb struct lkpi_sta *lsta; 4925310743c4SBjoern A. Zeeb struct ieee80211_sta *sta; 4926310743c4SBjoern A. Zeeb struct ieee80211_ampdu_params params = { }; 4927310743c4SBjoern A. Zeeb int error; 49289fb91463SBjoern A. Zeeb 49299fb91463SBjoern A. Zeeb ic = ni->ni_ic; 49309fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 4931310743c4SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 4932310743c4SBjoern A. Zeeb vap = ni->ni_vap; 4933310743c4SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 4934310743c4SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 4935310743c4SBjoern A. Zeeb lsta = ni->ni_drv_data; 4936310743c4SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 49379fb91463SBjoern A. Zeeb 4938310743c4SBjoern A. Zeeb if (!lsta->added_to_drv) { 4939310743c4SBjoern A. Zeeb ic_printf(ic, "%s: lsta %p ni %p, sta %p not added to firmware\n", 4940310743c4SBjoern A. Zeeb __func__, lsta, ni, sta); 4941310743c4SBjoern A. Zeeb goto n80211; 4942310743c4SBjoern A. Zeeb } 49439fb91463SBjoern A. Zeeb 4944310743c4SBjoern A. Zeeb /* We need to free the allocated resources. */ 4945310743c4SBjoern A. Zeeb params.sta = sta; 4946310743c4SBjoern A. Zeeb IMPROVE("net80211 does not provide a reason to us"); 4947310743c4SBjoern A. Zeeb params.action = IEEE80211_AMPDU_TX_STOP_CONT; /* params.action = FLUSH, FLUSH_CONT */ 4948310743c4SBjoern A. Zeeb params.buf_size = 0; 4949310743c4SBjoern A. Zeeb params.timeout = 0; 4950310743c4SBjoern A. Zeeb params.ssn = 0; 4951310743c4SBjoern A. Zeeb params.tid = tap->txa_tid; 4952310743c4SBjoern A. Zeeb params.amsdu = false; 4953310743c4SBjoern A. Zeeb 4954310743c4SBjoern A. Zeeb IEEE80211_UNLOCK(ic); 4955310743c4SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 4956310743c4SBjoern A. Zeeb error = lkpi_80211_mo_ampdu_action(hw, vif, ¶ms); 4957310743c4SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 4958310743c4SBjoern A. Zeeb IEEE80211_LOCK(ic); 4959310743c4SBjoern A. Zeeb if (error != 0) { 4960310743c4SBjoern A. Zeeb ic_printf(ic, "%s: mo_ampdu_action returned %d. ni %p tap %p\n", 4961310743c4SBjoern A. Zeeb __func__, error, ni, tap); 4962310743c4SBjoern A. Zeeb goto n80211; 4963310743c4SBjoern A. Zeeb } 4964310743c4SBjoern A. Zeeb 4965310743c4SBjoern A. Zeeb IMPROVE_HT("anyting else?"); 4966310743c4SBjoern A. Zeeb 4967310743c4SBjoern A. Zeeb n80211: 49689fb91463SBjoern A. Zeeb lhw->ic_addba_stop(ni, tap); 49699fb91463SBjoern A. Zeeb } 49709fb91463SBjoern A. Zeeb 49719fb91463SBjoern A. Zeeb static void 49729fb91463SBjoern A. Zeeb lkpi_ic_addba_response_timeout(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap) 49739fb91463SBjoern A. Zeeb { 49749fb91463SBjoern A. Zeeb struct ieee80211com *ic; 49759fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 49769fb91463SBjoern A. Zeeb 49779fb91463SBjoern A. Zeeb ic = ni->ni_ic; 49789fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 49799fb91463SBjoern A. Zeeb 49809fb91463SBjoern A. Zeeb IMPROVE_HT(); 49819fb91463SBjoern A. Zeeb 49829fb91463SBjoern A. Zeeb lhw->ic_addba_response_timeout(ni, tap); 49839fb91463SBjoern A. Zeeb } 49849fb91463SBjoern A. Zeeb 49859fb91463SBjoern A. Zeeb static void 49869fb91463SBjoern A. Zeeb lkpi_ic_bar_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 49879fb91463SBjoern A. Zeeb int status) 49889fb91463SBjoern A. Zeeb { 49899fb91463SBjoern A. Zeeb struct ieee80211com *ic; 49909fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 49919fb91463SBjoern A. Zeeb 49929fb91463SBjoern A. Zeeb ic = ni->ni_ic; 49939fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 49949fb91463SBjoern A. Zeeb 49959fb91463SBjoern A. Zeeb IMPROVE_HT(); 49969fb91463SBjoern A. Zeeb 49979fb91463SBjoern A. Zeeb lhw->ic_bar_response(ni, tap, status); 49989fb91463SBjoern A. Zeeb } 49999fb91463SBjoern A. Zeeb 50009fb91463SBjoern A. Zeeb static int 50019fb91463SBjoern A. Zeeb lkpi_ic_ampdu_rx_start(struct ieee80211_node *ni, struct ieee80211_rx_ampdu *rap, 50029fb91463SBjoern A. Zeeb int baparamset, int batimeout, int baseqctl) 50039fb91463SBjoern A. Zeeb { 50049fb91463SBjoern A. Zeeb struct ieee80211com *ic; 50059fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 50069fb91463SBjoern A. Zeeb struct ieee80211_hw *hw; 50079fb91463SBjoern A. Zeeb struct ieee80211vap *vap; 50089fb91463SBjoern A. Zeeb struct lkpi_vif *lvif; 50099fb91463SBjoern A. Zeeb struct ieee80211_vif *vif; 50109fb91463SBjoern A. Zeeb struct lkpi_sta *lsta; 50119fb91463SBjoern A. Zeeb struct ieee80211_sta *sta; 5012310743c4SBjoern A. Zeeb struct ieee80211_ampdu_params params = { }; 50139fb91463SBjoern A. Zeeb int error; 50149fb91463SBjoern A. Zeeb 50159fb91463SBjoern A. Zeeb ic = ni->ni_ic; 50169fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 50179fb91463SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 50189fb91463SBjoern A. Zeeb vap = ni->ni_vap; 50199fb91463SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 50209fb91463SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 50219fb91463SBjoern A. Zeeb lsta = ni->ni_drv_data; 50229fb91463SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 50239fb91463SBjoern A. Zeeb 5024310743c4SBjoern A. Zeeb IEEE80211_UNLOCK_ASSERT(ic); 5025310743c4SBjoern A. Zeeb 5026310743c4SBjoern A. Zeeb if (!lsta->added_to_drv) { 5027310743c4SBjoern A. Zeeb ic_printf(ic, "%s: lsta %p ni %p vap %p, sta %p not added to firmware\n", 5028310743c4SBjoern A. Zeeb __func__, lsta, ni, vap, sta); 5029310743c4SBjoern A. Zeeb return (-ENXIO); 5030310743c4SBjoern A. Zeeb } 5031310743c4SBjoern A. Zeeb 50329fb91463SBjoern A. Zeeb params.sta = sta; 50339fb91463SBjoern A. Zeeb params.action = IEEE80211_AMPDU_RX_START; 50349fb91463SBjoern A. Zeeb params.buf_size = _IEEE80211_MASKSHIFT(le16toh(baparamset), IEEE80211_BAPS_BUFSIZ); 50359fb91463SBjoern A. Zeeb if (params.buf_size == 0) 50369fb91463SBjoern A. Zeeb params.buf_size = IEEE80211_MAX_AMPDU_BUF_HT; 50379fb91463SBjoern A. Zeeb else 50389fb91463SBjoern A. Zeeb params.buf_size = min(params.buf_size, IEEE80211_MAX_AMPDU_BUF_HT); 5039310743c4SBjoern A. Zeeb if (hw->max_rx_aggregation_subframes > 0 && 5040310743c4SBjoern A. Zeeb params.buf_size > hw->max_rx_aggregation_subframes) 50419fb91463SBjoern A. Zeeb params.buf_size = hw->max_rx_aggregation_subframes; 50429fb91463SBjoern A. Zeeb params.timeout = le16toh(batimeout); 50439fb91463SBjoern A. Zeeb params.ssn = _IEEE80211_MASKSHIFT(le16toh(baseqctl), IEEE80211_BASEQ_START); 50449fb91463SBjoern A. Zeeb params.tid = _IEEE80211_MASKSHIFT(le16toh(baparamset), IEEE80211_BAPS_TID); 5045310743c4SBjoern A. Zeeb 5046310743c4SBjoern A. Zeeb /* Based on net80211::ampdu_rx_start(). */ 5047310743c4SBjoern A. Zeeb if ((vap->iv_htcaps & IEEE80211_HTC_RX_AMSDU_AMPDU) && 5048310743c4SBjoern A. Zeeb (_IEEE80211_MASKSHIFT(baparamset, IEEE80211_BAPS_AMSDU))) 5049310743c4SBjoern A. Zeeb params.amsdu = true; 5050310743c4SBjoern A. Zeeb else 50519fb91463SBjoern A. Zeeb params.amsdu = false; 50529fb91463SBjoern A. Zeeb 5053310743c4SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 50549fb91463SBjoern A. Zeeb error = lkpi_80211_mo_ampdu_action(hw, vif, ¶ms); 5055310743c4SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 50569fb91463SBjoern A. Zeeb if (error != 0) { 50579fb91463SBjoern A. Zeeb ic_printf(ic, "%s: mo_ampdu_action returned %d. ni %p rap %p\n", 50589fb91463SBjoern A. Zeeb __func__, error, ni, rap); 50599fb91463SBjoern A. Zeeb return (error); 50609fb91463SBjoern A. Zeeb } 5061310743c4SBjoern A. Zeeb 5062310743c4SBjoern A. Zeeb if (!ieee80211_hw_check(hw, SUPPORTS_REORDERING_BUFFER)) { 5063310743c4SBjoern A. Zeeb IMPROVE("%s: TODO: SUPPORTS_REORDERING_BUFFER not set; check net80211\n", __func__); 5064310743c4SBjoern A. Zeeb } 5065310743c4SBjoern A. Zeeb 50669fb91463SBjoern A. Zeeb IMPROVE_HT("net80211 is missing the error check on return and assumes success"); 50679fb91463SBjoern A. Zeeb 50689fb91463SBjoern A. Zeeb error = lhw->ic_ampdu_rx_start(ni, rap, baparamset, batimeout, baseqctl); 50699fb91463SBjoern A. Zeeb return (error); 50709fb91463SBjoern A. Zeeb } 50719fb91463SBjoern A. Zeeb 50729fb91463SBjoern A. Zeeb static void 50739fb91463SBjoern A. Zeeb lkpi_ic_ampdu_rx_stop(struct ieee80211_node *ni, struct ieee80211_rx_ampdu *rap) 50749fb91463SBjoern A. Zeeb { 50759fb91463SBjoern A. Zeeb struct ieee80211com *ic; 50769fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 50779fb91463SBjoern A. Zeeb struct ieee80211_hw *hw; 50789fb91463SBjoern A. Zeeb struct ieee80211vap *vap; 50799fb91463SBjoern A. Zeeb struct lkpi_vif *lvif; 50809fb91463SBjoern A. Zeeb struct ieee80211_vif *vif; 50819fb91463SBjoern A. Zeeb struct lkpi_sta *lsta; 50829fb91463SBjoern A. Zeeb struct ieee80211_sta *sta; 5083310743c4SBjoern A. Zeeb struct ieee80211_ampdu_params params = { }; 50849fb91463SBjoern A. Zeeb int error; 50859fb91463SBjoern A. Zeeb uint8_t tid; 508665c573e4SBjoern A. Zeeb bool ic_locked; 50879fb91463SBjoern A. Zeeb 50889fb91463SBjoern A. Zeeb ic = ni->ni_ic; 50899fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 50909fb91463SBjoern A. Zeeb 50919fb91463SBjoern A. Zeeb /* 50929fb91463SBjoern A. Zeeb * We should not (cannot) call into mac80211 ops with AMPDU_RX_STOP if 50939fb91463SBjoern A. Zeeb * we did not START. Some drivers pass it down to firmware which will 50949fb91463SBjoern A. Zeeb * simply barf and net80211 calls ieee80211_ht_node_cleanup() from 50959fb91463SBjoern A. Zeeb * ieee80211_ht_node_init() amongst others which will iterate over all 50969fb91463SBjoern A. Zeeb * tid and call ic_ampdu_rx_stop() unconditionally. 50979fb91463SBjoern A. Zeeb * XXX net80211 should probably be more "gentle" in these cases and 50989fb91463SBjoern A. Zeeb * track some state itself. 50999fb91463SBjoern A. Zeeb */ 51009fb91463SBjoern A. Zeeb if ((rap->rxa_flags & IEEE80211_AGGR_RUNNING) == 0) 51019fb91463SBjoern A. Zeeb goto net80211_only; 51029fb91463SBjoern A. Zeeb 51039fb91463SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 51049fb91463SBjoern A. Zeeb vap = ni->ni_vap; 51059fb91463SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 51069fb91463SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 51079fb91463SBjoern A. Zeeb lsta = ni->ni_drv_data; 51089fb91463SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 51099fb91463SBjoern A. Zeeb 51109fb91463SBjoern A. Zeeb IMPROVE_HT("This really should be passed from ht_recv_action_ba_delba."); 51119fb91463SBjoern A. Zeeb for (tid = 0; tid < WME_NUM_TID; tid++) { 51129fb91463SBjoern A. Zeeb if (&ni->ni_rx_ampdu[tid] == rap) 51139fb91463SBjoern A. Zeeb break; 51149fb91463SBjoern A. Zeeb } 51159fb91463SBjoern A. Zeeb 51169fb91463SBjoern A. Zeeb params.sta = sta; 51179fb91463SBjoern A. Zeeb params.action = IEEE80211_AMPDU_RX_STOP; 51189fb91463SBjoern A. Zeeb params.buf_size = 0; 51199fb91463SBjoern A. Zeeb params.timeout = 0; 51209fb91463SBjoern A. Zeeb params.ssn = 0; 51219fb91463SBjoern A. Zeeb params.tid = tid; 51229fb91463SBjoern A. Zeeb params.amsdu = false; 51239fb91463SBjoern A. Zeeb 512465c573e4SBjoern A. Zeeb ic_locked = IEEE80211_IS_LOCKED(ic); 512565c573e4SBjoern A. Zeeb if (ic_locked) 512665c573e4SBjoern A. Zeeb IEEE80211_UNLOCK(ic); 5127310743c4SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 51289fb91463SBjoern A. Zeeb error = lkpi_80211_mo_ampdu_action(hw, vif, ¶ms); 5129310743c4SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 513065c573e4SBjoern A. Zeeb if (ic_locked) 513165c573e4SBjoern A. Zeeb IEEE80211_LOCK(ic); 51329fb91463SBjoern A. Zeeb if (error != 0) 51339fb91463SBjoern A. Zeeb ic_printf(ic, "%s: mo_ampdu_action returned %d. ni %p rap %p\n", 51349fb91463SBjoern A. Zeeb __func__, error, ni, rap); 51359fb91463SBjoern A. Zeeb 51369fb91463SBjoern A. Zeeb net80211_only: 51379fb91463SBjoern A. Zeeb lhw->ic_ampdu_rx_stop(ni, rap); 51389fb91463SBjoern A. Zeeb } 51399fb91463SBjoern A. Zeeb #endif 51409fb91463SBjoern A. Zeeb 51419fb91463SBjoern A. Zeeb static void 51429fb91463SBjoern A. Zeeb lkpi_ic_getradiocaps_ht(struct ieee80211com *ic, struct ieee80211_hw *hw, 51439fb91463SBjoern A. Zeeb uint8_t *bands, int *chan_flags, enum nl80211_band band) 51449fb91463SBjoern A. Zeeb { 51459fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 51469fb91463SBjoern A. Zeeb struct ieee80211_sta_ht_cap *ht_cap; 51479fb91463SBjoern A. Zeeb 51489fb91463SBjoern A. Zeeb ht_cap = &hw->wiphy->bands[band]->ht_cap; 51499fb91463SBjoern A. Zeeb if (!ht_cap->ht_supported) 51509fb91463SBjoern A. Zeeb return; 51519fb91463SBjoern A. Zeeb 51529fb91463SBjoern A. Zeeb switch (band) { 51539fb91463SBjoern A. Zeeb case NL80211_BAND_2GHZ: 51549fb91463SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11NG); 51559fb91463SBjoern A. Zeeb break; 51569fb91463SBjoern A. Zeeb case NL80211_BAND_5GHZ: 51579fb91463SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11NA); 51589fb91463SBjoern A. Zeeb break; 51599fb91463SBjoern A. Zeeb default: 51609fb91463SBjoern A. Zeeb IMPROVE("Unsupported band %d", band); 51619fb91463SBjoern A. Zeeb return; 51629fb91463SBjoern A. Zeeb } 51639fb91463SBjoern A. Zeeb 51649fb91463SBjoern A. Zeeb ic->ic_htcaps = IEEE80211_HTC_HT; /* HT operation */ 51659fb91463SBjoern A. Zeeb 51669fb91463SBjoern A. Zeeb /* 51679fb91463SBjoern A. Zeeb * Rather than manually checking each flag and 51689fb91463SBjoern A. Zeeb * translating IEEE80211_HT_CAP_ to IEEE80211_HTCAP_, 51699fb91463SBjoern A. Zeeb * simply copy the 16bits. 51709fb91463SBjoern A. Zeeb */ 51719fb91463SBjoern A. Zeeb ic->ic_htcaps |= ht_cap->cap; 51729fb91463SBjoern A. Zeeb 51739fb91463SBjoern A. Zeeb /* Then deal with the other flags. */ 51749fb91463SBjoern A. Zeeb if (ieee80211_hw_check(hw, AMPDU_AGGREGATION)) 51759fb91463SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTC_AMPDU; 51769fb91463SBjoern A. Zeeb #ifdef __notyet__ 51779fb91463SBjoern A. Zeeb if (ieee80211_hw_check(hw, TX_AMSDU)) 51789fb91463SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTC_AMSDU; 51799fb91463SBjoern A. Zeeb if (ieee80211_hw_check(hw, SUPPORTS_AMSDU_IN_AMPDU)) 51809fb91463SBjoern A. Zeeb ic->ic_htcaps |= (IEEE80211_HTC_RX_AMSDU_AMPDU | 51819fb91463SBjoern A. Zeeb IEEE80211_HTC_TX_AMSDU_AMPDU); 51829fb91463SBjoern A. Zeeb #endif 51839fb91463SBjoern A. Zeeb 51849fb91463SBjoern A. Zeeb IMPROVE("PS, ampdu_*, ht_cap.mcs.tx_params, ..."); 51859fb91463SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_SMPS_OFF; 51869fb91463SBjoern A. Zeeb 51879fb91463SBjoern A. Zeeb /* Only add HT40 channels if supported. */ 51889fb91463SBjoern A. Zeeb if ((ic->ic_htcaps & IEEE80211_HTCAP_CHWIDTH40) != 0 && 51899fb91463SBjoern A. Zeeb chan_flags != NULL) 51909fb91463SBjoern A. Zeeb *chan_flags |= NET80211_CBW_FLAG_HT40; 51919fb91463SBjoern A. Zeeb #endif 51929fb91463SBjoern A. Zeeb } 51939fb91463SBjoern A. Zeeb 51946b4cac81SBjoern A. Zeeb static void 51956b4cac81SBjoern A. Zeeb lkpi_ic_getradiocaps(struct ieee80211com *ic, int maxchan, 51966b4cac81SBjoern A. Zeeb int *n, struct ieee80211_channel *c) 51976b4cac81SBjoern A. Zeeb { 51986b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 51996b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 52006b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 52016b4cac81SBjoern A. Zeeb uint8_t bands[IEEE80211_MODE_BYTES]; 52026b4cac81SBjoern A. Zeeb int chan_flags, error, i, nchans; 52036b4cac81SBjoern A. Zeeb 52046b4cac81SBjoern A. Zeeb /* Channels */ 52056b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 52066b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 52076b4cac81SBjoern A. Zeeb 52086b4cac81SBjoern A. Zeeb /* NL80211_BAND_2GHZ */ 52096b4cac81SBjoern A. Zeeb nchans = 0; 52106b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_2GHZ] != NULL) 52116b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[NL80211_BAND_2GHZ]->n_channels; 52126b4cac81SBjoern A. Zeeb if (nchans > 0) { 52136b4cac81SBjoern A. Zeeb memset(bands, 0, sizeof(bands)); 52146b4cac81SBjoern A. Zeeb chan_flags = 0; 52156b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11B); 52166b4cac81SBjoern A. Zeeb /* XXX-BZ unclear how to check for 11g. */ 52179fb91463SBjoern A. Zeeb 52189fb91463SBjoern A. Zeeb IMPROVE("the bitrates may have flags?"); 52196b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11G); 52209fb91463SBjoern A. Zeeb 52219fb91463SBjoern A. Zeeb lkpi_ic_getradiocaps_ht(ic, hw, bands, &chan_flags, 52229fb91463SBjoern A. Zeeb NL80211_BAND_2GHZ); 52236b4cac81SBjoern A. Zeeb 52246b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[NL80211_BAND_2GHZ]->channels; 5225cee56e77SBjoern A. Zeeb for (i = 0; i < nchans && *n < maxchan; i++) { 52266b4cac81SBjoern A. Zeeb uint32_t nflags = 0; 52276b4cac81SBjoern A. Zeeb int cflags = chan_flags; 52286b4cac81SBjoern A. Zeeb 52296b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) { 52303f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Skipping disabled chan " 52313f0083c4SBjoern A. Zeeb "[%u/%u/%#x]\n", __func__, 52326b4cac81SBjoern A. Zeeb channels[i].hw_value, 52336b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags); 52346b4cac81SBjoern A. Zeeb continue; 52356b4cac81SBjoern A. Zeeb } 52366b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_IR) 52376b4cac81SBjoern A. Zeeb nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE); 52386b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_RADAR) 52396b4cac81SBjoern A. Zeeb nflags |= IEEE80211_CHAN_DFS; 52406b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ) 52416b4cac81SBjoern A. Zeeb cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80); 52426b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ) 52436b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_VHT80; 52446b4cac81SBjoern A. Zeeb /* XXX how to map the remaining enum ieee80211_channel_flags? */ 52456b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_HT40) 52466b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_HT40; 52476b4cac81SBjoern A. Zeeb 52486b4cac81SBjoern A. Zeeb error = ieee80211_add_channel_cbw(c, maxchan, n, 52496b4cac81SBjoern A. Zeeb channels[i].hw_value, channels[i].center_freq, 52506b4cac81SBjoern A. Zeeb channels[i].max_power, 52515856761fSBjoern A. Zeeb nflags, bands, cflags); 5252cee56e77SBjoern A. Zeeb /* net80211::ENOBUFS: *n >= maxchans */ 5253cee56e77SBjoern A. Zeeb if (error != 0 && error != ENOBUFS) 52543f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Adding chan %u/%u/%#x/%#x/%#x/%#x " 52553f0083c4SBjoern A. Zeeb "returned error %d\n", 52566b4cac81SBjoern A. Zeeb __func__, channels[i].hw_value, 52576b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags, 52586b4cac81SBjoern A. Zeeb nflags, chan_flags, cflags, error); 5259cee56e77SBjoern A. Zeeb if (error != 0) 52606b4cac81SBjoern A. Zeeb break; 52616b4cac81SBjoern A. Zeeb } 52626b4cac81SBjoern A. Zeeb } 52636b4cac81SBjoern A. Zeeb 52646b4cac81SBjoern A. Zeeb /* NL80211_BAND_5GHZ */ 52656b4cac81SBjoern A. Zeeb nchans = 0; 52666b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ] != NULL) 52676b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[NL80211_BAND_5GHZ]->n_channels; 52686b4cac81SBjoern A. Zeeb if (nchans > 0) { 52696b4cac81SBjoern A. Zeeb memset(bands, 0, sizeof(bands)); 52706b4cac81SBjoern A. Zeeb chan_flags = 0; 52716b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11A); 52729fb91463SBjoern A. Zeeb 52739fb91463SBjoern A. Zeeb lkpi_ic_getradiocaps_ht(ic, hw, bands, &chan_flags, 52749fb91463SBjoern A. Zeeb NL80211_BAND_5GHZ); 52759fb91463SBjoern A. Zeeb 52769fb91463SBjoern A. Zeeb #ifdef LKPI_80211_VHT 52776b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.vht_supported){ 52786b4cac81SBjoern A. Zeeb 52796b4cac81SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_VHT; 5280562adbe1SBjoern A. Zeeb ic->ic_vht_cap.vht_cap_info = 52816b4cac81SBjoern A. Zeeb hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap; 5282ecb2e5f9SBjoern A. Zeeb ic->ic_vht_cap.supp_mcs = 5283ecb2e5f9SBjoern A. Zeeb hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.vht_mcs; 52846b4cac81SBjoern A. Zeeb 52856b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_VHT_5GHZ); 52866b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT80; 52876b4cac81SBjoern A. Zeeb if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160MHZ( 5288562adbe1SBjoern A. Zeeb ic->ic_vht_cap.vht_cap_info)) 52896b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT160; 52906b4cac81SBjoern A. Zeeb if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160_80P80MHZ( 5291562adbe1SBjoern A. Zeeb ic->ic_vht_cap.vht_cap_info)) 52926b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT80P80; 52936b4cac81SBjoern A. Zeeb } 52946b4cac81SBjoern A. Zeeb #endif 52956b4cac81SBjoern A. Zeeb 52966b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[NL80211_BAND_5GHZ]->channels; 5297cee56e77SBjoern A. Zeeb for (i = 0; i < nchans && *n < maxchan; i++) { 52986b4cac81SBjoern A. Zeeb uint32_t nflags = 0; 52996b4cac81SBjoern A. Zeeb int cflags = chan_flags; 53006b4cac81SBjoern A. Zeeb 53016b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) { 53023f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Skipping disabled chan " 53033f0083c4SBjoern A. Zeeb "[%u/%u/%#x]\n", __func__, 53046b4cac81SBjoern A. Zeeb channels[i].hw_value, 53056b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags); 53066b4cac81SBjoern A. Zeeb continue; 53076b4cac81SBjoern A. Zeeb } 53086b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_IR) 53096b4cac81SBjoern A. Zeeb nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE); 53106b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_RADAR) 53116b4cac81SBjoern A. Zeeb nflags |= IEEE80211_CHAN_DFS; 53126b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ) 53136b4cac81SBjoern A. Zeeb cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80); 53146b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ) 53156b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_VHT80; 53166b4cac81SBjoern A. Zeeb /* XXX hwo to map the remaining enum ieee80211_channel_flags? */ 53176b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_HT40) 53186b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_HT40; 53196b4cac81SBjoern A. Zeeb 53206b4cac81SBjoern A. Zeeb error = ieee80211_add_channel_cbw(c, maxchan, n, 53216b4cac81SBjoern A. Zeeb channels[i].hw_value, channels[i].center_freq, 53226b4cac81SBjoern A. Zeeb channels[i].max_power, 53235856761fSBjoern A. Zeeb nflags, bands, cflags); 5324cee56e77SBjoern A. Zeeb /* net80211::ENOBUFS: *n >= maxchans */ 5325cee56e77SBjoern A. Zeeb if (error != 0 && error != ENOBUFS) 53263f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Adding chan %u/%u/%#x/%#x/%#x/%#x " 53273f0083c4SBjoern A. Zeeb "returned error %d\n", 53286b4cac81SBjoern A. Zeeb __func__, channels[i].hw_value, 53296b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags, 53306b4cac81SBjoern A. Zeeb nflags, chan_flags, cflags, error); 5331cee56e77SBjoern A. Zeeb if (error != 0) 53326b4cac81SBjoern A. Zeeb break; 53336b4cac81SBjoern A. Zeeb } 53346b4cac81SBjoern A. Zeeb } 53356b4cac81SBjoern A. Zeeb } 53366b4cac81SBjoern A. Zeeb 53376b4cac81SBjoern A. Zeeb static void * 53386b4cac81SBjoern A. Zeeb lkpi_ieee80211_ifalloc(void) 53396b4cac81SBjoern A. Zeeb { 53406b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 53416b4cac81SBjoern A. Zeeb 53426b4cac81SBjoern A. Zeeb ic = malloc(sizeof(*ic), M_LKPI80211, M_WAITOK | M_ZERO); 53436b4cac81SBjoern A. Zeeb 53446b4cac81SBjoern A. Zeeb /* Setting these happens later when we have device information. */ 53456b4cac81SBjoern A. Zeeb ic->ic_softc = NULL; 53466b4cac81SBjoern A. Zeeb ic->ic_name = "linuxkpi"; 53476b4cac81SBjoern A. Zeeb 53486b4cac81SBjoern A. Zeeb return (ic); 53496b4cac81SBjoern A. Zeeb } 53506b4cac81SBjoern A. Zeeb 53516b4cac81SBjoern A. Zeeb struct ieee80211_hw * 53526b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_alloc_hw(size_t priv_len, const struct ieee80211_ops *ops) 53536b4cac81SBjoern A. Zeeb { 53546b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 53556b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 53566b4cac81SBjoern A. Zeeb struct wiphy *wiphy; 5357a5ae63edSBjoern A. Zeeb int ac; 53586b4cac81SBjoern A. Zeeb 53596b4cac81SBjoern A. Zeeb /* Get us and the driver data also allocated. */ 53606b4cac81SBjoern A. Zeeb wiphy = wiphy_new(&linuxkpi_mac80211cfgops, sizeof(*lhw) + priv_len); 53616b4cac81SBjoern A. Zeeb if (wiphy == NULL) 53626b4cac81SBjoern A. Zeeb return (NULL); 53636b4cac81SBjoern A. Zeeb 53646b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 53656b4cac81SBjoern A. Zeeb lhw->ops = ops; 5366652e22d3SBjoern A. Zeeb 53678ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK_INIT(lhw); 53688ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK_INIT(lhw); 5369eac3646fSBjoern A. Zeeb LKPI_80211_LHW_TXQ_LOCK_INIT(lhw); 53708891c455SBjoern A. Zeeb sx_init_flags(&lhw->lvif_sx, "lhw-lvif", SX_RECURSE | SX_DUPOK); 53716b4cac81SBjoern A. Zeeb TAILQ_INIT(&lhw->lvif_head); 5372a5ae63edSBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 5373a5ae63edSBjoern A. Zeeb lhw->txq_generation[ac] = 1; 5374a5ae63edSBjoern A. Zeeb TAILQ_INIT(&lhw->scheduled_txqs[ac]); 5375a5ae63edSBjoern A. Zeeb } 53766b4cac81SBjoern A. Zeeb 5377759a996dSBjoern A. Zeeb /* Deferred RX path. */ 5378759a996dSBjoern A. Zeeb LKPI_80211_LHW_RXQ_LOCK_INIT(lhw); 5379759a996dSBjoern A. Zeeb TASK_INIT(&lhw->rxq_task, 0, lkpi_80211_lhw_rxq_task, lhw); 5380759a996dSBjoern A. Zeeb mbufq_init(&lhw->rxq, IFQ_MAXLEN); 5381759a996dSBjoern A. Zeeb lhw->rxq_stopped = false; 5382759a996dSBjoern A. Zeeb 53836b4cac81SBjoern A. Zeeb /* 53846b4cac81SBjoern A. Zeeb * XXX-BZ TODO make sure there is a "_null" function to all ops 53856b4cac81SBjoern A. Zeeb * not initialized. 53866b4cac81SBjoern A. Zeeb */ 53876b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 53886b4cac81SBjoern A. Zeeb hw->wiphy = wiphy; 5389086be6a8SBjoern A. Zeeb hw->conf.flags |= IEEE80211_CONF_IDLE; 53906b4cac81SBjoern A. Zeeb hw->priv = (void *)(lhw + 1); 53916b4cac81SBjoern A. Zeeb 53926b4cac81SBjoern A. Zeeb /* BSD Specific. */ 53936b4cac81SBjoern A. Zeeb lhw->ic = lkpi_ieee80211_ifalloc(); 53946b4cac81SBjoern A. Zeeb 53956b4cac81SBjoern A. Zeeb IMPROVE(); 53966b4cac81SBjoern A. Zeeb 53976b4cac81SBjoern A. Zeeb return (hw); 53986b4cac81SBjoern A. Zeeb } 53996b4cac81SBjoern A. Zeeb 54006b4cac81SBjoern A. Zeeb void 54016b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iffree(struct ieee80211_hw *hw) 54026b4cac81SBjoern A. Zeeb { 54036b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 5404759a996dSBjoern A. Zeeb struct mbuf *m; 54056b4cac81SBjoern A. Zeeb 54066b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 54076b4cac81SBjoern A. Zeeb free(lhw->ic, M_LKPI80211); 54086b4cac81SBjoern A. Zeeb lhw->ic = NULL; 54096b4cac81SBjoern A. Zeeb 5410759a996dSBjoern A. Zeeb /* 5411759a996dSBjoern A. Zeeb * Drain the deferred RX path. 5412759a996dSBjoern A. Zeeb */ 5413759a996dSBjoern A. Zeeb LKPI_80211_LHW_RXQ_LOCK(lhw); 5414759a996dSBjoern A. Zeeb lhw->rxq_stopped = true; 5415759a996dSBjoern A. Zeeb LKPI_80211_LHW_RXQ_UNLOCK(lhw); 5416759a996dSBjoern A. Zeeb 5417759a996dSBjoern A. Zeeb /* Drain taskq, won't be restarted due to rxq_stopped being set. */ 5418759a996dSBjoern A. Zeeb while (taskqueue_cancel(taskqueue_thread, &lhw->rxq_task, NULL) != 0) 5419759a996dSBjoern A. Zeeb taskqueue_drain(taskqueue_thread, &lhw->rxq_task); 5420759a996dSBjoern A. Zeeb 5421759a996dSBjoern A. Zeeb /* Flush mbufq (make sure to release ni refs!). */ 5422759a996dSBjoern A. Zeeb m = mbufq_dequeue(&lhw->rxq); 5423759a996dSBjoern A. Zeeb while (m != NULL) { 5424759a996dSBjoern A. Zeeb struct m_tag *mtag; 5425759a996dSBjoern A. Zeeb 5426759a996dSBjoern A. Zeeb mtag = m_tag_locate(m, MTAG_ABI_LKPI80211, LKPI80211_TAG_RXNI, NULL); 5427759a996dSBjoern A. Zeeb if (mtag != NULL) { 5428759a996dSBjoern A. Zeeb struct lkpi_80211_tag_rxni *rxni; 5429759a996dSBjoern A. Zeeb 5430759a996dSBjoern A. Zeeb rxni = (struct lkpi_80211_tag_rxni *)(mtag + 1); 5431759a996dSBjoern A. Zeeb ieee80211_free_node(rxni->ni); 5432759a996dSBjoern A. Zeeb } 5433759a996dSBjoern A. Zeeb m_freem(m); 5434759a996dSBjoern A. Zeeb m = mbufq_dequeue(&lhw->rxq); 5435759a996dSBjoern A. Zeeb } 5436759a996dSBjoern A. Zeeb KASSERT(mbufq_empty(&lhw->rxq), ("%s: lhw %p has rxq len %d != 0\n", 5437759a996dSBjoern A. Zeeb __func__, lhw, mbufq_len(&lhw->rxq))); 5438759a996dSBjoern A. Zeeb LKPI_80211_LHW_RXQ_LOCK_DESTROY(lhw); 5439759a996dSBjoern A. Zeeb 54406b4cac81SBjoern A. Zeeb /* Cleanup more of lhw here or in wiphy_free()? */ 5441eac3646fSBjoern A. Zeeb LKPI_80211_LHW_TXQ_LOCK_DESTROY(lhw); 54428ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK_DESTROY(lhw); 5443eac3646fSBjoern A. Zeeb LKPI_80211_LHW_LOCK_DESTROY(lhw); 5444eac3646fSBjoern A. Zeeb sx_destroy(&lhw->lvif_sx); 54456b4cac81SBjoern A. Zeeb IMPROVE(); 54466b4cac81SBjoern A. Zeeb } 54476b4cac81SBjoern A. Zeeb 54486b4cac81SBjoern A. Zeeb void 54496b4cac81SBjoern A. Zeeb linuxkpi_set_ieee80211_dev(struct ieee80211_hw *hw, char *name) 54506b4cac81SBjoern A. Zeeb { 54516b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 54526b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 54536b4cac81SBjoern A. Zeeb 54546b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 54556b4cac81SBjoern A. Zeeb ic = lhw->ic; 54566b4cac81SBjoern A. Zeeb 54576b4cac81SBjoern A. Zeeb /* Now set a proper name before ieee80211_ifattach(). */ 54586b4cac81SBjoern A. Zeeb ic->ic_softc = lhw; 54596b4cac81SBjoern A. Zeeb ic->ic_name = name; 54606b4cac81SBjoern A. Zeeb 54616b4cac81SBjoern A. Zeeb /* XXX-BZ do we also need to set wiphy name? */ 54626b4cac81SBjoern A. Zeeb } 54636b4cac81SBjoern A. Zeeb 54646b4cac81SBjoern A. Zeeb struct ieee80211_hw * 54656b4cac81SBjoern A. Zeeb linuxkpi_wiphy_to_ieee80211_hw(struct wiphy *wiphy) 54666b4cac81SBjoern A. Zeeb { 54676b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 54686b4cac81SBjoern A. Zeeb 54696b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 54706b4cac81SBjoern A. Zeeb return (LHW_TO_HW(lhw)); 54716b4cac81SBjoern A. Zeeb } 54726b4cac81SBjoern A. Zeeb 54736b4cac81SBjoern A. Zeeb static void 54746b4cac81SBjoern A. Zeeb lkpi_radiotap_attach(struct lkpi_hw *lhw) 54756b4cac81SBjoern A. Zeeb { 54766b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 54776b4cac81SBjoern A. Zeeb 54786b4cac81SBjoern A. Zeeb ic = lhw->ic; 54796b4cac81SBjoern A. Zeeb ieee80211_radiotap_attach(ic, 54806b4cac81SBjoern A. Zeeb &lhw->rtap_tx.wt_ihdr, sizeof(lhw->rtap_tx), 54816b4cac81SBjoern A. Zeeb LKPI_RTAP_TX_FLAGS_PRESENT, 54826b4cac81SBjoern A. Zeeb &lhw->rtap_rx.wr_ihdr, sizeof(lhw->rtap_rx), 54836b4cac81SBjoern A. Zeeb LKPI_RTAP_RX_FLAGS_PRESENT); 54846b4cac81SBjoern A. Zeeb } 54856b4cac81SBjoern A. Zeeb 54862e183d99SBjoern A. Zeeb int 54876b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ifattach(struct ieee80211_hw *hw) 54886b4cac81SBjoern A. Zeeb { 54896b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 54906b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 5491c5b96b3eSBjoern A. Zeeb int band, i; 54926b4cac81SBjoern A. Zeeb 54936b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 54946b4cac81SBjoern A. Zeeb ic = lhw->ic; 54956b4cac81SBjoern A. Zeeb 5496652e22d3SBjoern A. Zeeb /* We do it this late as wiphy->dev should be set for the name. */ 5497652e22d3SBjoern A. Zeeb lhw->workq = alloc_ordered_workqueue(wiphy_name(hw->wiphy), 0); 5498652e22d3SBjoern A. Zeeb if (lhw->workq == NULL) 5499652e22d3SBjoern A. Zeeb return (-EAGAIN); 5500652e22d3SBjoern A. Zeeb 55016b4cac81SBjoern A. Zeeb /* XXX-BZ figure this out how they count his... */ 55026b4cac81SBjoern A. Zeeb if (!is_zero_ether_addr(hw->wiphy->perm_addr)) { 55036b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(ic->ic_macaddr, 55046b4cac81SBjoern A. Zeeb hw->wiphy->perm_addr); 55056b4cac81SBjoern A. Zeeb } else if (hw->wiphy->n_addresses > 0) { 55066b4cac81SBjoern A. Zeeb /* We take the first one. */ 55076b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(ic->ic_macaddr, 55086b4cac81SBjoern A. Zeeb hw->wiphy->addresses[0].addr); 55096b4cac81SBjoern A. Zeeb } else { 55106b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: warning, no hardware address!\n", __func__); 55116b4cac81SBjoern A. Zeeb } 55126b4cac81SBjoern A. Zeeb 55133d09d310SBjoern A. Zeeb #ifdef __not_yet__ 55143d09d310SBjoern A. Zeeb /* See comment in lkpi_80211_txq_tx_one(). */ 55156b4cac81SBjoern A. Zeeb ic->ic_headroom = hw->extra_tx_headroom; 55163d09d310SBjoern A. Zeeb #endif 55176b4cac81SBjoern A. Zeeb 55186b4cac81SBjoern A. Zeeb ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ 55196b4cac81SBjoern A. Zeeb ic->ic_opmode = IEEE80211_M_STA; 55206b4cac81SBjoern A. Zeeb 55216b4cac81SBjoern A. Zeeb /* Set device capabilities. */ 55226b4cac81SBjoern A. Zeeb /* XXX-BZ we need to get these from linux80211/drivers and convert. */ 55236b4cac81SBjoern A. Zeeb ic->ic_caps = 55246b4cac81SBjoern A. Zeeb IEEE80211_C_STA | 55256b4cac81SBjoern A. Zeeb IEEE80211_C_MONITOR | 55266b4cac81SBjoern A. Zeeb IEEE80211_C_WPA | /* WPA/RSN */ 55274a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 55286b4cac81SBjoern A. Zeeb IEEE80211_C_WME | 55294a67f1dfSBjoern A. Zeeb #endif 55306b4cac81SBjoern A. Zeeb #if 0 55316b4cac81SBjoern A. Zeeb IEEE80211_C_PMGT | 55326b4cac81SBjoern A. Zeeb #endif 55336b4cac81SBjoern A. Zeeb IEEE80211_C_SHSLOT | /* short slot time supported */ 55346b4cac81SBjoern A. Zeeb IEEE80211_C_SHPREAMBLE /* short preamble supported */ 55356b4cac81SBjoern A. Zeeb ; 55366b4cac81SBjoern A. Zeeb #if 0 55376b4cac81SBjoern A. Zeeb /* Scanning is a different kind of beast to re-work. */ 55386b4cac81SBjoern A. Zeeb ic->ic_caps |= IEEE80211_C_BGSCAN; 55396b4cac81SBjoern A. Zeeb #endif 5540cc4e78d5SBjoern A. Zeeb if (lhw->ops->hw_scan) { 5541cc4e78d5SBjoern A. Zeeb /* 5542cc4e78d5SBjoern A. Zeeb * Advertise full-offload scanning. 5543cc4e78d5SBjoern A. Zeeb * 5544cc4e78d5SBjoern A. Zeeb * Not limiting to SINGLE_SCAN_ON_ALL_BANDS here as otherwise 5545cc4e78d5SBjoern A. Zeeb * we essentially disable hw_scan for all drivers not setting 5546cc4e78d5SBjoern A. Zeeb * the flag. 5547cc4e78d5SBjoern A. Zeeb */ 55486b4cac81SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_SCAN_OFFLOAD; 5549a486fbbdSBjoern A. Zeeb lhw->scan_flags |= LKPI_LHW_SCAN_HW; 55506b4cac81SBjoern A. Zeeb } 55516b4cac81SBjoern A. Zeeb 5552527687a9SBjoern A. Zeeb /* 5553527687a9SBjoern A. Zeeb * The wiphy variables report bitmasks of avail antennas. 5554527687a9SBjoern A. Zeeb * (*get_antenna) get the current bitmask sets which can be 5555527687a9SBjoern A. Zeeb * altered by (*set_antenna) for some drivers. 5556527687a9SBjoern A. Zeeb * XXX-BZ will the count alone do us much good long-term in net80211? 5557527687a9SBjoern A. Zeeb */ 5558527687a9SBjoern A. Zeeb if (hw->wiphy->available_antennas_rx || 5559527687a9SBjoern A. Zeeb hw->wiphy->available_antennas_tx) { 5560527687a9SBjoern A. Zeeb uint32_t rxs, txs; 5561527687a9SBjoern A. Zeeb 5562527687a9SBjoern A. Zeeb if (lkpi_80211_mo_get_antenna(hw, &txs, &rxs) == 0) { 5563527687a9SBjoern A. Zeeb ic->ic_rxstream = bitcount32(rxs); 5564527687a9SBjoern A. Zeeb ic->ic_txstream = bitcount32(txs); 5565527687a9SBjoern A. Zeeb } 5566527687a9SBjoern A. Zeeb } 5567527687a9SBjoern A. Zeeb 55686b4cac81SBjoern A. Zeeb ic->ic_cryptocaps = 0; 5569b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 557011db70b6SBjoern A. Zeeb if (lkpi_hwcrypto && hw->wiphy->n_cipher_suites > 0) { 55716b4cac81SBjoern A. Zeeb for (i = 0; i < hw->wiphy->n_cipher_suites; i++) 55726b4cac81SBjoern A. Zeeb ic->ic_cryptocaps |= lkpi_l80211_to_net80211_cyphers( 55736b4cac81SBjoern A. Zeeb hw->wiphy->cipher_suites[i]); 55746b4cac81SBjoern A. Zeeb } 55756b4cac81SBjoern A. Zeeb #endif 55766b4cac81SBjoern A. Zeeb 55776b4cac81SBjoern A. Zeeb lkpi_ic_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans, 55786b4cac81SBjoern A. Zeeb ic->ic_channels); 55796b4cac81SBjoern A. Zeeb 55806b4cac81SBjoern A. Zeeb ieee80211_ifattach(ic); 55816b4cac81SBjoern A. Zeeb 55826b4cac81SBjoern A. Zeeb ic->ic_update_mcast = lkpi_ic_update_mcast; 55836b4cac81SBjoern A. Zeeb ic->ic_update_promisc = lkpi_ic_update_promisc; 55846b4cac81SBjoern A. Zeeb ic->ic_update_chw = lkpi_ic_update_chw; 55856b4cac81SBjoern A. Zeeb ic->ic_parent = lkpi_ic_parent; 55866b4cac81SBjoern A. Zeeb ic->ic_scan_start = lkpi_ic_scan_start; 55876b4cac81SBjoern A. Zeeb ic->ic_scan_end = lkpi_ic_scan_end; 55886b4cac81SBjoern A. Zeeb ic->ic_set_channel = lkpi_ic_set_channel; 55896b4cac81SBjoern A. Zeeb ic->ic_transmit = lkpi_ic_transmit; 55906b4cac81SBjoern A. Zeeb ic->ic_raw_xmit = lkpi_ic_raw_xmit; 55916b4cac81SBjoern A. Zeeb ic->ic_vap_create = lkpi_ic_vap_create; 55926b4cac81SBjoern A. Zeeb ic->ic_vap_delete = lkpi_ic_vap_delete; 55936b4cac81SBjoern A. Zeeb ic->ic_getradiocaps = lkpi_ic_getradiocaps; 55946b4cac81SBjoern A. Zeeb ic->ic_wme.wme_update = lkpi_ic_wme_update; 55956b4cac81SBjoern A. Zeeb 5596a486fbbdSBjoern A. Zeeb lhw->ic_scan_curchan = ic->ic_scan_curchan; 5597a486fbbdSBjoern A. Zeeb ic->ic_scan_curchan = lkpi_ic_scan_curchan; 5598a486fbbdSBjoern A. Zeeb lhw->ic_scan_mindwell = ic->ic_scan_mindwell; 5599a486fbbdSBjoern A. Zeeb ic->ic_scan_mindwell = lkpi_ic_scan_mindwell; 5600a486fbbdSBjoern A. Zeeb 56016b4cac81SBjoern A. Zeeb lhw->ic_node_alloc = ic->ic_node_alloc; 56026b4cac81SBjoern A. Zeeb ic->ic_node_alloc = lkpi_ic_node_alloc; 56036b4cac81SBjoern A. Zeeb lhw->ic_node_init = ic->ic_node_init; 56046b4cac81SBjoern A. Zeeb ic->ic_node_init = lkpi_ic_node_init; 56056b4cac81SBjoern A. Zeeb lhw->ic_node_cleanup = ic->ic_node_cleanup; 56066b4cac81SBjoern A. Zeeb ic->ic_node_cleanup = lkpi_ic_node_cleanup; 56076b4cac81SBjoern A. Zeeb lhw->ic_node_free = ic->ic_node_free; 56086b4cac81SBjoern A. Zeeb ic->ic_node_free = lkpi_ic_node_free; 56096b4cac81SBjoern A. Zeeb 56109fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 561186bc7259SBjoern A. Zeeb /* 561286bc7259SBjoern A. Zeeb * Only attach if the driver/firmware supports (*ampdu_action)(). 561386bc7259SBjoern A. Zeeb * Otherwise it is in the hands of net80211. 561486bc7259SBjoern A. Zeeb */ 561586bc7259SBjoern A. Zeeb if (lhw->ops->ampdu_action != NULL) { 56169fb91463SBjoern A. Zeeb lhw->ic_recv_action = ic->ic_recv_action; 56179fb91463SBjoern A. Zeeb ic->ic_recv_action = lkpi_ic_recv_action; 56189fb91463SBjoern A. Zeeb lhw->ic_send_action = ic->ic_send_action; 56199fb91463SBjoern A. Zeeb ic->ic_send_action = lkpi_ic_send_action; 56209fb91463SBjoern A. Zeeb 56219fb91463SBjoern A. Zeeb lhw->ic_ampdu_enable = ic->ic_ampdu_enable; 56229fb91463SBjoern A. Zeeb ic->ic_ampdu_enable = lkpi_ic_ampdu_enable; 56239fb91463SBjoern A. Zeeb 56249fb91463SBjoern A. Zeeb lhw->ic_addba_request = ic->ic_addba_request; 56259fb91463SBjoern A. Zeeb ic->ic_addba_request = lkpi_ic_addba_request; 56269fb91463SBjoern A. Zeeb lhw->ic_addba_response = ic->ic_addba_response; 56279fb91463SBjoern A. Zeeb ic->ic_addba_response = lkpi_ic_addba_response; 56289fb91463SBjoern A. Zeeb lhw->ic_addba_stop = ic->ic_addba_stop; 56299fb91463SBjoern A. Zeeb ic->ic_addba_stop = lkpi_ic_addba_stop; 56309fb91463SBjoern A. Zeeb lhw->ic_addba_response_timeout = ic->ic_addba_response_timeout; 56319fb91463SBjoern A. Zeeb ic->ic_addba_response_timeout = lkpi_ic_addba_response_timeout; 56329fb91463SBjoern A. Zeeb 56339fb91463SBjoern A. Zeeb lhw->ic_bar_response = ic->ic_bar_response; 56349fb91463SBjoern A. Zeeb ic->ic_bar_response = lkpi_ic_bar_response; 56359fb91463SBjoern A. Zeeb 56369fb91463SBjoern A. Zeeb lhw->ic_ampdu_rx_start = ic->ic_ampdu_rx_start; 56379fb91463SBjoern A. Zeeb ic->ic_ampdu_rx_start = lkpi_ic_ampdu_rx_start; 56389fb91463SBjoern A. Zeeb lhw->ic_ampdu_rx_stop = ic->ic_ampdu_rx_stop; 56399fb91463SBjoern A. Zeeb ic->ic_ampdu_rx_stop = lkpi_ic_ampdu_rx_stop; 564086bc7259SBjoern A. Zeeb } 56419fb91463SBjoern A. Zeeb #endif 56429fb91463SBjoern A. Zeeb 56436b4cac81SBjoern A. Zeeb lkpi_radiotap_attach(lhw); 56446b4cac81SBjoern A. Zeeb 5645c5b96b3eSBjoern A. Zeeb /* 5646c5b96b3eSBjoern A. Zeeb * Assign the first possible channel for now; seems Realtek drivers 5647c5b96b3eSBjoern A. Zeeb * expect one. 5648d9945d78SBjoern A. Zeeb * Also remember the amount of bands we support and the most rates 5649d9945d78SBjoern A. Zeeb * in any band so we can scale [(ext) sup rates] IE(s) accordingly. 5650c5b96b3eSBjoern A. Zeeb */ 5651d9945d78SBjoern A. Zeeb lhw->supbands = lhw->max_rates = 0; 5652f454a4a1SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 5653c5b96b3eSBjoern A. Zeeb struct ieee80211_supported_band *supband; 5654c5b96b3eSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 5655c5b96b3eSBjoern A. Zeeb 5656c5b96b3eSBjoern A. Zeeb supband = hw->wiphy->bands[band]; 5657c5b96b3eSBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 5658c5b96b3eSBjoern A. Zeeb continue; 5659c5b96b3eSBjoern A. Zeeb 5660d9945d78SBjoern A. Zeeb lhw->supbands++; 5661d9945d78SBjoern A. Zeeb lhw->max_rates = max(lhw->max_rates, supband->n_bitrates); 5662d9945d78SBjoern A. Zeeb 5663f454a4a1SBjoern A. Zeeb /* If we have a channel, we need to keep counting supbands. */ 5664f454a4a1SBjoern A. Zeeb if (hw->conf.chandef.chan != NULL) 5665f454a4a1SBjoern A. Zeeb continue; 5666f454a4a1SBjoern A. Zeeb 5667c5b96b3eSBjoern A. Zeeb channels = supband->channels; 5668c5b96b3eSBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 5669c5b96b3eSBjoern A. Zeeb 5670c5b96b3eSBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) 5671c5b96b3eSBjoern A. Zeeb continue; 5672c5b96b3eSBjoern A. Zeeb 56734a07abdeSBjoern A. Zeeb cfg80211_chandef_create(&hw->conf.chandef, &channels[i], 56749fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 567511450726SBjoern A. Zeeb (ic->ic_flags_ht & IEEE80211_FHT_HT) ? NL80211_CHAN_HT20 : 56769fb91463SBjoern A. Zeeb #endif 5677c5b96b3eSBjoern A. Zeeb NL80211_CHAN_NO_HT); 5678c5b96b3eSBjoern A. Zeeb break; 5679c5b96b3eSBjoern A. Zeeb } 5680c5b96b3eSBjoern A. Zeeb } 5681c5b96b3eSBjoern A. Zeeb 5682d9945d78SBjoern A. Zeeb IMPROVE("see net80211::ieee80211_chan_init vs. wiphy->bands[].bitrates possibly in lkpi_ic_getradiocaps?"); 5683d9945d78SBjoern A. Zeeb 5684d9945d78SBjoern A. Zeeb /* Make sure we do not support more than net80211 is willing to take. */ 5685d9945d78SBjoern A. Zeeb if (lhw->max_rates > IEEE80211_RATE_MAXSIZE) { 5686d9945d78SBjoern A. Zeeb ic_printf(ic, "%s: limiting max_rates %d to %d!\n", __func__, 5687d9945d78SBjoern A. Zeeb lhw->max_rates, IEEE80211_RATE_MAXSIZE); 5688d9945d78SBjoern A. Zeeb lhw->max_rates = IEEE80211_RATE_MAXSIZE; 5689d9945d78SBjoern A. Zeeb } 5690d9945d78SBjoern A. Zeeb 5691d9945d78SBjoern A. Zeeb /* 5692d9945d78SBjoern A. Zeeb * The maximum supported bitrates on any band + size for 5693d9945d78SBjoern A. Zeeb * DSSS Parameter Set give our per-band IE size. 5694d9945d78SBjoern A. Zeeb * SSID is the responsibility of the driver and goes on the side. 5695d9945d78SBjoern A. Zeeb * The user specified bits coming from the vap go into the 5696d9945d78SBjoern A. Zeeb * "common ies" fields. 5697d9945d78SBjoern A. Zeeb */ 5698d9945d78SBjoern A. Zeeb lhw->scan_ie_len = 2 + IEEE80211_RATE_SIZE; 5699d9945d78SBjoern A. Zeeb if (lhw->max_rates > IEEE80211_RATE_SIZE) 5700d9945d78SBjoern A. Zeeb lhw->scan_ie_len += 2 + (lhw->max_rates - IEEE80211_RATE_SIZE); 570178ca45dfSBjoern A. Zeeb 570278ca45dfSBjoern A. Zeeb if (hw->wiphy->features & NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) { 5703d9945d78SBjoern A. Zeeb /* 570478ca45dfSBjoern A. Zeeb * net80211 does not seem to support the DSSS Parameter Set but 570578ca45dfSBjoern A. Zeeb * some of the drivers insert it so calculate the extra fixed 570678ca45dfSBjoern A. Zeeb * space in. 5707d9945d78SBjoern A. Zeeb */ 5708d9945d78SBjoern A. Zeeb lhw->scan_ie_len += 2 + 1; 570978ca45dfSBjoern A. Zeeb } 5710d9945d78SBjoern A. Zeeb 57119fb91463SBjoern A. Zeeb #if defined(LKPI_80211_HT) 57129fb91463SBjoern A. Zeeb if ((ic->ic_htcaps & IEEE80211_HTC_HT) != 0) 57139fb91463SBjoern A. Zeeb lhw->scan_ie_len += sizeof(struct ieee80211_ie_htcap); 57149fb91463SBjoern A. Zeeb #endif 57159fb91463SBjoern A. Zeeb #if defined(LKPI_80211_VHT) 57161f73e0edSBjoern A. Zeeb if (IEEE80211_CONF_VHT(ic)) 57179fb91463SBjoern A. Zeeb lhw->scan_ie_len += 2 + sizeof(struct ieee80211_vht_cap); 57189fb91463SBjoern A. Zeeb #endif 57199fb91463SBjoern A. Zeeb 5720d9945d78SBjoern A. Zeeb /* Reduce the max_scan_ie_len "left" by the amount we consume already. */ 572178ca45dfSBjoern A. Zeeb if (hw->wiphy->max_scan_ie_len > 0) { 572278ca45dfSBjoern A. Zeeb if (lhw->scan_ie_len > hw->wiphy->max_scan_ie_len) 572378ca45dfSBjoern A. Zeeb goto err; 5724d9945d78SBjoern A. Zeeb hw->wiphy->max_scan_ie_len -= lhw->scan_ie_len; 572578ca45dfSBjoern A. Zeeb } 5726d9945d78SBjoern A. Zeeb 57276b4cac81SBjoern A. Zeeb if (bootverbose) 57286b4cac81SBjoern A. Zeeb ieee80211_announce(ic); 57292e183d99SBjoern A. Zeeb 57302e183d99SBjoern A. Zeeb return (0); 573178ca45dfSBjoern A. Zeeb err: 573278ca45dfSBjoern A. Zeeb IMPROVE("TODO FIXME CLEANUP"); 573378ca45dfSBjoern A. Zeeb return (-EAGAIN); 57346b4cac81SBjoern A. Zeeb } 57356b4cac81SBjoern A. Zeeb 57366b4cac81SBjoern A. Zeeb void 57376b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ifdetach(struct ieee80211_hw *hw) 57386b4cac81SBjoern A. Zeeb { 57396b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 57406b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 57416b4cac81SBjoern A. Zeeb 57426b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 57436b4cac81SBjoern A. Zeeb ic = lhw->ic; 57446b4cac81SBjoern A. Zeeb ieee80211_ifdetach(ic); 57456b4cac81SBjoern A. Zeeb } 57466b4cac81SBjoern A. Zeeb 57476b4cac81SBjoern A. Zeeb void 57486b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_interfaces(struct ieee80211_hw *hw, 57496b4cac81SBjoern A. Zeeb enum ieee80211_iface_iter flags, 57506b4cac81SBjoern A. Zeeb void(*iterfunc)(void *, uint8_t *, struct ieee80211_vif *), 57516b4cac81SBjoern A. Zeeb void *arg) 57526b4cac81SBjoern A. Zeeb { 57536b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 57546b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 57556b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 575661a68e50SBjoern A. Zeeb bool active, atomic, nin_drv; 57576b4cac81SBjoern A. Zeeb 57586b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 57596b4cac81SBjoern A. Zeeb 57606b4cac81SBjoern A. Zeeb if (flags & ~(IEEE80211_IFACE_ITER_NORMAL| 57616b4cac81SBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL| 576261a68e50SBjoern A. Zeeb IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER| 5763adff403fSBjoern A. Zeeb IEEE80211_IFACE_ITER_ACTIVE|IEEE80211_IFACE_ITER__ATOMIC)) { 57646b4cac81SBjoern A. Zeeb ic_printf(lhw->ic, "XXX TODO %s flags(%#x) not yet supported.\n", 57656b4cac81SBjoern A. Zeeb __func__, flags); 57666b4cac81SBjoern A. Zeeb } 57676b4cac81SBjoern A. Zeeb 5768adff403fSBjoern A. Zeeb active = (flags & IEEE80211_IFACE_ITER_ACTIVE) != 0; 57696b4cac81SBjoern A. Zeeb atomic = (flags & IEEE80211_IFACE_ITER__ATOMIC) != 0; 577061a68e50SBjoern A. Zeeb nin_drv = (flags & IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER) != 0; 57716b4cac81SBjoern A. Zeeb 57726b4cac81SBjoern A. Zeeb if (atomic) 57738891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 57746b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 57756b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 57766b4cac81SBjoern A. Zeeb 57776b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 57786b4cac81SBjoern A. Zeeb 57796b4cac81SBjoern A. Zeeb /* 57806b4cac81SBjoern A. Zeeb * If we want "active" interfaces, we need to distinguish on 57816b4cac81SBjoern A. Zeeb * whether the driver knows about them or not to be able to 57826b4cac81SBjoern A. Zeeb * handle the "resume" case correctly. Skip the ones the 57836b4cac81SBjoern A. Zeeb * driver does not know about. 57846b4cac81SBjoern A. Zeeb */ 57856b4cac81SBjoern A. Zeeb if (active && !lvif->added_to_drv && 57866b4cac81SBjoern A. Zeeb (flags & IEEE80211_IFACE_ITER_RESUME_ALL) != 0) 57876b4cac81SBjoern A. Zeeb continue; 57886b4cac81SBjoern A. Zeeb 57896b4cac81SBjoern A. Zeeb /* 579061a68e50SBjoern A. Zeeb * If we shall skip interfaces not added to the driver do so 579161a68e50SBjoern A. Zeeb * if we haven't yet. 579261a68e50SBjoern A. Zeeb */ 579361a68e50SBjoern A. Zeeb if (nin_drv && !lvif->added_to_drv) 579461a68e50SBjoern A. Zeeb continue; 579561a68e50SBjoern A. Zeeb 579661a68e50SBjoern A. Zeeb /* 57976b4cac81SBjoern A. Zeeb * Run the iterator function if we are either not asking 57986b4cac81SBjoern A. Zeeb * asking for active only or if the VAP is "running". 57996b4cac81SBjoern A. Zeeb */ 58006b4cac81SBjoern A. Zeeb /* XXX-BZ probably should have state in the lvif as well. */ 58016b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 58026b4cac81SBjoern A. Zeeb if (!active || (vap->iv_state != IEEE80211_S_INIT)) 58036b4cac81SBjoern A. Zeeb iterfunc(arg, vif->addr, vif); 58046b4cac81SBjoern A. Zeeb } 58056b4cac81SBjoern A. Zeeb if (atomic) 58068891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 58076b4cac81SBjoern A. Zeeb } 58086b4cac81SBjoern A. Zeeb 580911db70b6SBjoern A. Zeeb static void 581011db70b6SBjoern A. Zeeb lkpi_ieee80211_iterate_keys(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 581111db70b6SBjoern A. Zeeb ieee80211_keyix keyix, struct lkpi_sta *lsta, 581211db70b6SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_vif *, 581311db70b6SBjoern A. Zeeb struct ieee80211_sta *, struct ieee80211_key_conf *, void *), 581411db70b6SBjoern A. Zeeb void *arg) 581511db70b6SBjoern A. Zeeb { 581611db70b6SBjoern A. Zeeb if (!lsta->added_to_drv) 581711db70b6SBjoern A. Zeeb return; 581811db70b6SBjoern A. Zeeb 581911db70b6SBjoern A. Zeeb if (lsta->kc[keyix] == NULL) 582011db70b6SBjoern A. Zeeb return; 582111db70b6SBjoern A. Zeeb 582211db70b6SBjoern A. Zeeb iterfunc(hw, vif, LSTA_TO_STA(lsta), lsta->kc[keyix], arg); 582311db70b6SBjoern A. Zeeb } 582411db70b6SBjoern A. Zeeb 58256b4cac81SBjoern A. Zeeb void 58266b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_keys(struct ieee80211_hw *hw, 58276b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif, 58286b4cac81SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_vif *, 58296b4cac81SBjoern A. Zeeb struct ieee80211_sta *, struct ieee80211_key_conf *, void *), 583011db70b6SBjoern A. Zeeb void *arg, bool rcu) 58316b4cac81SBjoern A. Zeeb { 583211db70b6SBjoern A. Zeeb struct lkpi_sta *lsta; 583311db70b6SBjoern A. Zeeb struct lkpi_vif *lvif; 58346b4cac81SBjoern A. Zeeb 583511db70b6SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 583611db70b6SBjoern A. Zeeb 583711db70b6SBjoern A. Zeeb if (rcu) { 5838a8f735a6SBjoern A. Zeeb rcu_read_lock_held(); /* XXX-BZ is this correct? */ 5839a8f735a6SBjoern A. Zeeb 584011db70b6SBjoern A. Zeeb if (vif == NULL) { 584111db70b6SBjoern A. Zeeb TODO(); 584211db70b6SBjoern A. Zeeb } else { 5843a8f735a6SBjoern A. Zeeb list_for_each_entry_rcu(lsta, &lvif->lsta_list, lsta_list) { 584411db70b6SBjoern A. Zeeb for (ieee80211_keyix keyix = 0; keyix < nitems(lsta->kc); 584511db70b6SBjoern A. Zeeb keyix++) 584611db70b6SBjoern A. Zeeb lkpi_ieee80211_iterate_keys(hw, vif, 584711db70b6SBjoern A. Zeeb keyix, lsta, iterfunc, arg); 584811db70b6SBjoern A. Zeeb } 584911db70b6SBjoern A. Zeeb } 585011db70b6SBjoern A. Zeeb } else { 585111db70b6SBjoern A. Zeeb TODO("Used by suspend/resume; order of keys as installed to " 585211db70b6SBjoern A. Zeeb "firmware is important; we'll need to rewrite some code for that"); 585311db70b6SBjoern A. Zeeb lockdep_assert_wiphy(hw->wiphy); 585411db70b6SBjoern A. Zeeb 585511db70b6SBjoern A. Zeeb if (vif == NULL) { 585611db70b6SBjoern A. Zeeb TODO(); 585711db70b6SBjoern A. Zeeb } else { 5858a8f735a6SBjoern A. Zeeb list_for_each_entry(lsta, &lvif->lsta_list, lsta_list) { 585911db70b6SBjoern A. Zeeb for (ieee80211_keyix keyix = 0; keyix < nitems(lsta->kc); 586011db70b6SBjoern A. Zeeb keyix++) 586111db70b6SBjoern A. Zeeb lkpi_ieee80211_iterate_keys(hw, vif, 586211db70b6SBjoern A. Zeeb keyix, lsta, iterfunc, arg); 586311db70b6SBjoern A. Zeeb } 586411db70b6SBjoern A. Zeeb } 586511db70b6SBjoern A. Zeeb } 58666b4cac81SBjoern A. Zeeb } 58676b4cac81SBjoern A. Zeeb 58686b4cac81SBjoern A. Zeeb void 58696b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_chan_contexts(struct ieee80211_hw *hw, 58706b4cac81SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_chanctx_conf *, 58716b4cac81SBjoern A. Zeeb void *), 58726b4cac81SBjoern A. Zeeb void *arg) 58736b4cac81SBjoern A. Zeeb { 5874c5e25798SBjoern A. Zeeb struct lkpi_hw *lhw; 5875c5e25798SBjoern A. Zeeb struct lkpi_vif *lvif; 5876c5e25798SBjoern A. Zeeb struct ieee80211_vif *vif; 5877c5e25798SBjoern A. Zeeb struct lkpi_chanctx *lchanctx; 58786b4cac81SBjoern A. Zeeb 5879c5e25798SBjoern A. Zeeb KASSERT(hw != NULL && iterfunc != NULL, 5880c5e25798SBjoern A. Zeeb ("%s: hw %p iterfunc %p arg %p\n", __func__, hw, iterfunc, arg)); 5881c5e25798SBjoern A. Zeeb 5882c5e25798SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 5883c5e25798SBjoern A. Zeeb 5884c5e25798SBjoern A. Zeeb IMPROVE("lchanctx should be its own list somewhere"); 5885c5e25798SBjoern A. Zeeb 5886c5e25798SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 5887c5e25798SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 5888c5e25798SBjoern A. Zeeb 5889c5e25798SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 5890c5e25798SBjoern A. Zeeb if (vif->chanctx_conf == NULL) 5891c5e25798SBjoern A. Zeeb continue; 5892c5e25798SBjoern A. Zeeb 5893c5e25798SBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(vif->chanctx_conf); 5894c5e25798SBjoern A. Zeeb if (!lchanctx->added_to_drv) 5895c5e25798SBjoern A. Zeeb continue; 5896c5e25798SBjoern A. Zeeb 5897d1af434dSBjoern A. Zeeb iterfunc(hw, &lchanctx->chanctx_conf, arg); 5898c5e25798SBjoern A. Zeeb } 5899c5e25798SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 59006b4cac81SBjoern A. Zeeb } 59016b4cac81SBjoern A. Zeeb 59026b4cac81SBjoern A. Zeeb void 59036b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_stations_atomic(struct ieee80211_hw *hw, 59046b4cac81SBjoern A. Zeeb void (*iterfunc)(void *, struct ieee80211_sta *), void *arg) 59056b4cac81SBjoern A. Zeeb { 59066b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 59076b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 59086b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 59096b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 59106b4cac81SBjoern A. Zeeb 59116b4cac81SBjoern A. Zeeb KASSERT(hw != NULL && iterfunc != NULL, 59126b4cac81SBjoern A. Zeeb ("%s: hw %p iterfunc %p arg %p\n", __func__, hw, iterfunc, arg)); 59136b4cac81SBjoern A. Zeeb 59146b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 59156b4cac81SBjoern A. Zeeb 59168891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 59176b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 59186b4cac81SBjoern A. Zeeb 5919a8f735a6SBjoern A. Zeeb rcu_read_lock(); 5920a8f735a6SBjoern A. Zeeb list_for_each_entry_rcu(lsta, &lvif->lsta_list, lsta_list) { 59216b4cac81SBjoern A. Zeeb if (!lsta->added_to_drv) 59226b4cac81SBjoern A. Zeeb continue; 59236b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 59246b4cac81SBjoern A. Zeeb iterfunc(arg, sta); 59256b4cac81SBjoern A. Zeeb } 5926a8f735a6SBjoern A. Zeeb rcu_read_unlock(); 59276b4cac81SBjoern A. Zeeb } 59288891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 59296b4cac81SBjoern A. Zeeb } 59306b4cac81SBjoern A. Zeeb 5931673d62fcSBjoern A. Zeeb struct linuxkpi_ieee80211_regdomain * 5932673d62fcSBjoern A. Zeeb lkpi_get_linuxkpi_ieee80211_regdomain(size_t n) 5933673d62fcSBjoern A. Zeeb { 5934673d62fcSBjoern A. Zeeb struct linuxkpi_ieee80211_regdomain *regd; 5935673d62fcSBjoern A. Zeeb 5936673d62fcSBjoern A. Zeeb regd = kzalloc(sizeof(*regd) + n * sizeof(struct ieee80211_reg_rule), 5937673d62fcSBjoern A. Zeeb GFP_KERNEL); 5938673d62fcSBjoern A. Zeeb return (regd); 5939673d62fcSBjoern A. Zeeb } 5940673d62fcSBjoern A. Zeeb 59416b4cac81SBjoern A. Zeeb int 59426b4cac81SBjoern A. Zeeb linuxkpi_regulatory_set_wiphy_regd_sync(struct wiphy *wiphy, 59436b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_regdomain *regd) 59446b4cac81SBjoern A. Zeeb { 59456b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 59466b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 59476b4cac81SBjoern A. Zeeb struct ieee80211_regdomain *rd; 59486b4cac81SBjoern A. Zeeb 59496b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 59506b4cac81SBjoern A. Zeeb ic = lhw->ic; 59516b4cac81SBjoern A. Zeeb 59526b4cac81SBjoern A. Zeeb rd = &ic->ic_regdomain; 59536b4cac81SBjoern A. Zeeb if (rd->isocc[0] == '\0') { 59546b4cac81SBjoern A. Zeeb rd->isocc[0] = regd->alpha2[0]; 59556b4cac81SBjoern A. Zeeb rd->isocc[1] = regd->alpha2[1]; 59566b4cac81SBjoern A. Zeeb } 59576b4cac81SBjoern A. Zeeb 59586b4cac81SBjoern A. Zeeb TODO(); 59596b4cac81SBjoern A. Zeeb /* XXX-BZ finish the rest. */ 59606b4cac81SBjoern A. Zeeb 59616b4cac81SBjoern A. Zeeb return (0); 59626b4cac81SBjoern A. Zeeb } 59636b4cac81SBjoern A. Zeeb 59646b4cac81SBjoern A. Zeeb void 59656b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_scan_completed(struct ieee80211_hw *hw, 59666b4cac81SBjoern A. Zeeb struct cfg80211_scan_info *info) 59676b4cac81SBjoern A. Zeeb { 59686b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 59696b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 59706b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 59716b4cac81SBjoern A. Zeeb 59726b4cac81SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 59736b4cac81SBjoern A. Zeeb ic = lhw->ic; 59746b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 59756b4cac81SBjoern A. Zeeb 59766b4cac81SBjoern A. Zeeb ieee80211_scan_done(ss->ss_vap); 59776b4cac81SBjoern A. Zeeb 59788ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 59796b4cac81SBjoern A. Zeeb free(lhw->hw_req, M_LKPI80211); 59806b4cac81SBjoern A. Zeeb lhw->hw_req = NULL; 5981a486fbbdSBjoern A. Zeeb lhw->scan_flags &= ~LKPI_LHW_SCAN_RUNNING; 59826b4cac81SBjoern A. Zeeb wakeup(lhw); 59838ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 59846b4cac81SBjoern A. Zeeb 59856b4cac81SBjoern A. Zeeb return; 59866b4cac81SBjoern A. Zeeb } 59876b4cac81SBjoern A. Zeeb 5988759a996dSBjoern A. Zeeb static void 5989759a996dSBjoern A. Zeeb lkpi_80211_lhw_rxq_rx_one(struct lkpi_hw *lhw, struct mbuf *m) 5990759a996dSBjoern A. Zeeb { 5991759a996dSBjoern A. Zeeb struct ieee80211_node *ni; 5992759a996dSBjoern A. Zeeb struct m_tag *mtag; 5993759a996dSBjoern A. Zeeb int ok; 5994759a996dSBjoern A. Zeeb 5995759a996dSBjoern A. Zeeb ni = NULL; 5996759a996dSBjoern A. Zeeb mtag = m_tag_locate(m, MTAG_ABI_LKPI80211, LKPI80211_TAG_RXNI, NULL); 5997759a996dSBjoern A. Zeeb if (mtag != NULL) { 5998759a996dSBjoern A. Zeeb struct lkpi_80211_tag_rxni *rxni; 5999759a996dSBjoern A. Zeeb 6000759a996dSBjoern A. Zeeb rxni = (struct lkpi_80211_tag_rxni *)(mtag + 1); 6001759a996dSBjoern A. Zeeb ni = rxni->ni; 6002759a996dSBjoern A. Zeeb } 6003759a996dSBjoern A. Zeeb 6004759a996dSBjoern A. Zeeb if (ni != NULL) { 6005759a996dSBjoern A. Zeeb ok = ieee80211_input_mimo(ni, m); 6006759a996dSBjoern A. Zeeb ieee80211_free_node(ni); /* Release the reference. */ 6007759a996dSBjoern A. Zeeb if (ok < 0) 6008759a996dSBjoern A. Zeeb m_freem(m); 6009759a996dSBjoern A. Zeeb } else { 6010759a996dSBjoern A. Zeeb ok = ieee80211_input_mimo_all(lhw->ic, m); 6011759a996dSBjoern A. Zeeb /* mbuf got consumed. */ 6012759a996dSBjoern A. Zeeb } 6013759a996dSBjoern A. Zeeb 6014759a996dSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 6015759a996dSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 6016bd206a6fSBjoern A. Zeeb printf("TRACE-RX: %s: handled frame type %#0x\n", __func__, ok); 6017759a996dSBjoern A. Zeeb #endif 6018759a996dSBjoern A. Zeeb } 6019759a996dSBjoern A. Zeeb 6020759a996dSBjoern A. Zeeb static void 6021759a996dSBjoern A. Zeeb lkpi_80211_lhw_rxq_task(void *ctx, int pending) 6022759a996dSBjoern A. Zeeb { 6023759a996dSBjoern A. Zeeb struct lkpi_hw *lhw; 6024759a996dSBjoern A. Zeeb struct mbufq mq; 6025759a996dSBjoern A. Zeeb struct mbuf *m; 6026759a996dSBjoern A. Zeeb 6027759a996dSBjoern A. Zeeb lhw = ctx; 6028759a996dSBjoern A. Zeeb 6029759a996dSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 6030759a996dSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 6031bd206a6fSBjoern A. Zeeb printf("TRACE-RX: %s: lhw %p pending %d mbuf_qlen %d\n", 6032bd206a6fSBjoern A. Zeeb __func__, lhw, pending, mbufq_len(&lhw->rxq)); 6033759a996dSBjoern A. Zeeb #endif 6034759a996dSBjoern A. Zeeb 6035759a996dSBjoern A. Zeeb mbufq_init(&mq, IFQ_MAXLEN); 6036759a996dSBjoern A. Zeeb 6037759a996dSBjoern A. Zeeb LKPI_80211_LHW_RXQ_LOCK(lhw); 6038759a996dSBjoern A. Zeeb mbufq_concat(&mq, &lhw->rxq); 6039759a996dSBjoern A. Zeeb LKPI_80211_LHW_RXQ_UNLOCK(lhw); 6040759a996dSBjoern A. Zeeb 6041759a996dSBjoern A. Zeeb m = mbufq_dequeue(&mq); 6042759a996dSBjoern A. Zeeb while (m != NULL) { 6043759a996dSBjoern A. Zeeb lkpi_80211_lhw_rxq_rx_one(lhw, m); 6044759a996dSBjoern A. Zeeb m = mbufq_dequeue(&mq); 6045759a996dSBjoern A. Zeeb } 6046759a996dSBjoern A. Zeeb } 6047759a996dSBjoern A. Zeeb 604849010ba7SBjoern A. Zeeb static void 604949010ba7SBjoern A. Zeeb lkpi_convert_rx_status(struct ieee80211_hw *hw, 605049010ba7SBjoern A. Zeeb struct ieee80211_rx_status *rx_status, 605149010ba7SBjoern A. Zeeb struct ieee80211_rx_stats *rx_stats, 605249010ba7SBjoern A. Zeeb uint8_t *rssip) 605349010ba7SBjoern A. Zeeb { 605449010ba7SBjoern A. Zeeb struct ieee80211_supported_band *supband; 605549010ba7SBjoern A. Zeeb int i; 605649010ba7SBjoern A. Zeeb uint8_t rssi; 605749010ba7SBjoern A. Zeeb 605849010ba7SBjoern A. Zeeb memset(rx_stats, 0, sizeof(*rx_stats)); 605949010ba7SBjoern A. Zeeb rx_stats->r_flags = IEEE80211_R_NF | IEEE80211_R_RSSI; 606049010ba7SBjoern A. Zeeb /* XXX-BZ correct hardcoded noise floor, survey data? */ 606149010ba7SBjoern A. Zeeb rx_stats->c_nf = -96; 606249010ba7SBjoern A. Zeeb if (ieee80211_hw_check(hw, SIGNAL_DBM) && 606349010ba7SBjoern A. Zeeb !(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL)) 606449010ba7SBjoern A. Zeeb rssi = rx_status->signal; 606549010ba7SBjoern A. Zeeb else 606649010ba7SBjoern A. Zeeb rssi = rx_stats->c_nf; 606749010ba7SBjoern A. Zeeb /* 606849010ba7SBjoern A. Zeeb * net80211 signal strength data are in .5 dBm units relative to 606949010ba7SBjoern A. Zeeb * the current noise floor (see comment in ieee80211_node.h). 607049010ba7SBjoern A. Zeeb */ 607149010ba7SBjoern A. Zeeb rssi -= rx_stats->c_nf; 607249010ba7SBjoern A. Zeeb if (rssip != NULL) 607349010ba7SBjoern A. Zeeb *rssip = rssi; 607449010ba7SBjoern A. Zeeb rx_stats->c_rssi = rssi * 2; 607549010ba7SBjoern A. Zeeb rx_stats->r_flags |= IEEE80211_R_BAND; 607649010ba7SBjoern A. Zeeb rx_stats->c_band = 607749010ba7SBjoern A. Zeeb lkpi_nl80211_band_to_net80211_band(rx_status->band); 607849010ba7SBjoern A. Zeeb rx_stats->r_flags |= IEEE80211_R_FREQ | IEEE80211_R_IEEE; 607949010ba7SBjoern A. Zeeb rx_stats->c_freq = rx_status->freq; 608049010ba7SBjoern A. Zeeb rx_stats->c_ieee = ieee80211_mhz2ieee(rx_stats->c_freq, rx_stats->c_band); 608149010ba7SBjoern A. Zeeb 608249010ba7SBjoern A. Zeeb rx_stats->c_rx_tsf = rx_status->mactime; 608349010ba7SBjoern A. Zeeb 608449010ba7SBjoern A. Zeeb /* XXX RX_FLAG_MACTIME_IS_RTAP_TS64 ? */ 608549010ba7SBjoern A. Zeeb if ((rx_status->flag & RX_FLAG_MACTIME) == 608649010ba7SBjoern A. Zeeb (RX_FLAG_MACTIME_START|RX_FLAG_MACTIME_END)) { 608749010ba7SBjoern A. Zeeb rx_stats->r_flags |= IEEE80211_R_TSF64; 608849010ba7SBjoern A. Zeeb /* XXX RX_FLAG_MACTIME_PLCP_START ? */ 608949010ba7SBjoern A. Zeeb if ((rx_status->flag & RX_FLAG_MACTIME) == RX_FLAG_MACTIME_START) 609049010ba7SBjoern A. Zeeb rx_stats->r_flags |= IEEE80211_R_TSF_START; 609149010ba7SBjoern A. Zeeb if ((rx_status->flag & RX_FLAG_MACTIME) == RX_FLAG_MACTIME_END) 609249010ba7SBjoern A. Zeeb rx_stats->r_flags |= IEEE80211_R_TSF_END; 609349010ba7SBjoern A. Zeeb /* XXX-BZ if TSF_END will net80211 do the unwind of time? */ 609449010ba7SBjoern A. Zeeb } 609549010ba7SBjoern A. Zeeb 609649010ba7SBjoern A. Zeeb if (rx_status->chains != 0) { 609749010ba7SBjoern A. Zeeb int cc; 609849010ba7SBjoern A. Zeeb int8_t crssi; 609949010ba7SBjoern A. Zeeb 610049010ba7SBjoern A. Zeeb rx_stats->c_chain = rx_status->chains; 610149010ba7SBjoern A. Zeeb rx_stats->r_flags |= IEEE80211_R_C_CHAIN; 610249010ba7SBjoern A. Zeeb 610349010ba7SBjoern A. Zeeb cc = 0; 610449010ba7SBjoern A. Zeeb for (i = 0; i < nitems(rx_status->chain_signal); i++) { 610549010ba7SBjoern A. Zeeb if (!(rx_status->chains & BIT(i))) 610649010ba7SBjoern A. Zeeb continue; 610749010ba7SBjoern A. Zeeb crssi = rx_status->chain_signal[i]; 610849010ba7SBjoern A. Zeeb crssi -= rx_stats->c_nf; 610949010ba7SBjoern A. Zeeb rx_stats->c_rssi_ctl[i] = crssi * 2; 611049010ba7SBjoern A. Zeeb rx_stats->c_rssi_ext[i] = crssi * 2; /* XXX _ext ??? ATH thing? */ 611149010ba7SBjoern A. Zeeb /* We currently only have the global noise floor value. */ 611249010ba7SBjoern A. Zeeb rx_stats->c_nf_ctl[i] = rx_stats->c_nf; 611349010ba7SBjoern A. Zeeb rx_stats->c_nf_ext[i] = rx_stats->c_nf; 611449010ba7SBjoern A. Zeeb cc++; 611549010ba7SBjoern A. Zeeb } 611649010ba7SBjoern A. Zeeb if (cc > 0) 611749010ba7SBjoern A. Zeeb rx_stats->r_flags |= (IEEE80211_R_C_NF | IEEE80211_R_C_RSSI); 611849010ba7SBjoern A. Zeeb } 611949010ba7SBjoern A. Zeeb 612049010ba7SBjoern A. Zeeb /* XXX-NET80211 We are not going to populate c_phytype! */ 612149010ba7SBjoern A. Zeeb 612249010ba7SBjoern A. Zeeb switch (rx_status->encoding) { 612349010ba7SBjoern A. Zeeb case RX_ENC_LEGACY: 612449010ba7SBjoern A. Zeeb supband = hw->wiphy->bands[rx_status->band]; 612549010ba7SBjoern A. Zeeb if (supband != NULL) 612649010ba7SBjoern A. Zeeb rx_stats->c_rate = supband->bitrates[rx_status->rate_idx].bitrate; 612749010ba7SBjoern A. Zeeb /* Is there a LinuxKPI way of reporting IEEE80211_RX_F_CCK / _OFDM? */ 612849010ba7SBjoern A. Zeeb break; 612949010ba7SBjoern A. Zeeb case RX_ENC_HT: 613049010ba7SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_HT; 613149010ba7SBjoern A. Zeeb if ((rx_status->enc_flags & RX_ENC_FLAG_SHORT_GI) != 0) 613249010ba7SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_SHORTGI; 613349010ba7SBjoern A. Zeeb rx_stats->c_rate = rx_status->rate_idx; /* mcs */ 613449010ba7SBjoern A. Zeeb break; 613549010ba7SBjoern A. Zeeb case RX_ENC_VHT: 613649010ba7SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_VHT; 613749010ba7SBjoern A. Zeeb if ((rx_status->enc_flags & RX_ENC_FLAG_SHORT_GI) != 0) 613849010ba7SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_SHORTGI; 613949010ba7SBjoern A. Zeeb rx_stats->c_rate = rx_status->rate_idx; /* mcs */ 614049010ba7SBjoern A. Zeeb rx_stats->c_vhtnss = rx_status->nss; 614149010ba7SBjoern A. Zeeb break; 614249010ba7SBjoern A. Zeeb case RX_ENC_HE: 614349010ba7SBjoern A. Zeeb case RX_ENC_EHT: 614449010ba7SBjoern A. Zeeb TODO("net80211 has not matching encoding for %u", rx_status->encoding); 614549010ba7SBjoern A. Zeeb break; 614649010ba7SBjoern A. Zeeb } 614749010ba7SBjoern A. Zeeb 614849010ba7SBjoern A. Zeeb switch (rx_status->bw) { 614949010ba7SBjoern A. Zeeb case RATE_INFO_BW_20: 615049010ba7SBjoern A. Zeeb rx_stats->c_width = IEEE80211_RX_FW_20MHZ; 615149010ba7SBjoern A. Zeeb break; 615249010ba7SBjoern A. Zeeb case RATE_INFO_BW_40: 615349010ba7SBjoern A. Zeeb rx_stats->c_width = IEEE80211_RX_FW_40MHZ; 615449010ba7SBjoern A. Zeeb break; 615549010ba7SBjoern A. Zeeb case RATE_INFO_BW_80: 615649010ba7SBjoern A. Zeeb rx_stats->c_width = IEEE80211_RX_FW_80MHZ; 615749010ba7SBjoern A. Zeeb break; 615849010ba7SBjoern A. Zeeb case RATE_INFO_BW_160: 615949010ba7SBjoern A. Zeeb rx_stats->c_width = IEEE80211_RX_FW_160MHZ; 616049010ba7SBjoern A. Zeeb break; 616149010ba7SBjoern A. Zeeb case RATE_INFO_BW_320: 616249010ba7SBjoern A. Zeeb case RATE_INFO_BW_HE_RU: 616349010ba7SBjoern A. Zeeb case RATE_INFO_BW_EHT_RU: 616449010ba7SBjoern A. Zeeb case RATE_INFO_BW_5: 616549010ba7SBjoern A. Zeeb case RATE_INFO_BW_10: 616649010ba7SBjoern A. Zeeb TODO("net80211 has not matching bandwidth for %u", rx_status->bw); 616749010ba7SBjoern A. Zeeb break; 616849010ba7SBjoern A. Zeeb } 616949010ba7SBjoern A. Zeeb 617049010ba7SBjoern A. Zeeb if ((rx_status->enc_flags & RX_ENC_FLAG_LDPC) != 0) 617149010ba7SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_LDPC; 617249010ba7SBjoern A. Zeeb if ((rx_status->enc_flags & RX_ENC_FLAG_STBC_MASK) != 0) 617349010ba7SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_STBC; 617449010ba7SBjoern A. Zeeb 617549010ba7SBjoern A. Zeeb /* 617649010ba7SBjoern A. Zeeb * We only need these for LKPI_80211_HW_CRYPTO in theory but in 617749010ba7SBjoern A. Zeeb * case the hardware does something we do not expect always leave 617849010ba7SBjoern A. Zeeb * these enabled. Leaving this commant as documentation for the || 1. 617949010ba7SBjoern A. Zeeb */ 618049010ba7SBjoern A. Zeeb #if defined(LKPI_80211_HW_CRYPTO) || 1 618149010ba7SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_DECRYPTED) { 618249010ba7SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_DECRYPTED; 618349010ba7SBjoern A. Zeeb /* Only valid if decrypted is set. */ 618449010ba7SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_PN_VALIDATED) 618549010ba7SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_PN_VALIDATED; 618649010ba7SBjoern A. Zeeb } 618749010ba7SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_MMIC_STRIPPED) 618849010ba7SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_MMIC_STRIP; 618949010ba7SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_MIC_STRIPPED) { 619049010ba7SBjoern A. Zeeb /* net80211 re-uses M[ichael]MIC for MIC too. Confusing. */ 619149010ba7SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_MMIC_STRIP; 619249010ba7SBjoern A. Zeeb } 619349010ba7SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_IV_STRIPPED) 619449010ba7SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_IV_STRIP; 619549010ba7SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_MMIC_ERROR) 619649010ba7SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_FAIL_MIC; 619749010ba7SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_FAILED_FCS_CRC) 619849010ba7SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_FAIL_FCSCRC; 619949010ba7SBjoern A. Zeeb #endif 620049010ba7SBjoern A. Zeeb } 620149010ba7SBjoern A. Zeeb 6202e30e05d3SBjoern A. Zeeb /* For %list see comment towards the end of the function. */ 62036b4cac81SBjoern A. Zeeb void 62046b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb, 6205e30e05d3SBjoern A. Zeeb struct ieee80211_sta *sta, struct napi_struct *napi __unused, 6206e30e05d3SBjoern A. Zeeb struct list_head *list __unused) 62076b4cac81SBjoern A. Zeeb { 62086b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 62096b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 62106b4cac81SBjoern A. Zeeb struct mbuf *m; 62116b4cac81SBjoern A. Zeeb struct skb_shared_info *shinfo; 62126b4cac81SBjoern A. Zeeb struct ieee80211_rx_status *rx_status; 62136b4cac81SBjoern A. Zeeb struct ieee80211_rx_stats rx_stats; 62146b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 62156b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 62166b4cac81SBjoern A. Zeeb struct ieee80211_hdr *hdr; 62176b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 62189d9ba2b7SBjoern A. Zeeb int i, offset, ok; 621949010ba7SBjoern A. Zeeb uint8_t rssi; 6220c0cadd99SBjoern A. Zeeb bool is_beacon; 62216b4cac81SBjoern A. Zeeb 62226b4cac81SBjoern A. Zeeb if (skb->len < 2) { 62236b4cac81SBjoern A. Zeeb /* Need 80211 stats here. */ 62246b4cac81SBjoern A. Zeeb IMPROVE(); 62256b4cac81SBjoern A. Zeeb goto err; 62266b4cac81SBjoern A. Zeeb } 62276b4cac81SBjoern A. Zeeb 62286b4cac81SBjoern A. Zeeb /* 62296b4cac81SBjoern A. Zeeb * For now do the data copy; we can later improve things. Might even 62306b4cac81SBjoern A. Zeeb * have an mbuf backing the skb data then? 62316b4cac81SBjoern A. Zeeb */ 62326b4cac81SBjoern A. Zeeb m = m_get2(skb->len, M_NOWAIT, MT_DATA, M_PKTHDR); 62336b4cac81SBjoern A. Zeeb if (m == NULL) 62346b4cac81SBjoern A. Zeeb goto err; 62356b4cac81SBjoern A. Zeeb m_copyback(m, 0, skb->tail - skb->data, skb->data); 62366b4cac81SBjoern A. Zeeb 62376b4cac81SBjoern A. Zeeb shinfo = skb_shinfo(skb); 62386b4cac81SBjoern A. Zeeb offset = m->m_len; 62396b4cac81SBjoern A. Zeeb for (i = 0; i < shinfo->nr_frags; i++) { 62406b4cac81SBjoern A. Zeeb m_copyback(m, offset, shinfo->frags[i].size, 62416b4cac81SBjoern A. Zeeb (uint8_t *)linux_page_address(shinfo->frags[i].page) + 62426b4cac81SBjoern A. Zeeb shinfo->frags[i].offset); 62436b4cac81SBjoern A. Zeeb offset += shinfo->frags[i].size; 62446b4cac81SBjoern A. Zeeb } 62456b4cac81SBjoern A. Zeeb 62466b4cac81SBjoern A. Zeeb rx_status = IEEE80211_SKB_RXCB(skb); 62476b4cac81SBjoern A. Zeeb 62486b4cac81SBjoern A. Zeeb hdr = (void *)skb->data; 6249c0cadd99SBjoern A. Zeeb is_beacon = ieee80211_is_beacon(hdr->frame_control); 6250c0cadd99SBjoern A. Zeeb 6251c0cadd99SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 62529d9ba2b7SBjoern A. Zeeb if (is_beacon && (linuxkpi_debug_80211 & D80211_TRACE_RX_BEACONS) == 0) 62536b4cac81SBjoern A. Zeeb goto no_trace_beacons; 62546b4cac81SBjoern A. Zeeb 62559d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 62566b4cac81SBjoern A. Zeeb printf("TRACE-RX: %s: skb %p a/l/d/t-len (%u/%u/%u/%u) " 6257c0cadd99SBjoern A. Zeeb "h %p d %p t %p e %p sh %p (%u) m %p plen %u len %u%s\n", 62586b4cac81SBjoern A. Zeeb __func__, skb, skb->_alloc_len, skb->len, skb->data_len, 62596b4cac81SBjoern A. Zeeb skb->truesize, skb->head, skb->data, skb->tail, skb->end, 62606b4cac81SBjoern A. Zeeb shinfo, shinfo->nr_frags, 6261c0cadd99SBjoern A. Zeeb m, m->m_pkthdr.len, m->m_len, is_beacon ? " beacon" : ""); 62626b4cac81SBjoern A. Zeeb 62639d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX_DUMP) 62646b4cac81SBjoern A. Zeeb hexdump(mtod(m, const void *), m->m_len, "RX (raw) ", 0); 62656b4cac81SBjoern A. Zeeb 62666b4cac81SBjoern A. Zeeb /* Implement a dump_rxcb() !!! */ 62679d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 6268f1aeb5d8SBjoern A. Zeeb printf("TRACE-RX: %s: RXCB: %ju %ju %u, %b, %u, %#0x, %#0x, " 626960970a32SBjoern A. Zeeb "%u band %u, %u { %d %d %d %d }, %d, %#x %#x %#x %#x %u %u %u\n", 62706b4cac81SBjoern A. Zeeb __func__, 6271c8dafefaSBjoern A. Zeeb (uintmax_t)rx_status->boottime_ns, 6272c8dafefaSBjoern A. Zeeb (uintmax_t)rx_status->mactime, 62736b4cac81SBjoern A. Zeeb rx_status->device_timestamp, 6274f1aeb5d8SBjoern A. Zeeb rx_status->flag, IEEE80211_RX_STATUS_FLAGS_BITS, 62756b4cac81SBjoern A. Zeeb rx_status->freq, 62766b4cac81SBjoern A. Zeeb rx_status->bw, 62776b4cac81SBjoern A. Zeeb rx_status->encoding, 62786b4cac81SBjoern A. Zeeb rx_status->ampdu_reference, 62796b4cac81SBjoern A. Zeeb rx_status->band, 62806b4cac81SBjoern A. Zeeb rx_status->chains, 62816b4cac81SBjoern A. Zeeb rx_status->chain_signal[0], 62826b4cac81SBjoern A. Zeeb rx_status->chain_signal[1], 62836b4cac81SBjoern A. Zeeb rx_status->chain_signal[2], 628460970a32SBjoern A. Zeeb rx_status->chain_signal[3], 62856b4cac81SBjoern A. Zeeb rx_status->signal, 62866b4cac81SBjoern A. Zeeb rx_status->enc_flags, 62876b4cac81SBjoern A. Zeeb rx_status->he_dcm, 62886b4cac81SBjoern A. Zeeb rx_status->he_gi, 62896b4cac81SBjoern A. Zeeb rx_status->he_ru, 62906b4cac81SBjoern A. Zeeb rx_status->zero_length_psdu_type, 62916b4cac81SBjoern A. Zeeb rx_status->nss, 62926b4cac81SBjoern A. Zeeb rx_status->rate_idx); 62936b4cac81SBjoern A. Zeeb no_trace_beacons: 62946b4cac81SBjoern A. Zeeb #endif 62956b4cac81SBjoern A. Zeeb 629649010ba7SBjoern A. Zeeb rssi = 0; 629749010ba7SBjoern A. Zeeb lkpi_convert_rx_status(hw, rx_status, &rx_stats, &rssi); 62986b4cac81SBjoern A. Zeeb 62996b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 63006b4cac81SBjoern A. Zeeb ic = lhw->ic; 63016b4cac81SBjoern A. Zeeb 63026b4cac81SBjoern A. Zeeb ok = ieee80211_add_rx_params(m, &rx_stats); 63036b4cac81SBjoern A. Zeeb if (ok == 0) { 6304dbc06dd9SBjoern A. Zeeb m_freem(m); 63056b4cac81SBjoern A. Zeeb counter_u64_add(ic->ic_ierrors, 1); 63066b4cac81SBjoern A. Zeeb goto err; 63076b4cac81SBjoern A. Zeeb } 63086b4cac81SBjoern A. Zeeb 630958246901SBjoern A. Zeeb lsta = NULL; 63106b4cac81SBjoern A. Zeeb if (sta != NULL) { 63116b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 63126b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(lsta->ni); 63136b4cac81SBjoern A. Zeeb } else { 6314c8dafefaSBjoern A. Zeeb struct ieee80211_frame_min *wh; 6315c8dafefaSBjoern A. Zeeb 63166b4cac81SBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame_min *); 63176b4cac81SBjoern A. Zeeb ni = ieee80211_find_rxnode(ic, wh); 63186b4cac81SBjoern A. Zeeb if (ni != NULL) 63196b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 63206b4cac81SBjoern A. Zeeb } 63216b4cac81SBjoern A. Zeeb 63226b4cac81SBjoern A. Zeeb if (ni != NULL) 63236b4cac81SBjoern A. Zeeb vap = ni->ni_vap; 63246b4cac81SBjoern A. Zeeb else 63256b4cac81SBjoern A. Zeeb /* 63266b4cac81SBjoern A. Zeeb * XXX-BZ can we improve this by looking at the frame hdr 63276b4cac81SBjoern A. Zeeb * or other meta-data passed up? 63286b4cac81SBjoern A. Zeeb */ 63296b4cac81SBjoern A. Zeeb vap = TAILQ_FIRST(&ic->ic_vaps); 63306b4cac81SBjoern A. Zeeb 63319d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 63329d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 6333bd206a6fSBjoern A. Zeeb printf("TRACE-RX: %s: sta %p lsta %p state %d ni %p vap %p%s\n", 6334c0cadd99SBjoern A. Zeeb __func__, sta, lsta, (lsta != NULL) ? lsta->state : -1, 6335c0cadd99SBjoern A. Zeeb ni, vap, is_beacon ? " beacon" : ""); 63369d9ba2b7SBjoern A. Zeeb #endif 63376b4cac81SBjoern A. Zeeb 6338c0cadd99SBjoern A. Zeeb if (ni != NULL && vap != NULL && is_beacon && 6339c8dafefaSBjoern A. Zeeb rx_status->device_timestamp > 0 && 6340c8dafefaSBjoern A. Zeeb m->m_pkthdr.len >= sizeof(struct ieee80211_frame)) { 6341c8dafefaSBjoern A. Zeeb struct lkpi_vif *lvif; 6342c8dafefaSBjoern A. Zeeb struct ieee80211_vif *vif; 6343c8dafefaSBjoern A. Zeeb struct ieee80211_frame *wh; 6344c8dafefaSBjoern A. Zeeb 6345c8dafefaSBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame *); 6346c8dafefaSBjoern A. Zeeb if (!IEEE80211_ADDR_EQ(wh->i_addr2, ni->ni_bssid)) 6347c8dafefaSBjoern A. Zeeb goto skip_device_ts; 6348c8dafefaSBjoern A. Zeeb 6349c8dafefaSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 6350c8dafefaSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 6351c8dafefaSBjoern A. Zeeb 6352c8dafefaSBjoern A. Zeeb IMPROVE("TIMING_BEACON_ONLY?"); 6353c8dafefaSBjoern A. Zeeb /* mac80211 specific (not net80211) so keep it here. */ 6354c8dafefaSBjoern A. Zeeb vif->bss_conf.sync_device_ts = rx_status->device_timestamp; 6355c8dafefaSBjoern A. Zeeb /* 6356c8dafefaSBjoern A. Zeeb * net80211 should take care of the other information (sync_tsf, 6357c8dafefaSBjoern A. Zeeb * sync_dtim_count) as otherwise we need to parse the beacon. 6358c8dafefaSBjoern A. Zeeb */ 6359c8dafefaSBjoern A. Zeeb skip_device_ts: 63609fb91463SBjoern A. Zeeb ; 63619fb91463SBjoern A. Zeeb } 6362c8dafefaSBjoern A. Zeeb 63636b4cac81SBjoern A. Zeeb if (vap != NULL && vap->iv_state > IEEE80211_S_INIT && 63646b4cac81SBjoern A. Zeeb ieee80211_radiotap_active_vap(vap)) { 63656b4cac81SBjoern A. Zeeb struct lkpi_radiotap_rx_hdr *rtap; 63666b4cac81SBjoern A. Zeeb 63676b4cac81SBjoern A. Zeeb rtap = &lhw->rtap_rx; 63686b4cac81SBjoern A. Zeeb rtap->wr_tsft = rx_status->device_timestamp; 63696b4cac81SBjoern A. Zeeb rtap->wr_flags = 0; 63706b4cac81SBjoern A. Zeeb if (rx_status->enc_flags & RX_ENC_FLAG_SHORTPRE) 63716b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; 63726b4cac81SBjoern A. Zeeb if (rx_status->enc_flags & RX_ENC_FLAG_SHORT_GI) 63736b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTGI; 63746b4cac81SBjoern A. Zeeb #if 0 /* .. or it does not given we strip it below. */ 63756b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, RX_INCLUDES_FCS)) 63766b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_FCS; 63776b4cac81SBjoern A. Zeeb #endif 63786b4cac81SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_FAILED_FCS_CRC) 63796b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_BADFCS; 63806b4cac81SBjoern A. Zeeb rtap->wr_rate = 0; 63816b4cac81SBjoern A. Zeeb IMPROVE(); 63826b4cac81SBjoern A. Zeeb /* XXX TODO status->encoding / rate_index / bw */ 63836b4cac81SBjoern A. Zeeb rtap->wr_chan_freq = htole16(rx_stats.c_freq); 63846b4cac81SBjoern A. Zeeb if (ic->ic_curchan->ic_ieee == rx_stats.c_ieee) 63856b4cac81SBjoern A. Zeeb rtap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags); 6386170acccfSBjoern A. Zeeb rtap->wr_dbm_antsignal = rssi; 63876b4cac81SBjoern A. Zeeb rtap->wr_dbm_antnoise = rx_stats.c_nf; 63886b4cac81SBjoern A. Zeeb } 63896b4cac81SBjoern A. Zeeb 63906b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, RX_INCLUDES_FCS)) 63916b4cac81SBjoern A. Zeeb m_adj(m, -IEEE80211_CRC_LEN); 63926b4cac81SBjoern A. Zeeb 6393e30e05d3SBjoern A. Zeeb #if 0 6394e30e05d3SBjoern A. Zeeb if (list != NULL) { 6395e30e05d3SBjoern A. Zeeb /* 6396e30e05d3SBjoern A. Zeeb * Normally this would be queued up and delivered by 6397e30e05d3SBjoern A. Zeeb * netif_receive_skb_list(), napi_gro_receive(), or the like. 6398e30e05d3SBjoern A. Zeeb * See mt76::mac80211.c as only current possible consumer. 6399e30e05d3SBjoern A. Zeeb */ 6400e30e05d3SBjoern A. Zeeb IMPROVE("we simply pass the packet to net80211 to deal with."); 6401e30e05d3SBjoern A. Zeeb } 6402e30e05d3SBjoern A. Zeeb #endif 6403e30e05d3SBjoern A. Zeeb 6404759a996dSBjoern A. Zeeb /* 6405759a996dSBjoern A. Zeeb * Attach meta-information to the mbuf for the deferred RX path. 6406759a996dSBjoern A. Zeeb * Currently this is best-effort. Should we need to be hard, 6407759a996dSBjoern A. Zeeb * drop the frame and goto err; 6408759a996dSBjoern A. Zeeb */ 64096b4cac81SBjoern A. Zeeb if (ni != NULL) { 6410759a996dSBjoern A. Zeeb struct m_tag *mtag; 6411759a996dSBjoern A. Zeeb struct lkpi_80211_tag_rxni *rxni; 6412759a996dSBjoern A. Zeeb 6413759a996dSBjoern A. Zeeb mtag = m_tag_alloc(MTAG_ABI_LKPI80211, LKPI80211_TAG_RXNI, 6414759a996dSBjoern A. Zeeb sizeof(*rxni), IEEE80211_M_NOWAIT); 6415759a996dSBjoern A. Zeeb if (mtag != NULL) { 6416759a996dSBjoern A. Zeeb rxni = (struct lkpi_80211_tag_rxni *)(mtag + 1); 6417759a996dSBjoern A. Zeeb rxni->ni = ni; /* We hold a reference. */ 6418759a996dSBjoern A. Zeeb m_tag_prepend(m, mtag); 6419759a996dSBjoern A. Zeeb } 64206b4cac81SBjoern A. Zeeb } 64216b4cac81SBjoern A. Zeeb 6422759a996dSBjoern A. Zeeb LKPI_80211_LHW_RXQ_LOCK(lhw); 6423759a996dSBjoern A. Zeeb if (lhw->rxq_stopped) { 6424759a996dSBjoern A. Zeeb LKPI_80211_LHW_RXQ_UNLOCK(lhw); 6425759a996dSBjoern A. Zeeb m_freem(m); 6426759a996dSBjoern A. Zeeb goto err; 6427759a996dSBjoern A. Zeeb } 6428759a996dSBjoern A. Zeeb 6429759a996dSBjoern A. Zeeb mbufq_enqueue(&lhw->rxq, m); 6430759a996dSBjoern A. Zeeb taskqueue_enqueue(taskqueue_thread, &lhw->rxq_task); 6431759a996dSBjoern A. Zeeb LKPI_80211_LHW_RXQ_UNLOCK(lhw); 64326b4cac81SBjoern A. Zeeb 64336b4cac81SBjoern A. Zeeb IMPROVE(); 64346b4cac81SBjoern A. Zeeb 64356b4cac81SBjoern A. Zeeb err: 64366b4cac81SBjoern A. Zeeb /* The skb is ours so we can free it :-) */ 64376b4cac81SBjoern A. Zeeb kfree_skb(skb); 64386b4cac81SBjoern A. Zeeb } 64396b4cac81SBjoern A. Zeeb 64406b4cac81SBjoern A. Zeeb uint8_t 6441ec190d91SBjoern A. Zeeb linuxkpi_ieee80211_get_tid(struct ieee80211_hdr *hdr, bool nonqos_ok) 64426b4cac81SBjoern A. Zeeb { 64436b4cac81SBjoern A. Zeeb const struct ieee80211_frame *wh; 6444ec190d91SBjoern A. Zeeb uint8_t tid; 6445ec190d91SBjoern A. Zeeb 6446ec190d91SBjoern A. Zeeb /* Linux seems to assume this is a QOS-Data-Frame */ 6447ec190d91SBjoern A. Zeeb KASSERT(nonqos_ok || ieee80211_is_data_qos(hdr->frame_control), 6448ec190d91SBjoern A. Zeeb ("%s: hdr %p fc %#06x not qos_data\n", __func__, hdr, 6449ec190d91SBjoern A. Zeeb hdr->frame_control)); 64506b4cac81SBjoern A. Zeeb 64516b4cac81SBjoern A. Zeeb wh = (const struct ieee80211_frame *)hdr; 6452ec190d91SBjoern A. Zeeb tid = ieee80211_gettid(wh); 6453ec190d91SBjoern A. Zeeb KASSERT(nonqos_ok || tid == (tid & IEEE80211_QOS_TID), ("%s: tid %u " 6454ec190d91SBjoern A. Zeeb "not expected (%u?)\n", __func__, tid, IEEE80211_NONQOS_TID)); 6455ec190d91SBjoern A. Zeeb 6456ec190d91SBjoern A. Zeeb return (tid); 64576b4cac81SBjoern A. Zeeb } 64586b4cac81SBjoern A. Zeeb 6459ac1d519cSBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 6460ac1d519cSBjoern A. Zeeb 6461ac1d519cSBjoern A. Zeeb static void 6462ac1d519cSBjoern A. Zeeb lkpi_wiphy_work(struct work_struct *work) 6463ac1d519cSBjoern A. Zeeb { 6464ac1d519cSBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 6465ac1d519cSBjoern A. Zeeb struct wiphy *wiphy; 6466ac1d519cSBjoern A. Zeeb struct wiphy_work *wk; 6467ac1d519cSBjoern A. Zeeb 6468ac1d519cSBjoern A. Zeeb lwiphy = container_of(work, struct lkpi_wiphy, wwk); 6469ac1d519cSBjoern A. Zeeb wiphy = LWIPHY_TO_WIPHY(lwiphy); 6470ac1d519cSBjoern A. Zeeb 6471ac1d519cSBjoern A. Zeeb wiphy_lock(wiphy); 6472ac1d519cSBjoern A. Zeeb 6473ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_LOCK(lwiphy); 6474ac1d519cSBjoern A. Zeeb wk = list_first_entry_or_null(&lwiphy->wwk_list, struct wiphy_work, entry); 6475ac1d519cSBjoern A. Zeeb /* If there is nothing we do nothing. */ 6476ac1d519cSBjoern A. Zeeb if (wk == NULL) { 6477ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_UNLOCK(lwiphy); 6478ac1d519cSBjoern A. Zeeb wiphy_unlock(wiphy); 6479ac1d519cSBjoern A. Zeeb return; 6480ac1d519cSBjoern A. Zeeb } 6481ac1d519cSBjoern A. Zeeb list_del_init(&wk->entry); 6482ac1d519cSBjoern A. Zeeb 6483ac1d519cSBjoern A. Zeeb /* More work to do? */ 6484ac1d519cSBjoern A. Zeeb if (!list_empty(&lwiphy->wwk_list)) 6485ac1d519cSBjoern A. Zeeb schedule_work(work); 6486ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_UNLOCK(lwiphy); 6487ac1d519cSBjoern A. Zeeb 6488ac1d519cSBjoern A. Zeeb /* Finally call the (*wiphy_work_fn)() function. */ 6489ac1d519cSBjoern A. Zeeb wk->fn(wiphy, wk); 6490ac1d519cSBjoern A. Zeeb 6491ac1d519cSBjoern A. Zeeb wiphy_unlock(wiphy); 6492ac1d519cSBjoern A. Zeeb } 6493ac1d519cSBjoern A. Zeeb 6494ac1d519cSBjoern A. Zeeb void 6495ac1d519cSBjoern A. Zeeb linuxkpi_wiphy_work_queue(struct wiphy *wiphy, struct wiphy_work *wwk) 6496ac1d519cSBjoern A. Zeeb { 6497ac1d519cSBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 6498ac1d519cSBjoern A. Zeeb 6499ac1d519cSBjoern A. Zeeb lwiphy = WIPHY_TO_LWIPHY(wiphy); 6500ac1d519cSBjoern A. Zeeb 6501ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_LOCK(lwiphy); 6502ac1d519cSBjoern A. Zeeb /* Do not double-queue. */ 6503ac1d519cSBjoern A. Zeeb if (list_empty(&wwk->entry)) 6504ac1d519cSBjoern A. Zeeb list_add_tail(&wwk->entry, &lwiphy->wwk_list); 6505ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_UNLOCK(lwiphy); 6506ac1d519cSBjoern A. Zeeb 6507ac1d519cSBjoern A. Zeeb /* 6508ac1d519cSBjoern A. Zeeb * See how ieee80211_queue_work() work continues in Linux or if things 6509ac1d519cSBjoern A. Zeeb * migrate here over time? 6510ac1d519cSBjoern A. Zeeb * Use a system queue from linux/workqueue.h for now. 6511ac1d519cSBjoern A. Zeeb */ 6512ac1d519cSBjoern A. Zeeb queue_work(system_wq, &lwiphy->wwk); 6513ac1d519cSBjoern A. Zeeb } 6514ac1d519cSBjoern A. Zeeb 6515ac1d519cSBjoern A. Zeeb void 6516ac1d519cSBjoern A. Zeeb linuxkpi_wiphy_work_cancel(struct wiphy *wiphy, struct wiphy_work *wwk) 6517ac1d519cSBjoern A. Zeeb { 6518ac1d519cSBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 6519ac1d519cSBjoern A. Zeeb 6520ac1d519cSBjoern A. Zeeb lwiphy = WIPHY_TO_LWIPHY(wiphy); 6521ac1d519cSBjoern A. Zeeb 6522ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_LOCK(lwiphy); 6523ac1d519cSBjoern A. Zeeb /* Only cancel if queued. */ 6524ac1d519cSBjoern A. Zeeb if (!list_empty(&wwk->entry)) 6525ac1d519cSBjoern A. Zeeb list_del_init(&wwk->entry); 6526ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_UNLOCK(lwiphy); 6527ac1d519cSBjoern A. Zeeb } 6528ac1d519cSBjoern A. Zeeb 6529ac1d519cSBjoern A. Zeeb void 6530ac1d519cSBjoern A. Zeeb linuxkpi_wiphy_work_flush(struct wiphy *wiphy, struct wiphy_work *wwk) 6531ac1d519cSBjoern A. Zeeb { 6532ac1d519cSBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 6533ac1d519cSBjoern A. Zeeb struct wiphy_work *wk; 6534ac1d519cSBjoern A. Zeeb 6535ac1d519cSBjoern A. Zeeb lwiphy = WIPHY_TO_LWIPHY(wiphy); 6536ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_LOCK(lwiphy); 6537ac1d519cSBjoern A. Zeeb /* If wwk is unset, flush everything; called when wiphy is shut down. */ 6538ac1d519cSBjoern A. Zeeb if (wwk != NULL && list_empty(&wwk->entry)) { 6539ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_UNLOCK(lwiphy); 6540ac1d519cSBjoern A. Zeeb return; 6541ac1d519cSBjoern A. Zeeb } 6542ac1d519cSBjoern A. Zeeb 6543ac1d519cSBjoern A. Zeeb while (!list_empty(&lwiphy->wwk_list)) { 6544ac1d519cSBjoern A. Zeeb 6545ac1d519cSBjoern A. Zeeb wk = list_first_entry(&lwiphy->wwk_list, struct wiphy_work, 6546ac1d519cSBjoern A. Zeeb entry); 6547ac1d519cSBjoern A. Zeeb list_del_init(&wk->entry); 6548ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_UNLOCK(lwiphy); 6549ac1d519cSBjoern A. Zeeb wk->fn(wiphy, wk); 6550ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_LOCK(lwiphy); 6551ac1d519cSBjoern A. Zeeb if (wk == wwk) 6552ac1d519cSBjoern A. Zeeb break; 6553ac1d519cSBjoern A. Zeeb } 6554ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_UNLOCK(lwiphy); 6555ac1d519cSBjoern A. Zeeb } 6556ac1d519cSBjoern A. Zeeb 6557ac1d519cSBjoern A. Zeeb void 6558ac1d519cSBjoern A. Zeeb lkpi_wiphy_delayed_work_timer(struct timer_list *tl) 6559ac1d519cSBjoern A. Zeeb { 6560ac1d519cSBjoern A. Zeeb struct wiphy_delayed_work *wdwk; 6561ac1d519cSBjoern A. Zeeb 6562ac1d519cSBjoern A. Zeeb wdwk = from_timer(wdwk, tl, timer); 6563ac1d519cSBjoern A. Zeeb wiphy_work_queue(wdwk->wiphy, &wdwk->work); 6564ac1d519cSBjoern A. Zeeb } 6565ac1d519cSBjoern A. Zeeb 6566ac1d519cSBjoern A. Zeeb void 6567ac1d519cSBjoern A. Zeeb linuxkpi_wiphy_delayed_work_queue(struct wiphy *wiphy, 6568ac1d519cSBjoern A. Zeeb struct wiphy_delayed_work *wdwk, unsigned long delay) 6569ac1d519cSBjoern A. Zeeb { 6570ac1d519cSBjoern A. Zeeb if (delay == 0) { 6571ac1d519cSBjoern A. Zeeb /* Run right away. */ 6572ac1d519cSBjoern A. Zeeb del_timer(&wdwk->timer); 6573ac1d519cSBjoern A. Zeeb wiphy_work_queue(wiphy, &wdwk->work); 6574ac1d519cSBjoern A. Zeeb } else { 6575ac1d519cSBjoern A. Zeeb wdwk->wiphy = wiphy; 6576ac1d519cSBjoern A. Zeeb mod_timer(&wdwk->timer, jiffies + delay); 6577ac1d519cSBjoern A. Zeeb } 6578ac1d519cSBjoern A. Zeeb } 6579ac1d519cSBjoern A. Zeeb 6580ac1d519cSBjoern A. Zeeb void 6581ac1d519cSBjoern A. Zeeb linuxkpi_wiphy_delayed_work_cancel(struct wiphy *wiphy, 6582ac1d519cSBjoern A. Zeeb struct wiphy_delayed_work *wdwk) 6583ac1d519cSBjoern A. Zeeb { 6584ac1d519cSBjoern A. Zeeb del_timer_sync(&wdwk->timer); 6585ac1d519cSBjoern A. Zeeb wiphy_work_cancel(wiphy, &wdwk->work); 6586ac1d519cSBjoern A. Zeeb } 6587ac1d519cSBjoern A. Zeeb 6588ac1d519cSBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 6589ac1d519cSBjoern A. Zeeb 65906b4cac81SBjoern A. Zeeb struct wiphy * 65916b4cac81SBjoern A. Zeeb linuxkpi_wiphy_new(const struct cfg80211_ops *ops, size_t priv_len) 65926b4cac81SBjoern A. Zeeb { 65936b4cac81SBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 6594ac1d519cSBjoern A. Zeeb struct wiphy *wiphy; 65956b4cac81SBjoern A. Zeeb 65966b4cac81SBjoern A. Zeeb lwiphy = kzalloc(sizeof(*lwiphy) + priv_len, GFP_KERNEL); 65976b4cac81SBjoern A. Zeeb if (lwiphy == NULL) 65986b4cac81SBjoern A. Zeeb return (NULL); 65996b4cac81SBjoern A. Zeeb lwiphy->ops = ops; 66006b4cac81SBjoern A. Zeeb 6601ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_LOCK_INIT(lwiphy); 6602ac1d519cSBjoern A. Zeeb INIT_LIST_HEAD(&lwiphy->wwk_list); 6603ac1d519cSBjoern A. Zeeb INIT_WORK(&lwiphy->wwk, lkpi_wiphy_work); 6604ac1d519cSBjoern A. Zeeb 6605ac1d519cSBjoern A. Zeeb wiphy = LWIPHY_TO_WIPHY(lwiphy); 6606ac1d519cSBjoern A. Zeeb 6607ac1d519cSBjoern A. Zeeb mutex_init(&wiphy->mtx); 6608ac1d519cSBjoern A. Zeeb TODO(); 6609ac1d519cSBjoern A. Zeeb 6610ac1d519cSBjoern A. Zeeb return (wiphy); 66116b4cac81SBjoern A. Zeeb } 66126b4cac81SBjoern A. Zeeb 66136b4cac81SBjoern A. Zeeb void 66146b4cac81SBjoern A. Zeeb linuxkpi_wiphy_free(struct wiphy *wiphy) 66156b4cac81SBjoern A. Zeeb { 66166b4cac81SBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 66176b4cac81SBjoern A. Zeeb 66186b4cac81SBjoern A. Zeeb if (wiphy == NULL) 66196b4cac81SBjoern A. Zeeb return; 66206b4cac81SBjoern A. Zeeb 6621ac1d519cSBjoern A. Zeeb linuxkpi_wiphy_work_flush(wiphy, NULL); 6622ac1d519cSBjoern A. Zeeb mutex_destroy(&wiphy->mtx); 6623ac1d519cSBjoern A. Zeeb 66246b4cac81SBjoern A. Zeeb lwiphy = WIPHY_TO_LWIPHY(wiphy); 6625ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_LOCK_DESTROY(lwiphy); 6626ac1d519cSBjoern A. Zeeb 66276b4cac81SBjoern A. Zeeb kfree(lwiphy); 66286b4cac81SBjoern A. Zeeb } 66296b4cac81SBjoern A. Zeeb 6630a7c19b8aSBjoern A. Zeeb static uint32_t 6631a7c19b8aSBjoern A. Zeeb lkpi_cfg80211_calculate_bitrate_ht(struct rate_info *rate) 6632a7c19b8aSBjoern A. Zeeb { 6633a7c19b8aSBjoern A. Zeeb TODO("cfg80211_calculate_bitrate_ht"); 6634a7c19b8aSBjoern A. Zeeb return (rate->legacy); 6635a7c19b8aSBjoern A. Zeeb } 6636a7c19b8aSBjoern A. Zeeb 6637a7c19b8aSBjoern A. Zeeb static uint32_t 6638a7c19b8aSBjoern A. Zeeb lkpi_cfg80211_calculate_bitrate_vht(struct rate_info *rate) 6639a7c19b8aSBjoern A. Zeeb { 6640a7c19b8aSBjoern A. Zeeb TODO("cfg80211_calculate_bitrate_vht"); 6641a7c19b8aSBjoern A. Zeeb return (rate->legacy); 6642a7c19b8aSBjoern A. Zeeb } 6643a7c19b8aSBjoern A. Zeeb 6644a7c19b8aSBjoern A. Zeeb uint32_t 6645a7c19b8aSBjoern A. Zeeb linuxkpi_cfg80211_calculate_bitrate(struct rate_info *rate) 6646a7c19b8aSBjoern A. Zeeb { 6647a7c19b8aSBjoern A. Zeeb 6648a7c19b8aSBjoern A. Zeeb /* Beware: order! */ 6649a7c19b8aSBjoern A. Zeeb if (rate->flags & RATE_INFO_FLAGS_MCS) 6650a7c19b8aSBjoern A. Zeeb return (lkpi_cfg80211_calculate_bitrate_ht(rate)); 6651a7c19b8aSBjoern A. Zeeb 6652a7c19b8aSBjoern A. Zeeb if (rate->flags & RATE_INFO_FLAGS_VHT_MCS) 6653a7c19b8aSBjoern A. Zeeb return (lkpi_cfg80211_calculate_bitrate_vht(rate)); 6654a7c19b8aSBjoern A. Zeeb 6655a7c19b8aSBjoern A. Zeeb IMPROVE("HE/EHT/..."); 6656a7c19b8aSBjoern A. Zeeb 6657a7c19b8aSBjoern A. Zeeb return (rate->legacy); 6658a7c19b8aSBjoern A. Zeeb } 6659a7c19b8aSBjoern A. Zeeb 66606b4cac81SBjoern A. Zeeb uint32_t 66616b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_channel_to_frequency(uint32_t channel, 66626b4cac81SBjoern A. Zeeb enum nl80211_band band) 66636b4cac81SBjoern A. Zeeb { 66646b4cac81SBjoern A. Zeeb 66656b4cac81SBjoern A. Zeeb switch (band) { 66666b4cac81SBjoern A. Zeeb case NL80211_BAND_2GHZ: 66676b4cac81SBjoern A. Zeeb return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_2GHZ)); 66686b4cac81SBjoern A. Zeeb break; 66696b4cac81SBjoern A. Zeeb case NL80211_BAND_5GHZ: 66706b4cac81SBjoern A. Zeeb return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_5GHZ)); 66716b4cac81SBjoern A. Zeeb break; 66726b4cac81SBjoern A. Zeeb default: 66736b4cac81SBjoern A. Zeeb /* XXX abort, retry, error, panic? */ 66746b4cac81SBjoern A. Zeeb break; 66756b4cac81SBjoern A. Zeeb } 66766b4cac81SBjoern A. Zeeb 66776b4cac81SBjoern A. Zeeb return (0); 66786b4cac81SBjoern A. Zeeb } 66796b4cac81SBjoern A. Zeeb 66806b4cac81SBjoern A. Zeeb uint32_t 66816b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_frequency_to_channel(uint32_t freq, uint32_t flags __unused) 66826b4cac81SBjoern A. Zeeb { 66836b4cac81SBjoern A. Zeeb 66846b4cac81SBjoern A. Zeeb return (ieee80211_mhz2ieee(freq, 0)); 66856b4cac81SBjoern A. Zeeb } 66866b4cac81SBjoern A. Zeeb 6687ac867c20SBjoern A. Zeeb #if 0 66886b4cac81SBjoern A. Zeeb static struct lkpi_sta * 66896b4cac81SBjoern A. Zeeb lkpi_find_lsta_by_ni(struct lkpi_vif *lvif, struct ieee80211_node *ni) 66906b4cac81SBjoern A. Zeeb { 66916b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta, *temp; 66926b4cac81SBjoern A. Zeeb 6693a8f735a6SBjoern A. Zeeb rcu_read_lock(); 6694a8f735a6SBjoern A. Zeeb list_for_each_entry_rcu(lsta, &lvif->lsta_list, lsta_list) { 66956b4cac81SBjoern A. Zeeb if (lsta->ni == ni) { 6696a8f735a6SBjoern A. Zeeb rcu_read_unlock(); 66976b4cac81SBjoern A. Zeeb return (lsta); 66986b4cac81SBjoern A. Zeeb } 66996b4cac81SBjoern A. Zeeb } 6700a8f735a6SBjoern A. Zeeb rcu_read_unlock(); 67016b4cac81SBjoern A. Zeeb 67026b4cac81SBjoern A. Zeeb return (NULL); 67036b4cac81SBjoern A. Zeeb } 6704ac867c20SBjoern A. Zeeb #endif 67056b4cac81SBjoern A. Zeeb 67066b4cac81SBjoern A. Zeeb struct ieee80211_sta * 67076b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_find_sta(struct ieee80211_vif *vif, const u8 *peer) 67086b4cac81SBjoern A. Zeeb { 67096b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 6710a8f735a6SBjoern A. Zeeb struct lkpi_sta *lsta; 67116b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 67126b4cac81SBjoern A. Zeeb 67136b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 67146b4cac81SBjoern A. Zeeb 6715a8f735a6SBjoern A. Zeeb rcu_read_lock(); 6716a8f735a6SBjoern A. Zeeb list_for_each_entry_rcu(lsta, &lvif->lsta_list, lsta_list) { 67176b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 67186b4cac81SBjoern A. Zeeb if (IEEE80211_ADDR_EQ(sta->addr, peer)) { 6719a8f735a6SBjoern A. Zeeb rcu_read_unlock(); 67206b4cac81SBjoern A. Zeeb return (sta); 67216b4cac81SBjoern A. Zeeb } 67226b4cac81SBjoern A. Zeeb } 6723a8f735a6SBjoern A. Zeeb rcu_read_unlock(); 67246b4cac81SBjoern A. Zeeb return (NULL); 67256b4cac81SBjoern A. Zeeb } 67266b4cac81SBjoern A. Zeeb 67276b4cac81SBjoern A. Zeeb struct ieee80211_sta * 67282e183d99SBjoern A. Zeeb linuxkpi_ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw, 67292e183d99SBjoern A. Zeeb const uint8_t *addr, const uint8_t *ourvifaddr) 67306b4cac81SBjoern A. Zeeb { 67316b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 67326b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 67336b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 67346b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 67356b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 67366b4cac81SBjoern A. Zeeb 67376b4cac81SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 67386b4cac81SBjoern A. Zeeb sta = NULL; 67396b4cac81SBjoern A. Zeeb 67408891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 67416b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 67426b4cac81SBjoern A. Zeeb 67436b4cac81SBjoern A. Zeeb /* XXX-BZ check our address from the vif. */ 67446b4cac81SBjoern A. Zeeb 67456b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 67466b4cac81SBjoern A. Zeeb if (ourvifaddr != NULL && 67476b4cac81SBjoern A. Zeeb !IEEE80211_ADDR_EQ(vif->addr, ourvifaddr)) 67486b4cac81SBjoern A. Zeeb continue; 67496b4cac81SBjoern A. Zeeb sta = linuxkpi_ieee80211_find_sta(vif, addr); 67506b4cac81SBjoern A. Zeeb if (sta != NULL) 67516b4cac81SBjoern A. Zeeb break; 67526b4cac81SBjoern A. Zeeb } 67538891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 67546b4cac81SBjoern A. Zeeb 67556b4cac81SBjoern A. Zeeb if (sta != NULL) { 67566b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 67576b4cac81SBjoern A. Zeeb if (!lsta->added_to_drv) 67586b4cac81SBjoern A. Zeeb return (NULL); 67596b4cac81SBjoern A. Zeeb } 67606b4cac81SBjoern A. Zeeb 67616b4cac81SBjoern A. Zeeb return (sta); 67626b4cac81SBjoern A. Zeeb } 67636b4cac81SBjoern A. Zeeb 67646b4cac81SBjoern A. Zeeb struct sk_buff * 67656b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_tx_dequeue(struct ieee80211_hw *hw, 67666b4cac81SBjoern A. Zeeb struct ieee80211_txq *txq) 67676b4cac81SBjoern A. Zeeb { 67686b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 67690cbcfa19SBjoern A. Zeeb struct lkpi_vif *lvif; 67706b4cac81SBjoern A. Zeeb struct sk_buff *skb; 67716b4cac81SBjoern A. Zeeb 67720cbcfa19SBjoern A. Zeeb skb = NULL; 67736b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 67746b4cac81SBjoern A. Zeeb ltxq->seen_dequeue = true; 67756b4cac81SBjoern A. Zeeb 67760cbcfa19SBjoern A. Zeeb if (ltxq->stopped) 67770cbcfa19SBjoern A. Zeeb goto stopped; 67780cbcfa19SBjoern A. Zeeb 67790cbcfa19SBjoern A. Zeeb lvif = VIF_TO_LVIF(ltxq->txq.vif); 67800cbcfa19SBjoern A. Zeeb if (lvif->hw_queue_stopped[ltxq->txq.ac]) { 67810cbcfa19SBjoern A. Zeeb ltxq->stopped = true; 67820cbcfa19SBjoern A. Zeeb goto stopped; 67830cbcfa19SBjoern A. Zeeb } 67840cbcfa19SBjoern A. Zeeb 6785eac3646fSBjoern A. Zeeb IMPROVE("hw(TX_FRAG_LIST)"); 6786eac3646fSBjoern A. Zeeb 6787eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_LOCK(ltxq); 67886b4cac81SBjoern A. Zeeb skb = skb_dequeue(<xq->skbq); 6789eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_UNLOCK(ltxq); 67906b4cac81SBjoern A. Zeeb 67910cbcfa19SBjoern A. Zeeb stopped: 67926b4cac81SBjoern A. Zeeb return (skb); 67936b4cac81SBjoern A. Zeeb } 67946b4cac81SBjoern A. Zeeb 67956b4cac81SBjoern A. Zeeb void 67966b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_txq_get_depth(struct ieee80211_txq *txq, 679786220d3cSBjoern A. Zeeb unsigned long *frame_cnt, unsigned long *byte_cnt) 67986b4cac81SBjoern A. Zeeb { 67996b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 68006b4cac81SBjoern A. Zeeb struct sk_buff *skb; 680186220d3cSBjoern A. Zeeb unsigned long fc, bc; 68026b4cac81SBjoern A. Zeeb 68036b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 68046b4cac81SBjoern A. Zeeb 68056b4cac81SBjoern A. Zeeb fc = bc = 0; 6806eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_LOCK(ltxq); 68076b4cac81SBjoern A. Zeeb skb_queue_walk(<xq->skbq, skb) { 68086b4cac81SBjoern A. Zeeb fc++; 68096b4cac81SBjoern A. Zeeb bc += skb->len; 68106b4cac81SBjoern A. Zeeb } 6811eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_UNLOCK(ltxq); 68126b4cac81SBjoern A. Zeeb if (frame_cnt) 68136b4cac81SBjoern A. Zeeb *frame_cnt = fc; 68146b4cac81SBjoern A. Zeeb if (byte_cnt) 68156b4cac81SBjoern A. Zeeb *byte_cnt = bc; 68166b4cac81SBjoern A. Zeeb 68176b4cac81SBjoern A. Zeeb /* Validate that this is doing the correct thing. */ 68186b4cac81SBjoern A. Zeeb /* Should we keep track on en/dequeue? */ 68196b4cac81SBjoern A. Zeeb IMPROVE(); 68206b4cac81SBjoern A. Zeeb } 68216b4cac81SBjoern A. Zeeb 68226b4cac81SBjoern A. Zeeb /* 68236b4cac81SBjoern A. Zeeb * We are called from ieee80211_free_txskb() or ieee80211_tx_status(). 68246b4cac81SBjoern A. Zeeb * The latter tries to derive the success status from the info flags 68256b4cac81SBjoern A. Zeeb * passed back from the driver. rawx_mit() saves the ni on the m and the 68266b4cac81SBjoern A. Zeeb * m on the skb for us to be able to give feedback to net80211. 68276b4cac81SBjoern A. Zeeb */ 6828a8397571SBjoern A. Zeeb static void 6829a8397571SBjoern A. Zeeb _lkpi_ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb, 68306b4cac81SBjoern A. Zeeb int status) 68316b4cac81SBjoern A. Zeeb { 68326b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 68336b4cac81SBjoern A. Zeeb struct mbuf *m; 68346b4cac81SBjoern A. Zeeb 68356b4cac81SBjoern A. Zeeb m = skb->m; 68366b4cac81SBjoern A. Zeeb skb->m = NULL; 68376b4cac81SBjoern A. Zeeb 68386b4cac81SBjoern A. Zeeb if (m != NULL) { 68396b4cac81SBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 68406b4cac81SBjoern A. Zeeb /* Status: 0 is ok, != 0 is error. */ 68416b4cac81SBjoern A. Zeeb ieee80211_tx_complete(ni, m, status); 68426b4cac81SBjoern A. Zeeb /* ni & mbuf were consumed. */ 68436b4cac81SBjoern A. Zeeb } 6844a8397571SBjoern A. Zeeb } 68456b4cac81SBjoern A. Zeeb 6846a8397571SBjoern A. Zeeb void 6847a8397571SBjoern A. Zeeb linuxkpi_ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb, 6848a8397571SBjoern A. Zeeb int status) 6849a8397571SBjoern A. Zeeb { 6850a8397571SBjoern A. Zeeb 6851a8397571SBjoern A. Zeeb _lkpi_ieee80211_free_txskb(hw, skb, status); 68526b4cac81SBjoern A. Zeeb kfree_skb(skb); 68536b4cac81SBjoern A. Zeeb } 68546b4cac81SBjoern A. Zeeb 6855383b3e8fSBjoern A. Zeeb void 6856a8397571SBjoern A. Zeeb linuxkpi_ieee80211_tx_status_ext(struct ieee80211_hw *hw, 6857a8397571SBjoern A. Zeeb struct ieee80211_tx_status *txstat) 6858383b3e8fSBjoern A. Zeeb { 6859a8397571SBjoern A. Zeeb struct sk_buff *skb; 6860383b3e8fSBjoern A. Zeeb struct ieee80211_tx_info *info; 6861383b3e8fSBjoern A. Zeeb struct ieee80211_ratectl_tx_status txs; 6862383b3e8fSBjoern A. Zeeb struct ieee80211_node *ni; 6863383b3e8fSBjoern A. Zeeb int status; 6864383b3e8fSBjoern A. Zeeb 6865a8397571SBjoern A. Zeeb skb = txstat->skb; 6866383b3e8fSBjoern A. Zeeb if (skb->m != NULL) { 6867383b3e8fSBjoern A. Zeeb struct mbuf *m; 6868383b3e8fSBjoern A. Zeeb 6869383b3e8fSBjoern A. Zeeb m = skb->m; 6870383b3e8fSBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 6871383b3e8fSBjoern A. Zeeb memset(&txs, 0, sizeof(txs)); 6872383b3e8fSBjoern A. Zeeb } else { 6873383b3e8fSBjoern A. Zeeb ni = NULL; 6874383b3e8fSBjoern A. Zeeb } 6875383b3e8fSBjoern A. Zeeb 6876a8397571SBjoern A. Zeeb info = txstat->info; 6877383b3e8fSBjoern A. Zeeb if (info->flags & IEEE80211_TX_STAT_ACK) { 6878383b3e8fSBjoern A. Zeeb status = 0; /* No error. */ 6879383b3e8fSBjoern A. Zeeb txs.status = IEEE80211_RATECTL_TX_SUCCESS; 6880383b3e8fSBjoern A. Zeeb } else { 6881383b3e8fSBjoern A. Zeeb status = 1; 6882383b3e8fSBjoern A. Zeeb txs.status = IEEE80211_RATECTL_TX_FAIL_UNSPECIFIED; 6883383b3e8fSBjoern A. Zeeb } 6884383b3e8fSBjoern A. Zeeb 6885383b3e8fSBjoern A. Zeeb if (ni != NULL) { 6886e2c5ab09SJohn Baldwin int ridx __unused; 6887383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 6888383b3e8fSBjoern A. Zeeb int old_rate; 6889383b3e8fSBjoern A. Zeeb 6890383b3e8fSBjoern A. Zeeb old_rate = ni->ni_vap->iv_bss->ni_txrate; 6891383b3e8fSBjoern A. Zeeb #endif 6892383b3e8fSBjoern A. Zeeb txs.pktlen = skb->len; 6893383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_PKTLEN; 6894383b3e8fSBjoern A. Zeeb if (info->status.rates[0].count > 1) { 6895383b3e8fSBjoern A. Zeeb txs.long_retries = info->status.rates[0].count - 1; /* 1 + retries in drivers. */ 6896383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_LONG_RETRY; 6897383b3e8fSBjoern A. Zeeb } 6898383b3e8fSBjoern A. Zeeb #if 0 /* Unused in net80211 currently. */ 6899a8397571SBjoern A. Zeeb /* XXX-BZ convert check .flags for MCS/VHT/.. */ 6900383b3e8fSBjoern A. Zeeb txs.final_rate = info->status.rates[0].idx; 6901383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_FINAL_RATE; 6902383b3e8fSBjoern A. Zeeb #endif 6903adff403fSBjoern A. Zeeb if (info->status.flags & IEEE80211_TX_STATUS_ACK_SIGNAL_VALID) { 6904383b3e8fSBjoern A. Zeeb txs.rssi = info->status.ack_signal; /* XXX-BZ CONVERT? */ 6905383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_RSSI; 6906383b3e8fSBjoern A. Zeeb } 6907383b3e8fSBjoern A. Zeeb 6908383b3e8fSBjoern A. Zeeb IMPROVE("only update of rate matches but that requires us to get a proper rate"); 6909383b3e8fSBjoern A. Zeeb ieee80211_ratectl_tx_complete(ni, &txs); 6910383b3e8fSBjoern A. Zeeb ridx = ieee80211_ratectl_rate(ni->ni_vap->iv_bss, NULL, 0); 6911383b3e8fSBjoern A. Zeeb 6912383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 6913383b3e8fSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) { 6914383b3e8fSBjoern A. Zeeb printf("TX-RATE: %s: old %d new %d ridx %d, " 6915383b3e8fSBjoern A. Zeeb "long_retries %d\n", __func__, 6916383b3e8fSBjoern A. Zeeb old_rate, ni->ni_vap->iv_bss->ni_txrate, 6917383b3e8fSBjoern A. Zeeb ridx, txs.long_retries); 6918383b3e8fSBjoern A. Zeeb } 6919383b3e8fSBjoern A. Zeeb #endif 6920383b3e8fSBjoern A. Zeeb } 6921383b3e8fSBjoern A. Zeeb 6922383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 6923383b3e8fSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 6924383b3e8fSBjoern A. Zeeb printf("TX-STATUS: %s: hw %p skb %p status %d : flags %#x " 6925383b3e8fSBjoern A. Zeeb "band %u hw_queue %u tx_time_est %d : " 6926383b3e8fSBjoern A. Zeeb "rates [ %u %u %#x, %u %u %#x, %u %u %#x, %u %u %#x ] " 6927383b3e8fSBjoern A. Zeeb "ack_signal %u ampdu_ack_len %u ampdu_len %u antenna %u " 6928adff403fSBjoern A. Zeeb "tx_time %u flags %#x " 6929383b3e8fSBjoern A. Zeeb "status_driver_data [ %p %p ]\n", 6930383b3e8fSBjoern A. Zeeb __func__, hw, skb, status, info->flags, 6931383b3e8fSBjoern A. Zeeb info->band, info->hw_queue, info->tx_time_est, 6932383b3e8fSBjoern A. Zeeb info->status.rates[0].idx, info->status.rates[0].count, 6933383b3e8fSBjoern A. Zeeb info->status.rates[0].flags, 6934383b3e8fSBjoern A. Zeeb info->status.rates[1].idx, info->status.rates[1].count, 6935383b3e8fSBjoern A. Zeeb info->status.rates[1].flags, 6936383b3e8fSBjoern A. Zeeb info->status.rates[2].idx, info->status.rates[2].count, 6937383b3e8fSBjoern A. Zeeb info->status.rates[2].flags, 6938383b3e8fSBjoern A. Zeeb info->status.rates[3].idx, info->status.rates[3].count, 6939383b3e8fSBjoern A. Zeeb info->status.rates[3].flags, 6940383b3e8fSBjoern A. Zeeb info->status.ack_signal, info->status.ampdu_ack_len, 6941383b3e8fSBjoern A. Zeeb info->status.ampdu_len, info->status.antenna, 6942adff403fSBjoern A. Zeeb info->status.tx_time, info->status.flags, 6943383b3e8fSBjoern A. Zeeb info->status.status_driver_data[0], 6944383b3e8fSBjoern A. Zeeb info->status.status_driver_data[1]); 6945383b3e8fSBjoern A. Zeeb #endif 6946383b3e8fSBjoern A. Zeeb 6947a8397571SBjoern A. Zeeb if (txstat->free_list) { 6948a8397571SBjoern A. Zeeb _lkpi_ieee80211_free_txskb(hw, skb, status); 6949a8397571SBjoern A. Zeeb list_add_tail(&skb->list, txstat->free_list); 6950a8397571SBjoern A. Zeeb } else { 6951383b3e8fSBjoern A. Zeeb linuxkpi_ieee80211_free_txskb(hw, skb, status); 6952383b3e8fSBjoern A. Zeeb } 6953a8397571SBjoern A. Zeeb } 6954a8397571SBjoern A. Zeeb 6955a8397571SBjoern A. Zeeb void 6956a8397571SBjoern A. Zeeb linuxkpi_ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb) 6957a8397571SBjoern A. Zeeb { 6958a8397571SBjoern A. Zeeb struct ieee80211_tx_status status; 6959a8397571SBjoern A. Zeeb 6960a8397571SBjoern A. Zeeb memset(&status, 0, sizeof(status)); 6961a8397571SBjoern A. Zeeb status.info = IEEE80211_SKB_CB(skb); 6962a8397571SBjoern A. Zeeb status.skb = skb; 6963a8397571SBjoern A. Zeeb /* sta, n_rates, rates, free_list? */ 6964a8397571SBjoern A. Zeeb 6965a8397571SBjoern A. Zeeb ieee80211_tx_status_ext(hw, &status); 6966a8397571SBjoern A. Zeeb } 6967383b3e8fSBjoern A. Zeeb 69686b4cac81SBjoern A. Zeeb /* 69696b4cac81SBjoern A. Zeeb * This is an internal bandaid for the moment for the way we glue 69706b4cac81SBjoern A. Zeeb * skbs and mbufs together for TX. Once we have skbs backed by 69716b4cac81SBjoern A. Zeeb * mbufs this should go away. 69726b4cac81SBjoern A. Zeeb * This is a public function but kept on the private KPI (lkpi_) 69736b4cac81SBjoern A. Zeeb * and is not exposed by a header file. 69746b4cac81SBjoern A. Zeeb */ 69756b4cac81SBjoern A. Zeeb static void 69766b4cac81SBjoern A. Zeeb lkpi_ieee80211_free_skb_mbuf(void *p) 69776b4cac81SBjoern A. Zeeb { 69786b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 69796b4cac81SBjoern A. Zeeb struct mbuf *m; 69806b4cac81SBjoern A. Zeeb 69816b4cac81SBjoern A. Zeeb if (p == NULL) 69826b4cac81SBjoern A. Zeeb return; 69836b4cac81SBjoern A. Zeeb 69846b4cac81SBjoern A. Zeeb m = (struct mbuf *)p; 69856b4cac81SBjoern A. Zeeb M_ASSERTPKTHDR(m); 69866b4cac81SBjoern A. Zeeb 69876b4cac81SBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 69886b4cac81SBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = NULL; 69896b4cac81SBjoern A. Zeeb if (ni != NULL) 69906b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 69916b4cac81SBjoern A. Zeeb m_freem(m); 69926b4cac81SBjoern A. Zeeb } 69936b4cac81SBjoern A. Zeeb 69946b4cac81SBjoern A. Zeeb void 69956b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_queue_delayed_work(struct ieee80211_hw *hw, 69966b4cac81SBjoern A. Zeeb struct delayed_work *w, int delay) 69976b4cac81SBjoern A. Zeeb { 69986b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 69996b4cac81SBjoern A. Zeeb 70006b4cac81SBjoern A. Zeeb /* Need to make sure hw is in a stable (non-suspended) state. */ 70016b4cac81SBjoern A. Zeeb IMPROVE(); 70026b4cac81SBjoern A. Zeeb 70036b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 70046b4cac81SBjoern A. Zeeb queue_delayed_work(lhw->workq, w, delay); 70056b4cac81SBjoern A. Zeeb } 70066b4cac81SBjoern A. Zeeb 70076b4cac81SBjoern A. Zeeb void 70086b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_queue_work(struct ieee80211_hw *hw, 70096b4cac81SBjoern A. Zeeb struct work_struct *w) 70106b4cac81SBjoern A. Zeeb { 70116b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 70126b4cac81SBjoern A. Zeeb 70136b4cac81SBjoern A. Zeeb /* Need to make sure hw is in a stable (non-suspended) state. */ 70146b4cac81SBjoern A. Zeeb IMPROVE(); 70156b4cac81SBjoern A. Zeeb 70166b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 70176b4cac81SBjoern A. Zeeb queue_work(lhw->workq, w); 70186b4cac81SBjoern A. Zeeb } 70196b4cac81SBjoern A. Zeeb 70206b4cac81SBjoern A. Zeeb struct sk_buff * 7021ade774b1SBjoern A. Zeeb linuxkpi_ieee80211_probereq_get(struct ieee80211_hw *hw, uint8_t *addr, 7022ade774b1SBjoern A. Zeeb uint8_t *ssid, size_t ssid_len, size_t tailroom) 7023ade774b1SBjoern A. Zeeb { 7024ade774b1SBjoern A. Zeeb struct sk_buff *skb; 7025ade774b1SBjoern A. Zeeb struct ieee80211_frame *wh; 7026ade774b1SBjoern A. Zeeb uint8_t *p; 7027ade774b1SBjoern A. Zeeb size_t len; 7028ade774b1SBjoern A. Zeeb 7029ade774b1SBjoern A. Zeeb len = sizeof(*wh); 7030ade774b1SBjoern A. Zeeb len += 2 + ssid_len; 7031ade774b1SBjoern A. Zeeb 7032ade774b1SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + len + tailroom); 7033ade774b1SBjoern A. Zeeb if (skb == NULL) 7034ade774b1SBjoern A. Zeeb return (NULL); 7035ade774b1SBjoern A. Zeeb 7036ade774b1SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 7037ade774b1SBjoern A. Zeeb 7038ade774b1SBjoern A. Zeeb wh = skb_put_zero(skb, sizeof(*wh)); 7039ade774b1SBjoern A. Zeeb wh->i_fc[0] = IEEE80211_FC0_VERSION_0; 7040ade774b1SBjoern A. Zeeb wh->i_fc[0] |= IEEE80211_FC0_SUBTYPE_PROBE_REQ | IEEE80211_FC0_TYPE_MGT; 7041ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr1, ieee80211broadcastaddr); 7042ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr2, addr); 7043ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr3, ieee80211broadcastaddr); 7044ade774b1SBjoern A. Zeeb 7045ade774b1SBjoern A. Zeeb p = skb_put(skb, 2 + ssid_len); 7046ade774b1SBjoern A. Zeeb *p++ = IEEE80211_ELEMID_SSID; 7047ade774b1SBjoern A. Zeeb *p++ = ssid_len; 7048ade774b1SBjoern A. Zeeb if (ssid_len > 0) 7049ade774b1SBjoern A. Zeeb memcpy(p, ssid, ssid_len); 7050ade774b1SBjoern A. Zeeb 7051ade774b1SBjoern A. Zeeb return (skb); 7052ade774b1SBjoern A. Zeeb } 7053ade774b1SBjoern A. Zeeb 7054ade774b1SBjoern A. Zeeb struct sk_buff * 70556b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_pspoll_get(struct ieee80211_hw *hw, 70566b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif) 70576b4cac81SBjoern A. Zeeb { 70586b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 70596b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 70606b4cac81SBjoern A. Zeeb struct sk_buff *skb; 70616b4cac81SBjoern A. Zeeb struct ieee80211_frame_pspoll *psp; 70626b4cac81SBjoern A. Zeeb uint16_t v; 70636b4cac81SBjoern A. Zeeb 70646b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*psp)); 70656b4cac81SBjoern A. Zeeb if (skb == NULL) 70666b4cac81SBjoern A. Zeeb return (NULL); 70676b4cac81SBjoern A. Zeeb 70686b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 70696b4cac81SBjoern A. Zeeb 70706b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 70716b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 70726b4cac81SBjoern A. Zeeb 70736b4cac81SBjoern A. Zeeb psp = skb_put_zero(skb, sizeof(*psp)); 70746b4cac81SBjoern A. Zeeb psp->i_fc[0] = IEEE80211_FC0_VERSION_0; 70756b4cac81SBjoern A. Zeeb psp->i_fc[0] |= IEEE80211_FC0_SUBTYPE_PS_POLL | IEEE80211_FC0_TYPE_CTL; 7076616e1330SBjoern A. Zeeb v = htole16(vif->cfg.aid | 1<<15 | 1<<16); 70776b4cac81SBjoern A. Zeeb memcpy(&psp->i_aid, &v, sizeof(v)); 70786b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(psp->i_bssid, vap->iv_bss->ni_macaddr); 70796b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(psp->i_ta, vif->addr); 70806b4cac81SBjoern A. Zeeb 70816b4cac81SBjoern A. Zeeb return (skb); 70826b4cac81SBjoern A. Zeeb } 70836b4cac81SBjoern A. Zeeb 70846b4cac81SBjoern A. Zeeb struct sk_buff * 70856b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_nullfunc_get(struct ieee80211_hw *hw, 7086adff403fSBjoern A. Zeeb struct ieee80211_vif *vif, int linkid, bool qos) 70876b4cac81SBjoern A. Zeeb { 70886b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 70896b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 70906b4cac81SBjoern A. Zeeb struct sk_buff *skb; 70916b4cac81SBjoern A. Zeeb struct ieee80211_frame *nullf; 70926b4cac81SBjoern A. Zeeb 7093adff403fSBjoern A. Zeeb IMPROVE("linkid"); 7094adff403fSBjoern A. Zeeb 70956b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*nullf)); 70966b4cac81SBjoern A. Zeeb if (skb == NULL) 70976b4cac81SBjoern A. Zeeb return (NULL); 70986b4cac81SBjoern A. Zeeb 70996b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 71006b4cac81SBjoern A. Zeeb 71016b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 71026b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 71036b4cac81SBjoern A. Zeeb 71046b4cac81SBjoern A. Zeeb nullf = skb_put_zero(skb, sizeof(*nullf)); 71056b4cac81SBjoern A. Zeeb nullf->i_fc[0] = IEEE80211_FC0_VERSION_0; 71066b4cac81SBjoern A. Zeeb nullf->i_fc[0] |= IEEE80211_FC0_SUBTYPE_NODATA | IEEE80211_FC0_TYPE_DATA; 71076b4cac81SBjoern A. Zeeb nullf->i_fc[1] = IEEE80211_FC1_DIR_TODS; 71086b4cac81SBjoern A. Zeeb 71096b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr1, vap->iv_bss->ni_bssid); 71106b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr2, vif->addr); 71116b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr3, vap->iv_bss->ni_macaddr); 71126b4cac81SBjoern A. Zeeb 71136b4cac81SBjoern A. Zeeb return (skb); 71146b4cac81SBjoern A. Zeeb } 71156b4cac81SBjoern A. Zeeb 71166b4cac81SBjoern A. Zeeb struct wireless_dev * 71176b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_vif_to_wdev(struct ieee80211_vif *vif) 71186b4cac81SBjoern A. Zeeb { 71196b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 71206b4cac81SBjoern A. Zeeb 71216b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 71226b4cac81SBjoern A. Zeeb return (&lvif->wdev); 71236b4cac81SBjoern A. Zeeb } 71246b4cac81SBjoern A. Zeeb 71256b4cac81SBjoern A. Zeeb void 71266b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_connection_loss(struct ieee80211_vif *vif) 71276b4cac81SBjoern A. Zeeb { 71286b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 71296b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 71306b4cac81SBjoern A. Zeeb enum ieee80211_state nstate; 71316b4cac81SBjoern A. Zeeb int arg; 71326b4cac81SBjoern A. Zeeb 71336b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 71346b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 71356b4cac81SBjoern A. Zeeb 71366b4cac81SBjoern A. Zeeb /* 7137f3229b62SBjoern A. Zeeb * Go to init; otherwise we need to elaborately check state and 71386b4cac81SBjoern A. Zeeb * handle accordingly, e.g., if in RUN we could call iv_bmiss. 71396b4cac81SBjoern A. Zeeb * Let the statemachine handle all neccessary changes. 71406b4cac81SBjoern A. Zeeb */ 7141f3229b62SBjoern A. Zeeb nstate = IEEE80211_S_INIT; 7142bb81db90SBjoern A. Zeeb arg = 0; /* Not a valid reason. */ 71436b4cac81SBjoern A. Zeeb 7144018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: vif %p vap %p state %s\n", __func__, 7145018d93ecSBjoern A. Zeeb vif, vap, ieee80211_state_name[vap->iv_state]); 71466b4cac81SBjoern A. Zeeb ieee80211_new_state(vap, nstate, arg); 71476b4cac81SBjoern A. Zeeb } 71486b4cac81SBjoern A. Zeeb 7149bb81db90SBjoern A. Zeeb void 7150bb81db90SBjoern A. Zeeb linuxkpi_ieee80211_beacon_loss(struct ieee80211_vif *vif) 7151bb81db90SBjoern A. Zeeb { 7152bb81db90SBjoern A. Zeeb struct lkpi_vif *lvif; 7153bb81db90SBjoern A. Zeeb struct ieee80211vap *vap; 7154bb81db90SBjoern A. Zeeb 7155bb81db90SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 7156bb81db90SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 7157bb81db90SBjoern A. Zeeb 7158bb81db90SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: vif %p vap %p state %s\n", __func__, 7159bb81db90SBjoern A. Zeeb vif, vap, ieee80211_state_name[vap->iv_state]); 71603540911bSBjoern A. Zeeb ieee80211_beacon_miss(vap->iv_ic); 7161bb81db90SBjoern A. Zeeb } 7162bb81db90SBjoern A. Zeeb 71635edde07cSBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 71645edde07cSBjoern A. Zeeb 71655a9a0d78SBjoern A. Zeeb void 71665a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_stop_queue(struct ieee80211_hw *hw, int qnum) 71675a9a0d78SBjoern A. Zeeb { 71685a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 71695a9a0d78SBjoern A. Zeeb struct lkpi_vif *lvif; 71705a9a0d78SBjoern A. Zeeb struct ieee80211_vif *vif; 71715a9a0d78SBjoern A. Zeeb int ac_count, ac; 71725a9a0d78SBjoern A. Zeeb 71735a9a0d78SBjoern A. Zeeb KASSERT(qnum < hw->queues, ("%s: qnum %d >= hw->queues %d, hw %p\n", 71745a9a0d78SBjoern A. Zeeb __func__, qnum, hw->queues, hw)); 71755a9a0d78SBjoern A. Zeeb 71765a9a0d78SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 71775a9a0d78SBjoern A. Zeeb 71785a9a0d78SBjoern A. Zeeb /* See lkpi_ic_vap_create(). */ 71795a9a0d78SBjoern A. Zeeb if (hw->queues >= IEEE80211_NUM_ACS) 71805a9a0d78SBjoern A. Zeeb ac_count = IEEE80211_NUM_ACS; 71815a9a0d78SBjoern A. Zeeb else 71825a9a0d78SBjoern A. Zeeb ac_count = 1; 71835a9a0d78SBjoern A. Zeeb 71845a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 71855a9a0d78SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 71865a9a0d78SBjoern A. Zeeb 71875a9a0d78SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 71885a9a0d78SBjoern A. Zeeb for (ac = 0; ac < ac_count; ac++) { 71895a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 71905a9a0d78SBjoern A. Zeeb if (qnum == vif->hw_queue[ac]) { 71910d2cb6a6SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 71925a9a0d78SBjoern A. Zeeb /* 71935a9a0d78SBjoern A. Zeeb * For now log this to better understand 71945a9a0d78SBjoern A. Zeeb * how this is supposed to work. 71955a9a0d78SBjoern A. Zeeb */ 71960d2cb6a6SBjoern A. Zeeb if (lvif->hw_queue_stopped[ac] && 71970d2cb6a6SBjoern A. Zeeb (linuxkpi_debug_80211 & D80211_IMPROVE_TXQ) != 0) 71985a9a0d78SBjoern A. Zeeb ic_printf(lhw->ic, "%s:%d: lhw %p hw %p " 71995a9a0d78SBjoern A. Zeeb "lvif %p vif %p ac %d qnum %d already " 72005a9a0d78SBjoern A. Zeeb "stopped\n", __func__, __LINE__, 72015a9a0d78SBjoern A. Zeeb lhw, hw, lvif, vif, ac, qnum); 72020d2cb6a6SBjoern A. Zeeb #endif 72035a9a0d78SBjoern A. Zeeb lvif->hw_queue_stopped[ac] = true; 72045a9a0d78SBjoern A. Zeeb } 72055a9a0d78SBjoern A. Zeeb } 72065a9a0d78SBjoern A. Zeeb } 72075a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 72085a9a0d78SBjoern A. Zeeb } 72095a9a0d78SBjoern A. Zeeb 72105a9a0d78SBjoern A. Zeeb void 72115a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_stop_queues(struct ieee80211_hw *hw) 72125a9a0d78SBjoern A. Zeeb { 72135a9a0d78SBjoern A. Zeeb int i; 72145a9a0d78SBjoern A. Zeeb 72155a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Locking; do we need further info?"); 72165a9a0d78SBjoern A. Zeeb for (i = 0; i < hw->queues; i++) 72175a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_stop_queue(hw, i); 72185a9a0d78SBjoern A. Zeeb } 72195a9a0d78SBjoern A. Zeeb 72205a9a0d78SBjoern A. Zeeb 72215a9a0d78SBjoern A. Zeeb static void 72225a9a0d78SBjoern A. Zeeb lkpi_ieee80211_wake_queues(struct ieee80211_hw *hw, int hwq) 72235a9a0d78SBjoern A. Zeeb { 72245a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 72255a9a0d78SBjoern A. Zeeb struct lkpi_vif *lvif; 72265a9a0d78SBjoern A. Zeeb struct lkpi_sta *lsta; 72275a9a0d78SBjoern A. Zeeb int ac_count, ac, tid; 72285a9a0d78SBjoern A. Zeeb 72295a9a0d78SBjoern A. Zeeb /* See lkpi_ic_vap_create(). */ 72305a9a0d78SBjoern A. Zeeb if (hw->queues >= IEEE80211_NUM_ACS) 72315a9a0d78SBjoern A. Zeeb ac_count = IEEE80211_NUM_ACS; 72325a9a0d78SBjoern A. Zeeb else 72335a9a0d78SBjoern A. Zeeb ac_count = 1; 72345a9a0d78SBjoern A. Zeeb 72355a9a0d78SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 72365a9a0d78SBjoern A. Zeeb 72375a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Locking"); 72385a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 72395a9a0d78SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 72405a9a0d78SBjoern A. Zeeb struct ieee80211_vif *vif; 72415a9a0d78SBjoern A. Zeeb 72425a9a0d78SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 72435a9a0d78SBjoern A. Zeeb for (ac = 0; ac < ac_count; ac++) { 72445a9a0d78SBjoern A. Zeeb 72455a9a0d78SBjoern A. Zeeb if (hwq == vif->hw_queue[ac]) { 72465a9a0d78SBjoern A. Zeeb 72475a9a0d78SBjoern A. Zeeb /* XXX-BZ what about software scan? */ 72485a9a0d78SBjoern A. Zeeb 72490d2cb6a6SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 72505a9a0d78SBjoern A. Zeeb /* 72515a9a0d78SBjoern A. Zeeb * For now log this to better understand 72525a9a0d78SBjoern A. Zeeb * how this is supposed to work. 72535a9a0d78SBjoern A. Zeeb */ 72540d2cb6a6SBjoern A. Zeeb if (!lvif->hw_queue_stopped[ac] && 72550d2cb6a6SBjoern A. Zeeb (linuxkpi_debug_80211 & D80211_IMPROVE_TXQ) != 0) 72565a9a0d78SBjoern A. Zeeb ic_printf(lhw->ic, "%s:%d: lhw %p hw %p " 72575a9a0d78SBjoern A. Zeeb "lvif %p vif %p ac %d hw_q not stopped\n", 72585a9a0d78SBjoern A. Zeeb __func__, __LINE__, 72595a9a0d78SBjoern A. Zeeb lhw, hw, lvif, vif, ac); 72600d2cb6a6SBjoern A. Zeeb #endif 72615a9a0d78SBjoern A. Zeeb lvif->hw_queue_stopped[ac] = false; 72625a9a0d78SBjoern A. Zeeb 7263a8f735a6SBjoern A. Zeeb rcu_read_lock(); 7264a8f735a6SBjoern A. Zeeb list_for_each_entry_rcu(lsta, &lvif->lsta_list, lsta_list) { 72655a9a0d78SBjoern A. Zeeb struct ieee80211_sta *sta; 72665a9a0d78SBjoern A. Zeeb 72675a9a0d78SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 72685a9a0d78SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 72695a9a0d78SBjoern A. Zeeb struct lkpi_txq *ltxq; 72705a9a0d78SBjoern A. Zeeb 72715a9a0d78SBjoern A. Zeeb if (sta->txq[tid] == NULL) 72725a9a0d78SBjoern A. Zeeb continue; 72735a9a0d78SBjoern A. Zeeb 72745a9a0d78SBjoern A. Zeeb if (sta->txq[tid]->ac != ac) 72755a9a0d78SBjoern A. Zeeb continue; 72765a9a0d78SBjoern A. Zeeb 72775a9a0d78SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]); 72785a9a0d78SBjoern A. Zeeb if (!ltxq->stopped) 72795a9a0d78SBjoern A. Zeeb continue; 72805a9a0d78SBjoern A. Zeeb 72815a9a0d78SBjoern A. Zeeb ltxq->stopped = false; 72825a9a0d78SBjoern A. Zeeb 72835a9a0d78SBjoern A. Zeeb /* XXX-BZ see when this explodes with all the locking. taskq? */ 72845a9a0d78SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, sta->txq[tid]); 72855a9a0d78SBjoern A. Zeeb } 72865a9a0d78SBjoern A. Zeeb } 7287a8f735a6SBjoern A. Zeeb rcu_read_unlock(); 72885a9a0d78SBjoern A. Zeeb } 72895a9a0d78SBjoern A. Zeeb } 72905a9a0d78SBjoern A. Zeeb } 72915a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 72925a9a0d78SBjoern A. Zeeb } 72935a9a0d78SBjoern A. Zeeb 72945a9a0d78SBjoern A. Zeeb void 72955a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_wake_queues(struct ieee80211_hw *hw) 72965a9a0d78SBjoern A. Zeeb { 72975a9a0d78SBjoern A. Zeeb int i; 72985a9a0d78SBjoern A. Zeeb 72995a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Is this all/enough here?"); 73005a9a0d78SBjoern A. Zeeb for (i = 0; i < hw->queues; i++) 73015a9a0d78SBjoern A. Zeeb lkpi_ieee80211_wake_queues(hw, i); 73025a9a0d78SBjoern A. Zeeb } 73035a9a0d78SBjoern A. Zeeb 73045a9a0d78SBjoern A. Zeeb void 73055a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_wake_queue(struct ieee80211_hw *hw, int qnum) 73065a9a0d78SBjoern A. Zeeb { 73075a9a0d78SBjoern A. Zeeb 73085a9a0d78SBjoern A. Zeeb KASSERT(qnum < hw->queues, ("%s: qnum %d >= hw->queues %d, hw %p\n", 73095a9a0d78SBjoern A. Zeeb __func__, qnum, hw->queues, hw)); 73105a9a0d78SBjoern A. Zeeb 73115a9a0d78SBjoern A. Zeeb lkpi_ieee80211_wake_queues(hw, qnum); 73125a9a0d78SBjoern A. Zeeb } 73135a9a0d78SBjoern A. Zeeb 73145a9a0d78SBjoern A. Zeeb /* This is just hardware queues. */ 73155a9a0d78SBjoern A. Zeeb void 73165a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_txq_schedule_start(struct ieee80211_hw *hw, uint8_t ac) 73175a9a0d78SBjoern A. Zeeb { 73185a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 73195a9a0d78SBjoern A. Zeeb 73205a9a0d78SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 73215a9a0d78SBjoern A. Zeeb 73225a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Are there reasons why we wouldn't schedule?"); 73235a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 73245a9a0d78SBjoern A. Zeeb if (++lhw->txq_generation[ac] == 0) 73255a9a0d78SBjoern A. Zeeb lhw->txq_generation[ac]++; 73265a9a0d78SBjoern A. Zeeb } 73275a9a0d78SBjoern A. Zeeb 73285a9a0d78SBjoern A. Zeeb struct ieee80211_txq * 73295a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_next_txq(struct ieee80211_hw *hw, uint8_t ac) 73305a9a0d78SBjoern A. Zeeb { 73315a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 73325a9a0d78SBjoern A. Zeeb struct ieee80211_txq *txq; 73335a9a0d78SBjoern A. Zeeb struct lkpi_txq *ltxq; 73345a9a0d78SBjoern A. Zeeb 73355a9a0d78SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 73365a9a0d78SBjoern A. Zeeb txq = NULL; 73375a9a0d78SBjoern A. Zeeb 73385a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 73395a9a0d78SBjoern A. Zeeb 73405a9a0d78SBjoern A. Zeeb /* Check that we are scheduled. */ 73415a9a0d78SBjoern A. Zeeb if (lhw->txq_generation[ac] == 0) 73425a9a0d78SBjoern A. Zeeb goto out; 73435a9a0d78SBjoern A. Zeeb 73445a9a0d78SBjoern A. Zeeb ltxq = TAILQ_FIRST(&lhw->scheduled_txqs[ac]); 73455a9a0d78SBjoern A. Zeeb if (ltxq == NULL) 73465a9a0d78SBjoern A. Zeeb goto out; 73475a9a0d78SBjoern A. Zeeb if (ltxq->txq_generation == lhw->txq_generation[ac]) 73485a9a0d78SBjoern A. Zeeb goto out; 73495a9a0d78SBjoern A. Zeeb 73505a9a0d78SBjoern A. Zeeb ltxq->txq_generation = lhw->txq_generation[ac]; 73515a9a0d78SBjoern A. Zeeb TAILQ_REMOVE(&lhw->scheduled_txqs[ac], ltxq, txq_entry); 73525a9a0d78SBjoern A. Zeeb txq = <xq->txq; 73535a9a0d78SBjoern A. Zeeb TAILQ_ELEM_INIT(ltxq, txq_entry); 73545a9a0d78SBjoern A. Zeeb 73555a9a0d78SBjoern A. Zeeb out: 73565a9a0d78SBjoern A. Zeeb return (txq); 73575a9a0d78SBjoern A. Zeeb } 73585a9a0d78SBjoern A. Zeeb 73595a9a0d78SBjoern A. Zeeb void linuxkpi_ieee80211_schedule_txq(struct ieee80211_hw *hw, 73605a9a0d78SBjoern A. Zeeb struct ieee80211_txq *txq, bool withoutpkts) 73615a9a0d78SBjoern A. Zeeb { 73625a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 73635a9a0d78SBjoern A. Zeeb struct lkpi_txq *ltxq; 7364eac3646fSBjoern A. Zeeb bool ltxq_empty; 73655a9a0d78SBjoern A. Zeeb 73665a9a0d78SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 73675a9a0d78SBjoern A. Zeeb 73685a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 73695a9a0d78SBjoern A. Zeeb 73705a9a0d78SBjoern A. Zeeb /* Only schedule if work to do or asked to anyway. */ 7371eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_LOCK(ltxq); 7372eac3646fSBjoern A. Zeeb ltxq_empty = skb_queue_empty(<xq->skbq); 7373eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_UNLOCK(ltxq); 7374eac3646fSBjoern A. Zeeb if (!withoutpkts && ltxq_empty) 73755a9a0d78SBjoern A. Zeeb goto out; 73765a9a0d78SBjoern A. Zeeb 737741b746e0SAustin Shafer /* 737841b746e0SAustin Shafer * Make sure we do not double-schedule. We do this by checking tqe_prev, 737941b746e0SAustin Shafer * the previous entry in our tailq. tqe_prev is always valid if this entry 738041b746e0SAustin Shafer * is queued, tqe_next may be NULL if this is the only element in the list. 738141b746e0SAustin Shafer */ 738241b746e0SAustin Shafer if (ltxq->txq_entry.tqe_prev != NULL) 73835a9a0d78SBjoern A. Zeeb goto out; 73845a9a0d78SBjoern A. Zeeb 73855a9a0d78SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 73865a9a0d78SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lhw->scheduled_txqs[txq->ac], ltxq, txq_entry); 73875a9a0d78SBjoern A. Zeeb out: 73885a9a0d78SBjoern A. Zeeb return; 73895a9a0d78SBjoern A. Zeeb } 73905a9a0d78SBjoern A. Zeeb 7391eac3646fSBjoern A. Zeeb void 7392eac3646fSBjoern A. Zeeb linuxkpi_ieee80211_handle_wake_tx_queue(struct ieee80211_hw *hw, 7393eac3646fSBjoern A. Zeeb struct ieee80211_txq *txq) 7394eac3646fSBjoern A. Zeeb { 7395eac3646fSBjoern A. Zeeb struct lkpi_hw *lhw; 7396eac3646fSBjoern A. Zeeb struct ieee80211_txq *ntxq; 7397eac3646fSBjoern A. Zeeb struct ieee80211_tx_control control; 7398eac3646fSBjoern A. Zeeb struct sk_buff *skb; 7399eac3646fSBjoern A. Zeeb 7400eac3646fSBjoern A. Zeeb lhw = HW_TO_LHW(hw); 7401eac3646fSBjoern A. Zeeb 7402eac3646fSBjoern A. Zeeb LKPI_80211_LHW_TXQ_LOCK(lhw); 7403eac3646fSBjoern A. Zeeb ieee80211_txq_schedule_start(hw, txq->ac); 7404eac3646fSBjoern A. Zeeb do { 7405eac3646fSBjoern A. Zeeb ntxq = ieee80211_next_txq(hw, txq->ac); 7406eac3646fSBjoern A. Zeeb if (ntxq == NULL) 7407eac3646fSBjoern A. Zeeb break; 7408eac3646fSBjoern A. Zeeb 7409eac3646fSBjoern A. Zeeb memset(&control, 0, sizeof(control)); 7410eac3646fSBjoern A. Zeeb control.sta = ntxq->sta; 7411eac3646fSBjoern A. Zeeb do { 7412eac3646fSBjoern A. Zeeb skb = linuxkpi_ieee80211_tx_dequeue(hw, ntxq); 7413eac3646fSBjoern A. Zeeb if (skb == NULL) 7414eac3646fSBjoern A. Zeeb break; 7415eac3646fSBjoern A. Zeeb lkpi_80211_mo_tx(hw, &control, skb); 7416eac3646fSBjoern A. Zeeb } while(1); 7417eac3646fSBjoern A. Zeeb 7418eac3646fSBjoern A. Zeeb ieee80211_return_txq(hw, ntxq, false); 7419eac3646fSBjoern A. Zeeb } while (1); 7420eac3646fSBjoern A. Zeeb ieee80211_txq_schedule_end(hw, txq->ac); 7421eac3646fSBjoern A. Zeeb LKPI_80211_LHW_TXQ_UNLOCK(lhw); 7422eac3646fSBjoern A. Zeeb } 7423eac3646fSBjoern A. Zeeb 74245a9a0d78SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 74255a9a0d78SBjoern A. Zeeb 74265edde07cSBjoern A. Zeeb struct lkpi_cfg80211_bss { 74275edde07cSBjoern A. Zeeb u_int refcnt; 74285edde07cSBjoern A. Zeeb struct cfg80211_bss bss; 74295edde07cSBjoern A. Zeeb }; 74305edde07cSBjoern A. Zeeb 74315edde07cSBjoern A. Zeeb struct lkpi_cfg80211_get_bss_iter_lookup { 74325edde07cSBjoern A. Zeeb struct wiphy *wiphy; 74335edde07cSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 74345edde07cSBjoern A. Zeeb const uint8_t *bssid; 74355edde07cSBjoern A. Zeeb const uint8_t *ssid; 74365edde07cSBjoern A. Zeeb size_t ssid_len; 74375edde07cSBjoern A. Zeeb enum ieee80211_bss_type bss_type; 74385edde07cSBjoern A. Zeeb enum ieee80211_privacy privacy; 74395edde07cSBjoern A. Zeeb 74405edde07cSBjoern A. Zeeb /* 74415edde07cSBjoern A. Zeeb * Something to store a copy of the result as the net80211 scan cache 74425edde07cSBjoern A. Zeeb * is not refoucnted so a scan entry might go away any time. 74435edde07cSBjoern A. Zeeb */ 74445edde07cSBjoern A. Zeeb bool match; 74455edde07cSBjoern A. Zeeb struct cfg80211_bss *bss; 74465edde07cSBjoern A. Zeeb }; 74475edde07cSBjoern A. Zeeb 74485edde07cSBjoern A. Zeeb static void 74495edde07cSBjoern A. Zeeb lkpi_cfg80211_get_bss_iterf(void *arg, const struct ieee80211_scan_entry *se) 74505edde07cSBjoern A. Zeeb { 74515edde07cSBjoern A. Zeeb struct lkpi_cfg80211_get_bss_iter_lookup *lookup; 74525edde07cSBjoern A. Zeeb size_t ielen; 74535edde07cSBjoern A. Zeeb 74545edde07cSBjoern A. Zeeb lookup = arg; 74555edde07cSBjoern A. Zeeb 74565edde07cSBjoern A. Zeeb /* Do not try to find another match. */ 74575edde07cSBjoern A. Zeeb if (lookup->match) 74585edde07cSBjoern A. Zeeb return; 74595edde07cSBjoern A. Zeeb 74605edde07cSBjoern A. Zeeb /* Nothing to store result. */ 74615edde07cSBjoern A. Zeeb if (lookup->bss == NULL) 74625edde07cSBjoern A. Zeeb return; 74635edde07cSBjoern A. Zeeb 74645edde07cSBjoern A. Zeeb if (lookup->privacy != IEEE80211_PRIVACY_ANY) { 74655edde07cSBjoern A. Zeeb /* if (se->se_capinfo & IEEE80211_CAPINFO_PRIVACY) */ 74665edde07cSBjoern A. Zeeb /* We have no idea what to compare to as the drivers only request ANY */ 74675edde07cSBjoern A. Zeeb return; 74685edde07cSBjoern A. Zeeb } 74695edde07cSBjoern A. Zeeb 74705edde07cSBjoern A. Zeeb if (lookup->bss_type != IEEE80211_BSS_TYPE_ANY) { 74715edde07cSBjoern A. Zeeb /* if (se->se_capinfo & (IEEE80211_CAPINFO_IBSS|IEEE80211_CAPINFO_ESS)) */ 74725edde07cSBjoern A. Zeeb /* We have no idea what to compare to as the drivers only request ANY */ 74735edde07cSBjoern A. Zeeb return; 74745edde07cSBjoern A. Zeeb } 74755edde07cSBjoern A. Zeeb 74765edde07cSBjoern A. Zeeb if (lookup->chan != NULL) { 74775edde07cSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 74785edde07cSBjoern A. Zeeb 74795edde07cSBjoern A. Zeeb chan = linuxkpi_ieee80211_get_channel(lookup->wiphy, 74805edde07cSBjoern A. Zeeb se->se_chan->ic_freq); 74815edde07cSBjoern A. Zeeb if (chan == NULL || chan != lookup->chan) 74825edde07cSBjoern A. Zeeb return; 74835edde07cSBjoern A. Zeeb } 74845edde07cSBjoern A. Zeeb 74855edde07cSBjoern A. Zeeb if (lookup->bssid && !IEEE80211_ADDR_EQ(lookup->bssid, se->se_bssid)) 74865edde07cSBjoern A. Zeeb return; 74875edde07cSBjoern A. Zeeb 74885edde07cSBjoern A. Zeeb if (lookup->ssid) { 74895edde07cSBjoern A. Zeeb if (lookup->ssid_len != se->se_ssid[1] || 74905edde07cSBjoern A. Zeeb se->se_ssid[1] == 0) 74915edde07cSBjoern A. Zeeb return; 74925edde07cSBjoern A. Zeeb if (memcmp(lookup->ssid, se->se_ssid+2, lookup->ssid_len) != 0) 74935edde07cSBjoern A. Zeeb return; 74945edde07cSBjoern A. Zeeb } 74955edde07cSBjoern A. Zeeb 74965edde07cSBjoern A. Zeeb ielen = se->se_ies.len; 74975edde07cSBjoern A. Zeeb 74985edde07cSBjoern A. Zeeb lookup->bss->ies = malloc(sizeof(*lookup->bss->ies) + ielen, 74995edde07cSBjoern A. Zeeb M_LKPI80211, M_NOWAIT | M_ZERO); 75005edde07cSBjoern A. Zeeb if (lookup->bss->ies == NULL) 75015edde07cSBjoern A. Zeeb return; 75025edde07cSBjoern A. Zeeb 75035edde07cSBjoern A. Zeeb lookup->bss->ies->data = (uint8_t *)lookup->bss->ies + sizeof(*lookup->bss->ies); 75045edde07cSBjoern A. Zeeb lookup->bss->ies->len = ielen; 75055edde07cSBjoern A. Zeeb if (ielen) 75065edde07cSBjoern A. Zeeb memcpy(lookup->bss->ies->data, se->se_ies.data, ielen); 75075edde07cSBjoern A. Zeeb 75085edde07cSBjoern A. Zeeb lookup->match = true; 75095edde07cSBjoern A. Zeeb } 75105edde07cSBjoern A. Zeeb 75115edde07cSBjoern A. Zeeb struct cfg80211_bss * 75125edde07cSBjoern A. Zeeb linuxkpi_cfg80211_get_bss(struct wiphy *wiphy, struct linuxkpi_ieee80211_channel *chan, 75135edde07cSBjoern A. Zeeb const uint8_t *bssid, const uint8_t *ssid, size_t ssid_len, 75145edde07cSBjoern A. Zeeb enum ieee80211_bss_type bss_type, enum ieee80211_privacy privacy) 75155edde07cSBjoern A. Zeeb { 75165edde07cSBjoern A. Zeeb struct lkpi_cfg80211_bss *lbss; 75175edde07cSBjoern A. Zeeb struct lkpi_cfg80211_get_bss_iter_lookup lookup; 75185edde07cSBjoern A. Zeeb struct lkpi_hw *lhw; 75195edde07cSBjoern A. Zeeb struct ieee80211vap *vap; 75205edde07cSBjoern A. Zeeb 75215edde07cSBjoern A. Zeeb lhw = wiphy_priv(wiphy); 75225edde07cSBjoern A. Zeeb 75235edde07cSBjoern A. Zeeb /* Let's hope we can alloc. */ 75245edde07cSBjoern A. Zeeb lbss = malloc(sizeof(*lbss), M_LKPI80211, M_NOWAIT | M_ZERO); 75255edde07cSBjoern A. Zeeb if (lbss == NULL) { 75265edde07cSBjoern A. Zeeb ic_printf(lhw->ic, "%s: alloc failed.\n", __func__); 75275edde07cSBjoern A. Zeeb return (NULL); 75285edde07cSBjoern A. Zeeb } 75295edde07cSBjoern A. Zeeb 75305edde07cSBjoern A. Zeeb lookup.wiphy = wiphy; 75315edde07cSBjoern A. Zeeb lookup.chan = chan; 75325edde07cSBjoern A. Zeeb lookup.bssid = bssid; 75335edde07cSBjoern A. Zeeb lookup.ssid = ssid; 75345edde07cSBjoern A. Zeeb lookup.ssid_len = ssid_len; 75355edde07cSBjoern A. Zeeb lookup.bss_type = bss_type; 75365edde07cSBjoern A. Zeeb lookup.privacy = privacy; 75375edde07cSBjoern A. Zeeb lookup.match = false; 75385edde07cSBjoern A. Zeeb lookup.bss = &lbss->bss; 75395edde07cSBjoern A. Zeeb 75405edde07cSBjoern A. Zeeb IMPROVE("Iterate over all VAPs comparing perm_addr and addresses?"); 75415edde07cSBjoern A. Zeeb vap = TAILQ_FIRST(&lhw->ic->ic_vaps); 75425edde07cSBjoern A. Zeeb ieee80211_scan_iterate(vap, lkpi_cfg80211_get_bss_iterf, &lookup); 75435edde07cSBjoern A. Zeeb if (!lookup.match) { 75445edde07cSBjoern A. Zeeb free(lbss, M_LKPI80211); 75455edde07cSBjoern A. Zeeb return (NULL); 75465edde07cSBjoern A. Zeeb } 75475edde07cSBjoern A. Zeeb 75485edde07cSBjoern A. Zeeb refcount_init(&lbss->refcnt, 1); 75495edde07cSBjoern A. Zeeb return (&lbss->bss); 75505edde07cSBjoern A. Zeeb } 75515edde07cSBjoern A. Zeeb 75525edde07cSBjoern A. Zeeb void 75535edde07cSBjoern A. Zeeb linuxkpi_cfg80211_put_bss(struct wiphy *wiphy, struct cfg80211_bss *bss) 75545edde07cSBjoern A. Zeeb { 75555edde07cSBjoern A. Zeeb struct lkpi_cfg80211_bss *lbss; 75565edde07cSBjoern A. Zeeb 75575edde07cSBjoern A. Zeeb lbss = container_of(bss, struct lkpi_cfg80211_bss, bss); 75585edde07cSBjoern A. Zeeb 75595edde07cSBjoern A. Zeeb /* Free everything again on refcount ... */ 75605edde07cSBjoern A. Zeeb if (refcount_release(&lbss->refcnt)) { 75615edde07cSBjoern A. Zeeb free(lbss->bss.ies, M_LKPI80211); 75625edde07cSBjoern A. Zeeb free(lbss, M_LKPI80211); 75635edde07cSBjoern A. Zeeb } 75645edde07cSBjoern A. Zeeb } 75655edde07cSBjoern A. Zeeb 75665edde07cSBjoern A. Zeeb void 75675edde07cSBjoern A. Zeeb linuxkpi_cfg80211_bss_flush(struct wiphy *wiphy) 75685edde07cSBjoern A. Zeeb { 75695edde07cSBjoern A. Zeeb struct lkpi_hw *lhw; 75705edde07cSBjoern A. Zeeb struct ieee80211com *ic; 75715edde07cSBjoern A. Zeeb struct ieee80211vap *vap; 75725edde07cSBjoern A. Zeeb 75735edde07cSBjoern A. Zeeb lhw = wiphy_priv(wiphy); 75745edde07cSBjoern A. Zeeb ic = lhw->ic; 75755edde07cSBjoern A. Zeeb 75765edde07cSBjoern A. Zeeb /* 75775edde07cSBjoern A. Zeeb * If we haven't called ieee80211_ifattach() yet 75785edde07cSBjoern A. Zeeb * or there is no VAP, there are no scans to flush. 75795edde07cSBjoern A. Zeeb */ 75805edde07cSBjoern A. Zeeb if (ic == NULL || 75815edde07cSBjoern A. Zeeb (lhw->sc_flags & LKPI_MAC80211_DRV_STARTED) == 0) 75825edde07cSBjoern A. Zeeb return; 75835edde07cSBjoern A. Zeeb 75845edde07cSBjoern A. Zeeb /* Should only happen on the current one? Not seen it late enough. */ 75855edde07cSBjoern A. Zeeb IEEE80211_LOCK(ic); 75865edde07cSBjoern A. Zeeb TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) 75875edde07cSBjoern A. Zeeb ieee80211_scan_flush(vap); 75885edde07cSBjoern A. Zeeb IEEE80211_UNLOCK(ic); 75895edde07cSBjoern A. Zeeb } 75905edde07cSBjoern A. Zeeb 75915edde07cSBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 75925edde07cSBjoern A. Zeeb 7593ac1d519cSBjoern A. Zeeb /* 7594ac1d519cSBjoern A. Zeeb * hw->conf get initialized/set in various places for us: 7595ac1d519cSBjoern A. Zeeb * - linuxkpi_ieee80211_alloc_hw(): flags 7596ac1d519cSBjoern A. Zeeb * - linuxkpi_ieee80211_ifattach(): chandef 7597ac1d519cSBjoern A. Zeeb * - lkpi_ic_vap_create(): listen_interval 7598ac1d519cSBjoern A. Zeeb * - lkpi_ic_set_channel(): chandef, flags 7599ac1d519cSBjoern A. Zeeb */ 7600ac1d519cSBjoern A. Zeeb 7601ac1d519cSBjoern A. Zeeb int lkpi_80211_update_chandef(struct ieee80211_hw *hw, 7602ac1d519cSBjoern A. Zeeb struct ieee80211_chanctx_conf *new) 7603ac1d519cSBjoern A. Zeeb { 7604ac1d519cSBjoern A. Zeeb struct cfg80211_chan_def *cd; 7605ac1d519cSBjoern A. Zeeb uint32_t changed; 7606ac1d519cSBjoern A. Zeeb int error; 7607ac1d519cSBjoern A. Zeeb 7608ac1d519cSBjoern A. Zeeb changed = 0; 7609ac1d519cSBjoern A. Zeeb if (new == NULL || new->def.chan == NULL) 7610ac1d519cSBjoern A. Zeeb cd = NULL; 7611ac1d519cSBjoern A. Zeeb else 7612ac1d519cSBjoern A. Zeeb cd = &new->def; 7613ac1d519cSBjoern A. Zeeb 7614ac1d519cSBjoern A. Zeeb if (cd && cd->chan != hw->conf.chandef.chan) { 7615ac1d519cSBjoern A. Zeeb /* Copy; the chan pointer is fine and will stay valid. */ 7616ac1d519cSBjoern A. Zeeb hw->conf.chandef = *cd; 7617ac1d519cSBjoern A. Zeeb changed |= IEEE80211_CONF_CHANGE_CHANNEL; 7618ac1d519cSBjoern A. Zeeb } 7619ac1d519cSBjoern A. Zeeb IMPROVE("IEEE80211_CONF_CHANGE_PS, IEEE80211_CONF_CHANGE_POWER"); 7620ac1d519cSBjoern A. Zeeb 7621ac1d519cSBjoern A. Zeeb if (changed == 0) 7622ac1d519cSBjoern A. Zeeb return (0); 7623ac1d519cSBjoern A. Zeeb 7624ac1d519cSBjoern A. Zeeb error = lkpi_80211_mo_config(hw, changed); 7625ac1d519cSBjoern A. Zeeb return (error); 7626ac1d519cSBjoern A. Zeeb } 7627ac1d519cSBjoern A. Zeeb 7628ac1d519cSBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 7629ac1d519cSBjoern A. Zeeb 76306b4cac81SBjoern A. Zeeb MODULE_VERSION(linuxkpi_wlan, 1); 76316b4cac81SBjoern A. Zeeb MODULE_DEPEND(linuxkpi_wlan, linuxkpi, 1, 1, 1); 76326b4cac81SBjoern A. Zeeb MODULE_DEPEND(linuxkpi_wlan, wlan, 1, 1, 1); 7633