16b4cac81SBjoern A. Zeeb /*- 28ac540d3SBjoern A. Zeeb * Copyright (c) 2020-2023 The FreeBSD Foundation 3086be6a8SBjoern A. Zeeb * Copyright (c) 2020-2022 Bjoern A. Zeeb 46b4cac81SBjoern A. Zeeb * 56b4cac81SBjoern A. Zeeb * This software was developed by Björn Zeeb under sponsorship from 66b4cac81SBjoern A. Zeeb * the FreeBSD Foundation. 76b4cac81SBjoern A. Zeeb * 86b4cac81SBjoern A. Zeeb * Redistribution and use in source and binary forms, with or without 96b4cac81SBjoern A. Zeeb * modification, are permitted provided that the following conditions 106b4cac81SBjoern A. Zeeb * are met: 116b4cac81SBjoern A. Zeeb * 1. Redistributions of source code must retain the above copyright 126b4cac81SBjoern A. Zeeb * notice, this list of conditions and the following disclaimer. 136b4cac81SBjoern A. Zeeb * 2. Redistributions in binary form must reproduce the above copyright 146b4cac81SBjoern A. Zeeb * notice, this list of conditions and the following disclaimer in the 156b4cac81SBjoern A. Zeeb * documentation and/or other materials provided with the distribution. 166b4cac81SBjoern A. Zeeb * 176b4cac81SBjoern A. Zeeb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 186b4cac81SBjoern A. Zeeb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 196b4cac81SBjoern A. Zeeb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 206b4cac81SBjoern A. Zeeb * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 216b4cac81SBjoern A. Zeeb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 226b4cac81SBjoern A. Zeeb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 236b4cac81SBjoern A. Zeeb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 246b4cac81SBjoern A. Zeeb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 256b4cac81SBjoern A. Zeeb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 266b4cac81SBjoern A. Zeeb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 276b4cac81SBjoern A. Zeeb * SUCH DAMAGE. 286b4cac81SBjoern A. Zeeb */ 296b4cac81SBjoern A. Zeeb 306b4cac81SBjoern A. Zeeb /* 316b4cac81SBjoern A. Zeeb * Public functions are called linuxkpi_*(). 326b4cac81SBjoern A. Zeeb * Internal (static) functions are called lkpi_*(). 336b4cac81SBjoern A. Zeeb * 346b4cac81SBjoern A. Zeeb * The internal structures holding metadata over public structures are also 356b4cac81SBjoern A. Zeeb * called lkpi_xxx (usually with a member at the end called xxx). 366b4cac81SBjoern A. Zeeb * Note: we do not replicate the structure names but the general variable names 376b4cac81SBjoern A. Zeeb * for these (e.g., struct hw -> struct lkpi_hw, struct sta -> struct lkpi_sta). 386b4cac81SBjoern A. Zeeb * There are macros to access one from the other. 396b4cac81SBjoern A. Zeeb * We call the internal versions lxxx (e.g., hw -> lhw, sta -> lsta). 406b4cac81SBjoern A. Zeeb */ 416b4cac81SBjoern A. Zeeb 426b4cac81SBjoern A. Zeeb #include <sys/cdefs.h> 436b4cac81SBjoern A. Zeeb #include <sys/param.h> 446b4cac81SBjoern A. Zeeb #include <sys/types.h> 456b4cac81SBjoern A. Zeeb #include <sys/kernel.h> 466b4cac81SBjoern A. Zeeb #include <sys/errno.h> 476b4cac81SBjoern A. Zeeb #include <sys/malloc.h> 486b4cac81SBjoern A. Zeeb #include <sys/module.h> 496b4cac81SBjoern A. Zeeb #include <sys/mutex.h> 506b4cac81SBjoern A. Zeeb #include <sys/socket.h> 516b4cac81SBjoern A. Zeeb #include <sys/sysctl.h> 526b4cac81SBjoern A. Zeeb #include <sys/queue.h> 536b4cac81SBjoern A. Zeeb #include <sys/taskqueue.h> 54527687a9SBjoern A. Zeeb #include <sys/libkern.h> 556b4cac81SBjoern A. Zeeb 566b4cac81SBjoern A. Zeeb #include <net/if.h> 576b4cac81SBjoern A. Zeeb #include <net/if_var.h> 586b4cac81SBjoern A. Zeeb #include <net/if_media.h> 596b4cac81SBjoern A. Zeeb #include <net/ethernet.h> 606b4cac81SBjoern A. Zeeb 616b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_var.h> 626b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_proto.h> 636b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_ratectl.h> 646b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_radiotap.h> 656b4cac81SBjoern A. Zeeb 666b4cac81SBjoern A. Zeeb #define LINUXKPI_NET80211 676b4cac81SBjoern A. Zeeb #include <net/mac80211.h> 686b4cac81SBjoern A. Zeeb 696b4cac81SBjoern A. Zeeb #include <linux/workqueue.h> 706b4cac81SBjoern A. Zeeb #include "linux_80211.h" 716b4cac81SBjoern A. Zeeb 724a67f1dfSBjoern A. Zeeb #define LKPI_80211_WME 73b35f6cd0SBjoern A. Zeeb /* #define LKPI_80211_HW_CRYPTO */ 74b35f6cd0SBjoern A. Zeeb 756b4cac81SBjoern A. Zeeb static MALLOC_DEFINE(M_LKPI80211, "lkpi80211", "LinuxKPI 80211 compat"); 766b4cac81SBjoern A. Zeeb 775a9a0d78SBjoern A. Zeeb /* XXX-BZ really want this and others in queue.h */ 785a9a0d78SBjoern A. Zeeb #define TAILQ_ELEM_INIT(elm, field) do { \ 795a9a0d78SBjoern A. Zeeb (elm)->field.tqe_next = NULL; \ 805a9a0d78SBjoern A. Zeeb (elm)->field.tqe_prev = NULL; \ 815a9a0d78SBjoern A. Zeeb } while (0) 825a9a0d78SBjoern A. Zeeb 836b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 846b4cac81SBjoern A. Zeeb 859d9ba2b7SBjoern A. Zeeb /* Keep public for as long as header files are using it too. */ 869d9ba2b7SBjoern A. Zeeb int linuxkpi_debug_80211; 876b4cac81SBjoern A. Zeeb 886b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 899d9ba2b7SBjoern A. Zeeb SYSCTL_DECL(_compat_linuxkpi); 909d9ba2b7SBjoern A. Zeeb SYSCTL_NODE(_compat_linuxkpi, OID_AUTO, 80211, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 919d9ba2b7SBjoern A. Zeeb "LinuxKPI 802.11 compatibility layer"); 929d9ba2b7SBjoern A. Zeeb 939d9ba2b7SBjoern A. Zeeb SYSCTL_INT(_compat_linuxkpi_80211, OID_AUTO, debug, CTLFLAG_RWTUN, 949d9ba2b7SBjoern A. Zeeb &linuxkpi_debug_80211, 0, "LinuxKPI 802.11 debug level"); 959d9ba2b7SBjoern A. Zeeb 969d9ba2b7SBjoern A. Zeeb #define UNIMPLEMENTED if (linuxkpi_debug_80211 & D80211_TODO) \ 976b4cac81SBjoern A. Zeeb printf("XXX-TODO %s:%d: UNIMPLEMENTED\n", __func__, __LINE__) 989d9ba2b7SBjoern A. Zeeb #define TRACEOK() if (linuxkpi_debug_80211 & D80211_TRACEOK) \ 996b4cac81SBjoern A. Zeeb printf("XXX-TODO %s:%d: TRACEPOINT\n", __func__, __LINE__) 1006b4cac81SBjoern A. Zeeb #else 1016b4cac81SBjoern A. Zeeb #define UNIMPLEMENTED do { } while (0) 1026b4cac81SBjoern A. Zeeb #define TRACEOK() do { } while (0) 1036b4cac81SBjoern A. Zeeb #endif 1046b4cac81SBjoern A. Zeeb 1056b4cac81SBjoern A. Zeeb /* #define PREP_TX_INFO_DURATION (IEEE80211_TRANS_WAIT * 1000) */ 1066b4cac81SBjoern A. Zeeb #ifndef PREP_TX_INFO_DURATION 1076b4cac81SBjoern A. Zeeb #define PREP_TX_INFO_DURATION 0 /* Let the driver do its thing. */ 1086b4cac81SBjoern A. Zeeb #endif 1096b4cac81SBjoern A. Zeeb 1106b4cac81SBjoern A. Zeeb /* This is DSAP | SSAP | CTRL | ProtoID/OrgCode{3}. */ 1116b4cac81SBjoern A. Zeeb const uint8_t rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; 1126b4cac81SBjoern A. Zeeb 113b0f73768SBjoern A. Zeeb /* IEEE 802.11-05/0257r1 */ 114b0f73768SBjoern A. Zeeb const uint8_t bridge_tunnel_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; 115b0f73768SBjoern A. Zeeb 116fb3c249eSBjoern A. Zeeb /* IEEE 802.11e Table 20i-UP-to-AC mappings. */ 117fb3c249eSBjoern A. Zeeb static const uint8_t ieee80211e_up_to_ac[] = { 1184f61ef8bSBjoern A. Zeeb IEEE80211_AC_BE, 1194f61ef8bSBjoern A. Zeeb IEEE80211_AC_BK, 1204f61ef8bSBjoern A. Zeeb IEEE80211_AC_BK, 1214f61ef8bSBjoern A. Zeeb IEEE80211_AC_BE, 1224f61ef8bSBjoern A. Zeeb IEEE80211_AC_VI, 1234f61ef8bSBjoern A. Zeeb IEEE80211_AC_VI, 1244f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO, 1254f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO, 1264f61ef8bSBjoern A. Zeeb #if 0 1274f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO, /* We treat MGMT as TID 8, which is set as AC_VO */ 1284f61ef8bSBjoern A. Zeeb #endif 1294f61ef8bSBjoern A. Zeeb }; 1304f61ef8bSBjoern A. Zeeb 1316b4cac81SBjoern A. Zeeb const struct cfg80211_ops linuxkpi_mac80211cfgops = { 1326b4cac81SBjoern A. Zeeb /* 1336b4cac81SBjoern A. Zeeb * XXX TODO need a "glue layer" to link cfg80211 ops to 1346b4cac81SBjoern A. Zeeb * mac80211 and to the driver or net80211. 1356b4cac81SBjoern A. Zeeb * Can we pass some on 1:1? Need to compare the (*f)(). 1366b4cac81SBjoern A. Zeeb */ 1376b4cac81SBjoern A. Zeeb }; 1386b4cac81SBjoern A. Zeeb 1396b4cac81SBjoern A. Zeeb static struct lkpi_sta *lkpi_find_lsta_by_ni(struct lkpi_vif *, 1406b4cac81SBjoern A. Zeeb struct ieee80211_node *); 1416b4cac81SBjoern A. Zeeb static void lkpi_80211_txq_task(void *, int); 1426b4cac81SBjoern A. Zeeb static void lkpi_ieee80211_free_skb_mbuf(void *); 1434a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 1444a67f1dfSBjoern A. Zeeb static int lkpi_wme_update(struct lkpi_hw *, struct ieee80211vap *, bool); 1454a67f1dfSBjoern A. Zeeb #endif 1466b4cac81SBjoern A. Zeeb 147d9f59799SBjoern A. Zeeb static void 14867674c1cSBjoern A. Zeeb lkpi_lsta_dump(struct lkpi_sta *lsta, struct ieee80211_node *ni, 14967674c1cSBjoern A. Zeeb const char *_f, int _l) 150d9f59799SBjoern A. Zeeb { 151d9f59799SBjoern A. Zeeb 1529d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 1539d9ba2b7SBjoern A. Zeeb if ((linuxkpi_debug_80211 & D80211_TRACE_STA) == 0) 154d9f59799SBjoern A. Zeeb return; 155d9f59799SBjoern A. Zeeb if (lsta == NULL) 156d9f59799SBjoern A. Zeeb return; 157d9f59799SBjoern A. Zeeb 158d9f59799SBjoern A. Zeeb printf("%s:%d lsta %p ni %p sta %p\n", 15967674c1cSBjoern A. Zeeb _f, _l, lsta, ni, &lsta->sta); 16067674c1cSBjoern A. Zeeb if (ni != NULL) 16167674c1cSBjoern A. Zeeb ieee80211_dump_node(NULL, ni); 162d9f59799SBjoern A. Zeeb printf("\ttxq_task txq len %d mtx\n", mbufq_len(&lsta->txq)); 163d9f59799SBjoern A. Zeeb printf("\tkc %p state %d added_to_drv %d in_mgd %d\n", 164d9f59799SBjoern A. Zeeb lsta->kc, lsta->state, lsta->added_to_drv, lsta->in_mgd); 1659d9ba2b7SBjoern A. Zeeb #endif 166d9f59799SBjoern A. Zeeb } 167d9f59799SBjoern A. Zeeb 168d9f59799SBjoern A. Zeeb static void 169d9f59799SBjoern A. Zeeb lkpi_lsta_remove(struct lkpi_sta *lsta, struct lkpi_vif *lvif) 170d9f59799SBjoern A. Zeeb { 171d9f59799SBjoern A. Zeeb struct ieee80211_node *ni; 172d9f59799SBjoern A. Zeeb 1733689f8aeSColin Percival IMPROVE("XXX-BZ remove tqe_prev check once ni-sta-state-sync is fixed"); 1743689f8aeSColin Percival 175d9f59799SBjoern A. Zeeb ni = lsta->ni; 176d9f59799SBjoern A. Zeeb 177d9f59799SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 1783689f8aeSColin Percival if (lsta->lsta_entry.tqe_prev != NULL) 179d9f59799SBjoern A. Zeeb TAILQ_REMOVE(&lvif->lsta_head, lsta, lsta_entry); 180d9f59799SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 181d9f59799SBjoern A. Zeeb 182d9f59799SBjoern A. Zeeb lsta->ni = NULL; 183d9f59799SBjoern A. Zeeb ni->ni_drv_data = NULL; 184e24e8103SBjoern A. Zeeb if (ni != NULL) 185d9f59799SBjoern A. Zeeb ieee80211_free_node(ni); 186d9f59799SBjoern A. Zeeb 187e24e8103SBjoern A. Zeeb IMPROVE("more from lkpi_ic_node_free() should happen here."); 188e24e8103SBjoern A. Zeeb 189e24e8103SBjoern A. Zeeb free(lsta, M_LKPI80211); 190d9f59799SBjoern A. Zeeb } 191d9f59799SBjoern A. Zeeb 1924f61ef8bSBjoern A. Zeeb static struct lkpi_sta * 1934f61ef8bSBjoern A. Zeeb lkpi_lsta_alloc(struct ieee80211vap *vap, const uint8_t mac[IEEE80211_ADDR_LEN], 1944f61ef8bSBjoern A. Zeeb struct ieee80211_hw *hw, struct ieee80211_node *ni) 1954f61ef8bSBjoern A. Zeeb { 1964f61ef8bSBjoern A. Zeeb struct lkpi_sta *lsta; 1974f61ef8bSBjoern A. Zeeb struct lkpi_vif *lvif; 1984f61ef8bSBjoern A. Zeeb struct ieee80211_vif *vif; 1994f61ef8bSBjoern A. Zeeb struct ieee80211_sta *sta; 200b6b352e4SBjoern A. Zeeb int band, i, tid; 2014f61ef8bSBjoern A. Zeeb 2024f61ef8bSBjoern A. Zeeb lsta = malloc(sizeof(*lsta) + hw->sta_data_size, M_LKPI80211, 2034f61ef8bSBjoern A. Zeeb M_NOWAIT | M_ZERO); 2044f61ef8bSBjoern A. Zeeb if (lsta == NULL) 2054f61ef8bSBjoern A. Zeeb return (NULL); 2064f61ef8bSBjoern A. Zeeb 2074f61ef8bSBjoern A. Zeeb lsta->added_to_drv = false; 2084f61ef8bSBjoern A. Zeeb lsta->state = IEEE80211_STA_NOTEXIST; 2094f61ef8bSBjoern A. Zeeb #if 0 2104f61ef8bSBjoern A. Zeeb /* 2114f61ef8bSBjoern A. Zeeb * This needs to be done in node_init() as ieee80211_alloc_node() 2124f61ef8bSBjoern A. Zeeb * will initialise the refcount after us. 2134f61ef8bSBjoern A. Zeeb */ 2144f61ef8bSBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 2154f61ef8bSBjoern A. Zeeb #endif 2164f61ef8bSBjoern A. Zeeb /* The back-pointer "drv_data" to net80211_node let's us get lsta. */ 2174f61ef8bSBjoern A. Zeeb ni->ni_drv_data = lsta; 2184f61ef8bSBjoern A. Zeeb 2194f61ef8bSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 2204f61ef8bSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 2214f61ef8bSBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 2224f61ef8bSBjoern A. Zeeb 2234f61ef8bSBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->addr, mac); 224b6b352e4SBjoern A. Zeeb 225b6b352e4SBjoern A. Zeeb /* TXQ */ 2264f61ef8bSBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 2274f61ef8bSBjoern A. Zeeb struct lkpi_txq *ltxq; 2284f61ef8bSBjoern A. Zeeb 229d0d29110SBjoern A. Zeeb /* We are not limiting ourselves to hw.queues here. */ 2304f61ef8bSBjoern A. Zeeb ltxq = malloc(sizeof(*ltxq) + hw->txq_data_size, 2314f61ef8bSBjoern A. Zeeb M_LKPI80211, M_NOWAIT | M_ZERO); 2324f61ef8bSBjoern A. Zeeb if (ltxq == NULL) 2334f61ef8bSBjoern A. Zeeb goto cleanup; 2344f61ef8bSBjoern A. Zeeb /* iwlwifi//mvm/sta.c::tid_to_mac80211_ac[] */ 2354f61ef8bSBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) { 236d0d29110SBjoern A. Zeeb if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ)) { 237d0d29110SBjoern A. Zeeb free(ltxq, M_LKPI80211); 238d0d29110SBjoern A. Zeeb continue; 239d0d29110SBjoern A. Zeeb } 240d0d29110SBjoern A. Zeeb IMPROVE("AP/if we support non-STA here too"); 2414f61ef8bSBjoern A. Zeeb ltxq->txq.ac = IEEE80211_AC_VO; 2424f61ef8bSBjoern A. Zeeb } else { 243fb3c249eSBjoern A. Zeeb ltxq->txq.ac = ieee80211e_up_to_ac[tid & 7]; 2444f61ef8bSBjoern A. Zeeb } 245d0d29110SBjoern A. Zeeb ltxq->seen_dequeue = false; 2460cbcfa19SBjoern A. Zeeb ltxq->stopped = false; 247d0d29110SBjoern A. Zeeb ltxq->txq.vif = vif; 2484f61ef8bSBjoern A. Zeeb ltxq->txq.tid = tid; 2494f61ef8bSBjoern A. Zeeb ltxq->txq.sta = sta; 2500cbcfa19SBjoern A. Zeeb TAILQ_ELEM_INIT(ltxq, txq_entry); 251d0d29110SBjoern A. Zeeb skb_queue_head_init(<xq->skbq); 2524f61ef8bSBjoern A. Zeeb sta->txq[tid] = <xq->txq; 2534f61ef8bSBjoern A. Zeeb } 2544f61ef8bSBjoern A. Zeeb 255b6b352e4SBjoern A. Zeeb /* Deflink information. */ 256b6b352e4SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 257b6b352e4SBjoern A. Zeeb struct ieee80211_supported_band *supband; 258b6b352e4SBjoern A. Zeeb 259b6b352e4SBjoern A. Zeeb supband = hw->wiphy->bands[band]; 260b6b352e4SBjoern A. Zeeb if (supband == NULL) 261b6b352e4SBjoern A. Zeeb continue; 262b6b352e4SBjoern A. Zeeb 263b6b352e4SBjoern A. Zeeb for (i = 0; i < supband->n_bitrates; i++) { 264b6b352e4SBjoern A. Zeeb 265b6b352e4SBjoern A. Zeeb IMPROVE("Further supband->bitrates[i]* checks?"); 266b6b352e4SBjoern A. Zeeb /* or should we get them from the ni? */ 267b6b352e4SBjoern A. Zeeb sta->deflink.supp_rates[band] |= BIT(i); 268b6b352e4SBjoern A. Zeeb } 269b6b352e4SBjoern A. Zeeb } 2706ffb7bd4SBjoern A. Zeeb sta->deflink.smps_mode = IEEE80211_SMPS_OFF; 271b6b352e4SBjoern A. Zeeb IMPROVE("ht, vht, he, ... bandwidth, smps_mode, .."); 272b6b352e4SBjoern A. Zeeb /* bandwidth = IEEE80211_STA_RX_... */ 273b6b352e4SBjoern A. Zeeb 2746ffb7bd4SBjoern A. Zeeb /* Link configuration. */ 2756ffb7bd4SBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->deflink.addr, sta->addr); 2766ffb7bd4SBjoern A. Zeeb sta->link[0] = &sta->deflink; 2776ffb7bd4SBjoern A. Zeeb for (i = 1; i < nitems(sta->link); i++) { 2786ffb7bd4SBjoern A. Zeeb IMPROVE("more links; only link[0] = deflink currently."); 2796ffb7bd4SBjoern A. Zeeb } 2806ffb7bd4SBjoern A. Zeeb 2814f61ef8bSBjoern A. Zeeb /* Deferred TX path. */ 2824f61ef8bSBjoern A. Zeeb mtx_init(&lsta->txq_mtx, "lsta_txq", NULL, MTX_DEF); 2834f61ef8bSBjoern A. Zeeb TASK_INIT(&lsta->txq_task, 0, lkpi_80211_txq_task, lsta); 2844f61ef8bSBjoern A. Zeeb mbufq_init(&lsta->txq, IFQ_MAXLEN); 2854f61ef8bSBjoern A. Zeeb 2864f61ef8bSBjoern A. Zeeb return (lsta); 2874f61ef8bSBjoern A. Zeeb 2884f61ef8bSBjoern A. Zeeb cleanup: 2894f61ef8bSBjoern A. Zeeb for (; tid >= 0; tid--) 2904f61ef8bSBjoern A. Zeeb free(sta->txq[tid], M_LKPI80211); 2914f61ef8bSBjoern A. Zeeb free(lsta, M_LKPI80211); 2924f61ef8bSBjoern A. Zeeb return (NULL); 2934f61ef8bSBjoern A. Zeeb } 2944f61ef8bSBjoern A. Zeeb 2956b4cac81SBjoern A. Zeeb static enum nl80211_band 2966b4cac81SBjoern A. Zeeb lkpi_net80211_chan_to_nl80211_band(struct ieee80211_channel *c) 2976b4cac81SBjoern A. Zeeb { 2986b4cac81SBjoern A. Zeeb 2996b4cac81SBjoern A. Zeeb if (IEEE80211_IS_CHAN_2GHZ(c)) 3006b4cac81SBjoern A. Zeeb return (NL80211_BAND_2GHZ); 3016b4cac81SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_5GHZ(c)) 3026b4cac81SBjoern A. Zeeb return (NL80211_BAND_5GHZ); 3036b4cac81SBjoern A. Zeeb #ifdef __notyet__ 3046b4cac81SBjoern A. Zeeb else if () 3056b4cac81SBjoern A. Zeeb return (NL80211_BAND_6GHZ); 3066b4cac81SBjoern A. Zeeb else if () 3076b4cac81SBjoern A. Zeeb return (NL80211_BAND_60GHZ); 3086b4cac81SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_GSM(c)) 3096b4cac81SBjoern A. Zeeb return (NL80211_BAND_XXX); 3106b4cac81SBjoern A. Zeeb #endif 3116b4cac81SBjoern A. Zeeb else 3126b4cac81SBjoern A. Zeeb panic("%s: unsupported band. c %p flags %#x\n", 3136b4cac81SBjoern A. Zeeb __func__, c, c->ic_flags); 3146b4cac81SBjoern A. Zeeb } 3156b4cac81SBjoern A. Zeeb 3166b4cac81SBjoern A. Zeeb static uint32_t 3176b4cac81SBjoern A. Zeeb lkpi_nl80211_band_to_net80211_band(enum nl80211_band band) 3186b4cac81SBjoern A. Zeeb { 3196b4cac81SBjoern A. Zeeb 3206b4cac81SBjoern A. Zeeb /* XXX-BZ this is just silly; net80211 is too convoluted. */ 3216b4cac81SBjoern A. Zeeb /* IEEE80211_CHAN_A / _G / .. doesn't really work either. */ 3226b4cac81SBjoern A. Zeeb switch (band) { 3236b4cac81SBjoern A. Zeeb case NL80211_BAND_2GHZ: 3246b4cac81SBjoern A. Zeeb return (IEEE80211_CHAN_2GHZ); 3256b4cac81SBjoern A. Zeeb break; 3266b4cac81SBjoern A. Zeeb case NL80211_BAND_5GHZ: 3276b4cac81SBjoern A. Zeeb return (IEEE80211_CHAN_5GHZ); 3286b4cac81SBjoern A. Zeeb break; 3296b4cac81SBjoern A. Zeeb case NL80211_BAND_60GHZ: 3306b4cac81SBjoern A. Zeeb break; 3316b4cac81SBjoern A. Zeeb case NL80211_BAND_6GHZ: 3326b4cac81SBjoern A. Zeeb break; 3336b4cac81SBjoern A. Zeeb default: 3346b4cac81SBjoern A. Zeeb panic("%s: unsupported band %u\n", __func__, band); 3356b4cac81SBjoern A. Zeeb break; 3366b4cac81SBjoern A. Zeeb } 3376b4cac81SBjoern A. Zeeb 3386b4cac81SBjoern A. Zeeb IMPROVE(); 3396b4cac81SBjoern A. Zeeb return (0x00); 3406b4cac81SBjoern A. Zeeb } 3416b4cac81SBjoern A. Zeeb 342e3a0b120SBjoern A. Zeeb #if 0 3436b4cac81SBjoern A. Zeeb static enum ieee80211_ac_numbers 3446b4cac81SBjoern A. Zeeb lkpi_ac_net_to_l80211(int ac) 3456b4cac81SBjoern A. Zeeb { 3466b4cac81SBjoern A. Zeeb 3476b4cac81SBjoern A. Zeeb switch (ac) { 3486b4cac81SBjoern A. Zeeb case WME_AC_VO: 3496b4cac81SBjoern A. Zeeb return (IEEE80211_AC_VO); 3506b4cac81SBjoern A. Zeeb case WME_AC_VI: 3516b4cac81SBjoern A. Zeeb return (IEEE80211_AC_VI); 3526b4cac81SBjoern A. Zeeb case WME_AC_BE: 3536b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BE); 3546b4cac81SBjoern A. Zeeb case WME_AC_BK: 3556b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BK); 3566b4cac81SBjoern A. Zeeb default: 3576b4cac81SBjoern A. Zeeb printf("%s: invalid WME_AC_* input: ac = %d\n", __func__, ac); 3586b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BE); 3596b4cac81SBjoern A. Zeeb } 3606b4cac81SBjoern A. Zeeb } 361e3a0b120SBjoern A. Zeeb #endif 3626b4cac81SBjoern A. Zeeb 3636b4cac81SBjoern A. Zeeb static enum nl80211_iftype 3646b4cac81SBjoern A. Zeeb lkpi_opmode_to_vif_type(enum ieee80211_opmode opmode) 3656b4cac81SBjoern A. Zeeb { 3666b4cac81SBjoern A. Zeeb 3676b4cac81SBjoern A. Zeeb switch (opmode) { 3686b4cac81SBjoern A. Zeeb case IEEE80211_M_IBSS: 3696b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_ADHOC); 3706b4cac81SBjoern A. Zeeb break; 3716b4cac81SBjoern A. Zeeb case IEEE80211_M_STA: 3726b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_STATION); 3736b4cac81SBjoern A. Zeeb break; 3746b4cac81SBjoern A. Zeeb case IEEE80211_M_WDS: 3756b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_WDS); 3766b4cac81SBjoern A. Zeeb break; 3776b4cac81SBjoern A. Zeeb case IEEE80211_M_HOSTAP: 3786b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_AP); 3796b4cac81SBjoern A. Zeeb break; 3806b4cac81SBjoern A. Zeeb case IEEE80211_M_MONITOR: 3816b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_MONITOR); 3826b4cac81SBjoern A. Zeeb break; 3836b4cac81SBjoern A. Zeeb case IEEE80211_M_MBSS: 3846b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_MESH_POINT); 3856b4cac81SBjoern A. Zeeb break; 3866b4cac81SBjoern A. Zeeb case IEEE80211_M_AHDEMO: 3876b4cac81SBjoern A. Zeeb /* FALLTHROUGH */ 3886b4cac81SBjoern A. Zeeb default: 3896b4cac81SBjoern A. Zeeb printf("ERROR: %s: unsupported opmode %d\n", __func__, opmode); 3906b4cac81SBjoern A. Zeeb /* FALLTHROUGH */ 3916b4cac81SBjoern A. Zeeb } 3926b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_UNSPECIFIED); 3936b4cac81SBjoern A. Zeeb } 3946b4cac81SBjoern A. Zeeb 395b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 3966b4cac81SBjoern A. Zeeb static uint32_t 3976b4cac81SBjoern A. Zeeb lkpi_l80211_to_net80211_cyphers(uint32_t wlan_cipher_suite) 3986b4cac81SBjoern A. Zeeb { 3996b4cac81SBjoern A. Zeeb 4006b4cac81SBjoern A. Zeeb switch (wlan_cipher_suite) { 4016b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP40: 4026b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_WEP); 4036b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP: 4046b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_TKIP); 4056b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP: 4066b4cac81SBjoern A. Zeeb return (IEEE80211_CIPHER_AES_CCM); 4076b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP104: 4086b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_WEP); 4096b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_AES_CMAC: 4106b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP: 4116b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP_256: 4126b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP_256: 4136b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_128: 4146b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_256: 4156b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_CMAC_256: 4166b4cac81SBjoern A. Zeeb printf("%s: unsupported WLAN Cipher Suite %#08x | %u\n", __func__, 4176b4cac81SBjoern A. Zeeb wlan_cipher_suite >> 8, wlan_cipher_suite & 0xff); 4186b4cac81SBjoern A. Zeeb break; 4196b4cac81SBjoern A. Zeeb default: 4206b4cac81SBjoern A. Zeeb printf("%s: unknown WLAN Cipher Suite %#08x | %u\n", __func__, 4216b4cac81SBjoern A. Zeeb wlan_cipher_suite >> 8, wlan_cipher_suite & 0xff); 4226b4cac81SBjoern A. Zeeb } 4236b4cac81SBjoern A. Zeeb 4246b4cac81SBjoern A. Zeeb return (0); 4256b4cac81SBjoern A. Zeeb } 4266b4cac81SBjoern A. Zeeb 4276b4cac81SBjoern A. Zeeb static uint32_t 4286b4cac81SBjoern A. Zeeb lkpi_net80211_to_l80211_cipher_suite(uint32_t cipher, uint8_t keylen) 4296b4cac81SBjoern A. Zeeb { 4306b4cac81SBjoern A. Zeeb 4316b4cac81SBjoern A. Zeeb switch (cipher) { 4326b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_TKIP: 4336b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_TKIP); 4346b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_AES_CCM: 4356b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_CCMP); 4366b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_WEP: 4376b4cac81SBjoern A. Zeeb if (keylen < 8) 4386b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_WEP40); 4396b4cac81SBjoern A. Zeeb else 4406b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_WEP104); 4416b4cac81SBjoern A. Zeeb break; 4426b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_AES_OCB: 4436b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_TKIPMIC: 4446b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_CKIP: 4456b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_NONE: 4466b4cac81SBjoern A. Zeeb printf("%s: unsupported cipher %#010x\n", __func__, cipher); 4476b4cac81SBjoern A. Zeeb break; 4486b4cac81SBjoern A. Zeeb default: 4496b4cac81SBjoern A. Zeeb printf("%s: unknown cipher %#010x\n", __func__, cipher); 4506b4cac81SBjoern A. Zeeb }; 4516b4cac81SBjoern A. Zeeb return (0); 4526b4cac81SBjoern A. Zeeb } 4536b4cac81SBjoern A. Zeeb #endif 4546b4cac81SBjoern A. Zeeb 4556b4cac81SBjoern A. Zeeb #ifdef __notyet__ 4566b4cac81SBjoern A. Zeeb static enum ieee80211_sta_state 4576b4cac81SBjoern A. Zeeb lkpi_net80211_state_to_sta_state(enum ieee80211_state state) 4586b4cac81SBjoern A. Zeeb { 4596b4cac81SBjoern A. Zeeb 4606b4cac81SBjoern A. Zeeb /* 4616b4cac81SBjoern A. Zeeb * XXX-BZ The net80211 states are "try to ..", the lkpi8011 states are 4626b4cac81SBjoern A. Zeeb * "done". Also ASSOC/AUTHORIZED are both "RUN" then? 4636b4cac81SBjoern A. Zeeb */ 4646b4cac81SBjoern A. Zeeb switch (state) { 4656b4cac81SBjoern A. Zeeb case IEEE80211_S_INIT: 4666b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NOTEXIST); 4676b4cac81SBjoern A. Zeeb case IEEE80211_S_SCAN: 4686b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NONE); 4696b4cac81SBjoern A. Zeeb case IEEE80211_S_AUTH: 4706b4cac81SBjoern A. Zeeb return (IEEE80211_STA_AUTH); 4716b4cac81SBjoern A. Zeeb case IEEE80211_S_ASSOC: 4726b4cac81SBjoern A. Zeeb return (IEEE80211_STA_ASSOC); 4736b4cac81SBjoern A. Zeeb case IEEE80211_S_RUN: 4746b4cac81SBjoern A. Zeeb return (IEEE80211_STA_AUTHORIZED); 4756b4cac81SBjoern A. Zeeb case IEEE80211_S_CAC: 4766b4cac81SBjoern A. Zeeb case IEEE80211_S_CSA: 4776b4cac81SBjoern A. Zeeb case IEEE80211_S_SLEEP: 4786b4cac81SBjoern A. Zeeb default: 4796b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 4806b4cac81SBjoern A. Zeeb }; 4816b4cac81SBjoern A. Zeeb 4826b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NOTEXIST); 4836b4cac81SBjoern A. Zeeb } 4846b4cac81SBjoern A. Zeeb #endif 4856b4cac81SBjoern A. Zeeb 4866b4cac81SBjoern A. Zeeb static struct linuxkpi_ieee80211_channel * 4876b4cac81SBjoern A. Zeeb lkpi_find_lkpi80211_chan(struct lkpi_hw *lhw, 4886b4cac81SBjoern A. Zeeb struct ieee80211_channel *c) 4896b4cac81SBjoern A. Zeeb { 4906b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 4916b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 4926b4cac81SBjoern A. Zeeb enum nl80211_band band; 4936b4cac81SBjoern A. Zeeb int i, nchans; 4946b4cac81SBjoern A. Zeeb 4956b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 4966b4cac81SBjoern A. Zeeb band = lkpi_net80211_chan_to_nl80211_band(c); 4976b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[band] == NULL) 4986b4cac81SBjoern A. Zeeb return (NULL); 4996b4cac81SBjoern A. Zeeb 5006b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[band]->n_channels; 5016b4cac81SBjoern A. Zeeb if (nchans <= 0) 5026b4cac81SBjoern A. Zeeb return (NULL); 5036b4cac81SBjoern A. Zeeb 5046b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[band]->channels; 5056b4cac81SBjoern A. Zeeb for (i = 0; i < nchans; i++) { 5066b4cac81SBjoern A. Zeeb if (channels[i].hw_value == c->ic_ieee) 5076b4cac81SBjoern A. Zeeb return (&channels[i]); 5086b4cac81SBjoern A. Zeeb } 5096b4cac81SBjoern A. Zeeb 5106b4cac81SBjoern A. Zeeb return (NULL); 5116b4cac81SBjoern A. Zeeb } 5126b4cac81SBjoern A. Zeeb 5136b4cac81SBjoern A. Zeeb static struct linuxkpi_ieee80211_channel * 5146b4cac81SBjoern A. Zeeb lkpi_get_lkpi80211_chan(struct ieee80211com *ic, struct ieee80211_node *ni) 5156b4cac81SBjoern A. Zeeb { 5166b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 5176b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 5186b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 5196b4cac81SBjoern A. Zeeb 5206b4cac81SBjoern A. Zeeb chan = NULL; 5216b4cac81SBjoern A. Zeeb if (ni != NULL && ni->ni_chan != IEEE80211_CHAN_ANYC) 5226b4cac81SBjoern A. Zeeb c = ni->ni_chan; 5236b4cac81SBjoern A. Zeeb else if (ic->ic_bsschan != IEEE80211_CHAN_ANYC) 5246b4cac81SBjoern A. Zeeb c = ic->ic_bsschan; 5256b4cac81SBjoern A. Zeeb else if (ic->ic_curchan != IEEE80211_CHAN_ANYC) 5266b4cac81SBjoern A. Zeeb c = ic->ic_curchan; 5276b4cac81SBjoern A. Zeeb else 5286b4cac81SBjoern A. Zeeb c = NULL; 5296b4cac81SBjoern A. Zeeb 5306b4cac81SBjoern A. Zeeb if (c != NULL && c != IEEE80211_CHAN_ANYC) { 5316b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 5326b4cac81SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, c); 5336b4cac81SBjoern A. Zeeb } 5346b4cac81SBjoern A. Zeeb 5356b4cac81SBjoern A. Zeeb return (chan); 5366b4cac81SBjoern A. Zeeb } 5376b4cac81SBjoern A. Zeeb 5382e183d99SBjoern A. Zeeb struct linuxkpi_ieee80211_channel * 5392e183d99SBjoern A. Zeeb linuxkpi_ieee80211_get_channel(struct wiphy *wiphy, uint32_t freq) 5402e183d99SBjoern A. Zeeb { 5412e183d99SBjoern A. Zeeb enum nl80211_band band; 5422e183d99SBjoern A. Zeeb 5432e183d99SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 5442e183d99SBjoern A. Zeeb struct ieee80211_supported_band *supband; 5452e183d99SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 5462e183d99SBjoern A. Zeeb int i; 5472e183d99SBjoern A. Zeeb 5482e183d99SBjoern A. Zeeb supband = wiphy->bands[band]; 5492e183d99SBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 5502e183d99SBjoern A. Zeeb continue; 5512e183d99SBjoern A. Zeeb 5522e183d99SBjoern A. Zeeb channels = supband->channels; 5532e183d99SBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 5542e183d99SBjoern A. Zeeb if (channels[i].center_freq == freq) 5552e183d99SBjoern A. Zeeb return (&channels[i]); 5562e183d99SBjoern A. Zeeb } 5572e183d99SBjoern A. Zeeb } 5582e183d99SBjoern A. Zeeb 5592e183d99SBjoern A. Zeeb return (NULL); 5602e183d99SBjoern A. Zeeb } 5612e183d99SBjoern A. Zeeb 562b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 5636b4cac81SBjoern A. Zeeb static int 5646b4cac81SBjoern A. Zeeb _lkpi_iv_key_set_delete(struct ieee80211vap *vap, const struct ieee80211_key *k, 5656b4cac81SBjoern A. Zeeb enum set_key_cmd cmd) 5666b4cac81SBjoern A. Zeeb { 5676b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 5686b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 5696b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 5706b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 5716b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 5726b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 5736b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 5746b4cac81SBjoern A. Zeeb struct ieee80211_key_conf *kc; 5756b4cac81SBjoern A. Zeeb int error; 5766b4cac81SBjoern A. Zeeb 5776b4cac81SBjoern A. Zeeb /* XXX TODO Check (k->wk_flags & IEEE80211_KEY_SWENCRYPT) and don't upload to driver/hw? */ 5786b4cac81SBjoern A. Zeeb 5796b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 5806b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 5816b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 5826b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 5836b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 5846b4cac81SBjoern A. Zeeb 5856b4cac81SBjoern A. Zeeb memset(&kc, 0, sizeof(kc)); 5866b4cac81SBjoern A. Zeeb kc = malloc(sizeof(*kc) + k->wk_keylen, M_LKPI80211, M_WAITOK | M_ZERO); 5876b4cac81SBjoern A. Zeeb kc->cipher = lkpi_net80211_to_l80211_cipher_suite( 5886b4cac81SBjoern A. Zeeb k->wk_cipher->ic_cipher, k->wk_keylen); 5896b4cac81SBjoern A. Zeeb kc->keyidx = k->wk_keyix; 5906b4cac81SBjoern A. Zeeb #if 0 5916b4cac81SBjoern A. Zeeb kc->hw_key_idx = /* set by hw and needs to be passed for TX */; 5926b4cac81SBjoern A. Zeeb #endif 5936b4cac81SBjoern A. Zeeb atomic64_set(&kc->tx_pn, k->wk_keytsc); 5946b4cac81SBjoern A. Zeeb kc->keylen = k->wk_keylen; 5956b4cac81SBjoern A. Zeeb memcpy(kc->key, k->wk_key, k->wk_keylen); 5966b4cac81SBjoern A. Zeeb 5976b4cac81SBjoern A. Zeeb switch (kc->cipher) { 5986b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP: 5996b4cac81SBjoern A. Zeeb kc->iv_len = k->wk_cipher->ic_header; 6006b4cac81SBjoern A. Zeeb kc->icv_len = k->wk_cipher->ic_trailer; 6016b4cac81SBjoern A. Zeeb break; 6026b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP: 6036b4cac81SBjoern A. Zeeb default: 6046b4cac81SBjoern A. Zeeb IMPROVE(); 6056b4cac81SBjoern A. Zeeb return (0); 6066b4cac81SBjoern A. Zeeb }; 6076b4cac81SBjoern A. Zeeb 6086b4cac81SBjoern A. Zeeb ni = vap->iv_bss; 6096b4cac81SBjoern A. Zeeb sta = ieee80211_find_sta(vif, ni->ni_bssid); 6106b4cac81SBjoern A. Zeeb if (sta != NULL) { 6116b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 6126b4cac81SBjoern A. Zeeb 6136b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 6146b4cac81SBjoern A. Zeeb lsta->kc = kc; 6156b4cac81SBjoern A. Zeeb } 6166b4cac81SBjoern A. Zeeb 6176b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_set_key(hw, cmd, vif, sta, kc); 6186b4cac81SBjoern A. Zeeb if (error != 0) { 6196b4cac81SBjoern A. Zeeb /* XXX-BZ leaking kc currently */ 6206b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: set_key failed: %d\n", __func__, error); 6216b4cac81SBjoern A. Zeeb return (0); 6226b4cac81SBjoern A. Zeeb } else { 6236b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: set_key succeeded: keyidx %u hw_key_idx %u " 6246b4cac81SBjoern A. Zeeb "flags %#10x\n", __func__, 6256b4cac81SBjoern A. Zeeb kc->keyidx, kc->hw_key_idx, kc->flags); 6266b4cac81SBjoern A. Zeeb return (1); 6276b4cac81SBjoern A. Zeeb } 6286b4cac81SBjoern A. Zeeb } 6296b4cac81SBjoern A. Zeeb 6306b4cac81SBjoern A. Zeeb static int 6316b4cac81SBjoern A. Zeeb lkpi_iv_key_delete(struct ieee80211vap *vap, const struct ieee80211_key *k) 6326b4cac81SBjoern A. Zeeb { 6336b4cac81SBjoern A. Zeeb 6346b4cac81SBjoern A. Zeeb /* XXX-BZ one day we should replace this iterating over VIFs, or node list? */ 6356b4cac81SBjoern A. Zeeb return (_lkpi_iv_key_set_delete(vap, k, DISABLE_KEY)); 6366b4cac81SBjoern A. Zeeb } 6376b4cac81SBjoern A. Zeeb static int 6386b4cac81SBjoern A. Zeeb lkpi_iv_key_set(struct ieee80211vap *vap, const struct ieee80211_key *k) 6396b4cac81SBjoern A. Zeeb { 6406b4cac81SBjoern A. Zeeb 6416b4cac81SBjoern A. Zeeb return (_lkpi_iv_key_set_delete(vap, k, SET_KEY)); 6426b4cac81SBjoern A. Zeeb } 6436b4cac81SBjoern A. Zeeb #endif 6446b4cac81SBjoern A. Zeeb 6456b4cac81SBjoern A. Zeeb static u_int 6466b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast_copy(void *arg, struct sockaddr_dl *sdl, u_int cnt) 6476b4cac81SBjoern A. Zeeb { 6486b4cac81SBjoern A. Zeeb struct netdev_hw_addr_list *mc_list; 6496b4cac81SBjoern A. Zeeb struct netdev_hw_addr *addr; 6506b4cac81SBjoern A. Zeeb 6516b4cac81SBjoern A. Zeeb KASSERT(arg != NULL && sdl != NULL, ("%s: arg %p sdl %p cnt %u\n", 6526b4cac81SBjoern A. Zeeb __func__, arg, sdl, cnt)); 6536b4cac81SBjoern A. Zeeb 6546b4cac81SBjoern A. Zeeb mc_list = arg; 6556b4cac81SBjoern A. Zeeb /* If it is on the list already skip it. */ 6566b4cac81SBjoern A. Zeeb netdev_hw_addr_list_for_each(addr, mc_list) { 6576b4cac81SBjoern A. Zeeb if (!memcmp(addr->addr, LLADDR(sdl), sdl->sdl_alen)) 6586b4cac81SBjoern A. Zeeb return (0); 6596b4cac81SBjoern A. Zeeb } 6606b4cac81SBjoern A. Zeeb 6616b4cac81SBjoern A. Zeeb addr = malloc(sizeof(*addr), M_LKPI80211, M_NOWAIT | M_ZERO); 6626b4cac81SBjoern A. Zeeb if (addr == NULL) 6636b4cac81SBjoern A. Zeeb return (0); 6646b4cac81SBjoern A. Zeeb 6656b4cac81SBjoern A. Zeeb INIT_LIST_HEAD(&addr->addr_list); 6666b4cac81SBjoern A. Zeeb memcpy(addr->addr, LLADDR(sdl), sdl->sdl_alen); 6676b4cac81SBjoern A. Zeeb /* XXX this should be a netdev function? */ 6686b4cac81SBjoern A. Zeeb list_add(&addr->addr_list, &mc_list->addr_list); 6696b4cac81SBjoern A. Zeeb mc_list->count++; 6706b4cac81SBjoern A. Zeeb 6719d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 6729d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 6736b4cac81SBjoern A. Zeeb printf("%s:%d: mc_list count %d: added %6D\n", 6746b4cac81SBjoern A. Zeeb __func__, __LINE__, mc_list->count, addr->addr, ":"); 6759d9ba2b7SBjoern A. Zeeb #endif 6766b4cac81SBjoern A. Zeeb 6776b4cac81SBjoern A. Zeeb return (1); 6786b4cac81SBjoern A. Zeeb } 6796b4cac81SBjoern A. Zeeb 6806b4cac81SBjoern A. Zeeb static void 6816b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(struct ieee80211com *ic, bool force) 6826b4cac81SBjoern A. Zeeb { 6836b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 6846b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 6856b4cac81SBjoern A. Zeeb struct netdev_hw_addr_list mc_list; 6866b4cac81SBjoern A. Zeeb struct list_head *le, *next; 6876b4cac81SBjoern A. Zeeb struct netdev_hw_addr *addr; 6886b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 6896b4cac81SBjoern A. Zeeb u64 mc; 6906b4cac81SBjoern A. Zeeb unsigned int changed_flags, total_flags; 6916b4cac81SBjoern A. Zeeb 6926b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 6936b4cac81SBjoern A. Zeeb 6946b4cac81SBjoern A. Zeeb if (lhw->ops->prepare_multicast == NULL || 6956b4cac81SBjoern A. Zeeb lhw->ops->configure_filter == NULL) 6966b4cac81SBjoern A. Zeeb return; 6976b4cac81SBjoern A. Zeeb 6986b4cac81SBjoern A. Zeeb if (!lhw->update_mc && !force) 6996b4cac81SBjoern A. Zeeb return; 7006b4cac81SBjoern A. Zeeb 7016b4cac81SBjoern A. Zeeb changed_flags = total_flags = 0; 7026b4cac81SBjoern A. Zeeb mc_list.count = 0; 7036b4cac81SBjoern A. Zeeb INIT_LIST_HEAD(&mc_list.addr_list); 7046b4cac81SBjoern A. Zeeb if (ic->ic_allmulti == 0) { 7056b4cac81SBjoern A. Zeeb TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) 7066b4cac81SBjoern A. Zeeb if_foreach_llmaddr(vap->iv_ifp, 7076b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast_copy, &mc_list); 7086b4cac81SBjoern A. Zeeb } else { 7096b4cac81SBjoern A. Zeeb changed_flags |= FIF_ALLMULTI; 7106b4cac81SBjoern A. Zeeb } 7116b4cac81SBjoern A. Zeeb 7126b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 7136b4cac81SBjoern A. Zeeb mc = lkpi_80211_mo_prepare_multicast(hw, &mc_list); 7146b4cac81SBjoern A. Zeeb /* 7156b4cac81SBjoern A. Zeeb * XXX-BZ make sure to get this sorted what is a change, 7166b4cac81SBjoern A. Zeeb * what gets all set; what was already set? 7176b4cac81SBjoern A. Zeeb */ 7186b4cac81SBjoern A. Zeeb total_flags = changed_flags; 7196b4cac81SBjoern A. Zeeb lkpi_80211_mo_configure_filter(hw, changed_flags, &total_flags, mc); 7206b4cac81SBjoern A. Zeeb 7219d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 7229d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 7236b4cac81SBjoern A. Zeeb printf("%s: changed_flags %#06x count %d total_flags %#010x\n", 7246b4cac81SBjoern A. Zeeb __func__, changed_flags, mc_list.count, total_flags); 7259d9ba2b7SBjoern A. Zeeb #endif 7266b4cac81SBjoern A. Zeeb 7276b4cac81SBjoern A. Zeeb if (mc_list.count != 0) { 7286b4cac81SBjoern A. Zeeb list_for_each_safe(le, next, &mc_list.addr_list) { 7296b4cac81SBjoern A. Zeeb addr = list_entry(le, struct netdev_hw_addr, addr_list); 7306b4cac81SBjoern A. Zeeb free(addr, M_LKPI80211); 7316b4cac81SBjoern A. Zeeb mc_list.count--; 7326b4cac81SBjoern A. Zeeb } 7336b4cac81SBjoern A. Zeeb } 7346b4cac81SBjoern A. Zeeb KASSERT(mc_list.count == 0, ("%s: mc_list %p count %d != 0\n", 7356b4cac81SBjoern A. Zeeb __func__, &mc_list, mc_list.count)); 7366b4cac81SBjoern A. Zeeb } 7376b4cac81SBjoern A. Zeeb 738fa8f007dSBjoern A. Zeeb static enum ieee80211_bss_changed 739fa8f007dSBjoern A. Zeeb lkpi_update_dtim_tsf(struct ieee80211_vif *vif, struct ieee80211_node *ni, 740fa8f007dSBjoern A. Zeeb struct ieee80211vap *vap, const char *_f, int _l) 741fa8f007dSBjoern A. Zeeb { 742fa8f007dSBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 743fa8f007dSBjoern A. Zeeb 744fa8f007dSBjoern A. Zeeb bss_changed = 0; 745fa8f007dSBjoern A. Zeeb 7469d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 7479d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 748fa8f007dSBjoern A. Zeeb printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u " 749fa8f007dSBjoern A. Zeeb "dtim_period %u sync_dtim_count %u sync_tsf %ju " 750fa8f007dSBjoern A. Zeeb "sync_device_ts %u bss_changed %#08x\n", 751fa8f007dSBjoern A. Zeeb __func__, __LINE__, _f, _l, 752616e1330SBjoern A. Zeeb vif->cfg.assoc, vif->cfg.aid, 753fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int, vif->bss_conf.dtim_period, 754fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count, 755fa8f007dSBjoern A. Zeeb (uintmax_t)vif->bss_conf.sync_tsf, 756fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_device_ts, 757fa8f007dSBjoern A. Zeeb bss_changed); 7589d9ba2b7SBjoern A. Zeeb #endif 759fa8f007dSBjoern A. Zeeb 760fa8f007dSBjoern A. Zeeb if (vif->bss_conf.beacon_int != ni->ni_intval) { 761fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int = ni->ni_intval; 762fa8f007dSBjoern A. Zeeb /* iwlwifi FW bug workaround; iwl_mvm_mac_sta_state. */ 763fa8f007dSBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16) 764fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int = 16; 765fa8f007dSBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INT; 766fa8f007dSBjoern A. Zeeb } 767fa8f007dSBjoern A. Zeeb if (vif->bss_conf.dtim_period != vap->iv_dtim_period && 768fa8f007dSBjoern A. Zeeb vap->iv_dtim_period > 0) { 769fa8f007dSBjoern A. Zeeb vif->bss_conf.dtim_period = vap->iv_dtim_period; 770fa8f007dSBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INFO; 771fa8f007dSBjoern A. Zeeb } 772fa8f007dSBjoern A. Zeeb 773fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count = vap->iv_dtim_count; 774fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_tsf = le64toh(ni->ni_tstamp.tsf); 775fa8f007dSBjoern A. Zeeb /* vif->bss_conf.sync_device_ts = set in linuxkpi_ieee80211_rx. */ 776fa8f007dSBjoern A. Zeeb 7779d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 7789d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 779fa8f007dSBjoern A. Zeeb printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u " 780fa8f007dSBjoern A. Zeeb "dtim_period %u sync_dtim_count %u sync_tsf %ju " 781fa8f007dSBjoern A. Zeeb "sync_device_ts %u bss_changed %#08x\n", 782fa8f007dSBjoern A. Zeeb __func__, __LINE__, _f, _l, 783616e1330SBjoern A. Zeeb vif->cfg.assoc, vif->cfg.aid, 784fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int, vif->bss_conf.dtim_period, 785fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count, 786fa8f007dSBjoern A. Zeeb (uintmax_t)vif->bss_conf.sync_tsf, 787fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_device_ts, 788fa8f007dSBjoern A. Zeeb bss_changed); 7899d9ba2b7SBjoern A. Zeeb #endif 790fa8f007dSBjoern A. Zeeb 791fa8f007dSBjoern A. Zeeb return (bss_changed); 792fa8f007dSBjoern A. Zeeb } 793fa8f007dSBjoern A. Zeeb 7946b4cac81SBjoern A. Zeeb static void 7956b4cac81SBjoern A. Zeeb lkpi_stop_hw_scan(struct lkpi_hw *lhw, struct ieee80211_vif *vif) 7966b4cac81SBjoern A. Zeeb { 7976b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 7986b4cac81SBjoern A. Zeeb int error; 7998ac540d3SBjoern A. Zeeb bool cancel; 8006b4cac81SBjoern A. Zeeb 8018ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 8028ac540d3SBjoern A. Zeeb cancel = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0; 8038ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 8048ac540d3SBjoern A. Zeeb if (!cancel) 8056b4cac81SBjoern A. Zeeb return; 8066b4cac81SBjoern A. Zeeb 8076b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 8086b4cac81SBjoern A. Zeeb 809bec76628SBjoern A. Zeeb IEEE80211_UNLOCK(lhw->ic); 810bec76628SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 8116b4cac81SBjoern A. Zeeb /* Need to cancel the scan. */ 8126b4cac81SBjoern A. Zeeb lkpi_80211_mo_cancel_hw_scan(hw, vif); 8138ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 8146b4cac81SBjoern A. Zeeb 8156b4cac81SBjoern A. Zeeb /* Need to make sure we see ieee80211_scan_completed. */ 8168ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 8178ac540d3SBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) 8188ac540d3SBjoern A. Zeeb error = msleep(lhw, &lhw->scan_mtx, 0, "lhwscanstop", hz/2); 8198ac540d3SBjoern A. Zeeb cancel = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0; 8208ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 8218ac540d3SBjoern A. Zeeb 822bec76628SBjoern A. Zeeb IEEE80211_LOCK(lhw->ic); 8236b4cac81SBjoern A. Zeeb 8248ac540d3SBjoern A. Zeeb if (cancel) 8256b4cac81SBjoern A. Zeeb ic_printf(lhw->ic, "%s: failed to cancel scan: %d (%p, %p)\n", 8266b4cac81SBjoern A. Zeeb __func__, error, lhw, vif); 8276b4cac81SBjoern A. Zeeb } 8286b4cac81SBjoern A. Zeeb 8296b4cac81SBjoern A. Zeeb static void 830086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(struct ieee80211_hw *hw, bool new) 831086be6a8SBjoern A. Zeeb { 832086be6a8SBjoern A. Zeeb struct lkpi_hw *lhw; 833086be6a8SBjoern A. Zeeb int error; 834086be6a8SBjoern A. Zeeb bool old; 835086be6a8SBjoern A. Zeeb 836086be6a8SBjoern A. Zeeb old = hw->conf.flags & IEEE80211_CONF_IDLE; 837086be6a8SBjoern A. Zeeb if (old == new) 838086be6a8SBjoern A. Zeeb return; 839086be6a8SBjoern A. Zeeb 840086be6a8SBjoern A. Zeeb hw->conf.flags ^= IEEE80211_CONF_IDLE; 841086be6a8SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_IDLE); 842086be6a8SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) { 843086be6a8SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 844086be6a8SBjoern A. Zeeb ic_printf(lhw->ic, "ERROR: %s: config %#0x returned %d\n", 845086be6a8SBjoern A. Zeeb __func__, IEEE80211_CONF_CHANGE_IDLE, error); 846086be6a8SBjoern A. Zeeb } 847086be6a8SBjoern A. Zeeb } 848086be6a8SBjoern A. Zeeb 849086be6a8SBjoern A. Zeeb static void 8506b4cac81SBjoern A. Zeeb lkpi_disassoc(struct ieee80211_sta *sta, struct ieee80211_vif *vif, 8516b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw) 8526b4cac81SBjoern A. Zeeb { 8536b4cac81SBjoern A. Zeeb sta->aid = 0; 854616e1330SBjoern A. Zeeb if (vif->cfg.assoc) { 8556b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 8566b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 8576b4cac81SBjoern A. Zeeb 8586b4cac81SBjoern A. Zeeb lhw->update_mc = true; 8596b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(lhw->ic, true); 8606b4cac81SBjoern A. Zeeb 8616b4cac81SBjoern A. Zeeb changed = 0; 862616e1330SBjoern A. Zeeb vif->cfg.assoc = false; 863616e1330SBjoern A. Zeeb vif->cfg.aid = 0; 8646b4cac81SBjoern A. Zeeb changed |= BSS_CHANGED_ASSOC; 865d9f59799SBjoern A. Zeeb /* 866d9f59799SBjoern A. Zeeb * This will remove the sta from firmware for iwlwifi. 867d9f59799SBjoern A. Zeeb * So confusing that they use state and flags and ... ^%$%#%$^. 868d9f59799SBjoern A. Zeeb */ 8696b4cac81SBjoern A. Zeeb IMPROVE(); 8706b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 8716b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, 8726b4cac81SBjoern A. Zeeb changed); 873086be6a8SBjoern A. Zeeb 874086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true); 8756b4cac81SBjoern A. Zeeb } 8766b4cac81SBjoern A. Zeeb } 8776b4cac81SBjoern A. Zeeb 8786b4cac81SBjoern A. Zeeb static void 8796b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(struct ieee80211_hw *hw, struct ieee80211_sta *sta, 8806b4cac81SBjoern A. Zeeb bool dequeue_seen, bool no_emptyq) 8816b4cac81SBjoern A. Zeeb { 8826b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 8836b4cac81SBjoern A. Zeeb int tid; 8846b4cac81SBjoern A. Zeeb 8856b4cac81SBjoern A. Zeeb /* Wake up all queues to know they are allocated in the driver. */ 8866b4cac81SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 8876b4cac81SBjoern A. Zeeb 8886b4cac81SBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) { 8896b4cac81SBjoern A. Zeeb IMPROVE("station specific?"); 8906b4cac81SBjoern A. Zeeb if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ)) 8916b4cac81SBjoern A. Zeeb continue; 8926b4cac81SBjoern A. Zeeb } else if (tid >= hw->queues) 8936b4cac81SBjoern A. Zeeb continue; 8946b4cac81SBjoern A. Zeeb 8956b4cac81SBjoern A. Zeeb if (sta->txq[tid] == NULL) 8966b4cac81SBjoern A. Zeeb continue; 8976b4cac81SBjoern A. Zeeb 8986b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]); 8996b4cac81SBjoern A. Zeeb if (dequeue_seen && !ltxq->seen_dequeue) 9006b4cac81SBjoern A. Zeeb continue; 9016b4cac81SBjoern A. Zeeb 9026b4cac81SBjoern A. Zeeb if (no_emptyq && skb_queue_empty(<xq->skbq)) 9036b4cac81SBjoern A. Zeeb continue; 9046b4cac81SBjoern A. Zeeb 9056b4cac81SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, sta->txq[tid]); 9066b4cac81SBjoern A. Zeeb } 9076b4cac81SBjoern A. Zeeb } 9086b4cac81SBjoern A. Zeeb 9096b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 9106b4cac81SBjoern A. Zeeb 9116b4cac81SBjoern A. Zeeb static int 9126b4cac81SBjoern A. Zeeb lkpi_sta_state_do_nada(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 9136b4cac81SBjoern A. Zeeb { 9146b4cac81SBjoern A. Zeeb 9156b4cac81SBjoern A. Zeeb return (0); 9166b4cac81SBjoern A. Zeeb } 9176b4cac81SBjoern A. Zeeb 9186b4cac81SBjoern A. Zeeb /* lkpi_iv_newstate() handles the stop scan case generally. */ 9196b4cac81SBjoern A. Zeeb #define lkpi_sta_scan_to_init(_v, _n, _a) lkpi_sta_state_do_nada(_v, _n, _a) 9206b4cac81SBjoern A. Zeeb 9216b4cac81SBjoern A. Zeeb static int 9226b4cac81SBjoern A. Zeeb lkpi_sta_scan_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 9236b4cac81SBjoern A. Zeeb { 9246b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 925c5e25798SBjoern A. Zeeb struct lkpi_chanctx *lchanctx; 9266b4cac81SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 9276b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 9286b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 9296b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 9306b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 9316b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 9326b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 9336b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 9346b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 9356b4cac81SBjoern A. Zeeb uint32_t changed; 9366b4cac81SBjoern A. Zeeb int error; 9376b4cac81SBjoern A. Zeeb 9386b4cac81SBjoern A. Zeeb chan = lkpi_get_lkpi80211_chan(vap->iv_ic, vap->iv_bss); 9396b4cac81SBjoern A. Zeeb if (chan == NULL) { 9406b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: failed to get channel\n", __func__); 9416b4cac81SBjoern A. Zeeb return (ESRCH); 9426b4cac81SBjoern A. Zeeb } 9436b4cac81SBjoern A. Zeeb 9446b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 9456b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 9466b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 9476b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 9486b4cac81SBjoern A. Zeeb 949d9f59799SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 950d9f59799SBjoern A. Zeeb 9516b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 9528ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 9536b4cac81SBjoern A. Zeeb 9546b4cac81SBjoern A. Zeeb /* Add chanctx (or if exists, change it). */ 9556b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 9566b4cac81SBjoern A. Zeeb conf = vif->chanctx_conf; 957c5e25798SBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(conf); 9586b4cac81SBjoern A. Zeeb IMPROVE("diff changes for changed, working on live copy, rcu"); 9596b4cac81SBjoern A. Zeeb } else { 9606b4cac81SBjoern A. Zeeb /* Keep separate alloc as in Linux this is rcu managed? */ 961c5e25798SBjoern A. Zeeb lchanctx = malloc(sizeof(*lchanctx) + hw->chanctx_data_size, 9626b4cac81SBjoern A. Zeeb M_LKPI80211, M_WAITOK | M_ZERO); 963c5e25798SBjoern A. Zeeb conf = &lchanctx->conf; 9646b4cac81SBjoern A. Zeeb } 9656b4cac81SBjoern A. Zeeb 9666b4cac81SBjoern A. Zeeb conf->rx_chains_dynamic = 1; 9676b4cac81SBjoern A. Zeeb conf->rx_chains_static = 1; 9686b4cac81SBjoern A. Zeeb conf->radar_enabled = 9696b4cac81SBjoern A. Zeeb (chan->flags & IEEE80211_CHAN_RADAR) ? true : false; 9706b4cac81SBjoern A. Zeeb conf->def.chan = chan; 9716b4cac81SBjoern A. Zeeb conf->def.width = NL80211_CHAN_WIDTH_20_NOHT; 9726b4cac81SBjoern A. Zeeb conf->def.center_freq1 = chan->center_freq; 9736b4cac81SBjoern A. Zeeb conf->def.center_freq2 = 0; 9746b4cac81SBjoern A. Zeeb /* Responder ... */ 9756b4cac81SBjoern A. Zeeb conf->min_def.chan = chan; 9766b4cac81SBjoern A. Zeeb conf->min_def.width = NL80211_CHAN_WIDTH_20_NOHT; 9776b4cac81SBjoern A. Zeeb conf->min_def.center_freq1 = chan->center_freq; 9786b4cac81SBjoern A. Zeeb conf->min_def.center_freq2 = 0; 9796b4cac81SBjoern A. Zeeb IMPROVE("currently 20_NOHT only"); 9806b4cac81SBjoern A. Zeeb 9816ffb7bd4SBjoern A. Zeeb /* Set bss info (bss_info_changed). */ 9826ffb7bd4SBjoern A. Zeeb bss_changed = 0; 9836ffb7bd4SBjoern A. Zeeb vif->bss_conf.bssid = ni->ni_bssid; 9846ffb7bd4SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 9856ffb7bd4SBjoern A. Zeeb vif->bss_conf.txpower = ni->ni_txpower; 9866ffb7bd4SBjoern A. Zeeb bss_changed |= BSS_CHANGED_TXPOWER; 9876ffb7bd4SBjoern A. Zeeb vif->cfg.idle = false; 9886ffb7bd4SBjoern A. Zeeb bss_changed |= BSS_CHANGED_IDLE; 9896ffb7bd4SBjoern A. Zeeb 9906ffb7bd4SBjoern A. Zeeb /* vif->bss_conf.basic_rates ? Where exactly? */ 9916ffb7bd4SBjoern A. Zeeb 9926ffb7bd4SBjoern A. Zeeb /* Should almost assert it is this. */ 9936ffb7bd4SBjoern A. Zeeb vif->cfg.assoc = false; 9946ffb7bd4SBjoern A. Zeeb vif->cfg.aid = 0; 9956ffb7bd4SBjoern A. Zeeb 9966ffb7bd4SBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 9976ffb7bd4SBjoern A. Zeeb 9986b4cac81SBjoern A. Zeeb error = 0; 9996b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 10006b4cac81SBjoern A. Zeeb changed = IEEE80211_CHANCTX_CHANGE_MIN_WIDTH; 10016b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_RADAR; 10026b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_RX_CHAINS; 10036b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_WIDTH; 10046b4cac81SBjoern A. Zeeb lkpi_80211_mo_change_chanctx(hw, conf, changed); 10056b4cac81SBjoern A. Zeeb } else { 10066b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_add_chanctx(hw, conf); 10076b4cac81SBjoern A. Zeeb if (error == 0 || error == EOPNOTSUPP) { 10086b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.chan = conf->def.chan; 10096b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.width = conf->def.width; 10106b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.center_freq1 = 10116b4cac81SBjoern A. Zeeb conf->def.center_freq1; 10126b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.center_freq2 = 10136b4cac81SBjoern A. Zeeb conf->def.center_freq2; 10146b4cac81SBjoern A. Zeeb } else { 1015*018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_add_chanctx " 1016*018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 10176b4cac81SBjoern A. Zeeb goto out; 10186b4cac81SBjoern A. Zeeb } 10196ffb7bd4SBjoern A. Zeeb 10206ffb7bd4SBjoern A. Zeeb vif->bss_conf.chanctx_conf = conf; 10216ffb7bd4SBjoern A. Zeeb 10226b4cac81SBjoern A. Zeeb /* Assign vif chanctx. */ 10236b4cac81SBjoern A. Zeeb if (error == 0) 102468541546SBjoern A. Zeeb error = lkpi_80211_mo_assign_vif_chanctx(hw, vif, 102568541546SBjoern A. Zeeb &vif->bss_conf, conf); 10266b4cac81SBjoern A. Zeeb if (error == EOPNOTSUPP) 10276b4cac81SBjoern A. Zeeb error = 0; 10286b4cac81SBjoern A. Zeeb if (error != 0) { 1029*018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_assign_vif_chanctx " 1030*018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 10316b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 1032c5e25798SBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(conf); 1033c5e25798SBjoern A. Zeeb free(lchanctx, M_LKPI80211); 10346b4cac81SBjoern A. Zeeb goto out; 10356b4cac81SBjoern A. Zeeb } 10366b4cac81SBjoern A. Zeeb } 10376b4cac81SBjoern A. Zeeb IMPROVE("update radiotap chan fields too"); 10386b4cac81SBjoern A. Zeeb 10396b4cac81SBjoern A. Zeeb /* RATES */ 10406b4cac81SBjoern A. Zeeb IMPROVE("bss info: not all needs to come now and rates are missing"); 10416b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 10426b4cac81SBjoern A. Zeeb 1043d9f59799SBjoern A. Zeeb /* 1044d9f59799SBjoern A. Zeeb * This is a bandaid for now. If we went through (*iv_update_bss)() 1045d9f59799SBjoern A. Zeeb * and then removed the lsta we end up here without a lsta and have 1046d9f59799SBjoern A. Zeeb * to manually allocate and link it in as lkpi_ic_node_alloc()/init() 1047d9f59799SBjoern A. Zeeb * would normally do. 1048d9f59799SBjoern A. Zeeb * XXX-BZ I do not like this but currently we have no good way of 1049d9f59799SBjoern A. Zeeb * intercepting the bss swap and state changes and packets going out 1050d9f59799SBjoern A. Zeeb * workflow so live with this. It is a compat layer after all. 1051d9f59799SBjoern A. Zeeb */ 1052d9f59799SBjoern A. Zeeb if (ni->ni_drv_data == NULL) { 1053d9f59799SBjoern A. Zeeb lsta = lkpi_lsta_alloc(vap, ni->ni_macaddr, hw, ni); 1054d9f59799SBjoern A. Zeeb if (lsta == NULL) { 1055d9f59799SBjoern A. Zeeb error = ENOMEM; 1056*018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lkpi_lsta_alloc " 1057*018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 1058d9f59799SBjoern A. Zeeb goto out; 1059d9f59799SBjoern A. Zeeb } 1060d9f59799SBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 1061d9f59799SBjoern A. Zeeb } else { 10626b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 1063d9f59799SBjoern A. Zeeb } 1064e24e8103SBjoern A. Zeeb 1065e24e8103SBjoern A. Zeeb /* Insert the [l]sta into the list of known stations. */ 1066e24e8103SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 1067e24e8103SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lvif->lsta_head, lsta, lsta_entry); 1068e24e8103SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 1069e24e8103SBjoern A. Zeeb 1070d9f59799SBjoern A. Zeeb /* Add (or adjust) sta and change state (from NOTEXIST) to NONE. */ 10716b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 10726b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NOTEXIST, ("%s: lsta %p state not " 10736b4cac81SBjoern A. Zeeb "NOTEXIST: %#x\n", __func__, lsta, lsta->state)); 1074e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE); 10756b4cac81SBjoern A. Zeeb if (error != 0) { 10766b4cac81SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 1077*018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NONE) " 1078*018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 10796b4cac81SBjoern A. Zeeb goto out; 10806b4cac81SBjoern A. Zeeb } 10816b4cac81SBjoern A. Zeeb #if 0 10826b4cac81SBjoern A. Zeeb lsta->added_to_drv = true; /* mo manages. */ 10836b4cac81SBjoern A. Zeeb #endif 10846b4cac81SBjoern A. Zeeb 10859d9ba2b7SBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 10869d9ba2b7SBjoern A. Zeeb 10876b4cac81SBjoern A. Zeeb /* 10886b4cac81SBjoern A. Zeeb * Wakeup all queues now that sta is there so we have as much time to 10896b4cac81SBjoern A. Zeeb * possibly prepare the queue in the driver to be ready for the 1st 10906b4cac81SBjoern A. Zeeb * packet; lkpi_80211_txq_tx_one() still has a workaround as there 10916b4cac81SBjoern A. Zeeb * is no guarantee or way to check. 1092d9f59799SBjoern A. Zeeb * XXX-BZ and by now we know that this does not work on all drivers 1093d9f59799SBjoern A. Zeeb * for all queues. 10946b4cac81SBjoern A. Zeeb */ 1095e7fe0373SBjoern A. Zeeb lkpi_wake_tx_queues(hw, LSTA_TO_STA(lsta), false, false); 10966b4cac81SBjoern A. Zeeb 10976b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 10986b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 10996b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 11006b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 11016b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 11026b4cac81SBjoern A. Zeeb 11036b4cac81SBjoern A. Zeeb /* 11046b4cac81SBjoern A. Zeeb * What is going to happen next: 11056b4cac81SBjoern A. Zeeb * - <twiddle> .. we should end up in "auth_to_assoc" 11066b4cac81SBjoern A. Zeeb * - event_callback 11076b4cac81SBjoern A. Zeeb * - update sta_state (NONE to AUTH) 11086b4cac81SBjoern A. Zeeb * - mgd_complete_tx 11096b4cac81SBjoern A. Zeeb * (ideally we'd do that on a callback for something else ...) 11106b4cac81SBjoern A. Zeeb */ 11116b4cac81SBjoern A. Zeeb 11126b4cac81SBjoern A. Zeeb out: 11138ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 11146b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 11156b4cac81SBjoern A. Zeeb if (ni != NULL) 11166b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 11176b4cac81SBjoern A. Zeeb return (error); 11186b4cac81SBjoern A. Zeeb } 11196b4cac81SBjoern A. Zeeb 11206b4cac81SBjoern A. Zeeb static int 11216b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 11226b4cac81SBjoern A. Zeeb { 11236b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 11246b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 11256b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 11266b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 11276b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 11286b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 11296b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 11306b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 11316b4cac81SBjoern A. Zeeb int error; 11326b4cac81SBjoern A. Zeeb 11336b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 11346b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 11356b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 11366b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 11376b4cac81SBjoern A. Zeeb 11386b4cac81SBjoern A. Zeeb /* Keep ni around. */ 11396b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 11406b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 11416b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 11426b4cac81SBjoern A. Zeeb 114367674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 11446b4cac81SBjoern A. Zeeb 11456b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 11468ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 11476b4cac81SBjoern A. Zeeb 1148d9f59799SBjoern A. Zeeb /* flush, drop. */ 1149d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1150d9f59799SBjoern A. Zeeb 11516b4cac81SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 11526b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 11536b4cac81SBjoern A. Zeeb 11546b4cac81SBjoern A. Zeeb /* flush, no drop */ 11556b4cac81SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 11566b4cac81SBjoern A. Zeeb 11576b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 11586b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 11596b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 11606b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 11616b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 11626b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 11636b4cac81SBjoern A. Zeeb } 11646b4cac81SBjoern A. Zeeb 11656b4cac81SBjoern A. Zeeb /* sync_rx_queues */ 11666b4cac81SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 11676b4cac81SBjoern A. Zeeb 11686b4cac81SBjoern A. Zeeb /* sta_pre_rcu_remove */ 11696b4cac81SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 1170d9f59799SBjoern A. Zeeb 1171d9f59799SBjoern A. Zeeb /* Take the station down. */ 11726b4cac81SBjoern A. Zeeb 11736b4cac81SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 11746b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 11756b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 1176d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg)); 1177e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST); 11786b4cac81SBjoern A. Zeeb if (error != 0) { 11796b4cac81SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 1180*018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NOTEXIST) " 1181*018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 11826b4cac81SBjoern A. Zeeb goto out; 11836b4cac81SBjoern A. Zeeb } 11846b4cac81SBjoern A. Zeeb #if 0 11856b4cac81SBjoern A. Zeeb lsta->added_to_drv = false; /* mo manages. */ 11866b4cac81SBjoern A. Zeeb #endif 11876b4cac81SBjoern A. Zeeb 118867674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 11896b4cac81SBjoern A. Zeeb 1190d9f59799SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif); 1191d9f59799SBjoern A. Zeeb 1192d9f59799SBjoern A. Zeeb /* conf_tx */ 1193d9f59799SBjoern A. Zeeb 1194d9f59799SBjoern A. Zeeb /* Take the chan ctx down. */ 11956b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 1196c5e25798SBjoern A. Zeeb struct lkpi_chanctx *lchanctx; 11976b4cac81SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 11986b4cac81SBjoern A. Zeeb 11996b4cac81SBjoern A. Zeeb conf = vif->chanctx_conf; 12006b4cac81SBjoern A. Zeeb /* Remove vif context. */ 120168541546SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->bss_conf, &vif->chanctx_conf); 12026b4cac81SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 12036b4cac81SBjoern A. Zeeb 12046b4cac81SBjoern A. Zeeb /* Remove chan ctx. */ 12056b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 1206c5e25798SBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(conf); 1207c5e25798SBjoern A. Zeeb free(lchanctx, M_LKPI80211); 12086b4cac81SBjoern A. Zeeb } 12096b4cac81SBjoern A. Zeeb 12106b4cac81SBjoern A. Zeeb out: 12118ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 12126b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 12136b4cac81SBjoern A. Zeeb if (ni != NULL) 12146b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 12156b4cac81SBjoern A. Zeeb return (error); 12166b4cac81SBjoern A. Zeeb } 12176b4cac81SBjoern A. Zeeb 12186b4cac81SBjoern A. Zeeb static int 12196b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 12206b4cac81SBjoern A. Zeeb { 12216b4cac81SBjoern A. Zeeb int error; 12226b4cac81SBjoern A. Zeeb 12236b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_scan(vap, nstate, arg); 12246b4cac81SBjoern A. Zeeb if (error == 0) 12256b4cac81SBjoern A. Zeeb error = lkpi_sta_scan_to_init(vap, nstate, arg); 12266b4cac81SBjoern A. Zeeb return (error); 12276b4cac81SBjoern A. Zeeb } 12286b4cac81SBjoern A. Zeeb 12296b4cac81SBjoern A. Zeeb static int 12306b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 12316b4cac81SBjoern A. Zeeb { 12326b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 12336b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 12346b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 12356b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 12366b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 12376b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 12386b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 12396b4cac81SBjoern A. Zeeb int error; 12406b4cac81SBjoern A. Zeeb 12416b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 12426b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 12436b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 12446b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 12456b4cac81SBjoern A. Zeeb 12466b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 12478ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 12486b4cac81SBjoern A. Zeeb ni = NULL; 12496b4cac81SBjoern A. Zeeb 12506b4cac81SBjoern A. Zeeb /* Finish auth. */ 12516b4cac81SBjoern A. Zeeb IMPROVE("event callback"); 12526b4cac81SBjoern A. Zeeb 12536b4cac81SBjoern A. Zeeb /* Update sta_state (NONE to AUTH). */ 12546b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 12556b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 12566b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 12576b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 12586b4cac81SBjoern A. Zeeb "NONE: %#x\n", __func__, lsta, lsta->state)); 1259e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH); 1260*018d93ecSBjoern A. Zeeb if (error != 0) { 1261*018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTH) " 1262*018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 12636b4cac81SBjoern A. Zeeb goto out; 1264*018d93ecSBjoern A. Zeeb } 12656b4cac81SBjoern A. Zeeb 12666b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 12676b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 12686b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 12696b4cac81SBjoern A. Zeeb prep_tx_info.success = true; 12706b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 12716b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 12726b4cac81SBjoern A. Zeeb } 12736b4cac81SBjoern A. Zeeb 12746b4cac81SBjoern A. Zeeb /* Now start assoc. */ 12756b4cac81SBjoern A. Zeeb 12766b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 12776b4cac81SBjoern A. Zeeb if (!lsta->in_mgd) { 12786b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 12796b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 12806b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 12816b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 12826b4cac81SBjoern A. Zeeb } 12836b4cac81SBjoern A. Zeeb 12846b4cac81SBjoern A. Zeeb /* Wake tx queue to get packet out. */ 1285e7fe0373SBjoern A. Zeeb lkpi_wake_tx_queues(hw, LSTA_TO_STA(lsta), true, true); 12866b4cac81SBjoern A. Zeeb 12876b4cac81SBjoern A. Zeeb /* 12886b4cac81SBjoern A. Zeeb * <twiddle> .. we end up in "assoc_to_run" 12896b4cac81SBjoern A. Zeeb * - update sta_state (AUTH to ASSOC) 12906b4cac81SBjoern A. Zeeb * - conf_tx [all] 12916b4cac81SBjoern A. Zeeb * - bss_info_changed (assoc, aid, ssid, ..) 12926b4cac81SBjoern A. Zeeb * - change_chanctx (if needed) 12936b4cac81SBjoern A. Zeeb * - event_callback 12946b4cac81SBjoern A. Zeeb * - mgd_complete_tx 12956b4cac81SBjoern A. Zeeb */ 12966b4cac81SBjoern A. Zeeb 12976b4cac81SBjoern A. Zeeb out: 12988ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 12996b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 13006b4cac81SBjoern A. Zeeb if (ni != NULL) 13016b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 13026b4cac81SBjoern A. Zeeb return (error); 13036b4cac81SBjoern A. Zeeb } 13046b4cac81SBjoern A. Zeeb 13056b4cac81SBjoern A. Zeeb /* auth_to_auth, assoc_to_assoc. */ 13066b4cac81SBjoern A. Zeeb static int 13076b4cac81SBjoern A. Zeeb lkpi_sta_a_to_a(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 13086b4cac81SBjoern A. Zeeb { 13096b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 13106b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 13116b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 13126b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 13136b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 13146b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 13156b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 13166b4cac81SBjoern A. Zeeb 13176b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 13186b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 13196b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 13206b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 13216b4cac81SBjoern A. Zeeb 13226b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 13236b4cac81SBjoern A. Zeeb 13246b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 13258ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 13266b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 13276b4cac81SBjoern A. Zeeb 13286b4cac81SBjoern A. Zeeb IMPROVE("event callback?"); 13296b4cac81SBjoern A. Zeeb 13306b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 13316b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 13326b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 13336b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 13346b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 13356b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 13366b4cac81SBjoern A. Zeeb } 13376b4cac81SBjoern A. Zeeb 13386b4cac81SBjoern A. Zeeb /* Now start assoc. */ 13396b4cac81SBjoern A. Zeeb 13406b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 13416b4cac81SBjoern A. Zeeb if (!lsta->in_mgd) { 13426b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 13436b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 13446b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 13456b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 13466b4cac81SBjoern A. Zeeb } 13476b4cac81SBjoern A. Zeeb 13488ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 13496b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 13506b4cac81SBjoern A. Zeeb if (ni != NULL) 13516b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 13526b4cac81SBjoern A. Zeeb 13536b4cac81SBjoern A. Zeeb return (0); 13546b4cac81SBjoern A. Zeeb } 13556b4cac81SBjoern A. Zeeb 13566b4cac81SBjoern A. Zeeb static int 1357d9f59799SBjoern A. Zeeb _lkpi_sta_assoc_to_down(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 13586b4cac81SBjoern A. Zeeb { 13596b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 13606b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 13616b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 13626b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 13636b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 13646b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 13656b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 13666b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 1367d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 13686b4cac81SBjoern A. Zeeb int error; 13696b4cac81SBjoern A. Zeeb 13706b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 13716b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 13726b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 13736b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 13746b4cac81SBjoern A. Zeeb 13756b4cac81SBjoern A. Zeeb /* Keep ni around. */ 13766b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 13776b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 13786b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 13796b4cac81SBjoern A. Zeeb 138067674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1381d9f59799SBjoern A. Zeeb 1382d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 13838ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1384d9f59799SBjoern A. Zeeb 1385d9f59799SBjoern A. Zeeb /* flush, drop. */ 1386d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1387d9f59799SBjoern A. Zeeb 1388d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?"); 1389d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) && 1390d9f59799SBjoern A. Zeeb !lsta->in_mgd) { 1391d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1392d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 1393d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 1394d9f59799SBjoern A. Zeeb lsta->in_mgd = true; 1395d9f59799SBjoern A. Zeeb } 1396d9f59799SBjoern A. Zeeb 13978ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 1398d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1399d9f59799SBjoern A. Zeeb 1400d9f59799SBjoern A. Zeeb /* Call iv_newstate first so we get potential DISASSOC packet out. */ 1401d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 1402*018d93ecSBjoern A. Zeeb if (error != 0) { 1403*018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: iv_newstate(%p, %d, %d) " 1404*018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, vap, nstate, arg, error); 1405d9f59799SBjoern A. Zeeb goto outni; 1406*018d93ecSBjoern A. Zeeb } 1407d9f59799SBjoern A. Zeeb 1408d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 14098ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1410d9f59799SBjoern A. Zeeb 141167674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1412d9f59799SBjoern A. Zeeb 1413d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 1414d9f59799SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 1415d9f59799SBjoern A. Zeeb 1416d9f59799SBjoern A. Zeeb /* flush, no drop */ 1417d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 1418d9f59799SBjoern A. Zeeb 14196b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 14206b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 14216b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 14226b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 14236b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 14246b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 14256b4cac81SBjoern A. Zeeb } 14266b4cac81SBjoern A. Zeeb 1427d9f59799SBjoern A. Zeeb /* sync_rx_queues */ 1428d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 1429d9f59799SBjoern A. Zeeb 1430d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */ 1431d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 1432d9f59799SBjoern A. Zeeb 1433d9f59799SBjoern A. Zeeb /* Take the station down. */ 1434d9f59799SBjoern A. Zeeb 14356b4cac81SBjoern A. Zeeb /* Update sta and change state (from AUTH) to NONE. */ 14366b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 14376b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 14386b4cac81SBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 1439e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE); 1440*018d93ecSBjoern A. Zeeb if (error != 0) { 1441*018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NONE) " 1442*018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 14436b4cac81SBjoern A. Zeeb goto out; 1444*018d93ecSBjoern A. Zeeb } 14456b4cac81SBjoern A. Zeeb 144667674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 14476b4cac81SBjoern A. Zeeb 144816e688b2SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 144916e688b2SBjoern A. Zeeb /* 145016e688b2SBjoern A. Zeeb * We need to do this now, before sta changes to IEEE80211_STA_NOTEXIST 145116e688b2SBjoern A. Zeeb * as otherwise drivers (iwlwifi at least) will silently not remove 145216e688b2SBjoern A. Zeeb * the sta from the firmware and when we will add a new one trigger 145316e688b2SBjoern A. Zeeb * a fw assert. 145416e688b2SBjoern A. Zeeb */ 145516e688b2SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw); 145616e688b2SBjoern A. Zeeb 1457d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 1458d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 1459d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 1460d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg)); 1461e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST); 1462d9f59799SBjoern A. Zeeb if (error != 0) { 1463d9f59799SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 1464*018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NOTEXIST) " 1465*018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 1466d9f59799SBjoern A. Zeeb goto out; 1467d9f59799SBjoern A. Zeeb } 1468d9f59799SBjoern A. Zeeb 146916e688b2SBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); /* sta no longer save to use. */ 1470d9f59799SBjoern A. Zeeb 1471d9f59799SBjoern A. Zeeb IMPROVE("Any bss_info changes to announce?"); 1472d9f59799SBjoern A. Zeeb bss_changed = 0; 1473d9f59799SBjoern A. Zeeb vif->bss_conf.qos = 0; 1474d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 1475616e1330SBjoern A. Zeeb vif->cfg.ssid_len = 0; 1476616e1330SBjoern A. Zeeb memset(vif->cfg.ssid, '\0', sizeof(vif->cfg.ssid)); 1477d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 1478d9f59799SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 1479d9f59799SBjoern A. Zeeb 1480d9f59799SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif); 1481d9f59799SBjoern A. Zeeb 1482d9f59799SBjoern A. Zeeb /* conf_tx */ 1483d9f59799SBjoern A. Zeeb 1484d9f59799SBjoern A. Zeeb /* Take the chan ctx down. */ 1485d9f59799SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 1486c5e25798SBjoern A. Zeeb struct lkpi_chanctx *lchanctx; 1487d9f59799SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 1488d9f59799SBjoern A. Zeeb 1489d9f59799SBjoern A. Zeeb conf = vif->chanctx_conf; 1490d9f59799SBjoern A. Zeeb /* Remove vif context. */ 149168541546SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->bss_conf, &vif->chanctx_conf); 1492d9f59799SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 1493d9f59799SBjoern A. Zeeb 1494d9f59799SBjoern A. Zeeb /* Remove chan ctx. */ 1495d9f59799SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 1496c5e25798SBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(conf); 1497c5e25798SBjoern A. Zeeb free(lchanctx, M_LKPI80211); 1498d9f59799SBjoern A. Zeeb } 1499d9f59799SBjoern A. Zeeb 1500d9f59799SBjoern A. Zeeb error = EALREADY; 15016b4cac81SBjoern A. Zeeb out: 15028ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 15036b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1504d9f59799SBjoern A. Zeeb outni: 15056b4cac81SBjoern A. Zeeb if (ni != NULL) 15066b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 15076b4cac81SBjoern A. Zeeb return (error); 15086b4cac81SBjoern A. Zeeb } 15096b4cac81SBjoern A. Zeeb 15106b4cac81SBjoern A. Zeeb static int 1511d9f59799SBjoern A. Zeeb lkpi_sta_assoc_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 1512d9f59799SBjoern A. Zeeb { 1513d9f59799SBjoern A. Zeeb int error; 1514d9f59799SBjoern A. Zeeb 1515d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg); 1516d9f59799SBjoern A. Zeeb if (error != 0 && error != EALREADY) 1517d9f59799SBjoern A. Zeeb return (error); 1518d9f59799SBjoern A. Zeeb 1519d9f59799SBjoern A. Zeeb /* At this point iv_bss is long a new node! */ 1520d9f59799SBjoern A. Zeeb 1521d9f59799SBjoern A. Zeeb error |= lkpi_sta_scan_to_auth(vap, nstate, 0); 1522d9f59799SBjoern A. Zeeb return (error); 1523d9f59799SBjoern A. Zeeb } 1524d9f59799SBjoern A. Zeeb 1525d9f59799SBjoern A. Zeeb static int 15266b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 15276b4cac81SBjoern A. Zeeb { 15286b4cac81SBjoern A. Zeeb int error; 15296b4cac81SBjoern A. Zeeb 1530d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg); 15316b4cac81SBjoern A. Zeeb return (error); 15326b4cac81SBjoern A. Zeeb } 15336b4cac81SBjoern A. Zeeb 15346b4cac81SBjoern A. Zeeb static int 15356b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 15366b4cac81SBjoern A. Zeeb { 15376b4cac81SBjoern A. Zeeb int error; 15386b4cac81SBjoern A. Zeeb 1539d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg); 15406b4cac81SBjoern A. Zeeb return (error); 15416b4cac81SBjoern A. Zeeb } 15426b4cac81SBjoern A. Zeeb 15436b4cac81SBjoern A. Zeeb static int 15446b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 15456b4cac81SBjoern A. Zeeb { 15466b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 15476b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 15486b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 15496b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 15506b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 15516b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 15526b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 15536b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 15546b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 15556b4cac81SBjoern A. Zeeb int error; 15566b4cac81SBjoern A. Zeeb 15576b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 15586b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 15596b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 15606b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 15616b4cac81SBjoern A. Zeeb 15626b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 15638ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 15649597f7cbSBjoern A. Zeeb ni = NULL; 15656b4cac81SBjoern A. Zeeb 15666b4cac81SBjoern A. Zeeb IMPROVE("ponder some of this moved to ic_newassoc, scan_assoc_success, " 15676b4cac81SBjoern A. Zeeb "and to lesser extend ieee80211_notify_node_join"); 15686b4cac81SBjoern A. Zeeb 15699597f7cbSBjoern A. Zeeb /* Finish assoc. */ 15709597f7cbSBjoern A. Zeeb /* Update sta_state (AUTH to ASSOC) and set aid. */ 15716b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 15726b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 15736b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 15749597f7cbSBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 15759597f7cbSBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 15766b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 15779597f7cbSBjoern A. Zeeb sta->aid = IEEE80211_NODE_AID(ni); 15784a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 15794a67f1dfSBjoern A. Zeeb if (vap->iv_flags & IEEE80211_F_WME) 15804a67f1dfSBjoern A. Zeeb sta->wme = true; 15814a67f1dfSBjoern A. Zeeb #endif 1582e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC); 1583*018d93ecSBjoern A. Zeeb if (error != 0) { 1584*018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(ASSOC) " 1585*018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 15869597f7cbSBjoern A. Zeeb goto out; 1587*018d93ecSBjoern A. Zeeb } 15886b4cac81SBjoern A. Zeeb 15896b4cac81SBjoern A. Zeeb IMPROVE("wme / conf_tx [all]"); 15906b4cac81SBjoern A. Zeeb 15916b4cac81SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 15926b4cac81SBjoern A. Zeeb bss_changed = 0; 15934a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 15944a67f1dfSBjoern A. Zeeb bss_changed |= lkpi_wme_update(lhw, vap, true); 15954a67f1dfSBjoern A. Zeeb #endif 1596616e1330SBjoern A. Zeeb if (!vif->cfg.assoc || vif->cfg.aid != IEEE80211_NODE_AID(ni)) { 1597616e1330SBjoern A. Zeeb vif->cfg.assoc = true; 1598616e1330SBjoern A. Zeeb vif->cfg.aid = IEEE80211_NODE_AID(ni); 15996b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_ASSOC; 16006b4cac81SBjoern A. Zeeb } 16016b4cac81SBjoern A. Zeeb /* We set SSID but this is not BSSID! */ 1602616e1330SBjoern A. Zeeb vif->cfg.ssid_len = ni->ni_esslen; 1603616e1330SBjoern A. Zeeb memcpy(vif->cfg.ssid, ni->ni_essid, ni->ni_esslen); 16046b4cac81SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_SHPREAMBLE) != 16056b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble) { 16066b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble ^= 1; 16076b4cac81SBjoern A. Zeeb /* bss_changed |= BSS_CHANGED_??? */ 16086b4cac81SBjoern A. Zeeb } 16096b4cac81SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_SHSLOT) != 16106b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot) { 16116b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot ^= 1; 16126b4cac81SBjoern A. Zeeb /* bss_changed |= BSS_CHANGED_??? */ 16136b4cac81SBjoern A. Zeeb } 16146b4cac81SBjoern A. Zeeb if ((ni->ni_flags & IEEE80211_NODE_QOS) != 16156b4cac81SBjoern A. Zeeb vif->bss_conf.qos) { 16166b4cac81SBjoern A. Zeeb vif->bss_conf.qos ^= 1; 16176b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 16186b4cac81SBjoern A. Zeeb } 1619fa8f007dSBjoern A. Zeeb 1620fa8f007dSBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 1621fa8f007dSBjoern A. Zeeb 16226b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 16236b4cac81SBjoern A. Zeeb 16246b4cac81SBjoern A. Zeeb /* - change_chanctx (if needed) 16256b4cac81SBjoern A. Zeeb * - event_callback 16266b4cac81SBjoern A. Zeeb */ 16276b4cac81SBjoern A. Zeeb 16286b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 16296b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 16306b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 16316b4cac81SBjoern A. Zeeb prep_tx_info.success = true; 16326b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 16336b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 16346b4cac81SBjoern A. Zeeb } 16356b4cac81SBjoern A. Zeeb 1636086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, false); 1637086be6a8SBjoern A. Zeeb 16386b4cac81SBjoern A. Zeeb /* 16396b4cac81SBjoern A. Zeeb * And then: 16406b4cac81SBjoern A. Zeeb * - (more packets)? 16416b4cac81SBjoern A. Zeeb * - set_key 16426b4cac81SBjoern A. Zeeb * - set_default_unicast_key 16436b4cac81SBjoern A. Zeeb * - set_key (?) 16446b4cac81SBjoern A. Zeeb * - ipv6_addr_change (?) 16456b4cac81SBjoern A. Zeeb */ 16466b4cac81SBjoern A. Zeeb /* Prepare_multicast && configure_filter. */ 16476b4cac81SBjoern A. Zeeb lhw->update_mc = true; 16486b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(vap->iv_ic, true); 16496b4cac81SBjoern A. Zeeb 16506b4cac81SBjoern A. Zeeb if (!ieee80211_node_is_authorized(ni)) { 16516b4cac81SBjoern A. Zeeb IMPROVE("net80211 does not consider node authorized"); 16526b4cac81SBjoern A. Zeeb } 16536b4cac81SBjoern A. Zeeb 16546b4cac81SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTHORIZED). */ 16556b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 16566b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 16576b4cac81SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 1658e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTHORIZED); 16596b4cac81SBjoern A. Zeeb if (error != 0) { 16606b4cac81SBjoern A. Zeeb IMPROVE("undo some changes?"); 1661*018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTHORIZED) " 1662*018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 16636b4cac81SBjoern A. Zeeb goto out; 16646b4cac81SBjoern A. Zeeb } 16656b4cac81SBjoern A. Zeeb 16666b4cac81SBjoern A. Zeeb /* - drv_config (?) 16676b4cac81SBjoern A. Zeeb * - bss_info_changed 16686b4cac81SBjoern A. Zeeb * - set_rekey_data (?) 16696b4cac81SBjoern A. Zeeb * 16706b4cac81SBjoern A. Zeeb * And now we should be passing packets. 16716b4cac81SBjoern A. Zeeb */ 16726b4cac81SBjoern A. Zeeb IMPROVE("Need that bssid setting, and the keys"); 16736b4cac81SBjoern A. Zeeb 1674fa8f007dSBjoern A. Zeeb bss_changed = 0; 1675fa8f007dSBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 1676fa8f007dSBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 1677fa8f007dSBjoern A. Zeeb 16786b4cac81SBjoern A. Zeeb out: 16798ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 16806b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 16816b4cac81SBjoern A. Zeeb if (ni != NULL) 16826b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 16836b4cac81SBjoern A. Zeeb return (error); 16846b4cac81SBjoern A. Zeeb } 16856b4cac81SBjoern A. Zeeb 16866b4cac81SBjoern A. Zeeb static int 16876b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 16886b4cac81SBjoern A. Zeeb { 16896b4cac81SBjoern A. Zeeb int error; 16906b4cac81SBjoern A. Zeeb 16916b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_assoc(vap, nstate, arg); 16926b4cac81SBjoern A. Zeeb if (error == 0) 16936b4cac81SBjoern A. Zeeb error = lkpi_sta_assoc_to_run(vap, nstate, arg); 16946b4cac81SBjoern A. Zeeb return (error); 16956b4cac81SBjoern A. Zeeb } 16966b4cac81SBjoern A. Zeeb 16976b4cac81SBjoern A. Zeeb static int 16986b4cac81SBjoern A. Zeeb lkpi_sta_run_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 16996b4cac81SBjoern A. Zeeb { 17006b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 17016b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 17026b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 17036b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 17046b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 17056b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 17066b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 1707d9f59799SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 1708d9f59799SBjoern A. Zeeb #if 0 1709d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 1710d9f59799SBjoern A. Zeeb #endif 17116b4cac81SBjoern A. Zeeb int error; 17126b4cac81SBjoern A. Zeeb 17136b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 17146b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 17156b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 17166b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 17176b4cac81SBjoern A. Zeeb 17186b4cac81SBjoern A. Zeeb /* Keep ni around. */ 17196b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 17206b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 17216b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 17226b4cac81SBjoern A. Zeeb 172367674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1724d9f59799SBjoern A. Zeeb 1725d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 17268ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1727d9f59799SBjoern A. Zeeb 1728d9f59799SBjoern A. Zeeb /* flush, drop. */ 1729d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1730d9f59799SBjoern A. Zeeb 1731d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?"); 1732d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) && 1733d9f59799SBjoern A. Zeeb !lsta->in_mgd) { 1734d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1735d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 1736d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 1737d9f59799SBjoern A. Zeeb lsta->in_mgd = true; 1738d9f59799SBjoern A. Zeeb } 1739d9f59799SBjoern A. Zeeb 17408ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 1741d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1742d9f59799SBjoern A. Zeeb 1743d9f59799SBjoern A. Zeeb /* Call iv_newstate first so we get potential DISASSOC packet out. */ 1744d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 1745*018d93ecSBjoern A. Zeeb if (error != 0) { 1746*018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: iv_newstate(%p, %d, %d) " 1747*018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, vap, nstate, arg, error); 1748d9f59799SBjoern A. Zeeb goto outni; 1749*018d93ecSBjoern A. Zeeb } 1750d9f59799SBjoern A. Zeeb 1751d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 17528ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1753d9f59799SBjoern A. Zeeb 175467674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1755d9f59799SBjoern A. Zeeb 1756d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 1757d9f59799SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 1758d9f59799SBjoern A. Zeeb 1759d9f59799SBjoern A. Zeeb /* flush, no drop */ 1760d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 1761d9f59799SBjoern A. Zeeb 1762d9f59799SBjoern A. Zeeb /* End mgd_complete_tx. */ 1763d9f59799SBjoern A. Zeeb if (lsta->in_mgd) { 1764d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1765d9f59799SBjoern A. Zeeb prep_tx_info.success = false; 1766d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 1767d9f59799SBjoern A. Zeeb lsta->in_mgd = false; 1768d9f59799SBjoern A. Zeeb } 1769d9f59799SBjoern A. Zeeb 1770d9f59799SBjoern A. Zeeb #if 0 1771d9f59799SBjoern A. Zeeb /* sync_rx_queues */ 1772d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 1773d9f59799SBjoern A. Zeeb 1774d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */ 1775d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 1776d9f59799SBjoern A. Zeeb #endif 1777d9f59799SBjoern A. Zeeb 1778d9f59799SBjoern A. Zeeb /* Take the station down. */ 1779d9f59799SBjoern A. Zeeb 17806b4cac81SBjoern A. Zeeb /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */ 17816b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 17826b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not " 17836b4cac81SBjoern A. Zeeb "AUTHORIZED: %#x\n", __func__, lsta, lsta->state)); 1784e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC); 1785*018d93ecSBjoern A. Zeeb if (error != 0) { 1786*018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(ASSOC) " 1787*018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 17886b4cac81SBjoern A. Zeeb goto out; 1789*018d93ecSBjoern A. Zeeb } 17906b4cac81SBjoern A. Zeeb 179167674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 17926b4cac81SBjoern A. Zeeb 17936b4cac81SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTH). */ 17946b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 17956b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 17966b4cac81SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 1797e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH); 1798*018d93ecSBjoern A. Zeeb if (error != 0) { 1799*018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTH) " 1800*018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 18016b4cac81SBjoern A. Zeeb goto out; 1802*018d93ecSBjoern A. Zeeb } 18036b4cac81SBjoern A. Zeeb 180467674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 18056b4cac81SBjoern A. Zeeb 1806d9f59799SBjoern A. Zeeb #if 0 1807d9f59799SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 1808d9f59799SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw); 1809d9f59799SBjoern A. Zeeb #endif 1810d9f59799SBjoern A. Zeeb 1811d9f59799SBjoern A. Zeeb error = EALREADY; 18126b4cac81SBjoern A. Zeeb out: 18138ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 18146b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1815d9f59799SBjoern A. Zeeb outni: 18166b4cac81SBjoern A. Zeeb if (ni != NULL) 18176b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 18186b4cac81SBjoern A. Zeeb return (error); 18196b4cac81SBjoern A. Zeeb } 18206b4cac81SBjoern A. Zeeb 18216b4cac81SBjoern A. Zeeb static int 1822d9f59799SBjoern A. Zeeb lkpi_sta_run_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 1823d9f59799SBjoern A. Zeeb { 1824d9f59799SBjoern A. Zeeb struct lkpi_hw *lhw; 1825d9f59799SBjoern A. Zeeb struct ieee80211_hw *hw; 1826d9f59799SBjoern A. Zeeb struct lkpi_vif *lvif; 1827d9f59799SBjoern A. Zeeb struct ieee80211_vif *vif; 1828d9f59799SBjoern A. Zeeb struct ieee80211_node *ni; 1829d9f59799SBjoern A. Zeeb struct lkpi_sta *lsta; 1830d9f59799SBjoern A. Zeeb struct ieee80211_sta *sta; 1831d9f59799SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 1832d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 1833d9f59799SBjoern A. Zeeb int error; 1834d9f59799SBjoern A. Zeeb 1835d9f59799SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 1836d9f59799SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 1837d9f59799SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 1838d9f59799SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 1839d9f59799SBjoern A. Zeeb 1840d9f59799SBjoern A. Zeeb /* Keep ni around. */ 1841d9f59799SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 1842d9f59799SBjoern A. Zeeb lsta = ni->ni_drv_data; 1843d9f59799SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 1844d9f59799SBjoern A. Zeeb 184567674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1846d9f59799SBjoern A. Zeeb 1847d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 18488ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1849d9f59799SBjoern A. Zeeb 1850d9f59799SBjoern A. Zeeb /* flush, drop. */ 1851d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1852d9f59799SBjoern A. Zeeb 1853d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?"); 1854d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) && 1855d9f59799SBjoern A. Zeeb !lsta->in_mgd) { 1856d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1857d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 1858d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 1859d9f59799SBjoern A. Zeeb lsta->in_mgd = true; 1860d9f59799SBjoern A. Zeeb } 1861d9f59799SBjoern A. Zeeb 18628ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 1863d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1864d9f59799SBjoern A. Zeeb 1865d9f59799SBjoern A. Zeeb /* Call iv_newstate first so we get potential DISASSOC packet out. */ 1866d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 1867*018d93ecSBjoern A. Zeeb if (error != 0) { 1868*018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: iv_newstate(%p, %d, %d) " 1869*018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, vap, nstate, arg, error); 1870d9f59799SBjoern A. Zeeb goto outni; 1871*018d93ecSBjoern A. Zeeb } 1872d9f59799SBjoern A. Zeeb 1873d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 18748ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1875d9f59799SBjoern A. Zeeb 187667674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1877d9f59799SBjoern A. Zeeb 1878d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 1879d9f59799SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 1880d9f59799SBjoern A. Zeeb 1881d9f59799SBjoern A. Zeeb /* flush, no drop */ 1882d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 1883d9f59799SBjoern A. Zeeb 1884d9f59799SBjoern A. Zeeb /* End mgd_complete_tx. */ 1885d9f59799SBjoern A. Zeeb if (lsta->in_mgd) { 1886d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1887d9f59799SBjoern A. Zeeb prep_tx_info.success = false; 1888d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 1889d9f59799SBjoern A. Zeeb lsta->in_mgd = false; 1890d9f59799SBjoern A. Zeeb } 1891d9f59799SBjoern A. Zeeb 1892d9f59799SBjoern A. Zeeb /* sync_rx_queues */ 1893d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 1894d9f59799SBjoern A. Zeeb 1895d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */ 1896d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 1897d9f59799SBjoern A. Zeeb 1898d9f59799SBjoern A. Zeeb /* Take the station down. */ 1899d9f59799SBjoern A. Zeeb 1900d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */ 1901d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 1902d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not " 1903d9f59799SBjoern A. Zeeb "AUTHORIZED: %#x\n", __func__, lsta, lsta->state)); 1904e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC); 1905*018d93ecSBjoern A. Zeeb if (error != 0) { 1906*018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(ASSOC) " 1907*018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 1908d9f59799SBjoern A. Zeeb goto out; 1909*018d93ecSBjoern A. Zeeb } 1910d9f59799SBjoern A. Zeeb 191167674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1912d9f59799SBjoern A. Zeeb 1913d9f59799SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTH). */ 1914d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 1915d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 1916d9f59799SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 1917e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH); 1918*018d93ecSBjoern A. Zeeb if (error != 0) { 1919*018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTH) " 1920*018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 1921d9f59799SBjoern A. Zeeb goto out; 1922*018d93ecSBjoern A. Zeeb } 1923d9f59799SBjoern A. Zeeb 192467674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1925d9f59799SBjoern A. Zeeb 1926d9f59799SBjoern A. Zeeb /* Update sta and change state (from AUTH) to NONE. */ 1927d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 1928d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 1929d9f59799SBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 1930e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE); 1931*018d93ecSBjoern A. Zeeb if (error != 0) { 1932*018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NONE) " 1933*018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 1934d9f59799SBjoern A. Zeeb goto out; 1935*018d93ecSBjoern A. Zeeb } 1936d9f59799SBjoern A. Zeeb 193767674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1938d9f59799SBjoern A. Zeeb 193916e688b2SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 194016e688b2SBjoern A. Zeeb /* 194116e688b2SBjoern A. Zeeb * One would expect this to happen when going off AUTHORIZED. 194216e688b2SBjoern A. Zeeb * See comment there; removes the sta from fw. 194316e688b2SBjoern A. Zeeb */ 194416e688b2SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw); 194516e688b2SBjoern A. Zeeb 1946d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 1947d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 1948d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 1949d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg)); 1950e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST); 1951d9f59799SBjoern A. Zeeb if (error != 0) { 1952d9f59799SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 1953*018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NOTEXIST) " 1954*018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 1955d9f59799SBjoern A. Zeeb goto out; 1956d9f59799SBjoern A. Zeeb } 1957d9f59799SBjoern A. Zeeb 195816e688b2SBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); /* sta no longer save to use. */ 1959d9f59799SBjoern A. Zeeb 1960d9f59799SBjoern A. Zeeb IMPROVE("Any bss_info changes to announce?"); 1961d9f59799SBjoern A. Zeeb bss_changed = 0; 1962d9f59799SBjoern A. Zeeb vif->bss_conf.qos = 0; 1963d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 1964616e1330SBjoern A. Zeeb vif->cfg.ssid_len = 0; 1965616e1330SBjoern A. Zeeb memset(vif->cfg.ssid, '\0', sizeof(vif->cfg.ssid)); 1966d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 1967d9f59799SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 1968d9f59799SBjoern A. Zeeb 1969d9f59799SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif); 1970d9f59799SBjoern A. Zeeb 1971d9f59799SBjoern A. Zeeb /* conf_tx */ 1972d9f59799SBjoern A. Zeeb 1973d9f59799SBjoern A. Zeeb /* Take the chan ctx down. */ 1974d9f59799SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 1975c5e25798SBjoern A. Zeeb struct lkpi_chanctx *lchanctx; 1976d9f59799SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 1977d9f59799SBjoern A. Zeeb 1978d9f59799SBjoern A. Zeeb conf = vif->chanctx_conf; 1979d9f59799SBjoern A. Zeeb /* Remove vif context. */ 198068541546SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->bss_conf, &vif->chanctx_conf); 1981d9f59799SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 1982d9f59799SBjoern A. Zeeb 1983d9f59799SBjoern A. Zeeb /* Remove chan ctx. */ 1984d9f59799SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 1985c5e25798SBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(conf); 1986c5e25798SBjoern A. Zeeb free(lchanctx, M_LKPI80211); 1987d9f59799SBjoern A. Zeeb } 1988d9f59799SBjoern A. Zeeb 1989d9f59799SBjoern A. Zeeb error = EALREADY; 1990d9f59799SBjoern A. Zeeb out: 19918ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 1992d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1993d9f59799SBjoern A. Zeeb outni: 1994d9f59799SBjoern A. Zeeb if (ni != NULL) 1995d9f59799SBjoern A. Zeeb ieee80211_free_node(ni); 1996d9f59799SBjoern A. Zeeb return (error); 1997d9f59799SBjoern A. Zeeb } 1998d9f59799SBjoern A. Zeeb 1999d9f59799SBjoern A. Zeeb static int 2000d9f59799SBjoern A. Zeeb lkpi_sta_run_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 2001d9f59799SBjoern A. Zeeb { 2002d9f59799SBjoern A. Zeeb 2003d9f59799SBjoern A. Zeeb return (lkpi_sta_run_to_init(vap, nstate, arg)); 2004d9f59799SBjoern A. Zeeb } 2005d9f59799SBjoern A. Zeeb 2006d9f59799SBjoern A. Zeeb static int 20076b4cac81SBjoern A. Zeeb lkpi_sta_run_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 20086b4cac81SBjoern A. Zeeb { 20096b4cac81SBjoern A. Zeeb int error; 20106b4cac81SBjoern A. Zeeb 2011d9f59799SBjoern A. Zeeb error = lkpi_sta_run_to_init(vap, nstate, arg); 2012d9f59799SBjoern A. Zeeb if (error != 0 && error != EALREADY) 2013d9f59799SBjoern A. Zeeb return (error); 2014d9f59799SBjoern A. Zeeb 2015d9f59799SBjoern A. Zeeb /* At this point iv_bss is long a new node! */ 2016d9f59799SBjoern A. Zeeb 2017d9f59799SBjoern A. Zeeb error |= lkpi_sta_scan_to_auth(vap, nstate, 0); 20186b4cac81SBjoern A. Zeeb return (error); 20196b4cac81SBjoern A. Zeeb } 20206b4cac81SBjoern A. Zeeb 2021d9f59799SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 20226b4cac81SBjoern A. Zeeb 20236b4cac81SBjoern A. Zeeb /* 20246b4cac81SBjoern A. Zeeb * The matches the documented state changes in net80211::sta_newstate(). 20256b4cac81SBjoern A. Zeeb * XXX (1) without CSA and SLEEP yet, * XXX (2) not all unhandled cases 20266b4cac81SBjoern A. Zeeb * there are "invalid" (so there is a room for failure here). 20276b4cac81SBjoern A. Zeeb */ 20286b4cac81SBjoern A. Zeeb struct fsm_state { 20296b4cac81SBjoern A. Zeeb /* INIT, SCAN, AUTH, ASSOC, CAC, RUN, CSA, SLEEP */ 20306b4cac81SBjoern A. Zeeb enum ieee80211_state ostate; 20316b4cac81SBjoern A. Zeeb enum ieee80211_state nstate; 20326b4cac81SBjoern A. Zeeb int (*handler)(struct ieee80211vap *, enum ieee80211_state, int); 20336b4cac81SBjoern A. Zeeb } sta_state_fsm[] = { 20346b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, 20356b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, /* scan_to_init */ 20366b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_INIT, lkpi_sta_auth_to_init }, /* not explicitly in sta_newstate() */ 2037d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_INIT, lkpi_sta_assoc_to_init }, /* Send DEAUTH. */ 2038d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_INIT, lkpi_sta_run_to_init }, /* Send DISASSOC. */ 20396b4cac81SBjoern A. Zeeb 20406b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_SCAN, lkpi_sta_state_do_nada }, 20416b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_SCAN, lkpi_sta_state_do_nada }, 20426b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_SCAN, lkpi_sta_auth_to_scan }, 20436b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_SCAN, lkpi_sta_assoc_to_scan }, 2044d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_SCAN, lkpi_sta_run_to_scan }, /* Beacon miss. */ 20456b4cac81SBjoern A. Zeeb 2046d9f59799SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, /* Send AUTH. */ 2047d9f59799SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, /* Send AUTH. */ 2048d9f59799SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_AUTH, lkpi_sta_a_to_a }, /* Send ?AUTH. */ 2049d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_AUTH, lkpi_sta_assoc_to_auth }, /* Send ?AUTH. */ 2050d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_AUTH, lkpi_sta_run_to_auth }, /* Send ?AUTH. */ 20516b4cac81SBjoern A. Zeeb 2052d9f59799SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_ASSOC, lkpi_sta_auth_to_assoc }, /* Send ASSOCREQ. */ 2053d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_ASSOC, lkpi_sta_a_to_a }, /* Send ASSOCREQ. */ 2054d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_ASSOC, lkpi_sta_run_to_assoc }, /* Send ASSOCREQ/REASSOCREQ. */ 20556b4cac81SBjoern A. Zeeb 20566b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_RUN, lkpi_sta_auth_to_run }, 20576b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_RUN, lkpi_sta_assoc_to_run }, 20586b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_RUN, lkpi_sta_state_do_nada }, 20596b4cac81SBjoern A. Zeeb 20606b4cac81SBjoern A. Zeeb /* Dummy at the end without handler. */ 20616b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_INIT, NULL }, 20626b4cac81SBjoern A. Zeeb }; 20636b4cac81SBjoern A. Zeeb 20646b4cac81SBjoern A. Zeeb static int 20656b4cac81SBjoern A. Zeeb lkpi_iv_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 20666b4cac81SBjoern A. Zeeb { 20676b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 20686b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 20696b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 20706b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 20716b4cac81SBjoern A. Zeeb struct fsm_state *s; 20726b4cac81SBjoern A. Zeeb enum ieee80211_state ostate; 20736b4cac81SBjoern A. Zeeb int error; 20746b4cac81SBjoern A. Zeeb 20756b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 20766b4cac81SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(ic); 20776b4cac81SBjoern A. Zeeb ostate = vap->iv_state; 20786b4cac81SBjoern A. Zeeb 20799d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 20809d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 20816b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x\n", 20826b4cac81SBjoern A. Zeeb __func__, __LINE__, vap, nstate, arg); 20839d9ba2b7SBjoern A. Zeeb #endif 20846b4cac81SBjoern A. Zeeb 20856b4cac81SBjoern A. Zeeb if (vap->iv_opmode == IEEE80211_M_STA) { 20866b4cac81SBjoern A. Zeeb 20876b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 20886b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 20896b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 20906b4cac81SBjoern A. Zeeb 20916b4cac81SBjoern A. Zeeb /* No need to replicate this in most state handlers. */ 20926b4cac81SBjoern A. Zeeb if (ostate == IEEE80211_S_SCAN && nstate != IEEE80211_S_SCAN) 20936b4cac81SBjoern A. Zeeb lkpi_stop_hw_scan(lhw, vif); 20946b4cac81SBjoern A. Zeeb 20956b4cac81SBjoern A. Zeeb s = sta_state_fsm; 20966b4cac81SBjoern A. Zeeb 20976b4cac81SBjoern A. Zeeb } else { 20986b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: only station mode currently supported: " 20996b4cac81SBjoern A. Zeeb "cap %p iv_opmode %d\n", __func__, vap, vap->iv_opmode); 21006b4cac81SBjoern A. Zeeb return (ENOSYS); 21016b4cac81SBjoern A. Zeeb } 21026b4cac81SBjoern A. Zeeb 21036b4cac81SBjoern A. Zeeb error = 0; 21046b4cac81SBjoern A. Zeeb for (; s->handler != NULL; s++) { 21056b4cac81SBjoern A. Zeeb if (ostate == s->ostate && nstate == s->nstate) { 21069d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 21079d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 2108d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: new state %d (%s) ->" 2109d9f59799SBjoern A. Zeeb " %d (%s): arg %d.\n", __func__, 2110d9f59799SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 2111d9f59799SBjoern A. Zeeb nstate, ieee80211_state_name[nstate], arg); 21129d9ba2b7SBjoern A. Zeeb #endif 21136b4cac81SBjoern A. Zeeb error = s->handler(vap, nstate, arg); 21146b4cac81SBjoern A. Zeeb break; 21156b4cac81SBjoern A. Zeeb } 21166b4cac81SBjoern A. Zeeb } 21176b4cac81SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(vap->iv_ic); 21186b4cac81SBjoern A. Zeeb 21196b4cac81SBjoern A. Zeeb if (s->handler == NULL) { 2120d9f59799SBjoern A. Zeeb IMPROVE("turn this into a KASSERT\n"); 21216b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: unsupported state transition " 21226b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s)\n", __func__, 21236b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 21246b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 21256b4cac81SBjoern A. Zeeb return (ENOSYS); 21266b4cac81SBjoern A. Zeeb } 21276b4cac81SBjoern A. Zeeb 21286b4cac81SBjoern A. Zeeb if (error == EALREADY) { 21299d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 21309d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 2131d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: state transition %d (%s) -> " 2132d9f59799SBjoern A. Zeeb "%d (%s): iv_newstate already handled: %d.\n", 2133d9f59799SBjoern A. Zeeb __func__, ostate, ieee80211_state_name[ostate], 2134d9f59799SBjoern A. Zeeb nstate, ieee80211_state_name[nstate], error); 21359d9ba2b7SBjoern A. Zeeb #endif 21366b4cac81SBjoern A. Zeeb return (0); 21376b4cac81SBjoern A. Zeeb } 21386b4cac81SBjoern A. Zeeb 21396b4cac81SBjoern A. Zeeb if (error != 0) { 21406b4cac81SBjoern A. Zeeb /* XXX-BZ currently expected so ignore. */ 21416b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: error %d during state transition " 21426b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s)\n", __func__, error, 21436b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 21446b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 21456b4cac81SBjoern A. Zeeb /* return (error); */ 21466b4cac81SBjoern A. Zeeb } 21476b4cac81SBjoern A. Zeeb 21489d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 21499d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 2150d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x " 2151d9f59799SBjoern A. Zeeb "calling net80211 parent\n", 21526b4cac81SBjoern A. Zeeb __func__, __LINE__, vap, nstate, arg); 21539d9ba2b7SBjoern A. Zeeb #endif 21546b4cac81SBjoern A. Zeeb 21556b4cac81SBjoern A. Zeeb return (lvif->iv_newstate(vap, nstate, arg)); 21566b4cac81SBjoern A. Zeeb } 21576b4cac81SBjoern A. Zeeb 21586b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 21596b4cac81SBjoern A. Zeeb 2160d9f59799SBjoern A. Zeeb /* 2161d9f59799SBjoern A. Zeeb * We overload (*iv_update_bss) as otherwise we have cases in, e.g., 2162d9f59799SBjoern A. Zeeb * net80211::ieee80211_sta_join1() where vap->iv_bss gets replaced by a 2163d9f59799SBjoern A. Zeeb * new node without us knowing and thus our ni/lsta are out of sync. 2164d9f59799SBjoern A. Zeeb */ 2165d9f59799SBjoern A. Zeeb static struct ieee80211_node * 2166d9f59799SBjoern A. Zeeb lkpi_iv_update_bss(struct ieee80211vap *vap, struct ieee80211_node *ni) 2167d9f59799SBjoern A. Zeeb { 2168d9f59799SBjoern A. Zeeb struct lkpi_vif *lvif; 2169d9f59799SBjoern A. Zeeb struct ieee80211_node *obss; 2170d9f59799SBjoern A. Zeeb struct lkpi_sta *lsta; 2171ed3ef56bSBjoern A. Zeeb struct ieee80211_sta *sta; 2172d9f59799SBjoern A. Zeeb 2173d9f59799SBjoern A. Zeeb obss = vap->iv_bss; 2174d9f59799SBjoern A. Zeeb 21759d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 21769d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 21779d9ba2b7SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: obss %p ni_drv_data %p " 21789d9ba2b7SBjoern A. Zeeb "ni %p ni_drv_data %p\n", __func__, 21799d9ba2b7SBjoern A. Zeeb obss, (obss != NULL) ? obss->ni_drv_data : NULL, 21809d9ba2b7SBjoern A. Zeeb ni, (ni != NULL) ? ni->ni_drv_data : NULL); 21819d9ba2b7SBjoern A. Zeeb #endif 21829d9ba2b7SBjoern A. Zeeb 2183d9f59799SBjoern A. Zeeb /* Nothing to copy from. Just return. */ 2184d9f59799SBjoern A. Zeeb if (obss == NULL || obss->ni_drv_data == NULL) 2185d9f59799SBjoern A. Zeeb goto out; 2186d9f59799SBjoern A. Zeeb 2187d9f59799SBjoern A. Zeeb /* Nothing to copy to. Just return. */ 2188d9f59799SBjoern A. Zeeb IMPROVE("clearing the obss might still be needed?"); 2189d9f59799SBjoern A. Zeeb if (ni == NULL) 2190d9f59799SBjoern A. Zeeb goto out; 2191d9f59799SBjoern A. Zeeb 2192d9f59799SBjoern A. Zeeb /* Nothing changed? panic? */ 2193d9f59799SBjoern A. Zeeb if (obss == ni) 2194d9f59799SBjoern A. Zeeb goto out; 2195d9f59799SBjoern A. Zeeb 2196d9f59799SBjoern A. Zeeb lsta = obss->ni_drv_data; 2197d9f59799SBjoern A. Zeeb obss->ni_drv_data = ni->ni_drv_data; 2198d9f59799SBjoern A. Zeeb ni->ni_drv_data = lsta; 2199ed3ef56bSBjoern A. Zeeb if (lsta != NULL) { 2200d9f59799SBjoern A. Zeeb lsta->ni = ni; 2201ed3ef56bSBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 2202ed3ef56bSBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->addr, lsta->ni->ni_macaddr); 22036ffb7bd4SBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->deflink.addr, sta->addr); 2204ed3ef56bSBjoern A. Zeeb } 2205d9f59799SBjoern A. Zeeb lsta = obss->ni_drv_data; 2206ed3ef56bSBjoern A. Zeeb if (lsta != NULL) { 2207d9f59799SBjoern A. Zeeb lsta->ni = obss; 2208ed3ef56bSBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 2209ed3ef56bSBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->addr, lsta->ni->ni_macaddr); 22106ffb7bd4SBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->deflink.addr, sta->addr); 2211ed3ef56bSBjoern A. Zeeb } 2212d9f59799SBjoern A. Zeeb 2213d9f59799SBjoern A. Zeeb out: 2214ed3ef56bSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 2215d9f59799SBjoern A. Zeeb return (lvif->iv_update_bss(vap, ni)); 2216d9f59799SBjoern A. Zeeb } 2217d9f59799SBjoern A. Zeeb 22184a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 22196b4cac81SBjoern A. Zeeb static int 22204a67f1dfSBjoern A. Zeeb lkpi_wme_update(struct lkpi_hw *lhw, struct ieee80211vap *vap, bool planned) 22216b4cac81SBjoern A. Zeeb { 22224a67f1dfSBjoern A. Zeeb struct ieee80211com *ic; 22236b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 22246b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 22256b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 22266b4cac81SBjoern A. Zeeb struct chanAccParams chp; 22276b4cac81SBjoern A. Zeeb struct wmeParams wmeparr[WME_NUM_AC]; 22286b4cac81SBjoern A. Zeeb struct ieee80211_tx_queue_params txqp; 22296b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 22306b4cac81SBjoern A. Zeeb int error; 22316b4cac81SBjoern A. Zeeb uint16_t ac; 22326b4cac81SBjoern A. Zeeb 22336b4cac81SBjoern A. Zeeb IMPROVE(); 22346b4cac81SBjoern A. Zeeb KASSERT(WME_NUM_AC == IEEE80211_NUM_ACS, ("%s: WME_NUM_AC %d != " 22356b4cac81SBjoern A. Zeeb "IEEE80211_NUM_ACS %d\n", __func__, WME_NUM_AC, IEEE80211_NUM_ACS)); 22366b4cac81SBjoern A. Zeeb 22376b4cac81SBjoern A. Zeeb if (vap == NULL) 22386b4cac81SBjoern A. Zeeb return (0); 22396b4cac81SBjoern A. Zeeb 22404a67f1dfSBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WME) == 0) 22414a67f1dfSBjoern A. Zeeb return (0); 22424a67f1dfSBjoern A. Zeeb 22436b4cac81SBjoern A. Zeeb if (lhw->ops->conf_tx == NULL) 22446b4cac81SBjoern A. Zeeb return (0); 22456b4cac81SBjoern A. Zeeb 22464a67f1dfSBjoern A. Zeeb if (!planned && (vap->iv_state != IEEE80211_S_RUN)) { 22474a67f1dfSBjoern A. Zeeb lhw->update_wme = true; 22484a67f1dfSBjoern A. Zeeb return (0); 22494a67f1dfSBjoern A. Zeeb } 22504a67f1dfSBjoern A. Zeeb lhw->update_wme = false; 22516b4cac81SBjoern A. Zeeb 22524a67f1dfSBjoern A. Zeeb ic = lhw->ic; 22536b4cac81SBjoern A. Zeeb ieee80211_wme_ic_getparams(ic, &chp); 22546b4cac81SBjoern A. Zeeb IEEE80211_LOCK(ic); 22556b4cac81SBjoern A. Zeeb for (ac = 0; ac < WME_NUM_AC; ac++) 22566b4cac81SBjoern A. Zeeb wmeparr[ac] = chp.cap_wmeParams[ac]; 22576b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(ic); 22586b4cac81SBjoern A. Zeeb 22594a67f1dfSBjoern A. Zeeb hw = LHW_TO_HW(lhw); 22604a67f1dfSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 22614a67f1dfSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 22624a67f1dfSBjoern A. Zeeb 22636b4cac81SBjoern A. Zeeb /* Configure tx queues (conf_tx) & send BSS_CHANGED_QOS. */ 22646b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 22656b4cac81SBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 22666b4cac81SBjoern A. Zeeb struct wmeParams *wmep; 22676b4cac81SBjoern A. Zeeb 22686b4cac81SBjoern A. Zeeb wmep = &wmeparr[ac]; 22696b4cac81SBjoern A. Zeeb bzero(&txqp, sizeof(txqp)); 22706b4cac81SBjoern A. Zeeb txqp.cw_min = wmep->wmep_logcwmin; 22716b4cac81SBjoern A. Zeeb txqp.cw_max = wmep->wmep_logcwmax; 22726b4cac81SBjoern A. Zeeb txqp.txop = wmep->wmep_txopLimit; 22736b4cac81SBjoern A. Zeeb txqp.aifs = wmep->wmep_aifsn; 227468541546SBjoern A. Zeeb error = lkpi_80211_mo_conf_tx(hw, vif, /* link_id */0, ac, &txqp); 22756b4cac81SBjoern A. Zeeb if (error != 0) 22763f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: conf_tx ac %u failed %d\n", 22776b4cac81SBjoern A. Zeeb __func__, ac, error); 22786b4cac81SBjoern A. Zeeb } 22796b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 22806b4cac81SBjoern A. Zeeb changed = BSS_CHANGED_QOS; 22814a67f1dfSBjoern A. Zeeb if (!planned) 22826b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 22834a67f1dfSBjoern A. Zeeb 22844a67f1dfSBjoern A. Zeeb return (changed); 22854a67f1dfSBjoern A. Zeeb } 22866b4cac81SBjoern A. Zeeb #endif 22876b4cac81SBjoern A. Zeeb 22884a67f1dfSBjoern A. Zeeb static int 22894a67f1dfSBjoern A. Zeeb lkpi_ic_wme_update(struct ieee80211com *ic) 22904a67f1dfSBjoern A. Zeeb { 22914a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 22924a67f1dfSBjoern A. Zeeb struct ieee80211vap *vap; 22934a67f1dfSBjoern A. Zeeb struct lkpi_hw *lhw; 22944a67f1dfSBjoern A. Zeeb 22954a67f1dfSBjoern A. Zeeb IMPROVE("Use the per-VAP callback in net80211."); 22964a67f1dfSBjoern A. Zeeb vap = TAILQ_FIRST(&ic->ic_vaps); 22974a67f1dfSBjoern A. Zeeb if (vap == NULL) 22986b4cac81SBjoern A. Zeeb return (0); 22994a67f1dfSBjoern A. Zeeb 23004a67f1dfSBjoern A. Zeeb lhw = ic->ic_softc; 23014a67f1dfSBjoern A. Zeeb 23024a67f1dfSBjoern A. Zeeb lkpi_wme_update(lhw, vap, false); 23034a67f1dfSBjoern A. Zeeb #endif 23044a67f1dfSBjoern A. Zeeb return (0); /* unused */ 23056b4cac81SBjoern A. Zeeb } 23066b4cac81SBjoern A. Zeeb 23076b4cac81SBjoern A. Zeeb static struct ieee80211vap * 23086b4cac81SBjoern A. Zeeb lkpi_ic_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], 23096b4cac81SBjoern A. Zeeb int unit, enum ieee80211_opmode opmode, int flags, 23106b4cac81SBjoern A. Zeeb const uint8_t bssid[IEEE80211_ADDR_LEN], 23116b4cac81SBjoern A. Zeeb const uint8_t mac[IEEE80211_ADDR_LEN]) 23126b4cac81SBjoern A. Zeeb { 23136b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 23146b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 23156b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 23166b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 23176b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 2318a6042e17SBjoern A. Zeeb struct ieee80211_tx_queue_params txqp; 23196b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 23206b4cac81SBjoern A. Zeeb size_t len; 2321e3a0b120SBjoern A. Zeeb int error, i; 2322a6042e17SBjoern A. Zeeb uint16_t ac; 23236b4cac81SBjoern A. Zeeb 23246b4cac81SBjoern A. Zeeb if (!TAILQ_EMPTY(&ic->ic_vaps)) /* 1 so far. Add <n> once this works. */ 23256b4cac81SBjoern A. Zeeb return (NULL); 23266b4cac81SBjoern A. Zeeb 23276b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 23286b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 23296b4cac81SBjoern A. Zeeb 23306b4cac81SBjoern A. Zeeb len = sizeof(*lvif); 23316b4cac81SBjoern A. Zeeb len += hw->vif_data_size; /* vif->drv_priv */ 23326b4cac81SBjoern A. Zeeb 23336b4cac81SBjoern A. Zeeb lvif = malloc(len, M_80211_VAP, M_WAITOK | M_ZERO); 23346b4cac81SBjoern A. Zeeb mtx_init(&lvif->mtx, "lvif", NULL, MTX_DEF); 23356b4cac81SBjoern A. Zeeb TAILQ_INIT(&lvif->lsta_head); 23366b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 23376b4cac81SBjoern A. Zeeb 23386b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 23396b4cac81SBjoern A. Zeeb memcpy(vif->addr, mac, IEEE80211_ADDR_LEN); 23406b4cac81SBjoern A. Zeeb vif->p2p = false; 23416b4cac81SBjoern A. Zeeb vif->probe_req_reg = false; 23426b4cac81SBjoern A. Zeeb vif->type = lkpi_opmode_to_vif_type(opmode); 23436b4cac81SBjoern A. Zeeb lvif->wdev.iftype = vif->type; 23446b4cac81SBjoern A. Zeeb /* Need to fill in other fields as well. */ 23456b4cac81SBjoern A. Zeeb IMPROVE(); 23466b4cac81SBjoern A. Zeeb 23476b4cac81SBjoern A. Zeeb /* XXX-BZ hardcoded for now! */ 23486b4cac81SBjoern A. Zeeb #if 1 23496b4cac81SBjoern A. Zeeb vif->chanctx_conf = NULL; 2350adff403fSBjoern A. Zeeb vif->bss_conf.vif = vif; 23516ffb7bd4SBjoern A. Zeeb /* vap->iv_myaddr is not set until net80211::vap_setup or vap_attach. */ 23526ffb7bd4SBjoern A. Zeeb IEEE80211_ADDR_COPY(vif->bss_conf.addr, mac); 23536ffb7bd4SBjoern A. Zeeb vif->bss_conf.link_id = 0; /* Non-MLO operation. */ 23546b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.width = NL80211_CHAN_WIDTH_20_NOHT; 23556b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble = false; /* vap->iv_flags IEEE80211_F_SHPREAMBLE */ 23566b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot = false; /* vap->iv_flags IEEE80211_F_SHSLOT */ 23576b4cac81SBjoern A. Zeeb vif->bss_conf.qos = false; 23586b4cac81SBjoern A. Zeeb vif->bss_conf.use_cts_prot = false; /* vap->iv_protmode */ 23596b4cac81SBjoern A. Zeeb vif->bss_conf.ht_operation_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONE; 2360616e1330SBjoern A. Zeeb vif->cfg.aid = 0; 2361616e1330SBjoern A. Zeeb vif->cfg.assoc = false; 2362616e1330SBjoern A. Zeeb vif->cfg.idle = true; 2363616e1330SBjoern A. Zeeb vif->cfg.ps = false; 23646ffb7bd4SBjoern A. Zeeb IMPROVE("Check other fields and then figure out whats is left elsewhere of them"); 2365caaa79c3SBjoern A. Zeeb /* 2366caaa79c3SBjoern A. Zeeb * We need to initialize it to something as the bss_info_changed call 2367caaa79c3SBjoern A. Zeeb * will try to copy from it in iwlwifi and NULL is a panic. 2368caaa79c3SBjoern A. Zeeb * We will set the proper one in scan_to_auth() before being assoc. 2369caaa79c3SBjoern A. Zeeb */ 23706ffb7bd4SBjoern A. Zeeb vif->bss_conf.bssid = ieee80211broadcastaddr; 23716b4cac81SBjoern A. Zeeb #endif 23726b4cac81SBjoern A. Zeeb #if 0 23736b4cac81SBjoern A. Zeeb vif->bss_conf.dtim_period = 0; /* IEEE80211_DTIM_DEFAULT ; must stay 0. */ 23746b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(vif->bss_conf.bssid, bssid); 23756b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = ic->ic_bintval; 23766b4cac81SBjoern A. Zeeb /* iwlwifi bug. */ 23776b4cac81SBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16) 23786b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = 16; 23796b4cac81SBjoern A. Zeeb #endif 2380e3a0b120SBjoern A. Zeeb 23816ffb7bd4SBjoern A. Zeeb /* Link Config */ 23826ffb7bd4SBjoern A. Zeeb vif->link_conf[0] = &vif->bss_conf; 23836ffb7bd4SBjoern A. Zeeb for (i = 0; i < nitems(vif->link_conf); i++) { 23846ffb7bd4SBjoern A. Zeeb IMPROVE("more than 1 link one day"); 23856ffb7bd4SBjoern A. Zeeb } 23866ffb7bd4SBjoern A. Zeeb 2387e3a0b120SBjoern A. Zeeb /* Setup queue defaults; driver may override in (*add_interface). */ 2388e3a0b120SBjoern A. Zeeb for (i = 0; i < IEEE80211_NUM_ACS; i++) { 2389e3a0b120SBjoern A. Zeeb if (ieee80211_hw_check(hw, QUEUE_CONTROL)) 2390e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = IEEE80211_INVAL_HW_QUEUE; 2391e3a0b120SBjoern A. Zeeb else if (hw->queues >= IEEE80211_NUM_ACS) 2392e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = i; 2393e3a0b120SBjoern A. Zeeb else 2394e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = 0; 23950cbcfa19SBjoern A. Zeeb 23960cbcfa19SBjoern A. Zeeb /* Initialize the queue to running. Stopped? */ 23970cbcfa19SBjoern A. Zeeb lvif->hw_queue_stopped[i] = false; 2398e3a0b120SBjoern A. Zeeb } 2399e3a0b120SBjoern A. Zeeb vif->cab_queue = IEEE80211_INVAL_HW_QUEUE; 2400e3a0b120SBjoern A. Zeeb 24016b4cac81SBjoern A. Zeeb IMPROVE(); 24026b4cac81SBjoern A. Zeeb 24036b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_start(hw); 24046b4cac81SBjoern A. Zeeb if (error != 0) { 24053f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: failed to start hw: %d\n", __func__, error); 24066b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 24076b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 24086b4cac81SBjoern A. Zeeb return (NULL); 24096b4cac81SBjoern A. Zeeb } 24106b4cac81SBjoern A. Zeeb 24116b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_add_interface(hw, vif); 24126b4cac81SBjoern A. Zeeb if (error != 0) { 24136b4cac81SBjoern A. Zeeb IMPROVE(); /* XXX-BZ mo_stop()? */ 24143f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: failed to add interface: %d\n", __func__, error); 24156b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 24166b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 24176b4cac81SBjoern A. Zeeb return (NULL); 24186b4cac81SBjoern A. Zeeb } 24196b4cac81SBjoern A. Zeeb 24208891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 24216b4cac81SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lhw->lvif_head, lvif, lvif_entry); 24228891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 24236b4cac81SBjoern A. Zeeb 24246b4cac81SBjoern A. Zeeb /* Set bss_info. */ 24256b4cac81SBjoern A. Zeeb changed = 0; 24266b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 24276b4cac81SBjoern A. Zeeb 2428a6042e17SBjoern A. Zeeb /* Configure tx queues (conf_tx), default WME & send BSS_CHANGED_QOS. */ 2429a6042e17SBjoern A. Zeeb IMPROVE("Hardcoded values; to fix see 802.11-2016, 9.4.2.29 EDCA Parameter Set element"); 2430a6042e17SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 2431a6042e17SBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 2432a6042e17SBjoern A. Zeeb 2433a6042e17SBjoern A. Zeeb bzero(&txqp, sizeof(txqp)); 2434a6042e17SBjoern A. Zeeb txqp.cw_min = 15; 2435a6042e17SBjoern A. Zeeb txqp.cw_max = 1023; 2436a6042e17SBjoern A. Zeeb txqp.txop = 0; 2437a6042e17SBjoern A. Zeeb txqp.aifs = 2; 2438a6042e17SBjoern A. Zeeb error = lkpi_80211_mo_conf_tx(hw, vif, /* link_id */0, ac, &txqp); 2439a6042e17SBjoern A. Zeeb if (error != 0) 2440a6042e17SBjoern A. Zeeb ic_printf(ic, "%s: conf_tx ac %u failed %d\n", 2441a6042e17SBjoern A. Zeeb __func__, ac, error); 2442a6042e17SBjoern A. Zeeb } 2443a6042e17SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 2444a6042e17SBjoern A. Zeeb changed = BSS_CHANGED_QOS; 2445a6042e17SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 24466b4cac81SBjoern A. Zeeb 24476b4cac81SBjoern A. Zeeb /* Force MC init. */ 24486b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(ic, true); 24496b4cac81SBjoern A. Zeeb 24506b4cac81SBjoern A. Zeeb IMPROVE(); 24516b4cac81SBjoern A. Zeeb 24526b4cac81SBjoern A. Zeeb ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid); 24536b4cac81SBjoern A. Zeeb 24546b4cac81SBjoern A. Zeeb /* Override with LinuxKPI method so we can drive mac80211/cfg80211. */ 24556b4cac81SBjoern A. Zeeb lvif->iv_newstate = vap->iv_newstate; 24566b4cac81SBjoern A. Zeeb vap->iv_newstate = lkpi_iv_newstate; 2457d9f59799SBjoern A. Zeeb lvif->iv_update_bss = vap->iv_update_bss; 2458d9f59799SBjoern A. Zeeb vap->iv_update_bss = lkpi_iv_update_bss; 24596b4cac81SBjoern A. Zeeb 24606b4cac81SBjoern A. Zeeb /* Key management. */ 24616b4cac81SBjoern A. Zeeb if (lhw->ops->set_key != NULL) { 2462b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 24636b4cac81SBjoern A. Zeeb vap->iv_key_set = lkpi_iv_key_set; 24646b4cac81SBjoern A. Zeeb vap->iv_key_delete = lkpi_iv_key_delete; 24656b4cac81SBjoern A. Zeeb #endif 24666b4cac81SBjoern A. Zeeb } 24676b4cac81SBjoern A. Zeeb 24686b4cac81SBjoern A. Zeeb ieee80211_ratectl_init(vap); 24696b4cac81SBjoern A. Zeeb 24706b4cac81SBjoern A. Zeeb /* Complete setup. */ 24716b4cac81SBjoern A. Zeeb ieee80211_vap_attach(vap, ieee80211_media_change, 24726b4cac81SBjoern A. Zeeb ieee80211_media_status, mac); 24736b4cac81SBjoern A. Zeeb 24746b4cac81SBjoern A. Zeeb if (hw->max_listen_interval == 0) 24756b4cac81SBjoern A. Zeeb hw->max_listen_interval = 7 * (ic->ic_lintval / ic->ic_bintval); 24766b4cac81SBjoern A. Zeeb hw->conf.listen_interval = hw->max_listen_interval; 24776b4cac81SBjoern A. Zeeb ic->ic_set_channel(ic); 24786b4cac81SBjoern A. Zeeb 24796b4cac81SBjoern A. Zeeb /* XXX-BZ do we need to be able to update these? */ 24806b4cac81SBjoern A. Zeeb hw->wiphy->frag_threshold = vap->iv_fragthreshold; 24816b4cac81SBjoern A. Zeeb lkpi_80211_mo_set_frag_threshold(hw, vap->iv_fragthreshold); 24826b4cac81SBjoern A. Zeeb hw->wiphy->rts_threshold = vap->iv_rtsthreshold; 24836b4cac81SBjoern A. Zeeb lkpi_80211_mo_set_rts_threshold(hw, vap->iv_rtsthreshold); 24846b4cac81SBjoern A. Zeeb /* any others? */ 24856b4cac81SBjoern A. Zeeb IMPROVE(); 24866b4cac81SBjoern A. Zeeb 24876b4cac81SBjoern A. Zeeb return (vap); 24886b4cac81SBjoern A. Zeeb } 24896b4cac81SBjoern A. Zeeb 24904b0af114SBjoern A. Zeeb void 24914b0af114SBjoern A. Zeeb linuxkpi_ieee80211_unregister_hw(struct ieee80211_hw *hw) 24924b0af114SBjoern A. Zeeb { 24934b0af114SBjoern A. Zeeb 24944b0af114SBjoern A. Zeeb wiphy_unregister(hw->wiphy); 24954b0af114SBjoern A. Zeeb linuxkpi_ieee80211_ifdetach(hw); 24964b0af114SBjoern A. Zeeb 24974b0af114SBjoern A. Zeeb IMPROVE(); 24984b0af114SBjoern A. Zeeb } 24994b0af114SBjoern A. Zeeb 25004b0af114SBjoern A. Zeeb void 25014b0af114SBjoern A. Zeeb linuxkpi_ieee80211_restart_hw(struct ieee80211_hw *hw) 25024b0af114SBjoern A. Zeeb { 25034b0af114SBjoern A. Zeeb 25044b0af114SBjoern A. Zeeb TODO(); 25054b0af114SBjoern A. Zeeb } 25064b0af114SBjoern A. Zeeb 25076b4cac81SBjoern A. Zeeb static void 25086b4cac81SBjoern A. Zeeb lkpi_ic_vap_delete(struct ieee80211vap *vap) 25096b4cac81SBjoern A. Zeeb { 25106b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 25116b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 25126b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 25136b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 25146b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 25156b4cac81SBjoern A. Zeeb 25166b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 25176b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 25186b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 25196b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 25206b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 25216b4cac81SBjoern A. Zeeb 25228891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 25236b4cac81SBjoern A. Zeeb TAILQ_REMOVE(&lhw->lvif_head, lvif, lvif_entry); 25248891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 25256b4cac81SBjoern A. Zeeb 25266b4cac81SBjoern A. Zeeb ieee80211_ratectl_deinit(vap); 25276b4cac81SBjoern A. Zeeb ieee80211_vap_detach(vap); 2528dbf76919SBjoern A. Zeeb 2529dbf76919SBjoern A. Zeeb IMPROVE("clear up other bits in this state"); 2530dbf76919SBjoern A. Zeeb 2531dbf76919SBjoern A. Zeeb lkpi_80211_mo_remove_interface(hw, vif); 2532dbf76919SBjoern A. Zeeb 25336c38c6b1SBjoern A. Zeeb /* Single VAP, so we can do this here. */ 25346c38c6b1SBjoern A. Zeeb lkpi_80211_mo_stop(hw); 25356c38c6b1SBjoern A. Zeeb 25366b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 25376b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 25386b4cac81SBjoern A. Zeeb } 25396b4cac81SBjoern A. Zeeb 25406b4cac81SBjoern A. Zeeb static void 25416b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast(struct ieee80211com *ic) 25426b4cac81SBjoern A. Zeeb { 25436b4cac81SBjoern A. Zeeb 25446b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(ic, false); 25456b4cac81SBjoern A. Zeeb TRACEOK(); 25466b4cac81SBjoern A. Zeeb } 25476b4cac81SBjoern A. Zeeb 25486b4cac81SBjoern A. Zeeb static void 25496b4cac81SBjoern A. Zeeb lkpi_ic_update_promisc(struct ieee80211com *ic) 25506b4cac81SBjoern A. Zeeb { 25516b4cac81SBjoern A. Zeeb 25526b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 25536b4cac81SBjoern A. Zeeb } 25546b4cac81SBjoern A. Zeeb 25556b4cac81SBjoern A. Zeeb static void 25566b4cac81SBjoern A. Zeeb lkpi_ic_update_chw(struct ieee80211com *ic) 25576b4cac81SBjoern A. Zeeb { 25586b4cac81SBjoern A. Zeeb 25596b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 25606b4cac81SBjoern A. Zeeb } 25616b4cac81SBjoern A. Zeeb 25626b4cac81SBjoern A. Zeeb /* Start / stop device. */ 25636b4cac81SBjoern A. Zeeb static void 25646b4cac81SBjoern A. Zeeb lkpi_ic_parent(struct ieee80211com *ic) 25656b4cac81SBjoern A. Zeeb { 25666b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 25678d58a057SBjoern A. Zeeb #ifdef HW_START_STOP 25686b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 25696b4cac81SBjoern A. Zeeb int error; 25708d58a057SBjoern A. Zeeb #endif 25716b4cac81SBjoern A. Zeeb bool start_all; 25726b4cac81SBjoern A. Zeeb 25736b4cac81SBjoern A. Zeeb IMPROVE(); 25746b4cac81SBjoern A. Zeeb 25756b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 25768d58a057SBjoern A. Zeeb #ifdef HW_START_STOP 25776b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 25788d58a057SBjoern A. Zeeb #endif 25796b4cac81SBjoern A. Zeeb start_all = false; 25806b4cac81SBjoern A. Zeeb 25818ac540d3SBjoern A. Zeeb /* IEEE80211_UNLOCK(ic); */ 25828ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 25836b4cac81SBjoern A. Zeeb if (ic->ic_nrunning > 0) { 25848d58a057SBjoern A. Zeeb #ifdef HW_START_STOP 25856b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_start(hw); 25866b4cac81SBjoern A. Zeeb if (error == 0) 25878d58a057SBjoern A. Zeeb #endif 25886b4cac81SBjoern A. Zeeb start_all = true; 25896b4cac81SBjoern A. Zeeb } else { 25908d58a057SBjoern A. Zeeb #ifdef HW_START_STOP 25916b4cac81SBjoern A. Zeeb lkpi_80211_mo_stop(hw); 25928d58a057SBjoern A. Zeeb #endif 25936b4cac81SBjoern A. Zeeb } 25948ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 25958ac540d3SBjoern A. Zeeb /* IEEE80211_LOCK(ic); */ 25966b4cac81SBjoern A. Zeeb 25976b4cac81SBjoern A. Zeeb if (start_all) 25986b4cac81SBjoern A. Zeeb ieee80211_start_all(ic); 25996b4cac81SBjoern A. Zeeb } 26006b4cac81SBjoern A. Zeeb 26016b4cac81SBjoern A. Zeeb bool 26026b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_is_ie_id_in_ie_buf(const u8 ie, const u8 *ie_ids, 26036b4cac81SBjoern A. Zeeb size_t ie_ids_len) 26046b4cac81SBjoern A. Zeeb { 26056b4cac81SBjoern A. Zeeb int i; 26066b4cac81SBjoern A. Zeeb 26076b4cac81SBjoern A. Zeeb for (i = 0; i < ie_ids_len; i++) { 26086b4cac81SBjoern A. Zeeb if (ie == *ie_ids) 26096b4cac81SBjoern A. Zeeb return (true); 26106b4cac81SBjoern A. Zeeb } 26116b4cac81SBjoern A. Zeeb 26126b4cac81SBjoern A. Zeeb return (false); 26136b4cac81SBjoern A. Zeeb } 26146b4cac81SBjoern A. Zeeb 26156b4cac81SBjoern A. Zeeb /* Return true if skipped; false if error. */ 26166b4cac81SBjoern A. Zeeb bool 26176b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ie_advance(size_t *xp, const u8 *ies, size_t ies_len) 26186b4cac81SBjoern A. Zeeb { 26196b4cac81SBjoern A. Zeeb size_t x; 26206b4cac81SBjoern A. Zeeb uint8_t l; 26216b4cac81SBjoern A. Zeeb 26226b4cac81SBjoern A. Zeeb x = *xp; 26236b4cac81SBjoern A. Zeeb 26246b4cac81SBjoern A. Zeeb KASSERT(x < ies_len, ("%s: x %zu ies_len %zu ies %p\n", 26256b4cac81SBjoern A. Zeeb __func__, x, ies_len, ies)); 26266b4cac81SBjoern A. Zeeb l = ies[x + 1]; 26276b4cac81SBjoern A. Zeeb x += 2 + l; 26286b4cac81SBjoern A. Zeeb 26296b4cac81SBjoern A. Zeeb if (x > ies_len) 26306b4cac81SBjoern A. Zeeb return (false); 26316b4cac81SBjoern A. Zeeb 26326b4cac81SBjoern A. Zeeb *xp = x; 26336b4cac81SBjoern A. Zeeb return (true); 26346b4cac81SBjoern A. Zeeb } 26356b4cac81SBjoern A. Zeeb 2636d9945d78SBjoern A. Zeeb static uint8_t * 2637d9945d78SBjoern A. Zeeb lkpi_scan_ies_add(uint8_t *p, struct ieee80211_scan_ies *scan_ies, 2638d9945d78SBjoern A. Zeeb uint32_t band_mask, struct ieee80211vap *vap, struct ieee80211_hw *hw) 26396b4cac81SBjoern A. Zeeb { 2640d9945d78SBjoern A. Zeeb struct ieee80211_supported_band *supband; 2641d9945d78SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 26423dd98026SBjoern A. Zeeb struct ieee80211com *ic; 2643d9945d78SBjoern A. Zeeb const struct ieee80211_channel *chan; 2644d9945d78SBjoern A. Zeeb const struct ieee80211_rateset *rs; 2645d9945d78SBjoern A. Zeeb uint8_t *pb; 2646d9945d78SBjoern A. Zeeb int band, i; 26476b4cac81SBjoern A. Zeeb 26483dd98026SBjoern A. Zeeb ic = vap->iv_ic; 2649d9945d78SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 2650d9945d78SBjoern A. Zeeb if ((band_mask & (1 << band)) == 0) 2651d9945d78SBjoern A. Zeeb continue; 2652d9945d78SBjoern A. Zeeb 2653d9945d78SBjoern A. Zeeb supband = hw->wiphy->bands[band]; 2654d9945d78SBjoern A. Zeeb /* 2655d9945d78SBjoern A. Zeeb * This should not happen; 2656d9945d78SBjoern A. Zeeb * band_mask is a bitmask of valid bands to scan on. 2657d9945d78SBjoern A. Zeeb */ 2658d9945d78SBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 2659d9945d78SBjoern A. Zeeb continue; 2660d9945d78SBjoern A. Zeeb 2661d9945d78SBjoern A. Zeeb /* Find a first channel to get the mode and rates from. */ 2662d9945d78SBjoern A. Zeeb channels = supband->channels; 2663d9945d78SBjoern A. Zeeb chan = NULL; 2664d9945d78SBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 2665d9945d78SBjoern A. Zeeb 2666d9945d78SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) 2667d9945d78SBjoern A. Zeeb continue; 2668d9945d78SBjoern A. Zeeb 26693dd98026SBjoern A. Zeeb chan = ieee80211_find_channel(ic, 2670d9945d78SBjoern A. Zeeb channels[i].center_freq, 0); 2671d9945d78SBjoern A. Zeeb if (chan != NULL) 2672d9945d78SBjoern A. Zeeb break; 2673d9945d78SBjoern A. Zeeb } 2674d9945d78SBjoern A. Zeeb 2675d9945d78SBjoern A. Zeeb /* This really should not happen. */ 2676d9945d78SBjoern A. Zeeb if (chan == NULL) 2677d9945d78SBjoern A. Zeeb continue; 2678d9945d78SBjoern A. Zeeb 2679d9945d78SBjoern A. Zeeb pb = p; 26803dd98026SBjoern A. Zeeb rs = ieee80211_get_suprates(ic, chan); /* calls chan2mode */ 2681d9945d78SBjoern A. Zeeb p = ieee80211_add_rates(p, rs); 2682d9945d78SBjoern A. Zeeb p = ieee80211_add_xrates(p, rs); 2683d9945d78SBjoern A. Zeeb 26843dd98026SBjoern A. Zeeb #if defined(LKPI_80211_HT) 26853dd98026SBjoern A. Zeeb if ((vap->iv_flags_ht & IEEE80211_FHT_HT) != 0) { 26863dd98026SBjoern A. Zeeb struct ieee80211_channel *c; 26873dd98026SBjoern A. Zeeb 26883dd98026SBjoern A. Zeeb c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan, 26893dd98026SBjoern A. Zeeb vap->iv_flags_ht); 26903dd98026SBjoern A. Zeeb p = ieee80211_add_htcap_ch(p, vap, c); 26913dd98026SBjoern A. Zeeb } 26923dd98026SBjoern A. Zeeb #endif 26933dd98026SBjoern A. Zeeb #if defined(LKPI_80211_VHT) 26943dd98026SBjoern A. Zeeb if ((vap->iv_vht_flags & IEEE80211_FVHT_VHT) != 0) { 26953dd98026SBjoern A. Zeeb struct ieee80211_channel *c; 26963dd98026SBjoern A. Zeeb 26973dd98026SBjoern A. Zeeb c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan, 26983dd98026SBjoern A. Zeeb vap->iv_flags_ht); 26993dd98026SBjoern A. Zeeb c = ieee80211_vht_adjust_channel(ic, c, 27003dd98026SBjoern A. Zeeb vap->iv_vht_flags); 27013dd98026SBjoern A. Zeeb p = ieee80211_add_vhtcap_ch(p, vap, c); 27023dd98026SBjoern A. Zeeb } 27033dd98026SBjoern A. Zeeb #endif 27043dd98026SBjoern A. Zeeb 2705d9945d78SBjoern A. Zeeb scan_ies->ies[band] = pb; 2706d9945d78SBjoern A. Zeeb scan_ies->len[band] = p - pb; 2707d9945d78SBjoern A. Zeeb } 2708d9945d78SBjoern A. Zeeb 2709d9945d78SBjoern A. Zeeb /* Add common_ies */ 2710d9945d78SBjoern A. Zeeb pb = p; 2711d9945d78SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WPA1) != 0 && 2712d9945d78SBjoern A. Zeeb vap->iv_wpa_ie != NULL) { 2713d9945d78SBjoern A. Zeeb memcpy(p, vap->iv_wpa_ie, 2 + vap->iv_wpa_ie[1]); 2714d9945d78SBjoern A. Zeeb p += 2 + vap->iv_wpa_ie[1]; 2715d9945d78SBjoern A. Zeeb } 2716d9945d78SBjoern A. Zeeb if (vap->iv_appie_probereq != NULL) { 2717d9945d78SBjoern A. Zeeb memcpy(p, vap->iv_appie_probereq->ie_data, 2718d9945d78SBjoern A. Zeeb vap->iv_appie_probereq->ie_len); 2719d9945d78SBjoern A. Zeeb p += vap->iv_appie_probereq->ie_len; 2720d9945d78SBjoern A. Zeeb } 2721d9945d78SBjoern A. Zeeb scan_ies->common_ies = pb; 2722d9945d78SBjoern A. Zeeb scan_ies->common_ie_len = p - pb; 2723d9945d78SBjoern A. Zeeb 2724d9945d78SBjoern A. Zeeb return (p); 27256b4cac81SBjoern A. Zeeb } 27266b4cac81SBjoern A. Zeeb 27276b4cac81SBjoern A. Zeeb static void 27286b4cac81SBjoern A. Zeeb lkpi_ic_scan_start(struct ieee80211com *ic) 27296b4cac81SBjoern A. Zeeb { 27306b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 27316b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 27326b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 27336b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 27346b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 27356b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 27366b4cac81SBjoern A. Zeeb int error; 27378ac540d3SBjoern A. Zeeb bool is_hw_scan; 27386b4cac81SBjoern A. Zeeb 27396b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 27408ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 2741a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) { 27426b4cac81SBjoern A. Zeeb /* A scan is still running. */ 27438ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 27446b4cac81SBjoern A. Zeeb return; 27456b4cac81SBjoern A. Zeeb } 27468ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 27478ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 27486b4cac81SBjoern A. Zeeb 27496b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 27506b4cac81SBjoern A. Zeeb vap = ss->ss_vap; 27516b4cac81SBjoern A. Zeeb if (vap->iv_state != IEEE80211_S_SCAN) { 2752d3ef7fb4SBjoern A. Zeeb IMPROVE("We need to be able to scan if not in S_SCAN"); 27536b4cac81SBjoern A. Zeeb return; 27546b4cac81SBjoern A. Zeeb } 27556b4cac81SBjoern A. Zeeb 27566b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 27578ac540d3SBjoern A. Zeeb if (!is_hw_scan) { 2758a486fbbdSBjoern A. Zeeb /* If hw_scan is cleared clear FEXT_SCAN_OFFLOAD too. */ 2759a486fbbdSBjoern A. Zeeb vap->iv_flags_ext &= ~IEEE80211_FEXT_SCAN_OFFLOAD; 2760d3ef7fb4SBjoern A. Zeeb sw_scan: 27616b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 27626b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 2763086be6a8SBjoern A. Zeeb 2764086be6a8SBjoern A. Zeeb if (vap->iv_state == IEEE80211_S_SCAN) 2765086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, false); 2766086be6a8SBjoern A. Zeeb 27676b4cac81SBjoern A. Zeeb lkpi_80211_mo_sw_scan_start(hw, vif, vif->addr); 27686b4cac81SBjoern A. Zeeb /* net80211::scan_start() handled PS for us. */ 27696b4cac81SBjoern A. Zeeb IMPROVE(); 27706b4cac81SBjoern A. Zeeb /* XXX Also means it is too late to flush queues? 27716b4cac81SBjoern A. Zeeb * need to check iv_sta_ps or overload? */ 27726b4cac81SBjoern A. Zeeb /* XXX want to adjust ss end time/ maxdwell? */ 27736b4cac81SBjoern A. Zeeb 27746b4cac81SBjoern A. Zeeb } else { 27756b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 27766b4cac81SBjoern A. Zeeb struct ieee80211_scan_request *hw_req; 27776b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *lc, **cpp; 27786b4cac81SBjoern A. Zeeb struct cfg80211_ssid *ssids; 27796b4cac81SBjoern A. Zeeb struct cfg80211_scan_6ghz_params *s6gp; 27806b4cac81SBjoern A. Zeeb size_t chan_len, nchan, ssids_len, s6ghzlen; 2781d9945d78SBjoern A. Zeeb int band, i, ssid_count, common_ie_len; 2782d9945d78SBjoern A. Zeeb uint32_t band_mask; 2783d9945d78SBjoern A. Zeeb uint8_t *ie, *ieend; 27843206587aSBjoern A. Zeeb bool running; 2785d9945d78SBjoern A. Zeeb 2786d9945d78SBjoern A. Zeeb ssid_count = min(ss->ss_nssid, hw->wiphy->max_scan_ssids); 2787d9945d78SBjoern A. Zeeb ssids_len = ssid_count * sizeof(*ssids); 27886b4cac81SBjoern A. Zeeb s6ghzlen = 0 * (sizeof(*s6gp)); /* XXX-BZ */ 27896b4cac81SBjoern A. Zeeb 2790d9945d78SBjoern A. Zeeb band_mask = 0; 27916b4cac81SBjoern A. Zeeb nchan = 0; 2792d9945d78SBjoern A. Zeeb for (i = ss->ss_next; i < ss->ss_last; i++) { 27936b4cac81SBjoern A. Zeeb nchan++; 2794d9945d78SBjoern A. Zeeb band = lkpi_net80211_chan_to_nl80211_band( 2795d9945d78SBjoern A. Zeeb ss->ss_chans[ss->ss_next + i]); 2796d9945d78SBjoern A. Zeeb band_mask |= (1 << band); 2797d9945d78SBjoern A. Zeeb } 27983206587aSBjoern A. Zeeb 27993206587aSBjoern A. Zeeb if (!ieee80211_hw_check(hw, SINGLE_SCAN_ON_ALL_BANDS)) { 28003206587aSBjoern A. Zeeb IMPROVE("individual band scans not yet supported, only scanning first band"); 28013206587aSBjoern A. Zeeb /* In theory net80211 should drive this. */ 28023206587aSBjoern A. Zeeb /* Probably we need to add local logic for now; 28033206587aSBjoern A. Zeeb * need to deal with scan_complete 28043206587aSBjoern A. Zeeb * and cancel_scan and keep local state. 28053206587aSBjoern A. Zeeb * Also cut the nchan down above. 28063206587aSBjoern A. Zeeb */ 28073206587aSBjoern A. Zeeb /* XXX-BZ ath10k does not set this but still does it? &$%^ */ 28083206587aSBjoern A. Zeeb } 28093206587aSBjoern A. Zeeb 28106b4cac81SBjoern A. Zeeb chan_len = nchan * (sizeof(lc) + sizeof(*lc)); 28116b4cac81SBjoern A. Zeeb 2812d9945d78SBjoern A. Zeeb common_ie_len = 0; 2813d9945d78SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WPA1) != 0 && 2814d9945d78SBjoern A. Zeeb vap->iv_wpa_ie != NULL) 2815d9945d78SBjoern A. Zeeb common_ie_len += vap->iv_wpa_ie[1]; 2816d9945d78SBjoern A. Zeeb if (vap->iv_appie_probereq != NULL) 2817d9945d78SBjoern A. Zeeb common_ie_len += vap->iv_appie_probereq->ie_len; 2818d9945d78SBjoern A. Zeeb 2819d9945d78SBjoern A. Zeeb /* We would love to check this at an earlier stage... */ 2820d9945d78SBjoern A. Zeeb if (common_ie_len > hw->wiphy->max_scan_ie_len) { 2821d9945d78SBjoern A. Zeeb ic_printf(ic, "WARNING: %s: common_ie_len %d > " 2822d9945d78SBjoern A. Zeeb "wiphy->max_scan_ie_len %d\n", __func__, 2823d9945d78SBjoern A. Zeeb common_ie_len, hw->wiphy->max_scan_ie_len); 2824d9945d78SBjoern A. Zeeb } 2825d9945d78SBjoern A. Zeeb 28263206587aSBjoern A. Zeeb hw_req = malloc(sizeof(*hw_req) + ssids_len + 2827d9945d78SBjoern A. Zeeb s6ghzlen + chan_len + lhw->supbands * lhw->scan_ie_len + 2828d9945d78SBjoern A. Zeeb common_ie_len, M_LKPI80211, M_WAITOK | M_ZERO); 28296b4cac81SBjoern A. Zeeb 28306b4cac81SBjoern A. Zeeb hw_req->req.flags = 0; /* XXX ??? */ 28316b4cac81SBjoern A. Zeeb /* hw_req->req.wdev */ 28326b4cac81SBjoern A. Zeeb hw_req->req.wiphy = hw->wiphy; 28336b4cac81SBjoern A. Zeeb hw_req->req.no_cck = false; /* XXX */ 28346b4cac81SBjoern A. Zeeb #if 0 28356b4cac81SBjoern A. Zeeb /* This seems to pessimise default scanning behaviour. */ 28366b4cac81SBjoern A. Zeeb hw_req->req.duration_mandatory = TICKS_2_USEC(ss->ss_mindwell); 28376b4cac81SBjoern A. Zeeb hw_req->req.duration = TICKS_2_USEC(ss->ss_maxdwell); 28386b4cac81SBjoern A. Zeeb #endif 28396b4cac81SBjoern A. Zeeb #ifdef __notyet__ 28406b4cac81SBjoern A. Zeeb hw_req->req.flags |= NL80211_SCAN_FLAG_RANDOM_ADDR; 28416b4cac81SBjoern A. Zeeb memcpy(hw_req->req.mac_addr, xxx, IEEE80211_ADDR_LEN); 28426b4cac81SBjoern A. Zeeb memset(hw_req->req.mac_addr_mask, 0xxx, IEEE80211_ADDR_LEN); 28436b4cac81SBjoern A. Zeeb #endif 2844e1e90be0SBjoern A. Zeeb eth_broadcast_addr(hw_req->req.bssid); 28456b4cac81SBjoern A. Zeeb 28466b4cac81SBjoern A. Zeeb hw_req->req.n_channels = nchan; 28476b4cac81SBjoern A. Zeeb cpp = (struct linuxkpi_ieee80211_channel **)(hw_req + 1); 28486b4cac81SBjoern A. Zeeb lc = (struct linuxkpi_ieee80211_channel *)(cpp + nchan); 28496b4cac81SBjoern A. Zeeb for (i = 0; i < nchan; i++) { 28506b4cac81SBjoern A. Zeeb *(cpp + i) = 28516b4cac81SBjoern A. Zeeb (struct linuxkpi_ieee80211_channel *)(lc + i); 28526b4cac81SBjoern A. Zeeb } 28536b4cac81SBjoern A. Zeeb for (i = 0; i < nchan; i++) { 28546b4cac81SBjoern A. Zeeb c = ss->ss_chans[ss->ss_next + i]; 28556b4cac81SBjoern A. Zeeb 28566b4cac81SBjoern A. Zeeb lc->hw_value = c->ic_ieee; 28573206587aSBjoern A. Zeeb lc->center_freq = c->ic_freq; /* XXX */ 28586b4cac81SBjoern A. Zeeb /* lc->flags */ 28596b4cac81SBjoern A. Zeeb lc->band = lkpi_net80211_chan_to_nl80211_band(c); 28606b4cac81SBjoern A. Zeeb lc->max_power = c->ic_maxpower; 28616b4cac81SBjoern A. Zeeb /* lc-> ... */ 28626b4cac81SBjoern A. Zeeb lc++; 28636b4cac81SBjoern A. Zeeb } 28646b4cac81SBjoern A. Zeeb 2865d9945d78SBjoern A. Zeeb hw_req->req.n_ssids = ssid_count; 28666b4cac81SBjoern A. Zeeb if (hw_req->req.n_ssids > 0) { 28676b4cac81SBjoern A. Zeeb ssids = (struct cfg80211_ssid *)lc; 28686b4cac81SBjoern A. Zeeb hw_req->req.ssids = ssids; 2869d9945d78SBjoern A. Zeeb for (i = 0; i < ssid_count; i++) { 28706b4cac81SBjoern A. Zeeb ssids->ssid_len = ss->ss_ssid[i].len; 28716b4cac81SBjoern A. Zeeb memcpy(ssids->ssid, ss->ss_ssid[i].ssid, 28726b4cac81SBjoern A. Zeeb ss->ss_ssid[i].len); 28736b4cac81SBjoern A. Zeeb ssids++; 28746b4cac81SBjoern A. Zeeb } 28756b4cac81SBjoern A. Zeeb s6gp = (struct cfg80211_scan_6ghz_params *)ssids; 28766b4cac81SBjoern A. Zeeb } else { 28776b4cac81SBjoern A. Zeeb s6gp = (struct cfg80211_scan_6ghz_params *)lc; 28786b4cac81SBjoern A. Zeeb } 28796b4cac81SBjoern A. Zeeb 28806b4cac81SBjoern A. Zeeb /* 6GHz one day. */ 28816b4cac81SBjoern A. Zeeb hw_req->req.n_6ghz_params = 0; 28826b4cac81SBjoern A. Zeeb hw_req->req.scan_6ghz_params = NULL; 28836b4cac81SBjoern A. Zeeb hw_req->req.scan_6ghz = false; /* Weird boolean; not what you think. */ 28846b4cac81SBjoern A. Zeeb /* s6gp->... */ 28856b4cac81SBjoern A. Zeeb 2886d9945d78SBjoern A. Zeeb ie = ieend = (uint8_t *)s6gp; 2887d9945d78SBjoern A. Zeeb /* Copy per-band IEs, copy common IEs */ 2888d9945d78SBjoern A. Zeeb ieend = lkpi_scan_ies_add(ie, &hw_req->ies, band_mask, vap, hw); 2889d9945d78SBjoern A. Zeeb hw_req->req.ie = ie; 2890d9945d78SBjoern A. Zeeb hw_req->req.ie_len = ieend - ie; 2891d9945d78SBjoern A. Zeeb 28926b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 28936b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 28943206587aSBjoern A. Zeeb 28953206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 28963206587aSBjoern A. Zeeb /* Re-check under lock. */ 28973206587aSBjoern A. Zeeb running = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0; 28983206587aSBjoern A. Zeeb if (!running) { 28993206587aSBjoern A. Zeeb KASSERT(lhw->hw_req == NULL, ("%s: ic %p lhw %p hw_req %p " 29003206587aSBjoern A. Zeeb "!= NULL\n", __func__, ic, lhw, lhw->hw_req)); 29013206587aSBjoern A. Zeeb 29023206587aSBjoern A. Zeeb lhw->scan_flags |= LKPI_LHW_SCAN_RUNNING; 29033206587aSBjoern A. Zeeb lhw->hw_req = hw_req; 29043206587aSBjoern A. Zeeb } 29053206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 29063206587aSBjoern A. Zeeb if (running) { 29073206587aSBjoern A. Zeeb free(hw_req, M_LKPI80211); 29083206587aSBjoern A. Zeeb return; 29093206587aSBjoern A. Zeeb } 29103206587aSBjoern A. Zeeb 29116b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_hw_scan(hw, vif, hw_req); 29126b4cac81SBjoern A. Zeeb if (error != 0) { 2913d9945d78SBjoern A. Zeeb ieee80211_cancel_scan(vap); 2914d9945d78SBjoern A. Zeeb 29153206587aSBjoern A. Zeeb /* 29163206587aSBjoern A. Zeeb * ieee80211_scan_completed must be called in either 29173206587aSBjoern A. Zeeb * case of error or none. So let the free happen there 29183206587aSBjoern A. Zeeb * and only there. 29193206587aSBjoern A. Zeeb * That would be fine in theory but in practice drivers 29203206587aSBjoern A. Zeeb * behave differently: 29213206587aSBjoern A. Zeeb * ath10k does not return hw_scan until after scan_complete 29223206587aSBjoern A. Zeeb * and can then still return an error. 29233206587aSBjoern A. Zeeb * rtw88 can return 1 or -EBUSY without scan_complete 29243206587aSBjoern A. Zeeb * iwlwifi can return various errors before scan starts 29253206587aSBjoern A. Zeeb * ... 29263206587aSBjoern A. Zeeb * So we cannot rely on that behaviour and have to check 29273206587aSBjoern A. Zeeb * and balance between both code paths. 29283206587aSBjoern A. Zeeb */ 29293206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 29303206587aSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) { 29313206587aSBjoern A. Zeeb free(lhw->hw_req, M_LKPI80211); 29326b4cac81SBjoern A. Zeeb lhw->hw_req = NULL; 29333206587aSBjoern A. Zeeb lhw->scan_flags &= ~LKPI_LHW_SCAN_RUNNING; 29343206587aSBjoern A. Zeeb } 29353206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 2936d3ef7fb4SBjoern A. Zeeb 2937d3ef7fb4SBjoern A. Zeeb /* 2938d3ef7fb4SBjoern A. Zeeb * XXX-SIGH magic number. 2939d3ef7fb4SBjoern A. Zeeb * rtw88 has a magic "return 1" if offloading scan is 2940d3ef7fb4SBjoern A. Zeeb * not possible. Fall back to sw scan in that case. 2941d3ef7fb4SBjoern A. Zeeb */ 2942196cfd0bSBjoern A. Zeeb if (error == 1) { 29438ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 2944a486fbbdSBjoern A. Zeeb lhw->scan_flags &= ~LKPI_LHW_SCAN_HW; 29458ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 29463206587aSBjoern A. Zeeb /* 29473206587aSBjoern A. Zeeb * XXX If we clear this now and later a driver 29483206587aSBjoern A. Zeeb * thinks it * can do a hw_scan again, we will 29493206587aSBjoern A. Zeeb * currently not re-enable it? 29503206587aSBjoern A. Zeeb */ 29513206587aSBjoern A. Zeeb vap->iv_flags_ext &= ~IEEE80211_FEXT_SCAN_OFFLOAD; 2952196cfd0bSBjoern A. Zeeb ieee80211_start_scan(vap, 2953196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_ACTIVE | 2954196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_NOPICK | 2955196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_ONCE, 2956196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_FOREVER, 2957196cfd0bSBjoern A. Zeeb ss->ss_mindwell ? ss->ss_mindwell : msecs_to_ticks(20), 2958196cfd0bSBjoern A. Zeeb ss->ss_maxdwell ? ss->ss_maxdwell : msecs_to_ticks(200), 2959196cfd0bSBjoern A. Zeeb vap->iv_des_nssid, vap->iv_des_ssid); 2960d3ef7fb4SBjoern A. Zeeb goto sw_scan; 2961196cfd0bSBjoern A. Zeeb } 2962d3ef7fb4SBjoern A. Zeeb 2963d3ef7fb4SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: hw_scan returned %d\n", 2964d3ef7fb4SBjoern A. Zeeb __func__, error); 29656b4cac81SBjoern A. Zeeb } 29666b4cac81SBjoern A. Zeeb } 29676b4cac81SBjoern A. Zeeb } 29686b4cac81SBjoern A. Zeeb 29696b4cac81SBjoern A. Zeeb static void 29706b4cac81SBjoern A. Zeeb lkpi_ic_scan_end(struct ieee80211com *ic) 29716b4cac81SBjoern A. Zeeb { 29726b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 29738ac540d3SBjoern A. Zeeb bool is_hw_scan; 29746b4cac81SBjoern A. Zeeb 29756b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 29768ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 2977a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) == 0) { 29788ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 29796b4cac81SBjoern A. Zeeb return; 29806b4cac81SBjoern A. Zeeb } 29818ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 29828ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 29836b4cac81SBjoern A. Zeeb 29848ac540d3SBjoern A. Zeeb if (!is_hw_scan) { 2985a486fbbdSBjoern A. Zeeb struct ieee80211_scan_state *ss; 2986a486fbbdSBjoern A. Zeeb struct ieee80211vap *vap; 29876b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 29886b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 29896b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 29906b4cac81SBjoern A. Zeeb 2991a486fbbdSBjoern A. Zeeb ss = ic->ic_scan; 2992a486fbbdSBjoern A. Zeeb vap = ss->ss_vap; 29936b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 29946b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 29956b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 2996a486fbbdSBjoern A. Zeeb 29976b4cac81SBjoern A. Zeeb lkpi_80211_mo_sw_scan_complete(hw, vif); 29986b4cac81SBjoern A. Zeeb 29996b4cac81SBjoern A. Zeeb /* Send PS to stop buffering if n80211 does not for us? */ 3000086be6a8SBjoern A. Zeeb 3001086be6a8SBjoern A. Zeeb if (vap->iv_state == IEEE80211_S_SCAN) 3002086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true); 30036b4cac81SBjoern A. Zeeb } 30046b4cac81SBjoern A. Zeeb } 30056b4cac81SBjoern A. Zeeb 30066b4cac81SBjoern A. Zeeb static void 3007a486fbbdSBjoern A. Zeeb lkpi_ic_scan_curchan(struct ieee80211_scan_state *ss, 3008a486fbbdSBjoern A. Zeeb unsigned long maxdwell) 3009a486fbbdSBjoern A. Zeeb { 3010a486fbbdSBjoern A. Zeeb struct lkpi_hw *lhw; 30118ac540d3SBjoern A. Zeeb bool is_hw_scan; 3012a486fbbdSBjoern A. Zeeb 3013a486fbbdSBjoern A. Zeeb lhw = ss->ss_ic->ic_softc; 30148ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 30158ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 30168ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 30178ac540d3SBjoern A. Zeeb if (!is_hw_scan) 3018a486fbbdSBjoern A. Zeeb lhw->ic_scan_curchan(ss, maxdwell); 3019a486fbbdSBjoern A. Zeeb } 3020a486fbbdSBjoern A. Zeeb 3021a486fbbdSBjoern A. Zeeb static void 3022a486fbbdSBjoern A. Zeeb lkpi_ic_scan_mindwell(struct ieee80211_scan_state *ss) 3023a486fbbdSBjoern A. Zeeb { 3024a486fbbdSBjoern A. Zeeb struct lkpi_hw *lhw; 30258ac540d3SBjoern A. Zeeb bool is_hw_scan; 3026a486fbbdSBjoern A. Zeeb 3027a486fbbdSBjoern A. Zeeb lhw = ss->ss_ic->ic_softc; 30288ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 30298ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 30308ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 30318ac540d3SBjoern A. Zeeb if (!is_hw_scan) 3032a486fbbdSBjoern A. Zeeb lhw->ic_scan_mindwell(ss); 3033a486fbbdSBjoern A. Zeeb } 3034a486fbbdSBjoern A. Zeeb 3035a486fbbdSBjoern A. Zeeb static void 30366b4cac81SBjoern A. Zeeb lkpi_ic_set_channel(struct ieee80211com *ic) 30376b4cac81SBjoern A. Zeeb { 30386b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 30396b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 3040b2cf3c21SBjoern A. Zeeb struct ieee80211_channel *c; 3041b2cf3c21SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 30426b4cac81SBjoern A. Zeeb int error; 30438ac540d3SBjoern A. Zeeb bool hw_scan_running; 30446b4cac81SBjoern A. Zeeb 30456b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 3046b2cf3c21SBjoern A. Zeeb 3047b2cf3c21SBjoern A. Zeeb /* If we do not support (*config)() save us the work. */ 3048b2cf3c21SBjoern A. Zeeb if (lhw->ops->config == NULL) 30496b4cac81SBjoern A. Zeeb return; 30506b4cac81SBjoern A. Zeeb 3051a486fbbdSBjoern A. Zeeb /* If we have a hw_scan running do not switch channels. */ 30528ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 30538ac540d3SBjoern A. Zeeb hw_scan_running = 30548ac540d3SBjoern A. Zeeb (lhw->scan_flags & (LKPI_LHW_SCAN_RUNNING|LKPI_LHW_SCAN_HW)) == 30558ac540d3SBjoern A. Zeeb (LKPI_LHW_SCAN_RUNNING|LKPI_LHW_SCAN_HW); 30568ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 30578ac540d3SBjoern A. Zeeb if (hw_scan_running) 3058a486fbbdSBjoern A. Zeeb return; 3059a486fbbdSBjoern A. Zeeb 3060b2cf3c21SBjoern A. Zeeb c = ic->ic_curchan; 3061b2cf3c21SBjoern A. Zeeb if (c == NULL || c == IEEE80211_CHAN_ANYC) { 30626b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: c %p ops->config %p\n", __func__, 30636b4cac81SBjoern A. Zeeb c, lhw->ops->config); 30646b4cac81SBjoern A. Zeeb return; 30656b4cac81SBjoern A. Zeeb } 30666b4cac81SBjoern A. Zeeb 30676b4cac81SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, c); 30686b4cac81SBjoern A. Zeeb if (chan == NULL) { 30696b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: c %p chan %p\n", __func__, 30706b4cac81SBjoern A. Zeeb c, chan); 30716b4cac81SBjoern A. Zeeb return; 30726b4cac81SBjoern A. Zeeb } 30736b4cac81SBjoern A. Zeeb 30746b4cac81SBjoern A. Zeeb /* XXX max power for scanning? */ 30756b4cac81SBjoern A. Zeeb IMPROVE(); 30766b4cac81SBjoern A. Zeeb 30776b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 30784a07abdeSBjoern A. Zeeb cfg80211_chandef_create(&hw->conf.chandef, chan, 30794a07abdeSBjoern A. Zeeb NL80211_CHAN_NO_HT); 30806b4cac81SBjoern A. Zeeb 30816b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_CHANNEL); 30826b4cac81SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) { 30836b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: config %#0x returned %d\n", 30846b4cac81SBjoern A. Zeeb __func__, IEEE80211_CONF_CHANGE_CHANNEL, error); 30856b4cac81SBjoern A. Zeeb /* XXX should we unroll to the previous chandef? */ 30866b4cac81SBjoern A. Zeeb IMPROVE(); 30876b4cac81SBjoern A. Zeeb } else { 30886b4cac81SBjoern A. Zeeb /* Update radiotap channels as well. */ 30896b4cac81SBjoern A. Zeeb lhw->rtap_tx.wt_chan_freq = htole16(c->ic_freq); 30906b4cac81SBjoern A. Zeeb lhw->rtap_tx.wt_chan_flags = htole16(c->ic_flags); 30916b4cac81SBjoern A. Zeeb lhw->rtap_rx.wr_chan_freq = htole16(c->ic_freq); 30926b4cac81SBjoern A. Zeeb lhw->rtap_rx.wr_chan_flags = htole16(c->ic_flags); 30936b4cac81SBjoern A. Zeeb } 30946b4cac81SBjoern A. Zeeb 30956b4cac81SBjoern A. Zeeb /* Currently PS is hard coded off! Not sure it belongs here. */ 30966b4cac81SBjoern A. Zeeb IMPROVE(); 30976b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, SUPPORTS_PS) && 30986b4cac81SBjoern A. Zeeb (hw->conf.flags & IEEE80211_CONF_PS) != 0) { 30996b4cac81SBjoern A. Zeeb hw->conf.flags &= ~IEEE80211_CONF_PS; 31006b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_PS); 31016b4cac81SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) 31026b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: config %#0x returned " 31036b4cac81SBjoern A. Zeeb "%d\n", __func__, IEEE80211_CONF_CHANGE_PS, 31046b4cac81SBjoern A. Zeeb error); 31056b4cac81SBjoern A. Zeeb } 31066b4cac81SBjoern A. Zeeb } 31076b4cac81SBjoern A. Zeeb 31086b4cac81SBjoern A. Zeeb static struct ieee80211_node * 31096b4cac81SBjoern A. Zeeb lkpi_ic_node_alloc(struct ieee80211vap *vap, 31106b4cac81SBjoern A. Zeeb const uint8_t mac[IEEE80211_ADDR_LEN]) 31116b4cac81SBjoern A. Zeeb { 31126b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 31136b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 31144f61ef8bSBjoern A. Zeeb struct ieee80211_node *ni; 31156b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 31166b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 31176b4cac81SBjoern A. Zeeb 31186b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 31196b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 31206b4cac81SBjoern A. Zeeb 31216b4cac81SBjoern A. Zeeb /* We keep allocations de-coupled so we can deal with the two worlds. */ 31224f61ef8bSBjoern A. Zeeb if (lhw->ic_node_alloc == NULL) 31234f61ef8bSBjoern A. Zeeb return (NULL); 31244f61ef8bSBjoern A. Zeeb 31256b4cac81SBjoern A. Zeeb ni = lhw->ic_node_alloc(vap, mac); 31266b4cac81SBjoern A. Zeeb if (ni == NULL) 31276b4cac81SBjoern A. Zeeb return (NULL); 31286b4cac81SBjoern A. Zeeb 31296b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 31304f61ef8bSBjoern A. Zeeb lsta = lkpi_lsta_alloc(vap, mac, hw, ni); 31316b4cac81SBjoern A. Zeeb if (lsta == NULL) { 31326b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL) 31336b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni); 31346b4cac81SBjoern A. Zeeb return (NULL); 31356b4cac81SBjoern A. Zeeb } 31366b4cac81SBjoern A. Zeeb 31376b4cac81SBjoern A. Zeeb return (ni); 31386b4cac81SBjoern A. Zeeb } 31396b4cac81SBjoern A. Zeeb 31406b4cac81SBjoern A. Zeeb static int 31416b4cac81SBjoern A. Zeeb lkpi_ic_node_init(struct ieee80211_node *ni) 31426b4cac81SBjoern A. Zeeb { 31436b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 31446b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 31456b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 31466b4cac81SBjoern A. Zeeb int error; 31476b4cac81SBjoern A. Zeeb 31486b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 31496b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 31506b4cac81SBjoern A. Zeeb 31516b4cac81SBjoern A. Zeeb if (lhw->ic_node_init != NULL) { 31526b4cac81SBjoern A. Zeeb error = lhw->ic_node_init(ni); 31536b4cac81SBjoern A. Zeeb if (error != 0) 31546b4cac81SBjoern A. Zeeb return (error); 31556b4cac81SBjoern A. Zeeb } 31566b4cac81SBjoern A. Zeeb 31576b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 31586b4cac81SBjoern A. Zeeb 31596b4cac81SBjoern A. Zeeb /* Now take the reference before linking it to the table. */ 31606b4cac81SBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 31616b4cac81SBjoern A. Zeeb 31626b4cac81SBjoern A. Zeeb /* XXX-BZ Sync other state over. */ 31636b4cac81SBjoern A. Zeeb IMPROVE(); 31646b4cac81SBjoern A. Zeeb 31656b4cac81SBjoern A. Zeeb return (0); 31666b4cac81SBjoern A. Zeeb } 31676b4cac81SBjoern A. Zeeb 31686b4cac81SBjoern A. Zeeb static void 31696b4cac81SBjoern A. Zeeb lkpi_ic_node_cleanup(struct ieee80211_node *ni) 31706b4cac81SBjoern A. Zeeb { 31716b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 31726b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 31736b4cac81SBjoern A. Zeeb 31746b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 31756b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 31766b4cac81SBjoern A. Zeeb 31776b4cac81SBjoern A. Zeeb /* XXX-BZ remove from driver, ... */ 31786b4cac81SBjoern A. Zeeb IMPROVE(); 31796b4cac81SBjoern A. Zeeb 31806b4cac81SBjoern A. Zeeb if (lhw->ic_node_cleanup != NULL) 31816b4cac81SBjoern A. Zeeb lhw->ic_node_cleanup(ni); 31826b4cac81SBjoern A. Zeeb } 31836b4cac81SBjoern A. Zeeb 31846b4cac81SBjoern A. Zeeb static void 31856b4cac81SBjoern A. Zeeb lkpi_ic_node_free(struct ieee80211_node *ni) 31866b4cac81SBjoern A. Zeeb { 31876b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 31886b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 31896b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 31906b4cac81SBjoern A. Zeeb 31916b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 31926b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 31936b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 3194d9f59799SBjoern A. Zeeb if (lsta == NULL) 3195d9f59799SBjoern A. Zeeb goto out; 31966b4cac81SBjoern A. Zeeb 31976b4cac81SBjoern A. Zeeb /* XXX-BZ free resources, ... */ 31986b4cac81SBjoern A. Zeeb IMPROVE(); 31996b4cac81SBjoern A. Zeeb 32006b4cac81SBjoern A. Zeeb /* Flush mbufq (make sure to release ni refs!). */ 32016b4cac81SBjoern A. Zeeb #ifdef __notyet__ 32026b4cac81SBjoern A. Zeeb KASSERT(mbufq_len(&lsta->txq) == 0, ("%s: lsta %p has txq len %d != 0\n", 32036b4cac81SBjoern A. Zeeb __func__, lsta, mbufq_len(&lsta->txq))); 32046b4cac81SBjoern A. Zeeb #endif 32056b4cac81SBjoern A. Zeeb /* Drain taskq. */ 32066b4cac81SBjoern A. Zeeb 32076b4cac81SBjoern A. Zeeb /* Drain sta->txq[] */ 32086b4cac81SBjoern A. Zeeb mtx_destroy(&lsta->txq_mtx); 32096b4cac81SBjoern A. Zeeb 32106b4cac81SBjoern A. Zeeb /* Remove lsta if added_to_drv. */ 3211e24e8103SBjoern A. Zeeb 32126b4cac81SBjoern A. Zeeb /* Remove lsta from vif */ 3213e24e8103SBjoern A. Zeeb /* Remove ref from lsta node... */ 3214d9f59799SBjoern A. Zeeb /* Free lsta. */ 3215e24e8103SBjoern A. Zeeb lkpi_lsta_remove(lsta, VAP_TO_LVIF(ni->ni_vap)); 3216d9f59799SBjoern A. Zeeb 3217d9f59799SBjoern A. Zeeb out: 32186b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL) 32196b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni); 32206b4cac81SBjoern A. Zeeb } 32216b4cac81SBjoern A. Zeeb 32226b4cac81SBjoern A. Zeeb static int 32236b4cac81SBjoern A. Zeeb lkpi_ic_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, 32246b4cac81SBjoern A. Zeeb const struct ieee80211_bpf_params *params __unused) 32256b4cac81SBjoern A. Zeeb { 32266b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 32276b4cac81SBjoern A. Zeeb 32286b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 32296b4cac81SBjoern A. Zeeb 32306b4cac81SBjoern A. Zeeb /* Queue the packet and enqueue the task to handle it. */ 32316b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_LOCK(lsta); 32326b4cac81SBjoern A. Zeeb mbufq_enqueue(&lsta->txq, m); 32336b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_UNLOCK(lsta); 32346b4cac81SBjoern A. Zeeb 32359d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 32369d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 32376b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p ni %p %6D mbuf_qlen %d\n", 32386b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, ni, ni->ni_macaddr, ":", 32396b4cac81SBjoern A. Zeeb mbufq_len(&lsta->txq)); 32409d9ba2b7SBjoern A. Zeeb #endif 32416b4cac81SBjoern A. Zeeb 32426b4cac81SBjoern A. Zeeb taskqueue_enqueue(taskqueue_thread, &lsta->txq_task); 32436b4cac81SBjoern A. Zeeb return (0); 32446b4cac81SBjoern A. Zeeb } 32456b4cac81SBjoern A. Zeeb 32466b4cac81SBjoern A. Zeeb static void 32476b4cac81SBjoern A. Zeeb lkpi_80211_txq_tx_one(struct lkpi_sta *lsta, struct mbuf *m) 32486b4cac81SBjoern A. Zeeb { 32496b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 3250b35f6cd0SBjoern A. Zeeb #ifndef LKPI_80211_HW_CRYPTO 32516b4cac81SBjoern A. Zeeb struct ieee80211_frame *wh; 3252b35f6cd0SBjoern A. Zeeb #endif 32536b4cac81SBjoern A. Zeeb struct ieee80211_key *k; 32546b4cac81SBjoern A. Zeeb struct sk_buff *skb; 32556b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 32566b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 32576b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 32586b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 32596b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 32606b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 32616b4cac81SBjoern A. Zeeb struct ieee80211_tx_control control; 32626b4cac81SBjoern A. Zeeb struct ieee80211_tx_info *info; 32636b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 3264e3a0b120SBjoern A. Zeeb struct ieee80211_hdr *hdr; 32656b4cac81SBjoern A. Zeeb void *buf; 3266e3a0b120SBjoern A. Zeeb uint8_t ac, tid; 32676b4cac81SBjoern A. Zeeb 32686b4cac81SBjoern A. Zeeb M_ASSERTPKTHDR(m); 32696b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 32709d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX_DUMP) 32716b4cac81SBjoern A. Zeeb hexdump(mtod(m, const void *), m->m_len, "RAW TX (plain) ", 0); 32726b4cac81SBjoern A. Zeeb #endif 32736b4cac81SBjoern A. Zeeb 32746b4cac81SBjoern A. Zeeb ni = lsta->ni; 3275b35f6cd0SBjoern A. Zeeb k = NULL; 3276b35f6cd0SBjoern A. Zeeb #ifndef LKPI_80211_HW_CRYPTO 32776b4cac81SBjoern A. Zeeb /* Encrypt the frame if need be; XXX-BZ info->control.hw_key. */ 32786b4cac81SBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame *); 32796b4cac81SBjoern A. Zeeb if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { 32806b4cac81SBjoern A. Zeeb /* Retrieve key for TX && do software encryption. */ 32816b4cac81SBjoern A. Zeeb k = ieee80211_crypto_encap(ni, m); 32826b4cac81SBjoern A. Zeeb if (k == NULL) { 32836b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 32846b4cac81SBjoern A. Zeeb m_freem(m); 32856b4cac81SBjoern A. Zeeb return; 32866b4cac81SBjoern A. Zeeb } 32876b4cac81SBjoern A. Zeeb } 32886b4cac81SBjoern A. Zeeb #endif 32896b4cac81SBjoern A. Zeeb 32906b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 32916b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 32926b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 32936b4cac81SBjoern A. Zeeb c = ni->ni_chan; 32946b4cac81SBjoern A. Zeeb 32956b4cac81SBjoern A. Zeeb if (ieee80211_radiotap_active_vap(ni->ni_vap)) { 32966b4cac81SBjoern A. Zeeb struct lkpi_radiotap_tx_hdr *rtap; 32976b4cac81SBjoern A. Zeeb 32986b4cac81SBjoern A. Zeeb rtap = &lhw->rtap_tx; 32996b4cac81SBjoern A. Zeeb rtap->wt_flags = 0; 33006b4cac81SBjoern A. Zeeb if (k != NULL) 33016b4cac81SBjoern A. Zeeb rtap->wt_flags |= IEEE80211_RADIOTAP_F_WEP; 33026b4cac81SBjoern A. Zeeb if (m->m_flags & M_FRAG) 33036b4cac81SBjoern A. Zeeb rtap->wt_flags |= IEEE80211_RADIOTAP_F_FRAG; 33046b4cac81SBjoern A. Zeeb IMPROVE(); 33056b4cac81SBjoern A. Zeeb rtap->wt_rate = 0; 33066b4cac81SBjoern A. Zeeb if (c != NULL && c != IEEE80211_CHAN_ANYC) { 33076b4cac81SBjoern A. Zeeb rtap->wt_chan_freq = htole16(c->ic_freq); 33086b4cac81SBjoern A. Zeeb rtap->wt_chan_flags = htole16(c->ic_flags); 33096b4cac81SBjoern A. Zeeb } 33106b4cac81SBjoern A. Zeeb 33116b4cac81SBjoern A. Zeeb ieee80211_radiotap_tx(ni->ni_vap, m); 33126b4cac81SBjoern A. Zeeb } 33136b4cac81SBjoern A. Zeeb 33146b4cac81SBjoern A. Zeeb /* 33156b4cac81SBjoern A. Zeeb * net80211 should handle hw->extra_tx_headroom. 33166b4cac81SBjoern A. Zeeb * Though for as long as we are copying we don't mind. 33173d09d310SBjoern A. Zeeb * XXX-BZ rtw88 asks for too much headroom for ipv6+tcp: 33183d09d310SBjoern A. Zeeb * https://lists.freebsd.org/archives/freebsd-transport/2022-February/000012.html 33196b4cac81SBjoern A. Zeeb */ 33206b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + m->m_pkthdr.len); 33216b4cac81SBjoern A. Zeeb if (skb == NULL) { 33223f0083c4SBjoern A. Zeeb ic_printf(ic, "ERROR %s: skb alloc failed\n", __func__); 33236b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 33246b4cac81SBjoern A. Zeeb m_freem(m); 33256b4cac81SBjoern A. Zeeb return; 33266b4cac81SBjoern A. Zeeb } 33276b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 33286b4cac81SBjoern A. Zeeb 33296b4cac81SBjoern A. Zeeb /* XXX-BZ we need a SKB version understanding mbuf. */ 33306b4cac81SBjoern A. Zeeb /* Save the mbuf for ieee80211_tx_complete(). */ 33316b4cac81SBjoern A. Zeeb skb->m_free_func = lkpi_ieee80211_free_skb_mbuf; 33326b4cac81SBjoern A. Zeeb skb->m = m; 33336b4cac81SBjoern A. Zeeb #if 0 33346b4cac81SBjoern A. Zeeb skb_put_data(skb, m->m_data, m->m_pkthdr.len); 33356b4cac81SBjoern A. Zeeb #else 33366b4cac81SBjoern A. Zeeb buf = skb_put(skb, m->m_pkthdr.len); 33376b4cac81SBjoern A. Zeeb m_copydata(m, 0, m->m_pkthdr.len, buf); 33386b4cac81SBjoern A. Zeeb #endif 33396b4cac81SBjoern A. Zeeb /* Save the ni. */ 33406b4cac81SBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = ni; 33416b4cac81SBjoern A. Zeeb 33426b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(ni->ni_vap); 33436b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 33446b4cac81SBjoern A. Zeeb 3345e3a0b120SBjoern A. Zeeb hdr = (void *)skb->data; 3346e3a0b120SBjoern A. Zeeb tid = linuxkpi_ieee80211_get_tid(hdr, true); 3347e3a0b120SBjoern A. Zeeb if (tid == IEEE80211_NONQOS_TID) { /* == IEEE80211_NUM_TIDS */ 3348e3a0b120SBjoern A. Zeeb skb->priority = 0; 3349e3a0b120SBjoern A. Zeeb ac = IEEE80211_AC_BE; 3350e3a0b120SBjoern A. Zeeb } else { 3351e3a0b120SBjoern A. Zeeb skb->priority = tid & IEEE80211_QOS_CTL_TID_MASK; 3352fb3c249eSBjoern A. Zeeb ac = ieee80211e_up_to_ac[tid & 7]; 3353e3a0b120SBjoern A. Zeeb } 33546b4cac81SBjoern A. Zeeb skb_set_queue_mapping(skb, ac); 33556b4cac81SBjoern A. Zeeb 33566b4cac81SBjoern A. Zeeb info = IEEE80211_SKB_CB(skb); 33576b4cac81SBjoern A. Zeeb info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; 33586b4cac81SBjoern A. Zeeb /* Slight delay; probably only happens on scanning so fine? */ 33596b4cac81SBjoern A. Zeeb if (c == NULL || c == IEEE80211_CHAN_ANYC) 33606b4cac81SBjoern A. Zeeb c = ic->ic_curchan; 33616b4cac81SBjoern A. Zeeb info->band = lkpi_net80211_chan_to_nl80211_band(c); 3362e3a0b120SBjoern A. Zeeb info->hw_queue = vif->hw_queue[ac]; 33636b4cac81SBjoern A. Zeeb if (m->m_flags & M_EAPOL) 33646b4cac81SBjoern A. Zeeb info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO; 33656b4cac81SBjoern A. Zeeb info->control.vif = vif; 33666b4cac81SBjoern A. Zeeb /* XXX-BZ info->control.rates */ 33676b4cac81SBjoern A. Zeeb 33686b4cac81SBjoern A. Zeeb lsta = lkpi_find_lsta_by_ni(lvif, ni); 33696b4cac81SBjoern A. Zeeb if (lsta != NULL) { 33706b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 3371b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 33726b4cac81SBjoern A. Zeeb info->control.hw_key = lsta->kc; 33736b4cac81SBjoern A. Zeeb #endif 33746b4cac81SBjoern A. Zeeb } else { 33756b4cac81SBjoern A. Zeeb sta = NULL; 33766b4cac81SBjoern A. Zeeb } 33776b4cac81SBjoern A. Zeeb 33786b4cac81SBjoern A. Zeeb IMPROVE(); 33796b4cac81SBjoern A. Zeeb 33806b4cac81SBjoern A. Zeeb if (sta != NULL) { 33816b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 33826b4cac81SBjoern A. Zeeb 3383e3a0b120SBjoern A. Zeeb ltxq = NULL; 3384e3a0b120SBjoern A. Zeeb if (!ieee80211_is_data_present(hdr->frame_control)) { 3385e3a0b120SBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_STATION && 3386e3a0b120SBjoern A. Zeeb lsta->added_to_drv && 3387e3a0b120SBjoern A. Zeeb sta->txq[IEEE80211_NUM_TIDS] != NULL) 3388d0d29110SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[IEEE80211_NUM_TIDS]); 3389e3a0b120SBjoern A. Zeeb } else if (lsta->added_to_drv && 3390e3a0b120SBjoern A. Zeeb sta->txq[skb->priority] != NULL) { 3391e3a0b120SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[skb->priority]); 3392e3a0b120SBjoern A. Zeeb } 3393e3a0b120SBjoern A. Zeeb if (ltxq == NULL) 3394d0d29110SBjoern A. Zeeb goto ops_tx; 3395e3a0b120SBjoern A. Zeeb 3396d0d29110SBjoern A. Zeeb KASSERT(ltxq != NULL, ("%s: lsta %p sta %p m %p skb %p " 3397d0d29110SBjoern A. Zeeb "ltxq %p != NULL\n", __func__, lsta, sta, m, skb, ltxq)); 3398d0d29110SBjoern A. Zeeb 33996b4cac81SBjoern A. Zeeb skb_queue_tail(<xq->skbq, skb); 34009d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 34019d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 3402d0d29110SBjoern A. Zeeb printf("%s:%d mo_wake_tx_queue :: %d %u lsta %p sta %p " 3403d0d29110SBjoern A. Zeeb "ni %p %6D skb %p lxtq %p { qlen %u, ac %d tid %u } " 3404d0d29110SBjoern A. Zeeb "WAKE_TX_Q ac %d prio %u qmap %u\n", 3405fb6eaf74SBjoern A. Zeeb __func__, __LINE__, 3406d0d29110SBjoern A. Zeeb curthread->td_tid, (unsigned int)ticks, 3407d0d29110SBjoern A. Zeeb lsta, sta, ni, ni->ni_macaddr, ":", skb, ltxq, 3408d0d29110SBjoern A. Zeeb skb_queue_len(<xq->skbq), ltxq->txq.ac, 3409d0d29110SBjoern A. Zeeb ltxq->txq.tid, ac, skb->priority, skb->qmap); 34109d9ba2b7SBjoern A. Zeeb #endif 3411d0d29110SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, <xq->txq); 34126b4cac81SBjoern A. Zeeb return; 34136b4cac81SBjoern A. Zeeb } 34146b4cac81SBjoern A. Zeeb 34156b4cac81SBjoern A. Zeeb ops_tx: 34169d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 34179d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 3418d0d29110SBjoern A. Zeeb printf("%s:%d mo_tx :: lsta %p sta %p ni %p %6D skb %p " 3419d0d29110SBjoern A. Zeeb "TX ac %d prio %u qmap %u\n", 34206b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, sta, ni, ni->ni_macaddr, ":", 34216b4cac81SBjoern A. Zeeb skb, ac, skb->priority, skb->qmap); 34229d9ba2b7SBjoern A. Zeeb #endif 34236b4cac81SBjoern A. Zeeb memset(&control, 0, sizeof(control)); 34246b4cac81SBjoern A. Zeeb control.sta = sta; 34256b4cac81SBjoern A. Zeeb 34266b4cac81SBjoern A. Zeeb lkpi_80211_mo_tx(hw, &control, skb); 34276b4cac81SBjoern A. Zeeb return; 34286b4cac81SBjoern A. Zeeb } 34296b4cac81SBjoern A. Zeeb 34306b4cac81SBjoern A. Zeeb static void 34316b4cac81SBjoern A. Zeeb lkpi_80211_txq_task(void *ctx, int pending) 34326b4cac81SBjoern A. Zeeb { 34336b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 34346b4cac81SBjoern A. Zeeb struct mbufq mq; 34356b4cac81SBjoern A. Zeeb struct mbuf *m; 34366b4cac81SBjoern A. Zeeb 34376b4cac81SBjoern A. Zeeb lsta = ctx; 34386b4cac81SBjoern A. Zeeb 34399d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 34409d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 34416b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p ni %p %6D pending %d mbuf_qlen %d\n", 34429d9ba2b7SBjoern A. Zeeb __func__, __LINE__, lsta, lsta->ni, lsta->ni->ni_macaddr, ":", 34436b4cac81SBjoern A. Zeeb pending, mbufq_len(&lsta->txq)); 34449d9ba2b7SBjoern A. Zeeb #endif 34456b4cac81SBjoern A. Zeeb 34466b4cac81SBjoern A. Zeeb mbufq_init(&mq, IFQ_MAXLEN); 34476b4cac81SBjoern A. Zeeb 34486b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_LOCK(lsta); 34496b4cac81SBjoern A. Zeeb mbufq_concat(&mq, &lsta->txq); 34506b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_UNLOCK(lsta); 34516b4cac81SBjoern A. Zeeb 34526b4cac81SBjoern A. Zeeb m = mbufq_dequeue(&mq); 34536b4cac81SBjoern A. Zeeb while (m != NULL) { 34546b4cac81SBjoern A. Zeeb lkpi_80211_txq_tx_one(lsta, m); 34556b4cac81SBjoern A. Zeeb m = mbufq_dequeue(&mq); 34566b4cac81SBjoern A. Zeeb } 34576b4cac81SBjoern A. Zeeb } 34586b4cac81SBjoern A. Zeeb 34596b4cac81SBjoern A. Zeeb static int 34606b4cac81SBjoern A. Zeeb lkpi_ic_transmit(struct ieee80211com *ic, struct mbuf *m) 34616b4cac81SBjoern A. Zeeb { 34626b4cac81SBjoern A. Zeeb 34636b4cac81SBjoern A. Zeeb /* XXX TODO */ 34646b4cac81SBjoern A. Zeeb IMPROVE(); 34656b4cac81SBjoern A. Zeeb 34666b4cac81SBjoern A. Zeeb /* Quick and dirty cheating hack. */ 34676b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 34686b4cac81SBjoern A. Zeeb 34696b4cac81SBjoern A. Zeeb ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; 34706b4cac81SBjoern A. Zeeb return (lkpi_ic_raw_xmit(ni, m, NULL)); 34716b4cac81SBjoern A. Zeeb } 34726b4cac81SBjoern A. Zeeb 34736b4cac81SBjoern A. Zeeb static void 34746b4cac81SBjoern A. Zeeb lkpi_ic_getradiocaps(struct ieee80211com *ic, int maxchan, 34756b4cac81SBjoern A. Zeeb int *n, struct ieee80211_channel *c) 34766b4cac81SBjoern A. Zeeb { 34776b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 34786b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 34796b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 34806b4cac81SBjoern A. Zeeb uint8_t bands[IEEE80211_MODE_BYTES]; 34816b4cac81SBjoern A. Zeeb int chan_flags, error, i, nchans; 34826b4cac81SBjoern A. Zeeb 34836b4cac81SBjoern A. Zeeb /* Channels */ 34846b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 34856b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 34866b4cac81SBjoern A. Zeeb 34876b4cac81SBjoern A. Zeeb /* NL80211_BAND_2GHZ */ 34886b4cac81SBjoern A. Zeeb nchans = 0; 34896b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_2GHZ] != NULL) 34906b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[NL80211_BAND_2GHZ]->n_channels; 34916b4cac81SBjoern A. Zeeb if (nchans > 0) { 34926b4cac81SBjoern A. Zeeb memset(bands, 0, sizeof(bands)); 34936b4cac81SBjoern A. Zeeb chan_flags = 0; 34946b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11B); 34956b4cac81SBjoern A. Zeeb /* XXX-BZ unclear how to check for 11g. */ 34966b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11G); 34976b4cac81SBjoern A. Zeeb #ifdef __notyet__ 34986b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_2GHZ]->ht_cap.ht_supported) { 34996b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11NG); 35006b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_HT40; 35016b4cac81SBjoern A. Zeeb } 35026b4cac81SBjoern A. Zeeb #endif 35036b4cac81SBjoern A. Zeeb 35046b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[NL80211_BAND_2GHZ]->channels; 3505cee56e77SBjoern A. Zeeb for (i = 0; i < nchans && *n < maxchan; i++) { 35066b4cac81SBjoern A. Zeeb uint32_t nflags = 0; 35076b4cac81SBjoern A. Zeeb int cflags = chan_flags; 35086b4cac81SBjoern A. Zeeb 35096b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) { 35103f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Skipping disabled chan " 35113f0083c4SBjoern A. Zeeb "[%u/%u/%#x]\n", __func__, 35126b4cac81SBjoern A. Zeeb channels[i].hw_value, 35136b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags); 35146b4cac81SBjoern A. Zeeb continue; 35156b4cac81SBjoern A. Zeeb } 35166b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_IR) 35176b4cac81SBjoern A. Zeeb nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE); 35186b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_RADAR) 35196b4cac81SBjoern A. Zeeb nflags |= IEEE80211_CHAN_DFS; 35206b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ) 35216b4cac81SBjoern A. Zeeb cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80); 35226b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ) 35236b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_VHT80; 35246b4cac81SBjoern A. Zeeb /* XXX how to map the remaining enum ieee80211_channel_flags? */ 35256b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_HT40) 35266b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_HT40; 35276b4cac81SBjoern A. Zeeb 35286b4cac81SBjoern A. Zeeb error = ieee80211_add_channel_cbw(c, maxchan, n, 35296b4cac81SBjoern A. Zeeb channels[i].hw_value, channels[i].center_freq, 35306b4cac81SBjoern A. Zeeb channels[i].max_power, 35316b4cac81SBjoern A. Zeeb nflags, bands, chan_flags); 3532cee56e77SBjoern A. Zeeb /* net80211::ENOBUFS: *n >= maxchans */ 3533cee56e77SBjoern A. Zeeb if (error != 0 && error != ENOBUFS) 35343f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Adding chan %u/%u/%#x/%#x/%#x/%#x " 35353f0083c4SBjoern A. Zeeb "returned error %d\n", 35366b4cac81SBjoern A. Zeeb __func__, channels[i].hw_value, 35376b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags, 35386b4cac81SBjoern A. Zeeb nflags, chan_flags, cflags, error); 3539cee56e77SBjoern A. Zeeb if (error != 0) 35406b4cac81SBjoern A. Zeeb break; 35416b4cac81SBjoern A. Zeeb } 35426b4cac81SBjoern A. Zeeb } 35436b4cac81SBjoern A. Zeeb 35446b4cac81SBjoern A. Zeeb /* NL80211_BAND_5GHZ */ 35456b4cac81SBjoern A. Zeeb nchans = 0; 35466b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ] != NULL) 35476b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[NL80211_BAND_5GHZ]->n_channels; 35486b4cac81SBjoern A. Zeeb if (nchans > 0) { 35496b4cac81SBjoern A. Zeeb memset(bands, 0, sizeof(bands)); 35506b4cac81SBjoern A. Zeeb chan_flags = 0; 35516b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11A); 35526b4cac81SBjoern A. Zeeb #ifdef __not_yet__ 35536b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ]->ht_cap.ht_supported) { 35546b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11NA); 35556b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_HT40; 35566b4cac81SBjoern A. Zeeb } 35576b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.vht_supported){ 35586b4cac81SBjoern A. Zeeb 35596b4cac81SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_VHT; 35606b4cac81SBjoern A. Zeeb ic->ic_vhtcaps = 35616b4cac81SBjoern A. Zeeb hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap; 35626b4cac81SBjoern A. Zeeb 35636b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_VHT_5GHZ); 35646b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT80; 35656b4cac81SBjoern A. Zeeb if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160MHZ( 35666b4cac81SBjoern A. Zeeb ic->ic_vhtcaps)) 35676b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT160; 35686b4cac81SBjoern A. Zeeb if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160_80P80MHZ( 35696b4cac81SBjoern A. Zeeb ic->ic_vhtcaps)) 35706b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT80P80; 35716b4cac81SBjoern A. Zeeb } 35726b4cac81SBjoern A. Zeeb #endif 35736b4cac81SBjoern A. Zeeb 35746b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[NL80211_BAND_5GHZ]->channels; 3575cee56e77SBjoern A. Zeeb for (i = 0; i < nchans && *n < maxchan; i++) { 35766b4cac81SBjoern A. Zeeb uint32_t nflags = 0; 35776b4cac81SBjoern A. Zeeb int cflags = chan_flags; 35786b4cac81SBjoern A. Zeeb 35796b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) { 35803f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Skipping disabled chan " 35813f0083c4SBjoern A. Zeeb "[%u/%u/%#x]\n", __func__, 35826b4cac81SBjoern A. Zeeb channels[i].hw_value, 35836b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags); 35846b4cac81SBjoern A. Zeeb continue; 35856b4cac81SBjoern A. Zeeb } 35866b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_IR) 35876b4cac81SBjoern A. Zeeb nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE); 35886b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_RADAR) 35896b4cac81SBjoern A. Zeeb nflags |= IEEE80211_CHAN_DFS; 35906b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ) 35916b4cac81SBjoern A. Zeeb cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80); 35926b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ) 35936b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_VHT80; 35946b4cac81SBjoern A. Zeeb /* XXX hwo to map the remaining enum ieee80211_channel_flags? */ 35956b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_HT40) 35966b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_HT40; 35976b4cac81SBjoern A. Zeeb 35986b4cac81SBjoern A. Zeeb error = ieee80211_add_channel_cbw(c, maxchan, n, 35996b4cac81SBjoern A. Zeeb channels[i].hw_value, channels[i].center_freq, 36006b4cac81SBjoern A. Zeeb channels[i].max_power, 36016b4cac81SBjoern A. Zeeb nflags, bands, chan_flags); 3602cee56e77SBjoern A. Zeeb /* net80211::ENOBUFS: *n >= maxchans */ 3603cee56e77SBjoern A. Zeeb if (error != 0 && error != ENOBUFS) 36043f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Adding chan %u/%u/%#x/%#x/%#x/%#x " 36053f0083c4SBjoern A. Zeeb "returned error %d\n", 36066b4cac81SBjoern A. Zeeb __func__, channels[i].hw_value, 36076b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags, 36086b4cac81SBjoern A. Zeeb nflags, chan_flags, cflags, error); 3609cee56e77SBjoern A. Zeeb if (error != 0) 36106b4cac81SBjoern A. Zeeb break; 36116b4cac81SBjoern A. Zeeb } 36126b4cac81SBjoern A. Zeeb } 36136b4cac81SBjoern A. Zeeb } 36146b4cac81SBjoern A. Zeeb 36156b4cac81SBjoern A. Zeeb static void * 36166b4cac81SBjoern A. Zeeb lkpi_ieee80211_ifalloc(void) 36176b4cac81SBjoern A. Zeeb { 36186b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 36196b4cac81SBjoern A. Zeeb 36206b4cac81SBjoern A. Zeeb ic = malloc(sizeof(*ic), M_LKPI80211, M_WAITOK | M_ZERO); 36216b4cac81SBjoern A. Zeeb if (ic == NULL) 36226b4cac81SBjoern A. Zeeb return (NULL); 36236b4cac81SBjoern A. Zeeb 36246b4cac81SBjoern A. Zeeb /* Setting these happens later when we have device information. */ 36256b4cac81SBjoern A. Zeeb ic->ic_softc = NULL; 36266b4cac81SBjoern A. Zeeb ic->ic_name = "linuxkpi"; 36276b4cac81SBjoern A. Zeeb 36286b4cac81SBjoern A. Zeeb return (ic); 36296b4cac81SBjoern A. Zeeb } 36306b4cac81SBjoern A. Zeeb 36316b4cac81SBjoern A. Zeeb struct ieee80211_hw * 36326b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_alloc_hw(size_t priv_len, const struct ieee80211_ops *ops) 36336b4cac81SBjoern A. Zeeb { 36346b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 36356b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 36366b4cac81SBjoern A. Zeeb struct wiphy *wiphy; 3637a5ae63edSBjoern A. Zeeb int ac; 36386b4cac81SBjoern A. Zeeb 36396b4cac81SBjoern A. Zeeb /* Get us and the driver data also allocated. */ 36406b4cac81SBjoern A. Zeeb wiphy = wiphy_new(&linuxkpi_mac80211cfgops, sizeof(*lhw) + priv_len); 36416b4cac81SBjoern A. Zeeb if (wiphy == NULL) 36426b4cac81SBjoern A. Zeeb return (NULL); 36436b4cac81SBjoern A. Zeeb 36446b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 36456b4cac81SBjoern A. Zeeb lhw->ops = ops; 3646652e22d3SBjoern A. Zeeb 36478ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK_INIT(lhw); 36488ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK_INIT(lhw); 36498891c455SBjoern A. Zeeb sx_init_flags(&lhw->lvif_sx, "lhw-lvif", SX_RECURSE | SX_DUPOK); 36506b4cac81SBjoern A. Zeeb TAILQ_INIT(&lhw->lvif_head); 3651a5ae63edSBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 3652a5ae63edSBjoern A. Zeeb lhw->txq_generation[ac] = 1; 3653a5ae63edSBjoern A. Zeeb TAILQ_INIT(&lhw->scheduled_txqs[ac]); 3654a5ae63edSBjoern A. Zeeb } 36556b4cac81SBjoern A. Zeeb 36566b4cac81SBjoern A. Zeeb /* 36576b4cac81SBjoern A. Zeeb * XXX-BZ TODO make sure there is a "_null" function to all ops 36586b4cac81SBjoern A. Zeeb * not initialized. 36596b4cac81SBjoern A. Zeeb */ 36606b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 36616b4cac81SBjoern A. Zeeb hw->wiphy = wiphy; 3662086be6a8SBjoern A. Zeeb hw->conf.flags |= IEEE80211_CONF_IDLE; 36636b4cac81SBjoern A. Zeeb hw->priv = (void *)(lhw + 1); 36646b4cac81SBjoern A. Zeeb 36656b4cac81SBjoern A. Zeeb /* BSD Specific. */ 36666b4cac81SBjoern A. Zeeb lhw->ic = lkpi_ieee80211_ifalloc(); 36676b4cac81SBjoern A. Zeeb if (lhw->ic == NULL) { 36686b4cac81SBjoern A. Zeeb ieee80211_free_hw(hw); 36696b4cac81SBjoern A. Zeeb return (NULL); 36706b4cac81SBjoern A. Zeeb } 36716b4cac81SBjoern A. Zeeb 36726b4cac81SBjoern A. Zeeb IMPROVE(); 36736b4cac81SBjoern A. Zeeb 36746b4cac81SBjoern A. Zeeb return (hw); 36756b4cac81SBjoern A. Zeeb } 36766b4cac81SBjoern A. Zeeb 36776b4cac81SBjoern A. Zeeb void 36786b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iffree(struct ieee80211_hw *hw) 36796b4cac81SBjoern A. Zeeb { 36806b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 36816b4cac81SBjoern A. Zeeb 36826b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 36836b4cac81SBjoern A. Zeeb free(lhw->ic, M_LKPI80211); 36846b4cac81SBjoern A. Zeeb lhw->ic = NULL; 36856b4cac81SBjoern A. Zeeb 36866b4cac81SBjoern A. Zeeb /* Cleanup more of lhw here or in wiphy_free()? */ 36878891c455SBjoern A. Zeeb sx_destroy(&lhw->lvif_sx); 36888ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK_DESTROY(lhw); 36898ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK_DESTROY(lhw); 36906b4cac81SBjoern A. Zeeb IMPROVE(); 36916b4cac81SBjoern A. Zeeb } 36926b4cac81SBjoern A. Zeeb 36936b4cac81SBjoern A. Zeeb void 36946b4cac81SBjoern A. Zeeb linuxkpi_set_ieee80211_dev(struct ieee80211_hw *hw, char *name) 36956b4cac81SBjoern A. Zeeb { 36966b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 36976b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 36986b4cac81SBjoern A. Zeeb 36996b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 37006b4cac81SBjoern A. Zeeb ic = lhw->ic; 37016b4cac81SBjoern A. Zeeb 37026b4cac81SBjoern A. Zeeb /* Now set a proper name before ieee80211_ifattach(). */ 37036b4cac81SBjoern A. Zeeb ic->ic_softc = lhw; 37046b4cac81SBjoern A. Zeeb ic->ic_name = name; 37056b4cac81SBjoern A. Zeeb 37066b4cac81SBjoern A. Zeeb /* XXX-BZ do we also need to set wiphy name? */ 37076b4cac81SBjoern A. Zeeb } 37086b4cac81SBjoern A. Zeeb 37096b4cac81SBjoern A. Zeeb struct ieee80211_hw * 37106b4cac81SBjoern A. Zeeb linuxkpi_wiphy_to_ieee80211_hw(struct wiphy *wiphy) 37116b4cac81SBjoern A. Zeeb { 37126b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 37136b4cac81SBjoern A. Zeeb 37146b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 37156b4cac81SBjoern A. Zeeb return (LHW_TO_HW(lhw)); 37166b4cac81SBjoern A. Zeeb } 37176b4cac81SBjoern A. Zeeb 37186b4cac81SBjoern A. Zeeb static void 37196b4cac81SBjoern A. Zeeb lkpi_radiotap_attach(struct lkpi_hw *lhw) 37206b4cac81SBjoern A. Zeeb { 37216b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 37226b4cac81SBjoern A. Zeeb 37236b4cac81SBjoern A. Zeeb ic = lhw->ic; 37246b4cac81SBjoern A. Zeeb ieee80211_radiotap_attach(ic, 37256b4cac81SBjoern A. Zeeb &lhw->rtap_tx.wt_ihdr, sizeof(lhw->rtap_tx), 37266b4cac81SBjoern A. Zeeb LKPI_RTAP_TX_FLAGS_PRESENT, 37276b4cac81SBjoern A. Zeeb &lhw->rtap_rx.wr_ihdr, sizeof(lhw->rtap_rx), 37286b4cac81SBjoern A. Zeeb LKPI_RTAP_RX_FLAGS_PRESENT); 37296b4cac81SBjoern A. Zeeb } 37306b4cac81SBjoern A. Zeeb 37312e183d99SBjoern A. Zeeb int 37326b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ifattach(struct ieee80211_hw *hw) 37336b4cac81SBjoern A. Zeeb { 37346b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 37356b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 3736c5b96b3eSBjoern A. Zeeb int band, i; 37376b4cac81SBjoern A. Zeeb 37386b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 37396b4cac81SBjoern A. Zeeb ic = lhw->ic; 37406b4cac81SBjoern A. Zeeb 3741652e22d3SBjoern A. Zeeb /* We do it this late as wiphy->dev should be set for the name. */ 3742652e22d3SBjoern A. Zeeb lhw->workq = alloc_ordered_workqueue(wiphy_name(hw->wiphy), 0); 3743652e22d3SBjoern A. Zeeb if (lhw->workq == NULL) 3744652e22d3SBjoern A. Zeeb return (-EAGAIN); 3745652e22d3SBjoern A. Zeeb 37466b4cac81SBjoern A. Zeeb /* XXX-BZ figure this out how they count his... */ 37476b4cac81SBjoern A. Zeeb if (!is_zero_ether_addr(hw->wiphy->perm_addr)) { 37486b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(ic->ic_macaddr, 37496b4cac81SBjoern A. Zeeb hw->wiphy->perm_addr); 37506b4cac81SBjoern A. Zeeb } else if (hw->wiphy->n_addresses > 0) { 37516b4cac81SBjoern A. Zeeb /* We take the first one. */ 37526b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(ic->ic_macaddr, 37536b4cac81SBjoern A. Zeeb hw->wiphy->addresses[0].addr); 37546b4cac81SBjoern A. Zeeb } else { 37556b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: warning, no hardware address!\n", __func__); 37566b4cac81SBjoern A. Zeeb } 37576b4cac81SBjoern A. Zeeb 37583d09d310SBjoern A. Zeeb #ifdef __not_yet__ 37593d09d310SBjoern A. Zeeb /* See comment in lkpi_80211_txq_tx_one(). */ 37606b4cac81SBjoern A. Zeeb ic->ic_headroom = hw->extra_tx_headroom; 37613d09d310SBjoern A. Zeeb #endif 37626b4cac81SBjoern A. Zeeb 37636b4cac81SBjoern A. Zeeb ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ 37646b4cac81SBjoern A. Zeeb ic->ic_opmode = IEEE80211_M_STA; 37656b4cac81SBjoern A. Zeeb 37666b4cac81SBjoern A. Zeeb /* Set device capabilities. */ 37676b4cac81SBjoern A. Zeeb /* XXX-BZ we need to get these from linux80211/drivers and convert. */ 37686b4cac81SBjoern A. Zeeb ic->ic_caps = 37696b4cac81SBjoern A. Zeeb IEEE80211_C_STA | 37706b4cac81SBjoern A. Zeeb IEEE80211_C_MONITOR | 37716b4cac81SBjoern A. Zeeb IEEE80211_C_WPA | /* WPA/RSN */ 37724a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 37736b4cac81SBjoern A. Zeeb IEEE80211_C_WME | 37744a67f1dfSBjoern A. Zeeb #endif 37756b4cac81SBjoern A. Zeeb #if 0 37766b4cac81SBjoern A. Zeeb IEEE80211_C_PMGT | 37776b4cac81SBjoern A. Zeeb #endif 37786b4cac81SBjoern A. Zeeb IEEE80211_C_SHSLOT | /* short slot time supported */ 37796b4cac81SBjoern A. Zeeb IEEE80211_C_SHPREAMBLE /* short preamble supported */ 37806b4cac81SBjoern A. Zeeb ; 37816b4cac81SBjoern A. Zeeb #if 0 37826b4cac81SBjoern A. Zeeb /* Scanning is a different kind of beast to re-work. */ 37836b4cac81SBjoern A. Zeeb ic->ic_caps |= IEEE80211_C_BGSCAN; 37846b4cac81SBjoern A. Zeeb #endif 3785cc4e78d5SBjoern A. Zeeb if (lhw->ops->hw_scan) { 3786cc4e78d5SBjoern A. Zeeb /* 3787cc4e78d5SBjoern A. Zeeb * Advertise full-offload scanning. 3788cc4e78d5SBjoern A. Zeeb * 3789cc4e78d5SBjoern A. Zeeb * Not limiting to SINGLE_SCAN_ON_ALL_BANDS here as otherwise 3790cc4e78d5SBjoern A. Zeeb * we essentially disable hw_scan for all drivers not setting 3791cc4e78d5SBjoern A. Zeeb * the flag. 3792cc4e78d5SBjoern A. Zeeb */ 37936b4cac81SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_SCAN_OFFLOAD; 3794a486fbbdSBjoern A. Zeeb lhw->scan_flags |= LKPI_LHW_SCAN_HW; 37956b4cac81SBjoern A. Zeeb } 37966b4cac81SBjoern A. Zeeb 37976b4cac81SBjoern A. Zeeb #ifdef __notyet__ 37986b4cac81SBjoern A. Zeeb ic->ic_htcaps = IEEE80211_HTC_HT /* HT operation */ 37996b4cac81SBjoern A. Zeeb | IEEE80211_HTC_AMPDU /* A-MPDU tx/rx */ 38006b4cac81SBjoern A. Zeeb | IEEE80211_HTC_AMSDU /* A-MSDU tx/rx */ 38016b4cac81SBjoern A. Zeeb | IEEE80211_HTCAP_MAXAMSDU_3839 38026b4cac81SBjoern A. Zeeb /* max A-MSDU length */ 38036b4cac81SBjoern A. Zeeb | IEEE80211_HTCAP_SMPS_OFF; /* SM power save off */ 38046b4cac81SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_SHORTGI20; 38056b4cac81SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_CHWIDTH40 | IEEE80211_HTCAP_SHORTGI40; 38066b4cac81SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_TXSTBC; 38076b4cac81SBjoern A. Zeeb #endif 38086b4cac81SBjoern A. Zeeb 3809527687a9SBjoern A. Zeeb /* 3810527687a9SBjoern A. Zeeb * The wiphy variables report bitmasks of avail antennas. 3811527687a9SBjoern A. Zeeb * (*get_antenna) get the current bitmask sets which can be 3812527687a9SBjoern A. Zeeb * altered by (*set_antenna) for some drivers. 3813527687a9SBjoern A. Zeeb * XXX-BZ will the count alone do us much good long-term in net80211? 3814527687a9SBjoern A. Zeeb */ 3815527687a9SBjoern A. Zeeb if (hw->wiphy->available_antennas_rx || 3816527687a9SBjoern A. Zeeb hw->wiphy->available_antennas_tx) { 3817527687a9SBjoern A. Zeeb uint32_t rxs, txs; 3818527687a9SBjoern A. Zeeb 3819527687a9SBjoern A. Zeeb if (lkpi_80211_mo_get_antenna(hw, &txs, &rxs) == 0) { 3820527687a9SBjoern A. Zeeb ic->ic_rxstream = bitcount32(rxs); 3821527687a9SBjoern A. Zeeb ic->ic_txstream = bitcount32(txs); 3822527687a9SBjoern A. Zeeb } 3823527687a9SBjoern A. Zeeb } 3824527687a9SBjoern A. Zeeb 38256b4cac81SBjoern A. Zeeb ic->ic_cryptocaps = 0; 3826b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 38276b4cac81SBjoern A. Zeeb if (hw->wiphy->n_cipher_suites > 0) { 38286b4cac81SBjoern A. Zeeb for (i = 0; i < hw->wiphy->n_cipher_suites; i++) 38296b4cac81SBjoern A. Zeeb ic->ic_cryptocaps |= lkpi_l80211_to_net80211_cyphers( 38306b4cac81SBjoern A. Zeeb hw->wiphy->cipher_suites[i]); 38316b4cac81SBjoern A. Zeeb } 38326b4cac81SBjoern A. Zeeb #endif 38336b4cac81SBjoern A. Zeeb 38346b4cac81SBjoern A. Zeeb lkpi_ic_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans, 38356b4cac81SBjoern A. Zeeb ic->ic_channels); 38366b4cac81SBjoern A. Zeeb 38376b4cac81SBjoern A. Zeeb ieee80211_ifattach(ic); 38386b4cac81SBjoern A. Zeeb 38396b4cac81SBjoern A. Zeeb ic->ic_update_mcast = lkpi_ic_update_mcast; 38406b4cac81SBjoern A. Zeeb ic->ic_update_promisc = lkpi_ic_update_promisc; 38416b4cac81SBjoern A. Zeeb ic->ic_update_chw = lkpi_ic_update_chw; 38426b4cac81SBjoern A. Zeeb ic->ic_parent = lkpi_ic_parent; 38436b4cac81SBjoern A. Zeeb ic->ic_scan_start = lkpi_ic_scan_start; 38446b4cac81SBjoern A. Zeeb ic->ic_scan_end = lkpi_ic_scan_end; 38456b4cac81SBjoern A. Zeeb ic->ic_set_channel = lkpi_ic_set_channel; 38466b4cac81SBjoern A. Zeeb ic->ic_transmit = lkpi_ic_transmit; 38476b4cac81SBjoern A. Zeeb ic->ic_raw_xmit = lkpi_ic_raw_xmit; 38486b4cac81SBjoern A. Zeeb ic->ic_vap_create = lkpi_ic_vap_create; 38496b4cac81SBjoern A. Zeeb ic->ic_vap_delete = lkpi_ic_vap_delete; 38506b4cac81SBjoern A. Zeeb ic->ic_getradiocaps = lkpi_ic_getradiocaps; 38516b4cac81SBjoern A. Zeeb ic->ic_wme.wme_update = lkpi_ic_wme_update; 38526b4cac81SBjoern A. Zeeb 3853a486fbbdSBjoern A. Zeeb lhw->ic_scan_curchan = ic->ic_scan_curchan; 3854a486fbbdSBjoern A. Zeeb ic->ic_scan_curchan = lkpi_ic_scan_curchan; 3855a486fbbdSBjoern A. Zeeb lhw->ic_scan_mindwell = ic->ic_scan_mindwell; 3856a486fbbdSBjoern A. Zeeb ic->ic_scan_mindwell = lkpi_ic_scan_mindwell; 3857a486fbbdSBjoern A. Zeeb 38586b4cac81SBjoern A. Zeeb lhw->ic_node_alloc = ic->ic_node_alloc; 38596b4cac81SBjoern A. Zeeb ic->ic_node_alloc = lkpi_ic_node_alloc; 38606b4cac81SBjoern A. Zeeb lhw->ic_node_init = ic->ic_node_init; 38616b4cac81SBjoern A. Zeeb ic->ic_node_init = lkpi_ic_node_init; 38626b4cac81SBjoern A. Zeeb lhw->ic_node_cleanup = ic->ic_node_cleanup; 38636b4cac81SBjoern A. Zeeb ic->ic_node_cleanup = lkpi_ic_node_cleanup; 38646b4cac81SBjoern A. Zeeb lhw->ic_node_free = ic->ic_node_free; 38656b4cac81SBjoern A. Zeeb ic->ic_node_free = lkpi_ic_node_free; 38666b4cac81SBjoern A. Zeeb 38676b4cac81SBjoern A. Zeeb lkpi_radiotap_attach(lhw); 38686b4cac81SBjoern A. Zeeb 3869c5b96b3eSBjoern A. Zeeb /* 3870c5b96b3eSBjoern A. Zeeb * Assign the first possible channel for now; seems Realtek drivers 3871c5b96b3eSBjoern A. Zeeb * expect one. 3872d9945d78SBjoern A. Zeeb * Also remember the amount of bands we support and the most rates 3873d9945d78SBjoern A. Zeeb * in any band so we can scale [(ext) sup rates] IE(s) accordingly. 3874c5b96b3eSBjoern A. Zeeb */ 3875d9945d78SBjoern A. Zeeb lhw->supbands = lhw->max_rates = 0; 3876f454a4a1SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 3877c5b96b3eSBjoern A. Zeeb struct ieee80211_supported_band *supband; 3878c5b96b3eSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 3879c5b96b3eSBjoern A. Zeeb 3880c5b96b3eSBjoern A. Zeeb supband = hw->wiphy->bands[band]; 3881c5b96b3eSBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 3882c5b96b3eSBjoern A. Zeeb continue; 3883c5b96b3eSBjoern A. Zeeb 3884d9945d78SBjoern A. Zeeb lhw->supbands++; 3885d9945d78SBjoern A. Zeeb lhw->max_rates = max(lhw->max_rates, supband->n_bitrates); 3886d9945d78SBjoern A. Zeeb 3887f454a4a1SBjoern A. Zeeb /* If we have a channel, we need to keep counting supbands. */ 3888f454a4a1SBjoern A. Zeeb if (hw->conf.chandef.chan != NULL) 3889f454a4a1SBjoern A. Zeeb continue; 3890f454a4a1SBjoern A. Zeeb 3891c5b96b3eSBjoern A. Zeeb channels = supband->channels; 3892c5b96b3eSBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 3893c5b96b3eSBjoern A. Zeeb 3894c5b96b3eSBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) 3895c5b96b3eSBjoern A. Zeeb continue; 3896c5b96b3eSBjoern A. Zeeb 38974a07abdeSBjoern A. Zeeb cfg80211_chandef_create(&hw->conf.chandef, &channels[i], 3898c5b96b3eSBjoern A. Zeeb NL80211_CHAN_NO_HT); 3899c5b96b3eSBjoern A. Zeeb break; 3900c5b96b3eSBjoern A. Zeeb } 3901c5b96b3eSBjoern A. Zeeb } 3902c5b96b3eSBjoern A. Zeeb 3903d9945d78SBjoern A. Zeeb IMPROVE("see net80211::ieee80211_chan_init vs. wiphy->bands[].bitrates possibly in lkpi_ic_getradiocaps?"); 3904d9945d78SBjoern A. Zeeb 3905d9945d78SBjoern A. Zeeb /* Make sure we do not support more than net80211 is willing to take. */ 3906d9945d78SBjoern A. Zeeb if (lhw->max_rates > IEEE80211_RATE_MAXSIZE) { 3907d9945d78SBjoern A. Zeeb ic_printf(ic, "%s: limiting max_rates %d to %d!\n", __func__, 3908d9945d78SBjoern A. Zeeb lhw->max_rates, IEEE80211_RATE_MAXSIZE); 3909d9945d78SBjoern A. Zeeb lhw->max_rates = IEEE80211_RATE_MAXSIZE; 3910d9945d78SBjoern A. Zeeb } 3911d9945d78SBjoern A. Zeeb 3912d9945d78SBjoern A. Zeeb /* 3913d9945d78SBjoern A. Zeeb * The maximum supported bitrates on any band + size for 3914d9945d78SBjoern A. Zeeb * DSSS Parameter Set give our per-band IE size. 3915d9945d78SBjoern A. Zeeb * XXX-BZ FIXME add HT VHT ... later 3916d9945d78SBjoern A. Zeeb * SSID is the responsibility of the driver and goes on the side. 3917d9945d78SBjoern A. Zeeb * The user specified bits coming from the vap go into the 3918d9945d78SBjoern A. Zeeb * "common ies" fields. 3919d9945d78SBjoern A. Zeeb */ 3920d9945d78SBjoern A. Zeeb lhw->scan_ie_len = 2 + IEEE80211_RATE_SIZE; 3921d9945d78SBjoern A. Zeeb if (lhw->max_rates > IEEE80211_RATE_SIZE) 3922d9945d78SBjoern A. Zeeb lhw->scan_ie_len += 2 + (lhw->max_rates - IEEE80211_RATE_SIZE); 3923d9945d78SBjoern A. Zeeb /* 3924d9945d78SBjoern A. Zeeb * net80211 does not seem to support the DSSS Parameter Set but some of 3925d9945d78SBjoern A. Zeeb * the drivers insert it so calculate the extra fixed space in. 3926d9945d78SBjoern A. Zeeb */ 3927d9945d78SBjoern A. Zeeb lhw->scan_ie_len += 2 + 1; 3928d9945d78SBjoern A. Zeeb 3929d9945d78SBjoern A. Zeeb /* Reduce the max_scan_ie_len "left" by the amount we consume already. */ 3930d9945d78SBjoern A. Zeeb if (hw->wiphy->max_scan_ie_len > 0) 3931d9945d78SBjoern A. Zeeb hw->wiphy->max_scan_ie_len -= lhw->scan_ie_len; 3932d9945d78SBjoern A. Zeeb 39336b4cac81SBjoern A. Zeeb if (bootverbose) 39346b4cac81SBjoern A. Zeeb ieee80211_announce(ic); 39352e183d99SBjoern A. Zeeb 39362e183d99SBjoern A. Zeeb return (0); 39376b4cac81SBjoern A. Zeeb } 39386b4cac81SBjoern A. Zeeb 39396b4cac81SBjoern A. Zeeb void 39406b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ifdetach(struct ieee80211_hw *hw) 39416b4cac81SBjoern A. Zeeb { 39426b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 39436b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 39446b4cac81SBjoern A. Zeeb 39456b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 39466b4cac81SBjoern A. Zeeb ic = lhw->ic; 39476b4cac81SBjoern A. Zeeb ieee80211_ifdetach(ic); 39486b4cac81SBjoern A. Zeeb } 39496b4cac81SBjoern A. Zeeb 39506b4cac81SBjoern A. Zeeb void 39516b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_interfaces(struct ieee80211_hw *hw, 39526b4cac81SBjoern A. Zeeb enum ieee80211_iface_iter flags, 39536b4cac81SBjoern A. Zeeb void(*iterfunc)(void *, uint8_t *, struct ieee80211_vif *), 39546b4cac81SBjoern A. Zeeb void *arg) 39556b4cac81SBjoern A. Zeeb { 39566b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 39576b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 39586b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 395961a68e50SBjoern A. Zeeb bool active, atomic, nin_drv; 39606b4cac81SBjoern A. Zeeb 39616b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 39626b4cac81SBjoern A. Zeeb 39636b4cac81SBjoern A. Zeeb if (flags & ~(IEEE80211_IFACE_ITER_NORMAL| 39646b4cac81SBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL| 396561a68e50SBjoern A. Zeeb IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER| 3966adff403fSBjoern A. Zeeb IEEE80211_IFACE_ITER_ACTIVE|IEEE80211_IFACE_ITER__ATOMIC)) { 39676b4cac81SBjoern A. Zeeb ic_printf(lhw->ic, "XXX TODO %s flags(%#x) not yet supported.\n", 39686b4cac81SBjoern A. Zeeb __func__, flags); 39696b4cac81SBjoern A. Zeeb } 39706b4cac81SBjoern A. Zeeb 3971adff403fSBjoern A. Zeeb active = (flags & IEEE80211_IFACE_ITER_ACTIVE) != 0; 39726b4cac81SBjoern A. Zeeb atomic = (flags & IEEE80211_IFACE_ITER__ATOMIC) != 0; 397361a68e50SBjoern A. Zeeb nin_drv = (flags & IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER) != 0; 39746b4cac81SBjoern A. Zeeb 39756b4cac81SBjoern A. Zeeb if (atomic) 39768891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 39776b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 39786b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 39796b4cac81SBjoern A. Zeeb 39806b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 39816b4cac81SBjoern A. Zeeb 39826b4cac81SBjoern A. Zeeb /* 39836b4cac81SBjoern A. Zeeb * If we want "active" interfaces, we need to distinguish on 39846b4cac81SBjoern A. Zeeb * whether the driver knows about them or not to be able to 39856b4cac81SBjoern A. Zeeb * handle the "resume" case correctly. Skip the ones the 39866b4cac81SBjoern A. Zeeb * driver does not know about. 39876b4cac81SBjoern A. Zeeb */ 39886b4cac81SBjoern A. Zeeb if (active && !lvif->added_to_drv && 39896b4cac81SBjoern A. Zeeb (flags & IEEE80211_IFACE_ITER_RESUME_ALL) != 0) 39906b4cac81SBjoern A. Zeeb continue; 39916b4cac81SBjoern A. Zeeb 39926b4cac81SBjoern A. Zeeb /* 399361a68e50SBjoern A. Zeeb * If we shall skip interfaces not added to the driver do so 399461a68e50SBjoern A. Zeeb * if we haven't yet. 399561a68e50SBjoern A. Zeeb */ 399661a68e50SBjoern A. Zeeb if (nin_drv && !lvif->added_to_drv) 399761a68e50SBjoern A. Zeeb continue; 399861a68e50SBjoern A. Zeeb 399961a68e50SBjoern A. Zeeb /* 40006b4cac81SBjoern A. Zeeb * Run the iterator function if we are either not asking 40016b4cac81SBjoern A. Zeeb * asking for active only or if the VAP is "running". 40026b4cac81SBjoern A. Zeeb */ 40036b4cac81SBjoern A. Zeeb /* XXX-BZ probably should have state in the lvif as well. */ 40046b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 40056b4cac81SBjoern A. Zeeb if (!active || (vap->iv_state != IEEE80211_S_INIT)) 40066b4cac81SBjoern A. Zeeb iterfunc(arg, vif->addr, vif); 40076b4cac81SBjoern A. Zeeb } 40086b4cac81SBjoern A. Zeeb if (atomic) 40098891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 40106b4cac81SBjoern A. Zeeb } 40116b4cac81SBjoern A. Zeeb 40126b4cac81SBjoern A. Zeeb void 40136b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_keys(struct ieee80211_hw *hw, 40146b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif, 40156b4cac81SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_vif *, 40166b4cac81SBjoern A. Zeeb struct ieee80211_sta *, struct ieee80211_key_conf *, void *), 40176b4cac81SBjoern A. Zeeb void *arg) 40186b4cac81SBjoern A. Zeeb { 40196b4cac81SBjoern A. Zeeb 40206b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 40216b4cac81SBjoern A. Zeeb } 40226b4cac81SBjoern A. Zeeb 40236b4cac81SBjoern A. Zeeb void 40246b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_chan_contexts(struct ieee80211_hw *hw, 40256b4cac81SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_chanctx_conf *, 40266b4cac81SBjoern A. Zeeb void *), 40276b4cac81SBjoern A. Zeeb void *arg) 40286b4cac81SBjoern A. Zeeb { 4029c5e25798SBjoern A. Zeeb struct lkpi_hw *lhw; 4030c5e25798SBjoern A. Zeeb struct lkpi_vif *lvif; 4031c5e25798SBjoern A. Zeeb struct ieee80211_vif *vif; 4032c5e25798SBjoern A. Zeeb struct lkpi_chanctx *lchanctx; 40336b4cac81SBjoern A. Zeeb 4034c5e25798SBjoern A. Zeeb KASSERT(hw != NULL && iterfunc != NULL, 4035c5e25798SBjoern A. Zeeb ("%s: hw %p iterfunc %p arg %p\n", __func__, hw, iterfunc, arg)); 4036c5e25798SBjoern A. Zeeb 4037c5e25798SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 4038c5e25798SBjoern A. Zeeb 4039c5e25798SBjoern A. Zeeb IMPROVE("lchanctx should be its own list somewhere"); 4040c5e25798SBjoern A. Zeeb 4041c5e25798SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 4042c5e25798SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 4043c5e25798SBjoern A. Zeeb 4044c5e25798SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 4045c5e25798SBjoern A. Zeeb if (vif->chanctx_conf == NULL) 4046c5e25798SBjoern A. Zeeb continue; 4047c5e25798SBjoern A. Zeeb 4048c5e25798SBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(vif->chanctx_conf); 4049c5e25798SBjoern A. Zeeb if (!lchanctx->added_to_drv) 4050c5e25798SBjoern A. Zeeb continue; 4051c5e25798SBjoern A. Zeeb 4052c5e25798SBjoern A. Zeeb iterfunc(hw, &lchanctx->conf, arg); 4053c5e25798SBjoern A. Zeeb } 4054c5e25798SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 40556b4cac81SBjoern A. Zeeb } 40566b4cac81SBjoern A. Zeeb 40576b4cac81SBjoern A. Zeeb void 40586b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_stations_atomic(struct ieee80211_hw *hw, 40596b4cac81SBjoern A. Zeeb void (*iterfunc)(void *, struct ieee80211_sta *), void *arg) 40606b4cac81SBjoern A. Zeeb { 40616b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 40626b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 40636b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 40646b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 40656b4cac81SBjoern A. Zeeb 40666b4cac81SBjoern A. Zeeb KASSERT(hw != NULL && iterfunc != NULL, 40676b4cac81SBjoern A. Zeeb ("%s: hw %p iterfunc %p arg %p\n", __func__, hw, iterfunc, arg)); 40686b4cac81SBjoern A. Zeeb 40696b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 40706b4cac81SBjoern A. Zeeb 40718891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 40726b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 40736b4cac81SBjoern A. Zeeb 40746b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 40756b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lsta, &lvif->lsta_head, lsta_entry) { 40766b4cac81SBjoern A. Zeeb if (!lsta->added_to_drv) 40776b4cac81SBjoern A. Zeeb continue; 40786b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 40796b4cac81SBjoern A. Zeeb iterfunc(arg, sta); 40806b4cac81SBjoern A. Zeeb } 40816b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 40826b4cac81SBjoern A. Zeeb } 40838891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 40846b4cac81SBjoern A. Zeeb } 40856b4cac81SBjoern A. Zeeb 4086673d62fcSBjoern A. Zeeb struct linuxkpi_ieee80211_regdomain * 4087673d62fcSBjoern A. Zeeb lkpi_get_linuxkpi_ieee80211_regdomain(size_t n) 4088673d62fcSBjoern A. Zeeb { 4089673d62fcSBjoern A. Zeeb struct linuxkpi_ieee80211_regdomain *regd; 4090673d62fcSBjoern A. Zeeb 4091673d62fcSBjoern A. Zeeb regd = kzalloc(sizeof(*regd) + n * sizeof(struct ieee80211_reg_rule), 4092673d62fcSBjoern A. Zeeb GFP_KERNEL); 4093673d62fcSBjoern A. Zeeb return (regd); 4094673d62fcSBjoern A. Zeeb } 4095673d62fcSBjoern A. Zeeb 40966b4cac81SBjoern A. Zeeb int 40976b4cac81SBjoern A. Zeeb linuxkpi_regulatory_set_wiphy_regd_sync(struct wiphy *wiphy, 40986b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_regdomain *regd) 40996b4cac81SBjoern A. Zeeb { 41006b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 41016b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 41026b4cac81SBjoern A. Zeeb struct ieee80211_regdomain *rd; 41036b4cac81SBjoern A. Zeeb 41046b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 41056b4cac81SBjoern A. Zeeb ic = lhw->ic; 41066b4cac81SBjoern A. Zeeb 41076b4cac81SBjoern A. Zeeb rd = &ic->ic_regdomain; 41086b4cac81SBjoern A. Zeeb if (rd->isocc[0] == '\0') { 41096b4cac81SBjoern A. Zeeb rd->isocc[0] = regd->alpha2[0]; 41106b4cac81SBjoern A. Zeeb rd->isocc[1] = regd->alpha2[1]; 41116b4cac81SBjoern A. Zeeb } 41126b4cac81SBjoern A. Zeeb 41136b4cac81SBjoern A. Zeeb TODO(); 41146b4cac81SBjoern A. Zeeb /* XXX-BZ finish the rest. */ 41156b4cac81SBjoern A. Zeeb 41166b4cac81SBjoern A. Zeeb return (0); 41176b4cac81SBjoern A. Zeeb } 41186b4cac81SBjoern A. Zeeb 41196b4cac81SBjoern A. Zeeb void 41206b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_scan_completed(struct ieee80211_hw *hw, 41216b4cac81SBjoern A. Zeeb struct cfg80211_scan_info *info) 41226b4cac81SBjoern A. Zeeb { 41236b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 41246b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 41256b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 41266b4cac81SBjoern A. Zeeb 41276b4cac81SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 41286b4cac81SBjoern A. Zeeb ic = lhw->ic; 41296b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 41306b4cac81SBjoern A. Zeeb 41316b4cac81SBjoern A. Zeeb ieee80211_scan_done(ss->ss_vap); 41326b4cac81SBjoern A. Zeeb 41338ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 41346b4cac81SBjoern A. Zeeb free(lhw->hw_req, M_LKPI80211); 41356b4cac81SBjoern A. Zeeb lhw->hw_req = NULL; 4136a486fbbdSBjoern A. Zeeb lhw->scan_flags &= ~LKPI_LHW_SCAN_RUNNING; 41376b4cac81SBjoern A. Zeeb wakeup(lhw); 41388ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 41396b4cac81SBjoern A. Zeeb 41406b4cac81SBjoern A. Zeeb return; 41416b4cac81SBjoern A. Zeeb } 41426b4cac81SBjoern A. Zeeb 4143e30e05d3SBjoern A. Zeeb /* For %list see comment towards the end of the function. */ 41446b4cac81SBjoern A. Zeeb void 41456b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb, 4146e30e05d3SBjoern A. Zeeb struct ieee80211_sta *sta, struct napi_struct *napi __unused, 4147e30e05d3SBjoern A. Zeeb struct list_head *list __unused) 41486b4cac81SBjoern A. Zeeb { 41496b4cac81SBjoern A. Zeeb struct epoch_tracker et; 41506b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 41516b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 41526b4cac81SBjoern A. Zeeb struct mbuf *m; 41536b4cac81SBjoern A. Zeeb struct skb_shared_info *shinfo; 41546b4cac81SBjoern A. Zeeb struct ieee80211_rx_status *rx_status; 41556b4cac81SBjoern A. Zeeb struct ieee80211_rx_stats rx_stats; 41566b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 41576b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 41586b4cac81SBjoern A. Zeeb struct ieee80211_hdr *hdr; 41596b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 41609d9ba2b7SBjoern A. Zeeb int i, offset, ok; 4161170acccfSBjoern A. Zeeb int8_t rssi; 4162c0cadd99SBjoern A. Zeeb bool is_beacon; 41636b4cac81SBjoern A. Zeeb 41646b4cac81SBjoern A. Zeeb if (skb->len < 2) { 41656b4cac81SBjoern A. Zeeb /* Need 80211 stats here. */ 41666b4cac81SBjoern A. Zeeb IMPROVE(); 41676b4cac81SBjoern A. Zeeb goto err; 41686b4cac81SBjoern A. Zeeb } 41696b4cac81SBjoern A. Zeeb 41706b4cac81SBjoern A. Zeeb /* 41716b4cac81SBjoern A. Zeeb * For now do the data copy; we can later improve things. Might even 41726b4cac81SBjoern A. Zeeb * have an mbuf backing the skb data then? 41736b4cac81SBjoern A. Zeeb */ 41746b4cac81SBjoern A. Zeeb m = m_get2(skb->len, M_NOWAIT, MT_DATA, M_PKTHDR); 41756b4cac81SBjoern A. Zeeb if (m == NULL) 41766b4cac81SBjoern A. Zeeb goto err; 41776b4cac81SBjoern A. Zeeb m_copyback(m, 0, skb->tail - skb->data, skb->data); 41786b4cac81SBjoern A. Zeeb 41796b4cac81SBjoern A. Zeeb shinfo = skb_shinfo(skb); 41806b4cac81SBjoern A. Zeeb offset = m->m_len; 41816b4cac81SBjoern A. Zeeb for (i = 0; i < shinfo->nr_frags; i++) { 41826b4cac81SBjoern A. Zeeb m_copyback(m, offset, shinfo->frags[i].size, 41836b4cac81SBjoern A. Zeeb (uint8_t *)linux_page_address(shinfo->frags[i].page) + 41846b4cac81SBjoern A. Zeeb shinfo->frags[i].offset); 41856b4cac81SBjoern A. Zeeb offset += shinfo->frags[i].size; 41866b4cac81SBjoern A. Zeeb } 41876b4cac81SBjoern A. Zeeb 41886b4cac81SBjoern A. Zeeb rx_status = IEEE80211_SKB_RXCB(skb); 41896b4cac81SBjoern A. Zeeb 41906b4cac81SBjoern A. Zeeb hdr = (void *)skb->data; 4191c0cadd99SBjoern A. Zeeb is_beacon = ieee80211_is_beacon(hdr->frame_control); 4192c0cadd99SBjoern A. Zeeb 4193c0cadd99SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 41949d9ba2b7SBjoern A. Zeeb if (is_beacon && (linuxkpi_debug_80211 & D80211_TRACE_RX_BEACONS) == 0) 41956b4cac81SBjoern A. Zeeb goto no_trace_beacons; 41966b4cac81SBjoern A. Zeeb 41979d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 41986b4cac81SBjoern A. Zeeb printf("TRACE-RX: %s: skb %p a/l/d/t-len (%u/%u/%u/%u) " 4199c0cadd99SBjoern A. Zeeb "h %p d %p t %p e %p sh %p (%u) m %p plen %u len %u%s\n", 42006b4cac81SBjoern A. Zeeb __func__, skb, skb->_alloc_len, skb->len, skb->data_len, 42016b4cac81SBjoern A. Zeeb skb->truesize, skb->head, skb->data, skb->tail, skb->end, 42026b4cac81SBjoern A. Zeeb shinfo, shinfo->nr_frags, 4203c0cadd99SBjoern A. Zeeb m, m->m_pkthdr.len, m->m_len, is_beacon ? " beacon" : ""); 42046b4cac81SBjoern A. Zeeb 42059d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX_DUMP) 42066b4cac81SBjoern A. Zeeb hexdump(mtod(m, const void *), m->m_len, "RX (raw) ", 0); 42076b4cac81SBjoern A. Zeeb 42086b4cac81SBjoern A. Zeeb /* Implement a dump_rxcb() !!! */ 42099d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 4210c8dafefaSBjoern A. Zeeb printf("TRACE %s: RXCB: %ju %ju %u, %#0x, %u, %#0x, %#0x, " 421160970a32SBjoern A. Zeeb "%u band %u, %u { %d %d %d %d }, %d, %#x %#x %#x %#x %u %u %u\n", 42126b4cac81SBjoern A. Zeeb __func__, 4213c8dafefaSBjoern A. Zeeb (uintmax_t)rx_status->boottime_ns, 4214c8dafefaSBjoern A. Zeeb (uintmax_t)rx_status->mactime, 42156b4cac81SBjoern A. Zeeb rx_status->device_timestamp, 42166b4cac81SBjoern A. Zeeb rx_status->flag, 42176b4cac81SBjoern A. Zeeb rx_status->freq, 42186b4cac81SBjoern A. Zeeb rx_status->bw, 42196b4cac81SBjoern A. Zeeb rx_status->encoding, 42206b4cac81SBjoern A. Zeeb rx_status->ampdu_reference, 42216b4cac81SBjoern A. Zeeb rx_status->band, 42226b4cac81SBjoern A. Zeeb rx_status->chains, 42236b4cac81SBjoern A. Zeeb rx_status->chain_signal[0], 42246b4cac81SBjoern A. Zeeb rx_status->chain_signal[1], 42256b4cac81SBjoern A. Zeeb rx_status->chain_signal[2], 422660970a32SBjoern A. Zeeb rx_status->chain_signal[3], 42276b4cac81SBjoern A. Zeeb rx_status->signal, 42286b4cac81SBjoern A. Zeeb rx_status->enc_flags, 42296b4cac81SBjoern A. Zeeb rx_status->he_dcm, 42306b4cac81SBjoern A. Zeeb rx_status->he_gi, 42316b4cac81SBjoern A. Zeeb rx_status->he_ru, 42326b4cac81SBjoern A. Zeeb rx_status->zero_length_psdu_type, 42336b4cac81SBjoern A. Zeeb rx_status->nss, 42346b4cac81SBjoern A. Zeeb rx_status->rate_idx); 42356b4cac81SBjoern A. Zeeb no_trace_beacons: 42366b4cac81SBjoern A. Zeeb #endif 42376b4cac81SBjoern A. Zeeb 42386b4cac81SBjoern A. Zeeb memset(&rx_stats, 0, sizeof(rx_stats)); 42396b4cac81SBjoern A. Zeeb rx_stats.r_flags = IEEE80211_R_NF | IEEE80211_R_RSSI; 424060970a32SBjoern A. Zeeb /* XXX-BZ correct hardcoded rssi and noise floor, how? survey? */ 424160970a32SBjoern A. Zeeb rx_stats.c_nf = -96; 42426b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, SIGNAL_DBM) && 42436b4cac81SBjoern A. Zeeb !(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL)) 4244170acccfSBjoern A. Zeeb rssi = rx_status->signal; 42456b4cac81SBjoern A. Zeeb else 4246170acccfSBjoern A. Zeeb rssi = rx_stats.c_nf; 4247170acccfSBjoern A. Zeeb /* 4248170acccfSBjoern A. Zeeb * net80211 signal strength data are in .5 dBm units relative to 4249170acccfSBjoern A. Zeeb * the current noise floor (see comment in ieee80211_node.h). 4250170acccfSBjoern A. Zeeb */ 4251170acccfSBjoern A. Zeeb rssi -= rx_stats.c_nf; 4252170acccfSBjoern A. Zeeb rx_stats.c_rssi = rssi * 2; 42536b4cac81SBjoern A. Zeeb rx_stats.r_flags |= IEEE80211_R_BAND; 42546b4cac81SBjoern A. Zeeb rx_stats.c_band = 42556b4cac81SBjoern A. Zeeb lkpi_nl80211_band_to_net80211_band(rx_status->band); 42566b4cac81SBjoern A. Zeeb rx_stats.r_flags |= IEEE80211_R_FREQ | IEEE80211_R_IEEE; 42576b4cac81SBjoern A. Zeeb rx_stats.c_freq = rx_status->freq; 42586b4cac81SBjoern A. Zeeb rx_stats.c_ieee = ieee80211_mhz2ieee(rx_stats.c_freq, rx_stats.c_band); 42596b4cac81SBjoern A. Zeeb 42606b4cac81SBjoern A. Zeeb /* XXX (*sta_statistics)() to get to some of that? */ 42616b4cac81SBjoern A. Zeeb /* XXX-BZ dump the FreeBSD version of rx_stats as well! */ 42626b4cac81SBjoern A. Zeeb 42636b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 42646b4cac81SBjoern A. Zeeb ic = lhw->ic; 42656b4cac81SBjoern A. Zeeb 42666b4cac81SBjoern A. Zeeb ok = ieee80211_add_rx_params(m, &rx_stats); 42676b4cac81SBjoern A. Zeeb if (ok == 0) { 4268dbc06dd9SBjoern A. Zeeb m_freem(m); 42696b4cac81SBjoern A. Zeeb counter_u64_add(ic->ic_ierrors, 1); 42706b4cac81SBjoern A. Zeeb goto err; 42716b4cac81SBjoern A. Zeeb } 42726b4cac81SBjoern A. Zeeb 42736b4cac81SBjoern A. Zeeb if (sta != NULL) { 42746b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 42756b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(lsta->ni); 42766b4cac81SBjoern A. Zeeb } else { 4277c8dafefaSBjoern A. Zeeb struct ieee80211_frame_min *wh; 4278c8dafefaSBjoern A. Zeeb 42796b4cac81SBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame_min *); 42806b4cac81SBjoern A. Zeeb ni = ieee80211_find_rxnode(ic, wh); 42816b4cac81SBjoern A. Zeeb if (ni != NULL) 42826b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 42836b4cac81SBjoern A. Zeeb } 42846b4cac81SBjoern A. Zeeb 42856b4cac81SBjoern A. Zeeb if (ni != NULL) 42866b4cac81SBjoern A. Zeeb vap = ni->ni_vap; 42876b4cac81SBjoern A. Zeeb else 42886b4cac81SBjoern A. Zeeb /* 42896b4cac81SBjoern A. Zeeb * XXX-BZ can we improve this by looking at the frame hdr 42906b4cac81SBjoern A. Zeeb * or other meta-data passed up? 42916b4cac81SBjoern A. Zeeb */ 42926b4cac81SBjoern A. Zeeb vap = TAILQ_FIRST(&ic->ic_vaps); 42936b4cac81SBjoern A. Zeeb 42949d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 42959d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 4296c0cadd99SBjoern A. Zeeb printf("TRACE %s: sta %p lsta %p state %d ni %p vap %p%s\n", 4297c0cadd99SBjoern A. Zeeb __func__, sta, lsta, (lsta != NULL) ? lsta->state : -1, 4298c0cadd99SBjoern A. Zeeb ni, vap, is_beacon ? " beacon" : ""); 42999d9ba2b7SBjoern A. Zeeb #endif 43006b4cac81SBjoern A. Zeeb 4301c0cadd99SBjoern A. Zeeb if (ni != NULL && vap != NULL && is_beacon && 4302c8dafefaSBjoern A. Zeeb rx_status->device_timestamp > 0 && 4303c8dafefaSBjoern A. Zeeb m->m_pkthdr.len >= sizeof(struct ieee80211_frame)) { 4304c8dafefaSBjoern A. Zeeb struct lkpi_vif *lvif; 4305c8dafefaSBjoern A. Zeeb struct ieee80211_vif *vif; 4306c8dafefaSBjoern A. Zeeb struct ieee80211_frame *wh; 4307c8dafefaSBjoern A. Zeeb 4308c8dafefaSBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame *); 4309c8dafefaSBjoern A. Zeeb if (!IEEE80211_ADDR_EQ(wh->i_addr2, ni->ni_bssid)) 4310c8dafefaSBjoern A. Zeeb goto skip_device_ts; 4311c8dafefaSBjoern A. Zeeb 4312c8dafefaSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 4313c8dafefaSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 4314c8dafefaSBjoern A. Zeeb 4315c8dafefaSBjoern A. Zeeb IMPROVE("TIMING_BEACON_ONLY?"); 4316c8dafefaSBjoern A. Zeeb /* mac80211 specific (not net80211) so keep it here. */ 4317c8dafefaSBjoern A. Zeeb vif->bss_conf.sync_device_ts = rx_status->device_timestamp; 4318c8dafefaSBjoern A. Zeeb /* 4319c8dafefaSBjoern A. Zeeb * net80211 should take care of the other information (sync_tsf, 4320c8dafefaSBjoern A. Zeeb * sync_dtim_count) as otherwise we need to parse the beacon. 4321c8dafefaSBjoern A. Zeeb */ 4322c8dafefaSBjoern A. Zeeb } 4323c8dafefaSBjoern A. Zeeb skip_device_ts: 4324c8dafefaSBjoern A. Zeeb 43256b4cac81SBjoern A. Zeeb if (vap != NULL && vap->iv_state > IEEE80211_S_INIT && 43266b4cac81SBjoern A. Zeeb ieee80211_radiotap_active_vap(vap)) { 43276b4cac81SBjoern A. Zeeb struct lkpi_radiotap_rx_hdr *rtap; 43286b4cac81SBjoern A. Zeeb 43296b4cac81SBjoern A. Zeeb rtap = &lhw->rtap_rx; 43306b4cac81SBjoern A. Zeeb rtap->wr_tsft = rx_status->device_timestamp; 43316b4cac81SBjoern A. Zeeb rtap->wr_flags = 0; 43326b4cac81SBjoern A. Zeeb if (rx_status->enc_flags & RX_ENC_FLAG_SHORTPRE) 43336b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; 43346b4cac81SBjoern A. Zeeb if (rx_status->enc_flags & RX_ENC_FLAG_SHORT_GI) 43356b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTGI; 43366b4cac81SBjoern A. Zeeb #if 0 /* .. or it does not given we strip it below. */ 43376b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, RX_INCLUDES_FCS)) 43386b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_FCS; 43396b4cac81SBjoern A. Zeeb #endif 43406b4cac81SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_FAILED_FCS_CRC) 43416b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_BADFCS; 43426b4cac81SBjoern A. Zeeb rtap->wr_rate = 0; 43436b4cac81SBjoern A. Zeeb IMPROVE(); 43446b4cac81SBjoern A. Zeeb /* XXX TODO status->encoding / rate_index / bw */ 43456b4cac81SBjoern A. Zeeb rtap->wr_chan_freq = htole16(rx_stats.c_freq); 43466b4cac81SBjoern A. Zeeb if (ic->ic_curchan->ic_ieee == rx_stats.c_ieee) 43476b4cac81SBjoern A. Zeeb rtap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags); 4348170acccfSBjoern A. Zeeb rtap->wr_dbm_antsignal = rssi; 43496b4cac81SBjoern A. Zeeb rtap->wr_dbm_antnoise = rx_stats.c_nf; 43506b4cac81SBjoern A. Zeeb } 43516b4cac81SBjoern A. Zeeb 43526b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, RX_INCLUDES_FCS)) 43536b4cac81SBjoern A. Zeeb m_adj(m, -IEEE80211_CRC_LEN); 43546b4cac81SBjoern A. Zeeb 4355e30e05d3SBjoern A. Zeeb #if 0 4356e30e05d3SBjoern A. Zeeb if (list != NULL) { 4357e30e05d3SBjoern A. Zeeb /* 4358e30e05d3SBjoern A. Zeeb * Normally this would be queued up and delivered by 4359e30e05d3SBjoern A. Zeeb * netif_receive_skb_list(), napi_gro_receive(), or the like. 4360e30e05d3SBjoern A. Zeeb * See mt76::mac80211.c as only current possible consumer. 4361e30e05d3SBjoern A. Zeeb */ 4362e30e05d3SBjoern A. Zeeb IMPROVE("we simply pass the packet to net80211 to deal with."); 4363e30e05d3SBjoern A. Zeeb } 4364e30e05d3SBjoern A. Zeeb #endif 4365e30e05d3SBjoern A. Zeeb 43666b4cac81SBjoern A. Zeeb NET_EPOCH_ENTER(et); 43676b4cac81SBjoern A. Zeeb if (ni != NULL) { 43689d9ba2b7SBjoern A. Zeeb ok = ieee80211_input_mimo(ni, m); 43696b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 4370dbc06dd9SBjoern A. Zeeb if (ok < 0) 4371dbc06dd9SBjoern A. Zeeb m_freem(m); 43726b4cac81SBjoern A. Zeeb } else { 43739d9ba2b7SBjoern A. Zeeb ok = ieee80211_input_mimo_all(ic, m); 4374dbc06dd9SBjoern A. Zeeb /* mbuf got consumed. */ 43756b4cac81SBjoern A. Zeeb } 43766b4cac81SBjoern A. Zeeb NET_EPOCH_EXIT(et); 43776b4cac81SBjoern A. Zeeb 43789d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 43799d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 43809d9ba2b7SBjoern A. Zeeb printf("TRACE %s: handled frame type %#0x\n", __func__, ok); 43819d9ba2b7SBjoern A. Zeeb #endif 43826b4cac81SBjoern A. Zeeb 43836b4cac81SBjoern A. Zeeb IMPROVE(); 43846b4cac81SBjoern A. Zeeb 43856b4cac81SBjoern A. Zeeb err: 43866b4cac81SBjoern A. Zeeb /* The skb is ours so we can free it :-) */ 43876b4cac81SBjoern A. Zeeb kfree_skb(skb); 43886b4cac81SBjoern A. Zeeb } 43896b4cac81SBjoern A. Zeeb 43906b4cac81SBjoern A. Zeeb uint8_t 4391ec190d91SBjoern A. Zeeb linuxkpi_ieee80211_get_tid(struct ieee80211_hdr *hdr, bool nonqos_ok) 43926b4cac81SBjoern A. Zeeb { 43936b4cac81SBjoern A. Zeeb const struct ieee80211_frame *wh; 4394ec190d91SBjoern A. Zeeb uint8_t tid; 4395ec190d91SBjoern A. Zeeb 4396ec190d91SBjoern A. Zeeb /* Linux seems to assume this is a QOS-Data-Frame */ 4397ec190d91SBjoern A. Zeeb KASSERT(nonqos_ok || ieee80211_is_data_qos(hdr->frame_control), 4398ec190d91SBjoern A. Zeeb ("%s: hdr %p fc %#06x not qos_data\n", __func__, hdr, 4399ec190d91SBjoern A. Zeeb hdr->frame_control)); 44006b4cac81SBjoern A. Zeeb 44016b4cac81SBjoern A. Zeeb wh = (const struct ieee80211_frame *)hdr; 4402ec190d91SBjoern A. Zeeb tid = ieee80211_gettid(wh); 4403ec190d91SBjoern A. Zeeb KASSERT(nonqos_ok || tid == (tid & IEEE80211_QOS_TID), ("%s: tid %u " 4404ec190d91SBjoern A. Zeeb "not expected (%u?)\n", __func__, tid, IEEE80211_NONQOS_TID)); 4405ec190d91SBjoern A. Zeeb 4406ec190d91SBjoern A. Zeeb return (tid); 44076b4cac81SBjoern A. Zeeb } 44086b4cac81SBjoern A. Zeeb 44096b4cac81SBjoern A. Zeeb struct wiphy * 44106b4cac81SBjoern A. Zeeb linuxkpi_wiphy_new(const struct cfg80211_ops *ops, size_t priv_len) 44116b4cac81SBjoern A. Zeeb { 44126b4cac81SBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 44136b4cac81SBjoern A. Zeeb 44146b4cac81SBjoern A. Zeeb lwiphy = kzalloc(sizeof(*lwiphy) + priv_len, GFP_KERNEL); 44156b4cac81SBjoern A. Zeeb if (lwiphy == NULL) 44166b4cac81SBjoern A. Zeeb return (NULL); 44176b4cac81SBjoern A. Zeeb lwiphy->ops = ops; 44186b4cac81SBjoern A. Zeeb 44196b4cac81SBjoern A. Zeeb /* XXX TODO */ 44206b4cac81SBjoern A. Zeeb return (LWIPHY_TO_WIPHY(lwiphy)); 44216b4cac81SBjoern A. Zeeb } 44226b4cac81SBjoern A. Zeeb 44236b4cac81SBjoern A. Zeeb void 44246b4cac81SBjoern A. Zeeb linuxkpi_wiphy_free(struct wiphy *wiphy) 44256b4cac81SBjoern A. Zeeb { 44266b4cac81SBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 44276b4cac81SBjoern A. Zeeb 44286b4cac81SBjoern A. Zeeb if (wiphy == NULL) 44296b4cac81SBjoern A. Zeeb return; 44306b4cac81SBjoern A. Zeeb 44316b4cac81SBjoern A. Zeeb lwiphy = WIPHY_TO_LWIPHY(wiphy); 44326b4cac81SBjoern A. Zeeb kfree(lwiphy); 44336b4cac81SBjoern A. Zeeb } 44346b4cac81SBjoern A. Zeeb 44356b4cac81SBjoern A. Zeeb uint32_t 44366b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_channel_to_frequency(uint32_t channel, 44376b4cac81SBjoern A. Zeeb enum nl80211_band band) 44386b4cac81SBjoern A. Zeeb { 44396b4cac81SBjoern A. Zeeb 44406b4cac81SBjoern A. Zeeb switch (band) { 44416b4cac81SBjoern A. Zeeb case NL80211_BAND_2GHZ: 44426b4cac81SBjoern A. Zeeb return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_2GHZ)); 44436b4cac81SBjoern A. Zeeb break; 44446b4cac81SBjoern A. Zeeb case NL80211_BAND_5GHZ: 44456b4cac81SBjoern A. Zeeb return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_5GHZ)); 44466b4cac81SBjoern A. Zeeb break; 44476b4cac81SBjoern A. Zeeb default: 44486b4cac81SBjoern A. Zeeb /* XXX abort, retry, error, panic? */ 44496b4cac81SBjoern A. Zeeb break; 44506b4cac81SBjoern A. Zeeb } 44516b4cac81SBjoern A. Zeeb 44526b4cac81SBjoern A. Zeeb return (0); 44536b4cac81SBjoern A. Zeeb } 44546b4cac81SBjoern A. Zeeb 44556b4cac81SBjoern A. Zeeb uint32_t 44566b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_frequency_to_channel(uint32_t freq, uint32_t flags __unused) 44576b4cac81SBjoern A. Zeeb { 44586b4cac81SBjoern A. Zeeb 44596b4cac81SBjoern A. Zeeb return (ieee80211_mhz2ieee(freq, 0)); 44606b4cac81SBjoern A. Zeeb } 44616b4cac81SBjoern A. Zeeb 44626b4cac81SBjoern A. Zeeb static struct lkpi_sta * 44636b4cac81SBjoern A. Zeeb lkpi_find_lsta_by_ni(struct lkpi_vif *lvif, struct ieee80211_node *ni) 44646b4cac81SBjoern A. Zeeb { 44656b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta, *temp; 44666b4cac81SBjoern A. Zeeb 44676b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 44686b4cac81SBjoern A. Zeeb TAILQ_FOREACH_SAFE(lsta, &lvif->lsta_head, lsta_entry, temp) { 44696b4cac81SBjoern A. Zeeb if (lsta->ni == ni) { 44706b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 44716b4cac81SBjoern A. Zeeb return (lsta); 44726b4cac81SBjoern A. Zeeb } 44736b4cac81SBjoern A. Zeeb } 44746b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 44756b4cac81SBjoern A. Zeeb 44766b4cac81SBjoern A. Zeeb return (NULL); 44776b4cac81SBjoern A. Zeeb } 44786b4cac81SBjoern A. Zeeb 44796b4cac81SBjoern A. Zeeb struct ieee80211_sta * 44806b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_find_sta(struct ieee80211_vif *vif, const u8 *peer) 44816b4cac81SBjoern A. Zeeb { 44826b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 44836b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta, *temp; 44846b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 44856b4cac81SBjoern A. Zeeb 44866b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 44876b4cac81SBjoern A. Zeeb 44886b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 44896b4cac81SBjoern A. Zeeb TAILQ_FOREACH_SAFE(lsta, &lvif->lsta_head, lsta_entry, temp) { 44906b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 44916b4cac81SBjoern A. Zeeb if (IEEE80211_ADDR_EQ(sta->addr, peer)) { 44926b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 44936b4cac81SBjoern A. Zeeb return (sta); 44946b4cac81SBjoern A. Zeeb } 44956b4cac81SBjoern A. Zeeb } 44966b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 44976b4cac81SBjoern A. Zeeb return (NULL); 44986b4cac81SBjoern A. Zeeb } 44996b4cac81SBjoern A. Zeeb 45006b4cac81SBjoern A. Zeeb struct ieee80211_sta * 45012e183d99SBjoern A. Zeeb linuxkpi_ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw, 45022e183d99SBjoern A. Zeeb const uint8_t *addr, const uint8_t *ourvifaddr) 45036b4cac81SBjoern A. Zeeb { 45046b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 45056b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 45066b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 45076b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 45086b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 45096b4cac81SBjoern A. Zeeb 45106b4cac81SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 45116b4cac81SBjoern A. Zeeb sta = NULL; 45126b4cac81SBjoern A. Zeeb 45138891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 45146b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 45156b4cac81SBjoern A. Zeeb 45166b4cac81SBjoern A. Zeeb /* XXX-BZ check our address from the vif. */ 45176b4cac81SBjoern A. Zeeb 45186b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 45196b4cac81SBjoern A. Zeeb if (ourvifaddr != NULL && 45206b4cac81SBjoern A. Zeeb !IEEE80211_ADDR_EQ(vif->addr, ourvifaddr)) 45216b4cac81SBjoern A. Zeeb continue; 45226b4cac81SBjoern A. Zeeb sta = linuxkpi_ieee80211_find_sta(vif, addr); 45236b4cac81SBjoern A. Zeeb if (sta != NULL) 45246b4cac81SBjoern A. Zeeb break; 45256b4cac81SBjoern A. Zeeb } 45268891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 45276b4cac81SBjoern A. Zeeb 45286b4cac81SBjoern A. Zeeb if (sta != NULL) { 45296b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 45306b4cac81SBjoern A. Zeeb if (!lsta->added_to_drv) 45316b4cac81SBjoern A. Zeeb return (NULL); 45326b4cac81SBjoern A. Zeeb } 45336b4cac81SBjoern A. Zeeb 45346b4cac81SBjoern A. Zeeb return (sta); 45356b4cac81SBjoern A. Zeeb } 45366b4cac81SBjoern A. Zeeb 45376b4cac81SBjoern A. Zeeb struct sk_buff * 45386b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_tx_dequeue(struct ieee80211_hw *hw, 45396b4cac81SBjoern A. Zeeb struct ieee80211_txq *txq) 45406b4cac81SBjoern A. Zeeb { 45416b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 45420cbcfa19SBjoern A. Zeeb struct lkpi_vif *lvif; 45436b4cac81SBjoern A. Zeeb struct sk_buff *skb; 45446b4cac81SBjoern A. Zeeb 45450cbcfa19SBjoern A. Zeeb skb = NULL; 45466b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 45476b4cac81SBjoern A. Zeeb ltxq->seen_dequeue = true; 45486b4cac81SBjoern A. Zeeb 45490cbcfa19SBjoern A. Zeeb if (ltxq->stopped) 45500cbcfa19SBjoern A. Zeeb goto stopped; 45510cbcfa19SBjoern A. Zeeb 45520cbcfa19SBjoern A. Zeeb lvif = VIF_TO_LVIF(ltxq->txq.vif); 45530cbcfa19SBjoern A. Zeeb if (lvif->hw_queue_stopped[ltxq->txq.ac]) { 45540cbcfa19SBjoern A. Zeeb ltxq->stopped = true; 45550cbcfa19SBjoern A. Zeeb goto stopped; 45560cbcfa19SBjoern A. Zeeb } 45570cbcfa19SBjoern A. Zeeb 45586b4cac81SBjoern A. Zeeb skb = skb_dequeue(<xq->skbq); 45596b4cac81SBjoern A. Zeeb 45600cbcfa19SBjoern A. Zeeb stopped: 45616b4cac81SBjoern A. Zeeb return (skb); 45626b4cac81SBjoern A. Zeeb } 45636b4cac81SBjoern A. Zeeb 45646b4cac81SBjoern A. Zeeb void 45656b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_txq_get_depth(struct ieee80211_txq *txq, 456686220d3cSBjoern A. Zeeb unsigned long *frame_cnt, unsigned long *byte_cnt) 45676b4cac81SBjoern A. Zeeb { 45686b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 45696b4cac81SBjoern A. Zeeb struct sk_buff *skb; 457086220d3cSBjoern A. Zeeb unsigned long fc, bc; 45716b4cac81SBjoern A. Zeeb 45726b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 45736b4cac81SBjoern A. Zeeb 45746b4cac81SBjoern A. Zeeb fc = bc = 0; 45756b4cac81SBjoern A. Zeeb skb_queue_walk(<xq->skbq, skb) { 45766b4cac81SBjoern A. Zeeb fc++; 45776b4cac81SBjoern A. Zeeb bc += skb->len; 45786b4cac81SBjoern A. Zeeb } 45796b4cac81SBjoern A. Zeeb if (frame_cnt) 45806b4cac81SBjoern A. Zeeb *frame_cnt = fc; 45816b4cac81SBjoern A. Zeeb if (byte_cnt) 45826b4cac81SBjoern A. Zeeb *byte_cnt = bc; 45836b4cac81SBjoern A. Zeeb 45846b4cac81SBjoern A. Zeeb /* Validate that this is doing the correct thing. */ 45856b4cac81SBjoern A. Zeeb /* Should we keep track on en/dequeue? */ 45866b4cac81SBjoern A. Zeeb IMPROVE(); 45876b4cac81SBjoern A. Zeeb } 45886b4cac81SBjoern A. Zeeb 45896b4cac81SBjoern A. Zeeb /* 45906b4cac81SBjoern A. Zeeb * We are called from ieee80211_free_txskb() or ieee80211_tx_status(). 45916b4cac81SBjoern A. Zeeb * The latter tries to derive the success status from the info flags 45926b4cac81SBjoern A. Zeeb * passed back from the driver. rawx_mit() saves the ni on the m and the 45936b4cac81SBjoern A. Zeeb * m on the skb for us to be able to give feedback to net80211. 45946b4cac81SBjoern A. Zeeb */ 4595a8397571SBjoern A. Zeeb static void 4596a8397571SBjoern A. Zeeb _lkpi_ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb, 45976b4cac81SBjoern A. Zeeb int status) 45986b4cac81SBjoern A. Zeeb { 45996b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 46006b4cac81SBjoern A. Zeeb struct mbuf *m; 46016b4cac81SBjoern A. Zeeb 46026b4cac81SBjoern A. Zeeb m = skb->m; 46036b4cac81SBjoern A. Zeeb skb->m = NULL; 46046b4cac81SBjoern A. Zeeb 46056b4cac81SBjoern A. Zeeb if (m != NULL) { 46066b4cac81SBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 46076b4cac81SBjoern A. Zeeb /* Status: 0 is ok, != 0 is error. */ 46086b4cac81SBjoern A. Zeeb ieee80211_tx_complete(ni, m, status); 46096b4cac81SBjoern A. Zeeb /* ni & mbuf were consumed. */ 46106b4cac81SBjoern A. Zeeb } 4611a8397571SBjoern A. Zeeb } 46126b4cac81SBjoern A. Zeeb 4613a8397571SBjoern A. Zeeb void 4614a8397571SBjoern A. Zeeb linuxkpi_ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb, 4615a8397571SBjoern A. Zeeb int status) 4616a8397571SBjoern A. Zeeb { 4617a8397571SBjoern A. Zeeb 4618a8397571SBjoern A. Zeeb _lkpi_ieee80211_free_txskb(hw, skb, status); 46196b4cac81SBjoern A. Zeeb kfree_skb(skb); 46206b4cac81SBjoern A. Zeeb } 46216b4cac81SBjoern A. Zeeb 4622383b3e8fSBjoern A. Zeeb void 4623a8397571SBjoern A. Zeeb linuxkpi_ieee80211_tx_status_ext(struct ieee80211_hw *hw, 4624a8397571SBjoern A. Zeeb struct ieee80211_tx_status *txstat) 4625383b3e8fSBjoern A. Zeeb { 4626a8397571SBjoern A. Zeeb struct sk_buff *skb; 4627383b3e8fSBjoern A. Zeeb struct ieee80211_tx_info *info; 4628383b3e8fSBjoern A. Zeeb struct ieee80211_ratectl_tx_status txs; 4629383b3e8fSBjoern A. Zeeb struct ieee80211_node *ni; 4630383b3e8fSBjoern A. Zeeb int status; 4631383b3e8fSBjoern A. Zeeb 4632a8397571SBjoern A. Zeeb skb = txstat->skb; 4633383b3e8fSBjoern A. Zeeb if (skb->m != NULL) { 4634383b3e8fSBjoern A. Zeeb struct mbuf *m; 4635383b3e8fSBjoern A. Zeeb 4636383b3e8fSBjoern A. Zeeb m = skb->m; 4637383b3e8fSBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 4638383b3e8fSBjoern A. Zeeb memset(&txs, 0, sizeof(txs)); 4639383b3e8fSBjoern A. Zeeb } else { 4640383b3e8fSBjoern A. Zeeb ni = NULL; 4641383b3e8fSBjoern A. Zeeb } 4642383b3e8fSBjoern A. Zeeb 4643a8397571SBjoern A. Zeeb info = txstat->info; 4644383b3e8fSBjoern A. Zeeb if (info->flags & IEEE80211_TX_STAT_ACK) { 4645383b3e8fSBjoern A. Zeeb status = 0; /* No error. */ 4646383b3e8fSBjoern A. Zeeb txs.status = IEEE80211_RATECTL_TX_SUCCESS; 4647383b3e8fSBjoern A. Zeeb } else { 4648383b3e8fSBjoern A. Zeeb status = 1; 4649383b3e8fSBjoern A. Zeeb txs.status = IEEE80211_RATECTL_TX_FAIL_UNSPECIFIED; 4650383b3e8fSBjoern A. Zeeb } 4651383b3e8fSBjoern A. Zeeb 4652383b3e8fSBjoern A. Zeeb if (ni != NULL) { 4653e2c5ab09SJohn Baldwin int ridx __unused; 4654383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 4655383b3e8fSBjoern A. Zeeb int old_rate; 4656383b3e8fSBjoern A. Zeeb 4657383b3e8fSBjoern A. Zeeb old_rate = ni->ni_vap->iv_bss->ni_txrate; 4658383b3e8fSBjoern A. Zeeb #endif 4659383b3e8fSBjoern A. Zeeb txs.pktlen = skb->len; 4660383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_PKTLEN; 4661383b3e8fSBjoern A. Zeeb if (info->status.rates[0].count > 1) { 4662383b3e8fSBjoern A. Zeeb txs.long_retries = info->status.rates[0].count - 1; /* 1 + retries in drivers. */ 4663383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_LONG_RETRY; 4664383b3e8fSBjoern A. Zeeb } 4665383b3e8fSBjoern A. Zeeb #if 0 /* Unused in net80211 currently. */ 4666a8397571SBjoern A. Zeeb /* XXX-BZ convert check .flags for MCS/VHT/.. */ 4667383b3e8fSBjoern A. Zeeb txs.final_rate = info->status.rates[0].idx; 4668383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_FINAL_RATE; 4669383b3e8fSBjoern A. Zeeb #endif 4670adff403fSBjoern A. Zeeb if (info->status.flags & IEEE80211_TX_STATUS_ACK_SIGNAL_VALID) { 4671383b3e8fSBjoern A. Zeeb txs.rssi = info->status.ack_signal; /* XXX-BZ CONVERT? */ 4672383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_RSSI; 4673383b3e8fSBjoern A. Zeeb } 4674383b3e8fSBjoern A. Zeeb 4675383b3e8fSBjoern A. Zeeb IMPROVE("only update of rate matches but that requires us to get a proper rate"); 4676383b3e8fSBjoern A. Zeeb ieee80211_ratectl_tx_complete(ni, &txs); 4677383b3e8fSBjoern A. Zeeb ridx = ieee80211_ratectl_rate(ni->ni_vap->iv_bss, NULL, 0); 4678383b3e8fSBjoern A. Zeeb 4679383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 4680383b3e8fSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) { 4681383b3e8fSBjoern A. Zeeb printf("TX-RATE: %s: old %d new %d ridx %d, " 4682383b3e8fSBjoern A. Zeeb "long_retries %d\n", __func__, 4683383b3e8fSBjoern A. Zeeb old_rate, ni->ni_vap->iv_bss->ni_txrate, 4684383b3e8fSBjoern A. Zeeb ridx, txs.long_retries); 4685383b3e8fSBjoern A. Zeeb } 4686383b3e8fSBjoern A. Zeeb #endif 4687383b3e8fSBjoern A. Zeeb } 4688383b3e8fSBjoern A. Zeeb 4689383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 4690383b3e8fSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 4691383b3e8fSBjoern A. Zeeb printf("TX-STATUS: %s: hw %p skb %p status %d : flags %#x " 4692383b3e8fSBjoern A. Zeeb "band %u hw_queue %u tx_time_est %d : " 4693383b3e8fSBjoern A. Zeeb "rates [ %u %u %#x, %u %u %#x, %u %u %#x, %u %u %#x ] " 4694383b3e8fSBjoern A. Zeeb "ack_signal %u ampdu_ack_len %u ampdu_len %u antenna %u " 4695adff403fSBjoern A. Zeeb "tx_time %u flags %#x " 4696383b3e8fSBjoern A. Zeeb "status_driver_data [ %p %p ]\n", 4697383b3e8fSBjoern A. Zeeb __func__, hw, skb, status, info->flags, 4698383b3e8fSBjoern A. Zeeb info->band, info->hw_queue, info->tx_time_est, 4699383b3e8fSBjoern A. Zeeb info->status.rates[0].idx, info->status.rates[0].count, 4700383b3e8fSBjoern A. Zeeb info->status.rates[0].flags, 4701383b3e8fSBjoern A. Zeeb info->status.rates[1].idx, info->status.rates[1].count, 4702383b3e8fSBjoern A. Zeeb info->status.rates[1].flags, 4703383b3e8fSBjoern A. Zeeb info->status.rates[2].idx, info->status.rates[2].count, 4704383b3e8fSBjoern A. Zeeb info->status.rates[2].flags, 4705383b3e8fSBjoern A. Zeeb info->status.rates[3].idx, info->status.rates[3].count, 4706383b3e8fSBjoern A. Zeeb info->status.rates[3].flags, 4707383b3e8fSBjoern A. Zeeb info->status.ack_signal, info->status.ampdu_ack_len, 4708383b3e8fSBjoern A. Zeeb info->status.ampdu_len, info->status.antenna, 4709adff403fSBjoern A. Zeeb info->status.tx_time, info->status.flags, 4710383b3e8fSBjoern A. Zeeb info->status.status_driver_data[0], 4711383b3e8fSBjoern A. Zeeb info->status.status_driver_data[1]); 4712383b3e8fSBjoern A. Zeeb #endif 4713383b3e8fSBjoern A. Zeeb 4714a8397571SBjoern A. Zeeb if (txstat->free_list) { 4715a8397571SBjoern A. Zeeb _lkpi_ieee80211_free_txskb(hw, skb, status); 4716a8397571SBjoern A. Zeeb list_add_tail(&skb->list, txstat->free_list); 4717a8397571SBjoern A. Zeeb } else { 4718383b3e8fSBjoern A. Zeeb linuxkpi_ieee80211_free_txskb(hw, skb, status); 4719383b3e8fSBjoern A. Zeeb } 4720a8397571SBjoern A. Zeeb } 4721a8397571SBjoern A. Zeeb 4722a8397571SBjoern A. Zeeb void 4723a8397571SBjoern A. Zeeb linuxkpi_ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb) 4724a8397571SBjoern A. Zeeb { 4725a8397571SBjoern A. Zeeb struct ieee80211_tx_status status; 4726a8397571SBjoern A. Zeeb 4727a8397571SBjoern A. Zeeb memset(&status, 0, sizeof(status)); 4728a8397571SBjoern A. Zeeb status.info = IEEE80211_SKB_CB(skb); 4729a8397571SBjoern A. Zeeb status.skb = skb; 4730a8397571SBjoern A. Zeeb /* sta, n_rates, rates, free_list? */ 4731a8397571SBjoern A. Zeeb 4732a8397571SBjoern A. Zeeb ieee80211_tx_status_ext(hw, &status); 4733a8397571SBjoern A. Zeeb } 4734383b3e8fSBjoern A. Zeeb 47356b4cac81SBjoern A. Zeeb /* 47366b4cac81SBjoern A. Zeeb * This is an internal bandaid for the moment for the way we glue 47376b4cac81SBjoern A. Zeeb * skbs and mbufs together for TX. Once we have skbs backed by 47386b4cac81SBjoern A. Zeeb * mbufs this should go away. 47396b4cac81SBjoern A. Zeeb * This is a public function but kept on the private KPI (lkpi_) 47406b4cac81SBjoern A. Zeeb * and is not exposed by a header file. 47416b4cac81SBjoern A. Zeeb */ 47426b4cac81SBjoern A. Zeeb static void 47436b4cac81SBjoern A. Zeeb lkpi_ieee80211_free_skb_mbuf(void *p) 47446b4cac81SBjoern A. Zeeb { 47456b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 47466b4cac81SBjoern A. Zeeb struct mbuf *m; 47476b4cac81SBjoern A. Zeeb 47486b4cac81SBjoern A. Zeeb if (p == NULL) 47496b4cac81SBjoern A. Zeeb return; 47506b4cac81SBjoern A. Zeeb 47516b4cac81SBjoern A. Zeeb m = (struct mbuf *)p; 47526b4cac81SBjoern A. Zeeb M_ASSERTPKTHDR(m); 47536b4cac81SBjoern A. Zeeb 47546b4cac81SBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 47556b4cac81SBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = NULL; 47566b4cac81SBjoern A. Zeeb if (ni != NULL) 47576b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 47586b4cac81SBjoern A. Zeeb m_freem(m); 47596b4cac81SBjoern A. Zeeb } 47606b4cac81SBjoern A. Zeeb 47616b4cac81SBjoern A. Zeeb void 47626b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_queue_delayed_work(struct ieee80211_hw *hw, 47636b4cac81SBjoern A. Zeeb struct delayed_work *w, int delay) 47646b4cac81SBjoern A. Zeeb { 47656b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 47666b4cac81SBjoern A. Zeeb 47676b4cac81SBjoern A. Zeeb /* Need to make sure hw is in a stable (non-suspended) state. */ 47686b4cac81SBjoern A. Zeeb IMPROVE(); 47696b4cac81SBjoern A. Zeeb 47706b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 47716b4cac81SBjoern A. Zeeb queue_delayed_work(lhw->workq, w, delay); 47726b4cac81SBjoern A. Zeeb } 47736b4cac81SBjoern A. Zeeb 47746b4cac81SBjoern A. Zeeb void 47756b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_queue_work(struct ieee80211_hw *hw, 47766b4cac81SBjoern A. Zeeb struct work_struct *w) 47776b4cac81SBjoern A. Zeeb { 47786b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 47796b4cac81SBjoern A. Zeeb 47806b4cac81SBjoern A. Zeeb /* Need to make sure hw is in a stable (non-suspended) state. */ 47816b4cac81SBjoern A. Zeeb IMPROVE(); 47826b4cac81SBjoern A. Zeeb 47836b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 47846b4cac81SBjoern A. Zeeb queue_work(lhw->workq, w); 47856b4cac81SBjoern A. Zeeb } 47866b4cac81SBjoern A. Zeeb 47876b4cac81SBjoern A. Zeeb struct sk_buff * 4788ade774b1SBjoern A. Zeeb linuxkpi_ieee80211_probereq_get(struct ieee80211_hw *hw, uint8_t *addr, 4789ade774b1SBjoern A. Zeeb uint8_t *ssid, size_t ssid_len, size_t tailroom) 4790ade774b1SBjoern A. Zeeb { 4791ade774b1SBjoern A. Zeeb struct sk_buff *skb; 4792ade774b1SBjoern A. Zeeb struct ieee80211_frame *wh; 4793ade774b1SBjoern A. Zeeb uint8_t *p; 4794ade774b1SBjoern A. Zeeb size_t len; 4795ade774b1SBjoern A. Zeeb 4796ade774b1SBjoern A. Zeeb len = sizeof(*wh); 4797ade774b1SBjoern A. Zeeb len += 2 + ssid_len; 4798ade774b1SBjoern A. Zeeb 4799ade774b1SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + len + tailroom); 4800ade774b1SBjoern A. Zeeb if (skb == NULL) 4801ade774b1SBjoern A. Zeeb return (NULL); 4802ade774b1SBjoern A. Zeeb 4803ade774b1SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 4804ade774b1SBjoern A. Zeeb 4805ade774b1SBjoern A. Zeeb wh = skb_put_zero(skb, sizeof(*wh)); 4806ade774b1SBjoern A. Zeeb wh->i_fc[0] = IEEE80211_FC0_VERSION_0; 4807ade774b1SBjoern A. Zeeb wh->i_fc[0] |= IEEE80211_FC0_SUBTYPE_PROBE_REQ | IEEE80211_FC0_TYPE_MGT; 4808ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr1, ieee80211broadcastaddr); 4809ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr2, addr); 4810ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr3, ieee80211broadcastaddr); 4811ade774b1SBjoern A. Zeeb 4812ade774b1SBjoern A. Zeeb p = skb_put(skb, 2 + ssid_len); 4813ade774b1SBjoern A. Zeeb *p++ = IEEE80211_ELEMID_SSID; 4814ade774b1SBjoern A. Zeeb *p++ = ssid_len; 4815ade774b1SBjoern A. Zeeb if (ssid_len > 0) 4816ade774b1SBjoern A. Zeeb memcpy(p, ssid, ssid_len); 4817ade774b1SBjoern A. Zeeb 4818ade774b1SBjoern A. Zeeb return (skb); 4819ade774b1SBjoern A. Zeeb } 4820ade774b1SBjoern A. Zeeb 4821ade774b1SBjoern A. Zeeb struct sk_buff * 48226b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_pspoll_get(struct ieee80211_hw *hw, 48236b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif) 48246b4cac81SBjoern A. Zeeb { 48256b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 48266b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 48276b4cac81SBjoern A. Zeeb struct sk_buff *skb; 48286b4cac81SBjoern A. Zeeb struct ieee80211_frame_pspoll *psp; 48296b4cac81SBjoern A. Zeeb uint16_t v; 48306b4cac81SBjoern A. Zeeb 48316b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*psp)); 48326b4cac81SBjoern A. Zeeb if (skb == NULL) 48336b4cac81SBjoern A. Zeeb return (NULL); 48346b4cac81SBjoern A. Zeeb 48356b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 48366b4cac81SBjoern A. Zeeb 48376b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 48386b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 48396b4cac81SBjoern A. Zeeb 48406b4cac81SBjoern A. Zeeb psp = skb_put_zero(skb, sizeof(*psp)); 48416b4cac81SBjoern A. Zeeb psp->i_fc[0] = IEEE80211_FC0_VERSION_0; 48426b4cac81SBjoern A. Zeeb psp->i_fc[0] |= IEEE80211_FC0_SUBTYPE_PS_POLL | IEEE80211_FC0_TYPE_CTL; 4843616e1330SBjoern A. Zeeb v = htole16(vif->cfg.aid | 1<<15 | 1<<16); 48446b4cac81SBjoern A. Zeeb memcpy(&psp->i_aid, &v, sizeof(v)); 48456b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(psp->i_bssid, vap->iv_bss->ni_macaddr); 48466b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(psp->i_ta, vif->addr); 48476b4cac81SBjoern A. Zeeb 48486b4cac81SBjoern A. Zeeb return (skb); 48496b4cac81SBjoern A. Zeeb } 48506b4cac81SBjoern A. Zeeb 48516b4cac81SBjoern A. Zeeb struct sk_buff * 48526b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_nullfunc_get(struct ieee80211_hw *hw, 4853adff403fSBjoern A. Zeeb struct ieee80211_vif *vif, int linkid, bool qos) 48546b4cac81SBjoern A. Zeeb { 48556b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 48566b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 48576b4cac81SBjoern A. Zeeb struct sk_buff *skb; 48586b4cac81SBjoern A. Zeeb struct ieee80211_frame *nullf; 48596b4cac81SBjoern A. Zeeb 4860adff403fSBjoern A. Zeeb IMPROVE("linkid"); 4861adff403fSBjoern A. Zeeb 48626b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*nullf)); 48636b4cac81SBjoern A. Zeeb if (skb == NULL) 48646b4cac81SBjoern A. Zeeb return (NULL); 48656b4cac81SBjoern A. Zeeb 48666b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 48676b4cac81SBjoern A. Zeeb 48686b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 48696b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 48706b4cac81SBjoern A. Zeeb 48716b4cac81SBjoern A. Zeeb nullf = skb_put_zero(skb, sizeof(*nullf)); 48726b4cac81SBjoern A. Zeeb nullf->i_fc[0] = IEEE80211_FC0_VERSION_0; 48736b4cac81SBjoern A. Zeeb nullf->i_fc[0] |= IEEE80211_FC0_SUBTYPE_NODATA | IEEE80211_FC0_TYPE_DATA; 48746b4cac81SBjoern A. Zeeb nullf->i_fc[1] = IEEE80211_FC1_DIR_TODS; 48756b4cac81SBjoern A. Zeeb 48766b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr1, vap->iv_bss->ni_bssid); 48776b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr2, vif->addr); 48786b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr3, vap->iv_bss->ni_macaddr); 48796b4cac81SBjoern A. Zeeb 48806b4cac81SBjoern A. Zeeb return (skb); 48816b4cac81SBjoern A. Zeeb } 48826b4cac81SBjoern A. Zeeb 48836b4cac81SBjoern A. Zeeb struct wireless_dev * 48846b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_vif_to_wdev(struct ieee80211_vif *vif) 48856b4cac81SBjoern A. Zeeb { 48866b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 48876b4cac81SBjoern A. Zeeb 48886b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 48896b4cac81SBjoern A. Zeeb return (&lvif->wdev); 48906b4cac81SBjoern A. Zeeb } 48916b4cac81SBjoern A. Zeeb 48926b4cac81SBjoern A. Zeeb void 48936b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_connection_loss(struct ieee80211_vif *vif) 48946b4cac81SBjoern A. Zeeb { 48956b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 48966b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 48976b4cac81SBjoern A. Zeeb enum ieee80211_state nstate; 48986b4cac81SBjoern A. Zeeb int arg; 48996b4cac81SBjoern A. Zeeb 49006b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 49016b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 49026b4cac81SBjoern A. Zeeb 49036b4cac81SBjoern A. Zeeb /* 4904f3229b62SBjoern A. Zeeb * Go to init; otherwise we need to elaborately check state and 49056b4cac81SBjoern A. Zeeb * handle accordingly, e.g., if in RUN we could call iv_bmiss. 49066b4cac81SBjoern A. Zeeb * Let the statemachine handle all neccessary changes. 49076b4cac81SBjoern A. Zeeb */ 4908f3229b62SBjoern A. Zeeb nstate = IEEE80211_S_INIT; 4909bb81db90SBjoern A. Zeeb arg = 0; /* Not a valid reason. */ 49106b4cac81SBjoern A. Zeeb 4911*018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: vif %p vap %p state %s\n", __func__, 4912*018d93ecSBjoern A. Zeeb vif, vap, ieee80211_state_name[vap->iv_state]); 49136b4cac81SBjoern A. Zeeb ieee80211_new_state(vap, nstate, arg); 49146b4cac81SBjoern A. Zeeb } 49156b4cac81SBjoern A. Zeeb 4916bb81db90SBjoern A. Zeeb void 4917bb81db90SBjoern A. Zeeb linuxkpi_ieee80211_beacon_loss(struct ieee80211_vif *vif) 4918bb81db90SBjoern A. Zeeb { 4919bb81db90SBjoern A. Zeeb struct lkpi_vif *lvif; 4920bb81db90SBjoern A. Zeeb struct ieee80211vap *vap; 4921bb81db90SBjoern A. Zeeb 4922bb81db90SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 4923bb81db90SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 4924bb81db90SBjoern A. Zeeb 4925bb81db90SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: vif %p vap %p state %s\n", __func__, 4926bb81db90SBjoern A. Zeeb vif, vap, ieee80211_state_name[vap->iv_state]); 49273540911bSBjoern A. Zeeb ieee80211_beacon_miss(vap->iv_ic); 4928bb81db90SBjoern A. Zeeb } 4929bb81db90SBjoern A. Zeeb 49305edde07cSBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 49315edde07cSBjoern A. Zeeb 49325a9a0d78SBjoern A. Zeeb void 49335a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_stop_queue(struct ieee80211_hw *hw, int qnum) 49345a9a0d78SBjoern A. Zeeb { 49355a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 49365a9a0d78SBjoern A. Zeeb struct lkpi_vif *lvif; 49375a9a0d78SBjoern A. Zeeb struct ieee80211_vif *vif; 49385a9a0d78SBjoern A. Zeeb int ac_count, ac; 49395a9a0d78SBjoern A. Zeeb 49405a9a0d78SBjoern A. Zeeb KASSERT(qnum < hw->queues, ("%s: qnum %d >= hw->queues %d, hw %p\n", 49415a9a0d78SBjoern A. Zeeb __func__, qnum, hw->queues, hw)); 49425a9a0d78SBjoern A. Zeeb 49435a9a0d78SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 49445a9a0d78SBjoern A. Zeeb 49455a9a0d78SBjoern A. Zeeb /* See lkpi_ic_vap_create(). */ 49465a9a0d78SBjoern A. Zeeb if (hw->queues >= IEEE80211_NUM_ACS) 49475a9a0d78SBjoern A. Zeeb ac_count = IEEE80211_NUM_ACS; 49485a9a0d78SBjoern A. Zeeb else 49495a9a0d78SBjoern A. Zeeb ac_count = 1; 49505a9a0d78SBjoern A. Zeeb 49515a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 49525a9a0d78SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 49535a9a0d78SBjoern A. Zeeb 49545a9a0d78SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 49555a9a0d78SBjoern A. Zeeb for (ac = 0; ac < ac_count; ac++) { 49565a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 49575a9a0d78SBjoern A. Zeeb if (qnum == vif->hw_queue[ac]) { 49580d2cb6a6SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 49595a9a0d78SBjoern A. Zeeb /* 49605a9a0d78SBjoern A. Zeeb * For now log this to better understand 49615a9a0d78SBjoern A. Zeeb * how this is supposed to work. 49625a9a0d78SBjoern A. Zeeb */ 49630d2cb6a6SBjoern A. Zeeb if (lvif->hw_queue_stopped[ac] && 49640d2cb6a6SBjoern A. Zeeb (linuxkpi_debug_80211 & D80211_IMPROVE_TXQ) != 0) 49655a9a0d78SBjoern A. Zeeb ic_printf(lhw->ic, "%s:%d: lhw %p hw %p " 49665a9a0d78SBjoern A. Zeeb "lvif %p vif %p ac %d qnum %d already " 49675a9a0d78SBjoern A. Zeeb "stopped\n", __func__, __LINE__, 49685a9a0d78SBjoern A. Zeeb lhw, hw, lvif, vif, ac, qnum); 49690d2cb6a6SBjoern A. Zeeb #endif 49705a9a0d78SBjoern A. Zeeb lvif->hw_queue_stopped[ac] = true; 49715a9a0d78SBjoern A. Zeeb } 49725a9a0d78SBjoern A. Zeeb } 49735a9a0d78SBjoern A. Zeeb } 49745a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 49755a9a0d78SBjoern A. Zeeb } 49765a9a0d78SBjoern A. Zeeb 49775a9a0d78SBjoern A. Zeeb void 49785a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_stop_queues(struct ieee80211_hw *hw) 49795a9a0d78SBjoern A. Zeeb { 49805a9a0d78SBjoern A. Zeeb int i; 49815a9a0d78SBjoern A. Zeeb 49825a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Locking; do we need further info?"); 49835a9a0d78SBjoern A. Zeeb for (i = 0; i < hw->queues; i++) 49845a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_stop_queue(hw, i); 49855a9a0d78SBjoern A. Zeeb } 49865a9a0d78SBjoern A. Zeeb 49875a9a0d78SBjoern A. Zeeb 49885a9a0d78SBjoern A. Zeeb static void 49895a9a0d78SBjoern A. Zeeb lkpi_ieee80211_wake_queues(struct ieee80211_hw *hw, int hwq) 49905a9a0d78SBjoern A. Zeeb { 49915a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 49925a9a0d78SBjoern A. Zeeb struct lkpi_vif *lvif; 49935a9a0d78SBjoern A. Zeeb struct lkpi_sta *lsta; 49945a9a0d78SBjoern A. Zeeb int ac_count, ac, tid; 49955a9a0d78SBjoern A. Zeeb 49965a9a0d78SBjoern A. Zeeb /* See lkpi_ic_vap_create(). */ 49975a9a0d78SBjoern A. Zeeb if (hw->queues >= IEEE80211_NUM_ACS) 49985a9a0d78SBjoern A. Zeeb ac_count = IEEE80211_NUM_ACS; 49995a9a0d78SBjoern A. Zeeb else 50005a9a0d78SBjoern A. Zeeb ac_count = 1; 50015a9a0d78SBjoern A. Zeeb 50025a9a0d78SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 50035a9a0d78SBjoern A. Zeeb 50045a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Locking"); 50055a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 50065a9a0d78SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 50075a9a0d78SBjoern A. Zeeb struct ieee80211_vif *vif; 50085a9a0d78SBjoern A. Zeeb 50095a9a0d78SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 50105a9a0d78SBjoern A. Zeeb for (ac = 0; ac < ac_count; ac++) { 50115a9a0d78SBjoern A. Zeeb 50125a9a0d78SBjoern A. Zeeb if (hwq == vif->hw_queue[ac]) { 50135a9a0d78SBjoern A. Zeeb 50145a9a0d78SBjoern A. Zeeb /* XXX-BZ what about software scan? */ 50155a9a0d78SBjoern A. Zeeb 50160d2cb6a6SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 50175a9a0d78SBjoern A. Zeeb /* 50185a9a0d78SBjoern A. Zeeb * For now log this to better understand 50195a9a0d78SBjoern A. Zeeb * how this is supposed to work. 50205a9a0d78SBjoern A. Zeeb */ 50210d2cb6a6SBjoern A. Zeeb if (!lvif->hw_queue_stopped[ac] && 50220d2cb6a6SBjoern A. Zeeb (linuxkpi_debug_80211 & D80211_IMPROVE_TXQ) != 0) 50235a9a0d78SBjoern A. Zeeb ic_printf(lhw->ic, "%s:%d: lhw %p hw %p " 50245a9a0d78SBjoern A. Zeeb "lvif %p vif %p ac %d hw_q not stopped\n", 50255a9a0d78SBjoern A. Zeeb __func__, __LINE__, 50265a9a0d78SBjoern A. Zeeb lhw, hw, lvif, vif, ac); 50270d2cb6a6SBjoern A. Zeeb #endif 50285a9a0d78SBjoern A. Zeeb lvif->hw_queue_stopped[ac] = false; 50295a9a0d78SBjoern A. Zeeb 50305a9a0d78SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 50315a9a0d78SBjoern A. Zeeb TAILQ_FOREACH(lsta, &lvif->lsta_head, lsta_entry) { 50325a9a0d78SBjoern A. Zeeb struct ieee80211_sta *sta; 50335a9a0d78SBjoern A. Zeeb 50345a9a0d78SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 50355a9a0d78SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 50365a9a0d78SBjoern A. Zeeb struct lkpi_txq *ltxq; 50375a9a0d78SBjoern A. Zeeb 50385a9a0d78SBjoern A. Zeeb if (sta->txq[tid] == NULL) 50395a9a0d78SBjoern A. Zeeb continue; 50405a9a0d78SBjoern A. Zeeb 50415a9a0d78SBjoern A. Zeeb if (sta->txq[tid]->ac != ac) 50425a9a0d78SBjoern A. Zeeb continue; 50435a9a0d78SBjoern A. Zeeb 50445a9a0d78SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]); 50455a9a0d78SBjoern A. Zeeb if (!ltxq->stopped) 50465a9a0d78SBjoern A. Zeeb continue; 50475a9a0d78SBjoern A. Zeeb 50485a9a0d78SBjoern A. Zeeb ltxq->stopped = false; 50495a9a0d78SBjoern A. Zeeb 50505a9a0d78SBjoern A. Zeeb /* XXX-BZ see when this explodes with all the locking. taskq? */ 50515a9a0d78SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, sta->txq[tid]); 50525a9a0d78SBjoern A. Zeeb } 50535a9a0d78SBjoern A. Zeeb } 50545a9a0d78SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 50555a9a0d78SBjoern A. Zeeb } 50565a9a0d78SBjoern A. Zeeb } 50575a9a0d78SBjoern A. Zeeb } 50585a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 50595a9a0d78SBjoern A. Zeeb } 50605a9a0d78SBjoern A. Zeeb 50615a9a0d78SBjoern A. Zeeb void 50625a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_wake_queues(struct ieee80211_hw *hw) 50635a9a0d78SBjoern A. Zeeb { 50645a9a0d78SBjoern A. Zeeb int i; 50655a9a0d78SBjoern A. Zeeb 50665a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Is this all/enough here?"); 50675a9a0d78SBjoern A. Zeeb for (i = 0; i < hw->queues; i++) 50685a9a0d78SBjoern A. Zeeb lkpi_ieee80211_wake_queues(hw, i); 50695a9a0d78SBjoern A. Zeeb } 50705a9a0d78SBjoern A. Zeeb 50715a9a0d78SBjoern A. Zeeb void 50725a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_wake_queue(struct ieee80211_hw *hw, int qnum) 50735a9a0d78SBjoern A. Zeeb { 50745a9a0d78SBjoern A. Zeeb 50755a9a0d78SBjoern A. Zeeb KASSERT(qnum < hw->queues, ("%s: qnum %d >= hw->queues %d, hw %p\n", 50765a9a0d78SBjoern A. Zeeb __func__, qnum, hw->queues, hw)); 50775a9a0d78SBjoern A. Zeeb 50785a9a0d78SBjoern A. Zeeb lkpi_ieee80211_wake_queues(hw, qnum); 50795a9a0d78SBjoern A. Zeeb } 50805a9a0d78SBjoern A. Zeeb 50815a9a0d78SBjoern A. Zeeb /* This is just hardware queues. */ 50825a9a0d78SBjoern A. Zeeb void 50835a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_txq_schedule_start(struct ieee80211_hw *hw, uint8_t ac) 50845a9a0d78SBjoern A. Zeeb { 50855a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 50865a9a0d78SBjoern A. Zeeb 50875a9a0d78SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 50885a9a0d78SBjoern A. Zeeb 50895a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Are there reasons why we wouldn't schedule?"); 50905a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 50915a9a0d78SBjoern A. Zeeb if (++lhw->txq_generation[ac] == 0) 50925a9a0d78SBjoern A. Zeeb lhw->txq_generation[ac]++; 50935a9a0d78SBjoern A. Zeeb } 50945a9a0d78SBjoern A. Zeeb 50955a9a0d78SBjoern A. Zeeb struct ieee80211_txq * 50965a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_next_txq(struct ieee80211_hw *hw, uint8_t ac) 50975a9a0d78SBjoern A. Zeeb { 50985a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 50995a9a0d78SBjoern A. Zeeb struct ieee80211_txq *txq; 51005a9a0d78SBjoern A. Zeeb struct lkpi_txq *ltxq; 51015a9a0d78SBjoern A. Zeeb 51025a9a0d78SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 51035a9a0d78SBjoern A. Zeeb txq = NULL; 51045a9a0d78SBjoern A. Zeeb 51055a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 51065a9a0d78SBjoern A. Zeeb 51075a9a0d78SBjoern A. Zeeb /* Check that we are scheduled. */ 51085a9a0d78SBjoern A. Zeeb if (lhw->txq_generation[ac] == 0) 51095a9a0d78SBjoern A. Zeeb goto out; 51105a9a0d78SBjoern A. Zeeb 51115a9a0d78SBjoern A. Zeeb ltxq = TAILQ_FIRST(&lhw->scheduled_txqs[ac]); 51125a9a0d78SBjoern A. Zeeb if (ltxq == NULL) 51135a9a0d78SBjoern A. Zeeb goto out; 51145a9a0d78SBjoern A. Zeeb if (ltxq->txq_generation == lhw->txq_generation[ac]) 51155a9a0d78SBjoern A. Zeeb goto out; 51165a9a0d78SBjoern A. Zeeb 51175a9a0d78SBjoern A. Zeeb ltxq->txq_generation = lhw->txq_generation[ac]; 51185a9a0d78SBjoern A. Zeeb TAILQ_REMOVE(&lhw->scheduled_txqs[ac], ltxq, txq_entry); 51195a9a0d78SBjoern A. Zeeb txq = <xq->txq; 51205a9a0d78SBjoern A. Zeeb TAILQ_ELEM_INIT(ltxq, txq_entry); 51215a9a0d78SBjoern A. Zeeb 51225a9a0d78SBjoern A. Zeeb out: 51235a9a0d78SBjoern A. Zeeb return (txq); 51245a9a0d78SBjoern A. Zeeb } 51255a9a0d78SBjoern A. Zeeb 51265a9a0d78SBjoern A. Zeeb void linuxkpi_ieee80211_schedule_txq(struct ieee80211_hw *hw, 51275a9a0d78SBjoern A. Zeeb struct ieee80211_txq *txq, bool withoutpkts) 51285a9a0d78SBjoern A. Zeeb { 51295a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 51305a9a0d78SBjoern A. Zeeb struct lkpi_txq *ltxq; 51315a9a0d78SBjoern A. Zeeb 51325a9a0d78SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 51335a9a0d78SBjoern A. Zeeb 51345a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 51355a9a0d78SBjoern A. Zeeb 51365a9a0d78SBjoern A. Zeeb /* Only schedule if work to do or asked to anyway. */ 51375a9a0d78SBjoern A. Zeeb if (!withoutpkts && skb_queue_empty(<xq->skbq)) 51385a9a0d78SBjoern A. Zeeb goto out; 51395a9a0d78SBjoern A. Zeeb 51405a9a0d78SBjoern A. Zeeb /* Make sure we do not double-schedule. */ 51415a9a0d78SBjoern A. Zeeb if (ltxq->txq_entry.tqe_next != NULL) 51425a9a0d78SBjoern A. Zeeb goto out; 51435a9a0d78SBjoern A. Zeeb 51445a9a0d78SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 51455a9a0d78SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lhw->scheduled_txqs[txq->ac], ltxq, txq_entry); 51465a9a0d78SBjoern A. Zeeb out: 51475a9a0d78SBjoern A. Zeeb return; 51485a9a0d78SBjoern A. Zeeb } 51495a9a0d78SBjoern A. Zeeb 51505a9a0d78SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 51515a9a0d78SBjoern A. Zeeb 51525edde07cSBjoern A. Zeeb struct lkpi_cfg80211_bss { 51535edde07cSBjoern A. Zeeb u_int refcnt; 51545edde07cSBjoern A. Zeeb struct cfg80211_bss bss; 51555edde07cSBjoern A. Zeeb }; 51565edde07cSBjoern A. Zeeb 51575edde07cSBjoern A. Zeeb struct lkpi_cfg80211_get_bss_iter_lookup { 51585edde07cSBjoern A. Zeeb struct wiphy *wiphy; 51595edde07cSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 51605edde07cSBjoern A. Zeeb const uint8_t *bssid; 51615edde07cSBjoern A. Zeeb const uint8_t *ssid; 51625edde07cSBjoern A. Zeeb size_t ssid_len; 51635edde07cSBjoern A. Zeeb enum ieee80211_bss_type bss_type; 51645edde07cSBjoern A. Zeeb enum ieee80211_privacy privacy; 51655edde07cSBjoern A. Zeeb 51665edde07cSBjoern A. Zeeb /* 51675edde07cSBjoern A. Zeeb * Something to store a copy of the result as the net80211 scan cache 51685edde07cSBjoern A. Zeeb * is not refoucnted so a scan entry might go away any time. 51695edde07cSBjoern A. Zeeb */ 51705edde07cSBjoern A. Zeeb bool match; 51715edde07cSBjoern A. Zeeb struct cfg80211_bss *bss; 51725edde07cSBjoern A. Zeeb }; 51735edde07cSBjoern A. Zeeb 51745edde07cSBjoern A. Zeeb static void 51755edde07cSBjoern A. Zeeb lkpi_cfg80211_get_bss_iterf(void *arg, const struct ieee80211_scan_entry *se) 51765edde07cSBjoern A. Zeeb { 51775edde07cSBjoern A. Zeeb struct lkpi_cfg80211_get_bss_iter_lookup *lookup; 51785edde07cSBjoern A. Zeeb size_t ielen; 51795edde07cSBjoern A. Zeeb 51805edde07cSBjoern A. Zeeb lookup = arg; 51815edde07cSBjoern A. Zeeb 51825edde07cSBjoern A. Zeeb /* Do not try to find another match. */ 51835edde07cSBjoern A. Zeeb if (lookup->match) 51845edde07cSBjoern A. Zeeb return; 51855edde07cSBjoern A. Zeeb 51865edde07cSBjoern A. Zeeb /* Nothing to store result. */ 51875edde07cSBjoern A. Zeeb if (lookup->bss == NULL) 51885edde07cSBjoern A. Zeeb return; 51895edde07cSBjoern A. Zeeb 51905edde07cSBjoern A. Zeeb if (lookup->privacy != IEEE80211_PRIVACY_ANY) { 51915edde07cSBjoern A. Zeeb /* if (se->se_capinfo & IEEE80211_CAPINFO_PRIVACY) */ 51925edde07cSBjoern A. Zeeb /* We have no idea what to compare to as the drivers only request ANY */ 51935edde07cSBjoern A. Zeeb return; 51945edde07cSBjoern A. Zeeb } 51955edde07cSBjoern A. Zeeb 51965edde07cSBjoern A. Zeeb if (lookup->bss_type != IEEE80211_BSS_TYPE_ANY) { 51975edde07cSBjoern A. Zeeb /* if (se->se_capinfo & (IEEE80211_CAPINFO_IBSS|IEEE80211_CAPINFO_ESS)) */ 51985edde07cSBjoern A. Zeeb /* We have no idea what to compare to as the drivers only request ANY */ 51995edde07cSBjoern A. Zeeb return; 52005edde07cSBjoern A. Zeeb } 52015edde07cSBjoern A. Zeeb 52025edde07cSBjoern A. Zeeb if (lookup->chan != NULL) { 52035edde07cSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 52045edde07cSBjoern A. Zeeb 52055edde07cSBjoern A. Zeeb chan = linuxkpi_ieee80211_get_channel(lookup->wiphy, 52065edde07cSBjoern A. Zeeb se->se_chan->ic_freq); 52075edde07cSBjoern A. Zeeb if (chan == NULL || chan != lookup->chan) 52085edde07cSBjoern A. Zeeb return; 52095edde07cSBjoern A. Zeeb } 52105edde07cSBjoern A. Zeeb 52115edde07cSBjoern A. Zeeb if (lookup->bssid && !IEEE80211_ADDR_EQ(lookup->bssid, se->se_bssid)) 52125edde07cSBjoern A. Zeeb return; 52135edde07cSBjoern A. Zeeb 52145edde07cSBjoern A. Zeeb if (lookup->ssid) { 52155edde07cSBjoern A. Zeeb if (lookup->ssid_len != se->se_ssid[1] || 52165edde07cSBjoern A. Zeeb se->se_ssid[1] == 0) 52175edde07cSBjoern A. Zeeb return; 52185edde07cSBjoern A. Zeeb if (memcmp(lookup->ssid, se->se_ssid+2, lookup->ssid_len) != 0) 52195edde07cSBjoern A. Zeeb return; 52205edde07cSBjoern A. Zeeb } 52215edde07cSBjoern A. Zeeb 52225edde07cSBjoern A. Zeeb ielen = se->se_ies.len; 52235edde07cSBjoern A. Zeeb 52245edde07cSBjoern A. Zeeb lookup->bss->ies = malloc(sizeof(*lookup->bss->ies) + ielen, 52255edde07cSBjoern A. Zeeb M_LKPI80211, M_NOWAIT | M_ZERO); 52265edde07cSBjoern A. Zeeb if (lookup->bss->ies == NULL) 52275edde07cSBjoern A. Zeeb return; 52285edde07cSBjoern A. Zeeb 52295edde07cSBjoern A. Zeeb lookup->bss->ies->data = (uint8_t *)lookup->bss->ies + sizeof(*lookup->bss->ies); 52305edde07cSBjoern A. Zeeb lookup->bss->ies->len = ielen; 52315edde07cSBjoern A. Zeeb if (ielen) 52325edde07cSBjoern A. Zeeb memcpy(lookup->bss->ies->data, se->se_ies.data, ielen); 52335edde07cSBjoern A. Zeeb 52345edde07cSBjoern A. Zeeb lookup->match = true; 52355edde07cSBjoern A. Zeeb } 52365edde07cSBjoern A. Zeeb 52375edde07cSBjoern A. Zeeb struct cfg80211_bss * 52385edde07cSBjoern A. Zeeb linuxkpi_cfg80211_get_bss(struct wiphy *wiphy, struct linuxkpi_ieee80211_channel *chan, 52395edde07cSBjoern A. Zeeb const uint8_t *bssid, const uint8_t *ssid, size_t ssid_len, 52405edde07cSBjoern A. Zeeb enum ieee80211_bss_type bss_type, enum ieee80211_privacy privacy) 52415edde07cSBjoern A. Zeeb { 52425edde07cSBjoern A. Zeeb struct lkpi_cfg80211_bss *lbss; 52435edde07cSBjoern A. Zeeb struct lkpi_cfg80211_get_bss_iter_lookup lookup; 52445edde07cSBjoern A. Zeeb struct lkpi_hw *lhw; 52455edde07cSBjoern A. Zeeb struct ieee80211vap *vap; 52465edde07cSBjoern A. Zeeb 52475edde07cSBjoern A. Zeeb lhw = wiphy_priv(wiphy); 52485edde07cSBjoern A. Zeeb 52495edde07cSBjoern A. Zeeb /* Let's hope we can alloc. */ 52505edde07cSBjoern A. Zeeb lbss = malloc(sizeof(*lbss), M_LKPI80211, M_NOWAIT | M_ZERO); 52515edde07cSBjoern A. Zeeb if (lbss == NULL) { 52525edde07cSBjoern A. Zeeb ic_printf(lhw->ic, "%s: alloc failed.\n", __func__); 52535edde07cSBjoern A. Zeeb return (NULL); 52545edde07cSBjoern A. Zeeb } 52555edde07cSBjoern A. Zeeb 52565edde07cSBjoern A. Zeeb lookup.wiphy = wiphy; 52575edde07cSBjoern A. Zeeb lookup.chan = chan; 52585edde07cSBjoern A. Zeeb lookup.bssid = bssid; 52595edde07cSBjoern A. Zeeb lookup.ssid = ssid; 52605edde07cSBjoern A. Zeeb lookup.ssid_len = ssid_len; 52615edde07cSBjoern A. Zeeb lookup.bss_type = bss_type; 52625edde07cSBjoern A. Zeeb lookup.privacy = privacy; 52635edde07cSBjoern A. Zeeb lookup.match = false; 52645edde07cSBjoern A. Zeeb lookup.bss = &lbss->bss; 52655edde07cSBjoern A. Zeeb 52665edde07cSBjoern A. Zeeb IMPROVE("Iterate over all VAPs comparing perm_addr and addresses?"); 52675edde07cSBjoern A. Zeeb vap = TAILQ_FIRST(&lhw->ic->ic_vaps); 52685edde07cSBjoern A. Zeeb ieee80211_scan_iterate(vap, lkpi_cfg80211_get_bss_iterf, &lookup); 52695edde07cSBjoern A. Zeeb if (!lookup.match) { 52705edde07cSBjoern A. Zeeb free(lbss, M_LKPI80211); 52715edde07cSBjoern A. Zeeb return (NULL); 52725edde07cSBjoern A. Zeeb } 52735edde07cSBjoern A. Zeeb 52745edde07cSBjoern A. Zeeb refcount_init(&lbss->refcnt, 1); 52755edde07cSBjoern A. Zeeb return (&lbss->bss); 52765edde07cSBjoern A. Zeeb } 52775edde07cSBjoern A. Zeeb 52785edde07cSBjoern A. Zeeb void 52795edde07cSBjoern A. Zeeb linuxkpi_cfg80211_put_bss(struct wiphy *wiphy, struct cfg80211_bss *bss) 52805edde07cSBjoern A. Zeeb { 52815edde07cSBjoern A. Zeeb struct lkpi_cfg80211_bss *lbss; 52825edde07cSBjoern A. Zeeb 52835edde07cSBjoern A. Zeeb lbss = container_of(bss, struct lkpi_cfg80211_bss, bss); 52845edde07cSBjoern A. Zeeb 52855edde07cSBjoern A. Zeeb /* Free everything again on refcount ... */ 52865edde07cSBjoern A. Zeeb if (refcount_release(&lbss->refcnt)) { 52875edde07cSBjoern A. Zeeb free(lbss->bss.ies, M_LKPI80211); 52885edde07cSBjoern A. Zeeb free(lbss, M_LKPI80211); 52895edde07cSBjoern A. Zeeb } 52905edde07cSBjoern A. Zeeb } 52915edde07cSBjoern A. Zeeb 52925edde07cSBjoern A. Zeeb void 52935edde07cSBjoern A. Zeeb linuxkpi_cfg80211_bss_flush(struct wiphy *wiphy) 52945edde07cSBjoern A. Zeeb { 52955edde07cSBjoern A. Zeeb struct lkpi_hw *lhw; 52965edde07cSBjoern A. Zeeb struct ieee80211com *ic; 52975edde07cSBjoern A. Zeeb struct ieee80211vap *vap; 52985edde07cSBjoern A. Zeeb 52995edde07cSBjoern A. Zeeb lhw = wiphy_priv(wiphy); 53005edde07cSBjoern A. Zeeb ic = lhw->ic; 53015edde07cSBjoern A. Zeeb 53025edde07cSBjoern A. Zeeb /* 53035edde07cSBjoern A. Zeeb * If we haven't called ieee80211_ifattach() yet 53045edde07cSBjoern A. Zeeb * or there is no VAP, there are no scans to flush. 53055edde07cSBjoern A. Zeeb */ 53065edde07cSBjoern A. Zeeb if (ic == NULL || 53075edde07cSBjoern A. Zeeb (lhw->sc_flags & LKPI_MAC80211_DRV_STARTED) == 0) 53085edde07cSBjoern A. Zeeb return; 53095edde07cSBjoern A. Zeeb 53105edde07cSBjoern A. Zeeb /* Should only happen on the current one? Not seen it late enough. */ 53115edde07cSBjoern A. Zeeb IEEE80211_LOCK(ic); 53125edde07cSBjoern A. Zeeb TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) 53135edde07cSBjoern A. Zeeb ieee80211_scan_flush(vap); 53145edde07cSBjoern A. Zeeb IEEE80211_UNLOCK(ic); 53155edde07cSBjoern A. Zeeb } 53165edde07cSBjoern A. Zeeb 53175edde07cSBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 53185edde07cSBjoern A. Zeeb 53196b4cac81SBjoern A. Zeeb MODULE_VERSION(linuxkpi_wlan, 1); 53206b4cac81SBjoern A. Zeeb MODULE_DEPEND(linuxkpi_wlan, linuxkpi, 1, 1, 1); 53216b4cac81SBjoern A. Zeeb MODULE_DEPEND(linuxkpi_wlan, wlan, 1, 1, 1); 5322