16b4cac81SBjoern A. Zeeb /*- 2*8ac540d3SBjoern 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 __FBSDID("$FreeBSD$"); 446b4cac81SBjoern A. Zeeb 456b4cac81SBjoern A. Zeeb #include <sys/param.h> 466b4cac81SBjoern A. Zeeb #include <sys/types.h> 476b4cac81SBjoern A. Zeeb #include <sys/kernel.h> 486b4cac81SBjoern A. Zeeb #include <sys/errno.h> 496b4cac81SBjoern A. Zeeb #include <sys/malloc.h> 506b4cac81SBjoern A. Zeeb #include <sys/module.h> 516b4cac81SBjoern A. Zeeb #include <sys/mutex.h> 526b4cac81SBjoern A. Zeeb #include <sys/socket.h> 536b4cac81SBjoern A. Zeeb #include <sys/sysctl.h> 546b4cac81SBjoern A. Zeeb #include <sys/queue.h> 556b4cac81SBjoern A. Zeeb #include <sys/taskqueue.h> 56527687a9SBjoern A. Zeeb #include <sys/libkern.h> 576b4cac81SBjoern A. Zeeb 586b4cac81SBjoern A. Zeeb #include <net/if.h> 596b4cac81SBjoern A. Zeeb #include <net/if_var.h> 606b4cac81SBjoern A. Zeeb #include <net/if_media.h> 616b4cac81SBjoern A. Zeeb #include <net/ethernet.h> 626b4cac81SBjoern A. Zeeb 636b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_var.h> 646b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_proto.h> 656b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_ratectl.h> 666b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_radiotap.h> 676b4cac81SBjoern A. Zeeb 686b4cac81SBjoern A. Zeeb #define LINUXKPI_NET80211 696b4cac81SBjoern A. Zeeb #include <net/mac80211.h> 706b4cac81SBjoern A. Zeeb 716b4cac81SBjoern A. Zeeb #include <linux/workqueue.h> 726b4cac81SBjoern A. Zeeb #include "linux_80211.h" 736b4cac81SBjoern A. Zeeb 744a67f1dfSBjoern A. Zeeb #define LKPI_80211_WME 75b35f6cd0SBjoern A. Zeeb /* #define LKPI_80211_HW_CRYPTO */ 76b35f6cd0SBjoern A. Zeeb 776b4cac81SBjoern A. Zeeb static MALLOC_DEFINE(M_LKPI80211, "lkpi80211", "LinuxKPI 80211 compat"); 786b4cac81SBjoern A. Zeeb 795a9a0d78SBjoern A. Zeeb /* XXX-BZ really want this and others in queue.h */ 805a9a0d78SBjoern A. Zeeb #define TAILQ_ELEM_INIT(elm, field) do { \ 815a9a0d78SBjoern A. Zeeb (elm)->field.tqe_next = NULL; \ 825a9a0d78SBjoern A. Zeeb (elm)->field.tqe_prev = NULL; \ 835a9a0d78SBjoern A. Zeeb } while (0) 845a9a0d78SBjoern A. Zeeb 856b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 866b4cac81SBjoern A. Zeeb 879d9ba2b7SBjoern A. Zeeb /* Keep public for as long as header files are using it too. */ 889d9ba2b7SBjoern A. Zeeb int linuxkpi_debug_80211; 896b4cac81SBjoern A. Zeeb 906b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 919d9ba2b7SBjoern A. Zeeb SYSCTL_DECL(_compat_linuxkpi); 929d9ba2b7SBjoern A. Zeeb SYSCTL_NODE(_compat_linuxkpi, OID_AUTO, 80211, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 939d9ba2b7SBjoern A. Zeeb "LinuxKPI 802.11 compatibility layer"); 949d9ba2b7SBjoern A. Zeeb 959d9ba2b7SBjoern A. Zeeb SYSCTL_INT(_compat_linuxkpi_80211, OID_AUTO, debug, CTLFLAG_RWTUN, 969d9ba2b7SBjoern A. Zeeb &linuxkpi_debug_80211, 0, "LinuxKPI 802.11 debug level"); 979d9ba2b7SBjoern A. Zeeb 989d9ba2b7SBjoern A. Zeeb #define UNIMPLEMENTED if (linuxkpi_debug_80211 & D80211_TODO) \ 996b4cac81SBjoern A. Zeeb printf("XXX-TODO %s:%d: UNIMPLEMENTED\n", __func__, __LINE__) 1009d9ba2b7SBjoern A. Zeeb #define TRACEOK() if (linuxkpi_debug_80211 & D80211_TRACEOK) \ 1016b4cac81SBjoern A. Zeeb printf("XXX-TODO %s:%d: TRACEPOINT\n", __func__, __LINE__) 1026b4cac81SBjoern A. Zeeb #else 1036b4cac81SBjoern A. Zeeb #define UNIMPLEMENTED do { } while (0) 1046b4cac81SBjoern A. Zeeb #define TRACEOK() do { } while (0) 1056b4cac81SBjoern A. Zeeb #endif 1066b4cac81SBjoern A. Zeeb 1076b4cac81SBjoern A. Zeeb /* #define PREP_TX_INFO_DURATION (IEEE80211_TRANS_WAIT * 1000) */ 1086b4cac81SBjoern A. Zeeb #ifndef PREP_TX_INFO_DURATION 1096b4cac81SBjoern A. Zeeb #define PREP_TX_INFO_DURATION 0 /* Let the driver do its thing. */ 1106b4cac81SBjoern A. Zeeb #endif 1116b4cac81SBjoern A. Zeeb 112caaa79c3SBjoern A. Zeeb /* c.f. ieee80211_ioctl.c */ 113caaa79c3SBjoern A. Zeeb static const uint8_t zerobssid[IEEE80211_ADDR_LEN]; 114caaa79c3SBjoern A. Zeeb 1156b4cac81SBjoern A. Zeeb /* This is DSAP | SSAP | CTRL | ProtoID/OrgCode{3}. */ 1166b4cac81SBjoern A. Zeeb const uint8_t rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; 1176b4cac81SBjoern A. Zeeb 118b0f73768SBjoern A. Zeeb /* IEEE 802.11-05/0257r1 */ 119b0f73768SBjoern A. Zeeb const uint8_t bridge_tunnel_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; 120b0f73768SBjoern A. Zeeb 1214f61ef8bSBjoern A. Zeeb const uint8_t tid_to_mac80211_ac[] = { 1224f61ef8bSBjoern A. Zeeb IEEE80211_AC_BE, 1234f61ef8bSBjoern A. Zeeb IEEE80211_AC_BK, 1244f61ef8bSBjoern A. Zeeb IEEE80211_AC_BK, 1254f61ef8bSBjoern A. Zeeb IEEE80211_AC_BE, 1264f61ef8bSBjoern A. Zeeb IEEE80211_AC_VI, 1274f61ef8bSBjoern A. Zeeb IEEE80211_AC_VI, 1284f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO, 1294f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO, 1304f61ef8bSBjoern A. Zeeb #if 0 1314f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO, /* We treat MGMT as TID 8, which is set as AC_VO */ 1324f61ef8bSBjoern A. Zeeb #endif 1334f61ef8bSBjoern A. Zeeb }; 1344f61ef8bSBjoern A. Zeeb 1356b4cac81SBjoern A. Zeeb const struct cfg80211_ops linuxkpi_mac80211cfgops = { 1366b4cac81SBjoern A. Zeeb /* 1376b4cac81SBjoern A. Zeeb * XXX TODO need a "glue layer" to link cfg80211 ops to 1386b4cac81SBjoern A. Zeeb * mac80211 and to the driver or net80211. 1396b4cac81SBjoern A. Zeeb * Can we pass some on 1:1? Need to compare the (*f)(). 1406b4cac81SBjoern A. Zeeb */ 1416b4cac81SBjoern A. Zeeb }; 1426b4cac81SBjoern A. Zeeb 1436b4cac81SBjoern A. Zeeb static struct lkpi_sta *lkpi_find_lsta_by_ni(struct lkpi_vif *, 1446b4cac81SBjoern A. Zeeb struct ieee80211_node *); 1456b4cac81SBjoern A. Zeeb static void lkpi_80211_txq_task(void *, int); 1466b4cac81SBjoern A. Zeeb static void lkpi_ieee80211_free_skb_mbuf(void *); 1474a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 1484a67f1dfSBjoern A. Zeeb static int lkpi_wme_update(struct lkpi_hw *, struct ieee80211vap *, bool); 1494a67f1dfSBjoern A. Zeeb #endif 1506b4cac81SBjoern A. Zeeb 151d9f59799SBjoern A. Zeeb static void 15267674c1cSBjoern A. Zeeb lkpi_lsta_dump(struct lkpi_sta *lsta, struct ieee80211_node *ni, 15367674c1cSBjoern A. Zeeb const char *_f, int _l) 154d9f59799SBjoern A. Zeeb { 155d9f59799SBjoern A. Zeeb 1569d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 1579d9ba2b7SBjoern A. Zeeb if ((linuxkpi_debug_80211 & D80211_TRACE_STA) == 0) 158d9f59799SBjoern A. Zeeb return; 159d9f59799SBjoern A. Zeeb if (lsta == NULL) 160d9f59799SBjoern A. Zeeb return; 161d9f59799SBjoern A. Zeeb 162d9f59799SBjoern A. Zeeb printf("%s:%d lsta %p ni %p sta %p\n", 16367674c1cSBjoern A. Zeeb _f, _l, lsta, ni, &lsta->sta); 16467674c1cSBjoern A. Zeeb if (ni != NULL) 16567674c1cSBjoern A. Zeeb ieee80211_dump_node(NULL, ni); 166d9f59799SBjoern A. Zeeb printf("\ttxq_task txq len %d mtx\n", mbufq_len(&lsta->txq)); 167d9f59799SBjoern A. Zeeb printf("\tkc %p state %d added_to_drv %d in_mgd %d\n", 168d9f59799SBjoern A. Zeeb lsta->kc, lsta->state, lsta->added_to_drv, lsta->in_mgd); 1699d9ba2b7SBjoern A. Zeeb #endif 170d9f59799SBjoern A. Zeeb } 171d9f59799SBjoern A. Zeeb 172d9f59799SBjoern A. Zeeb static void 173d9f59799SBjoern A. Zeeb lkpi_lsta_remove(struct lkpi_sta *lsta, struct lkpi_vif *lvif) 174d9f59799SBjoern A. Zeeb { 175d9f59799SBjoern A. Zeeb struct ieee80211_node *ni; 176d9f59799SBjoern A. Zeeb 1773689f8aeSColin Percival IMPROVE("XXX-BZ remove tqe_prev check once ni-sta-state-sync is fixed"); 1783689f8aeSColin Percival 179d9f59799SBjoern A. Zeeb ni = lsta->ni; 180d9f59799SBjoern A. Zeeb 181d9f59799SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 1823689f8aeSColin Percival if (lsta->lsta_entry.tqe_prev != NULL) 183d9f59799SBjoern A. Zeeb TAILQ_REMOVE(&lvif->lsta_head, lsta, lsta_entry); 184d9f59799SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 185d9f59799SBjoern A. Zeeb 186d9f59799SBjoern A. Zeeb lsta->ni = NULL; 187d9f59799SBjoern A. Zeeb ni->ni_drv_data = NULL; 188e24e8103SBjoern A. Zeeb if (ni != NULL) 189d9f59799SBjoern A. Zeeb ieee80211_free_node(ni); 190d9f59799SBjoern A. Zeeb 191e24e8103SBjoern A. Zeeb IMPROVE("more from lkpi_ic_node_free() should happen here."); 192e24e8103SBjoern A. Zeeb 193e24e8103SBjoern A. Zeeb free(lsta, M_LKPI80211); 194d9f59799SBjoern A. Zeeb } 195d9f59799SBjoern A. Zeeb 1964f61ef8bSBjoern A. Zeeb static struct lkpi_sta * 1974f61ef8bSBjoern A. Zeeb lkpi_lsta_alloc(struct ieee80211vap *vap, const uint8_t mac[IEEE80211_ADDR_LEN], 1984f61ef8bSBjoern A. Zeeb struct ieee80211_hw *hw, struct ieee80211_node *ni) 1994f61ef8bSBjoern A. Zeeb { 2004f61ef8bSBjoern A. Zeeb struct lkpi_sta *lsta; 2014f61ef8bSBjoern A. Zeeb struct lkpi_vif *lvif; 2024f61ef8bSBjoern A. Zeeb struct ieee80211_vif *vif; 2034f61ef8bSBjoern A. Zeeb struct ieee80211_sta *sta; 204b6b352e4SBjoern A. Zeeb int band, i, tid; 2054f61ef8bSBjoern A. Zeeb 2064f61ef8bSBjoern A. Zeeb lsta = malloc(sizeof(*lsta) + hw->sta_data_size, M_LKPI80211, 2074f61ef8bSBjoern A. Zeeb M_NOWAIT | M_ZERO); 2084f61ef8bSBjoern A. Zeeb if (lsta == NULL) 2094f61ef8bSBjoern A. Zeeb return (NULL); 2104f61ef8bSBjoern A. Zeeb 2114f61ef8bSBjoern A. Zeeb lsta->added_to_drv = false; 2124f61ef8bSBjoern A. Zeeb lsta->state = IEEE80211_STA_NOTEXIST; 2134f61ef8bSBjoern A. Zeeb #if 0 2144f61ef8bSBjoern A. Zeeb /* 2154f61ef8bSBjoern A. Zeeb * This needs to be done in node_init() as ieee80211_alloc_node() 2164f61ef8bSBjoern A. Zeeb * will initialise the refcount after us. 2174f61ef8bSBjoern A. Zeeb */ 2184f61ef8bSBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 2194f61ef8bSBjoern A. Zeeb #endif 2204f61ef8bSBjoern A. Zeeb /* The back-pointer "drv_data" to net80211_node let's us get lsta. */ 2214f61ef8bSBjoern A. Zeeb ni->ni_drv_data = lsta; 2224f61ef8bSBjoern A. Zeeb 2234f61ef8bSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 2244f61ef8bSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 2254f61ef8bSBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 2264f61ef8bSBjoern A. Zeeb 2274f61ef8bSBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->addr, mac); 228b6b352e4SBjoern A. Zeeb 229b6b352e4SBjoern A. Zeeb /* TXQ */ 2304f61ef8bSBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 2314f61ef8bSBjoern A. Zeeb struct lkpi_txq *ltxq; 2324f61ef8bSBjoern A. Zeeb 233d0d29110SBjoern A. Zeeb /* We are not limiting ourselves to hw.queues here. */ 2344f61ef8bSBjoern A. Zeeb ltxq = malloc(sizeof(*ltxq) + hw->txq_data_size, 2354f61ef8bSBjoern A. Zeeb M_LKPI80211, M_NOWAIT | M_ZERO); 2364f61ef8bSBjoern A. Zeeb if (ltxq == NULL) 2374f61ef8bSBjoern A. Zeeb goto cleanup; 2384f61ef8bSBjoern A. Zeeb /* iwlwifi//mvm/sta.c::tid_to_mac80211_ac[] */ 2394f61ef8bSBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) { 240d0d29110SBjoern A. Zeeb if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ)) { 241d0d29110SBjoern A. Zeeb free(ltxq, M_LKPI80211); 242d0d29110SBjoern A. Zeeb continue; 243d0d29110SBjoern A. Zeeb } 244d0d29110SBjoern A. Zeeb IMPROVE("AP/if we support non-STA here too"); 2454f61ef8bSBjoern A. Zeeb ltxq->txq.ac = IEEE80211_AC_VO; 2464f61ef8bSBjoern A. Zeeb } else { 2474f61ef8bSBjoern A. Zeeb ltxq->txq.ac = tid_to_mac80211_ac[tid & 7]; 2484f61ef8bSBjoern A. Zeeb } 249d0d29110SBjoern A. Zeeb ltxq->seen_dequeue = false; 2500cbcfa19SBjoern A. Zeeb ltxq->stopped = false; 251d0d29110SBjoern A. Zeeb ltxq->txq.vif = vif; 2524f61ef8bSBjoern A. Zeeb ltxq->txq.tid = tid; 2534f61ef8bSBjoern A. Zeeb ltxq->txq.sta = sta; 2540cbcfa19SBjoern A. Zeeb TAILQ_ELEM_INIT(ltxq, txq_entry); 255d0d29110SBjoern A. Zeeb skb_queue_head_init(<xq->skbq); 2564f61ef8bSBjoern A. Zeeb sta->txq[tid] = <xq->txq; 2574f61ef8bSBjoern A. Zeeb } 2584f61ef8bSBjoern A. Zeeb 259b6b352e4SBjoern A. Zeeb /* Deflink information. */ 260b6b352e4SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 261b6b352e4SBjoern A. Zeeb struct ieee80211_supported_band *supband; 262b6b352e4SBjoern A. Zeeb 263b6b352e4SBjoern A. Zeeb supband = hw->wiphy->bands[band]; 264b6b352e4SBjoern A. Zeeb if (supband == NULL) 265b6b352e4SBjoern A. Zeeb continue; 266b6b352e4SBjoern A. Zeeb 267b6b352e4SBjoern A. Zeeb for (i = 0; i < supband->n_bitrates; i++) { 268b6b352e4SBjoern A. Zeeb 269b6b352e4SBjoern A. Zeeb IMPROVE("Further supband->bitrates[i]* checks?"); 270b6b352e4SBjoern A. Zeeb /* or should we get them from the ni? */ 271b6b352e4SBjoern A. Zeeb sta->deflink.supp_rates[band] |= BIT(i); 272b6b352e4SBjoern A. Zeeb } 273b6b352e4SBjoern A. Zeeb } 274b6b352e4SBjoern A. Zeeb IMPROVE("ht, vht, he, ... bandwidth, smps_mode, .."); 275b6b352e4SBjoern A. Zeeb /* bandwidth = IEEE80211_STA_RX_... */ 276b6b352e4SBjoern A. Zeeb 2774f61ef8bSBjoern A. Zeeb /* Deferred TX path. */ 2784f61ef8bSBjoern A. Zeeb mtx_init(&lsta->txq_mtx, "lsta_txq", NULL, MTX_DEF); 2794f61ef8bSBjoern A. Zeeb TASK_INIT(&lsta->txq_task, 0, lkpi_80211_txq_task, lsta); 2804f61ef8bSBjoern A. Zeeb mbufq_init(&lsta->txq, IFQ_MAXLEN); 2814f61ef8bSBjoern A. Zeeb 2824f61ef8bSBjoern A. Zeeb return (lsta); 2834f61ef8bSBjoern A. Zeeb 2844f61ef8bSBjoern A. Zeeb cleanup: 2854f61ef8bSBjoern A. Zeeb for (; tid >= 0; tid--) 2864f61ef8bSBjoern A. Zeeb free(sta->txq[tid], M_LKPI80211); 2874f61ef8bSBjoern A. Zeeb free(lsta, M_LKPI80211); 2884f61ef8bSBjoern A. Zeeb return (NULL); 2894f61ef8bSBjoern A. Zeeb } 2904f61ef8bSBjoern A. Zeeb 2916b4cac81SBjoern A. Zeeb static enum nl80211_band 2926b4cac81SBjoern A. Zeeb lkpi_net80211_chan_to_nl80211_band(struct ieee80211_channel *c) 2936b4cac81SBjoern A. Zeeb { 2946b4cac81SBjoern A. Zeeb 2956b4cac81SBjoern A. Zeeb if (IEEE80211_IS_CHAN_2GHZ(c)) 2966b4cac81SBjoern A. Zeeb return (NL80211_BAND_2GHZ); 2976b4cac81SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_5GHZ(c)) 2986b4cac81SBjoern A. Zeeb return (NL80211_BAND_5GHZ); 2996b4cac81SBjoern A. Zeeb #ifdef __notyet__ 3006b4cac81SBjoern A. Zeeb else if () 3016b4cac81SBjoern A. Zeeb return (NL80211_BAND_6GHZ); 3026b4cac81SBjoern A. Zeeb else if () 3036b4cac81SBjoern A. Zeeb return (NL80211_BAND_60GHZ); 3046b4cac81SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_GSM(c)) 3056b4cac81SBjoern A. Zeeb return (NL80211_BAND_XXX); 3066b4cac81SBjoern A. Zeeb #endif 3076b4cac81SBjoern A. Zeeb else 3086b4cac81SBjoern A. Zeeb panic("%s: unsupported band. c %p flags %#x\n", 3096b4cac81SBjoern A. Zeeb __func__, c, c->ic_flags); 3106b4cac81SBjoern A. Zeeb } 3116b4cac81SBjoern A. Zeeb 3126b4cac81SBjoern A. Zeeb static uint32_t 3136b4cac81SBjoern A. Zeeb lkpi_nl80211_band_to_net80211_band(enum nl80211_band band) 3146b4cac81SBjoern A. Zeeb { 3156b4cac81SBjoern A. Zeeb 3166b4cac81SBjoern A. Zeeb /* XXX-BZ this is just silly; net80211 is too convoluted. */ 3176b4cac81SBjoern A. Zeeb /* IEEE80211_CHAN_A / _G / .. doesn't really work either. */ 3186b4cac81SBjoern A. Zeeb switch (band) { 3196b4cac81SBjoern A. Zeeb case NL80211_BAND_2GHZ: 3206b4cac81SBjoern A. Zeeb return (IEEE80211_CHAN_2GHZ); 3216b4cac81SBjoern A. Zeeb break; 3226b4cac81SBjoern A. Zeeb case NL80211_BAND_5GHZ: 3236b4cac81SBjoern A. Zeeb return (IEEE80211_CHAN_5GHZ); 3246b4cac81SBjoern A. Zeeb break; 3256b4cac81SBjoern A. Zeeb case NL80211_BAND_60GHZ: 3266b4cac81SBjoern A. Zeeb break; 3276b4cac81SBjoern A. Zeeb case NL80211_BAND_6GHZ: 3286b4cac81SBjoern A. Zeeb break; 3296b4cac81SBjoern A. Zeeb default: 3306b4cac81SBjoern A. Zeeb panic("%s: unsupported band %u\n", __func__, band); 3316b4cac81SBjoern A. Zeeb break; 3326b4cac81SBjoern A. Zeeb } 3336b4cac81SBjoern A. Zeeb 3346b4cac81SBjoern A. Zeeb IMPROVE(); 3356b4cac81SBjoern A. Zeeb return (0x00); 3366b4cac81SBjoern A. Zeeb } 3376b4cac81SBjoern A. Zeeb 338e3a0b120SBjoern A. Zeeb #if 0 3396b4cac81SBjoern A. Zeeb static enum ieee80211_ac_numbers 3406b4cac81SBjoern A. Zeeb lkpi_ac_net_to_l80211(int ac) 3416b4cac81SBjoern A. Zeeb { 3426b4cac81SBjoern A. Zeeb 3436b4cac81SBjoern A. Zeeb switch (ac) { 3446b4cac81SBjoern A. Zeeb case WME_AC_VO: 3456b4cac81SBjoern A. Zeeb return (IEEE80211_AC_VO); 3466b4cac81SBjoern A. Zeeb case WME_AC_VI: 3476b4cac81SBjoern A. Zeeb return (IEEE80211_AC_VI); 3486b4cac81SBjoern A. Zeeb case WME_AC_BE: 3496b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BE); 3506b4cac81SBjoern A. Zeeb case WME_AC_BK: 3516b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BK); 3526b4cac81SBjoern A. Zeeb default: 3536b4cac81SBjoern A. Zeeb printf("%s: invalid WME_AC_* input: ac = %d\n", __func__, ac); 3546b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BE); 3556b4cac81SBjoern A. Zeeb } 3566b4cac81SBjoern A. Zeeb } 357e3a0b120SBjoern A. Zeeb #endif 3586b4cac81SBjoern A. Zeeb 3596b4cac81SBjoern A. Zeeb static enum nl80211_iftype 3606b4cac81SBjoern A. Zeeb lkpi_opmode_to_vif_type(enum ieee80211_opmode opmode) 3616b4cac81SBjoern A. Zeeb { 3626b4cac81SBjoern A. Zeeb 3636b4cac81SBjoern A. Zeeb switch (opmode) { 3646b4cac81SBjoern A. Zeeb case IEEE80211_M_IBSS: 3656b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_ADHOC); 3666b4cac81SBjoern A. Zeeb break; 3676b4cac81SBjoern A. Zeeb case IEEE80211_M_STA: 3686b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_STATION); 3696b4cac81SBjoern A. Zeeb break; 3706b4cac81SBjoern A. Zeeb case IEEE80211_M_WDS: 3716b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_WDS); 3726b4cac81SBjoern A. Zeeb break; 3736b4cac81SBjoern A. Zeeb case IEEE80211_M_HOSTAP: 3746b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_AP); 3756b4cac81SBjoern A. Zeeb break; 3766b4cac81SBjoern A. Zeeb case IEEE80211_M_MONITOR: 3776b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_MONITOR); 3786b4cac81SBjoern A. Zeeb break; 3796b4cac81SBjoern A. Zeeb case IEEE80211_M_MBSS: 3806b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_MESH_POINT); 3816b4cac81SBjoern A. Zeeb break; 3826b4cac81SBjoern A. Zeeb case IEEE80211_M_AHDEMO: 3836b4cac81SBjoern A. Zeeb /* FALLTHROUGH */ 3846b4cac81SBjoern A. Zeeb default: 3856b4cac81SBjoern A. Zeeb printf("ERROR: %s: unsupported opmode %d\n", __func__, opmode); 3866b4cac81SBjoern A. Zeeb /* FALLTHROUGH */ 3876b4cac81SBjoern A. Zeeb } 3886b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_UNSPECIFIED); 3896b4cac81SBjoern A. Zeeb } 3906b4cac81SBjoern A. Zeeb 391b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 3926b4cac81SBjoern A. Zeeb static uint32_t 3936b4cac81SBjoern A. Zeeb lkpi_l80211_to_net80211_cyphers(uint32_t wlan_cipher_suite) 3946b4cac81SBjoern A. Zeeb { 3956b4cac81SBjoern A. Zeeb 3966b4cac81SBjoern A. Zeeb switch (wlan_cipher_suite) { 3976b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP40: 3986b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_WEP); 3996b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP: 4006b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_TKIP); 4016b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP: 4026b4cac81SBjoern A. Zeeb return (IEEE80211_CIPHER_AES_CCM); 4036b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP104: 4046b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_WEP); 4056b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_AES_CMAC: 4066b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP: 4076b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP_256: 4086b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP_256: 4096b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_128: 4106b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_256: 4116b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_CMAC_256: 4126b4cac81SBjoern A. Zeeb printf("%s: unsupported WLAN Cipher Suite %#08x | %u\n", __func__, 4136b4cac81SBjoern A. Zeeb wlan_cipher_suite >> 8, wlan_cipher_suite & 0xff); 4146b4cac81SBjoern A. Zeeb break; 4156b4cac81SBjoern A. Zeeb default: 4166b4cac81SBjoern A. Zeeb printf("%s: unknown WLAN Cipher Suite %#08x | %u\n", __func__, 4176b4cac81SBjoern A. Zeeb wlan_cipher_suite >> 8, wlan_cipher_suite & 0xff); 4186b4cac81SBjoern A. Zeeb } 4196b4cac81SBjoern A. Zeeb 4206b4cac81SBjoern A. Zeeb return (0); 4216b4cac81SBjoern A. Zeeb } 4226b4cac81SBjoern A. Zeeb 4236b4cac81SBjoern A. Zeeb static uint32_t 4246b4cac81SBjoern A. Zeeb lkpi_net80211_to_l80211_cipher_suite(uint32_t cipher, uint8_t keylen) 4256b4cac81SBjoern A. Zeeb { 4266b4cac81SBjoern A. Zeeb 4276b4cac81SBjoern A. Zeeb switch (cipher) { 4286b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_TKIP: 4296b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_TKIP); 4306b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_AES_CCM: 4316b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_CCMP); 4326b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_WEP: 4336b4cac81SBjoern A. Zeeb if (keylen < 8) 4346b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_WEP40); 4356b4cac81SBjoern A. Zeeb else 4366b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_WEP104); 4376b4cac81SBjoern A. Zeeb break; 4386b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_AES_OCB: 4396b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_TKIPMIC: 4406b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_CKIP: 4416b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_NONE: 4426b4cac81SBjoern A. Zeeb printf("%s: unsupported cipher %#010x\n", __func__, cipher); 4436b4cac81SBjoern A. Zeeb break; 4446b4cac81SBjoern A. Zeeb default: 4456b4cac81SBjoern A. Zeeb printf("%s: unknown cipher %#010x\n", __func__, cipher); 4466b4cac81SBjoern A. Zeeb }; 4476b4cac81SBjoern A. Zeeb return (0); 4486b4cac81SBjoern A. Zeeb } 4496b4cac81SBjoern A. Zeeb #endif 4506b4cac81SBjoern A. Zeeb 4516b4cac81SBjoern A. Zeeb #ifdef __notyet__ 4526b4cac81SBjoern A. Zeeb static enum ieee80211_sta_state 4536b4cac81SBjoern A. Zeeb lkpi_net80211_state_to_sta_state(enum ieee80211_state state) 4546b4cac81SBjoern A. Zeeb { 4556b4cac81SBjoern A. Zeeb 4566b4cac81SBjoern A. Zeeb /* 4576b4cac81SBjoern A. Zeeb * XXX-BZ The net80211 states are "try to ..", the lkpi8011 states are 4586b4cac81SBjoern A. Zeeb * "done". Also ASSOC/AUTHORIZED are both "RUN" then? 4596b4cac81SBjoern A. Zeeb */ 4606b4cac81SBjoern A. Zeeb switch (state) { 4616b4cac81SBjoern A. Zeeb case IEEE80211_S_INIT: 4626b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NOTEXIST); 4636b4cac81SBjoern A. Zeeb case IEEE80211_S_SCAN: 4646b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NONE); 4656b4cac81SBjoern A. Zeeb case IEEE80211_S_AUTH: 4666b4cac81SBjoern A. Zeeb return (IEEE80211_STA_AUTH); 4676b4cac81SBjoern A. Zeeb case IEEE80211_S_ASSOC: 4686b4cac81SBjoern A. Zeeb return (IEEE80211_STA_ASSOC); 4696b4cac81SBjoern A. Zeeb case IEEE80211_S_RUN: 4706b4cac81SBjoern A. Zeeb return (IEEE80211_STA_AUTHORIZED); 4716b4cac81SBjoern A. Zeeb case IEEE80211_S_CAC: 4726b4cac81SBjoern A. Zeeb case IEEE80211_S_CSA: 4736b4cac81SBjoern A. Zeeb case IEEE80211_S_SLEEP: 4746b4cac81SBjoern A. Zeeb default: 4756b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 4766b4cac81SBjoern A. Zeeb }; 4776b4cac81SBjoern A. Zeeb 4786b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NOTEXIST); 4796b4cac81SBjoern A. Zeeb } 4806b4cac81SBjoern A. Zeeb #endif 4816b4cac81SBjoern A. Zeeb 4826b4cac81SBjoern A. Zeeb static struct linuxkpi_ieee80211_channel * 4836b4cac81SBjoern A. Zeeb lkpi_find_lkpi80211_chan(struct lkpi_hw *lhw, 4846b4cac81SBjoern A. Zeeb struct ieee80211_channel *c) 4856b4cac81SBjoern A. Zeeb { 4866b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 4876b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 4886b4cac81SBjoern A. Zeeb enum nl80211_band band; 4896b4cac81SBjoern A. Zeeb int i, nchans; 4906b4cac81SBjoern A. Zeeb 4916b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 4926b4cac81SBjoern A. Zeeb band = lkpi_net80211_chan_to_nl80211_band(c); 4936b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[band] == NULL) 4946b4cac81SBjoern A. Zeeb return (NULL); 4956b4cac81SBjoern A. Zeeb 4966b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[band]->n_channels; 4976b4cac81SBjoern A. Zeeb if (nchans <= 0) 4986b4cac81SBjoern A. Zeeb return (NULL); 4996b4cac81SBjoern A. Zeeb 5006b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[band]->channels; 5016b4cac81SBjoern A. Zeeb for (i = 0; i < nchans; i++) { 5026b4cac81SBjoern A. Zeeb if (channels[i].hw_value == c->ic_ieee) 5036b4cac81SBjoern A. Zeeb return (&channels[i]); 5046b4cac81SBjoern A. Zeeb } 5056b4cac81SBjoern A. Zeeb 5066b4cac81SBjoern A. Zeeb return (NULL); 5076b4cac81SBjoern A. Zeeb } 5086b4cac81SBjoern A. Zeeb 5096b4cac81SBjoern A. Zeeb static struct linuxkpi_ieee80211_channel * 5106b4cac81SBjoern A. Zeeb lkpi_get_lkpi80211_chan(struct ieee80211com *ic, struct ieee80211_node *ni) 5116b4cac81SBjoern A. Zeeb { 5126b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 5136b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 5146b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 5156b4cac81SBjoern A. Zeeb 5166b4cac81SBjoern A. Zeeb chan = NULL; 5176b4cac81SBjoern A. Zeeb if (ni != NULL && ni->ni_chan != IEEE80211_CHAN_ANYC) 5186b4cac81SBjoern A. Zeeb c = ni->ni_chan; 5196b4cac81SBjoern A. Zeeb else if (ic->ic_bsschan != IEEE80211_CHAN_ANYC) 5206b4cac81SBjoern A. Zeeb c = ic->ic_bsschan; 5216b4cac81SBjoern A. Zeeb else if (ic->ic_curchan != IEEE80211_CHAN_ANYC) 5226b4cac81SBjoern A. Zeeb c = ic->ic_curchan; 5236b4cac81SBjoern A. Zeeb else 5246b4cac81SBjoern A. Zeeb c = NULL; 5256b4cac81SBjoern A. Zeeb 5266b4cac81SBjoern A. Zeeb if (c != NULL && c != IEEE80211_CHAN_ANYC) { 5276b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 5286b4cac81SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, c); 5296b4cac81SBjoern A. Zeeb } 5306b4cac81SBjoern A. Zeeb 5316b4cac81SBjoern A. Zeeb return (chan); 5326b4cac81SBjoern A. Zeeb } 5336b4cac81SBjoern A. Zeeb 5342e183d99SBjoern A. Zeeb struct linuxkpi_ieee80211_channel * 5352e183d99SBjoern A. Zeeb linuxkpi_ieee80211_get_channel(struct wiphy *wiphy, uint32_t freq) 5362e183d99SBjoern A. Zeeb { 5372e183d99SBjoern A. Zeeb enum nl80211_band band; 5382e183d99SBjoern A. Zeeb 5392e183d99SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 5402e183d99SBjoern A. Zeeb struct ieee80211_supported_band *supband; 5412e183d99SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 5422e183d99SBjoern A. Zeeb int i; 5432e183d99SBjoern A. Zeeb 5442e183d99SBjoern A. Zeeb supband = wiphy->bands[band]; 5452e183d99SBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 5462e183d99SBjoern A. Zeeb continue; 5472e183d99SBjoern A. Zeeb 5482e183d99SBjoern A. Zeeb channels = supband->channels; 5492e183d99SBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 5502e183d99SBjoern A. Zeeb if (channels[i].center_freq == freq) 5512e183d99SBjoern A. Zeeb return (&channels[i]); 5522e183d99SBjoern A. Zeeb } 5532e183d99SBjoern A. Zeeb } 5542e183d99SBjoern A. Zeeb 5552e183d99SBjoern A. Zeeb return (NULL); 5562e183d99SBjoern A. Zeeb } 5572e183d99SBjoern A. Zeeb 558b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 5596b4cac81SBjoern A. Zeeb static int 5606b4cac81SBjoern A. Zeeb _lkpi_iv_key_set_delete(struct ieee80211vap *vap, const struct ieee80211_key *k, 5616b4cac81SBjoern A. Zeeb enum set_key_cmd cmd) 5626b4cac81SBjoern A. Zeeb { 5636b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 5646b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 5656b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 5666b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 5676b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 5686b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 5696b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 5706b4cac81SBjoern A. Zeeb struct ieee80211_key_conf *kc; 5716b4cac81SBjoern A. Zeeb int error; 5726b4cac81SBjoern A. Zeeb 5736b4cac81SBjoern A. Zeeb /* XXX TODO Check (k->wk_flags & IEEE80211_KEY_SWENCRYPT) and don't upload to driver/hw? */ 5746b4cac81SBjoern A. Zeeb 5756b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 5766b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 5776b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 5786b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 5796b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 5806b4cac81SBjoern A. Zeeb 5816b4cac81SBjoern A. Zeeb memset(&kc, 0, sizeof(kc)); 5826b4cac81SBjoern A. Zeeb kc = malloc(sizeof(*kc) + k->wk_keylen, M_LKPI80211, M_WAITOK | M_ZERO); 5836b4cac81SBjoern A. Zeeb kc->cipher = lkpi_net80211_to_l80211_cipher_suite( 5846b4cac81SBjoern A. Zeeb k->wk_cipher->ic_cipher, k->wk_keylen); 5856b4cac81SBjoern A. Zeeb kc->keyidx = k->wk_keyix; 5866b4cac81SBjoern A. Zeeb #if 0 5876b4cac81SBjoern A. Zeeb kc->hw_key_idx = /* set by hw and needs to be passed for TX */; 5886b4cac81SBjoern A. Zeeb #endif 5896b4cac81SBjoern A. Zeeb atomic64_set(&kc->tx_pn, k->wk_keytsc); 5906b4cac81SBjoern A. Zeeb kc->keylen = k->wk_keylen; 5916b4cac81SBjoern A. Zeeb memcpy(kc->key, k->wk_key, k->wk_keylen); 5926b4cac81SBjoern A. Zeeb 5936b4cac81SBjoern A. Zeeb switch (kc->cipher) { 5946b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP: 5956b4cac81SBjoern A. Zeeb kc->iv_len = k->wk_cipher->ic_header; 5966b4cac81SBjoern A. Zeeb kc->icv_len = k->wk_cipher->ic_trailer; 5976b4cac81SBjoern A. Zeeb break; 5986b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP: 5996b4cac81SBjoern A. Zeeb default: 6006b4cac81SBjoern A. Zeeb IMPROVE(); 6016b4cac81SBjoern A. Zeeb return (0); 6026b4cac81SBjoern A. Zeeb }; 6036b4cac81SBjoern A. Zeeb 6046b4cac81SBjoern A. Zeeb ni = vap->iv_bss; 6056b4cac81SBjoern A. Zeeb sta = ieee80211_find_sta(vif, ni->ni_bssid); 6066b4cac81SBjoern A. Zeeb if (sta != NULL) { 6076b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 6086b4cac81SBjoern A. Zeeb 6096b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 6106b4cac81SBjoern A. Zeeb lsta->kc = kc; 6116b4cac81SBjoern A. Zeeb } 6126b4cac81SBjoern A. Zeeb 6136b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_set_key(hw, cmd, vif, sta, kc); 6146b4cac81SBjoern A. Zeeb if (error != 0) { 6156b4cac81SBjoern A. Zeeb /* XXX-BZ leaking kc currently */ 6166b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: set_key failed: %d\n", __func__, error); 6176b4cac81SBjoern A. Zeeb return (0); 6186b4cac81SBjoern A. Zeeb } else { 6196b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: set_key succeeded: keyidx %u hw_key_idx %u " 6206b4cac81SBjoern A. Zeeb "flags %#10x\n", __func__, 6216b4cac81SBjoern A. Zeeb kc->keyidx, kc->hw_key_idx, kc->flags); 6226b4cac81SBjoern A. Zeeb return (1); 6236b4cac81SBjoern A. Zeeb } 6246b4cac81SBjoern A. Zeeb } 6256b4cac81SBjoern A. Zeeb 6266b4cac81SBjoern A. Zeeb static int 6276b4cac81SBjoern A. Zeeb lkpi_iv_key_delete(struct ieee80211vap *vap, const struct ieee80211_key *k) 6286b4cac81SBjoern A. Zeeb { 6296b4cac81SBjoern A. Zeeb 6306b4cac81SBjoern A. Zeeb /* XXX-BZ one day we should replace this iterating over VIFs, or node list? */ 6316b4cac81SBjoern A. Zeeb return (_lkpi_iv_key_set_delete(vap, k, DISABLE_KEY)); 6326b4cac81SBjoern A. Zeeb } 6336b4cac81SBjoern A. Zeeb static int 6346b4cac81SBjoern A. Zeeb lkpi_iv_key_set(struct ieee80211vap *vap, const struct ieee80211_key *k) 6356b4cac81SBjoern A. Zeeb { 6366b4cac81SBjoern A. Zeeb 6376b4cac81SBjoern A. Zeeb return (_lkpi_iv_key_set_delete(vap, k, SET_KEY)); 6386b4cac81SBjoern A. Zeeb } 6396b4cac81SBjoern A. Zeeb #endif 6406b4cac81SBjoern A. Zeeb 6416b4cac81SBjoern A. Zeeb static u_int 6426b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast_copy(void *arg, struct sockaddr_dl *sdl, u_int cnt) 6436b4cac81SBjoern A. Zeeb { 6446b4cac81SBjoern A. Zeeb struct netdev_hw_addr_list *mc_list; 6456b4cac81SBjoern A. Zeeb struct netdev_hw_addr *addr; 6466b4cac81SBjoern A. Zeeb 6476b4cac81SBjoern A. Zeeb KASSERT(arg != NULL && sdl != NULL, ("%s: arg %p sdl %p cnt %u\n", 6486b4cac81SBjoern A. Zeeb __func__, arg, sdl, cnt)); 6496b4cac81SBjoern A. Zeeb 6506b4cac81SBjoern A. Zeeb mc_list = arg; 6516b4cac81SBjoern A. Zeeb /* If it is on the list already skip it. */ 6526b4cac81SBjoern A. Zeeb netdev_hw_addr_list_for_each(addr, mc_list) { 6536b4cac81SBjoern A. Zeeb if (!memcmp(addr->addr, LLADDR(sdl), sdl->sdl_alen)) 6546b4cac81SBjoern A. Zeeb return (0); 6556b4cac81SBjoern A. Zeeb } 6566b4cac81SBjoern A. Zeeb 6576b4cac81SBjoern A. Zeeb addr = malloc(sizeof(*addr), M_LKPI80211, M_NOWAIT | M_ZERO); 6586b4cac81SBjoern A. Zeeb if (addr == NULL) 6596b4cac81SBjoern A. Zeeb return (0); 6606b4cac81SBjoern A. Zeeb 6616b4cac81SBjoern A. Zeeb INIT_LIST_HEAD(&addr->addr_list); 6626b4cac81SBjoern A. Zeeb memcpy(addr->addr, LLADDR(sdl), sdl->sdl_alen); 6636b4cac81SBjoern A. Zeeb /* XXX this should be a netdev function? */ 6646b4cac81SBjoern A. Zeeb list_add(&addr->addr_list, &mc_list->addr_list); 6656b4cac81SBjoern A. Zeeb mc_list->count++; 6666b4cac81SBjoern A. Zeeb 6679d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 6689d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 6696b4cac81SBjoern A. Zeeb printf("%s:%d: mc_list count %d: added %6D\n", 6706b4cac81SBjoern A. Zeeb __func__, __LINE__, mc_list->count, addr->addr, ":"); 6719d9ba2b7SBjoern A. Zeeb #endif 6726b4cac81SBjoern A. Zeeb 6736b4cac81SBjoern A. Zeeb return (1); 6746b4cac81SBjoern A. Zeeb } 6756b4cac81SBjoern A. Zeeb 6766b4cac81SBjoern A. Zeeb static void 6776b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(struct ieee80211com *ic, bool force) 6786b4cac81SBjoern A. Zeeb { 6796b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 6806b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 6816b4cac81SBjoern A. Zeeb struct netdev_hw_addr_list mc_list; 6826b4cac81SBjoern A. Zeeb struct list_head *le, *next; 6836b4cac81SBjoern A. Zeeb struct netdev_hw_addr *addr; 6846b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 6856b4cac81SBjoern A. Zeeb u64 mc; 6866b4cac81SBjoern A. Zeeb unsigned int changed_flags, total_flags; 6876b4cac81SBjoern A. Zeeb 6886b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 6896b4cac81SBjoern A. Zeeb 6906b4cac81SBjoern A. Zeeb if (lhw->ops->prepare_multicast == NULL || 6916b4cac81SBjoern A. Zeeb lhw->ops->configure_filter == NULL) 6926b4cac81SBjoern A. Zeeb return; 6936b4cac81SBjoern A. Zeeb 6946b4cac81SBjoern A. Zeeb if (!lhw->update_mc && !force) 6956b4cac81SBjoern A. Zeeb return; 6966b4cac81SBjoern A. Zeeb 6976b4cac81SBjoern A. Zeeb changed_flags = total_flags = 0; 6986b4cac81SBjoern A. Zeeb mc_list.count = 0; 6996b4cac81SBjoern A. Zeeb INIT_LIST_HEAD(&mc_list.addr_list); 7006b4cac81SBjoern A. Zeeb if (ic->ic_allmulti == 0) { 7016b4cac81SBjoern A. Zeeb TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) 7026b4cac81SBjoern A. Zeeb if_foreach_llmaddr(vap->iv_ifp, 7036b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast_copy, &mc_list); 7046b4cac81SBjoern A. Zeeb } else { 7056b4cac81SBjoern A. Zeeb changed_flags |= FIF_ALLMULTI; 7066b4cac81SBjoern A. Zeeb } 7076b4cac81SBjoern A. Zeeb 7086b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 7096b4cac81SBjoern A. Zeeb mc = lkpi_80211_mo_prepare_multicast(hw, &mc_list); 7106b4cac81SBjoern A. Zeeb /* 7116b4cac81SBjoern A. Zeeb * XXX-BZ make sure to get this sorted what is a change, 7126b4cac81SBjoern A. Zeeb * what gets all set; what was already set? 7136b4cac81SBjoern A. Zeeb */ 7146b4cac81SBjoern A. Zeeb total_flags = changed_flags; 7156b4cac81SBjoern A. Zeeb lkpi_80211_mo_configure_filter(hw, changed_flags, &total_flags, mc); 7166b4cac81SBjoern A. Zeeb 7179d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 7189d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 7196b4cac81SBjoern A. Zeeb printf("%s: changed_flags %#06x count %d total_flags %#010x\n", 7206b4cac81SBjoern A. Zeeb __func__, changed_flags, mc_list.count, total_flags); 7219d9ba2b7SBjoern A. Zeeb #endif 7226b4cac81SBjoern A. Zeeb 7236b4cac81SBjoern A. Zeeb if (mc_list.count != 0) { 7246b4cac81SBjoern A. Zeeb list_for_each_safe(le, next, &mc_list.addr_list) { 7256b4cac81SBjoern A. Zeeb addr = list_entry(le, struct netdev_hw_addr, addr_list); 7266b4cac81SBjoern A. Zeeb free(addr, M_LKPI80211); 7276b4cac81SBjoern A. Zeeb mc_list.count--; 7286b4cac81SBjoern A. Zeeb } 7296b4cac81SBjoern A. Zeeb } 7306b4cac81SBjoern A. Zeeb KASSERT(mc_list.count == 0, ("%s: mc_list %p count %d != 0\n", 7316b4cac81SBjoern A. Zeeb __func__, &mc_list, mc_list.count)); 7326b4cac81SBjoern A. Zeeb } 7336b4cac81SBjoern A. Zeeb 734fa8f007dSBjoern A. Zeeb static enum ieee80211_bss_changed 735fa8f007dSBjoern A. Zeeb lkpi_update_dtim_tsf(struct ieee80211_vif *vif, struct ieee80211_node *ni, 736fa8f007dSBjoern A. Zeeb struct ieee80211vap *vap, const char *_f, int _l) 737fa8f007dSBjoern A. Zeeb { 738fa8f007dSBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 739fa8f007dSBjoern A. Zeeb 740fa8f007dSBjoern A. Zeeb bss_changed = 0; 741fa8f007dSBjoern A. Zeeb 7429d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 7439d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 744fa8f007dSBjoern A. Zeeb printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u " 745fa8f007dSBjoern A. Zeeb "dtim_period %u sync_dtim_count %u sync_tsf %ju " 746fa8f007dSBjoern A. Zeeb "sync_device_ts %u bss_changed %#08x\n", 747fa8f007dSBjoern A. Zeeb __func__, __LINE__, _f, _l, 748fa8f007dSBjoern A. Zeeb vif->bss_conf.assoc, vif->bss_conf.aid, 749fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int, vif->bss_conf.dtim_period, 750fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count, 751fa8f007dSBjoern A. Zeeb (uintmax_t)vif->bss_conf.sync_tsf, 752fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_device_ts, 753fa8f007dSBjoern A. Zeeb bss_changed); 7549d9ba2b7SBjoern A. Zeeb #endif 755fa8f007dSBjoern A. Zeeb 756fa8f007dSBjoern A. Zeeb if (vif->bss_conf.beacon_int != ni->ni_intval) { 757fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int = ni->ni_intval; 758fa8f007dSBjoern A. Zeeb /* iwlwifi FW bug workaround; iwl_mvm_mac_sta_state. */ 759fa8f007dSBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16) 760fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int = 16; 761fa8f007dSBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INT; 762fa8f007dSBjoern A. Zeeb } 763fa8f007dSBjoern A. Zeeb if (vif->bss_conf.dtim_period != vap->iv_dtim_period && 764fa8f007dSBjoern A. Zeeb vap->iv_dtim_period > 0) { 765fa8f007dSBjoern A. Zeeb vif->bss_conf.dtim_period = vap->iv_dtim_period; 766fa8f007dSBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INFO; 767fa8f007dSBjoern A. Zeeb } 768fa8f007dSBjoern A. Zeeb 769fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count = vap->iv_dtim_count; 770fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_tsf = le64toh(ni->ni_tstamp.tsf); 771fa8f007dSBjoern A. Zeeb /* vif->bss_conf.sync_device_ts = set in linuxkpi_ieee80211_rx. */ 772fa8f007dSBjoern A. Zeeb 7739d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 7749d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 775fa8f007dSBjoern A. Zeeb printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u " 776fa8f007dSBjoern A. Zeeb "dtim_period %u sync_dtim_count %u sync_tsf %ju " 777fa8f007dSBjoern A. Zeeb "sync_device_ts %u bss_changed %#08x\n", 778fa8f007dSBjoern A. Zeeb __func__, __LINE__, _f, _l, 779fa8f007dSBjoern A. Zeeb vif->bss_conf.assoc, vif->bss_conf.aid, 780fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int, vif->bss_conf.dtim_period, 781fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count, 782fa8f007dSBjoern A. Zeeb (uintmax_t)vif->bss_conf.sync_tsf, 783fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_device_ts, 784fa8f007dSBjoern A. Zeeb bss_changed); 7859d9ba2b7SBjoern A. Zeeb #endif 786fa8f007dSBjoern A. Zeeb 787fa8f007dSBjoern A. Zeeb return (bss_changed); 788fa8f007dSBjoern A. Zeeb } 789fa8f007dSBjoern A. Zeeb 7906b4cac81SBjoern A. Zeeb static void 7916b4cac81SBjoern A. Zeeb lkpi_stop_hw_scan(struct lkpi_hw *lhw, struct ieee80211_vif *vif) 7926b4cac81SBjoern A. Zeeb { 7936b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 7946b4cac81SBjoern A. Zeeb int error; 795*8ac540d3SBjoern A. Zeeb bool cancel; 7966b4cac81SBjoern A. Zeeb 797*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 798*8ac540d3SBjoern A. Zeeb cancel = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0; 799*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 800*8ac540d3SBjoern A. Zeeb if (!cancel) 8016b4cac81SBjoern A. Zeeb return; 8026b4cac81SBjoern A. Zeeb 8036b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 8046b4cac81SBjoern A. Zeeb 805bec76628SBjoern A. Zeeb IEEE80211_UNLOCK(lhw->ic); 806bec76628SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 8076b4cac81SBjoern A. Zeeb /* Need to cancel the scan. */ 8086b4cac81SBjoern A. Zeeb lkpi_80211_mo_cancel_hw_scan(hw, vif); 809*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 8106b4cac81SBjoern A. Zeeb 8116b4cac81SBjoern A. Zeeb /* Need to make sure we see ieee80211_scan_completed. */ 812*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 813*8ac540d3SBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) 814*8ac540d3SBjoern A. Zeeb error = msleep(lhw, &lhw->scan_mtx, 0, "lhwscanstop", hz/2); 815*8ac540d3SBjoern A. Zeeb cancel = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0; 816*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 817*8ac540d3SBjoern A. Zeeb 818bec76628SBjoern A. Zeeb IEEE80211_LOCK(lhw->ic); 8196b4cac81SBjoern A. Zeeb 820*8ac540d3SBjoern A. Zeeb if (cancel) 8216b4cac81SBjoern A. Zeeb ic_printf(lhw->ic, "%s: failed to cancel scan: %d (%p, %p)\n", 8226b4cac81SBjoern A. Zeeb __func__, error, lhw, vif); 8236b4cac81SBjoern A. Zeeb } 8246b4cac81SBjoern A. Zeeb 8256b4cac81SBjoern A. Zeeb static void 826086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(struct ieee80211_hw *hw, bool new) 827086be6a8SBjoern A. Zeeb { 828086be6a8SBjoern A. Zeeb struct lkpi_hw *lhw; 829086be6a8SBjoern A. Zeeb int error; 830086be6a8SBjoern A. Zeeb bool old; 831086be6a8SBjoern A. Zeeb 832086be6a8SBjoern A. Zeeb old = hw->conf.flags & IEEE80211_CONF_IDLE; 833086be6a8SBjoern A. Zeeb if (old == new) 834086be6a8SBjoern A. Zeeb return; 835086be6a8SBjoern A. Zeeb 836086be6a8SBjoern A. Zeeb hw->conf.flags ^= IEEE80211_CONF_IDLE; 837086be6a8SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_IDLE); 838086be6a8SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) { 839086be6a8SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 840086be6a8SBjoern A. Zeeb ic_printf(lhw->ic, "ERROR: %s: config %#0x returned %d\n", 841086be6a8SBjoern A. Zeeb __func__, IEEE80211_CONF_CHANGE_IDLE, error); 842086be6a8SBjoern A. Zeeb } 843086be6a8SBjoern A. Zeeb } 844086be6a8SBjoern A. Zeeb 845086be6a8SBjoern A. Zeeb static void 8466b4cac81SBjoern A. Zeeb lkpi_disassoc(struct ieee80211_sta *sta, struct ieee80211_vif *vif, 8476b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw) 8486b4cac81SBjoern A. Zeeb { 8496b4cac81SBjoern A. Zeeb sta->aid = 0; 8506b4cac81SBjoern A. Zeeb if (vif->bss_conf.assoc) { 8516b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 8526b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 8536b4cac81SBjoern A. Zeeb 8546b4cac81SBjoern A. Zeeb lhw->update_mc = true; 8556b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(lhw->ic, true); 8566b4cac81SBjoern A. Zeeb 8576b4cac81SBjoern A. Zeeb changed = 0; 8586b4cac81SBjoern A. Zeeb vif->bss_conf.assoc = false; 8596b4cac81SBjoern A. Zeeb vif->bss_conf.aid = 0; 8606b4cac81SBjoern A. Zeeb changed |= BSS_CHANGED_ASSOC; 861d9f59799SBjoern A. Zeeb /* 862d9f59799SBjoern A. Zeeb * This will remove the sta from firmware for iwlwifi. 863d9f59799SBjoern A. Zeeb * So confusing that they use state and flags and ... ^%$%#%$^. 864d9f59799SBjoern A. Zeeb */ 8656b4cac81SBjoern A. Zeeb IMPROVE(); 8666b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 8676b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, 8686b4cac81SBjoern A. Zeeb changed); 869086be6a8SBjoern A. Zeeb 870086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true); 8716b4cac81SBjoern A. Zeeb } 8726b4cac81SBjoern A. Zeeb } 8736b4cac81SBjoern A. Zeeb 8746b4cac81SBjoern A. Zeeb static void 8756b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(struct ieee80211_hw *hw, struct ieee80211_sta *sta, 8766b4cac81SBjoern A. Zeeb bool dequeue_seen, bool no_emptyq) 8776b4cac81SBjoern A. Zeeb { 8786b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 8796b4cac81SBjoern A. Zeeb int tid; 8806b4cac81SBjoern A. Zeeb 8816b4cac81SBjoern A. Zeeb /* Wake up all queues to know they are allocated in the driver. */ 8826b4cac81SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 8836b4cac81SBjoern A. Zeeb 8846b4cac81SBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) { 8856b4cac81SBjoern A. Zeeb IMPROVE("station specific?"); 8866b4cac81SBjoern A. Zeeb if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ)) 8876b4cac81SBjoern A. Zeeb continue; 8886b4cac81SBjoern A. Zeeb } else if (tid >= hw->queues) 8896b4cac81SBjoern A. Zeeb continue; 8906b4cac81SBjoern A. Zeeb 8916b4cac81SBjoern A. Zeeb if (sta->txq[tid] == NULL) 8926b4cac81SBjoern A. Zeeb continue; 8936b4cac81SBjoern A. Zeeb 8946b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]); 8956b4cac81SBjoern A. Zeeb if (dequeue_seen && !ltxq->seen_dequeue) 8966b4cac81SBjoern A. Zeeb continue; 8976b4cac81SBjoern A. Zeeb 8986b4cac81SBjoern A. Zeeb if (no_emptyq && skb_queue_empty(<xq->skbq)) 8996b4cac81SBjoern A. Zeeb continue; 9006b4cac81SBjoern A. Zeeb 9016b4cac81SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, sta->txq[tid]); 9026b4cac81SBjoern A. Zeeb } 9036b4cac81SBjoern A. Zeeb } 9046b4cac81SBjoern A. Zeeb 9056b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 9066b4cac81SBjoern A. Zeeb 9076b4cac81SBjoern A. Zeeb static int 9086b4cac81SBjoern A. Zeeb lkpi_sta_state_do_nada(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 9096b4cac81SBjoern A. Zeeb { 9106b4cac81SBjoern A. Zeeb 9116b4cac81SBjoern A. Zeeb return (0); 9126b4cac81SBjoern A. Zeeb } 9136b4cac81SBjoern A. Zeeb 9146b4cac81SBjoern A. Zeeb /* lkpi_iv_newstate() handles the stop scan case generally. */ 9156b4cac81SBjoern A. Zeeb #define lkpi_sta_scan_to_init(_v, _n, _a) lkpi_sta_state_do_nada(_v, _n, _a) 9166b4cac81SBjoern A. Zeeb 9176b4cac81SBjoern A. Zeeb static int 9186b4cac81SBjoern A. Zeeb lkpi_sta_scan_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 9196b4cac81SBjoern A. Zeeb { 9206b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 9216b4cac81SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 9226b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 9236b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 9246b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 9256b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 9266b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 9276b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 9286b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 9296b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 9306b4cac81SBjoern A. Zeeb uint32_t changed; 9316b4cac81SBjoern A. Zeeb int error; 9326b4cac81SBjoern A. Zeeb 9336b4cac81SBjoern A. Zeeb chan = lkpi_get_lkpi80211_chan(vap->iv_ic, vap->iv_bss); 9346b4cac81SBjoern A. Zeeb if (chan == NULL) { 9356b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: failed to get channel\n", __func__); 9366b4cac81SBjoern A. Zeeb return (ESRCH); 9376b4cac81SBjoern A. Zeeb } 9386b4cac81SBjoern A. Zeeb 9396b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 9406b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 9416b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 9426b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 9436b4cac81SBjoern A. Zeeb 944d9f59799SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 945d9f59799SBjoern A. Zeeb 9466b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 947*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 9486b4cac81SBjoern A. Zeeb 9496b4cac81SBjoern A. Zeeb /* Add chanctx (or if exists, change it). */ 9506b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 9516b4cac81SBjoern A. Zeeb conf = vif->chanctx_conf; 9526b4cac81SBjoern A. Zeeb IMPROVE("diff changes for changed, working on live copy, rcu"); 9536b4cac81SBjoern A. Zeeb } else { 9546b4cac81SBjoern A. Zeeb /* Keep separate alloc as in Linux this is rcu managed? */ 9556b4cac81SBjoern A. Zeeb conf = malloc(sizeof(*conf) + hw->chanctx_data_size, 9566b4cac81SBjoern A. Zeeb M_LKPI80211, M_WAITOK | M_ZERO); 9576b4cac81SBjoern A. Zeeb } 9586b4cac81SBjoern A. Zeeb 9596b4cac81SBjoern A. Zeeb conf->rx_chains_dynamic = 1; 9606b4cac81SBjoern A. Zeeb conf->rx_chains_static = 1; 9616b4cac81SBjoern A. Zeeb conf->radar_enabled = 9626b4cac81SBjoern A. Zeeb (chan->flags & IEEE80211_CHAN_RADAR) ? true : false; 9636b4cac81SBjoern A. Zeeb conf->def.chan = chan; 9646b4cac81SBjoern A. Zeeb conf->def.width = NL80211_CHAN_WIDTH_20_NOHT; 9656b4cac81SBjoern A. Zeeb conf->def.center_freq1 = chan->center_freq; 9666b4cac81SBjoern A. Zeeb conf->def.center_freq2 = 0; 9676b4cac81SBjoern A. Zeeb /* Responder ... */ 9686b4cac81SBjoern A. Zeeb conf->min_def.chan = chan; 9696b4cac81SBjoern A. Zeeb conf->min_def.width = NL80211_CHAN_WIDTH_20_NOHT; 9706b4cac81SBjoern A. Zeeb conf->min_def.center_freq1 = chan->center_freq; 9716b4cac81SBjoern A. Zeeb conf->min_def.center_freq2 = 0; 9726b4cac81SBjoern A. Zeeb IMPROVE("currently 20_NOHT only"); 9736b4cac81SBjoern A. Zeeb 9746b4cac81SBjoern A. Zeeb error = 0; 9756b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 9766b4cac81SBjoern A. Zeeb changed = IEEE80211_CHANCTX_CHANGE_MIN_WIDTH; 9776b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_RADAR; 9786b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_RX_CHAINS; 9796b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_WIDTH; 9806b4cac81SBjoern A. Zeeb lkpi_80211_mo_change_chanctx(hw, conf, changed); 9816b4cac81SBjoern A. Zeeb } else { 9826b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_add_chanctx(hw, conf); 9836b4cac81SBjoern A. Zeeb if (error == 0 || error == EOPNOTSUPP) { 9846b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.chan = conf->def.chan; 9856b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.width = conf->def.width; 9866b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.center_freq1 = 9876b4cac81SBjoern A. Zeeb conf->def.center_freq1; 9886b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.center_freq2 = 9896b4cac81SBjoern A. Zeeb conf->def.center_freq2; 9906b4cac81SBjoern A. Zeeb } else { 9916b4cac81SBjoern A. Zeeb goto out; 9926b4cac81SBjoern A. Zeeb } 9936b4cac81SBjoern A. Zeeb /* Assign vif chanctx. */ 9946b4cac81SBjoern A. Zeeb if (error == 0) 9956b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_assign_vif_chanctx(hw, vif, conf); 9966b4cac81SBjoern A. Zeeb if (error == EOPNOTSUPP) 9976b4cac81SBjoern A. Zeeb error = 0; 9986b4cac81SBjoern A. Zeeb if (error != 0) { 9996b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 10006b4cac81SBjoern A. Zeeb free(conf, M_LKPI80211); 10016b4cac81SBjoern A. Zeeb goto out; 10026b4cac81SBjoern A. Zeeb } 10036b4cac81SBjoern A. Zeeb } 10046b4cac81SBjoern A. Zeeb IMPROVE("update radiotap chan fields too"); 10056b4cac81SBjoern A. Zeeb 10066b4cac81SBjoern A. Zeeb /* Set bss info (bss_info_changed). */ 10076b4cac81SBjoern A. Zeeb bss_changed = 0; 1008caaa79c3SBjoern A. Zeeb vif->bss_conf.bssid = ni->ni_bssid; 10096b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 10106b4cac81SBjoern A. Zeeb vif->bss_conf.txpower = ni->ni_txpower; 10116b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_TXPOWER; 10126b4cac81SBjoern A. Zeeb vif->bss_conf.idle = false; 10136b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_IDLE; 1014c8dafefaSBjoern A. Zeeb 10156b4cac81SBjoern A. Zeeb /* Should almost assert it is this. */ 10166b4cac81SBjoern A. Zeeb vif->bss_conf.assoc = false; 10176b4cac81SBjoern A. Zeeb vif->bss_conf.aid = 0; 1018fa8f007dSBjoern A. Zeeb 1019fa8f007dSBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 1020fa8f007dSBjoern A. Zeeb 10216b4cac81SBjoern A. Zeeb /* RATES */ 10226b4cac81SBjoern A. Zeeb IMPROVE("bss info: not all needs to come now and rates are missing"); 10236b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 10246b4cac81SBjoern A. Zeeb 1025d9f59799SBjoern A. Zeeb /* 1026d9f59799SBjoern A. Zeeb * This is a bandaid for now. If we went through (*iv_update_bss)() 1027d9f59799SBjoern A. Zeeb * and then removed the lsta we end up here without a lsta and have 1028d9f59799SBjoern A. Zeeb * to manually allocate and link it in as lkpi_ic_node_alloc()/init() 1029d9f59799SBjoern A. Zeeb * would normally do. 1030d9f59799SBjoern A. Zeeb * XXX-BZ I do not like this but currently we have no good way of 1031d9f59799SBjoern A. Zeeb * intercepting the bss swap and state changes and packets going out 1032d9f59799SBjoern A. Zeeb * workflow so live with this. It is a compat layer after all. 1033d9f59799SBjoern A. Zeeb */ 1034d9f59799SBjoern A. Zeeb if (ni->ni_drv_data == NULL) { 1035d9f59799SBjoern A. Zeeb lsta = lkpi_lsta_alloc(vap, ni->ni_macaddr, hw, ni); 1036d9f59799SBjoern A. Zeeb if (lsta == NULL) { 1037d9f59799SBjoern A. Zeeb error = ENOMEM; 1038d9f59799SBjoern A. Zeeb goto out; 1039d9f59799SBjoern A. Zeeb } 1040d9f59799SBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 1041d9f59799SBjoern A. Zeeb } else { 10426b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 1043d9f59799SBjoern A. Zeeb } 1044e24e8103SBjoern A. Zeeb 1045e24e8103SBjoern A. Zeeb /* Insert the [l]sta into the list of known stations. */ 1046e24e8103SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 1047e24e8103SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lvif->lsta_head, lsta, lsta_entry); 1048e24e8103SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 1049e24e8103SBjoern A. Zeeb 1050d9f59799SBjoern A. Zeeb /* Add (or adjust) sta and change state (from NOTEXIST) to NONE. */ 10516b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 10526b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NOTEXIST, ("%s: lsta %p state not " 10536b4cac81SBjoern A. Zeeb "NOTEXIST: %#x\n", __func__, lsta, lsta->state)); 1054e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE); 10556b4cac81SBjoern A. Zeeb if (error != 0) { 10566b4cac81SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 10576b4cac81SBjoern A. Zeeb goto out; 10586b4cac81SBjoern A. Zeeb } 10596b4cac81SBjoern A. Zeeb #if 0 10606b4cac81SBjoern A. Zeeb lsta->added_to_drv = true; /* mo manages. */ 10616b4cac81SBjoern A. Zeeb #endif 10626b4cac81SBjoern A. Zeeb 10639d9ba2b7SBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 10649d9ba2b7SBjoern A. Zeeb 10656b4cac81SBjoern A. Zeeb /* 10666b4cac81SBjoern A. Zeeb * Wakeup all queues now that sta is there so we have as much time to 10676b4cac81SBjoern A. Zeeb * possibly prepare the queue in the driver to be ready for the 1st 10686b4cac81SBjoern A. Zeeb * packet; lkpi_80211_txq_tx_one() still has a workaround as there 10696b4cac81SBjoern A. Zeeb * is no guarantee or way to check. 1070d9f59799SBjoern A. Zeeb * XXX-BZ and by now we know that this does not work on all drivers 1071d9f59799SBjoern A. Zeeb * for all queues. 10726b4cac81SBjoern A. Zeeb */ 1073e7fe0373SBjoern A. Zeeb lkpi_wake_tx_queues(hw, LSTA_TO_STA(lsta), false, false); 10746b4cac81SBjoern A. Zeeb 10756b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 10766b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 10776b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 10786b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 10796b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 10806b4cac81SBjoern A. Zeeb 10816b4cac81SBjoern A. Zeeb /* 10826b4cac81SBjoern A. Zeeb * What is going to happen next: 10836b4cac81SBjoern A. Zeeb * - <twiddle> .. we should end up in "auth_to_assoc" 10846b4cac81SBjoern A. Zeeb * - event_callback 10856b4cac81SBjoern A. Zeeb * - update sta_state (NONE to AUTH) 10866b4cac81SBjoern A. Zeeb * - mgd_complete_tx 10876b4cac81SBjoern A. Zeeb * (ideally we'd do that on a callback for something else ...) 10886b4cac81SBjoern A. Zeeb */ 10896b4cac81SBjoern A. Zeeb 10906b4cac81SBjoern A. Zeeb out: 1091*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 10926b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 10936b4cac81SBjoern A. Zeeb if (ni != NULL) 10946b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 10956b4cac81SBjoern A. Zeeb return (error); 10966b4cac81SBjoern A. Zeeb } 10976b4cac81SBjoern A. Zeeb 10986b4cac81SBjoern A. Zeeb static int 10996b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 11006b4cac81SBjoern A. Zeeb { 11016b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 11026b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 11036b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 11046b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 11056b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 11066b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 11076b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 11086b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 11096b4cac81SBjoern A. Zeeb int error; 11106b4cac81SBjoern A. Zeeb 11116b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 11126b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 11136b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 11146b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 11156b4cac81SBjoern A. Zeeb 11166b4cac81SBjoern A. Zeeb /* Keep ni around. */ 11176b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 11186b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 11196b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 11206b4cac81SBjoern A. Zeeb 112167674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 11226b4cac81SBjoern A. Zeeb 11236b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 1124*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 11256b4cac81SBjoern A. Zeeb 1126d9f59799SBjoern A. Zeeb /* flush, drop. */ 1127d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1128d9f59799SBjoern A. Zeeb 11296b4cac81SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 11306b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 11316b4cac81SBjoern A. Zeeb 11326b4cac81SBjoern A. Zeeb /* flush, no drop */ 11336b4cac81SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 11346b4cac81SBjoern A. Zeeb 11356b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 11366b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 11376b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 11386b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 11396b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 11406b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 11416b4cac81SBjoern A. Zeeb } 11426b4cac81SBjoern A. Zeeb 11436b4cac81SBjoern A. Zeeb /* sync_rx_queues */ 11446b4cac81SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 11456b4cac81SBjoern A. Zeeb 11466b4cac81SBjoern A. Zeeb /* sta_pre_rcu_remove */ 11476b4cac81SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 1148d9f59799SBjoern A. Zeeb 1149d9f59799SBjoern A. Zeeb /* Take the station down. */ 11506b4cac81SBjoern A. Zeeb 11516b4cac81SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 11526b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 11536b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 1154d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg)); 1155e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST); 11566b4cac81SBjoern A. Zeeb if (error != 0) { 11576b4cac81SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 11586b4cac81SBjoern A. Zeeb goto out; 11596b4cac81SBjoern A. Zeeb } 11606b4cac81SBjoern A. Zeeb #if 0 11616b4cac81SBjoern A. Zeeb lsta->added_to_drv = false; /* mo manages. */ 11626b4cac81SBjoern A. Zeeb #endif 11636b4cac81SBjoern A. Zeeb 116467674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 11656b4cac81SBjoern A. Zeeb 1166d9f59799SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif); 1167d9f59799SBjoern A. Zeeb 1168d9f59799SBjoern A. Zeeb /* conf_tx */ 1169d9f59799SBjoern A. Zeeb 1170d9f59799SBjoern A. Zeeb /* Take the chan ctx down. */ 11716b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 11726b4cac81SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 11736b4cac81SBjoern A. Zeeb 11746b4cac81SBjoern A. Zeeb conf = vif->chanctx_conf; 11756b4cac81SBjoern A. Zeeb /* Remove vif context. */ 11766b4cac81SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->chanctx_conf); 11776b4cac81SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 11786b4cac81SBjoern A. Zeeb 11796b4cac81SBjoern A. Zeeb /* Remove chan ctx. */ 11806b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 11816b4cac81SBjoern A. Zeeb free(conf, M_LKPI80211); 11826b4cac81SBjoern A. Zeeb } 11836b4cac81SBjoern A. Zeeb 11846b4cac81SBjoern A. Zeeb out: 1185*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 11866b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 11876b4cac81SBjoern A. Zeeb if (ni != NULL) 11886b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 11896b4cac81SBjoern A. Zeeb return (error); 11906b4cac81SBjoern A. Zeeb } 11916b4cac81SBjoern A. Zeeb 11926b4cac81SBjoern A. Zeeb static int 11936b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 11946b4cac81SBjoern A. Zeeb { 11956b4cac81SBjoern A. Zeeb int error; 11966b4cac81SBjoern A. Zeeb 11976b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_scan(vap, nstate, arg); 11986b4cac81SBjoern A. Zeeb if (error == 0) 11996b4cac81SBjoern A. Zeeb error = lkpi_sta_scan_to_init(vap, nstate, arg); 12006b4cac81SBjoern A. Zeeb return (error); 12016b4cac81SBjoern A. Zeeb } 12026b4cac81SBjoern A. Zeeb 12036b4cac81SBjoern A. Zeeb static int 12046b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 12056b4cac81SBjoern A. Zeeb { 12066b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 12076b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 12086b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 12096b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 12106b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 12116b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 12126b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 12136b4cac81SBjoern A. Zeeb int error; 12146b4cac81SBjoern A. Zeeb 12156b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 12166b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 12176b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 12186b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 12196b4cac81SBjoern A. Zeeb 12206b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 1221*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 12226b4cac81SBjoern A. Zeeb ni = NULL; 12236b4cac81SBjoern A. Zeeb 12246b4cac81SBjoern A. Zeeb /* Finish auth. */ 12256b4cac81SBjoern A. Zeeb IMPROVE("event callback"); 12266b4cac81SBjoern A. Zeeb 12276b4cac81SBjoern A. Zeeb /* Update sta_state (NONE to AUTH). */ 12286b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 12296b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 12306b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 12316b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 12326b4cac81SBjoern A. Zeeb "NONE: %#x\n", __func__, lsta, lsta->state)); 1233e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH); 12346b4cac81SBjoern A. Zeeb if (error != 0) 12356b4cac81SBjoern A. Zeeb goto out; 12366b4cac81SBjoern A. Zeeb 12376b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 12386b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 12396b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 12406b4cac81SBjoern A. Zeeb prep_tx_info.success = true; 12416b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 12426b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 12436b4cac81SBjoern A. Zeeb } 12446b4cac81SBjoern A. Zeeb 12456b4cac81SBjoern A. Zeeb /* Now start assoc. */ 12466b4cac81SBjoern A. Zeeb 12476b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 12486b4cac81SBjoern A. Zeeb if (!lsta->in_mgd) { 12496b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 12506b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 12516b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 12526b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 12536b4cac81SBjoern A. Zeeb } 12546b4cac81SBjoern A. Zeeb 12556b4cac81SBjoern A. Zeeb /* Wake tx queue to get packet out. */ 1256e7fe0373SBjoern A. Zeeb lkpi_wake_tx_queues(hw, LSTA_TO_STA(lsta), true, true); 12576b4cac81SBjoern A. Zeeb 12586b4cac81SBjoern A. Zeeb /* 12596b4cac81SBjoern A. Zeeb * <twiddle> .. we end up in "assoc_to_run" 12606b4cac81SBjoern A. Zeeb * - update sta_state (AUTH to ASSOC) 12616b4cac81SBjoern A. Zeeb * - conf_tx [all] 12626b4cac81SBjoern A. Zeeb * - bss_info_changed (assoc, aid, ssid, ..) 12636b4cac81SBjoern A. Zeeb * - change_chanctx (if needed) 12646b4cac81SBjoern A. Zeeb * - event_callback 12656b4cac81SBjoern A. Zeeb * - mgd_complete_tx 12666b4cac81SBjoern A. Zeeb */ 12676b4cac81SBjoern A. Zeeb 12686b4cac81SBjoern A. Zeeb out: 1269*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 12706b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 12716b4cac81SBjoern A. Zeeb if (ni != NULL) 12726b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 12736b4cac81SBjoern A. Zeeb return (error); 12746b4cac81SBjoern A. Zeeb } 12756b4cac81SBjoern A. Zeeb 12766b4cac81SBjoern A. Zeeb /* auth_to_auth, assoc_to_assoc. */ 12776b4cac81SBjoern A. Zeeb static int 12786b4cac81SBjoern A. Zeeb lkpi_sta_a_to_a(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 12796b4cac81SBjoern A. Zeeb { 12806b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 12816b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 12826b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 12836b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 12846b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 12856b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 12866b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 12876b4cac81SBjoern A. Zeeb 12886b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 12896b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 12906b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 12916b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 12926b4cac81SBjoern A. Zeeb 12936b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 12946b4cac81SBjoern A. Zeeb 12956b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 1296*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 12976b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 12986b4cac81SBjoern A. Zeeb 12996b4cac81SBjoern A. Zeeb IMPROVE("event callback?"); 13006b4cac81SBjoern A. Zeeb 13016b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 13026b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 13036b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 13046b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 13056b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 13066b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 13076b4cac81SBjoern A. Zeeb } 13086b4cac81SBjoern A. Zeeb 13096b4cac81SBjoern A. Zeeb /* Now start assoc. */ 13106b4cac81SBjoern A. Zeeb 13116b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 13126b4cac81SBjoern A. Zeeb if (!lsta->in_mgd) { 13136b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 13146b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 13156b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 13166b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 13176b4cac81SBjoern A. Zeeb } 13186b4cac81SBjoern A. Zeeb 1319*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 13206b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 13216b4cac81SBjoern A. Zeeb if (ni != NULL) 13226b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 13236b4cac81SBjoern A. Zeeb 13246b4cac81SBjoern A. Zeeb return (0); 13256b4cac81SBjoern A. Zeeb } 13266b4cac81SBjoern A. Zeeb 13276b4cac81SBjoern A. Zeeb static int 1328d9f59799SBjoern A. Zeeb _lkpi_sta_assoc_to_down(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 13296b4cac81SBjoern A. Zeeb { 13306b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 13316b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 13326b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 13336b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 13346b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 13356b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 13366b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 13376b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 1338d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 13396b4cac81SBjoern A. Zeeb int error; 13406b4cac81SBjoern A. Zeeb 13416b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 13426b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 13436b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 13446b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 13456b4cac81SBjoern A. Zeeb 13466b4cac81SBjoern A. Zeeb /* Keep ni around. */ 13476b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 13486b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 13496b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 13506b4cac81SBjoern A. Zeeb 135167674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1352d9f59799SBjoern A. Zeeb 1353d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 1354*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1355d9f59799SBjoern A. Zeeb 1356d9f59799SBjoern A. Zeeb /* flush, drop. */ 1357d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1358d9f59799SBjoern A. Zeeb 1359d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?"); 1360d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) && 1361d9f59799SBjoern A. Zeeb !lsta->in_mgd) { 1362d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1363d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 1364d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 1365d9f59799SBjoern A. Zeeb lsta->in_mgd = true; 1366d9f59799SBjoern A. Zeeb } 1367d9f59799SBjoern A. Zeeb 1368*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 1369d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1370d9f59799SBjoern A. Zeeb 1371d9f59799SBjoern A. Zeeb /* Call iv_newstate first so we get potential DISASSOC packet out. */ 1372d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 1373d9f59799SBjoern A. Zeeb if (error != 0) 1374d9f59799SBjoern A. Zeeb goto outni; 1375d9f59799SBjoern A. Zeeb 1376d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 1377*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1378d9f59799SBjoern A. Zeeb 137967674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1380d9f59799SBjoern A. Zeeb 1381d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 1382d9f59799SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 1383d9f59799SBjoern A. Zeeb 1384d9f59799SBjoern A. Zeeb /* flush, no drop */ 1385d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 1386d9f59799SBjoern A. Zeeb 13876b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 13886b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 13896b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 13906b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 13916b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 13926b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 13936b4cac81SBjoern A. Zeeb } 13946b4cac81SBjoern A. Zeeb 1395d9f59799SBjoern A. Zeeb /* sync_rx_queues */ 1396d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 1397d9f59799SBjoern A. Zeeb 1398d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */ 1399d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 1400d9f59799SBjoern A. Zeeb 1401d9f59799SBjoern A. Zeeb /* Take the station down. */ 1402d9f59799SBjoern A. Zeeb 14036b4cac81SBjoern A. Zeeb /* Update sta and change state (from AUTH) to NONE. */ 14046b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 14056b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 14066b4cac81SBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 1407e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE); 14086b4cac81SBjoern A. Zeeb if (error != 0) 14096b4cac81SBjoern A. Zeeb goto out; 14106b4cac81SBjoern A. Zeeb 141167674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 14126b4cac81SBjoern A. Zeeb 1413d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 1414d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 1415d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 1416d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg)); 1417e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST); 1418d9f59799SBjoern A. Zeeb if (error != 0) { 1419d9f59799SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 1420d9f59799SBjoern A. Zeeb goto out; 1421d9f59799SBjoern A. Zeeb } 1422d9f59799SBjoern A. Zeeb #if 0 1423d9f59799SBjoern A. Zeeb lsta->added_to_drv = false; /* mo manages. */ 1424d9f59799SBjoern A. Zeeb #endif 1425d9f59799SBjoern A. Zeeb 142667674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1427d9f59799SBjoern A. Zeeb 1428d9f59799SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 1429d9f59799SBjoern A. Zeeb /* We need to do this now, can only do after sta is IEEE80211_STA_NOTEXIST. */ 1430d9f59799SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw); 1431d9f59799SBjoern A. Zeeb 1432d9f59799SBjoern A. Zeeb IMPROVE("Any bss_info changes to announce?"); 1433d9f59799SBjoern A. Zeeb bss_changed = 0; 1434d9f59799SBjoern A. Zeeb vif->bss_conf.qos = 0; 1435d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 1436d9f59799SBjoern A. Zeeb vif->bss_conf.ssid_len = 0; 1437d9f59799SBjoern A. Zeeb memset(vif->bss_conf.ssid, '\0', sizeof(vif->bss_conf.ssid)); 1438d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 1439d9f59799SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 1440d9f59799SBjoern A. Zeeb 1441d9f59799SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif); 1442d9f59799SBjoern A. Zeeb 1443d9f59799SBjoern A. Zeeb /* conf_tx */ 1444d9f59799SBjoern A. Zeeb 1445d9f59799SBjoern A. Zeeb /* Take the chan ctx down. */ 1446d9f59799SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 1447d9f59799SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 1448d9f59799SBjoern A. Zeeb 1449d9f59799SBjoern A. Zeeb conf = vif->chanctx_conf; 1450d9f59799SBjoern A. Zeeb /* Remove vif context. */ 1451d9f59799SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->chanctx_conf); 1452d9f59799SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 1453d9f59799SBjoern A. Zeeb 1454d9f59799SBjoern A. Zeeb /* Remove chan ctx. */ 1455d9f59799SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 1456d9f59799SBjoern A. Zeeb free(conf, M_LKPI80211); 1457d9f59799SBjoern A. Zeeb } 1458d9f59799SBjoern A. Zeeb 1459d9f59799SBjoern A. Zeeb error = EALREADY; 14606b4cac81SBjoern A. Zeeb out: 1461*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 14626b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1463d9f59799SBjoern A. Zeeb outni: 14646b4cac81SBjoern A. Zeeb if (ni != NULL) 14656b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 14666b4cac81SBjoern A. Zeeb return (error); 14676b4cac81SBjoern A. Zeeb } 14686b4cac81SBjoern A. Zeeb 14696b4cac81SBjoern A. Zeeb static int 1470d9f59799SBjoern A. Zeeb lkpi_sta_assoc_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 1471d9f59799SBjoern A. Zeeb { 1472d9f59799SBjoern A. Zeeb int error; 1473d9f59799SBjoern A. Zeeb 1474d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg); 1475d9f59799SBjoern A. Zeeb if (error != 0 && error != EALREADY) 1476d9f59799SBjoern A. Zeeb return (error); 1477d9f59799SBjoern A. Zeeb 1478d9f59799SBjoern A. Zeeb /* At this point iv_bss is long a new node! */ 1479d9f59799SBjoern A. Zeeb 1480d9f59799SBjoern A. Zeeb error |= lkpi_sta_scan_to_auth(vap, nstate, 0); 1481d9f59799SBjoern A. Zeeb return (error); 1482d9f59799SBjoern A. Zeeb } 1483d9f59799SBjoern A. Zeeb 1484d9f59799SBjoern A. Zeeb static int 14856b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 14866b4cac81SBjoern A. Zeeb { 14876b4cac81SBjoern A. Zeeb int error; 14886b4cac81SBjoern A. Zeeb 1489d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg); 14906b4cac81SBjoern A. Zeeb return (error); 14916b4cac81SBjoern A. Zeeb } 14926b4cac81SBjoern A. Zeeb 14936b4cac81SBjoern A. Zeeb static int 14946b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 14956b4cac81SBjoern A. Zeeb { 14966b4cac81SBjoern A. Zeeb int error; 14976b4cac81SBjoern A. Zeeb 1498d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg); 14996b4cac81SBjoern A. Zeeb return (error); 15006b4cac81SBjoern A. Zeeb } 15016b4cac81SBjoern A. Zeeb 15026b4cac81SBjoern A. Zeeb static int 15036b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 15046b4cac81SBjoern A. Zeeb { 15056b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 15066b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 15076b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 15086b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 15096b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 15106b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 15116b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 15126b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 15136b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 15146b4cac81SBjoern A. Zeeb int error; 15156b4cac81SBjoern A. Zeeb 15166b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 15176b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 15186b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 15196b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 15206b4cac81SBjoern A. Zeeb 15216b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 1522*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 15239597f7cbSBjoern A. Zeeb ni = NULL; 15246b4cac81SBjoern A. Zeeb 15256b4cac81SBjoern A. Zeeb IMPROVE("ponder some of this moved to ic_newassoc, scan_assoc_success, " 15266b4cac81SBjoern A. Zeeb "and to lesser extend ieee80211_notify_node_join"); 15276b4cac81SBjoern A. Zeeb 15289597f7cbSBjoern A. Zeeb /* Finish assoc. */ 15299597f7cbSBjoern A. Zeeb /* Update sta_state (AUTH to ASSOC) and set aid. */ 15306b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 15316b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 15326b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 15339597f7cbSBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 15349597f7cbSBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 15356b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 15369597f7cbSBjoern A. Zeeb sta->aid = IEEE80211_NODE_AID(ni); 15374a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 15384a67f1dfSBjoern A. Zeeb if (vap->iv_flags & IEEE80211_F_WME) 15394a67f1dfSBjoern A. Zeeb sta->wme = true; 15404a67f1dfSBjoern A. Zeeb #endif 1541e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC); 15429597f7cbSBjoern A. Zeeb if (error != 0) 15439597f7cbSBjoern A. Zeeb goto out; 15446b4cac81SBjoern A. Zeeb 15456b4cac81SBjoern A. Zeeb IMPROVE("wme / conf_tx [all]"); 15466b4cac81SBjoern A. Zeeb 15476b4cac81SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 15486b4cac81SBjoern A. Zeeb bss_changed = 0; 15494a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 15504a67f1dfSBjoern A. Zeeb bss_changed |= lkpi_wme_update(lhw, vap, true); 15514a67f1dfSBjoern A. Zeeb #endif 15526b4cac81SBjoern A. Zeeb if (!vif->bss_conf.assoc || vif->bss_conf.aid != IEEE80211_NODE_AID(ni)) { 15536b4cac81SBjoern A. Zeeb vif->bss_conf.assoc = true; 15546b4cac81SBjoern A. Zeeb vif->bss_conf.aid = IEEE80211_NODE_AID(ni); 15556b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_ASSOC; 15566b4cac81SBjoern A. Zeeb } 15576b4cac81SBjoern A. Zeeb /* We set SSID but this is not BSSID! */ 15586b4cac81SBjoern A. Zeeb vif->bss_conf.ssid_len = ni->ni_esslen; 15596b4cac81SBjoern A. Zeeb memcpy(vif->bss_conf.ssid, ni->ni_essid, ni->ni_esslen); 15606b4cac81SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_SHPREAMBLE) != 15616b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble) { 15626b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble ^= 1; 15636b4cac81SBjoern A. Zeeb /* bss_changed |= BSS_CHANGED_??? */ 15646b4cac81SBjoern A. Zeeb } 15656b4cac81SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_SHSLOT) != 15666b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot) { 15676b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot ^= 1; 15686b4cac81SBjoern A. Zeeb /* bss_changed |= BSS_CHANGED_??? */ 15696b4cac81SBjoern A. Zeeb } 15706b4cac81SBjoern A. Zeeb if ((ni->ni_flags & IEEE80211_NODE_QOS) != 15716b4cac81SBjoern A. Zeeb vif->bss_conf.qos) { 15726b4cac81SBjoern A. Zeeb vif->bss_conf.qos ^= 1; 15736b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 15746b4cac81SBjoern A. Zeeb } 1575fa8f007dSBjoern A. Zeeb 1576fa8f007dSBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 1577fa8f007dSBjoern A. Zeeb 15786b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 15796b4cac81SBjoern A. Zeeb 15806b4cac81SBjoern A. Zeeb /* - change_chanctx (if needed) 15816b4cac81SBjoern A. Zeeb * - event_callback 15826b4cac81SBjoern A. Zeeb */ 15836b4cac81SBjoern A. Zeeb 15846b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 15856b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 15866b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 15876b4cac81SBjoern A. Zeeb prep_tx_info.success = true; 15886b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 15896b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 15906b4cac81SBjoern A. Zeeb } 15916b4cac81SBjoern A. Zeeb 1592086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, false); 1593086be6a8SBjoern A. Zeeb 15946b4cac81SBjoern A. Zeeb /* 15956b4cac81SBjoern A. Zeeb * And then: 15966b4cac81SBjoern A. Zeeb * - (more packets)? 15976b4cac81SBjoern A. Zeeb * - set_key 15986b4cac81SBjoern A. Zeeb * - set_default_unicast_key 15996b4cac81SBjoern A. Zeeb * - set_key (?) 16006b4cac81SBjoern A. Zeeb * - ipv6_addr_change (?) 16016b4cac81SBjoern A. Zeeb */ 16026b4cac81SBjoern A. Zeeb /* Prepare_multicast && configure_filter. */ 16036b4cac81SBjoern A. Zeeb lhw->update_mc = true; 16046b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(vap->iv_ic, true); 16056b4cac81SBjoern A. Zeeb 16066b4cac81SBjoern A. Zeeb if (!ieee80211_node_is_authorized(ni)) { 16076b4cac81SBjoern A. Zeeb IMPROVE("net80211 does not consider node authorized"); 16086b4cac81SBjoern A. Zeeb } 16096b4cac81SBjoern A. Zeeb 16106b4cac81SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTHORIZED). */ 16116b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 16126b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 16136b4cac81SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 1614e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTHORIZED); 16156b4cac81SBjoern A. Zeeb if (error != 0) { 16166b4cac81SBjoern A. Zeeb IMPROVE("undo some changes?"); 16176b4cac81SBjoern A. Zeeb goto out; 16186b4cac81SBjoern A. Zeeb } 16196b4cac81SBjoern A. Zeeb 16206b4cac81SBjoern A. Zeeb /* - drv_config (?) 16216b4cac81SBjoern A. Zeeb * - bss_info_changed 16226b4cac81SBjoern A. Zeeb * - set_rekey_data (?) 16236b4cac81SBjoern A. Zeeb * 16246b4cac81SBjoern A. Zeeb * And now we should be passing packets. 16256b4cac81SBjoern A. Zeeb */ 16266b4cac81SBjoern A. Zeeb IMPROVE("Need that bssid setting, and the keys"); 16276b4cac81SBjoern A. Zeeb 1628fa8f007dSBjoern A. Zeeb bss_changed = 0; 1629fa8f007dSBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 1630fa8f007dSBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 1631fa8f007dSBjoern A. Zeeb 16326b4cac81SBjoern A. Zeeb out: 1633*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 16346b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 16356b4cac81SBjoern A. Zeeb if (ni != NULL) 16366b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 16376b4cac81SBjoern A. Zeeb return (error); 16386b4cac81SBjoern A. Zeeb } 16396b4cac81SBjoern A. Zeeb 16406b4cac81SBjoern A. Zeeb static int 16416b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 16426b4cac81SBjoern A. Zeeb { 16436b4cac81SBjoern A. Zeeb int error; 16446b4cac81SBjoern A. Zeeb 16456b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_assoc(vap, nstate, arg); 16466b4cac81SBjoern A. Zeeb if (error == 0) 16476b4cac81SBjoern A. Zeeb error = lkpi_sta_assoc_to_run(vap, nstate, arg); 16486b4cac81SBjoern A. Zeeb return (error); 16496b4cac81SBjoern A. Zeeb } 16506b4cac81SBjoern A. Zeeb 16516b4cac81SBjoern A. Zeeb static int 16526b4cac81SBjoern A. Zeeb lkpi_sta_run_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 16536b4cac81SBjoern A. Zeeb { 16546b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 16556b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 16566b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 16576b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 16586b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 16596b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 16606b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 1661d9f59799SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 1662d9f59799SBjoern A. Zeeb #if 0 1663d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 1664d9f59799SBjoern A. Zeeb #endif 16656b4cac81SBjoern A. Zeeb int error; 16666b4cac81SBjoern A. Zeeb 16676b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 16686b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 16696b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 16706b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 16716b4cac81SBjoern A. Zeeb 16726b4cac81SBjoern A. Zeeb /* Keep ni around. */ 16736b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 16746b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 16756b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 16766b4cac81SBjoern A. Zeeb 167767674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1678d9f59799SBjoern A. Zeeb 1679d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 1680*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1681d9f59799SBjoern A. Zeeb 1682d9f59799SBjoern A. Zeeb /* flush, drop. */ 1683d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1684d9f59799SBjoern A. Zeeb 1685d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?"); 1686d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) && 1687d9f59799SBjoern A. Zeeb !lsta->in_mgd) { 1688d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1689d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 1690d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 1691d9f59799SBjoern A. Zeeb lsta->in_mgd = true; 1692d9f59799SBjoern A. Zeeb } 1693d9f59799SBjoern A. Zeeb 1694*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 1695d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1696d9f59799SBjoern A. Zeeb 1697d9f59799SBjoern A. Zeeb /* Call iv_newstate first so we get potential DISASSOC packet out. */ 1698d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 1699d9f59799SBjoern A. Zeeb if (error != 0) 1700d9f59799SBjoern A. Zeeb goto outni; 1701d9f59799SBjoern A. Zeeb 1702d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 1703*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1704d9f59799SBjoern A. Zeeb 170567674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1706d9f59799SBjoern A. Zeeb 1707d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 1708d9f59799SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 1709d9f59799SBjoern A. Zeeb 1710d9f59799SBjoern A. Zeeb /* flush, no drop */ 1711d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 1712d9f59799SBjoern A. Zeeb 1713d9f59799SBjoern A. Zeeb /* End mgd_complete_tx. */ 1714d9f59799SBjoern A. Zeeb if (lsta->in_mgd) { 1715d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1716d9f59799SBjoern A. Zeeb prep_tx_info.success = false; 1717d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 1718d9f59799SBjoern A. Zeeb lsta->in_mgd = false; 1719d9f59799SBjoern A. Zeeb } 1720d9f59799SBjoern A. Zeeb 1721d9f59799SBjoern A. Zeeb #if 0 1722d9f59799SBjoern A. Zeeb /* sync_rx_queues */ 1723d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 1724d9f59799SBjoern A. Zeeb 1725d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */ 1726d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 1727d9f59799SBjoern A. Zeeb #endif 1728d9f59799SBjoern A. Zeeb 1729d9f59799SBjoern A. Zeeb /* Take the station down. */ 1730d9f59799SBjoern A. Zeeb 17316b4cac81SBjoern A. Zeeb /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */ 17326b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 17336b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not " 17346b4cac81SBjoern A. Zeeb "AUTHORIZED: %#x\n", __func__, lsta, lsta->state)); 1735e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC); 17366b4cac81SBjoern A. Zeeb if (error != 0) 17376b4cac81SBjoern A. Zeeb goto out; 17386b4cac81SBjoern A. Zeeb 173967674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 17406b4cac81SBjoern A. Zeeb 17416b4cac81SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTH). */ 17426b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 17436b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 17446b4cac81SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 1745e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH); 17466b4cac81SBjoern A. Zeeb if (error != 0) 17476b4cac81SBjoern A. Zeeb goto out; 17486b4cac81SBjoern A. Zeeb 174967674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 17506b4cac81SBjoern A. Zeeb 1751d9f59799SBjoern A. Zeeb #if 0 1752d9f59799SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 1753d9f59799SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw); 1754d9f59799SBjoern A. Zeeb #endif 1755d9f59799SBjoern A. Zeeb 1756d9f59799SBjoern A. Zeeb error = EALREADY; 17576b4cac81SBjoern A. Zeeb out: 1758*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 17596b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1760d9f59799SBjoern A. Zeeb outni: 17616b4cac81SBjoern A. Zeeb if (ni != NULL) 17626b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 17636b4cac81SBjoern A. Zeeb return (error); 17646b4cac81SBjoern A. Zeeb } 17656b4cac81SBjoern A. Zeeb 17666b4cac81SBjoern A. Zeeb static int 1767d9f59799SBjoern A. Zeeb lkpi_sta_run_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 1768d9f59799SBjoern A. Zeeb { 1769d9f59799SBjoern A. Zeeb struct lkpi_hw *lhw; 1770d9f59799SBjoern A. Zeeb struct ieee80211_hw *hw; 1771d9f59799SBjoern A. Zeeb struct lkpi_vif *lvif; 1772d9f59799SBjoern A. Zeeb struct ieee80211_vif *vif; 1773d9f59799SBjoern A. Zeeb struct ieee80211_node *ni; 1774d9f59799SBjoern A. Zeeb struct lkpi_sta *lsta; 1775d9f59799SBjoern A. Zeeb struct ieee80211_sta *sta; 1776d9f59799SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 1777d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 1778d9f59799SBjoern A. Zeeb int error; 1779d9f59799SBjoern A. Zeeb 1780d9f59799SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 1781d9f59799SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 1782d9f59799SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 1783d9f59799SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 1784d9f59799SBjoern A. Zeeb 1785d9f59799SBjoern A. Zeeb /* Keep ni around. */ 1786d9f59799SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 1787d9f59799SBjoern A. Zeeb lsta = ni->ni_drv_data; 1788d9f59799SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 1789d9f59799SBjoern A. Zeeb 179067674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1791d9f59799SBjoern A. Zeeb 1792d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 1793*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1794d9f59799SBjoern A. Zeeb 1795d9f59799SBjoern A. Zeeb /* flush, drop. */ 1796d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1797d9f59799SBjoern A. Zeeb 1798d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?"); 1799d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) && 1800d9f59799SBjoern A. Zeeb !lsta->in_mgd) { 1801d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1802d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 1803d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 1804d9f59799SBjoern A. Zeeb lsta->in_mgd = true; 1805d9f59799SBjoern A. Zeeb } 1806d9f59799SBjoern A. Zeeb 1807*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 1808d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1809d9f59799SBjoern A. Zeeb 1810d9f59799SBjoern A. Zeeb /* Call iv_newstate first so we get potential DISASSOC packet out. */ 1811d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 1812d9f59799SBjoern A. Zeeb if (error != 0) 1813d9f59799SBjoern A. Zeeb goto outni; 1814d9f59799SBjoern A. Zeeb 1815d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 1816*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1817d9f59799SBjoern A. Zeeb 181867674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1819d9f59799SBjoern A. Zeeb 1820d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 1821d9f59799SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 1822d9f59799SBjoern A. Zeeb 1823d9f59799SBjoern A. Zeeb /* flush, no drop */ 1824d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 1825d9f59799SBjoern A. Zeeb 1826d9f59799SBjoern A. Zeeb /* End mgd_complete_tx. */ 1827d9f59799SBjoern A. Zeeb if (lsta->in_mgd) { 1828d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1829d9f59799SBjoern A. Zeeb prep_tx_info.success = false; 1830d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 1831d9f59799SBjoern A. Zeeb lsta->in_mgd = false; 1832d9f59799SBjoern A. Zeeb } 1833d9f59799SBjoern A. Zeeb 1834d9f59799SBjoern A. Zeeb /* sync_rx_queues */ 1835d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 1836d9f59799SBjoern A. Zeeb 1837d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */ 1838d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 1839d9f59799SBjoern A. Zeeb 1840d9f59799SBjoern A. Zeeb /* Take the station down. */ 1841d9f59799SBjoern A. Zeeb 1842d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */ 1843d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 1844d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not " 1845d9f59799SBjoern A. Zeeb "AUTHORIZED: %#x\n", __func__, lsta, lsta->state)); 1846e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC); 1847d9f59799SBjoern A. Zeeb if (error != 0) 1848d9f59799SBjoern A. Zeeb goto out; 1849d9f59799SBjoern A. Zeeb 185067674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1851d9f59799SBjoern A. Zeeb 1852d9f59799SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTH). */ 1853d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 1854d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 1855d9f59799SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 1856e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH); 1857d9f59799SBjoern A. Zeeb if (error != 0) 1858d9f59799SBjoern A. Zeeb goto out; 1859d9f59799SBjoern A. Zeeb 186067674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1861d9f59799SBjoern A. Zeeb 1862d9f59799SBjoern A. Zeeb /* Update sta and change state (from AUTH) to NONE. */ 1863d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 1864d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 1865d9f59799SBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 1866e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE); 1867d9f59799SBjoern A. Zeeb if (error != 0) 1868d9f59799SBjoern A. Zeeb goto out; 1869d9f59799SBjoern A. Zeeb 187067674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1871d9f59799SBjoern A. Zeeb 1872d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 1873d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 1874d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 1875d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg)); 1876e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST); 1877d9f59799SBjoern A. Zeeb if (error != 0) { 1878d9f59799SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 1879d9f59799SBjoern A. Zeeb goto out; 1880d9f59799SBjoern A. Zeeb } 1881d9f59799SBjoern A. Zeeb #if 0 1882d9f59799SBjoern A. Zeeb lsta->added_to_drv = false; /* mo manages. */ 1883d9f59799SBjoern A. Zeeb #endif 1884d9f59799SBjoern A. Zeeb 188567674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1886d9f59799SBjoern A. Zeeb 1887d9f59799SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 1888d9f59799SBjoern A. Zeeb /* 1889d9f59799SBjoern A. Zeeb * One would expect this to happen when going off AUTHORIZED. 1890d9f59799SBjoern A. Zeeb * See comment there; removes the sta from fw. 1891d9f59799SBjoern A. Zeeb */ 1892d9f59799SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw); 1893d9f59799SBjoern A. Zeeb 1894d9f59799SBjoern A. Zeeb IMPROVE("Any bss_info changes to announce?"); 1895d9f59799SBjoern A. Zeeb bss_changed = 0; 1896d9f59799SBjoern A. Zeeb vif->bss_conf.qos = 0; 1897d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 1898d9f59799SBjoern A. Zeeb vif->bss_conf.ssid_len = 0; 1899d9f59799SBjoern A. Zeeb memset(vif->bss_conf.ssid, '\0', sizeof(vif->bss_conf.ssid)); 1900d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 1901d9f59799SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 1902d9f59799SBjoern A. Zeeb 1903d9f59799SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif); 1904d9f59799SBjoern A. Zeeb 1905d9f59799SBjoern A. Zeeb /* conf_tx */ 1906d9f59799SBjoern A. Zeeb 1907d9f59799SBjoern A. Zeeb /* Take the chan ctx down. */ 1908d9f59799SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 1909d9f59799SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 1910d9f59799SBjoern A. Zeeb 1911d9f59799SBjoern A. Zeeb conf = vif->chanctx_conf; 1912d9f59799SBjoern A. Zeeb /* Remove vif context. */ 1913d9f59799SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->chanctx_conf); 1914d9f59799SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 1915d9f59799SBjoern A. Zeeb 1916d9f59799SBjoern A. Zeeb /* Remove chan ctx. */ 1917d9f59799SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 1918d9f59799SBjoern A. Zeeb free(conf, M_LKPI80211); 1919d9f59799SBjoern A. Zeeb } 1920d9f59799SBjoern A. Zeeb 1921d9f59799SBjoern A. Zeeb error = EALREADY; 1922d9f59799SBjoern A. Zeeb out: 1923*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 1924d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1925d9f59799SBjoern A. Zeeb outni: 1926d9f59799SBjoern A. Zeeb if (ni != NULL) 1927d9f59799SBjoern A. Zeeb ieee80211_free_node(ni); 1928d9f59799SBjoern A. Zeeb return (error); 1929d9f59799SBjoern A. Zeeb } 1930d9f59799SBjoern A. Zeeb 1931d9f59799SBjoern A. Zeeb static int 1932d9f59799SBjoern A. Zeeb lkpi_sta_run_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 1933d9f59799SBjoern A. Zeeb { 1934d9f59799SBjoern A. Zeeb 1935d9f59799SBjoern A. Zeeb return (lkpi_sta_run_to_init(vap, nstate, arg)); 1936d9f59799SBjoern A. Zeeb } 1937d9f59799SBjoern A. Zeeb 1938d9f59799SBjoern A. Zeeb static int 19396b4cac81SBjoern A. Zeeb lkpi_sta_run_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 19406b4cac81SBjoern A. Zeeb { 19416b4cac81SBjoern A. Zeeb int error; 19426b4cac81SBjoern A. Zeeb 1943d9f59799SBjoern A. Zeeb error = lkpi_sta_run_to_init(vap, nstate, arg); 1944d9f59799SBjoern A. Zeeb if (error != 0 && error != EALREADY) 1945d9f59799SBjoern A. Zeeb return (error); 1946d9f59799SBjoern A. Zeeb 1947d9f59799SBjoern A. Zeeb /* At this point iv_bss is long a new node! */ 1948d9f59799SBjoern A. Zeeb 1949d9f59799SBjoern A. Zeeb error |= lkpi_sta_scan_to_auth(vap, nstate, 0); 19506b4cac81SBjoern A. Zeeb return (error); 19516b4cac81SBjoern A. Zeeb } 19526b4cac81SBjoern A. Zeeb 1953d9f59799SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 19546b4cac81SBjoern A. Zeeb 19556b4cac81SBjoern A. Zeeb /* 19566b4cac81SBjoern A. Zeeb * The matches the documented state changes in net80211::sta_newstate(). 19576b4cac81SBjoern A. Zeeb * XXX (1) without CSA and SLEEP yet, * XXX (2) not all unhandled cases 19586b4cac81SBjoern A. Zeeb * there are "invalid" (so there is a room for failure here). 19596b4cac81SBjoern A. Zeeb */ 19606b4cac81SBjoern A. Zeeb struct fsm_state { 19616b4cac81SBjoern A. Zeeb /* INIT, SCAN, AUTH, ASSOC, CAC, RUN, CSA, SLEEP */ 19626b4cac81SBjoern A. Zeeb enum ieee80211_state ostate; 19636b4cac81SBjoern A. Zeeb enum ieee80211_state nstate; 19646b4cac81SBjoern A. Zeeb int (*handler)(struct ieee80211vap *, enum ieee80211_state, int); 19656b4cac81SBjoern A. Zeeb } sta_state_fsm[] = { 19666b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, 19676b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, /* scan_to_init */ 19686b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_INIT, lkpi_sta_auth_to_init }, /* not explicitly in sta_newstate() */ 1969d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_INIT, lkpi_sta_assoc_to_init }, /* Send DEAUTH. */ 1970d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_INIT, lkpi_sta_run_to_init }, /* Send DISASSOC. */ 19716b4cac81SBjoern A. Zeeb 19726b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_SCAN, lkpi_sta_state_do_nada }, 19736b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_SCAN, lkpi_sta_state_do_nada }, 19746b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_SCAN, lkpi_sta_auth_to_scan }, 19756b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_SCAN, lkpi_sta_assoc_to_scan }, 1976d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_SCAN, lkpi_sta_run_to_scan }, /* Beacon miss. */ 19776b4cac81SBjoern A. Zeeb 1978d9f59799SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, /* Send AUTH. */ 1979d9f59799SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, /* Send AUTH. */ 1980d9f59799SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_AUTH, lkpi_sta_a_to_a }, /* Send ?AUTH. */ 1981d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_AUTH, lkpi_sta_assoc_to_auth }, /* Send ?AUTH. */ 1982d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_AUTH, lkpi_sta_run_to_auth }, /* Send ?AUTH. */ 19836b4cac81SBjoern A. Zeeb 1984d9f59799SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_ASSOC, lkpi_sta_auth_to_assoc }, /* Send ASSOCREQ. */ 1985d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_ASSOC, lkpi_sta_a_to_a }, /* Send ASSOCREQ. */ 1986d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_ASSOC, lkpi_sta_run_to_assoc }, /* Send ASSOCREQ/REASSOCREQ. */ 19876b4cac81SBjoern A. Zeeb 19886b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_RUN, lkpi_sta_auth_to_run }, 19896b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_RUN, lkpi_sta_assoc_to_run }, 19906b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_RUN, lkpi_sta_state_do_nada }, 19916b4cac81SBjoern A. Zeeb 19926b4cac81SBjoern A. Zeeb /* Dummy at the end without handler. */ 19936b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_INIT, NULL }, 19946b4cac81SBjoern A. Zeeb }; 19956b4cac81SBjoern A. Zeeb 19966b4cac81SBjoern A. Zeeb static int 19976b4cac81SBjoern A. Zeeb lkpi_iv_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 19986b4cac81SBjoern A. Zeeb { 19996b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 20006b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 20016b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 20026b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 20036b4cac81SBjoern A. Zeeb struct fsm_state *s; 20046b4cac81SBjoern A. Zeeb enum ieee80211_state ostate; 20056b4cac81SBjoern A. Zeeb int error; 20066b4cac81SBjoern A. Zeeb 20076b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 20086b4cac81SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(ic); 20096b4cac81SBjoern A. Zeeb ostate = vap->iv_state; 20106b4cac81SBjoern A. Zeeb 20119d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 20129d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 20136b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x\n", 20146b4cac81SBjoern A. Zeeb __func__, __LINE__, vap, nstate, arg); 20159d9ba2b7SBjoern A. Zeeb #endif 20166b4cac81SBjoern A. Zeeb 20176b4cac81SBjoern A. Zeeb if (vap->iv_opmode == IEEE80211_M_STA) { 20186b4cac81SBjoern A. Zeeb 20196b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 20206b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 20216b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 20226b4cac81SBjoern A. Zeeb 20236b4cac81SBjoern A. Zeeb /* No need to replicate this in most state handlers. */ 20246b4cac81SBjoern A. Zeeb if (ostate == IEEE80211_S_SCAN && nstate != IEEE80211_S_SCAN) 20256b4cac81SBjoern A. Zeeb lkpi_stop_hw_scan(lhw, vif); 20266b4cac81SBjoern A. Zeeb 20276b4cac81SBjoern A. Zeeb s = sta_state_fsm; 20286b4cac81SBjoern A. Zeeb 20296b4cac81SBjoern A. Zeeb } else { 20306b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: only station mode currently supported: " 20316b4cac81SBjoern A. Zeeb "cap %p iv_opmode %d\n", __func__, vap, vap->iv_opmode); 20326b4cac81SBjoern A. Zeeb return (ENOSYS); 20336b4cac81SBjoern A. Zeeb } 20346b4cac81SBjoern A. Zeeb 20356b4cac81SBjoern A. Zeeb error = 0; 20366b4cac81SBjoern A. Zeeb for (; s->handler != NULL; s++) { 20376b4cac81SBjoern A. Zeeb if (ostate == s->ostate && nstate == s->nstate) { 20389d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 20399d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 2040d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: new state %d (%s) ->" 2041d9f59799SBjoern A. Zeeb " %d (%s): arg %d.\n", __func__, 2042d9f59799SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 2043d9f59799SBjoern A. Zeeb nstate, ieee80211_state_name[nstate], arg); 20449d9ba2b7SBjoern A. Zeeb #endif 20456b4cac81SBjoern A. Zeeb error = s->handler(vap, nstate, arg); 20466b4cac81SBjoern A. Zeeb break; 20476b4cac81SBjoern A. Zeeb } 20486b4cac81SBjoern A. Zeeb } 20496b4cac81SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(vap->iv_ic); 20506b4cac81SBjoern A. Zeeb 20516b4cac81SBjoern A. Zeeb if (s->handler == NULL) { 2052d9f59799SBjoern A. Zeeb IMPROVE("turn this into a KASSERT\n"); 20536b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: unsupported state transition " 20546b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s)\n", __func__, 20556b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 20566b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 20576b4cac81SBjoern A. Zeeb return (ENOSYS); 20586b4cac81SBjoern A. Zeeb } 20596b4cac81SBjoern A. Zeeb 20606b4cac81SBjoern A. Zeeb if (error == EALREADY) { 20619d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 20629d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 2063d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: state transition %d (%s) -> " 2064d9f59799SBjoern A. Zeeb "%d (%s): iv_newstate already handled: %d.\n", 2065d9f59799SBjoern A. Zeeb __func__, ostate, ieee80211_state_name[ostate], 2066d9f59799SBjoern A. Zeeb nstate, ieee80211_state_name[nstate], error); 20679d9ba2b7SBjoern A. Zeeb #endif 20686b4cac81SBjoern A. Zeeb return (0); 20696b4cac81SBjoern A. Zeeb } 20706b4cac81SBjoern A. Zeeb 20716b4cac81SBjoern A. Zeeb if (error != 0) { 20726b4cac81SBjoern A. Zeeb /* XXX-BZ currently expected so ignore. */ 20736b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: error %d during state transition " 20746b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s)\n", __func__, error, 20756b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 20766b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 20776b4cac81SBjoern A. Zeeb /* return (error); */ 20786b4cac81SBjoern A. Zeeb } 20796b4cac81SBjoern A. Zeeb 20809d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 20819d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 2082d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x " 2083d9f59799SBjoern A. Zeeb "calling net80211 parent\n", 20846b4cac81SBjoern A. Zeeb __func__, __LINE__, vap, nstate, arg); 20859d9ba2b7SBjoern A. Zeeb #endif 20866b4cac81SBjoern A. Zeeb 20876b4cac81SBjoern A. Zeeb return (lvif->iv_newstate(vap, nstate, arg)); 20886b4cac81SBjoern A. Zeeb } 20896b4cac81SBjoern A. Zeeb 20906b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 20916b4cac81SBjoern A. Zeeb 2092d9f59799SBjoern A. Zeeb /* 2093d9f59799SBjoern A. Zeeb * We overload (*iv_update_bss) as otherwise we have cases in, e.g., 2094d9f59799SBjoern A. Zeeb * net80211::ieee80211_sta_join1() where vap->iv_bss gets replaced by a 2095d9f59799SBjoern A. Zeeb * new node without us knowing and thus our ni/lsta are out of sync. 2096d9f59799SBjoern A. Zeeb */ 2097d9f59799SBjoern A. Zeeb static struct ieee80211_node * 2098d9f59799SBjoern A. Zeeb lkpi_iv_update_bss(struct ieee80211vap *vap, struct ieee80211_node *ni) 2099d9f59799SBjoern A. Zeeb { 2100d9f59799SBjoern A. Zeeb struct lkpi_vif *lvif; 2101d9f59799SBjoern A. Zeeb struct ieee80211_node *obss; 2102d9f59799SBjoern A. Zeeb struct lkpi_sta *lsta; 2103ed3ef56bSBjoern A. Zeeb struct ieee80211_sta *sta; 2104d9f59799SBjoern A. Zeeb 2105d9f59799SBjoern A. Zeeb obss = vap->iv_bss; 2106d9f59799SBjoern A. Zeeb 21079d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 21089d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 21099d9ba2b7SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: obss %p ni_drv_data %p " 21109d9ba2b7SBjoern A. Zeeb "ni %p ni_drv_data %p\n", __func__, 21119d9ba2b7SBjoern A. Zeeb obss, (obss != NULL) ? obss->ni_drv_data : NULL, 21129d9ba2b7SBjoern A. Zeeb ni, (ni != NULL) ? ni->ni_drv_data : NULL); 21139d9ba2b7SBjoern A. Zeeb #endif 21149d9ba2b7SBjoern A. Zeeb 2115d9f59799SBjoern A. Zeeb /* Nothing to copy from. Just return. */ 2116d9f59799SBjoern A. Zeeb if (obss == NULL || obss->ni_drv_data == NULL) 2117d9f59799SBjoern A. Zeeb goto out; 2118d9f59799SBjoern A. Zeeb 2119d9f59799SBjoern A. Zeeb /* Nothing to copy to. Just return. */ 2120d9f59799SBjoern A. Zeeb IMPROVE("clearing the obss might still be needed?"); 2121d9f59799SBjoern A. Zeeb if (ni == NULL) 2122d9f59799SBjoern A. Zeeb goto out; 2123d9f59799SBjoern A. Zeeb 2124d9f59799SBjoern A. Zeeb /* Nothing changed? panic? */ 2125d9f59799SBjoern A. Zeeb if (obss == ni) 2126d9f59799SBjoern A. Zeeb goto out; 2127d9f59799SBjoern A. Zeeb 2128d9f59799SBjoern A. Zeeb lsta = obss->ni_drv_data; 2129d9f59799SBjoern A. Zeeb obss->ni_drv_data = ni->ni_drv_data; 2130d9f59799SBjoern A. Zeeb ni->ni_drv_data = lsta; 2131ed3ef56bSBjoern A. Zeeb if (lsta != NULL) { 2132d9f59799SBjoern A. Zeeb lsta->ni = ni; 2133ed3ef56bSBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 2134ed3ef56bSBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->addr, lsta->ni->ni_macaddr); 2135ed3ef56bSBjoern A. Zeeb } 2136d9f59799SBjoern A. Zeeb lsta = obss->ni_drv_data; 2137ed3ef56bSBjoern A. Zeeb if (lsta != NULL) { 2138d9f59799SBjoern A. Zeeb lsta->ni = obss; 2139ed3ef56bSBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 2140ed3ef56bSBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->addr, lsta->ni->ni_macaddr); 2141ed3ef56bSBjoern A. Zeeb } 2142d9f59799SBjoern A. Zeeb 2143d9f59799SBjoern A. Zeeb out: 2144ed3ef56bSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 2145d9f59799SBjoern A. Zeeb return (lvif->iv_update_bss(vap, ni)); 2146d9f59799SBjoern A. Zeeb } 2147d9f59799SBjoern A. Zeeb 21484a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 21496b4cac81SBjoern A. Zeeb static int 21504a67f1dfSBjoern A. Zeeb lkpi_wme_update(struct lkpi_hw *lhw, struct ieee80211vap *vap, bool planned) 21516b4cac81SBjoern A. Zeeb { 21524a67f1dfSBjoern A. Zeeb struct ieee80211com *ic; 21536b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 21546b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 21556b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 21566b4cac81SBjoern A. Zeeb struct chanAccParams chp; 21576b4cac81SBjoern A. Zeeb struct wmeParams wmeparr[WME_NUM_AC]; 21586b4cac81SBjoern A. Zeeb struct ieee80211_tx_queue_params txqp; 21596b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 21606b4cac81SBjoern A. Zeeb int error; 21616b4cac81SBjoern A. Zeeb uint16_t ac; 21626b4cac81SBjoern A. Zeeb 21636b4cac81SBjoern A. Zeeb IMPROVE(); 21646b4cac81SBjoern A. Zeeb KASSERT(WME_NUM_AC == IEEE80211_NUM_ACS, ("%s: WME_NUM_AC %d != " 21656b4cac81SBjoern A. Zeeb "IEEE80211_NUM_ACS %d\n", __func__, WME_NUM_AC, IEEE80211_NUM_ACS)); 21666b4cac81SBjoern A. Zeeb 21676b4cac81SBjoern A. Zeeb if (vap == NULL) 21686b4cac81SBjoern A. Zeeb return (0); 21696b4cac81SBjoern A. Zeeb 21704a67f1dfSBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WME) == 0) 21714a67f1dfSBjoern A. Zeeb return (0); 21724a67f1dfSBjoern A. Zeeb 21736b4cac81SBjoern A. Zeeb if (lhw->ops->conf_tx == NULL) 21746b4cac81SBjoern A. Zeeb return (0); 21756b4cac81SBjoern A. Zeeb 21764a67f1dfSBjoern A. Zeeb if (!planned && (vap->iv_state != IEEE80211_S_RUN)) { 21774a67f1dfSBjoern A. Zeeb lhw->update_wme = true; 21784a67f1dfSBjoern A. Zeeb return (0); 21794a67f1dfSBjoern A. Zeeb } 21804a67f1dfSBjoern A. Zeeb lhw->update_wme = false; 21816b4cac81SBjoern A. Zeeb 21824a67f1dfSBjoern A. Zeeb ic = lhw->ic; 21836b4cac81SBjoern A. Zeeb ieee80211_wme_ic_getparams(ic, &chp); 21846b4cac81SBjoern A. Zeeb IEEE80211_LOCK(ic); 21856b4cac81SBjoern A. Zeeb for (ac = 0; ac < WME_NUM_AC; ac++) 21866b4cac81SBjoern A. Zeeb wmeparr[ac] = chp.cap_wmeParams[ac]; 21876b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(ic); 21886b4cac81SBjoern A. Zeeb 21894a67f1dfSBjoern A. Zeeb hw = LHW_TO_HW(lhw); 21904a67f1dfSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 21914a67f1dfSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 21924a67f1dfSBjoern A. Zeeb 21936b4cac81SBjoern A. Zeeb /* Configure tx queues (conf_tx) & send BSS_CHANGED_QOS. */ 21946b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 21956b4cac81SBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 21966b4cac81SBjoern A. Zeeb struct wmeParams *wmep; 21976b4cac81SBjoern A. Zeeb 21986b4cac81SBjoern A. Zeeb wmep = &wmeparr[ac]; 21996b4cac81SBjoern A. Zeeb bzero(&txqp, sizeof(txqp)); 22006b4cac81SBjoern A. Zeeb txqp.cw_min = wmep->wmep_logcwmin; 22016b4cac81SBjoern A. Zeeb txqp.cw_max = wmep->wmep_logcwmax; 22026b4cac81SBjoern A. Zeeb txqp.txop = wmep->wmep_txopLimit; 22036b4cac81SBjoern A. Zeeb txqp.aifs = wmep->wmep_aifsn; 22046b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_conf_tx(hw, vif, ac, &txqp); 22056b4cac81SBjoern A. Zeeb if (error != 0) 22063f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: conf_tx ac %u failed %d\n", 22076b4cac81SBjoern A. Zeeb __func__, ac, error); 22086b4cac81SBjoern A. Zeeb } 22096b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 22106b4cac81SBjoern A. Zeeb changed = BSS_CHANGED_QOS; 22114a67f1dfSBjoern A. Zeeb if (!planned) 22126b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 22134a67f1dfSBjoern A. Zeeb 22144a67f1dfSBjoern A. Zeeb return (changed); 22154a67f1dfSBjoern A. Zeeb } 22166b4cac81SBjoern A. Zeeb #endif 22176b4cac81SBjoern A. Zeeb 22184a67f1dfSBjoern A. Zeeb static int 22194a67f1dfSBjoern A. Zeeb lkpi_ic_wme_update(struct ieee80211com *ic) 22204a67f1dfSBjoern A. Zeeb { 22214a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 22224a67f1dfSBjoern A. Zeeb struct ieee80211vap *vap; 22234a67f1dfSBjoern A. Zeeb struct lkpi_hw *lhw; 22244a67f1dfSBjoern A. Zeeb 22254a67f1dfSBjoern A. Zeeb IMPROVE("Use the per-VAP callback in net80211."); 22264a67f1dfSBjoern A. Zeeb vap = TAILQ_FIRST(&ic->ic_vaps); 22274a67f1dfSBjoern A. Zeeb if (vap == NULL) 22286b4cac81SBjoern A. Zeeb return (0); 22294a67f1dfSBjoern A. Zeeb 22304a67f1dfSBjoern A. Zeeb lhw = ic->ic_softc; 22314a67f1dfSBjoern A. Zeeb 22324a67f1dfSBjoern A. Zeeb lkpi_wme_update(lhw, vap, false); 22334a67f1dfSBjoern A. Zeeb #endif 22344a67f1dfSBjoern A. Zeeb return (0); /* unused */ 22356b4cac81SBjoern A. Zeeb } 22366b4cac81SBjoern A. Zeeb 22376b4cac81SBjoern A. Zeeb static struct ieee80211vap * 22386b4cac81SBjoern A. Zeeb lkpi_ic_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], 22396b4cac81SBjoern A. Zeeb int unit, enum ieee80211_opmode opmode, int flags, 22406b4cac81SBjoern A. Zeeb const uint8_t bssid[IEEE80211_ADDR_LEN], 22416b4cac81SBjoern A. Zeeb const uint8_t mac[IEEE80211_ADDR_LEN]) 22426b4cac81SBjoern A. Zeeb { 22436b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 22446b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 22456b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 22466b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 22476b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 22486b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 22496b4cac81SBjoern A. Zeeb size_t len; 2250e3a0b120SBjoern A. Zeeb int error, i; 22516b4cac81SBjoern A. Zeeb 22526b4cac81SBjoern A. Zeeb if (!TAILQ_EMPTY(&ic->ic_vaps)) /* 1 so far. Add <n> once this works. */ 22536b4cac81SBjoern A. Zeeb return (NULL); 22546b4cac81SBjoern A. Zeeb 22556b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 22566b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 22576b4cac81SBjoern A. Zeeb 22586b4cac81SBjoern A. Zeeb len = sizeof(*lvif); 22596b4cac81SBjoern A. Zeeb len += hw->vif_data_size; /* vif->drv_priv */ 22606b4cac81SBjoern A. Zeeb 22616b4cac81SBjoern A. Zeeb lvif = malloc(len, M_80211_VAP, M_WAITOK | M_ZERO); 22626b4cac81SBjoern A. Zeeb mtx_init(&lvif->mtx, "lvif", NULL, MTX_DEF); 22636b4cac81SBjoern A. Zeeb TAILQ_INIT(&lvif->lsta_head); 22646b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 22656b4cac81SBjoern A. Zeeb 22666b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 22676b4cac81SBjoern A. Zeeb memcpy(vif->addr, mac, IEEE80211_ADDR_LEN); 22686b4cac81SBjoern A. Zeeb vif->p2p = false; 22696b4cac81SBjoern A. Zeeb vif->probe_req_reg = false; 22706b4cac81SBjoern A. Zeeb vif->type = lkpi_opmode_to_vif_type(opmode); 22716b4cac81SBjoern A. Zeeb lvif->wdev.iftype = vif->type; 22726b4cac81SBjoern A. Zeeb /* Need to fill in other fields as well. */ 22736b4cac81SBjoern A. Zeeb IMPROVE(); 22746b4cac81SBjoern A. Zeeb 22756b4cac81SBjoern A. Zeeb /* XXX-BZ hardcoded for now! */ 22766b4cac81SBjoern A. Zeeb #if 1 22776b4cac81SBjoern A. Zeeb vif->chanctx_conf = NULL; 22786b4cac81SBjoern A. Zeeb vif->bss_conf.idle = true; 22796b4cac81SBjoern A. Zeeb vif->bss_conf.ps = false; 22806b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.width = NL80211_CHAN_WIDTH_20_NOHT; 22816b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble = false; /* vap->iv_flags IEEE80211_F_SHPREAMBLE */ 22826b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot = false; /* vap->iv_flags IEEE80211_F_SHSLOT */ 22836b4cac81SBjoern A. Zeeb vif->bss_conf.qos = false; 22846b4cac81SBjoern A. Zeeb vif->bss_conf.use_cts_prot = false; /* vap->iv_protmode */ 22856b4cac81SBjoern A. Zeeb vif->bss_conf.ht_operation_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONE; 22866b4cac81SBjoern A. Zeeb vif->bss_conf.assoc = false; 22876b4cac81SBjoern A. Zeeb vif->bss_conf.aid = 0; 2288caaa79c3SBjoern A. Zeeb /* 2289caaa79c3SBjoern A. Zeeb * We need to initialize it to something as the bss_info_changed call 2290caaa79c3SBjoern A. Zeeb * will try to copy from it in iwlwifi and NULL is a panic. 2291caaa79c3SBjoern A. Zeeb * We will set the proper one in scan_to_auth() before being assoc. 2292caaa79c3SBjoern A. Zeeb * NB: the logic there with using an array as bssid_override and checking 2293caaa79c3SBjoern A. Zeeb * for non-NULL later is flawed but in their workflow does not seem to 2294caaa79c3SBjoern A. Zeeb * matter. 2295caaa79c3SBjoern A. Zeeb */ 2296caaa79c3SBjoern A. Zeeb vif->bss_conf.bssid = zerobssid; 22976b4cac81SBjoern A. Zeeb #endif 22986b4cac81SBjoern A. Zeeb #if 0 22996b4cac81SBjoern A. Zeeb vif->bss_conf.dtim_period = 0; /* IEEE80211_DTIM_DEFAULT ; must stay 0. */ 23006b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(vif->bss_conf.bssid, bssid); 23016b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = ic->ic_bintval; 23026b4cac81SBjoern A. Zeeb /* iwlwifi bug. */ 23036b4cac81SBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16) 23046b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = 16; 23056b4cac81SBjoern A. Zeeb #endif 2306e3a0b120SBjoern A. Zeeb 2307e3a0b120SBjoern A. Zeeb /* Setup queue defaults; driver may override in (*add_interface). */ 2308e3a0b120SBjoern A. Zeeb for (i = 0; i < IEEE80211_NUM_ACS; i++) { 2309e3a0b120SBjoern A. Zeeb if (ieee80211_hw_check(hw, QUEUE_CONTROL)) 2310e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = IEEE80211_INVAL_HW_QUEUE; 2311e3a0b120SBjoern A. Zeeb else if (hw->queues >= IEEE80211_NUM_ACS) 2312e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = i; 2313e3a0b120SBjoern A. Zeeb else 2314e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = 0; 23150cbcfa19SBjoern A. Zeeb 23160cbcfa19SBjoern A. Zeeb /* Initialize the queue to running. Stopped? */ 23170cbcfa19SBjoern A. Zeeb lvif->hw_queue_stopped[i] = false; 2318e3a0b120SBjoern A. Zeeb } 2319e3a0b120SBjoern A. Zeeb vif->cab_queue = IEEE80211_INVAL_HW_QUEUE; 2320e3a0b120SBjoern A. Zeeb 23216b4cac81SBjoern A. Zeeb IMPROVE(); 23226b4cac81SBjoern A. Zeeb 23236b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_start(hw); 23246b4cac81SBjoern A. Zeeb if (error != 0) { 23253f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: failed to start hw: %d\n", __func__, error); 23266b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 23276b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 23286b4cac81SBjoern A. Zeeb return (NULL); 23296b4cac81SBjoern A. Zeeb } 23306b4cac81SBjoern A. Zeeb 23316b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_add_interface(hw, vif); 23326b4cac81SBjoern A. Zeeb if (error != 0) { 23336b4cac81SBjoern A. Zeeb IMPROVE(); /* XXX-BZ mo_stop()? */ 23343f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: failed to add interface: %d\n", __func__, error); 23356b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 23366b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 23376b4cac81SBjoern A. Zeeb return (NULL); 23386b4cac81SBjoern A. Zeeb } 23396b4cac81SBjoern A. Zeeb 23408891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 23416b4cac81SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lhw->lvif_head, lvif, lvif_entry); 23428891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 23436b4cac81SBjoern A. Zeeb 23446b4cac81SBjoern A. Zeeb /* Set bss_info. */ 23456b4cac81SBjoern A. Zeeb changed = 0; 23466b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 23476b4cac81SBjoern A. Zeeb 23486b4cac81SBjoern A. Zeeb /* conf_tx setup; default WME? */ 23496b4cac81SBjoern A. Zeeb 23506b4cac81SBjoern A. Zeeb /* Force MC init. */ 23516b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(ic, true); 23526b4cac81SBjoern A. Zeeb 23536b4cac81SBjoern A. Zeeb IMPROVE(); 23546b4cac81SBjoern A. Zeeb 23556b4cac81SBjoern A. Zeeb ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid); 23566b4cac81SBjoern A. Zeeb 23576b4cac81SBjoern A. Zeeb /* Override with LinuxKPI method so we can drive mac80211/cfg80211. */ 23586b4cac81SBjoern A. Zeeb lvif->iv_newstate = vap->iv_newstate; 23596b4cac81SBjoern A. Zeeb vap->iv_newstate = lkpi_iv_newstate; 2360d9f59799SBjoern A. Zeeb lvif->iv_update_bss = vap->iv_update_bss; 2361d9f59799SBjoern A. Zeeb vap->iv_update_bss = lkpi_iv_update_bss; 23626b4cac81SBjoern A. Zeeb 23636b4cac81SBjoern A. Zeeb /* Key management. */ 23646b4cac81SBjoern A. Zeeb if (lhw->ops->set_key != NULL) { 2365b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 23666b4cac81SBjoern A. Zeeb vap->iv_key_set = lkpi_iv_key_set; 23676b4cac81SBjoern A. Zeeb vap->iv_key_delete = lkpi_iv_key_delete; 23686b4cac81SBjoern A. Zeeb #endif 23696b4cac81SBjoern A. Zeeb } 23706b4cac81SBjoern A. Zeeb 23716b4cac81SBjoern A. Zeeb ieee80211_ratectl_init(vap); 23726b4cac81SBjoern A. Zeeb 23736b4cac81SBjoern A. Zeeb /* Complete setup. */ 23746b4cac81SBjoern A. Zeeb ieee80211_vap_attach(vap, ieee80211_media_change, 23756b4cac81SBjoern A. Zeeb ieee80211_media_status, mac); 23766b4cac81SBjoern A. Zeeb 23776b4cac81SBjoern A. Zeeb if (hw->max_listen_interval == 0) 23786b4cac81SBjoern A. Zeeb hw->max_listen_interval = 7 * (ic->ic_lintval / ic->ic_bintval); 23796b4cac81SBjoern A. Zeeb hw->conf.listen_interval = hw->max_listen_interval; 23806b4cac81SBjoern A. Zeeb ic->ic_set_channel(ic); 23816b4cac81SBjoern A. Zeeb 23826b4cac81SBjoern A. Zeeb /* XXX-BZ do we need to be able to update these? */ 23836b4cac81SBjoern A. Zeeb hw->wiphy->frag_threshold = vap->iv_fragthreshold; 23846b4cac81SBjoern A. Zeeb lkpi_80211_mo_set_frag_threshold(hw, vap->iv_fragthreshold); 23856b4cac81SBjoern A. Zeeb hw->wiphy->rts_threshold = vap->iv_rtsthreshold; 23866b4cac81SBjoern A. Zeeb lkpi_80211_mo_set_rts_threshold(hw, vap->iv_rtsthreshold); 23876b4cac81SBjoern A. Zeeb /* any others? */ 23886b4cac81SBjoern A. Zeeb IMPROVE(); 23896b4cac81SBjoern A. Zeeb 23906b4cac81SBjoern A. Zeeb return (vap); 23916b4cac81SBjoern A. Zeeb } 23926b4cac81SBjoern A. Zeeb 23934b0af114SBjoern A. Zeeb void 23944b0af114SBjoern A. Zeeb linuxkpi_ieee80211_unregister_hw(struct ieee80211_hw *hw) 23954b0af114SBjoern A. Zeeb { 23964b0af114SBjoern A. Zeeb 23974b0af114SBjoern A. Zeeb wiphy_unregister(hw->wiphy); 23984b0af114SBjoern A. Zeeb linuxkpi_ieee80211_ifdetach(hw); 23994b0af114SBjoern A. Zeeb 24004b0af114SBjoern A. Zeeb IMPROVE(); 24014b0af114SBjoern A. Zeeb } 24024b0af114SBjoern A. Zeeb 24034b0af114SBjoern A. Zeeb void 24044b0af114SBjoern A. Zeeb linuxkpi_ieee80211_restart_hw(struct ieee80211_hw *hw) 24054b0af114SBjoern A. Zeeb { 24064b0af114SBjoern A. Zeeb 24074b0af114SBjoern A. Zeeb TODO(); 24084b0af114SBjoern A. Zeeb } 24094b0af114SBjoern A. Zeeb 24106b4cac81SBjoern A. Zeeb static void 24116b4cac81SBjoern A. Zeeb lkpi_ic_vap_delete(struct ieee80211vap *vap) 24126b4cac81SBjoern A. Zeeb { 24136b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 24146b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 24156b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 24166b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 24176b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 24186b4cac81SBjoern A. Zeeb 24196b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 24206b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 24216b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 24226b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 24236b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 24246b4cac81SBjoern A. Zeeb 24258891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 24266b4cac81SBjoern A. Zeeb TAILQ_REMOVE(&lhw->lvif_head, lvif, lvif_entry); 24278891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 24286b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_interface(hw, vif); 24296b4cac81SBjoern A. Zeeb 24306b4cac81SBjoern A. Zeeb ieee80211_ratectl_deinit(vap); 24316b4cac81SBjoern A. Zeeb ieee80211_vap_detach(vap); 24326b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 24336b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 24346b4cac81SBjoern A. Zeeb } 24356b4cac81SBjoern A. Zeeb 24366b4cac81SBjoern A. Zeeb static void 24376b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast(struct ieee80211com *ic) 24386b4cac81SBjoern A. Zeeb { 24396b4cac81SBjoern A. Zeeb 24406b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(ic, false); 24416b4cac81SBjoern A. Zeeb TRACEOK(); 24426b4cac81SBjoern A. Zeeb } 24436b4cac81SBjoern A. Zeeb 24446b4cac81SBjoern A. Zeeb static void 24456b4cac81SBjoern A. Zeeb lkpi_ic_update_promisc(struct ieee80211com *ic) 24466b4cac81SBjoern A. Zeeb { 24476b4cac81SBjoern A. Zeeb 24486b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 24496b4cac81SBjoern A. Zeeb } 24506b4cac81SBjoern A. Zeeb 24516b4cac81SBjoern A. Zeeb static void 24526b4cac81SBjoern A. Zeeb lkpi_ic_update_chw(struct ieee80211com *ic) 24536b4cac81SBjoern A. Zeeb { 24546b4cac81SBjoern A. Zeeb 24556b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 24566b4cac81SBjoern A. Zeeb } 24576b4cac81SBjoern A. Zeeb 24586b4cac81SBjoern A. Zeeb /* Start / stop device. */ 24596b4cac81SBjoern A. Zeeb static void 24606b4cac81SBjoern A. Zeeb lkpi_ic_parent(struct ieee80211com *ic) 24616b4cac81SBjoern A. Zeeb { 24626b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 24636b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 24646b4cac81SBjoern A. Zeeb int error; 24656b4cac81SBjoern A. Zeeb bool start_all; 24666b4cac81SBjoern A. Zeeb 24676b4cac81SBjoern A. Zeeb IMPROVE(); 24686b4cac81SBjoern A. Zeeb 24696b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 24706b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 24716b4cac81SBjoern A. Zeeb start_all = false; 24726b4cac81SBjoern A. Zeeb 2473*8ac540d3SBjoern A. Zeeb /* IEEE80211_UNLOCK(ic); */ 2474*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 24756b4cac81SBjoern A. Zeeb if (ic->ic_nrunning > 0) { 24766b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_start(hw); 24776b4cac81SBjoern A. Zeeb if (error == 0) 24786b4cac81SBjoern A. Zeeb start_all = true; 24796b4cac81SBjoern A. Zeeb } else { 24806b4cac81SBjoern A. Zeeb lkpi_80211_mo_stop(hw); 24816b4cac81SBjoern A. Zeeb } 2482*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 2483*8ac540d3SBjoern A. Zeeb /* IEEE80211_LOCK(ic); */ 24846b4cac81SBjoern A. Zeeb 24856b4cac81SBjoern A. Zeeb if (start_all) 24866b4cac81SBjoern A. Zeeb ieee80211_start_all(ic); 24876b4cac81SBjoern A. Zeeb } 24886b4cac81SBjoern A. Zeeb 24896b4cac81SBjoern A. Zeeb bool 24906b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_is_ie_id_in_ie_buf(const u8 ie, const u8 *ie_ids, 24916b4cac81SBjoern A. Zeeb size_t ie_ids_len) 24926b4cac81SBjoern A. Zeeb { 24936b4cac81SBjoern A. Zeeb int i; 24946b4cac81SBjoern A. Zeeb 24956b4cac81SBjoern A. Zeeb for (i = 0; i < ie_ids_len; i++) { 24966b4cac81SBjoern A. Zeeb if (ie == *ie_ids) 24976b4cac81SBjoern A. Zeeb return (true); 24986b4cac81SBjoern A. Zeeb } 24996b4cac81SBjoern A. Zeeb 25006b4cac81SBjoern A. Zeeb return (false); 25016b4cac81SBjoern A. Zeeb } 25026b4cac81SBjoern A. Zeeb 25036b4cac81SBjoern A. Zeeb /* Return true if skipped; false if error. */ 25046b4cac81SBjoern A. Zeeb bool 25056b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ie_advance(size_t *xp, const u8 *ies, size_t ies_len) 25066b4cac81SBjoern A. Zeeb { 25076b4cac81SBjoern A. Zeeb size_t x; 25086b4cac81SBjoern A. Zeeb uint8_t l; 25096b4cac81SBjoern A. Zeeb 25106b4cac81SBjoern A. Zeeb x = *xp; 25116b4cac81SBjoern A. Zeeb 25126b4cac81SBjoern A. Zeeb KASSERT(x < ies_len, ("%s: x %zu ies_len %zu ies %p\n", 25136b4cac81SBjoern A. Zeeb __func__, x, ies_len, ies)); 25146b4cac81SBjoern A. Zeeb l = ies[x + 1]; 25156b4cac81SBjoern A. Zeeb x += 2 + l; 25166b4cac81SBjoern A. Zeeb 25176b4cac81SBjoern A. Zeeb if (x > ies_len) 25186b4cac81SBjoern A. Zeeb return (false); 25196b4cac81SBjoern A. Zeeb 25206b4cac81SBjoern A. Zeeb *xp = x; 25216b4cac81SBjoern A. Zeeb return (true); 25226b4cac81SBjoern A. Zeeb } 25236b4cac81SBjoern A. Zeeb 2524d9945d78SBjoern A. Zeeb static uint8_t * 2525d9945d78SBjoern A. Zeeb lkpi_scan_ies_add(uint8_t *p, struct ieee80211_scan_ies *scan_ies, 2526d9945d78SBjoern A. Zeeb uint32_t band_mask, struct ieee80211vap *vap, struct ieee80211_hw *hw) 25276b4cac81SBjoern A. Zeeb { 2528d9945d78SBjoern A. Zeeb struct ieee80211_supported_band *supband; 2529d9945d78SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 25303dd98026SBjoern A. Zeeb struct ieee80211com *ic; 2531d9945d78SBjoern A. Zeeb const struct ieee80211_channel *chan; 2532d9945d78SBjoern A. Zeeb const struct ieee80211_rateset *rs; 2533d9945d78SBjoern A. Zeeb uint8_t *pb; 2534d9945d78SBjoern A. Zeeb int band, i; 25356b4cac81SBjoern A. Zeeb 25363dd98026SBjoern A. Zeeb ic = vap->iv_ic; 2537d9945d78SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 2538d9945d78SBjoern A. Zeeb if ((band_mask & (1 << band)) == 0) 2539d9945d78SBjoern A. Zeeb continue; 2540d9945d78SBjoern A. Zeeb 2541d9945d78SBjoern A. Zeeb supband = hw->wiphy->bands[band]; 2542d9945d78SBjoern A. Zeeb /* 2543d9945d78SBjoern A. Zeeb * This should not happen; 2544d9945d78SBjoern A. Zeeb * band_mask is a bitmask of valid bands to scan on. 2545d9945d78SBjoern A. Zeeb */ 2546d9945d78SBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 2547d9945d78SBjoern A. Zeeb continue; 2548d9945d78SBjoern A. Zeeb 2549d9945d78SBjoern A. Zeeb /* Find a first channel to get the mode and rates from. */ 2550d9945d78SBjoern A. Zeeb channels = supband->channels; 2551d9945d78SBjoern A. Zeeb chan = NULL; 2552d9945d78SBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 2553d9945d78SBjoern A. Zeeb 2554d9945d78SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) 2555d9945d78SBjoern A. Zeeb continue; 2556d9945d78SBjoern A. Zeeb 25573dd98026SBjoern A. Zeeb chan = ieee80211_find_channel(ic, 2558d9945d78SBjoern A. Zeeb channels[i].center_freq, 0); 2559d9945d78SBjoern A. Zeeb if (chan != NULL) 2560d9945d78SBjoern A. Zeeb break; 2561d9945d78SBjoern A. Zeeb } 2562d9945d78SBjoern A. Zeeb 2563d9945d78SBjoern A. Zeeb /* This really should not happen. */ 2564d9945d78SBjoern A. Zeeb if (chan == NULL) 2565d9945d78SBjoern A. Zeeb continue; 2566d9945d78SBjoern A. Zeeb 2567d9945d78SBjoern A. Zeeb pb = p; 25683dd98026SBjoern A. Zeeb rs = ieee80211_get_suprates(ic, chan); /* calls chan2mode */ 2569d9945d78SBjoern A. Zeeb p = ieee80211_add_rates(p, rs); 2570d9945d78SBjoern A. Zeeb p = ieee80211_add_xrates(p, rs); 2571d9945d78SBjoern A. Zeeb 25723dd98026SBjoern A. Zeeb #if defined(LKPI_80211_HT) 25733dd98026SBjoern A. Zeeb if ((vap->iv_flags_ht & IEEE80211_FHT_HT) != 0) { 25743dd98026SBjoern A. Zeeb struct ieee80211_channel *c; 25753dd98026SBjoern A. Zeeb 25763dd98026SBjoern A. Zeeb c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan, 25773dd98026SBjoern A. Zeeb vap->iv_flags_ht); 25783dd98026SBjoern A. Zeeb p = ieee80211_add_htcap_ch(p, vap, c); 25793dd98026SBjoern A. Zeeb } 25803dd98026SBjoern A. Zeeb #endif 25813dd98026SBjoern A. Zeeb #if defined(LKPI_80211_VHT) 25823dd98026SBjoern A. Zeeb if ((vap->iv_vht_flags & IEEE80211_FVHT_VHT) != 0) { 25833dd98026SBjoern A. Zeeb struct ieee80211_channel *c; 25843dd98026SBjoern A. Zeeb 25853dd98026SBjoern A. Zeeb c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan, 25863dd98026SBjoern A. Zeeb vap->iv_flags_ht); 25873dd98026SBjoern A. Zeeb c = ieee80211_vht_adjust_channel(ic, c, 25883dd98026SBjoern A. Zeeb vap->iv_vht_flags); 25893dd98026SBjoern A. Zeeb p = ieee80211_add_vhtcap_ch(p, vap, c); 25903dd98026SBjoern A. Zeeb } 25913dd98026SBjoern A. Zeeb #endif 25923dd98026SBjoern A. Zeeb 2593d9945d78SBjoern A. Zeeb scan_ies->ies[band] = pb; 2594d9945d78SBjoern A. Zeeb scan_ies->len[band] = p - pb; 2595d9945d78SBjoern A. Zeeb } 2596d9945d78SBjoern A. Zeeb 2597d9945d78SBjoern A. Zeeb /* Add common_ies */ 2598d9945d78SBjoern A. Zeeb pb = p; 2599d9945d78SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WPA1) != 0 && 2600d9945d78SBjoern A. Zeeb vap->iv_wpa_ie != NULL) { 2601d9945d78SBjoern A. Zeeb memcpy(p, vap->iv_wpa_ie, 2 + vap->iv_wpa_ie[1]); 2602d9945d78SBjoern A. Zeeb p += 2 + vap->iv_wpa_ie[1]; 2603d9945d78SBjoern A. Zeeb } 2604d9945d78SBjoern A. Zeeb if (vap->iv_appie_probereq != NULL) { 2605d9945d78SBjoern A. Zeeb memcpy(p, vap->iv_appie_probereq->ie_data, 2606d9945d78SBjoern A. Zeeb vap->iv_appie_probereq->ie_len); 2607d9945d78SBjoern A. Zeeb p += vap->iv_appie_probereq->ie_len; 2608d9945d78SBjoern A. Zeeb } 2609d9945d78SBjoern A. Zeeb scan_ies->common_ies = pb; 2610d9945d78SBjoern A. Zeeb scan_ies->common_ie_len = p - pb; 2611d9945d78SBjoern A. Zeeb 2612d9945d78SBjoern A. Zeeb return (p); 26136b4cac81SBjoern A. Zeeb } 26146b4cac81SBjoern A. Zeeb 26156b4cac81SBjoern A. Zeeb static void 26166b4cac81SBjoern A. Zeeb lkpi_ic_scan_start(struct ieee80211com *ic) 26176b4cac81SBjoern A. Zeeb { 26186b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 26196b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 26206b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 26216b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 26226b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 26236b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 26246b4cac81SBjoern A. Zeeb int error; 2625*8ac540d3SBjoern A. Zeeb bool is_hw_scan; 26266b4cac81SBjoern A. Zeeb 26276b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 2628*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 2629a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) { 26306b4cac81SBjoern A. Zeeb /* A scan is still running. */ 2631*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 26326b4cac81SBjoern A. Zeeb return; 26336b4cac81SBjoern A. Zeeb } 2634*8ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 2635*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 26366b4cac81SBjoern A. Zeeb 26376b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 26386b4cac81SBjoern A. Zeeb vap = ss->ss_vap; 26396b4cac81SBjoern A. Zeeb if (vap->iv_state != IEEE80211_S_SCAN) { 2640d3ef7fb4SBjoern A. Zeeb IMPROVE("We need to be able to scan if not in S_SCAN"); 26416b4cac81SBjoern A. Zeeb return; 26426b4cac81SBjoern A. Zeeb } 26436b4cac81SBjoern A. Zeeb 26446b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 2645*8ac540d3SBjoern A. Zeeb if (!is_hw_scan) { 2646a486fbbdSBjoern A. Zeeb /* If hw_scan is cleared clear FEXT_SCAN_OFFLOAD too. */ 2647a486fbbdSBjoern A. Zeeb vap->iv_flags_ext &= ~IEEE80211_FEXT_SCAN_OFFLOAD; 2648d3ef7fb4SBjoern A. Zeeb sw_scan: 26496b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 26506b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 2651086be6a8SBjoern A. Zeeb 2652086be6a8SBjoern A. Zeeb if (vap->iv_state == IEEE80211_S_SCAN) 2653086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, false); 2654086be6a8SBjoern A. Zeeb 26556b4cac81SBjoern A. Zeeb lkpi_80211_mo_sw_scan_start(hw, vif, vif->addr); 26566b4cac81SBjoern A. Zeeb /* net80211::scan_start() handled PS for us. */ 26576b4cac81SBjoern A. Zeeb IMPROVE(); 26586b4cac81SBjoern A. Zeeb /* XXX Also means it is too late to flush queues? 26596b4cac81SBjoern A. Zeeb * need to check iv_sta_ps or overload? */ 26606b4cac81SBjoern A. Zeeb /* XXX want to adjust ss end time/ maxdwell? */ 26616b4cac81SBjoern A. Zeeb 26626b4cac81SBjoern A. Zeeb } else { 26636b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 26646b4cac81SBjoern A. Zeeb struct ieee80211_scan_request *hw_req; 26656b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *lc, **cpp; 26666b4cac81SBjoern A. Zeeb struct cfg80211_ssid *ssids; 26676b4cac81SBjoern A. Zeeb struct cfg80211_scan_6ghz_params *s6gp; 26686b4cac81SBjoern A. Zeeb size_t chan_len, nchan, ssids_len, s6ghzlen; 2669d9945d78SBjoern A. Zeeb int band, i, ssid_count, common_ie_len; 2670d9945d78SBjoern A. Zeeb uint32_t band_mask; 2671d9945d78SBjoern A. Zeeb uint8_t *ie, *ieend; 26726b4cac81SBjoern A. Zeeb 2673d9945d78SBjoern A. Zeeb if (!ieee80211_hw_check(hw, SINGLE_SCAN_ON_ALL_BANDS)) { 2674d9945d78SBjoern A. Zeeb IMPROVE("individual band scans not yet supported"); 2675d9945d78SBjoern A. Zeeb /* In theory net80211 would have to drive this. */ 2676d9945d78SBjoern A. Zeeb return; 2677d9945d78SBjoern A. Zeeb } 2678d9945d78SBjoern A. Zeeb 2679d9945d78SBjoern A. Zeeb ssid_count = min(ss->ss_nssid, hw->wiphy->max_scan_ssids); 2680d9945d78SBjoern A. Zeeb ssids_len = ssid_count * sizeof(*ssids); 26816b4cac81SBjoern A. Zeeb s6ghzlen = 0 * (sizeof(*s6gp)); /* XXX-BZ */ 26826b4cac81SBjoern A. Zeeb 2683d9945d78SBjoern A. Zeeb band_mask = 0; 26846b4cac81SBjoern A. Zeeb nchan = 0; 2685d9945d78SBjoern A. Zeeb for (i = ss->ss_next; i < ss->ss_last; i++) { 26866b4cac81SBjoern A. Zeeb nchan++; 2687d9945d78SBjoern A. Zeeb band = lkpi_net80211_chan_to_nl80211_band( 2688d9945d78SBjoern A. Zeeb ss->ss_chans[ss->ss_next + i]); 2689d9945d78SBjoern A. Zeeb band_mask |= (1 << band); 2690d9945d78SBjoern A. Zeeb } 26916b4cac81SBjoern A. Zeeb chan_len = nchan * (sizeof(lc) + sizeof(*lc)); 26926b4cac81SBjoern A. Zeeb 2693d9945d78SBjoern A. Zeeb common_ie_len = 0; 2694d9945d78SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WPA1) != 0 && 2695d9945d78SBjoern A. Zeeb vap->iv_wpa_ie != NULL) 2696d9945d78SBjoern A. Zeeb common_ie_len += vap->iv_wpa_ie[1]; 2697d9945d78SBjoern A. Zeeb if (vap->iv_appie_probereq != NULL) 2698d9945d78SBjoern A. Zeeb common_ie_len += vap->iv_appie_probereq->ie_len; 2699d9945d78SBjoern A. Zeeb 2700d9945d78SBjoern A. Zeeb /* We would love to check this at an earlier stage... */ 2701d9945d78SBjoern A. Zeeb if (common_ie_len > hw->wiphy->max_scan_ie_len) { 2702d9945d78SBjoern A. Zeeb ic_printf(ic, "WARNING: %s: common_ie_len %d > " 2703d9945d78SBjoern A. Zeeb "wiphy->max_scan_ie_len %d\n", __func__, 2704d9945d78SBjoern A. Zeeb common_ie_len, hw->wiphy->max_scan_ie_len); 2705d9945d78SBjoern A. Zeeb } 2706d9945d78SBjoern A. Zeeb 27076b4cac81SBjoern A. Zeeb KASSERT(lhw->hw_req == NULL, ("%s: ic %p lhw %p hw_req %p " 27086b4cac81SBjoern A. Zeeb "!= NULL\n", __func__, ic, lhw, lhw->hw_req)); 27096b4cac81SBjoern A. Zeeb 2710d9945d78SBjoern A. Zeeb lhw->hw_req = hw_req = malloc(sizeof(*hw_req) + ssids_len + 2711d9945d78SBjoern A. Zeeb s6ghzlen + chan_len + lhw->supbands * lhw->scan_ie_len + 2712d9945d78SBjoern A. Zeeb common_ie_len, M_LKPI80211, M_WAITOK | M_ZERO); 27136b4cac81SBjoern A. Zeeb 27146b4cac81SBjoern A. Zeeb hw_req->req.flags = 0; /* XXX ??? */ 27156b4cac81SBjoern A. Zeeb /* hw_req->req.wdev */ 27166b4cac81SBjoern A. Zeeb hw_req->req.wiphy = hw->wiphy; 27176b4cac81SBjoern A. Zeeb hw_req->req.no_cck = false; /* XXX */ 27186b4cac81SBjoern A. Zeeb #if 0 27196b4cac81SBjoern A. Zeeb /* This seems to pessimise default scanning behaviour. */ 27206b4cac81SBjoern A. Zeeb hw_req->req.duration_mandatory = TICKS_2_USEC(ss->ss_mindwell); 27216b4cac81SBjoern A. Zeeb hw_req->req.duration = TICKS_2_USEC(ss->ss_maxdwell); 27226b4cac81SBjoern A. Zeeb #endif 27236b4cac81SBjoern A. Zeeb #ifdef __notyet__ 27246b4cac81SBjoern A. Zeeb hw_req->req.flags |= NL80211_SCAN_FLAG_RANDOM_ADDR; 27256b4cac81SBjoern A. Zeeb memcpy(hw_req->req.mac_addr, xxx, IEEE80211_ADDR_LEN); 27266b4cac81SBjoern A. Zeeb memset(hw_req->req.mac_addr_mask, 0xxx, IEEE80211_ADDR_LEN); 27276b4cac81SBjoern A. Zeeb #endif 27286b4cac81SBjoern A. Zeeb 27296b4cac81SBjoern A. Zeeb hw_req->req.n_channels = nchan; 27306b4cac81SBjoern A. Zeeb cpp = (struct linuxkpi_ieee80211_channel **)(hw_req + 1); 27316b4cac81SBjoern A. Zeeb lc = (struct linuxkpi_ieee80211_channel *)(cpp + nchan); 27326b4cac81SBjoern A. Zeeb for (i = 0; i < nchan; i++) { 27336b4cac81SBjoern A. Zeeb *(cpp + i) = 27346b4cac81SBjoern A. Zeeb (struct linuxkpi_ieee80211_channel *)(lc + i); 27356b4cac81SBjoern A. Zeeb } 27366b4cac81SBjoern A. Zeeb for (i = 0; i < nchan; i++) { 27376b4cac81SBjoern A. Zeeb c = ss->ss_chans[ss->ss_next + i]; 27386b4cac81SBjoern A. Zeeb 27396b4cac81SBjoern A. Zeeb lc->hw_value = c->ic_ieee; 27406b4cac81SBjoern A. Zeeb lc->center_freq = c->ic_freq; 27416b4cac81SBjoern A. Zeeb /* lc->flags */ 27426b4cac81SBjoern A. Zeeb lc->band = lkpi_net80211_chan_to_nl80211_band(c); 27436b4cac81SBjoern A. Zeeb lc->max_power = c->ic_maxpower; 27446b4cac81SBjoern A. Zeeb /* lc-> ... */ 27456b4cac81SBjoern A. Zeeb lc++; 27466b4cac81SBjoern A. Zeeb } 27476b4cac81SBjoern A. Zeeb 2748d9945d78SBjoern A. Zeeb hw_req->req.n_ssids = ssid_count; 27496b4cac81SBjoern A. Zeeb if (hw_req->req.n_ssids > 0) { 27506b4cac81SBjoern A. Zeeb ssids = (struct cfg80211_ssid *)lc; 27516b4cac81SBjoern A. Zeeb hw_req->req.ssids = ssids; 2752d9945d78SBjoern A. Zeeb for (i = 0; i < ssid_count; i++) { 27536b4cac81SBjoern A. Zeeb ssids->ssid_len = ss->ss_ssid[i].len; 27546b4cac81SBjoern A. Zeeb memcpy(ssids->ssid, ss->ss_ssid[i].ssid, 27556b4cac81SBjoern A. Zeeb ss->ss_ssid[i].len); 27566b4cac81SBjoern A. Zeeb ssids++; 27576b4cac81SBjoern A. Zeeb } 27586b4cac81SBjoern A. Zeeb s6gp = (struct cfg80211_scan_6ghz_params *)ssids; 27596b4cac81SBjoern A. Zeeb } else { 27606b4cac81SBjoern A. Zeeb s6gp = (struct cfg80211_scan_6ghz_params *)lc; 27616b4cac81SBjoern A. Zeeb } 27626b4cac81SBjoern A. Zeeb 27636b4cac81SBjoern A. Zeeb /* 6GHz one day. */ 27646b4cac81SBjoern A. Zeeb hw_req->req.n_6ghz_params = 0; 27656b4cac81SBjoern A. Zeeb hw_req->req.scan_6ghz_params = NULL; 27666b4cac81SBjoern A. Zeeb hw_req->req.scan_6ghz = false; /* Weird boolean; not what you think. */ 27676b4cac81SBjoern A. Zeeb /* s6gp->... */ 27686b4cac81SBjoern A. Zeeb 2769d9945d78SBjoern A. Zeeb ie = ieend = (uint8_t *)s6gp; 2770d9945d78SBjoern A. Zeeb /* Copy per-band IEs, copy common IEs */ 2771d9945d78SBjoern A. Zeeb ieend = lkpi_scan_ies_add(ie, &hw_req->ies, band_mask, vap, hw); 2772d9945d78SBjoern A. Zeeb hw_req->req.ie = ie; 2773d9945d78SBjoern A. Zeeb hw_req->req.ie_len = ieend - ie; 2774d9945d78SBjoern A. Zeeb 27756b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 27766b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 27776b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_hw_scan(hw, vif, hw_req); 27786b4cac81SBjoern A. Zeeb if (error != 0) { 2779d9945d78SBjoern A. Zeeb ieee80211_cancel_scan(vap); 2780d9945d78SBjoern A. Zeeb 27816b4cac81SBjoern A. Zeeb free(hw_req, M_LKPI80211); 27826b4cac81SBjoern A. Zeeb lhw->hw_req = NULL; 2783d3ef7fb4SBjoern A. Zeeb 2784d3ef7fb4SBjoern A. Zeeb /* 2785d3ef7fb4SBjoern A. Zeeb * XXX-SIGH magic number. 2786d3ef7fb4SBjoern A. Zeeb * rtw88 has a magic "return 1" if offloading scan is 2787d3ef7fb4SBjoern A. Zeeb * not possible. Fall back to sw scan in that case. 2788d3ef7fb4SBjoern A. Zeeb */ 2789196cfd0bSBjoern A. Zeeb if (error == 1) { 2790*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 2791a486fbbdSBjoern A. Zeeb lhw->scan_flags &= ~LKPI_LHW_SCAN_HW; 2792*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 2793196cfd0bSBjoern A. Zeeb ieee80211_start_scan(vap, 2794196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_ACTIVE | 2795196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_NOPICK | 2796196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_ONCE, 2797196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_FOREVER, 2798196cfd0bSBjoern A. Zeeb ss->ss_mindwell ? ss->ss_mindwell : msecs_to_ticks(20), 2799196cfd0bSBjoern A. Zeeb ss->ss_maxdwell ? ss->ss_maxdwell : msecs_to_ticks(200), 2800196cfd0bSBjoern A. Zeeb vap->iv_des_nssid, vap->iv_des_ssid); 2801d3ef7fb4SBjoern A. Zeeb goto sw_scan; 2802196cfd0bSBjoern A. Zeeb } 2803d3ef7fb4SBjoern A. Zeeb 2804d3ef7fb4SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: hw_scan returned %d\n", 2805d3ef7fb4SBjoern A. Zeeb __func__, error); 28066b4cac81SBjoern A. Zeeb } 28076b4cac81SBjoern A. Zeeb } 28086b4cac81SBjoern A. Zeeb } 28096b4cac81SBjoern A. Zeeb 28106b4cac81SBjoern A. Zeeb static void 28116b4cac81SBjoern A. Zeeb lkpi_ic_scan_end(struct ieee80211com *ic) 28126b4cac81SBjoern A. Zeeb { 28136b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 2814*8ac540d3SBjoern A. Zeeb bool is_hw_scan; 28156b4cac81SBjoern A. Zeeb 28166b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 2817*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 2818a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) == 0) { 2819*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 28206b4cac81SBjoern A. Zeeb return; 28216b4cac81SBjoern A. Zeeb } 2822*8ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 2823*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 28246b4cac81SBjoern A. Zeeb 2825*8ac540d3SBjoern A. Zeeb if (!is_hw_scan) { 2826a486fbbdSBjoern A. Zeeb struct ieee80211_scan_state *ss; 2827a486fbbdSBjoern A. Zeeb struct ieee80211vap *vap; 28286b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 28296b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 28306b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 28316b4cac81SBjoern A. Zeeb 2832a486fbbdSBjoern A. Zeeb ss = ic->ic_scan; 2833a486fbbdSBjoern A. Zeeb vap = ss->ss_vap; 28346b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 28356b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 28366b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 2837a486fbbdSBjoern A. Zeeb 28386b4cac81SBjoern A. Zeeb lkpi_80211_mo_sw_scan_complete(hw, vif); 28396b4cac81SBjoern A. Zeeb 28406b4cac81SBjoern A. Zeeb /* Send PS to stop buffering if n80211 does not for us? */ 2841086be6a8SBjoern A. Zeeb 2842086be6a8SBjoern A. Zeeb if (vap->iv_state == IEEE80211_S_SCAN) 2843086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true); 28446b4cac81SBjoern A. Zeeb } 28456b4cac81SBjoern A. Zeeb } 28466b4cac81SBjoern A. Zeeb 28476b4cac81SBjoern A. Zeeb static void 2848a486fbbdSBjoern A. Zeeb lkpi_ic_scan_curchan(struct ieee80211_scan_state *ss, 2849a486fbbdSBjoern A. Zeeb unsigned long maxdwell) 2850a486fbbdSBjoern A. Zeeb { 2851a486fbbdSBjoern A. Zeeb struct lkpi_hw *lhw; 2852*8ac540d3SBjoern A. Zeeb bool is_hw_scan; 2853a486fbbdSBjoern A. Zeeb 2854a486fbbdSBjoern A. Zeeb lhw = ss->ss_ic->ic_softc; 2855*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 2856*8ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 2857*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 2858*8ac540d3SBjoern A. Zeeb if (!is_hw_scan) 2859a486fbbdSBjoern A. Zeeb lhw->ic_scan_curchan(ss, maxdwell); 2860a486fbbdSBjoern A. Zeeb } 2861a486fbbdSBjoern A. Zeeb 2862a486fbbdSBjoern A. Zeeb static void 2863a486fbbdSBjoern A. Zeeb lkpi_ic_scan_mindwell(struct ieee80211_scan_state *ss) 2864a486fbbdSBjoern A. Zeeb { 2865a486fbbdSBjoern A. Zeeb struct lkpi_hw *lhw; 2866*8ac540d3SBjoern A. Zeeb bool is_hw_scan; 2867a486fbbdSBjoern A. Zeeb 2868a486fbbdSBjoern A. Zeeb lhw = ss->ss_ic->ic_softc; 2869*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 2870*8ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 2871*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 2872*8ac540d3SBjoern A. Zeeb if (!is_hw_scan) 2873a486fbbdSBjoern A. Zeeb lhw->ic_scan_mindwell(ss); 2874a486fbbdSBjoern A. Zeeb } 2875a486fbbdSBjoern A. Zeeb 2876a486fbbdSBjoern A. Zeeb static void 28776b4cac81SBjoern A. Zeeb lkpi_ic_set_channel(struct ieee80211com *ic) 28786b4cac81SBjoern A. Zeeb { 28796b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 28806b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 2881b2cf3c21SBjoern A. Zeeb struct ieee80211_channel *c; 2882b2cf3c21SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 28836b4cac81SBjoern A. Zeeb int error; 2884*8ac540d3SBjoern A. Zeeb bool hw_scan_running; 28856b4cac81SBjoern A. Zeeb 28866b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 2887b2cf3c21SBjoern A. Zeeb 2888b2cf3c21SBjoern A. Zeeb /* If we do not support (*config)() save us the work. */ 2889b2cf3c21SBjoern A. Zeeb if (lhw->ops->config == NULL) 28906b4cac81SBjoern A. Zeeb return; 28916b4cac81SBjoern A. Zeeb 2892a486fbbdSBjoern A. Zeeb /* If we have a hw_scan running do not switch channels. */ 2893*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 2894*8ac540d3SBjoern A. Zeeb hw_scan_running = 2895*8ac540d3SBjoern A. Zeeb (lhw->scan_flags & (LKPI_LHW_SCAN_RUNNING|LKPI_LHW_SCAN_HW)) == 2896*8ac540d3SBjoern A. Zeeb (LKPI_LHW_SCAN_RUNNING|LKPI_LHW_SCAN_HW); 2897*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 2898*8ac540d3SBjoern A. Zeeb if (hw_scan_running) 2899a486fbbdSBjoern A. Zeeb return; 2900a486fbbdSBjoern A. Zeeb 2901b2cf3c21SBjoern A. Zeeb c = ic->ic_curchan; 2902b2cf3c21SBjoern A. Zeeb if (c == NULL || c == IEEE80211_CHAN_ANYC) { 29036b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: c %p ops->config %p\n", __func__, 29046b4cac81SBjoern A. Zeeb c, lhw->ops->config); 29056b4cac81SBjoern A. Zeeb return; 29066b4cac81SBjoern A. Zeeb } 29076b4cac81SBjoern A. Zeeb 29086b4cac81SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, c); 29096b4cac81SBjoern A. Zeeb if (chan == NULL) { 29106b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: c %p chan %p\n", __func__, 29116b4cac81SBjoern A. Zeeb c, chan); 29126b4cac81SBjoern A. Zeeb return; 29136b4cac81SBjoern A. Zeeb } 29146b4cac81SBjoern A. Zeeb 29156b4cac81SBjoern A. Zeeb /* XXX max power for scanning? */ 29166b4cac81SBjoern A. Zeeb IMPROVE(); 29176b4cac81SBjoern A. Zeeb 29186b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 29194a07abdeSBjoern A. Zeeb cfg80211_chandef_create(&hw->conf.chandef, chan, 29204a07abdeSBjoern A. Zeeb NL80211_CHAN_NO_HT); 29216b4cac81SBjoern A. Zeeb 29226b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_CHANNEL); 29236b4cac81SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) { 29246b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: config %#0x returned %d\n", 29256b4cac81SBjoern A. Zeeb __func__, IEEE80211_CONF_CHANGE_CHANNEL, error); 29266b4cac81SBjoern A. Zeeb /* XXX should we unroll to the previous chandef? */ 29276b4cac81SBjoern A. Zeeb IMPROVE(); 29286b4cac81SBjoern A. Zeeb } else { 29296b4cac81SBjoern A. Zeeb /* Update radiotap channels as well. */ 29306b4cac81SBjoern A. Zeeb lhw->rtap_tx.wt_chan_freq = htole16(c->ic_freq); 29316b4cac81SBjoern A. Zeeb lhw->rtap_tx.wt_chan_flags = htole16(c->ic_flags); 29326b4cac81SBjoern A. Zeeb lhw->rtap_rx.wr_chan_freq = htole16(c->ic_freq); 29336b4cac81SBjoern A. Zeeb lhw->rtap_rx.wr_chan_flags = htole16(c->ic_flags); 29346b4cac81SBjoern A. Zeeb } 29356b4cac81SBjoern A. Zeeb 29366b4cac81SBjoern A. Zeeb /* Currently PS is hard coded off! Not sure it belongs here. */ 29376b4cac81SBjoern A. Zeeb IMPROVE(); 29386b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, SUPPORTS_PS) && 29396b4cac81SBjoern A. Zeeb (hw->conf.flags & IEEE80211_CONF_PS) != 0) { 29406b4cac81SBjoern A. Zeeb hw->conf.flags &= ~IEEE80211_CONF_PS; 29416b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_PS); 29426b4cac81SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) 29436b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: config %#0x returned " 29446b4cac81SBjoern A. Zeeb "%d\n", __func__, IEEE80211_CONF_CHANGE_PS, 29456b4cac81SBjoern A. Zeeb error); 29466b4cac81SBjoern A. Zeeb } 29476b4cac81SBjoern A. Zeeb } 29486b4cac81SBjoern A. Zeeb 29496b4cac81SBjoern A. Zeeb static struct ieee80211_node * 29506b4cac81SBjoern A. Zeeb lkpi_ic_node_alloc(struct ieee80211vap *vap, 29516b4cac81SBjoern A. Zeeb const uint8_t mac[IEEE80211_ADDR_LEN]) 29526b4cac81SBjoern A. Zeeb { 29536b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 29546b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 29554f61ef8bSBjoern A. Zeeb struct ieee80211_node *ni; 29566b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 29576b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 29586b4cac81SBjoern A. Zeeb 29596b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 29606b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 29616b4cac81SBjoern A. Zeeb 29626b4cac81SBjoern A. Zeeb /* We keep allocations de-coupled so we can deal with the two worlds. */ 29634f61ef8bSBjoern A. Zeeb if (lhw->ic_node_alloc == NULL) 29644f61ef8bSBjoern A. Zeeb return (NULL); 29654f61ef8bSBjoern A. Zeeb 29666b4cac81SBjoern A. Zeeb ni = lhw->ic_node_alloc(vap, mac); 29676b4cac81SBjoern A. Zeeb if (ni == NULL) 29686b4cac81SBjoern A. Zeeb return (NULL); 29696b4cac81SBjoern A. Zeeb 29706b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 29714f61ef8bSBjoern A. Zeeb lsta = lkpi_lsta_alloc(vap, mac, hw, ni); 29726b4cac81SBjoern A. Zeeb if (lsta == NULL) { 29736b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL) 29746b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni); 29756b4cac81SBjoern A. Zeeb return (NULL); 29766b4cac81SBjoern A. Zeeb } 29776b4cac81SBjoern A. Zeeb 29786b4cac81SBjoern A. Zeeb return (ni); 29796b4cac81SBjoern A. Zeeb } 29806b4cac81SBjoern A. Zeeb 29816b4cac81SBjoern A. Zeeb static int 29826b4cac81SBjoern A. Zeeb lkpi_ic_node_init(struct ieee80211_node *ni) 29836b4cac81SBjoern A. Zeeb { 29846b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 29856b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 29866b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 29876b4cac81SBjoern A. Zeeb int error; 29886b4cac81SBjoern A. Zeeb 29896b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 29906b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 29916b4cac81SBjoern A. Zeeb 29926b4cac81SBjoern A. Zeeb if (lhw->ic_node_init != NULL) { 29936b4cac81SBjoern A. Zeeb error = lhw->ic_node_init(ni); 29946b4cac81SBjoern A. Zeeb if (error != 0) 29956b4cac81SBjoern A. Zeeb return (error); 29966b4cac81SBjoern A. Zeeb } 29976b4cac81SBjoern A. Zeeb 29986b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 29996b4cac81SBjoern A. Zeeb 30006b4cac81SBjoern A. Zeeb /* Now take the reference before linking it to the table. */ 30016b4cac81SBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 30026b4cac81SBjoern A. Zeeb 30036b4cac81SBjoern A. Zeeb /* XXX-BZ Sync other state over. */ 30046b4cac81SBjoern A. Zeeb IMPROVE(); 30056b4cac81SBjoern A. Zeeb 30066b4cac81SBjoern A. Zeeb return (0); 30076b4cac81SBjoern A. Zeeb } 30086b4cac81SBjoern A. Zeeb 30096b4cac81SBjoern A. Zeeb static void 30106b4cac81SBjoern A. Zeeb lkpi_ic_node_cleanup(struct ieee80211_node *ni) 30116b4cac81SBjoern A. Zeeb { 30126b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 30136b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 30146b4cac81SBjoern A. Zeeb 30156b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 30166b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 30176b4cac81SBjoern A. Zeeb 30186b4cac81SBjoern A. Zeeb /* XXX-BZ remove from driver, ... */ 30196b4cac81SBjoern A. Zeeb IMPROVE(); 30206b4cac81SBjoern A. Zeeb 30216b4cac81SBjoern A. Zeeb if (lhw->ic_node_cleanup != NULL) 30226b4cac81SBjoern A. Zeeb lhw->ic_node_cleanup(ni); 30236b4cac81SBjoern A. Zeeb } 30246b4cac81SBjoern A. Zeeb 30256b4cac81SBjoern A. Zeeb static void 30266b4cac81SBjoern A. Zeeb lkpi_ic_node_free(struct ieee80211_node *ni) 30276b4cac81SBjoern A. Zeeb { 30286b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 30296b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 30306b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 30316b4cac81SBjoern A. Zeeb 30326b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 30336b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 30346b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 3035d9f59799SBjoern A. Zeeb if (lsta == NULL) 3036d9f59799SBjoern A. Zeeb goto out; 30376b4cac81SBjoern A. Zeeb 30386b4cac81SBjoern A. Zeeb /* XXX-BZ free resources, ... */ 30396b4cac81SBjoern A. Zeeb IMPROVE(); 30406b4cac81SBjoern A. Zeeb 30416b4cac81SBjoern A. Zeeb /* Flush mbufq (make sure to release ni refs!). */ 30426b4cac81SBjoern A. Zeeb #ifdef __notyet__ 30436b4cac81SBjoern A. Zeeb KASSERT(mbufq_len(&lsta->txq) == 0, ("%s: lsta %p has txq len %d != 0\n", 30446b4cac81SBjoern A. Zeeb __func__, lsta, mbufq_len(&lsta->txq))); 30456b4cac81SBjoern A. Zeeb #endif 30466b4cac81SBjoern A. Zeeb /* Drain taskq. */ 30476b4cac81SBjoern A. Zeeb 30486b4cac81SBjoern A. Zeeb /* Drain sta->txq[] */ 30496b4cac81SBjoern A. Zeeb mtx_destroy(&lsta->txq_mtx); 30506b4cac81SBjoern A. Zeeb 30516b4cac81SBjoern A. Zeeb /* Remove lsta if added_to_drv. */ 3052e24e8103SBjoern A. Zeeb 30536b4cac81SBjoern A. Zeeb /* Remove lsta from vif */ 3054e24e8103SBjoern A. Zeeb /* Remove ref from lsta node... */ 3055d9f59799SBjoern A. Zeeb /* Free lsta. */ 3056e24e8103SBjoern A. Zeeb lkpi_lsta_remove(lsta, VAP_TO_LVIF(ni->ni_vap)); 3057d9f59799SBjoern A. Zeeb 3058d9f59799SBjoern A. Zeeb out: 30596b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL) 30606b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni); 30616b4cac81SBjoern A. Zeeb } 30626b4cac81SBjoern A. Zeeb 30636b4cac81SBjoern A. Zeeb static int 30646b4cac81SBjoern A. Zeeb lkpi_ic_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, 30656b4cac81SBjoern A. Zeeb const struct ieee80211_bpf_params *params __unused) 30666b4cac81SBjoern A. Zeeb { 30676b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 30686b4cac81SBjoern A. Zeeb 30696b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 30706b4cac81SBjoern A. Zeeb 30716b4cac81SBjoern A. Zeeb /* Queue the packet and enqueue the task to handle it. */ 30726b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_LOCK(lsta); 30736b4cac81SBjoern A. Zeeb mbufq_enqueue(&lsta->txq, m); 30746b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_UNLOCK(lsta); 30756b4cac81SBjoern A. Zeeb 30769d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 30779d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 30786b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p ni %p %6D mbuf_qlen %d\n", 30796b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, ni, ni->ni_macaddr, ":", 30806b4cac81SBjoern A. Zeeb mbufq_len(&lsta->txq)); 30819d9ba2b7SBjoern A. Zeeb #endif 30826b4cac81SBjoern A. Zeeb 30836b4cac81SBjoern A. Zeeb taskqueue_enqueue(taskqueue_thread, &lsta->txq_task); 30846b4cac81SBjoern A. Zeeb return (0); 30856b4cac81SBjoern A. Zeeb } 30866b4cac81SBjoern A. Zeeb 30876b4cac81SBjoern A. Zeeb static void 30886b4cac81SBjoern A. Zeeb lkpi_80211_txq_tx_one(struct lkpi_sta *lsta, struct mbuf *m) 30896b4cac81SBjoern A. Zeeb { 30906b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 3091b35f6cd0SBjoern A. Zeeb #ifndef LKPI_80211_HW_CRYPTO 30926b4cac81SBjoern A. Zeeb struct ieee80211_frame *wh; 3093b35f6cd0SBjoern A. Zeeb #endif 30946b4cac81SBjoern A. Zeeb struct ieee80211_key *k; 30956b4cac81SBjoern A. Zeeb struct sk_buff *skb; 30966b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 30976b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 30986b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 30996b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 31006b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 31016b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 31026b4cac81SBjoern A. Zeeb struct ieee80211_tx_control control; 31036b4cac81SBjoern A. Zeeb struct ieee80211_tx_info *info; 31046b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 3105e3a0b120SBjoern A. Zeeb struct ieee80211_hdr *hdr; 31066b4cac81SBjoern A. Zeeb void *buf; 3107e3a0b120SBjoern A. Zeeb uint8_t ac, tid; 31086b4cac81SBjoern A. Zeeb 31096b4cac81SBjoern A. Zeeb M_ASSERTPKTHDR(m); 31106b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 31119d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX_DUMP) 31126b4cac81SBjoern A. Zeeb hexdump(mtod(m, const void *), m->m_len, "RAW TX (plain) ", 0); 31136b4cac81SBjoern A. Zeeb #endif 31146b4cac81SBjoern A. Zeeb 31156b4cac81SBjoern A. Zeeb ni = lsta->ni; 3116b35f6cd0SBjoern A. Zeeb k = NULL; 3117b35f6cd0SBjoern A. Zeeb #ifndef LKPI_80211_HW_CRYPTO 31186b4cac81SBjoern A. Zeeb /* Encrypt the frame if need be; XXX-BZ info->control.hw_key. */ 31196b4cac81SBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame *); 31206b4cac81SBjoern A. Zeeb if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { 31216b4cac81SBjoern A. Zeeb /* Retrieve key for TX && do software encryption. */ 31226b4cac81SBjoern A. Zeeb k = ieee80211_crypto_encap(ni, m); 31236b4cac81SBjoern A. Zeeb if (k == NULL) { 31246b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 31256b4cac81SBjoern A. Zeeb m_freem(m); 31266b4cac81SBjoern A. Zeeb return; 31276b4cac81SBjoern A. Zeeb } 31286b4cac81SBjoern A. Zeeb } 31296b4cac81SBjoern A. Zeeb #endif 31306b4cac81SBjoern A. Zeeb 31316b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 31326b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 31336b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 31346b4cac81SBjoern A. Zeeb c = ni->ni_chan; 31356b4cac81SBjoern A. Zeeb 31366b4cac81SBjoern A. Zeeb if (ieee80211_radiotap_active_vap(ni->ni_vap)) { 31376b4cac81SBjoern A. Zeeb struct lkpi_radiotap_tx_hdr *rtap; 31386b4cac81SBjoern A. Zeeb 31396b4cac81SBjoern A. Zeeb rtap = &lhw->rtap_tx; 31406b4cac81SBjoern A. Zeeb rtap->wt_flags = 0; 31416b4cac81SBjoern A. Zeeb if (k != NULL) 31426b4cac81SBjoern A. Zeeb rtap->wt_flags |= IEEE80211_RADIOTAP_F_WEP; 31436b4cac81SBjoern A. Zeeb if (m->m_flags & M_FRAG) 31446b4cac81SBjoern A. Zeeb rtap->wt_flags |= IEEE80211_RADIOTAP_F_FRAG; 31456b4cac81SBjoern A. Zeeb IMPROVE(); 31466b4cac81SBjoern A. Zeeb rtap->wt_rate = 0; 31476b4cac81SBjoern A. Zeeb if (c != NULL && c != IEEE80211_CHAN_ANYC) { 31486b4cac81SBjoern A. Zeeb rtap->wt_chan_freq = htole16(c->ic_freq); 31496b4cac81SBjoern A. Zeeb rtap->wt_chan_flags = htole16(c->ic_flags); 31506b4cac81SBjoern A. Zeeb } 31516b4cac81SBjoern A. Zeeb 31526b4cac81SBjoern A. Zeeb ieee80211_radiotap_tx(ni->ni_vap, m); 31536b4cac81SBjoern A. Zeeb } 31546b4cac81SBjoern A. Zeeb 31556b4cac81SBjoern A. Zeeb /* 31566b4cac81SBjoern A. Zeeb * net80211 should handle hw->extra_tx_headroom. 31576b4cac81SBjoern A. Zeeb * Though for as long as we are copying we don't mind. 31583d09d310SBjoern A. Zeeb * XXX-BZ rtw88 asks for too much headroom for ipv6+tcp: 31593d09d310SBjoern A. Zeeb * https://lists.freebsd.org/archives/freebsd-transport/2022-February/000012.html 31606b4cac81SBjoern A. Zeeb */ 31616b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + m->m_pkthdr.len); 31626b4cac81SBjoern A. Zeeb if (skb == NULL) { 31633f0083c4SBjoern A. Zeeb ic_printf(ic, "ERROR %s: skb alloc failed\n", __func__); 31646b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 31656b4cac81SBjoern A. Zeeb m_freem(m); 31666b4cac81SBjoern A. Zeeb return; 31676b4cac81SBjoern A. Zeeb } 31686b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 31696b4cac81SBjoern A. Zeeb 31706b4cac81SBjoern A. Zeeb /* XXX-BZ we need a SKB version understanding mbuf. */ 31716b4cac81SBjoern A. Zeeb /* Save the mbuf for ieee80211_tx_complete(). */ 31726b4cac81SBjoern A. Zeeb skb->m_free_func = lkpi_ieee80211_free_skb_mbuf; 31736b4cac81SBjoern A. Zeeb skb->m = m; 31746b4cac81SBjoern A. Zeeb #if 0 31756b4cac81SBjoern A. Zeeb skb_put_data(skb, m->m_data, m->m_pkthdr.len); 31766b4cac81SBjoern A. Zeeb #else 31776b4cac81SBjoern A. Zeeb buf = skb_put(skb, m->m_pkthdr.len); 31786b4cac81SBjoern A. Zeeb m_copydata(m, 0, m->m_pkthdr.len, buf); 31796b4cac81SBjoern A. Zeeb #endif 31806b4cac81SBjoern A. Zeeb /* Save the ni. */ 31816b4cac81SBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = ni; 31826b4cac81SBjoern A. Zeeb 31836b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(ni->ni_vap); 31846b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 31856b4cac81SBjoern A. Zeeb 3186e3a0b120SBjoern A. Zeeb hdr = (void *)skb->data; 3187e3a0b120SBjoern A. Zeeb tid = linuxkpi_ieee80211_get_tid(hdr, true); 3188e3a0b120SBjoern A. Zeeb if (tid == IEEE80211_NONQOS_TID) { /* == IEEE80211_NUM_TIDS */ 3189e3a0b120SBjoern A. Zeeb skb->priority = 0; 3190e3a0b120SBjoern A. Zeeb ac = IEEE80211_AC_BE; 3191e3a0b120SBjoern A. Zeeb } else { 3192e3a0b120SBjoern A. Zeeb skb->priority = tid & IEEE80211_QOS_CTL_TID_MASK; 3193e3a0b120SBjoern A. Zeeb ac = tid_to_mac80211_ac[tid & 7]; 3194e3a0b120SBjoern A. Zeeb } 31956b4cac81SBjoern A. Zeeb skb_set_queue_mapping(skb, ac); 31966b4cac81SBjoern A. Zeeb 31976b4cac81SBjoern A. Zeeb info = IEEE80211_SKB_CB(skb); 31986b4cac81SBjoern A. Zeeb info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; 31996b4cac81SBjoern A. Zeeb /* Slight delay; probably only happens on scanning so fine? */ 32006b4cac81SBjoern A. Zeeb if (c == NULL || c == IEEE80211_CHAN_ANYC) 32016b4cac81SBjoern A. Zeeb c = ic->ic_curchan; 32026b4cac81SBjoern A. Zeeb info->band = lkpi_net80211_chan_to_nl80211_band(c); 3203e3a0b120SBjoern A. Zeeb info->hw_queue = vif->hw_queue[ac]; 32046b4cac81SBjoern A. Zeeb if (m->m_flags & M_EAPOL) 32056b4cac81SBjoern A. Zeeb info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO; 32066b4cac81SBjoern A. Zeeb info->control.vif = vif; 32076b4cac81SBjoern A. Zeeb /* XXX-BZ info->control.rates */ 32086b4cac81SBjoern A. Zeeb 32096b4cac81SBjoern A. Zeeb lsta = lkpi_find_lsta_by_ni(lvif, ni); 32106b4cac81SBjoern A. Zeeb if (lsta != NULL) { 32116b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 3212b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 32136b4cac81SBjoern A. Zeeb info->control.hw_key = lsta->kc; 32146b4cac81SBjoern A. Zeeb #endif 32156b4cac81SBjoern A. Zeeb } else { 32166b4cac81SBjoern A. Zeeb sta = NULL; 32176b4cac81SBjoern A. Zeeb } 32186b4cac81SBjoern A. Zeeb 32196b4cac81SBjoern A. Zeeb IMPROVE(); 32206b4cac81SBjoern A. Zeeb 32216b4cac81SBjoern A. Zeeb if (sta != NULL) { 32226b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 32236b4cac81SBjoern A. Zeeb 3224e3a0b120SBjoern A. Zeeb ltxq = NULL; 3225e3a0b120SBjoern A. Zeeb if (!ieee80211_is_data_present(hdr->frame_control)) { 3226e3a0b120SBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_STATION && 3227e3a0b120SBjoern A. Zeeb lsta->added_to_drv && 3228e3a0b120SBjoern A. Zeeb sta->txq[IEEE80211_NUM_TIDS] != NULL) 3229d0d29110SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[IEEE80211_NUM_TIDS]); 3230e3a0b120SBjoern A. Zeeb } else if (lsta->added_to_drv && 3231e3a0b120SBjoern A. Zeeb sta->txq[skb->priority] != NULL) { 3232e3a0b120SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[skb->priority]); 3233e3a0b120SBjoern A. Zeeb } 3234e3a0b120SBjoern A. Zeeb if (ltxq == NULL) 3235d0d29110SBjoern A. Zeeb goto ops_tx; 3236e3a0b120SBjoern A. Zeeb 3237d0d29110SBjoern A. Zeeb KASSERT(ltxq != NULL, ("%s: lsta %p sta %p m %p skb %p " 3238d0d29110SBjoern A. Zeeb "ltxq %p != NULL\n", __func__, lsta, sta, m, skb, ltxq)); 3239d0d29110SBjoern A. Zeeb 32406b4cac81SBjoern A. Zeeb skb_queue_tail(<xq->skbq, skb); 32419d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 32429d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 3243d0d29110SBjoern A. Zeeb printf("%s:%d mo_wake_tx_queue :: %d %u lsta %p sta %p " 3244d0d29110SBjoern A. Zeeb "ni %p %6D skb %p lxtq %p { qlen %u, ac %d tid %u } " 3245d0d29110SBjoern A. Zeeb "WAKE_TX_Q ac %d prio %u qmap %u\n", 3246fb6eaf74SBjoern A. Zeeb __func__, __LINE__, 3247d0d29110SBjoern A. Zeeb curthread->td_tid, (unsigned int)ticks, 3248d0d29110SBjoern A. Zeeb lsta, sta, ni, ni->ni_macaddr, ":", skb, ltxq, 3249d0d29110SBjoern A. Zeeb skb_queue_len(<xq->skbq), ltxq->txq.ac, 3250d0d29110SBjoern A. Zeeb ltxq->txq.tid, ac, skb->priority, skb->qmap); 32519d9ba2b7SBjoern A. Zeeb #endif 3252d0d29110SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, <xq->txq); 32536b4cac81SBjoern A. Zeeb return; 32546b4cac81SBjoern A. Zeeb } 32556b4cac81SBjoern A. Zeeb 32566b4cac81SBjoern A. Zeeb ops_tx: 32579d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 32589d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 3259d0d29110SBjoern A. Zeeb printf("%s:%d mo_tx :: lsta %p sta %p ni %p %6D skb %p " 3260d0d29110SBjoern A. Zeeb "TX ac %d prio %u qmap %u\n", 32616b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, sta, ni, ni->ni_macaddr, ":", 32626b4cac81SBjoern A. Zeeb skb, ac, skb->priority, skb->qmap); 32639d9ba2b7SBjoern A. Zeeb #endif 32646b4cac81SBjoern A. Zeeb memset(&control, 0, sizeof(control)); 32656b4cac81SBjoern A. Zeeb control.sta = sta; 32666b4cac81SBjoern A. Zeeb 32676b4cac81SBjoern A. Zeeb lkpi_80211_mo_tx(hw, &control, skb); 32686b4cac81SBjoern A. Zeeb return; 32696b4cac81SBjoern A. Zeeb } 32706b4cac81SBjoern A. Zeeb 32716b4cac81SBjoern A. Zeeb static void 32726b4cac81SBjoern A. Zeeb lkpi_80211_txq_task(void *ctx, int pending) 32736b4cac81SBjoern A. Zeeb { 32746b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 32756b4cac81SBjoern A. Zeeb struct mbufq mq; 32766b4cac81SBjoern A. Zeeb struct mbuf *m; 32776b4cac81SBjoern A. Zeeb 32786b4cac81SBjoern A. Zeeb lsta = ctx; 32796b4cac81SBjoern A. Zeeb 32809d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 32819d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 32826b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p ni %p %6D pending %d mbuf_qlen %d\n", 32839d9ba2b7SBjoern A. Zeeb __func__, __LINE__, lsta, lsta->ni, lsta->ni->ni_macaddr, ":", 32846b4cac81SBjoern A. Zeeb pending, mbufq_len(&lsta->txq)); 32859d9ba2b7SBjoern A. Zeeb #endif 32866b4cac81SBjoern A. Zeeb 32876b4cac81SBjoern A. Zeeb mbufq_init(&mq, IFQ_MAXLEN); 32886b4cac81SBjoern A. Zeeb 32896b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_LOCK(lsta); 32906b4cac81SBjoern A. Zeeb mbufq_concat(&mq, &lsta->txq); 32916b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_UNLOCK(lsta); 32926b4cac81SBjoern A. Zeeb 32936b4cac81SBjoern A. Zeeb m = mbufq_dequeue(&mq); 32946b4cac81SBjoern A. Zeeb while (m != NULL) { 32956b4cac81SBjoern A. Zeeb lkpi_80211_txq_tx_one(lsta, m); 32966b4cac81SBjoern A. Zeeb m = mbufq_dequeue(&mq); 32976b4cac81SBjoern A. Zeeb } 32986b4cac81SBjoern A. Zeeb } 32996b4cac81SBjoern A. Zeeb 33006b4cac81SBjoern A. Zeeb static int 33016b4cac81SBjoern A. Zeeb lkpi_ic_transmit(struct ieee80211com *ic, struct mbuf *m) 33026b4cac81SBjoern A. Zeeb { 33036b4cac81SBjoern A. Zeeb 33046b4cac81SBjoern A. Zeeb /* XXX TODO */ 33056b4cac81SBjoern A. Zeeb IMPROVE(); 33066b4cac81SBjoern A. Zeeb 33076b4cac81SBjoern A. Zeeb /* Quick and dirty cheating hack. */ 33086b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 33096b4cac81SBjoern A. Zeeb 33106b4cac81SBjoern A. Zeeb ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; 33116b4cac81SBjoern A. Zeeb return (lkpi_ic_raw_xmit(ni, m, NULL)); 33126b4cac81SBjoern A. Zeeb } 33136b4cac81SBjoern A. Zeeb 33146b4cac81SBjoern A. Zeeb static void 33156b4cac81SBjoern A. Zeeb lkpi_ic_getradiocaps(struct ieee80211com *ic, int maxchan, 33166b4cac81SBjoern A. Zeeb int *n, struct ieee80211_channel *c) 33176b4cac81SBjoern A. Zeeb { 33186b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 33196b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 33206b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 33216b4cac81SBjoern A. Zeeb uint8_t bands[IEEE80211_MODE_BYTES]; 33226b4cac81SBjoern A. Zeeb int chan_flags, error, i, nchans; 33236b4cac81SBjoern A. Zeeb 33246b4cac81SBjoern A. Zeeb /* Channels */ 33256b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 33266b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 33276b4cac81SBjoern A. Zeeb 33286b4cac81SBjoern A. Zeeb /* NL80211_BAND_2GHZ */ 33296b4cac81SBjoern A. Zeeb nchans = 0; 33306b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_2GHZ] != NULL) 33316b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[NL80211_BAND_2GHZ]->n_channels; 33326b4cac81SBjoern A. Zeeb if (nchans > 0) { 33336b4cac81SBjoern A. Zeeb memset(bands, 0, sizeof(bands)); 33346b4cac81SBjoern A. Zeeb chan_flags = 0; 33356b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11B); 33366b4cac81SBjoern A. Zeeb /* XXX-BZ unclear how to check for 11g. */ 33376b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11G); 33386b4cac81SBjoern A. Zeeb #ifdef __notyet__ 33396b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_2GHZ]->ht_cap.ht_supported) { 33406b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11NG); 33416b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_HT40; 33426b4cac81SBjoern A. Zeeb } 33436b4cac81SBjoern A. Zeeb #endif 33446b4cac81SBjoern A. Zeeb 33456b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[NL80211_BAND_2GHZ]->channels; 3346cee56e77SBjoern A. Zeeb for (i = 0; i < nchans && *n < maxchan; i++) { 33476b4cac81SBjoern A. Zeeb uint32_t nflags = 0; 33486b4cac81SBjoern A. Zeeb int cflags = chan_flags; 33496b4cac81SBjoern A. Zeeb 33506b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) { 33513f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Skipping disabled chan " 33523f0083c4SBjoern A. Zeeb "[%u/%u/%#x]\n", __func__, 33536b4cac81SBjoern A. Zeeb channels[i].hw_value, 33546b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags); 33556b4cac81SBjoern A. Zeeb continue; 33566b4cac81SBjoern A. Zeeb } 33576b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_IR) 33586b4cac81SBjoern A. Zeeb nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE); 33596b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_RADAR) 33606b4cac81SBjoern A. Zeeb nflags |= IEEE80211_CHAN_DFS; 33616b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ) 33626b4cac81SBjoern A. Zeeb cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80); 33636b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ) 33646b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_VHT80; 33656b4cac81SBjoern A. Zeeb /* XXX how to map the remaining enum ieee80211_channel_flags? */ 33666b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_HT40) 33676b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_HT40; 33686b4cac81SBjoern A. Zeeb 33696b4cac81SBjoern A. Zeeb error = ieee80211_add_channel_cbw(c, maxchan, n, 33706b4cac81SBjoern A. Zeeb channels[i].hw_value, channels[i].center_freq, 33716b4cac81SBjoern A. Zeeb channels[i].max_power, 33726b4cac81SBjoern A. Zeeb nflags, bands, chan_flags); 3373cee56e77SBjoern A. Zeeb /* net80211::ENOBUFS: *n >= maxchans */ 3374cee56e77SBjoern A. Zeeb if (error != 0 && error != ENOBUFS) 33753f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Adding chan %u/%u/%#x/%#x/%#x/%#x " 33763f0083c4SBjoern A. Zeeb "returned error %d\n", 33776b4cac81SBjoern A. Zeeb __func__, channels[i].hw_value, 33786b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags, 33796b4cac81SBjoern A. Zeeb nflags, chan_flags, cflags, error); 3380cee56e77SBjoern A. Zeeb if (error != 0) 33816b4cac81SBjoern A. Zeeb break; 33826b4cac81SBjoern A. Zeeb } 33836b4cac81SBjoern A. Zeeb } 33846b4cac81SBjoern A. Zeeb 33856b4cac81SBjoern A. Zeeb /* NL80211_BAND_5GHZ */ 33866b4cac81SBjoern A. Zeeb nchans = 0; 33876b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ] != NULL) 33886b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[NL80211_BAND_5GHZ]->n_channels; 33896b4cac81SBjoern A. Zeeb if (nchans > 0) { 33906b4cac81SBjoern A. Zeeb memset(bands, 0, sizeof(bands)); 33916b4cac81SBjoern A. Zeeb chan_flags = 0; 33926b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11A); 33936b4cac81SBjoern A. Zeeb #ifdef __not_yet__ 33946b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ]->ht_cap.ht_supported) { 33956b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11NA); 33966b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_HT40; 33976b4cac81SBjoern A. Zeeb } 33986b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.vht_supported){ 33996b4cac81SBjoern A. Zeeb 34006b4cac81SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_VHT; 34016b4cac81SBjoern A. Zeeb ic->ic_vhtcaps = 34026b4cac81SBjoern A. Zeeb hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap; 34036b4cac81SBjoern A. Zeeb 34046b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_VHT_5GHZ); 34056b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT80; 34066b4cac81SBjoern A. Zeeb if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160MHZ( 34076b4cac81SBjoern A. Zeeb ic->ic_vhtcaps)) 34086b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT160; 34096b4cac81SBjoern A. Zeeb if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160_80P80MHZ( 34106b4cac81SBjoern A. Zeeb ic->ic_vhtcaps)) 34116b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT80P80; 34126b4cac81SBjoern A. Zeeb } 34136b4cac81SBjoern A. Zeeb #endif 34146b4cac81SBjoern A. Zeeb 34156b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[NL80211_BAND_5GHZ]->channels; 3416cee56e77SBjoern A. Zeeb for (i = 0; i < nchans && *n < maxchan; i++) { 34176b4cac81SBjoern A. Zeeb uint32_t nflags = 0; 34186b4cac81SBjoern A. Zeeb int cflags = chan_flags; 34196b4cac81SBjoern A. Zeeb 34206b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) { 34213f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Skipping disabled chan " 34223f0083c4SBjoern A. Zeeb "[%u/%u/%#x]\n", __func__, 34236b4cac81SBjoern A. Zeeb channels[i].hw_value, 34246b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags); 34256b4cac81SBjoern A. Zeeb continue; 34266b4cac81SBjoern A. Zeeb } 34276b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_IR) 34286b4cac81SBjoern A. Zeeb nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE); 34296b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_RADAR) 34306b4cac81SBjoern A. Zeeb nflags |= IEEE80211_CHAN_DFS; 34316b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ) 34326b4cac81SBjoern A. Zeeb cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80); 34336b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ) 34346b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_VHT80; 34356b4cac81SBjoern A. Zeeb /* XXX hwo to map the remaining enum ieee80211_channel_flags? */ 34366b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_HT40) 34376b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_HT40; 34386b4cac81SBjoern A. Zeeb 34396b4cac81SBjoern A. Zeeb error = ieee80211_add_channel_cbw(c, maxchan, n, 34406b4cac81SBjoern A. Zeeb channels[i].hw_value, channels[i].center_freq, 34416b4cac81SBjoern A. Zeeb channels[i].max_power, 34426b4cac81SBjoern A. Zeeb nflags, bands, chan_flags); 3443cee56e77SBjoern A. Zeeb /* net80211::ENOBUFS: *n >= maxchans */ 3444cee56e77SBjoern A. Zeeb if (error != 0 && error != ENOBUFS) 34453f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Adding chan %u/%u/%#x/%#x/%#x/%#x " 34463f0083c4SBjoern A. Zeeb "returned error %d\n", 34476b4cac81SBjoern A. Zeeb __func__, channels[i].hw_value, 34486b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags, 34496b4cac81SBjoern A. Zeeb nflags, chan_flags, cflags, error); 3450cee56e77SBjoern A. Zeeb if (error != 0) 34516b4cac81SBjoern A. Zeeb break; 34526b4cac81SBjoern A. Zeeb } 34536b4cac81SBjoern A. Zeeb } 34546b4cac81SBjoern A. Zeeb } 34556b4cac81SBjoern A. Zeeb 34566b4cac81SBjoern A. Zeeb static void * 34576b4cac81SBjoern A. Zeeb lkpi_ieee80211_ifalloc(void) 34586b4cac81SBjoern A. Zeeb { 34596b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 34606b4cac81SBjoern A. Zeeb 34616b4cac81SBjoern A. Zeeb ic = malloc(sizeof(*ic), M_LKPI80211, M_WAITOK | M_ZERO); 34626b4cac81SBjoern A. Zeeb if (ic == NULL) 34636b4cac81SBjoern A. Zeeb return (NULL); 34646b4cac81SBjoern A. Zeeb 34656b4cac81SBjoern A. Zeeb /* Setting these happens later when we have device information. */ 34666b4cac81SBjoern A. Zeeb ic->ic_softc = NULL; 34676b4cac81SBjoern A. Zeeb ic->ic_name = "linuxkpi"; 34686b4cac81SBjoern A. Zeeb 34696b4cac81SBjoern A. Zeeb return (ic); 34706b4cac81SBjoern A. Zeeb } 34716b4cac81SBjoern A. Zeeb 34726b4cac81SBjoern A. Zeeb struct ieee80211_hw * 34736b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_alloc_hw(size_t priv_len, const struct ieee80211_ops *ops) 34746b4cac81SBjoern A. Zeeb { 34756b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 34766b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 34776b4cac81SBjoern A. Zeeb struct wiphy *wiphy; 34786b4cac81SBjoern A. Zeeb 34796b4cac81SBjoern A. Zeeb /* Get us and the driver data also allocated. */ 34806b4cac81SBjoern A. Zeeb wiphy = wiphy_new(&linuxkpi_mac80211cfgops, sizeof(*lhw) + priv_len); 34816b4cac81SBjoern A. Zeeb if (wiphy == NULL) 34826b4cac81SBjoern A. Zeeb return (NULL); 34836b4cac81SBjoern A. Zeeb 34846b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 34856b4cac81SBjoern A. Zeeb lhw->ops = ops; 3486652e22d3SBjoern A. Zeeb 3487*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK_INIT(lhw); 3488*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK_INIT(lhw); 34898891c455SBjoern A. Zeeb sx_init_flags(&lhw->lvif_sx, "lhw-lvif", SX_RECURSE | SX_DUPOK); 34906b4cac81SBjoern A. Zeeb TAILQ_INIT(&lhw->lvif_head); 34916b4cac81SBjoern A. Zeeb 34926b4cac81SBjoern A. Zeeb /* 34936b4cac81SBjoern A. Zeeb * XXX-BZ TODO make sure there is a "_null" function to all ops 34946b4cac81SBjoern A. Zeeb * not initialized. 34956b4cac81SBjoern A. Zeeb */ 34966b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 34976b4cac81SBjoern A. Zeeb hw->wiphy = wiphy; 3498086be6a8SBjoern A. Zeeb hw->conf.flags |= IEEE80211_CONF_IDLE; 34996b4cac81SBjoern A. Zeeb hw->priv = (void *)(lhw + 1); 35006b4cac81SBjoern A. Zeeb 35016b4cac81SBjoern A. Zeeb /* BSD Specific. */ 35026b4cac81SBjoern A. Zeeb lhw->ic = lkpi_ieee80211_ifalloc(); 35036b4cac81SBjoern A. Zeeb if (lhw->ic == NULL) { 35046b4cac81SBjoern A. Zeeb ieee80211_free_hw(hw); 35056b4cac81SBjoern A. Zeeb return (NULL); 35066b4cac81SBjoern A. Zeeb } 35076b4cac81SBjoern A. Zeeb 35086b4cac81SBjoern A. Zeeb IMPROVE(); 35096b4cac81SBjoern A. Zeeb 35106b4cac81SBjoern A. Zeeb return (hw); 35116b4cac81SBjoern A. Zeeb } 35126b4cac81SBjoern A. Zeeb 35136b4cac81SBjoern A. Zeeb void 35146b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iffree(struct ieee80211_hw *hw) 35156b4cac81SBjoern A. Zeeb { 35166b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 35176b4cac81SBjoern A. Zeeb 35186b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 35196b4cac81SBjoern A. Zeeb free(lhw->ic, M_LKPI80211); 35206b4cac81SBjoern A. Zeeb lhw->ic = NULL; 35216b4cac81SBjoern A. Zeeb 35226b4cac81SBjoern A. Zeeb /* Cleanup more of lhw here or in wiphy_free()? */ 35238891c455SBjoern A. Zeeb sx_destroy(&lhw->lvif_sx); 3524*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK_DESTROY(lhw); 3525*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK_DESTROY(lhw); 35266b4cac81SBjoern A. Zeeb IMPROVE(); 35276b4cac81SBjoern A. Zeeb } 35286b4cac81SBjoern A. Zeeb 35296b4cac81SBjoern A. Zeeb void 35306b4cac81SBjoern A. Zeeb linuxkpi_set_ieee80211_dev(struct ieee80211_hw *hw, char *name) 35316b4cac81SBjoern A. Zeeb { 35326b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 35336b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 35346b4cac81SBjoern A. Zeeb 35356b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 35366b4cac81SBjoern A. Zeeb ic = lhw->ic; 35376b4cac81SBjoern A. Zeeb 35386b4cac81SBjoern A. Zeeb /* Now set a proper name before ieee80211_ifattach(). */ 35396b4cac81SBjoern A. Zeeb ic->ic_softc = lhw; 35406b4cac81SBjoern A. Zeeb ic->ic_name = name; 35416b4cac81SBjoern A. Zeeb 35426b4cac81SBjoern A. Zeeb /* XXX-BZ do we also need to set wiphy name? */ 35436b4cac81SBjoern A. Zeeb } 35446b4cac81SBjoern A. Zeeb 35456b4cac81SBjoern A. Zeeb struct ieee80211_hw * 35466b4cac81SBjoern A. Zeeb linuxkpi_wiphy_to_ieee80211_hw(struct wiphy *wiphy) 35476b4cac81SBjoern A. Zeeb { 35486b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 35496b4cac81SBjoern A. Zeeb 35506b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 35516b4cac81SBjoern A. Zeeb return (LHW_TO_HW(lhw)); 35526b4cac81SBjoern A. Zeeb } 35536b4cac81SBjoern A. Zeeb 35546b4cac81SBjoern A. Zeeb static void 35556b4cac81SBjoern A. Zeeb lkpi_radiotap_attach(struct lkpi_hw *lhw) 35566b4cac81SBjoern A. Zeeb { 35576b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 35586b4cac81SBjoern A. Zeeb 35596b4cac81SBjoern A. Zeeb ic = lhw->ic; 35606b4cac81SBjoern A. Zeeb ieee80211_radiotap_attach(ic, 35616b4cac81SBjoern A. Zeeb &lhw->rtap_tx.wt_ihdr, sizeof(lhw->rtap_tx), 35626b4cac81SBjoern A. Zeeb LKPI_RTAP_TX_FLAGS_PRESENT, 35636b4cac81SBjoern A. Zeeb &lhw->rtap_rx.wr_ihdr, sizeof(lhw->rtap_rx), 35646b4cac81SBjoern A. Zeeb LKPI_RTAP_RX_FLAGS_PRESENT); 35656b4cac81SBjoern A. Zeeb } 35666b4cac81SBjoern A. Zeeb 35672e183d99SBjoern A. Zeeb int 35686b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ifattach(struct ieee80211_hw *hw) 35696b4cac81SBjoern A. Zeeb { 35706b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 35716b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 3572c5b96b3eSBjoern A. Zeeb int band, i; 35736b4cac81SBjoern A. Zeeb 35746b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 35756b4cac81SBjoern A. Zeeb ic = lhw->ic; 35766b4cac81SBjoern A. Zeeb 3577652e22d3SBjoern A. Zeeb /* We do it this late as wiphy->dev should be set for the name. */ 3578652e22d3SBjoern A. Zeeb lhw->workq = alloc_ordered_workqueue(wiphy_name(hw->wiphy), 0); 3579652e22d3SBjoern A. Zeeb if (lhw->workq == NULL) 3580652e22d3SBjoern A. Zeeb return (-EAGAIN); 3581652e22d3SBjoern A. Zeeb 35826b4cac81SBjoern A. Zeeb /* XXX-BZ figure this out how they count his... */ 35836b4cac81SBjoern A. Zeeb if (!is_zero_ether_addr(hw->wiphy->perm_addr)) { 35846b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(ic->ic_macaddr, 35856b4cac81SBjoern A. Zeeb hw->wiphy->perm_addr); 35866b4cac81SBjoern A. Zeeb } else if (hw->wiphy->n_addresses > 0) { 35876b4cac81SBjoern A. Zeeb /* We take the first one. */ 35886b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(ic->ic_macaddr, 35896b4cac81SBjoern A. Zeeb hw->wiphy->addresses[0].addr); 35906b4cac81SBjoern A. Zeeb } else { 35916b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: warning, no hardware address!\n", __func__); 35926b4cac81SBjoern A. Zeeb } 35936b4cac81SBjoern A. Zeeb 35943d09d310SBjoern A. Zeeb #ifdef __not_yet__ 35953d09d310SBjoern A. Zeeb /* See comment in lkpi_80211_txq_tx_one(). */ 35966b4cac81SBjoern A. Zeeb ic->ic_headroom = hw->extra_tx_headroom; 35973d09d310SBjoern A. Zeeb #endif 35986b4cac81SBjoern A. Zeeb 35996b4cac81SBjoern A. Zeeb ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ 36006b4cac81SBjoern A. Zeeb ic->ic_opmode = IEEE80211_M_STA; 36016b4cac81SBjoern A. Zeeb 36026b4cac81SBjoern A. Zeeb /* Set device capabilities. */ 36036b4cac81SBjoern A. Zeeb /* XXX-BZ we need to get these from linux80211/drivers and convert. */ 36046b4cac81SBjoern A. Zeeb ic->ic_caps = 36056b4cac81SBjoern A. Zeeb IEEE80211_C_STA | 36066b4cac81SBjoern A. Zeeb IEEE80211_C_MONITOR | 36076b4cac81SBjoern A. Zeeb IEEE80211_C_WPA | /* WPA/RSN */ 36084a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 36096b4cac81SBjoern A. Zeeb IEEE80211_C_WME | 36104a67f1dfSBjoern A. Zeeb #endif 36116b4cac81SBjoern A. Zeeb #if 0 36126b4cac81SBjoern A. Zeeb IEEE80211_C_PMGT | 36136b4cac81SBjoern A. Zeeb #endif 36146b4cac81SBjoern A. Zeeb IEEE80211_C_SHSLOT | /* short slot time supported */ 36156b4cac81SBjoern A. Zeeb IEEE80211_C_SHPREAMBLE /* short preamble supported */ 36166b4cac81SBjoern A. Zeeb ; 36176b4cac81SBjoern A. Zeeb #if 0 36186b4cac81SBjoern A. Zeeb /* Scanning is a different kind of beast to re-work. */ 36196b4cac81SBjoern A. Zeeb ic->ic_caps |= IEEE80211_C_BGSCAN; 36206b4cac81SBjoern A. Zeeb #endif 3621cc4e78d5SBjoern A. Zeeb if (lhw->ops->hw_scan) { 3622cc4e78d5SBjoern A. Zeeb /* 3623cc4e78d5SBjoern A. Zeeb * Advertise full-offload scanning. 3624cc4e78d5SBjoern A. Zeeb * 3625cc4e78d5SBjoern A. Zeeb * Not limiting to SINGLE_SCAN_ON_ALL_BANDS here as otherwise 3626cc4e78d5SBjoern A. Zeeb * we essentially disable hw_scan for all drivers not setting 3627cc4e78d5SBjoern A. Zeeb * the flag. 3628cc4e78d5SBjoern A. Zeeb */ 36296b4cac81SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_SCAN_OFFLOAD; 3630a486fbbdSBjoern A. Zeeb lhw->scan_flags |= LKPI_LHW_SCAN_HW; 36316b4cac81SBjoern A. Zeeb } 36326b4cac81SBjoern A. Zeeb 36336b4cac81SBjoern A. Zeeb #ifdef __notyet__ 36346b4cac81SBjoern A. Zeeb ic->ic_htcaps = IEEE80211_HTC_HT /* HT operation */ 36356b4cac81SBjoern A. Zeeb | IEEE80211_HTC_AMPDU /* A-MPDU tx/rx */ 36366b4cac81SBjoern A. Zeeb | IEEE80211_HTC_AMSDU /* A-MSDU tx/rx */ 36376b4cac81SBjoern A. Zeeb | IEEE80211_HTCAP_MAXAMSDU_3839 36386b4cac81SBjoern A. Zeeb /* max A-MSDU length */ 36396b4cac81SBjoern A. Zeeb | IEEE80211_HTCAP_SMPS_OFF; /* SM power save off */ 36406b4cac81SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_SHORTGI20; 36416b4cac81SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_CHWIDTH40 | IEEE80211_HTCAP_SHORTGI40; 36426b4cac81SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_TXSTBC; 36436b4cac81SBjoern A. Zeeb #endif 36446b4cac81SBjoern A. Zeeb 3645527687a9SBjoern A. Zeeb /* 3646527687a9SBjoern A. Zeeb * The wiphy variables report bitmasks of avail antennas. 3647527687a9SBjoern A. Zeeb * (*get_antenna) get the current bitmask sets which can be 3648527687a9SBjoern A. Zeeb * altered by (*set_antenna) for some drivers. 3649527687a9SBjoern A. Zeeb * XXX-BZ will the count alone do us much good long-term in net80211? 3650527687a9SBjoern A. Zeeb */ 3651527687a9SBjoern A. Zeeb if (hw->wiphy->available_antennas_rx || 3652527687a9SBjoern A. Zeeb hw->wiphy->available_antennas_tx) { 3653527687a9SBjoern A. Zeeb uint32_t rxs, txs; 3654527687a9SBjoern A. Zeeb 3655527687a9SBjoern A. Zeeb if (lkpi_80211_mo_get_antenna(hw, &txs, &rxs) == 0) { 3656527687a9SBjoern A. Zeeb ic->ic_rxstream = bitcount32(rxs); 3657527687a9SBjoern A. Zeeb ic->ic_txstream = bitcount32(txs); 3658527687a9SBjoern A. Zeeb } 3659527687a9SBjoern A. Zeeb } 3660527687a9SBjoern A. Zeeb 36616b4cac81SBjoern A. Zeeb ic->ic_cryptocaps = 0; 3662b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 36636b4cac81SBjoern A. Zeeb if (hw->wiphy->n_cipher_suites > 0) { 36646b4cac81SBjoern A. Zeeb for (i = 0; i < hw->wiphy->n_cipher_suites; i++) 36656b4cac81SBjoern A. Zeeb ic->ic_cryptocaps |= lkpi_l80211_to_net80211_cyphers( 36666b4cac81SBjoern A. Zeeb hw->wiphy->cipher_suites[i]); 36676b4cac81SBjoern A. Zeeb } 36686b4cac81SBjoern A. Zeeb #endif 36696b4cac81SBjoern A. Zeeb 36706b4cac81SBjoern A. Zeeb lkpi_ic_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans, 36716b4cac81SBjoern A. Zeeb ic->ic_channels); 36726b4cac81SBjoern A. Zeeb 36736b4cac81SBjoern A. Zeeb ieee80211_ifattach(ic); 36746b4cac81SBjoern A. Zeeb 36756b4cac81SBjoern A. Zeeb ic->ic_update_mcast = lkpi_ic_update_mcast; 36766b4cac81SBjoern A. Zeeb ic->ic_update_promisc = lkpi_ic_update_promisc; 36776b4cac81SBjoern A. Zeeb ic->ic_update_chw = lkpi_ic_update_chw; 36786b4cac81SBjoern A. Zeeb ic->ic_parent = lkpi_ic_parent; 36796b4cac81SBjoern A. Zeeb ic->ic_scan_start = lkpi_ic_scan_start; 36806b4cac81SBjoern A. Zeeb ic->ic_scan_end = lkpi_ic_scan_end; 36816b4cac81SBjoern A. Zeeb ic->ic_set_channel = lkpi_ic_set_channel; 36826b4cac81SBjoern A. Zeeb ic->ic_transmit = lkpi_ic_transmit; 36836b4cac81SBjoern A. Zeeb ic->ic_raw_xmit = lkpi_ic_raw_xmit; 36846b4cac81SBjoern A. Zeeb ic->ic_vap_create = lkpi_ic_vap_create; 36856b4cac81SBjoern A. Zeeb ic->ic_vap_delete = lkpi_ic_vap_delete; 36866b4cac81SBjoern A. Zeeb ic->ic_getradiocaps = lkpi_ic_getradiocaps; 36876b4cac81SBjoern A. Zeeb ic->ic_wme.wme_update = lkpi_ic_wme_update; 36886b4cac81SBjoern A. Zeeb 3689a486fbbdSBjoern A. Zeeb lhw->ic_scan_curchan = ic->ic_scan_curchan; 3690a486fbbdSBjoern A. Zeeb ic->ic_scan_curchan = lkpi_ic_scan_curchan; 3691a486fbbdSBjoern A. Zeeb lhw->ic_scan_mindwell = ic->ic_scan_mindwell; 3692a486fbbdSBjoern A. Zeeb ic->ic_scan_mindwell = lkpi_ic_scan_mindwell; 3693a486fbbdSBjoern A. Zeeb 36946b4cac81SBjoern A. Zeeb lhw->ic_node_alloc = ic->ic_node_alloc; 36956b4cac81SBjoern A. Zeeb ic->ic_node_alloc = lkpi_ic_node_alloc; 36966b4cac81SBjoern A. Zeeb lhw->ic_node_init = ic->ic_node_init; 36976b4cac81SBjoern A. Zeeb ic->ic_node_init = lkpi_ic_node_init; 36986b4cac81SBjoern A. Zeeb lhw->ic_node_cleanup = ic->ic_node_cleanup; 36996b4cac81SBjoern A. Zeeb ic->ic_node_cleanup = lkpi_ic_node_cleanup; 37006b4cac81SBjoern A. Zeeb lhw->ic_node_free = ic->ic_node_free; 37016b4cac81SBjoern A. Zeeb ic->ic_node_free = lkpi_ic_node_free; 37026b4cac81SBjoern A. Zeeb 37036b4cac81SBjoern A. Zeeb lkpi_radiotap_attach(lhw); 37046b4cac81SBjoern A. Zeeb 3705c5b96b3eSBjoern A. Zeeb /* 3706c5b96b3eSBjoern A. Zeeb * Assign the first possible channel for now; seems Realtek drivers 3707c5b96b3eSBjoern A. Zeeb * expect one. 3708d9945d78SBjoern A. Zeeb * Also remember the amount of bands we support and the most rates 3709d9945d78SBjoern A. Zeeb * in any band so we can scale [(ext) sup rates] IE(s) accordingly. 3710c5b96b3eSBjoern A. Zeeb */ 3711d9945d78SBjoern A. Zeeb lhw->supbands = lhw->max_rates = 0; 3712c5b96b3eSBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS && 3713c5b96b3eSBjoern A. Zeeb hw->conf.chandef.chan == NULL; band++) { 3714c5b96b3eSBjoern A. Zeeb struct ieee80211_supported_band *supband; 3715c5b96b3eSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 3716c5b96b3eSBjoern A. Zeeb 3717c5b96b3eSBjoern A. Zeeb supband = hw->wiphy->bands[band]; 3718c5b96b3eSBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 3719c5b96b3eSBjoern A. Zeeb continue; 3720c5b96b3eSBjoern A. Zeeb 3721d9945d78SBjoern A. Zeeb lhw->supbands++; 3722d9945d78SBjoern A. Zeeb lhw->max_rates = max(lhw->max_rates, supband->n_bitrates); 3723d9945d78SBjoern A. Zeeb 3724c5b96b3eSBjoern A. Zeeb channels = supband->channels; 3725c5b96b3eSBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 3726c5b96b3eSBjoern A. Zeeb 3727c5b96b3eSBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) 3728c5b96b3eSBjoern A. Zeeb continue; 3729c5b96b3eSBjoern A. Zeeb 37304a07abdeSBjoern A. Zeeb cfg80211_chandef_create(&hw->conf.chandef, &channels[i], 3731c5b96b3eSBjoern A. Zeeb NL80211_CHAN_NO_HT); 3732c5b96b3eSBjoern A. Zeeb break; 3733c5b96b3eSBjoern A. Zeeb } 3734c5b96b3eSBjoern A. Zeeb } 3735c5b96b3eSBjoern A. Zeeb 3736d9945d78SBjoern A. Zeeb IMPROVE("see net80211::ieee80211_chan_init vs. wiphy->bands[].bitrates possibly in lkpi_ic_getradiocaps?"); 3737d9945d78SBjoern A. Zeeb 3738d9945d78SBjoern A. Zeeb /* Make sure we do not support more than net80211 is willing to take. */ 3739d9945d78SBjoern A. Zeeb if (lhw->max_rates > IEEE80211_RATE_MAXSIZE) { 3740d9945d78SBjoern A. Zeeb ic_printf(ic, "%s: limiting max_rates %d to %d!\n", __func__, 3741d9945d78SBjoern A. Zeeb lhw->max_rates, IEEE80211_RATE_MAXSIZE); 3742d9945d78SBjoern A. Zeeb lhw->max_rates = IEEE80211_RATE_MAXSIZE; 3743d9945d78SBjoern A. Zeeb } 3744d9945d78SBjoern A. Zeeb 3745d9945d78SBjoern A. Zeeb /* 3746d9945d78SBjoern A. Zeeb * The maximum supported bitrates on any band + size for 3747d9945d78SBjoern A. Zeeb * DSSS Parameter Set give our per-band IE size. 3748d9945d78SBjoern A. Zeeb * XXX-BZ FIXME add HT VHT ... later 3749d9945d78SBjoern A. Zeeb * SSID is the responsibility of the driver and goes on the side. 3750d9945d78SBjoern A. Zeeb * The user specified bits coming from the vap go into the 3751d9945d78SBjoern A. Zeeb * "common ies" fields. 3752d9945d78SBjoern A. Zeeb */ 3753d9945d78SBjoern A. Zeeb lhw->scan_ie_len = 2 + IEEE80211_RATE_SIZE; 3754d9945d78SBjoern A. Zeeb if (lhw->max_rates > IEEE80211_RATE_SIZE) 3755d9945d78SBjoern A. Zeeb lhw->scan_ie_len += 2 + (lhw->max_rates - IEEE80211_RATE_SIZE); 3756d9945d78SBjoern A. Zeeb /* 3757d9945d78SBjoern A. Zeeb * net80211 does not seem to support the DSSS Parameter Set but some of 3758d9945d78SBjoern A. Zeeb * the drivers insert it so calculate the extra fixed space in. 3759d9945d78SBjoern A. Zeeb */ 3760d9945d78SBjoern A. Zeeb lhw->scan_ie_len += 2 + 1; 3761d9945d78SBjoern A. Zeeb 3762d9945d78SBjoern A. Zeeb /* Reduce the max_scan_ie_len "left" by the amount we consume already. */ 3763d9945d78SBjoern A. Zeeb if (hw->wiphy->max_scan_ie_len > 0) 3764d9945d78SBjoern A. Zeeb hw->wiphy->max_scan_ie_len -= lhw->scan_ie_len; 3765d9945d78SBjoern A. Zeeb 37666b4cac81SBjoern A. Zeeb if (bootverbose) 37676b4cac81SBjoern A. Zeeb ieee80211_announce(ic); 37682e183d99SBjoern A. Zeeb 37692e183d99SBjoern A. Zeeb return (0); 37706b4cac81SBjoern A. Zeeb } 37716b4cac81SBjoern A. Zeeb 37726b4cac81SBjoern A. Zeeb void 37736b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ifdetach(struct ieee80211_hw *hw) 37746b4cac81SBjoern A. Zeeb { 37756b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 37766b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 37776b4cac81SBjoern A. Zeeb 37786b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 37796b4cac81SBjoern A. Zeeb ic = lhw->ic; 37806b4cac81SBjoern A. Zeeb ieee80211_ifdetach(ic); 37816b4cac81SBjoern A. Zeeb } 37826b4cac81SBjoern A. Zeeb 37836b4cac81SBjoern A. Zeeb void 37846b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_interfaces(struct ieee80211_hw *hw, 37856b4cac81SBjoern A. Zeeb enum ieee80211_iface_iter flags, 37866b4cac81SBjoern A. Zeeb void(*iterfunc)(void *, uint8_t *, struct ieee80211_vif *), 37876b4cac81SBjoern A. Zeeb void *arg) 37886b4cac81SBjoern A. Zeeb { 37896b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 37906b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 37916b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 379261a68e50SBjoern A. Zeeb bool active, atomic, nin_drv; 37936b4cac81SBjoern A. Zeeb 37946b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 37956b4cac81SBjoern A. Zeeb 37966b4cac81SBjoern A. Zeeb if (flags & ~(IEEE80211_IFACE_ITER_NORMAL| 37976b4cac81SBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL| 379861a68e50SBjoern A. Zeeb IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER| 37996b4cac81SBjoern A. Zeeb IEEE80211_IFACE_ITER__ACTIVE|IEEE80211_IFACE_ITER__ATOMIC)) { 38006b4cac81SBjoern A. Zeeb ic_printf(lhw->ic, "XXX TODO %s flags(%#x) not yet supported.\n", 38016b4cac81SBjoern A. Zeeb __func__, flags); 38026b4cac81SBjoern A. Zeeb } 38036b4cac81SBjoern A. Zeeb 38046b4cac81SBjoern A. Zeeb active = (flags & IEEE80211_IFACE_ITER__ACTIVE) != 0; 38056b4cac81SBjoern A. Zeeb atomic = (flags & IEEE80211_IFACE_ITER__ATOMIC) != 0; 380661a68e50SBjoern A. Zeeb nin_drv = (flags & IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER) != 0; 38076b4cac81SBjoern A. Zeeb 38086b4cac81SBjoern A. Zeeb if (atomic) 38098891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 38106b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 38116b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 38126b4cac81SBjoern A. Zeeb 38136b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 38146b4cac81SBjoern A. Zeeb 38156b4cac81SBjoern A. Zeeb /* 38166b4cac81SBjoern A. Zeeb * If we want "active" interfaces, we need to distinguish on 38176b4cac81SBjoern A. Zeeb * whether the driver knows about them or not to be able to 38186b4cac81SBjoern A. Zeeb * handle the "resume" case correctly. Skip the ones the 38196b4cac81SBjoern A. Zeeb * driver does not know about. 38206b4cac81SBjoern A. Zeeb */ 38216b4cac81SBjoern A. Zeeb if (active && !lvif->added_to_drv && 38226b4cac81SBjoern A. Zeeb (flags & IEEE80211_IFACE_ITER_RESUME_ALL) != 0) 38236b4cac81SBjoern A. Zeeb continue; 38246b4cac81SBjoern A. Zeeb 38256b4cac81SBjoern A. Zeeb /* 382661a68e50SBjoern A. Zeeb * If we shall skip interfaces not added to the driver do so 382761a68e50SBjoern A. Zeeb * if we haven't yet. 382861a68e50SBjoern A. Zeeb */ 382961a68e50SBjoern A. Zeeb if (nin_drv && !lvif->added_to_drv) 383061a68e50SBjoern A. Zeeb continue; 383161a68e50SBjoern A. Zeeb 383261a68e50SBjoern A. Zeeb /* 38336b4cac81SBjoern A. Zeeb * Run the iterator function if we are either not asking 38346b4cac81SBjoern A. Zeeb * asking for active only or if the VAP is "running". 38356b4cac81SBjoern A. Zeeb */ 38366b4cac81SBjoern A. Zeeb /* XXX-BZ probably should have state in the lvif as well. */ 38376b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 38386b4cac81SBjoern A. Zeeb if (!active || (vap->iv_state != IEEE80211_S_INIT)) 38396b4cac81SBjoern A. Zeeb iterfunc(arg, vif->addr, vif); 38406b4cac81SBjoern A. Zeeb } 38416b4cac81SBjoern A. Zeeb if (atomic) 38428891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 38436b4cac81SBjoern A. Zeeb } 38446b4cac81SBjoern A. Zeeb 38456b4cac81SBjoern A. Zeeb void 38466b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_keys(struct ieee80211_hw *hw, 38476b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif, 38486b4cac81SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_vif *, 38496b4cac81SBjoern A. Zeeb struct ieee80211_sta *, struct ieee80211_key_conf *, void *), 38506b4cac81SBjoern A. Zeeb void *arg) 38516b4cac81SBjoern A. Zeeb { 38526b4cac81SBjoern A. Zeeb 38536b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 38546b4cac81SBjoern A. Zeeb } 38556b4cac81SBjoern A. Zeeb 38566b4cac81SBjoern A. Zeeb void 38576b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_chan_contexts(struct ieee80211_hw *hw, 38586b4cac81SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_chanctx_conf *, 38596b4cac81SBjoern A. Zeeb void *), 38606b4cac81SBjoern A. Zeeb void *arg) 38616b4cac81SBjoern A. Zeeb { 38626b4cac81SBjoern A. Zeeb 38636b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 38646b4cac81SBjoern A. Zeeb } 38656b4cac81SBjoern A. Zeeb 38666b4cac81SBjoern A. Zeeb void 38676b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_stations_atomic(struct ieee80211_hw *hw, 38686b4cac81SBjoern A. Zeeb void (*iterfunc)(void *, struct ieee80211_sta *), void *arg) 38696b4cac81SBjoern A. Zeeb { 38706b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 38716b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 38726b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 38736b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 38746b4cac81SBjoern A. Zeeb 38756b4cac81SBjoern A. Zeeb KASSERT(hw != NULL && iterfunc != NULL, 38766b4cac81SBjoern A. Zeeb ("%s: hw %p iterfunc %p arg %p\n", __func__, hw, iterfunc, arg)); 38776b4cac81SBjoern A. Zeeb 38786b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 38796b4cac81SBjoern A. Zeeb 38808891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 38816b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 38826b4cac81SBjoern A. Zeeb 38836b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 38846b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lsta, &lvif->lsta_head, lsta_entry) { 38856b4cac81SBjoern A. Zeeb if (!lsta->added_to_drv) 38866b4cac81SBjoern A. Zeeb continue; 38876b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 38886b4cac81SBjoern A. Zeeb iterfunc(arg, sta); 38896b4cac81SBjoern A. Zeeb } 38906b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 38916b4cac81SBjoern A. Zeeb } 38928891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 38936b4cac81SBjoern A. Zeeb } 38946b4cac81SBjoern A. Zeeb 38956b4cac81SBjoern A. Zeeb int 38966b4cac81SBjoern A. Zeeb linuxkpi_regulatory_set_wiphy_regd_sync(struct wiphy *wiphy, 38976b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_regdomain *regd) 38986b4cac81SBjoern A. Zeeb { 38996b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 39006b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 39016b4cac81SBjoern A. Zeeb struct ieee80211_regdomain *rd; 39026b4cac81SBjoern A. Zeeb 39036b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 39046b4cac81SBjoern A. Zeeb ic = lhw->ic; 39056b4cac81SBjoern A. Zeeb 39066b4cac81SBjoern A. Zeeb rd = &ic->ic_regdomain; 39076b4cac81SBjoern A. Zeeb if (rd->isocc[0] == '\0') { 39086b4cac81SBjoern A. Zeeb rd->isocc[0] = regd->alpha2[0]; 39096b4cac81SBjoern A. Zeeb rd->isocc[1] = regd->alpha2[1]; 39106b4cac81SBjoern A. Zeeb } 39116b4cac81SBjoern A. Zeeb 39126b4cac81SBjoern A. Zeeb TODO(); 39136b4cac81SBjoern A. Zeeb /* XXX-BZ finish the rest. */ 39146b4cac81SBjoern A. Zeeb 39156b4cac81SBjoern A. Zeeb return (0); 39166b4cac81SBjoern A. Zeeb } 39176b4cac81SBjoern A. Zeeb 39186b4cac81SBjoern A. Zeeb void 39196b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_scan_completed(struct ieee80211_hw *hw, 39206b4cac81SBjoern A. Zeeb struct cfg80211_scan_info *info) 39216b4cac81SBjoern A. Zeeb { 39226b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 39236b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 39246b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 39256b4cac81SBjoern A. Zeeb 39266b4cac81SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 39276b4cac81SBjoern A. Zeeb ic = lhw->ic; 39286b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 39296b4cac81SBjoern A. Zeeb 39306b4cac81SBjoern A. Zeeb ieee80211_scan_done(ss->ss_vap); 39316b4cac81SBjoern A. Zeeb 3932*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 39336b4cac81SBjoern A. Zeeb free(lhw->hw_req, M_LKPI80211); 39346b4cac81SBjoern A. Zeeb lhw->hw_req = NULL; 3935a486fbbdSBjoern A. Zeeb lhw->scan_flags &= ~LKPI_LHW_SCAN_RUNNING; 39366b4cac81SBjoern A. Zeeb wakeup(lhw); 3937*8ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 39386b4cac81SBjoern A. Zeeb 39396b4cac81SBjoern A. Zeeb return; 39406b4cac81SBjoern A. Zeeb } 39416b4cac81SBjoern A. Zeeb 3942e30e05d3SBjoern A. Zeeb /* For %list see comment towards the end of the function. */ 39436b4cac81SBjoern A. Zeeb void 39446b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb, 3945e30e05d3SBjoern A. Zeeb struct ieee80211_sta *sta, struct napi_struct *napi __unused, 3946e30e05d3SBjoern A. Zeeb struct list_head *list __unused) 39476b4cac81SBjoern A. Zeeb { 39486b4cac81SBjoern A. Zeeb struct epoch_tracker et; 39496b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 39506b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 39516b4cac81SBjoern A. Zeeb struct mbuf *m; 39526b4cac81SBjoern A. Zeeb struct skb_shared_info *shinfo; 39536b4cac81SBjoern A. Zeeb struct ieee80211_rx_status *rx_status; 39546b4cac81SBjoern A. Zeeb struct ieee80211_rx_stats rx_stats; 39556b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 39566b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 39576b4cac81SBjoern A. Zeeb struct ieee80211_hdr *hdr; 39586b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 39599d9ba2b7SBjoern A. Zeeb int i, offset, ok; 3960170acccfSBjoern A. Zeeb int8_t rssi; 3961c0cadd99SBjoern A. Zeeb bool is_beacon; 39626b4cac81SBjoern A. Zeeb 39636b4cac81SBjoern A. Zeeb if (skb->len < 2) { 39646b4cac81SBjoern A. Zeeb /* Need 80211 stats here. */ 39656b4cac81SBjoern A. Zeeb IMPROVE(); 39666b4cac81SBjoern A. Zeeb goto err; 39676b4cac81SBjoern A. Zeeb } 39686b4cac81SBjoern A. Zeeb 39696b4cac81SBjoern A. Zeeb /* 39706b4cac81SBjoern A. Zeeb * For now do the data copy; we can later improve things. Might even 39716b4cac81SBjoern A. Zeeb * have an mbuf backing the skb data then? 39726b4cac81SBjoern A. Zeeb */ 39736b4cac81SBjoern A. Zeeb m = m_get2(skb->len, M_NOWAIT, MT_DATA, M_PKTHDR); 39746b4cac81SBjoern A. Zeeb if (m == NULL) 39756b4cac81SBjoern A. Zeeb goto err; 39766b4cac81SBjoern A. Zeeb m_copyback(m, 0, skb->tail - skb->data, skb->data); 39776b4cac81SBjoern A. Zeeb 39786b4cac81SBjoern A. Zeeb shinfo = skb_shinfo(skb); 39796b4cac81SBjoern A. Zeeb offset = m->m_len; 39806b4cac81SBjoern A. Zeeb for (i = 0; i < shinfo->nr_frags; i++) { 39816b4cac81SBjoern A. Zeeb m_copyback(m, offset, shinfo->frags[i].size, 39826b4cac81SBjoern A. Zeeb (uint8_t *)linux_page_address(shinfo->frags[i].page) + 39836b4cac81SBjoern A. Zeeb shinfo->frags[i].offset); 39846b4cac81SBjoern A. Zeeb offset += shinfo->frags[i].size; 39856b4cac81SBjoern A. Zeeb } 39866b4cac81SBjoern A. Zeeb 39876b4cac81SBjoern A. Zeeb rx_status = IEEE80211_SKB_RXCB(skb); 39886b4cac81SBjoern A. Zeeb 39896b4cac81SBjoern A. Zeeb hdr = (void *)skb->data; 3990c0cadd99SBjoern A. Zeeb is_beacon = ieee80211_is_beacon(hdr->frame_control); 3991c0cadd99SBjoern A. Zeeb 3992c0cadd99SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 39939d9ba2b7SBjoern A. Zeeb if (is_beacon && (linuxkpi_debug_80211 & D80211_TRACE_RX_BEACONS) == 0) 39946b4cac81SBjoern A. Zeeb goto no_trace_beacons; 39956b4cac81SBjoern A. Zeeb 39969d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 39976b4cac81SBjoern A. Zeeb printf("TRACE-RX: %s: skb %p a/l/d/t-len (%u/%u/%u/%u) " 3998c0cadd99SBjoern A. Zeeb "h %p d %p t %p e %p sh %p (%u) m %p plen %u len %u%s\n", 39996b4cac81SBjoern A. Zeeb __func__, skb, skb->_alloc_len, skb->len, skb->data_len, 40006b4cac81SBjoern A. Zeeb skb->truesize, skb->head, skb->data, skb->tail, skb->end, 40016b4cac81SBjoern A. Zeeb shinfo, shinfo->nr_frags, 4002c0cadd99SBjoern A. Zeeb m, m->m_pkthdr.len, m->m_len, is_beacon ? " beacon" : ""); 40036b4cac81SBjoern A. Zeeb 40049d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX_DUMP) 40056b4cac81SBjoern A. Zeeb hexdump(mtod(m, const void *), m->m_len, "RX (raw) ", 0); 40066b4cac81SBjoern A. Zeeb 40076b4cac81SBjoern A. Zeeb /* Implement a dump_rxcb() !!! */ 40089d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 4009c8dafefaSBjoern A. Zeeb printf("TRACE %s: RXCB: %ju %ju %u, %#0x, %u, %#0x, %#0x, " 401060970a32SBjoern A. Zeeb "%u band %u, %u { %d %d %d %d }, %d, %#x %#x %#x %#x %u %u %u\n", 40116b4cac81SBjoern A. Zeeb __func__, 4012c8dafefaSBjoern A. Zeeb (uintmax_t)rx_status->boottime_ns, 4013c8dafefaSBjoern A. Zeeb (uintmax_t)rx_status->mactime, 40146b4cac81SBjoern A. Zeeb rx_status->device_timestamp, 40156b4cac81SBjoern A. Zeeb rx_status->flag, 40166b4cac81SBjoern A. Zeeb rx_status->freq, 40176b4cac81SBjoern A. Zeeb rx_status->bw, 40186b4cac81SBjoern A. Zeeb rx_status->encoding, 40196b4cac81SBjoern A. Zeeb rx_status->ampdu_reference, 40206b4cac81SBjoern A. Zeeb rx_status->band, 40216b4cac81SBjoern A. Zeeb rx_status->chains, 40226b4cac81SBjoern A. Zeeb rx_status->chain_signal[0], 40236b4cac81SBjoern A. Zeeb rx_status->chain_signal[1], 40246b4cac81SBjoern A. Zeeb rx_status->chain_signal[2], 402560970a32SBjoern A. Zeeb rx_status->chain_signal[3], 40266b4cac81SBjoern A. Zeeb rx_status->signal, 40276b4cac81SBjoern A. Zeeb rx_status->enc_flags, 40286b4cac81SBjoern A. Zeeb rx_status->he_dcm, 40296b4cac81SBjoern A. Zeeb rx_status->he_gi, 40306b4cac81SBjoern A. Zeeb rx_status->he_ru, 40316b4cac81SBjoern A. Zeeb rx_status->zero_length_psdu_type, 40326b4cac81SBjoern A. Zeeb rx_status->nss, 40336b4cac81SBjoern A. Zeeb rx_status->rate_idx); 40346b4cac81SBjoern A. Zeeb no_trace_beacons: 40356b4cac81SBjoern A. Zeeb #endif 40366b4cac81SBjoern A. Zeeb 40376b4cac81SBjoern A. Zeeb memset(&rx_stats, 0, sizeof(rx_stats)); 40386b4cac81SBjoern A. Zeeb rx_stats.r_flags = IEEE80211_R_NF | IEEE80211_R_RSSI; 403960970a32SBjoern A. Zeeb /* XXX-BZ correct hardcoded rssi and noise floor, how? survey? */ 404060970a32SBjoern A. Zeeb rx_stats.c_nf = -96; 40416b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, SIGNAL_DBM) && 40426b4cac81SBjoern A. Zeeb !(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL)) 4043170acccfSBjoern A. Zeeb rssi = rx_status->signal; 40446b4cac81SBjoern A. Zeeb else 4045170acccfSBjoern A. Zeeb rssi = rx_stats.c_nf; 4046170acccfSBjoern A. Zeeb /* 4047170acccfSBjoern A. Zeeb * net80211 signal strength data are in .5 dBm units relative to 4048170acccfSBjoern A. Zeeb * the current noise floor (see comment in ieee80211_node.h). 4049170acccfSBjoern A. Zeeb */ 4050170acccfSBjoern A. Zeeb rssi -= rx_stats.c_nf; 4051170acccfSBjoern A. Zeeb rx_stats.c_rssi = rssi * 2; 40526b4cac81SBjoern A. Zeeb rx_stats.r_flags |= IEEE80211_R_BAND; 40536b4cac81SBjoern A. Zeeb rx_stats.c_band = 40546b4cac81SBjoern A. Zeeb lkpi_nl80211_band_to_net80211_band(rx_status->band); 40556b4cac81SBjoern A. Zeeb rx_stats.r_flags |= IEEE80211_R_FREQ | IEEE80211_R_IEEE; 40566b4cac81SBjoern A. Zeeb rx_stats.c_freq = rx_status->freq; 40576b4cac81SBjoern A. Zeeb rx_stats.c_ieee = ieee80211_mhz2ieee(rx_stats.c_freq, rx_stats.c_band); 40586b4cac81SBjoern A. Zeeb 40596b4cac81SBjoern A. Zeeb /* XXX (*sta_statistics)() to get to some of that? */ 40606b4cac81SBjoern A. Zeeb /* XXX-BZ dump the FreeBSD version of rx_stats as well! */ 40616b4cac81SBjoern A. Zeeb 40626b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 40636b4cac81SBjoern A. Zeeb ic = lhw->ic; 40646b4cac81SBjoern A. Zeeb 40656b4cac81SBjoern A. Zeeb ok = ieee80211_add_rx_params(m, &rx_stats); 40666b4cac81SBjoern A. Zeeb if (ok == 0) { 4067dbc06dd9SBjoern A. Zeeb m_freem(m); 40686b4cac81SBjoern A. Zeeb counter_u64_add(ic->ic_ierrors, 1); 40696b4cac81SBjoern A. Zeeb goto err; 40706b4cac81SBjoern A. Zeeb } 40716b4cac81SBjoern A. Zeeb 40726b4cac81SBjoern A. Zeeb if (sta != NULL) { 40736b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 40746b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(lsta->ni); 40756b4cac81SBjoern A. Zeeb } else { 4076c8dafefaSBjoern A. Zeeb struct ieee80211_frame_min *wh; 4077c8dafefaSBjoern A. Zeeb 40786b4cac81SBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame_min *); 40796b4cac81SBjoern A. Zeeb ni = ieee80211_find_rxnode(ic, wh); 40806b4cac81SBjoern A. Zeeb if (ni != NULL) 40816b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 40826b4cac81SBjoern A. Zeeb } 40836b4cac81SBjoern A. Zeeb 40846b4cac81SBjoern A. Zeeb if (ni != NULL) 40856b4cac81SBjoern A. Zeeb vap = ni->ni_vap; 40866b4cac81SBjoern A. Zeeb else 40876b4cac81SBjoern A. Zeeb /* 40886b4cac81SBjoern A. Zeeb * XXX-BZ can we improve this by looking at the frame hdr 40896b4cac81SBjoern A. Zeeb * or other meta-data passed up? 40906b4cac81SBjoern A. Zeeb */ 40916b4cac81SBjoern A. Zeeb vap = TAILQ_FIRST(&ic->ic_vaps); 40926b4cac81SBjoern A. Zeeb 40939d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 40949d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 4095c0cadd99SBjoern A. Zeeb printf("TRACE %s: sta %p lsta %p state %d ni %p vap %p%s\n", 4096c0cadd99SBjoern A. Zeeb __func__, sta, lsta, (lsta != NULL) ? lsta->state : -1, 4097c0cadd99SBjoern A. Zeeb ni, vap, is_beacon ? " beacon" : ""); 40989d9ba2b7SBjoern A. Zeeb #endif 40996b4cac81SBjoern A. Zeeb 4100c0cadd99SBjoern A. Zeeb if (ni != NULL && vap != NULL && is_beacon && 4101c8dafefaSBjoern A. Zeeb rx_status->device_timestamp > 0 && 4102c8dafefaSBjoern A. Zeeb m->m_pkthdr.len >= sizeof(struct ieee80211_frame)) { 4103c8dafefaSBjoern A. Zeeb struct lkpi_vif *lvif; 4104c8dafefaSBjoern A. Zeeb struct ieee80211_vif *vif; 4105c8dafefaSBjoern A. Zeeb struct ieee80211_frame *wh; 4106c8dafefaSBjoern A. Zeeb 4107c8dafefaSBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame *); 4108c8dafefaSBjoern A. Zeeb if (!IEEE80211_ADDR_EQ(wh->i_addr2, ni->ni_bssid)) 4109c8dafefaSBjoern A. Zeeb goto skip_device_ts; 4110c8dafefaSBjoern A. Zeeb 4111c8dafefaSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 4112c8dafefaSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 4113c8dafefaSBjoern A. Zeeb 4114c8dafefaSBjoern A. Zeeb IMPROVE("TIMING_BEACON_ONLY?"); 4115c8dafefaSBjoern A. Zeeb /* mac80211 specific (not net80211) so keep it here. */ 4116c8dafefaSBjoern A. Zeeb vif->bss_conf.sync_device_ts = rx_status->device_timestamp; 4117c8dafefaSBjoern A. Zeeb /* 4118c8dafefaSBjoern A. Zeeb * net80211 should take care of the other information (sync_tsf, 4119c8dafefaSBjoern A. Zeeb * sync_dtim_count) as otherwise we need to parse the beacon. 4120c8dafefaSBjoern A. Zeeb */ 4121c8dafefaSBjoern A. Zeeb } 4122c8dafefaSBjoern A. Zeeb skip_device_ts: 4123c8dafefaSBjoern A. Zeeb 41246b4cac81SBjoern A. Zeeb if (vap != NULL && vap->iv_state > IEEE80211_S_INIT && 41256b4cac81SBjoern A. Zeeb ieee80211_radiotap_active_vap(vap)) { 41266b4cac81SBjoern A. Zeeb struct lkpi_radiotap_rx_hdr *rtap; 41276b4cac81SBjoern A. Zeeb 41286b4cac81SBjoern A. Zeeb rtap = &lhw->rtap_rx; 41296b4cac81SBjoern A. Zeeb rtap->wr_tsft = rx_status->device_timestamp; 41306b4cac81SBjoern A. Zeeb rtap->wr_flags = 0; 41316b4cac81SBjoern A. Zeeb if (rx_status->enc_flags & RX_ENC_FLAG_SHORTPRE) 41326b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; 41336b4cac81SBjoern A. Zeeb if (rx_status->enc_flags & RX_ENC_FLAG_SHORT_GI) 41346b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTGI; 41356b4cac81SBjoern A. Zeeb #if 0 /* .. or it does not given we strip it below. */ 41366b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, RX_INCLUDES_FCS)) 41376b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_FCS; 41386b4cac81SBjoern A. Zeeb #endif 41396b4cac81SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_FAILED_FCS_CRC) 41406b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_BADFCS; 41416b4cac81SBjoern A. Zeeb rtap->wr_rate = 0; 41426b4cac81SBjoern A. Zeeb IMPROVE(); 41436b4cac81SBjoern A. Zeeb /* XXX TODO status->encoding / rate_index / bw */ 41446b4cac81SBjoern A. Zeeb rtap->wr_chan_freq = htole16(rx_stats.c_freq); 41456b4cac81SBjoern A. Zeeb if (ic->ic_curchan->ic_ieee == rx_stats.c_ieee) 41466b4cac81SBjoern A. Zeeb rtap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags); 4147170acccfSBjoern A. Zeeb rtap->wr_dbm_antsignal = rssi; 41486b4cac81SBjoern A. Zeeb rtap->wr_dbm_antnoise = rx_stats.c_nf; 41496b4cac81SBjoern A. Zeeb } 41506b4cac81SBjoern A. Zeeb 41516b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, RX_INCLUDES_FCS)) 41526b4cac81SBjoern A. Zeeb m_adj(m, -IEEE80211_CRC_LEN); 41536b4cac81SBjoern A. Zeeb 4154e30e05d3SBjoern A. Zeeb #if 0 4155e30e05d3SBjoern A. Zeeb if (list != NULL) { 4156e30e05d3SBjoern A. Zeeb /* 4157e30e05d3SBjoern A. Zeeb * Normally this would be queued up and delivered by 4158e30e05d3SBjoern A. Zeeb * netif_receive_skb_list(), napi_gro_receive(), or the like. 4159e30e05d3SBjoern A. Zeeb * See mt76::mac80211.c as only current possible consumer. 4160e30e05d3SBjoern A. Zeeb */ 4161e30e05d3SBjoern A. Zeeb IMPROVE("we simply pass the packet to net80211 to deal with."); 4162e30e05d3SBjoern A. Zeeb } 4163e30e05d3SBjoern A. Zeeb #endif 4164e30e05d3SBjoern A. Zeeb 41656b4cac81SBjoern A. Zeeb NET_EPOCH_ENTER(et); 41666b4cac81SBjoern A. Zeeb if (ni != NULL) { 41679d9ba2b7SBjoern A. Zeeb ok = ieee80211_input_mimo(ni, m); 41686b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 4169dbc06dd9SBjoern A. Zeeb if (ok < 0) 4170dbc06dd9SBjoern A. Zeeb m_freem(m); 41716b4cac81SBjoern A. Zeeb } else { 41729d9ba2b7SBjoern A. Zeeb ok = ieee80211_input_mimo_all(ic, m); 4173dbc06dd9SBjoern A. Zeeb /* mbuf got consumed. */ 41746b4cac81SBjoern A. Zeeb } 41756b4cac81SBjoern A. Zeeb NET_EPOCH_EXIT(et); 41766b4cac81SBjoern A. Zeeb 41779d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 41789d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 41799d9ba2b7SBjoern A. Zeeb printf("TRACE %s: handled frame type %#0x\n", __func__, ok); 41809d9ba2b7SBjoern A. Zeeb #endif 41816b4cac81SBjoern A. Zeeb 41826b4cac81SBjoern A. Zeeb IMPROVE(); 41836b4cac81SBjoern A. Zeeb 41846b4cac81SBjoern A. Zeeb err: 41856b4cac81SBjoern A. Zeeb /* The skb is ours so we can free it :-) */ 41866b4cac81SBjoern A. Zeeb kfree_skb(skb); 41876b4cac81SBjoern A. Zeeb } 41886b4cac81SBjoern A. Zeeb 41896b4cac81SBjoern A. Zeeb uint8_t 4190ec190d91SBjoern A. Zeeb linuxkpi_ieee80211_get_tid(struct ieee80211_hdr *hdr, bool nonqos_ok) 41916b4cac81SBjoern A. Zeeb { 41926b4cac81SBjoern A. Zeeb const struct ieee80211_frame *wh; 4193ec190d91SBjoern A. Zeeb uint8_t tid; 4194ec190d91SBjoern A. Zeeb 4195ec190d91SBjoern A. Zeeb /* Linux seems to assume this is a QOS-Data-Frame */ 4196ec190d91SBjoern A. Zeeb KASSERT(nonqos_ok || ieee80211_is_data_qos(hdr->frame_control), 4197ec190d91SBjoern A. Zeeb ("%s: hdr %p fc %#06x not qos_data\n", __func__, hdr, 4198ec190d91SBjoern A. Zeeb hdr->frame_control)); 41996b4cac81SBjoern A. Zeeb 42006b4cac81SBjoern A. Zeeb wh = (const struct ieee80211_frame *)hdr; 4201ec190d91SBjoern A. Zeeb tid = ieee80211_gettid(wh); 4202ec190d91SBjoern A. Zeeb KASSERT(nonqos_ok || tid == (tid & IEEE80211_QOS_TID), ("%s: tid %u " 4203ec190d91SBjoern A. Zeeb "not expected (%u?)\n", __func__, tid, IEEE80211_NONQOS_TID)); 4204ec190d91SBjoern A. Zeeb 4205ec190d91SBjoern A. Zeeb return (tid); 42066b4cac81SBjoern A. Zeeb } 42076b4cac81SBjoern A. Zeeb 42086b4cac81SBjoern A. Zeeb struct wiphy * 42096b4cac81SBjoern A. Zeeb linuxkpi_wiphy_new(const struct cfg80211_ops *ops, size_t priv_len) 42106b4cac81SBjoern A. Zeeb { 42116b4cac81SBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 42126b4cac81SBjoern A. Zeeb 42136b4cac81SBjoern A. Zeeb lwiphy = kzalloc(sizeof(*lwiphy) + priv_len, GFP_KERNEL); 42146b4cac81SBjoern A. Zeeb if (lwiphy == NULL) 42156b4cac81SBjoern A. Zeeb return (NULL); 42166b4cac81SBjoern A. Zeeb lwiphy->ops = ops; 42176b4cac81SBjoern A. Zeeb 42186b4cac81SBjoern A. Zeeb /* XXX TODO */ 42196b4cac81SBjoern A. Zeeb return (LWIPHY_TO_WIPHY(lwiphy)); 42206b4cac81SBjoern A. Zeeb } 42216b4cac81SBjoern A. Zeeb 42226b4cac81SBjoern A. Zeeb void 42236b4cac81SBjoern A. Zeeb linuxkpi_wiphy_free(struct wiphy *wiphy) 42246b4cac81SBjoern A. Zeeb { 42256b4cac81SBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 42266b4cac81SBjoern A. Zeeb 42276b4cac81SBjoern A. Zeeb if (wiphy == NULL) 42286b4cac81SBjoern A. Zeeb return; 42296b4cac81SBjoern A. Zeeb 42306b4cac81SBjoern A. Zeeb lwiphy = WIPHY_TO_LWIPHY(wiphy); 42316b4cac81SBjoern A. Zeeb kfree(lwiphy); 42326b4cac81SBjoern A. Zeeb } 42336b4cac81SBjoern A. Zeeb 42346b4cac81SBjoern A. Zeeb uint32_t 42356b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_channel_to_frequency(uint32_t channel, 42366b4cac81SBjoern A. Zeeb enum nl80211_band band) 42376b4cac81SBjoern A. Zeeb { 42386b4cac81SBjoern A. Zeeb 42396b4cac81SBjoern A. Zeeb switch (band) { 42406b4cac81SBjoern A. Zeeb case NL80211_BAND_2GHZ: 42416b4cac81SBjoern A. Zeeb return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_2GHZ)); 42426b4cac81SBjoern A. Zeeb break; 42436b4cac81SBjoern A. Zeeb case NL80211_BAND_5GHZ: 42446b4cac81SBjoern A. Zeeb return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_5GHZ)); 42456b4cac81SBjoern A. Zeeb break; 42466b4cac81SBjoern A. Zeeb default: 42476b4cac81SBjoern A. Zeeb /* XXX abort, retry, error, panic? */ 42486b4cac81SBjoern A. Zeeb break; 42496b4cac81SBjoern A. Zeeb } 42506b4cac81SBjoern A. Zeeb 42516b4cac81SBjoern A. Zeeb return (0); 42526b4cac81SBjoern A. Zeeb } 42536b4cac81SBjoern A. Zeeb 42546b4cac81SBjoern A. Zeeb uint32_t 42556b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_frequency_to_channel(uint32_t freq, uint32_t flags __unused) 42566b4cac81SBjoern A. Zeeb { 42576b4cac81SBjoern A. Zeeb 42586b4cac81SBjoern A. Zeeb return (ieee80211_mhz2ieee(freq, 0)); 42596b4cac81SBjoern A. Zeeb } 42606b4cac81SBjoern A. Zeeb 42616b4cac81SBjoern A. Zeeb static struct lkpi_sta * 42626b4cac81SBjoern A. Zeeb lkpi_find_lsta_by_ni(struct lkpi_vif *lvif, struct ieee80211_node *ni) 42636b4cac81SBjoern A. Zeeb { 42646b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta, *temp; 42656b4cac81SBjoern A. Zeeb 42666b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 42676b4cac81SBjoern A. Zeeb TAILQ_FOREACH_SAFE(lsta, &lvif->lsta_head, lsta_entry, temp) { 42686b4cac81SBjoern A. Zeeb if (lsta->ni == ni) { 42696b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 42706b4cac81SBjoern A. Zeeb return (lsta); 42716b4cac81SBjoern A. Zeeb } 42726b4cac81SBjoern A. Zeeb } 42736b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 42746b4cac81SBjoern A. Zeeb 42756b4cac81SBjoern A. Zeeb return (NULL); 42766b4cac81SBjoern A. Zeeb } 42776b4cac81SBjoern A. Zeeb 42786b4cac81SBjoern A. Zeeb struct ieee80211_sta * 42796b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_find_sta(struct ieee80211_vif *vif, const u8 *peer) 42806b4cac81SBjoern A. Zeeb { 42816b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 42826b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta, *temp; 42836b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 42846b4cac81SBjoern A. Zeeb 42856b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 42866b4cac81SBjoern A. Zeeb 42876b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 42886b4cac81SBjoern A. Zeeb TAILQ_FOREACH_SAFE(lsta, &lvif->lsta_head, lsta_entry, temp) { 42896b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 42906b4cac81SBjoern A. Zeeb if (IEEE80211_ADDR_EQ(sta->addr, peer)) { 42916b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 42926b4cac81SBjoern A. Zeeb return (sta); 42936b4cac81SBjoern A. Zeeb } 42946b4cac81SBjoern A. Zeeb } 42956b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 42966b4cac81SBjoern A. Zeeb return (NULL); 42976b4cac81SBjoern A. Zeeb } 42986b4cac81SBjoern A. Zeeb 42996b4cac81SBjoern A. Zeeb struct ieee80211_sta * 43002e183d99SBjoern A. Zeeb linuxkpi_ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw, 43012e183d99SBjoern A. Zeeb const uint8_t *addr, const uint8_t *ourvifaddr) 43026b4cac81SBjoern A. Zeeb { 43036b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 43046b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 43056b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 43066b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 43076b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 43086b4cac81SBjoern A. Zeeb 43096b4cac81SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 43106b4cac81SBjoern A. Zeeb sta = NULL; 43116b4cac81SBjoern A. Zeeb 43128891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 43136b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 43146b4cac81SBjoern A. Zeeb 43156b4cac81SBjoern A. Zeeb /* XXX-BZ check our address from the vif. */ 43166b4cac81SBjoern A. Zeeb 43176b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 43186b4cac81SBjoern A. Zeeb if (ourvifaddr != NULL && 43196b4cac81SBjoern A. Zeeb !IEEE80211_ADDR_EQ(vif->addr, ourvifaddr)) 43206b4cac81SBjoern A. Zeeb continue; 43216b4cac81SBjoern A. Zeeb sta = linuxkpi_ieee80211_find_sta(vif, addr); 43226b4cac81SBjoern A. Zeeb if (sta != NULL) 43236b4cac81SBjoern A. Zeeb break; 43246b4cac81SBjoern A. Zeeb } 43258891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 43266b4cac81SBjoern A. Zeeb 43276b4cac81SBjoern A. Zeeb if (sta != NULL) { 43286b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 43296b4cac81SBjoern A. Zeeb if (!lsta->added_to_drv) 43306b4cac81SBjoern A. Zeeb return (NULL); 43316b4cac81SBjoern A. Zeeb } 43326b4cac81SBjoern A. Zeeb 43336b4cac81SBjoern A. Zeeb return (sta); 43346b4cac81SBjoern A. Zeeb } 43356b4cac81SBjoern A. Zeeb 43366b4cac81SBjoern A. Zeeb struct sk_buff * 43376b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_tx_dequeue(struct ieee80211_hw *hw, 43386b4cac81SBjoern A. Zeeb struct ieee80211_txq *txq) 43396b4cac81SBjoern A. Zeeb { 43406b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 43410cbcfa19SBjoern A. Zeeb struct lkpi_vif *lvif; 43426b4cac81SBjoern A. Zeeb struct sk_buff *skb; 43436b4cac81SBjoern A. Zeeb 43440cbcfa19SBjoern A. Zeeb skb = NULL; 43456b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 43466b4cac81SBjoern A. Zeeb ltxq->seen_dequeue = true; 43476b4cac81SBjoern A. Zeeb 43480cbcfa19SBjoern A. Zeeb if (ltxq->stopped) 43490cbcfa19SBjoern A. Zeeb goto stopped; 43500cbcfa19SBjoern A. Zeeb 43510cbcfa19SBjoern A. Zeeb lvif = VIF_TO_LVIF(ltxq->txq.vif); 43520cbcfa19SBjoern A. Zeeb if (lvif->hw_queue_stopped[ltxq->txq.ac]) { 43530cbcfa19SBjoern A. Zeeb ltxq->stopped = true; 43540cbcfa19SBjoern A. Zeeb goto stopped; 43550cbcfa19SBjoern A. Zeeb } 43560cbcfa19SBjoern A. Zeeb 43576b4cac81SBjoern A. Zeeb skb = skb_dequeue(<xq->skbq); 43586b4cac81SBjoern A. Zeeb 43590cbcfa19SBjoern A. Zeeb stopped: 43606b4cac81SBjoern A. Zeeb return (skb); 43616b4cac81SBjoern A. Zeeb } 43626b4cac81SBjoern A. Zeeb 43636b4cac81SBjoern A. Zeeb void 43646b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_txq_get_depth(struct ieee80211_txq *txq, 436586220d3cSBjoern A. Zeeb unsigned long *frame_cnt, unsigned long *byte_cnt) 43666b4cac81SBjoern A. Zeeb { 43676b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 43686b4cac81SBjoern A. Zeeb struct sk_buff *skb; 436986220d3cSBjoern A. Zeeb unsigned long fc, bc; 43706b4cac81SBjoern A. Zeeb 43716b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 43726b4cac81SBjoern A. Zeeb 43736b4cac81SBjoern A. Zeeb fc = bc = 0; 43746b4cac81SBjoern A. Zeeb skb_queue_walk(<xq->skbq, skb) { 43756b4cac81SBjoern A. Zeeb fc++; 43766b4cac81SBjoern A. Zeeb bc += skb->len; 43776b4cac81SBjoern A. Zeeb } 43786b4cac81SBjoern A. Zeeb if (frame_cnt) 43796b4cac81SBjoern A. Zeeb *frame_cnt = fc; 43806b4cac81SBjoern A. Zeeb if (byte_cnt) 43816b4cac81SBjoern A. Zeeb *byte_cnt = bc; 43826b4cac81SBjoern A. Zeeb 43836b4cac81SBjoern A. Zeeb /* Validate that this is doing the correct thing. */ 43846b4cac81SBjoern A. Zeeb /* Should we keep track on en/dequeue? */ 43856b4cac81SBjoern A. Zeeb IMPROVE(); 43866b4cac81SBjoern A. Zeeb } 43876b4cac81SBjoern A. Zeeb 43886b4cac81SBjoern A. Zeeb /* 43896b4cac81SBjoern A. Zeeb * We are called from ieee80211_free_txskb() or ieee80211_tx_status(). 43906b4cac81SBjoern A. Zeeb * The latter tries to derive the success status from the info flags 43916b4cac81SBjoern A. Zeeb * passed back from the driver. rawx_mit() saves the ni on the m and the 43926b4cac81SBjoern A. Zeeb * m on the skb for us to be able to give feedback to net80211. 43936b4cac81SBjoern A. Zeeb */ 4394a8397571SBjoern A. Zeeb static void 4395a8397571SBjoern A. Zeeb _lkpi_ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb, 43966b4cac81SBjoern A. Zeeb int status) 43976b4cac81SBjoern A. Zeeb { 43986b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 43996b4cac81SBjoern A. Zeeb struct mbuf *m; 44006b4cac81SBjoern A. Zeeb 44016b4cac81SBjoern A. Zeeb m = skb->m; 44026b4cac81SBjoern A. Zeeb skb->m = NULL; 44036b4cac81SBjoern A. Zeeb 44046b4cac81SBjoern A. Zeeb if (m != NULL) { 44056b4cac81SBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 44066b4cac81SBjoern A. Zeeb /* Status: 0 is ok, != 0 is error. */ 44076b4cac81SBjoern A. Zeeb ieee80211_tx_complete(ni, m, status); 44086b4cac81SBjoern A. Zeeb /* ni & mbuf were consumed. */ 44096b4cac81SBjoern A. Zeeb } 4410a8397571SBjoern A. Zeeb } 44116b4cac81SBjoern A. Zeeb 4412a8397571SBjoern A. Zeeb void 4413a8397571SBjoern A. Zeeb linuxkpi_ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb, 4414a8397571SBjoern A. Zeeb int status) 4415a8397571SBjoern A. Zeeb { 4416a8397571SBjoern A. Zeeb 4417a8397571SBjoern A. Zeeb _lkpi_ieee80211_free_txskb(hw, skb, status); 44186b4cac81SBjoern A. Zeeb kfree_skb(skb); 44196b4cac81SBjoern A. Zeeb } 44206b4cac81SBjoern A. Zeeb 4421383b3e8fSBjoern A. Zeeb void 4422a8397571SBjoern A. Zeeb linuxkpi_ieee80211_tx_status_ext(struct ieee80211_hw *hw, 4423a8397571SBjoern A. Zeeb struct ieee80211_tx_status *txstat) 4424383b3e8fSBjoern A. Zeeb { 4425a8397571SBjoern A. Zeeb struct sk_buff *skb; 4426383b3e8fSBjoern A. Zeeb struct ieee80211_tx_info *info; 4427383b3e8fSBjoern A. Zeeb struct ieee80211_ratectl_tx_status txs; 4428383b3e8fSBjoern A. Zeeb struct ieee80211_node *ni; 4429383b3e8fSBjoern A. Zeeb int status; 4430383b3e8fSBjoern A. Zeeb 4431a8397571SBjoern A. Zeeb skb = txstat->skb; 4432383b3e8fSBjoern A. Zeeb if (skb->m != NULL) { 4433383b3e8fSBjoern A. Zeeb struct mbuf *m; 4434383b3e8fSBjoern A. Zeeb 4435383b3e8fSBjoern A. Zeeb m = skb->m; 4436383b3e8fSBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 4437383b3e8fSBjoern A. Zeeb memset(&txs, 0, sizeof(txs)); 4438383b3e8fSBjoern A. Zeeb } else { 4439383b3e8fSBjoern A. Zeeb ni = NULL; 4440383b3e8fSBjoern A. Zeeb } 4441383b3e8fSBjoern A. Zeeb 4442a8397571SBjoern A. Zeeb info = txstat->info; 4443383b3e8fSBjoern A. Zeeb if (info->flags & IEEE80211_TX_STAT_ACK) { 4444383b3e8fSBjoern A. Zeeb status = 0; /* No error. */ 4445383b3e8fSBjoern A. Zeeb txs.status = IEEE80211_RATECTL_TX_SUCCESS; 4446383b3e8fSBjoern A. Zeeb } else { 4447383b3e8fSBjoern A. Zeeb status = 1; 4448383b3e8fSBjoern A. Zeeb txs.status = IEEE80211_RATECTL_TX_FAIL_UNSPECIFIED; 4449383b3e8fSBjoern A. Zeeb } 4450383b3e8fSBjoern A. Zeeb 4451383b3e8fSBjoern A. Zeeb if (ni != NULL) { 4452e2c5ab09SJohn Baldwin int ridx __unused; 4453383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 4454383b3e8fSBjoern A. Zeeb int old_rate; 4455383b3e8fSBjoern A. Zeeb 4456383b3e8fSBjoern A. Zeeb old_rate = ni->ni_vap->iv_bss->ni_txrate; 4457383b3e8fSBjoern A. Zeeb #endif 4458383b3e8fSBjoern A. Zeeb txs.pktlen = skb->len; 4459383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_PKTLEN; 4460383b3e8fSBjoern A. Zeeb if (info->status.rates[0].count > 1) { 4461383b3e8fSBjoern A. Zeeb txs.long_retries = info->status.rates[0].count - 1; /* 1 + retries in drivers. */ 4462383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_LONG_RETRY; 4463383b3e8fSBjoern A. Zeeb } 4464383b3e8fSBjoern A. Zeeb #if 0 /* Unused in net80211 currently. */ 4465a8397571SBjoern A. Zeeb /* XXX-BZ convert check .flags for MCS/VHT/.. */ 4466383b3e8fSBjoern A. Zeeb txs.final_rate = info->status.rates[0].idx; 4467383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_FINAL_RATE; 4468383b3e8fSBjoern A. Zeeb #endif 4469383b3e8fSBjoern A. Zeeb if (info->status.is_valid_ack_signal) { 4470383b3e8fSBjoern A. Zeeb txs.rssi = info->status.ack_signal; /* XXX-BZ CONVERT? */ 4471383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_RSSI; 4472383b3e8fSBjoern A. Zeeb } 4473383b3e8fSBjoern A. Zeeb 4474383b3e8fSBjoern A. Zeeb IMPROVE("only update of rate matches but that requires us to get a proper rate"); 4475383b3e8fSBjoern A. Zeeb ieee80211_ratectl_tx_complete(ni, &txs); 4476383b3e8fSBjoern A. Zeeb ridx = ieee80211_ratectl_rate(ni->ni_vap->iv_bss, NULL, 0); 4477383b3e8fSBjoern A. Zeeb 4478383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 4479383b3e8fSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) { 4480383b3e8fSBjoern A. Zeeb printf("TX-RATE: %s: old %d new %d ridx %d, " 4481383b3e8fSBjoern A. Zeeb "long_retries %d\n", __func__, 4482383b3e8fSBjoern A. Zeeb old_rate, ni->ni_vap->iv_bss->ni_txrate, 4483383b3e8fSBjoern A. Zeeb ridx, txs.long_retries); 4484383b3e8fSBjoern A. Zeeb } 4485383b3e8fSBjoern A. Zeeb #endif 4486383b3e8fSBjoern A. Zeeb } 4487383b3e8fSBjoern A. Zeeb 4488383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 4489383b3e8fSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 4490383b3e8fSBjoern A. Zeeb printf("TX-STATUS: %s: hw %p skb %p status %d : flags %#x " 4491383b3e8fSBjoern A. Zeeb "band %u hw_queue %u tx_time_est %d : " 4492383b3e8fSBjoern A. Zeeb "rates [ %u %u %#x, %u %u %#x, %u %u %#x, %u %u %#x ] " 4493383b3e8fSBjoern A. Zeeb "ack_signal %u ampdu_ack_len %u ampdu_len %u antenna %u " 4494383b3e8fSBjoern A. Zeeb "tx_time %u is_valid_ack_signal %u " 4495383b3e8fSBjoern A. Zeeb "status_driver_data [ %p %p ]\n", 4496383b3e8fSBjoern A. Zeeb __func__, hw, skb, status, info->flags, 4497383b3e8fSBjoern A. Zeeb info->band, info->hw_queue, info->tx_time_est, 4498383b3e8fSBjoern A. Zeeb info->status.rates[0].idx, info->status.rates[0].count, 4499383b3e8fSBjoern A. Zeeb info->status.rates[0].flags, 4500383b3e8fSBjoern A. Zeeb info->status.rates[1].idx, info->status.rates[1].count, 4501383b3e8fSBjoern A. Zeeb info->status.rates[1].flags, 4502383b3e8fSBjoern A. Zeeb info->status.rates[2].idx, info->status.rates[2].count, 4503383b3e8fSBjoern A. Zeeb info->status.rates[2].flags, 4504383b3e8fSBjoern A. Zeeb info->status.rates[3].idx, info->status.rates[3].count, 4505383b3e8fSBjoern A. Zeeb info->status.rates[3].flags, 4506383b3e8fSBjoern A. Zeeb info->status.ack_signal, info->status.ampdu_ack_len, 4507383b3e8fSBjoern A. Zeeb info->status.ampdu_len, info->status.antenna, 4508383b3e8fSBjoern A. Zeeb info->status.tx_time, info->status.is_valid_ack_signal, 4509383b3e8fSBjoern A. Zeeb info->status.status_driver_data[0], 4510383b3e8fSBjoern A. Zeeb info->status.status_driver_data[1]); 4511383b3e8fSBjoern A. Zeeb #endif 4512383b3e8fSBjoern A. Zeeb 4513a8397571SBjoern A. Zeeb if (txstat->free_list) { 4514a8397571SBjoern A. Zeeb _lkpi_ieee80211_free_txskb(hw, skb, status); 4515a8397571SBjoern A. Zeeb list_add_tail(&skb->list, txstat->free_list); 4516a8397571SBjoern A. Zeeb } else { 4517383b3e8fSBjoern A. Zeeb linuxkpi_ieee80211_free_txskb(hw, skb, status); 4518383b3e8fSBjoern A. Zeeb } 4519a8397571SBjoern A. Zeeb } 4520a8397571SBjoern A. Zeeb 4521a8397571SBjoern A. Zeeb void 4522a8397571SBjoern A. Zeeb linuxkpi_ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb) 4523a8397571SBjoern A. Zeeb { 4524a8397571SBjoern A. Zeeb struct ieee80211_tx_status status; 4525a8397571SBjoern A. Zeeb 4526a8397571SBjoern A. Zeeb memset(&status, 0, sizeof(status)); 4527a8397571SBjoern A. Zeeb status.info = IEEE80211_SKB_CB(skb); 4528a8397571SBjoern A. Zeeb status.skb = skb; 4529a8397571SBjoern A. Zeeb /* sta, n_rates, rates, free_list? */ 4530a8397571SBjoern A. Zeeb 4531a8397571SBjoern A. Zeeb ieee80211_tx_status_ext(hw, &status); 4532a8397571SBjoern A. Zeeb } 4533383b3e8fSBjoern A. Zeeb 45346b4cac81SBjoern A. Zeeb /* 45356b4cac81SBjoern A. Zeeb * This is an internal bandaid for the moment for the way we glue 45366b4cac81SBjoern A. Zeeb * skbs and mbufs together for TX. Once we have skbs backed by 45376b4cac81SBjoern A. Zeeb * mbufs this should go away. 45386b4cac81SBjoern A. Zeeb * This is a public function but kept on the private KPI (lkpi_) 45396b4cac81SBjoern A. Zeeb * and is not exposed by a header file. 45406b4cac81SBjoern A. Zeeb */ 45416b4cac81SBjoern A. Zeeb static void 45426b4cac81SBjoern A. Zeeb lkpi_ieee80211_free_skb_mbuf(void *p) 45436b4cac81SBjoern A. Zeeb { 45446b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 45456b4cac81SBjoern A. Zeeb struct mbuf *m; 45466b4cac81SBjoern A. Zeeb 45476b4cac81SBjoern A. Zeeb if (p == NULL) 45486b4cac81SBjoern A. Zeeb return; 45496b4cac81SBjoern A. Zeeb 45506b4cac81SBjoern A. Zeeb m = (struct mbuf *)p; 45516b4cac81SBjoern A. Zeeb M_ASSERTPKTHDR(m); 45526b4cac81SBjoern A. Zeeb 45536b4cac81SBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 45546b4cac81SBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = NULL; 45556b4cac81SBjoern A. Zeeb if (ni != NULL) 45566b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 45576b4cac81SBjoern A. Zeeb m_freem(m); 45586b4cac81SBjoern A. Zeeb } 45596b4cac81SBjoern A. Zeeb 45606b4cac81SBjoern A. Zeeb void 45616b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_queue_delayed_work(struct ieee80211_hw *hw, 45626b4cac81SBjoern A. Zeeb struct delayed_work *w, int delay) 45636b4cac81SBjoern A. Zeeb { 45646b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 45656b4cac81SBjoern A. Zeeb 45666b4cac81SBjoern A. Zeeb /* Need to make sure hw is in a stable (non-suspended) state. */ 45676b4cac81SBjoern A. Zeeb IMPROVE(); 45686b4cac81SBjoern A. Zeeb 45696b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 45706b4cac81SBjoern A. Zeeb queue_delayed_work(lhw->workq, w, delay); 45716b4cac81SBjoern A. Zeeb } 45726b4cac81SBjoern A. Zeeb 45736b4cac81SBjoern A. Zeeb void 45746b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_queue_work(struct ieee80211_hw *hw, 45756b4cac81SBjoern A. Zeeb struct work_struct *w) 45766b4cac81SBjoern A. Zeeb { 45776b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 45786b4cac81SBjoern A. Zeeb 45796b4cac81SBjoern A. Zeeb /* Need to make sure hw is in a stable (non-suspended) state. */ 45806b4cac81SBjoern A. Zeeb IMPROVE(); 45816b4cac81SBjoern A. Zeeb 45826b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 45836b4cac81SBjoern A. Zeeb queue_work(lhw->workq, w); 45846b4cac81SBjoern A. Zeeb } 45856b4cac81SBjoern A. Zeeb 45866b4cac81SBjoern A. Zeeb struct sk_buff * 4587ade774b1SBjoern A. Zeeb linuxkpi_ieee80211_probereq_get(struct ieee80211_hw *hw, uint8_t *addr, 4588ade774b1SBjoern A. Zeeb uint8_t *ssid, size_t ssid_len, size_t tailroom) 4589ade774b1SBjoern A. Zeeb { 4590ade774b1SBjoern A. Zeeb struct sk_buff *skb; 4591ade774b1SBjoern A. Zeeb struct ieee80211_frame *wh; 4592ade774b1SBjoern A. Zeeb uint8_t *p; 4593ade774b1SBjoern A. Zeeb size_t len; 4594ade774b1SBjoern A. Zeeb 4595ade774b1SBjoern A. Zeeb len = sizeof(*wh); 4596ade774b1SBjoern A. Zeeb len += 2 + ssid_len; 4597ade774b1SBjoern A. Zeeb 4598ade774b1SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + len + tailroom); 4599ade774b1SBjoern A. Zeeb if (skb == NULL) 4600ade774b1SBjoern A. Zeeb return (NULL); 4601ade774b1SBjoern A. Zeeb 4602ade774b1SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 4603ade774b1SBjoern A. Zeeb 4604ade774b1SBjoern A. Zeeb wh = skb_put_zero(skb, sizeof(*wh)); 4605ade774b1SBjoern A. Zeeb wh->i_fc[0] = IEEE80211_FC0_VERSION_0; 4606ade774b1SBjoern A. Zeeb wh->i_fc[0] |= IEEE80211_FC0_SUBTYPE_PROBE_REQ | IEEE80211_FC0_TYPE_MGT; 4607ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr1, ieee80211broadcastaddr); 4608ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr2, addr); 4609ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr3, ieee80211broadcastaddr); 4610ade774b1SBjoern A. Zeeb 4611ade774b1SBjoern A. Zeeb p = skb_put(skb, 2 + ssid_len); 4612ade774b1SBjoern A. Zeeb *p++ = IEEE80211_ELEMID_SSID; 4613ade774b1SBjoern A. Zeeb *p++ = ssid_len; 4614ade774b1SBjoern A. Zeeb if (ssid_len > 0) 4615ade774b1SBjoern A. Zeeb memcpy(p, ssid, ssid_len); 4616ade774b1SBjoern A. Zeeb 4617ade774b1SBjoern A. Zeeb return (skb); 4618ade774b1SBjoern A. Zeeb } 4619ade774b1SBjoern A. Zeeb 4620ade774b1SBjoern A. Zeeb struct sk_buff * 46216b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_pspoll_get(struct ieee80211_hw *hw, 46226b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif) 46236b4cac81SBjoern A. Zeeb { 46246b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 46256b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 46266b4cac81SBjoern A. Zeeb struct sk_buff *skb; 46276b4cac81SBjoern A. Zeeb struct ieee80211_frame_pspoll *psp; 46286b4cac81SBjoern A. Zeeb uint16_t v; 46296b4cac81SBjoern A. Zeeb 46306b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*psp)); 46316b4cac81SBjoern A. Zeeb if (skb == NULL) 46326b4cac81SBjoern A. Zeeb return (NULL); 46336b4cac81SBjoern A. Zeeb 46346b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 46356b4cac81SBjoern A. Zeeb 46366b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 46376b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 46386b4cac81SBjoern A. Zeeb 46396b4cac81SBjoern A. Zeeb psp = skb_put_zero(skb, sizeof(*psp)); 46406b4cac81SBjoern A. Zeeb psp->i_fc[0] = IEEE80211_FC0_VERSION_0; 46416b4cac81SBjoern A. Zeeb psp->i_fc[0] |= IEEE80211_FC0_SUBTYPE_PS_POLL | IEEE80211_FC0_TYPE_CTL; 46426b4cac81SBjoern A. Zeeb v = htole16(vif->bss_conf.aid | 1<<15 | 1<<16); 46436b4cac81SBjoern A. Zeeb memcpy(&psp->i_aid, &v, sizeof(v)); 46446b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(psp->i_bssid, vap->iv_bss->ni_macaddr); 46456b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(psp->i_ta, vif->addr); 46466b4cac81SBjoern A. Zeeb 46476b4cac81SBjoern A. Zeeb return (skb); 46486b4cac81SBjoern A. Zeeb } 46496b4cac81SBjoern A. Zeeb 46506b4cac81SBjoern A. Zeeb struct sk_buff * 46516b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_nullfunc_get(struct ieee80211_hw *hw, 46526b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif, bool qos) 46536b4cac81SBjoern A. Zeeb { 46546b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 46556b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 46566b4cac81SBjoern A. Zeeb struct sk_buff *skb; 46576b4cac81SBjoern A. Zeeb struct ieee80211_frame *nullf; 46586b4cac81SBjoern A. Zeeb 46596b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*nullf)); 46606b4cac81SBjoern A. Zeeb if (skb == NULL) 46616b4cac81SBjoern A. Zeeb return (NULL); 46626b4cac81SBjoern A. Zeeb 46636b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 46646b4cac81SBjoern A. Zeeb 46656b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 46666b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 46676b4cac81SBjoern A. Zeeb 46686b4cac81SBjoern A. Zeeb nullf = skb_put_zero(skb, sizeof(*nullf)); 46696b4cac81SBjoern A. Zeeb nullf->i_fc[0] = IEEE80211_FC0_VERSION_0; 46706b4cac81SBjoern A. Zeeb nullf->i_fc[0] |= IEEE80211_FC0_SUBTYPE_NODATA | IEEE80211_FC0_TYPE_DATA; 46716b4cac81SBjoern A. Zeeb nullf->i_fc[1] = IEEE80211_FC1_DIR_TODS; 46726b4cac81SBjoern A. Zeeb 46736b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr1, vap->iv_bss->ni_bssid); 46746b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr2, vif->addr); 46756b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr3, vap->iv_bss->ni_macaddr); 46766b4cac81SBjoern A. Zeeb 46776b4cac81SBjoern A. Zeeb return (skb); 46786b4cac81SBjoern A. Zeeb } 46796b4cac81SBjoern A. Zeeb 46806b4cac81SBjoern A. Zeeb struct wireless_dev * 46816b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_vif_to_wdev(struct ieee80211_vif *vif) 46826b4cac81SBjoern A. Zeeb { 46836b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 46846b4cac81SBjoern A. Zeeb 46856b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 46866b4cac81SBjoern A. Zeeb return (&lvif->wdev); 46876b4cac81SBjoern A. Zeeb } 46886b4cac81SBjoern A. Zeeb 46896b4cac81SBjoern A. Zeeb void 46906b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_connection_loss(struct ieee80211_vif *vif) 46916b4cac81SBjoern A. Zeeb { 46926b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 46936b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 46946b4cac81SBjoern A. Zeeb enum ieee80211_state nstate; 46956b4cac81SBjoern A. Zeeb int arg; 46966b4cac81SBjoern A. Zeeb 46976b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 46986b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 46996b4cac81SBjoern A. Zeeb 47006b4cac81SBjoern A. Zeeb /* 4701f3229b62SBjoern A. Zeeb * Go to init; otherwise we need to elaborately check state and 47026b4cac81SBjoern A. Zeeb * handle accordingly, e.g., if in RUN we could call iv_bmiss. 47036b4cac81SBjoern A. Zeeb * Let the statemachine handle all neccessary changes. 47046b4cac81SBjoern A. Zeeb */ 4705f3229b62SBjoern A. Zeeb nstate = IEEE80211_S_INIT; 4706bb81db90SBjoern A. Zeeb arg = 0; /* Not a valid reason. */ 47076b4cac81SBjoern A. Zeeb 47089d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 47099d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 47106b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: vif %p\n", __func__, vif); 47119d9ba2b7SBjoern A. Zeeb #endif 47126b4cac81SBjoern A. Zeeb ieee80211_new_state(vap, nstate, arg); 47136b4cac81SBjoern A. Zeeb } 47146b4cac81SBjoern A. Zeeb 4715bb81db90SBjoern A. Zeeb void 4716bb81db90SBjoern A. Zeeb linuxkpi_ieee80211_beacon_loss(struct ieee80211_vif *vif) 4717bb81db90SBjoern A. Zeeb { 4718bb81db90SBjoern A. Zeeb struct lkpi_vif *lvif; 4719bb81db90SBjoern A. Zeeb struct ieee80211vap *vap; 4720bb81db90SBjoern A. Zeeb 4721bb81db90SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 4722bb81db90SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 4723bb81db90SBjoern A. Zeeb 47249d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 47259d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE || vap->iv_state != IEEE80211_S_RUN) 4726bb81db90SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: vif %p vap %p state %s\n", __func__, 4727bb81db90SBjoern A. Zeeb vif, vap, ieee80211_state_name[vap->iv_state]); 47289d9ba2b7SBjoern A. Zeeb #endif 47293540911bSBjoern A. Zeeb ieee80211_beacon_miss(vap->iv_ic); 4730bb81db90SBjoern A. Zeeb } 4731bb81db90SBjoern A. Zeeb 47325edde07cSBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 47335edde07cSBjoern A. Zeeb 47345a9a0d78SBjoern A. Zeeb void 47355a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_stop_queue(struct ieee80211_hw *hw, int qnum) 47365a9a0d78SBjoern A. Zeeb { 47375a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 47385a9a0d78SBjoern A. Zeeb struct lkpi_vif *lvif; 47395a9a0d78SBjoern A. Zeeb struct ieee80211_vif *vif; 47405a9a0d78SBjoern A. Zeeb int ac_count, ac; 47415a9a0d78SBjoern A. Zeeb 47425a9a0d78SBjoern A. Zeeb KASSERT(qnum < hw->queues, ("%s: qnum %d >= hw->queues %d, hw %p\n", 47435a9a0d78SBjoern A. Zeeb __func__, qnum, hw->queues, hw)); 47445a9a0d78SBjoern A. Zeeb 47455a9a0d78SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 47465a9a0d78SBjoern A. Zeeb 47475a9a0d78SBjoern A. Zeeb /* See lkpi_ic_vap_create(). */ 47485a9a0d78SBjoern A. Zeeb if (hw->queues >= IEEE80211_NUM_ACS) 47495a9a0d78SBjoern A. Zeeb ac_count = IEEE80211_NUM_ACS; 47505a9a0d78SBjoern A. Zeeb else 47515a9a0d78SBjoern A. Zeeb ac_count = 1; 47525a9a0d78SBjoern A. Zeeb 47535a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 47545a9a0d78SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 47555a9a0d78SBjoern A. Zeeb 47565a9a0d78SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 47575a9a0d78SBjoern A. Zeeb for (ac = 0; ac < ac_count; ac++) { 47585a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 47595a9a0d78SBjoern A. Zeeb if (qnum == vif->hw_queue[ac]) { 47605a9a0d78SBjoern A. Zeeb /* 47615a9a0d78SBjoern A. Zeeb * For now log this to better understand 47625a9a0d78SBjoern A. Zeeb * how this is supposed to work. 47635a9a0d78SBjoern A. Zeeb */ 47645a9a0d78SBjoern A. Zeeb if (lvif->hw_queue_stopped[ac]) 47655a9a0d78SBjoern A. Zeeb ic_printf(lhw->ic, "%s:%d: lhw %p hw %p " 47665a9a0d78SBjoern A. Zeeb "lvif %p vif %p ac %d qnum %d already " 47675a9a0d78SBjoern A. Zeeb "stopped\n", __func__, __LINE__, 47685a9a0d78SBjoern A. Zeeb lhw, hw, lvif, vif, ac, qnum); 47695a9a0d78SBjoern A. Zeeb lvif->hw_queue_stopped[ac] = true; 47705a9a0d78SBjoern A. Zeeb } 47715a9a0d78SBjoern A. Zeeb } 47725a9a0d78SBjoern A. Zeeb } 47735a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 47745a9a0d78SBjoern A. Zeeb } 47755a9a0d78SBjoern A. Zeeb 47765a9a0d78SBjoern A. Zeeb void 47775a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_stop_queues(struct ieee80211_hw *hw) 47785a9a0d78SBjoern A. Zeeb { 47795a9a0d78SBjoern A. Zeeb int i; 47805a9a0d78SBjoern A. Zeeb 47815a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Locking; do we need further info?"); 47825a9a0d78SBjoern A. Zeeb for (i = 0; i < hw->queues; i++) 47835a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_stop_queue(hw, i); 47845a9a0d78SBjoern A. Zeeb } 47855a9a0d78SBjoern A. Zeeb 47865a9a0d78SBjoern A. Zeeb 47875a9a0d78SBjoern A. Zeeb static void 47885a9a0d78SBjoern A. Zeeb lkpi_ieee80211_wake_queues(struct ieee80211_hw *hw, int hwq) 47895a9a0d78SBjoern A. Zeeb { 47905a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 47915a9a0d78SBjoern A. Zeeb struct lkpi_vif *lvif; 47925a9a0d78SBjoern A. Zeeb struct lkpi_sta *lsta; 47935a9a0d78SBjoern A. Zeeb int ac_count, ac, tid; 47945a9a0d78SBjoern A. Zeeb 47955a9a0d78SBjoern A. Zeeb /* See lkpi_ic_vap_create(). */ 47965a9a0d78SBjoern A. Zeeb if (hw->queues >= IEEE80211_NUM_ACS) 47975a9a0d78SBjoern A. Zeeb ac_count = IEEE80211_NUM_ACS; 47985a9a0d78SBjoern A. Zeeb else 47995a9a0d78SBjoern A. Zeeb ac_count = 1; 48005a9a0d78SBjoern A. Zeeb 48015a9a0d78SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 48025a9a0d78SBjoern A. Zeeb 48035a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Locking"); 48045a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 48055a9a0d78SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 48065a9a0d78SBjoern A. Zeeb struct ieee80211_vif *vif; 48075a9a0d78SBjoern A. Zeeb 48085a9a0d78SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 48095a9a0d78SBjoern A. Zeeb for (ac = 0; ac < ac_count; ac++) { 48105a9a0d78SBjoern A. Zeeb 48115a9a0d78SBjoern A. Zeeb if (hwq == vif->hw_queue[ac]) { 48125a9a0d78SBjoern A. Zeeb 48135a9a0d78SBjoern A. Zeeb /* XXX-BZ what about software scan? */ 48145a9a0d78SBjoern A. Zeeb 48155a9a0d78SBjoern A. Zeeb /* 48165a9a0d78SBjoern A. Zeeb * For now log this to better understand 48175a9a0d78SBjoern A. Zeeb * how this is supposed to work. 48185a9a0d78SBjoern A. Zeeb */ 48195a9a0d78SBjoern A. Zeeb if (!lvif->hw_queue_stopped[ac]) 48205a9a0d78SBjoern A. Zeeb ic_printf(lhw->ic, "%s:%d: lhw %p hw %p " 48215a9a0d78SBjoern A. Zeeb "lvif %p vif %p ac %d hw_q not stopped\n", 48225a9a0d78SBjoern A. Zeeb __func__, __LINE__, 48235a9a0d78SBjoern A. Zeeb lhw, hw, lvif, vif, ac); 48245a9a0d78SBjoern A. Zeeb lvif->hw_queue_stopped[ac] = false; 48255a9a0d78SBjoern A. Zeeb 48265a9a0d78SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 48275a9a0d78SBjoern A. Zeeb TAILQ_FOREACH(lsta, &lvif->lsta_head, lsta_entry) { 48285a9a0d78SBjoern A. Zeeb struct ieee80211_sta *sta; 48295a9a0d78SBjoern A. Zeeb 48305a9a0d78SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 48315a9a0d78SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 48325a9a0d78SBjoern A. Zeeb struct lkpi_txq *ltxq; 48335a9a0d78SBjoern A. Zeeb 48345a9a0d78SBjoern A. Zeeb if (sta->txq[tid] == NULL) 48355a9a0d78SBjoern A. Zeeb continue; 48365a9a0d78SBjoern A. Zeeb 48375a9a0d78SBjoern A. Zeeb if (sta->txq[tid]->ac != ac) 48385a9a0d78SBjoern A. Zeeb continue; 48395a9a0d78SBjoern A. Zeeb 48405a9a0d78SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]); 48415a9a0d78SBjoern A. Zeeb if (!ltxq->stopped) 48425a9a0d78SBjoern A. Zeeb continue; 48435a9a0d78SBjoern A. Zeeb 48445a9a0d78SBjoern A. Zeeb ltxq->stopped = false; 48455a9a0d78SBjoern A. Zeeb 48465a9a0d78SBjoern A. Zeeb /* XXX-BZ see when this explodes with all the locking. taskq? */ 48475a9a0d78SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, sta->txq[tid]); 48485a9a0d78SBjoern A. Zeeb } 48495a9a0d78SBjoern A. Zeeb } 48505a9a0d78SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 48515a9a0d78SBjoern A. Zeeb } 48525a9a0d78SBjoern A. Zeeb } 48535a9a0d78SBjoern A. Zeeb } 48545a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 48555a9a0d78SBjoern A. Zeeb } 48565a9a0d78SBjoern A. Zeeb 48575a9a0d78SBjoern A. Zeeb void 48585a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_wake_queues(struct ieee80211_hw *hw) 48595a9a0d78SBjoern A. Zeeb { 48605a9a0d78SBjoern A. Zeeb int i; 48615a9a0d78SBjoern A. Zeeb 48625a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Is this all/enough here?"); 48635a9a0d78SBjoern A. Zeeb for (i = 0; i < hw->queues; i++) 48645a9a0d78SBjoern A. Zeeb lkpi_ieee80211_wake_queues(hw, i); 48655a9a0d78SBjoern A. Zeeb } 48665a9a0d78SBjoern A. Zeeb 48675a9a0d78SBjoern A. Zeeb void 48685a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_wake_queue(struct ieee80211_hw *hw, int qnum) 48695a9a0d78SBjoern A. Zeeb { 48705a9a0d78SBjoern A. Zeeb 48715a9a0d78SBjoern A. Zeeb KASSERT(qnum < hw->queues, ("%s: qnum %d >= hw->queues %d, hw %p\n", 48725a9a0d78SBjoern A. Zeeb __func__, qnum, hw->queues, hw)); 48735a9a0d78SBjoern A. Zeeb 48745a9a0d78SBjoern A. Zeeb lkpi_ieee80211_wake_queues(hw, qnum); 48755a9a0d78SBjoern A. Zeeb } 48765a9a0d78SBjoern A. Zeeb 48775a9a0d78SBjoern A. Zeeb /* This is just hardware queues. */ 48785a9a0d78SBjoern A. Zeeb void 48795a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_txq_schedule_start(struct ieee80211_hw *hw, uint8_t ac) 48805a9a0d78SBjoern A. Zeeb { 48815a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 48825a9a0d78SBjoern A. Zeeb 48835a9a0d78SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 48845a9a0d78SBjoern A. Zeeb 48855a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Are there reasons why we wouldn't schedule?"); 48865a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 48875a9a0d78SBjoern A. Zeeb if (++lhw->txq_generation[ac] == 0) 48885a9a0d78SBjoern A. Zeeb lhw->txq_generation[ac]++; 48895a9a0d78SBjoern A. Zeeb } 48905a9a0d78SBjoern A. Zeeb 48915a9a0d78SBjoern A. Zeeb struct ieee80211_txq * 48925a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_next_txq(struct ieee80211_hw *hw, uint8_t ac) 48935a9a0d78SBjoern A. Zeeb { 48945a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 48955a9a0d78SBjoern A. Zeeb struct ieee80211_txq *txq; 48965a9a0d78SBjoern A. Zeeb struct lkpi_txq *ltxq; 48975a9a0d78SBjoern A. Zeeb 48985a9a0d78SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 48995a9a0d78SBjoern A. Zeeb txq = NULL; 49005a9a0d78SBjoern A. Zeeb 49015a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 49025a9a0d78SBjoern A. Zeeb 49035a9a0d78SBjoern A. Zeeb /* Check that we are scheduled. */ 49045a9a0d78SBjoern A. Zeeb if (lhw->txq_generation[ac] == 0) 49055a9a0d78SBjoern A. Zeeb goto out; 49065a9a0d78SBjoern A. Zeeb 49075a9a0d78SBjoern A. Zeeb ltxq = TAILQ_FIRST(&lhw->scheduled_txqs[ac]); 49085a9a0d78SBjoern A. Zeeb if (ltxq == NULL) 49095a9a0d78SBjoern A. Zeeb goto out; 49105a9a0d78SBjoern A. Zeeb if (ltxq->txq_generation == lhw->txq_generation[ac]) 49115a9a0d78SBjoern A. Zeeb goto out; 49125a9a0d78SBjoern A. Zeeb 49135a9a0d78SBjoern A. Zeeb ltxq->txq_generation = lhw->txq_generation[ac]; 49145a9a0d78SBjoern A. Zeeb TAILQ_REMOVE(&lhw->scheduled_txqs[ac], ltxq, txq_entry); 49155a9a0d78SBjoern A. Zeeb txq = <xq->txq; 49165a9a0d78SBjoern A. Zeeb TAILQ_ELEM_INIT(ltxq, txq_entry); 49175a9a0d78SBjoern A. Zeeb 49185a9a0d78SBjoern A. Zeeb out: 49195a9a0d78SBjoern A. Zeeb return (txq); 49205a9a0d78SBjoern A. Zeeb } 49215a9a0d78SBjoern A. Zeeb 49225a9a0d78SBjoern A. Zeeb void linuxkpi_ieee80211_schedule_txq(struct ieee80211_hw *hw, 49235a9a0d78SBjoern A. Zeeb struct ieee80211_txq *txq, bool withoutpkts) 49245a9a0d78SBjoern A. Zeeb { 49255a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 49265a9a0d78SBjoern A. Zeeb struct lkpi_txq *ltxq; 49275a9a0d78SBjoern A. Zeeb 49285a9a0d78SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 49295a9a0d78SBjoern A. Zeeb 49305a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 49315a9a0d78SBjoern A. Zeeb 49325a9a0d78SBjoern A. Zeeb /* Only schedule if work to do or asked to anyway. */ 49335a9a0d78SBjoern A. Zeeb if (!withoutpkts && skb_queue_empty(<xq->skbq)) 49345a9a0d78SBjoern A. Zeeb goto out; 49355a9a0d78SBjoern A. Zeeb 49365a9a0d78SBjoern A. Zeeb /* Make sure we do not double-schedule. */ 49375a9a0d78SBjoern A. Zeeb if (ltxq->txq_entry.tqe_next != NULL) 49385a9a0d78SBjoern A. Zeeb goto out; 49395a9a0d78SBjoern A. Zeeb 49405a9a0d78SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 49415a9a0d78SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lhw->scheduled_txqs[txq->ac], ltxq, txq_entry); 49425a9a0d78SBjoern A. Zeeb out: 49435a9a0d78SBjoern A. Zeeb return; 49445a9a0d78SBjoern A. Zeeb } 49455a9a0d78SBjoern A. Zeeb 49465a9a0d78SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 49475a9a0d78SBjoern A. Zeeb 49485edde07cSBjoern A. Zeeb struct lkpi_cfg80211_bss { 49495edde07cSBjoern A. Zeeb u_int refcnt; 49505edde07cSBjoern A. Zeeb struct cfg80211_bss bss; 49515edde07cSBjoern A. Zeeb }; 49525edde07cSBjoern A. Zeeb 49535edde07cSBjoern A. Zeeb struct lkpi_cfg80211_get_bss_iter_lookup { 49545edde07cSBjoern A. Zeeb struct wiphy *wiphy; 49555edde07cSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 49565edde07cSBjoern A. Zeeb const uint8_t *bssid; 49575edde07cSBjoern A. Zeeb const uint8_t *ssid; 49585edde07cSBjoern A. Zeeb size_t ssid_len; 49595edde07cSBjoern A. Zeeb enum ieee80211_bss_type bss_type; 49605edde07cSBjoern A. Zeeb enum ieee80211_privacy privacy; 49615edde07cSBjoern A. Zeeb 49625edde07cSBjoern A. Zeeb /* 49635edde07cSBjoern A. Zeeb * Something to store a copy of the result as the net80211 scan cache 49645edde07cSBjoern A. Zeeb * is not refoucnted so a scan entry might go away any time. 49655edde07cSBjoern A. Zeeb */ 49665edde07cSBjoern A. Zeeb bool match; 49675edde07cSBjoern A. Zeeb struct cfg80211_bss *bss; 49685edde07cSBjoern A. Zeeb }; 49695edde07cSBjoern A. Zeeb 49705edde07cSBjoern A. Zeeb static void 49715edde07cSBjoern A. Zeeb lkpi_cfg80211_get_bss_iterf(void *arg, const struct ieee80211_scan_entry *se) 49725edde07cSBjoern A. Zeeb { 49735edde07cSBjoern A. Zeeb struct lkpi_cfg80211_get_bss_iter_lookup *lookup; 49745edde07cSBjoern A. Zeeb size_t ielen; 49755edde07cSBjoern A. Zeeb 49765edde07cSBjoern A. Zeeb lookup = arg; 49775edde07cSBjoern A. Zeeb 49785edde07cSBjoern A. Zeeb /* Do not try to find another match. */ 49795edde07cSBjoern A. Zeeb if (lookup->match) 49805edde07cSBjoern A. Zeeb return; 49815edde07cSBjoern A. Zeeb 49825edde07cSBjoern A. Zeeb /* Nothing to store result. */ 49835edde07cSBjoern A. Zeeb if (lookup->bss == NULL) 49845edde07cSBjoern A. Zeeb return; 49855edde07cSBjoern A. Zeeb 49865edde07cSBjoern A. Zeeb if (lookup->privacy != IEEE80211_PRIVACY_ANY) { 49875edde07cSBjoern A. Zeeb /* if (se->se_capinfo & IEEE80211_CAPINFO_PRIVACY) */ 49885edde07cSBjoern A. Zeeb /* We have no idea what to compare to as the drivers only request ANY */ 49895edde07cSBjoern A. Zeeb return; 49905edde07cSBjoern A. Zeeb } 49915edde07cSBjoern A. Zeeb 49925edde07cSBjoern A. Zeeb if (lookup->bss_type != IEEE80211_BSS_TYPE_ANY) { 49935edde07cSBjoern A. Zeeb /* if (se->se_capinfo & (IEEE80211_CAPINFO_IBSS|IEEE80211_CAPINFO_ESS)) */ 49945edde07cSBjoern A. Zeeb /* We have no idea what to compare to as the drivers only request ANY */ 49955edde07cSBjoern A. Zeeb return; 49965edde07cSBjoern A. Zeeb } 49975edde07cSBjoern A. Zeeb 49985edde07cSBjoern A. Zeeb if (lookup->chan != NULL) { 49995edde07cSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 50005edde07cSBjoern A. Zeeb 50015edde07cSBjoern A. Zeeb chan = linuxkpi_ieee80211_get_channel(lookup->wiphy, 50025edde07cSBjoern A. Zeeb se->se_chan->ic_freq); 50035edde07cSBjoern A. Zeeb if (chan == NULL || chan != lookup->chan) 50045edde07cSBjoern A. Zeeb return; 50055edde07cSBjoern A. Zeeb } 50065edde07cSBjoern A. Zeeb 50075edde07cSBjoern A. Zeeb if (lookup->bssid && !IEEE80211_ADDR_EQ(lookup->bssid, se->se_bssid)) 50085edde07cSBjoern A. Zeeb return; 50095edde07cSBjoern A. Zeeb 50105edde07cSBjoern A. Zeeb if (lookup->ssid) { 50115edde07cSBjoern A. Zeeb if (lookup->ssid_len != se->se_ssid[1] || 50125edde07cSBjoern A. Zeeb se->se_ssid[1] == 0) 50135edde07cSBjoern A. Zeeb return; 50145edde07cSBjoern A. Zeeb if (memcmp(lookup->ssid, se->se_ssid+2, lookup->ssid_len) != 0) 50155edde07cSBjoern A. Zeeb return; 50165edde07cSBjoern A. Zeeb } 50175edde07cSBjoern A. Zeeb 50185edde07cSBjoern A. Zeeb ielen = se->se_ies.len; 50195edde07cSBjoern A. Zeeb 50205edde07cSBjoern A. Zeeb lookup->bss->ies = malloc(sizeof(*lookup->bss->ies) + ielen, 50215edde07cSBjoern A. Zeeb M_LKPI80211, M_NOWAIT | M_ZERO); 50225edde07cSBjoern A. Zeeb if (lookup->bss->ies == NULL) 50235edde07cSBjoern A. Zeeb return; 50245edde07cSBjoern A. Zeeb 50255edde07cSBjoern A. Zeeb lookup->bss->ies->data = (uint8_t *)lookup->bss->ies + sizeof(*lookup->bss->ies); 50265edde07cSBjoern A. Zeeb lookup->bss->ies->len = ielen; 50275edde07cSBjoern A. Zeeb if (ielen) 50285edde07cSBjoern A. Zeeb memcpy(lookup->bss->ies->data, se->se_ies.data, ielen); 50295edde07cSBjoern A. Zeeb 50305edde07cSBjoern A. Zeeb lookup->match = true; 50315edde07cSBjoern A. Zeeb } 50325edde07cSBjoern A. Zeeb 50335edde07cSBjoern A. Zeeb struct cfg80211_bss * 50345edde07cSBjoern A. Zeeb linuxkpi_cfg80211_get_bss(struct wiphy *wiphy, struct linuxkpi_ieee80211_channel *chan, 50355edde07cSBjoern A. Zeeb const uint8_t *bssid, const uint8_t *ssid, size_t ssid_len, 50365edde07cSBjoern A. Zeeb enum ieee80211_bss_type bss_type, enum ieee80211_privacy privacy) 50375edde07cSBjoern A. Zeeb { 50385edde07cSBjoern A. Zeeb struct lkpi_cfg80211_bss *lbss; 50395edde07cSBjoern A. Zeeb struct lkpi_cfg80211_get_bss_iter_lookup lookup; 50405edde07cSBjoern A. Zeeb struct lkpi_hw *lhw; 50415edde07cSBjoern A. Zeeb struct ieee80211vap *vap; 50425edde07cSBjoern A. Zeeb 50435edde07cSBjoern A. Zeeb lhw = wiphy_priv(wiphy); 50445edde07cSBjoern A. Zeeb 50455edde07cSBjoern A. Zeeb /* Let's hope we can alloc. */ 50465edde07cSBjoern A. Zeeb lbss = malloc(sizeof(*lbss), M_LKPI80211, M_NOWAIT | M_ZERO); 50475edde07cSBjoern A. Zeeb if (lbss == NULL) { 50485edde07cSBjoern A. Zeeb ic_printf(lhw->ic, "%s: alloc failed.\n", __func__); 50495edde07cSBjoern A. Zeeb return (NULL); 50505edde07cSBjoern A. Zeeb } 50515edde07cSBjoern A. Zeeb 50525edde07cSBjoern A. Zeeb lookup.wiphy = wiphy; 50535edde07cSBjoern A. Zeeb lookup.chan = chan; 50545edde07cSBjoern A. Zeeb lookup.bssid = bssid; 50555edde07cSBjoern A. Zeeb lookup.ssid = ssid; 50565edde07cSBjoern A. Zeeb lookup.ssid_len = ssid_len; 50575edde07cSBjoern A. Zeeb lookup.bss_type = bss_type; 50585edde07cSBjoern A. Zeeb lookup.privacy = privacy; 50595edde07cSBjoern A. Zeeb lookup.match = false; 50605edde07cSBjoern A. Zeeb lookup.bss = &lbss->bss; 50615edde07cSBjoern A. Zeeb 50625edde07cSBjoern A. Zeeb IMPROVE("Iterate over all VAPs comparing perm_addr and addresses?"); 50635edde07cSBjoern A. Zeeb vap = TAILQ_FIRST(&lhw->ic->ic_vaps); 50645edde07cSBjoern A. Zeeb ieee80211_scan_iterate(vap, lkpi_cfg80211_get_bss_iterf, &lookup); 50655edde07cSBjoern A. Zeeb if (!lookup.match) { 50665edde07cSBjoern A. Zeeb free(lbss, M_LKPI80211); 50675edde07cSBjoern A. Zeeb return (NULL); 50685edde07cSBjoern A. Zeeb } 50695edde07cSBjoern A. Zeeb 50705edde07cSBjoern A. Zeeb refcount_init(&lbss->refcnt, 1); 50715edde07cSBjoern A. Zeeb return (&lbss->bss); 50725edde07cSBjoern A. Zeeb } 50735edde07cSBjoern A. Zeeb 50745edde07cSBjoern A. Zeeb void 50755edde07cSBjoern A. Zeeb linuxkpi_cfg80211_put_bss(struct wiphy *wiphy, struct cfg80211_bss *bss) 50765edde07cSBjoern A. Zeeb { 50775edde07cSBjoern A. Zeeb struct lkpi_cfg80211_bss *lbss; 50785edde07cSBjoern A. Zeeb 50795edde07cSBjoern A. Zeeb lbss = container_of(bss, struct lkpi_cfg80211_bss, bss); 50805edde07cSBjoern A. Zeeb 50815edde07cSBjoern A. Zeeb /* Free everything again on refcount ... */ 50825edde07cSBjoern A. Zeeb if (refcount_release(&lbss->refcnt)) { 50835edde07cSBjoern A. Zeeb free(lbss->bss.ies, M_LKPI80211); 50845edde07cSBjoern A. Zeeb free(lbss, M_LKPI80211); 50855edde07cSBjoern A. Zeeb } 50865edde07cSBjoern A. Zeeb } 50875edde07cSBjoern A. Zeeb 50885edde07cSBjoern A. Zeeb void 50895edde07cSBjoern A. Zeeb linuxkpi_cfg80211_bss_flush(struct wiphy *wiphy) 50905edde07cSBjoern A. Zeeb { 50915edde07cSBjoern A. Zeeb struct lkpi_hw *lhw; 50925edde07cSBjoern A. Zeeb struct ieee80211com *ic; 50935edde07cSBjoern A. Zeeb struct ieee80211vap *vap; 50945edde07cSBjoern A. Zeeb 50955edde07cSBjoern A. Zeeb lhw = wiphy_priv(wiphy); 50965edde07cSBjoern A. Zeeb ic = lhw->ic; 50975edde07cSBjoern A. Zeeb 50985edde07cSBjoern A. Zeeb /* 50995edde07cSBjoern A. Zeeb * If we haven't called ieee80211_ifattach() yet 51005edde07cSBjoern A. Zeeb * or there is no VAP, there are no scans to flush. 51015edde07cSBjoern A. Zeeb */ 51025edde07cSBjoern A. Zeeb if (ic == NULL || 51035edde07cSBjoern A. Zeeb (lhw->sc_flags & LKPI_MAC80211_DRV_STARTED) == 0) 51045edde07cSBjoern A. Zeeb return; 51055edde07cSBjoern A. Zeeb 51065edde07cSBjoern A. Zeeb /* Should only happen on the current one? Not seen it late enough. */ 51075edde07cSBjoern A. Zeeb IEEE80211_LOCK(ic); 51085edde07cSBjoern A. Zeeb TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) 51095edde07cSBjoern A. Zeeb ieee80211_scan_flush(vap); 51105edde07cSBjoern A. Zeeb IEEE80211_UNLOCK(ic); 51115edde07cSBjoern A. Zeeb } 51125edde07cSBjoern A. Zeeb 51135edde07cSBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 51145edde07cSBjoern A. Zeeb 51156b4cac81SBjoern A. Zeeb MODULE_VERSION(linuxkpi_wlan, 1); 51166b4cac81SBjoern A. Zeeb MODULE_DEPEND(linuxkpi_wlan, linuxkpi, 1, 1, 1); 51176b4cac81SBjoern A. Zeeb MODULE_DEPEND(linuxkpi_wlan, wlan, 1, 1, 1); 5118