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
8275d23d88SBjoern A. Zeeb #define LKPI_80211_HT
832c44f1ffSBjoern 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");
110b71d3043SBjoern A. Zeeb
111b71d3043SBjoern A. Zeeb static bool lkpi_hwcrypto_tkip = false;
112b71d3043SBjoern A. Zeeb SYSCTL_BOOL(_compat_linuxkpi_80211, OID_AUTO, tkip, CTLFLAG_RDTUN,
113b71d3043SBjoern A. Zeeb &lkpi_hwcrypto_tkip, 0, "Enable LinuxKPI 802.11 TKIP crypto offload");
11411db70b6SBjoern A. Zeeb #endif
11511db70b6SBjoern A. Zeeb
11640839418SBjoern A. Zeeb /* Keep public for as long as header files are using it too. */
11740839418SBjoern A. Zeeb int linuxkpi_debug_80211;
11840839418SBjoern A. Zeeb
11940839418SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
1209d9ba2b7SBjoern A. Zeeb SYSCTL_INT(_compat_linuxkpi_80211, OID_AUTO, debug, CTLFLAG_RWTUN,
1219d9ba2b7SBjoern A. Zeeb &linuxkpi_debug_80211, 0, "LinuxKPI 802.11 debug level");
1229d9ba2b7SBjoern A. Zeeb
1239d9ba2b7SBjoern A. Zeeb #define UNIMPLEMENTED if (linuxkpi_debug_80211 & D80211_TODO) \
1246b4cac81SBjoern A. Zeeb printf("XXX-TODO %s:%d: UNIMPLEMENTED\n", __func__, __LINE__)
1259d9ba2b7SBjoern A. Zeeb #define TRACEOK() if (linuxkpi_debug_80211 & D80211_TRACEOK) \
1266b4cac81SBjoern A. Zeeb printf("XXX-TODO %s:%d: TRACEPOINT\n", __func__, __LINE__)
1276b4cac81SBjoern A. Zeeb #else
1286b4cac81SBjoern A. Zeeb #define UNIMPLEMENTED do { } while (0)
1296b4cac81SBjoern A. Zeeb #define TRACEOK() do { } while (0)
1306b4cac81SBjoern A. Zeeb #endif
1316b4cac81SBjoern A. Zeeb
1326b4cac81SBjoern A. Zeeb /* #define PREP_TX_INFO_DURATION (IEEE80211_TRANS_WAIT * 1000) */
1336b4cac81SBjoern A. Zeeb #ifndef PREP_TX_INFO_DURATION
1346b4cac81SBjoern A. Zeeb #define PREP_TX_INFO_DURATION 0 /* Let the driver do its thing. */
1356b4cac81SBjoern A. Zeeb #endif
1366b4cac81SBjoern A. Zeeb
1376b4cac81SBjoern A. Zeeb /* This is DSAP | SSAP | CTRL | ProtoID/OrgCode{3}. */
1386b4cac81SBjoern A. Zeeb const uint8_t rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
1396b4cac81SBjoern A. Zeeb
140b0f73768SBjoern A. Zeeb /* IEEE 802.11-05/0257r1 */
141b0f73768SBjoern A. Zeeb const uint8_t bridge_tunnel_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
142b0f73768SBjoern A. Zeeb
143fb3c249eSBjoern A. Zeeb /* IEEE 802.11e Table 20i-UP-to-AC mappings. */
144fb3c249eSBjoern A. Zeeb static const uint8_t ieee80211e_up_to_ac[] = {
1454f61ef8bSBjoern A. Zeeb IEEE80211_AC_BE,
1464f61ef8bSBjoern A. Zeeb IEEE80211_AC_BK,
1474f61ef8bSBjoern A. Zeeb IEEE80211_AC_BK,
1484f61ef8bSBjoern A. Zeeb IEEE80211_AC_BE,
1494f61ef8bSBjoern A. Zeeb IEEE80211_AC_VI,
1504f61ef8bSBjoern A. Zeeb IEEE80211_AC_VI,
1514f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO,
1524f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO,
1534f61ef8bSBjoern A. Zeeb #if 0
1544f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO, /* We treat MGMT as TID 8, which is set as AC_VO */
1554f61ef8bSBjoern A. Zeeb #endif
1564f61ef8bSBjoern A. Zeeb };
1574f61ef8bSBjoern A. Zeeb
1586b4cac81SBjoern A. Zeeb const struct cfg80211_ops linuxkpi_mac80211cfgops = {
1596b4cac81SBjoern A. Zeeb /*
1606b4cac81SBjoern A. Zeeb * XXX TODO need a "glue layer" to link cfg80211 ops to
1616b4cac81SBjoern A. Zeeb * mac80211 and to the driver or net80211.
1626b4cac81SBjoern A. Zeeb * Can we pass some on 1:1? Need to compare the (*f)().
1636b4cac81SBjoern A. Zeeb */
1646b4cac81SBjoern A. Zeeb };
1656b4cac81SBjoern A. Zeeb
166ac867c20SBjoern A. Zeeb #if 0
1676b4cac81SBjoern A. Zeeb static struct lkpi_sta *lkpi_find_lsta_by_ni(struct lkpi_vif *,
1686b4cac81SBjoern A. Zeeb struct ieee80211_node *);
169ac867c20SBjoern A. Zeeb #endif
17088665349SBjoern A. Zeeb static void lkpi_80211_txq_tx_one(struct lkpi_sta *, struct mbuf *);
1716b4cac81SBjoern A. Zeeb static void lkpi_80211_txq_task(void *, int);
172759a996dSBjoern A. Zeeb static void lkpi_80211_lhw_rxq_task(void *, int);
1736b4cac81SBjoern A. Zeeb static void lkpi_ieee80211_free_skb_mbuf(void *);
1744a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME
1754a67f1dfSBjoern A. Zeeb static int lkpi_wme_update(struct lkpi_hw *, struct ieee80211vap *, bool);
1764a67f1dfSBjoern A. Zeeb #endif
177db480c29SBjoern A. Zeeb static void lkpi_ieee80211_wake_queues_locked(struct ieee80211_hw *);
1786b4cac81SBjoern A. Zeeb
17940839418SBjoern A. Zeeb static const char *
lkpi_rate_info_bw_to_str(enum rate_info_bw bw)18040839418SBjoern A. Zeeb lkpi_rate_info_bw_to_str(enum rate_info_bw bw)
18140839418SBjoern A. Zeeb {
18240839418SBjoern A. Zeeb
18340839418SBjoern A. Zeeb switch (bw) {
18440839418SBjoern A. Zeeb
18540839418SBjoern A. Zeeb case RATE_INFO_BW_20:
18640839418SBjoern A. Zeeb return ("20");
18740839418SBjoern A. Zeeb break;
18840839418SBjoern A. Zeeb case RATE_INFO_BW_5:
18940839418SBjoern A. Zeeb return ("5");
19040839418SBjoern A. Zeeb break;
19140839418SBjoern A. Zeeb case RATE_INFO_BW_10:
19240839418SBjoern A. Zeeb return ("10");
19340839418SBjoern A. Zeeb break;
19440839418SBjoern A. Zeeb case RATE_INFO_BW_40:
19540839418SBjoern A. Zeeb return ("40");
19640839418SBjoern A. Zeeb break;
19740839418SBjoern A. Zeeb case RATE_INFO_BW_80:
19840839418SBjoern A. Zeeb return ("80");
19940839418SBjoern A. Zeeb break;
20040839418SBjoern A. Zeeb case RATE_INFO_BW_160:
20140839418SBjoern A. Zeeb return ("160");
20240839418SBjoern A. Zeeb break;
20340839418SBjoern A. Zeeb case RATE_INFO_BW_HE_RU:
20440839418SBjoern A. Zeeb IMPROVE("nl80211_he_ru_alloc");
20540839418SBjoern A. Zeeb return ("HE_RU");
20640839418SBjoern A. Zeeb break;
20740839418SBjoern A. Zeeb case RATE_INFO_BW_320:
20840839418SBjoern A. Zeeb return ("320");
20940839418SBjoern A. Zeeb break;
21040839418SBjoern A. Zeeb case RATE_INFO_BW_EHT_RU:
21140839418SBjoern A. Zeeb IMPROVE("nl80211_eht_ru_alloc");
21240839418SBjoern A. Zeeb return ("EHT_RU");
21340839418SBjoern A. Zeeb break;
21440839418SBjoern A. Zeeb default:
21540839418SBjoern A. Zeeb return ("?");
21640839418SBjoern A. Zeeb break;
21740839418SBjoern A. Zeeb }
21840839418SBjoern A. Zeeb }
21940839418SBjoern A. Zeeb
22040839418SBjoern A. Zeeb static void
lkpi_nl80211_sta_info_to_str(struct sbuf * s,const char * prefix,const uint64_t flags)22140839418SBjoern A. Zeeb lkpi_nl80211_sta_info_to_str(struct sbuf *s, const char *prefix,
22240839418SBjoern A. Zeeb const uint64_t flags)
22340839418SBjoern A. Zeeb {
22440839418SBjoern A. Zeeb int bit, i;
22540839418SBjoern A. Zeeb
22640839418SBjoern A. Zeeb sbuf_printf(s, "%s %#010jx", prefix, flags);
22740839418SBjoern A. Zeeb
22840839418SBjoern A. Zeeb i = 0;
22940839418SBjoern A. Zeeb for (bit = 0; bit < BITS_PER_TYPE(flags); bit++) {
23040839418SBjoern A. Zeeb
23140839418SBjoern A. Zeeb if ((flags & BIT_ULL(bit)) == 0)
23240839418SBjoern A. Zeeb continue;
23340839418SBjoern A. Zeeb
23440839418SBjoern A. Zeeb #define EXPAND_CASE(_flag) \
23540839418SBjoern A. Zeeb case NL80211_STA_INFO_ ## _flag: \
23640839418SBjoern A. Zeeb sbuf_printf(s, "%c%s", (i == 0) ? '<' : ',', #_flag); \
23740839418SBjoern A. Zeeb i++; \
23840839418SBjoern A. Zeeb break;
23940839418SBjoern A. Zeeb
24040839418SBjoern A. Zeeb switch (bit) {
24140839418SBjoern A. Zeeb EXPAND_CASE(BEACON_RX)
24240839418SBjoern A. Zeeb EXPAND_CASE(BEACON_SIGNAL_AVG)
24340839418SBjoern A. Zeeb EXPAND_CASE(BSS_PARAM)
24440839418SBjoern A. Zeeb EXPAND_CASE(CHAIN_SIGNAL)
24540839418SBjoern A. Zeeb EXPAND_CASE(CHAIN_SIGNAL_AVG)
24640839418SBjoern A. Zeeb EXPAND_CASE(CONNECTED_TIME)
24740839418SBjoern A. Zeeb EXPAND_CASE(INACTIVE_TIME)
24840839418SBjoern A. Zeeb EXPAND_CASE(SIGNAL)
24940839418SBjoern A. Zeeb EXPAND_CASE(SIGNAL_AVG)
25040839418SBjoern A. Zeeb EXPAND_CASE(STA_FLAGS)
25140839418SBjoern A. Zeeb EXPAND_CASE(RX_BITRATE)
25240839418SBjoern A. Zeeb EXPAND_CASE(RX_PACKETS)
25340839418SBjoern A. Zeeb EXPAND_CASE(RX_BYTES)
25440839418SBjoern A. Zeeb EXPAND_CASE(RX_DROP_MISC)
25540839418SBjoern A. Zeeb EXPAND_CASE(TX_BITRATE)
25640839418SBjoern A. Zeeb EXPAND_CASE(TX_PACKETS)
25740839418SBjoern A. Zeeb EXPAND_CASE(TX_BYTES)
25840839418SBjoern A. Zeeb EXPAND_CASE(TX_BYTES64)
25940839418SBjoern A. Zeeb EXPAND_CASE(RX_BYTES64)
26040839418SBjoern A. Zeeb EXPAND_CASE(TX_FAILED)
26140839418SBjoern A. Zeeb EXPAND_CASE(TX_RETRIES)
26240839418SBjoern A. Zeeb EXPAND_CASE(RX_DURATION)
26340839418SBjoern A. Zeeb EXPAND_CASE(TX_DURATION)
26440839418SBjoern A. Zeeb EXPAND_CASE(ACK_SIGNAL)
26540839418SBjoern A. Zeeb EXPAND_CASE(ACK_SIGNAL_AVG)
26640839418SBjoern A. Zeeb default:
26740839418SBjoern A. Zeeb sbuf_printf(s, "%c?%d", (i == 0) ? '<' : ',', bit);
26840839418SBjoern A. Zeeb break;
26940839418SBjoern A. Zeeb }
27040839418SBjoern A. Zeeb }
27140839418SBjoern A. Zeeb #undef EXPAND_CASE
27240839418SBjoern A. Zeeb if (i > 0)
27340839418SBjoern A. Zeeb sbuf_printf(s, ">");
27440839418SBjoern A. Zeeb sbuf_printf(s, "\n");
27540839418SBjoern A. Zeeb }
27640839418SBjoern A. Zeeb
27740839418SBjoern A. Zeeb static int
lkpi_80211_dump_stas(SYSCTL_HANDLER_ARGS)27840839418SBjoern A. Zeeb lkpi_80211_dump_stas(SYSCTL_HANDLER_ARGS)
27940839418SBjoern A. Zeeb {
28040839418SBjoern A. Zeeb struct lkpi_hw *lhw;
28140839418SBjoern A. Zeeb struct ieee80211_hw *hw;
28240839418SBjoern A. Zeeb struct ieee80211vap *vap;
28340839418SBjoern A. Zeeb struct lkpi_vif *lvif;
28440839418SBjoern A. Zeeb struct ieee80211_vif *vif;
28540839418SBjoern A. Zeeb struct lkpi_sta *lsta;
28640839418SBjoern A. Zeeb struct ieee80211_sta *sta;
28740839418SBjoern A. Zeeb struct station_info sinfo;
28840839418SBjoern A. Zeeb struct sbuf s;
28940839418SBjoern A. Zeeb int error;
29040839418SBjoern A. Zeeb
29140839418SBjoern A. Zeeb if (req->newptr)
29240839418SBjoern A. Zeeb return (EPERM);
29340839418SBjoern A. Zeeb
29440839418SBjoern A. Zeeb lvif = (struct lkpi_vif *)arg1;
29540839418SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
29640839418SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif);
29740839418SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc;
29840839418SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
29940839418SBjoern A. Zeeb
30040839418SBjoern A. Zeeb sbuf_new_for_sysctl(&s, NULL, 1024, req);
30140839418SBjoern A. Zeeb
30240839418SBjoern A. Zeeb wiphy_lock(hw->wiphy);
303a8f735a6SBjoern A. Zeeb list_for_each_entry(lsta, &lvif->lsta_list, lsta_list) {
30440839418SBjoern A. Zeeb sta = LSTA_TO_STA(lsta);
30540839418SBjoern A. Zeeb
30640839418SBjoern A. Zeeb sbuf_putc(&s, '\n');
30740839418SBjoern A. Zeeb sbuf_printf(&s, "lsta %p sta %p added_to_drv %d\n", lsta, sta, lsta->added_to_drv);
30840839418SBjoern A. Zeeb
30940839418SBjoern A. Zeeb memset(&sinfo, 0, sizeof(sinfo));
31040839418SBjoern A. Zeeb error = lkpi_80211_mo_sta_statistics(hw, vif, sta, &sinfo);
31140839418SBjoern A. Zeeb if (error == EEXIST) /* Not added to driver. */
31240839418SBjoern A. Zeeb continue;
31340839418SBjoern A. Zeeb if (error == ENOTSUPP) {
31440839418SBjoern A. Zeeb sbuf_printf(&s, " sta_statistics not supported\n");
31540839418SBjoern A. Zeeb continue;
31640839418SBjoern A. Zeeb }
31740839418SBjoern A. Zeeb if (error != 0) {
31840839418SBjoern A. Zeeb sbuf_printf(&s, " sta_statistics failed: %d\n", error);
31940839418SBjoern A. Zeeb continue;
32040839418SBjoern A. Zeeb }
32140839418SBjoern A. Zeeb
322a1adefb1SBjoern A. Zeeb /* If no RX_BITRATE is reported, try to fill it in from the lsta sinfo. */
323a1adefb1SBjoern A. Zeeb if ((sinfo.filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) == 0 &&
324a1adefb1SBjoern A. Zeeb (lsta->sinfo.filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) != 0) {
325a1adefb1SBjoern A. Zeeb memcpy(&sinfo.rxrate, &lsta->sinfo.rxrate, sizeof(sinfo.rxrate));
326a1adefb1SBjoern A. Zeeb sinfo.filled |= BIT_ULL(NL80211_STA_INFO_RX_BITRATE);
327a1adefb1SBjoern A. Zeeb }
328a1adefb1SBjoern A. Zeeb
32940839418SBjoern A. Zeeb lkpi_nl80211_sta_info_to_str(&s, " nl80211_sta_info (valid fields)", sinfo.filled);
33040839418SBjoern A. Zeeb sbuf_printf(&s, " connected_time %u inactive_time %u\n",
33140839418SBjoern A. Zeeb sinfo.connected_time, sinfo.inactive_time);
33240839418SBjoern A. Zeeb sbuf_printf(&s, " rx_bytes %ju rx_packets %u rx_dropped_misc %u\n",
33340839418SBjoern A. Zeeb (uintmax_t)sinfo.rx_bytes, sinfo.rx_packets, sinfo.rx_dropped_misc);
33440839418SBjoern A. Zeeb sbuf_printf(&s, " rx_duration %ju rx_beacon %u rx_beacon_signal_avg %d\n",
33540839418SBjoern A. Zeeb (uintmax_t)sinfo.rx_duration, sinfo.rx_beacon, (int8_t)sinfo.rx_beacon_signal_avg);
33640839418SBjoern A. Zeeb
33740839418SBjoern A. Zeeb sbuf_printf(&s, " tx_bytes %ju tx_packets %u tx_failed %u\n",
33840839418SBjoern A. Zeeb (uintmax_t)sinfo.tx_bytes, sinfo.tx_packets, sinfo.tx_failed);
33940839418SBjoern A. Zeeb sbuf_printf(&s, " tx_duration %ju tx_retries %u\n",
34040839418SBjoern A. Zeeb (uintmax_t)sinfo.tx_duration, sinfo.tx_retries);
34140839418SBjoern A. Zeeb
34240839418SBjoern A. Zeeb sbuf_printf(&s, " signal %d signal_avg %d ack_signal %d avg_ack_signal %d\n",
34340839418SBjoern A. Zeeb sinfo.signal, sinfo.signal_avg, sinfo.ack_signal, sinfo.avg_ack_signal);
34440839418SBjoern A. Zeeb
34540839418SBjoern A. Zeeb sbuf_printf(&s, " generation %d assoc_req_ies_len %zu chains %d\n",
34640839418SBjoern A. Zeeb sinfo.generation, sinfo.assoc_req_ies_len, sinfo.chains);
34740839418SBjoern A. Zeeb
34840839418SBjoern A. Zeeb for (int i = 0; i < sinfo.chains && i < IEEE80211_MAX_CHAINS; i++) {
34940839418SBjoern A. Zeeb sbuf_printf(&s, " chain[%d] signal %d signal_avg %d\n",
35040839418SBjoern A. Zeeb i, (int8_t)sinfo.chain_signal[i], (int8_t)sinfo.chain_signal_avg[i]);
35140839418SBjoern A. Zeeb }
35240839418SBjoern A. Zeeb
35340839418SBjoern A. Zeeb /* assoc_req_ies, bss_param, sta_flags */
35440839418SBjoern A. Zeeb
35540839418SBjoern A. Zeeb sbuf_printf(&s, " rxrate: flags %b bw %u(%s) legacy %u kbit/s mcs %u nss %u\n",
35640839418SBjoern A. Zeeb sinfo.rxrate.flags, CFG80211_RATE_INFO_FLAGS_BITS,
35740839418SBjoern A. Zeeb sinfo.rxrate.bw, lkpi_rate_info_bw_to_str(sinfo.rxrate.bw),
35840839418SBjoern A. Zeeb sinfo.rxrate.legacy * 100,
35940839418SBjoern A. Zeeb sinfo.rxrate.mcs, sinfo.rxrate.nss);
36040839418SBjoern A. Zeeb sbuf_printf(&s, " he_dcm %u he_gi %u he_ru_alloc %u eht_gi %u\n",
36140839418SBjoern A. Zeeb sinfo.rxrate.he_dcm, sinfo.rxrate.he_gi, sinfo.rxrate.he_ru_alloc,
36240839418SBjoern A. Zeeb sinfo.rxrate.eht_gi);
36340839418SBjoern A. Zeeb sbuf_printf(&s, " txrate: flags %b bw %u(%s) legacy %u kbit/s mcs %u nss %u\n",
36440839418SBjoern A. Zeeb sinfo.txrate.flags, CFG80211_RATE_INFO_FLAGS_BITS,
36540839418SBjoern A. Zeeb sinfo.txrate.bw, lkpi_rate_info_bw_to_str(sinfo.txrate.bw),
36640839418SBjoern A. Zeeb sinfo.txrate.legacy * 100,
36740839418SBjoern A. Zeeb sinfo.txrate.mcs, sinfo.txrate.nss);
36840839418SBjoern A. Zeeb sbuf_printf(&s, " he_dcm %u he_gi %u he_ru_alloc %u eht_gi %u\n",
36940839418SBjoern A. Zeeb sinfo.txrate.he_dcm, sinfo.txrate.he_gi, sinfo.txrate.he_ru_alloc,
37040839418SBjoern A. Zeeb sinfo.txrate.eht_gi);
37140839418SBjoern A. Zeeb }
37240839418SBjoern A. Zeeb wiphy_unlock(hw->wiphy);
37340839418SBjoern A. Zeeb
37440839418SBjoern A. Zeeb sbuf_finish(&s);
37540839418SBjoern A. Zeeb sbuf_delete(&s);
37640839418SBjoern A. Zeeb
37740839418SBjoern A. Zeeb return (0);
37840839418SBjoern A. Zeeb }
37940839418SBjoern A. Zeeb
38062d51a43SBjoern A. Zeeb static enum ieee80211_sta_rx_bw
lkpi_cw_to_rx_bw(enum nl80211_chan_width cw)38162d51a43SBjoern A. Zeeb lkpi_cw_to_rx_bw(enum nl80211_chan_width cw)
38262d51a43SBjoern A. Zeeb {
38362d51a43SBjoern A. Zeeb switch (cw) {
38462d51a43SBjoern A. Zeeb case NL80211_CHAN_WIDTH_320:
38562d51a43SBjoern A. Zeeb return (IEEE80211_STA_RX_BW_320);
38662d51a43SBjoern A. Zeeb case NL80211_CHAN_WIDTH_160:
38762d51a43SBjoern A. Zeeb case NL80211_CHAN_WIDTH_80P80:
38862d51a43SBjoern A. Zeeb return (IEEE80211_STA_RX_BW_160);
38962d51a43SBjoern A. Zeeb case NL80211_CHAN_WIDTH_80:
39062d51a43SBjoern A. Zeeb return (IEEE80211_STA_RX_BW_80);
39162d51a43SBjoern A. Zeeb case NL80211_CHAN_WIDTH_40:
39262d51a43SBjoern A. Zeeb return (IEEE80211_STA_RX_BW_40);
39362d51a43SBjoern A. Zeeb case NL80211_CHAN_WIDTH_20:
39462d51a43SBjoern A. Zeeb case NL80211_CHAN_WIDTH_20_NOHT:
39562d51a43SBjoern A. Zeeb return (IEEE80211_STA_RX_BW_20);
39662d51a43SBjoern A. Zeeb case NL80211_CHAN_WIDTH_5:
39762d51a43SBjoern A. Zeeb case NL80211_CHAN_WIDTH_10:
39862d51a43SBjoern A. Zeeb /* Unsupported input. */
39962d51a43SBjoern A. Zeeb return (IEEE80211_STA_RX_BW_20);
40062d51a43SBjoern A. Zeeb }
40162d51a43SBjoern A. Zeeb }
40262d51a43SBjoern A. Zeeb
40362d51a43SBjoern A. Zeeb static enum nl80211_chan_width
lkpi_rx_bw_to_cw(enum ieee80211_sta_rx_bw rx_bw)40462d51a43SBjoern A. Zeeb lkpi_rx_bw_to_cw(enum ieee80211_sta_rx_bw rx_bw)
40562d51a43SBjoern A. Zeeb {
40662d51a43SBjoern A. Zeeb switch (rx_bw) {
40762d51a43SBjoern A. Zeeb case IEEE80211_STA_RX_BW_20:
40862d51a43SBjoern A. Zeeb return (NL80211_CHAN_WIDTH_20); /* _NOHT */
40962d51a43SBjoern A. Zeeb case IEEE80211_STA_RX_BW_40:
41062d51a43SBjoern A. Zeeb return (NL80211_CHAN_WIDTH_40);
41162d51a43SBjoern A. Zeeb case IEEE80211_STA_RX_BW_80:
41262d51a43SBjoern A. Zeeb return (NL80211_CHAN_WIDTH_80);
41362d51a43SBjoern A. Zeeb case IEEE80211_STA_RX_BW_160:
41462d51a43SBjoern A. Zeeb return (NL80211_CHAN_WIDTH_160); /* 80P80 */
41562d51a43SBjoern A. Zeeb case IEEE80211_STA_RX_BW_320:
41662d51a43SBjoern A. Zeeb return (NL80211_CHAN_WIDTH_320);
41762d51a43SBjoern A. Zeeb }
41862d51a43SBjoern A. Zeeb }
41962d51a43SBjoern A. Zeeb
42062d51a43SBjoern A. Zeeb static void
lkpi_sync_chanctx_cw_from_rx_bw(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta)42162d51a43SBjoern A. Zeeb lkpi_sync_chanctx_cw_from_rx_bw(struct ieee80211_hw *hw,
42262d51a43SBjoern A. Zeeb struct ieee80211_vif *vif, struct ieee80211_sta *sta)
42362d51a43SBjoern A. Zeeb {
42462d51a43SBjoern A. Zeeb struct ieee80211_chanctx_conf *chanctx_conf;
42562d51a43SBjoern A. Zeeb enum ieee80211_sta_rx_bw old_bw;
42662d51a43SBjoern A. Zeeb uint32_t changed;
42762d51a43SBjoern A. Zeeb
42862d51a43SBjoern A. Zeeb chanctx_conf = rcu_dereference_protected(vif->bss_conf.chanctx_conf,
42962d51a43SBjoern A. Zeeb lockdep_is_held(&hw->wiphy->mtx));
43062d51a43SBjoern A. Zeeb if (chanctx_conf == NULL)
43162d51a43SBjoern A. Zeeb return;
43262d51a43SBjoern A. Zeeb
43362d51a43SBjoern A. Zeeb old_bw = lkpi_cw_to_rx_bw(chanctx_conf->def.width);
43462d51a43SBjoern A. Zeeb if (old_bw == sta->deflink.bandwidth)
43562d51a43SBjoern A. Zeeb return;
43662d51a43SBjoern A. Zeeb
43762d51a43SBjoern A. Zeeb chanctx_conf->def.width = lkpi_rx_bw_to_cw(sta->deflink.bandwidth);
43862d51a43SBjoern A. Zeeb if (chanctx_conf->def.width == NL80211_CHAN_WIDTH_20 &&
43962d51a43SBjoern A. Zeeb !sta->deflink.ht_cap.ht_supported)
44062d51a43SBjoern A. Zeeb chanctx_conf->def.width = NL80211_CHAN_WIDTH_20_NOHT;
44162d51a43SBjoern A. Zeeb
44262d51a43SBjoern A. Zeeb chanctx_conf->min_def = chanctx_conf->def;
44362d51a43SBjoern A. Zeeb
44462d51a43SBjoern A. Zeeb vif->bss_conf.chanreq.oper.width = chanctx_conf->def.width;
44562d51a43SBjoern A. Zeeb
44662d51a43SBjoern A. Zeeb changed = IEEE80211_CHANCTX_CHANGE_MIN_WIDTH;
44762d51a43SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_WIDTH;
44862d51a43SBjoern A. Zeeb lkpi_80211_mo_change_chanctx(hw, chanctx_conf, changed);
44962d51a43SBjoern A. Zeeb }
45062d51a43SBjoern A. Zeeb
4519fb91463SBjoern A. Zeeb #if defined(LKPI_80211_HT)
4529fb91463SBjoern A. Zeeb static void
lkpi_sta_sync_ht_from_ni(struct ieee80211_vif * vif,struct ieee80211_sta * sta,struct ieee80211_node * ni)45362d51a43SBjoern A. Zeeb lkpi_sta_sync_ht_from_ni(struct ieee80211_vif *vif, struct ieee80211_sta *sta,
45462d51a43SBjoern A. Zeeb struct ieee80211_node *ni)
4559fb91463SBjoern A. Zeeb {
4569fb91463SBjoern A. Zeeb struct ieee80211vap *vap;
4579fb91463SBjoern A. Zeeb uint8_t *ie;
4589fb91463SBjoern A. Zeeb struct ieee80211_ht_cap *htcap;
4599fb91463SBjoern A. Zeeb int i, rx_nss;
4609fb91463SBjoern A. Zeeb
461f9c7a07dSBjoern A. Zeeb if ((ni->ni_flags & IEEE80211_NODE_HT) == 0) {
462f9c7a07dSBjoern A. Zeeb sta->deflink.ht_cap.ht_supported = false;
4639fb91463SBjoern A. Zeeb return;
464f9c7a07dSBjoern A. Zeeb }
4659fb91463SBjoern A. Zeeb
4669fb91463SBjoern A. Zeeb sta->deflink.ht_cap.ht_supported = true;
4679fb91463SBjoern A. Zeeb
4689fb91463SBjoern A. Zeeb /* htcap->ampdu_params_info */
4699fb91463SBjoern A. Zeeb vap = ni->ni_vap;
4709fb91463SBjoern A. Zeeb sta->deflink.ht_cap.ampdu_density = _IEEE80211_MASKSHIFT(ni->ni_htparam, IEEE80211_HTCAP_MPDUDENSITY);
4719fb91463SBjoern A. Zeeb if (sta->deflink.ht_cap.ampdu_density > vap->iv_ampdu_density)
4729fb91463SBjoern A. Zeeb sta->deflink.ht_cap.ampdu_density = vap->iv_ampdu_density;
4739fb91463SBjoern A. Zeeb sta->deflink.ht_cap.ampdu_factor = _IEEE80211_MASKSHIFT(ni->ni_htparam, IEEE80211_HTCAP_MAXRXAMPDU);
4749fb91463SBjoern A. Zeeb if (sta->deflink.ht_cap.ampdu_factor > vap->iv_ampdu_rxmax)
4759fb91463SBjoern A. Zeeb sta->deflink.ht_cap.ampdu_factor = vap->iv_ampdu_rxmax;
4769fb91463SBjoern A. Zeeb
4779fb91463SBjoern A. Zeeb ie = ni->ni_ies.htcap_ie;
4789fb91463SBjoern A. Zeeb KASSERT(ie != NULL, ("%s: HT but no htcap_ie on ni %p\n", __func__, ni));
4799fb91463SBjoern A. Zeeb if (ie[0] == IEEE80211_ELEMID_VENDOR)
4809fb91463SBjoern A. Zeeb ie += 4;
4819fb91463SBjoern A. Zeeb ie += 2;
4829fb91463SBjoern A. Zeeb htcap = (struct ieee80211_ht_cap *)ie;
4839fb91463SBjoern A. Zeeb sta->deflink.ht_cap.cap = htcap->cap_info;
4849fb91463SBjoern A. Zeeb sta->deflink.ht_cap.mcs = htcap->mcs;
4859fb91463SBjoern A. Zeeb
486f9c7a07dSBjoern A. Zeeb /*
487f9c7a07dSBjoern A. Zeeb * 802.11n-2009 20.6 Parameters for HT MCSs gives the mandatory/
488f9c7a07dSBjoern A. Zeeb * optional MCS for Nss=1..4. We need to check the first four
489f9c7a07dSBjoern A. Zeeb * MCS sets from the Rx MCS Bitmask; then there is MCS 32 and
490f9c7a07dSBjoern A. Zeeb * MCS33.. is UEQM.
491f9c7a07dSBjoern A. Zeeb */
4929fb91463SBjoern A. Zeeb rx_nss = 0;
493f9c7a07dSBjoern A. Zeeb for (i = 0; i < 4; i++) {
49458dae28fSBjoern A. Zeeb if (htcap->mcs.rx_mask[i] != 0)
4959fb91463SBjoern A. Zeeb rx_nss++;
4969fb91463SBjoern A. Zeeb }
49758dae28fSBjoern A. Zeeb if (rx_nss > 0) {
498f9c7a07dSBjoern A. Zeeb sta->deflink.rx_nss = rx_nss;
49958dae28fSBjoern A. Zeeb } else {
50058dae28fSBjoern A. Zeeb sta->deflink.ht_cap.ht_supported = false;
50158dae28fSBjoern A. Zeeb return;
50258dae28fSBjoern A. Zeeb }
50358dae28fSBjoern A. Zeeb
50458dae28fSBjoern A. Zeeb if ((sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) != 0 &&
50558dae28fSBjoern A. Zeeb IEEE80211_IS_CHAN_HT40(ni->ni_chan))
50658dae28fSBjoern A. Zeeb sta->deflink.bandwidth = IEEE80211_STA_RX_BW_40;
50758dae28fSBjoern A. Zeeb else
50858dae28fSBjoern A. Zeeb sta->deflink.bandwidth = IEEE80211_STA_RX_BW_20;
5099fb91463SBjoern A. Zeeb
510f9c7a07dSBjoern A. Zeeb IMPROVE("sta->wme");
511f9c7a07dSBjoern A. Zeeb
512f9c7a07dSBjoern A. Zeeb if (sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_MAX_AMSDU)
513f9c7a07dSBjoern A. Zeeb sta->deflink.agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_HT_7935;
514f9c7a07dSBjoern A. Zeeb else
515f9c7a07dSBjoern A. Zeeb sta->deflink.agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_HT_3839;
516f9c7a07dSBjoern A. Zeeb sta->deflink.agg.max_rc_amsdu_len = IEEE80211_MAX_MPDU_LEN_HT_BA;
517f9c7a07dSBjoern A. Zeeb #ifdef __handled_by_driver__ /* iwlwifi only? actually unused? */
518f9c7a07dSBjoern A. Zeeb for (i = 0; i < nitems(sta.deflink.agg.max_tid_amsdu_len); i++) {
519f9c7a07dSBjoern A. Zeeb sta->deflink.agg.max_tid_amsdu_len[j] = ;
520f9c7a07dSBjoern A. Zeeb }
521f9c7a07dSBjoern A. Zeeb #endif
5229fb91463SBjoern A. Zeeb }
5239fb91463SBjoern A. Zeeb #endif
5249fb91463SBjoern A. Zeeb
5259fb91463SBjoern A. Zeeb #if defined(LKPI_80211_VHT)
5269fb91463SBjoern A. Zeeb static void
lkpi_sta_sync_vht_from_ni(struct ieee80211_vif * vif,struct ieee80211_sta * sta,struct ieee80211_node * ni)52762d51a43SBjoern A. Zeeb lkpi_sta_sync_vht_from_ni(struct ieee80211_vif *vif, struct ieee80211_sta *sta,
52862d51a43SBjoern A. Zeeb struct ieee80211_node *ni)
5299fb91463SBjoern A. Zeeb {
5309df0d1f3SBjoern A. Zeeb enum ieee80211_sta_rx_bw bw;
531f9c7a07dSBjoern A. Zeeb uint32_t width;
532f9c7a07dSBjoern A. Zeeb int rx_nss;
533f9c7a07dSBjoern A. Zeeb uint16_t rx_mcs_map;
534f9c7a07dSBjoern A. Zeeb uint8_t mcs;
5359fb91463SBjoern A. Zeeb
5365393cd34SBjoern A. Zeeb if ((ni->ni_flags & IEEE80211_NODE_VHT) == 0 ||
5375393cd34SBjoern A. Zeeb !IEEE80211_IS_CHAN_VHT_5GHZ(ni->ni_chan)) {
538f9c7a07dSBjoern A. Zeeb sta->deflink.vht_cap.vht_supported = false;
5399fb91463SBjoern A. Zeeb return;
540f9c7a07dSBjoern A. Zeeb }
5419fb91463SBjoern A. Zeeb
542f9c7a07dSBjoern A. Zeeb sta->deflink.vht_cap.vht_supported = true;
543f9c7a07dSBjoern A. Zeeb
544f9c7a07dSBjoern A. Zeeb sta->deflink.vht_cap.cap = ni->ni_vhtcap;
545f9c7a07dSBjoern A. Zeeb sta->deflink.vht_cap.vht_mcs = ni->ni_vht_mcsinfo;
546f9c7a07dSBjoern A. Zeeb
5473e022a91SBjoern A. Zeeb /*
5483e022a91SBjoern A. Zeeb * If VHT20/40 are selected do not update the bandwidth
5493e022a91SBjoern A. Zeeb * from HT but stya on VHT.
5503e022a91SBjoern A. Zeeb */
5513e022a91SBjoern A. Zeeb if (ni->ni_vht_chanwidth == IEEE80211_VHT_CHANWIDTH_USE_HT)
5523e022a91SBjoern A. Zeeb goto skip_bw;
5533e022a91SBjoern A. Zeeb
5549df0d1f3SBjoern A. Zeeb bw = sta->deflink.bandwidth;
555f9c7a07dSBjoern A. Zeeb width = (sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK);
556f9c7a07dSBjoern A. Zeeb switch (width) {
5579df0d1f3SBjoern A. Zeeb /* Deprecated. */
558f9c7a07dSBjoern A. Zeeb case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
559f9c7a07dSBjoern A. Zeeb case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
5609df0d1f3SBjoern A. Zeeb bw = IEEE80211_STA_RX_BW_160;
561f9c7a07dSBjoern A. Zeeb break;
562f9c7a07dSBjoern A. Zeeb default:
563f9c7a07dSBjoern A. Zeeb /* Check if we do support 160Mhz somehow after all. */
564f9c7a07dSBjoern A. Zeeb if ((sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_EXT_NSS_BW_MASK) != 0)
5659df0d1f3SBjoern A. Zeeb bw = IEEE80211_STA_RX_BW_160;
566f9c7a07dSBjoern A. Zeeb else
5679df0d1f3SBjoern A. Zeeb bw = IEEE80211_STA_RX_BW_80;
5689fb91463SBjoern A. Zeeb }
5699df0d1f3SBjoern A. Zeeb /*
5709df0d1f3SBjoern A. Zeeb * While we can set what is possibly supported we also need to be
5719df0d1f3SBjoern A. Zeeb * on a channel which supports that bandwidth; e.g., we can support
5729df0d1f3SBjoern A. Zeeb * VHT160 but the AP only does VHT80.
5739df0d1f3SBjoern A. Zeeb * Further ni_chan will also have filtered out what we disabled
5749df0d1f3SBjoern A. Zeeb * by configuration.
5759df0d1f3SBjoern A. Zeeb * Once net80211 channel selection is fixed for 802.11-2020 and
5769df0d1f3SBjoern A. Zeeb * VHT160 we can possibly spare ourselves the above.
5779df0d1f3SBjoern A. Zeeb */
5789df0d1f3SBjoern A. Zeeb if (bw == IEEE80211_STA_RX_BW_160 &&
5799df0d1f3SBjoern A. Zeeb !IEEE80211_IS_CHAN_VHT160(ni->ni_chan) &&
5809df0d1f3SBjoern A. Zeeb !IEEE80211_IS_CHAN_VHT80P80(ni->ni_chan))
5819df0d1f3SBjoern A. Zeeb bw = IEEE80211_STA_RX_BW_80;
5829df0d1f3SBjoern A. Zeeb if (bw == IEEE80211_STA_RX_BW_80 &&
5839df0d1f3SBjoern A. Zeeb !IEEE80211_IS_CHAN_VHT80(ni->ni_chan))
5849df0d1f3SBjoern A. Zeeb bw = sta->deflink.bandwidth;
5859df0d1f3SBjoern A. Zeeb sta->deflink.bandwidth = bw;
5863e022a91SBjoern A. Zeeb skip_bw:
587f9c7a07dSBjoern A. Zeeb
588f9c7a07dSBjoern A. Zeeb rx_nss = 0;
589f9c7a07dSBjoern A. Zeeb rx_mcs_map = sta->deflink.vht_cap.vht_mcs.rx_mcs_map;
590f9c7a07dSBjoern A. Zeeb for (int i = 7; i >= 0; i--) {
591f9c7a07dSBjoern A. Zeeb mcs = rx_mcs_map >> (2 * i);
592f9c7a07dSBjoern A. Zeeb mcs &= 0x3;
593f9c7a07dSBjoern A. Zeeb if (mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
594f9c7a07dSBjoern A. Zeeb rx_nss = i + 1;
595f9c7a07dSBjoern A. Zeeb break;
596f9c7a07dSBjoern A. Zeeb }
597f9c7a07dSBjoern A. Zeeb }
598f9c7a07dSBjoern A. Zeeb if (rx_nss > 0)
599f9c7a07dSBjoern A. Zeeb sta->deflink.rx_nss = rx_nss;
600f9c7a07dSBjoern A. Zeeb
601f9c7a07dSBjoern A. Zeeb switch (sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_MAX_MPDU_MASK) {
602f9c7a07dSBjoern A. Zeeb case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454:
603f9c7a07dSBjoern A. Zeeb sta->deflink.agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_11454;
604f9c7a07dSBjoern A. Zeeb break;
605f9c7a07dSBjoern A. Zeeb case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991:
606f9c7a07dSBjoern A. Zeeb sta->deflink.agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_7991;
607f9c7a07dSBjoern A. Zeeb break;
608f9c7a07dSBjoern A. Zeeb case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895:
609f9c7a07dSBjoern A. Zeeb default:
610f9c7a07dSBjoern A. Zeeb sta->deflink.agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_3895;
611f9c7a07dSBjoern A. Zeeb break;
612f9c7a07dSBjoern A. Zeeb }
6139fb91463SBjoern A. Zeeb }
6149fb91463SBjoern A. Zeeb #endif
6159fb91463SBjoern A. Zeeb
616d9f59799SBjoern A. Zeeb static void
lkpi_sta_sync_from_ni(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta,struct ieee80211_node * ni,bool updchnctx)61762d51a43SBjoern A. Zeeb lkpi_sta_sync_from_ni(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
61862d51a43SBjoern A. Zeeb struct ieee80211_sta *sta, struct ieee80211_node *ni, bool updchnctx)
619f9c7a07dSBjoern A. Zeeb {
620f9c7a07dSBjoern A. Zeeb
621f9c7a07dSBjoern A. Zeeb #if defined(LKPI_80211_HT)
62262d51a43SBjoern A. Zeeb lkpi_sta_sync_ht_from_ni(vif, sta, ni);
623f9c7a07dSBjoern A. Zeeb #endif
624f9c7a07dSBjoern A. Zeeb #if defined(LKPI_80211_VHT)
62562d51a43SBjoern A. Zeeb lkpi_sta_sync_vht_from_ni(vif, sta, ni);
626f9c7a07dSBjoern A. Zeeb #endif
62734c150ccSBjoern A. Zeeb
62834c150ccSBjoern A. Zeeb /*
62934c150ccSBjoern A. Zeeb * Ensure rx_nss is at least 1 as otherwise drivers run into
63034c150ccSBjoern A. Zeeb * unexpected problems.
63134c150ccSBjoern A. Zeeb */
63234c150ccSBjoern A. Zeeb sta->deflink.rx_nss = MAX(1, sta->deflink.rx_nss);
63334c150ccSBjoern A. Zeeb
63462d51a43SBjoern A. Zeeb /*
63562d51a43SBjoern A. Zeeb * We are also called from node allocation which net80211
63662d51a43SBjoern A. Zeeb * can do even on `ifconfig down`; in that case the chanctx
63762d51a43SBjoern A. Zeeb * may still be valid and we get a discrepancy between
63862d51a43SBjoern A. Zeeb * sta and chanctx. Thus do not try to update the chanctx
63962d51a43SBjoern A. Zeeb * when called from lkpi_lsta_alloc().
64062d51a43SBjoern A. Zeeb */
64162d51a43SBjoern A. Zeeb if (updchnctx)
64262d51a43SBjoern A. Zeeb lkpi_sync_chanctx_cw_from_rx_bw(hw, vif, sta);
643f9c7a07dSBjoern A. Zeeb }
644f9c7a07dSBjoern A. Zeeb
645389265e3SBjoern A. Zeeb static uint8_t
lkpi_get_max_rx_chains(struct ieee80211_node * ni)646389265e3SBjoern A. Zeeb lkpi_get_max_rx_chains(struct ieee80211_node *ni)
647389265e3SBjoern A. Zeeb {
648389265e3SBjoern A. Zeeb uint8_t chains;
649389265e3SBjoern A. Zeeb #if defined(LKPI_80211_HT) || defined(LKPI_80211_VHT)
650389265e3SBjoern A. Zeeb struct lkpi_sta *lsta;
651389265e3SBjoern A. Zeeb struct ieee80211_sta *sta;
652389265e3SBjoern A. Zeeb
653389265e3SBjoern A. Zeeb lsta = ni->ni_drv_data;
654389265e3SBjoern A. Zeeb sta = LSTA_TO_STA(lsta);
655389265e3SBjoern A. Zeeb #endif
656389265e3SBjoern A. Zeeb
657389265e3SBjoern A. Zeeb chains = 1;
658389265e3SBjoern A. Zeeb #if defined(LKPI_80211_HT)
659389265e3SBjoern A. Zeeb IMPROVE("We should factor counting MCS/NSS out for sync and here");
660389265e3SBjoern A. Zeeb if (sta->deflink.ht_cap.ht_supported)
661389265e3SBjoern A. Zeeb chains = MAX(chains, sta->deflink.rx_nss);
662389265e3SBjoern A. Zeeb #endif
663389265e3SBjoern A. Zeeb
664389265e3SBjoern A. Zeeb #if defined(LKPI_80211_VHT)
665389265e3SBjoern A. Zeeb if (sta->deflink.vht_cap.vht_supported)
666389265e3SBjoern A. Zeeb chains = MAX(chains, sta->deflink.rx_nss);
667389265e3SBjoern A. Zeeb #endif
668389265e3SBjoern A. Zeeb
669389265e3SBjoern A. Zeeb return (chains);
670389265e3SBjoern A. Zeeb }
671389265e3SBjoern A. Zeeb
672f9c7a07dSBjoern A. Zeeb static void
lkpi_lsta_dump(struct lkpi_sta * lsta,struct ieee80211_node * ni,const char * _f,int _l)67367674c1cSBjoern A. Zeeb lkpi_lsta_dump(struct lkpi_sta *lsta, struct ieee80211_node *ni,
67467674c1cSBjoern A. Zeeb const char *_f, int _l)
675d9f59799SBjoern A. Zeeb {
676d9f59799SBjoern A. Zeeb
6779d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
6789d9ba2b7SBjoern A. Zeeb if ((linuxkpi_debug_80211 & D80211_TRACE_STA) == 0)
679d9f59799SBjoern A. Zeeb return;
680d9f59799SBjoern A. Zeeb if (lsta == NULL)
681d9f59799SBjoern A. Zeeb return;
682d9f59799SBjoern A. Zeeb
683d9f59799SBjoern A. Zeeb printf("%s:%d lsta %p ni %p sta %p\n",
68467674c1cSBjoern A. Zeeb _f, _l, lsta, ni, &lsta->sta);
68567674c1cSBjoern A. Zeeb if (ni != NULL)
68667674c1cSBjoern A. Zeeb ieee80211_dump_node(NULL, ni);
687d9f59799SBjoern A. Zeeb printf("\ttxq_task txq len %d mtx\n", mbufq_len(&lsta->txq));
688d9f59799SBjoern A. Zeeb printf("\tkc %p state %d added_to_drv %d in_mgd %d\n",
68911db70b6SBjoern A. Zeeb &lsta->kc[0], lsta->state, lsta->added_to_drv, lsta->in_mgd);
6909d9ba2b7SBjoern A. Zeeb #endif
691d9f59799SBjoern A. Zeeb }
692d9f59799SBjoern A. Zeeb
693d9f59799SBjoern A. Zeeb static void
lkpi_lsta_remove(struct lkpi_sta * lsta,struct lkpi_vif * lvif)694d9f59799SBjoern A. Zeeb lkpi_lsta_remove(struct lkpi_sta *lsta, struct lkpi_vif *lvif)
695d9f59799SBjoern A. Zeeb {
696d9f59799SBjoern A. Zeeb
697cd0fcf9fSBjoern A. Zeeb lockdep_assert_wiphy(lsta->hw->wiphy);
698d9f59799SBjoern A. Zeeb
699a8f735a6SBjoern A. Zeeb KASSERT(!list_empty(&lsta->lsta_list),
700a8f735a6SBjoern A. Zeeb ("%s: lsta %p ni %p\n", __func__, lsta, lsta->ni));
701a8f735a6SBjoern A. Zeeb list_del_init(&lsta->lsta_list);
702d9f59799SBjoern A. Zeeb }
703d9f59799SBjoern A. Zeeb
7044f61ef8bSBjoern A. Zeeb static struct lkpi_sta *
lkpi_lsta_alloc(struct ieee80211vap * vap,const uint8_t mac[IEEE80211_ADDR_LEN],struct ieee80211_hw * hw,struct ieee80211_node * ni)7054f61ef8bSBjoern A. Zeeb lkpi_lsta_alloc(struct ieee80211vap *vap, const uint8_t mac[IEEE80211_ADDR_LEN],
7064f61ef8bSBjoern A. Zeeb struct ieee80211_hw *hw, struct ieee80211_node *ni)
7074f61ef8bSBjoern A. Zeeb {
7084f61ef8bSBjoern A. Zeeb struct lkpi_sta *lsta;
7094f61ef8bSBjoern A. Zeeb struct lkpi_vif *lvif;
7104f61ef8bSBjoern A. Zeeb struct ieee80211_vif *vif;
7114f61ef8bSBjoern A. Zeeb struct ieee80211_sta *sta;
712b6b352e4SBjoern A. Zeeb int band, i, tid;
7134f61ef8bSBjoern A. Zeeb
7144f61ef8bSBjoern A. Zeeb lsta = malloc(sizeof(*lsta) + hw->sta_data_size, M_LKPI80211,
7154f61ef8bSBjoern A. Zeeb M_NOWAIT | M_ZERO);
7164f61ef8bSBjoern A. Zeeb if (lsta == NULL)
7174f61ef8bSBjoern A. Zeeb return (NULL);
7184f61ef8bSBjoern A. Zeeb
719a8f735a6SBjoern A. Zeeb lsta->hw = hw;
7204f61ef8bSBjoern A. Zeeb lsta->added_to_drv = false;
7214f61ef8bSBjoern A. Zeeb lsta->state = IEEE80211_STA_NOTEXIST;
7224f61ef8bSBjoern A. Zeeb /*
7230936c648SBjoern A. Zeeb * Link the ni to the lsta here without taking a reference.
7240936c648SBjoern A. Zeeb * For one we would have to take the reference in node_init()
7250936c648SBjoern A. Zeeb * as ieee80211_alloc_node() will initialise the refcount after us.
7260936c648SBjoern A. Zeeb * For the other a ni and an lsta are 1:1 mapped and always together
7270936c648SBjoern A. Zeeb * from [ic_]node_alloc() to [ic_]node_free() so we are essentally
7280936c648SBjoern A. Zeeb * using the ni references for the lsta as well despite it being
7290936c648SBjoern A. Zeeb * two separate allocations.
7304f61ef8bSBjoern A. Zeeb */
7310936c648SBjoern A. Zeeb lsta->ni = ni;
7324f61ef8bSBjoern A. Zeeb /* The back-pointer "drv_data" to net80211_node let's us get lsta. */
7334f61ef8bSBjoern A. Zeeb ni->ni_drv_data = lsta;
7344f61ef8bSBjoern A. Zeeb
7354f61ef8bSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
7364f61ef8bSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
7374f61ef8bSBjoern A. Zeeb sta = LSTA_TO_STA(lsta);
7384f61ef8bSBjoern A. Zeeb
7394f61ef8bSBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->addr, mac);
740b6b352e4SBjoern A. Zeeb
741b6b352e4SBjoern A. Zeeb /* TXQ */
7424f61ef8bSBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) {
7434f61ef8bSBjoern A. Zeeb struct lkpi_txq *ltxq;
7444f61ef8bSBjoern A. Zeeb
745d0d29110SBjoern A. Zeeb /* We are not limiting ourselves to hw.queues here. */
7464f61ef8bSBjoern A. Zeeb ltxq = malloc(sizeof(*ltxq) + hw->txq_data_size,
7474f61ef8bSBjoern A. Zeeb M_LKPI80211, M_NOWAIT | M_ZERO);
7484f61ef8bSBjoern A. Zeeb if (ltxq == NULL)
7494f61ef8bSBjoern A. Zeeb goto cleanup;
7504f61ef8bSBjoern A. Zeeb /* iwlwifi//mvm/sta.c::tid_to_mac80211_ac[] */
7514f61ef8bSBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) {
752d0d29110SBjoern A. Zeeb if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ)) {
753d0d29110SBjoern A. Zeeb free(ltxq, M_LKPI80211);
754d0d29110SBjoern A. Zeeb continue;
755d0d29110SBjoern A. Zeeb }
756d0d29110SBjoern A. Zeeb IMPROVE("AP/if we support non-STA here too");
7574f61ef8bSBjoern A. Zeeb ltxq->txq.ac = IEEE80211_AC_VO;
7584f61ef8bSBjoern A. Zeeb } else {
759fb3c249eSBjoern A. Zeeb ltxq->txq.ac = ieee80211e_up_to_ac[tid & 7];
7604f61ef8bSBjoern A. Zeeb }
761d0d29110SBjoern A. Zeeb ltxq->seen_dequeue = false;
7620cbcfa19SBjoern A. Zeeb ltxq->stopped = false;
763d0d29110SBjoern A. Zeeb ltxq->txq.vif = vif;
7644f61ef8bSBjoern A. Zeeb ltxq->txq.tid = tid;
7654f61ef8bSBjoern A. Zeeb ltxq->txq.sta = sta;
7660cbcfa19SBjoern A. Zeeb TAILQ_ELEM_INIT(ltxq, txq_entry);
767d0d29110SBjoern A. Zeeb skb_queue_head_init(<xq->skbq);
768eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_LOCK_INIT(ltxq);
7694f61ef8bSBjoern A. Zeeb sta->txq[tid] = <xq->txq;
7704f61ef8bSBjoern A. Zeeb }
7714f61ef8bSBjoern A. Zeeb
772b6b352e4SBjoern A. Zeeb /* Deflink information. */
773b6b352e4SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) {
774b6b352e4SBjoern A. Zeeb struct ieee80211_supported_band *supband;
775b6b352e4SBjoern A. Zeeb
776b6b352e4SBjoern A. Zeeb supband = hw->wiphy->bands[band];
777b6b352e4SBjoern A. Zeeb if (supband == NULL)
778b6b352e4SBjoern A. Zeeb continue;
779b6b352e4SBjoern A. Zeeb
780b6b352e4SBjoern A. Zeeb for (i = 0; i < supband->n_bitrates; i++) {
78173cd1c5dSBjoern A. Zeeb switch (band) {
78273cd1c5dSBjoern A. Zeeb case NL80211_BAND_2GHZ:
78373cd1c5dSBjoern A. Zeeb switch (supband->bitrates[i].bitrate) {
78473cd1c5dSBjoern A. Zeeb case 240: /* 11g only */
78573cd1c5dSBjoern A. Zeeb case 120: /* 11g only */
78673cd1c5dSBjoern A. Zeeb case 110:
78773cd1c5dSBjoern A. Zeeb case 60: /* 11g only */
78873cd1c5dSBjoern A. Zeeb case 55:
78973cd1c5dSBjoern A. Zeeb case 20:
79073cd1c5dSBjoern A. Zeeb case 10:
791b6b352e4SBjoern A. Zeeb sta->deflink.supp_rates[band] |= BIT(i);
79273cd1c5dSBjoern A. Zeeb break;
79373cd1c5dSBjoern A. Zeeb }
79473cd1c5dSBjoern A. Zeeb break;
79573cd1c5dSBjoern A. Zeeb case NL80211_BAND_5GHZ:
79673cd1c5dSBjoern A. Zeeb switch (supband->bitrates[i].bitrate) {
79773cd1c5dSBjoern A. Zeeb case 240:
79873cd1c5dSBjoern A. Zeeb case 120:
79973cd1c5dSBjoern A. Zeeb case 60:
80073cd1c5dSBjoern A. Zeeb sta->deflink.supp_rates[band] |= BIT(i);
80173cd1c5dSBjoern A. Zeeb break;
80273cd1c5dSBjoern A. Zeeb }
80373cd1c5dSBjoern A. Zeeb break;
80473cd1c5dSBjoern A. Zeeb }
805b6b352e4SBjoern A. Zeeb }
806b6b352e4SBjoern A. Zeeb }
8079fb91463SBjoern A. Zeeb
8086ffb7bd4SBjoern A. Zeeb sta->deflink.smps_mode = IEEE80211_SMPS_OFF;
8099fb91463SBjoern A. Zeeb sta->deflink.bandwidth = IEEE80211_STA_RX_BW_20;
810f5a58c2dSMikhail Pchelin sta->deflink.rx_nss = 1;
8119fb91463SBjoern A. Zeeb
81262d51a43SBjoern A. Zeeb lkpi_sta_sync_from_ni(hw, vif, sta, ni, false);
8139fb91463SBjoern A. Zeeb
814f9c7a07dSBjoern A. Zeeb IMPROVE("he, eht, bw_320, ... smps_mode, ..");
815b6b352e4SBjoern A. Zeeb
8166ffb7bd4SBjoern A. Zeeb /* Link configuration. */
8176ffb7bd4SBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->deflink.addr, sta->addr);
8186ffb7bd4SBjoern A. Zeeb sta->link[0] = &sta->deflink;
8196ffb7bd4SBjoern A. Zeeb for (i = 1; i < nitems(sta->link); i++) {
8206ffb7bd4SBjoern A. Zeeb IMPROVE("more links; only link[0] = deflink currently.");
8216ffb7bd4SBjoern A. Zeeb }
82271034267SBjoern A. Zeeb IMPROVE("11be");
82371034267SBjoern A. Zeeb sta->mlo = false;
8246ffb7bd4SBjoern A. Zeeb
8254f61ef8bSBjoern A. Zeeb /* Deferred TX path. */
826fa4e4257SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_LOCK_INIT(lsta);
8274f61ef8bSBjoern A. Zeeb TASK_INIT(&lsta->txq_task, 0, lkpi_80211_txq_task, lsta);
828832b8e98SBjoern A. Zeeb mbufq_init(&lsta->txq, 32 * NAPI_POLL_WEIGHT);
8290936c648SBjoern A. Zeeb lsta->txq_ready = true;
8304f61ef8bSBjoern A. Zeeb
8314f61ef8bSBjoern A. Zeeb return (lsta);
8324f61ef8bSBjoern A. Zeeb
8334f61ef8bSBjoern A. Zeeb cleanup:
834eac3646fSBjoern A. Zeeb for (; tid >= 0; tid--) {
835eac3646fSBjoern A. Zeeb struct lkpi_txq *ltxq;
836eac3646fSBjoern A. Zeeb
837eac3646fSBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]);
838eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_LOCK_DESTROY(ltxq);
8394f61ef8bSBjoern A. Zeeb free(sta->txq[tid], M_LKPI80211);
840eac3646fSBjoern A. Zeeb }
8414f61ef8bSBjoern A. Zeeb free(lsta, M_LKPI80211);
8424f61ef8bSBjoern A. Zeeb return (NULL);
8434f61ef8bSBjoern A. Zeeb }
8444f61ef8bSBjoern A. Zeeb
8450936c648SBjoern A. Zeeb static void
lkpi_lsta_free(struct lkpi_sta * lsta,struct ieee80211_node * ni)8460936c648SBjoern A. Zeeb lkpi_lsta_free(struct lkpi_sta *lsta, struct ieee80211_node *ni)
8470936c648SBjoern A. Zeeb {
8480936c648SBjoern A. Zeeb struct mbuf *m;
8490936c648SBjoern A. Zeeb
8500936c648SBjoern A. Zeeb if (lsta->added_to_drv)
8510936c648SBjoern A. Zeeb panic("%s: Trying to free an lsta still known to firmware: "
8520936c648SBjoern A. Zeeb "lsta %p ni %p added_to_drv %d\n",
8530936c648SBjoern A. Zeeb __func__, lsta, ni, lsta->added_to_drv);
8540936c648SBjoern A. Zeeb
8550936c648SBjoern A. Zeeb /* XXX-BZ free resources, ... */
8560936c648SBjoern A. Zeeb IMPROVE();
8570936c648SBjoern A. Zeeb
858fa4e4257SBjoern A. Zeeb /* Drain sta->txq[] */
859fa4e4257SBjoern A. Zeeb
860fa4e4257SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_LOCK(lsta);
8610936c648SBjoern A. Zeeb lsta->txq_ready = false;
862fa4e4257SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_UNLOCK(lsta);
8630936c648SBjoern A. Zeeb
8640936c648SBjoern A. Zeeb /* Drain taskq, won't be restarted until added_to_drv is set again. */
8650936c648SBjoern A. Zeeb while (taskqueue_cancel(taskqueue_thread, &lsta->txq_task, NULL) != 0)
8660936c648SBjoern A. Zeeb taskqueue_drain(taskqueue_thread, &lsta->txq_task);
8670936c648SBjoern A. Zeeb
8680936c648SBjoern A. Zeeb /* Flush mbufq (make sure to release ni refs!). */
8690936c648SBjoern A. Zeeb m = mbufq_dequeue(&lsta->txq);
8700936c648SBjoern A. Zeeb while (m != NULL) {
8710936c648SBjoern A. Zeeb struct ieee80211_node *nim;
8720936c648SBjoern A. Zeeb
8730936c648SBjoern A. Zeeb nim = (struct ieee80211_node *)m->m_pkthdr.rcvif;
8740936c648SBjoern A. Zeeb if (nim != NULL)
8750936c648SBjoern A. Zeeb ieee80211_free_node(nim);
8760936c648SBjoern A. Zeeb m_freem(m);
8770936c648SBjoern A. Zeeb m = mbufq_dequeue(&lsta->txq);
8780936c648SBjoern A. Zeeb }
8790936c648SBjoern A. Zeeb KASSERT(mbufq_empty(&lsta->txq), ("%s: lsta %p has txq len %d != 0\n",
8800936c648SBjoern A. Zeeb __func__, lsta, mbufq_len(&lsta->txq)));
881fa4e4257SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_LOCK_DESTROY(lsta);
8820936c648SBjoern A. Zeeb
8830936c648SBjoern A. Zeeb /* Remove lsta from vif; that is done by the state machine. Should assert it? */
8840936c648SBjoern A. Zeeb
8850936c648SBjoern A. Zeeb IMPROVE("Make sure everything is cleaned up.");
8860936c648SBjoern A. Zeeb
8870936c648SBjoern A. Zeeb /* Free lsta. */
8880936c648SBjoern A. Zeeb lsta->ni = NULL;
8890936c648SBjoern A. Zeeb ni->ni_drv_data = NULL;
8900936c648SBjoern A. Zeeb free(lsta, M_LKPI80211);
8910936c648SBjoern A. Zeeb }
8920936c648SBjoern A. Zeeb
8930936c648SBjoern A. Zeeb
8946b4cac81SBjoern A. Zeeb static enum nl80211_band
lkpi_net80211_chan_to_nl80211_band(struct ieee80211_channel * c)8956b4cac81SBjoern A. Zeeb lkpi_net80211_chan_to_nl80211_band(struct ieee80211_channel *c)
8966b4cac81SBjoern A. Zeeb {
8976b4cac81SBjoern A. Zeeb
8986b4cac81SBjoern A. Zeeb if (IEEE80211_IS_CHAN_2GHZ(c))
8996b4cac81SBjoern A. Zeeb return (NL80211_BAND_2GHZ);
9006b4cac81SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_5GHZ(c))
9016b4cac81SBjoern A. Zeeb return (NL80211_BAND_5GHZ);
9026b4cac81SBjoern A. Zeeb #ifdef __notyet__
9036b4cac81SBjoern A. Zeeb else if ()
9046b4cac81SBjoern A. Zeeb return (NL80211_BAND_6GHZ);
9056b4cac81SBjoern A. Zeeb else if ()
9066b4cac81SBjoern A. Zeeb return (NL80211_BAND_60GHZ);
9076b4cac81SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_GSM(c))
9086b4cac81SBjoern A. Zeeb return (NL80211_BAND_XXX);
9096b4cac81SBjoern A. Zeeb #endif
9106b4cac81SBjoern A. Zeeb else
9116b4cac81SBjoern A. Zeeb panic("%s: unsupported band. c %p flags %#x\n",
9126b4cac81SBjoern A. Zeeb __func__, c, c->ic_flags);
9136b4cac81SBjoern A. Zeeb }
9146b4cac81SBjoern A. Zeeb
9156b4cac81SBjoern A. Zeeb static uint32_t
lkpi_nl80211_band_to_net80211_band(enum nl80211_band band)9166b4cac81SBjoern A. Zeeb lkpi_nl80211_band_to_net80211_band(enum nl80211_band band)
9176b4cac81SBjoern A. Zeeb {
9186b4cac81SBjoern A. Zeeb
9196b4cac81SBjoern A. Zeeb /* XXX-BZ this is just silly; net80211 is too convoluted. */
9206b4cac81SBjoern A. Zeeb /* IEEE80211_CHAN_A / _G / .. doesn't really work either. */
9216b4cac81SBjoern A. Zeeb switch (band) {
9226b4cac81SBjoern A. Zeeb case NL80211_BAND_2GHZ:
9236b4cac81SBjoern A. Zeeb return (IEEE80211_CHAN_2GHZ);
9246b4cac81SBjoern A. Zeeb break;
9256b4cac81SBjoern A. Zeeb case NL80211_BAND_5GHZ:
9266b4cac81SBjoern A. Zeeb return (IEEE80211_CHAN_5GHZ);
9276b4cac81SBjoern A. Zeeb break;
9286b4cac81SBjoern A. Zeeb case NL80211_BAND_60GHZ:
9296b4cac81SBjoern A. Zeeb break;
9306b4cac81SBjoern A. Zeeb case NL80211_BAND_6GHZ:
9316b4cac81SBjoern A. Zeeb break;
9326b4cac81SBjoern A. Zeeb default:
9336b4cac81SBjoern A. Zeeb panic("%s: unsupported band %u\n", __func__, band);
9346b4cac81SBjoern A. Zeeb break;
9356b4cac81SBjoern A. Zeeb }
9366b4cac81SBjoern A. Zeeb
9376b4cac81SBjoern A. Zeeb IMPROVE();
9386b4cac81SBjoern A. Zeeb return (0x00);
9396b4cac81SBjoern A. Zeeb }
9406b4cac81SBjoern A. Zeeb
941e3a0b120SBjoern A. Zeeb #if 0
9426b4cac81SBjoern A. Zeeb static enum ieee80211_ac_numbers
9436b4cac81SBjoern A. Zeeb lkpi_ac_net_to_l80211(int ac)
9446b4cac81SBjoern A. Zeeb {
9456b4cac81SBjoern A. Zeeb
9466b4cac81SBjoern A. Zeeb switch (ac) {
9476b4cac81SBjoern A. Zeeb case WME_AC_VO:
9486b4cac81SBjoern A. Zeeb return (IEEE80211_AC_VO);
9496b4cac81SBjoern A. Zeeb case WME_AC_VI:
9506b4cac81SBjoern A. Zeeb return (IEEE80211_AC_VI);
9516b4cac81SBjoern A. Zeeb case WME_AC_BE:
9526b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BE);
9536b4cac81SBjoern A. Zeeb case WME_AC_BK:
9546b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BK);
9556b4cac81SBjoern A. Zeeb default:
9566b4cac81SBjoern A. Zeeb printf("%s: invalid WME_AC_* input: ac = %d\n", __func__, ac);
9576b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BE);
9586b4cac81SBjoern A. Zeeb }
9596b4cac81SBjoern A. Zeeb }
960e3a0b120SBjoern A. Zeeb #endif
9616b4cac81SBjoern A. Zeeb
9626b4cac81SBjoern A. Zeeb static enum nl80211_iftype
lkpi_opmode_to_vif_type(enum ieee80211_opmode opmode)9636b4cac81SBjoern A. Zeeb lkpi_opmode_to_vif_type(enum ieee80211_opmode opmode)
9646b4cac81SBjoern A. Zeeb {
9656b4cac81SBjoern A. Zeeb
9666b4cac81SBjoern A. Zeeb switch (opmode) {
9676b4cac81SBjoern A. Zeeb case IEEE80211_M_IBSS:
9686b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_ADHOC);
9696b4cac81SBjoern A. Zeeb break;
9706b4cac81SBjoern A. Zeeb case IEEE80211_M_STA:
9716b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_STATION);
9726b4cac81SBjoern A. Zeeb break;
9736b4cac81SBjoern A. Zeeb case IEEE80211_M_WDS:
9746b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_WDS);
9756b4cac81SBjoern A. Zeeb break;
9766b4cac81SBjoern A. Zeeb case IEEE80211_M_HOSTAP:
9776b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_AP);
9786b4cac81SBjoern A. Zeeb break;
9796b4cac81SBjoern A. Zeeb case IEEE80211_M_MONITOR:
9806b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_MONITOR);
9816b4cac81SBjoern A. Zeeb break;
9826b4cac81SBjoern A. Zeeb case IEEE80211_M_MBSS:
9836b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_MESH_POINT);
9846b4cac81SBjoern A. Zeeb break;
9856b4cac81SBjoern A. Zeeb case IEEE80211_M_AHDEMO:
9866b4cac81SBjoern A. Zeeb /* FALLTHROUGH */
9876b4cac81SBjoern A. Zeeb default:
9886b4cac81SBjoern A. Zeeb printf("ERROR: %s: unsupported opmode %d\n", __func__, opmode);
9896b4cac81SBjoern A. Zeeb /* FALLTHROUGH */
9906b4cac81SBjoern A. Zeeb }
9916b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_UNSPECIFIED);
9926b4cac81SBjoern A. Zeeb }
9936b4cac81SBjoern A. Zeeb
994b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO
99512a511c8SBjoern A. Zeeb static const char *
lkpi_cipher_suite_to_name(uint32_t wlan_cipher_suite)99612a511c8SBjoern A. Zeeb lkpi_cipher_suite_to_name(uint32_t wlan_cipher_suite)
99712a511c8SBjoern A. Zeeb {
99812a511c8SBjoern A. Zeeb switch (wlan_cipher_suite) {
99912a511c8SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP40:
100012a511c8SBjoern A. Zeeb return ("WEP40");
1001bf8c25f1SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP104:
1002bf8c25f1SBjoern A. Zeeb return ("WEP104");
100312a511c8SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP:
100412a511c8SBjoern A. Zeeb return ("TKIP");
100512a511c8SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP:
100612a511c8SBjoern A. Zeeb return ("CCMP");
1007bf8c25f1SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP_256:
1008bf8c25f1SBjoern A. Zeeb return ("CCMP_256");
100912a511c8SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP:
101012a511c8SBjoern A. Zeeb return ("GCMP");
101112a511c8SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP_256:
101212a511c8SBjoern A. Zeeb return ("GCMP_256");
1013bf8c25f1SBjoern A. Zeeb case WLAN_CIPHER_SUITE_AES_CMAC:
1014bf8c25f1SBjoern A. Zeeb return ("AES_CMAC");
1015bf8c25f1SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_CMAC_256:
1016bf8c25f1SBjoern A. Zeeb return ("BIP_CMAC_256");
101712a511c8SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_128:
101812a511c8SBjoern A. Zeeb return ("BIP_GMAC_128");
101912a511c8SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_256:
102012a511c8SBjoern A. Zeeb return ("BIP_GMAC_256");
102112a511c8SBjoern A. Zeeb default:
102212a511c8SBjoern A. Zeeb return ("??");
102312a511c8SBjoern A. Zeeb }
102412a511c8SBjoern A. Zeeb }
102512a511c8SBjoern A. Zeeb
10266b4cac81SBjoern A. Zeeb static uint32_t
lkpi_l80211_to_net80211_cyphers(struct ieee80211com * ic,uint32_t wlan_cipher_suite)1027bf8c25f1SBjoern A. Zeeb lkpi_l80211_to_net80211_cyphers(struct ieee80211com *ic,
1028bf8c25f1SBjoern A. Zeeb uint32_t wlan_cipher_suite)
10296b4cac81SBjoern A. Zeeb {
10306b4cac81SBjoern A. Zeeb switch (wlan_cipher_suite) {
10316b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP40:
10326b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_WEP);
1033bf8c25f1SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP104:
1034bf8c25f1SBjoern A. Zeeb return (IEEE80211_CRYPTO_WEP);
10356b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP:
10366b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_TKIP);
10376b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP:
1038906521f8SBjoern A. Zeeb return (IEEE80211_CRYPTO_AES_CCM);
10396b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP_256:
1040bf8c25f1SBjoern A. Zeeb return (IEEE80211_CRYPTO_AES_CCM_256);
1041bf8c25f1SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP:
1042bf8c25f1SBjoern A. Zeeb return (IEEE80211_CRYPTO_AES_GCM_128);
1043bf8c25f1SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP_256:
1044bf8c25f1SBjoern A. Zeeb return (IEEE80211_CRYPTO_AES_GCM_256);
1045bf8c25f1SBjoern A. Zeeb case WLAN_CIPHER_SUITE_AES_CMAC:
1046bf8c25f1SBjoern A. Zeeb return (IEEE80211_CRYPTO_BIP_CMAC_128);
10476b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_CMAC_256:
1048bf8c25f1SBjoern A. Zeeb return (IEEE80211_CRYPTO_BIP_CMAC_256);
1049bf8c25f1SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_128:
1050bf8c25f1SBjoern A. Zeeb return (IEEE80211_CRYPTO_BIP_GMAC_128);
1051bf8c25f1SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_256:
1052bf8c25f1SBjoern A. Zeeb return (IEEE80211_CRYPTO_BIP_GMAC_256);
10536b4cac81SBjoern A. Zeeb default:
1054bf8c25f1SBjoern A. Zeeb ic_printf(ic, "%s: unknown WLAN Cipher Suite %#08x | %u (%s)\n",
105512a511c8SBjoern A. Zeeb __func__,
105612a511c8SBjoern A. Zeeb wlan_cipher_suite >> 8, wlan_cipher_suite & 0xff,
105712a511c8SBjoern A. Zeeb lkpi_cipher_suite_to_name(wlan_cipher_suite));
10586b4cac81SBjoern A. Zeeb return (0);
10596b4cac81SBjoern A. Zeeb }
1060bf8c25f1SBjoern A. Zeeb }
10616b4cac81SBjoern A. Zeeb
10626b4cac81SBjoern A. Zeeb static uint32_t
lkpi_net80211_to_l80211_cipher_suite(uint32_t cipher,uint8_t keylen)10636b4cac81SBjoern A. Zeeb lkpi_net80211_to_l80211_cipher_suite(uint32_t cipher, uint8_t keylen)
10646b4cac81SBjoern A. Zeeb {
10656b4cac81SBjoern A. Zeeb
10666b4cac81SBjoern A. Zeeb switch (cipher) {
10676b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_WEP:
1068aaee0ed3SBjoern A. Zeeb if (keylen == (40/NBBY))
10696b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_WEP40);
1070aaee0ed3SBjoern A. Zeeb else if (keylen == (104/NBBY))
10716b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_WEP104);
1072aaee0ed3SBjoern A. Zeeb else {
1073aaee0ed3SBjoern A. Zeeb printf("%s: WEP with unsupported keylen %d\n",
1074aaee0ed3SBjoern A. Zeeb __func__, keylen * NBBY);
1075aaee0ed3SBjoern A. Zeeb return (0);
1076aaee0ed3SBjoern A. Zeeb }
10776b4cac81SBjoern A. Zeeb break;
1078bf8c25f1SBjoern A. Zeeb case IEEE80211_CIPHER_TKIP:
1079bf8c25f1SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_TKIP);
1080bf8c25f1SBjoern A. Zeeb case IEEE80211_CIPHER_AES_CCM:
1081bf8c25f1SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_CCMP);
1082bf8c25f1SBjoern A. Zeeb case IEEE80211_CIPHER_AES_CCM_256:
1083bf8c25f1SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_CCMP_256);
1084bf8c25f1SBjoern A. Zeeb case IEEE80211_CIPHER_AES_GCM_128:
1085bf8c25f1SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_GCMP);
1086bf8c25f1SBjoern A. Zeeb case IEEE80211_CIPHER_AES_GCM_256:
1087bf8c25f1SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_GCMP_256);
1088bf8c25f1SBjoern A. Zeeb case IEEE80211_CIPHER_BIP_CMAC_128:
1089bf8c25f1SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_AES_CMAC);
1090bf8c25f1SBjoern A. Zeeb case IEEE80211_CIPHER_BIP_CMAC_256:
1091bf8c25f1SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_BIP_CMAC_256);
1092bf8c25f1SBjoern A. Zeeb case IEEE80211_CIPHER_BIP_GMAC_128:
1093bf8c25f1SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_BIP_GMAC_128);
1094bf8c25f1SBjoern A. Zeeb case IEEE80211_CIPHER_BIP_GMAC_256:
1095bf8c25f1SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_BIP_GMAC_256);
1096bf8c25f1SBjoern A. Zeeb
10976b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_AES_OCB:
10986b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_TKIPMIC:
1099bf8c25f1SBjoern A. Zeeb /*
1100bf8c25f1SBjoern A. Zeeb * TKIP w/ hw MIC support
1101bf8c25f1SBjoern A. Zeeb * (gone wrong; should really be a crypto flag in net80211).
1102bf8c25f1SBjoern A. Zeeb */
11036b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_CKIP:
11046b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_NONE:
11056b4cac81SBjoern A. Zeeb printf("%s: unsupported cipher %#010x\n", __func__, cipher);
11066b4cac81SBjoern A. Zeeb break;
11076b4cac81SBjoern A. Zeeb default:
11086b4cac81SBjoern A. Zeeb printf("%s: unknown cipher %#010x\n", __func__, cipher);
11096b4cac81SBjoern A. Zeeb };
11106b4cac81SBjoern A. Zeeb return (0);
11116b4cac81SBjoern A. Zeeb }
11126b4cac81SBjoern A. Zeeb #endif
11136b4cac81SBjoern A. Zeeb
11146b4cac81SBjoern A. Zeeb #ifdef __notyet__
11156b4cac81SBjoern A. Zeeb static enum ieee80211_sta_state
lkpi_net80211_state_to_sta_state(enum ieee80211_state state)11166b4cac81SBjoern A. Zeeb lkpi_net80211_state_to_sta_state(enum ieee80211_state state)
11176b4cac81SBjoern A. Zeeb {
11186b4cac81SBjoern A. Zeeb
11196b4cac81SBjoern A. Zeeb /*
11206b4cac81SBjoern A. Zeeb * XXX-BZ The net80211 states are "try to ..", the lkpi8011 states are
11216b4cac81SBjoern A. Zeeb * "done". Also ASSOC/AUTHORIZED are both "RUN" then?
11226b4cac81SBjoern A. Zeeb */
11236b4cac81SBjoern A. Zeeb switch (state) {
11246b4cac81SBjoern A. Zeeb case IEEE80211_S_INIT:
11256b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NOTEXIST);
11266b4cac81SBjoern A. Zeeb case IEEE80211_S_SCAN:
11276b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NONE);
11286b4cac81SBjoern A. Zeeb case IEEE80211_S_AUTH:
11296b4cac81SBjoern A. Zeeb return (IEEE80211_STA_AUTH);
11306b4cac81SBjoern A. Zeeb case IEEE80211_S_ASSOC:
11316b4cac81SBjoern A. Zeeb return (IEEE80211_STA_ASSOC);
11326b4cac81SBjoern A. Zeeb case IEEE80211_S_RUN:
11336b4cac81SBjoern A. Zeeb return (IEEE80211_STA_AUTHORIZED);
11346b4cac81SBjoern A. Zeeb case IEEE80211_S_CAC:
11356b4cac81SBjoern A. Zeeb case IEEE80211_S_CSA:
11366b4cac81SBjoern A. Zeeb case IEEE80211_S_SLEEP:
11376b4cac81SBjoern A. Zeeb default:
11386b4cac81SBjoern A. Zeeb UNIMPLEMENTED;
11396b4cac81SBjoern A. Zeeb };
11406b4cac81SBjoern A. Zeeb
11416b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NOTEXIST);
11426b4cac81SBjoern A. Zeeb }
11436b4cac81SBjoern A. Zeeb #endif
11446b4cac81SBjoern A. Zeeb
11456b4cac81SBjoern A. Zeeb static struct linuxkpi_ieee80211_channel *
lkpi_find_lkpi80211_chan(struct lkpi_hw * lhw,struct ieee80211_channel * c)11466b4cac81SBjoern A. Zeeb lkpi_find_lkpi80211_chan(struct lkpi_hw *lhw,
11476b4cac81SBjoern A. Zeeb struct ieee80211_channel *c)
11486b4cac81SBjoern A. Zeeb {
11496b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw;
11506b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels;
11516b4cac81SBjoern A. Zeeb enum nl80211_band band;
11526b4cac81SBjoern A. Zeeb int i, nchans;
11536b4cac81SBjoern A. Zeeb
11546b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
11556b4cac81SBjoern A. Zeeb band = lkpi_net80211_chan_to_nl80211_band(c);
11566b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[band] == NULL)
11576b4cac81SBjoern A. Zeeb return (NULL);
11586b4cac81SBjoern A. Zeeb
11596b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[band]->n_channels;
11606b4cac81SBjoern A. Zeeb if (nchans <= 0)
11616b4cac81SBjoern A. Zeeb return (NULL);
11626b4cac81SBjoern A. Zeeb
11636b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[band]->channels;
11646b4cac81SBjoern A. Zeeb for (i = 0; i < nchans; i++) {
11656b4cac81SBjoern A. Zeeb if (channels[i].hw_value == c->ic_ieee)
11666b4cac81SBjoern A. Zeeb return (&channels[i]);
11676b4cac81SBjoern A. Zeeb }
11686b4cac81SBjoern A. Zeeb
11696b4cac81SBjoern A. Zeeb return (NULL);
11706b4cac81SBjoern A. Zeeb }
11716b4cac81SBjoern A. Zeeb
11722ac8a218SBjoern A. Zeeb #if 0
11736b4cac81SBjoern A. Zeeb static struct linuxkpi_ieee80211_channel *
11746b4cac81SBjoern A. Zeeb lkpi_get_lkpi80211_chan(struct ieee80211com *ic, struct ieee80211_node *ni)
11756b4cac81SBjoern A. Zeeb {
11766b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan;
11776b4cac81SBjoern A. Zeeb struct ieee80211_channel *c;
11786b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
11796b4cac81SBjoern A. Zeeb
11806b4cac81SBjoern A. Zeeb chan = NULL;
11816b4cac81SBjoern A. Zeeb if (ni != NULL && ni->ni_chan != IEEE80211_CHAN_ANYC)
11826b4cac81SBjoern A. Zeeb c = ni->ni_chan;
11836b4cac81SBjoern A. Zeeb else if (ic->ic_bsschan != IEEE80211_CHAN_ANYC)
11846b4cac81SBjoern A. Zeeb c = ic->ic_bsschan;
11856b4cac81SBjoern A. Zeeb else if (ic->ic_curchan != IEEE80211_CHAN_ANYC)
11866b4cac81SBjoern A. Zeeb c = ic->ic_curchan;
11876b4cac81SBjoern A. Zeeb else
11886b4cac81SBjoern A. Zeeb c = NULL;
11896b4cac81SBjoern A. Zeeb
11906b4cac81SBjoern A. Zeeb if (c != NULL && c != IEEE80211_CHAN_ANYC) {
11916b4cac81SBjoern A. Zeeb lhw = ic->ic_softc;
11926b4cac81SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, c);
11936b4cac81SBjoern A. Zeeb }
11946b4cac81SBjoern A. Zeeb
11956b4cac81SBjoern A. Zeeb return (chan);
11966b4cac81SBjoern A. Zeeb }
11972ac8a218SBjoern A. Zeeb #endif
11986b4cac81SBjoern A. Zeeb
11992e183d99SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *
linuxkpi_ieee80211_get_channel(struct wiphy * wiphy,uint32_t freq)12002e183d99SBjoern A. Zeeb linuxkpi_ieee80211_get_channel(struct wiphy *wiphy, uint32_t freq)
12012e183d99SBjoern A. Zeeb {
12022e183d99SBjoern A. Zeeb enum nl80211_band band;
12032e183d99SBjoern A. Zeeb
12042e183d99SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) {
12052e183d99SBjoern A. Zeeb struct ieee80211_supported_band *supband;
12062e183d99SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels;
12072e183d99SBjoern A. Zeeb int i;
12082e183d99SBjoern A. Zeeb
12092e183d99SBjoern A. Zeeb supband = wiphy->bands[band];
12102e183d99SBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0)
12112e183d99SBjoern A. Zeeb continue;
12122e183d99SBjoern A. Zeeb
12132e183d99SBjoern A. Zeeb channels = supband->channels;
12142e183d99SBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) {
12152e183d99SBjoern A. Zeeb if (channels[i].center_freq == freq)
12162e183d99SBjoern A. Zeeb return (&channels[i]);
12172e183d99SBjoern A. Zeeb }
12182e183d99SBjoern A. Zeeb }
12192e183d99SBjoern A. Zeeb
12202e183d99SBjoern A. Zeeb return (NULL);
12212e183d99SBjoern A. Zeeb }
12222e183d99SBjoern A. Zeeb
1223b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO
12246b4cac81SBjoern A. Zeeb static int
lkpi_sta_del_keys(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct lkpi_sta * lsta)122511db70b6SBjoern A. Zeeb lkpi_sta_del_keys(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
122611db70b6SBjoern A. Zeeb struct lkpi_sta *lsta)
122711db70b6SBjoern A. Zeeb {
122811db70b6SBjoern A. Zeeb int error;
122911db70b6SBjoern A. Zeeb
123011db70b6SBjoern A. Zeeb if (!lkpi_hwcrypto)
123111db70b6SBjoern A. Zeeb return (0);
123211db70b6SBjoern A. Zeeb
123311db70b6SBjoern A. Zeeb lockdep_assert_wiphy(hw->wiphy);
123411db70b6SBjoern A. Zeeb ieee80211_ref_node(lsta->ni);
123511db70b6SBjoern A. Zeeb
123611db70b6SBjoern A. Zeeb error = 0;
123711db70b6SBjoern A. Zeeb for (ieee80211_keyix keyix = 0; keyix < nitems(lsta->kc); keyix++) {
123811db70b6SBjoern A. Zeeb struct ieee80211_key_conf *kc;
123911db70b6SBjoern A. Zeeb int err;
124011db70b6SBjoern A. Zeeb
124111db70b6SBjoern A. Zeeb if (lsta->kc[keyix] == NULL)
124211db70b6SBjoern A. Zeeb continue;
124311db70b6SBjoern A. Zeeb kc = lsta->kc[keyix];
124411db70b6SBjoern A. Zeeb
1245a6f6329cSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
1246a6f6329cSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO)
124780386ed9SBjoern A. Zeeb ic_printf(lsta->ni->ni_ic, "%d %lu %s: running set_key cmd %d(%s) for "
1248a6f6329cSBjoern A. Zeeb "sta %6D: keyidx %u hw_key_idx %u flags %b\n",
124980386ed9SBjoern A. Zeeb curthread->td_tid, jiffies, __func__,
125080386ed9SBjoern A. Zeeb DISABLE_KEY, "DISABLE", lsta->sta.addr, ":",
1251a6f6329cSBjoern A. Zeeb kc->keyidx, kc->hw_key_idx, kc->flags, IEEE80211_KEY_FLAG_BITS);
1252a6f6329cSBjoern A. Zeeb #endif
1253a6f6329cSBjoern A. Zeeb
125411db70b6SBjoern A. Zeeb err = lkpi_80211_mo_set_key(hw, DISABLE_KEY, vif,
125511db70b6SBjoern A. Zeeb LSTA_TO_STA(lsta), kc);
125611db70b6SBjoern A. Zeeb if (err != 0) {
125780386ed9SBjoern A. Zeeb ic_printf(lsta->ni->ni_ic, "%d %lu %s: set_key cmd %d(%s) for "
125880386ed9SBjoern A. Zeeb "sta %6D failed: %d\n", curthread->td_tid, jiffies, __func__,
125980386ed9SBjoern A. Zeeb DISABLE_KEY, "DISABLE", lsta->sta.addr, ":", err);
126011db70b6SBjoern A. Zeeb error++;
126111db70b6SBjoern A. Zeeb
126211db70b6SBjoern A. Zeeb /*
126311db70b6SBjoern A. Zeeb * If we free the key here we will never be able to get it
126411db70b6SBjoern A. Zeeb * removed from the driver/fw which will likely make us
126511db70b6SBjoern A. Zeeb * crash (firmware).
126611db70b6SBjoern A. Zeeb */
126711db70b6SBjoern A. Zeeb continue;
126811db70b6SBjoern A. Zeeb }
126911db70b6SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
127011db70b6SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO)
127180386ed9SBjoern A. Zeeb ic_printf(lsta->ni->ni_ic, "%d %lu %s: set_key cmd %d(%s) for "
1272a6f6329cSBjoern A. Zeeb "sta %6D succeeded: keyidx %u hw_key_idx %u flags %b\n",
127380386ed9SBjoern A. Zeeb curthread->td_tid, jiffies, __func__,
127480386ed9SBjoern A. Zeeb DISABLE_KEY, "DISABLE", lsta->sta.addr, ":",
1275a6f6329cSBjoern A. Zeeb kc->keyidx, kc->hw_key_idx, kc->flags, IEEE80211_KEY_FLAG_BITS);
127611db70b6SBjoern A. Zeeb #endif
127711db70b6SBjoern A. Zeeb
127811db70b6SBjoern A. Zeeb lsta->kc[keyix] = NULL;
127911db70b6SBjoern A. Zeeb free(kc, M_LKPI80211);
128011db70b6SBjoern A. Zeeb }
128111db70b6SBjoern A. Zeeb ieee80211_free_node(lsta->ni);
128211db70b6SBjoern A. Zeeb return (error);
128311db70b6SBjoern A. Zeeb }
128411db70b6SBjoern A. Zeeb
1285aa294e8eSBjoern A. Zeeb /* XXX-BZ one day we should replace this iterating over VIFs, or node list? */
1286aa294e8eSBjoern A. Zeeb /* See also lkpi_sta_del_keys() these days. */
128711db70b6SBjoern A. Zeeb static int
lkpi_iv_key_delete(struct ieee80211vap * vap,const struct ieee80211_key * k)1288aa294e8eSBjoern A. Zeeb lkpi_iv_key_delete(struct ieee80211vap *vap, const struct ieee80211_key *k)
12896b4cac81SBjoern A. Zeeb {
12906b4cac81SBjoern A. Zeeb struct ieee80211com *ic;
12916b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
12926b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw;
12936b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
129411db70b6SBjoern A. Zeeb struct lkpi_sta *lsta;
12956b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif;
12966b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta;
12976b4cac81SBjoern A. Zeeb struct ieee80211_node *ni;
12986b4cac81SBjoern A. Zeeb struct ieee80211_key_conf *kc;
12996b4cac81SBjoern A. Zeeb int error;
13006b4cac81SBjoern A. Zeeb
13016b4cac81SBjoern A. Zeeb ic = vap->iv_ic;
1302284af342SBjoern A. Zeeb lhw = ic->ic_softc;
1303284af342SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
1304284af342SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
1305284af342SBjoern A. Zeeb
1306284af342SBjoern A. Zeeb /*
1307284af342SBjoern A. Zeeb * Make sure we do not make it here without going through
1308284af342SBjoern A. Zeeb * lkpi_iv_key_update_begin() first.
1309284af342SBjoern A. Zeeb */
1310284af342SBjoern A. Zeeb lockdep_assert_wiphy(hw->wiphy);
1311284af342SBjoern A. Zeeb
1312a6f6329cSBjoern A. Zeeb if (IEEE80211_KEY_UNDEFINED(k)) {
1313a6f6329cSBjoern A. Zeeb ic_printf(ic, "%s: vap %p key %p is undefined: %p %u\n",
1314a6f6329cSBjoern A. Zeeb __func__, vap, k, k->wk_cipher, k->wk_keyix);
1315a6f6329cSBjoern A. Zeeb return (0);
1316a6f6329cSBjoern A. Zeeb }
13176b4cac81SBjoern A. Zeeb
131811db70b6SBjoern A. Zeeb if (vap->iv_bss == NULL) {
131911db70b6SBjoern A. Zeeb ic_printf(ic, "%s: iv_bss %p for vap %p is NULL\n",
132011db70b6SBjoern A. Zeeb __func__, vap->iv_bss, vap);
132111db70b6SBjoern A. Zeeb return (0);
132211db70b6SBjoern A. Zeeb }
1323a6f6329cSBjoern A. Zeeb
132411db70b6SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss);
132511db70b6SBjoern A. Zeeb lsta = ni->ni_drv_data;
132611db70b6SBjoern A. Zeeb if (lsta == NULL) {
132711db70b6SBjoern A. Zeeb ic_printf(ic, "%s: ni %p (%6D) with lsta NULL\n",
132811db70b6SBjoern A. Zeeb __func__, ni, ni->ni_bssid, ":");
132911db70b6SBjoern A. Zeeb ieee80211_free_node(ni);
133011db70b6SBjoern A. Zeeb return (0);
133111db70b6SBjoern A. Zeeb }
133211db70b6SBjoern A. Zeeb sta = LSTA_TO_STA(lsta);
133311db70b6SBjoern A. Zeeb
133411db70b6SBjoern A. Zeeb if (lsta->kc[k->wk_keyix] == NULL) {
133511db70b6SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
133611db70b6SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO)
133780386ed9SBjoern A. Zeeb ic_printf(ic, "%d %lu %s: sta %6D and no key information, "
133811db70b6SBjoern A. Zeeb "keyidx %u wk_macaddr %6D; returning success\n",
133980386ed9SBjoern A. Zeeb curthread->td_tid, jiffies, __func__, sta->addr, ":",
134011db70b6SBjoern A. Zeeb k->wk_keyix, k->wk_macaddr, ":");
134111db70b6SBjoern A. Zeeb #endif
134211db70b6SBjoern A. Zeeb ieee80211_free_node(ni);
134311db70b6SBjoern A. Zeeb return (1);
134411db70b6SBjoern A. Zeeb }
134511db70b6SBjoern A. Zeeb kc = lsta->kc[k->wk_keyix];
134611db70b6SBjoern A. Zeeb
1347a6f6329cSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
1348a6f6329cSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO)
134980386ed9SBjoern A. Zeeb ic_printf(ic, "%d %lu %s: running set_key cmd %d(%s) for sta %6D: "
135080386ed9SBjoern A. Zeeb "keyidx %u hw_key_idx %u flags %b\n",
135180386ed9SBjoern A. Zeeb curthread->td_tid, jiffies, __func__,
1352a6f6329cSBjoern A. Zeeb DISABLE_KEY, "DISABLE", sta->addr, ":",
1353a6f6329cSBjoern A. Zeeb kc->keyidx, kc->hw_key_idx, kc->flags, IEEE80211_KEY_FLAG_BITS);
1354a6f6329cSBjoern A. Zeeb #endif
1355a6f6329cSBjoern A. Zeeb
1356a6f6329cSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
135711db70b6SBjoern A. Zeeb error = lkpi_80211_mo_set_key(hw, DISABLE_KEY, vif, sta, kc);
135811db70b6SBjoern A. Zeeb if (error != 0) {
135980386ed9SBjoern A. Zeeb ic_printf(ic, "%d %lu %s: set_key cmd %d(%s) for sta %6D failed: %d\n",
136080386ed9SBjoern A. Zeeb curthread->td_tid, jiffies, __func__,
136180386ed9SBjoern A. Zeeb DISABLE_KEY, "DISABLE", sta->addr, ":", error);
136211db70b6SBjoern A. Zeeb error = 0;
136311db70b6SBjoern A. Zeeb goto out;
136411db70b6SBjoern A. Zeeb }
136511db70b6SBjoern A. Zeeb
136611db70b6SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
136711db70b6SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO)
136880386ed9SBjoern A. Zeeb ic_printf(ic, "%d %lu %s: set_key cmd %d(%s) for sta %6D succeeded: "
136980386ed9SBjoern A. Zeeb "keyidx %u hw_key_idx %u flags %b\n",
137080386ed9SBjoern A. Zeeb curthread->td_tid, jiffies, __func__,
137111db70b6SBjoern A. Zeeb DISABLE_KEY, "DISABLE", sta->addr, ":",
1372a6f6329cSBjoern A. Zeeb kc->keyidx, kc->hw_key_idx, kc->flags, IEEE80211_KEY_FLAG_BITS);
137311db70b6SBjoern A. Zeeb #endif
137411db70b6SBjoern A. Zeeb lsta->kc[k->wk_keyix] = NULL;
137511db70b6SBjoern A. Zeeb free(kc, M_LKPI80211);
137611db70b6SBjoern A. Zeeb error = 1;
137711db70b6SBjoern A. Zeeb out:
137811db70b6SBjoern A. Zeeb ieee80211_free_node(ni);
137911db70b6SBjoern A. Zeeb return (error);
138011db70b6SBjoern A. Zeeb }
138111db70b6SBjoern A. Zeeb
138211db70b6SBjoern A. Zeeb static int
lkpi_iv_key_set(struct ieee80211vap * vap,const struct ieee80211_key * k)1383aa294e8eSBjoern A. Zeeb lkpi_iv_key_set(struct ieee80211vap *vap, const struct ieee80211_key *k)
138411db70b6SBjoern A. Zeeb {
138511db70b6SBjoern A. Zeeb struct ieee80211com *ic;
138611db70b6SBjoern A. Zeeb struct lkpi_hw *lhw;
138711db70b6SBjoern A. Zeeb struct ieee80211_hw *hw;
138811db70b6SBjoern A. Zeeb struct lkpi_vif *lvif;
138911db70b6SBjoern A. Zeeb struct lkpi_sta *lsta;
139011db70b6SBjoern A. Zeeb struct ieee80211_vif *vif;
139111db70b6SBjoern A. Zeeb struct ieee80211_sta *sta;
139211db70b6SBjoern A. Zeeb struct ieee80211_node *ni;
139311db70b6SBjoern A. Zeeb struct ieee80211_key_conf *kc;
139411db70b6SBjoern A. Zeeb uint32_t lcipher;
139592942717SBjoern A. Zeeb uint16_t exp_flags;
13964b9ae864SBjoern A. Zeeb uint8_t keylen;
139711db70b6SBjoern A. Zeeb int error;
139811db70b6SBjoern A. Zeeb
139911db70b6SBjoern A. Zeeb ic = vap->iv_ic;
1400284af342SBjoern A. Zeeb lhw = ic->ic_softc;
1401284af342SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
1402284af342SBjoern A. Zeeb
1403284af342SBjoern A. Zeeb /*
1404284af342SBjoern A. Zeeb * Make sure we do not make it here without going through
1405284af342SBjoern A. Zeeb * lkpi_iv_key_update_begin() first.
1406284af342SBjoern A. Zeeb */
1407284af342SBjoern A. Zeeb lockdep_assert_wiphy(hw->wiphy);
1408284af342SBjoern A. Zeeb
1409a6f6329cSBjoern A. Zeeb if (IEEE80211_KEY_UNDEFINED(k)) {
1410a6f6329cSBjoern A. Zeeb ic_printf(ic, "%s: vap %p key %p is undefined: %p %u\n",
1411a6f6329cSBjoern A. Zeeb __func__, vap, k, k->wk_cipher, k->wk_keyix);
1412a6f6329cSBjoern A. Zeeb return (0);
1413a6f6329cSBjoern A. Zeeb }
141411db70b6SBjoern A. Zeeb
141511db70b6SBjoern A. Zeeb if (vap->iv_bss == NULL) {
141611db70b6SBjoern A. Zeeb ic_printf(ic, "%s: iv_bss %p for vap %p is NULL\n",
141711db70b6SBjoern A. Zeeb __func__, vap->iv_bss, vap);
141811db70b6SBjoern A. Zeeb return (0);
141911db70b6SBjoern A. Zeeb }
142011db70b6SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss);
142111db70b6SBjoern A. Zeeb lsta = ni->ni_drv_data;
142211db70b6SBjoern A. Zeeb if (lsta == NULL) {
142311db70b6SBjoern A. Zeeb ic_printf(ic, "%s: ni %p (%6D) with lsta NULL\n",
142411db70b6SBjoern A. Zeeb __func__, ni, ni->ni_bssid, ":");
142511db70b6SBjoern A. Zeeb ieee80211_free_node(ni);
142611db70b6SBjoern A. Zeeb return (0);
142711db70b6SBjoern A. Zeeb }
142811db70b6SBjoern A. Zeeb sta = LSTA_TO_STA(lsta);
142911db70b6SBjoern A. Zeeb
14304b9ae864SBjoern A. Zeeb keylen = k->wk_keylen;
14314b9ae864SBjoern A. Zeeb lcipher = lkpi_net80211_to_l80211_cipher_suite(
14324b9ae864SBjoern A. Zeeb k->wk_cipher->ic_cipher, k->wk_keylen);
14334b9ae864SBjoern A. Zeeb switch (lcipher) {
14344b9ae864SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP:
14354b9ae864SBjoern A. Zeeb keylen += 2 * k->wk_cipher->ic_miclen;
14364b9ae864SBjoern A. Zeeb break;
143729ddd583SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP:
143829ddd583SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP:
143929ddd583SBjoern A. Zeeb break;
14404b9ae864SBjoern A. Zeeb default:
14414b9ae864SBjoern A. Zeeb ic_printf(ic, "%s: CIPHER SUITE %#x (%s) not supported\n",
14424b9ae864SBjoern A. Zeeb __func__, lcipher, lkpi_cipher_suite_to_name(lcipher));
14434b9ae864SBjoern A. Zeeb IMPROVE();
14444b9ae864SBjoern A. Zeeb ieee80211_free_node(ni);
14454b9ae864SBjoern A. Zeeb return (0);
14464b9ae864SBjoern A. Zeeb }
14474b9ae864SBjoern A. Zeeb
144811db70b6SBjoern A. Zeeb if (lsta->kc[k->wk_keyix] != NULL) {
144911db70b6SBjoern A. Zeeb IMPROVE("Still in firmware? Del first. Can we assert this cannot happen?");
145011db70b6SBjoern A. Zeeb ic_printf(ic, "%s: sta %6D found with key information\n",
145111db70b6SBjoern A. Zeeb __func__, sta->addr, ":");
145211db70b6SBjoern A. Zeeb kc = lsta->kc[k->wk_keyix];
145311db70b6SBjoern A. Zeeb lsta->kc[k->wk_keyix] = NULL;
145411db70b6SBjoern A. Zeeb free(kc, M_LKPI80211);
145511db70b6SBjoern A. Zeeb kc = NULL; /* safeguard */
145611db70b6SBjoern A. Zeeb }
145711db70b6SBjoern A. Zeeb
14584b9ae864SBjoern A. Zeeb kc = malloc(sizeof(*kc) + keylen, M_LKPI80211, M_WAITOK | M_ZERO);
145911db70b6SBjoern A. Zeeb kc->_k = k; /* Save the pointer to net80211. */
146011db70b6SBjoern A. Zeeb kc->cipher = lcipher;
14616b4cac81SBjoern A. Zeeb kc->keyidx = k->wk_keyix;
14626b4cac81SBjoern A. Zeeb #if 0
14636b4cac81SBjoern A. Zeeb kc->hw_key_idx = /* set by hw and needs to be passed for TX */;
14646b4cac81SBjoern A. Zeeb #endif
14656b4cac81SBjoern A. Zeeb atomic64_set(&kc->tx_pn, k->wk_keytsc);
14666b4cac81SBjoern A. Zeeb kc->keylen = k->wk_keylen;
14676b4cac81SBjoern A. Zeeb memcpy(kc->key, k->wk_key, k->wk_keylen);
14686b4cac81SBjoern A. Zeeb
146911db70b6SBjoern A. Zeeb if (k->wk_flags & (IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV))
147011db70b6SBjoern A. Zeeb kc->flags |= IEEE80211_KEY_FLAG_PAIRWISE;
147111db70b6SBjoern A. Zeeb if (k->wk_flags & IEEE80211_KEY_GROUP)
147211db70b6SBjoern A. Zeeb kc->flags &= ~IEEE80211_KEY_FLAG_PAIRWISE;
147311db70b6SBjoern A. Zeeb
14746b4cac81SBjoern A. Zeeb kc->iv_len = k->wk_cipher->ic_header;
14756b4cac81SBjoern A. Zeeb kc->icv_len = k->wk_cipher->ic_trailer;
147629ddd583SBjoern A. Zeeb
147729ddd583SBjoern A. Zeeb switch (kc->cipher) {
14786b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP:
14794b9ae864SBjoern A. Zeeb memcpy(kc->key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY, k->wk_txmic, k->wk_cipher->ic_miclen);
14804b9ae864SBjoern A. Zeeb memcpy(kc->key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY, k->wk_rxmic, k->wk_cipher->ic_miclen);
148129ddd583SBjoern A. Zeeb break;
148229ddd583SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP:
148329ddd583SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP:
148492942717SBjoern A. Zeeb break;
14856b4cac81SBjoern A. Zeeb default:
148611db70b6SBjoern A. Zeeb /* currently UNREACH */
14876b4cac81SBjoern A. Zeeb IMPROVE();
148811db70b6SBjoern A. Zeeb break;
14896b4cac81SBjoern A. Zeeb };
149011db70b6SBjoern A. Zeeb lsta->kc[k->wk_keyix] = kc;
14916b4cac81SBjoern A. Zeeb
1492a6f6329cSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
1493a6f6329cSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO)
149480386ed9SBjoern A. Zeeb ic_printf(ic, "%d %lu %s: running set_key cmd %d(%s) for sta %6D: "
149580386ed9SBjoern A. Zeeb "kc %p keyidx %u hw_key_idx %u keylen %u flags %b\n",
149680386ed9SBjoern A. Zeeb curthread->td_tid, jiffies, __func__,
14974b9ae864SBjoern A. Zeeb SET_KEY, "SET", sta->addr, ":", kc, kc->keyidx, kc->hw_key_idx,
14984b9ae864SBjoern A. Zeeb kc->keylen, kc->flags, IEEE80211_KEY_FLAG_BITS);
1499a6f6329cSBjoern A. Zeeb #endif
1500a6f6329cSBjoern A. Zeeb
1501a6f6329cSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
1502a6f6329cSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
150311db70b6SBjoern A. Zeeb error = lkpi_80211_mo_set_key(hw, SET_KEY, vif, sta, kc);
150411db70b6SBjoern A. Zeeb if (error != 0) {
150580386ed9SBjoern A. Zeeb ic_printf(ic, "%d %lu %s: set_key cmd %d(%s) for sta %6D failed: %d\n",
150680386ed9SBjoern A. Zeeb curthread->td_tid, jiffies, __func__,
150780386ed9SBjoern A. Zeeb SET_KEY, "SET", sta->addr, ":", error);
150811db70b6SBjoern A. Zeeb lsta->kc[k->wk_keyix] = NULL;
150911db70b6SBjoern A. Zeeb free(kc, M_LKPI80211);
151011db70b6SBjoern A. Zeeb ieee80211_free_node(ni);
151111db70b6SBjoern A. Zeeb return (0);
15126b4cac81SBjoern A. Zeeb }
15136b4cac81SBjoern A. Zeeb
151411db70b6SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
151511db70b6SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO)
151680386ed9SBjoern A. Zeeb ic_printf(ic, "%d %lu %s: set_key cmd %d(%s) for sta %6D succeeded: "
151780386ed9SBjoern A. Zeeb "kc %p keyidx %u hw_key_idx %u flags %b\n",
151880386ed9SBjoern A. Zeeb curthread->td_tid, jiffies, __func__,
151911db70b6SBjoern A. Zeeb SET_KEY, "SET", sta->addr, ":",
1520a6f6329cSBjoern A. Zeeb kc, kc->keyidx, kc->hw_key_idx, kc->flags, IEEE80211_KEY_FLAG_BITS);
152111db70b6SBjoern A. Zeeb #endif
152211db70b6SBjoern A. Zeeb
152392942717SBjoern A. Zeeb exp_flags = 0;
152492942717SBjoern A. Zeeb switch (kc->cipher) {
152592942717SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP:
152692942717SBjoern A. Zeeb exp_flags = (IEEE80211_KEY_FLAG_PAIRWISE |
152792942717SBjoern A. Zeeb IEEE80211_KEY_FLAG_PUT_IV_SPACE |
152892942717SBjoern A. Zeeb IEEE80211_KEY_FLAG_GENERATE_MMIC |
152992942717SBjoern A. Zeeb IEEE80211_KEY_FLAG_PUT_MIC_SPACE);
153092942717SBjoern A. Zeeb #define TKIP_INVAL_COMBINATION \
153192942717SBjoern A. Zeeb (IEEE80211_KEY_FLAG_PUT_MIC_SPACE|IEEE80211_KEY_FLAG_GENERATE_MMIC)
153292942717SBjoern A. Zeeb if ((kc->flags & TKIP_INVAL_COMBINATION) == TKIP_INVAL_COMBINATION) {
153392942717SBjoern A. Zeeb ic_printf(ic, "%s: SET_KEY for %s returned invalid "
153492942717SBjoern A. Zeeb "combination %b\n", __func__,
153592942717SBjoern A. Zeeb lkpi_cipher_suite_to_name(kc->cipher),
153692942717SBjoern A. Zeeb kc->flags, IEEE80211_KEY_FLAG_BITS);
153792942717SBjoern A. Zeeb }
153892942717SBjoern A. Zeeb #undef TKIP_INVAL_COMBINATION
153992942717SBjoern A. Zeeb #ifdef __notyet__
154092942717SBjoern A. Zeeb /* Do flags surgery; special see linuxkpi_ieee80211_ifattach(). */
154192942717SBjoern A. Zeeb if ((kc->flags & IEEE80211_KEY_FLAG_GENERATE_MMIC) != 0) {
154292942717SBjoern A. Zeeb k->wk_flags &= ~(IEEE80211_KEY_NOMICMGT|IEEE80211_KEY_NOMIC);
154392942717SBjoern A. Zeeb k->wk_flags |= IEEE80211_KEY_SWMIC;
154492942717SBjoern A. Zeeb ic->ic_cryptocaps &= ~IEEE80211_CRYPTO_TKIPMIC
154592942717SBjoern A. Zeeb }
154692942717SBjoern A. Zeeb #endif
154792942717SBjoern A. Zeeb break;
154892942717SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP:
154929ddd583SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP:
155092942717SBjoern A. Zeeb exp_flags = (IEEE80211_KEY_FLAG_PAIRWISE |
155192942717SBjoern A. Zeeb IEEE80211_KEY_FLAG_PUT_IV_SPACE |
155292942717SBjoern A. Zeeb IEEE80211_KEY_FLAG_GENERATE_IV |
155391716e8dSBjoern A. Zeeb IEEE80211_KEY_FLAG_GENERATE_IV_MGMT | /* Only needs IV geeration for MGMT frames. */
155491716e8dSBjoern A. Zeeb IEEE80211_KEY_FLAG_SW_MGMT_TX); /* MFP in software */
155592942717SBjoern A. Zeeb break;
155692942717SBjoern A. Zeeb }
155792942717SBjoern A. Zeeb if ((kc->flags & ~exp_flags) != 0)
155892942717SBjoern A. Zeeb ic_printf(ic, "%s: SET_KEY for %s returned unexpected key flags: "
155992942717SBjoern A. Zeeb " %#06x & ~%#06x = %b\n", __func__,
156092942717SBjoern A. Zeeb lkpi_cipher_suite_to_name(kc->cipher), kc->flags, exp_flags,
156192942717SBjoern A. Zeeb (kc->flags & ~exp_flags), IEEE80211_KEY_FLAG_BITS);
156292942717SBjoern A. Zeeb
156392942717SBjoern A. Zeeb #ifdef __notyet__
156492942717SBjoern A. Zeeb /* Do flags surgery. */
156592942717SBjoern A. Zeeb if ((kc->flags & IEEE80211_KEY_FLAG_GENERATE_IV_MGMT) == 0)
156692942717SBjoern A. Zeeb k->wk_flags |= IEEE80211_KEY_NOIVMGT;
156792942717SBjoern A. Zeeb if ((kc->flags & IEEE80211_KEY_FLAG_GENERATE_IV) == 0)
156892942717SBjoern A. Zeeb k->wk_flags |= IEEE80211_KEY_NOIV;
156992942717SBjoern A. Zeeb #endif
157092942717SBjoern A. Zeeb
157111db70b6SBjoern A. Zeeb ieee80211_free_node(ni);
15726b4cac81SBjoern A. Zeeb return (1);
15736b4cac81SBjoern A. Zeeb }
15746b4cac81SBjoern A. Zeeb
1575b8dfc3ecSBjoern A. Zeeb static void
lkpi_iv_key_update_begin(struct ieee80211vap * vap)1576b8dfc3ecSBjoern A. Zeeb lkpi_iv_key_update_begin(struct ieee80211vap *vap)
1577b8dfc3ecSBjoern A. Zeeb {
1578b8dfc3ecSBjoern A. Zeeb struct ieee80211_node_table *nt;
1579b8dfc3ecSBjoern A. Zeeb struct ieee80211com *ic;
1580b8dfc3ecSBjoern A. Zeeb struct lkpi_hw *lhw;
1581b8dfc3ecSBjoern A. Zeeb struct ieee80211_hw *hw;
1582b8dfc3ecSBjoern A. Zeeb struct lkpi_vif *lvif;
1583a6413bceSBjoern A. Zeeb struct ieee80211_node *ni;
1584a6165709SBjoern A. Zeeb bool icislocked, ntislocked;
1585b8dfc3ecSBjoern A. Zeeb
1586b8dfc3ecSBjoern A. Zeeb ic = vap->iv_ic;
1587b8dfc3ecSBjoern A. Zeeb lhw = ic->ic_softc;
1588b8dfc3ecSBjoern A. Zeeb hw = LHW_TO_HW(lhw);
1589b8dfc3ecSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
1590b8dfc3ecSBjoern A. Zeeb nt = &ic->ic_sta;
1591b8dfc3ecSBjoern A. Zeeb
1592a6165709SBjoern A. Zeeb icislocked = IEEE80211_IS_LOCKED(ic);
1593a6165709SBjoern A. Zeeb ntislocked = IEEE80211_NODE_IS_LOCKED(nt);
1594b8dfc3ecSBjoern A. Zeeb
1595b8dfc3ecSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
1596b8dfc3ecSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO)
159780386ed9SBjoern A. Zeeb ic_printf(ic, "%d %lu %s: vap %p ic %p %slocked nt %p %slocked "
159880386ed9SBjoern A. Zeeb "lvif ic_unlocked %d nt_unlocked %d\n",
159980386ed9SBjoern A. Zeeb curthread->td_tid, jiffies, __func__, vap,
1600a6165709SBjoern A. Zeeb ic, icislocked ? "" : "un", nt, ntislocked ? "" : "un",
1601a6165709SBjoern A. Zeeb lvif->ic_unlocked, lvif->nt_unlocked);
1602b8dfc3ecSBjoern A. Zeeb #endif
1603b8dfc3ecSBjoern A. Zeeb
1604a6413bceSBjoern A. Zeeb /*
1605a6413bceSBjoern A. Zeeb * This is inconsistent net80211 locking to be fixed one day.
1606a6413bceSBjoern A. Zeeb */
1607a6413bceSBjoern A. Zeeb /* Try to make sure the node does not go away while possibly unlocked. */
1608a6413bceSBjoern A. Zeeb ni = NULL;
1609a6413bceSBjoern A. Zeeb if (icislocked || ntislocked) {
1610a6413bceSBjoern A. Zeeb if (vap->iv_bss != NULL)
1611a6413bceSBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss);
1612a6413bceSBjoern A. Zeeb }
1613a6413bceSBjoern A. Zeeb
1614a6165709SBjoern A. Zeeb if (icislocked)
1615a6165709SBjoern A. Zeeb IEEE80211_UNLOCK(ic);
1616a6165709SBjoern A. Zeeb if (ntislocked)
1617b8dfc3ecSBjoern A. Zeeb IEEE80211_NODE_UNLOCK(nt);
1618b8dfc3ecSBjoern A. Zeeb
1619b8dfc3ecSBjoern A. Zeeb wiphy_lock(hw->wiphy);
1620b8dfc3ecSBjoern A. Zeeb
1621a6413bceSBjoern A. Zeeb KASSERT(lvif->key_update_iv_bss == NULL, ("%s: key_update_iv_bss not NULL %p",
1622a6413bceSBjoern A. Zeeb __func__, lvif->key_update_iv_bss));
1623a6413bceSBjoern A. Zeeb lvif->key_update_iv_bss = ni;
1624a6413bceSBjoern A. Zeeb
1625b8dfc3ecSBjoern A. Zeeb /*
1626a6165709SBjoern A. Zeeb * ic/nt_unlocked could be a bool given we are under the lock and there
1627b8dfc3ecSBjoern A. Zeeb * must only be a single thread.
1628b8dfc3ecSBjoern A. Zeeb * In case anything in the future disturbs the order the refcnt will
1629b8dfc3ecSBjoern A. Zeeb * help us catching problems a lot easier.
1630b8dfc3ecSBjoern A. Zeeb */
1631a6165709SBjoern A. Zeeb if (icislocked)
1632a6165709SBjoern A. Zeeb refcount_acquire(&lvif->ic_unlocked);
1633a6165709SBjoern A. Zeeb if (ntislocked)
1634b8dfc3ecSBjoern A. Zeeb refcount_acquire(&lvif->nt_unlocked);
1635db480c29SBjoern A. Zeeb
1636db480c29SBjoern A. Zeeb /*
1637db480c29SBjoern A. Zeeb * Stop the queues while doing key updates.
1638db480c29SBjoern A. Zeeb */
1639db480c29SBjoern A. Zeeb ieee80211_stop_queues(hw);
1640b8dfc3ecSBjoern A. Zeeb }
1641b8dfc3ecSBjoern A. Zeeb
1642b8dfc3ecSBjoern A. Zeeb static void
lkpi_iv_key_update_end(struct ieee80211vap * vap)1643b8dfc3ecSBjoern A. Zeeb lkpi_iv_key_update_end(struct ieee80211vap *vap)
1644b8dfc3ecSBjoern A. Zeeb {
1645b8dfc3ecSBjoern A. Zeeb struct ieee80211_node_table *nt;
1646b8dfc3ecSBjoern A. Zeeb struct ieee80211com *ic;
1647b8dfc3ecSBjoern A. Zeeb struct lkpi_hw *lhw;
1648b8dfc3ecSBjoern A. Zeeb struct ieee80211_hw *hw;
1649b8dfc3ecSBjoern A. Zeeb struct lkpi_vif *lvif;
1650a6165709SBjoern A. Zeeb bool icislocked, ntislocked;
1651b8dfc3ecSBjoern A. Zeeb
1652b8dfc3ecSBjoern A. Zeeb ic = vap->iv_ic;
1653b8dfc3ecSBjoern A. Zeeb lhw = ic->ic_softc;
1654b8dfc3ecSBjoern A. Zeeb hw = LHW_TO_HW(lhw);
1655b8dfc3ecSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
1656b8dfc3ecSBjoern A. Zeeb nt = &ic->ic_sta;
1657b8dfc3ecSBjoern A. Zeeb
1658db480c29SBjoern A. Zeeb /*
1659db480c29SBjoern A. Zeeb * Re-enabled the queues after the key update.
1660db480c29SBjoern A. Zeeb */
1661db480c29SBjoern A. Zeeb lkpi_ieee80211_wake_queues_locked(hw);
1662db480c29SBjoern A. Zeeb
1663a6165709SBjoern A. Zeeb icislocked = IEEE80211_IS_LOCKED(ic);
1664a6165709SBjoern A. Zeeb MPASS(!icislocked);
1665a6165709SBjoern A. Zeeb ntislocked = IEEE80211_NODE_IS_LOCKED(nt);
1666a6165709SBjoern A. Zeeb MPASS(!ntislocked);
1667b8dfc3ecSBjoern A. Zeeb
1668b8dfc3ecSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
1669b8dfc3ecSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO)
167080386ed9SBjoern A. Zeeb ic_printf(ic, "%d %lu %s: vap %p ic %p %slocked nt %p %slocked "
167180386ed9SBjoern A. Zeeb "lvif ic_unlocked %d nt_unlocked %d\n",
167280386ed9SBjoern A. Zeeb curthread->td_tid, jiffies, __func__, vap,
1673a6165709SBjoern A. Zeeb ic, icislocked ? "" : "un", nt, ntislocked ? "" : "un",
1674a6165709SBjoern A. Zeeb lvif->ic_unlocked, lvif->nt_unlocked);
1675b8dfc3ecSBjoern A. Zeeb #endif
1676b8dfc3ecSBjoern A. Zeeb
1677b8dfc3ecSBjoern A. Zeeb /*
1678b8dfc3ecSBjoern A. Zeeb * Check under lock; see comment in lkpi_iv_key_update_begin().
1679b8dfc3ecSBjoern A. Zeeb * In case the refcnt gets out of sync locking in net80211 will
1680b8dfc3ecSBjoern A. Zeeb * quickly barf as well (trying to unlock a lock not held).
1681b8dfc3ecSBjoern A. Zeeb */
1682a6165709SBjoern A. Zeeb icislocked = refcount_release_if_last(&lvif->ic_unlocked);
1683a6165709SBjoern A. Zeeb ntislocked = refcount_release_if_last(&lvif->nt_unlocked);
1684a6413bceSBjoern A. Zeeb
1685a6413bceSBjoern A. Zeeb if (lvif->key_update_iv_bss != NULL) {
1686a6413bceSBjoern A. Zeeb ieee80211_free_node(lvif->key_update_iv_bss);
1687a6413bceSBjoern A. Zeeb lvif->key_update_iv_bss = NULL;
1688a6413bceSBjoern A. Zeeb }
1689a6413bceSBjoern A. Zeeb
1690b8dfc3ecSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
1691b8dfc3ecSBjoern A. Zeeb
1692a6165709SBjoern A. Zeeb /*
1693a6165709SBjoern A. Zeeb * This is inconsistent net80211 locking to be fixed one day.
1694a6165709SBjoern A. Zeeb * ic before nt to avoid a LOR.
1695a6165709SBjoern A. Zeeb */
1696a6165709SBjoern A. Zeeb if (icislocked)
1697a6165709SBjoern A. Zeeb IEEE80211_LOCK(ic);
1698a6165709SBjoern A. Zeeb if (ntislocked)
1699b8dfc3ecSBjoern A. Zeeb IEEE80211_NODE_LOCK(nt);
1700b8dfc3ecSBjoern A. Zeeb }
17016b4cac81SBjoern A. Zeeb #endif
17026b4cac81SBjoern A. Zeeb
17036b4cac81SBjoern A. Zeeb static u_int
lkpi_ic_update_mcast_copy(void * arg,struct sockaddr_dl * sdl,u_int cnt)17046b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast_copy(void *arg, struct sockaddr_dl *sdl, u_int cnt)
17056b4cac81SBjoern A. Zeeb {
17066b4cac81SBjoern A. Zeeb struct netdev_hw_addr_list *mc_list;
17076b4cac81SBjoern A. Zeeb struct netdev_hw_addr *addr;
17086b4cac81SBjoern A. Zeeb
17096b4cac81SBjoern A. Zeeb KASSERT(arg != NULL && sdl != NULL, ("%s: arg %p sdl %p cnt %u\n",
17106b4cac81SBjoern A. Zeeb __func__, arg, sdl, cnt));
17116b4cac81SBjoern A. Zeeb
17126b4cac81SBjoern A. Zeeb mc_list = arg;
17136b4cac81SBjoern A. Zeeb /* If it is on the list already skip it. */
17146b4cac81SBjoern A. Zeeb netdev_hw_addr_list_for_each(addr, mc_list) {
17156b4cac81SBjoern A. Zeeb if (!memcmp(addr->addr, LLADDR(sdl), sdl->sdl_alen))
17166b4cac81SBjoern A. Zeeb return (0);
17176b4cac81SBjoern A. Zeeb }
17186b4cac81SBjoern A. Zeeb
17196b4cac81SBjoern A. Zeeb addr = malloc(sizeof(*addr), M_LKPI80211, M_NOWAIT | M_ZERO);
17206b4cac81SBjoern A. Zeeb if (addr == NULL)
17216b4cac81SBjoern A. Zeeb return (0);
17226b4cac81SBjoern A. Zeeb
17236b4cac81SBjoern A. Zeeb INIT_LIST_HEAD(&addr->addr_list);
17246b4cac81SBjoern A. Zeeb memcpy(addr->addr, LLADDR(sdl), sdl->sdl_alen);
17256b4cac81SBjoern A. Zeeb /* XXX this should be a netdev function? */
17266b4cac81SBjoern A. Zeeb list_add(&addr->addr_list, &mc_list->addr_list);
17276b4cac81SBjoern A. Zeeb mc_list->count++;
17286b4cac81SBjoern A. Zeeb
17299d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
17309d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE)
17316b4cac81SBjoern A. Zeeb printf("%s:%d: mc_list count %d: added %6D\n",
17326b4cac81SBjoern A. Zeeb __func__, __LINE__, mc_list->count, addr->addr, ":");
17339d9ba2b7SBjoern A. Zeeb #endif
17346b4cac81SBjoern A. Zeeb
17356b4cac81SBjoern A. Zeeb return (1);
17366b4cac81SBjoern A. Zeeb }
17376b4cac81SBjoern A. Zeeb
17386b4cac81SBjoern A. Zeeb static void
lkpi_update_mcast_filter(struct ieee80211com * ic,bool force)17396b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(struct ieee80211com *ic, bool force)
17406b4cac81SBjoern A. Zeeb {
17416b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
17426b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw;
17436b4cac81SBjoern A. Zeeb struct netdev_hw_addr_list mc_list;
17446b4cac81SBjoern A. Zeeb struct list_head *le, *next;
17456b4cac81SBjoern A. Zeeb struct netdev_hw_addr *addr;
17466b4cac81SBjoern A. Zeeb struct ieee80211vap *vap;
17476b4cac81SBjoern A. Zeeb u64 mc;
17486b4cac81SBjoern A. Zeeb unsigned int changed_flags, total_flags;
17496b4cac81SBjoern A. Zeeb
17506b4cac81SBjoern A. Zeeb lhw = ic->ic_softc;
17516b4cac81SBjoern A. Zeeb
17526b4cac81SBjoern A. Zeeb if (lhw->ops->prepare_multicast == NULL ||
17536b4cac81SBjoern A. Zeeb lhw->ops->configure_filter == NULL)
17546b4cac81SBjoern A. Zeeb return;
17556b4cac81SBjoern A. Zeeb
17566b4cac81SBjoern A. Zeeb if (!lhw->update_mc && !force)
17576b4cac81SBjoern A. Zeeb return;
17586b4cac81SBjoern A. Zeeb
17596b4cac81SBjoern A. Zeeb changed_flags = total_flags = 0;
17606b4cac81SBjoern A. Zeeb mc_list.count = 0;
17616b4cac81SBjoern A. Zeeb INIT_LIST_HEAD(&mc_list.addr_list);
17626b4cac81SBjoern A. Zeeb if (ic->ic_allmulti == 0) {
17636b4cac81SBjoern A. Zeeb TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
17646b4cac81SBjoern A. Zeeb if_foreach_llmaddr(vap->iv_ifp,
17656b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast_copy, &mc_list);
17666b4cac81SBjoern A. Zeeb } else {
17676b4cac81SBjoern A. Zeeb changed_flags |= FIF_ALLMULTI;
17686b4cac81SBjoern A. Zeeb }
17696b4cac81SBjoern A. Zeeb
17706b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
17716b4cac81SBjoern A. Zeeb mc = lkpi_80211_mo_prepare_multicast(hw, &mc_list);
17726b4cac81SBjoern A. Zeeb /*
17736b4cac81SBjoern A. Zeeb * XXX-BZ make sure to get this sorted what is a change,
17746b4cac81SBjoern A. Zeeb * what gets all set; what was already set?
17756b4cac81SBjoern A. Zeeb */
17766b4cac81SBjoern A. Zeeb total_flags = changed_flags;
17776b4cac81SBjoern A. Zeeb lkpi_80211_mo_configure_filter(hw, changed_flags, &total_flags, mc);
17786b4cac81SBjoern A. Zeeb
17799d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
17809d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE)
17816b4cac81SBjoern A. Zeeb printf("%s: changed_flags %#06x count %d total_flags %#010x\n",
17826b4cac81SBjoern A. Zeeb __func__, changed_flags, mc_list.count, total_flags);
17839d9ba2b7SBjoern A. Zeeb #endif
17846b4cac81SBjoern A. Zeeb
17856b4cac81SBjoern A. Zeeb if (mc_list.count != 0) {
17866b4cac81SBjoern A. Zeeb list_for_each_safe(le, next, &mc_list.addr_list) {
17876b4cac81SBjoern A. Zeeb addr = list_entry(le, struct netdev_hw_addr, addr_list);
17886b4cac81SBjoern A. Zeeb free(addr, M_LKPI80211);
17896b4cac81SBjoern A. Zeeb mc_list.count--;
17906b4cac81SBjoern A. Zeeb }
17916b4cac81SBjoern A. Zeeb }
17926b4cac81SBjoern A. Zeeb KASSERT(mc_list.count == 0, ("%s: mc_list %p count %d != 0\n",
17936b4cac81SBjoern A. Zeeb __func__, &mc_list, mc_list.count));
17946b4cac81SBjoern A. Zeeb }
17956b4cac81SBjoern A. Zeeb
1796fa8f007dSBjoern A. Zeeb static enum ieee80211_bss_changed
lkpi_update_dtim_tsf(struct ieee80211_vif * vif,struct ieee80211_node * ni,struct ieee80211vap * vap,const char * _f,int _l)1797fa8f007dSBjoern A. Zeeb lkpi_update_dtim_tsf(struct ieee80211_vif *vif, struct ieee80211_node *ni,
1798fa8f007dSBjoern A. Zeeb struct ieee80211vap *vap, const char *_f, int _l)
1799fa8f007dSBjoern A. Zeeb {
1800fa8f007dSBjoern A. Zeeb enum ieee80211_bss_changed bss_changed;
1801fa8f007dSBjoern A. Zeeb
1802fa8f007dSBjoern A. Zeeb bss_changed = 0;
1803fa8f007dSBjoern A. Zeeb
18049d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
18059d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE)
1806fa8f007dSBjoern A. Zeeb printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u "
1807fa8f007dSBjoern A. Zeeb "dtim_period %u sync_dtim_count %u sync_tsf %ju "
1808ac1d519cSBjoern A. Zeeb "sync_device_ts %u bss_changed %#010jx\n",
1809fa8f007dSBjoern A. Zeeb __func__, __LINE__, _f, _l,
1810616e1330SBjoern A. Zeeb vif->cfg.assoc, vif->cfg.aid,
1811fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int, vif->bss_conf.dtim_period,
1812fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count,
1813fa8f007dSBjoern A. Zeeb (uintmax_t)vif->bss_conf.sync_tsf,
1814fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_device_ts,
1815ac1d519cSBjoern A. Zeeb (uintmax_t)bss_changed);
18169d9ba2b7SBjoern A. Zeeb #endif
1817fa8f007dSBjoern A. Zeeb
1818fa8f007dSBjoern A. Zeeb if (vif->bss_conf.beacon_int != ni->ni_intval) {
1819fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int = ni->ni_intval;
1820fa8f007dSBjoern A. Zeeb /* iwlwifi FW bug workaround; iwl_mvm_mac_sta_state. */
1821fa8f007dSBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16)
1822fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int = 16;
1823fa8f007dSBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INT;
1824fa8f007dSBjoern A. Zeeb }
1825fa8f007dSBjoern A. Zeeb if (vif->bss_conf.dtim_period != vap->iv_dtim_period &&
1826fa8f007dSBjoern A. Zeeb vap->iv_dtim_period > 0) {
1827fa8f007dSBjoern A. Zeeb vif->bss_conf.dtim_period = vap->iv_dtim_period;
1828fa8f007dSBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INFO;
1829fa8f007dSBjoern A. Zeeb }
1830fa8f007dSBjoern A. Zeeb
1831fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count = vap->iv_dtim_count;
1832fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_tsf = le64toh(ni->ni_tstamp.tsf);
1833fa8f007dSBjoern A. Zeeb /* vif->bss_conf.sync_device_ts = set in linuxkpi_ieee80211_rx. */
1834fa8f007dSBjoern A. Zeeb
18359d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
18369d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE)
1837fa8f007dSBjoern A. Zeeb printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u "
1838fa8f007dSBjoern A. Zeeb "dtim_period %u sync_dtim_count %u sync_tsf %ju "
1839ac1d519cSBjoern A. Zeeb "sync_device_ts %u bss_changed %#010jx\n",
1840fa8f007dSBjoern A. Zeeb __func__, __LINE__, _f, _l,
1841616e1330SBjoern A. Zeeb vif->cfg.assoc, vif->cfg.aid,
1842fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int, vif->bss_conf.dtim_period,
1843fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count,
1844fa8f007dSBjoern A. Zeeb (uintmax_t)vif->bss_conf.sync_tsf,
1845fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_device_ts,
1846ac1d519cSBjoern A. Zeeb (uintmax_t)bss_changed);
18479d9ba2b7SBjoern A. Zeeb #endif
1848fa8f007dSBjoern A. Zeeb
1849fa8f007dSBjoern A. Zeeb return (bss_changed);
1850fa8f007dSBjoern A. Zeeb }
1851fa8f007dSBjoern A. Zeeb
18526b4cac81SBjoern A. Zeeb static void
lkpi_stop_hw_scan(struct lkpi_hw * lhw,struct ieee80211_vif * vif)18536b4cac81SBjoern A. Zeeb lkpi_stop_hw_scan(struct lkpi_hw *lhw, struct ieee80211_vif *vif)
18546b4cac81SBjoern A. Zeeb {
18556b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw;
18566b4cac81SBjoern A. Zeeb int error;
18578ac540d3SBjoern A. Zeeb bool cancel;
18586b4cac81SBjoern A. Zeeb
18598ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw);
18608ac540d3SBjoern A. Zeeb cancel = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0;
18618ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw);
18628ac540d3SBjoern A. Zeeb if (!cancel)
18636b4cac81SBjoern A. Zeeb return;
18646b4cac81SBjoern A. Zeeb
18656b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
18666b4cac81SBjoern A. Zeeb
1867bec76628SBjoern A. Zeeb IEEE80211_UNLOCK(lhw->ic);
1868cd0fcf9fSBjoern A. Zeeb wiphy_lock(hw->wiphy);
18696b4cac81SBjoern A. Zeeb /* Need to cancel the scan. */
18706b4cac81SBjoern A. Zeeb lkpi_80211_mo_cancel_hw_scan(hw, vif);
1871cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
18726b4cac81SBjoern A. Zeeb
18736b4cac81SBjoern A. Zeeb /* Need to make sure we see ieee80211_scan_completed. */
18748ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw);
18758ac540d3SBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0)
18768ac540d3SBjoern A. Zeeb error = msleep(lhw, &lhw->scan_mtx, 0, "lhwscanstop", hz/2);
18778ac540d3SBjoern A. Zeeb cancel = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0;
18788ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw);
18798ac540d3SBjoern A. Zeeb
1880bec76628SBjoern A. Zeeb IEEE80211_LOCK(lhw->ic);
18816b4cac81SBjoern A. Zeeb
18828ac540d3SBjoern A. Zeeb if (cancel)
18836b4cac81SBjoern A. Zeeb ic_printf(lhw->ic, "%s: failed to cancel scan: %d (%p, %p)\n",
18846b4cac81SBjoern A. Zeeb __func__, error, lhw, vif);
18856b4cac81SBjoern A. Zeeb }
18866b4cac81SBjoern A. Zeeb
18876b4cac81SBjoern A. Zeeb static void
lkpi_hw_conf_idle(struct ieee80211_hw * hw,bool new)1888086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(struct ieee80211_hw *hw, bool new)
1889086be6a8SBjoern A. Zeeb {
1890086be6a8SBjoern A. Zeeb struct lkpi_hw *lhw;
1891086be6a8SBjoern A. Zeeb int error;
1892086be6a8SBjoern A. Zeeb bool old;
1893086be6a8SBjoern A. Zeeb
1894086be6a8SBjoern A. Zeeb old = hw->conf.flags & IEEE80211_CONF_IDLE;
1895086be6a8SBjoern A. Zeeb if (old == new)
1896086be6a8SBjoern A. Zeeb return;
1897086be6a8SBjoern A. Zeeb
1898086be6a8SBjoern A. Zeeb hw->conf.flags ^= IEEE80211_CONF_IDLE;
1899086be6a8SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_IDLE);
1900086be6a8SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) {
1901086be6a8SBjoern A. Zeeb lhw = HW_TO_LHW(hw);
1902086be6a8SBjoern A. Zeeb ic_printf(lhw->ic, "ERROR: %s: config %#0x returned %d\n",
1903086be6a8SBjoern A. Zeeb __func__, IEEE80211_CONF_CHANGE_IDLE, error);
1904086be6a8SBjoern A. Zeeb }
1905086be6a8SBjoern A. Zeeb }
1906086be6a8SBjoern A. Zeeb
19075a4d2461SBjoern A. Zeeb static enum ieee80211_bss_changed
lkpi_disassoc(struct ieee80211_sta * sta,struct ieee80211_vif * vif,struct lkpi_hw * lhw)19086b4cac81SBjoern A. Zeeb lkpi_disassoc(struct ieee80211_sta *sta, struct ieee80211_vif *vif,
19096b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw)
19106b4cac81SBjoern A. Zeeb {
19115a4d2461SBjoern A. Zeeb enum ieee80211_bss_changed changed;
19125a4d2461SBjoern A. Zeeb
19135a4d2461SBjoern A. Zeeb changed = 0;
19146b4cac81SBjoern A. Zeeb sta->aid = 0;
1915616e1330SBjoern A. Zeeb if (vif->cfg.assoc) {
19166b4cac81SBjoern A. Zeeb
19176b4cac81SBjoern A. Zeeb lhw->update_mc = true;
19186b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(lhw->ic, true);
19196b4cac81SBjoern A. Zeeb
1920616e1330SBjoern A. Zeeb vif->cfg.assoc = false;
1921616e1330SBjoern A. Zeeb vif->cfg.aid = 0;
19226b4cac81SBjoern A. Zeeb changed |= BSS_CHANGED_ASSOC;
19236b4cac81SBjoern A. Zeeb IMPROVE();
1924086be6a8SBjoern A. Zeeb
19255a4d2461SBjoern A. Zeeb /*
19265a4d2461SBjoern A. Zeeb * Executing the bss_info_changed(BSS_CHANGED_ASSOC) with
19275a4d2461SBjoern A. Zeeb * assoc = false right away here will remove the sta from
19285a4d2461SBjoern A. Zeeb * firmware for iwlwifi.
19295a4d2461SBjoern A. Zeeb * We no longer do this but only return the BSS_CHNAGED value.
19305a4d2461SBjoern A. Zeeb * The caller is responsible for removing the sta gong to
19315a4d2461SBjoern A. Zeeb * IEEE80211_STA_NOTEXIST and then executing the
19325a4d2461SBjoern A. Zeeb * bss_info_changed() update.
19335a4d2461SBjoern A. Zeeb * See lkpi_sta_run_to_init() for more detailed comment.
19345a4d2461SBjoern A. Zeeb */
19356b4cac81SBjoern A. Zeeb }
19365a4d2461SBjoern A. Zeeb
19375a4d2461SBjoern A. Zeeb return (changed);
19386b4cac81SBjoern A. Zeeb }
19396b4cac81SBjoern A. Zeeb
19406b4cac81SBjoern A. Zeeb static void
lkpi_wake_tx_queues(struct ieee80211_hw * hw,struct ieee80211_sta * sta,bool dequeue_seen,bool no_emptyq)19416b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
19426b4cac81SBjoern A. Zeeb bool dequeue_seen, bool no_emptyq)
19436b4cac81SBjoern A. Zeeb {
19446b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq;
19456b4cac81SBjoern A. Zeeb int tid;
1946eac3646fSBjoern A. Zeeb bool ltxq_empty;
19476b4cac81SBjoern A. Zeeb
19486b4cac81SBjoern A. Zeeb /* Wake up all queues to know they are allocated in the driver. */
19496b4cac81SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) {
19506b4cac81SBjoern A. Zeeb
19516b4cac81SBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) {
19526b4cac81SBjoern A. Zeeb IMPROVE("station specific?");
19536b4cac81SBjoern A. Zeeb if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ))
19546b4cac81SBjoern A. Zeeb continue;
19556b4cac81SBjoern A. Zeeb } else if (tid >= hw->queues)
19566b4cac81SBjoern A. Zeeb continue;
19576b4cac81SBjoern A. Zeeb
19586b4cac81SBjoern A. Zeeb if (sta->txq[tid] == NULL)
19596b4cac81SBjoern A. Zeeb continue;
19606b4cac81SBjoern A. Zeeb
19616b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]);
19626b4cac81SBjoern A. Zeeb if (dequeue_seen && !ltxq->seen_dequeue)
19636b4cac81SBjoern A. Zeeb continue;
19646b4cac81SBjoern A. Zeeb
1965eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_LOCK(ltxq);
1966eac3646fSBjoern A. Zeeb ltxq_empty = skb_queue_empty(<xq->skbq);
1967eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_UNLOCK(ltxq);
1968eac3646fSBjoern A. Zeeb if (no_emptyq && ltxq_empty)
19696b4cac81SBjoern A. Zeeb continue;
19706b4cac81SBjoern A. Zeeb
19716b4cac81SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, sta->txq[tid]);
19726b4cac81SBjoern A. Zeeb }
19736b4cac81SBjoern A. Zeeb }
19746b4cac81SBjoern A. Zeeb
197588665349SBjoern A. Zeeb /*
197688665349SBjoern A. Zeeb * On the way down from RUN -> ASSOC -> AUTH we may send a DISASSOC or DEAUTH
197788665349SBjoern A. Zeeb * packet. The problem is that the state machine functions tend to hold the
197888665349SBjoern A. Zeeb * LHW lock which will prevent lkpi_80211_txq_tx_one() from sending the packet.
197988665349SBjoern A. Zeeb * We call this after dropping the ic lock and before acquiring the LHW lock.
198088665349SBjoern A. Zeeb * we make sure no further packets are queued and if they are queued the task
198188665349SBjoern A. Zeeb * will finish or be cancelled. At the end if a packet is left we manually
198288665349SBjoern A. Zeeb * send it. scan_to_auth() would re-enable sending if the lsta would be
198388665349SBjoern A. Zeeb * re-used.
198488665349SBjoern A. Zeeb */
198588665349SBjoern A. Zeeb static void
lkpi_80211_flush_tx(struct lkpi_hw * lhw,struct lkpi_sta * lsta)198688665349SBjoern A. Zeeb lkpi_80211_flush_tx(struct lkpi_hw *lhw, struct lkpi_sta *lsta)
198788665349SBjoern A. Zeeb {
1988cd0fcf9fSBjoern A. Zeeb struct ieee80211_hw *hw;
198988665349SBjoern A. Zeeb struct mbufq mq;
199088665349SBjoern A. Zeeb struct mbuf *m;
199188665349SBjoern A. Zeeb int len;
199288665349SBjoern A. Zeeb
1993cd0fcf9fSBjoern A. Zeeb /* There is no lockdep_assert_not_held_wiphy(). */
1994cd0fcf9fSBjoern A. Zeeb hw = LHW_TO_HW(lhw);
1995cd0fcf9fSBjoern A. Zeeb lockdep_assert_not_held(&hw->wiphy->mtx);
199688665349SBjoern A. Zeeb
199788665349SBjoern A. Zeeb /* Do not accept any new packets until scan_to_auth or lsta_free(). */
199888665349SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_LOCK(lsta);
199988665349SBjoern A. Zeeb lsta->txq_ready = false;
200088665349SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_UNLOCK(lsta);
200188665349SBjoern A. Zeeb
200288665349SBjoern A. Zeeb while (taskqueue_cancel(taskqueue_thread, &lsta->txq_task, NULL) != 0)
200388665349SBjoern A. Zeeb taskqueue_drain(taskqueue_thread, &lsta->txq_task);
200488665349SBjoern A. Zeeb
200588665349SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_LOCK(lsta);
200688665349SBjoern A. Zeeb len = mbufq_len(&lsta->txq);
200788665349SBjoern A. Zeeb if (len <= 0) {
200888665349SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_UNLOCK(lsta);
200988665349SBjoern A. Zeeb return;
201088665349SBjoern A. Zeeb }
201188665349SBjoern A. Zeeb
201288665349SBjoern A. Zeeb mbufq_init(&mq, IFQ_MAXLEN);
201388665349SBjoern A. Zeeb mbufq_concat(&mq, &lsta->txq);
201488665349SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_UNLOCK(lsta);
201588665349SBjoern A. Zeeb
201688665349SBjoern A. Zeeb m = mbufq_dequeue(&mq);
201788665349SBjoern A. Zeeb while (m != NULL) {
201888665349SBjoern A. Zeeb lkpi_80211_txq_tx_one(lsta, m);
201988665349SBjoern A. Zeeb m = mbufq_dequeue(&mq);
202088665349SBjoern A. Zeeb }
202188665349SBjoern A. Zeeb }
202288665349SBjoern A. Zeeb
202350d826beSBjoern A. Zeeb
202450d826beSBjoern A. Zeeb static void
lkpi_remove_chanctx(struct ieee80211_hw * hw,struct ieee80211_vif * vif)202550d826beSBjoern A. Zeeb lkpi_remove_chanctx(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
202650d826beSBjoern A. Zeeb {
202750d826beSBjoern A. Zeeb struct ieee80211_chanctx_conf *chanctx_conf;
2028231168c7SBjoern A. Zeeb struct lkpi_chanctx *lchanctx;
202950d826beSBjoern A. Zeeb
2030231168c7SBjoern A. Zeeb chanctx_conf = rcu_dereference_protected(vif->bss_conf.chanctx_conf,
2031231168c7SBjoern A. Zeeb lockdep_is_held(&hw->wiphy->mtx));
2032231168c7SBjoern A. Zeeb
2033231168c7SBjoern A. Zeeb if (chanctx_conf == NULL)
2034231168c7SBjoern A. Zeeb return;
2035231168c7SBjoern A. Zeeb
203650d826beSBjoern A. Zeeb /* Remove vif context. */
2037231168c7SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->bss_conf, chanctx_conf);
203850d826beSBjoern A. Zeeb
203950d826beSBjoern A. Zeeb lkpi_hw_conf_idle(hw, true);
204050d826beSBjoern A. Zeeb
204150d826beSBjoern A. Zeeb /* Remove chan ctx. */
204250d826beSBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, chanctx_conf);
2043231168c7SBjoern A. Zeeb
2044231168c7SBjoern A. Zeeb /* Cleanup. */
2045231168c7SBjoern A. Zeeb rcu_assign_pointer(vif->bss_conf.chanctx_conf, NULL);
204650d826beSBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(chanctx_conf);
2047a8a47a41SBjoern A. Zeeb list_del(&lchanctx->entry);
204850d826beSBjoern A. Zeeb free(lchanctx, M_LKPI80211);
204950d826beSBjoern A. Zeeb }
205050d826beSBjoern A. Zeeb
205150d826beSBjoern A. Zeeb
20526b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */
20536b4cac81SBjoern A. Zeeb
20546b4cac81SBjoern A. Zeeb static int
lkpi_sta_state_do_nada(struct ieee80211vap * vap,enum ieee80211_state nstate,int arg)20556b4cac81SBjoern A. Zeeb lkpi_sta_state_do_nada(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
20566b4cac81SBjoern A. Zeeb {
20576b4cac81SBjoern A. Zeeb
20586b4cac81SBjoern A. Zeeb return (0);
20596b4cac81SBjoern A. Zeeb }
20606b4cac81SBjoern A. Zeeb
20616b4cac81SBjoern A. Zeeb /* lkpi_iv_newstate() handles the stop scan case generally. */
20626b4cac81SBjoern A. Zeeb #define lkpi_sta_scan_to_init(_v, _n, _a) lkpi_sta_state_do_nada(_v, _n, _a)
20636b4cac81SBjoern A. Zeeb
20646b4cac81SBjoern A. Zeeb static int
lkpi_sta_scan_to_auth(struct ieee80211vap * vap,enum ieee80211_state nstate,int arg)20656b4cac81SBjoern A. Zeeb lkpi_sta_scan_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
20666b4cac81SBjoern A. Zeeb {
20676b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan;
2068c5e25798SBjoern A. Zeeb struct lkpi_chanctx *lchanctx;
2069d1af434dSBjoern A. Zeeb struct ieee80211_chanctx_conf *chanctx_conf;
20706b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
20716b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw;
20726b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
20736b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif;
20746b4cac81SBjoern A. Zeeb struct ieee80211_node *ni;
20756b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta;
20766b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed;
20776b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info;
20786b4cac81SBjoern A. Zeeb uint32_t changed;
20796b4cac81SBjoern A. Zeeb int error;
208016d987feSBjoern A. Zeeb bool synched;
20816b4cac81SBjoern A. Zeeb
20822ac8a218SBjoern A. Zeeb /*
20832ac8a218SBjoern A. Zeeb * In here we use vap->iv_bss until lvif->lvif_bss is set.
20842ac8a218SBjoern A. Zeeb * For all later (STATE >= AUTH) functions we need to use the lvif
20852ac8a218SBjoern A. Zeeb * cache which will be tracked even through (*iv_update_bss)().
20862ac8a218SBjoern A. Zeeb */
20872ac8a218SBjoern A. Zeeb
20882ac8a218SBjoern A. Zeeb if (vap->iv_bss == NULL) {
20892ac8a218SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: no iv_bss for vap %p\n", __func__, vap);
20902ac8a218SBjoern A. Zeeb return (EINVAL);
20912ac8a218SBjoern A. Zeeb }
20920936c648SBjoern A. Zeeb /*
20930936c648SBjoern A. Zeeb * Keep the ni alive locally. In theory (and practice) iv_bss can change
20940936c648SBjoern A. Zeeb * once we unlock here. This is due to net80211 allowing state changes
20950936c648SBjoern A. Zeeb * and new join1() despite having an active node as well as due to
20960936c648SBjoern A. Zeeb * the fact that the iv_bss can be swapped under the hood in (*iv_update_bss).
20970936c648SBjoern A. Zeeb */
20982ac8a218SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss);
20992ac8a218SBjoern A. Zeeb if (ni->ni_chan == NULL || ni->ni_chan == IEEE80211_CHAN_ANYC) {
21002ac8a218SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: no channel set for iv_bss ni %p "
21012ac8a218SBjoern A. Zeeb "on vap %p\n", __func__, ni, vap);
21020936c648SBjoern A. Zeeb ieee80211_free_node(ni); /* Error handling for the local ni. */
21032ac8a218SBjoern A. Zeeb return (EINVAL);
21046b4cac81SBjoern A. Zeeb }
21056b4cac81SBjoern A. Zeeb
21066b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc;
21072ac8a218SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, ni->ni_chan);
21082ac8a218SBjoern A. Zeeb if (chan == NULL) {
21092ac8a218SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: failed to get LKPI channel from "
21102ac8a218SBjoern A. Zeeb "iv_bss ni %p on vap %p\n", __func__, ni, vap);
21110936c648SBjoern A. Zeeb ieee80211_free_node(ni); /* Error handling for the local ni. */
21122ac8a218SBjoern A. Zeeb return (ESRCH);
21132ac8a218SBjoern A. Zeeb }
21142ac8a218SBjoern A. Zeeb
21156b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
21166b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
21176b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
21186b4cac81SBjoern A. Zeeb
21190936c648SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif);
21200936c648SBjoern A. Zeeb /* XXX-BZ KASSERT later? */
21210936c648SBjoern A. Zeeb if (lvif->lvif_bss_synched || lvif->lvif_bss != NULL) {
21220936c648SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p "
21230936c648SBjoern A. Zeeb "lvif_bss->ni %p synched %d\n", __func__, __LINE__,
21240936c648SBjoern A. Zeeb lvif, vap, vap->iv_bss, lvif->lvif_bss,
21250936c648SBjoern A. Zeeb (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL,
21260936c648SBjoern A. Zeeb lvif->lvif_bss_synched);
212792690579SMark Johnston LKPI_80211_LVIF_UNLOCK(lvif);
212892690579SMark Johnston ieee80211_free_node(ni); /* Error handling for the local ni. */
21290936c648SBjoern A. Zeeb return (EBUSY);
21300936c648SBjoern A. Zeeb }
21310936c648SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif);
21320936c648SBjoern A. Zeeb
21336b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic);
2134cd0fcf9fSBjoern A. Zeeb wiphy_lock(hw->wiphy);
21356b4cac81SBjoern A. Zeeb
21366b4cac81SBjoern A. Zeeb /* Add chanctx (or if exists, change it). */
2137560708cbSBjoern A. Zeeb chanctx_conf = rcu_dereference_protected(vif->bss_conf.chanctx_conf,
2138560708cbSBjoern A. Zeeb lockdep_is_held(&hw->wiphy->mtx));
2139560708cbSBjoern A. Zeeb if (chanctx_conf != NULL) {
2140d1af434dSBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(chanctx_conf);
21416b4cac81SBjoern A. Zeeb IMPROVE("diff changes for changed, working on live copy, rcu");
21426b4cac81SBjoern A. Zeeb } else {
21436b4cac81SBjoern A. Zeeb /* Keep separate alloc as in Linux this is rcu managed? */
2144c5e25798SBjoern A. Zeeb lchanctx = malloc(sizeof(*lchanctx) + hw->chanctx_data_size,
21456b4cac81SBjoern A. Zeeb M_LKPI80211, M_WAITOK | M_ZERO);
2146d1af434dSBjoern A. Zeeb chanctx_conf = &lchanctx->chanctx_conf;
21476b4cac81SBjoern A. Zeeb }
21486b4cac81SBjoern A. Zeeb
2149d1af434dSBjoern A. Zeeb chanctx_conf->rx_chains_static = 1;
2150389265e3SBjoern A. Zeeb chanctx_conf->rx_chains_dynamic = 1;
2151d1af434dSBjoern A. Zeeb chanctx_conf->radar_enabled =
21526b4cac81SBjoern A. Zeeb (chan->flags & IEEE80211_CHAN_RADAR) ? true : false;
2153d1af434dSBjoern A. Zeeb chanctx_conf->def.chan = chan;
2154d1af434dSBjoern A. Zeeb chanctx_conf->def.width = NL80211_CHAN_WIDTH_20_NOHT;
215590d8e307SBjoern A. Zeeb chanctx_conf->def.center_freq1 = ieee80211_get_channel_center_freq1(ni->ni_chan);
215690d8e307SBjoern A. Zeeb chanctx_conf->def.center_freq2 = ieee80211_get_channel_center_freq2(ni->ni_chan);
21579fb91463SBjoern A. Zeeb IMPROVE("Check vht_cap from band not just chan?");
21582ac8a218SBjoern A. Zeeb KASSERT(ni->ni_chan != NULL && ni->ni_chan != IEEE80211_CHAN_ANYC,
21592ac8a218SBjoern A. Zeeb ("%s:%d: ni %p ni_chan %p\n", __func__, __LINE__, ni, ni->ni_chan));
216062d51a43SBjoern A. Zeeb
21619fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT
21629fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_HT(ni->ni_chan)) {
216390d8e307SBjoern A. Zeeb if (IEEE80211_IS_CHAN_HT40(ni->ni_chan))
2164d1af434dSBjoern A. Zeeb chanctx_conf->def.width = NL80211_CHAN_WIDTH_40;
216590d8e307SBjoern A. Zeeb else
2166d1af434dSBjoern A. Zeeb chanctx_conf->def.width = NL80211_CHAN_WIDTH_20;
21679fb91463SBjoern A. Zeeb }
21689fb91463SBjoern A. Zeeb #endif
21699fb91463SBjoern A. Zeeb #ifdef LKPI_80211_VHT
21705393cd34SBjoern A. Zeeb if (IEEE80211_IS_CHAN_VHT_5GHZ(ni->ni_chan)) {
217190d8e307SBjoern A. Zeeb if (IEEE80211_IS_CHAN_VHT80P80(ni->ni_chan))
2172d1af434dSBjoern A. Zeeb chanctx_conf->def.width = NL80211_CHAN_WIDTH_80P80;
217390d8e307SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_VHT160(ni->ni_chan))
2174d1af434dSBjoern A. Zeeb chanctx_conf->def.width = NL80211_CHAN_WIDTH_160;
21754bf049bfSBjoern A. Zeeb else if (IEEE80211_IS_CHAN_VHT80(ni->ni_chan))
2176d1af434dSBjoern A. Zeeb chanctx_conf->def.width = NL80211_CHAN_WIDTH_80;
21779fb91463SBjoern A. Zeeb }
21789fb91463SBjoern A. Zeeb #endif
2179389265e3SBjoern A. Zeeb chanctx_conf->rx_chains_dynamic = lkpi_get_max_rx_chains(ni);
21806b4cac81SBjoern A. Zeeb /* Responder ... */
218190d8e307SBjoern A. Zeeb #if 0
218290d8e307SBjoern A. Zeeb chanctx_conf->min_def.chan = chanctx_conf->def.chan;
2183d1af434dSBjoern A. Zeeb chanctx_conf->min_def.width = NL80211_CHAN_WIDTH_20_NOHT;
218490d8e307SBjoern A. Zeeb #ifdef LKPI_80211_HT
218590d8e307SBjoern A. Zeeb if (IEEE80211_IS_CHAN_HT(ni->ni_chan) || IEEE80211_IS_CHAN_VHT(ni->ni_chan))
218690d8e307SBjoern A. Zeeb chanctx_conf->min_def.width = NL80211_CHAN_WIDTH_20;
218790d8e307SBjoern A. Zeeb #endif
218890d8e307SBjoern A. Zeeb chanctx_conf->min_def.center_freq1 = chanctx_conf->def.center_freq1;
218990d8e307SBjoern A. Zeeb chanctx_conf->min_def.center_freq2 = chanctx_conf->def.center_freq2;
219090d8e307SBjoern A. Zeeb #else
219190d8e307SBjoern A. Zeeb chanctx_conf->min_def = chanctx_conf->def;
219290d8e307SBjoern A. Zeeb #endif
21936b4cac81SBjoern A. Zeeb
21946ffb7bd4SBjoern A. Zeeb /* Set bss info (bss_info_changed). */
21956ffb7bd4SBjoern A. Zeeb bss_changed = 0;
21966ffb7bd4SBjoern A. Zeeb vif->bss_conf.bssid = ni->ni_bssid;
21976ffb7bd4SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID;
21986ffb7bd4SBjoern A. Zeeb vif->bss_conf.txpower = ni->ni_txpower;
21996ffb7bd4SBjoern A. Zeeb bss_changed |= BSS_CHANGED_TXPOWER;
22006ffb7bd4SBjoern A. Zeeb vif->cfg.idle = false;
22016ffb7bd4SBjoern A. Zeeb bss_changed |= BSS_CHANGED_IDLE;
22026ffb7bd4SBjoern A. Zeeb
22036ffb7bd4SBjoern A. Zeeb /* vif->bss_conf.basic_rates ? Where exactly? */
22046ffb7bd4SBjoern A. Zeeb
22056ffb7bd4SBjoern A. Zeeb /* Should almost assert it is this. */
22066ffb7bd4SBjoern A. Zeeb vif->cfg.assoc = false;
22076ffb7bd4SBjoern A. Zeeb vif->cfg.aid = 0;
22086ffb7bd4SBjoern A. Zeeb
22096ffb7bd4SBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__);
22106ffb7bd4SBjoern A. Zeeb
22116b4cac81SBjoern A. Zeeb error = 0;
2212560708cbSBjoern A. Zeeb if (vif->bss_conf.chanctx_conf == chanctx_conf) {
22136b4cac81SBjoern A. Zeeb changed = IEEE80211_CHANCTX_CHANGE_MIN_WIDTH;
22146b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_RADAR;
22156b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_RX_CHAINS;
22166b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_WIDTH;
2217d1af434dSBjoern A. Zeeb lkpi_80211_mo_change_chanctx(hw, chanctx_conf, changed);
22186b4cac81SBjoern A. Zeeb } else {
2219d1af434dSBjoern A. Zeeb error = lkpi_80211_mo_add_chanctx(hw, chanctx_conf);
22206b4cac81SBjoern A. Zeeb if (error == 0 || error == EOPNOTSUPP) {
22217b43f4d0SBjoern A. Zeeb vif->bss_conf.chanreq.oper.chan = chanctx_conf->def.chan;
22227b43f4d0SBjoern A. Zeeb vif->bss_conf.chanreq.oper.width = chanctx_conf->def.width;
22237b43f4d0SBjoern A. Zeeb vif->bss_conf.chanreq.oper.center_freq1 =
2224d1af434dSBjoern A. Zeeb chanctx_conf->def.center_freq1;
22257b43f4d0SBjoern A. Zeeb vif->bss_conf.chanreq.oper.center_freq2 =
2226d1af434dSBjoern A. Zeeb chanctx_conf->def.center_freq2;
22276b4cac81SBjoern A. Zeeb } else {
2228018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_add_chanctx "
2229018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error);
22306b4cac81SBjoern A. Zeeb goto out;
22316b4cac81SBjoern A. Zeeb }
22326ffb7bd4SBjoern A. Zeeb
2233a8a47a41SBjoern A. Zeeb list_add_rcu(&lchanctx->entry, &lhw->lchanctx_list);
2234560708cbSBjoern A. Zeeb rcu_assign_pointer(vif->bss_conf.chanctx_conf, chanctx_conf);
22356ffb7bd4SBjoern A. Zeeb
22366b4cac81SBjoern A. Zeeb /* Assign vif chanctx. */
22376b4cac81SBjoern A. Zeeb if (error == 0)
223868541546SBjoern A. Zeeb error = lkpi_80211_mo_assign_vif_chanctx(hw, vif,
2239d1af434dSBjoern A. Zeeb &vif->bss_conf, chanctx_conf);
22406b4cac81SBjoern A. Zeeb if (error == EOPNOTSUPP)
22416b4cac81SBjoern A. Zeeb error = 0;
22426b4cac81SBjoern A. Zeeb if (error != 0) {
2243018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_assign_vif_chanctx "
2244018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error);
2245d1af434dSBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, chanctx_conf);
2246560708cbSBjoern A. Zeeb rcu_assign_pointer(vif->bss_conf.chanctx_conf, NULL);
2247d1af434dSBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(chanctx_conf);
2248a8a47a41SBjoern A. Zeeb list_del(&lchanctx->entry);
2249c5e25798SBjoern A. Zeeb free(lchanctx, M_LKPI80211);
22506b4cac81SBjoern A. Zeeb goto out;
22516b4cac81SBjoern A. Zeeb }
22526b4cac81SBjoern A. Zeeb }
22536b4cac81SBjoern A. Zeeb IMPROVE("update radiotap chan fields too");
22546b4cac81SBjoern A. Zeeb
22556b4cac81SBjoern A. Zeeb /* RATES */
22566b4cac81SBjoern A. Zeeb IMPROVE("bss info: not all needs to come now and rates are missing");
22576b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed);
22586b4cac81SBjoern A. Zeeb
2259d9f59799SBjoern A. Zeeb /*
22600936c648SBjoern A. Zeeb * Given ni and lsta are 1:1 from alloc to free we can assert that
22610936c648SBjoern A. Zeeb * ni always has lsta data attach despite net80211 node swapping
22620936c648SBjoern A. Zeeb * under the hoods.
2263d9f59799SBjoern A. Zeeb */
22640936c648SBjoern A. Zeeb KASSERT(ni->ni_drv_data != NULL, ("%s: ni %p ni_drv_data %p\n",
22650936c648SBjoern A. Zeeb __func__, ni, ni->ni_drv_data));
22666b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data;
2267e24e8103SBjoern A. Zeeb
22682ac8a218SBjoern A. Zeeb /* Insert the [l]sta into the list of known stations. */
2269a8f735a6SBjoern A. Zeeb list_add_tail(&lsta->lsta_list, &lvif->lsta_list);
2270e24e8103SBjoern A. Zeeb
2271d9f59799SBjoern A. Zeeb /* Add (or adjust) sta and change state (from NOTEXIST) to NONE. */
22726b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
22736b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NOTEXIST, ("%s: lsta %p state not "
22746b4cac81SBjoern A. Zeeb "NOTEXIST: %#x\n", __func__, lsta, lsta->state));
2275e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE);
22766b4cac81SBjoern A. Zeeb if (error != 0) {
22776b4cac81SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?");
2278018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NONE) "
2279018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error);
22806b4cac81SBjoern A. Zeeb goto out;
22816b4cac81SBjoern A. Zeeb }
22826b4cac81SBjoern A. Zeeb #if 0
22836b4cac81SBjoern A. Zeeb lsta->added_to_drv = true; /* mo manages. */
22846b4cac81SBjoern A. Zeeb #endif
22856b4cac81SBjoern A. Zeeb
22869d9ba2b7SBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
22879d9ba2b7SBjoern A. Zeeb
22881665ef97SBjoern A. Zeeb #if 0
22896b4cac81SBjoern A. Zeeb /*
22906b4cac81SBjoern A. Zeeb * Wakeup all queues now that sta is there so we have as much time to
22916b4cac81SBjoern A. Zeeb * possibly prepare the queue in the driver to be ready for the 1st
22926b4cac81SBjoern A. Zeeb * packet; lkpi_80211_txq_tx_one() still has a workaround as there
22936b4cac81SBjoern A. Zeeb * is no guarantee or way to check.
2294d9f59799SBjoern A. Zeeb * XXX-BZ and by now we know that this does not work on all drivers
2295d9f59799SBjoern A. Zeeb * for all queues.
22966b4cac81SBjoern A. Zeeb */
2297e7fe0373SBjoern A. Zeeb lkpi_wake_tx_queues(hw, LSTA_TO_STA(lsta), false, false);
22981665ef97SBjoern A. Zeeb #endif
22996b4cac81SBjoern A. Zeeb
23006b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */
23016b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info));
23026b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION;
23036b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info);
23046b4cac81SBjoern A. Zeeb lsta->in_mgd = true;
23056b4cac81SBjoern A. Zeeb
23066b4cac81SBjoern A. Zeeb /*
23076b4cac81SBjoern A. Zeeb * What is going to happen next:
23086b4cac81SBjoern A. Zeeb * - <twiddle> .. we should end up in "auth_to_assoc"
23096b4cac81SBjoern A. Zeeb * - event_callback
23106b4cac81SBjoern A. Zeeb * - update sta_state (NONE to AUTH)
23116b4cac81SBjoern A. Zeeb * - mgd_complete_tx
23126b4cac81SBjoern A. Zeeb * (ideally we'd do that on a callback for something else ...)
23136b4cac81SBjoern A. Zeeb */
23146b4cac81SBjoern A. Zeeb
2315cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
2316105b9df2SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic);
2317105b9df2SBjoern A. Zeeb
2318105b9df2SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif);
2319105b9df2SBjoern A. Zeeb /* Re-check given (*iv_update_bss) could have happened while we were unlocked. */
2320105b9df2SBjoern A. Zeeb if (lvif->lvif_bss_synched || lvif->lvif_bss != NULL ||
2321105b9df2SBjoern A. Zeeb lsta->ni != vap->iv_bss)
2322105b9df2SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p "
2323105b9df2SBjoern A. Zeeb "lvif_bss->ni %p synched %d, ni %p lsta %p\n", __func__, __LINE__,
2324105b9df2SBjoern A. Zeeb lvif, vap, vap->iv_bss, lvif->lvif_bss,
2325105b9df2SBjoern A. Zeeb (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL,
2326105b9df2SBjoern A. Zeeb lvif->lvif_bss_synched, ni, lsta);
2327105b9df2SBjoern A. Zeeb
2328105b9df2SBjoern A. Zeeb /*
2329105b9df2SBjoern A. Zeeb * Reference the "ni" for caching the lsta/ni in lvif->lvif_bss.
2330105b9df2SBjoern A. Zeeb * Given we cache lsta we use lsta->ni instead of ni here (even though
2331105b9df2SBjoern A. Zeeb * lsta->ni == ni) to be distinct from the rest of the code where we do
2332105b9df2SBjoern A. Zeeb * assume that ni == vap->iv_bss which it may or may not be.
2333105b9df2SBjoern A. Zeeb * So do NOT use iv_bss here anymore as that may have diverged from our
2334105b9df2SBjoern A. Zeeb * function local ni already while ic was unlocked and would lead to
2335105b9df2SBjoern A. Zeeb * inconsistencies. Go and see if we lost a race and do not update
2336105b9df2SBjoern A. Zeeb * lvif_bss_synched in that case.
2337105b9df2SBjoern A. Zeeb */
2338105b9df2SBjoern A. Zeeb ieee80211_ref_node(lsta->ni);
2339105b9df2SBjoern A. Zeeb lvif->lvif_bss = lsta;
2340105b9df2SBjoern A. Zeeb if (lsta->ni == vap->iv_bss) {
234116d987feSBjoern A. Zeeb lvif->lvif_bss_synched = synched = true;
2342105b9df2SBjoern A. Zeeb } else {
2343105b9df2SBjoern A. Zeeb /* Set to un-synched no matter what. */
234416d987feSBjoern A. Zeeb lvif->lvif_bss_synched = synched = false;
2345105b9df2SBjoern A. Zeeb /*
2346105b9df2SBjoern A. Zeeb * We do not error as someone has to take us down.
2347105b9df2SBjoern A. Zeeb * If we are followed by a 2nd, new net80211::join1() going to
2348105b9df2SBjoern A. Zeeb * AUTH lkpi_sta_a_to_a() will error, lkpi_sta_auth_to_{scan,init}()
2349105b9df2SBjoern A. Zeeb * will take the lvif->lvif_bss node down eventually.
2350105b9df2SBjoern A. Zeeb * What happens with the vap->iv_bss node will entirely be up
2351105b9df2SBjoern A. Zeeb * to net80211 as we never used the node beyond alloc()/free()
2352105b9df2SBjoern A. Zeeb * and we do not hold an extra reference for that anymore given
2353105b9df2SBjoern A. Zeeb * ni : lsta == 1:1.
235416d987feSBjoern A. Zeeb * Problem is if we do not error a MGMT/AUTH frame will be
235516d987feSBjoern A. Zeeb * sent from net80211::sta_newstate(); disable lsta queue below.
2356105b9df2SBjoern A. Zeeb */
2357105b9df2SBjoern A. Zeeb }
2358105b9df2SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif);
235916d987feSBjoern A. Zeeb /*
236016d987feSBjoern A. Zeeb * Make sure in case the sta did not change and we re-added it,
236116d987feSBjoern A. Zeeb * that we can tx again but only if the vif/iv_bss are in sync.
236216d987feSBjoern A. Zeeb * Otherwise this should prevent the MGMT/AUTH frame from being
236316d987feSBjoern A. Zeeb * sent triggering a warning in iwlwifi.
236416d987feSBjoern A. Zeeb */
236516d987feSBjoern A. Zeeb LKPI_80211_LSTA_TXQ_LOCK(lsta);
236616d987feSBjoern A. Zeeb lsta->txq_ready = synched;
236716d987feSBjoern A. Zeeb LKPI_80211_LSTA_TXQ_UNLOCK(lsta);
2368105b9df2SBjoern A. Zeeb goto out_relocked;
2369105b9df2SBjoern A. Zeeb
23706b4cac81SBjoern A. Zeeb out:
2371cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
23726b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic);
2373105b9df2SBjoern A. Zeeb out_relocked:
23740936c648SBjoern A. Zeeb /*
2375105b9df2SBjoern A. Zeeb * Release the reference that kept the ni stable locally
23760936c648SBjoern A. Zeeb * during the work of this function.
23770936c648SBjoern A. Zeeb */
23786b4cac81SBjoern A. Zeeb if (ni != NULL)
23796b4cac81SBjoern A. Zeeb ieee80211_free_node(ni);
23806b4cac81SBjoern A. Zeeb return (error);
23816b4cac81SBjoern A. Zeeb }
23826b4cac81SBjoern A. Zeeb
23836b4cac81SBjoern A. Zeeb static int
lkpi_sta_auth_to_scan(struct ieee80211vap * vap,enum ieee80211_state nstate,int arg)23846b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
23856b4cac81SBjoern A. Zeeb {
23866b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
23876b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw;
23886b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
23896b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif;
23906b4cac81SBjoern A. Zeeb struct ieee80211_node *ni;
23916b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta;
23926b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta;
23936b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info;
23946b4cac81SBjoern A. Zeeb int error;
23956b4cac81SBjoern A. Zeeb
23966b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc;
23976b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
23986b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
23996b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
24006b4cac81SBjoern A. Zeeb
24012ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif);
24022ac8a218SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
24032ac8a218SBjoern A. Zeeb /* XXX-BZ KASSERT later; state going down so no action. */
24042ac8a218SBjoern A. Zeeb if (lvif->lvif_bss == NULL)
24052ac8a218SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p "
24062ac8a218SBjoern A. Zeeb "lvif_bss->ni %p synched %d\n", __func__, __LINE__,
24072ac8a218SBjoern A. Zeeb lvif, vap, vap->iv_bss, lvif->lvif_bss,
24082ac8a218SBjoern A. Zeeb (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL,
24092ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched);
24102ac8a218SBjoern A. Zeeb #endif
24112ac8a218SBjoern A. Zeeb
24122ac8a218SBjoern A. Zeeb lsta = lvif->lvif_bss;
24132ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif);
24142ac8a218SBjoern A. Zeeb KASSERT(lsta != NULL && lsta->ni != NULL, ("%s: lsta %p ni %p "
24152ac8a218SBjoern A. Zeeb "lvif %p vap %p\n", __func__,
24162ac8a218SBjoern A. Zeeb lsta, (lsta != NULL) ? lsta->ni : NULL, lvif, vap));
24172ac8a218SBjoern A. Zeeb ni = lsta->ni; /* Reference held for lvif_bss. */
24186b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta);
24196b4cac81SBjoern A. Zeeb
242067674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
24216b4cac81SBjoern A. Zeeb
24226b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic);
2423cd0fcf9fSBjoern A. Zeeb wiphy_lock(hw->wiphy);
24246b4cac81SBjoern A. Zeeb
2425d9f59799SBjoern A. Zeeb /* flush, drop. */
2426d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true);
2427d9f59799SBjoern A. Zeeb
24286b4cac81SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */
242988665349SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, false, true);
24306b4cac81SBjoern A. Zeeb
24316b4cac81SBjoern A. Zeeb /* flush, no drop */
24326b4cac81SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false);
24336b4cac81SBjoern A. Zeeb
24346b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */
24356b4cac81SBjoern A. Zeeb if (lsta->in_mgd) {
24366b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info));
24376b4cac81SBjoern A. Zeeb prep_tx_info.success = false;
24386b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info);
24396b4cac81SBjoern A. Zeeb lsta->in_mgd = false;
24406b4cac81SBjoern A. Zeeb }
24416b4cac81SBjoern A. Zeeb
24426b4cac81SBjoern A. Zeeb /* sync_rx_queues */
24436b4cac81SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw);
24446b4cac81SBjoern A. Zeeb
24456b4cac81SBjoern A. Zeeb /* sta_pre_rcu_remove */
24466b4cac81SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta);
2447d9f59799SBjoern A. Zeeb
2448d9f59799SBjoern A. Zeeb /* Take the station down. */
24496b4cac81SBjoern A. Zeeb
24506b4cac81SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */
24516b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
24526b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not "
2453d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg));
2454e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST);
24556b4cac81SBjoern A. Zeeb if (error != 0) {
24566b4cac81SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?");
2457018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NOTEXIST) "
2458018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error);
24596b4cac81SBjoern A. Zeeb goto out;
24606b4cac81SBjoern A. Zeeb }
24616b4cac81SBjoern A. Zeeb #if 0
24626b4cac81SBjoern A. Zeeb lsta->added_to_drv = false; /* mo manages. */
24636b4cac81SBjoern A. Zeeb #endif
24646b4cac81SBjoern A. Zeeb
246567674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
24666b4cac81SBjoern A. Zeeb
24672ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif);
24682ac8a218SBjoern A. Zeeb /* Remove ni reference for this cache of lsta. */
24692ac8a218SBjoern A. Zeeb lvif->lvif_bss = NULL;
24702ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched = false;
24712ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif);
2472d9f59799SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif);
24730936c648SBjoern A. Zeeb /*
24740936c648SBjoern A. Zeeb * The very last release the reference on the ni for the ni/lsta on
24750936c648SBjoern A. Zeeb * lvif->lvif_bss. Upon return from this both ni and lsta are invalid
24760936c648SBjoern A. Zeeb * and potentially freed.
24770936c648SBjoern A. Zeeb */
24780936c648SBjoern A. Zeeb ieee80211_free_node(ni);
2479d9f59799SBjoern A. Zeeb
2480d9f59799SBjoern A. Zeeb /* conf_tx */
2481d9f59799SBjoern A. Zeeb
248250d826beSBjoern A. Zeeb lkpi_remove_chanctx(hw, vif);
24836b4cac81SBjoern A. Zeeb
24846b4cac81SBjoern A. Zeeb out:
2485cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
24866b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic);
24876b4cac81SBjoern A. Zeeb return (error);
24886b4cac81SBjoern A. Zeeb }
24896b4cac81SBjoern A. Zeeb
24906b4cac81SBjoern A. Zeeb static int
lkpi_sta_auth_to_init(struct ieee80211vap * vap,enum ieee80211_state nstate,int arg)24916b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
24926b4cac81SBjoern A. Zeeb {
24936b4cac81SBjoern A. Zeeb int error;
24946b4cac81SBjoern A. Zeeb
24956b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_scan(vap, nstate, arg);
24966b4cac81SBjoern A. Zeeb if (error == 0)
24976b4cac81SBjoern A. Zeeb error = lkpi_sta_scan_to_init(vap, nstate, arg);
24986b4cac81SBjoern A. Zeeb return (error);
24996b4cac81SBjoern A. Zeeb }
25006b4cac81SBjoern A. Zeeb
25016b4cac81SBjoern A. Zeeb static int
lkpi_sta_auth_to_assoc(struct ieee80211vap * vap,enum ieee80211_state nstate,int arg)25026b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
25036b4cac81SBjoern A. Zeeb {
25046b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
25056b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw;
25066b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
25076b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif;
25086b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta;
25096b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info;
25106b4cac81SBjoern A. Zeeb int error;
25116b4cac81SBjoern A. Zeeb
25126b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc;
25136b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
25146b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
25156b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
25166b4cac81SBjoern A. Zeeb
25176b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic);
2518cd0fcf9fSBjoern A. Zeeb wiphy_lock(hw->wiphy);
25192ac8a218SBjoern A. Zeeb
25202ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif);
25212ac8a218SBjoern A. Zeeb /* XXX-BZ KASSERT later? */
25222ac8a218SBjoern A. Zeeb if (!lvif->lvif_bss_synched || lvif->lvif_bss == NULL) {
25232ac8a218SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
25242ac8a218SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p "
25252ac8a218SBjoern A. Zeeb "lvif_bss->ni %p synched %d\n", __func__, __LINE__,
25262ac8a218SBjoern A. Zeeb lvif, vap, vap->iv_bss, lvif->lvif_bss,
25272ac8a218SBjoern A. Zeeb (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL,
25282ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched);
25292ac8a218SBjoern A. Zeeb #endif
25302ac8a218SBjoern A. Zeeb error = ENOTRECOVERABLE;
25312ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif);
25322ac8a218SBjoern A. Zeeb goto out;
25332ac8a218SBjoern A. Zeeb }
25342ac8a218SBjoern A. Zeeb lsta = lvif->lvif_bss;
25352ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif);
25362ac8a218SBjoern A. Zeeb
25372ac8a218SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: lsta %p\n", __func__, lsta));
25386b4cac81SBjoern A. Zeeb
25396b4cac81SBjoern A. Zeeb /* Finish auth. */
25406b4cac81SBjoern A. Zeeb IMPROVE("event callback");
25416b4cac81SBjoern A. Zeeb
25426b4cac81SBjoern A. Zeeb /* Update sta_state (NONE to AUTH). */
25436b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not "
25446b4cac81SBjoern A. Zeeb "NONE: %#x\n", __func__, lsta, lsta->state));
2545e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH);
2546018d93ecSBjoern A. Zeeb if (error != 0) {
2547018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTH) "
2548018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error);
25496b4cac81SBjoern A. Zeeb goto out;
2550018d93ecSBjoern A. Zeeb }
25516b4cac81SBjoern A. Zeeb
25526b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */
25536b4cac81SBjoern A. Zeeb if (lsta->in_mgd) {
25546b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info));
25556b4cac81SBjoern A. Zeeb prep_tx_info.success = true;
25566b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info);
25576b4cac81SBjoern A. Zeeb lsta->in_mgd = false;
25586b4cac81SBjoern A. Zeeb }
25596b4cac81SBjoern A. Zeeb
25606b4cac81SBjoern A. Zeeb /* Now start assoc. */
25616b4cac81SBjoern A. Zeeb
25626b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */
25636b4cac81SBjoern A. Zeeb if (!lsta->in_mgd) {
25646b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info));
25656b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION;
25666b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info);
25676b4cac81SBjoern A. Zeeb lsta->in_mgd = true;
25686b4cac81SBjoern A. Zeeb }
25696b4cac81SBjoern A. Zeeb
25706b4cac81SBjoern A. Zeeb /* Wake tx queue to get packet out. */
257188665349SBjoern A. Zeeb lkpi_wake_tx_queues(hw, LSTA_TO_STA(lsta), false, true);
25726b4cac81SBjoern A. Zeeb
25736b4cac81SBjoern A. Zeeb /*
25746b4cac81SBjoern A. Zeeb * <twiddle> .. we end up in "assoc_to_run"
25756b4cac81SBjoern A. Zeeb * - update sta_state (AUTH to ASSOC)
25766b4cac81SBjoern A. Zeeb * - conf_tx [all]
25776b4cac81SBjoern A. Zeeb * - bss_info_changed (assoc, aid, ssid, ..)
25786b4cac81SBjoern A. Zeeb * - change_chanctx (if needed)
25796b4cac81SBjoern A. Zeeb * - event_callback
25806b4cac81SBjoern A. Zeeb * - mgd_complete_tx
25816b4cac81SBjoern A. Zeeb */
25826b4cac81SBjoern A. Zeeb
25836b4cac81SBjoern A. Zeeb out:
2584cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
25856b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic);
25866b4cac81SBjoern A. Zeeb return (error);
25876b4cac81SBjoern A. Zeeb }
25886b4cac81SBjoern A. Zeeb
25896b4cac81SBjoern A. Zeeb /* auth_to_auth, assoc_to_assoc. */
25906b4cac81SBjoern A. Zeeb static int
lkpi_sta_a_to_a(struct ieee80211vap * vap,enum ieee80211_state nstate,int arg)25916b4cac81SBjoern A. Zeeb lkpi_sta_a_to_a(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
25926b4cac81SBjoern A. Zeeb {
25936b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
25946b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw;
25956b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
25966b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif;
25976b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta;
25986b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info;
25992ac8a218SBjoern A. Zeeb int error;
26006b4cac81SBjoern A. Zeeb
26016b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc;
26026b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
26036b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
26046b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
26056b4cac81SBjoern A. Zeeb
26066b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic);
2607cd0fcf9fSBjoern A. Zeeb wiphy_lock(hw->wiphy);
26082ac8a218SBjoern A. Zeeb
26092ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif);
26102ac8a218SBjoern A. Zeeb /* XXX-BZ KASSERT later? */
26112ac8a218SBjoern A. Zeeb if (!lvif->lvif_bss_synched || lvif->lvif_bss == NULL) {
26122ac8a218SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
26132ac8a218SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p "
26142ac8a218SBjoern A. Zeeb "lvif_bss->ni %p synched %d\n", __func__, __LINE__,
26152ac8a218SBjoern A. Zeeb lvif, vap, vap->iv_bss, lvif->lvif_bss,
26162ac8a218SBjoern A. Zeeb (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL,
26172ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched);
26182ac8a218SBjoern A. Zeeb #endif
26192ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif);
26202ac8a218SBjoern A. Zeeb error = ENOTRECOVERABLE;
26212ac8a218SBjoern A. Zeeb goto out;
26222ac8a218SBjoern A. Zeeb }
26232ac8a218SBjoern A. Zeeb lsta = lvif->lvif_bss;
26242ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif);
26252ac8a218SBjoern A. Zeeb
26262ac8a218SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: lsta %p! lvif %p vap %p\n", __func__,
26272ac8a218SBjoern A. Zeeb lsta, lvif, vap));
26286b4cac81SBjoern A. Zeeb
26296b4cac81SBjoern A. Zeeb IMPROVE("event callback?");
26306b4cac81SBjoern A. Zeeb
26316b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */
26326b4cac81SBjoern A. Zeeb if (lsta->in_mgd) {
26336b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info));
26346b4cac81SBjoern A. Zeeb prep_tx_info.success = false;
26356b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info);
26366b4cac81SBjoern A. Zeeb lsta->in_mgd = false;
26376b4cac81SBjoern A. Zeeb }
26386b4cac81SBjoern A. Zeeb
26396b4cac81SBjoern A. Zeeb /* Now start assoc. */
26406b4cac81SBjoern A. Zeeb
26416b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */
26426b4cac81SBjoern A. Zeeb if (!lsta->in_mgd) {
26436b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info));
26446b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION;
26456b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info);
26466b4cac81SBjoern A. Zeeb lsta->in_mgd = true;
26476b4cac81SBjoern A. Zeeb }
26486b4cac81SBjoern A. Zeeb
26492ac8a218SBjoern A. Zeeb error = 0;
26502ac8a218SBjoern A. Zeeb out:
2651cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
26526b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic);
26536b4cac81SBjoern A. Zeeb
26542ac8a218SBjoern A. Zeeb return (error);
26556b4cac81SBjoern A. Zeeb }
26566b4cac81SBjoern A. Zeeb
26576b4cac81SBjoern A. Zeeb static int
_lkpi_sta_assoc_to_down(struct ieee80211vap * vap,enum ieee80211_state nstate,int arg)2658d9f59799SBjoern A. Zeeb _lkpi_sta_assoc_to_down(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
26596b4cac81SBjoern A. Zeeb {
26606b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
26616b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw;
26626b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
26636b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif;
26646b4cac81SBjoern A. Zeeb struct ieee80211_node *ni;
26656b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta;
26666b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta;
26676b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info;
2668d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed;
26696b4cac81SBjoern A. Zeeb int error;
26706b4cac81SBjoern A. Zeeb
26716b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc;
26726b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
26736b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
26746b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
26756b4cac81SBjoern A. Zeeb
26762ac8a218SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic);
2677cd0fcf9fSBjoern A. Zeeb wiphy_lock(hw->wiphy);
26782ac8a218SBjoern A. Zeeb
26792ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif);
26802ac8a218SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
26812ac8a218SBjoern A. Zeeb /* XXX-BZ KASSERT later; state going down so no action. */
26822ac8a218SBjoern A. Zeeb if (lvif->lvif_bss == NULL)
26832ac8a218SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p "
26842ac8a218SBjoern A. Zeeb "lvif_bss->ni %p synched %d\n", __func__, __LINE__,
26852ac8a218SBjoern A. Zeeb lvif, vap, vap->iv_bss, lvif->lvif_bss,
26862ac8a218SBjoern A. Zeeb (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL,
26872ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched);
26882ac8a218SBjoern A. Zeeb #endif
26892ac8a218SBjoern A. Zeeb lsta = lvif->lvif_bss;
26902ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif);
26912ac8a218SBjoern A. Zeeb KASSERT(lsta != NULL && lsta->ni != NULL, ("%s: lsta %p ni %p "
26922ac8a218SBjoern A. Zeeb "lvif %p vap %p\n", __func__,
26932ac8a218SBjoern A. Zeeb lsta, (lsta != NULL) ? lsta->ni : NULL, lvif, vap));
26942ac8a218SBjoern A. Zeeb
26952ac8a218SBjoern A. Zeeb ni = lsta->ni; /* Reference held for lvif_bss. */
26966b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta);
26976b4cac81SBjoern A. Zeeb
269867674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
2699d9f59799SBjoern A. Zeeb
2700d9f59799SBjoern A. Zeeb /* flush, drop. */
2701d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true);
2702d9f59799SBjoern A. Zeeb
2703d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?");
2704d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) &&
2705d9f59799SBjoern A. Zeeb !lsta->in_mgd) {
2706d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info));
2707d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION;
2708ac1d519cSBjoern A. Zeeb prep_tx_info.was_assoc = true;
2709d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info);
2710d9f59799SBjoern A. Zeeb lsta->in_mgd = true;
2711d9f59799SBjoern A. Zeeb }
2712d9f59799SBjoern A. Zeeb
2713cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
2714d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic);
2715d9f59799SBjoern A. Zeeb
271688665349SBjoern A. Zeeb /* Call iv_newstate first so we get potential DEAUTH packet out. */
2717d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg);
2718018d93ecSBjoern A. Zeeb if (error != 0) {
2719018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: iv_newstate(%p, %d, %d) "
2720018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, vap, nstate, arg, error);
2721d9f59799SBjoern A. Zeeb goto outni;
2722018d93ecSBjoern A. Zeeb }
2723d9f59799SBjoern A. Zeeb
2724d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic);
272588665349SBjoern A. Zeeb
272688665349SBjoern A. Zeeb /* Ensure the packets get out. */
272788665349SBjoern A. Zeeb lkpi_80211_flush_tx(lhw, lsta);
272888665349SBjoern A. Zeeb
2729cd0fcf9fSBjoern A. Zeeb wiphy_lock(hw->wiphy);
2730d9f59799SBjoern A. Zeeb
273167674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
2732d9f59799SBjoern A. Zeeb
2733d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */
273488665349SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, false, true);
2735d9f59799SBjoern A. Zeeb
2736d9f59799SBjoern A. Zeeb /* flush, no drop */
2737d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false);
2738d9f59799SBjoern A. Zeeb
27396b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */
27406b4cac81SBjoern A. Zeeb if (lsta->in_mgd) {
27416b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info));
27426b4cac81SBjoern A. Zeeb prep_tx_info.success = false;
2743ac1d519cSBjoern A. Zeeb prep_tx_info.was_assoc = true;
27446b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info);
27456b4cac81SBjoern A. Zeeb lsta->in_mgd = false;
27466b4cac81SBjoern A. Zeeb }
27476b4cac81SBjoern A. Zeeb
2748d9f59799SBjoern A. Zeeb /* sync_rx_queues */
2749d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw);
2750d9f59799SBjoern A. Zeeb
2751d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */
2752d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta);
2753d9f59799SBjoern A. Zeeb
2754d9f59799SBjoern A. Zeeb /* Take the station down. */
2755d9f59799SBjoern A. Zeeb
27566b4cac81SBjoern A. Zeeb /* Update sta and change state (from AUTH) to NONE. */
27576b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
27586b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not "
27596b4cac81SBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state));
2760e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE);
2761018d93ecSBjoern A. Zeeb if (error != 0) {
2762018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NONE) "
2763018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error);
27646b4cac81SBjoern A. Zeeb goto out;
2765018d93ecSBjoern A. Zeeb }
27666b4cac81SBjoern A. Zeeb
27675a4d2461SBjoern A. Zeeb /* See comment in lkpi_sta_run_to_init(). */
27685a4d2461SBjoern A. Zeeb bss_changed = 0;
27695a4d2461SBjoern A. Zeeb bss_changed |= lkpi_disassoc(sta, vif, lhw);
27706b4cac81SBjoern A. Zeeb
27715a4d2461SBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
277216e688b2SBjoern A. Zeeb
2773d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */
2774d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
2775d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not "
2776d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg));
2777e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST);
2778d9f59799SBjoern A. Zeeb if (error != 0) {
2779d9f59799SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?");
2780018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NOTEXIST) "
2781018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error);
2782d9f59799SBjoern A. Zeeb goto out;
2783d9f59799SBjoern A. Zeeb }
2784d9f59799SBjoern A. Zeeb
278516e688b2SBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); /* sta no longer save to use. */
2786d9f59799SBjoern A. Zeeb
2787d9f59799SBjoern A. Zeeb IMPROVE("Any bss_info changes to announce?");
2788d9f59799SBjoern A. Zeeb vif->bss_conf.qos = 0;
2789d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS;
2790616e1330SBjoern A. Zeeb vif->cfg.ssid_len = 0;
2791616e1330SBjoern A. Zeeb memset(vif->cfg.ssid, '\0', sizeof(vif->cfg.ssid));
2792d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID;
2793d9f59799SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed);
2794d9f59799SBjoern A. Zeeb
27952ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif);
27962ac8a218SBjoern A. Zeeb /* Remove ni reference for this cache of lsta. */
27972ac8a218SBjoern A. Zeeb lvif->lvif_bss = NULL;
27982ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched = false;
27992ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif);
2800d9f59799SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif);
28010936c648SBjoern A. Zeeb /*
28020936c648SBjoern A. Zeeb * The very last release the reference on the ni for the ni/lsta on
28030936c648SBjoern A. Zeeb * lvif->lvif_bss. Upon return from this both ni and lsta are invalid
28040936c648SBjoern A. Zeeb * and potentially freed.
28050936c648SBjoern A. Zeeb */
28060936c648SBjoern A. Zeeb ieee80211_free_node(ni);
2807d9f59799SBjoern A. Zeeb
2808d9f59799SBjoern A. Zeeb /* conf_tx */
2809d9f59799SBjoern A. Zeeb
281050d826beSBjoern A. Zeeb lkpi_remove_chanctx(hw, vif);
2811d9f59799SBjoern A. Zeeb
2812d9f59799SBjoern A. Zeeb error = EALREADY;
28136b4cac81SBjoern A. Zeeb out:
2814cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
28156b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic);
2816d9f59799SBjoern A. Zeeb outni:
28176b4cac81SBjoern A. Zeeb return (error);
28186b4cac81SBjoern A. Zeeb }
28196b4cac81SBjoern A. Zeeb
28206b4cac81SBjoern A. Zeeb static int
lkpi_sta_assoc_to_auth(struct ieee80211vap * vap,enum ieee80211_state nstate,int arg)2821d9f59799SBjoern A. Zeeb lkpi_sta_assoc_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
2822d9f59799SBjoern A. Zeeb {
2823d9f59799SBjoern A. Zeeb int error;
2824d9f59799SBjoern A. Zeeb
2825d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg);
2826d9f59799SBjoern A. Zeeb if (error != 0 && error != EALREADY)
2827d9f59799SBjoern A. Zeeb return (error);
2828d9f59799SBjoern A. Zeeb
2829d9f59799SBjoern A. Zeeb /* At this point iv_bss is long a new node! */
2830d9f59799SBjoern A. Zeeb
2831d9f59799SBjoern A. Zeeb error |= lkpi_sta_scan_to_auth(vap, nstate, 0);
2832d9f59799SBjoern A. Zeeb return (error);
2833d9f59799SBjoern A. Zeeb }
2834d9f59799SBjoern A. Zeeb
2835d9f59799SBjoern A. Zeeb static int
lkpi_sta_assoc_to_scan(struct ieee80211vap * vap,enum ieee80211_state nstate,int arg)28366b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
28376b4cac81SBjoern A. Zeeb {
28386b4cac81SBjoern A. Zeeb int error;
28396b4cac81SBjoern A. Zeeb
2840d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg);
28416b4cac81SBjoern A. Zeeb return (error);
28426b4cac81SBjoern A. Zeeb }
28436b4cac81SBjoern A. Zeeb
28446b4cac81SBjoern A. Zeeb static int
lkpi_sta_assoc_to_init(struct ieee80211vap * vap,enum ieee80211_state nstate,int arg)28456b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
28466b4cac81SBjoern A. Zeeb {
28476b4cac81SBjoern A. Zeeb int error;
28486b4cac81SBjoern A. Zeeb
2849d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg);
28506b4cac81SBjoern A. Zeeb return (error);
28516b4cac81SBjoern A. Zeeb }
28526b4cac81SBjoern A. Zeeb
28536b4cac81SBjoern A. Zeeb static int
lkpi_sta_assoc_to_run(struct ieee80211vap * vap,enum ieee80211_state nstate,int arg)28546b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
28556b4cac81SBjoern A. Zeeb {
28566b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
28576b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw;
28586b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
28596b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif;
28606b4cac81SBjoern A. Zeeb struct ieee80211_node *ni;
28616b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta;
28626b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta;
28636b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info;
28646b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed;
28656b4cac81SBjoern A. Zeeb int error;
28666b4cac81SBjoern A. Zeeb
28676b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc;
28686b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
28696b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
28706b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
28716b4cac81SBjoern A. Zeeb
28726b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic);
2873cd0fcf9fSBjoern A. Zeeb wiphy_lock(hw->wiphy);
28742ac8a218SBjoern A. Zeeb
28752ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif);
28762ac8a218SBjoern A. Zeeb /* XXX-BZ KASSERT later? */
28772ac8a218SBjoern A. Zeeb if (!lvif->lvif_bss_synched || lvif->lvif_bss == NULL) {
28782ac8a218SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
28792ac8a218SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p "
28802ac8a218SBjoern A. Zeeb "lvif_bss->ni %p synched %d\n", __func__, __LINE__,
28812ac8a218SBjoern A. Zeeb lvif, vap, vap->iv_bss, lvif->lvif_bss,
28822ac8a218SBjoern A. Zeeb (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL,
28832ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched);
28842ac8a218SBjoern A. Zeeb #endif
28852ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif);
28862ac8a218SBjoern A. Zeeb error = ENOTRECOVERABLE;
28872ac8a218SBjoern A. Zeeb goto out;
28882ac8a218SBjoern A. Zeeb }
28892ac8a218SBjoern A. Zeeb lsta = lvif->lvif_bss;
28902ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif);
28912ac8a218SBjoern A. Zeeb KASSERT(lsta != NULL && lsta->ni != NULL, ("%s: lsta %p ni %p "
28922ac8a218SBjoern A. Zeeb "lvif %p vap %p\n", __func__,
28932ac8a218SBjoern A. Zeeb lsta, (lsta != NULL) ? lsta->ni : NULL, lvif, vap));
28942ac8a218SBjoern A. Zeeb
28952ac8a218SBjoern A. Zeeb ni = lsta->ni; /* Reference held for lvif_bss. */
28966b4cac81SBjoern A. Zeeb
28976b4cac81SBjoern A. Zeeb IMPROVE("ponder some of this moved to ic_newassoc, scan_assoc_success, "
28986b4cac81SBjoern A. Zeeb "and to lesser extend ieee80211_notify_node_join");
28996b4cac81SBjoern A. Zeeb
29009597f7cbSBjoern A. Zeeb /* Finish assoc. */
29019597f7cbSBjoern A. Zeeb /* Update sta_state (AUTH to ASSOC) and set aid. */
29029597f7cbSBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not "
29039597f7cbSBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state));
29046b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta);
29059597f7cbSBjoern A. Zeeb sta->aid = IEEE80211_NODE_AID(ni);
29064a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME
29074a67f1dfSBjoern A. Zeeb if (vap->iv_flags & IEEE80211_F_WME)
29084a67f1dfSBjoern A. Zeeb sta->wme = true;
29094a67f1dfSBjoern A. Zeeb #endif
2910e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC);
2911018d93ecSBjoern A. Zeeb if (error != 0) {
2912018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(ASSOC) "
2913018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error);
29149597f7cbSBjoern A. Zeeb goto out;
2915018d93ecSBjoern A. Zeeb }
29166b4cac81SBjoern A. Zeeb
29176b4cac81SBjoern A. Zeeb IMPROVE("wme / conf_tx [all]");
29186b4cac81SBjoern A. Zeeb
29196b4cac81SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */
29206b4cac81SBjoern A. Zeeb bss_changed = 0;
29214a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME
29224a67f1dfSBjoern A. Zeeb bss_changed |= lkpi_wme_update(lhw, vap, true);
29234a67f1dfSBjoern A. Zeeb #endif
2924616e1330SBjoern A. Zeeb if (!vif->cfg.assoc || vif->cfg.aid != IEEE80211_NODE_AID(ni)) {
2925616e1330SBjoern A. Zeeb vif->cfg.assoc = true;
2926616e1330SBjoern A. Zeeb vif->cfg.aid = IEEE80211_NODE_AID(ni);
29276b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_ASSOC;
29286b4cac81SBjoern A. Zeeb }
29296b4cac81SBjoern A. Zeeb /* We set SSID but this is not BSSID! */
2930616e1330SBjoern A. Zeeb vif->cfg.ssid_len = ni->ni_esslen;
2931616e1330SBjoern A. Zeeb memcpy(vif->cfg.ssid, ni->ni_essid, ni->ni_esslen);
29326b4cac81SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_SHPREAMBLE) !=
29336b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble) {
29346b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble ^= 1;
29356b4cac81SBjoern A. Zeeb /* bss_changed |= BSS_CHANGED_??? */
29366b4cac81SBjoern A. Zeeb }
29376b4cac81SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_SHSLOT) !=
29386b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot) {
29396b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot ^= 1;
29406b4cac81SBjoern A. Zeeb /* bss_changed |= BSS_CHANGED_??? */
29416b4cac81SBjoern A. Zeeb }
29426b4cac81SBjoern A. Zeeb if ((ni->ni_flags & IEEE80211_NODE_QOS) !=
29436b4cac81SBjoern A. Zeeb vif->bss_conf.qos) {
29446b4cac81SBjoern A. Zeeb vif->bss_conf.qos ^= 1;
29456b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS;
29466b4cac81SBjoern A. Zeeb }
2947fa8f007dSBjoern A. Zeeb
2948fa8f007dSBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__);
29496b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed);
29506b4cac81SBjoern A. Zeeb
29516b4cac81SBjoern A. Zeeb /* - change_chanctx (if needed)
29526b4cac81SBjoern A. Zeeb * - event_callback
29536b4cac81SBjoern A. Zeeb */
29546b4cac81SBjoern A. Zeeb
29556b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */
29566b4cac81SBjoern A. Zeeb if (lsta->in_mgd) {
29576b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info));
29586b4cac81SBjoern A. Zeeb prep_tx_info.success = true;
29596b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info);
29606b4cac81SBjoern A. Zeeb lsta->in_mgd = false;
29616b4cac81SBjoern A. Zeeb }
29626b4cac81SBjoern A. Zeeb
2963086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, false);
2964086be6a8SBjoern A. Zeeb
29656b4cac81SBjoern A. Zeeb /*
29666b4cac81SBjoern A. Zeeb * And then:
29676b4cac81SBjoern A. Zeeb * - (more packets)?
29686b4cac81SBjoern A. Zeeb * - set_key
29696b4cac81SBjoern A. Zeeb * - set_default_unicast_key
29706b4cac81SBjoern A. Zeeb * - set_key (?)
29716b4cac81SBjoern A. Zeeb * - ipv6_addr_change (?)
29726b4cac81SBjoern A. Zeeb */
29736b4cac81SBjoern A. Zeeb /* Prepare_multicast && configure_filter. */
29746b4cac81SBjoern A. Zeeb lhw->update_mc = true;
29756b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(vap->iv_ic, true);
29766b4cac81SBjoern A. Zeeb
29776b4cac81SBjoern A. Zeeb if (!ieee80211_node_is_authorized(ni)) {
29786b4cac81SBjoern A. Zeeb IMPROVE("net80211 does not consider node authorized");
29796b4cac81SBjoern A. Zeeb }
29806b4cac81SBjoern A. Zeeb
29819fb91463SBjoern A. Zeeb IMPROVE("Is this the right spot, has net80211 done all updates already?");
298262d51a43SBjoern A. Zeeb lkpi_sta_sync_from_ni(hw, vif, sta, ni, true);
29839fb91463SBjoern A. Zeeb
2984*6e7a6a66SBjoern A. Zeeb /* Update thresholds. */
2985*6e7a6a66SBjoern A. Zeeb hw->wiphy->frag_threshold = vap->iv_fragthreshold;
2986*6e7a6a66SBjoern A. Zeeb lkpi_80211_mo_set_frag_threshold(hw, vap->iv_fragthreshold);
2987*6e7a6a66SBjoern A. Zeeb hw->wiphy->rts_threshold = vap->iv_rtsthreshold;
2988*6e7a6a66SBjoern A. Zeeb lkpi_80211_mo_set_rts_threshold(hw, vap->iv_rtsthreshold);
2989*6e7a6a66SBjoern A. Zeeb
29906b4cac81SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTHORIZED). */
29916b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
29926b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not "
29936b4cac81SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state));
2994e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTHORIZED);
29956b4cac81SBjoern A. Zeeb if (error != 0) {
29966b4cac81SBjoern A. Zeeb IMPROVE("undo some changes?");
2997018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTHORIZED) "
2998018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error);
29996b4cac81SBjoern A. Zeeb goto out;
30006b4cac81SBjoern A. Zeeb }
30016b4cac81SBjoern A. Zeeb
30026b4cac81SBjoern A. Zeeb /* - drv_config (?)
30036b4cac81SBjoern A. Zeeb * - bss_info_changed
30046b4cac81SBjoern A. Zeeb * - set_rekey_data (?)
30056b4cac81SBjoern A. Zeeb *
30066b4cac81SBjoern A. Zeeb * And now we should be passing packets.
30076b4cac81SBjoern A. Zeeb */
30086b4cac81SBjoern A. Zeeb IMPROVE("Need that bssid setting, and the keys");
30096b4cac81SBjoern A. Zeeb
3010fa8f007dSBjoern A. Zeeb bss_changed = 0;
3011fa8f007dSBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__);
3012fa8f007dSBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed);
3013fa8f007dSBjoern A. Zeeb
30146b4cac81SBjoern A. Zeeb out:
3015cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
30166b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic);
30176b4cac81SBjoern A. Zeeb return (error);
30186b4cac81SBjoern A. Zeeb }
30196b4cac81SBjoern A. Zeeb
30206b4cac81SBjoern A. Zeeb static int
lkpi_sta_auth_to_run(struct ieee80211vap * vap,enum ieee80211_state nstate,int arg)30216b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
30226b4cac81SBjoern A. Zeeb {
30236b4cac81SBjoern A. Zeeb int error;
30246b4cac81SBjoern A. Zeeb
30256b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_assoc(vap, nstate, arg);
30266b4cac81SBjoern A. Zeeb if (error == 0)
30276b4cac81SBjoern A. Zeeb error = lkpi_sta_assoc_to_run(vap, nstate, arg);
30286b4cac81SBjoern A. Zeeb return (error);
30296b4cac81SBjoern A. Zeeb }
30306b4cac81SBjoern A. Zeeb
30316b4cac81SBjoern A. Zeeb static int
lkpi_sta_run_to_assoc(struct ieee80211vap * vap,enum ieee80211_state nstate,int arg)30326b4cac81SBjoern A. Zeeb lkpi_sta_run_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
30336b4cac81SBjoern A. Zeeb {
30346b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
30356b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw;
30366b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
30376b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif;
30386b4cac81SBjoern A. Zeeb struct ieee80211_node *ni;
30396b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta;
30406b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta;
3041d9f59799SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info;
3042d9f59799SBjoern A. Zeeb #if 0
3043d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed;
3044d9f59799SBjoern A. Zeeb #endif
30456b4cac81SBjoern A. Zeeb int error;
30466b4cac81SBjoern A. Zeeb
30476b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc;
30486b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
30496b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
30506b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
30516b4cac81SBjoern A. Zeeb
30522ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif);
30532ac8a218SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
30542ac8a218SBjoern A. Zeeb /* XXX-BZ KASSERT later; state going down so no action. */
30552ac8a218SBjoern A. Zeeb if (lvif->lvif_bss == NULL)
30562ac8a218SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p "
30572ac8a218SBjoern A. Zeeb "lvif_bss->ni %p synched %d\n", __func__, __LINE__,
30582ac8a218SBjoern A. Zeeb lvif, vap, vap->iv_bss, lvif->lvif_bss,
30592ac8a218SBjoern A. Zeeb (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL,
30602ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched);
30612ac8a218SBjoern A. Zeeb #endif
30622ac8a218SBjoern A. Zeeb lsta = lvif->lvif_bss;
30632ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif);
30642ac8a218SBjoern A. Zeeb KASSERT(lsta != NULL && lsta->ni != NULL, ("%s: lsta %p ni %p "
30652ac8a218SBjoern A. Zeeb "lvif %p vap %p\n", __func__,
30662ac8a218SBjoern A. Zeeb lsta, (lsta != NULL) ? lsta->ni : NULL, lvif, vap));
30672ac8a218SBjoern A. Zeeb
30682ac8a218SBjoern A. Zeeb ni = lsta->ni; /* Reference held for lvif_bss. */
30696b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta);
30706b4cac81SBjoern A. Zeeb
307167674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
3072d9f59799SBjoern A. Zeeb
3073d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic);
3074cd0fcf9fSBjoern A. Zeeb wiphy_lock(hw->wiphy);
3075d9f59799SBjoern A. Zeeb
3076d9f59799SBjoern A. Zeeb /* flush, drop. */
3077d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true);
3078d9f59799SBjoern A. Zeeb
3079d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?");
3080d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) &&
3081d9f59799SBjoern A. Zeeb !lsta->in_mgd) {
3082d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info));
3083d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION;
3084ac1d519cSBjoern A. Zeeb prep_tx_info.was_assoc = true;
3085d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info);
3086d9f59799SBjoern A. Zeeb lsta->in_mgd = true;
3087d9f59799SBjoern A. Zeeb }
3088d9f59799SBjoern A. Zeeb
3089cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
3090d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic);
3091d9f59799SBjoern A. Zeeb
3092d9f59799SBjoern A. Zeeb /* Call iv_newstate first so we get potential DISASSOC packet out. */
3093d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg);
3094018d93ecSBjoern A. Zeeb if (error != 0) {
3095018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: iv_newstate(%p, %d, %d) "
3096018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, vap, nstate, arg, error);
3097d9f59799SBjoern A. Zeeb goto outni;
3098018d93ecSBjoern A. Zeeb }
3099d9f59799SBjoern A. Zeeb
3100d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic);
310188665349SBjoern A. Zeeb
310288665349SBjoern A. Zeeb /* Ensure the packets get out. */
310388665349SBjoern A. Zeeb lkpi_80211_flush_tx(lhw, lsta);
310488665349SBjoern A. Zeeb
3105cd0fcf9fSBjoern A. Zeeb wiphy_lock(hw->wiphy);
3106d9f59799SBjoern A. Zeeb
310767674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
3108d9f59799SBjoern A. Zeeb
3109d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */
311088665349SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, false, true);
3111d9f59799SBjoern A. Zeeb
3112d9f59799SBjoern A. Zeeb /* flush, no drop */
3113d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false);
3114d9f59799SBjoern A. Zeeb
3115d9f59799SBjoern A. Zeeb /* End mgd_complete_tx. */
3116d9f59799SBjoern A. Zeeb if (lsta->in_mgd) {
3117d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info));
3118d9f59799SBjoern A. Zeeb prep_tx_info.success = false;
3119ac1d519cSBjoern A. Zeeb prep_tx_info.was_assoc = true;
3120d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info);
3121d9f59799SBjoern A. Zeeb lsta->in_mgd = false;
3122d9f59799SBjoern A. Zeeb }
3123d9f59799SBjoern A. Zeeb
3124d9f59799SBjoern A. Zeeb #if 0
3125d9f59799SBjoern A. Zeeb /* sync_rx_queues */
3126d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw);
3127d9f59799SBjoern A. Zeeb
3128d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */
3129d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta);
3130d9f59799SBjoern A. Zeeb #endif
3131d9f59799SBjoern A. Zeeb
3132d9f59799SBjoern A. Zeeb /* Take the station down. */
3133d9f59799SBjoern A. Zeeb
31346b4cac81SBjoern A. Zeeb /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */
31356b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
31366b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not "
31376b4cac81SBjoern A. Zeeb "AUTHORIZED: %#x\n", __func__, lsta, lsta->state));
3138e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC);
3139018d93ecSBjoern A. Zeeb if (error != 0) {
3140018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(ASSOC) "
3141018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error);
31426b4cac81SBjoern A. Zeeb goto out;
3143018d93ecSBjoern A. Zeeb }
31446b4cac81SBjoern A. Zeeb
314567674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
31466b4cac81SBjoern A. Zeeb
314711db70b6SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO
314811db70b6SBjoern A. Zeeb if (lkpi_hwcrypto) {
314911db70b6SBjoern A. Zeeb error = lkpi_sta_del_keys(hw, vif, lsta);
315011db70b6SBjoern A. Zeeb if (error != 0) {
315111db70b6SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lkpi_sta_del_keys "
315211db70b6SBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error);
315311db70b6SBjoern A. Zeeb /*
315411db70b6SBjoern A. Zeeb * Either drv/fw will crash or cleanup itself,
315511db70b6SBjoern A. Zeeb * otherwise net80211 will delete the keys (at a
315611db70b6SBjoern A. Zeeb * less appropriate time).
315711db70b6SBjoern A. Zeeb */
315811db70b6SBjoern A. Zeeb /* goto out; */
315911db70b6SBjoern A. Zeeb }
316011db70b6SBjoern A. Zeeb }
316111db70b6SBjoern A. Zeeb #endif
316211db70b6SBjoern A. Zeeb
31636b4cac81SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTH). */
31646b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
31656b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not "
31666b4cac81SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state));
3167e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH);
3168018d93ecSBjoern A. Zeeb if (error != 0) {
3169018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTH) "
3170018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error);
31716b4cac81SBjoern A. Zeeb goto out;
3172018d93ecSBjoern A. Zeeb }
31736b4cac81SBjoern A. Zeeb
317467674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
31756b4cac81SBjoern A. Zeeb
3176d9f59799SBjoern A. Zeeb #if 0
3177d9f59799SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */
3178d9f59799SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw);
3179d9f59799SBjoern A. Zeeb #endif
3180d9f59799SBjoern A. Zeeb
3181d9f59799SBjoern A. Zeeb error = EALREADY;
31826b4cac81SBjoern A. Zeeb out:
3183cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
31846b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic);
3185d9f59799SBjoern A. Zeeb outni:
31866b4cac81SBjoern A. Zeeb return (error);
31876b4cac81SBjoern A. Zeeb }
31886b4cac81SBjoern A. Zeeb
31896b4cac81SBjoern A. Zeeb static int
lkpi_sta_run_to_init(struct ieee80211vap * vap,enum ieee80211_state nstate,int arg)3190d9f59799SBjoern A. Zeeb lkpi_sta_run_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
3191d9f59799SBjoern A. Zeeb {
3192d9f59799SBjoern A. Zeeb struct lkpi_hw *lhw;
3193d9f59799SBjoern A. Zeeb struct ieee80211_hw *hw;
3194d9f59799SBjoern A. Zeeb struct lkpi_vif *lvif;
3195d9f59799SBjoern A. Zeeb struct ieee80211_vif *vif;
3196d9f59799SBjoern A. Zeeb struct ieee80211_node *ni;
3197d9f59799SBjoern A. Zeeb struct lkpi_sta *lsta;
3198d9f59799SBjoern A. Zeeb struct ieee80211_sta *sta;
3199d9f59799SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info;
3200d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed;
3201d9f59799SBjoern A. Zeeb int error;
3202d9f59799SBjoern A. Zeeb
3203d9f59799SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc;
3204d9f59799SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
3205d9f59799SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
3206d9f59799SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
3207d9f59799SBjoern A. Zeeb
32082ac8a218SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic);
3209cd0fcf9fSBjoern A. Zeeb wiphy_lock(hw->wiphy);
32102ac8a218SBjoern A. Zeeb
32112ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif);
32122ac8a218SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
32132ac8a218SBjoern A. Zeeb /* XXX-BZ KASSERT later; state going down so no action. */
32142ac8a218SBjoern A. Zeeb if (lvif->lvif_bss == NULL)
32152ac8a218SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p "
32162ac8a218SBjoern A. Zeeb "lvif_bss->ni %p synched %d\n", __func__, __LINE__,
32172ac8a218SBjoern A. Zeeb lvif, vap, vap->iv_bss, lvif->lvif_bss,
32182ac8a218SBjoern A. Zeeb (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL,
32192ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched);
32202ac8a218SBjoern A. Zeeb #endif
32212ac8a218SBjoern A. Zeeb lsta = lvif->lvif_bss;
32222ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif);
32232ac8a218SBjoern A. Zeeb KASSERT(lsta != NULL && lsta->ni != NULL, ("%s: lsta %p ni %p "
32242ac8a218SBjoern A. Zeeb "lvif %p vap %p\n", __func__,
32252ac8a218SBjoern A. Zeeb lsta, (lsta != NULL) ? lsta->ni : NULL, lvif, vap));
32262ac8a218SBjoern A. Zeeb
32272ac8a218SBjoern A. Zeeb ni = lsta->ni; /* Reference held for lvif_bss. */
3228d9f59799SBjoern A. Zeeb sta = LSTA_TO_STA(lsta);
3229d9f59799SBjoern A. Zeeb
323067674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
3231d9f59799SBjoern A. Zeeb
3232d9f59799SBjoern A. Zeeb /* flush, drop. */
3233d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true);
3234d9f59799SBjoern A. Zeeb
3235d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?");
3236d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) &&
3237d9f59799SBjoern A. Zeeb !lsta->in_mgd) {
3238d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info));
3239d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION;
3240ac1d519cSBjoern A. Zeeb prep_tx_info.was_assoc = true;
3241d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info);
3242d9f59799SBjoern A. Zeeb lsta->in_mgd = true;
3243d9f59799SBjoern A. Zeeb }
3244d9f59799SBjoern A. Zeeb
3245cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
3246d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic);
3247d9f59799SBjoern A. Zeeb
3248d9f59799SBjoern A. Zeeb /* Call iv_newstate first so we get potential DISASSOC packet out. */
3249d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg);
3250018d93ecSBjoern A. Zeeb if (error != 0) {
3251018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: iv_newstate(%p, %d, %d) "
3252018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, vap, nstate, arg, error);
3253d9f59799SBjoern A. Zeeb goto outni;
3254018d93ecSBjoern A. Zeeb }
3255d9f59799SBjoern A. Zeeb
3256d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic);
325788665349SBjoern A. Zeeb
325888665349SBjoern A. Zeeb /* Ensure the packets get out. */
325988665349SBjoern A. Zeeb lkpi_80211_flush_tx(lhw, lsta);
326088665349SBjoern A. Zeeb
3261cd0fcf9fSBjoern A. Zeeb wiphy_lock(hw->wiphy);
3262d9f59799SBjoern A. Zeeb
326367674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
3264d9f59799SBjoern A. Zeeb
3265d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */
326688665349SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, false, true);
3267d9f59799SBjoern A. Zeeb
3268d9f59799SBjoern A. Zeeb /* flush, no drop */
3269d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false);
3270d9f59799SBjoern A. Zeeb
3271d9f59799SBjoern A. Zeeb /* End mgd_complete_tx. */
3272d9f59799SBjoern A. Zeeb if (lsta->in_mgd) {
3273d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info));
3274d9f59799SBjoern A. Zeeb prep_tx_info.success = false;
3275ac1d519cSBjoern A. Zeeb prep_tx_info.was_assoc = true;
3276d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info);
3277d9f59799SBjoern A. Zeeb lsta->in_mgd = false;
3278d9f59799SBjoern A. Zeeb }
3279d9f59799SBjoern A. Zeeb
3280d9f59799SBjoern A. Zeeb /* sync_rx_queues */
3281d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw);
3282d9f59799SBjoern A. Zeeb
3283d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */
3284d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta);
3285d9f59799SBjoern A. Zeeb
3286d9f59799SBjoern A. Zeeb /* Take the station down. */
3287d9f59799SBjoern A. Zeeb
3288d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */
3289d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
3290d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not "
3291d9f59799SBjoern A. Zeeb "AUTHORIZED: %#x\n", __func__, lsta, lsta->state));
3292e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC);
3293018d93ecSBjoern A. Zeeb if (error != 0) {
3294018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(ASSOC) "
3295018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error);
3296d9f59799SBjoern A. Zeeb goto out;
3297018d93ecSBjoern A. Zeeb }
3298d9f59799SBjoern A. Zeeb
329967674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
3300d9f59799SBjoern A. Zeeb
330111db70b6SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO
330211db70b6SBjoern A. Zeeb if (lkpi_hwcrypto) {
330311db70b6SBjoern A. Zeeb error = lkpi_sta_del_keys(hw, vif, lsta);
330411db70b6SBjoern A. Zeeb if (error != 0) {
330511db70b6SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lkpi_sta_del_keys "
330611db70b6SBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error);
330711db70b6SBjoern A. Zeeb /*
330811db70b6SBjoern A. Zeeb * Either drv/fw will crash or cleanup itself,
330911db70b6SBjoern A. Zeeb * otherwise net80211 will delete the keys (at a
331011db70b6SBjoern A. Zeeb * less appropriate time).
331111db70b6SBjoern A. Zeeb */
331211db70b6SBjoern A. Zeeb /* goto out; */
331311db70b6SBjoern A. Zeeb }
331411db70b6SBjoern A. Zeeb }
331511db70b6SBjoern A. Zeeb #endif
331611db70b6SBjoern A. Zeeb
3317d9f59799SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTH). */
3318d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
3319d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not "
3320d9f59799SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state));
3321e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH);
3322018d93ecSBjoern A. Zeeb if (error != 0) {
3323018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTH) "
3324018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error);
3325d9f59799SBjoern A. Zeeb goto out;
3326018d93ecSBjoern A. Zeeb }
3327d9f59799SBjoern A. Zeeb
332867674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
3329d9f59799SBjoern A. Zeeb
3330d9f59799SBjoern A. Zeeb /* Update sta and change state (from AUTH) to NONE. */
3331d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
3332d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not "
3333d9f59799SBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state));
3334e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE);
3335018d93ecSBjoern A. Zeeb if (error != 0) {
3336018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NONE) "
3337018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error);
3338d9f59799SBjoern A. Zeeb goto out;
3339018d93ecSBjoern A. Zeeb }
3340d9f59799SBjoern A. Zeeb
33415a4d2461SBjoern A. Zeeb bss_changed = 0;
334216e688b2SBjoern A. Zeeb /*
33435a4d2461SBjoern A. Zeeb * Start updating bss info (bss_info_changed) (assoc, aid, ..).
33445a4d2461SBjoern A. Zeeb *
334516e688b2SBjoern A. Zeeb * One would expect this to happen when going off AUTHORIZED.
33465a4d2461SBjoern A. Zeeb * See comment there; removes the sta from fw if not careful
33475a4d2461SBjoern A. Zeeb * (bss_info_changed() change is executed right away).
33485a4d2461SBjoern A. Zeeb *
33495a4d2461SBjoern A. Zeeb * We need to do this now, before sta changes to IEEE80211_STA_NOTEXIST
33505a4d2461SBjoern A. Zeeb * as otherwise drivers (iwlwifi at least) will silently not remove
33515a4d2461SBjoern A. Zeeb * the sta from the firmware and when we will add a new one trigger
33525a4d2461SBjoern A. Zeeb * a fw assert.
33535a4d2461SBjoern A. Zeeb *
33545a4d2461SBjoern A. Zeeb * The order which works best so far avoiding early removal or silent
33555a4d2461SBjoern A. Zeeb * non-removal seems to be (for iwlwifi::mld-mac80211.c cases;
33565a4d2461SBjoern A. Zeeb * the iwlwifi:mac80211.c case still to be tested):
33575a4d2461SBjoern A. Zeeb * 1) lkpi_disassoc(): set vif->cfg.assoc = false (aid=0 side effect here)
33585a4d2461SBjoern A. Zeeb * 2) call the last sta_state update -> IEEE80211_STA_NOTEXIST
33595a4d2461SBjoern A. Zeeb * (removes the sta given assoc is false)
33605a4d2461SBjoern A. Zeeb * 3) add the remaining BSS_CHANGED changes and call bss_info_changed()
33615a4d2461SBjoern A. Zeeb * 4) call unassign_vif_chanctx
33625a4d2461SBjoern A. Zeeb * 5) call lkpi_hw_conf_idle
33635a4d2461SBjoern A. Zeeb * 6) call remove_chanctx
336416e688b2SBjoern A. Zeeb */
33655a4d2461SBjoern A. Zeeb bss_changed |= lkpi_disassoc(sta, vif, lhw);
33665a4d2461SBjoern A. Zeeb
33675a4d2461SBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
336816e688b2SBjoern A. Zeeb
3369d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */
3370d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
3371d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not "
3372d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg));
3373e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST);
3374d9f59799SBjoern A. Zeeb if (error != 0) {
3375d9f59799SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?");
3376018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NOTEXIST) "
3377018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error);
3378d9f59799SBjoern A. Zeeb goto out;
3379d9f59799SBjoern A. Zeeb }
3380d9f59799SBjoern A. Zeeb
33815a4d2461SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif);
33825a4d2461SBjoern A. Zeeb
338316e688b2SBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); /* sta no longer save to use. */
3384d9f59799SBjoern A. Zeeb
3385d9f59799SBjoern A. Zeeb IMPROVE("Any bss_info changes to announce?");
3386d9f59799SBjoern A. Zeeb vif->bss_conf.qos = 0;
3387d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS;
3388616e1330SBjoern A. Zeeb vif->cfg.ssid_len = 0;
3389616e1330SBjoern A. Zeeb memset(vif->cfg.ssid, '\0', sizeof(vif->cfg.ssid));
3390d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID;
33915a4d2461SBjoern A. Zeeb vif->bss_conf.use_short_preamble = false;
33925a4d2461SBjoern A. Zeeb vif->bss_conf.qos = false;
33935a4d2461SBjoern A. Zeeb /* XXX BSS_CHANGED_???? */
3394d9f59799SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed);
3395d9f59799SBjoern A. Zeeb
33962ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif);
33972ac8a218SBjoern A. Zeeb /* Remove ni reference for this cache of lsta. */
33982ac8a218SBjoern A. Zeeb lvif->lvif_bss = NULL;
33992ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched = false;
34002ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif);
34010936c648SBjoern A. Zeeb /*
34020936c648SBjoern A. Zeeb * The very last release the reference on the ni for the ni/lsta on
34030936c648SBjoern A. Zeeb * lvif->lvif_bss. Upon return from this both ni and lsta are invalid
34040936c648SBjoern A. Zeeb * and potentially freed.
34050936c648SBjoern A. Zeeb */
34060936c648SBjoern A. Zeeb ieee80211_free_node(ni);
3407d9f59799SBjoern A. Zeeb
3408d9f59799SBjoern A. Zeeb /* conf_tx */
3409d9f59799SBjoern A. Zeeb
341050d826beSBjoern A. Zeeb lkpi_remove_chanctx(hw, vif);
3411d9f59799SBjoern A. Zeeb
3412d9f59799SBjoern A. Zeeb error = EALREADY;
3413d9f59799SBjoern A. Zeeb out:
3414cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
3415d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic);
3416d9f59799SBjoern A. Zeeb outni:
3417d9f59799SBjoern A. Zeeb return (error);
3418d9f59799SBjoern A. Zeeb }
3419d9f59799SBjoern A. Zeeb
3420d9f59799SBjoern A. Zeeb static int
lkpi_sta_run_to_scan(struct ieee80211vap * vap,enum ieee80211_state nstate,int arg)3421d9f59799SBjoern A. Zeeb lkpi_sta_run_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
3422d9f59799SBjoern A. Zeeb {
3423d9f59799SBjoern A. Zeeb
3424d9f59799SBjoern A. Zeeb return (lkpi_sta_run_to_init(vap, nstate, arg));
3425d9f59799SBjoern A. Zeeb }
3426d9f59799SBjoern A. Zeeb
3427d9f59799SBjoern A. Zeeb static int
lkpi_sta_run_to_auth(struct ieee80211vap * vap,enum ieee80211_state nstate,int arg)34286b4cac81SBjoern A. Zeeb lkpi_sta_run_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
34296b4cac81SBjoern A. Zeeb {
34306b4cac81SBjoern A. Zeeb int error;
34316b4cac81SBjoern A. Zeeb
3432d9f59799SBjoern A. Zeeb error = lkpi_sta_run_to_init(vap, nstate, arg);
3433d9f59799SBjoern A. Zeeb if (error != 0 && error != EALREADY)
3434d9f59799SBjoern A. Zeeb return (error);
3435d9f59799SBjoern A. Zeeb
3436d9f59799SBjoern A. Zeeb /* At this point iv_bss is long a new node! */
3437d9f59799SBjoern A. Zeeb
3438d9f59799SBjoern A. Zeeb error |= lkpi_sta_scan_to_auth(vap, nstate, 0);
34396b4cac81SBjoern A. Zeeb return (error);
34406b4cac81SBjoern A. Zeeb }
34416b4cac81SBjoern A. Zeeb
3442d9f59799SBjoern A. Zeeb /* -------------------------------------------------------------------------- */
34436b4cac81SBjoern A. Zeeb
34446b4cac81SBjoern A. Zeeb /*
34456b4cac81SBjoern A. Zeeb * The matches the documented state changes in net80211::sta_newstate().
34466b4cac81SBjoern A. Zeeb * XXX (1) without CSA and SLEEP yet, * XXX (2) not all unhandled cases
34476b4cac81SBjoern A. Zeeb * there are "invalid" (so there is a room for failure here).
34486b4cac81SBjoern A. Zeeb */
34496b4cac81SBjoern A. Zeeb struct fsm_state {
34506b4cac81SBjoern A. Zeeb /* INIT, SCAN, AUTH, ASSOC, CAC, RUN, CSA, SLEEP */
34516b4cac81SBjoern A. Zeeb enum ieee80211_state ostate;
34526b4cac81SBjoern A. Zeeb enum ieee80211_state nstate;
34536b4cac81SBjoern A. Zeeb int (*handler)(struct ieee80211vap *, enum ieee80211_state, int);
34546b4cac81SBjoern A. Zeeb } sta_state_fsm[] = {
34556b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_INIT, lkpi_sta_state_do_nada },
34566b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, /* scan_to_init */
34576b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_INIT, lkpi_sta_auth_to_init }, /* not explicitly in sta_newstate() */
3458d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_INIT, lkpi_sta_assoc_to_init }, /* Send DEAUTH. */
3459d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_INIT, lkpi_sta_run_to_init }, /* Send DISASSOC. */
34606b4cac81SBjoern A. Zeeb
34616b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_SCAN, lkpi_sta_state_do_nada },
34626b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_SCAN, lkpi_sta_state_do_nada },
34636b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_SCAN, lkpi_sta_auth_to_scan },
34646b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_SCAN, lkpi_sta_assoc_to_scan },
3465d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_SCAN, lkpi_sta_run_to_scan }, /* Beacon miss. */
34666b4cac81SBjoern A. Zeeb
3467d9f59799SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, /* Send AUTH. */
3468d9f59799SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, /* Send AUTH. */
3469d9f59799SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_AUTH, lkpi_sta_a_to_a }, /* Send ?AUTH. */
3470d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_AUTH, lkpi_sta_assoc_to_auth }, /* Send ?AUTH. */
3471d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_AUTH, lkpi_sta_run_to_auth }, /* Send ?AUTH. */
34726b4cac81SBjoern A. Zeeb
3473d9f59799SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_ASSOC, lkpi_sta_auth_to_assoc }, /* Send ASSOCREQ. */
3474d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_ASSOC, lkpi_sta_a_to_a }, /* Send ASSOCREQ. */
3475d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_ASSOC, lkpi_sta_run_to_assoc }, /* Send ASSOCREQ/REASSOCREQ. */
34766b4cac81SBjoern A. Zeeb
34776b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_RUN, lkpi_sta_auth_to_run },
34786b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_RUN, lkpi_sta_assoc_to_run },
34796b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_RUN, lkpi_sta_state_do_nada },
34806b4cac81SBjoern A. Zeeb
34816b4cac81SBjoern A. Zeeb /* Dummy at the end without handler. */
34826b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_INIT, NULL },
34836b4cac81SBjoern A. Zeeb };
34846b4cac81SBjoern A. Zeeb
34856b4cac81SBjoern A. Zeeb static int
lkpi_iv_newstate(struct ieee80211vap * vap,enum ieee80211_state nstate,int arg)34866b4cac81SBjoern A. Zeeb lkpi_iv_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
34876b4cac81SBjoern A. Zeeb {
34886b4cac81SBjoern A. Zeeb struct ieee80211com *ic;
34896b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
34906b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
34916b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif;
34926b4cac81SBjoern A. Zeeb struct fsm_state *s;
34936b4cac81SBjoern A. Zeeb enum ieee80211_state ostate;
34946b4cac81SBjoern A. Zeeb int error;
34956b4cac81SBjoern A. Zeeb
34966b4cac81SBjoern A. Zeeb ic = vap->iv_ic;
34976b4cac81SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(ic);
34986b4cac81SBjoern A. Zeeb ostate = vap->iv_state;
34996b4cac81SBjoern A. Zeeb
35009d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
35019d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE)
35026b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x\n",
35036b4cac81SBjoern A. Zeeb __func__, __LINE__, vap, nstate, arg);
35049d9ba2b7SBjoern A. Zeeb #endif
35056b4cac81SBjoern A. Zeeb
35066b4cac81SBjoern A. Zeeb if (vap->iv_opmode == IEEE80211_M_STA) {
35076b4cac81SBjoern A. Zeeb
35086b4cac81SBjoern A. Zeeb lhw = ic->ic_softc;
35096b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
35106b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
35116b4cac81SBjoern A. Zeeb
35126b4cac81SBjoern A. Zeeb /* No need to replicate this in most state handlers. */
35136b4cac81SBjoern A. Zeeb if (ostate == IEEE80211_S_SCAN && nstate != IEEE80211_S_SCAN)
35146b4cac81SBjoern A. Zeeb lkpi_stop_hw_scan(lhw, vif);
35156b4cac81SBjoern A. Zeeb
35166b4cac81SBjoern A. Zeeb s = sta_state_fsm;
35176b4cac81SBjoern A. Zeeb
35186b4cac81SBjoern A. Zeeb } else {
35196b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: only station mode currently supported: "
35206b4cac81SBjoern A. Zeeb "cap %p iv_opmode %d\n", __func__, vap, vap->iv_opmode);
35216b4cac81SBjoern A. Zeeb return (ENOSYS);
35226b4cac81SBjoern A. Zeeb }
35236b4cac81SBjoern A. Zeeb
35246b4cac81SBjoern A. Zeeb error = 0;
35256b4cac81SBjoern A. Zeeb for (; s->handler != NULL; s++) {
35266b4cac81SBjoern A. Zeeb if (ostate == s->ostate && nstate == s->nstate) {
35279d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
35289d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE)
3529d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: new state %d (%s) ->"
3530d9f59799SBjoern A. Zeeb " %d (%s): arg %d.\n", __func__,
3531d9f59799SBjoern A. Zeeb ostate, ieee80211_state_name[ostate],
3532d9f59799SBjoern A. Zeeb nstate, ieee80211_state_name[nstate], arg);
35339d9ba2b7SBjoern A. Zeeb #endif
35346b4cac81SBjoern A. Zeeb error = s->handler(vap, nstate, arg);
35356b4cac81SBjoern A. Zeeb break;
35366b4cac81SBjoern A. Zeeb }
35376b4cac81SBjoern A. Zeeb }
35386b4cac81SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(vap->iv_ic);
35396b4cac81SBjoern A. Zeeb
35406b4cac81SBjoern A. Zeeb if (s->handler == NULL) {
3541d9f59799SBjoern A. Zeeb IMPROVE("turn this into a KASSERT\n");
35426b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: unsupported state transition "
35436b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s)\n", __func__,
35446b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate],
35456b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]);
35466b4cac81SBjoern A. Zeeb return (ENOSYS);
35476b4cac81SBjoern A. Zeeb }
35486b4cac81SBjoern A. Zeeb
35496b4cac81SBjoern A. Zeeb if (error == EALREADY) {
35509d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
35519d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE)
3552d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: state transition %d (%s) -> "
3553d9f59799SBjoern A. Zeeb "%d (%s): iv_newstate already handled: %d.\n",
3554d9f59799SBjoern A. Zeeb __func__, ostate, ieee80211_state_name[ostate],
3555d9f59799SBjoern A. Zeeb nstate, ieee80211_state_name[nstate], error);
35569d9ba2b7SBjoern A. Zeeb #endif
35576b4cac81SBjoern A. Zeeb return (0);
35586b4cac81SBjoern A. Zeeb }
35596b4cac81SBjoern A. Zeeb
35606b4cac81SBjoern A. Zeeb if (error != 0) {
35616b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: error %d during state transition "
35626b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s)\n", __func__, error,
35636b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate],
35646b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]);
356545c27ad5SBjoern A. Zeeb return (error);
35666b4cac81SBjoern A. Zeeb }
35676b4cac81SBjoern A. Zeeb
35689d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
35699d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE)
3570d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x "
3571d9f59799SBjoern A. Zeeb "calling net80211 parent\n",
35726b4cac81SBjoern A. Zeeb __func__, __LINE__, vap, nstate, arg);
35739d9ba2b7SBjoern A. Zeeb #endif
35746b4cac81SBjoern A. Zeeb
35756b4cac81SBjoern A. Zeeb return (lvif->iv_newstate(vap, nstate, arg));
35766b4cac81SBjoern A. Zeeb }
35776b4cac81SBjoern A. Zeeb
35786b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */
35796b4cac81SBjoern A. Zeeb
3580d9f59799SBjoern A. Zeeb /*
3581d9f59799SBjoern A. Zeeb * We overload (*iv_update_bss) as otherwise we have cases in, e.g.,
3582d9f59799SBjoern A. Zeeb * net80211::ieee80211_sta_join1() where vap->iv_bss gets replaced by a
3583d9f59799SBjoern A. Zeeb * new node without us knowing and thus our ni/lsta are out of sync.
3584d9f59799SBjoern A. Zeeb */
3585d9f59799SBjoern A. Zeeb static struct ieee80211_node *
lkpi_iv_update_bss(struct ieee80211vap * vap,struct ieee80211_node * ni)3586d9f59799SBjoern A. Zeeb lkpi_iv_update_bss(struct ieee80211vap *vap, struct ieee80211_node *ni)
3587d9f59799SBjoern A. Zeeb {
3588d9f59799SBjoern A. Zeeb struct lkpi_vif *lvif;
35892ac8a218SBjoern A. Zeeb struct ieee80211_node *rni;
3590d9f59799SBjoern A. Zeeb
35912ac8a218SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(vap->iv_ic);
3592d9f59799SBjoern A. Zeeb
3593ed3ef56bSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
35942ac8a218SBjoern A. Zeeb
35952ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif);
35962ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched = false;
35972ac8a218SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif);
35982ac8a218SBjoern A. Zeeb
35992ac8a218SBjoern A. Zeeb rni = lvif->iv_update_bss(vap, ni);
36002ac8a218SBjoern A. Zeeb return (rni);
3601d9f59799SBjoern A. Zeeb }
3602d9f59799SBjoern A. Zeeb
36034a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME
36046b4cac81SBjoern A. Zeeb static int
lkpi_wme_update(struct lkpi_hw * lhw,struct ieee80211vap * vap,bool planned)36054a67f1dfSBjoern A. Zeeb lkpi_wme_update(struct lkpi_hw *lhw, struct ieee80211vap *vap, bool planned)
36066b4cac81SBjoern A. Zeeb {
36074a67f1dfSBjoern A. Zeeb struct ieee80211com *ic;
36086b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw;
36096b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
36106b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif;
36116b4cac81SBjoern A. Zeeb struct chanAccParams chp;
36126b4cac81SBjoern A. Zeeb struct wmeParams wmeparr[WME_NUM_AC];
36136b4cac81SBjoern A. Zeeb struct ieee80211_tx_queue_params txqp;
36146b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed;
36156b4cac81SBjoern A. Zeeb int error;
36166b4cac81SBjoern A. Zeeb uint16_t ac;
36176b4cac81SBjoern A. Zeeb
3618cd0fcf9fSBjoern A. Zeeb hw = LHW_TO_HW(lhw);
3619cd0fcf9fSBjoern A. Zeeb lockdep_assert_wiphy(hw->wiphy);
3620cd0fcf9fSBjoern A. Zeeb
36216b4cac81SBjoern A. Zeeb IMPROVE();
36226b4cac81SBjoern A. Zeeb KASSERT(WME_NUM_AC == IEEE80211_NUM_ACS, ("%s: WME_NUM_AC %d != "
36236b4cac81SBjoern A. Zeeb "IEEE80211_NUM_ACS %d\n", __func__, WME_NUM_AC, IEEE80211_NUM_ACS));
36246b4cac81SBjoern A. Zeeb
36256b4cac81SBjoern A. Zeeb if (vap == NULL)
36266b4cac81SBjoern A. Zeeb return (0);
36276b4cac81SBjoern A. Zeeb
36284a67f1dfSBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WME) == 0)
36294a67f1dfSBjoern A. Zeeb return (0);
36304a67f1dfSBjoern A. Zeeb
36316b4cac81SBjoern A. Zeeb if (lhw->ops->conf_tx == NULL)
36326b4cac81SBjoern A. Zeeb return (0);
36336b4cac81SBjoern A. Zeeb
36344a67f1dfSBjoern A. Zeeb if (!planned && (vap->iv_state != IEEE80211_S_RUN)) {
36354a67f1dfSBjoern A. Zeeb lhw->update_wme = true;
36364a67f1dfSBjoern A. Zeeb return (0);
36374a67f1dfSBjoern A. Zeeb }
36384a67f1dfSBjoern A. Zeeb lhw->update_wme = false;
36396b4cac81SBjoern A. Zeeb
36404a67f1dfSBjoern A. Zeeb ic = lhw->ic;
36416b4cac81SBjoern A. Zeeb ieee80211_wme_ic_getparams(ic, &chp);
36426b4cac81SBjoern A. Zeeb IEEE80211_LOCK(ic);
36436b4cac81SBjoern A. Zeeb for (ac = 0; ac < WME_NUM_AC; ac++)
36446b4cac81SBjoern A. Zeeb wmeparr[ac] = chp.cap_wmeParams[ac];
36456b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(ic);
36466b4cac81SBjoern A. Zeeb
36474a67f1dfSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
36484a67f1dfSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
36494a67f1dfSBjoern A. Zeeb
36506b4cac81SBjoern A. Zeeb /* Configure tx queues (conf_tx) & send BSS_CHANGED_QOS. */
36516b4cac81SBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
36526b4cac81SBjoern A. Zeeb struct wmeParams *wmep;
36536b4cac81SBjoern A. Zeeb
36546b4cac81SBjoern A. Zeeb wmep = &wmeparr[ac];
36556b4cac81SBjoern A. Zeeb bzero(&txqp, sizeof(txqp));
36566b4cac81SBjoern A. Zeeb txqp.cw_min = wmep->wmep_logcwmin;
36576b4cac81SBjoern A. Zeeb txqp.cw_max = wmep->wmep_logcwmax;
36586b4cac81SBjoern A. Zeeb txqp.txop = wmep->wmep_txopLimit;
36596b4cac81SBjoern A. Zeeb txqp.aifs = wmep->wmep_aifsn;
366068541546SBjoern A. Zeeb error = lkpi_80211_mo_conf_tx(hw, vif, /* link_id */0, ac, &txqp);
36616b4cac81SBjoern A. Zeeb if (error != 0)
36623f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: conf_tx ac %u failed %d\n",
36636b4cac81SBjoern A. Zeeb __func__, ac, error);
36646b4cac81SBjoern A. Zeeb }
36656b4cac81SBjoern A. Zeeb changed = BSS_CHANGED_QOS;
36664a67f1dfSBjoern A. Zeeb if (!planned)
36676b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed);
36684a67f1dfSBjoern A. Zeeb
36694a67f1dfSBjoern A. Zeeb return (changed);
36704a67f1dfSBjoern A. Zeeb }
36716b4cac81SBjoern A. Zeeb #endif
36726b4cac81SBjoern A. Zeeb
36734a67f1dfSBjoern A. Zeeb static int
lkpi_ic_wme_update(struct ieee80211com * ic)36744a67f1dfSBjoern A. Zeeb lkpi_ic_wme_update(struct ieee80211com *ic)
36754a67f1dfSBjoern A. Zeeb {
36764a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME
36774a67f1dfSBjoern A. Zeeb struct ieee80211vap *vap;
36784a67f1dfSBjoern A. Zeeb struct lkpi_hw *lhw;
3679cd0fcf9fSBjoern A. Zeeb struct ieee80211_hw *hw;
36804a67f1dfSBjoern A. Zeeb
36814a67f1dfSBjoern A. Zeeb IMPROVE("Use the per-VAP callback in net80211.");
36824a67f1dfSBjoern A. Zeeb vap = TAILQ_FIRST(&ic->ic_vaps);
36834a67f1dfSBjoern A. Zeeb if (vap == NULL)
36846b4cac81SBjoern A. Zeeb return (0);
36854a67f1dfSBjoern A. Zeeb
36864a67f1dfSBjoern A. Zeeb lhw = ic->ic_softc;
3687cd0fcf9fSBjoern A. Zeeb hw = LHW_TO_HW(lhw);
36884a67f1dfSBjoern A. Zeeb
3689cd0fcf9fSBjoern A. Zeeb wiphy_lock(hw->wiphy);
36904a67f1dfSBjoern A. Zeeb lkpi_wme_update(lhw, vap, false);
3691cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
36924a67f1dfSBjoern A. Zeeb #endif
36934a67f1dfSBjoern A. Zeeb return (0); /* unused */
36946b4cac81SBjoern A. Zeeb }
36956b4cac81SBjoern A. Zeeb
36964aff4048SBjoern A. Zeeb /*
36974aff4048SBjoern A. Zeeb * Change link-layer address on the vif (if the vap is not started/"UP").
36984aff4048SBjoern A. Zeeb * This can happen if a user changes 'ether' using ifconfig.
36994aff4048SBjoern A. Zeeb * The code is based on net80211/ieee80211_freebsd.c::wlan_iflladdr() but
37004aff4048SBjoern A. Zeeb * we do use a per-[l]vif event handler to be sure we exist as we
37014aff4048SBjoern A. Zeeb * cannot assume that from every vap derives a vif and we have a hard
37024aff4048SBjoern A. Zeeb * time checking based on net80211 information.
3703edab5a28SBjoern A. Zeeb * Should this ever become a real problem we could add a callback function
3704edab5a28SBjoern A. Zeeb * to wlan_iflladdr() to be set optionally but that would be for a
3705edab5a28SBjoern A. Zeeb * single-consumer (or needs a list) -- was just too complicated for an
3706edab5a28SBjoern A. Zeeb * otherwise perfect mechanism FreeBSD already provides.
37074aff4048SBjoern A. Zeeb */
37084aff4048SBjoern A. Zeeb static void
lkpi_vif_iflladdr(void * arg,struct ifnet * ifp)37094aff4048SBjoern A. Zeeb lkpi_vif_iflladdr(void *arg, struct ifnet *ifp)
37104aff4048SBjoern A. Zeeb {
37114aff4048SBjoern A. Zeeb struct epoch_tracker et;
37124aff4048SBjoern A. Zeeb struct ieee80211_vif *vif;
37134aff4048SBjoern A. Zeeb
37144aff4048SBjoern A. Zeeb NET_EPOCH_ENTER(et);
3715edab5a28SBjoern A. Zeeb /* NB: identify vap's by if_transmit; left as an extra check. */
3716edab5a28SBjoern A. Zeeb if (if_gettransmitfn(ifp) != ieee80211_vap_transmit ||
3717edab5a28SBjoern A. Zeeb (if_getflags(ifp) & IFF_UP) != 0) {
37184aff4048SBjoern A. Zeeb NET_EPOCH_EXIT(et);
37194aff4048SBjoern A. Zeeb return;
37204aff4048SBjoern A. Zeeb }
37214aff4048SBjoern A. Zeeb
37224aff4048SBjoern A. Zeeb vif = arg;
372357609cb2SJustin Hibbits IEEE80211_ADDR_COPY(vif->bss_conf.addr, if_getlladdr(ifp));
37244aff4048SBjoern A. Zeeb NET_EPOCH_EXIT(et);
37254aff4048SBjoern A. Zeeb }
37264aff4048SBjoern A. Zeeb
37276b4cac81SBjoern A. Zeeb static struct ieee80211vap *
lkpi_ic_vap_create(struct ieee80211com * ic,const char name[IFNAMSIZ],int unit,enum ieee80211_opmode opmode,int flags,const uint8_t bssid[IEEE80211_ADDR_LEN],const uint8_t mac[IEEE80211_ADDR_LEN])37286b4cac81SBjoern A. Zeeb lkpi_ic_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ],
37296b4cac81SBjoern A. Zeeb int unit, enum ieee80211_opmode opmode, int flags,
37306b4cac81SBjoern A. Zeeb const uint8_t bssid[IEEE80211_ADDR_LEN],
37316b4cac81SBjoern A. Zeeb const uint8_t mac[IEEE80211_ADDR_LEN])
37326b4cac81SBjoern A. Zeeb {
37336b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
37346b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw;
37356b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
37366b4cac81SBjoern A. Zeeb struct ieee80211vap *vap;
37376b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif;
3738a6042e17SBjoern A. Zeeb struct ieee80211_tx_queue_params txqp;
37396b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed;
374040839418SBjoern A. Zeeb struct sysctl_oid *node;
37416b4cac81SBjoern A. Zeeb size_t len;
3742e3a0b120SBjoern A. Zeeb int error, i;
3743a6042e17SBjoern A. Zeeb uint16_t ac;
37446b4cac81SBjoern A. Zeeb
37456b4cac81SBjoern A. Zeeb if (!TAILQ_EMPTY(&ic->ic_vaps)) /* 1 so far. Add <n> once this works. */
37466b4cac81SBjoern A. Zeeb return (NULL);
37476b4cac81SBjoern A. Zeeb
37486b4cac81SBjoern A. Zeeb lhw = ic->ic_softc;
37496b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
37506b4cac81SBjoern A. Zeeb
37516b4cac81SBjoern A. Zeeb len = sizeof(*lvif);
37526b4cac81SBjoern A. Zeeb len += hw->vif_data_size; /* vif->drv_priv */
37536b4cac81SBjoern A. Zeeb
37546b4cac81SBjoern A. Zeeb lvif = malloc(len, M_80211_VAP, M_WAITOK | M_ZERO);
37556b4cac81SBjoern A. Zeeb mtx_init(&lvif->mtx, "lvif", NULL, MTX_DEF);
3756a8f735a6SBjoern A. Zeeb INIT_LIST_HEAD(&lvif->lsta_list);
37572ac8a218SBjoern A. Zeeb lvif->lvif_bss = NULL;
3758b8dfc3ecSBjoern A. Zeeb refcount_init(&lvif->nt_unlocked, 0);
37592ac8a218SBjoern A. Zeeb lvif->lvif_bss_synched = false;
37606b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif);
37616b4cac81SBjoern A. Zeeb
37626b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
37636b4cac81SBjoern A. Zeeb memcpy(vif->addr, mac, IEEE80211_ADDR_LEN);
37646b4cac81SBjoern A. Zeeb vif->p2p = false;
37656b4cac81SBjoern A. Zeeb vif->probe_req_reg = false;
37666b4cac81SBjoern A. Zeeb vif->type = lkpi_opmode_to_vif_type(opmode);
37676b4cac81SBjoern A. Zeeb lvif->wdev.iftype = vif->type;
37686b4cac81SBjoern A. Zeeb /* Need to fill in other fields as well. */
37696b4cac81SBjoern A. Zeeb IMPROVE();
37706b4cac81SBjoern A. Zeeb
37716b4cac81SBjoern A. Zeeb /* XXX-BZ hardcoded for now! */
37726b4cac81SBjoern A. Zeeb #if 1
3773560708cbSBjoern A. Zeeb RCU_INIT_POINTER(vif->bss_conf.chanctx_conf, NULL);
3774adff403fSBjoern A. Zeeb vif->bss_conf.vif = vif;
37756ffb7bd4SBjoern A. Zeeb /* vap->iv_myaddr is not set until net80211::vap_setup or vap_attach. */
37766ffb7bd4SBjoern A. Zeeb IEEE80211_ADDR_COPY(vif->bss_conf.addr, mac);
37774aff4048SBjoern A. Zeeb lvif->lvif_ifllevent = EVENTHANDLER_REGISTER(iflladdr_event,
37784aff4048SBjoern A. Zeeb lkpi_vif_iflladdr, vif, EVENTHANDLER_PRI_ANY);
37796ffb7bd4SBjoern A. Zeeb vif->bss_conf.link_id = 0; /* Non-MLO operation. */
37807b43f4d0SBjoern A. Zeeb vif->bss_conf.chanreq.oper.width = NL80211_CHAN_WIDTH_20_NOHT;
37816b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble = false; /* vap->iv_flags IEEE80211_F_SHPREAMBLE */
37826b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot = false; /* vap->iv_flags IEEE80211_F_SHSLOT */
37836b4cac81SBjoern A. Zeeb vif->bss_conf.qos = false;
37846b4cac81SBjoern A. Zeeb vif->bss_conf.use_cts_prot = false; /* vap->iv_protmode */
37856b4cac81SBjoern A. Zeeb vif->bss_conf.ht_operation_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
3786616e1330SBjoern A. Zeeb vif->cfg.aid = 0;
3787616e1330SBjoern A. Zeeb vif->cfg.assoc = false;
3788616e1330SBjoern A. Zeeb vif->cfg.idle = true;
3789616e1330SBjoern A. Zeeb vif->cfg.ps = false;
37906ffb7bd4SBjoern A. Zeeb IMPROVE("Check other fields and then figure out whats is left elsewhere of them");
3791caaa79c3SBjoern A. Zeeb /*
3792caaa79c3SBjoern A. Zeeb * We need to initialize it to something as the bss_info_changed call
3793caaa79c3SBjoern A. Zeeb * will try to copy from it in iwlwifi and NULL is a panic.
3794caaa79c3SBjoern A. Zeeb * We will set the proper one in scan_to_auth() before being assoc.
3795caaa79c3SBjoern A. Zeeb */
37966ffb7bd4SBjoern A. Zeeb vif->bss_conf.bssid = ieee80211broadcastaddr;
37976b4cac81SBjoern A. Zeeb #endif
37986b4cac81SBjoern A. Zeeb #if 0
37996b4cac81SBjoern A. Zeeb vif->bss_conf.dtim_period = 0; /* IEEE80211_DTIM_DEFAULT ; must stay 0. */
38006b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(vif->bss_conf.bssid, bssid);
38016b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = ic->ic_bintval;
38026b4cac81SBjoern A. Zeeb /* iwlwifi bug. */
38036b4cac81SBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16)
38046b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = 16;
38056b4cac81SBjoern A. Zeeb #endif
3806e3a0b120SBjoern A. Zeeb
38076ffb7bd4SBjoern A. Zeeb /* Link Config */
38086ffb7bd4SBjoern A. Zeeb vif->link_conf[0] = &vif->bss_conf;
38096ffb7bd4SBjoern A. Zeeb for (i = 0; i < nitems(vif->link_conf); i++) {
38106ffb7bd4SBjoern A. Zeeb IMPROVE("more than 1 link one day");
38116ffb7bd4SBjoern A. Zeeb }
38126ffb7bd4SBjoern A. Zeeb
3813e3a0b120SBjoern A. Zeeb /* Setup queue defaults; driver may override in (*add_interface). */
3814e3a0b120SBjoern A. Zeeb for (i = 0; i < IEEE80211_NUM_ACS; i++) {
3815e3a0b120SBjoern A. Zeeb if (ieee80211_hw_check(hw, QUEUE_CONTROL))
3816e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = IEEE80211_INVAL_HW_QUEUE;
3817e3a0b120SBjoern A. Zeeb else if (hw->queues >= IEEE80211_NUM_ACS)
3818e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = i;
3819e3a0b120SBjoern A. Zeeb else
3820e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = 0;
38210cbcfa19SBjoern A. Zeeb
38220cbcfa19SBjoern A. Zeeb /* Initialize the queue to running. Stopped? */
38230cbcfa19SBjoern A. Zeeb lvif->hw_queue_stopped[i] = false;
3824e3a0b120SBjoern A. Zeeb }
3825e3a0b120SBjoern A. Zeeb vif->cab_queue = IEEE80211_INVAL_HW_QUEUE;
3826e3a0b120SBjoern A. Zeeb
38276b4cac81SBjoern A. Zeeb IMPROVE();
38286b4cac81SBjoern A. Zeeb
38296b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_start(hw);
38306b4cac81SBjoern A. Zeeb if (error != 0) {
38313f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: failed to start hw: %d\n", __func__, error);
38326b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx);
38336b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP);
38346b4cac81SBjoern A. Zeeb return (NULL);
38356b4cac81SBjoern A. Zeeb }
38366b4cac81SBjoern A. Zeeb
38376b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_add_interface(hw, vif);
38386b4cac81SBjoern A. Zeeb if (error != 0) {
38396b4cac81SBjoern A. Zeeb IMPROVE(); /* XXX-BZ mo_stop()? */
38403f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: failed to add interface: %d\n", __func__, error);
38416b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx);
38426b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP);
38436b4cac81SBjoern A. Zeeb return (NULL);
38446b4cac81SBjoern A. Zeeb }
38456b4cac81SBjoern A. Zeeb
38468891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw);
38476b4cac81SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lhw->lvif_head, lvif, lvif_entry);
38488891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw);
38496b4cac81SBjoern A. Zeeb
38506b4cac81SBjoern A. Zeeb /* Set bss_info. */
38516b4cac81SBjoern A. Zeeb changed = 0;
38526b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed);
38536b4cac81SBjoern A. Zeeb
3854a6042e17SBjoern A. Zeeb /* Configure tx queues (conf_tx), default WME & send BSS_CHANGED_QOS. */
3855a6042e17SBjoern A. Zeeb IMPROVE("Hardcoded values; to fix see 802.11-2016, 9.4.2.29 EDCA Parameter Set element");
3856cd0fcf9fSBjoern A. Zeeb wiphy_lock(hw->wiphy);
3857a6042e17SBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
3858a6042e17SBjoern A. Zeeb
3859a6042e17SBjoern A. Zeeb bzero(&txqp, sizeof(txqp));
3860a6042e17SBjoern A. Zeeb txqp.cw_min = 15;
3861a6042e17SBjoern A. Zeeb txqp.cw_max = 1023;
3862a6042e17SBjoern A. Zeeb txqp.txop = 0;
3863a6042e17SBjoern A. Zeeb txqp.aifs = 2;
3864a6042e17SBjoern A. Zeeb error = lkpi_80211_mo_conf_tx(hw, vif, /* link_id */0, ac, &txqp);
3865a6042e17SBjoern A. Zeeb if (error != 0)
3866a6042e17SBjoern A. Zeeb ic_printf(ic, "%s: conf_tx ac %u failed %d\n",
3867a6042e17SBjoern A. Zeeb __func__, ac, error);
3868a6042e17SBjoern A. Zeeb }
3869cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
3870a6042e17SBjoern A. Zeeb changed = BSS_CHANGED_QOS;
3871a6042e17SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed);
38726b4cac81SBjoern A. Zeeb
38736b4cac81SBjoern A. Zeeb /* Force MC init. */
38746b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(ic, true);
38756b4cac81SBjoern A. Zeeb
38766b4cac81SBjoern A. Zeeb IMPROVE();
38776b4cac81SBjoern A. Zeeb
38786b4cac81SBjoern A. Zeeb ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid);
38796b4cac81SBjoern A. Zeeb
38806b4cac81SBjoern A. Zeeb /* Override with LinuxKPI method so we can drive mac80211/cfg80211. */
38816b4cac81SBjoern A. Zeeb lvif->iv_newstate = vap->iv_newstate;
38826b4cac81SBjoern A. Zeeb vap->iv_newstate = lkpi_iv_newstate;
3883d9f59799SBjoern A. Zeeb lvif->iv_update_bss = vap->iv_update_bss;
3884d9f59799SBjoern A. Zeeb vap->iv_update_bss = lkpi_iv_update_bss;
38856b4cac81SBjoern A. Zeeb
3886b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO
388711db70b6SBjoern A. Zeeb /* Key management. */
388811db70b6SBjoern A. Zeeb if (lkpi_hwcrypto && lhw->ops->set_key != NULL) {
38896b4cac81SBjoern A. Zeeb vap->iv_key_set = lkpi_iv_key_set;
38906b4cac81SBjoern A. Zeeb vap->iv_key_delete = lkpi_iv_key_delete;
3891b8dfc3ecSBjoern A. Zeeb vap->iv_key_update_begin = lkpi_iv_key_update_begin;
3892b8dfc3ecSBjoern A. Zeeb vap->iv_key_update_end = lkpi_iv_key_update_end;
38936b4cac81SBjoern A. Zeeb }
389411db70b6SBjoern A. Zeeb #endif
38956b4cac81SBjoern A. Zeeb
38969fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT
38979fb91463SBjoern A. Zeeb /* Stay with the iv_ampdu_rxmax,limit / iv_ampdu_density defaults until later. */
38989fb91463SBjoern A. Zeeb #endif
38999fb91463SBjoern A. Zeeb
39006b4cac81SBjoern A. Zeeb ieee80211_ratectl_init(vap);
39016b4cac81SBjoern A. Zeeb
39026b4cac81SBjoern A. Zeeb /* Complete setup. */
39036b4cac81SBjoern A. Zeeb ieee80211_vap_attach(vap, ieee80211_media_change,
39046b4cac81SBjoern A. Zeeb ieee80211_media_status, mac);
39056b4cac81SBjoern A. Zeeb
390611db70b6SBjoern A. Zeeb #ifdef LKPI_80211_HT
390711db70b6SBjoern A. Zeeb /*
390811db70b6SBjoern A. Zeeb * Modern chipset/fw/drv will do A-MPDU in drv/fw and fail
390911db70b6SBjoern A. Zeeb * to do so if they cannot do the crypto too.
391011db70b6SBjoern A. Zeeb */
391111db70b6SBjoern A. Zeeb if (!lkpi_hwcrypto && ieee80211_hw_check(hw, AMPDU_AGGREGATION))
391211db70b6SBjoern A. Zeeb vap->iv_flags_ht &= ~IEEE80211_FHT_AMPDU_RX;
391311db70b6SBjoern A. Zeeb #endif
3914ac2c7271SBjoern A. Zeeb #if defined(LKPI_80211_HT)
3915ac2c7271SBjoern A. Zeeb /* 20250125-BZ Keep A-MPDU TX cleared until we sorted out AddBA for all drivers. */
3916ac2c7271SBjoern A. Zeeb vap->iv_flags_ht &= ~IEEE80211_FHT_AMPDU_TX;
3917ac2c7271SBjoern A. Zeeb #endif
391811db70b6SBjoern A. Zeeb
39196b4cac81SBjoern A. Zeeb if (hw->max_listen_interval == 0)
39206b4cac81SBjoern A. Zeeb hw->max_listen_interval = 7 * (ic->ic_lintval / ic->ic_bintval);
39216b4cac81SBjoern A. Zeeb hw->conf.listen_interval = hw->max_listen_interval;
39226b4cac81SBjoern A. Zeeb ic->ic_set_channel(ic);
39236b4cac81SBjoern A. Zeeb
39246b4cac81SBjoern A. Zeeb /* XXX-BZ do we need to be able to update these? */
39256b4cac81SBjoern A. Zeeb hw->wiphy->frag_threshold = vap->iv_fragthreshold;
39266b4cac81SBjoern A. Zeeb lkpi_80211_mo_set_frag_threshold(hw, vap->iv_fragthreshold);
39276b4cac81SBjoern A. Zeeb hw->wiphy->rts_threshold = vap->iv_rtsthreshold;
39286b4cac81SBjoern A. Zeeb lkpi_80211_mo_set_rts_threshold(hw, vap->iv_rtsthreshold);
39296b4cac81SBjoern A. Zeeb /* any others? */
393040839418SBjoern A. Zeeb
393140839418SBjoern A. Zeeb /* Add per-VIF/VAP sysctls. */
393240839418SBjoern A. Zeeb sysctl_ctx_init(&lvif->sysctl_ctx);
393340839418SBjoern A. Zeeb
393440839418SBjoern A. Zeeb node = SYSCTL_ADD_NODE(&lvif->sysctl_ctx,
393540839418SBjoern A. Zeeb SYSCTL_CHILDREN(&sysctl___compat_linuxkpi_80211),
393640839418SBjoern A. Zeeb OID_AUTO, if_name(vap->iv_ifp),
393740839418SBjoern A. Zeeb CTLFLAG_RD | CTLFLAG_SKIP | CTLFLAG_MPSAFE, NULL, "VIF Information");
393840839418SBjoern A. Zeeb
393940839418SBjoern A. Zeeb SYSCTL_ADD_PROC(&lvif->sysctl_ctx,
394040839418SBjoern A. Zeeb SYSCTL_CHILDREN(node), OID_AUTO, "dump_stas",
394140839418SBjoern A. Zeeb CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, lvif, 0,
394240839418SBjoern A. Zeeb lkpi_80211_dump_stas, "A", "Dump sta statistics of this vif");
394340839418SBjoern A. Zeeb
39446b4cac81SBjoern A. Zeeb IMPROVE();
39456b4cac81SBjoern A. Zeeb
39466b4cac81SBjoern A. Zeeb return (vap);
39476b4cac81SBjoern A. Zeeb }
39486b4cac81SBjoern A. Zeeb
39494b0af114SBjoern A. Zeeb void
linuxkpi_ieee80211_unregister_hw(struct ieee80211_hw * hw)39504b0af114SBjoern A. Zeeb linuxkpi_ieee80211_unregister_hw(struct ieee80211_hw *hw)
39514b0af114SBjoern A. Zeeb {
39524b0af114SBjoern A. Zeeb
39534b0af114SBjoern A. Zeeb wiphy_unregister(hw->wiphy);
39544b0af114SBjoern A. Zeeb linuxkpi_ieee80211_ifdetach(hw);
39554b0af114SBjoern A. Zeeb
39564b0af114SBjoern A. Zeeb IMPROVE();
39574b0af114SBjoern A. Zeeb }
39584b0af114SBjoern A. Zeeb
39594b0af114SBjoern A. Zeeb void
linuxkpi_ieee80211_restart_hw(struct ieee80211_hw * hw)39604b0af114SBjoern A. Zeeb linuxkpi_ieee80211_restart_hw(struct ieee80211_hw *hw)
39614b0af114SBjoern A. Zeeb {
39624b0af114SBjoern A. Zeeb
39634b0af114SBjoern A. Zeeb TODO();
39644b0af114SBjoern A. Zeeb }
39654b0af114SBjoern A. Zeeb
39666b4cac81SBjoern A. Zeeb static void
lkpi_ic_vap_delete(struct ieee80211vap * vap)39676b4cac81SBjoern A. Zeeb lkpi_ic_vap_delete(struct ieee80211vap *vap)
39686b4cac81SBjoern A. Zeeb {
39696b4cac81SBjoern A. Zeeb struct ieee80211com *ic;
39706b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
39716b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw;
39726b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
39736b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif;
39746b4cac81SBjoern A. Zeeb
39756b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
39766b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
39776b4cac81SBjoern A. Zeeb ic = vap->iv_ic;
39786b4cac81SBjoern A. Zeeb lhw = ic->ic_softc;
39796b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
39806b4cac81SBjoern A. Zeeb
39814aff4048SBjoern A. Zeeb EVENTHANDLER_DEREGISTER(iflladdr_event, lvif->lvif_ifllevent);
39824aff4048SBjoern A. Zeeb
398340839418SBjoern A. Zeeb /* Clear up per-VIF/VAP sysctls. */
398440839418SBjoern A. Zeeb sysctl_ctx_free(&lvif->sysctl_ctx);
398540839418SBjoern A. Zeeb
39868891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw);
39876b4cac81SBjoern A. Zeeb TAILQ_REMOVE(&lhw->lvif_head, lvif, lvif_entry);
39888891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw);
39896b4cac81SBjoern A. Zeeb
39906b4cac81SBjoern A. Zeeb ieee80211_ratectl_deinit(vap);
39916b4cac81SBjoern A. Zeeb ieee80211_vap_detach(vap);
3992dbf76919SBjoern A. Zeeb
3993dbf76919SBjoern A. Zeeb IMPROVE("clear up other bits in this state");
3994dbf76919SBjoern A. Zeeb
3995dbf76919SBjoern A. Zeeb lkpi_80211_mo_remove_interface(hw, vif);
3996dbf76919SBjoern A. Zeeb
39976c38c6b1SBjoern A. Zeeb /* Single VAP, so we can do this here. */
39987b43f4d0SBjoern A. Zeeb lkpi_80211_mo_stop(hw, false); /* XXX SUSPEND */
39996c38c6b1SBjoern A. Zeeb
40006b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx);
40016b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP);
40026b4cac81SBjoern A. Zeeb }
40036b4cac81SBjoern A. Zeeb
40046b4cac81SBjoern A. Zeeb static void
lkpi_ic_update_mcast(struct ieee80211com * ic)40056b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast(struct ieee80211com *ic)
40066b4cac81SBjoern A. Zeeb {
40076b4cac81SBjoern A. Zeeb
40086b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(ic, false);
40096b4cac81SBjoern A. Zeeb TRACEOK();
40106b4cac81SBjoern A. Zeeb }
40116b4cac81SBjoern A. Zeeb
40126b4cac81SBjoern A. Zeeb static void
lkpi_ic_update_promisc(struct ieee80211com * ic)40136b4cac81SBjoern A. Zeeb lkpi_ic_update_promisc(struct ieee80211com *ic)
40146b4cac81SBjoern A. Zeeb {
40156b4cac81SBjoern A. Zeeb
40166b4cac81SBjoern A. Zeeb UNIMPLEMENTED;
40176b4cac81SBjoern A. Zeeb }
40186b4cac81SBjoern A. Zeeb
40196b4cac81SBjoern A. Zeeb static void
lkpi_ic_update_chw(struct ieee80211com * ic)40206b4cac81SBjoern A. Zeeb lkpi_ic_update_chw(struct ieee80211com *ic)
40216b4cac81SBjoern A. Zeeb {
40226b4cac81SBjoern A. Zeeb
40236b4cac81SBjoern A. Zeeb UNIMPLEMENTED;
40246b4cac81SBjoern A. Zeeb }
40256b4cac81SBjoern A. Zeeb
40266b4cac81SBjoern A. Zeeb /* Start / stop device. */
40276b4cac81SBjoern A. Zeeb static void
lkpi_ic_parent(struct ieee80211com * ic)40286b4cac81SBjoern A. Zeeb lkpi_ic_parent(struct ieee80211com *ic)
40296b4cac81SBjoern A. Zeeb {
40306b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
40316b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw;
4032cd0fcf9fSBjoern A. Zeeb #ifdef HW_START_STOP
40336b4cac81SBjoern A. Zeeb int error;
40348d58a057SBjoern A. Zeeb #endif
40356b4cac81SBjoern A. Zeeb bool start_all;
40366b4cac81SBjoern A. Zeeb
40376b4cac81SBjoern A. Zeeb IMPROVE();
40386b4cac81SBjoern A. Zeeb
40396b4cac81SBjoern A. Zeeb lhw = ic->ic_softc;
40406b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
40416b4cac81SBjoern A. Zeeb start_all = false;
40426b4cac81SBjoern A. Zeeb
40438ac540d3SBjoern A. Zeeb /* IEEE80211_UNLOCK(ic); */
4044cd0fcf9fSBjoern A. Zeeb wiphy_lock(hw->wiphy);
40456b4cac81SBjoern A. Zeeb if (ic->ic_nrunning > 0) {
40468d58a057SBjoern A. Zeeb #ifdef HW_START_STOP
40476b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_start(hw);
40486b4cac81SBjoern A. Zeeb if (error == 0)
40498d58a057SBjoern A. Zeeb #endif
40506b4cac81SBjoern A. Zeeb start_all = true;
40516b4cac81SBjoern A. Zeeb } else {
40528d58a057SBjoern A. Zeeb #ifdef HW_START_STOP
40537b43f4d0SBjoern A. Zeeb lkpi_80211_mo_stop(hw, false); /* XXX SUSPEND */
40548d58a057SBjoern A. Zeeb #endif
40556b4cac81SBjoern A. Zeeb }
4056cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
40578ac540d3SBjoern A. Zeeb /* IEEE80211_LOCK(ic); */
40586b4cac81SBjoern A. Zeeb
40596b4cac81SBjoern A. Zeeb if (start_all)
40606b4cac81SBjoern A. Zeeb ieee80211_start_all(ic);
40616b4cac81SBjoern A. Zeeb }
40626b4cac81SBjoern A. Zeeb
40636b4cac81SBjoern A. Zeeb bool
linuxkpi_ieee80211_is_ie_id_in_ie_buf(const u8 ie,const u8 * ie_ids,size_t ie_ids_len)40646b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_is_ie_id_in_ie_buf(const u8 ie, const u8 *ie_ids,
40656b4cac81SBjoern A. Zeeb size_t ie_ids_len)
40666b4cac81SBjoern A. Zeeb {
40676b4cac81SBjoern A. Zeeb int i;
40686b4cac81SBjoern A. Zeeb
40696b4cac81SBjoern A. Zeeb for (i = 0; i < ie_ids_len; i++) {
40706b4cac81SBjoern A. Zeeb if (ie == *ie_ids)
40716b4cac81SBjoern A. Zeeb return (true);
40726b4cac81SBjoern A. Zeeb }
40736b4cac81SBjoern A. Zeeb
40746b4cac81SBjoern A. Zeeb return (false);
40756b4cac81SBjoern A. Zeeb }
40766b4cac81SBjoern A. Zeeb
40776b4cac81SBjoern A. Zeeb /* Return true if skipped; false if error. */
40786b4cac81SBjoern A. Zeeb bool
linuxkpi_ieee80211_ie_advance(size_t * xp,const u8 * ies,size_t ies_len)40796b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ie_advance(size_t *xp, const u8 *ies, size_t ies_len)
40806b4cac81SBjoern A. Zeeb {
40816b4cac81SBjoern A. Zeeb size_t x;
40826b4cac81SBjoern A. Zeeb uint8_t l;
40836b4cac81SBjoern A. Zeeb
40846b4cac81SBjoern A. Zeeb x = *xp;
40856b4cac81SBjoern A. Zeeb
40866b4cac81SBjoern A. Zeeb KASSERT(x < ies_len, ("%s: x %zu ies_len %zu ies %p\n",
40876b4cac81SBjoern A. Zeeb __func__, x, ies_len, ies));
40886b4cac81SBjoern A. Zeeb l = ies[x + 1];
40896b4cac81SBjoern A. Zeeb x += 2 + l;
40906b4cac81SBjoern A. Zeeb
40916b4cac81SBjoern A. Zeeb if (x > ies_len)
40926b4cac81SBjoern A. Zeeb return (false);
40936b4cac81SBjoern A. Zeeb
40946b4cac81SBjoern A. Zeeb *xp = x;
40956b4cac81SBjoern A. Zeeb return (true);
40966b4cac81SBjoern A. Zeeb }
40976b4cac81SBjoern A. Zeeb
4098d9945d78SBjoern A. Zeeb static uint8_t *
lkpi_scan_ies_add(uint8_t * p,struct ieee80211_scan_ies * scan_ies,uint32_t band_mask,struct ieee80211vap * vap,struct ieee80211_hw * hw)4099d9945d78SBjoern A. Zeeb lkpi_scan_ies_add(uint8_t *p, struct ieee80211_scan_ies *scan_ies,
4100d9945d78SBjoern A. Zeeb uint32_t band_mask, struct ieee80211vap *vap, struct ieee80211_hw *hw)
41016b4cac81SBjoern A. Zeeb {
4102d9945d78SBjoern A. Zeeb struct ieee80211_supported_band *supband;
4103d9945d78SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels;
41043dd98026SBjoern A. Zeeb struct ieee80211com *ic;
4105d9945d78SBjoern A. Zeeb const struct ieee80211_channel *chan;
4106d9945d78SBjoern A. Zeeb const struct ieee80211_rateset *rs;
4107d9945d78SBjoern A. Zeeb uint8_t *pb;
4108d9945d78SBjoern A. Zeeb int band, i;
41096b4cac81SBjoern A. Zeeb
41103dd98026SBjoern A. Zeeb ic = vap->iv_ic;
4111d9945d78SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) {
4112d9945d78SBjoern A. Zeeb if ((band_mask & (1 << band)) == 0)
4113d9945d78SBjoern A. Zeeb continue;
4114d9945d78SBjoern A. Zeeb
4115d9945d78SBjoern A. Zeeb supband = hw->wiphy->bands[band];
4116d9945d78SBjoern A. Zeeb /*
4117d9945d78SBjoern A. Zeeb * This should not happen;
4118d9945d78SBjoern A. Zeeb * band_mask is a bitmask of valid bands to scan on.
4119d9945d78SBjoern A. Zeeb */
4120d9945d78SBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0)
4121d9945d78SBjoern A. Zeeb continue;
4122d9945d78SBjoern A. Zeeb
4123d9945d78SBjoern A. Zeeb /* Find a first channel to get the mode and rates from. */
4124d9945d78SBjoern A. Zeeb channels = supband->channels;
4125d9945d78SBjoern A. Zeeb chan = NULL;
4126d9945d78SBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) {
4127f1a110f1SBjoern A. Zeeb uint32_t flags;
4128d9945d78SBjoern A. Zeeb
4129d9945d78SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED)
4130d9945d78SBjoern A. Zeeb continue;
4131d9945d78SBjoern A. Zeeb
4132f1a110f1SBjoern A. Zeeb flags = 0;
4133f1a110f1SBjoern A. Zeeb switch (band) {
4134f1a110f1SBjoern A. Zeeb case NL80211_BAND_2GHZ:
4135f1a110f1SBjoern A. Zeeb flags |= IEEE80211_CHAN_G;
4136f1a110f1SBjoern A. Zeeb break;
4137f1a110f1SBjoern A. Zeeb case NL80211_BAND_5GHZ:
4138f1a110f1SBjoern A. Zeeb flags |= IEEE80211_CHAN_A;
4139f1a110f1SBjoern A. Zeeb break;
4140f1a110f1SBjoern A. Zeeb default:
4141f1a110f1SBjoern A. Zeeb panic("%s:%d: unupported band %d\n",
4142f1a110f1SBjoern A. Zeeb __func__, __LINE__, band);
4143f1a110f1SBjoern A. Zeeb }
4144f1a110f1SBjoern A. Zeeb
41453dd98026SBjoern A. Zeeb chan = ieee80211_find_channel(ic,
4146f1a110f1SBjoern A. Zeeb channels[i].center_freq, flags);
4147d9945d78SBjoern A. Zeeb if (chan != NULL)
4148d9945d78SBjoern A. Zeeb break;
4149d9945d78SBjoern A. Zeeb }
4150d9945d78SBjoern A. Zeeb
4151d9945d78SBjoern A. Zeeb /* This really should not happen. */
4152d9945d78SBjoern A. Zeeb if (chan == NULL)
4153d9945d78SBjoern A. Zeeb continue;
4154d9945d78SBjoern A. Zeeb
4155d9945d78SBjoern A. Zeeb pb = p;
41563dd98026SBjoern A. Zeeb rs = ieee80211_get_suprates(ic, chan); /* calls chan2mode */
4157d9945d78SBjoern A. Zeeb p = ieee80211_add_rates(p, rs);
4158d9945d78SBjoern A. Zeeb p = ieee80211_add_xrates(p, rs);
4159d9945d78SBjoern A. Zeeb
41603dd98026SBjoern A. Zeeb #if defined(LKPI_80211_HT)
41613dd98026SBjoern A. Zeeb if ((vap->iv_flags_ht & IEEE80211_FHT_HT) != 0) {
41623dd98026SBjoern A. Zeeb struct ieee80211_channel *c;
41633dd98026SBjoern A. Zeeb
41643dd98026SBjoern A. Zeeb c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan,
41653dd98026SBjoern A. Zeeb vap->iv_flags_ht);
41663dd98026SBjoern A. Zeeb p = ieee80211_add_htcap_ch(p, vap, c);
41673dd98026SBjoern A. Zeeb }
41683dd98026SBjoern A. Zeeb #endif
41693dd98026SBjoern A. Zeeb #if defined(LKPI_80211_VHT)
41705393cd34SBjoern A. Zeeb if (band == NL80211_BAND_5GHZ &&
41715393cd34SBjoern A. Zeeb (vap->iv_vht_flags & IEEE80211_FVHT_VHT) != 0) {
41723dd98026SBjoern A. Zeeb struct ieee80211_channel *c;
41733dd98026SBjoern A. Zeeb
41743dd98026SBjoern A. Zeeb c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan,
41753dd98026SBjoern A. Zeeb vap->iv_flags_ht);
41763dd98026SBjoern A. Zeeb c = ieee80211_vht_adjust_channel(ic, c,
41773dd98026SBjoern A. Zeeb vap->iv_vht_flags);
41783dd98026SBjoern A. Zeeb p = ieee80211_add_vhtcap_ch(p, vap, c);
41793dd98026SBjoern A. Zeeb }
41803dd98026SBjoern A. Zeeb #endif
41813dd98026SBjoern A. Zeeb
4182d9945d78SBjoern A. Zeeb scan_ies->ies[band] = pb;
4183d9945d78SBjoern A. Zeeb scan_ies->len[band] = p - pb;
4184d9945d78SBjoern A. Zeeb }
4185d9945d78SBjoern A. Zeeb
4186d9945d78SBjoern A. Zeeb /* Add common_ies */
4187d9945d78SBjoern A. Zeeb pb = p;
4188d9945d78SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WPA1) != 0 &&
4189d9945d78SBjoern A. Zeeb vap->iv_wpa_ie != NULL) {
4190d9945d78SBjoern A. Zeeb memcpy(p, vap->iv_wpa_ie, 2 + vap->iv_wpa_ie[1]);
4191d9945d78SBjoern A. Zeeb p += 2 + vap->iv_wpa_ie[1];
4192d9945d78SBjoern A. Zeeb }
4193d9945d78SBjoern A. Zeeb if (vap->iv_appie_probereq != NULL) {
4194d9945d78SBjoern A. Zeeb memcpy(p, vap->iv_appie_probereq->ie_data,
4195d9945d78SBjoern A. Zeeb vap->iv_appie_probereq->ie_len);
4196d9945d78SBjoern A. Zeeb p += vap->iv_appie_probereq->ie_len;
4197d9945d78SBjoern A. Zeeb }
4198d9945d78SBjoern A. Zeeb scan_ies->common_ies = pb;
4199d9945d78SBjoern A. Zeeb scan_ies->common_ie_len = p - pb;
4200d9945d78SBjoern A. Zeeb
4201d9945d78SBjoern A. Zeeb return (p);
42026b4cac81SBjoern A. Zeeb }
42036b4cac81SBjoern A. Zeeb
42046b4cac81SBjoern A. Zeeb static void
lkpi_ic_scan_start(struct ieee80211com * ic)42056b4cac81SBjoern A. Zeeb lkpi_ic_scan_start(struct ieee80211com *ic)
42066b4cac81SBjoern A. Zeeb {
42076b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
42086b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw;
42096b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
42106b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif;
42116b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss;
42126b4cac81SBjoern A. Zeeb struct ieee80211vap *vap;
42136b4cac81SBjoern A. Zeeb int error;
42148ac540d3SBjoern A. Zeeb bool is_hw_scan;
42156b4cac81SBjoern A. Zeeb
42166b4cac81SBjoern A. Zeeb lhw = ic->ic_softc;
42178ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw);
4218a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) {
42196b4cac81SBjoern A. Zeeb /* A scan is still running. */
42208ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw);
42216b4cac81SBjoern A. Zeeb return;
42226b4cac81SBjoern A. Zeeb }
42238ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0;
42248ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw);
42256b4cac81SBjoern A. Zeeb
42266b4cac81SBjoern A. Zeeb ss = ic->ic_scan;
42276b4cac81SBjoern A. Zeeb vap = ss->ss_vap;
42286b4cac81SBjoern A. Zeeb if (vap->iv_state != IEEE80211_S_SCAN) {
4229d3ef7fb4SBjoern A. Zeeb IMPROVE("We need to be able to scan if not in S_SCAN");
42306b4cac81SBjoern A. Zeeb return;
42316b4cac81SBjoern A. Zeeb }
42326b4cac81SBjoern A. Zeeb
42336b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
42348ac540d3SBjoern A. Zeeb if (!is_hw_scan) {
4235a486fbbdSBjoern A. Zeeb /* If hw_scan is cleared clear FEXT_SCAN_OFFLOAD too. */
4236a486fbbdSBjoern A. Zeeb vap->iv_flags_ext &= ~IEEE80211_FEXT_SCAN_OFFLOAD;
4237d3ef7fb4SBjoern A. Zeeb sw_scan:
42386b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
42396b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
4240086be6a8SBjoern A. Zeeb
4241086be6a8SBjoern A. Zeeb if (vap->iv_state == IEEE80211_S_SCAN)
4242086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, false);
4243086be6a8SBjoern A. Zeeb
42446b4cac81SBjoern A. Zeeb lkpi_80211_mo_sw_scan_start(hw, vif, vif->addr);
42456b4cac81SBjoern A. Zeeb /* net80211::scan_start() handled PS for us. */
42466b4cac81SBjoern A. Zeeb IMPROVE();
42476b4cac81SBjoern A. Zeeb /* XXX Also means it is too late to flush queues?
42486b4cac81SBjoern A. Zeeb * need to check iv_sta_ps or overload? */
42496b4cac81SBjoern A. Zeeb /* XXX want to adjust ss end time/ maxdwell? */
42506b4cac81SBjoern A. Zeeb
42516b4cac81SBjoern A. Zeeb } else {
42526b4cac81SBjoern A. Zeeb struct ieee80211_scan_request *hw_req;
42536b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *lc, **cpp;
42546b4cac81SBjoern A. Zeeb struct cfg80211_ssid *ssids;
42556b4cac81SBjoern A. Zeeb struct cfg80211_scan_6ghz_params *s6gp;
42566b4cac81SBjoern A. Zeeb size_t chan_len, nchan, ssids_len, s6ghzlen;
4257d9945d78SBjoern A. Zeeb int band, i, ssid_count, common_ie_len;
4258d9945d78SBjoern A. Zeeb uint32_t band_mask;
4259d9945d78SBjoern A. Zeeb uint8_t *ie, *ieend;
42603206587aSBjoern A. Zeeb bool running;
4261d9945d78SBjoern A. Zeeb
4262d9945d78SBjoern A. Zeeb ssid_count = min(ss->ss_nssid, hw->wiphy->max_scan_ssids);
4263d9945d78SBjoern A. Zeeb ssids_len = ssid_count * sizeof(*ssids);
42646b4cac81SBjoern A. Zeeb s6ghzlen = 0 * (sizeof(*s6gp)); /* XXX-BZ */
42656b4cac81SBjoern A. Zeeb
4266d9945d78SBjoern A. Zeeb band_mask = 0;
42676b4cac81SBjoern A. Zeeb nchan = 0;
4268c272abc5SBjoern A. Zeeb if (ieee80211_hw_check(hw, SINGLE_SCAN_ON_ALL_BANDS)) {
4269c272abc5SBjoern A. Zeeb #if 0 /* Avoid net80211 scan lists until it has proper scan offload support. */
4270d9945d78SBjoern A. Zeeb for (i = ss->ss_next; i < ss->ss_last; i++) {
42716b4cac81SBjoern A. Zeeb nchan++;
4272d9945d78SBjoern A. Zeeb band = lkpi_net80211_chan_to_nl80211_band(
4273d9945d78SBjoern A. Zeeb ss->ss_chans[ss->ss_next + i]);
4274d9945d78SBjoern A. Zeeb band_mask |= (1 << band);
4275d9945d78SBjoern A. Zeeb }
4276c272abc5SBjoern A. Zeeb #else
4277c272abc5SBjoern A. Zeeb /* Instead we scan for all channels all the time. */
4278c272abc5SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) {
4279c272abc5SBjoern A. Zeeb switch (band) {
4280c272abc5SBjoern A. Zeeb case NL80211_BAND_2GHZ:
4281c272abc5SBjoern A. Zeeb case NL80211_BAND_5GHZ:
4282c272abc5SBjoern A. Zeeb break;
4283c272abc5SBjoern A. Zeeb default:
4284c272abc5SBjoern A. Zeeb continue;
4285c272abc5SBjoern A. Zeeb }
4286c272abc5SBjoern A. Zeeb if (hw->wiphy->bands[band] != NULL) {
4287c272abc5SBjoern A. Zeeb nchan += hw->wiphy->bands[band]->n_channels;
4288c272abc5SBjoern A. Zeeb band_mask |= (1 << band);
4289c272abc5SBjoern A. Zeeb }
4290c272abc5SBjoern A. Zeeb }
4291c272abc5SBjoern A. Zeeb #endif
4292c272abc5SBjoern A. Zeeb } else {
42933206587aSBjoern A. Zeeb IMPROVE("individual band scans not yet supported, only scanning first band");
42943206587aSBjoern A. Zeeb /* In theory net80211 should drive this. */
42953206587aSBjoern A. Zeeb /* Probably we need to add local logic for now;
42963206587aSBjoern A. Zeeb * need to deal with scan_complete
42973206587aSBjoern A. Zeeb * and cancel_scan and keep local state.
42983206587aSBjoern A. Zeeb * Also cut the nchan down above.
42993206587aSBjoern A. Zeeb */
43003206587aSBjoern A. Zeeb /* XXX-BZ ath10k does not set this but still does it? &$%^ */
43013206587aSBjoern A. Zeeb }
43023206587aSBjoern A. Zeeb
43036b4cac81SBjoern A. Zeeb chan_len = nchan * (sizeof(lc) + sizeof(*lc));
43046b4cac81SBjoern A. Zeeb
4305d9945d78SBjoern A. Zeeb common_ie_len = 0;
4306d9945d78SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WPA1) != 0 &&
4307d9945d78SBjoern A. Zeeb vap->iv_wpa_ie != NULL)
4308d9945d78SBjoern A. Zeeb common_ie_len += vap->iv_wpa_ie[1];
4309d9945d78SBjoern A. Zeeb if (vap->iv_appie_probereq != NULL)
4310d9945d78SBjoern A. Zeeb common_ie_len += vap->iv_appie_probereq->ie_len;
4311d9945d78SBjoern A. Zeeb
4312d9945d78SBjoern A. Zeeb /* We would love to check this at an earlier stage... */
4313d9945d78SBjoern A. Zeeb if (common_ie_len > hw->wiphy->max_scan_ie_len) {
4314d9945d78SBjoern A. Zeeb ic_printf(ic, "WARNING: %s: common_ie_len %d > "
4315d9945d78SBjoern A. Zeeb "wiphy->max_scan_ie_len %d\n", __func__,
4316d9945d78SBjoern A. Zeeb common_ie_len, hw->wiphy->max_scan_ie_len);
4317d9945d78SBjoern A. Zeeb }
4318d9945d78SBjoern A. Zeeb
43193206587aSBjoern A. Zeeb hw_req = malloc(sizeof(*hw_req) + ssids_len +
4320d9945d78SBjoern A. Zeeb s6ghzlen + chan_len + lhw->supbands * lhw->scan_ie_len +
4321d9945d78SBjoern A. Zeeb common_ie_len, M_LKPI80211, M_WAITOK | M_ZERO);
43226b4cac81SBjoern A. Zeeb
43236b4cac81SBjoern A. Zeeb hw_req->req.flags = 0; /* XXX ??? */
43246b4cac81SBjoern A. Zeeb /* hw_req->req.wdev */
43256b4cac81SBjoern A. Zeeb hw_req->req.wiphy = hw->wiphy;
43266b4cac81SBjoern A. Zeeb hw_req->req.no_cck = false; /* XXX */
43276b4cac81SBjoern A. Zeeb #if 0
43286b4cac81SBjoern A. Zeeb /* This seems to pessimise default scanning behaviour. */
43296b4cac81SBjoern A. Zeeb hw_req->req.duration_mandatory = TICKS_2_USEC(ss->ss_mindwell);
43306b4cac81SBjoern A. Zeeb hw_req->req.duration = TICKS_2_USEC(ss->ss_maxdwell);
43316b4cac81SBjoern A. Zeeb #endif
43326b4cac81SBjoern A. Zeeb #ifdef __notyet__
43336b4cac81SBjoern A. Zeeb hw_req->req.flags |= NL80211_SCAN_FLAG_RANDOM_ADDR;
43346b4cac81SBjoern A. Zeeb memcpy(hw_req->req.mac_addr, xxx, IEEE80211_ADDR_LEN);
43356b4cac81SBjoern A. Zeeb memset(hw_req->req.mac_addr_mask, 0xxx, IEEE80211_ADDR_LEN);
43366b4cac81SBjoern A. Zeeb #endif
4337e1e90be0SBjoern A. Zeeb eth_broadcast_addr(hw_req->req.bssid);
43386b4cac81SBjoern A. Zeeb
43396b4cac81SBjoern A. Zeeb hw_req->req.n_channels = nchan;
43406b4cac81SBjoern A. Zeeb cpp = (struct linuxkpi_ieee80211_channel **)(hw_req + 1);
43416b4cac81SBjoern A. Zeeb lc = (struct linuxkpi_ieee80211_channel *)(cpp + nchan);
43426b4cac81SBjoern A. Zeeb for (i = 0; i < nchan; i++) {
43436b4cac81SBjoern A. Zeeb *(cpp + i) =
43446b4cac81SBjoern A. Zeeb (struct linuxkpi_ieee80211_channel *)(lc + i);
43456b4cac81SBjoern A. Zeeb }
4346c272abc5SBjoern A. Zeeb #if 0 /* Avoid net80211 scan lists until it has proper scan offload support. */
43476b4cac81SBjoern A. Zeeb for (i = 0; i < nchan; i++) {
4348c272abc5SBjoern A. Zeeb struct ieee80211_channel *c;
43496b4cac81SBjoern A. Zeeb
4350c272abc5SBjoern A. Zeeb c = ss->ss_chans[ss->ss_next + i];
43516b4cac81SBjoern A. Zeeb lc->hw_value = c->ic_ieee;
43523206587aSBjoern A. Zeeb lc->center_freq = c->ic_freq; /* XXX */
43536b4cac81SBjoern A. Zeeb /* lc->flags */
43546b4cac81SBjoern A. Zeeb lc->band = lkpi_net80211_chan_to_nl80211_band(c);
43556b4cac81SBjoern A. Zeeb lc->max_power = c->ic_maxpower;
43566b4cac81SBjoern A. Zeeb /* lc-> ... */
43576b4cac81SBjoern A. Zeeb lc++;
43586b4cac81SBjoern A. Zeeb }
4359c272abc5SBjoern A. Zeeb #else
4360c272abc5SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) {
4361c272abc5SBjoern A. Zeeb struct ieee80211_supported_band *supband;
4362c272abc5SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels;
4363c272abc5SBjoern A. Zeeb
4364c272abc5SBjoern A. Zeeb /* Band disabled for scanning? */
4365c272abc5SBjoern A. Zeeb if ((band_mask & (1 << band)) == 0)
4366c272abc5SBjoern A. Zeeb continue;
4367c272abc5SBjoern A. Zeeb
4368c272abc5SBjoern A. Zeeb /* Nothing to scan in band? */
4369c272abc5SBjoern A. Zeeb supband = hw->wiphy->bands[band];
4370c272abc5SBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0)
4371c272abc5SBjoern A. Zeeb continue;
4372c272abc5SBjoern A. Zeeb
4373c272abc5SBjoern A. Zeeb channels = supband->channels;
4374c272abc5SBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) {
4375c272abc5SBjoern A. Zeeb *lc = channels[i];
4376c272abc5SBjoern A. Zeeb lc++;
4377c272abc5SBjoern A. Zeeb }
4378c272abc5SBjoern A. Zeeb }
4379c272abc5SBjoern A. Zeeb #endif
43806b4cac81SBjoern A. Zeeb
4381d9945d78SBjoern A. Zeeb hw_req->req.n_ssids = ssid_count;
43826b4cac81SBjoern A. Zeeb if (hw_req->req.n_ssids > 0) {
43836b4cac81SBjoern A. Zeeb ssids = (struct cfg80211_ssid *)lc;
43846b4cac81SBjoern A. Zeeb hw_req->req.ssids = ssids;
4385d9945d78SBjoern A. Zeeb for (i = 0; i < ssid_count; i++) {
43866b4cac81SBjoern A. Zeeb ssids->ssid_len = ss->ss_ssid[i].len;
43876b4cac81SBjoern A. Zeeb memcpy(ssids->ssid, ss->ss_ssid[i].ssid,
43886b4cac81SBjoern A. Zeeb ss->ss_ssid[i].len);
43896b4cac81SBjoern A. Zeeb ssids++;
43906b4cac81SBjoern A. Zeeb }
43916b4cac81SBjoern A. Zeeb s6gp = (struct cfg80211_scan_6ghz_params *)ssids;
43926b4cac81SBjoern A. Zeeb } else {
43936b4cac81SBjoern A. Zeeb s6gp = (struct cfg80211_scan_6ghz_params *)lc;
43946b4cac81SBjoern A. Zeeb }
43956b4cac81SBjoern A. Zeeb
43966b4cac81SBjoern A. Zeeb /* 6GHz one day. */
43976b4cac81SBjoern A. Zeeb hw_req->req.n_6ghz_params = 0;
43986b4cac81SBjoern A. Zeeb hw_req->req.scan_6ghz_params = NULL;
43996b4cac81SBjoern A. Zeeb hw_req->req.scan_6ghz = false; /* Weird boolean; not what you think. */
44006b4cac81SBjoern A. Zeeb /* s6gp->... */
44016b4cac81SBjoern A. Zeeb
4402d9945d78SBjoern A. Zeeb ie = ieend = (uint8_t *)s6gp;
4403d9945d78SBjoern A. Zeeb /* Copy per-band IEs, copy common IEs */
4404d9945d78SBjoern A. Zeeb ieend = lkpi_scan_ies_add(ie, &hw_req->ies, band_mask, vap, hw);
4405d9945d78SBjoern A. Zeeb hw_req->req.ie = ie;
4406d9945d78SBjoern A. Zeeb hw_req->req.ie_len = ieend - ie;
4407d9945d78SBjoern A. Zeeb
44086b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
44096b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
44103206587aSBjoern A. Zeeb
44113206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw);
44123206587aSBjoern A. Zeeb /* Re-check under lock. */
44133206587aSBjoern A. Zeeb running = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0;
44143206587aSBjoern A. Zeeb if (!running) {
44153206587aSBjoern A. Zeeb KASSERT(lhw->hw_req == NULL, ("%s: ic %p lhw %p hw_req %p "
44163206587aSBjoern A. Zeeb "!= NULL\n", __func__, ic, lhw, lhw->hw_req));
44173206587aSBjoern A. Zeeb
44183206587aSBjoern A. Zeeb lhw->scan_flags |= LKPI_LHW_SCAN_RUNNING;
44193206587aSBjoern A. Zeeb lhw->hw_req = hw_req;
44203206587aSBjoern A. Zeeb }
44213206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw);
44223206587aSBjoern A. Zeeb if (running) {
44233206587aSBjoern A. Zeeb free(hw_req, M_LKPI80211);
44243206587aSBjoern A. Zeeb return;
44253206587aSBjoern A. Zeeb }
44263206587aSBjoern A. Zeeb
44276b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_hw_scan(hw, vif, hw_req);
44286b4cac81SBjoern A. Zeeb if (error != 0) {
4429d9945d78SBjoern A. Zeeb ieee80211_cancel_scan(vap);
4430d9945d78SBjoern A. Zeeb
44313206587aSBjoern A. Zeeb /*
44323206587aSBjoern A. Zeeb * ieee80211_scan_completed must be called in either
44333206587aSBjoern A. Zeeb * case of error or none. So let the free happen there
44343206587aSBjoern A. Zeeb * and only there.
44353206587aSBjoern A. Zeeb * That would be fine in theory but in practice drivers
44363206587aSBjoern A. Zeeb * behave differently:
44373206587aSBjoern A. Zeeb * ath10k does not return hw_scan until after scan_complete
44383206587aSBjoern A. Zeeb * and can then still return an error.
44393206587aSBjoern A. Zeeb * rtw88 can return 1 or -EBUSY without scan_complete
44403206587aSBjoern A. Zeeb * iwlwifi can return various errors before scan starts
44413206587aSBjoern A. Zeeb * ...
44423206587aSBjoern A. Zeeb * So we cannot rely on that behaviour and have to check
44433206587aSBjoern A. Zeeb * and balance between both code paths.
44443206587aSBjoern A. Zeeb */
44453206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw);
44463206587aSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) {
44473206587aSBjoern A. Zeeb free(lhw->hw_req, M_LKPI80211);
44486b4cac81SBjoern A. Zeeb lhw->hw_req = NULL;
44493206587aSBjoern A. Zeeb lhw->scan_flags &= ~LKPI_LHW_SCAN_RUNNING;
44503206587aSBjoern A. Zeeb }
44513206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw);
4452d3ef7fb4SBjoern A. Zeeb
4453d3ef7fb4SBjoern A. Zeeb /*
4454d3ef7fb4SBjoern A. Zeeb * XXX-SIGH magic number.
4455d3ef7fb4SBjoern A. Zeeb * rtw88 has a magic "return 1" if offloading scan is
4456d3ef7fb4SBjoern A. Zeeb * not possible. Fall back to sw scan in that case.
4457d3ef7fb4SBjoern A. Zeeb */
4458196cfd0bSBjoern A. Zeeb if (error == 1) {
44598ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw);
4460a486fbbdSBjoern A. Zeeb lhw->scan_flags &= ~LKPI_LHW_SCAN_HW;
44618ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw);
44623206587aSBjoern A. Zeeb /*
44633206587aSBjoern A. Zeeb * XXX If we clear this now and later a driver
44643206587aSBjoern A. Zeeb * thinks it * can do a hw_scan again, we will
44653206587aSBjoern A. Zeeb * currently not re-enable it?
44663206587aSBjoern A. Zeeb */
44673206587aSBjoern A. Zeeb vap->iv_flags_ext &= ~IEEE80211_FEXT_SCAN_OFFLOAD;
4468196cfd0bSBjoern A. Zeeb ieee80211_start_scan(vap,
4469196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_ACTIVE |
4470196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_NOPICK |
4471196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_ONCE,
4472196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_FOREVER,
4473196cfd0bSBjoern A. Zeeb ss->ss_mindwell ? ss->ss_mindwell : msecs_to_ticks(20),
4474196cfd0bSBjoern A. Zeeb ss->ss_maxdwell ? ss->ss_maxdwell : msecs_to_ticks(200),
4475196cfd0bSBjoern A. Zeeb vap->iv_des_nssid, vap->iv_des_ssid);
4476d3ef7fb4SBjoern A. Zeeb goto sw_scan;
4477196cfd0bSBjoern A. Zeeb }
4478d3ef7fb4SBjoern A. Zeeb
4479d3ef7fb4SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: hw_scan returned %d\n",
4480d3ef7fb4SBjoern A. Zeeb __func__, error);
44816b4cac81SBjoern A. Zeeb }
44826b4cac81SBjoern A. Zeeb }
44836b4cac81SBjoern A. Zeeb }
44846b4cac81SBjoern A. Zeeb
44856b4cac81SBjoern A. Zeeb static void
lkpi_ic_scan_end(struct ieee80211com * ic)44866b4cac81SBjoern A. Zeeb lkpi_ic_scan_end(struct ieee80211com *ic)
44876b4cac81SBjoern A. Zeeb {
44886b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
44898ac540d3SBjoern A. Zeeb bool is_hw_scan;
44906b4cac81SBjoern A. Zeeb
44916b4cac81SBjoern A. Zeeb lhw = ic->ic_softc;
44928ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw);
4493a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) == 0) {
44948ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw);
44956b4cac81SBjoern A. Zeeb return;
44966b4cac81SBjoern A. Zeeb }
44978ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0;
44988ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw);
44996b4cac81SBjoern A. Zeeb
45008ac540d3SBjoern A. Zeeb if (!is_hw_scan) {
4501a486fbbdSBjoern A. Zeeb struct ieee80211_scan_state *ss;
4502a486fbbdSBjoern A. Zeeb struct ieee80211vap *vap;
45036b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw;
45046b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
45056b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif;
45066b4cac81SBjoern A. Zeeb
4507a486fbbdSBjoern A. Zeeb ss = ic->ic_scan;
4508a486fbbdSBjoern A. Zeeb vap = ss->ss_vap;
45096b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
45106b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
45116b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
4512a486fbbdSBjoern A. Zeeb
45136b4cac81SBjoern A. Zeeb lkpi_80211_mo_sw_scan_complete(hw, vif);
45146b4cac81SBjoern A. Zeeb
45156b4cac81SBjoern A. Zeeb /* Send PS to stop buffering if n80211 does not for us? */
4516086be6a8SBjoern A. Zeeb
4517086be6a8SBjoern A. Zeeb if (vap->iv_state == IEEE80211_S_SCAN)
4518086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true);
45196b4cac81SBjoern A. Zeeb }
45206b4cac81SBjoern A. Zeeb }
45216b4cac81SBjoern A. Zeeb
45226b4cac81SBjoern A. Zeeb static void
lkpi_ic_scan_curchan(struct ieee80211_scan_state * ss,unsigned long maxdwell)4523a486fbbdSBjoern A. Zeeb lkpi_ic_scan_curchan(struct ieee80211_scan_state *ss,
4524a486fbbdSBjoern A. Zeeb unsigned long maxdwell)
4525a486fbbdSBjoern A. Zeeb {
4526a486fbbdSBjoern A. Zeeb struct lkpi_hw *lhw;
45278ac540d3SBjoern A. Zeeb bool is_hw_scan;
4528a486fbbdSBjoern A. Zeeb
4529a486fbbdSBjoern A. Zeeb lhw = ss->ss_ic->ic_softc;
45308ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw);
45318ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0;
45328ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw);
45338ac540d3SBjoern A. Zeeb if (!is_hw_scan)
4534a486fbbdSBjoern A. Zeeb lhw->ic_scan_curchan(ss, maxdwell);
4535a486fbbdSBjoern A. Zeeb }
4536a486fbbdSBjoern A. Zeeb
4537a486fbbdSBjoern A. Zeeb static void
lkpi_ic_scan_mindwell(struct ieee80211_scan_state * ss)4538a486fbbdSBjoern A. Zeeb lkpi_ic_scan_mindwell(struct ieee80211_scan_state *ss)
4539a486fbbdSBjoern A. Zeeb {
4540a486fbbdSBjoern A. Zeeb struct lkpi_hw *lhw;
45418ac540d3SBjoern A. Zeeb bool is_hw_scan;
4542a486fbbdSBjoern A. Zeeb
4543a486fbbdSBjoern A. Zeeb lhw = ss->ss_ic->ic_softc;
45448ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw);
45458ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0;
45468ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw);
45478ac540d3SBjoern A. Zeeb if (!is_hw_scan)
4548a486fbbdSBjoern A. Zeeb lhw->ic_scan_mindwell(ss);
4549a486fbbdSBjoern A. Zeeb }
4550a486fbbdSBjoern A. Zeeb
4551a486fbbdSBjoern A. Zeeb static void
lkpi_ic_set_channel(struct ieee80211com * ic)45526b4cac81SBjoern A. Zeeb lkpi_ic_set_channel(struct ieee80211com *ic)
45536b4cac81SBjoern A. Zeeb {
45546b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
45556b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw;
4556b2cf3c21SBjoern A. Zeeb struct ieee80211_channel *c;
4557b2cf3c21SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan;
45586b4cac81SBjoern A. Zeeb int error;
45598ac540d3SBjoern A. Zeeb bool hw_scan_running;
45606b4cac81SBjoern A. Zeeb
45616b4cac81SBjoern A. Zeeb lhw = ic->ic_softc;
4562b2cf3c21SBjoern A. Zeeb
4563b2cf3c21SBjoern A. Zeeb /* If we do not support (*config)() save us the work. */
4564b2cf3c21SBjoern A. Zeeb if (lhw->ops->config == NULL)
45656b4cac81SBjoern A. Zeeb return;
45666b4cac81SBjoern A. Zeeb
4567a486fbbdSBjoern A. Zeeb /* If we have a hw_scan running do not switch channels. */
45688ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw);
45698ac540d3SBjoern A. Zeeb hw_scan_running =
45708ac540d3SBjoern A. Zeeb (lhw->scan_flags & (LKPI_LHW_SCAN_RUNNING|LKPI_LHW_SCAN_HW)) ==
45718ac540d3SBjoern A. Zeeb (LKPI_LHW_SCAN_RUNNING|LKPI_LHW_SCAN_HW);
45728ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw);
45738ac540d3SBjoern A. Zeeb if (hw_scan_running)
4574a486fbbdSBjoern A. Zeeb return;
4575a486fbbdSBjoern A. Zeeb
4576b2cf3c21SBjoern A. Zeeb c = ic->ic_curchan;
4577b2cf3c21SBjoern A. Zeeb if (c == NULL || c == IEEE80211_CHAN_ANYC) {
45786b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: c %p ops->config %p\n", __func__,
45796b4cac81SBjoern A. Zeeb c, lhw->ops->config);
45806b4cac81SBjoern A. Zeeb return;
45816b4cac81SBjoern A. Zeeb }
45826b4cac81SBjoern A. Zeeb
45836b4cac81SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, c);
45846b4cac81SBjoern A. Zeeb if (chan == NULL) {
45856b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: c %p chan %p\n", __func__,
45866b4cac81SBjoern A. Zeeb c, chan);
45876b4cac81SBjoern A. Zeeb return;
45886b4cac81SBjoern A. Zeeb }
45896b4cac81SBjoern A. Zeeb
45906b4cac81SBjoern A. Zeeb /* XXX max power for scanning? */
45916b4cac81SBjoern A. Zeeb IMPROVE();
45926b4cac81SBjoern A. Zeeb
45936b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
45944a07abdeSBjoern A. Zeeb cfg80211_chandef_create(&hw->conf.chandef, chan,
45959fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT
459611450726SBjoern A. Zeeb (ic->ic_flags_ht & IEEE80211_FHT_HT) ? NL80211_CHAN_HT20 :
45979fb91463SBjoern A. Zeeb #endif
45984a07abdeSBjoern A. Zeeb NL80211_CHAN_NO_HT);
45996b4cac81SBjoern A. Zeeb
46006b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_CHANNEL);
46016b4cac81SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) {
46026b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: config %#0x returned %d\n",
46036b4cac81SBjoern A. Zeeb __func__, IEEE80211_CONF_CHANGE_CHANNEL, error);
46046b4cac81SBjoern A. Zeeb /* XXX should we unroll to the previous chandef? */
46056b4cac81SBjoern A. Zeeb IMPROVE();
46066b4cac81SBjoern A. Zeeb } else {
46076b4cac81SBjoern A. Zeeb /* Update radiotap channels as well. */
46086b4cac81SBjoern A. Zeeb lhw->rtap_tx.wt_chan_freq = htole16(c->ic_freq);
46096b4cac81SBjoern A. Zeeb lhw->rtap_tx.wt_chan_flags = htole16(c->ic_flags);
46106b4cac81SBjoern A. Zeeb lhw->rtap_rx.wr_chan_freq = htole16(c->ic_freq);
46116b4cac81SBjoern A. Zeeb lhw->rtap_rx.wr_chan_flags = htole16(c->ic_flags);
46126b4cac81SBjoern A. Zeeb }
46136b4cac81SBjoern A. Zeeb
46146b4cac81SBjoern A. Zeeb /* Currently PS is hard coded off! Not sure it belongs here. */
46156b4cac81SBjoern A. Zeeb IMPROVE();
46166b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, SUPPORTS_PS) &&
46176b4cac81SBjoern A. Zeeb (hw->conf.flags & IEEE80211_CONF_PS) != 0) {
46186b4cac81SBjoern A. Zeeb hw->conf.flags &= ~IEEE80211_CONF_PS;
46196b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_PS);
46206b4cac81SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP)
46216b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: config %#0x returned "
46226b4cac81SBjoern A. Zeeb "%d\n", __func__, IEEE80211_CONF_CHANGE_PS,
46236b4cac81SBjoern A. Zeeb error);
46246b4cac81SBjoern A. Zeeb }
46256b4cac81SBjoern A. Zeeb }
46266b4cac81SBjoern A. Zeeb
46276b4cac81SBjoern A. Zeeb static struct ieee80211_node *
lkpi_ic_node_alloc(struct ieee80211vap * vap,const uint8_t mac[IEEE80211_ADDR_LEN])46286b4cac81SBjoern A. Zeeb lkpi_ic_node_alloc(struct ieee80211vap *vap,
46296b4cac81SBjoern A. Zeeb const uint8_t mac[IEEE80211_ADDR_LEN])
46306b4cac81SBjoern A. Zeeb {
46316b4cac81SBjoern A. Zeeb struct ieee80211com *ic;
46326b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
46334f61ef8bSBjoern A. Zeeb struct ieee80211_node *ni;
46346b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw;
46356b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta;
46366b4cac81SBjoern A. Zeeb
46376b4cac81SBjoern A. Zeeb ic = vap->iv_ic;
46386b4cac81SBjoern A. Zeeb lhw = ic->ic_softc;
46396b4cac81SBjoern A. Zeeb
46406b4cac81SBjoern A. Zeeb /* We keep allocations de-coupled so we can deal with the two worlds. */
46414f61ef8bSBjoern A. Zeeb if (lhw->ic_node_alloc == NULL)
46424f61ef8bSBjoern A. Zeeb return (NULL);
46434f61ef8bSBjoern A. Zeeb
46446b4cac81SBjoern A. Zeeb ni = lhw->ic_node_alloc(vap, mac);
46456b4cac81SBjoern A. Zeeb if (ni == NULL)
46466b4cac81SBjoern A. Zeeb return (NULL);
46476b4cac81SBjoern A. Zeeb
46486b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
46494f61ef8bSBjoern A. Zeeb lsta = lkpi_lsta_alloc(vap, mac, hw, ni);
46506b4cac81SBjoern A. Zeeb if (lsta == NULL) {
46516b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL)
46526b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni);
46536b4cac81SBjoern A. Zeeb return (NULL);
46546b4cac81SBjoern A. Zeeb }
46556b4cac81SBjoern A. Zeeb
46566b4cac81SBjoern A. Zeeb return (ni);
46576b4cac81SBjoern A. Zeeb }
46586b4cac81SBjoern A. Zeeb
46596b4cac81SBjoern A. Zeeb static int
lkpi_ic_node_init(struct ieee80211_node * ni)46606b4cac81SBjoern A. Zeeb lkpi_ic_node_init(struct ieee80211_node *ni)
46616b4cac81SBjoern A. Zeeb {
46626b4cac81SBjoern A. Zeeb struct ieee80211com *ic;
46636b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
46646b4cac81SBjoern A. Zeeb int error;
46656b4cac81SBjoern A. Zeeb
46666b4cac81SBjoern A. Zeeb ic = ni->ni_ic;
46676b4cac81SBjoern A. Zeeb lhw = ic->ic_softc;
46686b4cac81SBjoern A. Zeeb
46696b4cac81SBjoern A. Zeeb if (lhw->ic_node_init != NULL) {
46706b4cac81SBjoern A. Zeeb error = lhw->ic_node_init(ni);
46716b4cac81SBjoern A. Zeeb if (error != 0)
46726b4cac81SBjoern A. Zeeb return (error);
46736b4cac81SBjoern A. Zeeb }
46746b4cac81SBjoern A. Zeeb
46756b4cac81SBjoern A. Zeeb /* XXX-BZ Sync other state over. */
46766b4cac81SBjoern A. Zeeb IMPROVE();
46776b4cac81SBjoern A. Zeeb
46786b4cac81SBjoern A. Zeeb return (0);
46796b4cac81SBjoern A. Zeeb }
46806b4cac81SBjoern A. Zeeb
46816b4cac81SBjoern A. Zeeb static void
lkpi_ic_node_cleanup(struct ieee80211_node * ni)46826b4cac81SBjoern A. Zeeb lkpi_ic_node_cleanup(struct ieee80211_node *ni)
46836b4cac81SBjoern A. Zeeb {
46846b4cac81SBjoern A. Zeeb struct ieee80211com *ic;
46856b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
46866b4cac81SBjoern A. Zeeb
46876b4cac81SBjoern A. Zeeb ic = ni->ni_ic;
46886b4cac81SBjoern A. Zeeb lhw = ic->ic_softc;
46896b4cac81SBjoern A. Zeeb
46906b4cac81SBjoern A. Zeeb /* XXX-BZ remove from driver, ... */
46916b4cac81SBjoern A. Zeeb IMPROVE();
46926b4cac81SBjoern A. Zeeb
46936b4cac81SBjoern A. Zeeb if (lhw->ic_node_cleanup != NULL)
46946b4cac81SBjoern A. Zeeb lhw->ic_node_cleanup(ni);
46956b4cac81SBjoern A. Zeeb }
46966b4cac81SBjoern A. Zeeb
46976b4cac81SBjoern A. Zeeb static void
lkpi_ic_node_free(struct ieee80211_node * ni)46986b4cac81SBjoern A. Zeeb lkpi_ic_node_free(struct ieee80211_node *ni)
46996b4cac81SBjoern A. Zeeb {
47006b4cac81SBjoern A. Zeeb struct ieee80211com *ic;
47016b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
47026b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta;
47036b4cac81SBjoern A. Zeeb
47046b4cac81SBjoern A. Zeeb ic = ni->ni_ic;
47056b4cac81SBjoern A. Zeeb lhw = ic->ic_softc;
47066b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data;
47076b4cac81SBjoern A. Zeeb
47080936c648SBjoern A. Zeeb /* KASSERT lsta is not NULL here. Print ni/ni__refcnt. */
47096b4cac81SBjoern A. Zeeb
47100936c648SBjoern A. Zeeb /*
47110936c648SBjoern A. Zeeb * Pass in the original ni just in case of error we could check that
47120936c648SBjoern A. Zeeb * it is the same as lsta->ni.
47130936c648SBjoern A. Zeeb */
47140936c648SBjoern A. Zeeb lkpi_lsta_free(lsta, ni);
47156b4cac81SBjoern A. Zeeb
47166b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL)
47176b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni);
47186b4cac81SBjoern A. Zeeb }
47196b4cac81SBjoern A. Zeeb
47209a45c3caSBjoern A. Zeeb /*
47219a45c3caSBjoern A. Zeeb * lkpi_xmit() called from both the (*ic_raw_xmit) as well as the (*ic_transmit)
47229a45c3caSBjoern A. Zeeb * call path.
47239a45c3caSBjoern A. Zeeb * Unfortunately they have slightly different invariants. See
47249a45c3caSBjoern A. Zeeb * ieee80211_raw_output() and ieee80211_parent_xmitpkt().
47259a45c3caSBjoern A. Zeeb * Both take care of the ni reference in case of error, and otherwise during
47269a45c3caSBjoern A. Zeeb * the callback after transmit.
47279a45c3caSBjoern A. Zeeb * The difference is that in case of error (*ic_raw_xmit) needs us to release
47289a45c3caSBjoern A. Zeeb * the mbuf, while (*ic_transmit) will free the mbuf itself.
47299a45c3caSBjoern A. Zeeb */
47306b4cac81SBjoern A. Zeeb static int
lkpi_xmit(struct ieee80211_node * ni,struct mbuf * m,const struct ieee80211_bpf_params * params __unused,bool freem)47319a45c3caSBjoern A. Zeeb lkpi_xmit(struct ieee80211_node *ni, struct mbuf *m,
47329a45c3caSBjoern A. Zeeb const struct ieee80211_bpf_params *params __unused,
47339a45c3caSBjoern A. Zeeb bool freem)
47346b4cac81SBjoern A. Zeeb {
47356b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta;
4736c816f64eSBjoern A. Zeeb int error;
47376b4cac81SBjoern A. Zeeb
47386b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data;
4739fa4e4257SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_LOCK(lsta);
47402372f8ccSBjoern A. Zeeb #if 0
474188665349SBjoern A. Zeeb if (!lsta->added_to_drv || !lsta->txq_ready) {
47422372f8ccSBjoern A. Zeeb #else
47432372f8ccSBjoern A. Zeeb /*
47442372f8ccSBjoern A. Zeeb * Backout this part of 886653492945f which breaks rtw88 or
47452372f8ccSBjoern A. Zeeb * in general drivers without (*sta_state)() but only the
47462372f8ccSBjoern A. Zeeb * legacy fallback to (*sta_add)().
47472372f8ccSBjoern A. Zeeb */
47482372f8ccSBjoern A. Zeeb if (!lsta->txq_ready) {
47492372f8ccSBjoern A. Zeeb #endif
4750fa4e4257SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_UNLOCK(lsta);
47519a45c3caSBjoern A. Zeeb if (freem)
47520936c648SBjoern A. Zeeb m_free(m);
47530936c648SBjoern A. Zeeb return (ENETDOWN);
47540936c648SBjoern A. Zeeb }
47556b4cac81SBjoern A. Zeeb
47566b4cac81SBjoern A. Zeeb /* Queue the packet and enqueue the task to handle it. */
4757c816f64eSBjoern A. Zeeb error = mbufq_enqueue(&lsta->txq, m);
4758c816f64eSBjoern A. Zeeb if (error != 0) {
4759c816f64eSBjoern A. Zeeb LKPI_80211_LSTA_TXQ_UNLOCK(lsta);
47609a45c3caSBjoern A. Zeeb if (freem)
4761c816f64eSBjoern A. Zeeb m_free(m);
4762c816f64eSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
4763c816f64eSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX)
4764c816f64eSBjoern A. Zeeb ic_printf(ni->ni_ic, "%s: mbufq_enqueue failed: %d\n",
4765c816f64eSBjoern A. Zeeb __func__, error);
4766c816f64eSBjoern A. Zeeb #endif
4767c816f64eSBjoern A. Zeeb return (ENETDOWN);
4768c816f64eSBjoern A. Zeeb }
4769fa4e4257SBjoern A. Zeeb taskqueue_enqueue(taskqueue_thread, &lsta->txq_task);
4770fa4e4257SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_UNLOCK(lsta);
47716b4cac81SBjoern A. Zeeb
47729d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
47739d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX)
47746b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p ni %p %6D mbuf_qlen %d\n",
47756b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, ni, ni->ni_macaddr, ":",
47766b4cac81SBjoern A. Zeeb mbufq_len(&lsta->txq));
47779d9ba2b7SBjoern A. Zeeb #endif
47786b4cac81SBjoern A. Zeeb
47796b4cac81SBjoern A. Zeeb return (0);
47806b4cac81SBjoern A. Zeeb }
47816b4cac81SBjoern A. Zeeb
47829a45c3caSBjoern A. Zeeb static int
47839a45c3caSBjoern A. Zeeb lkpi_ic_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
47849a45c3caSBjoern A. Zeeb const struct ieee80211_bpf_params *params __unused)
47859a45c3caSBjoern A. Zeeb {
47869a45c3caSBjoern A. Zeeb return (lkpi_xmit(ni, m, NULL, true));
47879a45c3caSBjoern A. Zeeb }
47889a45c3caSBjoern A. Zeeb
478911db70b6SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO
47904b9ae864SBjoern A. Zeeb /*
47914b9ae864SBjoern A. Zeeb * This is a bit of a hack given we know we are operating on a
47924b9ae864SBjoern A. Zeeb * single frame and we know that hardware will deal with it.
47934b9ae864SBjoern A. Zeeb * But otherwise the enmic bit and the encrypt bit need to be
47944b9ae864SBjoern A. Zeeb * decoupled.
47954b9ae864SBjoern A. Zeeb */
479611db70b6SBjoern A. Zeeb static int
479798e55905SBjoern A. Zeeb lkpi_hw_crypto_prepare_tkip(struct ieee80211_key *k,
479898e55905SBjoern A. Zeeb struct ieee80211_key_conf *kc, struct sk_buff *skb)
479911db70b6SBjoern A. Zeeb {
480098e55905SBjoern A. Zeeb struct ieee80211_hdr *hdr;
480198e55905SBjoern A. Zeeb uint32_t hlen, hdrlen;
48024b9ae864SBjoern A. Zeeb uint8_t *p;
480398e55905SBjoern A. Zeeb
480498e55905SBjoern A. Zeeb /*
48054b9ae864SBjoern A. Zeeb * TKIP only happens on data.
48064b9ae864SBjoern A. Zeeb */
48074b9ae864SBjoern A. Zeeb hdr = (void *)skb->data;
48084b9ae864SBjoern A. Zeeb if (!ieee80211_is_data_present(hdr->frame_control))
48094b9ae864SBjoern A. Zeeb return (0);
48104b9ae864SBjoern A. Zeeb
48114b9ae864SBjoern A. Zeeb /*
48124b9ae864SBjoern A. Zeeb * "enmic" (though we do not do that).
48134b9ae864SBjoern A. Zeeb */
48144b9ae864SBjoern A. Zeeb /* any conditions to not apply this? */
48154b9ae864SBjoern A. Zeeb if (skb_tailroom(skb) < k->wk_cipher->ic_miclen)
48164b9ae864SBjoern A. Zeeb return (ENOBUFS);
48174b9ae864SBjoern A. Zeeb
48184b9ae864SBjoern A. Zeeb p = skb_put(skb, k->wk_cipher->ic_miclen);
48194b9ae864SBjoern A. Zeeb if ((kc->flags & IEEE80211_KEY_FLAG_PUT_MIC_SPACE) != 0)
48204b9ae864SBjoern A. Zeeb goto encrypt;
48214b9ae864SBjoern A. Zeeb
48224b9ae864SBjoern A. Zeeb /*
48234b9ae864SBjoern A. Zeeb * (*enmic) which we hopefully do not have to do with hw accel.
48244b9ae864SBjoern A. Zeeb * That means if we make it here we have a problem.
48254b9ae864SBjoern A. Zeeb */
48264b9ae864SBjoern A. Zeeb TODO("(*enmic)");
48274b9ae864SBjoern A. Zeeb return (ENXIO);
48284b9ae864SBjoern A. Zeeb
48294b9ae864SBjoern A. Zeeb encrypt:
48304b9ae864SBjoern A. Zeeb /*
48314b9ae864SBjoern A. Zeeb * "encrypt" (though we do not do that).
48324b9ae864SBjoern A. Zeeb */
48334b9ae864SBjoern A. Zeeb /*
48344b9ae864SBjoern A. Zeeb * Check if we have anything to do as requested by driver
483598e55905SBjoern A. Zeeb * or if we are done?
483698e55905SBjoern A. Zeeb */
483798e55905SBjoern A. Zeeb if ((kc->flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE) == 0 &&
483898e55905SBjoern A. Zeeb (kc->flags & IEEE80211_KEY_FLAG_GENERATE_IV) == 0)
483998e55905SBjoern A. Zeeb return (0);
484098e55905SBjoern A. Zeeb
484198e55905SBjoern A. Zeeb hlen = k->wk_cipher->ic_header;
484298e55905SBjoern A. Zeeb if (skb_headroom(skb) < hlen)
48434b9ae864SBjoern A. Zeeb return (ENOBUFS);
484498e55905SBjoern A. Zeeb
484598e55905SBjoern A. Zeeb hdr = (void *)skb->data;
484698e55905SBjoern A. Zeeb hdrlen = ieee80211_hdrlen(hdr->frame_control);
484798e55905SBjoern A. Zeeb p = skb_push(skb, hlen);
484898e55905SBjoern A. Zeeb memmove(p, p + hlen, hdrlen);
484998e55905SBjoern A. Zeeb
485098e55905SBjoern A. Zeeb /* If driver request space only we are done. */
485198e55905SBjoern A. Zeeb if ((kc->flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE) != 0)
485298e55905SBjoern A. Zeeb return (0);
485398e55905SBjoern A. Zeeb
485498e55905SBjoern A. Zeeb p += hdrlen;
485598e55905SBjoern A. Zeeb k->wk_cipher->ic_setiv(k, p);
485698e55905SBjoern A. Zeeb
48574b9ae864SBjoern A. Zeeb /* If we make it hear we do sw encryption. */
48584b9ae864SBjoern A. Zeeb TODO("sw encrypt");
485998e55905SBjoern A. Zeeb return (ENXIO);
486098e55905SBjoern A. Zeeb }
486129ddd583SBjoern A. Zeeb
486298e55905SBjoern A. Zeeb static int
486398e55905SBjoern A. Zeeb lkpi_hw_crypto_prepare_ccmp(struct ieee80211_key *k,
486498e55905SBjoern A. Zeeb struct ieee80211_key_conf *kc, struct sk_buff *skb)
486598e55905SBjoern A. Zeeb {
486611db70b6SBjoern A. Zeeb struct ieee80211_hdr *hdr;
486711db70b6SBjoern A. Zeeb uint32_t hlen, hdrlen;
486811db70b6SBjoern A. Zeeb uint8_t *p;
486911db70b6SBjoern A. Zeeb
487011db70b6SBjoern A. Zeeb hdr = (void *)skb->data;
487111db70b6SBjoern A. Zeeb
487211db70b6SBjoern A. Zeeb /*
487311db70b6SBjoern A. Zeeb * Check if we have anythig to do as requested by driver
487411db70b6SBjoern A. Zeeb * or if we are done?
487511db70b6SBjoern A. Zeeb */
487611db70b6SBjoern A. Zeeb if ((kc->flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE) == 0 &&
487711db70b6SBjoern A. Zeeb (kc->flags & IEEE80211_KEY_FLAG_GENERATE_IV) == 0 &&
487811db70b6SBjoern A. Zeeb /* MFP */
487911db70b6SBjoern A. Zeeb !((kc->flags & IEEE80211_KEY_FLAG_GENERATE_IV_MGMT) != 0 &&
488011db70b6SBjoern A. Zeeb ieee80211_is_mgmt(hdr->frame_control)))
488111db70b6SBjoern A. Zeeb return (0);
488211db70b6SBjoern A. Zeeb
488311db70b6SBjoern A. Zeeb hlen = k->wk_cipher->ic_header;
488411db70b6SBjoern A. Zeeb if (skb_headroom(skb) < hlen)
48854b9ae864SBjoern A. Zeeb return (ENOBUFS);
488611db70b6SBjoern A. Zeeb
488711db70b6SBjoern A. Zeeb hdrlen = ieee80211_hdrlen(hdr->frame_control);
488811db70b6SBjoern A. Zeeb p = skb_push(skb, hlen);
488911db70b6SBjoern A. Zeeb memmove(p, p + hlen, hdrlen);
489011db70b6SBjoern A. Zeeb
489111db70b6SBjoern A. Zeeb /* If driver request space only we are done. */
489211db70b6SBjoern A. Zeeb if ((kc->flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE) != 0)
489311db70b6SBjoern A. Zeeb return (0);
489411db70b6SBjoern A. Zeeb
489511db70b6SBjoern A. Zeeb p += hdrlen;
489611db70b6SBjoern A. Zeeb k->wk_cipher->ic_setiv(k, p);
489711db70b6SBjoern A. Zeeb
489811db70b6SBjoern A. Zeeb return (0);
489911db70b6SBjoern A. Zeeb }
490098e55905SBjoern A. Zeeb
490198e55905SBjoern A. Zeeb static int
490298e55905SBjoern A. Zeeb lkpi_hw_crypto_prepare(struct lkpi_sta *lsta, struct ieee80211_key *k,
490398e55905SBjoern A. Zeeb struct sk_buff *skb)
490498e55905SBjoern A. Zeeb {
490598e55905SBjoern A. Zeeb struct ieee80211_tx_info *info;
490698e55905SBjoern A. Zeeb struct ieee80211_key_conf *kc;
490798e55905SBjoern A. Zeeb
490898e55905SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: lsta is NULL", __func__));
490998e55905SBjoern A. Zeeb KASSERT(k != NULL, ("%s: key is NULL", __func__));
491098e55905SBjoern A. Zeeb KASSERT(skb != NULL, ("%s: skb is NULL", __func__));
491198e55905SBjoern A. Zeeb
491298e55905SBjoern A. Zeeb kc = lsta->kc[k->wk_keyix];
491398e55905SBjoern A. Zeeb
491498e55905SBjoern A. Zeeb info = IEEE80211_SKB_CB(skb);
491598e55905SBjoern A. Zeeb info->control.hw_key = kc;
491698e55905SBjoern A. Zeeb
491798e55905SBjoern A. Zeeb /* MUST NOT happen. KASSERT? */
491898e55905SBjoern A. Zeeb if (kc == NULL) {
491998e55905SBjoern A. Zeeb ic_printf(lsta->ni->ni_ic, "%s: lsta %p k %p skb %p, "
492098e55905SBjoern A. Zeeb "kc is NULL on hw crypto offload\n", __func__, lsta, k, skb);
492198e55905SBjoern A. Zeeb return (ENXIO);
492298e55905SBjoern A. Zeeb }
492398e55905SBjoern A. Zeeb
492498e55905SBjoern A. Zeeb switch (kc->cipher) {
492598e55905SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP:
492698e55905SBjoern A. Zeeb return (lkpi_hw_crypto_prepare_tkip(k, kc, skb));
492798e55905SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP:
492898e55905SBjoern A. Zeeb return (lkpi_hw_crypto_prepare_ccmp(k, kc, skb));
492929ddd583SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP:
493029ddd583SBjoern A. Zeeb return (lkpi_hw_crypto_prepare_ccmp(k, kc, skb));
493198e55905SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP40:
493298e55905SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP104:
493398e55905SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP_256:
493498e55905SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP_256:
493598e55905SBjoern A. Zeeb case WLAN_CIPHER_SUITE_AES_CMAC:
493698e55905SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_CMAC_256:
493798e55905SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_128:
493898e55905SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_256:
493998e55905SBjoern A. Zeeb default:
494098e55905SBjoern A. Zeeb ic_printf(lsta->ni->ni_ic, "%s: lsta %p k %p kc %p skb %p, "
494198e55905SBjoern A. Zeeb "unsupported cipher suite %u (%s)\n", __func__, lsta, k, kc,
494298e55905SBjoern A. Zeeb skb, kc->cipher, lkpi_cipher_suite_to_name(kc->cipher));
494398e55905SBjoern A. Zeeb return (EOPNOTSUPP);
494498e55905SBjoern A. Zeeb }
494598e55905SBjoern A. Zeeb }
494698e55905SBjoern A. Zeeb
494798e55905SBjoern A. Zeeb static uint8_t
494898e55905SBjoern A. Zeeb lkpi_hw_crypto_tailroom(struct lkpi_sta *lsta, struct ieee80211_key *k)
494998e55905SBjoern A. Zeeb {
495098e55905SBjoern A. Zeeb struct ieee80211_key_conf *kc;
495198e55905SBjoern A. Zeeb
495298e55905SBjoern A. Zeeb kc = lsta->kc[k->wk_keyix];
495398e55905SBjoern A. Zeeb if (kc == NULL)
495498e55905SBjoern A. Zeeb return (0);
495598e55905SBjoern A. Zeeb
495698e55905SBjoern A. Zeeb IMPROVE("which other flags need tailroom?");
495798e55905SBjoern A. Zeeb if (kc->flags & (IEEE80211_KEY_FLAG_PUT_MIC_SPACE))
495898e55905SBjoern A. Zeeb return (32); /* Large enough to hold everything and pow2. */
495998e55905SBjoern A. Zeeb
496098e55905SBjoern A. Zeeb return (0);
496198e55905SBjoern A. Zeeb }
496211db70b6SBjoern A. Zeeb #endif
496311db70b6SBjoern A. Zeeb
49646b4cac81SBjoern A. Zeeb static void
49656b4cac81SBjoern A. Zeeb lkpi_80211_txq_tx_one(struct lkpi_sta *lsta, struct mbuf *m)
49666b4cac81SBjoern A. Zeeb {
49676b4cac81SBjoern A. Zeeb struct ieee80211_node *ni;
49686b4cac81SBjoern A. Zeeb struct ieee80211_frame *wh;
49696b4cac81SBjoern A. Zeeb struct ieee80211_key *k;
49706b4cac81SBjoern A. Zeeb struct sk_buff *skb;
49716b4cac81SBjoern A. Zeeb struct ieee80211com *ic;
49726b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
49736b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw;
49746b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
49756b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif;
49766b4cac81SBjoern A. Zeeb struct ieee80211_channel *c;
49776b4cac81SBjoern A. Zeeb struct ieee80211_tx_control control;
49786b4cac81SBjoern A. Zeeb struct ieee80211_tx_info *info;
49796b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta;
4980e3a0b120SBjoern A. Zeeb struct ieee80211_hdr *hdr;
4981ac867c20SBjoern A. Zeeb struct lkpi_txq *ltxq;
49826b4cac81SBjoern A. Zeeb void *buf;
498311db70b6SBjoern A. Zeeb ieee80211_keyix keyix;
498498e55905SBjoern A. Zeeb uint8_t ac, tid, tailroom;
49856b4cac81SBjoern A. Zeeb
49866b4cac81SBjoern A. Zeeb M_ASSERTPKTHDR(m);
49876b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
49889d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX_DUMP)
49896b4cac81SBjoern A. Zeeb hexdump(mtod(m, const void *), m->m_len, "RAW TX (plain) ", 0);
49906b4cac81SBjoern A. Zeeb #endif
49916b4cac81SBjoern A. Zeeb
49926b4cac81SBjoern A. Zeeb ni = lsta->ni;
4993b35f6cd0SBjoern A. Zeeb k = NULL;
499411db70b6SBjoern A. Zeeb keyix = IEEE80211_KEYIX_NONE;
49956b4cac81SBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame *);
49966b4cac81SBjoern A. Zeeb if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) {
499711db70b6SBjoern A. Zeeb
499811db70b6SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO
499911db70b6SBjoern A. Zeeb if (lkpi_hwcrypto) {
500011db70b6SBjoern A. Zeeb k = ieee80211_crypto_get_txkey(ni, m);
500111db70b6SBjoern A. Zeeb if (k != NULL && lsta->kc[k->wk_keyix] != NULL)
500211db70b6SBjoern A. Zeeb keyix = k->wk_keyix;
500311db70b6SBjoern A. Zeeb }
500411db70b6SBjoern A. Zeeb #endif
500511db70b6SBjoern A. Zeeb
500611db70b6SBjoern A. Zeeb /* Encrypt the frame if need be. */
500711db70b6SBjoern A. Zeeb if (keyix == IEEE80211_KEYIX_NONE) {
50086b4cac81SBjoern A. Zeeb /* Retrieve key for TX && do software encryption. */
50096b4cac81SBjoern A. Zeeb k = ieee80211_crypto_encap(ni, m);
50106b4cac81SBjoern A. Zeeb if (k == NULL) {
50116b4cac81SBjoern A. Zeeb ieee80211_free_node(ni);
50126b4cac81SBjoern A. Zeeb m_freem(m);
50136b4cac81SBjoern A. Zeeb return;
50146b4cac81SBjoern A. Zeeb }
50156b4cac81SBjoern A. Zeeb }
501611db70b6SBjoern A. Zeeb }
50176b4cac81SBjoern A. Zeeb
50186b4cac81SBjoern A. Zeeb ic = ni->ni_ic;
50196b4cac81SBjoern A. Zeeb lhw = ic->ic_softc;
50206b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
50216b4cac81SBjoern A. Zeeb c = ni->ni_chan;
50226b4cac81SBjoern A. Zeeb
50236b4cac81SBjoern A. Zeeb if (ieee80211_radiotap_active_vap(ni->ni_vap)) {
50246b4cac81SBjoern A. Zeeb struct lkpi_radiotap_tx_hdr *rtap;
50256b4cac81SBjoern A. Zeeb
50266b4cac81SBjoern A. Zeeb rtap = &lhw->rtap_tx;
50276b4cac81SBjoern A. Zeeb rtap->wt_flags = 0;
50286b4cac81SBjoern A. Zeeb if (k != NULL)
50296b4cac81SBjoern A. Zeeb rtap->wt_flags |= IEEE80211_RADIOTAP_F_WEP;
50306b4cac81SBjoern A. Zeeb if (m->m_flags & M_FRAG)
50316b4cac81SBjoern A. Zeeb rtap->wt_flags |= IEEE80211_RADIOTAP_F_FRAG;
50326b4cac81SBjoern A. Zeeb IMPROVE();
50336b4cac81SBjoern A. Zeeb rtap->wt_rate = 0;
50346b4cac81SBjoern A. Zeeb if (c != NULL && c != IEEE80211_CHAN_ANYC) {
50356b4cac81SBjoern A. Zeeb rtap->wt_chan_freq = htole16(c->ic_freq);
50366b4cac81SBjoern A. Zeeb rtap->wt_chan_flags = htole16(c->ic_flags);
50376b4cac81SBjoern A. Zeeb }
50386b4cac81SBjoern A. Zeeb
50396b4cac81SBjoern A. Zeeb ieee80211_radiotap_tx(ni->ni_vap, m);
50406b4cac81SBjoern A. Zeeb }
50416b4cac81SBjoern A. Zeeb
504298e55905SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO
504398e55905SBjoern A. Zeeb if (lkpi_hwcrypto && keyix != IEEE80211_KEYIX_NONE)
504498e55905SBjoern A. Zeeb tailroom = lkpi_hw_crypto_tailroom(lsta, k);
504598e55905SBjoern A. Zeeb else
504698e55905SBjoern A. Zeeb #endif
504798e55905SBjoern A. Zeeb tailroom = 0;
504898e55905SBjoern A. Zeeb
50496b4cac81SBjoern A. Zeeb /*
50506b4cac81SBjoern A. Zeeb * net80211 should handle hw->extra_tx_headroom.
50516b4cac81SBjoern A. Zeeb * Though for as long as we are copying we don't mind.
50523d09d310SBjoern A. Zeeb * XXX-BZ rtw88 asks for too much headroom for ipv6+tcp:
50533d09d310SBjoern A. Zeeb * https://lists.freebsd.org/archives/freebsd-transport/2022-February/000012.html
50546b4cac81SBjoern A. Zeeb */
505598e55905SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + tailroom + m->m_pkthdr.len);
50566b4cac81SBjoern A. Zeeb if (skb == NULL) {
5057bcf1d8eeSBjoern A. Zeeb static uint8_t skb_alloc_failures = 0;
5058bcf1d8eeSBjoern A. Zeeb
5059bcf1d8eeSBjoern A. Zeeb if (skb_alloc_failures++ == 0) {
5060bcf1d8eeSBjoern A. Zeeb int tid;
5061bcf1d8eeSBjoern A. Zeeb
5062bcf1d8eeSBjoern A. Zeeb sta = LSTA_TO_STA(lsta);
5063bcf1d8eeSBjoern A. Zeeb ic_printf(ic, "ERROR %s: skb alloc failed %d + %d, lsta %p sta %p ni %p\n",
5064bcf1d8eeSBjoern A. Zeeb __func__, hw->extra_tx_headroom, m->m_pkthdr.len, lsta, sta, ni);
5065bcf1d8eeSBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) {
5066bcf1d8eeSBjoern A. Zeeb if (sta->txq[tid] == NULL)
5067bcf1d8eeSBjoern A. Zeeb continue;
5068bcf1d8eeSBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]);
5069bcf1d8eeSBjoern A. Zeeb ic_printf(ic, " tid %d ltxq %p seen_dequeue %d stopped %d skb_queue_len %u\n",
5070bcf1d8eeSBjoern A. Zeeb tid, ltxq, ltxq->seen_dequeue, ltxq->stopped, skb_queue_len(<xq->skbq));
5071bcf1d8eeSBjoern A. Zeeb }
5072bcf1d8eeSBjoern A. Zeeb }
50736b4cac81SBjoern A. Zeeb ieee80211_free_node(ni);
50746b4cac81SBjoern A. Zeeb m_freem(m);
50756b4cac81SBjoern A. Zeeb return;
50766b4cac81SBjoern A. Zeeb }
50776b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom);
50786b4cac81SBjoern A. Zeeb
50796b4cac81SBjoern A. Zeeb /* XXX-BZ we need a SKB version understanding mbuf. */
50806b4cac81SBjoern A. Zeeb /* Save the mbuf for ieee80211_tx_complete(). */
50816b4cac81SBjoern A. Zeeb skb->m_free_func = lkpi_ieee80211_free_skb_mbuf;
50826b4cac81SBjoern A. Zeeb skb->m = m;
50836b4cac81SBjoern A. Zeeb #if 0
50846b4cac81SBjoern A. Zeeb skb_put_data(skb, m->m_data, m->m_pkthdr.len);
50856b4cac81SBjoern A. Zeeb #else
50866b4cac81SBjoern A. Zeeb buf = skb_put(skb, m->m_pkthdr.len);
50876b4cac81SBjoern A. Zeeb m_copydata(m, 0, m->m_pkthdr.len, buf);
50886b4cac81SBjoern A. Zeeb #endif
50896b4cac81SBjoern A. Zeeb /* Save the ni. */
50906b4cac81SBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = ni;
50916b4cac81SBjoern A. Zeeb
50926b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(ni->ni_vap);
50936b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
50946b4cac81SBjoern A. Zeeb
5095e3a0b120SBjoern A. Zeeb hdr = (void *)skb->data;
5096e3a0b120SBjoern A. Zeeb tid = linuxkpi_ieee80211_get_tid(hdr, true);
5097e3a0b120SBjoern A. Zeeb if (tid == IEEE80211_NONQOS_TID) { /* == IEEE80211_NUM_TIDS */
50981665ef97SBjoern A. Zeeb if (!ieee80211_is_data(hdr->frame_control)) {
50991665ef97SBjoern A. Zeeb /* MGMT and CTRL frames go on TID 7/VO. */
51001665ef97SBjoern A. Zeeb skb->priority = 7;
51011665ef97SBjoern A. Zeeb ac = IEEE80211_AC_VO;
51021665ef97SBjoern A. Zeeb } else {
51031665ef97SBjoern A. Zeeb /* Other non-QOS traffic goes to BE. */
51041665ef97SBjoern A. Zeeb /* Contrary to net80211 we MUST NOT promote M_EAPOL. */
5105e3a0b120SBjoern A. Zeeb skb->priority = 0;
5106e3a0b120SBjoern A. Zeeb ac = IEEE80211_AC_BE;
51071665ef97SBjoern A. Zeeb }
5108e3a0b120SBjoern A. Zeeb } else {
5109e3a0b120SBjoern A. Zeeb skb->priority = tid & IEEE80211_QOS_CTL_TID_MASK;
5110fb3c249eSBjoern A. Zeeb ac = ieee80211e_up_to_ac[tid & 7];
5111e3a0b120SBjoern A. Zeeb }
51126b4cac81SBjoern A. Zeeb skb_set_queue_mapping(skb, ac);
51136b4cac81SBjoern A. Zeeb
51146b4cac81SBjoern A. Zeeb info = IEEE80211_SKB_CB(skb);
51156b4cac81SBjoern A. Zeeb info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
51166b4cac81SBjoern A. Zeeb /* Slight delay; probably only happens on scanning so fine? */
51176b4cac81SBjoern A. Zeeb if (c == NULL || c == IEEE80211_CHAN_ANYC)
51186b4cac81SBjoern A. Zeeb c = ic->ic_curchan;
51196b4cac81SBjoern A. Zeeb info->band = lkpi_net80211_chan_to_nl80211_band(c);
5120e3a0b120SBjoern A. Zeeb info->hw_queue = vif->hw_queue[ac];
51216b4cac81SBjoern A. Zeeb if (m->m_flags & M_EAPOL)
51226b4cac81SBjoern A. Zeeb info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO;
51236b4cac81SBjoern A. Zeeb info->control.vif = vif;
51246b4cac81SBjoern A. Zeeb /* XXX-BZ info->control.rates */
51259fb91463SBjoern A. Zeeb #ifdef __notyet__
51269fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT
51279fb91463SBjoern A. Zeeb info->control.rts_cts_rate_idx=
51289fb91463SBjoern A. Zeeb info->control.use_rts= /* RTS */
51299fb91463SBjoern A. Zeeb info->control.use_cts_prot= /* RTS/CTS*/
51309fb91463SBjoern A. Zeeb #endif
51319fb91463SBjoern A. Zeeb #endif
51326b4cac81SBjoern A. Zeeb
51336b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta);
5134b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO
513511db70b6SBjoern A. Zeeb if (lkpi_hwcrypto && keyix != IEEE80211_KEYIX_NONE) {
513611db70b6SBjoern A. Zeeb int error;
513711db70b6SBjoern A. Zeeb
513811db70b6SBjoern A. Zeeb error = lkpi_hw_crypto_prepare(lsta, k, skb);
513911db70b6SBjoern A. Zeeb if (error != 0) {
514011db70b6SBjoern A. Zeeb /*
514111db70b6SBjoern A. Zeeb * We only have to free the skb which will free the
514211db70b6SBjoern A. Zeeb * mbuf and release the reference on the ni.
514311db70b6SBjoern A. Zeeb */
514411db70b6SBjoern A. Zeeb dev_kfree_skb(skb);
514511db70b6SBjoern A. Zeeb return;
514611db70b6SBjoern A. Zeeb }
514711db70b6SBjoern A. Zeeb }
51486b4cac81SBjoern A. Zeeb #endif
51496b4cac81SBjoern A. Zeeb
51506b4cac81SBjoern A. Zeeb IMPROVE();
51516b4cac81SBjoern A. Zeeb
5152e3a0b120SBjoern A. Zeeb ltxq = NULL;
5153e3a0b120SBjoern A. Zeeb if (!ieee80211_is_data_present(hdr->frame_control)) {
5154e3a0b120SBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_STATION &&
5155e3a0b120SBjoern A. Zeeb lsta->added_to_drv &&
5156e3a0b120SBjoern A. Zeeb sta->txq[IEEE80211_NUM_TIDS] != NULL)
5157d0d29110SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[IEEE80211_NUM_TIDS]);
5158e3a0b120SBjoern A. Zeeb } else if (lsta->added_to_drv &&
5159e3a0b120SBjoern A. Zeeb sta->txq[skb->priority] != NULL) {
5160e3a0b120SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[skb->priority]);
5161e3a0b120SBjoern A. Zeeb }
5162e3a0b120SBjoern A. Zeeb if (ltxq == NULL)
5163d0d29110SBjoern A. Zeeb goto ops_tx;
5164e3a0b120SBjoern A. Zeeb
5165d0d29110SBjoern A. Zeeb KASSERT(ltxq != NULL, ("%s: lsta %p sta %p m %p skb %p "
5166d0d29110SBjoern A. Zeeb "ltxq %p != NULL\n", __func__, lsta, sta, m, skb, ltxq));
5167d0d29110SBjoern A. Zeeb
5168eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_LOCK(ltxq);
51696b4cac81SBjoern A. Zeeb skb_queue_tail(<xq->skbq, skb);
51709d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
51719d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX)
5172325aa4dbSMark Johnston printf("%s:%d mo_wake_tx_queue :: %d %lu lsta %p sta %p "
5173d0d29110SBjoern A. Zeeb "ni %p %6D skb %p lxtq %p { qlen %u, ac %d tid %u } "
5174d0d29110SBjoern A. Zeeb "WAKE_TX_Q ac %d prio %u qmap %u\n",
5175fb6eaf74SBjoern A. Zeeb __func__, __LINE__,
5176325aa4dbSMark Johnston curthread->td_tid, jiffies,
5177d0d29110SBjoern A. Zeeb lsta, sta, ni, ni->ni_macaddr, ":", skb, ltxq,
5178d0d29110SBjoern A. Zeeb skb_queue_len(<xq->skbq), ltxq->txq.ac,
5179d0d29110SBjoern A. Zeeb ltxq->txq.tid, ac, skb->priority, skb->qmap);
51809d9ba2b7SBjoern A. Zeeb #endif
5181eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_UNLOCK(ltxq);
5182cd0fcf9fSBjoern A. Zeeb wiphy_lock(hw->wiphy);
5183d0d29110SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, <xq->txq);
5184cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
51856b4cac81SBjoern A. Zeeb return;
51866b4cac81SBjoern A. Zeeb
51876b4cac81SBjoern A. Zeeb ops_tx:
51889d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
51899d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX)
5190d0d29110SBjoern A. Zeeb printf("%s:%d mo_tx :: lsta %p sta %p ni %p %6D skb %p "
5191d0d29110SBjoern A. Zeeb "TX ac %d prio %u qmap %u\n",
51926b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, sta, ni, ni->ni_macaddr, ":",
51936b4cac81SBjoern A. Zeeb skb, ac, skb->priority, skb->qmap);
51949d9ba2b7SBjoern A. Zeeb #endif
51956b4cac81SBjoern A. Zeeb memset(&control, 0, sizeof(control));
51966b4cac81SBjoern A. Zeeb control.sta = sta;
5197cd0fcf9fSBjoern A. Zeeb wiphy_lock(hw->wiphy);
51986b4cac81SBjoern A. Zeeb lkpi_80211_mo_tx(hw, &control, skb);
5199cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
52006b4cac81SBjoern A. Zeeb }
52016b4cac81SBjoern A. Zeeb
52026b4cac81SBjoern A. Zeeb static void
52036b4cac81SBjoern A. Zeeb lkpi_80211_txq_task(void *ctx, int pending)
52046b4cac81SBjoern A. Zeeb {
52056b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta;
52066b4cac81SBjoern A. Zeeb struct mbufq mq;
52076b4cac81SBjoern A. Zeeb struct mbuf *m;
520888665349SBjoern A. Zeeb bool shall_tx;
52096b4cac81SBjoern A. Zeeb
52106b4cac81SBjoern A. Zeeb lsta = ctx;
52116b4cac81SBjoern A. Zeeb
52129d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
52139d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX)
52146b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p ni %p %6D pending %d mbuf_qlen %d\n",
52159d9ba2b7SBjoern A. Zeeb __func__, __LINE__, lsta, lsta->ni, lsta->ni->ni_macaddr, ":",
52166b4cac81SBjoern A. Zeeb pending, mbufq_len(&lsta->txq));
52179d9ba2b7SBjoern A. Zeeb #endif
52186b4cac81SBjoern A. Zeeb
52196b4cac81SBjoern A. Zeeb mbufq_init(&mq, IFQ_MAXLEN);
52206b4cac81SBjoern A. Zeeb
5221fa4e4257SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_LOCK(lsta);
5222fa4e4257SBjoern A. Zeeb /*
5223fa4e4257SBjoern A. Zeeb * Do not re-check lsta->txq_ready here; we may have a pending
522488665349SBjoern A. Zeeb * disassoc/deauth frame still. On the contrary if txq_ready is
522588665349SBjoern A. Zeeb * false we do not have a valid sta anymore in the firmware so no
522688665349SBjoern A. Zeeb * point to try to TX.
522788665349SBjoern A. Zeeb * We also use txq_ready as a semaphore and will drain the txq manually
522888665349SBjoern A. Zeeb * if needed on our way towards SCAN/INIT in the state machine.
5229fa4e4257SBjoern A. Zeeb */
52302372f8ccSBjoern A. Zeeb #if 0
523188665349SBjoern A. Zeeb shall_tx = lsta->added_to_drv && lsta->txq_ready;
52322372f8ccSBjoern A. Zeeb #else
52332372f8ccSBjoern A. Zeeb /*
52342372f8ccSBjoern A. Zeeb * Backout this part of 886653492945f which breaks rtw88 or
52352372f8ccSBjoern A. Zeeb * in general drivers without (*sta_state)() but only the
52362372f8ccSBjoern A. Zeeb * legacy fallback to (*sta_add)().
52372372f8ccSBjoern A. Zeeb */
52382372f8ccSBjoern A. Zeeb shall_tx = lsta->txq_ready;
52392372f8ccSBjoern A. Zeeb #endif
524088665349SBjoern A. Zeeb if (__predict_true(shall_tx))
52416b4cac81SBjoern A. Zeeb mbufq_concat(&mq, &lsta->txq);
524288665349SBjoern A. Zeeb /*
524388665349SBjoern A. Zeeb * else a state change will push the packets out manually or
524488665349SBjoern A. Zeeb * lkpi_lsta_free() will drain the lsta->txq and free the mbufs.
524588665349SBjoern A. Zeeb */
5246fa4e4257SBjoern A. Zeeb LKPI_80211_LSTA_TXQ_UNLOCK(lsta);
52476b4cac81SBjoern A. Zeeb
52486b4cac81SBjoern A. Zeeb m = mbufq_dequeue(&mq);
52496b4cac81SBjoern A. Zeeb while (m != NULL) {
52506b4cac81SBjoern A. Zeeb lkpi_80211_txq_tx_one(lsta, m);
52516b4cac81SBjoern A. Zeeb m = mbufq_dequeue(&mq);
52526b4cac81SBjoern A. Zeeb }
52536b4cac81SBjoern A. Zeeb }
52546b4cac81SBjoern A. Zeeb
52556b4cac81SBjoern A. Zeeb static int
52566b4cac81SBjoern A. Zeeb lkpi_ic_transmit(struct ieee80211com *ic, struct mbuf *m)
52576b4cac81SBjoern A. Zeeb {
52586b4cac81SBjoern A. Zeeb
52596b4cac81SBjoern A. Zeeb /* XXX TODO */
52606b4cac81SBjoern A. Zeeb IMPROVE();
52616b4cac81SBjoern A. Zeeb
52626b4cac81SBjoern A. Zeeb /* Quick and dirty cheating hack. */
52636b4cac81SBjoern A. Zeeb struct ieee80211_node *ni;
52646b4cac81SBjoern A. Zeeb
52656b4cac81SBjoern A. Zeeb ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
52669a45c3caSBjoern A. Zeeb return (lkpi_xmit(ni, m, NULL, false));
52676b4cac81SBjoern A. Zeeb }
52686b4cac81SBjoern A. Zeeb
52699fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT
52709fb91463SBjoern A. Zeeb static int
52719fb91463SBjoern A. Zeeb lkpi_ic_recv_action(struct ieee80211_node *ni, const struct ieee80211_frame *wh,
52729fb91463SBjoern A. Zeeb const uint8_t *frm, const uint8_t *efrm)
52739fb91463SBjoern A. Zeeb {
52749fb91463SBjoern A. Zeeb struct ieee80211com *ic;
52759fb91463SBjoern A. Zeeb struct lkpi_hw *lhw;
52769fb91463SBjoern A. Zeeb
52779fb91463SBjoern A. Zeeb ic = ni->ni_ic;
52789fb91463SBjoern A. Zeeb lhw = ic->ic_softc;
52799fb91463SBjoern A. Zeeb
5280310743c4SBjoern A. Zeeb IMPROVE_HT("recv_action called; nothing to do in lkpi; make debugging");
52819fb91463SBjoern A. Zeeb
52829fb91463SBjoern A. Zeeb return (lhw->ic_recv_action(ni, wh, frm, efrm));
52839fb91463SBjoern A. Zeeb }
52849fb91463SBjoern A. Zeeb
52859fb91463SBjoern A. Zeeb static int
52869fb91463SBjoern A. Zeeb lkpi_ic_send_action(struct ieee80211_node *ni, int category, int action, void *sa)
52879fb91463SBjoern A. Zeeb {
52889fb91463SBjoern A. Zeeb struct ieee80211com *ic;
52899fb91463SBjoern A. Zeeb struct lkpi_hw *lhw;
52909fb91463SBjoern A. Zeeb
52919fb91463SBjoern A. Zeeb ic = ni->ni_ic;
52929fb91463SBjoern A. Zeeb lhw = ic->ic_softc;
52939fb91463SBjoern A. Zeeb
5294310743c4SBjoern A. Zeeb IMPROVE_HT("send_action called; nothing to do in lkpi; make debugging");
52959fb91463SBjoern A. Zeeb
52969fb91463SBjoern A. Zeeb return (lhw->ic_send_action(ni, category, action, sa));
52979fb91463SBjoern A. Zeeb }
52989fb91463SBjoern A. Zeeb
52999fb91463SBjoern A. Zeeb
53009fb91463SBjoern A. Zeeb static int
53019fb91463SBjoern A. Zeeb lkpi_ic_ampdu_enable(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap)
53029fb91463SBjoern A. Zeeb {
53039fb91463SBjoern A. Zeeb struct ieee80211com *ic;
53049fb91463SBjoern A. Zeeb struct lkpi_hw *lhw;
53059fb91463SBjoern A. Zeeb
53069fb91463SBjoern A. Zeeb ic = ni->ni_ic;
53079fb91463SBjoern A. Zeeb lhw = ic->ic_softc;
53089fb91463SBjoern A. Zeeb
5309310743c4SBjoern A. Zeeb IMPROVE_HT("ieee80211_ampdu_enable called; nothing to do in lkpi for now; make debugging");
53109fb91463SBjoern A. Zeeb
53119fb91463SBjoern A. Zeeb return (lhw->ic_ampdu_enable(ni, tap));
53129fb91463SBjoern A. Zeeb }
53139fb91463SBjoern A. Zeeb
5314310743c4SBjoern A. Zeeb /*
5315310743c4SBjoern A. Zeeb * (*ic_addba_request)() is called by ieee80211_ampdu_request() before
5316310743c4SBjoern A. Zeeb * calling send_action(CAT_BA, BA_ADDBA_REQUEST).
5317310743c4SBjoern A. Zeeb *
5318310743c4SBjoern A. Zeeb * NB: returns 0 on ERROR!
5319310743c4SBjoern A. Zeeb */
53209fb91463SBjoern A. Zeeb static int
53219fb91463SBjoern A. Zeeb lkpi_ic_addba_request(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap,
53229fb91463SBjoern A. Zeeb int dialogtoken, int baparamset, int batimeout)
53239fb91463SBjoern A. Zeeb {
53249fb91463SBjoern A. Zeeb struct ieee80211com *ic;
53259fb91463SBjoern A. Zeeb struct lkpi_hw *lhw;
5326310743c4SBjoern A. Zeeb struct ieee80211_hw *hw;
5327310743c4SBjoern A. Zeeb struct ieee80211vap *vap;
5328310743c4SBjoern A. Zeeb struct lkpi_vif *lvif;
5329310743c4SBjoern A. Zeeb struct ieee80211_vif *vif;
5330310743c4SBjoern A. Zeeb struct lkpi_sta *lsta;
5331310743c4SBjoern A. Zeeb struct ieee80211_sta *sta;
5332310743c4SBjoern A. Zeeb struct ieee80211_ampdu_params params = { };
5333310743c4SBjoern A. Zeeb int error;
53349fb91463SBjoern A. Zeeb
53359fb91463SBjoern A. Zeeb ic = ni->ni_ic;
53369fb91463SBjoern A. Zeeb lhw = ic->ic_softc;
5337310743c4SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
5338310743c4SBjoern A. Zeeb vap = ni->ni_vap;
5339310743c4SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
5340310743c4SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
5341310743c4SBjoern A. Zeeb lsta = ni->ni_drv_data;
5342310743c4SBjoern A. Zeeb sta = LSTA_TO_STA(lsta);
53439fb91463SBjoern A. Zeeb
5344310743c4SBjoern A. Zeeb if (!lsta->added_to_drv) {
5345310743c4SBjoern A. Zeeb ic_printf(ic, "%s: lsta %p ni %p, sta %p not added to firmware\n",
5346310743c4SBjoern A. Zeeb __func__, lsta, ni, sta);
5347310743c4SBjoern A. Zeeb return (0);
5348310743c4SBjoern A. Zeeb }
5349310743c4SBjoern A. Zeeb
5350310743c4SBjoern A. Zeeb params.sta = sta;
5351310743c4SBjoern A. Zeeb params.action = IEEE80211_AMPDU_TX_START;
5352310743c4SBjoern A. Zeeb /* Keep 0 here! */
5353310743c4SBjoern A. Zeeb params.buf_size = 0;
5354310743c4SBjoern A. Zeeb params.timeout = 0;
5355310743c4SBjoern A. Zeeb params.ssn = tap->txa_start & (IEEE80211_SEQ_RANGE-1);
5356310743c4SBjoern A. Zeeb params.tid = tap->txa_tid;
5357310743c4SBjoern A. Zeeb params.amsdu = false;
5358310743c4SBjoern A. Zeeb
5359310743c4SBjoern A. Zeeb IEEE80211_UNLOCK(ic);
5360cd0fcf9fSBjoern A. Zeeb wiphy_lock(hw->wiphy);
5361310743c4SBjoern A. Zeeb error = lkpi_80211_mo_ampdu_action(hw, vif, ¶ms);
5362cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
5363310743c4SBjoern A. Zeeb IEEE80211_LOCK(ic);
5364310743c4SBjoern A. Zeeb if (error != 0) {
5365310743c4SBjoern A. Zeeb ic_printf(ic, "%s: mo_ampdu_action returned %d. ni %p tap %p\n",
5366310743c4SBjoern A. Zeeb __func__, error, ni, tap);
5367310743c4SBjoern A. Zeeb return (0);
5368310743c4SBjoern A. Zeeb }
53699fb91463SBjoern A. Zeeb
53709fb91463SBjoern A. Zeeb return (lhw->ic_addba_request(ni, tap, dialogtoken, baparamset, batimeout));
53719fb91463SBjoern A. Zeeb }
53729fb91463SBjoern A. Zeeb
5373310743c4SBjoern A. Zeeb /*
5374310743c4SBjoern A. Zeeb * (*ic_addba_response)() is called from ht_recv_action_ba_addba_response()
5375310743c4SBjoern A. Zeeb * and calls the default ieee80211_addba_response() which always returns 1.
5376310743c4SBjoern A. Zeeb *
5377310743c4SBjoern A. Zeeb * NB: No error checking in net80211!
5378310743c4SBjoern A. Zeeb * Staying with 0 is an error.
5379310743c4SBjoern A. Zeeb */
53809fb91463SBjoern A. Zeeb static int
53819fb91463SBjoern A. Zeeb lkpi_ic_addba_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap,
53829fb91463SBjoern A. Zeeb int status, int baparamset, int batimeout)
53839fb91463SBjoern A. Zeeb {
53849fb91463SBjoern A. Zeeb struct ieee80211com *ic;
53859fb91463SBjoern A. Zeeb struct lkpi_hw *lhw;
5386310743c4SBjoern A. Zeeb struct ieee80211_hw *hw;
5387310743c4SBjoern A. Zeeb struct ieee80211vap *vap;
5388310743c4SBjoern A. Zeeb struct lkpi_vif *lvif;
5389310743c4SBjoern A. Zeeb struct ieee80211_vif *vif;
5390310743c4SBjoern A. Zeeb struct lkpi_sta *lsta;
5391310743c4SBjoern A. Zeeb struct ieee80211_sta *sta;
5392310743c4SBjoern A. Zeeb struct ieee80211_ampdu_params params = { };
5393310743c4SBjoern A. Zeeb int error;
53949fb91463SBjoern A. Zeeb
53959fb91463SBjoern A. Zeeb ic = ni->ni_ic;
53969fb91463SBjoern A. Zeeb lhw = ic->ic_softc;
5397310743c4SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
5398310743c4SBjoern A. Zeeb vap = ni->ni_vap;
5399310743c4SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
5400310743c4SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
5401310743c4SBjoern A. Zeeb lsta = ni->ni_drv_data;
5402310743c4SBjoern A. Zeeb sta = LSTA_TO_STA(lsta);
54039fb91463SBjoern A. Zeeb
5404310743c4SBjoern A. Zeeb if (!lsta->added_to_drv) {
5405310743c4SBjoern A. Zeeb ic_printf(ic, "%s: lsta %p ni %p, sta %p not added to firmware\n",
5406310743c4SBjoern A. Zeeb __func__, lsta, ni, sta);
5407310743c4SBjoern A. Zeeb return (0);
5408310743c4SBjoern A. Zeeb }
5409310743c4SBjoern A. Zeeb
5410310743c4SBjoern A. Zeeb if (status == IEEE80211_STATUS_SUCCESS) {
5411310743c4SBjoern A. Zeeb params.sta = sta;
5412310743c4SBjoern A. Zeeb params.action = IEEE80211_AMPDU_TX_OPERATIONAL;
5413310743c4SBjoern A. Zeeb params.buf_size = tap->txa_wnd;
5414310743c4SBjoern A. Zeeb params.timeout = 0;
5415310743c4SBjoern A. Zeeb params.ssn = 0;
5416310743c4SBjoern A. Zeeb params.tid = tap->txa_tid;
5417310743c4SBjoern A. Zeeb if ((tap->txa_flags & IEEE80211_AGGR_AMSDU) != 0)
5418310743c4SBjoern A. Zeeb params.amsdu = true;
5419310743c4SBjoern A. Zeeb else
5420310743c4SBjoern A. Zeeb params.amsdu = false;
5421310743c4SBjoern A. Zeeb } else {
5422310743c4SBjoern A. Zeeb /* We need to free the allocated resources. */
5423310743c4SBjoern A. Zeeb params.sta = sta;
5424310743c4SBjoern A. Zeeb switch (status) {
5425310743c4SBjoern A. Zeeb /* params.action = FLUSH, FLUSH_CONT */
5426310743c4SBjoern A. Zeeb default:
5427310743c4SBjoern A. Zeeb params.action = IEEE80211_AMPDU_TX_STOP_CONT;
5428310743c4SBjoern A. Zeeb break;
5429310743c4SBjoern A. Zeeb }
5430310743c4SBjoern A. Zeeb params.buf_size = 0;
5431310743c4SBjoern A. Zeeb params.timeout = 0;
5432310743c4SBjoern A. Zeeb params.ssn = 0;
5433310743c4SBjoern A. Zeeb params.tid = tap->txa_tid;
5434310743c4SBjoern A. Zeeb params.amsdu = false;
5435310743c4SBjoern A. Zeeb }
5436310743c4SBjoern A. Zeeb
5437310743c4SBjoern A. Zeeb IEEE80211_UNLOCK(ic);
5438cd0fcf9fSBjoern A. Zeeb wiphy_lock(hw->wiphy);
5439310743c4SBjoern A. Zeeb error = lkpi_80211_mo_ampdu_action(hw, vif, ¶ms);
5440cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
5441310743c4SBjoern A. Zeeb IEEE80211_LOCK(ic);
5442310743c4SBjoern A. Zeeb if (error != 0) {
5443310743c4SBjoern A. Zeeb ic_printf(ic, "%s: mo_ampdu_action returned %d. ni %p tap %p\n",
5444310743c4SBjoern A. Zeeb __func__, error, ni, tap);
5445310743c4SBjoern A. Zeeb return (0);
5446310743c4SBjoern A. Zeeb }
5447310743c4SBjoern A. Zeeb
5448310743c4SBjoern A. Zeeb IMPROVE_HT("who unleashes the TXQ? and when?, do we need to ni->ni_txseqs[tid] = tap->txa_start & 0xfff;");
54499fb91463SBjoern A. Zeeb
54509fb91463SBjoern A. Zeeb return (lhw->ic_addba_response(ni, tap, status, baparamset, batimeout));
54519fb91463SBjoern A. Zeeb }
54529fb91463SBjoern A. Zeeb
5453310743c4SBjoern A. Zeeb /*
5454310743c4SBjoern A. Zeeb * (*ic_addba_stop)() is called from ampdu_tx_stop(), ht_recv_action_ba_delba(),
5455310743c4SBjoern A. Zeeb * and ieee80211_ampdu_stop() and calls the default ieee80211_addba_stop().
5456310743c4SBjoern A. Zeeb */
54579fb91463SBjoern A. Zeeb static void
54589fb91463SBjoern A. Zeeb lkpi_ic_addba_stop(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap)
54599fb91463SBjoern A. Zeeb {
54609fb91463SBjoern A. Zeeb struct ieee80211com *ic;
54619fb91463SBjoern A. Zeeb struct lkpi_hw *lhw;
5462310743c4SBjoern A. Zeeb struct ieee80211_hw *hw;
5463310743c4SBjoern A. Zeeb struct ieee80211vap *vap;
5464310743c4SBjoern A. Zeeb struct lkpi_vif *lvif;
5465310743c4SBjoern A. Zeeb struct ieee80211_vif *vif;
5466310743c4SBjoern A. Zeeb struct lkpi_sta *lsta;
5467310743c4SBjoern A. Zeeb struct ieee80211_sta *sta;
5468310743c4SBjoern A. Zeeb struct ieee80211_ampdu_params params = { };
5469310743c4SBjoern A. Zeeb int error;
54709fb91463SBjoern A. Zeeb
54719fb91463SBjoern A. Zeeb ic = ni->ni_ic;
54729fb91463SBjoern A. Zeeb lhw = ic->ic_softc;
5473310743c4SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
5474310743c4SBjoern A. Zeeb vap = ni->ni_vap;
5475310743c4SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
5476310743c4SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
5477310743c4SBjoern A. Zeeb lsta = ni->ni_drv_data;
5478310743c4SBjoern A. Zeeb sta = LSTA_TO_STA(lsta);
54799fb91463SBjoern A. Zeeb
5480310743c4SBjoern A. Zeeb if (!lsta->added_to_drv) {
5481310743c4SBjoern A. Zeeb ic_printf(ic, "%s: lsta %p ni %p, sta %p not added to firmware\n",
5482310743c4SBjoern A. Zeeb __func__, lsta, ni, sta);
5483310743c4SBjoern A. Zeeb goto n80211;
5484310743c4SBjoern A. Zeeb }
54859fb91463SBjoern A. Zeeb
5486310743c4SBjoern A. Zeeb /* We need to free the allocated resources. */
5487310743c4SBjoern A. Zeeb params.sta = sta;
5488310743c4SBjoern A. Zeeb IMPROVE("net80211 does not provide a reason to us");
5489310743c4SBjoern A. Zeeb params.action = IEEE80211_AMPDU_TX_STOP_CONT; /* params.action = FLUSH, FLUSH_CONT */
5490310743c4SBjoern A. Zeeb params.buf_size = 0;
5491310743c4SBjoern A. Zeeb params.timeout = 0;
5492310743c4SBjoern A. Zeeb params.ssn = 0;
5493310743c4SBjoern A. Zeeb params.tid = tap->txa_tid;
5494310743c4SBjoern A. Zeeb params.amsdu = false;
5495310743c4SBjoern A. Zeeb
5496310743c4SBjoern A. Zeeb IEEE80211_UNLOCK(ic);
5497cd0fcf9fSBjoern A. Zeeb wiphy_lock(hw->wiphy);
5498310743c4SBjoern A. Zeeb error = lkpi_80211_mo_ampdu_action(hw, vif, ¶ms);
5499cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
5500310743c4SBjoern A. Zeeb IEEE80211_LOCK(ic);
5501310743c4SBjoern A. Zeeb if (error != 0) {
5502310743c4SBjoern A. Zeeb ic_printf(ic, "%s: mo_ampdu_action returned %d. ni %p tap %p\n",
5503310743c4SBjoern A. Zeeb __func__, error, ni, tap);
5504310743c4SBjoern A. Zeeb goto n80211;
5505310743c4SBjoern A. Zeeb }
5506310743c4SBjoern A. Zeeb
5507310743c4SBjoern A. Zeeb IMPROVE_HT("anyting else?");
5508310743c4SBjoern A. Zeeb
5509310743c4SBjoern A. Zeeb n80211:
55109fb91463SBjoern A. Zeeb lhw->ic_addba_stop(ni, tap);
55119fb91463SBjoern A. Zeeb }
55129fb91463SBjoern A. Zeeb
55139fb91463SBjoern A. Zeeb static void
55149fb91463SBjoern A. Zeeb lkpi_ic_addba_response_timeout(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap)
55159fb91463SBjoern A. Zeeb {
55169fb91463SBjoern A. Zeeb struct ieee80211com *ic;
55179fb91463SBjoern A. Zeeb struct lkpi_hw *lhw;
55189fb91463SBjoern A. Zeeb
55199fb91463SBjoern A. Zeeb ic = ni->ni_ic;
55209fb91463SBjoern A. Zeeb lhw = ic->ic_softc;
55219fb91463SBjoern A. Zeeb
55229fb91463SBjoern A. Zeeb IMPROVE_HT();
55239fb91463SBjoern A. Zeeb
55249fb91463SBjoern A. Zeeb lhw->ic_addba_response_timeout(ni, tap);
55259fb91463SBjoern A. Zeeb }
55269fb91463SBjoern A. Zeeb
55279fb91463SBjoern A. Zeeb static void
55289fb91463SBjoern A. Zeeb lkpi_ic_bar_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap,
55299fb91463SBjoern A. Zeeb int status)
55309fb91463SBjoern A. Zeeb {
55319fb91463SBjoern A. Zeeb struct ieee80211com *ic;
55329fb91463SBjoern A. Zeeb struct lkpi_hw *lhw;
55339fb91463SBjoern A. Zeeb
55349fb91463SBjoern A. Zeeb ic = ni->ni_ic;
55359fb91463SBjoern A. Zeeb lhw = ic->ic_softc;
55369fb91463SBjoern A. Zeeb
55379fb91463SBjoern A. Zeeb IMPROVE_HT();
55389fb91463SBjoern A. Zeeb
55399fb91463SBjoern A. Zeeb lhw->ic_bar_response(ni, tap, status);
55409fb91463SBjoern A. Zeeb }
55419fb91463SBjoern A. Zeeb
55429fb91463SBjoern A. Zeeb static int
55439fb91463SBjoern A. Zeeb lkpi_ic_ampdu_rx_start(struct ieee80211_node *ni, struct ieee80211_rx_ampdu *rap,
55449fb91463SBjoern A. Zeeb int baparamset, int batimeout, int baseqctl)
55459fb91463SBjoern A. Zeeb {
55469fb91463SBjoern A. Zeeb struct ieee80211com *ic;
55479fb91463SBjoern A. Zeeb struct lkpi_hw *lhw;
55489fb91463SBjoern A. Zeeb struct ieee80211_hw *hw;
55499fb91463SBjoern A. Zeeb struct ieee80211vap *vap;
55509fb91463SBjoern A. Zeeb struct lkpi_vif *lvif;
55519fb91463SBjoern A. Zeeb struct ieee80211_vif *vif;
55529fb91463SBjoern A. Zeeb struct lkpi_sta *lsta;
55539fb91463SBjoern A. Zeeb struct ieee80211_sta *sta;
5554310743c4SBjoern A. Zeeb struct ieee80211_ampdu_params params = { };
55559fb91463SBjoern A. Zeeb int error;
55569fb91463SBjoern A. Zeeb
55579fb91463SBjoern A. Zeeb ic = ni->ni_ic;
55589fb91463SBjoern A. Zeeb lhw = ic->ic_softc;
55599fb91463SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
55609fb91463SBjoern A. Zeeb vap = ni->ni_vap;
55619fb91463SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
55629fb91463SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
55639fb91463SBjoern A. Zeeb lsta = ni->ni_drv_data;
55649fb91463SBjoern A. Zeeb sta = LSTA_TO_STA(lsta);
55659fb91463SBjoern A. Zeeb
5566310743c4SBjoern A. Zeeb IEEE80211_UNLOCK_ASSERT(ic);
5567310743c4SBjoern A. Zeeb
5568310743c4SBjoern A. Zeeb if (!lsta->added_to_drv) {
5569310743c4SBjoern A. Zeeb ic_printf(ic, "%s: lsta %p ni %p vap %p, sta %p not added to firmware\n",
5570310743c4SBjoern A. Zeeb __func__, lsta, ni, vap, sta);
5571310743c4SBjoern A. Zeeb return (-ENXIO);
5572310743c4SBjoern A. Zeeb }
5573310743c4SBjoern A. Zeeb
55749fb91463SBjoern A. Zeeb params.sta = sta;
55759fb91463SBjoern A. Zeeb params.action = IEEE80211_AMPDU_RX_START;
55769fb91463SBjoern A. Zeeb params.buf_size = _IEEE80211_MASKSHIFT(le16toh(baparamset), IEEE80211_BAPS_BUFSIZ);
55779fb91463SBjoern A. Zeeb if (params.buf_size == 0)
55789fb91463SBjoern A. Zeeb params.buf_size = IEEE80211_MAX_AMPDU_BUF_HT;
55799fb91463SBjoern A. Zeeb else
55809fb91463SBjoern A. Zeeb params.buf_size = min(params.buf_size, IEEE80211_MAX_AMPDU_BUF_HT);
5581310743c4SBjoern A. Zeeb if (hw->max_rx_aggregation_subframes > 0 &&
5582310743c4SBjoern A. Zeeb params.buf_size > hw->max_rx_aggregation_subframes)
55839fb91463SBjoern A. Zeeb params.buf_size = hw->max_rx_aggregation_subframes;
55849fb91463SBjoern A. Zeeb params.timeout = le16toh(batimeout);
55859fb91463SBjoern A. Zeeb params.ssn = _IEEE80211_MASKSHIFT(le16toh(baseqctl), IEEE80211_BASEQ_START);
55869fb91463SBjoern A. Zeeb params.tid = _IEEE80211_MASKSHIFT(le16toh(baparamset), IEEE80211_BAPS_TID);
5587310743c4SBjoern A. Zeeb
5588310743c4SBjoern A. Zeeb /* Based on net80211::ampdu_rx_start(). */
5589310743c4SBjoern A. Zeeb if ((vap->iv_htcaps & IEEE80211_HTC_RX_AMSDU_AMPDU) &&
5590310743c4SBjoern A. Zeeb (_IEEE80211_MASKSHIFT(baparamset, IEEE80211_BAPS_AMSDU)))
5591310743c4SBjoern A. Zeeb params.amsdu = true;
5592310743c4SBjoern A. Zeeb else
55939fb91463SBjoern A. Zeeb params.amsdu = false;
55949fb91463SBjoern A. Zeeb
5595cd0fcf9fSBjoern A. Zeeb wiphy_lock(hw->wiphy);
55969fb91463SBjoern A. Zeeb error = lkpi_80211_mo_ampdu_action(hw, vif, ¶ms);
5597cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
55989fb91463SBjoern A. Zeeb if (error != 0) {
55999fb91463SBjoern A. Zeeb ic_printf(ic, "%s: mo_ampdu_action returned %d. ni %p rap %p\n",
56009fb91463SBjoern A. Zeeb __func__, error, ni, rap);
56019fb91463SBjoern A. Zeeb return (error);
56029fb91463SBjoern A. Zeeb }
5603310743c4SBjoern A. Zeeb
5604310743c4SBjoern A. Zeeb if (!ieee80211_hw_check(hw, SUPPORTS_REORDERING_BUFFER)) {
5605310743c4SBjoern A. Zeeb IMPROVE("%s: TODO: SUPPORTS_REORDERING_BUFFER not set; check net80211\n", __func__);
5606310743c4SBjoern A. Zeeb }
5607310743c4SBjoern A. Zeeb
56089fb91463SBjoern A. Zeeb IMPROVE_HT("net80211 is missing the error check on return and assumes success");
56099fb91463SBjoern A. Zeeb
56109fb91463SBjoern A. Zeeb error = lhw->ic_ampdu_rx_start(ni, rap, baparamset, batimeout, baseqctl);
56119fb91463SBjoern A. Zeeb return (error);
56129fb91463SBjoern A. Zeeb }
56139fb91463SBjoern A. Zeeb
56149fb91463SBjoern A. Zeeb static void
56159fb91463SBjoern A. Zeeb lkpi_ic_ampdu_rx_stop(struct ieee80211_node *ni, struct ieee80211_rx_ampdu *rap)
56169fb91463SBjoern A. Zeeb {
56179fb91463SBjoern A. Zeeb struct ieee80211com *ic;
56189fb91463SBjoern A. Zeeb struct lkpi_hw *lhw;
56199fb91463SBjoern A. Zeeb struct ieee80211_hw *hw;
56209fb91463SBjoern A. Zeeb struct ieee80211vap *vap;
56219fb91463SBjoern A. Zeeb struct lkpi_vif *lvif;
56229fb91463SBjoern A. Zeeb struct ieee80211_vif *vif;
56239fb91463SBjoern A. Zeeb struct lkpi_sta *lsta;
56249fb91463SBjoern A. Zeeb struct ieee80211_sta *sta;
5625310743c4SBjoern A. Zeeb struct ieee80211_ampdu_params params = { };
56269fb91463SBjoern A. Zeeb int error;
56279fb91463SBjoern A. Zeeb uint8_t tid;
562865c573e4SBjoern A. Zeeb bool ic_locked;
56299fb91463SBjoern A. Zeeb
56309fb91463SBjoern A. Zeeb ic = ni->ni_ic;
56319fb91463SBjoern A. Zeeb lhw = ic->ic_softc;
56329fb91463SBjoern A. Zeeb
56339fb91463SBjoern A. Zeeb /*
56349fb91463SBjoern A. Zeeb * We should not (cannot) call into mac80211 ops with AMPDU_RX_STOP if
56359fb91463SBjoern A. Zeeb * we did not START. Some drivers pass it down to firmware which will
56369fb91463SBjoern A. Zeeb * simply barf and net80211 calls ieee80211_ht_node_cleanup() from
56379fb91463SBjoern A. Zeeb * ieee80211_ht_node_init() amongst others which will iterate over all
56389fb91463SBjoern A. Zeeb * tid and call ic_ampdu_rx_stop() unconditionally.
56399fb91463SBjoern A. Zeeb * XXX net80211 should probably be more "gentle" in these cases and
56409fb91463SBjoern A. Zeeb * track some state itself.
56419fb91463SBjoern A. Zeeb */
56429fb91463SBjoern A. Zeeb if ((rap->rxa_flags & IEEE80211_AGGR_RUNNING) == 0)
56439fb91463SBjoern A. Zeeb goto net80211_only;
56449fb91463SBjoern A. Zeeb
56459fb91463SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
56469fb91463SBjoern A. Zeeb vap = ni->ni_vap;
56479fb91463SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
56489fb91463SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
56499fb91463SBjoern A. Zeeb lsta = ni->ni_drv_data;
56509fb91463SBjoern A. Zeeb sta = LSTA_TO_STA(lsta);
56519fb91463SBjoern A. Zeeb
56529fb91463SBjoern A. Zeeb IMPROVE_HT("This really should be passed from ht_recv_action_ba_delba.");
56539fb91463SBjoern A. Zeeb for (tid = 0; tid < WME_NUM_TID; tid++) {
56549fb91463SBjoern A. Zeeb if (&ni->ni_rx_ampdu[tid] == rap)
56559fb91463SBjoern A. Zeeb break;
56569fb91463SBjoern A. Zeeb }
56579fb91463SBjoern A. Zeeb
56589fb91463SBjoern A. Zeeb params.sta = sta;
56599fb91463SBjoern A. Zeeb params.action = IEEE80211_AMPDU_RX_STOP;
56609fb91463SBjoern A. Zeeb params.buf_size = 0;
56619fb91463SBjoern A. Zeeb params.timeout = 0;
56629fb91463SBjoern A. Zeeb params.ssn = 0;
56639fb91463SBjoern A. Zeeb params.tid = tid;
56649fb91463SBjoern A. Zeeb params.amsdu = false;
56659fb91463SBjoern A. Zeeb
566665c573e4SBjoern A. Zeeb ic_locked = IEEE80211_IS_LOCKED(ic);
566765c573e4SBjoern A. Zeeb if (ic_locked)
566865c573e4SBjoern A. Zeeb IEEE80211_UNLOCK(ic);
5669cd0fcf9fSBjoern A. Zeeb wiphy_lock(hw->wiphy);
56709fb91463SBjoern A. Zeeb error = lkpi_80211_mo_ampdu_action(hw, vif, ¶ms);
5671cd0fcf9fSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
567265c573e4SBjoern A. Zeeb if (ic_locked)
567365c573e4SBjoern A. Zeeb IEEE80211_LOCK(ic);
56749fb91463SBjoern A. Zeeb if (error != 0)
56759fb91463SBjoern A. Zeeb ic_printf(ic, "%s: mo_ampdu_action returned %d. ni %p rap %p\n",
56769fb91463SBjoern A. Zeeb __func__, error, ni, rap);
56779fb91463SBjoern A. Zeeb
56789fb91463SBjoern A. Zeeb net80211_only:
56799fb91463SBjoern A. Zeeb lhw->ic_ampdu_rx_stop(ni, rap);
56809fb91463SBjoern A. Zeeb }
56819fb91463SBjoern A. Zeeb #endif
56829fb91463SBjoern A. Zeeb
56839fb91463SBjoern A. Zeeb static void
56849fb91463SBjoern A. Zeeb lkpi_ic_getradiocaps_ht(struct ieee80211com *ic, struct ieee80211_hw *hw,
56859fb91463SBjoern A. Zeeb uint8_t *bands, int *chan_flags, enum nl80211_band band)
56869fb91463SBjoern A. Zeeb {
56879fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT
56889fb91463SBjoern A. Zeeb struct ieee80211_sta_ht_cap *ht_cap;
56899fb91463SBjoern A. Zeeb
56909fb91463SBjoern A. Zeeb ht_cap = &hw->wiphy->bands[band]->ht_cap;
56919fb91463SBjoern A. Zeeb if (!ht_cap->ht_supported)
56929fb91463SBjoern A. Zeeb return;
56939fb91463SBjoern A. Zeeb
56949fb91463SBjoern A. Zeeb switch (band) {
56959fb91463SBjoern A. Zeeb case NL80211_BAND_2GHZ:
56969fb91463SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11NG);
56979fb91463SBjoern A. Zeeb break;
56989fb91463SBjoern A. Zeeb case NL80211_BAND_5GHZ:
56999fb91463SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11NA);
57009fb91463SBjoern A. Zeeb break;
57019fb91463SBjoern A. Zeeb default:
57029fb91463SBjoern A. Zeeb IMPROVE("Unsupported band %d", band);
57039fb91463SBjoern A. Zeeb return;
57049fb91463SBjoern A. Zeeb }
57059fb91463SBjoern A. Zeeb
57069fb91463SBjoern A. Zeeb ic->ic_htcaps = IEEE80211_HTC_HT; /* HT operation */
57079fb91463SBjoern A. Zeeb
57089fb91463SBjoern A. Zeeb /*
57099fb91463SBjoern A. Zeeb * Rather than manually checking each flag and
57109fb91463SBjoern A. Zeeb * translating IEEE80211_HT_CAP_ to IEEE80211_HTCAP_,
57119fb91463SBjoern A. Zeeb * simply copy the 16bits.
57129fb91463SBjoern A. Zeeb */
57139fb91463SBjoern A. Zeeb ic->ic_htcaps |= ht_cap->cap;
57149fb91463SBjoern A. Zeeb
57159fb91463SBjoern A. Zeeb /* Then deal with the other flags. */
57169fb91463SBjoern A. Zeeb if (ieee80211_hw_check(hw, AMPDU_AGGREGATION))
57179fb91463SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTC_AMPDU;
57189fb91463SBjoern A. Zeeb #ifdef __notyet__
57199fb91463SBjoern A. Zeeb if (ieee80211_hw_check(hw, TX_AMSDU))
57209fb91463SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTC_AMSDU;
57219fb91463SBjoern A. Zeeb if (ieee80211_hw_check(hw, SUPPORTS_AMSDU_IN_AMPDU))
57229fb91463SBjoern A. Zeeb ic->ic_htcaps |= (IEEE80211_HTC_RX_AMSDU_AMPDU |
57239fb91463SBjoern A. Zeeb IEEE80211_HTC_TX_AMSDU_AMPDU);
57249fb91463SBjoern A. Zeeb #endif
57259fb91463SBjoern A. Zeeb
57269fb91463SBjoern A. Zeeb IMPROVE("PS, ampdu_*, ht_cap.mcs.tx_params, ...");
57279fb91463SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_SMPS_OFF;
57289fb91463SBjoern A. Zeeb
57299fb91463SBjoern A. Zeeb /* Only add HT40 channels if supported. */
57309fb91463SBjoern A. Zeeb if ((ic->ic_htcaps & IEEE80211_HTCAP_CHWIDTH40) != 0 &&
57319fb91463SBjoern A. Zeeb chan_flags != NULL)
57329fb91463SBjoern A. Zeeb *chan_flags |= NET80211_CBW_FLAG_HT40;
57339fb91463SBjoern A. Zeeb #endif
57349fb91463SBjoern A. Zeeb }
57359fb91463SBjoern A. Zeeb
57366b4cac81SBjoern A. Zeeb static void
57376b4cac81SBjoern A. Zeeb lkpi_ic_getradiocaps(struct ieee80211com *ic, int maxchan,
57386b4cac81SBjoern A. Zeeb int *n, struct ieee80211_channel *c)
57396b4cac81SBjoern A. Zeeb {
57406b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
57416b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw;
57426b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels;
57436b4cac81SBjoern A. Zeeb uint8_t bands[IEEE80211_MODE_BYTES];
57446b4cac81SBjoern A. Zeeb int chan_flags, error, i, nchans;
57456b4cac81SBjoern A. Zeeb
57466b4cac81SBjoern A. Zeeb /* Channels */
57476b4cac81SBjoern A. Zeeb lhw = ic->ic_softc;
57486b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
57496b4cac81SBjoern A. Zeeb
57506b4cac81SBjoern A. Zeeb /* NL80211_BAND_2GHZ */
57516b4cac81SBjoern A. Zeeb nchans = 0;
57526b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_2GHZ] != NULL)
57536b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[NL80211_BAND_2GHZ]->n_channels;
57546b4cac81SBjoern A. Zeeb if (nchans > 0) {
57556b4cac81SBjoern A. Zeeb memset(bands, 0, sizeof(bands));
57566b4cac81SBjoern A. Zeeb chan_flags = 0;
57576b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11B);
57586b4cac81SBjoern A. Zeeb /* XXX-BZ unclear how to check for 11g. */
57599fb91463SBjoern A. Zeeb
57609fb91463SBjoern A. Zeeb IMPROVE("the bitrates may have flags?");
57616b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11G);
57629fb91463SBjoern A. Zeeb
57639fb91463SBjoern A. Zeeb lkpi_ic_getradiocaps_ht(ic, hw, bands, &chan_flags,
57649fb91463SBjoern A. Zeeb NL80211_BAND_2GHZ);
57656b4cac81SBjoern A. Zeeb
57666b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[NL80211_BAND_2GHZ]->channels;
5767cee56e77SBjoern A. Zeeb for (i = 0; i < nchans && *n < maxchan; i++) {
57686b4cac81SBjoern A. Zeeb uint32_t nflags = 0;
57696b4cac81SBjoern A. Zeeb int cflags = chan_flags;
57706b4cac81SBjoern A. Zeeb
57716b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) {
57723f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Skipping disabled chan "
57733f0083c4SBjoern A. Zeeb "[%u/%u/%#x]\n", __func__,
57746b4cac81SBjoern A. Zeeb channels[i].hw_value,
57756b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags);
57766b4cac81SBjoern A. Zeeb continue;
57776b4cac81SBjoern A. Zeeb }
57786b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_IR)
57796b4cac81SBjoern A. Zeeb nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE);
57806b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_RADAR)
57816b4cac81SBjoern A. Zeeb nflags |= IEEE80211_CHAN_DFS;
57826b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ)
57836b4cac81SBjoern A. Zeeb cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80);
57846b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ)
57856b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_VHT80;
57866b4cac81SBjoern A. Zeeb /* XXX how to map the remaining enum ieee80211_channel_flags? */
57876b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_HT40)
57886b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_HT40;
57896b4cac81SBjoern A. Zeeb
57906b4cac81SBjoern A. Zeeb error = ieee80211_add_channel_cbw(c, maxchan, n,
57916b4cac81SBjoern A. Zeeb channels[i].hw_value, channels[i].center_freq,
57926b4cac81SBjoern A. Zeeb channels[i].max_power,
57935856761fSBjoern A. Zeeb nflags, bands, cflags);
5794cee56e77SBjoern A. Zeeb /* net80211::ENOBUFS: *n >= maxchans */
5795cee56e77SBjoern A. Zeeb if (error != 0 && error != ENOBUFS)
57963f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Adding chan %u/%u/%#x/%#x/%#x/%#x "
57973f0083c4SBjoern A. Zeeb "returned error %d\n",
57986b4cac81SBjoern A. Zeeb __func__, channels[i].hw_value,
57996b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags,
58006b4cac81SBjoern A. Zeeb nflags, chan_flags, cflags, error);
5801cee56e77SBjoern A. Zeeb if (error != 0)
58026b4cac81SBjoern A. Zeeb break;
58036b4cac81SBjoern A. Zeeb }
58046b4cac81SBjoern A. Zeeb }
58056b4cac81SBjoern A. Zeeb
58066b4cac81SBjoern A. Zeeb /* NL80211_BAND_5GHZ */
58076b4cac81SBjoern A. Zeeb nchans = 0;
58086b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ] != NULL)
58096b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[NL80211_BAND_5GHZ]->n_channels;
58106b4cac81SBjoern A. Zeeb if (nchans > 0) {
58116b4cac81SBjoern A. Zeeb memset(bands, 0, sizeof(bands));
58126b4cac81SBjoern A. Zeeb chan_flags = 0;
58136b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11A);
58149fb91463SBjoern A. Zeeb
58159fb91463SBjoern A. Zeeb lkpi_ic_getradiocaps_ht(ic, hw, bands, &chan_flags,
58169fb91463SBjoern A. Zeeb NL80211_BAND_5GHZ);
58179fb91463SBjoern A. Zeeb
58189fb91463SBjoern A. Zeeb #ifdef LKPI_80211_VHT
58196b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.vht_supported) {
58206b4cac81SBjoern A. Zeeb
58216b4cac81SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_VHT;
5822562adbe1SBjoern A. Zeeb ic->ic_vht_cap.vht_cap_info =
58236b4cac81SBjoern A. Zeeb hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap;
5824ecb2e5f9SBjoern A. Zeeb ic->ic_vht_cap.supp_mcs =
5825ecb2e5f9SBjoern A. Zeeb hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.vht_mcs;
58266b4cac81SBjoern A. Zeeb
58276b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_VHT_5GHZ);
58286b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT80;
58296b4cac81SBjoern A. Zeeb if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160MHZ(
5830562adbe1SBjoern A. Zeeb ic->ic_vht_cap.vht_cap_info))
58316b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT160;
58326b4cac81SBjoern A. Zeeb if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160_80P80MHZ(
5833562adbe1SBjoern A. Zeeb ic->ic_vht_cap.vht_cap_info))
58346b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT80P80;
58356b4cac81SBjoern A. Zeeb }
58366b4cac81SBjoern A. Zeeb #endif
58376b4cac81SBjoern A. Zeeb
58386b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[NL80211_BAND_5GHZ]->channels;
5839cee56e77SBjoern A. Zeeb for (i = 0; i < nchans && *n < maxchan; i++) {
58406b4cac81SBjoern A. Zeeb uint32_t nflags = 0;
58416b4cac81SBjoern A. Zeeb int cflags = chan_flags;
58426b4cac81SBjoern A. Zeeb
58436b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) {
58443f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Skipping disabled chan "
58453f0083c4SBjoern A. Zeeb "[%u/%u/%#x]\n", __func__,
58466b4cac81SBjoern A. Zeeb channels[i].hw_value,
58476b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags);
58486b4cac81SBjoern A. Zeeb continue;
58496b4cac81SBjoern A. Zeeb }
58506b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_IR)
58516b4cac81SBjoern A. Zeeb nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE);
58526b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_RADAR)
58536b4cac81SBjoern A. Zeeb nflags |= IEEE80211_CHAN_DFS;
58546b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ)
58556b4cac81SBjoern A. Zeeb cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80);
58566b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ)
58576b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_VHT80;
58586b4cac81SBjoern A. Zeeb /* XXX hwo to map the remaining enum ieee80211_channel_flags? */
58596b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_HT40)
58606b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_HT40;
58616b4cac81SBjoern A. Zeeb
58626b4cac81SBjoern A. Zeeb error = ieee80211_add_channel_cbw(c, maxchan, n,
58636b4cac81SBjoern A. Zeeb channels[i].hw_value, channels[i].center_freq,
58646b4cac81SBjoern A. Zeeb channels[i].max_power,
58655856761fSBjoern A. Zeeb nflags, bands, cflags);
5866cee56e77SBjoern A. Zeeb /* net80211::ENOBUFS: *n >= maxchans */
5867cee56e77SBjoern A. Zeeb if (error != 0 && error != ENOBUFS)
58683f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Adding chan %u/%u/%#x/%#x/%#x/%#x "
58693f0083c4SBjoern A. Zeeb "returned error %d\n",
58706b4cac81SBjoern A. Zeeb __func__, channels[i].hw_value,
58716b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags,
58726b4cac81SBjoern A. Zeeb nflags, chan_flags, cflags, error);
5873cee56e77SBjoern A. Zeeb if (error != 0)
58746b4cac81SBjoern A. Zeeb break;
58756b4cac81SBjoern A. Zeeb }
58766b4cac81SBjoern A. Zeeb }
58776b4cac81SBjoern A. Zeeb }
58786b4cac81SBjoern A. Zeeb
58796b4cac81SBjoern A. Zeeb static void *
58806b4cac81SBjoern A. Zeeb lkpi_ieee80211_ifalloc(void)
58816b4cac81SBjoern A. Zeeb {
58826b4cac81SBjoern A. Zeeb struct ieee80211com *ic;
58836b4cac81SBjoern A. Zeeb
58846b4cac81SBjoern A. Zeeb ic = malloc(sizeof(*ic), M_LKPI80211, M_WAITOK | M_ZERO);
58856b4cac81SBjoern A. Zeeb
58866b4cac81SBjoern A. Zeeb /* Setting these happens later when we have device information. */
58876b4cac81SBjoern A. Zeeb ic->ic_softc = NULL;
58886b4cac81SBjoern A. Zeeb ic->ic_name = "linuxkpi";
58896b4cac81SBjoern A. Zeeb
58906b4cac81SBjoern A. Zeeb return (ic);
58916b4cac81SBjoern A. Zeeb }
58926b4cac81SBjoern A. Zeeb
58936b4cac81SBjoern A. Zeeb struct ieee80211_hw *
58946b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_alloc_hw(size_t priv_len, const struct ieee80211_ops *ops)
58956b4cac81SBjoern A. Zeeb {
58966b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw;
58976b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
58986b4cac81SBjoern A. Zeeb struct wiphy *wiphy;
5899a5ae63edSBjoern A. Zeeb int ac;
59006b4cac81SBjoern A. Zeeb
59016b4cac81SBjoern A. Zeeb /* Get us and the driver data also allocated. */
59026b4cac81SBjoern A. Zeeb wiphy = wiphy_new(&linuxkpi_mac80211cfgops, sizeof(*lhw) + priv_len);
59036b4cac81SBjoern A. Zeeb if (wiphy == NULL)
59046b4cac81SBjoern A. Zeeb return (NULL);
59056b4cac81SBjoern A. Zeeb
59066b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy);
59076b4cac81SBjoern A. Zeeb lhw->ops = ops;
5908652e22d3SBjoern A. Zeeb
59098ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK_INIT(lhw);
5910eac3646fSBjoern A. Zeeb LKPI_80211_LHW_TXQ_LOCK_INIT(lhw);
59118891c455SBjoern A. Zeeb sx_init_flags(&lhw->lvif_sx, "lhw-lvif", SX_RECURSE | SX_DUPOK);
59126b4cac81SBjoern A. Zeeb TAILQ_INIT(&lhw->lvif_head);
5913a5ae63edSBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
5914a5ae63edSBjoern A. Zeeb lhw->txq_generation[ac] = 1;
5915a5ae63edSBjoern A. Zeeb TAILQ_INIT(&lhw->scheduled_txqs[ac]);
5916a5ae63edSBjoern A. Zeeb }
59176b4cac81SBjoern A. Zeeb
5918a8a47a41SBjoern A. Zeeb /* Chanctx_conf */
5919a8a47a41SBjoern A. Zeeb INIT_LIST_HEAD(&lhw->lchanctx_list);
5920a8a47a41SBjoern A. Zeeb
5921759a996dSBjoern A. Zeeb /* Deferred RX path. */
5922759a996dSBjoern A. Zeeb LKPI_80211_LHW_RXQ_LOCK_INIT(lhw);
5923759a996dSBjoern A. Zeeb TASK_INIT(&lhw->rxq_task, 0, lkpi_80211_lhw_rxq_task, lhw);
5924832b8e98SBjoern A. Zeeb mbufq_init(&lhw->rxq, 32 * NAPI_POLL_WEIGHT);
5925759a996dSBjoern A. Zeeb lhw->rxq_stopped = false;
5926759a996dSBjoern A. Zeeb
59276b4cac81SBjoern A. Zeeb /*
59286b4cac81SBjoern A. Zeeb * XXX-BZ TODO make sure there is a "_null" function to all ops
59296b4cac81SBjoern A. Zeeb * not initialized.
59306b4cac81SBjoern A. Zeeb */
59316b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw);
59326b4cac81SBjoern A. Zeeb hw->wiphy = wiphy;
5933086be6a8SBjoern A. Zeeb hw->conf.flags |= IEEE80211_CONF_IDLE;
59346b4cac81SBjoern A. Zeeb hw->priv = (void *)(lhw + 1);
59356b4cac81SBjoern A. Zeeb
59366b4cac81SBjoern A. Zeeb /* BSD Specific. */
59376b4cac81SBjoern A. Zeeb lhw->ic = lkpi_ieee80211_ifalloc();
59386b4cac81SBjoern A. Zeeb
59396b4cac81SBjoern A. Zeeb IMPROVE();
59406b4cac81SBjoern A. Zeeb
59416b4cac81SBjoern A. Zeeb return (hw);
59426b4cac81SBjoern A. Zeeb }
59436b4cac81SBjoern A. Zeeb
59446b4cac81SBjoern A. Zeeb void
59456b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iffree(struct ieee80211_hw *hw)
59466b4cac81SBjoern A. Zeeb {
59476b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
5948759a996dSBjoern A. Zeeb struct mbuf *m;
59496b4cac81SBjoern A. Zeeb
59506b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw);
59516b4cac81SBjoern A. Zeeb free(lhw->ic, M_LKPI80211);
59526b4cac81SBjoern A. Zeeb lhw->ic = NULL;
59536b4cac81SBjoern A. Zeeb
5954759a996dSBjoern A. Zeeb /*
5955759a996dSBjoern A. Zeeb * Drain the deferred RX path.
5956759a996dSBjoern A. Zeeb */
5957759a996dSBjoern A. Zeeb LKPI_80211_LHW_RXQ_LOCK(lhw);
5958759a996dSBjoern A. Zeeb lhw->rxq_stopped = true;
5959759a996dSBjoern A. Zeeb LKPI_80211_LHW_RXQ_UNLOCK(lhw);
5960759a996dSBjoern A. Zeeb
5961759a996dSBjoern A. Zeeb /* Drain taskq, won't be restarted due to rxq_stopped being set. */
5962759a996dSBjoern A. Zeeb while (taskqueue_cancel(taskqueue_thread, &lhw->rxq_task, NULL) != 0)
5963759a996dSBjoern A. Zeeb taskqueue_drain(taskqueue_thread, &lhw->rxq_task);
5964759a996dSBjoern A. Zeeb
5965759a996dSBjoern A. Zeeb /* Flush mbufq (make sure to release ni refs!). */
5966759a996dSBjoern A. Zeeb m = mbufq_dequeue(&lhw->rxq);
5967759a996dSBjoern A. Zeeb while (m != NULL) {
5968dbae3dcfSBjoern A. Zeeb #ifdef LKPI_80211_USE_MTAG
5969759a996dSBjoern A. Zeeb struct m_tag *mtag;
5970759a996dSBjoern A. Zeeb
5971759a996dSBjoern A. Zeeb mtag = m_tag_locate(m, MTAG_ABI_LKPI80211, LKPI80211_TAG_RXNI, NULL);
5972759a996dSBjoern A. Zeeb if (mtag != NULL) {
5973759a996dSBjoern A. Zeeb struct lkpi_80211_tag_rxni *rxni;
5974759a996dSBjoern A. Zeeb
5975759a996dSBjoern A. Zeeb rxni = (struct lkpi_80211_tag_rxni *)(mtag + 1);
5976759a996dSBjoern A. Zeeb ieee80211_free_node(rxni->ni);
5977759a996dSBjoern A. Zeeb }
5978dbae3dcfSBjoern A. Zeeb #else
5979dbae3dcfSBjoern A. Zeeb if (m->m_pkthdr.PH_loc.ptr != NULL) {
5980dbae3dcfSBjoern A. Zeeb struct ieee80211_node *ni;
5981dbae3dcfSBjoern A. Zeeb
5982dbae3dcfSBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr;
5983dbae3dcfSBjoern A. Zeeb ieee80211_free_node(ni);
5984dbae3dcfSBjoern A. Zeeb }
5985dbae3dcfSBjoern A. Zeeb #endif
5986759a996dSBjoern A. Zeeb m_freem(m);
5987759a996dSBjoern A. Zeeb m = mbufq_dequeue(&lhw->rxq);
5988759a996dSBjoern A. Zeeb }
5989759a996dSBjoern A. Zeeb KASSERT(mbufq_empty(&lhw->rxq), ("%s: lhw %p has rxq len %d != 0\n",
5990759a996dSBjoern A. Zeeb __func__, lhw, mbufq_len(&lhw->rxq)));
5991759a996dSBjoern A. Zeeb LKPI_80211_LHW_RXQ_LOCK_DESTROY(lhw);
5992759a996dSBjoern A. Zeeb
5993a8a47a41SBjoern A. Zeeb /* Chanctx_conf. */
5994a8a47a41SBjoern A. Zeeb if (!list_empty_careful(&lhw->lchanctx_list)) {
5995a8a47a41SBjoern A. Zeeb struct lkpi_chanctx *lchanctx, *next;
5996a8a47a41SBjoern A. Zeeb struct ieee80211_chanctx_conf *chanctx_conf;
5997a8a47a41SBjoern A. Zeeb
5998a8a47a41SBjoern A. Zeeb list_for_each_entry_safe(lchanctx, next, &lhw->lchanctx_list, entry) {
5999a8a47a41SBjoern A. Zeeb if (lchanctx->added_to_drv) {
6000a8a47a41SBjoern A. Zeeb /* In reality we should panic? */
6001a8a47a41SBjoern A. Zeeb chanctx_conf = &lchanctx->chanctx_conf;
6002a8a47a41SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, chanctx_conf);
6003a8a47a41SBjoern A. Zeeb }
6004a8a47a41SBjoern A. Zeeb list_del(&lchanctx->entry);
6005a8a47a41SBjoern A. Zeeb free(lchanctx, M_LKPI80211);
6006a8a47a41SBjoern A. Zeeb }
6007a8a47a41SBjoern A. Zeeb }
6008a8a47a41SBjoern A. Zeeb
60096b4cac81SBjoern A. Zeeb /* Cleanup more of lhw here or in wiphy_free()? */
6010eac3646fSBjoern A. Zeeb LKPI_80211_LHW_TXQ_LOCK_DESTROY(lhw);
60118ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK_DESTROY(lhw);
6012eac3646fSBjoern A. Zeeb sx_destroy(&lhw->lvif_sx);
60136b4cac81SBjoern A. Zeeb IMPROVE();
60146b4cac81SBjoern A. Zeeb }
60156b4cac81SBjoern A. Zeeb
60166b4cac81SBjoern A. Zeeb void
60176b4cac81SBjoern A. Zeeb linuxkpi_set_ieee80211_dev(struct ieee80211_hw *hw, char *name)
60186b4cac81SBjoern A. Zeeb {
60196b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
60206b4cac81SBjoern A. Zeeb struct ieee80211com *ic;
60216b4cac81SBjoern A. Zeeb
60226b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw);
60236b4cac81SBjoern A. Zeeb ic = lhw->ic;
60246b4cac81SBjoern A. Zeeb
60256b4cac81SBjoern A. Zeeb /* Now set a proper name before ieee80211_ifattach(). */
60266b4cac81SBjoern A. Zeeb ic->ic_softc = lhw;
60276b4cac81SBjoern A. Zeeb ic->ic_name = name;
60286b4cac81SBjoern A. Zeeb
60296b4cac81SBjoern A. Zeeb /* XXX-BZ do we also need to set wiphy name? */
60306b4cac81SBjoern A. Zeeb }
60316b4cac81SBjoern A. Zeeb
60326b4cac81SBjoern A. Zeeb struct ieee80211_hw *
60336b4cac81SBjoern A. Zeeb linuxkpi_wiphy_to_ieee80211_hw(struct wiphy *wiphy)
60346b4cac81SBjoern A. Zeeb {
60356b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
60366b4cac81SBjoern A. Zeeb
60376b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy);
60386b4cac81SBjoern A. Zeeb return (LHW_TO_HW(lhw));
60396b4cac81SBjoern A. Zeeb }
60406b4cac81SBjoern A. Zeeb
60416b4cac81SBjoern A. Zeeb static void
60426b4cac81SBjoern A. Zeeb lkpi_radiotap_attach(struct lkpi_hw *lhw)
60436b4cac81SBjoern A. Zeeb {
60446b4cac81SBjoern A. Zeeb struct ieee80211com *ic;
60456b4cac81SBjoern A. Zeeb
60466b4cac81SBjoern A. Zeeb ic = lhw->ic;
60476b4cac81SBjoern A. Zeeb ieee80211_radiotap_attach(ic,
60486b4cac81SBjoern A. Zeeb &lhw->rtap_tx.wt_ihdr, sizeof(lhw->rtap_tx),
60496b4cac81SBjoern A. Zeeb LKPI_RTAP_TX_FLAGS_PRESENT,
60506b4cac81SBjoern A. Zeeb &lhw->rtap_rx.wr_ihdr, sizeof(lhw->rtap_rx),
60516b4cac81SBjoern A. Zeeb LKPI_RTAP_RX_FLAGS_PRESENT);
60526b4cac81SBjoern A. Zeeb }
60536b4cac81SBjoern A. Zeeb
60542e183d99SBjoern A. Zeeb int
60556b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ifattach(struct ieee80211_hw *hw)
60566b4cac81SBjoern A. Zeeb {
60576b4cac81SBjoern A. Zeeb struct ieee80211com *ic;
60586b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
6059c5b96b3eSBjoern A. Zeeb int band, i;
60606b4cac81SBjoern A. Zeeb
60616b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw);
60626b4cac81SBjoern A. Zeeb ic = lhw->ic;
60636b4cac81SBjoern A. Zeeb
6064652e22d3SBjoern A. Zeeb /* We do it this late as wiphy->dev should be set for the name. */
6065652e22d3SBjoern A. Zeeb lhw->workq = alloc_ordered_workqueue(wiphy_name(hw->wiphy), 0);
6066652e22d3SBjoern A. Zeeb if (lhw->workq == NULL)
6067652e22d3SBjoern A. Zeeb return (-EAGAIN);
6068652e22d3SBjoern A. Zeeb
60696b4cac81SBjoern A. Zeeb /* XXX-BZ figure this out how they count his... */
60706b4cac81SBjoern A. Zeeb if (!is_zero_ether_addr(hw->wiphy->perm_addr)) {
60716b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(ic->ic_macaddr,
60726b4cac81SBjoern A. Zeeb hw->wiphy->perm_addr);
60736b4cac81SBjoern A. Zeeb } else if (hw->wiphy->n_addresses > 0) {
60746b4cac81SBjoern A. Zeeb /* We take the first one. */
60756b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(ic->ic_macaddr,
60766b4cac81SBjoern A. Zeeb hw->wiphy->addresses[0].addr);
60776b4cac81SBjoern A. Zeeb } else {
60786b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: warning, no hardware address!\n", __func__);
60796b4cac81SBjoern A. Zeeb }
60806b4cac81SBjoern A. Zeeb
60813d09d310SBjoern A. Zeeb #ifdef __not_yet__
60823d09d310SBjoern A. Zeeb /* See comment in lkpi_80211_txq_tx_one(). */
60836b4cac81SBjoern A. Zeeb ic->ic_headroom = hw->extra_tx_headroom;
60843d09d310SBjoern A. Zeeb #endif
60856b4cac81SBjoern A. Zeeb
60866b4cac81SBjoern A. Zeeb ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */
60876b4cac81SBjoern A. Zeeb ic->ic_opmode = IEEE80211_M_STA;
60886b4cac81SBjoern A. Zeeb
60896b4cac81SBjoern A. Zeeb /* Set device capabilities. */
60906b4cac81SBjoern A. Zeeb /* XXX-BZ we need to get these from linux80211/drivers and convert. */
60916b4cac81SBjoern A. Zeeb ic->ic_caps =
60926b4cac81SBjoern A. Zeeb IEEE80211_C_STA |
60936b4cac81SBjoern A. Zeeb IEEE80211_C_MONITOR |
60946b4cac81SBjoern A. Zeeb IEEE80211_C_WPA | /* WPA/RSN */
60954a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME
60966b4cac81SBjoern A. Zeeb IEEE80211_C_WME |
60974a67f1dfSBjoern A. Zeeb #endif
60986b4cac81SBjoern A. Zeeb #if 0
60996b4cac81SBjoern A. Zeeb IEEE80211_C_PMGT |
61006b4cac81SBjoern A. Zeeb #endif
61016b4cac81SBjoern A. Zeeb IEEE80211_C_SHSLOT | /* short slot time supported */
61026b4cac81SBjoern A. Zeeb IEEE80211_C_SHPREAMBLE /* short preamble supported */
61036b4cac81SBjoern A. Zeeb ;
61046b4cac81SBjoern A. Zeeb #if 0
61056b4cac81SBjoern A. Zeeb /* Scanning is a different kind of beast to re-work. */
61066b4cac81SBjoern A. Zeeb ic->ic_caps |= IEEE80211_C_BGSCAN;
61076b4cac81SBjoern A. Zeeb #endif
6108cc4e78d5SBjoern A. Zeeb if (lhw->ops->hw_scan) {
6109cc4e78d5SBjoern A. Zeeb /*
6110cc4e78d5SBjoern A. Zeeb * Advertise full-offload scanning.
6111cc4e78d5SBjoern A. Zeeb *
6112cc4e78d5SBjoern A. Zeeb * Not limiting to SINGLE_SCAN_ON_ALL_BANDS here as otherwise
6113cc4e78d5SBjoern A. Zeeb * we essentially disable hw_scan for all drivers not setting
6114cc4e78d5SBjoern A. Zeeb * the flag.
6115cc4e78d5SBjoern A. Zeeb */
61166b4cac81SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_SCAN_OFFLOAD;
6117a486fbbdSBjoern A. Zeeb lhw->scan_flags |= LKPI_LHW_SCAN_HW;
61186b4cac81SBjoern A. Zeeb }
61196b4cac81SBjoern A. Zeeb
612063578bf2SBjoern A. Zeeb /* Does HW support Fragmentation offload? */
612163578bf2SBjoern A. Zeeb if (ieee80211_hw_check(hw, SUPPORTS_TX_FRAG))
612263578bf2SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_FRAG_OFFLOAD;
612363578bf2SBjoern A. Zeeb
6124527687a9SBjoern A. Zeeb /*
6125527687a9SBjoern A. Zeeb * The wiphy variables report bitmasks of avail antennas.
6126527687a9SBjoern A. Zeeb * (*get_antenna) get the current bitmask sets which can be
6127527687a9SBjoern A. Zeeb * altered by (*set_antenna) for some drivers.
6128527687a9SBjoern A. Zeeb * XXX-BZ will the count alone do us much good long-term in net80211?
6129527687a9SBjoern A. Zeeb */
6130527687a9SBjoern A. Zeeb if (hw->wiphy->available_antennas_rx ||
6131527687a9SBjoern A. Zeeb hw->wiphy->available_antennas_tx) {
6132527687a9SBjoern A. Zeeb uint32_t rxs, txs;
6133527687a9SBjoern A. Zeeb
6134527687a9SBjoern A. Zeeb if (lkpi_80211_mo_get_antenna(hw, &txs, &rxs) == 0) {
6135527687a9SBjoern A. Zeeb ic->ic_rxstream = bitcount32(rxs);
6136527687a9SBjoern A. Zeeb ic->ic_txstream = bitcount32(txs);
6137527687a9SBjoern A. Zeeb }
6138527687a9SBjoern A. Zeeb }
6139527687a9SBjoern A. Zeeb
61406b4cac81SBjoern A. Zeeb ic->ic_cryptocaps = 0;
6141b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO
614211db70b6SBjoern A. Zeeb if (lkpi_hwcrypto && hw->wiphy->n_cipher_suites > 0) {
6143bf8c25f1SBjoern A. Zeeb uint32_t hwciphers;
6144bf8c25f1SBjoern A. Zeeb
6145bf8c25f1SBjoern A. Zeeb hwciphers = 0;
614692942717SBjoern A. Zeeb for (i = 0; i < hw->wiphy->n_cipher_suites; i++) {
614792942717SBjoern A. Zeeb uint32_t cs;
614892942717SBjoern A. Zeeb
614992942717SBjoern A. Zeeb cs = lkpi_l80211_to_net80211_cyphers(
6150bf8c25f1SBjoern A. Zeeb ic, hw->wiphy->cipher_suites[i]);
615192942717SBjoern A. Zeeb if (cs == IEEE80211_CRYPTO_TKIP) {
615292942717SBjoern A. Zeeb /*
615392942717SBjoern A. Zeeb * We do set this here. We will only find out
615492942717SBjoern A. Zeeb * when doing a SET_KEY operation depending on
615592942717SBjoern A. Zeeb * what the driver returns.
615692942717SBjoern A. Zeeb * net80211::ieee80211_crypto_newkey()
615792942717SBjoern A. Zeeb * checks this so we will have to do flags
615892942717SBjoern A. Zeeb * surgery later.
615992942717SBjoern A. Zeeb */
616092942717SBjoern A. Zeeb cs |= IEEE80211_CRYPTO_TKIPMIC;
616192942717SBjoern A. Zeeb }
616292942717SBjoern A. Zeeb hwciphers |= cs;
616392942717SBjoern A. Zeeb }
6164bf8c25f1SBjoern A. Zeeb /*
6165bf8c25f1SBjoern A. Zeeb * (20250415) nothing anywhere in the path checks we actually
6166bf8c25f1SBjoern A. Zeeb * support all these in net80211.
6167bf8c25f1SBjoern A. Zeeb * net80211 supports _256 variants but the ioctl does not.
6168bf8c25f1SBjoern A. Zeeb */
6169bf8c25f1SBjoern A. Zeeb IMPROVE("as net80211 grows more support, enable them");
617092942717SBjoern A. Zeeb hwciphers &= (IEEE80211_CRYPTO_WEP |
617192942717SBjoern A. Zeeb IEEE80211_CRYPTO_TKIP | IEEE80211_CRYPTO_TKIPMIC |
6172bf8c25f1SBjoern A. Zeeb IEEE80211_CRYPTO_AES_CCM | IEEE80211_CRYPTO_AES_GCM_128);
6173b71d3043SBjoern A. Zeeb /*
6174b71d3043SBjoern A. Zeeb * We only support CCMP here, so further filter.
6175b71d3043SBjoern A. Zeeb * Also permit TKIP if turned on.
6176b71d3043SBjoern A. Zeeb */
6177b71d3043SBjoern A. Zeeb hwciphers &= (IEEE80211_CRYPTO_AES_CCM |
617829ddd583SBjoern A. Zeeb IEEE80211_CRYPTO_AES_GCM_128 |
6179b71d3043SBjoern A. Zeeb (lkpi_hwcrypto_tkip ? (IEEE80211_CRYPTO_TKIP |
6180b71d3043SBjoern A. Zeeb IEEE80211_CRYPTO_TKIPMIC) : 0));
6181bf8c25f1SBjoern A. Zeeb ieee80211_set_hardware_ciphers(ic, hwciphers);
61826b4cac81SBjoern A. Zeeb }
61836b4cac81SBjoern A. Zeeb #endif
61846b4cac81SBjoern A. Zeeb
61856b4cac81SBjoern A. Zeeb lkpi_ic_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans,
61866b4cac81SBjoern A. Zeeb ic->ic_channels);
61876b4cac81SBjoern A. Zeeb
61886b4cac81SBjoern A. Zeeb ieee80211_ifattach(ic);
61896b4cac81SBjoern A. Zeeb
61906b4cac81SBjoern A. Zeeb ic->ic_update_mcast = lkpi_ic_update_mcast;
61916b4cac81SBjoern A. Zeeb ic->ic_update_promisc = lkpi_ic_update_promisc;
61926b4cac81SBjoern A. Zeeb ic->ic_update_chw = lkpi_ic_update_chw;
61936b4cac81SBjoern A. Zeeb ic->ic_parent = lkpi_ic_parent;
61946b4cac81SBjoern A. Zeeb ic->ic_scan_start = lkpi_ic_scan_start;
61956b4cac81SBjoern A. Zeeb ic->ic_scan_end = lkpi_ic_scan_end;
61966b4cac81SBjoern A. Zeeb ic->ic_set_channel = lkpi_ic_set_channel;
61976b4cac81SBjoern A. Zeeb ic->ic_transmit = lkpi_ic_transmit;
61986b4cac81SBjoern A. Zeeb ic->ic_raw_xmit = lkpi_ic_raw_xmit;
61996b4cac81SBjoern A. Zeeb ic->ic_vap_create = lkpi_ic_vap_create;
62006b4cac81SBjoern A. Zeeb ic->ic_vap_delete = lkpi_ic_vap_delete;
62016b4cac81SBjoern A. Zeeb ic->ic_getradiocaps = lkpi_ic_getradiocaps;
62026b4cac81SBjoern A. Zeeb ic->ic_wme.wme_update = lkpi_ic_wme_update;
62036b4cac81SBjoern A. Zeeb
6204a486fbbdSBjoern A. Zeeb lhw->ic_scan_curchan = ic->ic_scan_curchan;
6205a486fbbdSBjoern A. Zeeb ic->ic_scan_curchan = lkpi_ic_scan_curchan;
6206a486fbbdSBjoern A. Zeeb lhw->ic_scan_mindwell = ic->ic_scan_mindwell;
6207a486fbbdSBjoern A. Zeeb ic->ic_scan_mindwell = lkpi_ic_scan_mindwell;
6208a486fbbdSBjoern A. Zeeb
62096b4cac81SBjoern A. Zeeb lhw->ic_node_alloc = ic->ic_node_alloc;
62106b4cac81SBjoern A. Zeeb ic->ic_node_alloc = lkpi_ic_node_alloc;
62116b4cac81SBjoern A. Zeeb lhw->ic_node_init = ic->ic_node_init;
62126b4cac81SBjoern A. Zeeb ic->ic_node_init = lkpi_ic_node_init;
62136b4cac81SBjoern A. Zeeb lhw->ic_node_cleanup = ic->ic_node_cleanup;
62146b4cac81SBjoern A. Zeeb ic->ic_node_cleanup = lkpi_ic_node_cleanup;
62156b4cac81SBjoern A. Zeeb lhw->ic_node_free = ic->ic_node_free;
62166b4cac81SBjoern A. Zeeb ic->ic_node_free = lkpi_ic_node_free;
62176b4cac81SBjoern A. Zeeb
62189fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT
621986bc7259SBjoern A. Zeeb /*
622086bc7259SBjoern A. Zeeb * Only attach if the driver/firmware supports (*ampdu_action)().
622186bc7259SBjoern A. Zeeb * Otherwise it is in the hands of net80211.
622286bc7259SBjoern A. Zeeb */
622386bc7259SBjoern A. Zeeb if (lhw->ops->ampdu_action != NULL) {
62249fb91463SBjoern A. Zeeb lhw->ic_recv_action = ic->ic_recv_action;
62259fb91463SBjoern A. Zeeb ic->ic_recv_action = lkpi_ic_recv_action;
62269fb91463SBjoern A. Zeeb lhw->ic_send_action = ic->ic_send_action;
62279fb91463SBjoern A. Zeeb ic->ic_send_action = lkpi_ic_send_action;
62289fb91463SBjoern A. Zeeb
62299fb91463SBjoern A. Zeeb lhw->ic_ampdu_enable = ic->ic_ampdu_enable;
62309fb91463SBjoern A. Zeeb ic->ic_ampdu_enable = lkpi_ic_ampdu_enable;
62319fb91463SBjoern A. Zeeb
62329fb91463SBjoern A. Zeeb lhw->ic_addba_request = ic->ic_addba_request;
62339fb91463SBjoern A. Zeeb ic->ic_addba_request = lkpi_ic_addba_request;
62349fb91463SBjoern A. Zeeb lhw->ic_addba_response = ic->ic_addba_response;
62359fb91463SBjoern A. Zeeb ic->ic_addba_response = lkpi_ic_addba_response;
62369fb91463SBjoern A. Zeeb lhw->ic_addba_stop = ic->ic_addba_stop;
62379fb91463SBjoern A. Zeeb ic->ic_addba_stop = lkpi_ic_addba_stop;
62389fb91463SBjoern A. Zeeb lhw->ic_addba_response_timeout = ic->ic_addba_response_timeout;
62399fb91463SBjoern A. Zeeb ic->ic_addba_response_timeout = lkpi_ic_addba_response_timeout;
62409fb91463SBjoern A. Zeeb
62419fb91463SBjoern A. Zeeb lhw->ic_bar_response = ic->ic_bar_response;
62429fb91463SBjoern A. Zeeb ic->ic_bar_response = lkpi_ic_bar_response;
62439fb91463SBjoern A. Zeeb
62449fb91463SBjoern A. Zeeb lhw->ic_ampdu_rx_start = ic->ic_ampdu_rx_start;
62459fb91463SBjoern A. Zeeb ic->ic_ampdu_rx_start = lkpi_ic_ampdu_rx_start;
62469fb91463SBjoern A. Zeeb lhw->ic_ampdu_rx_stop = ic->ic_ampdu_rx_stop;
62479fb91463SBjoern A. Zeeb ic->ic_ampdu_rx_stop = lkpi_ic_ampdu_rx_stop;
624886bc7259SBjoern A. Zeeb }
62499fb91463SBjoern A. Zeeb #endif
62509fb91463SBjoern A. Zeeb
62516b4cac81SBjoern A. Zeeb lkpi_radiotap_attach(lhw);
62526b4cac81SBjoern A. Zeeb
6253c5b96b3eSBjoern A. Zeeb /*
6254c5b96b3eSBjoern A. Zeeb * Assign the first possible channel for now; seems Realtek drivers
6255c5b96b3eSBjoern A. Zeeb * expect one.
6256d9945d78SBjoern A. Zeeb * Also remember the amount of bands we support and the most rates
6257d9945d78SBjoern A. Zeeb * in any band so we can scale [(ext) sup rates] IE(s) accordingly.
6258c5b96b3eSBjoern A. Zeeb */
6259d9945d78SBjoern A. Zeeb lhw->supbands = lhw->max_rates = 0;
6260f454a4a1SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) {
6261c5b96b3eSBjoern A. Zeeb struct ieee80211_supported_band *supband;
6262c5b96b3eSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels;
6263c5b96b3eSBjoern A. Zeeb
6264c5b96b3eSBjoern A. Zeeb supband = hw->wiphy->bands[band];
6265c5b96b3eSBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0)
6266c5b96b3eSBjoern A. Zeeb continue;
6267c5b96b3eSBjoern A. Zeeb
6268d9945d78SBjoern A. Zeeb lhw->supbands++;
6269d9945d78SBjoern A. Zeeb lhw->max_rates = max(lhw->max_rates, supband->n_bitrates);
6270d9945d78SBjoern A. Zeeb
6271f454a4a1SBjoern A. Zeeb /* If we have a channel, we need to keep counting supbands. */
6272f454a4a1SBjoern A. Zeeb if (hw->conf.chandef.chan != NULL)
6273f454a4a1SBjoern A. Zeeb continue;
6274f454a4a1SBjoern A. Zeeb
6275c5b96b3eSBjoern A. Zeeb channels = supband->channels;
6276c5b96b3eSBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) {
6277c5b96b3eSBjoern A. Zeeb
6278c5b96b3eSBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED)
6279c5b96b3eSBjoern A. Zeeb continue;
6280c5b96b3eSBjoern A. Zeeb
62814a07abdeSBjoern A. Zeeb cfg80211_chandef_create(&hw->conf.chandef, &channels[i],
62829fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT
628311450726SBjoern A. Zeeb (ic->ic_flags_ht & IEEE80211_FHT_HT) ? NL80211_CHAN_HT20 :
62849fb91463SBjoern A. Zeeb #endif
6285c5b96b3eSBjoern A. Zeeb NL80211_CHAN_NO_HT);
6286c5b96b3eSBjoern A. Zeeb break;
6287c5b96b3eSBjoern A. Zeeb }
6288c5b96b3eSBjoern A. Zeeb }
6289c5b96b3eSBjoern A. Zeeb
6290d9945d78SBjoern A. Zeeb IMPROVE("see net80211::ieee80211_chan_init vs. wiphy->bands[].bitrates possibly in lkpi_ic_getradiocaps?");
6291d9945d78SBjoern A. Zeeb
6292d9945d78SBjoern A. Zeeb /* Make sure we do not support more than net80211 is willing to take. */
6293d9945d78SBjoern A. Zeeb if (lhw->max_rates > IEEE80211_RATE_MAXSIZE) {
6294d9945d78SBjoern A. Zeeb ic_printf(ic, "%s: limiting max_rates %d to %d!\n", __func__,
6295d9945d78SBjoern A. Zeeb lhw->max_rates, IEEE80211_RATE_MAXSIZE);
6296d9945d78SBjoern A. Zeeb lhw->max_rates = IEEE80211_RATE_MAXSIZE;
6297d9945d78SBjoern A. Zeeb }
6298d9945d78SBjoern A. Zeeb
6299d9945d78SBjoern A. Zeeb /*
6300d9945d78SBjoern A. Zeeb * The maximum supported bitrates on any band + size for
6301d9945d78SBjoern A. Zeeb * DSSS Parameter Set give our per-band IE size.
6302d9945d78SBjoern A. Zeeb * SSID is the responsibility of the driver and goes on the side.
6303d9945d78SBjoern A. Zeeb * The user specified bits coming from the vap go into the
6304d9945d78SBjoern A. Zeeb * "common ies" fields.
6305d9945d78SBjoern A. Zeeb */
6306d9945d78SBjoern A. Zeeb lhw->scan_ie_len = 2 + IEEE80211_RATE_SIZE;
6307d9945d78SBjoern A. Zeeb if (lhw->max_rates > IEEE80211_RATE_SIZE)
6308d9945d78SBjoern A. Zeeb lhw->scan_ie_len += 2 + (lhw->max_rates - IEEE80211_RATE_SIZE);
630978ca45dfSBjoern A. Zeeb
631078ca45dfSBjoern A. Zeeb if (hw->wiphy->features & NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) {
6311d9945d78SBjoern A. Zeeb /*
631278ca45dfSBjoern A. Zeeb * net80211 does not seem to support the DSSS Parameter Set but
631378ca45dfSBjoern A. Zeeb * some of the drivers insert it so calculate the extra fixed
631478ca45dfSBjoern A. Zeeb * space in.
6315d9945d78SBjoern A. Zeeb */
6316d9945d78SBjoern A. Zeeb lhw->scan_ie_len += 2 + 1;
631778ca45dfSBjoern A. Zeeb }
6318d9945d78SBjoern A. Zeeb
63199fb91463SBjoern A. Zeeb #if defined(LKPI_80211_HT)
63209fb91463SBjoern A. Zeeb if ((ic->ic_htcaps & IEEE80211_HTC_HT) != 0)
63219fb91463SBjoern A. Zeeb lhw->scan_ie_len += sizeof(struct ieee80211_ie_htcap);
63229fb91463SBjoern A. Zeeb #endif
63239fb91463SBjoern A. Zeeb #if defined(LKPI_80211_VHT)
63241f73e0edSBjoern A. Zeeb if (IEEE80211_CONF_VHT(ic))
63259fb91463SBjoern A. Zeeb lhw->scan_ie_len += 2 + sizeof(struct ieee80211_vht_cap);
63269fb91463SBjoern A. Zeeb #endif
63279fb91463SBjoern A. Zeeb
6328d9945d78SBjoern A. Zeeb /* Reduce the max_scan_ie_len "left" by the amount we consume already. */
632978ca45dfSBjoern A. Zeeb if (hw->wiphy->max_scan_ie_len > 0) {
633078ca45dfSBjoern A. Zeeb if (lhw->scan_ie_len > hw->wiphy->max_scan_ie_len)
633178ca45dfSBjoern A. Zeeb goto err;
6332d9945d78SBjoern A. Zeeb hw->wiphy->max_scan_ie_len -= lhw->scan_ie_len;
633378ca45dfSBjoern A. Zeeb }
6334d9945d78SBjoern A. Zeeb
63356b4cac81SBjoern A. Zeeb if (bootverbose)
63366b4cac81SBjoern A. Zeeb ieee80211_announce(ic);
63372e183d99SBjoern A. Zeeb
63382e183d99SBjoern A. Zeeb return (0);
633978ca45dfSBjoern A. Zeeb err:
634078ca45dfSBjoern A. Zeeb IMPROVE("TODO FIXME CLEANUP");
634178ca45dfSBjoern A. Zeeb return (-EAGAIN);
63426b4cac81SBjoern A. Zeeb }
63436b4cac81SBjoern A. Zeeb
63446b4cac81SBjoern A. Zeeb void
63456b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ifdetach(struct ieee80211_hw *hw)
63466b4cac81SBjoern A. Zeeb {
63476b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
63486b4cac81SBjoern A. Zeeb struct ieee80211com *ic;
63496b4cac81SBjoern A. Zeeb
63506b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw);
63516b4cac81SBjoern A. Zeeb ic = lhw->ic;
63526b4cac81SBjoern A. Zeeb ieee80211_ifdetach(ic);
63536b4cac81SBjoern A. Zeeb }
63546b4cac81SBjoern A. Zeeb
63556b4cac81SBjoern A. Zeeb void
63566b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_interfaces(struct ieee80211_hw *hw,
63576b4cac81SBjoern A. Zeeb enum ieee80211_iface_iter flags,
63586b4cac81SBjoern A. Zeeb void(*iterfunc)(void *, uint8_t *, struct ieee80211_vif *),
63596b4cac81SBjoern A. Zeeb void *arg)
63606b4cac81SBjoern A. Zeeb {
63616b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
63626b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
63636b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif;
636461a68e50SBjoern A. Zeeb bool active, atomic, nin_drv;
63656b4cac81SBjoern A. Zeeb
63666b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw);
63676b4cac81SBjoern A. Zeeb
63686b4cac81SBjoern A. Zeeb if (flags & ~(IEEE80211_IFACE_ITER_NORMAL|
63696b4cac81SBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL|
637061a68e50SBjoern A. Zeeb IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER|
6371adff403fSBjoern A. Zeeb IEEE80211_IFACE_ITER_ACTIVE|IEEE80211_IFACE_ITER__ATOMIC)) {
63726b4cac81SBjoern A. Zeeb ic_printf(lhw->ic, "XXX TODO %s flags(%#x) not yet supported.\n",
63736b4cac81SBjoern A. Zeeb __func__, flags);
63746b4cac81SBjoern A. Zeeb }
63756b4cac81SBjoern A. Zeeb
6376adff403fSBjoern A. Zeeb active = (flags & IEEE80211_IFACE_ITER_ACTIVE) != 0;
63776b4cac81SBjoern A. Zeeb atomic = (flags & IEEE80211_IFACE_ITER__ATOMIC) != 0;
637861a68e50SBjoern A. Zeeb nin_drv = (flags & IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER) != 0;
63796b4cac81SBjoern A. Zeeb
63806b4cac81SBjoern A. Zeeb if (atomic)
63818891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw);
63826b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) {
63836b4cac81SBjoern A. Zeeb struct ieee80211vap *vap;
63846b4cac81SBjoern A. Zeeb
63856b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
63866b4cac81SBjoern A. Zeeb
63876b4cac81SBjoern A. Zeeb /*
63886b4cac81SBjoern A. Zeeb * If we want "active" interfaces, we need to distinguish on
63896b4cac81SBjoern A. Zeeb * whether the driver knows about them or not to be able to
63906b4cac81SBjoern A. Zeeb * handle the "resume" case correctly. Skip the ones the
63916b4cac81SBjoern A. Zeeb * driver does not know about.
63926b4cac81SBjoern A. Zeeb */
63936b4cac81SBjoern A. Zeeb if (active && !lvif->added_to_drv &&
63946b4cac81SBjoern A. Zeeb (flags & IEEE80211_IFACE_ITER_RESUME_ALL) != 0)
63956b4cac81SBjoern A. Zeeb continue;
63966b4cac81SBjoern A. Zeeb
63976b4cac81SBjoern A. Zeeb /*
639861a68e50SBjoern A. Zeeb * If we shall skip interfaces not added to the driver do so
639961a68e50SBjoern A. Zeeb * if we haven't yet.
640061a68e50SBjoern A. Zeeb */
640161a68e50SBjoern A. Zeeb if (nin_drv && !lvif->added_to_drv)
640261a68e50SBjoern A. Zeeb continue;
640361a68e50SBjoern A. Zeeb
640461a68e50SBjoern A. Zeeb /*
64056b4cac81SBjoern A. Zeeb * Run the iterator function if we are either not asking
64066b4cac81SBjoern A. Zeeb * asking for active only or if the VAP is "running".
64076b4cac81SBjoern A. Zeeb */
64086b4cac81SBjoern A. Zeeb /* XXX-BZ probably should have state in the lvif as well. */
64096b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif);
64106b4cac81SBjoern A. Zeeb if (!active || (vap->iv_state != IEEE80211_S_INIT))
64116b4cac81SBjoern A. Zeeb iterfunc(arg, vif->addr, vif);
64126b4cac81SBjoern A. Zeeb }
64136b4cac81SBjoern A. Zeeb if (atomic)
64148891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw);
64156b4cac81SBjoern A. Zeeb }
64166b4cac81SBjoern A. Zeeb
641711db70b6SBjoern A. Zeeb static void
641811db70b6SBjoern A. Zeeb lkpi_ieee80211_iterate_keys(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
641911db70b6SBjoern A. Zeeb ieee80211_keyix keyix, struct lkpi_sta *lsta,
642011db70b6SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_vif *,
642111db70b6SBjoern A. Zeeb struct ieee80211_sta *, struct ieee80211_key_conf *, void *),
642211db70b6SBjoern A. Zeeb void *arg)
642311db70b6SBjoern A. Zeeb {
642411db70b6SBjoern A. Zeeb if (!lsta->added_to_drv)
642511db70b6SBjoern A. Zeeb return;
642611db70b6SBjoern A. Zeeb
642711db70b6SBjoern A. Zeeb if (lsta->kc[keyix] == NULL)
642811db70b6SBjoern A. Zeeb return;
642911db70b6SBjoern A. Zeeb
643011db70b6SBjoern A. Zeeb iterfunc(hw, vif, LSTA_TO_STA(lsta), lsta->kc[keyix], arg);
643111db70b6SBjoern A. Zeeb }
643211db70b6SBjoern A. Zeeb
64336b4cac81SBjoern A. Zeeb void
64346b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_keys(struct ieee80211_hw *hw,
64356b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif,
64366b4cac81SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_vif *,
64376b4cac81SBjoern A. Zeeb struct ieee80211_sta *, struct ieee80211_key_conf *, void *),
643811db70b6SBjoern A. Zeeb void *arg, bool rcu)
64396b4cac81SBjoern A. Zeeb {
644011db70b6SBjoern A. Zeeb struct lkpi_sta *lsta;
644111db70b6SBjoern A. Zeeb struct lkpi_vif *lvif;
64426b4cac81SBjoern A. Zeeb
644311db70b6SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif);
644411db70b6SBjoern A. Zeeb
644511db70b6SBjoern A. Zeeb if (rcu) {
6446a8f735a6SBjoern A. Zeeb rcu_read_lock_held(); /* XXX-BZ is this correct? */
6447a8f735a6SBjoern A. Zeeb
644811db70b6SBjoern A. Zeeb if (vif == NULL) {
644911db70b6SBjoern A. Zeeb TODO();
645011db70b6SBjoern A. Zeeb } else {
6451a8f735a6SBjoern A. Zeeb list_for_each_entry_rcu(lsta, &lvif->lsta_list, lsta_list) {
645211db70b6SBjoern A. Zeeb for (ieee80211_keyix keyix = 0; keyix < nitems(lsta->kc);
645311db70b6SBjoern A. Zeeb keyix++)
645411db70b6SBjoern A. Zeeb lkpi_ieee80211_iterate_keys(hw, vif,
645511db70b6SBjoern A. Zeeb keyix, lsta, iterfunc, arg);
645611db70b6SBjoern A. Zeeb }
645711db70b6SBjoern A. Zeeb }
645811db70b6SBjoern A. Zeeb } else {
645911db70b6SBjoern A. Zeeb TODO("Used by suspend/resume; order of keys as installed to "
646011db70b6SBjoern A. Zeeb "firmware is important; we'll need to rewrite some code for that");
646111db70b6SBjoern A. Zeeb lockdep_assert_wiphy(hw->wiphy);
646211db70b6SBjoern A. Zeeb
646311db70b6SBjoern A. Zeeb if (vif == NULL) {
646411db70b6SBjoern A. Zeeb TODO();
646511db70b6SBjoern A. Zeeb } else {
6466a8f735a6SBjoern A. Zeeb list_for_each_entry(lsta, &lvif->lsta_list, lsta_list) {
646711db70b6SBjoern A. Zeeb for (ieee80211_keyix keyix = 0; keyix < nitems(lsta->kc);
646811db70b6SBjoern A. Zeeb keyix++)
646911db70b6SBjoern A. Zeeb lkpi_ieee80211_iterate_keys(hw, vif,
647011db70b6SBjoern A. Zeeb keyix, lsta, iterfunc, arg);
647111db70b6SBjoern A. Zeeb }
647211db70b6SBjoern A. Zeeb }
647311db70b6SBjoern A. Zeeb }
64746b4cac81SBjoern A. Zeeb }
64756b4cac81SBjoern A. Zeeb
64766b4cac81SBjoern A. Zeeb void
64776b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_chan_contexts(struct ieee80211_hw *hw,
64786b4cac81SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_chanctx_conf *,
64796b4cac81SBjoern A. Zeeb void *),
64806b4cac81SBjoern A. Zeeb void *arg)
64816b4cac81SBjoern A. Zeeb {
6482c5e25798SBjoern A. Zeeb struct lkpi_hw *lhw;
6483c5e25798SBjoern A. Zeeb struct lkpi_chanctx *lchanctx;
64846b4cac81SBjoern A. Zeeb
6485c5e25798SBjoern A. Zeeb KASSERT(hw != NULL && iterfunc != NULL,
6486c5e25798SBjoern A. Zeeb ("%s: hw %p iterfunc %p arg %p\n", __func__, hw, iterfunc, arg));
6487c5e25798SBjoern A. Zeeb
6488c5e25798SBjoern A. Zeeb lhw = HW_TO_LHW(hw);
6489c5e25798SBjoern A. Zeeb
6490a8a47a41SBjoern A. Zeeb rcu_read_lock();
6491a8a47a41SBjoern A. Zeeb list_for_each_entry_rcu(lchanctx, &lhw->lchanctx_list, entry) {
6492c5e25798SBjoern A. Zeeb if (!lchanctx->added_to_drv)
6493c5e25798SBjoern A. Zeeb continue;
6494d1af434dSBjoern A. Zeeb iterfunc(hw, &lchanctx->chanctx_conf, arg);
6495c5e25798SBjoern A. Zeeb }
6496a8a47a41SBjoern A. Zeeb rcu_read_unlock();
64976b4cac81SBjoern A. Zeeb }
64986b4cac81SBjoern A. Zeeb
64996b4cac81SBjoern A. Zeeb void
65006b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_stations_atomic(struct ieee80211_hw *hw,
65016b4cac81SBjoern A. Zeeb void (*iterfunc)(void *, struct ieee80211_sta *), void *arg)
65026b4cac81SBjoern A. Zeeb {
65036b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
65046b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
65056b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta;
65066b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta;
65076b4cac81SBjoern A. Zeeb
65086b4cac81SBjoern A. Zeeb KASSERT(hw != NULL && iterfunc != NULL,
65096b4cac81SBjoern A. Zeeb ("%s: hw %p iterfunc %p arg %p\n", __func__, hw, iterfunc, arg));
65106b4cac81SBjoern A. Zeeb
65116b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw);
65126b4cac81SBjoern A. Zeeb
65138891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw);
65146b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) {
65156b4cac81SBjoern A. Zeeb
6516a8f735a6SBjoern A. Zeeb rcu_read_lock();
6517a8f735a6SBjoern A. Zeeb list_for_each_entry_rcu(lsta, &lvif->lsta_list, lsta_list) {
65186b4cac81SBjoern A. Zeeb if (!lsta->added_to_drv)
65196b4cac81SBjoern A. Zeeb continue;
65206b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta);
65216b4cac81SBjoern A. Zeeb iterfunc(arg, sta);
65226b4cac81SBjoern A. Zeeb }
6523a8f735a6SBjoern A. Zeeb rcu_read_unlock();
65246b4cac81SBjoern A. Zeeb }
65258891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw);
65266b4cac81SBjoern A. Zeeb }
65276b4cac81SBjoern A. Zeeb
6528673d62fcSBjoern A. Zeeb struct linuxkpi_ieee80211_regdomain *
6529673d62fcSBjoern A. Zeeb lkpi_get_linuxkpi_ieee80211_regdomain(size_t n)
6530673d62fcSBjoern A. Zeeb {
6531673d62fcSBjoern A. Zeeb struct linuxkpi_ieee80211_regdomain *regd;
6532673d62fcSBjoern A. Zeeb
6533673d62fcSBjoern A. Zeeb regd = kzalloc(sizeof(*regd) + n * sizeof(struct ieee80211_reg_rule),
6534673d62fcSBjoern A. Zeeb GFP_KERNEL);
6535673d62fcSBjoern A. Zeeb return (regd);
6536673d62fcSBjoern A. Zeeb }
6537673d62fcSBjoern A. Zeeb
65386b4cac81SBjoern A. Zeeb int
65396b4cac81SBjoern A. Zeeb linuxkpi_regulatory_set_wiphy_regd_sync(struct wiphy *wiphy,
65406b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_regdomain *regd)
65416b4cac81SBjoern A. Zeeb {
65426b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
65436b4cac81SBjoern A. Zeeb struct ieee80211com *ic;
65446b4cac81SBjoern A. Zeeb struct ieee80211_regdomain *rd;
65456b4cac81SBjoern A. Zeeb
65466b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy);
65476b4cac81SBjoern A. Zeeb ic = lhw->ic;
65486b4cac81SBjoern A. Zeeb
65496b4cac81SBjoern A. Zeeb rd = &ic->ic_regdomain;
65506b4cac81SBjoern A. Zeeb if (rd->isocc[0] == '\0') {
65516b4cac81SBjoern A. Zeeb rd->isocc[0] = regd->alpha2[0];
65526b4cac81SBjoern A. Zeeb rd->isocc[1] = regd->alpha2[1];
65536b4cac81SBjoern A. Zeeb }
65546b4cac81SBjoern A. Zeeb
65556b4cac81SBjoern A. Zeeb TODO();
65566b4cac81SBjoern A. Zeeb /* XXX-BZ finish the rest. */
65576b4cac81SBjoern A. Zeeb
65586b4cac81SBjoern A. Zeeb return (0);
65596b4cac81SBjoern A. Zeeb }
65606b4cac81SBjoern A. Zeeb
65616b4cac81SBjoern A. Zeeb void
65626b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_scan_completed(struct ieee80211_hw *hw,
65636b4cac81SBjoern A. Zeeb struct cfg80211_scan_info *info)
65646b4cac81SBjoern A. Zeeb {
65656b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
65666b4cac81SBjoern A. Zeeb struct ieee80211com *ic;
65676b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss;
65686b4cac81SBjoern A. Zeeb
65696b4cac81SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy);
65706b4cac81SBjoern A. Zeeb ic = lhw->ic;
65716b4cac81SBjoern A. Zeeb ss = ic->ic_scan;
65726b4cac81SBjoern A. Zeeb
65736b4cac81SBjoern A. Zeeb ieee80211_scan_done(ss->ss_vap);
65746b4cac81SBjoern A. Zeeb
65758ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw);
65766b4cac81SBjoern A. Zeeb free(lhw->hw_req, M_LKPI80211);
65776b4cac81SBjoern A. Zeeb lhw->hw_req = NULL;
6578a486fbbdSBjoern A. Zeeb lhw->scan_flags &= ~LKPI_LHW_SCAN_RUNNING;
65796b4cac81SBjoern A. Zeeb wakeup(lhw);
65808ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw);
65816b4cac81SBjoern A. Zeeb
65826b4cac81SBjoern A. Zeeb return;
65836b4cac81SBjoern A. Zeeb }
65846b4cac81SBjoern A. Zeeb
6585759a996dSBjoern A. Zeeb static void
6586759a996dSBjoern A. Zeeb lkpi_80211_lhw_rxq_rx_one(struct lkpi_hw *lhw, struct mbuf *m)
6587759a996dSBjoern A. Zeeb {
6588759a996dSBjoern A. Zeeb struct ieee80211_node *ni;
6589dbae3dcfSBjoern A. Zeeb #ifdef LKPI_80211_USE_MTAG
6590759a996dSBjoern A. Zeeb struct m_tag *mtag;
6591dbae3dcfSBjoern A. Zeeb #endif
6592759a996dSBjoern A. Zeeb int ok;
6593759a996dSBjoern A. Zeeb
6594759a996dSBjoern A. Zeeb ni = NULL;
6595dbae3dcfSBjoern A. Zeeb #ifdef LKPI_80211_USE_MTAG
6596759a996dSBjoern A. Zeeb mtag = m_tag_locate(m, MTAG_ABI_LKPI80211, LKPI80211_TAG_RXNI, NULL);
6597759a996dSBjoern A. Zeeb if (mtag != NULL) {
6598759a996dSBjoern A. Zeeb struct lkpi_80211_tag_rxni *rxni;
6599759a996dSBjoern A. Zeeb
6600759a996dSBjoern A. Zeeb rxni = (struct lkpi_80211_tag_rxni *)(mtag + 1);
6601759a996dSBjoern A. Zeeb ni = rxni->ni;
6602759a996dSBjoern A. Zeeb }
6603dbae3dcfSBjoern A. Zeeb #else
6604dbae3dcfSBjoern A. Zeeb if (m->m_pkthdr.PH_loc.ptr != NULL) {
6605dbae3dcfSBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr;
6606dbae3dcfSBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = NULL;
6607dbae3dcfSBjoern A. Zeeb }
6608dbae3dcfSBjoern A. Zeeb #endif
6609759a996dSBjoern A. Zeeb
6610759a996dSBjoern A. Zeeb if (ni != NULL) {
6611759a996dSBjoern A. Zeeb ok = ieee80211_input_mimo(ni, m);
6612759a996dSBjoern A. Zeeb ieee80211_free_node(ni); /* Release the reference. */
6613759a996dSBjoern A. Zeeb if (ok < 0)
6614759a996dSBjoern A. Zeeb m_freem(m);
6615759a996dSBjoern A. Zeeb } else {
6616759a996dSBjoern A. Zeeb ok = ieee80211_input_mimo_all(lhw->ic, m);
6617759a996dSBjoern A. Zeeb /* mbuf got consumed. */
6618759a996dSBjoern A. Zeeb }
6619759a996dSBjoern A. Zeeb
6620759a996dSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
6621759a996dSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX)
6622bd206a6fSBjoern A. Zeeb printf("TRACE-RX: %s: handled frame type %#0x\n", __func__, ok);
6623759a996dSBjoern A. Zeeb #endif
6624759a996dSBjoern A. Zeeb }
6625759a996dSBjoern A. Zeeb
6626759a996dSBjoern A. Zeeb static void
6627759a996dSBjoern A. Zeeb lkpi_80211_lhw_rxq_task(void *ctx, int pending)
6628759a996dSBjoern A. Zeeb {
6629759a996dSBjoern A. Zeeb struct lkpi_hw *lhw;
6630759a996dSBjoern A. Zeeb struct mbufq mq;
6631759a996dSBjoern A. Zeeb struct mbuf *m;
6632759a996dSBjoern A. Zeeb
6633759a996dSBjoern A. Zeeb lhw = ctx;
6634759a996dSBjoern A. Zeeb
6635759a996dSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
6636759a996dSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX)
6637bd206a6fSBjoern A. Zeeb printf("TRACE-RX: %s: lhw %p pending %d mbuf_qlen %d\n",
6638bd206a6fSBjoern A. Zeeb __func__, lhw, pending, mbufq_len(&lhw->rxq));
6639759a996dSBjoern A. Zeeb #endif
6640759a996dSBjoern A. Zeeb
6641759a996dSBjoern A. Zeeb mbufq_init(&mq, IFQ_MAXLEN);
6642759a996dSBjoern A. Zeeb
6643759a996dSBjoern A. Zeeb LKPI_80211_LHW_RXQ_LOCK(lhw);
6644759a996dSBjoern A. Zeeb mbufq_concat(&mq, &lhw->rxq);
6645759a996dSBjoern A. Zeeb LKPI_80211_LHW_RXQ_UNLOCK(lhw);
6646759a996dSBjoern A. Zeeb
6647759a996dSBjoern A. Zeeb m = mbufq_dequeue(&mq);
6648759a996dSBjoern A. Zeeb while (m != NULL) {
6649759a996dSBjoern A. Zeeb lkpi_80211_lhw_rxq_rx_one(lhw, m);
6650759a996dSBjoern A. Zeeb m = mbufq_dequeue(&mq);
6651759a996dSBjoern A. Zeeb }
6652759a996dSBjoern A. Zeeb }
6653759a996dSBjoern A. Zeeb
665449010ba7SBjoern A. Zeeb static void
6655a1adefb1SBjoern A. Zeeb lkpi_convert_rx_status(struct ieee80211_hw *hw, struct lkpi_sta *lsta,
665649010ba7SBjoern A. Zeeb struct ieee80211_rx_status *rx_status,
665749010ba7SBjoern A. Zeeb struct ieee80211_rx_stats *rx_stats,
665849010ba7SBjoern A. Zeeb uint8_t *rssip)
665949010ba7SBjoern A. Zeeb {
666049010ba7SBjoern A. Zeeb struct ieee80211_supported_band *supband;
6661a1adefb1SBjoern A. Zeeb struct rate_info rxrate;
666249010ba7SBjoern A. Zeeb int i;
666349010ba7SBjoern A. Zeeb uint8_t rssi;
666449010ba7SBjoern A. Zeeb
6665a1adefb1SBjoern A. Zeeb memset(&rxrate, 0, sizeof(rxrate));
666649010ba7SBjoern A. Zeeb memset(rx_stats, 0, sizeof(*rx_stats));
666749010ba7SBjoern A. Zeeb rx_stats->r_flags = IEEE80211_R_NF | IEEE80211_R_RSSI;
666849010ba7SBjoern A. Zeeb /* XXX-BZ correct hardcoded noise floor, survey data? */
666949010ba7SBjoern A. Zeeb rx_stats->c_nf = -96;
667049010ba7SBjoern A. Zeeb if (ieee80211_hw_check(hw, SIGNAL_DBM) &&
667149010ba7SBjoern A. Zeeb !(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
667249010ba7SBjoern A. Zeeb rssi = rx_status->signal;
667349010ba7SBjoern A. Zeeb else
667449010ba7SBjoern A. Zeeb rssi = rx_stats->c_nf;
667549010ba7SBjoern A. Zeeb /*
667649010ba7SBjoern A. Zeeb * net80211 signal strength data are in .5 dBm units relative to
667749010ba7SBjoern A. Zeeb * the current noise floor (see comment in ieee80211_node.h).
667849010ba7SBjoern A. Zeeb */
667949010ba7SBjoern A. Zeeb rssi -= rx_stats->c_nf;
668049010ba7SBjoern A. Zeeb if (rssip != NULL)
668149010ba7SBjoern A. Zeeb *rssip = rssi;
668249010ba7SBjoern A. Zeeb rx_stats->c_rssi = rssi * 2;
668349010ba7SBjoern A. Zeeb rx_stats->r_flags |= IEEE80211_R_BAND;
668449010ba7SBjoern A. Zeeb rx_stats->c_band =
668549010ba7SBjoern A. Zeeb lkpi_nl80211_band_to_net80211_band(rx_status->band);
668649010ba7SBjoern A. Zeeb rx_stats->r_flags |= IEEE80211_R_FREQ | IEEE80211_R_IEEE;
668749010ba7SBjoern A. Zeeb rx_stats->c_freq = rx_status->freq;
668849010ba7SBjoern A. Zeeb rx_stats->c_ieee = ieee80211_mhz2ieee(rx_stats->c_freq, rx_stats->c_band);
668949010ba7SBjoern A. Zeeb
669049010ba7SBjoern A. Zeeb rx_stats->c_rx_tsf = rx_status->mactime;
669149010ba7SBjoern A. Zeeb
669249010ba7SBjoern A. Zeeb /* XXX RX_FLAG_MACTIME_IS_RTAP_TS64 ? */
669349010ba7SBjoern A. Zeeb if ((rx_status->flag & RX_FLAG_MACTIME) ==
669449010ba7SBjoern A. Zeeb (RX_FLAG_MACTIME_START|RX_FLAG_MACTIME_END)) {
669549010ba7SBjoern A. Zeeb rx_stats->r_flags |= IEEE80211_R_TSF64;
669649010ba7SBjoern A. Zeeb /* XXX RX_FLAG_MACTIME_PLCP_START ? */
669749010ba7SBjoern A. Zeeb if ((rx_status->flag & RX_FLAG_MACTIME) == RX_FLAG_MACTIME_START)
669849010ba7SBjoern A. Zeeb rx_stats->r_flags |= IEEE80211_R_TSF_START;
669949010ba7SBjoern A. Zeeb if ((rx_status->flag & RX_FLAG_MACTIME) == RX_FLAG_MACTIME_END)
670049010ba7SBjoern A. Zeeb rx_stats->r_flags |= IEEE80211_R_TSF_END;
670149010ba7SBjoern A. Zeeb /* XXX-BZ if TSF_END will net80211 do the unwind of time? */
670249010ba7SBjoern A. Zeeb }
670349010ba7SBjoern A. Zeeb
670449010ba7SBjoern A. Zeeb if (rx_status->chains != 0) {
670549010ba7SBjoern A. Zeeb int cc;
670649010ba7SBjoern A. Zeeb int8_t crssi;
670749010ba7SBjoern A. Zeeb
670849010ba7SBjoern A. Zeeb rx_stats->c_chain = rx_status->chains;
670949010ba7SBjoern A. Zeeb rx_stats->r_flags |= IEEE80211_R_C_CHAIN;
671049010ba7SBjoern A. Zeeb
671149010ba7SBjoern A. Zeeb cc = 0;
671249010ba7SBjoern A. Zeeb for (i = 0; i < nitems(rx_status->chain_signal); i++) {
671349010ba7SBjoern A. Zeeb if (!(rx_status->chains & BIT(i)))
671449010ba7SBjoern A. Zeeb continue;
671549010ba7SBjoern A. Zeeb crssi = rx_status->chain_signal[i];
671649010ba7SBjoern A. Zeeb crssi -= rx_stats->c_nf;
671749010ba7SBjoern A. Zeeb rx_stats->c_rssi_ctl[i] = crssi * 2;
671849010ba7SBjoern A. Zeeb rx_stats->c_rssi_ext[i] = crssi * 2; /* XXX _ext ??? ATH thing? */
671949010ba7SBjoern A. Zeeb /* We currently only have the global noise floor value. */
672049010ba7SBjoern A. Zeeb rx_stats->c_nf_ctl[i] = rx_stats->c_nf;
672149010ba7SBjoern A. Zeeb rx_stats->c_nf_ext[i] = rx_stats->c_nf;
672249010ba7SBjoern A. Zeeb cc++;
672349010ba7SBjoern A. Zeeb }
672449010ba7SBjoern A. Zeeb if (cc > 0)
672549010ba7SBjoern A. Zeeb rx_stats->r_flags |= (IEEE80211_R_C_NF | IEEE80211_R_C_RSSI);
672649010ba7SBjoern A. Zeeb }
672749010ba7SBjoern A. Zeeb
672849010ba7SBjoern A. Zeeb /* XXX-NET80211 We are not going to populate c_phytype! */
672949010ba7SBjoern A. Zeeb
673049010ba7SBjoern A. Zeeb switch (rx_status->encoding) {
673149010ba7SBjoern A. Zeeb case RX_ENC_LEGACY:
6732a1adefb1SBjoern A. Zeeb {
6733a1adefb1SBjoern A. Zeeb uint32_t legacy = 0;
6734a1adefb1SBjoern A. Zeeb
673549010ba7SBjoern A. Zeeb supband = hw->wiphy->bands[rx_status->band];
673649010ba7SBjoern A. Zeeb if (supband != NULL)
6737a1adefb1SBjoern A. Zeeb legacy = supband->bitrates[rx_status->rate_idx].bitrate;
6738a1adefb1SBjoern A. Zeeb rx_stats->c_rate = legacy;
6739a1adefb1SBjoern A. Zeeb rxrate.legacy = legacy;
674049010ba7SBjoern A. Zeeb /* Is there a LinuxKPI way of reporting IEEE80211_RX_F_CCK / _OFDM? */
674149010ba7SBjoern A. Zeeb break;
6742a1adefb1SBjoern A. Zeeb }
674349010ba7SBjoern A. Zeeb case RX_ENC_HT:
674449010ba7SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_HT;
674549010ba7SBjoern A. Zeeb rx_stats->c_rate = rx_status->rate_idx; /* mcs */
6746a1adefb1SBjoern A. Zeeb rxrate.flags |= RATE_INFO_FLAGS_MCS;
6747a1adefb1SBjoern A. Zeeb rxrate.mcs = rx_status->rate_idx;
6748a1adefb1SBjoern A. Zeeb if ((rx_status->enc_flags & RX_ENC_FLAG_SHORT_GI) != 0) {
6749a1adefb1SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_SHORTGI;
6750a1adefb1SBjoern A. Zeeb rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
6751a1adefb1SBjoern A. Zeeb }
675249010ba7SBjoern A. Zeeb break;
675349010ba7SBjoern A. Zeeb case RX_ENC_VHT:
675449010ba7SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_VHT;
675549010ba7SBjoern A. Zeeb rx_stats->c_rate = rx_status->rate_idx; /* mcs */
675649010ba7SBjoern A. Zeeb rx_stats->c_vhtnss = rx_status->nss;
6757a1adefb1SBjoern A. Zeeb rxrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
6758a1adefb1SBjoern A. Zeeb rxrate.mcs = rx_status->rate_idx;
6759a1adefb1SBjoern A. Zeeb rxrate.nss = rx_status->nss;
6760a1adefb1SBjoern A. Zeeb if ((rx_status->enc_flags & RX_ENC_FLAG_SHORT_GI) != 0) {
6761a1adefb1SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_SHORTGI;
6762a1adefb1SBjoern A. Zeeb rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
6763a1adefb1SBjoern A. Zeeb }
676449010ba7SBjoern A. Zeeb break;
676549010ba7SBjoern A. Zeeb case RX_ENC_HE:
6766a1adefb1SBjoern A. Zeeb rxrate.flags |= RATE_INFO_FLAGS_HE_MCS;
6767a1adefb1SBjoern A. Zeeb rxrate.mcs = rx_status->rate_idx;
6768a1adefb1SBjoern A. Zeeb rxrate.nss = rx_status->nss;
6769a1adefb1SBjoern A. Zeeb /* XXX TODO */
6770a1adefb1SBjoern A. Zeeb TODO("net80211 has not matching encoding for %u", rx_status->encoding);
6771a1adefb1SBjoern A. Zeeb break;
677249010ba7SBjoern A. Zeeb case RX_ENC_EHT:
6773a1adefb1SBjoern A. Zeeb rxrate.flags |= RATE_INFO_FLAGS_EHT_MCS;
6774a1adefb1SBjoern A. Zeeb rxrate.mcs = rx_status->rate_idx;
6775a1adefb1SBjoern A. Zeeb rxrate.nss = rx_status->nss;
6776a1adefb1SBjoern A. Zeeb /* XXX TODO */
677749010ba7SBjoern A. Zeeb TODO("net80211 has not matching encoding for %u", rx_status->encoding);
677849010ba7SBjoern A. Zeeb break;
677949010ba7SBjoern A. Zeeb }
678049010ba7SBjoern A. Zeeb
6781a1adefb1SBjoern A. Zeeb rxrate.bw = rx_status->bw;
678249010ba7SBjoern A. Zeeb switch (rx_status->bw) {
678349010ba7SBjoern A. Zeeb case RATE_INFO_BW_20:
678449010ba7SBjoern A. Zeeb rx_stats->c_width = IEEE80211_RX_FW_20MHZ;
678549010ba7SBjoern A. Zeeb break;
678649010ba7SBjoern A. Zeeb case RATE_INFO_BW_40:
678749010ba7SBjoern A. Zeeb rx_stats->c_width = IEEE80211_RX_FW_40MHZ;
678849010ba7SBjoern A. Zeeb break;
678949010ba7SBjoern A. Zeeb case RATE_INFO_BW_80:
679049010ba7SBjoern A. Zeeb rx_stats->c_width = IEEE80211_RX_FW_80MHZ;
679149010ba7SBjoern A. Zeeb break;
679249010ba7SBjoern A. Zeeb case RATE_INFO_BW_160:
679349010ba7SBjoern A. Zeeb rx_stats->c_width = IEEE80211_RX_FW_160MHZ;
679449010ba7SBjoern A. Zeeb break;
679549010ba7SBjoern A. Zeeb case RATE_INFO_BW_320:
679649010ba7SBjoern A. Zeeb case RATE_INFO_BW_HE_RU:
679749010ba7SBjoern A. Zeeb case RATE_INFO_BW_EHT_RU:
679849010ba7SBjoern A. Zeeb case RATE_INFO_BW_5:
679949010ba7SBjoern A. Zeeb case RATE_INFO_BW_10:
680049010ba7SBjoern A. Zeeb TODO("net80211 has not matching bandwidth for %u", rx_status->bw);
680149010ba7SBjoern A. Zeeb break;
680249010ba7SBjoern A. Zeeb }
680349010ba7SBjoern A. Zeeb
680449010ba7SBjoern A. Zeeb if ((rx_status->enc_flags & RX_ENC_FLAG_LDPC) != 0)
680549010ba7SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_LDPC;
680649010ba7SBjoern A. Zeeb if ((rx_status->enc_flags & RX_ENC_FLAG_STBC_MASK) != 0)
680749010ba7SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_STBC;
680849010ba7SBjoern A. Zeeb
680949010ba7SBjoern A. Zeeb /*
681049010ba7SBjoern A. Zeeb * We only need these for LKPI_80211_HW_CRYPTO in theory but in
681149010ba7SBjoern A. Zeeb * case the hardware does something we do not expect always leave
681249010ba7SBjoern A. Zeeb * these enabled. Leaving this commant as documentation for the || 1.
681349010ba7SBjoern A. Zeeb */
681449010ba7SBjoern A. Zeeb #if defined(LKPI_80211_HW_CRYPTO) || 1
681549010ba7SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_DECRYPTED) {
681649010ba7SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_DECRYPTED;
681749010ba7SBjoern A. Zeeb /* Only valid if decrypted is set. */
681849010ba7SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_PN_VALIDATED)
681949010ba7SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_PN_VALIDATED;
682049010ba7SBjoern A. Zeeb }
6821731ff400SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_IV_STRIPPED)
6822731ff400SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_IV_STRIP;
6823731ff400SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_ICV_STRIPPED)
6824731ff400SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_ICV_STRIP;
6825731ff400SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_MIC_STRIPPED)
6826731ff400SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_MIC_STRIP;
682749010ba7SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_MMIC_STRIPPED)
682849010ba7SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_MMIC_STRIP;
6829394a9a5bSBjoern A. Zeeb if (rx_status->flag & RX_FLAG_MMIC_ERROR)
6830394a9a5bSBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_FAIL_MMIC;
683149010ba7SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_FAILED_FCS_CRC)
683249010ba7SBjoern A. Zeeb rx_stats->c_pktflags |= IEEE80211_RX_F_FAIL_FCSCRC;
683349010ba7SBjoern A. Zeeb #endif
6834a1adefb1SBjoern A. Zeeb
6835a1adefb1SBjoern A. Zeeb if (lsta != NULL) {
6836a1adefb1SBjoern A. Zeeb memcpy(&lsta->sinfo.rxrate, &rxrate, sizeof(rxrate));
6837a1adefb1SBjoern A. Zeeb lsta->sinfo.filled |= BIT_ULL(NL80211_STA_INFO_RX_BITRATE);
6838a1adefb1SBjoern A. Zeeb }
683949010ba7SBjoern A. Zeeb }
684049010ba7SBjoern A. Zeeb
6841e30e05d3SBjoern A. Zeeb /* For %list see comment towards the end of the function. */
68426b4cac81SBjoern A. Zeeb void
68436b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
6844e30e05d3SBjoern A. Zeeb struct ieee80211_sta *sta, struct napi_struct *napi __unused,
6845e30e05d3SBjoern A. Zeeb struct list_head *list __unused)
68466b4cac81SBjoern A. Zeeb {
68476b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
68486b4cac81SBjoern A. Zeeb struct ieee80211com *ic;
68496b4cac81SBjoern A. Zeeb struct mbuf *m;
68506b4cac81SBjoern A. Zeeb struct skb_shared_info *shinfo;
68516b4cac81SBjoern A. Zeeb struct ieee80211_rx_status *rx_status;
68526b4cac81SBjoern A. Zeeb struct ieee80211_rx_stats rx_stats;
68536b4cac81SBjoern A. Zeeb struct ieee80211_node *ni;
68546b4cac81SBjoern A. Zeeb struct ieee80211vap *vap;
68556b4cac81SBjoern A. Zeeb struct ieee80211_hdr *hdr;
68566b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta;
6857c816f64eSBjoern A. Zeeb int i, offset, ok, error;
685849010ba7SBjoern A. Zeeb uint8_t rssi;
6859c0cadd99SBjoern A. Zeeb bool is_beacon;
68606b4cac81SBjoern A. Zeeb
6861c013f810SBjoern A. Zeeb lhw = HW_TO_LHW(hw);
6862c013f810SBjoern A. Zeeb ic = lhw->ic;
6863c013f810SBjoern A. Zeeb
68646b4cac81SBjoern A. Zeeb if (skb->len < 2) {
68656b4cac81SBjoern A. Zeeb /* Need 80211 stats here. */
6866c013f810SBjoern A. Zeeb counter_u64_add(ic->ic_ierrors, 1);
68676b4cac81SBjoern A. Zeeb IMPROVE();
68686b4cac81SBjoern A. Zeeb goto err;
68696b4cac81SBjoern A. Zeeb }
68706b4cac81SBjoern A. Zeeb
68716b4cac81SBjoern A. Zeeb /*
68726b4cac81SBjoern A. Zeeb * For now do the data copy; we can later improve things. Might even
68736b4cac81SBjoern A. Zeeb * have an mbuf backing the skb data then?
68746b4cac81SBjoern A. Zeeb */
687502382a0aSBjoern A. Zeeb m = m_get3(skb->len, M_NOWAIT, MT_DATA, M_PKTHDR);
6876c013f810SBjoern A. Zeeb if (m == NULL) {
6877c013f810SBjoern A. Zeeb counter_u64_add(ic->ic_ierrors, 1);
68786b4cac81SBjoern A. Zeeb goto err;
6879c013f810SBjoern A. Zeeb }
68806b4cac81SBjoern A. Zeeb m_copyback(m, 0, skb->tail - skb->data, skb->data);
68816b4cac81SBjoern A. Zeeb
68826b4cac81SBjoern A. Zeeb shinfo = skb_shinfo(skb);
68836b4cac81SBjoern A. Zeeb offset = m->m_len;
68846b4cac81SBjoern A. Zeeb for (i = 0; i < shinfo->nr_frags; i++) {
68856b4cac81SBjoern A. Zeeb m_copyback(m, offset, shinfo->frags[i].size,
68866b4cac81SBjoern A. Zeeb (uint8_t *)linux_page_address(shinfo->frags[i].page) +
68876b4cac81SBjoern A. Zeeb shinfo->frags[i].offset);
68886b4cac81SBjoern A. Zeeb offset += shinfo->frags[i].size;
68896b4cac81SBjoern A. Zeeb }
68906b4cac81SBjoern A. Zeeb
68916b4cac81SBjoern A. Zeeb rx_status = IEEE80211_SKB_RXCB(skb);
68926b4cac81SBjoern A. Zeeb
68936b4cac81SBjoern A. Zeeb hdr = (void *)skb->data;
6894c0cadd99SBjoern A. Zeeb is_beacon = ieee80211_is_beacon(hdr->frame_control);
6895c0cadd99SBjoern A. Zeeb
6896c0cadd99SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
68979d9ba2b7SBjoern A. Zeeb if (is_beacon && (linuxkpi_debug_80211 & D80211_TRACE_RX_BEACONS) == 0)
68986b4cac81SBjoern A. Zeeb goto no_trace_beacons;
68996b4cac81SBjoern A. Zeeb
69009d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX)
690173e3969fSBjoern A. Zeeb printf("TRACE-RX: %s: skb %p l/d/t-len (%u/%u/%u) "
6902c0cadd99SBjoern A. Zeeb "h %p d %p t %p e %p sh %p (%u) m %p plen %u len %u%s\n",
690373e3969fSBjoern A. Zeeb __func__, skb, skb->len, skb->data_len,
69046b4cac81SBjoern A. Zeeb skb->truesize, skb->head, skb->data, skb->tail, skb->end,
69056b4cac81SBjoern A. Zeeb shinfo, shinfo->nr_frags,
6906c0cadd99SBjoern A. Zeeb m, m->m_pkthdr.len, m->m_len, is_beacon ? " beacon" : "");
69076b4cac81SBjoern A. Zeeb
69089d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX_DUMP)
69096b4cac81SBjoern A. Zeeb hexdump(mtod(m, const void *), m->m_len, "RX (raw) ", 0);
69106b4cac81SBjoern A. Zeeb
69116b4cac81SBjoern A. Zeeb /* Implement a dump_rxcb() !!! */
69129d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX)
6913f1aeb5d8SBjoern A. Zeeb printf("TRACE-RX: %s: RXCB: %ju %ju %u, %b, %u, %#0x, %#0x, "
691460970a32SBjoern A. Zeeb "%u band %u, %u { %d %d %d %d }, %d, %#x %#x %#x %#x %u %u %u\n",
69156b4cac81SBjoern A. Zeeb __func__,
6916c8dafefaSBjoern A. Zeeb (uintmax_t)rx_status->boottime_ns,
6917c8dafefaSBjoern A. Zeeb (uintmax_t)rx_status->mactime,
69186b4cac81SBjoern A. Zeeb rx_status->device_timestamp,
6919f1aeb5d8SBjoern A. Zeeb rx_status->flag, IEEE80211_RX_STATUS_FLAGS_BITS,
69206b4cac81SBjoern A. Zeeb rx_status->freq,
69216b4cac81SBjoern A. Zeeb rx_status->bw,
69226b4cac81SBjoern A. Zeeb rx_status->encoding,
69236b4cac81SBjoern A. Zeeb rx_status->ampdu_reference,
69246b4cac81SBjoern A. Zeeb rx_status->band,
69256b4cac81SBjoern A. Zeeb rx_status->chains,
69266b4cac81SBjoern A. Zeeb rx_status->chain_signal[0],
69276b4cac81SBjoern A. Zeeb rx_status->chain_signal[1],
69286b4cac81SBjoern A. Zeeb rx_status->chain_signal[2],
692960970a32SBjoern A. Zeeb rx_status->chain_signal[3],
69306b4cac81SBjoern A. Zeeb rx_status->signal,
69316b4cac81SBjoern A. Zeeb rx_status->enc_flags,
69326b4cac81SBjoern A. Zeeb rx_status->he_dcm,
69336b4cac81SBjoern A. Zeeb rx_status->he_gi,
69346b4cac81SBjoern A. Zeeb rx_status->he_ru,
69356b4cac81SBjoern A. Zeeb rx_status->zero_length_psdu_type,
69366b4cac81SBjoern A. Zeeb rx_status->nss,
69376b4cac81SBjoern A. Zeeb rx_status->rate_idx);
69386b4cac81SBjoern A. Zeeb no_trace_beacons:
69396b4cac81SBjoern A. Zeeb #endif
69406b4cac81SBjoern A. Zeeb
694158246901SBjoern A. Zeeb lsta = NULL;
69426b4cac81SBjoern A. Zeeb if (sta != NULL) {
69436b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta);
69446b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(lsta->ni);
69456b4cac81SBjoern A. Zeeb } else {
6946c8dafefaSBjoern A. Zeeb struct ieee80211_frame_min *wh;
6947c8dafefaSBjoern A. Zeeb
69486b4cac81SBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame_min *);
69496b4cac81SBjoern A. Zeeb ni = ieee80211_find_rxnode(ic, wh);
69506b4cac81SBjoern A. Zeeb if (ni != NULL)
69516b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data;
69526b4cac81SBjoern A. Zeeb }
69536b4cac81SBjoern A. Zeeb
6954a1adefb1SBjoern A. Zeeb rssi = 0;
6955a1adefb1SBjoern A. Zeeb lkpi_convert_rx_status(hw, lsta, rx_status, &rx_stats, &rssi);
6956a1adefb1SBjoern A. Zeeb
6957a1adefb1SBjoern A. Zeeb ok = ieee80211_add_rx_params(m, &rx_stats);
6958a1adefb1SBjoern A. Zeeb if (ok == 0) {
6959a1adefb1SBjoern A. Zeeb m_freem(m);
6960a1adefb1SBjoern A. Zeeb counter_u64_add(ic->ic_ierrors, 1);
6961a1adefb1SBjoern A. Zeeb goto err;
6962a1adefb1SBjoern A. Zeeb }
6963a1adefb1SBjoern A. Zeeb
69646b4cac81SBjoern A. Zeeb if (ni != NULL)
69656b4cac81SBjoern A. Zeeb vap = ni->ni_vap;
69666b4cac81SBjoern A. Zeeb else
69676b4cac81SBjoern A. Zeeb /*
69686b4cac81SBjoern A. Zeeb * XXX-BZ can we improve this by looking at the frame hdr
69696b4cac81SBjoern A. Zeeb * or other meta-data passed up?
69706b4cac81SBjoern A. Zeeb */
69716b4cac81SBjoern A. Zeeb vap = TAILQ_FIRST(&ic->ic_vaps);
69726b4cac81SBjoern A. Zeeb
69739d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
69749d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX)
6975bd206a6fSBjoern A. Zeeb printf("TRACE-RX: %s: sta %p lsta %p state %d ni %p vap %p%s\n",
6976c0cadd99SBjoern A. Zeeb __func__, sta, lsta, (lsta != NULL) ? lsta->state : -1,
6977c0cadd99SBjoern A. Zeeb ni, vap, is_beacon ? " beacon" : "");
69789d9ba2b7SBjoern A. Zeeb #endif
69796b4cac81SBjoern A. Zeeb
6980c0cadd99SBjoern A. Zeeb if (ni != NULL && vap != NULL && is_beacon &&
6981c8dafefaSBjoern A. Zeeb rx_status->device_timestamp > 0 &&
6982c8dafefaSBjoern A. Zeeb m->m_pkthdr.len >= sizeof(struct ieee80211_frame)) {
6983c8dafefaSBjoern A. Zeeb struct lkpi_vif *lvif;
6984c8dafefaSBjoern A. Zeeb struct ieee80211_vif *vif;
6985c8dafefaSBjoern A. Zeeb struct ieee80211_frame *wh;
6986c8dafefaSBjoern A. Zeeb
6987c8dafefaSBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame *);
6988c8dafefaSBjoern A. Zeeb if (!IEEE80211_ADDR_EQ(wh->i_addr2, ni->ni_bssid))
6989c8dafefaSBjoern A. Zeeb goto skip_device_ts;
6990c8dafefaSBjoern A. Zeeb
6991c8dafefaSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap);
6992c8dafefaSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
6993c8dafefaSBjoern A. Zeeb
6994c8dafefaSBjoern A. Zeeb IMPROVE("TIMING_BEACON_ONLY?");
6995c8dafefaSBjoern A. Zeeb /* mac80211 specific (not net80211) so keep it here. */
6996c8dafefaSBjoern A. Zeeb vif->bss_conf.sync_device_ts = rx_status->device_timestamp;
6997c8dafefaSBjoern A. Zeeb /*
6998c8dafefaSBjoern A. Zeeb * net80211 should take care of the other information (sync_tsf,
6999c8dafefaSBjoern A. Zeeb * sync_dtim_count) as otherwise we need to parse the beacon.
7000c8dafefaSBjoern A. Zeeb */
7001c8dafefaSBjoern A. Zeeb skip_device_ts:
70029fb91463SBjoern A. Zeeb ;
70039fb91463SBjoern A. Zeeb }
7004c8dafefaSBjoern A. Zeeb
70056b4cac81SBjoern A. Zeeb if (vap != NULL && vap->iv_state > IEEE80211_S_INIT &&
70066b4cac81SBjoern A. Zeeb ieee80211_radiotap_active_vap(vap)) {
70076b4cac81SBjoern A. Zeeb struct lkpi_radiotap_rx_hdr *rtap;
70086b4cac81SBjoern A. Zeeb
70096b4cac81SBjoern A. Zeeb rtap = &lhw->rtap_rx;
70106b4cac81SBjoern A. Zeeb rtap->wr_tsft = rx_status->device_timestamp;
70116b4cac81SBjoern A. Zeeb rtap->wr_flags = 0;
70126b4cac81SBjoern A. Zeeb if (rx_status->enc_flags & RX_ENC_FLAG_SHORTPRE)
70136b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
70146b4cac81SBjoern A. Zeeb if (rx_status->enc_flags & RX_ENC_FLAG_SHORT_GI)
70156b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTGI;
70166b4cac81SBjoern A. Zeeb #if 0 /* .. or it does not given we strip it below. */
70176b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, RX_INCLUDES_FCS))
70186b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_FCS;
70196b4cac81SBjoern A. Zeeb #endif
70206b4cac81SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_FAILED_FCS_CRC)
70216b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_BADFCS;
70226b4cac81SBjoern A. Zeeb rtap->wr_rate = 0;
70236b4cac81SBjoern A. Zeeb IMPROVE();
70246b4cac81SBjoern A. Zeeb /* XXX TODO status->encoding / rate_index / bw */
70256b4cac81SBjoern A. Zeeb rtap->wr_chan_freq = htole16(rx_stats.c_freq);
70266b4cac81SBjoern A. Zeeb if (ic->ic_curchan->ic_ieee == rx_stats.c_ieee)
70276b4cac81SBjoern A. Zeeb rtap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags);
7028170acccfSBjoern A. Zeeb rtap->wr_dbm_antsignal = rssi;
70296b4cac81SBjoern A. Zeeb rtap->wr_dbm_antnoise = rx_stats.c_nf;
70306b4cac81SBjoern A. Zeeb }
70316b4cac81SBjoern A. Zeeb
70326b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, RX_INCLUDES_FCS))
70336b4cac81SBjoern A. Zeeb m_adj(m, -IEEE80211_CRC_LEN);
70346b4cac81SBjoern A. Zeeb
7035e30e05d3SBjoern A. Zeeb #if 0
7036e30e05d3SBjoern A. Zeeb if (list != NULL) {
7037e30e05d3SBjoern A. Zeeb /*
7038e30e05d3SBjoern A. Zeeb * Normally this would be queued up and delivered by
7039e30e05d3SBjoern A. Zeeb * netif_receive_skb_list(), napi_gro_receive(), or the like.
7040e30e05d3SBjoern A. Zeeb * See mt76::mac80211.c as only current possible consumer.
7041e30e05d3SBjoern A. Zeeb */
7042e30e05d3SBjoern A. Zeeb IMPROVE("we simply pass the packet to net80211 to deal with.");
7043e30e05d3SBjoern A. Zeeb }
7044e30e05d3SBjoern A. Zeeb #endif
7045e30e05d3SBjoern A. Zeeb
7046c013f810SBjoern A. Zeeb /* Attach meta-information to the mbuf for the deferred RX path. */
70476b4cac81SBjoern A. Zeeb if (ni != NULL) {
7048dbae3dcfSBjoern A. Zeeb #ifdef LKPI_80211_USE_MTAG
7049759a996dSBjoern A. Zeeb struct m_tag *mtag;
7050759a996dSBjoern A. Zeeb struct lkpi_80211_tag_rxni *rxni;
7051759a996dSBjoern A. Zeeb
7052759a996dSBjoern A. Zeeb mtag = m_tag_alloc(MTAG_ABI_LKPI80211, LKPI80211_TAG_RXNI,
7053759a996dSBjoern A. Zeeb sizeof(*rxni), IEEE80211_M_NOWAIT);
7054c013f810SBjoern A. Zeeb if (mtag == NULL) {
7055c013f810SBjoern A. Zeeb m_freem(m);
7056c013f810SBjoern A. Zeeb counter_u64_add(ic->ic_ierrors, 1);
7057c013f810SBjoern A. Zeeb goto err;
7058c013f810SBjoern A. Zeeb }
7059759a996dSBjoern A. Zeeb rxni = (struct lkpi_80211_tag_rxni *)(mtag + 1);
7060759a996dSBjoern A. Zeeb rxni->ni = ni; /* We hold a reference. */
7061759a996dSBjoern A. Zeeb m_tag_prepend(m, mtag);
7062dbae3dcfSBjoern A. Zeeb #else
7063dbae3dcfSBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = ni; /* We hold a reference. */
7064dbae3dcfSBjoern A. Zeeb #endif
7065759a996dSBjoern A. Zeeb }
70666b4cac81SBjoern A. Zeeb
7067759a996dSBjoern A. Zeeb LKPI_80211_LHW_RXQ_LOCK(lhw);
7068759a996dSBjoern A. Zeeb if (lhw->rxq_stopped) {
7069759a996dSBjoern A. Zeeb LKPI_80211_LHW_RXQ_UNLOCK(lhw);
7070759a996dSBjoern A. Zeeb m_freem(m);
7071c013f810SBjoern A. Zeeb counter_u64_add(ic->ic_ierrors, 1);
7072759a996dSBjoern A. Zeeb goto err;
7073759a996dSBjoern A. Zeeb }
7074759a996dSBjoern A. Zeeb
7075c816f64eSBjoern A. Zeeb error = mbufq_enqueue(&lhw->rxq, m);
7076c816f64eSBjoern A. Zeeb if (error != 0) {
7077c816f64eSBjoern A. Zeeb LKPI_80211_LHW_RXQ_UNLOCK(lhw);
7078c816f64eSBjoern A. Zeeb m_freem(m);
7079c816f64eSBjoern A. Zeeb counter_u64_add(ic->ic_ierrors, 1);
7080c816f64eSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
7081c816f64eSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX)
7082c816f64eSBjoern A. Zeeb ic_printf(ni->ni_ic, "%s: mbufq_enqueue failed: %d\n",
7083c816f64eSBjoern A. Zeeb __func__, error);
7084c816f64eSBjoern A. Zeeb #endif
7085c816f64eSBjoern A. Zeeb goto err;
7086c816f64eSBjoern A. Zeeb }
7087759a996dSBjoern A. Zeeb taskqueue_enqueue(taskqueue_thread, &lhw->rxq_task);
7088759a996dSBjoern A. Zeeb LKPI_80211_LHW_RXQ_UNLOCK(lhw);
70896b4cac81SBjoern A. Zeeb
70906b4cac81SBjoern A. Zeeb IMPROVE();
70916b4cac81SBjoern A. Zeeb
70926b4cac81SBjoern A. Zeeb err:
70936b4cac81SBjoern A. Zeeb /* The skb is ours so we can free it :-) */
70946b4cac81SBjoern A. Zeeb kfree_skb(skb);
70956b4cac81SBjoern A. Zeeb }
70966b4cac81SBjoern A. Zeeb
70976b4cac81SBjoern A. Zeeb uint8_t
7098ec190d91SBjoern A. Zeeb linuxkpi_ieee80211_get_tid(struct ieee80211_hdr *hdr, bool nonqos_ok)
70996b4cac81SBjoern A. Zeeb {
71006b4cac81SBjoern A. Zeeb const struct ieee80211_frame *wh;
7101ec190d91SBjoern A. Zeeb uint8_t tid;
7102ec190d91SBjoern A. Zeeb
7103ec190d91SBjoern A. Zeeb /* Linux seems to assume this is a QOS-Data-Frame */
7104ec190d91SBjoern A. Zeeb KASSERT(nonqos_ok || ieee80211_is_data_qos(hdr->frame_control),
7105ec190d91SBjoern A. Zeeb ("%s: hdr %p fc %#06x not qos_data\n", __func__, hdr,
7106ec190d91SBjoern A. Zeeb hdr->frame_control));
71076b4cac81SBjoern A. Zeeb
71086b4cac81SBjoern A. Zeeb wh = (const struct ieee80211_frame *)hdr;
7109ec190d91SBjoern A. Zeeb tid = ieee80211_gettid(wh);
7110ec190d91SBjoern A. Zeeb KASSERT(nonqos_ok || tid == (tid & IEEE80211_QOS_TID), ("%s: tid %u "
7111ec190d91SBjoern A. Zeeb "not expected (%u?)\n", __func__, tid, IEEE80211_NONQOS_TID));
7112ec190d91SBjoern A. Zeeb
7113ec190d91SBjoern A. Zeeb return (tid);
71146b4cac81SBjoern A. Zeeb }
71156b4cac81SBjoern A. Zeeb
7116ac1d519cSBjoern A. Zeeb /* -------------------------------------------------------------------------- */
7117ac1d519cSBjoern A. Zeeb
7118ac1d519cSBjoern A. Zeeb static void
7119ac1d519cSBjoern A. Zeeb lkpi_wiphy_work(struct work_struct *work)
7120ac1d519cSBjoern A. Zeeb {
7121ac1d519cSBjoern A. Zeeb struct lkpi_wiphy *lwiphy;
7122ac1d519cSBjoern A. Zeeb struct wiphy *wiphy;
7123ac1d519cSBjoern A. Zeeb struct wiphy_work *wk;
7124ac1d519cSBjoern A. Zeeb
7125ac1d519cSBjoern A. Zeeb lwiphy = container_of(work, struct lkpi_wiphy, wwk);
7126ac1d519cSBjoern A. Zeeb wiphy = LWIPHY_TO_WIPHY(lwiphy);
7127ac1d519cSBjoern A. Zeeb
7128ac1d519cSBjoern A. Zeeb wiphy_lock(wiphy);
7129ac1d519cSBjoern A. Zeeb
7130ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_LOCK(lwiphy);
7131ac1d519cSBjoern A. Zeeb wk = list_first_entry_or_null(&lwiphy->wwk_list, struct wiphy_work, entry);
7132ac1d519cSBjoern A. Zeeb /* If there is nothing we do nothing. */
7133ac1d519cSBjoern A. Zeeb if (wk == NULL) {
7134ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_UNLOCK(lwiphy);
7135ac1d519cSBjoern A. Zeeb wiphy_unlock(wiphy);
7136ac1d519cSBjoern A. Zeeb return;
7137ac1d519cSBjoern A. Zeeb }
7138ac1d519cSBjoern A. Zeeb list_del_init(&wk->entry);
7139ac1d519cSBjoern A. Zeeb
7140ac1d519cSBjoern A. Zeeb /* More work to do? */
7141ac1d519cSBjoern A. Zeeb if (!list_empty(&lwiphy->wwk_list))
7142ac1d519cSBjoern A. Zeeb schedule_work(work);
7143ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_UNLOCK(lwiphy);
7144ac1d519cSBjoern A. Zeeb
7145ac1d519cSBjoern A. Zeeb /* Finally call the (*wiphy_work_fn)() function. */
7146ac1d519cSBjoern A. Zeeb wk->fn(wiphy, wk);
7147ac1d519cSBjoern A. Zeeb
7148ac1d519cSBjoern A. Zeeb wiphy_unlock(wiphy);
7149ac1d519cSBjoern A. Zeeb }
7150ac1d519cSBjoern A. Zeeb
7151ac1d519cSBjoern A. Zeeb void
7152ac1d519cSBjoern A. Zeeb linuxkpi_wiphy_work_queue(struct wiphy *wiphy, struct wiphy_work *wwk)
7153ac1d519cSBjoern A. Zeeb {
7154ac1d519cSBjoern A. Zeeb struct lkpi_wiphy *lwiphy;
7155ac1d519cSBjoern A. Zeeb
7156ac1d519cSBjoern A. Zeeb lwiphy = WIPHY_TO_LWIPHY(wiphy);
7157ac1d519cSBjoern A. Zeeb
7158ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_LOCK(lwiphy);
7159ac1d519cSBjoern A. Zeeb /* Do not double-queue. */
7160ac1d519cSBjoern A. Zeeb if (list_empty(&wwk->entry))
7161ac1d519cSBjoern A. Zeeb list_add_tail(&wwk->entry, &lwiphy->wwk_list);
7162ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_UNLOCK(lwiphy);
7163ac1d519cSBjoern A. Zeeb
7164ac1d519cSBjoern A. Zeeb /*
7165ac1d519cSBjoern A. Zeeb * See how ieee80211_queue_work() work continues in Linux or if things
7166ac1d519cSBjoern A. Zeeb * migrate here over time?
7167ac1d519cSBjoern A. Zeeb * Use a system queue from linux/workqueue.h for now.
7168ac1d519cSBjoern A. Zeeb */
7169ac1d519cSBjoern A. Zeeb queue_work(system_wq, &lwiphy->wwk);
7170ac1d519cSBjoern A. Zeeb }
7171ac1d519cSBjoern A. Zeeb
7172ac1d519cSBjoern A. Zeeb void
7173ac1d519cSBjoern A. Zeeb linuxkpi_wiphy_work_cancel(struct wiphy *wiphy, struct wiphy_work *wwk)
7174ac1d519cSBjoern A. Zeeb {
7175ac1d519cSBjoern A. Zeeb struct lkpi_wiphy *lwiphy;
7176ac1d519cSBjoern A. Zeeb
7177ac1d519cSBjoern A. Zeeb lwiphy = WIPHY_TO_LWIPHY(wiphy);
7178ac1d519cSBjoern A. Zeeb
7179ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_LOCK(lwiphy);
7180ac1d519cSBjoern A. Zeeb /* Only cancel if queued. */
7181ac1d519cSBjoern A. Zeeb if (!list_empty(&wwk->entry))
7182ac1d519cSBjoern A. Zeeb list_del_init(&wwk->entry);
7183ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_UNLOCK(lwiphy);
7184ac1d519cSBjoern A. Zeeb }
7185ac1d519cSBjoern A. Zeeb
7186ac1d519cSBjoern A. Zeeb void
7187ac1d519cSBjoern A. Zeeb linuxkpi_wiphy_work_flush(struct wiphy *wiphy, struct wiphy_work *wwk)
7188ac1d519cSBjoern A. Zeeb {
7189ac1d519cSBjoern A. Zeeb struct lkpi_wiphy *lwiphy;
7190ac1d519cSBjoern A. Zeeb struct wiphy_work *wk;
7191ac1d519cSBjoern A. Zeeb
7192ac1d519cSBjoern A. Zeeb lwiphy = WIPHY_TO_LWIPHY(wiphy);
7193ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_LOCK(lwiphy);
7194ac1d519cSBjoern A. Zeeb /* If wwk is unset, flush everything; called when wiphy is shut down. */
7195ac1d519cSBjoern A. Zeeb if (wwk != NULL && list_empty(&wwk->entry)) {
7196ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_UNLOCK(lwiphy);
7197ac1d519cSBjoern A. Zeeb return;
7198ac1d519cSBjoern A. Zeeb }
7199ac1d519cSBjoern A. Zeeb
7200ac1d519cSBjoern A. Zeeb while (!list_empty(&lwiphy->wwk_list)) {
7201ac1d519cSBjoern A. Zeeb
7202ac1d519cSBjoern A. Zeeb wk = list_first_entry(&lwiphy->wwk_list, struct wiphy_work,
7203ac1d519cSBjoern A. Zeeb entry);
7204ac1d519cSBjoern A. Zeeb list_del_init(&wk->entry);
7205ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_UNLOCK(lwiphy);
7206ac1d519cSBjoern A. Zeeb wk->fn(wiphy, wk);
7207ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_LOCK(lwiphy);
7208ac1d519cSBjoern A. Zeeb if (wk == wwk)
7209ac1d519cSBjoern A. Zeeb break;
7210ac1d519cSBjoern A. Zeeb }
7211ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_UNLOCK(lwiphy);
7212ac1d519cSBjoern A. Zeeb }
7213ac1d519cSBjoern A. Zeeb
7214ac1d519cSBjoern A. Zeeb void
7215ac1d519cSBjoern A. Zeeb lkpi_wiphy_delayed_work_timer(struct timer_list *tl)
7216ac1d519cSBjoern A. Zeeb {
7217ac1d519cSBjoern A. Zeeb struct wiphy_delayed_work *wdwk;
7218ac1d519cSBjoern A. Zeeb
7219ac1d519cSBjoern A. Zeeb wdwk = from_timer(wdwk, tl, timer);
7220ac1d519cSBjoern A. Zeeb wiphy_work_queue(wdwk->wiphy, &wdwk->work);
7221ac1d519cSBjoern A. Zeeb }
7222ac1d519cSBjoern A. Zeeb
7223ac1d519cSBjoern A. Zeeb void
7224ac1d519cSBjoern A. Zeeb linuxkpi_wiphy_delayed_work_queue(struct wiphy *wiphy,
7225ac1d519cSBjoern A. Zeeb struct wiphy_delayed_work *wdwk, unsigned long delay)
7226ac1d519cSBjoern A. Zeeb {
7227ac1d519cSBjoern A. Zeeb if (delay == 0) {
7228ac1d519cSBjoern A. Zeeb /* Run right away. */
7229ac1d519cSBjoern A. Zeeb del_timer(&wdwk->timer);
7230ac1d519cSBjoern A. Zeeb wiphy_work_queue(wiphy, &wdwk->work);
7231ac1d519cSBjoern A. Zeeb } else {
7232ac1d519cSBjoern A. Zeeb wdwk->wiphy = wiphy;
7233ac1d519cSBjoern A. Zeeb mod_timer(&wdwk->timer, jiffies + delay);
7234ac1d519cSBjoern A. Zeeb }
7235ac1d519cSBjoern A. Zeeb }
7236ac1d519cSBjoern A. Zeeb
7237ac1d519cSBjoern A. Zeeb void
7238ac1d519cSBjoern A. Zeeb linuxkpi_wiphy_delayed_work_cancel(struct wiphy *wiphy,
7239ac1d519cSBjoern A. Zeeb struct wiphy_delayed_work *wdwk)
7240ac1d519cSBjoern A. Zeeb {
7241ac1d519cSBjoern A. Zeeb del_timer_sync(&wdwk->timer);
7242ac1d519cSBjoern A. Zeeb wiphy_work_cancel(wiphy, &wdwk->work);
7243ac1d519cSBjoern A. Zeeb }
7244ac1d519cSBjoern A. Zeeb
7245ac1d519cSBjoern A. Zeeb /* -------------------------------------------------------------------------- */
7246ac1d519cSBjoern A. Zeeb
72476b4cac81SBjoern A. Zeeb struct wiphy *
72486b4cac81SBjoern A. Zeeb linuxkpi_wiphy_new(const struct cfg80211_ops *ops, size_t priv_len)
72496b4cac81SBjoern A. Zeeb {
72506b4cac81SBjoern A. Zeeb struct lkpi_wiphy *lwiphy;
7251ac1d519cSBjoern A. Zeeb struct wiphy *wiphy;
72526b4cac81SBjoern A. Zeeb
72536b4cac81SBjoern A. Zeeb lwiphy = kzalloc(sizeof(*lwiphy) + priv_len, GFP_KERNEL);
72546b4cac81SBjoern A. Zeeb if (lwiphy == NULL)
72556b4cac81SBjoern A. Zeeb return (NULL);
72566b4cac81SBjoern A. Zeeb lwiphy->ops = ops;
72576b4cac81SBjoern A. Zeeb
7258ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_LOCK_INIT(lwiphy);
7259ac1d519cSBjoern A. Zeeb INIT_LIST_HEAD(&lwiphy->wwk_list);
7260ac1d519cSBjoern A. Zeeb INIT_WORK(&lwiphy->wwk, lkpi_wiphy_work);
7261ac1d519cSBjoern A. Zeeb
7262ac1d519cSBjoern A. Zeeb wiphy = LWIPHY_TO_WIPHY(lwiphy);
7263ac1d519cSBjoern A. Zeeb
7264ac1d519cSBjoern A. Zeeb mutex_init(&wiphy->mtx);
7265ac1d519cSBjoern A. Zeeb TODO();
7266ac1d519cSBjoern A. Zeeb
7267ac1d519cSBjoern A. Zeeb return (wiphy);
72686b4cac81SBjoern A. Zeeb }
72696b4cac81SBjoern A. Zeeb
72706b4cac81SBjoern A. Zeeb void
72716b4cac81SBjoern A. Zeeb linuxkpi_wiphy_free(struct wiphy *wiphy)
72726b4cac81SBjoern A. Zeeb {
72736b4cac81SBjoern A. Zeeb struct lkpi_wiphy *lwiphy;
72746b4cac81SBjoern A. Zeeb
72756b4cac81SBjoern A. Zeeb if (wiphy == NULL)
72766b4cac81SBjoern A. Zeeb return;
72776b4cac81SBjoern A. Zeeb
7278ac1d519cSBjoern A. Zeeb linuxkpi_wiphy_work_flush(wiphy, NULL);
7279ac1d519cSBjoern A. Zeeb mutex_destroy(&wiphy->mtx);
7280ac1d519cSBjoern A. Zeeb
72816b4cac81SBjoern A. Zeeb lwiphy = WIPHY_TO_LWIPHY(wiphy);
7282ac1d519cSBjoern A. Zeeb LKPI_80211_LWIPHY_WORK_LOCK_DESTROY(lwiphy);
7283ac1d519cSBjoern A. Zeeb
72846b4cac81SBjoern A. Zeeb kfree(lwiphy);
72856b4cac81SBjoern A. Zeeb }
72866b4cac81SBjoern A. Zeeb
7287a7c19b8aSBjoern A. Zeeb static uint32_t
7288a7c19b8aSBjoern A. Zeeb lkpi_cfg80211_calculate_bitrate_ht(struct rate_info *rate)
7289a7c19b8aSBjoern A. Zeeb {
7290a7c19b8aSBjoern A. Zeeb TODO("cfg80211_calculate_bitrate_ht");
7291a7c19b8aSBjoern A. Zeeb return (rate->legacy);
7292a7c19b8aSBjoern A. Zeeb }
7293a7c19b8aSBjoern A. Zeeb
7294a7c19b8aSBjoern A. Zeeb static uint32_t
7295a7c19b8aSBjoern A. Zeeb lkpi_cfg80211_calculate_bitrate_vht(struct rate_info *rate)
7296a7c19b8aSBjoern A. Zeeb {
7297a7c19b8aSBjoern A. Zeeb TODO("cfg80211_calculate_bitrate_vht");
7298a7c19b8aSBjoern A. Zeeb return (rate->legacy);
7299a7c19b8aSBjoern A. Zeeb }
7300a7c19b8aSBjoern A. Zeeb
7301a7c19b8aSBjoern A. Zeeb uint32_t
7302a7c19b8aSBjoern A. Zeeb linuxkpi_cfg80211_calculate_bitrate(struct rate_info *rate)
7303a7c19b8aSBjoern A. Zeeb {
7304a7c19b8aSBjoern A. Zeeb
7305a7c19b8aSBjoern A. Zeeb /* Beware: order! */
7306a7c19b8aSBjoern A. Zeeb if (rate->flags & RATE_INFO_FLAGS_MCS)
7307a7c19b8aSBjoern A. Zeeb return (lkpi_cfg80211_calculate_bitrate_ht(rate));
7308a7c19b8aSBjoern A. Zeeb
7309a7c19b8aSBjoern A. Zeeb if (rate->flags & RATE_INFO_FLAGS_VHT_MCS)
7310a7c19b8aSBjoern A. Zeeb return (lkpi_cfg80211_calculate_bitrate_vht(rate));
7311a7c19b8aSBjoern A. Zeeb
7312a7c19b8aSBjoern A. Zeeb IMPROVE("HE/EHT/...");
7313a7c19b8aSBjoern A. Zeeb
7314a7c19b8aSBjoern A. Zeeb return (rate->legacy);
7315a7c19b8aSBjoern A. Zeeb }
7316a7c19b8aSBjoern A. Zeeb
73176b4cac81SBjoern A. Zeeb uint32_t
73186b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_channel_to_frequency(uint32_t channel,
73196b4cac81SBjoern A. Zeeb enum nl80211_band band)
73206b4cac81SBjoern A. Zeeb {
73216b4cac81SBjoern A. Zeeb
73226b4cac81SBjoern A. Zeeb switch (band) {
73236b4cac81SBjoern A. Zeeb case NL80211_BAND_2GHZ:
73246b4cac81SBjoern A. Zeeb return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_2GHZ));
73256b4cac81SBjoern A. Zeeb break;
73266b4cac81SBjoern A. Zeeb case NL80211_BAND_5GHZ:
73276b4cac81SBjoern A. Zeeb return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_5GHZ));
73286b4cac81SBjoern A. Zeeb break;
73296b4cac81SBjoern A. Zeeb default:
73306b4cac81SBjoern A. Zeeb /* XXX abort, retry, error, panic? */
73316b4cac81SBjoern A. Zeeb break;
73326b4cac81SBjoern A. Zeeb }
73336b4cac81SBjoern A. Zeeb
73346b4cac81SBjoern A. Zeeb return (0);
73356b4cac81SBjoern A. Zeeb }
73366b4cac81SBjoern A. Zeeb
73376b4cac81SBjoern A. Zeeb uint32_t
73386b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_frequency_to_channel(uint32_t freq, uint32_t flags __unused)
73396b4cac81SBjoern A. Zeeb {
73406b4cac81SBjoern A. Zeeb
73416b4cac81SBjoern A. Zeeb return (ieee80211_mhz2ieee(freq, 0));
73426b4cac81SBjoern A. Zeeb }
73436b4cac81SBjoern A. Zeeb
7344ac867c20SBjoern A. Zeeb #if 0
73456b4cac81SBjoern A. Zeeb static struct lkpi_sta *
73466b4cac81SBjoern A. Zeeb lkpi_find_lsta_by_ni(struct lkpi_vif *lvif, struct ieee80211_node *ni)
73476b4cac81SBjoern A. Zeeb {
73486b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta, *temp;
73496b4cac81SBjoern A. Zeeb
7350a8f735a6SBjoern A. Zeeb rcu_read_lock();
7351a8f735a6SBjoern A. Zeeb list_for_each_entry_rcu(lsta, &lvif->lsta_list, lsta_list) {
73526b4cac81SBjoern A. Zeeb if (lsta->ni == ni) {
7353a8f735a6SBjoern A. Zeeb rcu_read_unlock();
73546b4cac81SBjoern A. Zeeb return (lsta);
73556b4cac81SBjoern A. Zeeb }
73566b4cac81SBjoern A. Zeeb }
7357a8f735a6SBjoern A. Zeeb rcu_read_unlock();
73586b4cac81SBjoern A. Zeeb
73596b4cac81SBjoern A. Zeeb return (NULL);
73606b4cac81SBjoern A. Zeeb }
7361ac867c20SBjoern A. Zeeb #endif
73626b4cac81SBjoern A. Zeeb
73636b4cac81SBjoern A. Zeeb struct ieee80211_sta *
73646b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_find_sta(struct ieee80211_vif *vif, const u8 *peer)
73656b4cac81SBjoern A. Zeeb {
73666b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
7367a8f735a6SBjoern A. Zeeb struct lkpi_sta *lsta;
73686b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta;
73696b4cac81SBjoern A. Zeeb
73706b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif);
73716b4cac81SBjoern A. Zeeb
7372a8f735a6SBjoern A. Zeeb rcu_read_lock();
7373a8f735a6SBjoern A. Zeeb list_for_each_entry_rcu(lsta, &lvif->lsta_list, lsta_list) {
73746b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta);
73756b4cac81SBjoern A. Zeeb if (IEEE80211_ADDR_EQ(sta->addr, peer)) {
7376a8f735a6SBjoern A. Zeeb rcu_read_unlock();
73776b4cac81SBjoern A. Zeeb return (sta);
73786b4cac81SBjoern A. Zeeb }
73796b4cac81SBjoern A. Zeeb }
7380a8f735a6SBjoern A. Zeeb rcu_read_unlock();
73816b4cac81SBjoern A. Zeeb return (NULL);
73826b4cac81SBjoern A. Zeeb }
73836b4cac81SBjoern A. Zeeb
73846b4cac81SBjoern A. Zeeb struct ieee80211_sta *
73852e183d99SBjoern A. Zeeb linuxkpi_ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw,
73862e183d99SBjoern A. Zeeb const uint8_t *addr, const uint8_t *ourvifaddr)
73876b4cac81SBjoern A. Zeeb {
73886b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
73896b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
73906b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta;
73916b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif;
73926b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta;
73936b4cac81SBjoern A. Zeeb
73946b4cac81SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy);
73956b4cac81SBjoern A. Zeeb sta = NULL;
73966b4cac81SBjoern A. Zeeb
73978891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw);
73986b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) {
73996b4cac81SBjoern A. Zeeb
74006b4cac81SBjoern A. Zeeb /* XXX-BZ check our address from the vif. */
74016b4cac81SBjoern A. Zeeb
74026b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
74036b4cac81SBjoern A. Zeeb if (ourvifaddr != NULL &&
74046b4cac81SBjoern A. Zeeb !IEEE80211_ADDR_EQ(vif->addr, ourvifaddr))
74056b4cac81SBjoern A. Zeeb continue;
74066b4cac81SBjoern A. Zeeb sta = linuxkpi_ieee80211_find_sta(vif, addr);
74076b4cac81SBjoern A. Zeeb if (sta != NULL)
74086b4cac81SBjoern A. Zeeb break;
74096b4cac81SBjoern A. Zeeb }
74108891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw);
74116b4cac81SBjoern A. Zeeb
74126b4cac81SBjoern A. Zeeb if (sta != NULL) {
74136b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta);
74146b4cac81SBjoern A. Zeeb if (!lsta->added_to_drv)
74156b4cac81SBjoern A. Zeeb return (NULL);
74166b4cac81SBjoern A. Zeeb }
74176b4cac81SBjoern A. Zeeb
74186b4cac81SBjoern A. Zeeb return (sta);
74196b4cac81SBjoern A. Zeeb }
74206b4cac81SBjoern A. Zeeb
74216b4cac81SBjoern A. Zeeb struct sk_buff *
74226b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_tx_dequeue(struct ieee80211_hw *hw,
74236b4cac81SBjoern A. Zeeb struct ieee80211_txq *txq)
74246b4cac81SBjoern A. Zeeb {
74256b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq;
74260cbcfa19SBjoern A. Zeeb struct lkpi_vif *lvif;
74276b4cac81SBjoern A. Zeeb struct sk_buff *skb;
74286b4cac81SBjoern A. Zeeb
7429bc24342dSBjoern A. Zeeb IMPROVE("wiphy_lock? or assert?");
74300cbcfa19SBjoern A. Zeeb skb = NULL;
74316b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq);
74326b4cac81SBjoern A. Zeeb ltxq->seen_dequeue = true;
74336b4cac81SBjoern A. Zeeb
74340cbcfa19SBjoern A. Zeeb if (ltxq->stopped)
74350cbcfa19SBjoern A. Zeeb goto stopped;
74360cbcfa19SBjoern A. Zeeb
74370cbcfa19SBjoern A. Zeeb lvif = VIF_TO_LVIF(ltxq->txq.vif);
74380cbcfa19SBjoern A. Zeeb if (lvif->hw_queue_stopped[ltxq->txq.ac]) {
74390cbcfa19SBjoern A. Zeeb ltxq->stopped = true;
74400cbcfa19SBjoern A. Zeeb goto stopped;
74410cbcfa19SBjoern A. Zeeb }
74420cbcfa19SBjoern A. Zeeb
7443eac3646fSBjoern A. Zeeb IMPROVE("hw(TX_FRAG_LIST)");
7444eac3646fSBjoern A. Zeeb
7445eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_LOCK(ltxq);
74466b4cac81SBjoern A. Zeeb skb = skb_dequeue(<xq->skbq);
7447eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_UNLOCK(ltxq);
74486b4cac81SBjoern A. Zeeb
74490cbcfa19SBjoern A. Zeeb stopped:
74506b4cac81SBjoern A. Zeeb return (skb);
74516b4cac81SBjoern A. Zeeb }
74526b4cac81SBjoern A. Zeeb
74536b4cac81SBjoern A. Zeeb void
74546b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_txq_get_depth(struct ieee80211_txq *txq,
745586220d3cSBjoern A. Zeeb unsigned long *frame_cnt, unsigned long *byte_cnt)
74566b4cac81SBjoern A. Zeeb {
74576b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq;
74586b4cac81SBjoern A. Zeeb struct sk_buff *skb;
745986220d3cSBjoern A. Zeeb unsigned long fc, bc;
74606b4cac81SBjoern A. Zeeb
74616b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq);
74626b4cac81SBjoern A. Zeeb
74636b4cac81SBjoern A. Zeeb fc = bc = 0;
7464eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_LOCK(ltxq);
74656b4cac81SBjoern A. Zeeb skb_queue_walk(<xq->skbq, skb) {
74666b4cac81SBjoern A. Zeeb fc++;
74676b4cac81SBjoern A. Zeeb bc += skb->len;
74686b4cac81SBjoern A. Zeeb }
7469eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_UNLOCK(ltxq);
74706b4cac81SBjoern A. Zeeb if (frame_cnt)
74716b4cac81SBjoern A. Zeeb *frame_cnt = fc;
74726b4cac81SBjoern A. Zeeb if (byte_cnt)
74736b4cac81SBjoern A. Zeeb *byte_cnt = bc;
74746b4cac81SBjoern A. Zeeb
74756b4cac81SBjoern A. Zeeb /* Validate that this is doing the correct thing. */
74766b4cac81SBjoern A. Zeeb /* Should we keep track on en/dequeue? */
74776b4cac81SBjoern A. Zeeb IMPROVE();
74786b4cac81SBjoern A. Zeeb }
74796b4cac81SBjoern A. Zeeb
74806b4cac81SBjoern A. Zeeb /*
74816b4cac81SBjoern A. Zeeb * We are called from ieee80211_free_txskb() or ieee80211_tx_status().
74826b4cac81SBjoern A. Zeeb * The latter tries to derive the success status from the info flags
74836b4cac81SBjoern A. Zeeb * passed back from the driver. rawx_mit() saves the ni on the m and the
74846b4cac81SBjoern A. Zeeb * m on the skb for us to be able to give feedback to net80211.
74856b4cac81SBjoern A. Zeeb */
7486a8397571SBjoern A. Zeeb static void
7487a8397571SBjoern A. Zeeb _lkpi_ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb,
74886b4cac81SBjoern A. Zeeb int status)
74896b4cac81SBjoern A. Zeeb {
74906b4cac81SBjoern A. Zeeb struct ieee80211_node *ni;
74916b4cac81SBjoern A. Zeeb struct mbuf *m;
74926b4cac81SBjoern A. Zeeb
74936b4cac81SBjoern A. Zeeb m = skb->m;
74946b4cac81SBjoern A. Zeeb skb->m = NULL;
74956b4cac81SBjoern A. Zeeb
74966b4cac81SBjoern A. Zeeb if (m != NULL) {
74976b4cac81SBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr;
74986b4cac81SBjoern A. Zeeb /* Status: 0 is ok, != 0 is error. */
74996b4cac81SBjoern A. Zeeb ieee80211_tx_complete(ni, m, status);
75006b4cac81SBjoern A. Zeeb /* ni & mbuf were consumed. */
75016b4cac81SBjoern A. Zeeb }
7502a8397571SBjoern A. Zeeb }
75036b4cac81SBjoern A. Zeeb
7504a8397571SBjoern A. Zeeb void
7505a8397571SBjoern A. Zeeb linuxkpi_ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb,
7506a8397571SBjoern A. Zeeb int status)
7507a8397571SBjoern A. Zeeb {
7508a8397571SBjoern A. Zeeb
7509a8397571SBjoern A. Zeeb _lkpi_ieee80211_free_txskb(hw, skb, status);
75106b4cac81SBjoern A. Zeeb kfree_skb(skb);
75116b4cac81SBjoern A. Zeeb }
75126b4cac81SBjoern A. Zeeb
7513383b3e8fSBjoern A. Zeeb void
7514a8397571SBjoern A. Zeeb linuxkpi_ieee80211_tx_status_ext(struct ieee80211_hw *hw,
7515a8397571SBjoern A. Zeeb struct ieee80211_tx_status *txstat)
7516383b3e8fSBjoern A. Zeeb {
7517a8397571SBjoern A. Zeeb struct sk_buff *skb;
7518383b3e8fSBjoern A. Zeeb struct ieee80211_tx_info *info;
7519383b3e8fSBjoern A. Zeeb struct ieee80211_ratectl_tx_status txs;
7520383b3e8fSBjoern A. Zeeb struct ieee80211_node *ni;
7521383b3e8fSBjoern A. Zeeb int status;
7522383b3e8fSBjoern A. Zeeb
7523a8397571SBjoern A. Zeeb skb = txstat->skb;
7524383b3e8fSBjoern A. Zeeb if (skb->m != NULL) {
7525383b3e8fSBjoern A. Zeeb struct mbuf *m;
7526383b3e8fSBjoern A. Zeeb
7527383b3e8fSBjoern A. Zeeb m = skb->m;
7528383b3e8fSBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr;
7529383b3e8fSBjoern A. Zeeb memset(&txs, 0, sizeof(txs));
7530383b3e8fSBjoern A. Zeeb } else {
7531383b3e8fSBjoern A. Zeeb ni = NULL;
7532383b3e8fSBjoern A. Zeeb }
7533383b3e8fSBjoern A. Zeeb
7534a8397571SBjoern A. Zeeb info = txstat->info;
7535383b3e8fSBjoern A. Zeeb if (info->flags & IEEE80211_TX_STAT_ACK) {
7536383b3e8fSBjoern A. Zeeb status = 0; /* No error. */
7537383b3e8fSBjoern A. Zeeb txs.status = IEEE80211_RATECTL_TX_SUCCESS;
7538383b3e8fSBjoern A. Zeeb } else {
7539383b3e8fSBjoern A. Zeeb status = 1;
7540383b3e8fSBjoern A. Zeeb txs.status = IEEE80211_RATECTL_TX_FAIL_UNSPECIFIED;
7541383b3e8fSBjoern A. Zeeb }
7542383b3e8fSBjoern A. Zeeb
7543383b3e8fSBjoern A. Zeeb if (ni != NULL) {
7544383b3e8fSBjoern A. Zeeb txs.pktlen = skb->len;
7545383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_PKTLEN;
7546383b3e8fSBjoern A. Zeeb if (info->status.rates[0].count > 1) {
7547383b3e8fSBjoern A. Zeeb txs.long_retries = info->status.rates[0].count - 1; /* 1 + retries in drivers. */
7548383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_LONG_RETRY;
7549383b3e8fSBjoern A. Zeeb }
7550383b3e8fSBjoern A. Zeeb #if 0 /* Unused in net80211 currently. */
7551a8397571SBjoern A. Zeeb /* XXX-BZ convert check .flags for MCS/VHT/.. */
7552383b3e8fSBjoern A. Zeeb txs.final_rate = info->status.rates[0].idx;
7553383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_FINAL_RATE;
7554383b3e8fSBjoern A. Zeeb #endif
7555adff403fSBjoern A. Zeeb if (info->status.flags & IEEE80211_TX_STATUS_ACK_SIGNAL_VALID) {
7556383b3e8fSBjoern A. Zeeb txs.rssi = info->status.ack_signal; /* XXX-BZ CONVERT? */
7557383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_RSSI;
7558383b3e8fSBjoern A. Zeeb }
7559383b3e8fSBjoern A. Zeeb
7560d1a37f28SBjoern A. Zeeb IMPROVE("only update rate if needed but that requires us to get a proper rate from mo_sta_statistics");
7561383b3e8fSBjoern A. Zeeb ieee80211_ratectl_tx_complete(ni, &txs);
756246de4d9fSAdrian Chadd ieee80211_ratectl_rate(ni->ni_vap->iv_bss, NULL, 0);
7563383b3e8fSBjoern A. Zeeb
7564383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
7565383b3e8fSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) {
7566d1a37f28SBjoern A. Zeeb printf("TX-RATE: %s: long_retries %d\n", __func__,
756746de4d9fSAdrian Chadd txs.long_retries);
7568383b3e8fSBjoern A. Zeeb }
7569383b3e8fSBjoern A. Zeeb #endif
7570383b3e8fSBjoern A. Zeeb }
7571383b3e8fSBjoern A. Zeeb
7572383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
7573383b3e8fSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX)
7574383b3e8fSBjoern A. Zeeb printf("TX-STATUS: %s: hw %p skb %p status %d : flags %#x "
7575383b3e8fSBjoern A. Zeeb "band %u hw_queue %u tx_time_est %d : "
7576383b3e8fSBjoern A. Zeeb "rates [ %u %u %#x, %u %u %#x, %u %u %#x, %u %u %#x ] "
7577383b3e8fSBjoern A. Zeeb "ack_signal %u ampdu_ack_len %u ampdu_len %u antenna %u "
7578adff403fSBjoern A. Zeeb "tx_time %u flags %#x "
7579383b3e8fSBjoern A. Zeeb "status_driver_data [ %p %p ]\n",
7580383b3e8fSBjoern A. Zeeb __func__, hw, skb, status, info->flags,
7581383b3e8fSBjoern A. Zeeb info->band, info->hw_queue, info->tx_time_est,
7582383b3e8fSBjoern A. Zeeb info->status.rates[0].idx, info->status.rates[0].count,
7583383b3e8fSBjoern A. Zeeb info->status.rates[0].flags,
7584383b3e8fSBjoern A. Zeeb info->status.rates[1].idx, info->status.rates[1].count,
7585383b3e8fSBjoern A. Zeeb info->status.rates[1].flags,
7586383b3e8fSBjoern A. Zeeb info->status.rates[2].idx, info->status.rates[2].count,
7587383b3e8fSBjoern A. Zeeb info->status.rates[2].flags,
7588383b3e8fSBjoern A. Zeeb info->status.rates[3].idx, info->status.rates[3].count,
7589383b3e8fSBjoern A. Zeeb info->status.rates[3].flags,
7590383b3e8fSBjoern A. Zeeb info->status.ack_signal, info->status.ampdu_ack_len,
7591383b3e8fSBjoern A. Zeeb info->status.ampdu_len, info->status.antenna,
7592adff403fSBjoern A. Zeeb info->status.tx_time, info->status.flags,
7593383b3e8fSBjoern A. Zeeb info->status.status_driver_data[0],
7594383b3e8fSBjoern A. Zeeb info->status.status_driver_data[1]);
7595383b3e8fSBjoern A. Zeeb #endif
7596383b3e8fSBjoern A. Zeeb
7597a8397571SBjoern A. Zeeb if (txstat->free_list) {
7598a8397571SBjoern A. Zeeb _lkpi_ieee80211_free_txskb(hw, skb, status);
7599a8397571SBjoern A. Zeeb list_add_tail(&skb->list, txstat->free_list);
7600a8397571SBjoern A. Zeeb } else {
7601383b3e8fSBjoern A. Zeeb linuxkpi_ieee80211_free_txskb(hw, skb, status);
7602383b3e8fSBjoern A. Zeeb }
7603a8397571SBjoern A. Zeeb }
7604a8397571SBjoern A. Zeeb
7605a8397571SBjoern A. Zeeb void
7606a8397571SBjoern A. Zeeb linuxkpi_ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
7607a8397571SBjoern A. Zeeb {
7608a8397571SBjoern A. Zeeb struct ieee80211_tx_status status;
7609a8397571SBjoern A. Zeeb
7610a8397571SBjoern A. Zeeb memset(&status, 0, sizeof(status));
7611a8397571SBjoern A. Zeeb status.info = IEEE80211_SKB_CB(skb);
7612a8397571SBjoern A. Zeeb status.skb = skb;
7613a8397571SBjoern A. Zeeb /* sta, n_rates, rates, free_list? */
7614a8397571SBjoern A. Zeeb
7615a8397571SBjoern A. Zeeb ieee80211_tx_status_ext(hw, &status);
7616a8397571SBjoern A. Zeeb }
7617383b3e8fSBjoern A. Zeeb
76186b4cac81SBjoern A. Zeeb /*
76196b4cac81SBjoern A. Zeeb * This is an internal bandaid for the moment for the way we glue
76206b4cac81SBjoern A. Zeeb * skbs and mbufs together for TX. Once we have skbs backed by
76216b4cac81SBjoern A. Zeeb * mbufs this should go away.
76226b4cac81SBjoern A. Zeeb * This is a public function but kept on the private KPI (lkpi_)
76236b4cac81SBjoern A. Zeeb * and is not exposed by a header file.
76246b4cac81SBjoern A. Zeeb */
76256b4cac81SBjoern A. Zeeb static void
76266b4cac81SBjoern A. Zeeb lkpi_ieee80211_free_skb_mbuf(void *p)
76276b4cac81SBjoern A. Zeeb {
76286b4cac81SBjoern A. Zeeb struct ieee80211_node *ni;
76296b4cac81SBjoern A. Zeeb struct mbuf *m;
76306b4cac81SBjoern A. Zeeb
76316b4cac81SBjoern A. Zeeb if (p == NULL)
76326b4cac81SBjoern A. Zeeb return;
76336b4cac81SBjoern A. Zeeb
76346b4cac81SBjoern A. Zeeb m = (struct mbuf *)p;
76356b4cac81SBjoern A. Zeeb M_ASSERTPKTHDR(m);
76366b4cac81SBjoern A. Zeeb
76376b4cac81SBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr;
76386b4cac81SBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = NULL;
76396b4cac81SBjoern A. Zeeb if (ni != NULL)
76406b4cac81SBjoern A. Zeeb ieee80211_free_node(ni);
76416b4cac81SBjoern A. Zeeb m_freem(m);
76426b4cac81SBjoern A. Zeeb }
76436b4cac81SBjoern A. Zeeb
76446b4cac81SBjoern A. Zeeb void
76456b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_queue_delayed_work(struct ieee80211_hw *hw,
76466b4cac81SBjoern A. Zeeb struct delayed_work *w, int delay)
76476b4cac81SBjoern A. Zeeb {
76486b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
76496b4cac81SBjoern A. Zeeb
76506b4cac81SBjoern A. Zeeb /* Need to make sure hw is in a stable (non-suspended) state. */
76516b4cac81SBjoern A. Zeeb IMPROVE();
76526b4cac81SBjoern A. Zeeb
76536b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw);
76546b4cac81SBjoern A. Zeeb queue_delayed_work(lhw->workq, w, delay);
76556b4cac81SBjoern A. Zeeb }
76566b4cac81SBjoern A. Zeeb
76576b4cac81SBjoern A. Zeeb void
76586b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_queue_work(struct ieee80211_hw *hw,
76596b4cac81SBjoern A. Zeeb struct work_struct *w)
76606b4cac81SBjoern A. Zeeb {
76616b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw;
76626b4cac81SBjoern A. Zeeb
76636b4cac81SBjoern A. Zeeb /* Need to make sure hw is in a stable (non-suspended) state. */
76646b4cac81SBjoern A. Zeeb IMPROVE();
76656b4cac81SBjoern A. Zeeb
76666b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw);
76676b4cac81SBjoern A. Zeeb queue_work(lhw->workq, w);
76686b4cac81SBjoern A. Zeeb }
76696b4cac81SBjoern A. Zeeb
76706b4cac81SBjoern A. Zeeb struct sk_buff *
7671ade774b1SBjoern A. Zeeb linuxkpi_ieee80211_probereq_get(struct ieee80211_hw *hw, uint8_t *addr,
7672ade774b1SBjoern A. Zeeb uint8_t *ssid, size_t ssid_len, size_t tailroom)
7673ade774b1SBjoern A. Zeeb {
7674ade774b1SBjoern A. Zeeb struct sk_buff *skb;
7675ade774b1SBjoern A. Zeeb struct ieee80211_frame *wh;
7676ade774b1SBjoern A. Zeeb uint8_t *p;
7677ade774b1SBjoern A. Zeeb size_t len;
7678ade774b1SBjoern A. Zeeb
7679ade774b1SBjoern A. Zeeb len = sizeof(*wh);
7680ade774b1SBjoern A. Zeeb len += 2 + ssid_len;
7681ade774b1SBjoern A. Zeeb
7682ade774b1SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + len + tailroom);
7683ade774b1SBjoern A. Zeeb if (skb == NULL)
7684ade774b1SBjoern A. Zeeb return (NULL);
7685ade774b1SBjoern A. Zeeb
7686ade774b1SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom);
7687ade774b1SBjoern A. Zeeb
7688ade774b1SBjoern A. Zeeb wh = skb_put_zero(skb, sizeof(*wh));
7689ade774b1SBjoern A. Zeeb wh->i_fc[0] = IEEE80211_FC0_VERSION_0;
7690ade774b1SBjoern A. Zeeb wh->i_fc[0] |= IEEE80211_FC0_SUBTYPE_PROBE_REQ | IEEE80211_FC0_TYPE_MGT;
7691ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr1, ieee80211broadcastaddr);
7692ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr2, addr);
7693ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr3, ieee80211broadcastaddr);
7694ade774b1SBjoern A. Zeeb
7695ade774b1SBjoern A. Zeeb p = skb_put(skb, 2 + ssid_len);
7696ade774b1SBjoern A. Zeeb *p++ = IEEE80211_ELEMID_SSID;
7697ade774b1SBjoern A. Zeeb *p++ = ssid_len;
7698ade774b1SBjoern A. Zeeb if (ssid_len > 0)
7699ade774b1SBjoern A. Zeeb memcpy(p, ssid, ssid_len);
7700ade774b1SBjoern A. Zeeb
7701ade774b1SBjoern A. Zeeb return (skb);
7702ade774b1SBjoern A. Zeeb }
7703ade774b1SBjoern A. Zeeb
7704ade774b1SBjoern A. Zeeb struct sk_buff *
77056b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_pspoll_get(struct ieee80211_hw *hw,
77066b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif)
77076b4cac81SBjoern A. Zeeb {
77086b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
77096b4cac81SBjoern A. Zeeb struct ieee80211vap *vap;
77106b4cac81SBjoern A. Zeeb struct sk_buff *skb;
77116b4cac81SBjoern A. Zeeb struct ieee80211_frame_pspoll *psp;
77126b4cac81SBjoern A. Zeeb uint16_t v;
77136b4cac81SBjoern A. Zeeb
77146b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*psp));
77156b4cac81SBjoern A. Zeeb if (skb == NULL)
77166b4cac81SBjoern A. Zeeb return (NULL);
77176b4cac81SBjoern A. Zeeb
77186b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom);
77196b4cac81SBjoern A. Zeeb
77206b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif);
77216b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif);
77226b4cac81SBjoern A. Zeeb
77236b4cac81SBjoern A. Zeeb psp = skb_put_zero(skb, sizeof(*psp));
77246b4cac81SBjoern A. Zeeb psp->i_fc[0] = IEEE80211_FC0_VERSION_0;
77256b4cac81SBjoern A. Zeeb psp->i_fc[0] |= IEEE80211_FC0_SUBTYPE_PS_POLL | IEEE80211_FC0_TYPE_CTL;
7726616e1330SBjoern A. Zeeb v = htole16(vif->cfg.aid | 1<<15 | 1<<16);
77276b4cac81SBjoern A. Zeeb memcpy(&psp->i_aid, &v, sizeof(v));
77286b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(psp->i_bssid, vap->iv_bss->ni_macaddr);
77296b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(psp->i_ta, vif->addr);
77306b4cac81SBjoern A. Zeeb
77316b4cac81SBjoern A. Zeeb return (skb);
77326b4cac81SBjoern A. Zeeb }
77336b4cac81SBjoern A. Zeeb
77346b4cac81SBjoern A. Zeeb struct sk_buff *
77356b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_nullfunc_get(struct ieee80211_hw *hw,
7736adff403fSBjoern A. Zeeb struct ieee80211_vif *vif, int linkid, bool qos)
77376b4cac81SBjoern A. Zeeb {
77386b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
77396b4cac81SBjoern A. Zeeb struct ieee80211vap *vap;
77406b4cac81SBjoern A. Zeeb struct sk_buff *skb;
77416b4cac81SBjoern A. Zeeb struct ieee80211_frame *nullf;
77426b4cac81SBjoern A. Zeeb
7743adff403fSBjoern A. Zeeb IMPROVE("linkid");
7744adff403fSBjoern A. Zeeb
77456b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*nullf));
77466b4cac81SBjoern A. Zeeb if (skb == NULL)
77476b4cac81SBjoern A. Zeeb return (NULL);
77486b4cac81SBjoern A. Zeeb
77496b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom);
77506b4cac81SBjoern A. Zeeb
77516b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif);
77526b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif);
77536b4cac81SBjoern A. Zeeb
77546b4cac81SBjoern A. Zeeb nullf = skb_put_zero(skb, sizeof(*nullf));
77556b4cac81SBjoern A. Zeeb nullf->i_fc[0] = IEEE80211_FC0_VERSION_0;
77566b4cac81SBjoern A. Zeeb nullf->i_fc[0] |= IEEE80211_FC0_SUBTYPE_NODATA | IEEE80211_FC0_TYPE_DATA;
77576b4cac81SBjoern A. Zeeb nullf->i_fc[1] = IEEE80211_FC1_DIR_TODS;
77586b4cac81SBjoern A. Zeeb
77596b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr1, vap->iv_bss->ni_bssid);
77606b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr2, vif->addr);
77616b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr3, vap->iv_bss->ni_macaddr);
77626b4cac81SBjoern A. Zeeb
77636b4cac81SBjoern A. Zeeb return (skb);
77646b4cac81SBjoern A. Zeeb }
77656b4cac81SBjoern A. Zeeb
77666b4cac81SBjoern A. Zeeb struct wireless_dev *
77676b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_vif_to_wdev(struct ieee80211_vif *vif)
77686b4cac81SBjoern A. Zeeb {
77696b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
77706b4cac81SBjoern A. Zeeb
77716b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif);
77726b4cac81SBjoern A. Zeeb return (&lvif->wdev);
77736b4cac81SBjoern A. Zeeb }
77746b4cac81SBjoern A. Zeeb
77756b4cac81SBjoern A. Zeeb void
77766b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_connection_loss(struct ieee80211_vif *vif)
77776b4cac81SBjoern A. Zeeb {
77786b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif;
77796b4cac81SBjoern A. Zeeb struct ieee80211vap *vap;
77806b4cac81SBjoern A. Zeeb enum ieee80211_state nstate;
77816b4cac81SBjoern A. Zeeb int arg;
77826b4cac81SBjoern A. Zeeb
77836b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif);
77846b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif);
77856b4cac81SBjoern A. Zeeb
77866b4cac81SBjoern A. Zeeb /*
7787f3229b62SBjoern A. Zeeb * Go to init; otherwise we need to elaborately check state and
77886b4cac81SBjoern A. Zeeb * handle accordingly, e.g., if in RUN we could call iv_bmiss.
77896b4cac81SBjoern A. Zeeb * Let the statemachine handle all neccessary changes.
77906b4cac81SBjoern A. Zeeb */
7791f3229b62SBjoern A. Zeeb nstate = IEEE80211_S_INIT;
7792bb81db90SBjoern A. Zeeb arg = 0; /* Not a valid reason. */
77936b4cac81SBjoern A. Zeeb
7794018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: vif %p vap %p state %s\n", __func__,
7795018d93ecSBjoern A. Zeeb vif, vap, ieee80211_state_name[vap->iv_state]);
77966b4cac81SBjoern A. Zeeb ieee80211_new_state(vap, nstate, arg);
77976b4cac81SBjoern A. Zeeb }
77986b4cac81SBjoern A. Zeeb
7799bb81db90SBjoern A. Zeeb void
7800bb81db90SBjoern A. Zeeb linuxkpi_ieee80211_beacon_loss(struct ieee80211_vif *vif)
7801bb81db90SBjoern A. Zeeb {
7802bb81db90SBjoern A. Zeeb struct lkpi_vif *lvif;
7803bb81db90SBjoern A. Zeeb struct ieee80211vap *vap;
7804bb81db90SBjoern A. Zeeb
7805bb81db90SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif);
7806bb81db90SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif);
7807bb81db90SBjoern A. Zeeb
7808bb81db90SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: vif %p vap %p state %s\n", __func__,
7809bb81db90SBjoern A. Zeeb vif, vap, ieee80211_state_name[vap->iv_state]);
78103540911bSBjoern A. Zeeb ieee80211_beacon_miss(vap->iv_ic);
7811bb81db90SBjoern A. Zeeb }
7812bb81db90SBjoern A. Zeeb
78135edde07cSBjoern A. Zeeb /* -------------------------------------------------------------------------- */
78145edde07cSBjoern A. Zeeb
78155a9a0d78SBjoern A. Zeeb void
78165a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_stop_queue(struct ieee80211_hw *hw, int qnum)
78175a9a0d78SBjoern A. Zeeb {
78185a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw;
78195a9a0d78SBjoern A. Zeeb struct lkpi_vif *lvif;
78205a9a0d78SBjoern A. Zeeb struct ieee80211_vif *vif;
78215a9a0d78SBjoern A. Zeeb int ac_count, ac;
78225a9a0d78SBjoern A. Zeeb
78235a9a0d78SBjoern A. Zeeb KASSERT(qnum < hw->queues, ("%s: qnum %d >= hw->queues %d, hw %p\n",
78245a9a0d78SBjoern A. Zeeb __func__, qnum, hw->queues, hw));
78255a9a0d78SBjoern A. Zeeb
78265a9a0d78SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy);
78275a9a0d78SBjoern A. Zeeb
78285a9a0d78SBjoern A. Zeeb /* See lkpi_ic_vap_create(). */
78295a9a0d78SBjoern A. Zeeb if (hw->queues >= IEEE80211_NUM_ACS)
78305a9a0d78SBjoern A. Zeeb ac_count = IEEE80211_NUM_ACS;
78315a9a0d78SBjoern A. Zeeb else
78325a9a0d78SBjoern A. Zeeb ac_count = 1;
78335a9a0d78SBjoern A. Zeeb
78345a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw);
78355a9a0d78SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) {
78365a9a0d78SBjoern A. Zeeb
78375a9a0d78SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
78385a9a0d78SBjoern A. Zeeb for (ac = 0; ac < ac_count; ac++) {
78395a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING");
78405a9a0d78SBjoern A. Zeeb if (qnum == vif->hw_queue[ac]) {
78410d2cb6a6SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
78425a9a0d78SBjoern A. Zeeb /*
78435a9a0d78SBjoern A. Zeeb * For now log this to better understand
78445a9a0d78SBjoern A. Zeeb * how this is supposed to work.
78455a9a0d78SBjoern A. Zeeb */
78460d2cb6a6SBjoern A. Zeeb if (lvif->hw_queue_stopped[ac] &&
78470d2cb6a6SBjoern A. Zeeb (linuxkpi_debug_80211 & D80211_IMPROVE_TXQ) != 0)
78485a9a0d78SBjoern A. Zeeb ic_printf(lhw->ic, "%s:%d: lhw %p hw %p "
78495a9a0d78SBjoern A. Zeeb "lvif %p vif %p ac %d qnum %d already "
78505a9a0d78SBjoern A. Zeeb "stopped\n", __func__, __LINE__,
78515a9a0d78SBjoern A. Zeeb lhw, hw, lvif, vif, ac, qnum);
78520d2cb6a6SBjoern A. Zeeb #endif
78535a9a0d78SBjoern A. Zeeb lvif->hw_queue_stopped[ac] = true;
78545a9a0d78SBjoern A. Zeeb }
78555a9a0d78SBjoern A. Zeeb }
78565a9a0d78SBjoern A. Zeeb }
78575a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw);
78585a9a0d78SBjoern A. Zeeb }
78595a9a0d78SBjoern A. Zeeb
78605a9a0d78SBjoern A. Zeeb void
78615a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_stop_queues(struct ieee80211_hw *hw)
78625a9a0d78SBjoern A. Zeeb {
78635a9a0d78SBjoern A. Zeeb int i;
78645a9a0d78SBjoern A. Zeeb
78655a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Locking; do we need further info?");
78665a9a0d78SBjoern A. Zeeb for (i = 0; i < hw->queues; i++)
78675a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_stop_queue(hw, i);
78685a9a0d78SBjoern A. Zeeb }
78695a9a0d78SBjoern A. Zeeb
78705a9a0d78SBjoern A. Zeeb
78715a9a0d78SBjoern A. Zeeb static void
78725a9a0d78SBjoern A. Zeeb lkpi_ieee80211_wake_queues(struct ieee80211_hw *hw, int hwq)
78735a9a0d78SBjoern A. Zeeb {
78745a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw;
78755a9a0d78SBjoern A. Zeeb struct lkpi_vif *lvif;
78765a9a0d78SBjoern A. Zeeb struct lkpi_sta *lsta;
78775a9a0d78SBjoern A. Zeeb int ac_count, ac, tid;
78785a9a0d78SBjoern A. Zeeb
78795a9a0d78SBjoern A. Zeeb /* See lkpi_ic_vap_create(). */
78805a9a0d78SBjoern A. Zeeb if (hw->queues >= IEEE80211_NUM_ACS)
78815a9a0d78SBjoern A. Zeeb ac_count = IEEE80211_NUM_ACS;
78825a9a0d78SBjoern A. Zeeb else
78835a9a0d78SBjoern A. Zeeb ac_count = 1;
78845a9a0d78SBjoern A. Zeeb
78855a9a0d78SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy);
78865a9a0d78SBjoern A. Zeeb
78875a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Locking");
78885a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw);
78895a9a0d78SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) {
78905a9a0d78SBjoern A. Zeeb struct ieee80211_vif *vif;
78915a9a0d78SBjoern A. Zeeb
78925a9a0d78SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif);
78935a9a0d78SBjoern A. Zeeb for (ac = 0; ac < ac_count; ac++) {
78945a9a0d78SBjoern A. Zeeb
78955a9a0d78SBjoern A. Zeeb if (hwq == vif->hw_queue[ac]) {
78965a9a0d78SBjoern A. Zeeb
78975a9a0d78SBjoern A. Zeeb /* XXX-BZ what about software scan? */
78985a9a0d78SBjoern A. Zeeb
78990d2cb6a6SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211
79005a9a0d78SBjoern A. Zeeb /*
79015a9a0d78SBjoern A. Zeeb * For now log this to better understand
79025a9a0d78SBjoern A. Zeeb * how this is supposed to work.
79035a9a0d78SBjoern A. Zeeb */
79040d2cb6a6SBjoern A. Zeeb if (!lvif->hw_queue_stopped[ac] &&
79050d2cb6a6SBjoern A. Zeeb (linuxkpi_debug_80211 & D80211_IMPROVE_TXQ) != 0)
79065a9a0d78SBjoern A. Zeeb ic_printf(lhw->ic, "%s:%d: lhw %p hw %p "
79075a9a0d78SBjoern A. Zeeb "lvif %p vif %p ac %d hw_q not stopped\n",
79085a9a0d78SBjoern A. Zeeb __func__, __LINE__,
79095a9a0d78SBjoern A. Zeeb lhw, hw, lvif, vif, ac);
79100d2cb6a6SBjoern A. Zeeb #endif
79115a9a0d78SBjoern A. Zeeb lvif->hw_queue_stopped[ac] = false;
79125a9a0d78SBjoern A. Zeeb
7913a8f735a6SBjoern A. Zeeb rcu_read_lock();
7914a8f735a6SBjoern A. Zeeb list_for_each_entry_rcu(lsta, &lvif->lsta_list, lsta_list) {
79155a9a0d78SBjoern A. Zeeb struct ieee80211_sta *sta;
79165a9a0d78SBjoern A. Zeeb
79175a9a0d78SBjoern A. Zeeb sta = LSTA_TO_STA(lsta);
79185a9a0d78SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) {
79195a9a0d78SBjoern A. Zeeb struct lkpi_txq *ltxq;
79205a9a0d78SBjoern A. Zeeb
79215a9a0d78SBjoern A. Zeeb if (sta->txq[tid] == NULL)
79225a9a0d78SBjoern A. Zeeb continue;
79235a9a0d78SBjoern A. Zeeb
79245a9a0d78SBjoern A. Zeeb if (sta->txq[tid]->ac != ac)
79255a9a0d78SBjoern A. Zeeb continue;
79265a9a0d78SBjoern A. Zeeb
79275a9a0d78SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]);
79285a9a0d78SBjoern A. Zeeb if (!ltxq->stopped)
79295a9a0d78SBjoern A. Zeeb continue;
79305a9a0d78SBjoern A. Zeeb
79315a9a0d78SBjoern A. Zeeb ltxq->stopped = false;
79325a9a0d78SBjoern A. Zeeb
7933bc24342dSBjoern A. Zeeb if (!skb_queue_empty(<xq->skbq))
79345a9a0d78SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, sta->txq[tid]);
79355a9a0d78SBjoern A. Zeeb }
79365a9a0d78SBjoern A. Zeeb }
7937a8f735a6SBjoern A. Zeeb rcu_read_unlock();
79385a9a0d78SBjoern A. Zeeb }
79395a9a0d78SBjoern A. Zeeb }
79405a9a0d78SBjoern A. Zeeb }
79415a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw);
79425a9a0d78SBjoern A. Zeeb }
79435a9a0d78SBjoern A. Zeeb
7944bc24342dSBjoern A. Zeeb static void
7945bc24342dSBjoern A. Zeeb lkpi_ieee80211_wake_queues_locked(struct ieee80211_hw *hw)
79465a9a0d78SBjoern A. Zeeb {
79475a9a0d78SBjoern A. Zeeb int i;
79485a9a0d78SBjoern A. Zeeb
79495a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Is this all/enough here?");
79505a9a0d78SBjoern A. Zeeb for (i = 0; i < hw->queues; i++)
79515a9a0d78SBjoern A. Zeeb lkpi_ieee80211_wake_queues(hw, i);
79525a9a0d78SBjoern A. Zeeb }
79535a9a0d78SBjoern A. Zeeb
79545a9a0d78SBjoern A. Zeeb void
7955bc24342dSBjoern A. Zeeb linuxkpi_ieee80211_wake_queues(struct ieee80211_hw *hw)
7956bc24342dSBjoern A. Zeeb {
7957bc24342dSBjoern A. Zeeb wiphy_lock(hw->wiphy);
7958bc24342dSBjoern A. Zeeb lkpi_ieee80211_wake_queues_locked(hw);
7959bc24342dSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
7960bc24342dSBjoern A. Zeeb }
7961bc24342dSBjoern A. Zeeb
7962bc24342dSBjoern A. Zeeb void
79635a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_wake_queue(struct ieee80211_hw *hw, int qnum)
79645a9a0d78SBjoern A. Zeeb {
79655a9a0d78SBjoern A. Zeeb
79665a9a0d78SBjoern A. Zeeb KASSERT(qnum < hw->queues, ("%s: qnum %d >= hw->queues %d, hw %p\n",
79675a9a0d78SBjoern A. Zeeb __func__, qnum, hw->queues, hw));
79685a9a0d78SBjoern A. Zeeb
7969bc24342dSBjoern A. Zeeb wiphy_lock(hw->wiphy);
79705a9a0d78SBjoern A. Zeeb lkpi_ieee80211_wake_queues(hw, qnum);
7971bc24342dSBjoern A. Zeeb wiphy_unlock(hw->wiphy);
79725a9a0d78SBjoern A. Zeeb }
79735a9a0d78SBjoern A. Zeeb
79745a9a0d78SBjoern A. Zeeb /* This is just hardware queues. */
79755a9a0d78SBjoern A. Zeeb void
79765a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_txq_schedule_start(struct ieee80211_hw *hw, uint8_t ac)
79775a9a0d78SBjoern A. Zeeb {
79785a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw;
79795a9a0d78SBjoern A. Zeeb
79805a9a0d78SBjoern A. Zeeb lhw = HW_TO_LHW(hw);
79815a9a0d78SBjoern A. Zeeb
79825a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Are there reasons why we wouldn't schedule?");
79835a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING");
79845a9a0d78SBjoern A. Zeeb if (++lhw->txq_generation[ac] == 0)
79855a9a0d78SBjoern A. Zeeb lhw->txq_generation[ac]++;
79865a9a0d78SBjoern A. Zeeb }
79875a9a0d78SBjoern A. Zeeb
79885a9a0d78SBjoern A. Zeeb struct ieee80211_txq *
79895a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_next_txq(struct ieee80211_hw *hw, uint8_t ac)
79905a9a0d78SBjoern A. Zeeb {
79915a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw;
79925a9a0d78SBjoern A. Zeeb struct ieee80211_txq *txq;
79935a9a0d78SBjoern A. Zeeb struct lkpi_txq *ltxq;
79945a9a0d78SBjoern A. Zeeb
79955a9a0d78SBjoern A. Zeeb lhw = HW_TO_LHW(hw);
79965a9a0d78SBjoern A. Zeeb txq = NULL;
79975a9a0d78SBjoern A. Zeeb
79985a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING");
79995a9a0d78SBjoern A. Zeeb
80005a9a0d78SBjoern A. Zeeb /* Check that we are scheduled. */
80015a9a0d78SBjoern A. Zeeb if (lhw->txq_generation[ac] == 0)
80025a9a0d78SBjoern A. Zeeb goto out;
80035a9a0d78SBjoern A. Zeeb
80045a9a0d78SBjoern A. Zeeb ltxq = TAILQ_FIRST(&lhw->scheduled_txqs[ac]);
80055a9a0d78SBjoern A. Zeeb if (ltxq == NULL)
80065a9a0d78SBjoern A. Zeeb goto out;
80075a9a0d78SBjoern A. Zeeb if (ltxq->txq_generation == lhw->txq_generation[ac])
80085a9a0d78SBjoern A. Zeeb goto out;
80095a9a0d78SBjoern A. Zeeb
80105a9a0d78SBjoern A. Zeeb ltxq->txq_generation = lhw->txq_generation[ac];
80115a9a0d78SBjoern A. Zeeb TAILQ_REMOVE(&lhw->scheduled_txqs[ac], ltxq, txq_entry);
80125a9a0d78SBjoern A. Zeeb txq = <xq->txq;
80135a9a0d78SBjoern A. Zeeb TAILQ_ELEM_INIT(ltxq, txq_entry);
80145a9a0d78SBjoern A. Zeeb
80155a9a0d78SBjoern A. Zeeb out:
80165a9a0d78SBjoern A. Zeeb return (txq);
80175a9a0d78SBjoern A. Zeeb }
80185a9a0d78SBjoern A. Zeeb
80195a9a0d78SBjoern A. Zeeb void linuxkpi_ieee80211_schedule_txq(struct ieee80211_hw *hw,
80205a9a0d78SBjoern A. Zeeb struct ieee80211_txq *txq, bool withoutpkts)
80215a9a0d78SBjoern A. Zeeb {
80225a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw;
80235a9a0d78SBjoern A. Zeeb struct lkpi_txq *ltxq;
8024eac3646fSBjoern A. Zeeb bool ltxq_empty;
80255a9a0d78SBjoern A. Zeeb
80265a9a0d78SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq);
80275a9a0d78SBjoern A. Zeeb
80285a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING");
80295a9a0d78SBjoern A. Zeeb
80305a9a0d78SBjoern A. Zeeb /* Only schedule if work to do or asked to anyway. */
8031eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_LOCK(ltxq);
8032eac3646fSBjoern A. Zeeb ltxq_empty = skb_queue_empty(<xq->skbq);
8033eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_UNLOCK(ltxq);
8034eac3646fSBjoern A. Zeeb if (!withoutpkts && ltxq_empty)
80355a9a0d78SBjoern A. Zeeb goto out;
80365a9a0d78SBjoern A. Zeeb
803741b746e0SAustin Shafer /*
803841b746e0SAustin Shafer * Make sure we do not double-schedule. We do this by checking tqe_prev,
803941b746e0SAustin Shafer * the previous entry in our tailq. tqe_prev is always valid if this entry
804041b746e0SAustin Shafer * is queued, tqe_next may be NULL if this is the only element in the list.
804141b746e0SAustin Shafer */
804241b746e0SAustin Shafer if (ltxq->txq_entry.tqe_prev != NULL)
80435a9a0d78SBjoern A. Zeeb goto out;
80445a9a0d78SBjoern A. Zeeb
80455a9a0d78SBjoern A. Zeeb lhw = HW_TO_LHW(hw);
80465a9a0d78SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lhw->scheduled_txqs[txq->ac], ltxq, txq_entry);
80475a9a0d78SBjoern A. Zeeb out:
80485a9a0d78SBjoern A. Zeeb return;
80495a9a0d78SBjoern A. Zeeb }
80505a9a0d78SBjoern A. Zeeb
8051eac3646fSBjoern A. Zeeb void
8052eac3646fSBjoern A. Zeeb linuxkpi_ieee80211_handle_wake_tx_queue(struct ieee80211_hw *hw,
8053eac3646fSBjoern A. Zeeb struct ieee80211_txq *txq)
8054eac3646fSBjoern A. Zeeb {
8055eac3646fSBjoern A. Zeeb struct lkpi_hw *lhw;
8056eac3646fSBjoern A. Zeeb struct ieee80211_txq *ntxq;
8057eac3646fSBjoern A. Zeeb struct ieee80211_tx_control control;
8058eac3646fSBjoern A. Zeeb struct sk_buff *skb;
8059eac3646fSBjoern A. Zeeb
8060eac3646fSBjoern A. Zeeb lhw = HW_TO_LHW(hw);
8061eac3646fSBjoern A. Zeeb
8062eac3646fSBjoern A. Zeeb LKPI_80211_LHW_TXQ_LOCK(lhw);
8063eac3646fSBjoern A. Zeeb ieee80211_txq_schedule_start(hw, txq->ac);
8064eac3646fSBjoern A. Zeeb do {
8065eac3646fSBjoern A. Zeeb ntxq = ieee80211_next_txq(hw, txq->ac);
8066eac3646fSBjoern A. Zeeb if (ntxq == NULL)
8067eac3646fSBjoern A. Zeeb break;
8068eac3646fSBjoern A. Zeeb
8069eac3646fSBjoern A. Zeeb memset(&control, 0, sizeof(control));
8070eac3646fSBjoern A. Zeeb control.sta = ntxq->sta;
8071eac3646fSBjoern A. Zeeb do {
8072eac3646fSBjoern A. Zeeb skb = linuxkpi_ieee80211_tx_dequeue(hw, ntxq);
8073eac3646fSBjoern A. Zeeb if (skb == NULL)
8074eac3646fSBjoern A. Zeeb break;
8075eac3646fSBjoern A. Zeeb lkpi_80211_mo_tx(hw, &control, skb);
8076eac3646fSBjoern A. Zeeb } while(1);
8077eac3646fSBjoern A. Zeeb
8078eac3646fSBjoern A. Zeeb ieee80211_return_txq(hw, ntxq, false);
8079eac3646fSBjoern A. Zeeb } while (1);
8080eac3646fSBjoern A. Zeeb ieee80211_txq_schedule_end(hw, txq->ac);
8081eac3646fSBjoern A. Zeeb LKPI_80211_LHW_TXQ_UNLOCK(lhw);
8082eac3646fSBjoern A. Zeeb }
8083eac3646fSBjoern A. Zeeb
80845a9a0d78SBjoern A. Zeeb /* -------------------------------------------------------------------------- */
80855a9a0d78SBjoern A. Zeeb
80865edde07cSBjoern A. Zeeb struct lkpi_cfg80211_bss {
80875edde07cSBjoern A. Zeeb u_int refcnt;
80885edde07cSBjoern A. Zeeb struct cfg80211_bss bss;
80895edde07cSBjoern A. Zeeb };
80905edde07cSBjoern A. Zeeb
80915edde07cSBjoern A. Zeeb struct lkpi_cfg80211_get_bss_iter_lookup {
80925edde07cSBjoern A. Zeeb struct wiphy *wiphy;
80935edde07cSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan;
80945edde07cSBjoern A. Zeeb const uint8_t *bssid;
80955edde07cSBjoern A. Zeeb const uint8_t *ssid;
80965edde07cSBjoern A. Zeeb size_t ssid_len;
80975edde07cSBjoern A. Zeeb enum ieee80211_bss_type bss_type;
80985edde07cSBjoern A. Zeeb enum ieee80211_privacy privacy;
80995edde07cSBjoern A. Zeeb
81005edde07cSBjoern A. Zeeb /*
81015edde07cSBjoern A. Zeeb * Something to store a copy of the result as the net80211 scan cache
81025edde07cSBjoern A. Zeeb * is not refoucnted so a scan entry might go away any time.
81035edde07cSBjoern A. Zeeb */
81045edde07cSBjoern A. Zeeb bool match;
81055edde07cSBjoern A. Zeeb struct cfg80211_bss *bss;
81065edde07cSBjoern A. Zeeb };
81075edde07cSBjoern A. Zeeb
81085edde07cSBjoern A. Zeeb static void
81095edde07cSBjoern A. Zeeb lkpi_cfg80211_get_bss_iterf(void *arg, const struct ieee80211_scan_entry *se)
81105edde07cSBjoern A. Zeeb {
81115edde07cSBjoern A. Zeeb struct lkpi_cfg80211_get_bss_iter_lookup *lookup;
81125edde07cSBjoern A. Zeeb size_t ielen;
81135edde07cSBjoern A. Zeeb
81145edde07cSBjoern A. Zeeb lookup = arg;
81155edde07cSBjoern A. Zeeb
81165edde07cSBjoern A. Zeeb /* Do not try to find another match. */
81175edde07cSBjoern A. Zeeb if (lookup->match)
81185edde07cSBjoern A. Zeeb return;
81195edde07cSBjoern A. Zeeb
81205edde07cSBjoern A. Zeeb /* Nothing to store result. */
81215edde07cSBjoern A. Zeeb if (lookup->bss == NULL)
81225edde07cSBjoern A. Zeeb return;
81235edde07cSBjoern A. Zeeb
81245edde07cSBjoern A. Zeeb if (lookup->privacy != IEEE80211_PRIVACY_ANY) {
81255edde07cSBjoern A. Zeeb /* if (se->se_capinfo & IEEE80211_CAPINFO_PRIVACY) */
81265edde07cSBjoern A. Zeeb /* We have no idea what to compare to as the drivers only request ANY */
81275edde07cSBjoern A. Zeeb return;
81285edde07cSBjoern A. Zeeb }
81295edde07cSBjoern A. Zeeb
81305edde07cSBjoern A. Zeeb if (lookup->bss_type != IEEE80211_BSS_TYPE_ANY) {
81315edde07cSBjoern A. Zeeb /* if (se->se_capinfo & (IEEE80211_CAPINFO_IBSS|IEEE80211_CAPINFO_ESS)) */
81325edde07cSBjoern A. Zeeb /* We have no idea what to compare to as the drivers only request ANY */
81335edde07cSBjoern A. Zeeb return;
81345edde07cSBjoern A. Zeeb }
81355edde07cSBjoern A. Zeeb
81365edde07cSBjoern A. Zeeb if (lookup->chan != NULL) {
81375edde07cSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan;
81385edde07cSBjoern A. Zeeb
81395edde07cSBjoern A. Zeeb chan = linuxkpi_ieee80211_get_channel(lookup->wiphy,
81405edde07cSBjoern A. Zeeb se->se_chan->ic_freq);
81415edde07cSBjoern A. Zeeb if (chan == NULL || chan != lookup->chan)
81425edde07cSBjoern A. Zeeb return;
81435edde07cSBjoern A. Zeeb }
81445edde07cSBjoern A. Zeeb
81455edde07cSBjoern A. Zeeb if (lookup->bssid && !IEEE80211_ADDR_EQ(lookup->bssid, se->se_bssid))
81465edde07cSBjoern A. Zeeb return;
81475edde07cSBjoern A. Zeeb
81485edde07cSBjoern A. Zeeb if (lookup->ssid) {
81495edde07cSBjoern A. Zeeb if (lookup->ssid_len != se->se_ssid[1] ||
81505edde07cSBjoern A. Zeeb se->se_ssid[1] == 0)
81515edde07cSBjoern A. Zeeb return;
81525edde07cSBjoern A. Zeeb if (memcmp(lookup->ssid, se->se_ssid+2, lookup->ssid_len) != 0)
81535edde07cSBjoern A. Zeeb return;
81545edde07cSBjoern A. Zeeb }
81555edde07cSBjoern A. Zeeb
81565edde07cSBjoern A. Zeeb ielen = se->se_ies.len;
81575edde07cSBjoern A. Zeeb
81585edde07cSBjoern A. Zeeb lookup->bss->ies = malloc(sizeof(*lookup->bss->ies) + ielen,
81595edde07cSBjoern A. Zeeb M_LKPI80211, M_NOWAIT | M_ZERO);
81605edde07cSBjoern A. Zeeb if (lookup->bss->ies == NULL)
81615edde07cSBjoern A. Zeeb return;
81625edde07cSBjoern A. Zeeb
81635edde07cSBjoern A. Zeeb lookup->bss->ies->data = (uint8_t *)lookup->bss->ies + sizeof(*lookup->bss->ies);
81645edde07cSBjoern A. Zeeb lookup->bss->ies->len = ielen;
81655edde07cSBjoern A. Zeeb if (ielen)
81665edde07cSBjoern A. Zeeb memcpy(lookup->bss->ies->data, se->se_ies.data, ielen);
81675edde07cSBjoern A. Zeeb
81685edde07cSBjoern A. Zeeb lookup->match = true;
81695edde07cSBjoern A. Zeeb }
81705edde07cSBjoern A. Zeeb
81715edde07cSBjoern A. Zeeb struct cfg80211_bss *
81725edde07cSBjoern A. Zeeb linuxkpi_cfg80211_get_bss(struct wiphy *wiphy, struct linuxkpi_ieee80211_channel *chan,
81735edde07cSBjoern A. Zeeb const uint8_t *bssid, const uint8_t *ssid, size_t ssid_len,
81745edde07cSBjoern A. Zeeb enum ieee80211_bss_type bss_type, enum ieee80211_privacy privacy)
81755edde07cSBjoern A. Zeeb {
81765edde07cSBjoern A. Zeeb struct lkpi_cfg80211_bss *lbss;
81775edde07cSBjoern A. Zeeb struct lkpi_cfg80211_get_bss_iter_lookup lookup;
81785edde07cSBjoern A. Zeeb struct lkpi_hw *lhw;
81795edde07cSBjoern A. Zeeb struct ieee80211vap *vap;
81805edde07cSBjoern A. Zeeb
81815edde07cSBjoern A. Zeeb lhw = wiphy_priv(wiphy);
81825edde07cSBjoern A. Zeeb
81835edde07cSBjoern A. Zeeb /* Let's hope we can alloc. */
81845edde07cSBjoern A. Zeeb lbss = malloc(sizeof(*lbss), M_LKPI80211, M_NOWAIT | M_ZERO);
81855edde07cSBjoern A. Zeeb if (lbss == NULL) {
81865edde07cSBjoern A. Zeeb ic_printf(lhw->ic, "%s: alloc failed.\n", __func__);
81875edde07cSBjoern A. Zeeb return (NULL);
81885edde07cSBjoern A. Zeeb }
81895edde07cSBjoern A. Zeeb
81905edde07cSBjoern A. Zeeb lookup.wiphy = wiphy;
81915edde07cSBjoern A. Zeeb lookup.chan = chan;
81925edde07cSBjoern A. Zeeb lookup.bssid = bssid;
81935edde07cSBjoern A. Zeeb lookup.ssid = ssid;
81945edde07cSBjoern A. Zeeb lookup.ssid_len = ssid_len;
81955edde07cSBjoern A. Zeeb lookup.bss_type = bss_type;
81965edde07cSBjoern A. Zeeb lookup.privacy = privacy;
81975edde07cSBjoern A. Zeeb lookup.match = false;
81985edde07cSBjoern A. Zeeb lookup.bss = &lbss->bss;
81995edde07cSBjoern A. Zeeb
82005edde07cSBjoern A. Zeeb IMPROVE("Iterate over all VAPs comparing perm_addr and addresses?");
82015edde07cSBjoern A. Zeeb vap = TAILQ_FIRST(&lhw->ic->ic_vaps);
82025edde07cSBjoern A. Zeeb ieee80211_scan_iterate(vap, lkpi_cfg80211_get_bss_iterf, &lookup);
82035edde07cSBjoern A. Zeeb if (!lookup.match) {
82045edde07cSBjoern A. Zeeb free(lbss, M_LKPI80211);
82055edde07cSBjoern A. Zeeb return (NULL);
82065edde07cSBjoern A. Zeeb }
82075edde07cSBjoern A. Zeeb
82085edde07cSBjoern A. Zeeb refcount_init(&lbss->refcnt, 1);
82095edde07cSBjoern A. Zeeb return (&lbss->bss);
82105edde07cSBjoern A. Zeeb }
82115edde07cSBjoern A. Zeeb
82125edde07cSBjoern A. Zeeb void
82135edde07cSBjoern A. Zeeb linuxkpi_cfg80211_put_bss(struct wiphy *wiphy, struct cfg80211_bss *bss)
82145edde07cSBjoern A. Zeeb {
82155edde07cSBjoern A. Zeeb struct lkpi_cfg80211_bss *lbss;
82165edde07cSBjoern A. Zeeb
82175edde07cSBjoern A. Zeeb lbss = container_of(bss, struct lkpi_cfg80211_bss, bss);
82185edde07cSBjoern A. Zeeb
82195edde07cSBjoern A. Zeeb /* Free everything again on refcount ... */
82205edde07cSBjoern A. Zeeb if (refcount_release(&lbss->refcnt)) {
82215edde07cSBjoern A. Zeeb free(lbss->bss.ies, M_LKPI80211);
82225edde07cSBjoern A. Zeeb free(lbss, M_LKPI80211);
82235edde07cSBjoern A. Zeeb }
82245edde07cSBjoern A. Zeeb }
82255edde07cSBjoern A. Zeeb
82265edde07cSBjoern A. Zeeb void
82275edde07cSBjoern A. Zeeb linuxkpi_cfg80211_bss_flush(struct wiphy *wiphy)
82285edde07cSBjoern A. Zeeb {
82295edde07cSBjoern A. Zeeb struct lkpi_hw *lhw;
82305edde07cSBjoern A. Zeeb struct ieee80211com *ic;
82315edde07cSBjoern A. Zeeb struct ieee80211vap *vap;
82325edde07cSBjoern A. Zeeb
82335edde07cSBjoern A. Zeeb lhw = wiphy_priv(wiphy);
82345edde07cSBjoern A. Zeeb ic = lhw->ic;
82355edde07cSBjoern A. Zeeb
82365edde07cSBjoern A. Zeeb /*
82375edde07cSBjoern A. Zeeb * If we haven't called ieee80211_ifattach() yet
82385edde07cSBjoern A. Zeeb * or there is no VAP, there are no scans to flush.
82395edde07cSBjoern A. Zeeb */
82405edde07cSBjoern A. Zeeb if (ic == NULL ||
82415edde07cSBjoern A. Zeeb (lhw->sc_flags & LKPI_MAC80211_DRV_STARTED) == 0)
82425edde07cSBjoern A. Zeeb return;
82435edde07cSBjoern A. Zeeb
82445edde07cSBjoern A. Zeeb /* Should only happen on the current one? Not seen it late enough. */
82455edde07cSBjoern A. Zeeb IEEE80211_LOCK(ic);
82465edde07cSBjoern A. Zeeb TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
82475edde07cSBjoern A. Zeeb ieee80211_scan_flush(vap);
82485edde07cSBjoern A. Zeeb IEEE80211_UNLOCK(ic);
82495edde07cSBjoern A. Zeeb }
82505edde07cSBjoern A. Zeeb
82515edde07cSBjoern A. Zeeb /* -------------------------------------------------------------------------- */
82525edde07cSBjoern A. Zeeb
8253ac1d519cSBjoern A. Zeeb /*
8254ac1d519cSBjoern A. Zeeb * hw->conf get initialized/set in various places for us:
8255ac1d519cSBjoern A. Zeeb * - linuxkpi_ieee80211_alloc_hw(): flags
8256ac1d519cSBjoern A. Zeeb * - linuxkpi_ieee80211_ifattach(): chandef
8257ac1d519cSBjoern A. Zeeb * - lkpi_ic_vap_create(): listen_interval
8258ac1d519cSBjoern A. Zeeb * - lkpi_ic_set_channel(): chandef, flags
8259ac1d519cSBjoern A. Zeeb */
8260ac1d519cSBjoern A. Zeeb
8261ac1d519cSBjoern A. Zeeb int lkpi_80211_update_chandef(struct ieee80211_hw *hw,
8262ac1d519cSBjoern A. Zeeb struct ieee80211_chanctx_conf *new)
8263ac1d519cSBjoern A. Zeeb {
8264ac1d519cSBjoern A. Zeeb struct cfg80211_chan_def *cd;
8265ac1d519cSBjoern A. Zeeb uint32_t changed;
8266ac1d519cSBjoern A. Zeeb int error;
8267ac1d519cSBjoern A. Zeeb
8268ac1d519cSBjoern A. Zeeb changed = 0;
8269ac1d519cSBjoern A. Zeeb if (new == NULL || new->def.chan == NULL)
8270ac1d519cSBjoern A. Zeeb cd = NULL;
8271ac1d519cSBjoern A. Zeeb else
8272ac1d519cSBjoern A. Zeeb cd = &new->def;
8273ac1d519cSBjoern A. Zeeb
8274ac1d519cSBjoern A. Zeeb if (cd && cd->chan != hw->conf.chandef.chan) {
8275ac1d519cSBjoern A. Zeeb /* Copy; the chan pointer is fine and will stay valid. */
8276ac1d519cSBjoern A. Zeeb hw->conf.chandef = *cd;
8277ac1d519cSBjoern A. Zeeb changed |= IEEE80211_CONF_CHANGE_CHANNEL;
8278ac1d519cSBjoern A. Zeeb }
8279ac1d519cSBjoern A. Zeeb IMPROVE("IEEE80211_CONF_CHANGE_PS, IEEE80211_CONF_CHANGE_POWER");
8280ac1d519cSBjoern A. Zeeb
8281ac1d519cSBjoern A. Zeeb if (changed == 0)
8282ac1d519cSBjoern A. Zeeb return (0);
8283ac1d519cSBjoern A. Zeeb
8284ac1d519cSBjoern A. Zeeb error = lkpi_80211_mo_config(hw, changed);
8285ac1d519cSBjoern A. Zeeb return (error);
8286ac1d519cSBjoern A. Zeeb }
8287ac1d519cSBjoern A. Zeeb
8288ac1d519cSBjoern A. Zeeb /* -------------------------------------------------------------------------- */
8289ac1d519cSBjoern A. Zeeb
82906b4cac81SBjoern A. Zeeb MODULE_VERSION(linuxkpi_wlan, 1);
82916b4cac81SBjoern A. Zeeb MODULE_DEPEND(linuxkpi_wlan, linuxkpi, 1, 1, 1);
82926b4cac81SBjoern A. Zeeb MODULE_DEPEND(linuxkpi_wlan, wlan, 1, 1, 1);
8293