16b4cac81SBjoern A. Zeeb /*- 28ac540d3SBjoern A. Zeeb * Copyright (c) 2020-2023 The FreeBSD Foundation 3086be6a8SBjoern A. Zeeb * Copyright (c) 2020-2022 Bjoern A. Zeeb 46b4cac81SBjoern A. Zeeb * 56b4cac81SBjoern A. Zeeb * This software was developed by Björn Zeeb under sponsorship from 66b4cac81SBjoern A. Zeeb * the FreeBSD Foundation. 76b4cac81SBjoern A. Zeeb * 86b4cac81SBjoern A. Zeeb * Redistribution and use in source and binary forms, with or without 96b4cac81SBjoern A. Zeeb * modification, are permitted provided that the following conditions 106b4cac81SBjoern A. Zeeb * are met: 116b4cac81SBjoern A. Zeeb * 1. Redistributions of source code must retain the above copyright 126b4cac81SBjoern A. Zeeb * notice, this list of conditions and the following disclaimer. 136b4cac81SBjoern A. Zeeb * 2. Redistributions in binary form must reproduce the above copyright 146b4cac81SBjoern A. Zeeb * notice, this list of conditions and the following disclaimer in the 156b4cac81SBjoern A. Zeeb * documentation and/or other materials provided with the distribution. 166b4cac81SBjoern A. Zeeb * 176b4cac81SBjoern A. Zeeb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 186b4cac81SBjoern A. Zeeb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 196b4cac81SBjoern A. Zeeb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 206b4cac81SBjoern A. Zeeb * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 216b4cac81SBjoern A. Zeeb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 226b4cac81SBjoern A. Zeeb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 236b4cac81SBjoern A. Zeeb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 246b4cac81SBjoern A. Zeeb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 256b4cac81SBjoern A. Zeeb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 266b4cac81SBjoern A. Zeeb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 276b4cac81SBjoern A. Zeeb * SUCH DAMAGE. 286b4cac81SBjoern A. Zeeb */ 296b4cac81SBjoern A. Zeeb 306b4cac81SBjoern A. Zeeb /* 316b4cac81SBjoern A. Zeeb * Public functions are called linuxkpi_*(). 326b4cac81SBjoern A. Zeeb * Internal (static) functions are called lkpi_*(). 336b4cac81SBjoern A. Zeeb * 346b4cac81SBjoern A. Zeeb * The internal structures holding metadata over public structures are also 356b4cac81SBjoern A. Zeeb * called lkpi_xxx (usually with a member at the end called xxx). 366b4cac81SBjoern A. Zeeb * Note: we do not replicate the structure names but the general variable names 376b4cac81SBjoern A. Zeeb * for these (e.g., struct hw -> struct lkpi_hw, struct sta -> struct lkpi_sta). 386b4cac81SBjoern A. Zeeb * There are macros to access one from the other. 396b4cac81SBjoern A. Zeeb * We call the internal versions lxxx (e.g., hw -> lhw, sta -> lsta). 406b4cac81SBjoern A. Zeeb */ 416b4cac81SBjoern A. Zeeb 426b4cac81SBjoern A. Zeeb #include <sys/cdefs.h> 436b4cac81SBjoern A. Zeeb #include <sys/param.h> 446b4cac81SBjoern A. Zeeb #include <sys/types.h> 456b4cac81SBjoern A. Zeeb #include <sys/kernel.h> 466b4cac81SBjoern A. Zeeb #include <sys/errno.h> 476b4cac81SBjoern A. Zeeb #include <sys/malloc.h> 486b4cac81SBjoern A. Zeeb #include <sys/module.h> 496b4cac81SBjoern A. Zeeb #include <sys/mutex.h> 506b4cac81SBjoern A. Zeeb #include <sys/socket.h> 516b4cac81SBjoern A. Zeeb #include <sys/sysctl.h> 526b4cac81SBjoern A. Zeeb #include <sys/queue.h> 536b4cac81SBjoern A. Zeeb #include <sys/taskqueue.h> 54527687a9SBjoern A. Zeeb #include <sys/libkern.h> 556b4cac81SBjoern A. Zeeb 566b4cac81SBjoern A. Zeeb #include <net/if.h> 576b4cac81SBjoern A. Zeeb #include <net/if_var.h> 586b4cac81SBjoern A. Zeeb #include <net/if_media.h> 596b4cac81SBjoern A. Zeeb #include <net/ethernet.h> 606b4cac81SBjoern A. Zeeb 616b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_var.h> 626b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_proto.h> 636b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_ratectl.h> 646b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_radiotap.h> 656b4cac81SBjoern A. Zeeb 666b4cac81SBjoern A. Zeeb #define LINUXKPI_NET80211 676b4cac81SBjoern A. Zeeb #include <net/mac80211.h> 686b4cac81SBjoern A. Zeeb 696b4cac81SBjoern A. Zeeb #include <linux/workqueue.h> 706b4cac81SBjoern A. Zeeb #include "linux_80211.h" 716b4cac81SBjoern A. Zeeb 724a67f1dfSBjoern A. Zeeb #define LKPI_80211_WME 73b35f6cd0SBjoern A. Zeeb /* #define LKPI_80211_HW_CRYPTO */ 74b35f6cd0SBjoern A. Zeeb 756b4cac81SBjoern A. Zeeb static MALLOC_DEFINE(M_LKPI80211, "lkpi80211", "LinuxKPI 80211 compat"); 766b4cac81SBjoern A. Zeeb 775a9a0d78SBjoern A. Zeeb /* XXX-BZ really want this and others in queue.h */ 785a9a0d78SBjoern A. Zeeb #define TAILQ_ELEM_INIT(elm, field) do { \ 795a9a0d78SBjoern A. Zeeb (elm)->field.tqe_next = NULL; \ 805a9a0d78SBjoern A. Zeeb (elm)->field.tqe_prev = NULL; \ 815a9a0d78SBjoern A. Zeeb } while (0) 825a9a0d78SBjoern A. Zeeb 836b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 846b4cac81SBjoern A. Zeeb 859d9ba2b7SBjoern A. Zeeb /* Keep public for as long as header files are using it too. */ 869d9ba2b7SBjoern A. Zeeb int linuxkpi_debug_80211; 876b4cac81SBjoern A. Zeeb 886b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 899d9ba2b7SBjoern A. Zeeb SYSCTL_DECL(_compat_linuxkpi); 909d9ba2b7SBjoern A. Zeeb SYSCTL_NODE(_compat_linuxkpi, OID_AUTO, 80211, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 919d9ba2b7SBjoern A. Zeeb "LinuxKPI 802.11 compatibility layer"); 929d9ba2b7SBjoern A. Zeeb 939d9ba2b7SBjoern A. Zeeb SYSCTL_INT(_compat_linuxkpi_80211, OID_AUTO, debug, CTLFLAG_RWTUN, 949d9ba2b7SBjoern A. Zeeb &linuxkpi_debug_80211, 0, "LinuxKPI 802.11 debug level"); 959d9ba2b7SBjoern A. Zeeb 969d9ba2b7SBjoern A. Zeeb #define UNIMPLEMENTED if (linuxkpi_debug_80211 & D80211_TODO) \ 976b4cac81SBjoern A. Zeeb printf("XXX-TODO %s:%d: UNIMPLEMENTED\n", __func__, __LINE__) 989d9ba2b7SBjoern A. Zeeb #define TRACEOK() if (linuxkpi_debug_80211 & D80211_TRACEOK) \ 996b4cac81SBjoern A. Zeeb printf("XXX-TODO %s:%d: TRACEPOINT\n", __func__, __LINE__) 1006b4cac81SBjoern A. Zeeb #else 1016b4cac81SBjoern A. Zeeb #define UNIMPLEMENTED do { } while (0) 1026b4cac81SBjoern A. Zeeb #define TRACEOK() do { } while (0) 1036b4cac81SBjoern A. Zeeb #endif 1046b4cac81SBjoern A. Zeeb 1056b4cac81SBjoern A. Zeeb /* #define PREP_TX_INFO_DURATION (IEEE80211_TRANS_WAIT * 1000) */ 1066b4cac81SBjoern A. Zeeb #ifndef PREP_TX_INFO_DURATION 1076b4cac81SBjoern A. Zeeb #define PREP_TX_INFO_DURATION 0 /* Let the driver do its thing. */ 1086b4cac81SBjoern A. Zeeb #endif 1096b4cac81SBjoern A. Zeeb 110caaa79c3SBjoern A. Zeeb /* c.f. ieee80211_ioctl.c */ 111caaa79c3SBjoern A. Zeeb static const uint8_t zerobssid[IEEE80211_ADDR_LEN]; 112caaa79c3SBjoern A. Zeeb 1136b4cac81SBjoern A. Zeeb /* This is DSAP | SSAP | CTRL | ProtoID/OrgCode{3}. */ 1146b4cac81SBjoern A. Zeeb const uint8_t rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; 1156b4cac81SBjoern A. Zeeb 116b0f73768SBjoern A. Zeeb /* IEEE 802.11-05/0257r1 */ 117b0f73768SBjoern A. Zeeb const uint8_t bridge_tunnel_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; 118b0f73768SBjoern A. Zeeb 1194f61ef8bSBjoern A. Zeeb const uint8_t tid_to_mac80211_ac[] = { 1204f61ef8bSBjoern A. Zeeb IEEE80211_AC_BE, 1214f61ef8bSBjoern A. Zeeb IEEE80211_AC_BK, 1224f61ef8bSBjoern A. Zeeb IEEE80211_AC_BK, 1234f61ef8bSBjoern A. Zeeb IEEE80211_AC_BE, 1244f61ef8bSBjoern A. Zeeb IEEE80211_AC_VI, 1254f61ef8bSBjoern A. Zeeb IEEE80211_AC_VI, 1264f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO, 1274f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO, 1284f61ef8bSBjoern A. Zeeb #if 0 1294f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO, /* We treat MGMT as TID 8, which is set as AC_VO */ 1304f61ef8bSBjoern A. Zeeb #endif 1314f61ef8bSBjoern A. Zeeb }; 1324f61ef8bSBjoern A. Zeeb 1336b4cac81SBjoern A. Zeeb const struct cfg80211_ops linuxkpi_mac80211cfgops = { 1346b4cac81SBjoern A. Zeeb /* 1356b4cac81SBjoern A. Zeeb * XXX TODO need a "glue layer" to link cfg80211 ops to 1366b4cac81SBjoern A. Zeeb * mac80211 and to the driver or net80211. 1376b4cac81SBjoern A. Zeeb * Can we pass some on 1:1? Need to compare the (*f)(). 1386b4cac81SBjoern A. Zeeb */ 1396b4cac81SBjoern A. Zeeb }; 1406b4cac81SBjoern A. Zeeb 1416b4cac81SBjoern A. Zeeb static struct lkpi_sta *lkpi_find_lsta_by_ni(struct lkpi_vif *, 1426b4cac81SBjoern A. Zeeb struct ieee80211_node *); 1436b4cac81SBjoern A. Zeeb static void lkpi_80211_txq_task(void *, int); 1446b4cac81SBjoern A. Zeeb static void lkpi_ieee80211_free_skb_mbuf(void *); 1454a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 1464a67f1dfSBjoern A. Zeeb static int lkpi_wme_update(struct lkpi_hw *, struct ieee80211vap *, bool); 1474a67f1dfSBjoern A. Zeeb #endif 1486b4cac81SBjoern A. Zeeb 149d9f59799SBjoern A. Zeeb static void 15067674c1cSBjoern A. Zeeb lkpi_lsta_dump(struct lkpi_sta *lsta, struct ieee80211_node *ni, 15167674c1cSBjoern A. Zeeb const char *_f, int _l) 152d9f59799SBjoern A. Zeeb { 153d9f59799SBjoern A. Zeeb 1549d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 1559d9ba2b7SBjoern A. Zeeb if ((linuxkpi_debug_80211 & D80211_TRACE_STA) == 0) 156d9f59799SBjoern A. Zeeb return; 157d9f59799SBjoern A. Zeeb if (lsta == NULL) 158d9f59799SBjoern A. Zeeb return; 159d9f59799SBjoern A. Zeeb 160d9f59799SBjoern A. Zeeb printf("%s:%d lsta %p ni %p sta %p\n", 16167674c1cSBjoern A. Zeeb _f, _l, lsta, ni, &lsta->sta); 16267674c1cSBjoern A. Zeeb if (ni != NULL) 16367674c1cSBjoern A. Zeeb ieee80211_dump_node(NULL, ni); 164d9f59799SBjoern A. Zeeb printf("\ttxq_task txq len %d mtx\n", mbufq_len(&lsta->txq)); 165d9f59799SBjoern A. Zeeb printf("\tkc %p state %d added_to_drv %d in_mgd %d\n", 166d9f59799SBjoern A. Zeeb lsta->kc, lsta->state, lsta->added_to_drv, lsta->in_mgd); 1679d9ba2b7SBjoern A. Zeeb #endif 168d9f59799SBjoern A. Zeeb } 169d9f59799SBjoern A. Zeeb 170d9f59799SBjoern A. Zeeb static void 171d9f59799SBjoern A. Zeeb lkpi_lsta_remove(struct lkpi_sta *lsta, struct lkpi_vif *lvif) 172d9f59799SBjoern A. Zeeb { 173d9f59799SBjoern A. Zeeb struct ieee80211_node *ni; 174d9f59799SBjoern A. Zeeb 1753689f8aeSColin Percival IMPROVE("XXX-BZ remove tqe_prev check once ni-sta-state-sync is fixed"); 1763689f8aeSColin Percival 177d9f59799SBjoern A. Zeeb ni = lsta->ni; 178d9f59799SBjoern A. Zeeb 179d9f59799SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 1803689f8aeSColin Percival if (lsta->lsta_entry.tqe_prev != NULL) 181d9f59799SBjoern A. Zeeb TAILQ_REMOVE(&lvif->lsta_head, lsta, lsta_entry); 182d9f59799SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 183d9f59799SBjoern A. Zeeb 184d9f59799SBjoern A. Zeeb lsta->ni = NULL; 185d9f59799SBjoern A. Zeeb ni->ni_drv_data = NULL; 186e24e8103SBjoern A. Zeeb if (ni != NULL) 187d9f59799SBjoern A. Zeeb ieee80211_free_node(ni); 188d9f59799SBjoern A. Zeeb 189e24e8103SBjoern A. Zeeb IMPROVE("more from lkpi_ic_node_free() should happen here."); 190e24e8103SBjoern A. Zeeb 191e24e8103SBjoern A. Zeeb free(lsta, M_LKPI80211); 192d9f59799SBjoern A. Zeeb } 193d9f59799SBjoern A. Zeeb 1944f61ef8bSBjoern A. Zeeb static struct lkpi_sta * 1954f61ef8bSBjoern A. Zeeb lkpi_lsta_alloc(struct ieee80211vap *vap, const uint8_t mac[IEEE80211_ADDR_LEN], 1964f61ef8bSBjoern A. Zeeb struct ieee80211_hw *hw, struct ieee80211_node *ni) 1974f61ef8bSBjoern A. Zeeb { 1984f61ef8bSBjoern A. Zeeb struct lkpi_sta *lsta; 1994f61ef8bSBjoern A. Zeeb struct lkpi_vif *lvif; 2004f61ef8bSBjoern A. Zeeb struct ieee80211_vif *vif; 2014f61ef8bSBjoern A. Zeeb struct ieee80211_sta *sta; 202b6b352e4SBjoern A. Zeeb int band, i, tid; 2034f61ef8bSBjoern A. Zeeb 2044f61ef8bSBjoern A. Zeeb lsta = malloc(sizeof(*lsta) + hw->sta_data_size, M_LKPI80211, 2054f61ef8bSBjoern A. Zeeb M_NOWAIT | M_ZERO); 2064f61ef8bSBjoern A. Zeeb if (lsta == NULL) 2074f61ef8bSBjoern A. Zeeb return (NULL); 2084f61ef8bSBjoern A. Zeeb 2094f61ef8bSBjoern A. Zeeb lsta->added_to_drv = false; 2104f61ef8bSBjoern A. Zeeb lsta->state = IEEE80211_STA_NOTEXIST; 2114f61ef8bSBjoern A. Zeeb #if 0 2124f61ef8bSBjoern A. Zeeb /* 2134f61ef8bSBjoern A. Zeeb * This needs to be done in node_init() as ieee80211_alloc_node() 2144f61ef8bSBjoern A. Zeeb * will initialise the refcount after us. 2154f61ef8bSBjoern A. Zeeb */ 2164f61ef8bSBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 2174f61ef8bSBjoern A. Zeeb #endif 2184f61ef8bSBjoern A. Zeeb /* The back-pointer "drv_data" to net80211_node let's us get lsta. */ 2194f61ef8bSBjoern A. Zeeb ni->ni_drv_data = lsta; 2204f61ef8bSBjoern A. Zeeb 2214f61ef8bSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 2224f61ef8bSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 2234f61ef8bSBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 2244f61ef8bSBjoern A. Zeeb 2254f61ef8bSBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->addr, mac); 226b6b352e4SBjoern A. Zeeb 227b6b352e4SBjoern A. Zeeb /* TXQ */ 2284f61ef8bSBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 2294f61ef8bSBjoern A. Zeeb struct lkpi_txq *ltxq; 2304f61ef8bSBjoern A. Zeeb 231d0d29110SBjoern A. Zeeb /* We are not limiting ourselves to hw.queues here. */ 2324f61ef8bSBjoern A. Zeeb ltxq = malloc(sizeof(*ltxq) + hw->txq_data_size, 2334f61ef8bSBjoern A. Zeeb M_LKPI80211, M_NOWAIT | M_ZERO); 2344f61ef8bSBjoern A. Zeeb if (ltxq == NULL) 2354f61ef8bSBjoern A. Zeeb goto cleanup; 2364f61ef8bSBjoern A. Zeeb /* iwlwifi//mvm/sta.c::tid_to_mac80211_ac[] */ 2374f61ef8bSBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) { 238d0d29110SBjoern A. Zeeb if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ)) { 239d0d29110SBjoern A. Zeeb free(ltxq, M_LKPI80211); 240d0d29110SBjoern A. Zeeb continue; 241d0d29110SBjoern A. Zeeb } 242d0d29110SBjoern A. Zeeb IMPROVE("AP/if we support non-STA here too"); 2434f61ef8bSBjoern A. Zeeb ltxq->txq.ac = IEEE80211_AC_VO; 2444f61ef8bSBjoern A. Zeeb } else { 2454f61ef8bSBjoern A. Zeeb ltxq->txq.ac = tid_to_mac80211_ac[tid & 7]; 2464f61ef8bSBjoern A. Zeeb } 247d0d29110SBjoern A. Zeeb ltxq->seen_dequeue = false; 2480cbcfa19SBjoern A. Zeeb ltxq->stopped = false; 249d0d29110SBjoern A. Zeeb ltxq->txq.vif = vif; 2504f61ef8bSBjoern A. Zeeb ltxq->txq.tid = tid; 2514f61ef8bSBjoern A. Zeeb ltxq->txq.sta = sta; 2520cbcfa19SBjoern A. Zeeb TAILQ_ELEM_INIT(ltxq, txq_entry); 253d0d29110SBjoern A. Zeeb skb_queue_head_init(<xq->skbq); 2544f61ef8bSBjoern A. Zeeb sta->txq[tid] = <xq->txq; 2554f61ef8bSBjoern A. Zeeb } 2564f61ef8bSBjoern A. Zeeb 257b6b352e4SBjoern A. Zeeb /* Deflink information. */ 258b6b352e4SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 259b6b352e4SBjoern A. Zeeb struct ieee80211_supported_band *supband; 260b6b352e4SBjoern A. Zeeb 261b6b352e4SBjoern A. Zeeb supband = hw->wiphy->bands[band]; 262b6b352e4SBjoern A. Zeeb if (supband == NULL) 263b6b352e4SBjoern A. Zeeb continue; 264b6b352e4SBjoern A. Zeeb 265b6b352e4SBjoern A. Zeeb for (i = 0; i < supband->n_bitrates; i++) { 266b6b352e4SBjoern A. Zeeb 267b6b352e4SBjoern A. Zeeb IMPROVE("Further supband->bitrates[i]* checks?"); 268b6b352e4SBjoern A. Zeeb /* or should we get them from the ni? */ 269b6b352e4SBjoern A. Zeeb sta->deflink.supp_rates[band] |= BIT(i); 270b6b352e4SBjoern A. Zeeb } 271b6b352e4SBjoern A. Zeeb } 272b6b352e4SBjoern A. Zeeb IMPROVE("ht, vht, he, ... bandwidth, smps_mode, .."); 273b6b352e4SBjoern A. Zeeb /* bandwidth = IEEE80211_STA_RX_... */ 274b6b352e4SBjoern A. Zeeb 2754f61ef8bSBjoern A. Zeeb /* Deferred TX path. */ 2764f61ef8bSBjoern A. Zeeb mtx_init(&lsta->txq_mtx, "lsta_txq", NULL, MTX_DEF); 2774f61ef8bSBjoern A. Zeeb TASK_INIT(&lsta->txq_task, 0, lkpi_80211_txq_task, lsta); 2784f61ef8bSBjoern A. Zeeb mbufq_init(&lsta->txq, IFQ_MAXLEN); 2794f61ef8bSBjoern A. Zeeb 2804f61ef8bSBjoern A. Zeeb return (lsta); 2814f61ef8bSBjoern A. Zeeb 2824f61ef8bSBjoern A. Zeeb cleanup: 2834f61ef8bSBjoern A. Zeeb for (; tid >= 0; tid--) 2844f61ef8bSBjoern A. Zeeb free(sta->txq[tid], M_LKPI80211); 2854f61ef8bSBjoern A. Zeeb free(lsta, M_LKPI80211); 2864f61ef8bSBjoern A. Zeeb return (NULL); 2874f61ef8bSBjoern A. Zeeb } 2884f61ef8bSBjoern A. Zeeb 2896b4cac81SBjoern A. Zeeb static enum nl80211_band 2906b4cac81SBjoern A. Zeeb lkpi_net80211_chan_to_nl80211_band(struct ieee80211_channel *c) 2916b4cac81SBjoern A. Zeeb { 2926b4cac81SBjoern A. Zeeb 2936b4cac81SBjoern A. Zeeb if (IEEE80211_IS_CHAN_2GHZ(c)) 2946b4cac81SBjoern A. Zeeb return (NL80211_BAND_2GHZ); 2956b4cac81SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_5GHZ(c)) 2966b4cac81SBjoern A. Zeeb return (NL80211_BAND_5GHZ); 2976b4cac81SBjoern A. Zeeb #ifdef __notyet__ 2986b4cac81SBjoern A. Zeeb else if () 2996b4cac81SBjoern A. Zeeb return (NL80211_BAND_6GHZ); 3006b4cac81SBjoern A. Zeeb else if () 3016b4cac81SBjoern A. Zeeb return (NL80211_BAND_60GHZ); 3026b4cac81SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_GSM(c)) 3036b4cac81SBjoern A. Zeeb return (NL80211_BAND_XXX); 3046b4cac81SBjoern A. Zeeb #endif 3056b4cac81SBjoern A. Zeeb else 3066b4cac81SBjoern A. Zeeb panic("%s: unsupported band. c %p flags %#x\n", 3076b4cac81SBjoern A. Zeeb __func__, c, c->ic_flags); 3086b4cac81SBjoern A. Zeeb } 3096b4cac81SBjoern A. Zeeb 3106b4cac81SBjoern A. Zeeb static uint32_t 3116b4cac81SBjoern A. Zeeb lkpi_nl80211_band_to_net80211_band(enum nl80211_band band) 3126b4cac81SBjoern A. Zeeb { 3136b4cac81SBjoern A. Zeeb 3146b4cac81SBjoern A. Zeeb /* XXX-BZ this is just silly; net80211 is too convoluted. */ 3156b4cac81SBjoern A. Zeeb /* IEEE80211_CHAN_A / _G / .. doesn't really work either. */ 3166b4cac81SBjoern A. Zeeb switch (band) { 3176b4cac81SBjoern A. Zeeb case NL80211_BAND_2GHZ: 3186b4cac81SBjoern A. Zeeb return (IEEE80211_CHAN_2GHZ); 3196b4cac81SBjoern A. Zeeb break; 3206b4cac81SBjoern A. Zeeb case NL80211_BAND_5GHZ: 3216b4cac81SBjoern A. Zeeb return (IEEE80211_CHAN_5GHZ); 3226b4cac81SBjoern A. Zeeb break; 3236b4cac81SBjoern A. Zeeb case NL80211_BAND_60GHZ: 3246b4cac81SBjoern A. Zeeb break; 3256b4cac81SBjoern A. Zeeb case NL80211_BAND_6GHZ: 3266b4cac81SBjoern A. Zeeb break; 3276b4cac81SBjoern A. Zeeb default: 3286b4cac81SBjoern A. Zeeb panic("%s: unsupported band %u\n", __func__, band); 3296b4cac81SBjoern A. Zeeb break; 3306b4cac81SBjoern A. Zeeb } 3316b4cac81SBjoern A. Zeeb 3326b4cac81SBjoern A. Zeeb IMPROVE(); 3336b4cac81SBjoern A. Zeeb return (0x00); 3346b4cac81SBjoern A. Zeeb } 3356b4cac81SBjoern A. Zeeb 336e3a0b120SBjoern A. Zeeb #if 0 3376b4cac81SBjoern A. Zeeb static enum ieee80211_ac_numbers 3386b4cac81SBjoern A. Zeeb lkpi_ac_net_to_l80211(int ac) 3396b4cac81SBjoern A. Zeeb { 3406b4cac81SBjoern A. Zeeb 3416b4cac81SBjoern A. Zeeb switch (ac) { 3426b4cac81SBjoern A. Zeeb case WME_AC_VO: 3436b4cac81SBjoern A. Zeeb return (IEEE80211_AC_VO); 3446b4cac81SBjoern A. Zeeb case WME_AC_VI: 3456b4cac81SBjoern A. Zeeb return (IEEE80211_AC_VI); 3466b4cac81SBjoern A. Zeeb case WME_AC_BE: 3476b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BE); 3486b4cac81SBjoern A. Zeeb case WME_AC_BK: 3496b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BK); 3506b4cac81SBjoern A. Zeeb default: 3516b4cac81SBjoern A. Zeeb printf("%s: invalid WME_AC_* input: ac = %d\n", __func__, ac); 3526b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BE); 3536b4cac81SBjoern A. Zeeb } 3546b4cac81SBjoern A. Zeeb } 355e3a0b120SBjoern A. Zeeb #endif 3566b4cac81SBjoern A. Zeeb 3576b4cac81SBjoern A. Zeeb static enum nl80211_iftype 3586b4cac81SBjoern A. Zeeb lkpi_opmode_to_vif_type(enum ieee80211_opmode opmode) 3596b4cac81SBjoern A. Zeeb { 3606b4cac81SBjoern A. Zeeb 3616b4cac81SBjoern A. Zeeb switch (opmode) { 3626b4cac81SBjoern A. Zeeb case IEEE80211_M_IBSS: 3636b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_ADHOC); 3646b4cac81SBjoern A. Zeeb break; 3656b4cac81SBjoern A. Zeeb case IEEE80211_M_STA: 3666b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_STATION); 3676b4cac81SBjoern A. Zeeb break; 3686b4cac81SBjoern A. Zeeb case IEEE80211_M_WDS: 3696b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_WDS); 3706b4cac81SBjoern A. Zeeb break; 3716b4cac81SBjoern A. Zeeb case IEEE80211_M_HOSTAP: 3726b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_AP); 3736b4cac81SBjoern A. Zeeb break; 3746b4cac81SBjoern A. Zeeb case IEEE80211_M_MONITOR: 3756b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_MONITOR); 3766b4cac81SBjoern A. Zeeb break; 3776b4cac81SBjoern A. Zeeb case IEEE80211_M_MBSS: 3786b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_MESH_POINT); 3796b4cac81SBjoern A. Zeeb break; 3806b4cac81SBjoern A. Zeeb case IEEE80211_M_AHDEMO: 3816b4cac81SBjoern A. Zeeb /* FALLTHROUGH */ 3826b4cac81SBjoern A. Zeeb default: 3836b4cac81SBjoern A. Zeeb printf("ERROR: %s: unsupported opmode %d\n", __func__, opmode); 3846b4cac81SBjoern A. Zeeb /* FALLTHROUGH */ 3856b4cac81SBjoern A. Zeeb } 3866b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_UNSPECIFIED); 3876b4cac81SBjoern A. Zeeb } 3886b4cac81SBjoern A. Zeeb 389b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 3906b4cac81SBjoern A. Zeeb static uint32_t 3916b4cac81SBjoern A. Zeeb lkpi_l80211_to_net80211_cyphers(uint32_t wlan_cipher_suite) 3926b4cac81SBjoern A. Zeeb { 3936b4cac81SBjoern A. Zeeb 3946b4cac81SBjoern A. Zeeb switch (wlan_cipher_suite) { 3956b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP40: 3966b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_WEP); 3976b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP: 3986b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_TKIP); 3996b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP: 4006b4cac81SBjoern A. Zeeb return (IEEE80211_CIPHER_AES_CCM); 4016b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP104: 4026b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_WEP); 4036b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_AES_CMAC: 4046b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP: 4056b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP_256: 4066b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP_256: 4076b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_128: 4086b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_256: 4096b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_CMAC_256: 4106b4cac81SBjoern A. Zeeb printf("%s: unsupported WLAN Cipher Suite %#08x | %u\n", __func__, 4116b4cac81SBjoern A. Zeeb wlan_cipher_suite >> 8, wlan_cipher_suite & 0xff); 4126b4cac81SBjoern A. Zeeb break; 4136b4cac81SBjoern A. Zeeb default: 4146b4cac81SBjoern A. Zeeb printf("%s: unknown WLAN Cipher Suite %#08x | %u\n", __func__, 4156b4cac81SBjoern A. Zeeb wlan_cipher_suite >> 8, wlan_cipher_suite & 0xff); 4166b4cac81SBjoern A. Zeeb } 4176b4cac81SBjoern A. Zeeb 4186b4cac81SBjoern A. Zeeb return (0); 4196b4cac81SBjoern A. Zeeb } 4206b4cac81SBjoern A. Zeeb 4216b4cac81SBjoern A. Zeeb static uint32_t 4226b4cac81SBjoern A. Zeeb lkpi_net80211_to_l80211_cipher_suite(uint32_t cipher, uint8_t keylen) 4236b4cac81SBjoern A. Zeeb { 4246b4cac81SBjoern A. Zeeb 4256b4cac81SBjoern A. Zeeb switch (cipher) { 4266b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_TKIP: 4276b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_TKIP); 4286b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_AES_CCM: 4296b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_CCMP); 4306b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_WEP: 4316b4cac81SBjoern A. Zeeb if (keylen < 8) 4326b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_WEP40); 4336b4cac81SBjoern A. Zeeb else 4346b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_WEP104); 4356b4cac81SBjoern A. Zeeb break; 4366b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_AES_OCB: 4376b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_TKIPMIC: 4386b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_CKIP: 4396b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_NONE: 4406b4cac81SBjoern A. Zeeb printf("%s: unsupported cipher %#010x\n", __func__, cipher); 4416b4cac81SBjoern A. Zeeb break; 4426b4cac81SBjoern A. Zeeb default: 4436b4cac81SBjoern A. Zeeb printf("%s: unknown cipher %#010x\n", __func__, cipher); 4446b4cac81SBjoern A. Zeeb }; 4456b4cac81SBjoern A. Zeeb return (0); 4466b4cac81SBjoern A. Zeeb } 4476b4cac81SBjoern A. Zeeb #endif 4486b4cac81SBjoern A. Zeeb 4496b4cac81SBjoern A. Zeeb #ifdef __notyet__ 4506b4cac81SBjoern A. Zeeb static enum ieee80211_sta_state 4516b4cac81SBjoern A. Zeeb lkpi_net80211_state_to_sta_state(enum ieee80211_state state) 4526b4cac81SBjoern A. Zeeb { 4536b4cac81SBjoern A. Zeeb 4546b4cac81SBjoern A. Zeeb /* 4556b4cac81SBjoern A. Zeeb * XXX-BZ The net80211 states are "try to ..", the lkpi8011 states are 4566b4cac81SBjoern A. Zeeb * "done". Also ASSOC/AUTHORIZED are both "RUN" then? 4576b4cac81SBjoern A. Zeeb */ 4586b4cac81SBjoern A. Zeeb switch (state) { 4596b4cac81SBjoern A. Zeeb case IEEE80211_S_INIT: 4606b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NOTEXIST); 4616b4cac81SBjoern A. Zeeb case IEEE80211_S_SCAN: 4626b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NONE); 4636b4cac81SBjoern A. Zeeb case IEEE80211_S_AUTH: 4646b4cac81SBjoern A. Zeeb return (IEEE80211_STA_AUTH); 4656b4cac81SBjoern A. Zeeb case IEEE80211_S_ASSOC: 4666b4cac81SBjoern A. Zeeb return (IEEE80211_STA_ASSOC); 4676b4cac81SBjoern A. Zeeb case IEEE80211_S_RUN: 4686b4cac81SBjoern A. Zeeb return (IEEE80211_STA_AUTHORIZED); 4696b4cac81SBjoern A. Zeeb case IEEE80211_S_CAC: 4706b4cac81SBjoern A. Zeeb case IEEE80211_S_CSA: 4716b4cac81SBjoern A. Zeeb case IEEE80211_S_SLEEP: 4726b4cac81SBjoern A. Zeeb default: 4736b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 4746b4cac81SBjoern A. Zeeb }; 4756b4cac81SBjoern A. Zeeb 4766b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NOTEXIST); 4776b4cac81SBjoern A. Zeeb } 4786b4cac81SBjoern A. Zeeb #endif 4796b4cac81SBjoern A. Zeeb 4806b4cac81SBjoern A. Zeeb static struct linuxkpi_ieee80211_channel * 4816b4cac81SBjoern A. Zeeb lkpi_find_lkpi80211_chan(struct lkpi_hw *lhw, 4826b4cac81SBjoern A. Zeeb struct ieee80211_channel *c) 4836b4cac81SBjoern A. Zeeb { 4846b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 4856b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 4866b4cac81SBjoern A. Zeeb enum nl80211_band band; 4876b4cac81SBjoern A. Zeeb int i, nchans; 4886b4cac81SBjoern A. Zeeb 4896b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 4906b4cac81SBjoern A. Zeeb band = lkpi_net80211_chan_to_nl80211_band(c); 4916b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[band] == NULL) 4926b4cac81SBjoern A. Zeeb return (NULL); 4936b4cac81SBjoern A. Zeeb 4946b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[band]->n_channels; 4956b4cac81SBjoern A. Zeeb if (nchans <= 0) 4966b4cac81SBjoern A. Zeeb return (NULL); 4976b4cac81SBjoern A. Zeeb 4986b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[band]->channels; 4996b4cac81SBjoern A. Zeeb for (i = 0; i < nchans; i++) { 5006b4cac81SBjoern A. Zeeb if (channels[i].hw_value == c->ic_ieee) 5016b4cac81SBjoern A. Zeeb return (&channels[i]); 5026b4cac81SBjoern A. Zeeb } 5036b4cac81SBjoern A. Zeeb 5046b4cac81SBjoern A. Zeeb return (NULL); 5056b4cac81SBjoern A. Zeeb } 5066b4cac81SBjoern A. Zeeb 5076b4cac81SBjoern A. Zeeb static struct linuxkpi_ieee80211_channel * 5086b4cac81SBjoern A. Zeeb lkpi_get_lkpi80211_chan(struct ieee80211com *ic, struct ieee80211_node *ni) 5096b4cac81SBjoern A. Zeeb { 5106b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 5116b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 5126b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 5136b4cac81SBjoern A. Zeeb 5146b4cac81SBjoern A. Zeeb chan = NULL; 5156b4cac81SBjoern A. Zeeb if (ni != NULL && ni->ni_chan != IEEE80211_CHAN_ANYC) 5166b4cac81SBjoern A. Zeeb c = ni->ni_chan; 5176b4cac81SBjoern A. Zeeb else if (ic->ic_bsschan != IEEE80211_CHAN_ANYC) 5186b4cac81SBjoern A. Zeeb c = ic->ic_bsschan; 5196b4cac81SBjoern A. Zeeb else if (ic->ic_curchan != IEEE80211_CHAN_ANYC) 5206b4cac81SBjoern A. Zeeb c = ic->ic_curchan; 5216b4cac81SBjoern A. Zeeb else 5226b4cac81SBjoern A. Zeeb c = NULL; 5236b4cac81SBjoern A. Zeeb 5246b4cac81SBjoern A. Zeeb if (c != NULL && c != IEEE80211_CHAN_ANYC) { 5256b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 5266b4cac81SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, c); 5276b4cac81SBjoern A. Zeeb } 5286b4cac81SBjoern A. Zeeb 5296b4cac81SBjoern A. Zeeb return (chan); 5306b4cac81SBjoern A. Zeeb } 5316b4cac81SBjoern A. Zeeb 5322e183d99SBjoern A. Zeeb struct linuxkpi_ieee80211_channel * 5332e183d99SBjoern A. Zeeb linuxkpi_ieee80211_get_channel(struct wiphy *wiphy, uint32_t freq) 5342e183d99SBjoern A. Zeeb { 5352e183d99SBjoern A. Zeeb enum nl80211_band band; 5362e183d99SBjoern A. Zeeb 5372e183d99SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 5382e183d99SBjoern A. Zeeb struct ieee80211_supported_band *supband; 5392e183d99SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 5402e183d99SBjoern A. Zeeb int i; 5412e183d99SBjoern A. Zeeb 5422e183d99SBjoern A. Zeeb supband = wiphy->bands[band]; 5432e183d99SBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 5442e183d99SBjoern A. Zeeb continue; 5452e183d99SBjoern A. Zeeb 5462e183d99SBjoern A. Zeeb channels = supband->channels; 5472e183d99SBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 5482e183d99SBjoern A. Zeeb if (channels[i].center_freq == freq) 5492e183d99SBjoern A. Zeeb return (&channels[i]); 5502e183d99SBjoern A. Zeeb } 5512e183d99SBjoern A. Zeeb } 5522e183d99SBjoern A. Zeeb 5532e183d99SBjoern A. Zeeb return (NULL); 5542e183d99SBjoern A. Zeeb } 5552e183d99SBjoern A. Zeeb 556b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 5576b4cac81SBjoern A. Zeeb static int 5586b4cac81SBjoern A. Zeeb _lkpi_iv_key_set_delete(struct ieee80211vap *vap, const struct ieee80211_key *k, 5596b4cac81SBjoern A. Zeeb enum set_key_cmd cmd) 5606b4cac81SBjoern A. Zeeb { 5616b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 5626b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 5636b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 5646b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 5656b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 5666b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 5676b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 5686b4cac81SBjoern A. Zeeb struct ieee80211_key_conf *kc; 5696b4cac81SBjoern A. Zeeb int error; 5706b4cac81SBjoern A. Zeeb 5716b4cac81SBjoern A. Zeeb /* XXX TODO Check (k->wk_flags & IEEE80211_KEY_SWENCRYPT) and don't upload to driver/hw? */ 5726b4cac81SBjoern A. Zeeb 5736b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 5746b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 5756b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 5766b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 5776b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 5786b4cac81SBjoern A. Zeeb 5796b4cac81SBjoern A. Zeeb memset(&kc, 0, sizeof(kc)); 5806b4cac81SBjoern A. Zeeb kc = malloc(sizeof(*kc) + k->wk_keylen, M_LKPI80211, M_WAITOK | M_ZERO); 5816b4cac81SBjoern A. Zeeb kc->cipher = lkpi_net80211_to_l80211_cipher_suite( 5826b4cac81SBjoern A. Zeeb k->wk_cipher->ic_cipher, k->wk_keylen); 5836b4cac81SBjoern A. Zeeb kc->keyidx = k->wk_keyix; 5846b4cac81SBjoern A. Zeeb #if 0 5856b4cac81SBjoern A. Zeeb kc->hw_key_idx = /* set by hw and needs to be passed for TX */; 5866b4cac81SBjoern A. Zeeb #endif 5876b4cac81SBjoern A. Zeeb atomic64_set(&kc->tx_pn, k->wk_keytsc); 5886b4cac81SBjoern A. Zeeb kc->keylen = k->wk_keylen; 5896b4cac81SBjoern A. Zeeb memcpy(kc->key, k->wk_key, k->wk_keylen); 5906b4cac81SBjoern A. Zeeb 5916b4cac81SBjoern A. Zeeb switch (kc->cipher) { 5926b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP: 5936b4cac81SBjoern A. Zeeb kc->iv_len = k->wk_cipher->ic_header; 5946b4cac81SBjoern A. Zeeb kc->icv_len = k->wk_cipher->ic_trailer; 5956b4cac81SBjoern A. Zeeb break; 5966b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP: 5976b4cac81SBjoern A. Zeeb default: 5986b4cac81SBjoern A. Zeeb IMPROVE(); 5996b4cac81SBjoern A. Zeeb return (0); 6006b4cac81SBjoern A. Zeeb }; 6016b4cac81SBjoern A. Zeeb 6026b4cac81SBjoern A. Zeeb ni = vap->iv_bss; 6036b4cac81SBjoern A. Zeeb sta = ieee80211_find_sta(vif, ni->ni_bssid); 6046b4cac81SBjoern A. Zeeb if (sta != NULL) { 6056b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 6066b4cac81SBjoern A. Zeeb 6076b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 6086b4cac81SBjoern A. Zeeb lsta->kc = kc; 6096b4cac81SBjoern A. Zeeb } 6106b4cac81SBjoern A. Zeeb 6116b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_set_key(hw, cmd, vif, sta, kc); 6126b4cac81SBjoern A. Zeeb if (error != 0) { 6136b4cac81SBjoern A. Zeeb /* XXX-BZ leaking kc currently */ 6146b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: set_key failed: %d\n", __func__, error); 6156b4cac81SBjoern A. Zeeb return (0); 6166b4cac81SBjoern A. Zeeb } else { 6176b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: set_key succeeded: keyidx %u hw_key_idx %u " 6186b4cac81SBjoern A. Zeeb "flags %#10x\n", __func__, 6196b4cac81SBjoern A. Zeeb kc->keyidx, kc->hw_key_idx, kc->flags); 6206b4cac81SBjoern A. Zeeb return (1); 6216b4cac81SBjoern A. Zeeb } 6226b4cac81SBjoern A. Zeeb } 6236b4cac81SBjoern A. Zeeb 6246b4cac81SBjoern A. Zeeb static int 6256b4cac81SBjoern A. Zeeb lkpi_iv_key_delete(struct ieee80211vap *vap, const struct ieee80211_key *k) 6266b4cac81SBjoern A. Zeeb { 6276b4cac81SBjoern A. Zeeb 6286b4cac81SBjoern A. Zeeb /* XXX-BZ one day we should replace this iterating over VIFs, or node list? */ 6296b4cac81SBjoern A. Zeeb return (_lkpi_iv_key_set_delete(vap, k, DISABLE_KEY)); 6306b4cac81SBjoern A. Zeeb } 6316b4cac81SBjoern A. Zeeb static int 6326b4cac81SBjoern A. Zeeb lkpi_iv_key_set(struct ieee80211vap *vap, const struct ieee80211_key *k) 6336b4cac81SBjoern A. Zeeb { 6346b4cac81SBjoern A. Zeeb 6356b4cac81SBjoern A. Zeeb return (_lkpi_iv_key_set_delete(vap, k, SET_KEY)); 6366b4cac81SBjoern A. Zeeb } 6376b4cac81SBjoern A. Zeeb #endif 6386b4cac81SBjoern A. Zeeb 6396b4cac81SBjoern A. Zeeb static u_int 6406b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast_copy(void *arg, struct sockaddr_dl *sdl, u_int cnt) 6416b4cac81SBjoern A. Zeeb { 6426b4cac81SBjoern A. Zeeb struct netdev_hw_addr_list *mc_list; 6436b4cac81SBjoern A. Zeeb struct netdev_hw_addr *addr; 6446b4cac81SBjoern A. Zeeb 6456b4cac81SBjoern A. Zeeb KASSERT(arg != NULL && sdl != NULL, ("%s: arg %p sdl %p cnt %u\n", 6466b4cac81SBjoern A. Zeeb __func__, arg, sdl, cnt)); 6476b4cac81SBjoern A. Zeeb 6486b4cac81SBjoern A. Zeeb mc_list = arg; 6496b4cac81SBjoern A. Zeeb /* If it is on the list already skip it. */ 6506b4cac81SBjoern A. Zeeb netdev_hw_addr_list_for_each(addr, mc_list) { 6516b4cac81SBjoern A. Zeeb if (!memcmp(addr->addr, LLADDR(sdl), sdl->sdl_alen)) 6526b4cac81SBjoern A. Zeeb return (0); 6536b4cac81SBjoern A. Zeeb } 6546b4cac81SBjoern A. Zeeb 6556b4cac81SBjoern A. Zeeb addr = malloc(sizeof(*addr), M_LKPI80211, M_NOWAIT | M_ZERO); 6566b4cac81SBjoern A. Zeeb if (addr == NULL) 6576b4cac81SBjoern A. Zeeb return (0); 6586b4cac81SBjoern A. Zeeb 6596b4cac81SBjoern A. Zeeb INIT_LIST_HEAD(&addr->addr_list); 6606b4cac81SBjoern A. Zeeb memcpy(addr->addr, LLADDR(sdl), sdl->sdl_alen); 6616b4cac81SBjoern A. Zeeb /* XXX this should be a netdev function? */ 6626b4cac81SBjoern A. Zeeb list_add(&addr->addr_list, &mc_list->addr_list); 6636b4cac81SBjoern A. Zeeb mc_list->count++; 6646b4cac81SBjoern A. Zeeb 6659d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 6669d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 6676b4cac81SBjoern A. Zeeb printf("%s:%d: mc_list count %d: added %6D\n", 6686b4cac81SBjoern A. Zeeb __func__, __LINE__, mc_list->count, addr->addr, ":"); 6699d9ba2b7SBjoern A. Zeeb #endif 6706b4cac81SBjoern A. Zeeb 6716b4cac81SBjoern A. Zeeb return (1); 6726b4cac81SBjoern A. Zeeb } 6736b4cac81SBjoern A. Zeeb 6746b4cac81SBjoern A. Zeeb static void 6756b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(struct ieee80211com *ic, bool force) 6766b4cac81SBjoern A. Zeeb { 6776b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 6786b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 6796b4cac81SBjoern A. Zeeb struct netdev_hw_addr_list mc_list; 6806b4cac81SBjoern A. Zeeb struct list_head *le, *next; 6816b4cac81SBjoern A. Zeeb struct netdev_hw_addr *addr; 6826b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 6836b4cac81SBjoern A. Zeeb u64 mc; 6846b4cac81SBjoern A. Zeeb unsigned int changed_flags, total_flags; 6856b4cac81SBjoern A. Zeeb 6866b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 6876b4cac81SBjoern A. Zeeb 6886b4cac81SBjoern A. Zeeb if (lhw->ops->prepare_multicast == NULL || 6896b4cac81SBjoern A. Zeeb lhw->ops->configure_filter == NULL) 6906b4cac81SBjoern A. Zeeb return; 6916b4cac81SBjoern A. Zeeb 6926b4cac81SBjoern A. Zeeb if (!lhw->update_mc && !force) 6936b4cac81SBjoern A. Zeeb return; 6946b4cac81SBjoern A. Zeeb 6956b4cac81SBjoern A. Zeeb changed_flags = total_flags = 0; 6966b4cac81SBjoern A. Zeeb mc_list.count = 0; 6976b4cac81SBjoern A. Zeeb INIT_LIST_HEAD(&mc_list.addr_list); 6986b4cac81SBjoern A. Zeeb if (ic->ic_allmulti == 0) { 6996b4cac81SBjoern A. Zeeb TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) 7006b4cac81SBjoern A. Zeeb if_foreach_llmaddr(vap->iv_ifp, 7016b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast_copy, &mc_list); 7026b4cac81SBjoern A. Zeeb } else { 7036b4cac81SBjoern A. Zeeb changed_flags |= FIF_ALLMULTI; 7046b4cac81SBjoern A. Zeeb } 7056b4cac81SBjoern A. Zeeb 7066b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 7076b4cac81SBjoern A. Zeeb mc = lkpi_80211_mo_prepare_multicast(hw, &mc_list); 7086b4cac81SBjoern A. Zeeb /* 7096b4cac81SBjoern A. Zeeb * XXX-BZ make sure to get this sorted what is a change, 7106b4cac81SBjoern A. Zeeb * what gets all set; what was already set? 7116b4cac81SBjoern A. Zeeb */ 7126b4cac81SBjoern A. Zeeb total_flags = changed_flags; 7136b4cac81SBjoern A. Zeeb lkpi_80211_mo_configure_filter(hw, changed_flags, &total_flags, mc); 7146b4cac81SBjoern A. Zeeb 7159d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 7169d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 7176b4cac81SBjoern A. Zeeb printf("%s: changed_flags %#06x count %d total_flags %#010x\n", 7186b4cac81SBjoern A. Zeeb __func__, changed_flags, mc_list.count, total_flags); 7199d9ba2b7SBjoern A. Zeeb #endif 7206b4cac81SBjoern A. Zeeb 7216b4cac81SBjoern A. Zeeb if (mc_list.count != 0) { 7226b4cac81SBjoern A. Zeeb list_for_each_safe(le, next, &mc_list.addr_list) { 7236b4cac81SBjoern A. Zeeb addr = list_entry(le, struct netdev_hw_addr, addr_list); 7246b4cac81SBjoern A. Zeeb free(addr, M_LKPI80211); 7256b4cac81SBjoern A. Zeeb mc_list.count--; 7266b4cac81SBjoern A. Zeeb } 7276b4cac81SBjoern A. Zeeb } 7286b4cac81SBjoern A. Zeeb KASSERT(mc_list.count == 0, ("%s: mc_list %p count %d != 0\n", 7296b4cac81SBjoern A. Zeeb __func__, &mc_list, mc_list.count)); 7306b4cac81SBjoern A. Zeeb } 7316b4cac81SBjoern A. Zeeb 732fa8f007dSBjoern A. Zeeb static enum ieee80211_bss_changed 733fa8f007dSBjoern A. Zeeb lkpi_update_dtim_tsf(struct ieee80211_vif *vif, struct ieee80211_node *ni, 734fa8f007dSBjoern A. Zeeb struct ieee80211vap *vap, const char *_f, int _l) 735fa8f007dSBjoern A. Zeeb { 736fa8f007dSBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 737fa8f007dSBjoern A. Zeeb 738fa8f007dSBjoern A. Zeeb bss_changed = 0; 739fa8f007dSBjoern A. Zeeb 7409d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 7419d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 742fa8f007dSBjoern A. Zeeb printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u " 743fa8f007dSBjoern A. Zeeb "dtim_period %u sync_dtim_count %u sync_tsf %ju " 744fa8f007dSBjoern A. Zeeb "sync_device_ts %u bss_changed %#08x\n", 745fa8f007dSBjoern A. Zeeb __func__, __LINE__, _f, _l, 746616e1330SBjoern A. Zeeb vif->cfg.assoc, vif->cfg.aid, 747fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int, vif->bss_conf.dtim_period, 748fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count, 749fa8f007dSBjoern A. Zeeb (uintmax_t)vif->bss_conf.sync_tsf, 750fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_device_ts, 751fa8f007dSBjoern A. Zeeb bss_changed); 7529d9ba2b7SBjoern A. Zeeb #endif 753fa8f007dSBjoern A. Zeeb 754fa8f007dSBjoern A. Zeeb if (vif->bss_conf.beacon_int != ni->ni_intval) { 755fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int = ni->ni_intval; 756fa8f007dSBjoern A. Zeeb /* iwlwifi FW bug workaround; iwl_mvm_mac_sta_state. */ 757fa8f007dSBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16) 758fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int = 16; 759fa8f007dSBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INT; 760fa8f007dSBjoern A. Zeeb } 761fa8f007dSBjoern A. Zeeb if (vif->bss_conf.dtim_period != vap->iv_dtim_period && 762fa8f007dSBjoern A. Zeeb vap->iv_dtim_period > 0) { 763fa8f007dSBjoern A. Zeeb vif->bss_conf.dtim_period = vap->iv_dtim_period; 764fa8f007dSBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INFO; 765fa8f007dSBjoern A. Zeeb } 766fa8f007dSBjoern A. Zeeb 767fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count = vap->iv_dtim_count; 768fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_tsf = le64toh(ni->ni_tstamp.tsf); 769fa8f007dSBjoern A. Zeeb /* vif->bss_conf.sync_device_ts = set in linuxkpi_ieee80211_rx. */ 770fa8f007dSBjoern A. Zeeb 7719d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 7729d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 773fa8f007dSBjoern A. Zeeb printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u " 774fa8f007dSBjoern A. Zeeb "dtim_period %u sync_dtim_count %u sync_tsf %ju " 775fa8f007dSBjoern A. Zeeb "sync_device_ts %u bss_changed %#08x\n", 776fa8f007dSBjoern A. Zeeb __func__, __LINE__, _f, _l, 777616e1330SBjoern A. Zeeb vif->cfg.assoc, vif->cfg.aid, 778fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int, vif->bss_conf.dtim_period, 779fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count, 780fa8f007dSBjoern A. Zeeb (uintmax_t)vif->bss_conf.sync_tsf, 781fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_device_ts, 782fa8f007dSBjoern A. Zeeb bss_changed); 7839d9ba2b7SBjoern A. Zeeb #endif 784fa8f007dSBjoern A. Zeeb 785fa8f007dSBjoern A. Zeeb return (bss_changed); 786fa8f007dSBjoern A. Zeeb } 787fa8f007dSBjoern A. Zeeb 7886b4cac81SBjoern A. Zeeb static void 7896b4cac81SBjoern A. Zeeb lkpi_stop_hw_scan(struct lkpi_hw *lhw, struct ieee80211_vif *vif) 7906b4cac81SBjoern A. Zeeb { 7916b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 7926b4cac81SBjoern A. Zeeb int error; 7938ac540d3SBjoern A. Zeeb bool cancel; 7946b4cac81SBjoern A. Zeeb 7958ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 7968ac540d3SBjoern A. Zeeb cancel = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0; 7978ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 7988ac540d3SBjoern A. Zeeb if (!cancel) 7996b4cac81SBjoern A. Zeeb return; 8006b4cac81SBjoern A. Zeeb 8016b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 8026b4cac81SBjoern A. Zeeb 803bec76628SBjoern A. Zeeb IEEE80211_UNLOCK(lhw->ic); 804bec76628SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 8056b4cac81SBjoern A. Zeeb /* Need to cancel the scan. */ 8066b4cac81SBjoern A. Zeeb lkpi_80211_mo_cancel_hw_scan(hw, vif); 8078ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 8086b4cac81SBjoern A. Zeeb 8096b4cac81SBjoern A. Zeeb /* Need to make sure we see ieee80211_scan_completed. */ 8108ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 8118ac540d3SBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) 8128ac540d3SBjoern A. Zeeb error = msleep(lhw, &lhw->scan_mtx, 0, "lhwscanstop", hz/2); 8138ac540d3SBjoern A. Zeeb cancel = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0; 8148ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 8158ac540d3SBjoern A. Zeeb 816bec76628SBjoern A. Zeeb IEEE80211_LOCK(lhw->ic); 8176b4cac81SBjoern A. Zeeb 8188ac540d3SBjoern A. Zeeb if (cancel) 8196b4cac81SBjoern A. Zeeb ic_printf(lhw->ic, "%s: failed to cancel scan: %d (%p, %p)\n", 8206b4cac81SBjoern A. Zeeb __func__, error, lhw, vif); 8216b4cac81SBjoern A. Zeeb } 8226b4cac81SBjoern A. Zeeb 8236b4cac81SBjoern A. Zeeb static void 824086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(struct ieee80211_hw *hw, bool new) 825086be6a8SBjoern A. Zeeb { 826086be6a8SBjoern A. Zeeb struct lkpi_hw *lhw; 827086be6a8SBjoern A. Zeeb int error; 828086be6a8SBjoern A. Zeeb bool old; 829086be6a8SBjoern A. Zeeb 830086be6a8SBjoern A. Zeeb old = hw->conf.flags & IEEE80211_CONF_IDLE; 831086be6a8SBjoern A. Zeeb if (old == new) 832086be6a8SBjoern A. Zeeb return; 833086be6a8SBjoern A. Zeeb 834086be6a8SBjoern A. Zeeb hw->conf.flags ^= IEEE80211_CONF_IDLE; 835086be6a8SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_IDLE); 836086be6a8SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) { 837086be6a8SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 838086be6a8SBjoern A. Zeeb ic_printf(lhw->ic, "ERROR: %s: config %#0x returned %d\n", 839086be6a8SBjoern A. Zeeb __func__, IEEE80211_CONF_CHANGE_IDLE, error); 840086be6a8SBjoern A. Zeeb } 841086be6a8SBjoern A. Zeeb } 842086be6a8SBjoern A. Zeeb 843086be6a8SBjoern A. Zeeb static void 8446b4cac81SBjoern A. Zeeb lkpi_disassoc(struct ieee80211_sta *sta, struct ieee80211_vif *vif, 8456b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw) 8466b4cac81SBjoern A. Zeeb { 8476b4cac81SBjoern A. Zeeb sta->aid = 0; 848616e1330SBjoern A. Zeeb if (vif->cfg.assoc) { 8496b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 8506b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 8516b4cac81SBjoern A. Zeeb 8526b4cac81SBjoern A. Zeeb lhw->update_mc = true; 8536b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(lhw->ic, true); 8546b4cac81SBjoern A. Zeeb 8556b4cac81SBjoern A. Zeeb changed = 0; 856616e1330SBjoern A. Zeeb vif->cfg.assoc = false; 857616e1330SBjoern A. Zeeb vif->cfg.aid = 0; 8586b4cac81SBjoern A. Zeeb changed |= BSS_CHANGED_ASSOC; 859d9f59799SBjoern A. Zeeb /* 860d9f59799SBjoern A. Zeeb * This will remove the sta from firmware for iwlwifi. 861d9f59799SBjoern A. Zeeb * So confusing that they use state and flags and ... ^%$%#%$^. 862d9f59799SBjoern A. Zeeb */ 8636b4cac81SBjoern A. Zeeb IMPROVE(); 8646b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 8656b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, 8666b4cac81SBjoern A. Zeeb changed); 867086be6a8SBjoern A. Zeeb 868086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true); 8696b4cac81SBjoern A. Zeeb } 8706b4cac81SBjoern A. Zeeb } 8716b4cac81SBjoern A. Zeeb 8726b4cac81SBjoern A. Zeeb static void 8736b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(struct ieee80211_hw *hw, struct ieee80211_sta *sta, 8746b4cac81SBjoern A. Zeeb bool dequeue_seen, bool no_emptyq) 8756b4cac81SBjoern A. Zeeb { 8766b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 8776b4cac81SBjoern A. Zeeb int tid; 8786b4cac81SBjoern A. Zeeb 8796b4cac81SBjoern A. Zeeb /* Wake up all queues to know they are allocated in the driver. */ 8806b4cac81SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 8816b4cac81SBjoern A. Zeeb 8826b4cac81SBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) { 8836b4cac81SBjoern A. Zeeb IMPROVE("station specific?"); 8846b4cac81SBjoern A. Zeeb if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ)) 8856b4cac81SBjoern A. Zeeb continue; 8866b4cac81SBjoern A. Zeeb } else if (tid >= hw->queues) 8876b4cac81SBjoern A. Zeeb continue; 8886b4cac81SBjoern A. Zeeb 8896b4cac81SBjoern A. Zeeb if (sta->txq[tid] == NULL) 8906b4cac81SBjoern A. Zeeb continue; 8916b4cac81SBjoern A. Zeeb 8926b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]); 8936b4cac81SBjoern A. Zeeb if (dequeue_seen && !ltxq->seen_dequeue) 8946b4cac81SBjoern A. Zeeb continue; 8956b4cac81SBjoern A. Zeeb 8966b4cac81SBjoern A. Zeeb if (no_emptyq && skb_queue_empty(<xq->skbq)) 8976b4cac81SBjoern A. Zeeb continue; 8986b4cac81SBjoern A. Zeeb 8996b4cac81SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, sta->txq[tid]); 9006b4cac81SBjoern A. Zeeb } 9016b4cac81SBjoern A. Zeeb } 9026b4cac81SBjoern A. Zeeb 9036b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 9046b4cac81SBjoern A. Zeeb 9056b4cac81SBjoern A. Zeeb static int 9066b4cac81SBjoern A. Zeeb lkpi_sta_state_do_nada(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 9076b4cac81SBjoern A. Zeeb { 9086b4cac81SBjoern A. Zeeb 9096b4cac81SBjoern A. Zeeb return (0); 9106b4cac81SBjoern A. Zeeb } 9116b4cac81SBjoern A. Zeeb 9126b4cac81SBjoern A. Zeeb /* lkpi_iv_newstate() handles the stop scan case generally. */ 9136b4cac81SBjoern A. Zeeb #define lkpi_sta_scan_to_init(_v, _n, _a) lkpi_sta_state_do_nada(_v, _n, _a) 9146b4cac81SBjoern A. Zeeb 9156b4cac81SBjoern A. Zeeb static int 9166b4cac81SBjoern A. Zeeb lkpi_sta_scan_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 9176b4cac81SBjoern A. Zeeb { 9186b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 9196b4cac81SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 9206b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 9216b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 9226b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 9236b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 9246b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 9256b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 9266b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 9276b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 9286b4cac81SBjoern A. Zeeb uint32_t changed; 9296b4cac81SBjoern A. Zeeb int error; 9306b4cac81SBjoern A. Zeeb 9316b4cac81SBjoern A. Zeeb chan = lkpi_get_lkpi80211_chan(vap->iv_ic, vap->iv_bss); 9326b4cac81SBjoern A. Zeeb if (chan == NULL) { 9336b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: failed to get channel\n", __func__); 9346b4cac81SBjoern A. Zeeb return (ESRCH); 9356b4cac81SBjoern A. Zeeb } 9366b4cac81SBjoern A. Zeeb 9376b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 9386b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 9396b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 9406b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 9416b4cac81SBjoern A. Zeeb 942d9f59799SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 943d9f59799SBjoern A. Zeeb 9446b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 9458ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 9466b4cac81SBjoern A. Zeeb 9476b4cac81SBjoern A. Zeeb /* Add chanctx (or if exists, change it). */ 9486b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 9496b4cac81SBjoern A. Zeeb conf = vif->chanctx_conf; 9506b4cac81SBjoern A. Zeeb IMPROVE("diff changes for changed, working on live copy, rcu"); 9516b4cac81SBjoern A. Zeeb } else { 9526b4cac81SBjoern A. Zeeb /* Keep separate alloc as in Linux this is rcu managed? */ 9536b4cac81SBjoern A. Zeeb conf = malloc(sizeof(*conf) + hw->chanctx_data_size, 9546b4cac81SBjoern A. Zeeb M_LKPI80211, M_WAITOK | M_ZERO); 9556b4cac81SBjoern A. Zeeb } 9566b4cac81SBjoern A. Zeeb 9576b4cac81SBjoern A. Zeeb conf->rx_chains_dynamic = 1; 9586b4cac81SBjoern A. Zeeb conf->rx_chains_static = 1; 9596b4cac81SBjoern A. Zeeb conf->radar_enabled = 9606b4cac81SBjoern A. Zeeb (chan->flags & IEEE80211_CHAN_RADAR) ? true : false; 9616b4cac81SBjoern A. Zeeb conf->def.chan = chan; 9626b4cac81SBjoern A. Zeeb conf->def.width = NL80211_CHAN_WIDTH_20_NOHT; 9636b4cac81SBjoern A. Zeeb conf->def.center_freq1 = chan->center_freq; 9646b4cac81SBjoern A. Zeeb conf->def.center_freq2 = 0; 9656b4cac81SBjoern A. Zeeb /* Responder ... */ 9666b4cac81SBjoern A. Zeeb conf->min_def.chan = chan; 9676b4cac81SBjoern A. Zeeb conf->min_def.width = NL80211_CHAN_WIDTH_20_NOHT; 9686b4cac81SBjoern A. Zeeb conf->min_def.center_freq1 = chan->center_freq; 9696b4cac81SBjoern A. Zeeb conf->min_def.center_freq2 = 0; 9706b4cac81SBjoern A. Zeeb IMPROVE("currently 20_NOHT only"); 9716b4cac81SBjoern A. Zeeb 9726b4cac81SBjoern A. Zeeb error = 0; 9736b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 9746b4cac81SBjoern A. Zeeb changed = IEEE80211_CHANCTX_CHANGE_MIN_WIDTH; 9756b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_RADAR; 9766b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_RX_CHAINS; 9776b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_WIDTH; 9786b4cac81SBjoern A. Zeeb lkpi_80211_mo_change_chanctx(hw, conf, changed); 9796b4cac81SBjoern A. Zeeb } else { 9806b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_add_chanctx(hw, conf); 9816b4cac81SBjoern A. Zeeb if (error == 0 || error == EOPNOTSUPP) { 9826b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.chan = conf->def.chan; 9836b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.width = conf->def.width; 9846b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.center_freq1 = 9856b4cac81SBjoern A. Zeeb conf->def.center_freq1; 9866b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.center_freq2 = 9876b4cac81SBjoern A. Zeeb conf->def.center_freq2; 9886b4cac81SBjoern A. Zeeb } else { 9896b4cac81SBjoern A. Zeeb goto out; 9906b4cac81SBjoern A. Zeeb } 9916b4cac81SBjoern A. Zeeb /* Assign vif chanctx. */ 9926b4cac81SBjoern A. Zeeb if (error == 0) 99368541546SBjoern A. Zeeb error = lkpi_80211_mo_assign_vif_chanctx(hw, vif, 99468541546SBjoern A. Zeeb &vif->bss_conf, conf); 9956b4cac81SBjoern A. Zeeb if (error == EOPNOTSUPP) 9966b4cac81SBjoern A. Zeeb error = 0; 9976b4cac81SBjoern A. Zeeb if (error != 0) { 9986b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 9996b4cac81SBjoern A. Zeeb free(conf, M_LKPI80211); 10006b4cac81SBjoern A. Zeeb goto out; 10016b4cac81SBjoern A. Zeeb } 10026b4cac81SBjoern A. Zeeb } 10036b4cac81SBjoern A. Zeeb IMPROVE("update radiotap chan fields too"); 10046b4cac81SBjoern A. Zeeb 10056b4cac81SBjoern A. Zeeb /* Set bss info (bss_info_changed). */ 10066b4cac81SBjoern A. Zeeb bss_changed = 0; 1007caaa79c3SBjoern A. Zeeb vif->bss_conf.bssid = ni->ni_bssid; 10086b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 10096b4cac81SBjoern A. Zeeb vif->bss_conf.txpower = ni->ni_txpower; 10106b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_TXPOWER; 1011616e1330SBjoern A. Zeeb vif->cfg.idle = false; 10126b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_IDLE; 1013c8dafefaSBjoern A. Zeeb 10146b4cac81SBjoern A. Zeeb /* Should almost assert it is this. */ 1015616e1330SBjoern A. Zeeb vif->cfg.assoc = false; 1016616e1330SBjoern A. Zeeb vif->cfg.aid = 0; 1017fa8f007dSBjoern A. Zeeb 1018fa8f007dSBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 1019fa8f007dSBjoern A. Zeeb 10206b4cac81SBjoern A. Zeeb /* RATES */ 10216b4cac81SBjoern A. Zeeb IMPROVE("bss info: not all needs to come now and rates are missing"); 10226b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 10236b4cac81SBjoern A. Zeeb 1024d9f59799SBjoern A. Zeeb /* 1025d9f59799SBjoern A. Zeeb * This is a bandaid for now. If we went through (*iv_update_bss)() 1026d9f59799SBjoern A. Zeeb * and then removed the lsta we end up here without a lsta and have 1027d9f59799SBjoern A. Zeeb * to manually allocate and link it in as lkpi_ic_node_alloc()/init() 1028d9f59799SBjoern A. Zeeb * would normally do. 1029d9f59799SBjoern A. Zeeb * XXX-BZ I do not like this but currently we have no good way of 1030d9f59799SBjoern A. Zeeb * intercepting the bss swap and state changes and packets going out 1031d9f59799SBjoern A. Zeeb * workflow so live with this. It is a compat layer after all. 1032d9f59799SBjoern A. Zeeb */ 1033d9f59799SBjoern A. Zeeb if (ni->ni_drv_data == NULL) { 1034d9f59799SBjoern A. Zeeb lsta = lkpi_lsta_alloc(vap, ni->ni_macaddr, hw, ni); 1035d9f59799SBjoern A. Zeeb if (lsta == NULL) { 1036d9f59799SBjoern A. Zeeb error = ENOMEM; 1037d9f59799SBjoern A. Zeeb goto out; 1038d9f59799SBjoern A. Zeeb } 1039d9f59799SBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 1040d9f59799SBjoern A. Zeeb } else { 10416b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 1042d9f59799SBjoern A. Zeeb } 1043e24e8103SBjoern A. Zeeb 1044e24e8103SBjoern A. Zeeb /* Insert the [l]sta into the list of known stations. */ 1045e24e8103SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 1046e24e8103SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lvif->lsta_head, lsta, lsta_entry); 1047e24e8103SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 1048e24e8103SBjoern A. Zeeb 1049d9f59799SBjoern A. Zeeb /* Add (or adjust) sta and change state (from NOTEXIST) to NONE. */ 10506b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 10516b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NOTEXIST, ("%s: lsta %p state not " 10526b4cac81SBjoern A. Zeeb "NOTEXIST: %#x\n", __func__, lsta, lsta->state)); 1053e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE); 10546b4cac81SBjoern A. Zeeb if (error != 0) { 10556b4cac81SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 10566b4cac81SBjoern A. Zeeb goto out; 10576b4cac81SBjoern A. Zeeb } 10586b4cac81SBjoern A. Zeeb #if 0 10596b4cac81SBjoern A. Zeeb lsta->added_to_drv = true; /* mo manages. */ 10606b4cac81SBjoern A. Zeeb #endif 10616b4cac81SBjoern A. Zeeb 10629d9ba2b7SBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 10639d9ba2b7SBjoern A. Zeeb 10646b4cac81SBjoern A. Zeeb /* 10656b4cac81SBjoern A. Zeeb * Wakeup all queues now that sta is there so we have as much time to 10666b4cac81SBjoern A. Zeeb * possibly prepare the queue in the driver to be ready for the 1st 10676b4cac81SBjoern A. Zeeb * packet; lkpi_80211_txq_tx_one() still has a workaround as there 10686b4cac81SBjoern A. Zeeb * is no guarantee or way to check. 1069d9f59799SBjoern A. Zeeb * XXX-BZ and by now we know that this does not work on all drivers 1070d9f59799SBjoern A. Zeeb * for all queues. 10716b4cac81SBjoern A. Zeeb */ 1072e7fe0373SBjoern A. Zeeb lkpi_wake_tx_queues(hw, LSTA_TO_STA(lsta), false, false); 10736b4cac81SBjoern A. Zeeb 10746b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 10756b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 10766b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 10776b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 10786b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 10796b4cac81SBjoern A. Zeeb 10806b4cac81SBjoern A. Zeeb /* 10816b4cac81SBjoern A. Zeeb * What is going to happen next: 10826b4cac81SBjoern A. Zeeb * - <twiddle> .. we should end up in "auth_to_assoc" 10836b4cac81SBjoern A. Zeeb * - event_callback 10846b4cac81SBjoern A. Zeeb * - update sta_state (NONE to AUTH) 10856b4cac81SBjoern A. Zeeb * - mgd_complete_tx 10866b4cac81SBjoern A. Zeeb * (ideally we'd do that on a callback for something else ...) 10876b4cac81SBjoern A. Zeeb */ 10886b4cac81SBjoern A. Zeeb 10896b4cac81SBjoern A. Zeeb out: 10908ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 10916b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 10926b4cac81SBjoern A. Zeeb if (ni != NULL) 10936b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 10946b4cac81SBjoern A. Zeeb return (error); 10956b4cac81SBjoern A. Zeeb } 10966b4cac81SBjoern A. Zeeb 10976b4cac81SBjoern A. Zeeb static int 10986b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 10996b4cac81SBjoern A. Zeeb { 11006b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 11016b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 11026b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 11036b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 11046b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 11056b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 11066b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 11076b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 11086b4cac81SBjoern A. Zeeb int error; 11096b4cac81SBjoern A. Zeeb 11106b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 11116b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 11126b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 11136b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 11146b4cac81SBjoern A. Zeeb 11156b4cac81SBjoern A. Zeeb /* Keep ni around. */ 11166b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 11176b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 11186b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 11196b4cac81SBjoern A. Zeeb 112067674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 11216b4cac81SBjoern A. Zeeb 11226b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 11238ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 11246b4cac81SBjoern A. Zeeb 1125d9f59799SBjoern A. Zeeb /* flush, drop. */ 1126d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1127d9f59799SBjoern A. Zeeb 11286b4cac81SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 11296b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 11306b4cac81SBjoern A. Zeeb 11316b4cac81SBjoern A. Zeeb /* flush, no drop */ 11326b4cac81SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 11336b4cac81SBjoern A. Zeeb 11346b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 11356b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 11366b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 11376b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 11386b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 11396b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 11406b4cac81SBjoern A. Zeeb } 11416b4cac81SBjoern A. Zeeb 11426b4cac81SBjoern A. Zeeb /* sync_rx_queues */ 11436b4cac81SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 11446b4cac81SBjoern A. Zeeb 11456b4cac81SBjoern A. Zeeb /* sta_pre_rcu_remove */ 11466b4cac81SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 1147d9f59799SBjoern A. Zeeb 1148d9f59799SBjoern A. Zeeb /* Take the station down. */ 11496b4cac81SBjoern A. Zeeb 11506b4cac81SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 11516b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 11526b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 1153d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg)); 1154e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST); 11556b4cac81SBjoern A. Zeeb if (error != 0) { 11566b4cac81SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 11576b4cac81SBjoern A. Zeeb goto out; 11586b4cac81SBjoern A. Zeeb } 11596b4cac81SBjoern A. Zeeb #if 0 11606b4cac81SBjoern A. Zeeb lsta->added_to_drv = false; /* mo manages. */ 11616b4cac81SBjoern A. Zeeb #endif 11626b4cac81SBjoern A. Zeeb 116367674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 11646b4cac81SBjoern A. Zeeb 1165d9f59799SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif); 1166d9f59799SBjoern A. Zeeb 1167d9f59799SBjoern A. Zeeb /* conf_tx */ 1168d9f59799SBjoern A. Zeeb 1169d9f59799SBjoern A. Zeeb /* Take the chan ctx down. */ 11706b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 11716b4cac81SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 11726b4cac81SBjoern A. Zeeb 11736b4cac81SBjoern A. Zeeb conf = vif->chanctx_conf; 11746b4cac81SBjoern A. Zeeb /* Remove vif context. */ 117568541546SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->bss_conf, &vif->chanctx_conf); 11766b4cac81SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 11776b4cac81SBjoern A. Zeeb 11786b4cac81SBjoern A. Zeeb /* Remove chan ctx. */ 11796b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 11806b4cac81SBjoern A. Zeeb free(conf, M_LKPI80211); 11816b4cac81SBjoern A. Zeeb } 11826b4cac81SBjoern A. Zeeb 11836b4cac81SBjoern A. Zeeb out: 11848ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 11856b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 11866b4cac81SBjoern A. Zeeb if (ni != NULL) 11876b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 11886b4cac81SBjoern A. Zeeb return (error); 11896b4cac81SBjoern A. Zeeb } 11906b4cac81SBjoern A. Zeeb 11916b4cac81SBjoern A. Zeeb static int 11926b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 11936b4cac81SBjoern A. Zeeb { 11946b4cac81SBjoern A. Zeeb int error; 11956b4cac81SBjoern A. Zeeb 11966b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_scan(vap, nstate, arg); 11976b4cac81SBjoern A. Zeeb if (error == 0) 11986b4cac81SBjoern A. Zeeb error = lkpi_sta_scan_to_init(vap, nstate, arg); 11996b4cac81SBjoern A. Zeeb return (error); 12006b4cac81SBjoern A. Zeeb } 12016b4cac81SBjoern A. Zeeb 12026b4cac81SBjoern A. Zeeb static int 12036b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 12046b4cac81SBjoern A. Zeeb { 12056b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 12066b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 12076b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 12086b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 12096b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 12106b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 12116b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 12126b4cac81SBjoern A. Zeeb int error; 12136b4cac81SBjoern A. Zeeb 12146b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 12156b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 12166b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 12176b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 12186b4cac81SBjoern A. Zeeb 12196b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 12208ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 12216b4cac81SBjoern A. Zeeb ni = NULL; 12226b4cac81SBjoern A. Zeeb 12236b4cac81SBjoern A. Zeeb /* Finish auth. */ 12246b4cac81SBjoern A. Zeeb IMPROVE("event callback"); 12256b4cac81SBjoern A. Zeeb 12266b4cac81SBjoern A. Zeeb /* Update sta_state (NONE to AUTH). */ 12276b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 12286b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 12296b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 12306b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 12316b4cac81SBjoern A. Zeeb "NONE: %#x\n", __func__, lsta, lsta->state)); 1232e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH); 12336b4cac81SBjoern A. Zeeb if (error != 0) 12346b4cac81SBjoern A. Zeeb goto out; 12356b4cac81SBjoern A. Zeeb 12366b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 12376b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 12386b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 12396b4cac81SBjoern A. Zeeb prep_tx_info.success = true; 12406b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 12416b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 12426b4cac81SBjoern A. Zeeb } 12436b4cac81SBjoern A. Zeeb 12446b4cac81SBjoern A. Zeeb /* Now start assoc. */ 12456b4cac81SBjoern A. Zeeb 12466b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 12476b4cac81SBjoern A. Zeeb if (!lsta->in_mgd) { 12486b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 12496b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 12506b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 12516b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 12526b4cac81SBjoern A. Zeeb } 12536b4cac81SBjoern A. Zeeb 12546b4cac81SBjoern A. Zeeb /* Wake tx queue to get packet out. */ 1255e7fe0373SBjoern A. Zeeb lkpi_wake_tx_queues(hw, LSTA_TO_STA(lsta), true, true); 12566b4cac81SBjoern A. Zeeb 12576b4cac81SBjoern A. Zeeb /* 12586b4cac81SBjoern A. Zeeb * <twiddle> .. we end up in "assoc_to_run" 12596b4cac81SBjoern A. Zeeb * - update sta_state (AUTH to ASSOC) 12606b4cac81SBjoern A. Zeeb * - conf_tx [all] 12616b4cac81SBjoern A. Zeeb * - bss_info_changed (assoc, aid, ssid, ..) 12626b4cac81SBjoern A. Zeeb * - change_chanctx (if needed) 12636b4cac81SBjoern A. Zeeb * - event_callback 12646b4cac81SBjoern A. Zeeb * - mgd_complete_tx 12656b4cac81SBjoern A. Zeeb */ 12666b4cac81SBjoern A. Zeeb 12676b4cac81SBjoern A. Zeeb out: 12688ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 12696b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 12706b4cac81SBjoern A. Zeeb if (ni != NULL) 12716b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 12726b4cac81SBjoern A. Zeeb return (error); 12736b4cac81SBjoern A. Zeeb } 12746b4cac81SBjoern A. Zeeb 12756b4cac81SBjoern A. Zeeb /* auth_to_auth, assoc_to_assoc. */ 12766b4cac81SBjoern A. Zeeb static int 12776b4cac81SBjoern A. Zeeb lkpi_sta_a_to_a(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 12786b4cac81SBjoern A. Zeeb { 12796b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 12806b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 12816b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 12826b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 12836b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 12846b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 12856b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 12866b4cac81SBjoern A. Zeeb 12876b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 12886b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 12896b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 12906b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 12916b4cac81SBjoern A. Zeeb 12926b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 12936b4cac81SBjoern A. Zeeb 12946b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 12958ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 12966b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 12976b4cac81SBjoern A. Zeeb 12986b4cac81SBjoern A. Zeeb IMPROVE("event callback?"); 12996b4cac81SBjoern A. Zeeb 13006b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 13016b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 13026b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 13036b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 13046b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 13056b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 13066b4cac81SBjoern A. Zeeb } 13076b4cac81SBjoern A. Zeeb 13086b4cac81SBjoern A. Zeeb /* Now start assoc. */ 13096b4cac81SBjoern A. Zeeb 13106b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 13116b4cac81SBjoern A. Zeeb if (!lsta->in_mgd) { 13126b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 13136b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 13146b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 13156b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 13166b4cac81SBjoern A. Zeeb } 13176b4cac81SBjoern A. Zeeb 13188ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 13196b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 13206b4cac81SBjoern A. Zeeb if (ni != NULL) 13216b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 13226b4cac81SBjoern A. Zeeb 13236b4cac81SBjoern A. Zeeb return (0); 13246b4cac81SBjoern A. Zeeb } 13256b4cac81SBjoern A. Zeeb 13266b4cac81SBjoern A. Zeeb static int 1327d9f59799SBjoern A. Zeeb _lkpi_sta_assoc_to_down(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 13286b4cac81SBjoern A. Zeeb { 13296b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 13306b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 13316b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 13326b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 13336b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 13346b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 13356b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 13366b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 1337d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 13386b4cac81SBjoern A. Zeeb int error; 13396b4cac81SBjoern A. Zeeb 13406b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 13416b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 13426b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 13436b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 13446b4cac81SBjoern A. Zeeb 13456b4cac81SBjoern A. Zeeb /* Keep ni around. */ 13466b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 13476b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 13486b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 13496b4cac81SBjoern A. Zeeb 135067674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1351d9f59799SBjoern A. Zeeb 1352d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 13538ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1354d9f59799SBjoern A. Zeeb 1355d9f59799SBjoern A. Zeeb /* flush, drop. */ 1356d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1357d9f59799SBjoern A. Zeeb 1358d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?"); 1359d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) && 1360d9f59799SBjoern A. Zeeb !lsta->in_mgd) { 1361d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1362d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 1363d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 1364d9f59799SBjoern A. Zeeb lsta->in_mgd = true; 1365d9f59799SBjoern A. Zeeb } 1366d9f59799SBjoern A. Zeeb 13678ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 1368d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1369d9f59799SBjoern A. Zeeb 1370d9f59799SBjoern A. Zeeb /* Call iv_newstate first so we get potential DISASSOC packet out. */ 1371d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 1372d9f59799SBjoern A. Zeeb if (error != 0) 1373d9f59799SBjoern A. Zeeb goto outni; 1374d9f59799SBjoern A. Zeeb 1375d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 13768ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1377d9f59799SBjoern A. Zeeb 137867674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1379d9f59799SBjoern A. Zeeb 1380d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 1381d9f59799SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 1382d9f59799SBjoern A. Zeeb 1383d9f59799SBjoern A. Zeeb /* flush, no drop */ 1384d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 1385d9f59799SBjoern A. Zeeb 13866b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 13876b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 13886b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 13896b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 13906b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 13916b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 13926b4cac81SBjoern A. Zeeb } 13936b4cac81SBjoern A. Zeeb 1394d9f59799SBjoern A. Zeeb /* sync_rx_queues */ 1395d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 1396d9f59799SBjoern A. Zeeb 1397d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */ 1398d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 1399d9f59799SBjoern A. Zeeb 1400d9f59799SBjoern A. Zeeb /* Take the station down. */ 1401d9f59799SBjoern A. Zeeb 14026b4cac81SBjoern A. Zeeb /* Update sta and change state (from AUTH) to NONE. */ 14036b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 14046b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 14056b4cac81SBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 1406e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE); 14076b4cac81SBjoern A. Zeeb if (error != 0) 14086b4cac81SBjoern A. Zeeb goto out; 14096b4cac81SBjoern A. Zeeb 141067674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 14116b4cac81SBjoern A. Zeeb 1412d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 1413d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 1414d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 1415d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg)); 1416e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST); 1417d9f59799SBjoern A. Zeeb if (error != 0) { 1418d9f59799SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 1419d9f59799SBjoern A. Zeeb goto out; 1420d9f59799SBjoern A. Zeeb } 1421d9f59799SBjoern A. Zeeb #if 0 1422d9f59799SBjoern A. Zeeb lsta->added_to_drv = false; /* mo manages. */ 1423d9f59799SBjoern A. Zeeb #endif 1424d9f59799SBjoern A. Zeeb 142567674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1426d9f59799SBjoern A. Zeeb 1427d9f59799SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 1428d9f59799SBjoern A. Zeeb /* We need to do this now, can only do after sta is IEEE80211_STA_NOTEXIST. */ 1429d9f59799SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw); 1430d9f59799SBjoern A. Zeeb 1431d9f59799SBjoern A. Zeeb IMPROVE("Any bss_info changes to announce?"); 1432d9f59799SBjoern A. Zeeb bss_changed = 0; 1433d9f59799SBjoern A. Zeeb vif->bss_conf.qos = 0; 1434d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 1435616e1330SBjoern A. Zeeb vif->cfg.ssid_len = 0; 1436616e1330SBjoern A. Zeeb memset(vif->cfg.ssid, '\0', sizeof(vif->cfg.ssid)); 1437d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 1438d9f59799SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 1439d9f59799SBjoern A. Zeeb 1440d9f59799SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif); 1441d9f59799SBjoern A. Zeeb 1442d9f59799SBjoern A. Zeeb /* conf_tx */ 1443d9f59799SBjoern A. Zeeb 1444d9f59799SBjoern A. Zeeb /* Take the chan ctx down. */ 1445d9f59799SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 1446d9f59799SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 1447d9f59799SBjoern A. Zeeb 1448d9f59799SBjoern A. Zeeb conf = vif->chanctx_conf; 1449d9f59799SBjoern A. Zeeb /* Remove vif context. */ 145068541546SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->bss_conf, &vif->chanctx_conf); 1451d9f59799SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 1452d9f59799SBjoern A. Zeeb 1453d9f59799SBjoern A. Zeeb /* Remove chan ctx. */ 1454d9f59799SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 1455d9f59799SBjoern A. Zeeb free(conf, M_LKPI80211); 1456d9f59799SBjoern A. Zeeb } 1457d9f59799SBjoern A. Zeeb 1458d9f59799SBjoern A. Zeeb error = EALREADY; 14596b4cac81SBjoern A. Zeeb out: 14608ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 14616b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1462d9f59799SBjoern A. Zeeb outni: 14636b4cac81SBjoern A. Zeeb if (ni != NULL) 14646b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 14656b4cac81SBjoern A. Zeeb return (error); 14666b4cac81SBjoern A. Zeeb } 14676b4cac81SBjoern A. Zeeb 14686b4cac81SBjoern A. Zeeb static int 1469d9f59799SBjoern A. Zeeb lkpi_sta_assoc_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 1470d9f59799SBjoern A. Zeeb { 1471d9f59799SBjoern A. Zeeb int error; 1472d9f59799SBjoern A. Zeeb 1473d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg); 1474d9f59799SBjoern A. Zeeb if (error != 0 && error != EALREADY) 1475d9f59799SBjoern A. Zeeb return (error); 1476d9f59799SBjoern A. Zeeb 1477d9f59799SBjoern A. Zeeb /* At this point iv_bss is long a new node! */ 1478d9f59799SBjoern A. Zeeb 1479d9f59799SBjoern A. Zeeb error |= lkpi_sta_scan_to_auth(vap, nstate, 0); 1480d9f59799SBjoern A. Zeeb return (error); 1481d9f59799SBjoern A. Zeeb } 1482d9f59799SBjoern A. Zeeb 1483d9f59799SBjoern A. Zeeb static int 14846b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 14856b4cac81SBjoern A. Zeeb { 14866b4cac81SBjoern A. Zeeb int error; 14876b4cac81SBjoern A. Zeeb 1488d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg); 14896b4cac81SBjoern A. Zeeb return (error); 14906b4cac81SBjoern A. Zeeb } 14916b4cac81SBjoern A. Zeeb 14926b4cac81SBjoern A. Zeeb static int 14936b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 14946b4cac81SBjoern A. Zeeb { 14956b4cac81SBjoern A. Zeeb int error; 14966b4cac81SBjoern A. Zeeb 1497d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg); 14986b4cac81SBjoern A. Zeeb return (error); 14996b4cac81SBjoern A. Zeeb } 15006b4cac81SBjoern A. Zeeb 15016b4cac81SBjoern A. Zeeb static int 15026b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 15036b4cac81SBjoern A. Zeeb { 15046b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 15056b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 15066b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 15076b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 15086b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 15096b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 15106b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 15116b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 15126b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 15136b4cac81SBjoern A. Zeeb int error; 15146b4cac81SBjoern A. Zeeb 15156b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 15166b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 15176b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 15186b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 15196b4cac81SBjoern A. Zeeb 15206b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 15218ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 15229597f7cbSBjoern A. Zeeb ni = NULL; 15236b4cac81SBjoern A. Zeeb 15246b4cac81SBjoern A. Zeeb IMPROVE("ponder some of this moved to ic_newassoc, scan_assoc_success, " 15256b4cac81SBjoern A. Zeeb "and to lesser extend ieee80211_notify_node_join"); 15266b4cac81SBjoern A. Zeeb 15279597f7cbSBjoern A. Zeeb /* Finish assoc. */ 15289597f7cbSBjoern A. Zeeb /* Update sta_state (AUTH to ASSOC) and set aid. */ 15296b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 15306b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 15316b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 15329597f7cbSBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 15339597f7cbSBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 15346b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 15359597f7cbSBjoern A. Zeeb sta->aid = IEEE80211_NODE_AID(ni); 15364a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 15374a67f1dfSBjoern A. Zeeb if (vap->iv_flags & IEEE80211_F_WME) 15384a67f1dfSBjoern A. Zeeb sta->wme = true; 15394a67f1dfSBjoern A. Zeeb #endif 1540e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC); 15419597f7cbSBjoern A. Zeeb if (error != 0) 15429597f7cbSBjoern A. Zeeb goto out; 15436b4cac81SBjoern A. Zeeb 15446b4cac81SBjoern A. Zeeb IMPROVE("wme / conf_tx [all]"); 15456b4cac81SBjoern A. Zeeb 15466b4cac81SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 15476b4cac81SBjoern A. Zeeb bss_changed = 0; 15484a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 15494a67f1dfSBjoern A. Zeeb bss_changed |= lkpi_wme_update(lhw, vap, true); 15504a67f1dfSBjoern A. Zeeb #endif 1551616e1330SBjoern A. Zeeb if (!vif->cfg.assoc || vif->cfg.aid != IEEE80211_NODE_AID(ni)) { 1552616e1330SBjoern A. Zeeb vif->cfg.assoc = true; 1553616e1330SBjoern A. Zeeb vif->cfg.aid = IEEE80211_NODE_AID(ni); 15546b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_ASSOC; 15556b4cac81SBjoern A. Zeeb } 15566b4cac81SBjoern A. Zeeb /* We set SSID but this is not BSSID! */ 1557616e1330SBjoern A. Zeeb vif->cfg.ssid_len = ni->ni_esslen; 1558616e1330SBjoern A. Zeeb memcpy(vif->cfg.ssid, ni->ni_essid, ni->ni_esslen); 15596b4cac81SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_SHPREAMBLE) != 15606b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble) { 15616b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble ^= 1; 15626b4cac81SBjoern A. Zeeb /* bss_changed |= BSS_CHANGED_??? */ 15636b4cac81SBjoern A. Zeeb } 15646b4cac81SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_SHSLOT) != 15656b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot) { 15666b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot ^= 1; 15676b4cac81SBjoern A. Zeeb /* bss_changed |= BSS_CHANGED_??? */ 15686b4cac81SBjoern A. Zeeb } 15696b4cac81SBjoern A. Zeeb if ((ni->ni_flags & IEEE80211_NODE_QOS) != 15706b4cac81SBjoern A. Zeeb vif->bss_conf.qos) { 15716b4cac81SBjoern A. Zeeb vif->bss_conf.qos ^= 1; 15726b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 15736b4cac81SBjoern A. Zeeb } 1574fa8f007dSBjoern A. Zeeb 1575fa8f007dSBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 1576fa8f007dSBjoern A. Zeeb 15776b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 15786b4cac81SBjoern A. Zeeb 15796b4cac81SBjoern A. Zeeb /* - change_chanctx (if needed) 15806b4cac81SBjoern A. Zeeb * - event_callback 15816b4cac81SBjoern A. Zeeb */ 15826b4cac81SBjoern A. Zeeb 15836b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 15846b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 15856b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 15866b4cac81SBjoern A. Zeeb prep_tx_info.success = true; 15876b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 15886b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 15896b4cac81SBjoern A. Zeeb } 15906b4cac81SBjoern A. Zeeb 1591086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, false); 1592086be6a8SBjoern A. Zeeb 15936b4cac81SBjoern A. Zeeb /* 15946b4cac81SBjoern A. Zeeb * And then: 15956b4cac81SBjoern A. Zeeb * - (more packets)? 15966b4cac81SBjoern A. Zeeb * - set_key 15976b4cac81SBjoern A. Zeeb * - set_default_unicast_key 15986b4cac81SBjoern A. Zeeb * - set_key (?) 15996b4cac81SBjoern A. Zeeb * - ipv6_addr_change (?) 16006b4cac81SBjoern A. Zeeb */ 16016b4cac81SBjoern A. Zeeb /* Prepare_multicast && configure_filter. */ 16026b4cac81SBjoern A. Zeeb lhw->update_mc = true; 16036b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(vap->iv_ic, true); 16046b4cac81SBjoern A. Zeeb 16056b4cac81SBjoern A. Zeeb if (!ieee80211_node_is_authorized(ni)) { 16066b4cac81SBjoern A. Zeeb IMPROVE("net80211 does not consider node authorized"); 16076b4cac81SBjoern A. Zeeb } 16086b4cac81SBjoern A. Zeeb 16096b4cac81SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTHORIZED). */ 16106b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 16116b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 16126b4cac81SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 1613e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTHORIZED); 16146b4cac81SBjoern A. Zeeb if (error != 0) { 16156b4cac81SBjoern A. Zeeb IMPROVE("undo some changes?"); 16166b4cac81SBjoern A. Zeeb goto out; 16176b4cac81SBjoern A. Zeeb } 16186b4cac81SBjoern A. Zeeb 16196b4cac81SBjoern A. Zeeb /* - drv_config (?) 16206b4cac81SBjoern A. Zeeb * - bss_info_changed 16216b4cac81SBjoern A. Zeeb * - set_rekey_data (?) 16226b4cac81SBjoern A. Zeeb * 16236b4cac81SBjoern A. Zeeb * And now we should be passing packets. 16246b4cac81SBjoern A. Zeeb */ 16256b4cac81SBjoern A. Zeeb IMPROVE("Need that bssid setting, and the keys"); 16266b4cac81SBjoern A. Zeeb 1627fa8f007dSBjoern A. Zeeb bss_changed = 0; 1628fa8f007dSBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 1629fa8f007dSBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 1630fa8f007dSBjoern A. Zeeb 16316b4cac81SBjoern A. Zeeb out: 16328ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 16336b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 16346b4cac81SBjoern A. Zeeb if (ni != NULL) 16356b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 16366b4cac81SBjoern A. Zeeb return (error); 16376b4cac81SBjoern A. Zeeb } 16386b4cac81SBjoern A. Zeeb 16396b4cac81SBjoern A. Zeeb static int 16406b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 16416b4cac81SBjoern A. Zeeb { 16426b4cac81SBjoern A. Zeeb int error; 16436b4cac81SBjoern A. Zeeb 16446b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_assoc(vap, nstate, arg); 16456b4cac81SBjoern A. Zeeb if (error == 0) 16466b4cac81SBjoern A. Zeeb error = lkpi_sta_assoc_to_run(vap, nstate, arg); 16476b4cac81SBjoern A. Zeeb return (error); 16486b4cac81SBjoern A. Zeeb } 16496b4cac81SBjoern A. Zeeb 16506b4cac81SBjoern A. Zeeb static int 16516b4cac81SBjoern A. Zeeb lkpi_sta_run_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 16526b4cac81SBjoern A. Zeeb { 16536b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 16546b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 16556b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 16566b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 16576b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 16586b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 16596b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 1660d9f59799SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 1661d9f59799SBjoern A. Zeeb #if 0 1662d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 1663d9f59799SBjoern A. Zeeb #endif 16646b4cac81SBjoern A. Zeeb int error; 16656b4cac81SBjoern A. Zeeb 16666b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 16676b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 16686b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 16696b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 16706b4cac81SBjoern A. Zeeb 16716b4cac81SBjoern A. Zeeb /* Keep ni around. */ 16726b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 16736b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 16746b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 16756b4cac81SBjoern A. Zeeb 167667674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1677d9f59799SBjoern A. Zeeb 1678d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 16798ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1680d9f59799SBjoern A. Zeeb 1681d9f59799SBjoern A. Zeeb /* flush, drop. */ 1682d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1683d9f59799SBjoern A. Zeeb 1684d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?"); 1685d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) && 1686d9f59799SBjoern A. Zeeb !lsta->in_mgd) { 1687d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1688d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 1689d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 1690d9f59799SBjoern A. Zeeb lsta->in_mgd = true; 1691d9f59799SBjoern A. Zeeb } 1692d9f59799SBjoern A. Zeeb 16938ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 1694d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1695d9f59799SBjoern A. Zeeb 1696d9f59799SBjoern A. Zeeb /* Call iv_newstate first so we get potential DISASSOC packet out. */ 1697d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 1698d9f59799SBjoern A. Zeeb if (error != 0) 1699d9f59799SBjoern A. Zeeb goto outni; 1700d9f59799SBjoern A. Zeeb 1701d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 17028ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1703d9f59799SBjoern A. Zeeb 170467674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1705d9f59799SBjoern A. Zeeb 1706d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 1707d9f59799SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 1708d9f59799SBjoern A. Zeeb 1709d9f59799SBjoern A. Zeeb /* flush, no drop */ 1710d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 1711d9f59799SBjoern A. Zeeb 1712d9f59799SBjoern A. Zeeb /* End mgd_complete_tx. */ 1713d9f59799SBjoern A. Zeeb if (lsta->in_mgd) { 1714d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1715d9f59799SBjoern A. Zeeb prep_tx_info.success = false; 1716d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 1717d9f59799SBjoern A. Zeeb lsta->in_mgd = false; 1718d9f59799SBjoern A. Zeeb } 1719d9f59799SBjoern A. Zeeb 1720d9f59799SBjoern A. Zeeb #if 0 1721d9f59799SBjoern A. Zeeb /* sync_rx_queues */ 1722d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 1723d9f59799SBjoern A. Zeeb 1724d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */ 1725d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 1726d9f59799SBjoern A. Zeeb #endif 1727d9f59799SBjoern A. Zeeb 1728d9f59799SBjoern A. Zeeb /* Take the station down. */ 1729d9f59799SBjoern A. Zeeb 17306b4cac81SBjoern A. Zeeb /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */ 17316b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 17326b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not " 17336b4cac81SBjoern A. Zeeb "AUTHORIZED: %#x\n", __func__, lsta, lsta->state)); 1734e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC); 17356b4cac81SBjoern A. Zeeb if (error != 0) 17366b4cac81SBjoern A. Zeeb goto out; 17376b4cac81SBjoern A. Zeeb 173867674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 17396b4cac81SBjoern A. Zeeb 17406b4cac81SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTH). */ 17416b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 17426b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 17436b4cac81SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 1744e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH); 17456b4cac81SBjoern A. Zeeb if (error != 0) 17466b4cac81SBjoern A. Zeeb goto out; 17476b4cac81SBjoern A. Zeeb 174867674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 17496b4cac81SBjoern A. Zeeb 1750d9f59799SBjoern A. Zeeb #if 0 1751d9f59799SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 1752d9f59799SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw); 1753d9f59799SBjoern A. Zeeb #endif 1754d9f59799SBjoern A. Zeeb 1755d9f59799SBjoern A. Zeeb error = EALREADY; 17566b4cac81SBjoern A. Zeeb out: 17578ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 17586b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1759d9f59799SBjoern A. Zeeb outni: 17606b4cac81SBjoern A. Zeeb if (ni != NULL) 17616b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 17626b4cac81SBjoern A. Zeeb return (error); 17636b4cac81SBjoern A. Zeeb } 17646b4cac81SBjoern A. Zeeb 17656b4cac81SBjoern A. Zeeb static int 1766d9f59799SBjoern A. Zeeb lkpi_sta_run_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 1767d9f59799SBjoern A. Zeeb { 1768d9f59799SBjoern A. Zeeb struct lkpi_hw *lhw; 1769d9f59799SBjoern A. Zeeb struct ieee80211_hw *hw; 1770d9f59799SBjoern A. Zeeb struct lkpi_vif *lvif; 1771d9f59799SBjoern A. Zeeb struct ieee80211_vif *vif; 1772d9f59799SBjoern A. Zeeb struct ieee80211_node *ni; 1773d9f59799SBjoern A. Zeeb struct lkpi_sta *lsta; 1774d9f59799SBjoern A. Zeeb struct ieee80211_sta *sta; 1775d9f59799SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 1776d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 1777d9f59799SBjoern A. Zeeb int error; 1778d9f59799SBjoern A. Zeeb 1779d9f59799SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 1780d9f59799SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 1781d9f59799SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 1782d9f59799SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 1783d9f59799SBjoern A. Zeeb 1784d9f59799SBjoern A. Zeeb /* Keep ni around. */ 1785d9f59799SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 1786d9f59799SBjoern A. Zeeb lsta = ni->ni_drv_data; 1787d9f59799SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 1788d9f59799SBjoern A. Zeeb 178967674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1790d9f59799SBjoern A. Zeeb 1791d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 17928ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1793d9f59799SBjoern A. Zeeb 1794d9f59799SBjoern A. Zeeb /* flush, drop. */ 1795d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1796d9f59799SBjoern A. Zeeb 1797d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?"); 1798d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) && 1799d9f59799SBjoern A. Zeeb !lsta->in_mgd) { 1800d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1801d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 1802d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 1803d9f59799SBjoern A. Zeeb lsta->in_mgd = true; 1804d9f59799SBjoern A. Zeeb } 1805d9f59799SBjoern A. Zeeb 18068ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 1807d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1808d9f59799SBjoern A. Zeeb 1809d9f59799SBjoern A. Zeeb /* Call iv_newstate first so we get potential DISASSOC packet out. */ 1810d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 1811d9f59799SBjoern A. Zeeb if (error != 0) 1812d9f59799SBjoern A. Zeeb goto outni; 1813d9f59799SBjoern A. Zeeb 1814d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 18158ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1816d9f59799SBjoern A. Zeeb 181767674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1818d9f59799SBjoern A. Zeeb 1819d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 1820d9f59799SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 1821d9f59799SBjoern A. Zeeb 1822d9f59799SBjoern A. Zeeb /* flush, no drop */ 1823d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 1824d9f59799SBjoern A. Zeeb 1825d9f59799SBjoern A. Zeeb /* End mgd_complete_tx. */ 1826d9f59799SBjoern A. Zeeb if (lsta->in_mgd) { 1827d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1828d9f59799SBjoern A. Zeeb prep_tx_info.success = false; 1829d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 1830d9f59799SBjoern A. Zeeb lsta->in_mgd = false; 1831d9f59799SBjoern A. Zeeb } 1832d9f59799SBjoern A. Zeeb 1833d9f59799SBjoern A. Zeeb /* sync_rx_queues */ 1834d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 1835d9f59799SBjoern A. Zeeb 1836d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */ 1837d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 1838d9f59799SBjoern A. Zeeb 1839d9f59799SBjoern A. Zeeb /* Take the station down. */ 1840d9f59799SBjoern A. Zeeb 1841d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */ 1842d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 1843d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not " 1844d9f59799SBjoern A. Zeeb "AUTHORIZED: %#x\n", __func__, lsta, lsta->state)); 1845e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC); 1846d9f59799SBjoern A. Zeeb if (error != 0) 1847d9f59799SBjoern A. Zeeb goto out; 1848d9f59799SBjoern A. Zeeb 184967674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1850d9f59799SBjoern A. Zeeb 1851d9f59799SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTH). */ 1852d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 1853d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 1854d9f59799SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 1855e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH); 1856d9f59799SBjoern A. Zeeb if (error != 0) 1857d9f59799SBjoern A. Zeeb goto out; 1858d9f59799SBjoern A. Zeeb 185967674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1860d9f59799SBjoern A. Zeeb 1861d9f59799SBjoern A. Zeeb /* Update sta and change state (from AUTH) to NONE. */ 1862d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 1863d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 1864d9f59799SBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 1865e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE); 1866d9f59799SBjoern A. Zeeb if (error != 0) 1867d9f59799SBjoern A. Zeeb goto out; 1868d9f59799SBjoern A. Zeeb 186967674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1870d9f59799SBjoern A. Zeeb 1871d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 1872d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 1873d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 1874d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg)); 1875e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST); 1876d9f59799SBjoern A. Zeeb if (error != 0) { 1877d9f59799SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 1878d9f59799SBjoern A. Zeeb goto out; 1879d9f59799SBjoern A. Zeeb } 1880d9f59799SBjoern A. Zeeb #if 0 1881d9f59799SBjoern A. Zeeb lsta->added_to_drv = false; /* mo manages. */ 1882d9f59799SBjoern A. Zeeb #endif 1883d9f59799SBjoern A. Zeeb 188467674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1885d9f59799SBjoern A. Zeeb 1886d9f59799SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 1887d9f59799SBjoern A. Zeeb /* 1888d9f59799SBjoern A. Zeeb * One would expect this to happen when going off AUTHORIZED. 1889d9f59799SBjoern A. Zeeb * See comment there; removes the sta from fw. 1890d9f59799SBjoern A. Zeeb */ 1891d9f59799SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw); 1892d9f59799SBjoern A. Zeeb 1893d9f59799SBjoern A. Zeeb IMPROVE("Any bss_info changes to announce?"); 1894d9f59799SBjoern A. Zeeb bss_changed = 0; 1895d9f59799SBjoern A. Zeeb vif->bss_conf.qos = 0; 1896d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 1897616e1330SBjoern A. Zeeb vif->cfg.ssid_len = 0; 1898616e1330SBjoern A. Zeeb memset(vif->cfg.ssid, '\0', sizeof(vif->cfg.ssid)); 1899d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 1900d9f59799SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 1901d9f59799SBjoern A. Zeeb 1902d9f59799SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif); 1903d9f59799SBjoern A. Zeeb 1904d9f59799SBjoern A. Zeeb /* conf_tx */ 1905d9f59799SBjoern A. Zeeb 1906d9f59799SBjoern A. Zeeb /* Take the chan ctx down. */ 1907d9f59799SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 1908d9f59799SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 1909d9f59799SBjoern A. Zeeb 1910d9f59799SBjoern A. Zeeb conf = vif->chanctx_conf; 1911d9f59799SBjoern A. Zeeb /* Remove vif context. */ 191268541546SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->bss_conf, &vif->chanctx_conf); 1913d9f59799SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 1914d9f59799SBjoern A. Zeeb 1915d9f59799SBjoern A. Zeeb /* Remove chan ctx. */ 1916d9f59799SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 1917d9f59799SBjoern A. Zeeb free(conf, M_LKPI80211); 1918d9f59799SBjoern A. Zeeb } 1919d9f59799SBjoern A. Zeeb 1920d9f59799SBjoern A. Zeeb error = EALREADY; 1921d9f59799SBjoern A. Zeeb out: 19228ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 1923d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1924d9f59799SBjoern A. Zeeb outni: 1925d9f59799SBjoern A. Zeeb if (ni != NULL) 1926d9f59799SBjoern A. Zeeb ieee80211_free_node(ni); 1927d9f59799SBjoern A. Zeeb return (error); 1928d9f59799SBjoern A. Zeeb } 1929d9f59799SBjoern A. Zeeb 1930d9f59799SBjoern A. Zeeb static int 1931d9f59799SBjoern A. Zeeb lkpi_sta_run_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 1932d9f59799SBjoern A. Zeeb { 1933d9f59799SBjoern A. Zeeb 1934d9f59799SBjoern A. Zeeb return (lkpi_sta_run_to_init(vap, nstate, arg)); 1935d9f59799SBjoern A. Zeeb } 1936d9f59799SBjoern A. Zeeb 1937d9f59799SBjoern A. Zeeb static int 19386b4cac81SBjoern A. Zeeb lkpi_sta_run_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 19396b4cac81SBjoern A. Zeeb { 19406b4cac81SBjoern A. Zeeb int error; 19416b4cac81SBjoern A. Zeeb 1942d9f59799SBjoern A. Zeeb error = lkpi_sta_run_to_init(vap, nstate, arg); 1943d9f59799SBjoern A. Zeeb if (error != 0 && error != EALREADY) 1944d9f59799SBjoern A. Zeeb return (error); 1945d9f59799SBjoern A. Zeeb 1946d9f59799SBjoern A. Zeeb /* At this point iv_bss is long a new node! */ 1947d9f59799SBjoern A. Zeeb 1948d9f59799SBjoern A. Zeeb error |= lkpi_sta_scan_to_auth(vap, nstate, 0); 19496b4cac81SBjoern A. Zeeb return (error); 19506b4cac81SBjoern A. Zeeb } 19516b4cac81SBjoern A. Zeeb 1952d9f59799SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 19536b4cac81SBjoern A. Zeeb 19546b4cac81SBjoern A. Zeeb /* 19556b4cac81SBjoern A. Zeeb * The matches the documented state changes in net80211::sta_newstate(). 19566b4cac81SBjoern A. Zeeb * XXX (1) without CSA and SLEEP yet, * XXX (2) not all unhandled cases 19576b4cac81SBjoern A. Zeeb * there are "invalid" (so there is a room for failure here). 19586b4cac81SBjoern A. Zeeb */ 19596b4cac81SBjoern A. Zeeb struct fsm_state { 19606b4cac81SBjoern A. Zeeb /* INIT, SCAN, AUTH, ASSOC, CAC, RUN, CSA, SLEEP */ 19616b4cac81SBjoern A. Zeeb enum ieee80211_state ostate; 19626b4cac81SBjoern A. Zeeb enum ieee80211_state nstate; 19636b4cac81SBjoern A. Zeeb int (*handler)(struct ieee80211vap *, enum ieee80211_state, int); 19646b4cac81SBjoern A. Zeeb } sta_state_fsm[] = { 19656b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, 19666b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, /* scan_to_init */ 19676b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_INIT, lkpi_sta_auth_to_init }, /* not explicitly in sta_newstate() */ 1968d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_INIT, lkpi_sta_assoc_to_init }, /* Send DEAUTH. */ 1969d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_INIT, lkpi_sta_run_to_init }, /* Send DISASSOC. */ 19706b4cac81SBjoern A. Zeeb 19716b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_SCAN, lkpi_sta_state_do_nada }, 19726b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_SCAN, lkpi_sta_state_do_nada }, 19736b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_SCAN, lkpi_sta_auth_to_scan }, 19746b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_SCAN, lkpi_sta_assoc_to_scan }, 1975d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_SCAN, lkpi_sta_run_to_scan }, /* Beacon miss. */ 19766b4cac81SBjoern A. Zeeb 1977d9f59799SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, /* Send AUTH. */ 1978d9f59799SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, /* Send AUTH. */ 1979d9f59799SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_AUTH, lkpi_sta_a_to_a }, /* Send ?AUTH. */ 1980d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_AUTH, lkpi_sta_assoc_to_auth }, /* Send ?AUTH. */ 1981d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_AUTH, lkpi_sta_run_to_auth }, /* Send ?AUTH. */ 19826b4cac81SBjoern A. Zeeb 1983d9f59799SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_ASSOC, lkpi_sta_auth_to_assoc }, /* Send ASSOCREQ. */ 1984d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_ASSOC, lkpi_sta_a_to_a }, /* Send ASSOCREQ. */ 1985d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_ASSOC, lkpi_sta_run_to_assoc }, /* Send ASSOCREQ/REASSOCREQ. */ 19866b4cac81SBjoern A. Zeeb 19876b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_RUN, lkpi_sta_auth_to_run }, 19886b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_RUN, lkpi_sta_assoc_to_run }, 19896b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_RUN, lkpi_sta_state_do_nada }, 19906b4cac81SBjoern A. Zeeb 19916b4cac81SBjoern A. Zeeb /* Dummy at the end without handler. */ 19926b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_INIT, NULL }, 19936b4cac81SBjoern A. Zeeb }; 19946b4cac81SBjoern A. Zeeb 19956b4cac81SBjoern A. Zeeb static int 19966b4cac81SBjoern A. Zeeb lkpi_iv_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 19976b4cac81SBjoern A. Zeeb { 19986b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 19996b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 20006b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 20016b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 20026b4cac81SBjoern A. Zeeb struct fsm_state *s; 20036b4cac81SBjoern A. Zeeb enum ieee80211_state ostate; 20046b4cac81SBjoern A. Zeeb int error; 20056b4cac81SBjoern A. Zeeb 20066b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 20076b4cac81SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(ic); 20086b4cac81SBjoern A. Zeeb ostate = vap->iv_state; 20096b4cac81SBjoern A. Zeeb 20109d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 20119d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 20126b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x\n", 20136b4cac81SBjoern A. Zeeb __func__, __LINE__, vap, nstate, arg); 20149d9ba2b7SBjoern A. Zeeb #endif 20156b4cac81SBjoern A. Zeeb 20166b4cac81SBjoern A. Zeeb if (vap->iv_opmode == IEEE80211_M_STA) { 20176b4cac81SBjoern A. Zeeb 20186b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 20196b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 20206b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 20216b4cac81SBjoern A. Zeeb 20226b4cac81SBjoern A. Zeeb /* No need to replicate this in most state handlers. */ 20236b4cac81SBjoern A. Zeeb if (ostate == IEEE80211_S_SCAN && nstate != IEEE80211_S_SCAN) 20246b4cac81SBjoern A. Zeeb lkpi_stop_hw_scan(lhw, vif); 20256b4cac81SBjoern A. Zeeb 20266b4cac81SBjoern A. Zeeb s = sta_state_fsm; 20276b4cac81SBjoern A. Zeeb 20286b4cac81SBjoern A. Zeeb } else { 20296b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: only station mode currently supported: " 20306b4cac81SBjoern A. Zeeb "cap %p iv_opmode %d\n", __func__, vap, vap->iv_opmode); 20316b4cac81SBjoern A. Zeeb return (ENOSYS); 20326b4cac81SBjoern A. Zeeb } 20336b4cac81SBjoern A. Zeeb 20346b4cac81SBjoern A. Zeeb error = 0; 20356b4cac81SBjoern A. Zeeb for (; s->handler != NULL; s++) { 20366b4cac81SBjoern A. Zeeb if (ostate == s->ostate && nstate == s->nstate) { 20379d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 20389d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 2039d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: new state %d (%s) ->" 2040d9f59799SBjoern A. Zeeb " %d (%s): arg %d.\n", __func__, 2041d9f59799SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 2042d9f59799SBjoern A. Zeeb nstate, ieee80211_state_name[nstate], arg); 20439d9ba2b7SBjoern A. Zeeb #endif 20446b4cac81SBjoern A. Zeeb error = s->handler(vap, nstate, arg); 20456b4cac81SBjoern A. Zeeb break; 20466b4cac81SBjoern A. Zeeb } 20476b4cac81SBjoern A. Zeeb } 20486b4cac81SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(vap->iv_ic); 20496b4cac81SBjoern A. Zeeb 20506b4cac81SBjoern A. Zeeb if (s->handler == NULL) { 2051d9f59799SBjoern A. Zeeb IMPROVE("turn this into a KASSERT\n"); 20526b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: unsupported state transition " 20536b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s)\n", __func__, 20546b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 20556b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 20566b4cac81SBjoern A. Zeeb return (ENOSYS); 20576b4cac81SBjoern A. Zeeb } 20586b4cac81SBjoern A. Zeeb 20596b4cac81SBjoern A. Zeeb if (error == EALREADY) { 20609d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 20619d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 2062d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: state transition %d (%s) -> " 2063d9f59799SBjoern A. Zeeb "%d (%s): iv_newstate already handled: %d.\n", 2064d9f59799SBjoern A. Zeeb __func__, ostate, ieee80211_state_name[ostate], 2065d9f59799SBjoern A. Zeeb nstate, ieee80211_state_name[nstate], error); 20669d9ba2b7SBjoern A. Zeeb #endif 20676b4cac81SBjoern A. Zeeb return (0); 20686b4cac81SBjoern A. Zeeb } 20696b4cac81SBjoern A. Zeeb 20706b4cac81SBjoern A. Zeeb if (error != 0) { 20716b4cac81SBjoern A. Zeeb /* XXX-BZ currently expected so ignore. */ 20726b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: error %d during state transition " 20736b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s)\n", __func__, error, 20746b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 20756b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 20766b4cac81SBjoern A. Zeeb /* return (error); */ 20776b4cac81SBjoern A. Zeeb } 20786b4cac81SBjoern A. Zeeb 20799d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 20809d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 2081d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x " 2082d9f59799SBjoern A. Zeeb "calling net80211 parent\n", 20836b4cac81SBjoern A. Zeeb __func__, __LINE__, vap, nstate, arg); 20849d9ba2b7SBjoern A. Zeeb #endif 20856b4cac81SBjoern A. Zeeb 20866b4cac81SBjoern A. Zeeb return (lvif->iv_newstate(vap, nstate, arg)); 20876b4cac81SBjoern A. Zeeb } 20886b4cac81SBjoern A. Zeeb 20896b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 20906b4cac81SBjoern A. Zeeb 2091d9f59799SBjoern A. Zeeb /* 2092d9f59799SBjoern A. Zeeb * We overload (*iv_update_bss) as otherwise we have cases in, e.g., 2093d9f59799SBjoern A. Zeeb * net80211::ieee80211_sta_join1() where vap->iv_bss gets replaced by a 2094d9f59799SBjoern A. Zeeb * new node without us knowing and thus our ni/lsta are out of sync. 2095d9f59799SBjoern A. Zeeb */ 2096d9f59799SBjoern A. Zeeb static struct ieee80211_node * 2097d9f59799SBjoern A. Zeeb lkpi_iv_update_bss(struct ieee80211vap *vap, struct ieee80211_node *ni) 2098d9f59799SBjoern A. Zeeb { 2099d9f59799SBjoern A. Zeeb struct lkpi_vif *lvif; 2100d9f59799SBjoern A. Zeeb struct ieee80211_node *obss; 2101d9f59799SBjoern A. Zeeb struct lkpi_sta *lsta; 2102ed3ef56bSBjoern A. Zeeb struct ieee80211_sta *sta; 2103d9f59799SBjoern A. Zeeb 2104d9f59799SBjoern A. Zeeb obss = vap->iv_bss; 2105d9f59799SBjoern A. Zeeb 21069d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 21079d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 21089d9ba2b7SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: obss %p ni_drv_data %p " 21099d9ba2b7SBjoern A. Zeeb "ni %p ni_drv_data %p\n", __func__, 21109d9ba2b7SBjoern A. Zeeb obss, (obss != NULL) ? obss->ni_drv_data : NULL, 21119d9ba2b7SBjoern A. Zeeb ni, (ni != NULL) ? ni->ni_drv_data : NULL); 21129d9ba2b7SBjoern A. Zeeb #endif 21139d9ba2b7SBjoern A. Zeeb 2114d9f59799SBjoern A. Zeeb /* Nothing to copy from. Just return. */ 2115d9f59799SBjoern A. Zeeb if (obss == NULL || obss->ni_drv_data == NULL) 2116d9f59799SBjoern A. Zeeb goto out; 2117d9f59799SBjoern A. Zeeb 2118d9f59799SBjoern A. Zeeb /* Nothing to copy to. Just return. */ 2119d9f59799SBjoern A. Zeeb IMPROVE("clearing the obss might still be needed?"); 2120d9f59799SBjoern A. Zeeb if (ni == NULL) 2121d9f59799SBjoern A. Zeeb goto out; 2122d9f59799SBjoern A. Zeeb 2123d9f59799SBjoern A. Zeeb /* Nothing changed? panic? */ 2124d9f59799SBjoern A. Zeeb if (obss == ni) 2125d9f59799SBjoern A. Zeeb goto out; 2126d9f59799SBjoern A. Zeeb 2127d9f59799SBjoern A. Zeeb lsta = obss->ni_drv_data; 2128d9f59799SBjoern A. Zeeb obss->ni_drv_data = ni->ni_drv_data; 2129d9f59799SBjoern A. Zeeb ni->ni_drv_data = lsta; 2130ed3ef56bSBjoern A. Zeeb if (lsta != NULL) { 2131d9f59799SBjoern A. Zeeb lsta->ni = ni; 2132ed3ef56bSBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 2133ed3ef56bSBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->addr, lsta->ni->ni_macaddr); 2134ed3ef56bSBjoern A. Zeeb } 2135d9f59799SBjoern A. Zeeb lsta = obss->ni_drv_data; 2136ed3ef56bSBjoern A. Zeeb if (lsta != NULL) { 2137d9f59799SBjoern A. Zeeb lsta->ni = obss; 2138ed3ef56bSBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 2139ed3ef56bSBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->addr, lsta->ni->ni_macaddr); 2140ed3ef56bSBjoern A. Zeeb } 2141d9f59799SBjoern A. Zeeb 2142d9f59799SBjoern A. Zeeb out: 2143ed3ef56bSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 2144d9f59799SBjoern A. Zeeb return (lvif->iv_update_bss(vap, ni)); 2145d9f59799SBjoern A. Zeeb } 2146d9f59799SBjoern A. Zeeb 21474a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 21486b4cac81SBjoern A. Zeeb static int 21494a67f1dfSBjoern A. Zeeb lkpi_wme_update(struct lkpi_hw *lhw, struct ieee80211vap *vap, bool planned) 21506b4cac81SBjoern A. Zeeb { 21514a67f1dfSBjoern A. Zeeb struct ieee80211com *ic; 21526b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 21536b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 21546b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 21556b4cac81SBjoern A. Zeeb struct chanAccParams chp; 21566b4cac81SBjoern A. Zeeb struct wmeParams wmeparr[WME_NUM_AC]; 21576b4cac81SBjoern A. Zeeb struct ieee80211_tx_queue_params txqp; 21586b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 21596b4cac81SBjoern A. Zeeb int error; 21606b4cac81SBjoern A. Zeeb uint16_t ac; 21616b4cac81SBjoern A. Zeeb 21626b4cac81SBjoern A. Zeeb IMPROVE(); 21636b4cac81SBjoern A. Zeeb KASSERT(WME_NUM_AC == IEEE80211_NUM_ACS, ("%s: WME_NUM_AC %d != " 21646b4cac81SBjoern A. Zeeb "IEEE80211_NUM_ACS %d\n", __func__, WME_NUM_AC, IEEE80211_NUM_ACS)); 21656b4cac81SBjoern A. Zeeb 21666b4cac81SBjoern A. Zeeb if (vap == NULL) 21676b4cac81SBjoern A. Zeeb return (0); 21686b4cac81SBjoern A. Zeeb 21694a67f1dfSBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WME) == 0) 21704a67f1dfSBjoern A. Zeeb return (0); 21714a67f1dfSBjoern A. Zeeb 21726b4cac81SBjoern A. Zeeb if (lhw->ops->conf_tx == NULL) 21736b4cac81SBjoern A. Zeeb return (0); 21746b4cac81SBjoern A. Zeeb 21754a67f1dfSBjoern A. Zeeb if (!planned && (vap->iv_state != IEEE80211_S_RUN)) { 21764a67f1dfSBjoern A. Zeeb lhw->update_wme = true; 21774a67f1dfSBjoern A. Zeeb return (0); 21784a67f1dfSBjoern A. Zeeb } 21794a67f1dfSBjoern A. Zeeb lhw->update_wme = false; 21806b4cac81SBjoern A. Zeeb 21814a67f1dfSBjoern A. Zeeb ic = lhw->ic; 21826b4cac81SBjoern A. Zeeb ieee80211_wme_ic_getparams(ic, &chp); 21836b4cac81SBjoern A. Zeeb IEEE80211_LOCK(ic); 21846b4cac81SBjoern A. Zeeb for (ac = 0; ac < WME_NUM_AC; ac++) 21856b4cac81SBjoern A. Zeeb wmeparr[ac] = chp.cap_wmeParams[ac]; 21866b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(ic); 21876b4cac81SBjoern A. Zeeb 21884a67f1dfSBjoern A. Zeeb hw = LHW_TO_HW(lhw); 21894a67f1dfSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 21904a67f1dfSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 21914a67f1dfSBjoern A. Zeeb 21926b4cac81SBjoern A. Zeeb /* Configure tx queues (conf_tx) & send BSS_CHANGED_QOS. */ 21936b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 21946b4cac81SBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 21956b4cac81SBjoern A. Zeeb struct wmeParams *wmep; 21966b4cac81SBjoern A. Zeeb 21976b4cac81SBjoern A. Zeeb wmep = &wmeparr[ac]; 21986b4cac81SBjoern A. Zeeb bzero(&txqp, sizeof(txqp)); 21996b4cac81SBjoern A. Zeeb txqp.cw_min = wmep->wmep_logcwmin; 22006b4cac81SBjoern A. Zeeb txqp.cw_max = wmep->wmep_logcwmax; 22016b4cac81SBjoern A. Zeeb txqp.txop = wmep->wmep_txopLimit; 22026b4cac81SBjoern A. Zeeb txqp.aifs = wmep->wmep_aifsn; 220368541546SBjoern A. Zeeb error = lkpi_80211_mo_conf_tx(hw, vif, /* link_id */0, ac, &txqp); 22046b4cac81SBjoern A. Zeeb if (error != 0) 22053f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: conf_tx ac %u failed %d\n", 22066b4cac81SBjoern A. Zeeb __func__, ac, error); 22076b4cac81SBjoern A. Zeeb } 22086b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 22096b4cac81SBjoern A. Zeeb changed = BSS_CHANGED_QOS; 22104a67f1dfSBjoern A. Zeeb if (!planned) 22116b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 22124a67f1dfSBjoern A. Zeeb 22134a67f1dfSBjoern A. Zeeb return (changed); 22144a67f1dfSBjoern A. Zeeb } 22156b4cac81SBjoern A. Zeeb #endif 22166b4cac81SBjoern A. Zeeb 22174a67f1dfSBjoern A. Zeeb static int 22184a67f1dfSBjoern A. Zeeb lkpi_ic_wme_update(struct ieee80211com *ic) 22194a67f1dfSBjoern A. Zeeb { 22204a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 22214a67f1dfSBjoern A. Zeeb struct ieee80211vap *vap; 22224a67f1dfSBjoern A. Zeeb struct lkpi_hw *lhw; 22234a67f1dfSBjoern A. Zeeb 22244a67f1dfSBjoern A. Zeeb IMPROVE("Use the per-VAP callback in net80211."); 22254a67f1dfSBjoern A. Zeeb vap = TAILQ_FIRST(&ic->ic_vaps); 22264a67f1dfSBjoern A. Zeeb if (vap == NULL) 22276b4cac81SBjoern A. Zeeb return (0); 22284a67f1dfSBjoern A. Zeeb 22294a67f1dfSBjoern A. Zeeb lhw = ic->ic_softc; 22304a67f1dfSBjoern A. Zeeb 22314a67f1dfSBjoern A. Zeeb lkpi_wme_update(lhw, vap, false); 22324a67f1dfSBjoern A. Zeeb #endif 22334a67f1dfSBjoern A. Zeeb return (0); /* unused */ 22346b4cac81SBjoern A. Zeeb } 22356b4cac81SBjoern A. Zeeb 22366b4cac81SBjoern A. Zeeb static struct ieee80211vap * 22376b4cac81SBjoern A. Zeeb lkpi_ic_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], 22386b4cac81SBjoern A. Zeeb int unit, enum ieee80211_opmode opmode, int flags, 22396b4cac81SBjoern A. Zeeb const uint8_t bssid[IEEE80211_ADDR_LEN], 22406b4cac81SBjoern A. Zeeb const uint8_t mac[IEEE80211_ADDR_LEN]) 22416b4cac81SBjoern A. Zeeb { 22426b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 22436b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 22446b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 22456b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 22466b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 2247*a6042e17SBjoern A. Zeeb struct ieee80211_tx_queue_params txqp; 22486b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 22496b4cac81SBjoern A. Zeeb size_t len; 2250e3a0b120SBjoern A. Zeeb int error, i; 2251*a6042e17SBjoern A. Zeeb uint16_t ac; 22526b4cac81SBjoern A. Zeeb 22536b4cac81SBjoern A. Zeeb if (!TAILQ_EMPTY(&ic->ic_vaps)) /* 1 so far. Add <n> once this works. */ 22546b4cac81SBjoern A. Zeeb return (NULL); 22556b4cac81SBjoern A. Zeeb 22566b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 22576b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 22586b4cac81SBjoern A. Zeeb 22596b4cac81SBjoern A. Zeeb len = sizeof(*lvif); 22606b4cac81SBjoern A. Zeeb len += hw->vif_data_size; /* vif->drv_priv */ 22616b4cac81SBjoern A. Zeeb 22626b4cac81SBjoern A. Zeeb lvif = malloc(len, M_80211_VAP, M_WAITOK | M_ZERO); 22636b4cac81SBjoern A. Zeeb mtx_init(&lvif->mtx, "lvif", NULL, MTX_DEF); 22646b4cac81SBjoern A. Zeeb TAILQ_INIT(&lvif->lsta_head); 22656b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 22666b4cac81SBjoern A. Zeeb 22676b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 22686b4cac81SBjoern A. Zeeb memcpy(vif->addr, mac, IEEE80211_ADDR_LEN); 22696b4cac81SBjoern A. Zeeb vif->p2p = false; 22706b4cac81SBjoern A. Zeeb vif->probe_req_reg = false; 22716b4cac81SBjoern A. Zeeb vif->type = lkpi_opmode_to_vif_type(opmode); 22726b4cac81SBjoern A. Zeeb lvif->wdev.iftype = vif->type; 22736b4cac81SBjoern A. Zeeb /* Need to fill in other fields as well. */ 22746b4cac81SBjoern A. Zeeb IMPROVE(); 22756b4cac81SBjoern A. Zeeb 22766b4cac81SBjoern A. Zeeb /* XXX-BZ hardcoded for now! */ 22776b4cac81SBjoern A. Zeeb #if 1 22786b4cac81SBjoern A. Zeeb vif->chanctx_conf = NULL; 2279adff403fSBjoern A. Zeeb vif->bss_conf.vif = vif; 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; 2286616e1330SBjoern A. Zeeb vif->cfg.aid = 0; 2287616e1330SBjoern A. Zeeb vif->cfg.assoc = false; 2288616e1330SBjoern A. Zeeb vif->cfg.idle = true; 2289616e1330SBjoern A. Zeeb vif->cfg.ps = false; 2290caaa79c3SBjoern A. Zeeb /* 2291caaa79c3SBjoern A. Zeeb * We need to initialize it to something as the bss_info_changed call 2292caaa79c3SBjoern A. Zeeb * will try to copy from it in iwlwifi and NULL is a panic. 2293caaa79c3SBjoern A. Zeeb * We will set the proper one in scan_to_auth() before being assoc. 2294caaa79c3SBjoern A. Zeeb * NB: the logic there with using an array as bssid_override and checking 2295caaa79c3SBjoern A. Zeeb * for non-NULL later is flawed but in their workflow does not seem to 2296caaa79c3SBjoern A. Zeeb * matter. 2297caaa79c3SBjoern A. Zeeb */ 2298caaa79c3SBjoern A. Zeeb vif->bss_conf.bssid = zerobssid; 22996b4cac81SBjoern A. Zeeb #endif 23006b4cac81SBjoern A. Zeeb #if 0 23016b4cac81SBjoern A. Zeeb vif->bss_conf.dtim_period = 0; /* IEEE80211_DTIM_DEFAULT ; must stay 0. */ 23026b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(vif->bss_conf.bssid, bssid); 23036b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = ic->ic_bintval; 23046b4cac81SBjoern A. Zeeb /* iwlwifi bug. */ 23056b4cac81SBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16) 23066b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = 16; 23076b4cac81SBjoern A. Zeeb #endif 2308e3a0b120SBjoern A. Zeeb 2309e3a0b120SBjoern A. Zeeb /* Setup queue defaults; driver may override in (*add_interface). */ 2310e3a0b120SBjoern A. Zeeb for (i = 0; i < IEEE80211_NUM_ACS; i++) { 2311e3a0b120SBjoern A. Zeeb if (ieee80211_hw_check(hw, QUEUE_CONTROL)) 2312e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = IEEE80211_INVAL_HW_QUEUE; 2313e3a0b120SBjoern A. Zeeb else if (hw->queues >= IEEE80211_NUM_ACS) 2314e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = i; 2315e3a0b120SBjoern A. Zeeb else 2316e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = 0; 23170cbcfa19SBjoern A. Zeeb 23180cbcfa19SBjoern A. Zeeb /* Initialize the queue to running. Stopped? */ 23190cbcfa19SBjoern A. Zeeb lvif->hw_queue_stopped[i] = false; 2320e3a0b120SBjoern A. Zeeb } 2321e3a0b120SBjoern A. Zeeb vif->cab_queue = IEEE80211_INVAL_HW_QUEUE; 2322e3a0b120SBjoern A. Zeeb 23236b4cac81SBjoern A. Zeeb IMPROVE(); 23246b4cac81SBjoern A. Zeeb 23256b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_start(hw); 23266b4cac81SBjoern A. Zeeb if (error != 0) { 23273f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: failed to start hw: %d\n", __func__, error); 23286b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 23296b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 23306b4cac81SBjoern A. Zeeb return (NULL); 23316b4cac81SBjoern A. Zeeb } 23326b4cac81SBjoern A. Zeeb 23336b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_add_interface(hw, vif); 23346b4cac81SBjoern A. Zeeb if (error != 0) { 23356b4cac81SBjoern A. Zeeb IMPROVE(); /* XXX-BZ mo_stop()? */ 23363f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: failed to add interface: %d\n", __func__, error); 23376b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 23386b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 23396b4cac81SBjoern A. Zeeb return (NULL); 23406b4cac81SBjoern A. Zeeb } 23416b4cac81SBjoern A. Zeeb 23428891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 23436b4cac81SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lhw->lvif_head, lvif, lvif_entry); 23448891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 23456b4cac81SBjoern A. Zeeb 23466b4cac81SBjoern A. Zeeb /* Set bss_info. */ 23476b4cac81SBjoern A. Zeeb changed = 0; 23486b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 23496b4cac81SBjoern A. Zeeb 2350*a6042e17SBjoern A. Zeeb /* Configure tx queues (conf_tx), default WME & send BSS_CHANGED_QOS. */ 2351*a6042e17SBjoern A. Zeeb IMPROVE("Hardcoded values; to fix see 802.11-2016, 9.4.2.29 EDCA Parameter Set element"); 2352*a6042e17SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 2353*a6042e17SBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 2354*a6042e17SBjoern A. Zeeb 2355*a6042e17SBjoern A. Zeeb bzero(&txqp, sizeof(txqp)); 2356*a6042e17SBjoern A. Zeeb txqp.cw_min = 15; 2357*a6042e17SBjoern A. Zeeb txqp.cw_max = 1023; 2358*a6042e17SBjoern A. Zeeb txqp.txop = 0; 2359*a6042e17SBjoern A. Zeeb txqp.aifs = 2; 2360*a6042e17SBjoern A. Zeeb error = lkpi_80211_mo_conf_tx(hw, vif, /* link_id */0, ac, &txqp); 2361*a6042e17SBjoern A. Zeeb if (error != 0) 2362*a6042e17SBjoern A. Zeeb ic_printf(ic, "%s: conf_tx ac %u failed %d\n", 2363*a6042e17SBjoern A. Zeeb __func__, ac, error); 2364*a6042e17SBjoern A. Zeeb } 2365*a6042e17SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 2366*a6042e17SBjoern A. Zeeb changed = BSS_CHANGED_QOS; 2367*a6042e17SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 23686b4cac81SBjoern A. Zeeb 23696b4cac81SBjoern A. Zeeb /* Force MC init. */ 23706b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(ic, true); 23716b4cac81SBjoern A. Zeeb 23726b4cac81SBjoern A. Zeeb IMPROVE(); 23736b4cac81SBjoern A. Zeeb 23746b4cac81SBjoern A. Zeeb ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid); 23756b4cac81SBjoern A. Zeeb 23766b4cac81SBjoern A. Zeeb /* Override with LinuxKPI method so we can drive mac80211/cfg80211. */ 23776b4cac81SBjoern A. Zeeb lvif->iv_newstate = vap->iv_newstate; 23786b4cac81SBjoern A. Zeeb vap->iv_newstate = lkpi_iv_newstate; 2379d9f59799SBjoern A. Zeeb lvif->iv_update_bss = vap->iv_update_bss; 2380d9f59799SBjoern A. Zeeb vap->iv_update_bss = lkpi_iv_update_bss; 23816b4cac81SBjoern A. Zeeb 23826b4cac81SBjoern A. Zeeb /* Key management. */ 23836b4cac81SBjoern A. Zeeb if (lhw->ops->set_key != NULL) { 2384b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 23856b4cac81SBjoern A. Zeeb vap->iv_key_set = lkpi_iv_key_set; 23866b4cac81SBjoern A. Zeeb vap->iv_key_delete = lkpi_iv_key_delete; 23876b4cac81SBjoern A. Zeeb #endif 23886b4cac81SBjoern A. Zeeb } 23896b4cac81SBjoern A. Zeeb 23906b4cac81SBjoern A. Zeeb ieee80211_ratectl_init(vap); 23916b4cac81SBjoern A. Zeeb 23926b4cac81SBjoern A. Zeeb /* Complete setup. */ 23936b4cac81SBjoern A. Zeeb ieee80211_vap_attach(vap, ieee80211_media_change, 23946b4cac81SBjoern A. Zeeb ieee80211_media_status, mac); 23956b4cac81SBjoern A. Zeeb 23966b4cac81SBjoern A. Zeeb if (hw->max_listen_interval == 0) 23976b4cac81SBjoern A. Zeeb hw->max_listen_interval = 7 * (ic->ic_lintval / ic->ic_bintval); 23986b4cac81SBjoern A. Zeeb hw->conf.listen_interval = hw->max_listen_interval; 23996b4cac81SBjoern A. Zeeb ic->ic_set_channel(ic); 24006b4cac81SBjoern A. Zeeb 24016b4cac81SBjoern A. Zeeb /* XXX-BZ do we need to be able to update these? */ 24026b4cac81SBjoern A. Zeeb hw->wiphy->frag_threshold = vap->iv_fragthreshold; 24036b4cac81SBjoern A. Zeeb lkpi_80211_mo_set_frag_threshold(hw, vap->iv_fragthreshold); 24046b4cac81SBjoern A. Zeeb hw->wiphy->rts_threshold = vap->iv_rtsthreshold; 24056b4cac81SBjoern A. Zeeb lkpi_80211_mo_set_rts_threshold(hw, vap->iv_rtsthreshold); 24066b4cac81SBjoern A. Zeeb /* any others? */ 24076b4cac81SBjoern A. Zeeb IMPROVE(); 24086b4cac81SBjoern A. Zeeb 24096b4cac81SBjoern A. Zeeb return (vap); 24106b4cac81SBjoern A. Zeeb } 24116b4cac81SBjoern A. Zeeb 24124b0af114SBjoern A. Zeeb void 24134b0af114SBjoern A. Zeeb linuxkpi_ieee80211_unregister_hw(struct ieee80211_hw *hw) 24144b0af114SBjoern A. Zeeb { 24154b0af114SBjoern A. Zeeb 24164b0af114SBjoern A. Zeeb wiphy_unregister(hw->wiphy); 24174b0af114SBjoern A. Zeeb linuxkpi_ieee80211_ifdetach(hw); 24184b0af114SBjoern A. Zeeb 24194b0af114SBjoern A. Zeeb IMPROVE(); 24204b0af114SBjoern A. Zeeb } 24214b0af114SBjoern A. Zeeb 24224b0af114SBjoern A. Zeeb void 24234b0af114SBjoern A. Zeeb linuxkpi_ieee80211_restart_hw(struct ieee80211_hw *hw) 24244b0af114SBjoern A. Zeeb { 24254b0af114SBjoern A. Zeeb 24264b0af114SBjoern A. Zeeb TODO(); 24274b0af114SBjoern A. Zeeb } 24284b0af114SBjoern A. Zeeb 24296b4cac81SBjoern A. Zeeb static void 24306b4cac81SBjoern A. Zeeb lkpi_ic_vap_delete(struct ieee80211vap *vap) 24316b4cac81SBjoern A. Zeeb { 24326b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 24336b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 24346b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 24356b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 24366b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 24376b4cac81SBjoern A. Zeeb 24386b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 24396b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 24406b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 24416b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 24426b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 24436b4cac81SBjoern A. Zeeb 24448891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 24456b4cac81SBjoern A. Zeeb TAILQ_REMOVE(&lhw->lvif_head, lvif, lvif_entry); 24468891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 24476b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_interface(hw, vif); 24486b4cac81SBjoern A. Zeeb 24496b4cac81SBjoern A. Zeeb ieee80211_ratectl_deinit(vap); 24506b4cac81SBjoern A. Zeeb ieee80211_vap_detach(vap); 24516b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 24526b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 24536b4cac81SBjoern A. Zeeb } 24546b4cac81SBjoern A. Zeeb 24556b4cac81SBjoern A. Zeeb static void 24566b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast(struct ieee80211com *ic) 24576b4cac81SBjoern A. Zeeb { 24586b4cac81SBjoern A. Zeeb 24596b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(ic, false); 24606b4cac81SBjoern A. Zeeb TRACEOK(); 24616b4cac81SBjoern A. Zeeb } 24626b4cac81SBjoern A. Zeeb 24636b4cac81SBjoern A. Zeeb static void 24646b4cac81SBjoern A. Zeeb lkpi_ic_update_promisc(struct ieee80211com *ic) 24656b4cac81SBjoern A. Zeeb { 24666b4cac81SBjoern A. Zeeb 24676b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 24686b4cac81SBjoern A. Zeeb } 24696b4cac81SBjoern A. Zeeb 24706b4cac81SBjoern A. Zeeb static void 24716b4cac81SBjoern A. Zeeb lkpi_ic_update_chw(struct ieee80211com *ic) 24726b4cac81SBjoern A. Zeeb { 24736b4cac81SBjoern A. Zeeb 24746b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 24756b4cac81SBjoern A. Zeeb } 24766b4cac81SBjoern A. Zeeb 24776b4cac81SBjoern A. Zeeb /* Start / stop device. */ 24786b4cac81SBjoern A. Zeeb static void 24796b4cac81SBjoern A. Zeeb lkpi_ic_parent(struct ieee80211com *ic) 24806b4cac81SBjoern A. Zeeb { 24816b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 24828d58a057SBjoern A. Zeeb #ifdef HW_START_STOP 24836b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 24846b4cac81SBjoern A. Zeeb int error; 24858d58a057SBjoern A. Zeeb #endif 24866b4cac81SBjoern A. Zeeb bool start_all; 24876b4cac81SBjoern A. Zeeb 24886b4cac81SBjoern A. Zeeb IMPROVE(); 24896b4cac81SBjoern A. Zeeb 24906b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 24918d58a057SBjoern A. Zeeb #ifdef HW_START_STOP 24926b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 24938d58a057SBjoern A. Zeeb #endif 24946b4cac81SBjoern A. Zeeb start_all = false; 24956b4cac81SBjoern A. Zeeb 24968ac540d3SBjoern A. Zeeb /* IEEE80211_UNLOCK(ic); */ 24978ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 24986b4cac81SBjoern A. Zeeb if (ic->ic_nrunning > 0) { 24998d58a057SBjoern A. Zeeb #ifdef HW_START_STOP 25006b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_start(hw); 25016b4cac81SBjoern A. Zeeb if (error == 0) 25028d58a057SBjoern A. Zeeb #endif 25036b4cac81SBjoern A. Zeeb start_all = true; 25046b4cac81SBjoern A. Zeeb } else { 25058d58a057SBjoern A. Zeeb #ifdef HW_START_STOP 25066b4cac81SBjoern A. Zeeb lkpi_80211_mo_stop(hw); 25078d58a057SBjoern A. Zeeb #endif 25086b4cac81SBjoern A. Zeeb } 25098ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 25108ac540d3SBjoern A. Zeeb /* IEEE80211_LOCK(ic); */ 25116b4cac81SBjoern A. Zeeb 25126b4cac81SBjoern A. Zeeb if (start_all) 25136b4cac81SBjoern A. Zeeb ieee80211_start_all(ic); 25146b4cac81SBjoern A. Zeeb } 25156b4cac81SBjoern A. Zeeb 25166b4cac81SBjoern A. Zeeb bool 25176b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_is_ie_id_in_ie_buf(const u8 ie, const u8 *ie_ids, 25186b4cac81SBjoern A. Zeeb size_t ie_ids_len) 25196b4cac81SBjoern A. Zeeb { 25206b4cac81SBjoern A. Zeeb int i; 25216b4cac81SBjoern A. Zeeb 25226b4cac81SBjoern A. Zeeb for (i = 0; i < ie_ids_len; i++) { 25236b4cac81SBjoern A. Zeeb if (ie == *ie_ids) 25246b4cac81SBjoern A. Zeeb return (true); 25256b4cac81SBjoern A. Zeeb } 25266b4cac81SBjoern A. Zeeb 25276b4cac81SBjoern A. Zeeb return (false); 25286b4cac81SBjoern A. Zeeb } 25296b4cac81SBjoern A. Zeeb 25306b4cac81SBjoern A. Zeeb /* Return true if skipped; false if error. */ 25316b4cac81SBjoern A. Zeeb bool 25326b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ie_advance(size_t *xp, const u8 *ies, size_t ies_len) 25336b4cac81SBjoern A. Zeeb { 25346b4cac81SBjoern A. Zeeb size_t x; 25356b4cac81SBjoern A. Zeeb uint8_t l; 25366b4cac81SBjoern A. Zeeb 25376b4cac81SBjoern A. Zeeb x = *xp; 25386b4cac81SBjoern A. Zeeb 25396b4cac81SBjoern A. Zeeb KASSERT(x < ies_len, ("%s: x %zu ies_len %zu ies %p\n", 25406b4cac81SBjoern A. Zeeb __func__, x, ies_len, ies)); 25416b4cac81SBjoern A. Zeeb l = ies[x + 1]; 25426b4cac81SBjoern A. Zeeb x += 2 + l; 25436b4cac81SBjoern A. Zeeb 25446b4cac81SBjoern A. Zeeb if (x > ies_len) 25456b4cac81SBjoern A. Zeeb return (false); 25466b4cac81SBjoern A. Zeeb 25476b4cac81SBjoern A. Zeeb *xp = x; 25486b4cac81SBjoern A. Zeeb return (true); 25496b4cac81SBjoern A. Zeeb } 25506b4cac81SBjoern A. Zeeb 2551d9945d78SBjoern A. Zeeb static uint8_t * 2552d9945d78SBjoern A. Zeeb lkpi_scan_ies_add(uint8_t *p, struct ieee80211_scan_ies *scan_ies, 2553d9945d78SBjoern A. Zeeb uint32_t band_mask, struct ieee80211vap *vap, struct ieee80211_hw *hw) 25546b4cac81SBjoern A. Zeeb { 2555d9945d78SBjoern A. Zeeb struct ieee80211_supported_band *supband; 2556d9945d78SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 25573dd98026SBjoern A. Zeeb struct ieee80211com *ic; 2558d9945d78SBjoern A. Zeeb const struct ieee80211_channel *chan; 2559d9945d78SBjoern A. Zeeb const struct ieee80211_rateset *rs; 2560d9945d78SBjoern A. Zeeb uint8_t *pb; 2561d9945d78SBjoern A. Zeeb int band, i; 25626b4cac81SBjoern A. Zeeb 25633dd98026SBjoern A. Zeeb ic = vap->iv_ic; 2564d9945d78SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 2565d9945d78SBjoern A. Zeeb if ((band_mask & (1 << band)) == 0) 2566d9945d78SBjoern A. Zeeb continue; 2567d9945d78SBjoern A. Zeeb 2568d9945d78SBjoern A. Zeeb supband = hw->wiphy->bands[band]; 2569d9945d78SBjoern A. Zeeb /* 2570d9945d78SBjoern A. Zeeb * This should not happen; 2571d9945d78SBjoern A. Zeeb * band_mask is a bitmask of valid bands to scan on. 2572d9945d78SBjoern A. Zeeb */ 2573d9945d78SBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 2574d9945d78SBjoern A. Zeeb continue; 2575d9945d78SBjoern A. Zeeb 2576d9945d78SBjoern A. Zeeb /* Find a first channel to get the mode and rates from. */ 2577d9945d78SBjoern A. Zeeb channels = supband->channels; 2578d9945d78SBjoern A. Zeeb chan = NULL; 2579d9945d78SBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 2580d9945d78SBjoern A. Zeeb 2581d9945d78SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) 2582d9945d78SBjoern A. Zeeb continue; 2583d9945d78SBjoern A. Zeeb 25843dd98026SBjoern A. Zeeb chan = ieee80211_find_channel(ic, 2585d9945d78SBjoern A. Zeeb channels[i].center_freq, 0); 2586d9945d78SBjoern A. Zeeb if (chan != NULL) 2587d9945d78SBjoern A. Zeeb break; 2588d9945d78SBjoern A. Zeeb } 2589d9945d78SBjoern A. Zeeb 2590d9945d78SBjoern A. Zeeb /* This really should not happen. */ 2591d9945d78SBjoern A. Zeeb if (chan == NULL) 2592d9945d78SBjoern A. Zeeb continue; 2593d9945d78SBjoern A. Zeeb 2594d9945d78SBjoern A. Zeeb pb = p; 25953dd98026SBjoern A. Zeeb rs = ieee80211_get_suprates(ic, chan); /* calls chan2mode */ 2596d9945d78SBjoern A. Zeeb p = ieee80211_add_rates(p, rs); 2597d9945d78SBjoern A. Zeeb p = ieee80211_add_xrates(p, rs); 2598d9945d78SBjoern A. Zeeb 25993dd98026SBjoern A. Zeeb #if defined(LKPI_80211_HT) 26003dd98026SBjoern A. Zeeb if ((vap->iv_flags_ht & IEEE80211_FHT_HT) != 0) { 26013dd98026SBjoern A. Zeeb struct ieee80211_channel *c; 26023dd98026SBjoern A. Zeeb 26033dd98026SBjoern A. Zeeb c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan, 26043dd98026SBjoern A. Zeeb vap->iv_flags_ht); 26053dd98026SBjoern A. Zeeb p = ieee80211_add_htcap_ch(p, vap, c); 26063dd98026SBjoern A. Zeeb } 26073dd98026SBjoern A. Zeeb #endif 26083dd98026SBjoern A. Zeeb #if defined(LKPI_80211_VHT) 26093dd98026SBjoern A. Zeeb if ((vap->iv_vht_flags & IEEE80211_FVHT_VHT) != 0) { 26103dd98026SBjoern A. Zeeb struct ieee80211_channel *c; 26113dd98026SBjoern A. Zeeb 26123dd98026SBjoern A. Zeeb c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan, 26133dd98026SBjoern A. Zeeb vap->iv_flags_ht); 26143dd98026SBjoern A. Zeeb c = ieee80211_vht_adjust_channel(ic, c, 26153dd98026SBjoern A. Zeeb vap->iv_vht_flags); 26163dd98026SBjoern A. Zeeb p = ieee80211_add_vhtcap_ch(p, vap, c); 26173dd98026SBjoern A. Zeeb } 26183dd98026SBjoern A. Zeeb #endif 26193dd98026SBjoern A. Zeeb 2620d9945d78SBjoern A. Zeeb scan_ies->ies[band] = pb; 2621d9945d78SBjoern A. Zeeb scan_ies->len[band] = p - pb; 2622d9945d78SBjoern A. Zeeb } 2623d9945d78SBjoern A. Zeeb 2624d9945d78SBjoern A. Zeeb /* Add common_ies */ 2625d9945d78SBjoern A. Zeeb pb = p; 2626d9945d78SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WPA1) != 0 && 2627d9945d78SBjoern A. Zeeb vap->iv_wpa_ie != NULL) { 2628d9945d78SBjoern A. Zeeb memcpy(p, vap->iv_wpa_ie, 2 + vap->iv_wpa_ie[1]); 2629d9945d78SBjoern A. Zeeb p += 2 + vap->iv_wpa_ie[1]; 2630d9945d78SBjoern A. Zeeb } 2631d9945d78SBjoern A. Zeeb if (vap->iv_appie_probereq != NULL) { 2632d9945d78SBjoern A. Zeeb memcpy(p, vap->iv_appie_probereq->ie_data, 2633d9945d78SBjoern A. Zeeb vap->iv_appie_probereq->ie_len); 2634d9945d78SBjoern A. Zeeb p += vap->iv_appie_probereq->ie_len; 2635d9945d78SBjoern A. Zeeb } 2636d9945d78SBjoern A. Zeeb scan_ies->common_ies = pb; 2637d9945d78SBjoern A. Zeeb scan_ies->common_ie_len = p - pb; 2638d9945d78SBjoern A. Zeeb 2639d9945d78SBjoern A. Zeeb return (p); 26406b4cac81SBjoern A. Zeeb } 26416b4cac81SBjoern A. Zeeb 26426b4cac81SBjoern A. Zeeb static void 26436b4cac81SBjoern A. Zeeb lkpi_ic_scan_start(struct ieee80211com *ic) 26446b4cac81SBjoern A. Zeeb { 26456b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 26466b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 26476b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 26486b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 26496b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 26506b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 26516b4cac81SBjoern A. Zeeb int error; 26528ac540d3SBjoern A. Zeeb bool is_hw_scan; 26536b4cac81SBjoern A. Zeeb 26546b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 26558ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 2656a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) { 26576b4cac81SBjoern A. Zeeb /* A scan is still running. */ 26588ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 26596b4cac81SBjoern A. Zeeb return; 26606b4cac81SBjoern A. Zeeb } 26618ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 26628ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 26636b4cac81SBjoern A. Zeeb 26646b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 26656b4cac81SBjoern A. Zeeb vap = ss->ss_vap; 26666b4cac81SBjoern A. Zeeb if (vap->iv_state != IEEE80211_S_SCAN) { 2667d3ef7fb4SBjoern A. Zeeb IMPROVE("We need to be able to scan if not in S_SCAN"); 26686b4cac81SBjoern A. Zeeb return; 26696b4cac81SBjoern A. Zeeb } 26706b4cac81SBjoern A. Zeeb 26716b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 26728ac540d3SBjoern A. Zeeb if (!is_hw_scan) { 2673a486fbbdSBjoern A. Zeeb /* If hw_scan is cleared clear FEXT_SCAN_OFFLOAD too. */ 2674a486fbbdSBjoern A. Zeeb vap->iv_flags_ext &= ~IEEE80211_FEXT_SCAN_OFFLOAD; 2675d3ef7fb4SBjoern A. Zeeb sw_scan: 26766b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 26776b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 2678086be6a8SBjoern A. Zeeb 2679086be6a8SBjoern A. Zeeb if (vap->iv_state == IEEE80211_S_SCAN) 2680086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, false); 2681086be6a8SBjoern A. Zeeb 26826b4cac81SBjoern A. Zeeb lkpi_80211_mo_sw_scan_start(hw, vif, vif->addr); 26836b4cac81SBjoern A. Zeeb /* net80211::scan_start() handled PS for us. */ 26846b4cac81SBjoern A. Zeeb IMPROVE(); 26856b4cac81SBjoern A. Zeeb /* XXX Also means it is too late to flush queues? 26866b4cac81SBjoern A. Zeeb * need to check iv_sta_ps or overload? */ 26876b4cac81SBjoern A. Zeeb /* XXX want to adjust ss end time/ maxdwell? */ 26886b4cac81SBjoern A. Zeeb 26896b4cac81SBjoern A. Zeeb } else { 26906b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 26916b4cac81SBjoern A. Zeeb struct ieee80211_scan_request *hw_req; 26926b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *lc, **cpp; 26936b4cac81SBjoern A. Zeeb struct cfg80211_ssid *ssids; 26946b4cac81SBjoern A. Zeeb struct cfg80211_scan_6ghz_params *s6gp; 26956b4cac81SBjoern A. Zeeb size_t chan_len, nchan, ssids_len, s6ghzlen; 2696d9945d78SBjoern A. Zeeb int band, i, ssid_count, common_ie_len; 2697d9945d78SBjoern A. Zeeb uint32_t band_mask; 2698d9945d78SBjoern A. Zeeb uint8_t *ie, *ieend; 26993206587aSBjoern A. Zeeb bool running; 2700d9945d78SBjoern A. Zeeb 2701d9945d78SBjoern A. Zeeb ssid_count = min(ss->ss_nssid, hw->wiphy->max_scan_ssids); 2702d9945d78SBjoern A. Zeeb ssids_len = ssid_count * sizeof(*ssids); 27036b4cac81SBjoern A. Zeeb s6ghzlen = 0 * (sizeof(*s6gp)); /* XXX-BZ */ 27046b4cac81SBjoern A. Zeeb 2705d9945d78SBjoern A. Zeeb band_mask = 0; 27066b4cac81SBjoern A. Zeeb nchan = 0; 2707d9945d78SBjoern A. Zeeb for (i = ss->ss_next; i < ss->ss_last; i++) { 27086b4cac81SBjoern A. Zeeb nchan++; 2709d9945d78SBjoern A. Zeeb band = lkpi_net80211_chan_to_nl80211_band( 2710d9945d78SBjoern A. Zeeb ss->ss_chans[ss->ss_next + i]); 2711d9945d78SBjoern A. Zeeb band_mask |= (1 << band); 2712d9945d78SBjoern A. Zeeb } 27133206587aSBjoern A. Zeeb 27143206587aSBjoern A. Zeeb if (!ieee80211_hw_check(hw, SINGLE_SCAN_ON_ALL_BANDS)) { 27153206587aSBjoern A. Zeeb IMPROVE("individual band scans not yet supported, only scanning first band"); 27163206587aSBjoern A. Zeeb /* In theory net80211 should drive this. */ 27173206587aSBjoern A. Zeeb /* Probably we need to add local logic for now; 27183206587aSBjoern A. Zeeb * need to deal with scan_complete 27193206587aSBjoern A. Zeeb * and cancel_scan and keep local state. 27203206587aSBjoern A. Zeeb * Also cut the nchan down above. 27213206587aSBjoern A. Zeeb */ 27223206587aSBjoern A. Zeeb /* XXX-BZ ath10k does not set this but still does it? &$%^ */ 27233206587aSBjoern A. Zeeb } 27243206587aSBjoern A. Zeeb 27256b4cac81SBjoern A. Zeeb chan_len = nchan * (sizeof(lc) + sizeof(*lc)); 27266b4cac81SBjoern A. Zeeb 2727d9945d78SBjoern A. Zeeb common_ie_len = 0; 2728d9945d78SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WPA1) != 0 && 2729d9945d78SBjoern A. Zeeb vap->iv_wpa_ie != NULL) 2730d9945d78SBjoern A. Zeeb common_ie_len += vap->iv_wpa_ie[1]; 2731d9945d78SBjoern A. Zeeb if (vap->iv_appie_probereq != NULL) 2732d9945d78SBjoern A. Zeeb common_ie_len += vap->iv_appie_probereq->ie_len; 2733d9945d78SBjoern A. Zeeb 2734d9945d78SBjoern A. Zeeb /* We would love to check this at an earlier stage... */ 2735d9945d78SBjoern A. Zeeb if (common_ie_len > hw->wiphy->max_scan_ie_len) { 2736d9945d78SBjoern A. Zeeb ic_printf(ic, "WARNING: %s: common_ie_len %d > " 2737d9945d78SBjoern A. Zeeb "wiphy->max_scan_ie_len %d\n", __func__, 2738d9945d78SBjoern A. Zeeb common_ie_len, hw->wiphy->max_scan_ie_len); 2739d9945d78SBjoern A. Zeeb } 2740d9945d78SBjoern A. Zeeb 27413206587aSBjoern A. Zeeb hw_req = malloc(sizeof(*hw_req) + ssids_len + 2742d9945d78SBjoern A. Zeeb s6ghzlen + chan_len + lhw->supbands * lhw->scan_ie_len + 2743d9945d78SBjoern A. Zeeb common_ie_len, M_LKPI80211, M_WAITOK | M_ZERO); 27446b4cac81SBjoern A. Zeeb 27456b4cac81SBjoern A. Zeeb hw_req->req.flags = 0; /* XXX ??? */ 27466b4cac81SBjoern A. Zeeb /* hw_req->req.wdev */ 27476b4cac81SBjoern A. Zeeb hw_req->req.wiphy = hw->wiphy; 27486b4cac81SBjoern A. Zeeb hw_req->req.no_cck = false; /* XXX */ 27496b4cac81SBjoern A. Zeeb #if 0 27506b4cac81SBjoern A. Zeeb /* This seems to pessimise default scanning behaviour. */ 27516b4cac81SBjoern A. Zeeb hw_req->req.duration_mandatory = TICKS_2_USEC(ss->ss_mindwell); 27526b4cac81SBjoern A. Zeeb hw_req->req.duration = TICKS_2_USEC(ss->ss_maxdwell); 27536b4cac81SBjoern A. Zeeb #endif 27546b4cac81SBjoern A. Zeeb #ifdef __notyet__ 27556b4cac81SBjoern A. Zeeb hw_req->req.flags |= NL80211_SCAN_FLAG_RANDOM_ADDR; 27566b4cac81SBjoern A. Zeeb memcpy(hw_req->req.mac_addr, xxx, IEEE80211_ADDR_LEN); 27576b4cac81SBjoern A. Zeeb memset(hw_req->req.mac_addr_mask, 0xxx, IEEE80211_ADDR_LEN); 27586b4cac81SBjoern A. Zeeb #endif 2759e1e90be0SBjoern A. Zeeb eth_broadcast_addr(hw_req->req.bssid); 27606b4cac81SBjoern A. Zeeb 27616b4cac81SBjoern A. Zeeb hw_req->req.n_channels = nchan; 27626b4cac81SBjoern A. Zeeb cpp = (struct linuxkpi_ieee80211_channel **)(hw_req + 1); 27636b4cac81SBjoern A. Zeeb lc = (struct linuxkpi_ieee80211_channel *)(cpp + nchan); 27646b4cac81SBjoern A. Zeeb for (i = 0; i < nchan; i++) { 27656b4cac81SBjoern A. Zeeb *(cpp + i) = 27666b4cac81SBjoern A. Zeeb (struct linuxkpi_ieee80211_channel *)(lc + i); 27676b4cac81SBjoern A. Zeeb } 27686b4cac81SBjoern A. Zeeb for (i = 0; i < nchan; i++) { 27696b4cac81SBjoern A. Zeeb c = ss->ss_chans[ss->ss_next + i]; 27706b4cac81SBjoern A. Zeeb 27716b4cac81SBjoern A. Zeeb lc->hw_value = c->ic_ieee; 27723206587aSBjoern A. Zeeb lc->center_freq = c->ic_freq; /* XXX */ 27736b4cac81SBjoern A. Zeeb /* lc->flags */ 27746b4cac81SBjoern A. Zeeb lc->band = lkpi_net80211_chan_to_nl80211_band(c); 27756b4cac81SBjoern A. Zeeb lc->max_power = c->ic_maxpower; 27766b4cac81SBjoern A. Zeeb /* lc-> ... */ 27776b4cac81SBjoern A. Zeeb lc++; 27786b4cac81SBjoern A. Zeeb } 27796b4cac81SBjoern A. Zeeb 2780d9945d78SBjoern A. Zeeb hw_req->req.n_ssids = ssid_count; 27816b4cac81SBjoern A. Zeeb if (hw_req->req.n_ssids > 0) { 27826b4cac81SBjoern A. Zeeb ssids = (struct cfg80211_ssid *)lc; 27836b4cac81SBjoern A. Zeeb hw_req->req.ssids = ssids; 2784d9945d78SBjoern A. Zeeb for (i = 0; i < ssid_count; i++) { 27856b4cac81SBjoern A. Zeeb ssids->ssid_len = ss->ss_ssid[i].len; 27866b4cac81SBjoern A. Zeeb memcpy(ssids->ssid, ss->ss_ssid[i].ssid, 27876b4cac81SBjoern A. Zeeb ss->ss_ssid[i].len); 27886b4cac81SBjoern A. Zeeb ssids++; 27896b4cac81SBjoern A. Zeeb } 27906b4cac81SBjoern A. Zeeb s6gp = (struct cfg80211_scan_6ghz_params *)ssids; 27916b4cac81SBjoern A. Zeeb } else { 27926b4cac81SBjoern A. Zeeb s6gp = (struct cfg80211_scan_6ghz_params *)lc; 27936b4cac81SBjoern A. Zeeb } 27946b4cac81SBjoern A. Zeeb 27956b4cac81SBjoern A. Zeeb /* 6GHz one day. */ 27966b4cac81SBjoern A. Zeeb hw_req->req.n_6ghz_params = 0; 27976b4cac81SBjoern A. Zeeb hw_req->req.scan_6ghz_params = NULL; 27986b4cac81SBjoern A. Zeeb hw_req->req.scan_6ghz = false; /* Weird boolean; not what you think. */ 27996b4cac81SBjoern A. Zeeb /* s6gp->... */ 28006b4cac81SBjoern A. Zeeb 2801d9945d78SBjoern A. Zeeb ie = ieend = (uint8_t *)s6gp; 2802d9945d78SBjoern A. Zeeb /* Copy per-band IEs, copy common IEs */ 2803d9945d78SBjoern A. Zeeb ieend = lkpi_scan_ies_add(ie, &hw_req->ies, band_mask, vap, hw); 2804d9945d78SBjoern A. Zeeb hw_req->req.ie = ie; 2805d9945d78SBjoern A. Zeeb hw_req->req.ie_len = ieend - ie; 2806d9945d78SBjoern A. Zeeb 28076b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 28086b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 28093206587aSBjoern A. Zeeb 28103206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 28113206587aSBjoern A. Zeeb /* Re-check under lock. */ 28123206587aSBjoern A. Zeeb running = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0; 28133206587aSBjoern A. Zeeb if (!running) { 28143206587aSBjoern A. Zeeb KASSERT(lhw->hw_req == NULL, ("%s: ic %p lhw %p hw_req %p " 28153206587aSBjoern A. Zeeb "!= NULL\n", __func__, ic, lhw, lhw->hw_req)); 28163206587aSBjoern A. Zeeb 28173206587aSBjoern A. Zeeb lhw->scan_flags |= LKPI_LHW_SCAN_RUNNING; 28183206587aSBjoern A. Zeeb lhw->hw_req = hw_req; 28193206587aSBjoern A. Zeeb } 28203206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 28213206587aSBjoern A. Zeeb if (running) { 28223206587aSBjoern A. Zeeb free(hw_req, M_LKPI80211); 28233206587aSBjoern A. Zeeb return; 28243206587aSBjoern A. Zeeb } 28253206587aSBjoern A. Zeeb 28266b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_hw_scan(hw, vif, hw_req); 28276b4cac81SBjoern A. Zeeb if (error != 0) { 2828d9945d78SBjoern A. Zeeb ieee80211_cancel_scan(vap); 2829d9945d78SBjoern A. Zeeb 28303206587aSBjoern A. Zeeb /* 28313206587aSBjoern A. Zeeb * ieee80211_scan_completed must be called in either 28323206587aSBjoern A. Zeeb * case of error or none. So let the free happen there 28333206587aSBjoern A. Zeeb * and only there. 28343206587aSBjoern A. Zeeb * That would be fine in theory but in practice drivers 28353206587aSBjoern A. Zeeb * behave differently: 28363206587aSBjoern A. Zeeb * ath10k does not return hw_scan until after scan_complete 28373206587aSBjoern A. Zeeb * and can then still return an error. 28383206587aSBjoern A. Zeeb * rtw88 can return 1 or -EBUSY without scan_complete 28393206587aSBjoern A. Zeeb * iwlwifi can return various errors before scan starts 28403206587aSBjoern A. Zeeb * ... 28413206587aSBjoern A. Zeeb * So we cannot rely on that behaviour and have to check 28423206587aSBjoern A. Zeeb * and balance between both code paths. 28433206587aSBjoern A. Zeeb */ 28443206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 28453206587aSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) { 28463206587aSBjoern A. Zeeb free(lhw->hw_req, M_LKPI80211); 28476b4cac81SBjoern A. Zeeb lhw->hw_req = NULL; 28483206587aSBjoern A. Zeeb lhw->scan_flags &= ~LKPI_LHW_SCAN_RUNNING; 28493206587aSBjoern A. Zeeb } 28503206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 2851d3ef7fb4SBjoern A. Zeeb 2852d3ef7fb4SBjoern A. Zeeb /* 2853d3ef7fb4SBjoern A. Zeeb * XXX-SIGH magic number. 2854d3ef7fb4SBjoern A. Zeeb * rtw88 has a magic "return 1" if offloading scan is 2855d3ef7fb4SBjoern A. Zeeb * not possible. Fall back to sw scan in that case. 2856d3ef7fb4SBjoern A. Zeeb */ 2857196cfd0bSBjoern A. Zeeb if (error == 1) { 28588ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 2859a486fbbdSBjoern A. Zeeb lhw->scan_flags &= ~LKPI_LHW_SCAN_HW; 28608ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 28613206587aSBjoern A. Zeeb /* 28623206587aSBjoern A. Zeeb * XXX If we clear this now and later a driver 28633206587aSBjoern A. Zeeb * thinks it * can do a hw_scan again, we will 28643206587aSBjoern A. Zeeb * currently not re-enable it? 28653206587aSBjoern A. Zeeb */ 28663206587aSBjoern A. Zeeb vap->iv_flags_ext &= ~IEEE80211_FEXT_SCAN_OFFLOAD; 2867196cfd0bSBjoern A. Zeeb ieee80211_start_scan(vap, 2868196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_ACTIVE | 2869196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_NOPICK | 2870196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_ONCE, 2871196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_FOREVER, 2872196cfd0bSBjoern A. Zeeb ss->ss_mindwell ? ss->ss_mindwell : msecs_to_ticks(20), 2873196cfd0bSBjoern A. Zeeb ss->ss_maxdwell ? ss->ss_maxdwell : msecs_to_ticks(200), 2874196cfd0bSBjoern A. Zeeb vap->iv_des_nssid, vap->iv_des_ssid); 2875d3ef7fb4SBjoern A. Zeeb goto sw_scan; 2876196cfd0bSBjoern A. Zeeb } 2877d3ef7fb4SBjoern A. Zeeb 2878d3ef7fb4SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: hw_scan returned %d\n", 2879d3ef7fb4SBjoern A. Zeeb __func__, error); 28806b4cac81SBjoern A. Zeeb } 28816b4cac81SBjoern A. Zeeb } 28826b4cac81SBjoern A. Zeeb } 28836b4cac81SBjoern A. Zeeb 28846b4cac81SBjoern A. Zeeb static void 28856b4cac81SBjoern A. Zeeb lkpi_ic_scan_end(struct ieee80211com *ic) 28866b4cac81SBjoern A. Zeeb { 28876b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 28888ac540d3SBjoern A. Zeeb bool is_hw_scan; 28896b4cac81SBjoern A. Zeeb 28906b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 28918ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 2892a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) == 0) { 28938ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 28946b4cac81SBjoern A. Zeeb return; 28956b4cac81SBjoern A. Zeeb } 28968ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 28978ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 28986b4cac81SBjoern A. Zeeb 28998ac540d3SBjoern A. Zeeb if (!is_hw_scan) { 2900a486fbbdSBjoern A. Zeeb struct ieee80211_scan_state *ss; 2901a486fbbdSBjoern A. Zeeb struct ieee80211vap *vap; 29026b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 29036b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 29046b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 29056b4cac81SBjoern A. Zeeb 2906a486fbbdSBjoern A. Zeeb ss = ic->ic_scan; 2907a486fbbdSBjoern A. Zeeb vap = ss->ss_vap; 29086b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 29096b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 29106b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 2911a486fbbdSBjoern A. Zeeb 29126b4cac81SBjoern A. Zeeb lkpi_80211_mo_sw_scan_complete(hw, vif); 29136b4cac81SBjoern A. Zeeb 29146b4cac81SBjoern A. Zeeb /* Send PS to stop buffering if n80211 does not for us? */ 2915086be6a8SBjoern A. Zeeb 2916086be6a8SBjoern A. Zeeb if (vap->iv_state == IEEE80211_S_SCAN) 2917086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true); 29186b4cac81SBjoern A. Zeeb } 29196b4cac81SBjoern A. Zeeb } 29206b4cac81SBjoern A. Zeeb 29216b4cac81SBjoern A. Zeeb static void 2922a486fbbdSBjoern A. Zeeb lkpi_ic_scan_curchan(struct ieee80211_scan_state *ss, 2923a486fbbdSBjoern A. Zeeb unsigned long maxdwell) 2924a486fbbdSBjoern A. Zeeb { 2925a486fbbdSBjoern A. Zeeb struct lkpi_hw *lhw; 29268ac540d3SBjoern A. Zeeb bool is_hw_scan; 2927a486fbbdSBjoern A. Zeeb 2928a486fbbdSBjoern A. Zeeb lhw = ss->ss_ic->ic_softc; 29298ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 29308ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 29318ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 29328ac540d3SBjoern A. Zeeb if (!is_hw_scan) 2933a486fbbdSBjoern A. Zeeb lhw->ic_scan_curchan(ss, maxdwell); 2934a486fbbdSBjoern A. Zeeb } 2935a486fbbdSBjoern A. Zeeb 2936a486fbbdSBjoern A. Zeeb static void 2937a486fbbdSBjoern A. Zeeb lkpi_ic_scan_mindwell(struct ieee80211_scan_state *ss) 2938a486fbbdSBjoern A. Zeeb { 2939a486fbbdSBjoern A. Zeeb struct lkpi_hw *lhw; 29408ac540d3SBjoern A. Zeeb bool is_hw_scan; 2941a486fbbdSBjoern A. Zeeb 2942a486fbbdSBjoern A. Zeeb lhw = ss->ss_ic->ic_softc; 29438ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 29448ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 29458ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 29468ac540d3SBjoern A. Zeeb if (!is_hw_scan) 2947a486fbbdSBjoern A. Zeeb lhw->ic_scan_mindwell(ss); 2948a486fbbdSBjoern A. Zeeb } 2949a486fbbdSBjoern A. Zeeb 2950a486fbbdSBjoern A. Zeeb static void 29516b4cac81SBjoern A. Zeeb lkpi_ic_set_channel(struct ieee80211com *ic) 29526b4cac81SBjoern A. Zeeb { 29536b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 29546b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 2955b2cf3c21SBjoern A. Zeeb struct ieee80211_channel *c; 2956b2cf3c21SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 29576b4cac81SBjoern A. Zeeb int error; 29588ac540d3SBjoern A. Zeeb bool hw_scan_running; 29596b4cac81SBjoern A. Zeeb 29606b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 2961b2cf3c21SBjoern A. Zeeb 2962b2cf3c21SBjoern A. Zeeb /* If we do not support (*config)() save us the work. */ 2963b2cf3c21SBjoern A. Zeeb if (lhw->ops->config == NULL) 29646b4cac81SBjoern A. Zeeb return; 29656b4cac81SBjoern A. Zeeb 2966a486fbbdSBjoern A. Zeeb /* If we have a hw_scan running do not switch channels. */ 29678ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 29688ac540d3SBjoern A. Zeeb hw_scan_running = 29698ac540d3SBjoern A. Zeeb (lhw->scan_flags & (LKPI_LHW_SCAN_RUNNING|LKPI_LHW_SCAN_HW)) == 29708ac540d3SBjoern A. Zeeb (LKPI_LHW_SCAN_RUNNING|LKPI_LHW_SCAN_HW); 29718ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 29728ac540d3SBjoern A. Zeeb if (hw_scan_running) 2973a486fbbdSBjoern A. Zeeb return; 2974a486fbbdSBjoern A. Zeeb 2975b2cf3c21SBjoern A. Zeeb c = ic->ic_curchan; 2976b2cf3c21SBjoern A. Zeeb if (c == NULL || c == IEEE80211_CHAN_ANYC) { 29776b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: c %p ops->config %p\n", __func__, 29786b4cac81SBjoern A. Zeeb c, lhw->ops->config); 29796b4cac81SBjoern A. Zeeb return; 29806b4cac81SBjoern A. Zeeb } 29816b4cac81SBjoern A. Zeeb 29826b4cac81SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, c); 29836b4cac81SBjoern A. Zeeb if (chan == NULL) { 29846b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: c %p chan %p\n", __func__, 29856b4cac81SBjoern A. Zeeb c, chan); 29866b4cac81SBjoern A. Zeeb return; 29876b4cac81SBjoern A. Zeeb } 29886b4cac81SBjoern A. Zeeb 29896b4cac81SBjoern A. Zeeb /* XXX max power for scanning? */ 29906b4cac81SBjoern A. Zeeb IMPROVE(); 29916b4cac81SBjoern A. Zeeb 29926b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 29934a07abdeSBjoern A. Zeeb cfg80211_chandef_create(&hw->conf.chandef, chan, 29944a07abdeSBjoern A. Zeeb NL80211_CHAN_NO_HT); 29956b4cac81SBjoern A. Zeeb 29966b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_CHANNEL); 29976b4cac81SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) { 29986b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: config %#0x returned %d\n", 29996b4cac81SBjoern A. Zeeb __func__, IEEE80211_CONF_CHANGE_CHANNEL, error); 30006b4cac81SBjoern A. Zeeb /* XXX should we unroll to the previous chandef? */ 30016b4cac81SBjoern A. Zeeb IMPROVE(); 30026b4cac81SBjoern A. Zeeb } else { 30036b4cac81SBjoern A. Zeeb /* Update radiotap channels as well. */ 30046b4cac81SBjoern A. Zeeb lhw->rtap_tx.wt_chan_freq = htole16(c->ic_freq); 30056b4cac81SBjoern A. Zeeb lhw->rtap_tx.wt_chan_flags = htole16(c->ic_flags); 30066b4cac81SBjoern A. Zeeb lhw->rtap_rx.wr_chan_freq = htole16(c->ic_freq); 30076b4cac81SBjoern A. Zeeb lhw->rtap_rx.wr_chan_flags = htole16(c->ic_flags); 30086b4cac81SBjoern A. Zeeb } 30096b4cac81SBjoern A. Zeeb 30106b4cac81SBjoern A. Zeeb /* Currently PS is hard coded off! Not sure it belongs here. */ 30116b4cac81SBjoern A. Zeeb IMPROVE(); 30126b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, SUPPORTS_PS) && 30136b4cac81SBjoern A. Zeeb (hw->conf.flags & IEEE80211_CONF_PS) != 0) { 30146b4cac81SBjoern A. Zeeb hw->conf.flags &= ~IEEE80211_CONF_PS; 30156b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_PS); 30166b4cac81SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) 30176b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: config %#0x returned " 30186b4cac81SBjoern A. Zeeb "%d\n", __func__, IEEE80211_CONF_CHANGE_PS, 30196b4cac81SBjoern A. Zeeb error); 30206b4cac81SBjoern A. Zeeb } 30216b4cac81SBjoern A. Zeeb } 30226b4cac81SBjoern A. Zeeb 30236b4cac81SBjoern A. Zeeb static struct ieee80211_node * 30246b4cac81SBjoern A. Zeeb lkpi_ic_node_alloc(struct ieee80211vap *vap, 30256b4cac81SBjoern A. Zeeb const uint8_t mac[IEEE80211_ADDR_LEN]) 30266b4cac81SBjoern A. Zeeb { 30276b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 30286b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 30294f61ef8bSBjoern A. Zeeb struct ieee80211_node *ni; 30306b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 30316b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 30326b4cac81SBjoern A. Zeeb 30336b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 30346b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 30356b4cac81SBjoern A. Zeeb 30366b4cac81SBjoern A. Zeeb /* We keep allocations de-coupled so we can deal with the two worlds. */ 30374f61ef8bSBjoern A. Zeeb if (lhw->ic_node_alloc == NULL) 30384f61ef8bSBjoern A. Zeeb return (NULL); 30394f61ef8bSBjoern A. Zeeb 30406b4cac81SBjoern A. Zeeb ni = lhw->ic_node_alloc(vap, mac); 30416b4cac81SBjoern A. Zeeb if (ni == NULL) 30426b4cac81SBjoern A. Zeeb return (NULL); 30436b4cac81SBjoern A. Zeeb 30446b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 30454f61ef8bSBjoern A. Zeeb lsta = lkpi_lsta_alloc(vap, mac, hw, ni); 30466b4cac81SBjoern A. Zeeb if (lsta == NULL) { 30476b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL) 30486b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni); 30496b4cac81SBjoern A. Zeeb return (NULL); 30506b4cac81SBjoern A. Zeeb } 30516b4cac81SBjoern A. Zeeb 30526b4cac81SBjoern A. Zeeb return (ni); 30536b4cac81SBjoern A. Zeeb } 30546b4cac81SBjoern A. Zeeb 30556b4cac81SBjoern A. Zeeb static int 30566b4cac81SBjoern A. Zeeb lkpi_ic_node_init(struct ieee80211_node *ni) 30576b4cac81SBjoern A. Zeeb { 30586b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 30596b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 30606b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 30616b4cac81SBjoern A. Zeeb int error; 30626b4cac81SBjoern A. Zeeb 30636b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 30646b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 30656b4cac81SBjoern A. Zeeb 30666b4cac81SBjoern A. Zeeb if (lhw->ic_node_init != NULL) { 30676b4cac81SBjoern A. Zeeb error = lhw->ic_node_init(ni); 30686b4cac81SBjoern A. Zeeb if (error != 0) 30696b4cac81SBjoern A. Zeeb return (error); 30706b4cac81SBjoern A. Zeeb } 30716b4cac81SBjoern A. Zeeb 30726b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 30736b4cac81SBjoern A. Zeeb 30746b4cac81SBjoern A. Zeeb /* Now take the reference before linking it to the table. */ 30756b4cac81SBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 30766b4cac81SBjoern A. Zeeb 30776b4cac81SBjoern A. Zeeb /* XXX-BZ Sync other state over. */ 30786b4cac81SBjoern A. Zeeb IMPROVE(); 30796b4cac81SBjoern A. Zeeb 30806b4cac81SBjoern A. Zeeb return (0); 30816b4cac81SBjoern A. Zeeb } 30826b4cac81SBjoern A. Zeeb 30836b4cac81SBjoern A. Zeeb static void 30846b4cac81SBjoern A. Zeeb lkpi_ic_node_cleanup(struct ieee80211_node *ni) 30856b4cac81SBjoern A. Zeeb { 30866b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 30876b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 30886b4cac81SBjoern A. Zeeb 30896b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 30906b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 30916b4cac81SBjoern A. Zeeb 30926b4cac81SBjoern A. Zeeb /* XXX-BZ remove from driver, ... */ 30936b4cac81SBjoern A. Zeeb IMPROVE(); 30946b4cac81SBjoern A. Zeeb 30956b4cac81SBjoern A. Zeeb if (lhw->ic_node_cleanup != NULL) 30966b4cac81SBjoern A. Zeeb lhw->ic_node_cleanup(ni); 30976b4cac81SBjoern A. Zeeb } 30986b4cac81SBjoern A. Zeeb 30996b4cac81SBjoern A. Zeeb static void 31006b4cac81SBjoern A. Zeeb lkpi_ic_node_free(struct ieee80211_node *ni) 31016b4cac81SBjoern A. Zeeb { 31026b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 31036b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 31046b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 31056b4cac81SBjoern A. Zeeb 31066b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 31076b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 31086b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 3109d9f59799SBjoern A. Zeeb if (lsta == NULL) 3110d9f59799SBjoern A. Zeeb goto out; 31116b4cac81SBjoern A. Zeeb 31126b4cac81SBjoern A. Zeeb /* XXX-BZ free resources, ... */ 31136b4cac81SBjoern A. Zeeb IMPROVE(); 31146b4cac81SBjoern A. Zeeb 31156b4cac81SBjoern A. Zeeb /* Flush mbufq (make sure to release ni refs!). */ 31166b4cac81SBjoern A. Zeeb #ifdef __notyet__ 31176b4cac81SBjoern A. Zeeb KASSERT(mbufq_len(&lsta->txq) == 0, ("%s: lsta %p has txq len %d != 0\n", 31186b4cac81SBjoern A. Zeeb __func__, lsta, mbufq_len(&lsta->txq))); 31196b4cac81SBjoern A. Zeeb #endif 31206b4cac81SBjoern A. Zeeb /* Drain taskq. */ 31216b4cac81SBjoern A. Zeeb 31226b4cac81SBjoern A. Zeeb /* Drain sta->txq[] */ 31236b4cac81SBjoern A. Zeeb mtx_destroy(&lsta->txq_mtx); 31246b4cac81SBjoern A. Zeeb 31256b4cac81SBjoern A. Zeeb /* Remove lsta if added_to_drv. */ 3126e24e8103SBjoern A. Zeeb 31276b4cac81SBjoern A. Zeeb /* Remove lsta from vif */ 3128e24e8103SBjoern A. Zeeb /* Remove ref from lsta node... */ 3129d9f59799SBjoern A. Zeeb /* Free lsta. */ 3130e24e8103SBjoern A. Zeeb lkpi_lsta_remove(lsta, VAP_TO_LVIF(ni->ni_vap)); 3131d9f59799SBjoern A. Zeeb 3132d9f59799SBjoern A. Zeeb out: 31336b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL) 31346b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni); 31356b4cac81SBjoern A. Zeeb } 31366b4cac81SBjoern A. Zeeb 31376b4cac81SBjoern A. Zeeb static int 31386b4cac81SBjoern A. Zeeb lkpi_ic_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, 31396b4cac81SBjoern A. Zeeb const struct ieee80211_bpf_params *params __unused) 31406b4cac81SBjoern A. Zeeb { 31416b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 31426b4cac81SBjoern A. Zeeb 31436b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 31446b4cac81SBjoern A. Zeeb 31456b4cac81SBjoern A. Zeeb /* Queue the packet and enqueue the task to handle it. */ 31466b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_LOCK(lsta); 31476b4cac81SBjoern A. Zeeb mbufq_enqueue(&lsta->txq, m); 31486b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_UNLOCK(lsta); 31496b4cac81SBjoern A. Zeeb 31509d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 31519d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 31526b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p ni %p %6D mbuf_qlen %d\n", 31536b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, ni, ni->ni_macaddr, ":", 31546b4cac81SBjoern A. Zeeb mbufq_len(&lsta->txq)); 31559d9ba2b7SBjoern A. Zeeb #endif 31566b4cac81SBjoern A. Zeeb 31576b4cac81SBjoern A. Zeeb taskqueue_enqueue(taskqueue_thread, &lsta->txq_task); 31586b4cac81SBjoern A. Zeeb return (0); 31596b4cac81SBjoern A. Zeeb } 31606b4cac81SBjoern A. Zeeb 31616b4cac81SBjoern A. Zeeb static void 31626b4cac81SBjoern A. Zeeb lkpi_80211_txq_tx_one(struct lkpi_sta *lsta, struct mbuf *m) 31636b4cac81SBjoern A. Zeeb { 31646b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 3165b35f6cd0SBjoern A. Zeeb #ifndef LKPI_80211_HW_CRYPTO 31666b4cac81SBjoern A. Zeeb struct ieee80211_frame *wh; 3167b35f6cd0SBjoern A. Zeeb #endif 31686b4cac81SBjoern A. Zeeb struct ieee80211_key *k; 31696b4cac81SBjoern A. Zeeb struct sk_buff *skb; 31706b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 31716b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 31726b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 31736b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 31746b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 31756b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 31766b4cac81SBjoern A. Zeeb struct ieee80211_tx_control control; 31776b4cac81SBjoern A. Zeeb struct ieee80211_tx_info *info; 31786b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 3179e3a0b120SBjoern A. Zeeb struct ieee80211_hdr *hdr; 31806b4cac81SBjoern A. Zeeb void *buf; 3181e3a0b120SBjoern A. Zeeb uint8_t ac, tid; 31826b4cac81SBjoern A. Zeeb 31836b4cac81SBjoern A. Zeeb M_ASSERTPKTHDR(m); 31846b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 31859d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX_DUMP) 31866b4cac81SBjoern A. Zeeb hexdump(mtod(m, const void *), m->m_len, "RAW TX (plain) ", 0); 31876b4cac81SBjoern A. Zeeb #endif 31886b4cac81SBjoern A. Zeeb 31896b4cac81SBjoern A. Zeeb ni = lsta->ni; 3190b35f6cd0SBjoern A. Zeeb k = NULL; 3191b35f6cd0SBjoern A. Zeeb #ifndef LKPI_80211_HW_CRYPTO 31926b4cac81SBjoern A. Zeeb /* Encrypt the frame if need be; XXX-BZ info->control.hw_key. */ 31936b4cac81SBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame *); 31946b4cac81SBjoern A. Zeeb if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { 31956b4cac81SBjoern A. Zeeb /* Retrieve key for TX && do software encryption. */ 31966b4cac81SBjoern A. Zeeb k = ieee80211_crypto_encap(ni, m); 31976b4cac81SBjoern A. Zeeb if (k == NULL) { 31986b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 31996b4cac81SBjoern A. Zeeb m_freem(m); 32006b4cac81SBjoern A. Zeeb return; 32016b4cac81SBjoern A. Zeeb } 32026b4cac81SBjoern A. Zeeb } 32036b4cac81SBjoern A. Zeeb #endif 32046b4cac81SBjoern A. Zeeb 32056b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 32066b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 32076b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 32086b4cac81SBjoern A. Zeeb c = ni->ni_chan; 32096b4cac81SBjoern A. Zeeb 32106b4cac81SBjoern A. Zeeb if (ieee80211_radiotap_active_vap(ni->ni_vap)) { 32116b4cac81SBjoern A. Zeeb struct lkpi_radiotap_tx_hdr *rtap; 32126b4cac81SBjoern A. Zeeb 32136b4cac81SBjoern A. Zeeb rtap = &lhw->rtap_tx; 32146b4cac81SBjoern A. Zeeb rtap->wt_flags = 0; 32156b4cac81SBjoern A. Zeeb if (k != NULL) 32166b4cac81SBjoern A. Zeeb rtap->wt_flags |= IEEE80211_RADIOTAP_F_WEP; 32176b4cac81SBjoern A. Zeeb if (m->m_flags & M_FRAG) 32186b4cac81SBjoern A. Zeeb rtap->wt_flags |= IEEE80211_RADIOTAP_F_FRAG; 32196b4cac81SBjoern A. Zeeb IMPROVE(); 32206b4cac81SBjoern A. Zeeb rtap->wt_rate = 0; 32216b4cac81SBjoern A. Zeeb if (c != NULL && c != IEEE80211_CHAN_ANYC) { 32226b4cac81SBjoern A. Zeeb rtap->wt_chan_freq = htole16(c->ic_freq); 32236b4cac81SBjoern A. Zeeb rtap->wt_chan_flags = htole16(c->ic_flags); 32246b4cac81SBjoern A. Zeeb } 32256b4cac81SBjoern A. Zeeb 32266b4cac81SBjoern A. Zeeb ieee80211_radiotap_tx(ni->ni_vap, m); 32276b4cac81SBjoern A. Zeeb } 32286b4cac81SBjoern A. Zeeb 32296b4cac81SBjoern A. Zeeb /* 32306b4cac81SBjoern A. Zeeb * net80211 should handle hw->extra_tx_headroom. 32316b4cac81SBjoern A. Zeeb * Though for as long as we are copying we don't mind. 32323d09d310SBjoern A. Zeeb * XXX-BZ rtw88 asks for too much headroom for ipv6+tcp: 32333d09d310SBjoern A. Zeeb * https://lists.freebsd.org/archives/freebsd-transport/2022-February/000012.html 32346b4cac81SBjoern A. Zeeb */ 32356b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + m->m_pkthdr.len); 32366b4cac81SBjoern A. Zeeb if (skb == NULL) { 32373f0083c4SBjoern A. Zeeb ic_printf(ic, "ERROR %s: skb alloc failed\n", __func__); 32386b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 32396b4cac81SBjoern A. Zeeb m_freem(m); 32406b4cac81SBjoern A. Zeeb return; 32416b4cac81SBjoern A. Zeeb } 32426b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 32436b4cac81SBjoern A. Zeeb 32446b4cac81SBjoern A. Zeeb /* XXX-BZ we need a SKB version understanding mbuf. */ 32456b4cac81SBjoern A. Zeeb /* Save the mbuf for ieee80211_tx_complete(). */ 32466b4cac81SBjoern A. Zeeb skb->m_free_func = lkpi_ieee80211_free_skb_mbuf; 32476b4cac81SBjoern A. Zeeb skb->m = m; 32486b4cac81SBjoern A. Zeeb #if 0 32496b4cac81SBjoern A. Zeeb skb_put_data(skb, m->m_data, m->m_pkthdr.len); 32506b4cac81SBjoern A. Zeeb #else 32516b4cac81SBjoern A. Zeeb buf = skb_put(skb, m->m_pkthdr.len); 32526b4cac81SBjoern A. Zeeb m_copydata(m, 0, m->m_pkthdr.len, buf); 32536b4cac81SBjoern A. Zeeb #endif 32546b4cac81SBjoern A. Zeeb /* Save the ni. */ 32556b4cac81SBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = ni; 32566b4cac81SBjoern A. Zeeb 32576b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(ni->ni_vap); 32586b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 32596b4cac81SBjoern A. Zeeb 3260e3a0b120SBjoern A. Zeeb hdr = (void *)skb->data; 3261e3a0b120SBjoern A. Zeeb tid = linuxkpi_ieee80211_get_tid(hdr, true); 3262e3a0b120SBjoern A. Zeeb if (tid == IEEE80211_NONQOS_TID) { /* == IEEE80211_NUM_TIDS */ 3263e3a0b120SBjoern A. Zeeb skb->priority = 0; 3264e3a0b120SBjoern A. Zeeb ac = IEEE80211_AC_BE; 3265e3a0b120SBjoern A. Zeeb } else { 3266e3a0b120SBjoern A. Zeeb skb->priority = tid & IEEE80211_QOS_CTL_TID_MASK; 3267e3a0b120SBjoern A. Zeeb ac = tid_to_mac80211_ac[tid & 7]; 3268e3a0b120SBjoern A. Zeeb } 32696b4cac81SBjoern A. Zeeb skb_set_queue_mapping(skb, ac); 32706b4cac81SBjoern A. Zeeb 32716b4cac81SBjoern A. Zeeb info = IEEE80211_SKB_CB(skb); 32726b4cac81SBjoern A. Zeeb info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; 32736b4cac81SBjoern A. Zeeb /* Slight delay; probably only happens on scanning so fine? */ 32746b4cac81SBjoern A. Zeeb if (c == NULL || c == IEEE80211_CHAN_ANYC) 32756b4cac81SBjoern A. Zeeb c = ic->ic_curchan; 32766b4cac81SBjoern A. Zeeb info->band = lkpi_net80211_chan_to_nl80211_band(c); 3277e3a0b120SBjoern A. Zeeb info->hw_queue = vif->hw_queue[ac]; 32786b4cac81SBjoern A. Zeeb if (m->m_flags & M_EAPOL) 32796b4cac81SBjoern A. Zeeb info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO; 32806b4cac81SBjoern A. Zeeb info->control.vif = vif; 32816b4cac81SBjoern A. Zeeb /* XXX-BZ info->control.rates */ 32826b4cac81SBjoern A. Zeeb 32836b4cac81SBjoern A. Zeeb lsta = lkpi_find_lsta_by_ni(lvif, ni); 32846b4cac81SBjoern A. Zeeb if (lsta != NULL) { 32856b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 3286b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 32876b4cac81SBjoern A. Zeeb info->control.hw_key = lsta->kc; 32886b4cac81SBjoern A. Zeeb #endif 32896b4cac81SBjoern A. Zeeb } else { 32906b4cac81SBjoern A. Zeeb sta = NULL; 32916b4cac81SBjoern A. Zeeb } 32926b4cac81SBjoern A. Zeeb 32936b4cac81SBjoern A. Zeeb IMPROVE(); 32946b4cac81SBjoern A. Zeeb 32956b4cac81SBjoern A. Zeeb if (sta != NULL) { 32966b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 32976b4cac81SBjoern A. Zeeb 3298e3a0b120SBjoern A. Zeeb ltxq = NULL; 3299e3a0b120SBjoern A. Zeeb if (!ieee80211_is_data_present(hdr->frame_control)) { 3300e3a0b120SBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_STATION && 3301e3a0b120SBjoern A. Zeeb lsta->added_to_drv && 3302e3a0b120SBjoern A. Zeeb sta->txq[IEEE80211_NUM_TIDS] != NULL) 3303d0d29110SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[IEEE80211_NUM_TIDS]); 3304e3a0b120SBjoern A. Zeeb } else if (lsta->added_to_drv && 3305e3a0b120SBjoern A. Zeeb sta->txq[skb->priority] != NULL) { 3306e3a0b120SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[skb->priority]); 3307e3a0b120SBjoern A. Zeeb } 3308e3a0b120SBjoern A. Zeeb if (ltxq == NULL) 3309d0d29110SBjoern A. Zeeb goto ops_tx; 3310e3a0b120SBjoern A. Zeeb 3311d0d29110SBjoern A. Zeeb KASSERT(ltxq != NULL, ("%s: lsta %p sta %p m %p skb %p " 3312d0d29110SBjoern A. Zeeb "ltxq %p != NULL\n", __func__, lsta, sta, m, skb, ltxq)); 3313d0d29110SBjoern A. Zeeb 33146b4cac81SBjoern A. Zeeb skb_queue_tail(<xq->skbq, skb); 33159d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 33169d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 3317d0d29110SBjoern A. Zeeb printf("%s:%d mo_wake_tx_queue :: %d %u lsta %p sta %p " 3318d0d29110SBjoern A. Zeeb "ni %p %6D skb %p lxtq %p { qlen %u, ac %d tid %u } " 3319d0d29110SBjoern A. Zeeb "WAKE_TX_Q ac %d prio %u qmap %u\n", 3320fb6eaf74SBjoern A. Zeeb __func__, __LINE__, 3321d0d29110SBjoern A. Zeeb curthread->td_tid, (unsigned int)ticks, 3322d0d29110SBjoern A. Zeeb lsta, sta, ni, ni->ni_macaddr, ":", skb, ltxq, 3323d0d29110SBjoern A. Zeeb skb_queue_len(<xq->skbq), ltxq->txq.ac, 3324d0d29110SBjoern A. Zeeb ltxq->txq.tid, ac, skb->priority, skb->qmap); 33259d9ba2b7SBjoern A. Zeeb #endif 3326d0d29110SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, <xq->txq); 33276b4cac81SBjoern A. Zeeb return; 33286b4cac81SBjoern A. Zeeb } 33296b4cac81SBjoern A. Zeeb 33306b4cac81SBjoern A. Zeeb ops_tx: 33319d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 33329d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 3333d0d29110SBjoern A. Zeeb printf("%s:%d mo_tx :: lsta %p sta %p ni %p %6D skb %p " 3334d0d29110SBjoern A. Zeeb "TX ac %d prio %u qmap %u\n", 33356b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, sta, ni, ni->ni_macaddr, ":", 33366b4cac81SBjoern A. Zeeb skb, ac, skb->priority, skb->qmap); 33379d9ba2b7SBjoern A. Zeeb #endif 33386b4cac81SBjoern A. Zeeb memset(&control, 0, sizeof(control)); 33396b4cac81SBjoern A. Zeeb control.sta = sta; 33406b4cac81SBjoern A. Zeeb 33416b4cac81SBjoern A. Zeeb lkpi_80211_mo_tx(hw, &control, skb); 33426b4cac81SBjoern A. Zeeb return; 33436b4cac81SBjoern A. Zeeb } 33446b4cac81SBjoern A. Zeeb 33456b4cac81SBjoern A. Zeeb static void 33466b4cac81SBjoern A. Zeeb lkpi_80211_txq_task(void *ctx, int pending) 33476b4cac81SBjoern A. Zeeb { 33486b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 33496b4cac81SBjoern A. Zeeb struct mbufq mq; 33506b4cac81SBjoern A. Zeeb struct mbuf *m; 33516b4cac81SBjoern A. Zeeb 33526b4cac81SBjoern A. Zeeb lsta = ctx; 33536b4cac81SBjoern A. Zeeb 33549d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 33559d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 33566b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p ni %p %6D pending %d mbuf_qlen %d\n", 33579d9ba2b7SBjoern A. Zeeb __func__, __LINE__, lsta, lsta->ni, lsta->ni->ni_macaddr, ":", 33586b4cac81SBjoern A. Zeeb pending, mbufq_len(&lsta->txq)); 33599d9ba2b7SBjoern A. Zeeb #endif 33606b4cac81SBjoern A. Zeeb 33616b4cac81SBjoern A. Zeeb mbufq_init(&mq, IFQ_MAXLEN); 33626b4cac81SBjoern A. Zeeb 33636b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_LOCK(lsta); 33646b4cac81SBjoern A. Zeeb mbufq_concat(&mq, &lsta->txq); 33656b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_UNLOCK(lsta); 33666b4cac81SBjoern A. Zeeb 33676b4cac81SBjoern A. Zeeb m = mbufq_dequeue(&mq); 33686b4cac81SBjoern A. Zeeb while (m != NULL) { 33696b4cac81SBjoern A. Zeeb lkpi_80211_txq_tx_one(lsta, m); 33706b4cac81SBjoern A. Zeeb m = mbufq_dequeue(&mq); 33716b4cac81SBjoern A. Zeeb } 33726b4cac81SBjoern A. Zeeb } 33736b4cac81SBjoern A. Zeeb 33746b4cac81SBjoern A. Zeeb static int 33756b4cac81SBjoern A. Zeeb lkpi_ic_transmit(struct ieee80211com *ic, struct mbuf *m) 33766b4cac81SBjoern A. Zeeb { 33776b4cac81SBjoern A. Zeeb 33786b4cac81SBjoern A. Zeeb /* XXX TODO */ 33796b4cac81SBjoern A. Zeeb IMPROVE(); 33806b4cac81SBjoern A. Zeeb 33816b4cac81SBjoern A. Zeeb /* Quick and dirty cheating hack. */ 33826b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 33836b4cac81SBjoern A. Zeeb 33846b4cac81SBjoern A. Zeeb ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; 33856b4cac81SBjoern A. Zeeb return (lkpi_ic_raw_xmit(ni, m, NULL)); 33866b4cac81SBjoern A. Zeeb } 33876b4cac81SBjoern A. Zeeb 33886b4cac81SBjoern A. Zeeb static void 33896b4cac81SBjoern A. Zeeb lkpi_ic_getradiocaps(struct ieee80211com *ic, int maxchan, 33906b4cac81SBjoern A. Zeeb int *n, struct ieee80211_channel *c) 33916b4cac81SBjoern A. Zeeb { 33926b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 33936b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 33946b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 33956b4cac81SBjoern A. Zeeb uint8_t bands[IEEE80211_MODE_BYTES]; 33966b4cac81SBjoern A. Zeeb int chan_flags, error, i, nchans; 33976b4cac81SBjoern A. Zeeb 33986b4cac81SBjoern A. Zeeb /* Channels */ 33996b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 34006b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 34016b4cac81SBjoern A. Zeeb 34026b4cac81SBjoern A. Zeeb /* NL80211_BAND_2GHZ */ 34036b4cac81SBjoern A. Zeeb nchans = 0; 34046b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_2GHZ] != NULL) 34056b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[NL80211_BAND_2GHZ]->n_channels; 34066b4cac81SBjoern A. Zeeb if (nchans > 0) { 34076b4cac81SBjoern A. Zeeb memset(bands, 0, sizeof(bands)); 34086b4cac81SBjoern A. Zeeb chan_flags = 0; 34096b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11B); 34106b4cac81SBjoern A. Zeeb /* XXX-BZ unclear how to check for 11g. */ 34116b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11G); 34126b4cac81SBjoern A. Zeeb #ifdef __notyet__ 34136b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_2GHZ]->ht_cap.ht_supported) { 34146b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11NG); 34156b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_HT40; 34166b4cac81SBjoern A. Zeeb } 34176b4cac81SBjoern A. Zeeb #endif 34186b4cac81SBjoern A. Zeeb 34196b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[NL80211_BAND_2GHZ]->channels; 3420cee56e77SBjoern A. Zeeb for (i = 0; i < nchans && *n < maxchan; i++) { 34216b4cac81SBjoern A. Zeeb uint32_t nflags = 0; 34226b4cac81SBjoern A. Zeeb int cflags = chan_flags; 34236b4cac81SBjoern A. Zeeb 34246b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) { 34253f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Skipping disabled chan " 34263f0083c4SBjoern A. Zeeb "[%u/%u/%#x]\n", __func__, 34276b4cac81SBjoern A. Zeeb channels[i].hw_value, 34286b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags); 34296b4cac81SBjoern A. Zeeb continue; 34306b4cac81SBjoern A. Zeeb } 34316b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_IR) 34326b4cac81SBjoern A. Zeeb nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE); 34336b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_RADAR) 34346b4cac81SBjoern A. Zeeb nflags |= IEEE80211_CHAN_DFS; 34356b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ) 34366b4cac81SBjoern A. Zeeb cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80); 34376b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ) 34386b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_VHT80; 34396b4cac81SBjoern A. Zeeb /* XXX how to map the remaining enum ieee80211_channel_flags? */ 34406b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_HT40) 34416b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_HT40; 34426b4cac81SBjoern A. Zeeb 34436b4cac81SBjoern A. Zeeb error = ieee80211_add_channel_cbw(c, maxchan, n, 34446b4cac81SBjoern A. Zeeb channels[i].hw_value, channels[i].center_freq, 34456b4cac81SBjoern A. Zeeb channels[i].max_power, 34466b4cac81SBjoern A. Zeeb nflags, bands, chan_flags); 3447cee56e77SBjoern A. Zeeb /* net80211::ENOBUFS: *n >= maxchans */ 3448cee56e77SBjoern A. Zeeb if (error != 0 && error != ENOBUFS) 34493f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Adding chan %u/%u/%#x/%#x/%#x/%#x " 34503f0083c4SBjoern A. Zeeb "returned error %d\n", 34516b4cac81SBjoern A. Zeeb __func__, channels[i].hw_value, 34526b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags, 34536b4cac81SBjoern A. Zeeb nflags, chan_flags, cflags, error); 3454cee56e77SBjoern A. Zeeb if (error != 0) 34556b4cac81SBjoern A. Zeeb break; 34566b4cac81SBjoern A. Zeeb } 34576b4cac81SBjoern A. Zeeb } 34586b4cac81SBjoern A. Zeeb 34596b4cac81SBjoern A. Zeeb /* NL80211_BAND_5GHZ */ 34606b4cac81SBjoern A. Zeeb nchans = 0; 34616b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ] != NULL) 34626b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[NL80211_BAND_5GHZ]->n_channels; 34636b4cac81SBjoern A. Zeeb if (nchans > 0) { 34646b4cac81SBjoern A. Zeeb memset(bands, 0, sizeof(bands)); 34656b4cac81SBjoern A. Zeeb chan_flags = 0; 34666b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11A); 34676b4cac81SBjoern A. Zeeb #ifdef __not_yet__ 34686b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ]->ht_cap.ht_supported) { 34696b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11NA); 34706b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_HT40; 34716b4cac81SBjoern A. Zeeb } 34726b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.vht_supported){ 34736b4cac81SBjoern A. Zeeb 34746b4cac81SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_VHT; 34756b4cac81SBjoern A. Zeeb ic->ic_vhtcaps = 34766b4cac81SBjoern A. Zeeb hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap; 34776b4cac81SBjoern A. Zeeb 34786b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_VHT_5GHZ); 34796b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT80; 34806b4cac81SBjoern A. Zeeb if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160MHZ( 34816b4cac81SBjoern A. Zeeb ic->ic_vhtcaps)) 34826b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT160; 34836b4cac81SBjoern A. Zeeb if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160_80P80MHZ( 34846b4cac81SBjoern A. Zeeb ic->ic_vhtcaps)) 34856b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT80P80; 34866b4cac81SBjoern A. Zeeb } 34876b4cac81SBjoern A. Zeeb #endif 34886b4cac81SBjoern A. Zeeb 34896b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[NL80211_BAND_5GHZ]->channels; 3490cee56e77SBjoern A. Zeeb for (i = 0; i < nchans && *n < maxchan; i++) { 34916b4cac81SBjoern A. Zeeb uint32_t nflags = 0; 34926b4cac81SBjoern A. Zeeb int cflags = chan_flags; 34936b4cac81SBjoern A. Zeeb 34946b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) { 34953f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Skipping disabled chan " 34963f0083c4SBjoern A. Zeeb "[%u/%u/%#x]\n", __func__, 34976b4cac81SBjoern A. Zeeb channels[i].hw_value, 34986b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags); 34996b4cac81SBjoern A. Zeeb continue; 35006b4cac81SBjoern A. Zeeb } 35016b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_IR) 35026b4cac81SBjoern A. Zeeb nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE); 35036b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_RADAR) 35046b4cac81SBjoern A. Zeeb nflags |= IEEE80211_CHAN_DFS; 35056b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ) 35066b4cac81SBjoern A. Zeeb cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80); 35076b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ) 35086b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_VHT80; 35096b4cac81SBjoern A. Zeeb /* XXX hwo to map the remaining enum ieee80211_channel_flags? */ 35106b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_HT40) 35116b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_HT40; 35126b4cac81SBjoern A. Zeeb 35136b4cac81SBjoern A. Zeeb error = ieee80211_add_channel_cbw(c, maxchan, n, 35146b4cac81SBjoern A. Zeeb channels[i].hw_value, channels[i].center_freq, 35156b4cac81SBjoern A. Zeeb channels[i].max_power, 35166b4cac81SBjoern A. Zeeb nflags, bands, chan_flags); 3517cee56e77SBjoern A. Zeeb /* net80211::ENOBUFS: *n >= maxchans */ 3518cee56e77SBjoern A. Zeeb if (error != 0 && error != ENOBUFS) 35193f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Adding chan %u/%u/%#x/%#x/%#x/%#x " 35203f0083c4SBjoern A. Zeeb "returned error %d\n", 35216b4cac81SBjoern A. Zeeb __func__, channels[i].hw_value, 35226b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags, 35236b4cac81SBjoern A. Zeeb nflags, chan_flags, cflags, error); 3524cee56e77SBjoern A. Zeeb if (error != 0) 35256b4cac81SBjoern A. Zeeb break; 35266b4cac81SBjoern A. Zeeb } 35276b4cac81SBjoern A. Zeeb } 35286b4cac81SBjoern A. Zeeb } 35296b4cac81SBjoern A. Zeeb 35306b4cac81SBjoern A. Zeeb static void * 35316b4cac81SBjoern A. Zeeb lkpi_ieee80211_ifalloc(void) 35326b4cac81SBjoern A. Zeeb { 35336b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 35346b4cac81SBjoern A. Zeeb 35356b4cac81SBjoern A. Zeeb ic = malloc(sizeof(*ic), M_LKPI80211, M_WAITOK | M_ZERO); 35366b4cac81SBjoern A. Zeeb if (ic == NULL) 35376b4cac81SBjoern A. Zeeb return (NULL); 35386b4cac81SBjoern A. Zeeb 35396b4cac81SBjoern A. Zeeb /* Setting these happens later when we have device information. */ 35406b4cac81SBjoern A. Zeeb ic->ic_softc = NULL; 35416b4cac81SBjoern A. Zeeb ic->ic_name = "linuxkpi"; 35426b4cac81SBjoern A. Zeeb 35436b4cac81SBjoern A. Zeeb return (ic); 35446b4cac81SBjoern A. Zeeb } 35456b4cac81SBjoern A. Zeeb 35466b4cac81SBjoern A. Zeeb struct ieee80211_hw * 35476b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_alloc_hw(size_t priv_len, const struct ieee80211_ops *ops) 35486b4cac81SBjoern A. Zeeb { 35496b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 35506b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 35516b4cac81SBjoern A. Zeeb struct wiphy *wiphy; 3552a5ae63edSBjoern A. Zeeb int ac; 35536b4cac81SBjoern A. Zeeb 35546b4cac81SBjoern A. Zeeb /* Get us and the driver data also allocated. */ 35556b4cac81SBjoern A. Zeeb wiphy = wiphy_new(&linuxkpi_mac80211cfgops, sizeof(*lhw) + priv_len); 35566b4cac81SBjoern A. Zeeb if (wiphy == NULL) 35576b4cac81SBjoern A. Zeeb return (NULL); 35586b4cac81SBjoern A. Zeeb 35596b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 35606b4cac81SBjoern A. Zeeb lhw->ops = ops; 3561652e22d3SBjoern A. Zeeb 35628ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK_INIT(lhw); 35638ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK_INIT(lhw); 35648891c455SBjoern A. Zeeb sx_init_flags(&lhw->lvif_sx, "lhw-lvif", SX_RECURSE | SX_DUPOK); 35656b4cac81SBjoern A. Zeeb TAILQ_INIT(&lhw->lvif_head); 3566a5ae63edSBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 3567a5ae63edSBjoern A. Zeeb lhw->txq_generation[ac] = 1; 3568a5ae63edSBjoern A. Zeeb TAILQ_INIT(&lhw->scheduled_txqs[ac]); 3569a5ae63edSBjoern A. Zeeb } 35706b4cac81SBjoern A. Zeeb 35716b4cac81SBjoern A. Zeeb /* 35726b4cac81SBjoern A. Zeeb * XXX-BZ TODO make sure there is a "_null" function to all ops 35736b4cac81SBjoern A. Zeeb * not initialized. 35746b4cac81SBjoern A. Zeeb */ 35756b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 35766b4cac81SBjoern A. Zeeb hw->wiphy = wiphy; 3577086be6a8SBjoern A. Zeeb hw->conf.flags |= IEEE80211_CONF_IDLE; 35786b4cac81SBjoern A. Zeeb hw->priv = (void *)(lhw + 1); 35796b4cac81SBjoern A. Zeeb 35806b4cac81SBjoern A. Zeeb /* BSD Specific. */ 35816b4cac81SBjoern A. Zeeb lhw->ic = lkpi_ieee80211_ifalloc(); 35826b4cac81SBjoern A. Zeeb if (lhw->ic == NULL) { 35836b4cac81SBjoern A. Zeeb ieee80211_free_hw(hw); 35846b4cac81SBjoern A. Zeeb return (NULL); 35856b4cac81SBjoern A. Zeeb } 35866b4cac81SBjoern A. Zeeb 35876b4cac81SBjoern A. Zeeb IMPROVE(); 35886b4cac81SBjoern A. Zeeb 35896b4cac81SBjoern A. Zeeb return (hw); 35906b4cac81SBjoern A. Zeeb } 35916b4cac81SBjoern A. Zeeb 35926b4cac81SBjoern A. Zeeb void 35936b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iffree(struct ieee80211_hw *hw) 35946b4cac81SBjoern A. Zeeb { 35956b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 35966b4cac81SBjoern A. Zeeb 35976b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 35986b4cac81SBjoern A. Zeeb free(lhw->ic, M_LKPI80211); 35996b4cac81SBjoern A. Zeeb lhw->ic = NULL; 36006b4cac81SBjoern A. Zeeb 36016b4cac81SBjoern A. Zeeb /* Cleanup more of lhw here or in wiphy_free()? */ 36028891c455SBjoern A. Zeeb sx_destroy(&lhw->lvif_sx); 36038ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK_DESTROY(lhw); 36048ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK_DESTROY(lhw); 36056b4cac81SBjoern A. Zeeb IMPROVE(); 36066b4cac81SBjoern A. Zeeb } 36076b4cac81SBjoern A. Zeeb 36086b4cac81SBjoern A. Zeeb void 36096b4cac81SBjoern A. Zeeb linuxkpi_set_ieee80211_dev(struct ieee80211_hw *hw, char *name) 36106b4cac81SBjoern A. Zeeb { 36116b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 36126b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 36136b4cac81SBjoern A. Zeeb 36146b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 36156b4cac81SBjoern A. Zeeb ic = lhw->ic; 36166b4cac81SBjoern A. Zeeb 36176b4cac81SBjoern A. Zeeb /* Now set a proper name before ieee80211_ifattach(). */ 36186b4cac81SBjoern A. Zeeb ic->ic_softc = lhw; 36196b4cac81SBjoern A. Zeeb ic->ic_name = name; 36206b4cac81SBjoern A. Zeeb 36216b4cac81SBjoern A. Zeeb /* XXX-BZ do we also need to set wiphy name? */ 36226b4cac81SBjoern A. Zeeb } 36236b4cac81SBjoern A. Zeeb 36246b4cac81SBjoern A. Zeeb struct ieee80211_hw * 36256b4cac81SBjoern A. Zeeb linuxkpi_wiphy_to_ieee80211_hw(struct wiphy *wiphy) 36266b4cac81SBjoern A. Zeeb { 36276b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 36286b4cac81SBjoern A. Zeeb 36296b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 36306b4cac81SBjoern A. Zeeb return (LHW_TO_HW(lhw)); 36316b4cac81SBjoern A. Zeeb } 36326b4cac81SBjoern A. Zeeb 36336b4cac81SBjoern A. Zeeb static void 36346b4cac81SBjoern A. Zeeb lkpi_radiotap_attach(struct lkpi_hw *lhw) 36356b4cac81SBjoern A. Zeeb { 36366b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 36376b4cac81SBjoern A. Zeeb 36386b4cac81SBjoern A. Zeeb ic = lhw->ic; 36396b4cac81SBjoern A. Zeeb ieee80211_radiotap_attach(ic, 36406b4cac81SBjoern A. Zeeb &lhw->rtap_tx.wt_ihdr, sizeof(lhw->rtap_tx), 36416b4cac81SBjoern A. Zeeb LKPI_RTAP_TX_FLAGS_PRESENT, 36426b4cac81SBjoern A. Zeeb &lhw->rtap_rx.wr_ihdr, sizeof(lhw->rtap_rx), 36436b4cac81SBjoern A. Zeeb LKPI_RTAP_RX_FLAGS_PRESENT); 36446b4cac81SBjoern A. Zeeb } 36456b4cac81SBjoern A. Zeeb 36462e183d99SBjoern A. Zeeb int 36476b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ifattach(struct ieee80211_hw *hw) 36486b4cac81SBjoern A. Zeeb { 36496b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 36506b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 3651c5b96b3eSBjoern A. Zeeb int band, i; 36526b4cac81SBjoern A. Zeeb 36536b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 36546b4cac81SBjoern A. Zeeb ic = lhw->ic; 36556b4cac81SBjoern A. Zeeb 3656652e22d3SBjoern A. Zeeb /* We do it this late as wiphy->dev should be set for the name. */ 3657652e22d3SBjoern A. Zeeb lhw->workq = alloc_ordered_workqueue(wiphy_name(hw->wiphy), 0); 3658652e22d3SBjoern A. Zeeb if (lhw->workq == NULL) 3659652e22d3SBjoern A. Zeeb return (-EAGAIN); 3660652e22d3SBjoern A. Zeeb 36616b4cac81SBjoern A. Zeeb /* XXX-BZ figure this out how they count his... */ 36626b4cac81SBjoern A. Zeeb if (!is_zero_ether_addr(hw->wiphy->perm_addr)) { 36636b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(ic->ic_macaddr, 36646b4cac81SBjoern A. Zeeb hw->wiphy->perm_addr); 36656b4cac81SBjoern A. Zeeb } else if (hw->wiphy->n_addresses > 0) { 36666b4cac81SBjoern A. Zeeb /* We take the first one. */ 36676b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(ic->ic_macaddr, 36686b4cac81SBjoern A. Zeeb hw->wiphy->addresses[0].addr); 36696b4cac81SBjoern A. Zeeb } else { 36706b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: warning, no hardware address!\n", __func__); 36716b4cac81SBjoern A. Zeeb } 36726b4cac81SBjoern A. Zeeb 36733d09d310SBjoern A. Zeeb #ifdef __not_yet__ 36743d09d310SBjoern A. Zeeb /* See comment in lkpi_80211_txq_tx_one(). */ 36756b4cac81SBjoern A. Zeeb ic->ic_headroom = hw->extra_tx_headroom; 36763d09d310SBjoern A. Zeeb #endif 36776b4cac81SBjoern A. Zeeb 36786b4cac81SBjoern A. Zeeb ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ 36796b4cac81SBjoern A. Zeeb ic->ic_opmode = IEEE80211_M_STA; 36806b4cac81SBjoern A. Zeeb 36816b4cac81SBjoern A. Zeeb /* Set device capabilities. */ 36826b4cac81SBjoern A. Zeeb /* XXX-BZ we need to get these from linux80211/drivers and convert. */ 36836b4cac81SBjoern A. Zeeb ic->ic_caps = 36846b4cac81SBjoern A. Zeeb IEEE80211_C_STA | 36856b4cac81SBjoern A. Zeeb IEEE80211_C_MONITOR | 36866b4cac81SBjoern A. Zeeb IEEE80211_C_WPA | /* WPA/RSN */ 36874a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 36886b4cac81SBjoern A. Zeeb IEEE80211_C_WME | 36894a67f1dfSBjoern A. Zeeb #endif 36906b4cac81SBjoern A. Zeeb #if 0 36916b4cac81SBjoern A. Zeeb IEEE80211_C_PMGT | 36926b4cac81SBjoern A. Zeeb #endif 36936b4cac81SBjoern A. Zeeb IEEE80211_C_SHSLOT | /* short slot time supported */ 36946b4cac81SBjoern A. Zeeb IEEE80211_C_SHPREAMBLE /* short preamble supported */ 36956b4cac81SBjoern A. Zeeb ; 36966b4cac81SBjoern A. Zeeb #if 0 36976b4cac81SBjoern A. Zeeb /* Scanning is a different kind of beast to re-work. */ 36986b4cac81SBjoern A. Zeeb ic->ic_caps |= IEEE80211_C_BGSCAN; 36996b4cac81SBjoern A. Zeeb #endif 3700cc4e78d5SBjoern A. Zeeb if (lhw->ops->hw_scan) { 3701cc4e78d5SBjoern A. Zeeb /* 3702cc4e78d5SBjoern A. Zeeb * Advertise full-offload scanning. 3703cc4e78d5SBjoern A. Zeeb * 3704cc4e78d5SBjoern A. Zeeb * Not limiting to SINGLE_SCAN_ON_ALL_BANDS here as otherwise 3705cc4e78d5SBjoern A. Zeeb * we essentially disable hw_scan for all drivers not setting 3706cc4e78d5SBjoern A. Zeeb * the flag. 3707cc4e78d5SBjoern A. Zeeb */ 37086b4cac81SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_SCAN_OFFLOAD; 3709a486fbbdSBjoern A. Zeeb lhw->scan_flags |= LKPI_LHW_SCAN_HW; 37106b4cac81SBjoern A. Zeeb } 37116b4cac81SBjoern A. Zeeb 37126b4cac81SBjoern A. Zeeb #ifdef __notyet__ 37136b4cac81SBjoern A. Zeeb ic->ic_htcaps = IEEE80211_HTC_HT /* HT operation */ 37146b4cac81SBjoern A. Zeeb | IEEE80211_HTC_AMPDU /* A-MPDU tx/rx */ 37156b4cac81SBjoern A. Zeeb | IEEE80211_HTC_AMSDU /* A-MSDU tx/rx */ 37166b4cac81SBjoern A. Zeeb | IEEE80211_HTCAP_MAXAMSDU_3839 37176b4cac81SBjoern A. Zeeb /* max A-MSDU length */ 37186b4cac81SBjoern A. Zeeb | IEEE80211_HTCAP_SMPS_OFF; /* SM power save off */ 37196b4cac81SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_SHORTGI20; 37206b4cac81SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_CHWIDTH40 | IEEE80211_HTCAP_SHORTGI40; 37216b4cac81SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_TXSTBC; 37226b4cac81SBjoern A. Zeeb #endif 37236b4cac81SBjoern A. Zeeb 3724527687a9SBjoern A. Zeeb /* 3725527687a9SBjoern A. Zeeb * The wiphy variables report bitmasks of avail antennas. 3726527687a9SBjoern A. Zeeb * (*get_antenna) get the current bitmask sets which can be 3727527687a9SBjoern A. Zeeb * altered by (*set_antenna) for some drivers. 3728527687a9SBjoern A. Zeeb * XXX-BZ will the count alone do us much good long-term in net80211? 3729527687a9SBjoern A. Zeeb */ 3730527687a9SBjoern A. Zeeb if (hw->wiphy->available_antennas_rx || 3731527687a9SBjoern A. Zeeb hw->wiphy->available_antennas_tx) { 3732527687a9SBjoern A. Zeeb uint32_t rxs, txs; 3733527687a9SBjoern A. Zeeb 3734527687a9SBjoern A. Zeeb if (lkpi_80211_mo_get_antenna(hw, &txs, &rxs) == 0) { 3735527687a9SBjoern A. Zeeb ic->ic_rxstream = bitcount32(rxs); 3736527687a9SBjoern A. Zeeb ic->ic_txstream = bitcount32(txs); 3737527687a9SBjoern A. Zeeb } 3738527687a9SBjoern A. Zeeb } 3739527687a9SBjoern A. Zeeb 37406b4cac81SBjoern A. Zeeb ic->ic_cryptocaps = 0; 3741b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 37426b4cac81SBjoern A. Zeeb if (hw->wiphy->n_cipher_suites > 0) { 37436b4cac81SBjoern A. Zeeb for (i = 0; i < hw->wiphy->n_cipher_suites; i++) 37446b4cac81SBjoern A. Zeeb ic->ic_cryptocaps |= lkpi_l80211_to_net80211_cyphers( 37456b4cac81SBjoern A. Zeeb hw->wiphy->cipher_suites[i]); 37466b4cac81SBjoern A. Zeeb } 37476b4cac81SBjoern A. Zeeb #endif 37486b4cac81SBjoern A. Zeeb 37496b4cac81SBjoern A. Zeeb lkpi_ic_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans, 37506b4cac81SBjoern A. Zeeb ic->ic_channels); 37516b4cac81SBjoern A. Zeeb 37526b4cac81SBjoern A. Zeeb ieee80211_ifattach(ic); 37536b4cac81SBjoern A. Zeeb 37546b4cac81SBjoern A. Zeeb ic->ic_update_mcast = lkpi_ic_update_mcast; 37556b4cac81SBjoern A. Zeeb ic->ic_update_promisc = lkpi_ic_update_promisc; 37566b4cac81SBjoern A. Zeeb ic->ic_update_chw = lkpi_ic_update_chw; 37576b4cac81SBjoern A. Zeeb ic->ic_parent = lkpi_ic_parent; 37586b4cac81SBjoern A. Zeeb ic->ic_scan_start = lkpi_ic_scan_start; 37596b4cac81SBjoern A. Zeeb ic->ic_scan_end = lkpi_ic_scan_end; 37606b4cac81SBjoern A. Zeeb ic->ic_set_channel = lkpi_ic_set_channel; 37616b4cac81SBjoern A. Zeeb ic->ic_transmit = lkpi_ic_transmit; 37626b4cac81SBjoern A. Zeeb ic->ic_raw_xmit = lkpi_ic_raw_xmit; 37636b4cac81SBjoern A. Zeeb ic->ic_vap_create = lkpi_ic_vap_create; 37646b4cac81SBjoern A. Zeeb ic->ic_vap_delete = lkpi_ic_vap_delete; 37656b4cac81SBjoern A. Zeeb ic->ic_getradiocaps = lkpi_ic_getradiocaps; 37666b4cac81SBjoern A. Zeeb ic->ic_wme.wme_update = lkpi_ic_wme_update; 37676b4cac81SBjoern A. Zeeb 3768a486fbbdSBjoern A. Zeeb lhw->ic_scan_curchan = ic->ic_scan_curchan; 3769a486fbbdSBjoern A. Zeeb ic->ic_scan_curchan = lkpi_ic_scan_curchan; 3770a486fbbdSBjoern A. Zeeb lhw->ic_scan_mindwell = ic->ic_scan_mindwell; 3771a486fbbdSBjoern A. Zeeb ic->ic_scan_mindwell = lkpi_ic_scan_mindwell; 3772a486fbbdSBjoern A. Zeeb 37736b4cac81SBjoern A. Zeeb lhw->ic_node_alloc = ic->ic_node_alloc; 37746b4cac81SBjoern A. Zeeb ic->ic_node_alloc = lkpi_ic_node_alloc; 37756b4cac81SBjoern A. Zeeb lhw->ic_node_init = ic->ic_node_init; 37766b4cac81SBjoern A. Zeeb ic->ic_node_init = lkpi_ic_node_init; 37776b4cac81SBjoern A. Zeeb lhw->ic_node_cleanup = ic->ic_node_cleanup; 37786b4cac81SBjoern A. Zeeb ic->ic_node_cleanup = lkpi_ic_node_cleanup; 37796b4cac81SBjoern A. Zeeb lhw->ic_node_free = ic->ic_node_free; 37806b4cac81SBjoern A. Zeeb ic->ic_node_free = lkpi_ic_node_free; 37816b4cac81SBjoern A. Zeeb 37826b4cac81SBjoern A. Zeeb lkpi_radiotap_attach(lhw); 37836b4cac81SBjoern A. Zeeb 3784c5b96b3eSBjoern A. Zeeb /* 3785c5b96b3eSBjoern A. Zeeb * Assign the first possible channel for now; seems Realtek drivers 3786c5b96b3eSBjoern A. Zeeb * expect one. 3787d9945d78SBjoern A. Zeeb * Also remember the amount of bands we support and the most rates 3788d9945d78SBjoern A. Zeeb * in any band so we can scale [(ext) sup rates] IE(s) accordingly. 3789c5b96b3eSBjoern A. Zeeb */ 3790d9945d78SBjoern A. Zeeb lhw->supbands = lhw->max_rates = 0; 3791f454a4a1SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 3792c5b96b3eSBjoern A. Zeeb struct ieee80211_supported_band *supband; 3793c5b96b3eSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 3794c5b96b3eSBjoern A. Zeeb 3795c5b96b3eSBjoern A. Zeeb supband = hw->wiphy->bands[band]; 3796c5b96b3eSBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 3797c5b96b3eSBjoern A. Zeeb continue; 3798c5b96b3eSBjoern A. Zeeb 3799d9945d78SBjoern A. Zeeb lhw->supbands++; 3800d9945d78SBjoern A. Zeeb lhw->max_rates = max(lhw->max_rates, supband->n_bitrates); 3801d9945d78SBjoern A. Zeeb 3802f454a4a1SBjoern A. Zeeb /* If we have a channel, we need to keep counting supbands. */ 3803f454a4a1SBjoern A. Zeeb if (hw->conf.chandef.chan != NULL) 3804f454a4a1SBjoern A. Zeeb continue; 3805f454a4a1SBjoern A. Zeeb 3806c5b96b3eSBjoern A. Zeeb channels = supband->channels; 3807c5b96b3eSBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 3808c5b96b3eSBjoern A. Zeeb 3809c5b96b3eSBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) 3810c5b96b3eSBjoern A. Zeeb continue; 3811c5b96b3eSBjoern A. Zeeb 38124a07abdeSBjoern A. Zeeb cfg80211_chandef_create(&hw->conf.chandef, &channels[i], 3813c5b96b3eSBjoern A. Zeeb NL80211_CHAN_NO_HT); 3814c5b96b3eSBjoern A. Zeeb break; 3815c5b96b3eSBjoern A. Zeeb } 3816c5b96b3eSBjoern A. Zeeb } 3817c5b96b3eSBjoern A. Zeeb 3818d9945d78SBjoern A. Zeeb IMPROVE("see net80211::ieee80211_chan_init vs. wiphy->bands[].bitrates possibly in lkpi_ic_getradiocaps?"); 3819d9945d78SBjoern A. Zeeb 3820d9945d78SBjoern A. Zeeb /* Make sure we do not support more than net80211 is willing to take. */ 3821d9945d78SBjoern A. Zeeb if (lhw->max_rates > IEEE80211_RATE_MAXSIZE) { 3822d9945d78SBjoern A. Zeeb ic_printf(ic, "%s: limiting max_rates %d to %d!\n", __func__, 3823d9945d78SBjoern A. Zeeb lhw->max_rates, IEEE80211_RATE_MAXSIZE); 3824d9945d78SBjoern A. Zeeb lhw->max_rates = IEEE80211_RATE_MAXSIZE; 3825d9945d78SBjoern A. Zeeb } 3826d9945d78SBjoern A. Zeeb 3827d9945d78SBjoern A. Zeeb /* 3828d9945d78SBjoern A. Zeeb * The maximum supported bitrates on any band + size for 3829d9945d78SBjoern A. Zeeb * DSSS Parameter Set give our per-band IE size. 3830d9945d78SBjoern A. Zeeb * XXX-BZ FIXME add HT VHT ... later 3831d9945d78SBjoern A. Zeeb * SSID is the responsibility of the driver and goes on the side. 3832d9945d78SBjoern A. Zeeb * The user specified bits coming from the vap go into the 3833d9945d78SBjoern A. Zeeb * "common ies" fields. 3834d9945d78SBjoern A. Zeeb */ 3835d9945d78SBjoern A. Zeeb lhw->scan_ie_len = 2 + IEEE80211_RATE_SIZE; 3836d9945d78SBjoern A. Zeeb if (lhw->max_rates > IEEE80211_RATE_SIZE) 3837d9945d78SBjoern A. Zeeb lhw->scan_ie_len += 2 + (lhw->max_rates - IEEE80211_RATE_SIZE); 3838d9945d78SBjoern A. Zeeb /* 3839d9945d78SBjoern A. Zeeb * net80211 does not seem to support the DSSS Parameter Set but some of 3840d9945d78SBjoern A. Zeeb * the drivers insert it so calculate the extra fixed space in. 3841d9945d78SBjoern A. Zeeb */ 3842d9945d78SBjoern A. Zeeb lhw->scan_ie_len += 2 + 1; 3843d9945d78SBjoern A. Zeeb 3844d9945d78SBjoern A. Zeeb /* Reduce the max_scan_ie_len "left" by the amount we consume already. */ 3845d9945d78SBjoern A. Zeeb if (hw->wiphy->max_scan_ie_len > 0) 3846d9945d78SBjoern A. Zeeb hw->wiphy->max_scan_ie_len -= lhw->scan_ie_len; 3847d9945d78SBjoern A. Zeeb 38486b4cac81SBjoern A. Zeeb if (bootverbose) 38496b4cac81SBjoern A. Zeeb ieee80211_announce(ic); 38502e183d99SBjoern A. Zeeb 38512e183d99SBjoern A. Zeeb return (0); 38526b4cac81SBjoern A. Zeeb } 38536b4cac81SBjoern A. Zeeb 38546b4cac81SBjoern A. Zeeb void 38556b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ifdetach(struct ieee80211_hw *hw) 38566b4cac81SBjoern A. Zeeb { 38576b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 38586b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 38596b4cac81SBjoern A. Zeeb 38606b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 38616b4cac81SBjoern A. Zeeb ic = lhw->ic; 38626b4cac81SBjoern A. Zeeb ieee80211_ifdetach(ic); 38636b4cac81SBjoern A. Zeeb } 38646b4cac81SBjoern A. Zeeb 38656b4cac81SBjoern A. Zeeb void 38666b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_interfaces(struct ieee80211_hw *hw, 38676b4cac81SBjoern A. Zeeb enum ieee80211_iface_iter flags, 38686b4cac81SBjoern A. Zeeb void(*iterfunc)(void *, uint8_t *, struct ieee80211_vif *), 38696b4cac81SBjoern A. Zeeb void *arg) 38706b4cac81SBjoern A. Zeeb { 38716b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 38726b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 38736b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 387461a68e50SBjoern A. Zeeb bool active, atomic, nin_drv; 38756b4cac81SBjoern A. Zeeb 38766b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 38776b4cac81SBjoern A. Zeeb 38786b4cac81SBjoern A. Zeeb if (flags & ~(IEEE80211_IFACE_ITER_NORMAL| 38796b4cac81SBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL| 388061a68e50SBjoern A. Zeeb IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER| 3881adff403fSBjoern A. Zeeb IEEE80211_IFACE_ITER_ACTIVE|IEEE80211_IFACE_ITER__ATOMIC)) { 38826b4cac81SBjoern A. Zeeb ic_printf(lhw->ic, "XXX TODO %s flags(%#x) not yet supported.\n", 38836b4cac81SBjoern A. Zeeb __func__, flags); 38846b4cac81SBjoern A. Zeeb } 38856b4cac81SBjoern A. Zeeb 3886adff403fSBjoern A. Zeeb active = (flags & IEEE80211_IFACE_ITER_ACTIVE) != 0; 38876b4cac81SBjoern A. Zeeb atomic = (flags & IEEE80211_IFACE_ITER__ATOMIC) != 0; 388861a68e50SBjoern A. Zeeb nin_drv = (flags & IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER) != 0; 38896b4cac81SBjoern A. Zeeb 38906b4cac81SBjoern A. Zeeb if (atomic) 38918891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 38926b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 38936b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 38946b4cac81SBjoern A. Zeeb 38956b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 38966b4cac81SBjoern A. Zeeb 38976b4cac81SBjoern A. Zeeb /* 38986b4cac81SBjoern A. Zeeb * If we want "active" interfaces, we need to distinguish on 38996b4cac81SBjoern A. Zeeb * whether the driver knows about them or not to be able to 39006b4cac81SBjoern A. Zeeb * handle the "resume" case correctly. Skip the ones the 39016b4cac81SBjoern A. Zeeb * driver does not know about. 39026b4cac81SBjoern A. Zeeb */ 39036b4cac81SBjoern A. Zeeb if (active && !lvif->added_to_drv && 39046b4cac81SBjoern A. Zeeb (flags & IEEE80211_IFACE_ITER_RESUME_ALL) != 0) 39056b4cac81SBjoern A. Zeeb continue; 39066b4cac81SBjoern A. Zeeb 39076b4cac81SBjoern A. Zeeb /* 390861a68e50SBjoern A. Zeeb * If we shall skip interfaces not added to the driver do so 390961a68e50SBjoern A. Zeeb * if we haven't yet. 391061a68e50SBjoern A. Zeeb */ 391161a68e50SBjoern A. Zeeb if (nin_drv && !lvif->added_to_drv) 391261a68e50SBjoern A. Zeeb continue; 391361a68e50SBjoern A. Zeeb 391461a68e50SBjoern A. Zeeb /* 39156b4cac81SBjoern A. Zeeb * Run the iterator function if we are either not asking 39166b4cac81SBjoern A. Zeeb * asking for active only or if the VAP is "running". 39176b4cac81SBjoern A. Zeeb */ 39186b4cac81SBjoern A. Zeeb /* XXX-BZ probably should have state in the lvif as well. */ 39196b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 39206b4cac81SBjoern A. Zeeb if (!active || (vap->iv_state != IEEE80211_S_INIT)) 39216b4cac81SBjoern A. Zeeb iterfunc(arg, vif->addr, vif); 39226b4cac81SBjoern A. Zeeb } 39236b4cac81SBjoern A. Zeeb if (atomic) 39248891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 39256b4cac81SBjoern A. Zeeb } 39266b4cac81SBjoern A. Zeeb 39276b4cac81SBjoern A. Zeeb void 39286b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_keys(struct ieee80211_hw *hw, 39296b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif, 39306b4cac81SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_vif *, 39316b4cac81SBjoern A. Zeeb struct ieee80211_sta *, struct ieee80211_key_conf *, void *), 39326b4cac81SBjoern A. Zeeb void *arg) 39336b4cac81SBjoern A. Zeeb { 39346b4cac81SBjoern A. Zeeb 39356b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 39366b4cac81SBjoern A. Zeeb } 39376b4cac81SBjoern A. Zeeb 39386b4cac81SBjoern A. Zeeb void 39396b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_chan_contexts(struct ieee80211_hw *hw, 39406b4cac81SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_chanctx_conf *, 39416b4cac81SBjoern A. Zeeb void *), 39426b4cac81SBjoern A. Zeeb void *arg) 39436b4cac81SBjoern A. Zeeb { 39446b4cac81SBjoern A. Zeeb 39456b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 39466b4cac81SBjoern A. Zeeb } 39476b4cac81SBjoern A. Zeeb 39486b4cac81SBjoern A. Zeeb void 39496b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_stations_atomic(struct ieee80211_hw *hw, 39506b4cac81SBjoern A. Zeeb void (*iterfunc)(void *, struct ieee80211_sta *), void *arg) 39516b4cac81SBjoern A. Zeeb { 39526b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 39536b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 39546b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 39556b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 39566b4cac81SBjoern A. Zeeb 39576b4cac81SBjoern A. Zeeb KASSERT(hw != NULL && iterfunc != NULL, 39586b4cac81SBjoern A. Zeeb ("%s: hw %p iterfunc %p arg %p\n", __func__, hw, iterfunc, arg)); 39596b4cac81SBjoern A. Zeeb 39606b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 39616b4cac81SBjoern A. Zeeb 39628891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 39636b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 39646b4cac81SBjoern A. Zeeb 39656b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 39666b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lsta, &lvif->lsta_head, lsta_entry) { 39676b4cac81SBjoern A. Zeeb if (!lsta->added_to_drv) 39686b4cac81SBjoern A. Zeeb continue; 39696b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 39706b4cac81SBjoern A. Zeeb iterfunc(arg, sta); 39716b4cac81SBjoern A. Zeeb } 39726b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 39736b4cac81SBjoern A. Zeeb } 39748891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 39756b4cac81SBjoern A. Zeeb } 39766b4cac81SBjoern A. Zeeb 39776b4cac81SBjoern A. Zeeb int 39786b4cac81SBjoern A. Zeeb linuxkpi_regulatory_set_wiphy_regd_sync(struct wiphy *wiphy, 39796b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_regdomain *regd) 39806b4cac81SBjoern A. Zeeb { 39816b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 39826b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 39836b4cac81SBjoern A. Zeeb struct ieee80211_regdomain *rd; 39846b4cac81SBjoern A. Zeeb 39856b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 39866b4cac81SBjoern A. Zeeb ic = lhw->ic; 39876b4cac81SBjoern A. Zeeb 39886b4cac81SBjoern A. Zeeb rd = &ic->ic_regdomain; 39896b4cac81SBjoern A. Zeeb if (rd->isocc[0] == '\0') { 39906b4cac81SBjoern A. Zeeb rd->isocc[0] = regd->alpha2[0]; 39916b4cac81SBjoern A. Zeeb rd->isocc[1] = regd->alpha2[1]; 39926b4cac81SBjoern A. Zeeb } 39936b4cac81SBjoern A. Zeeb 39946b4cac81SBjoern A. Zeeb TODO(); 39956b4cac81SBjoern A. Zeeb /* XXX-BZ finish the rest. */ 39966b4cac81SBjoern A. Zeeb 39976b4cac81SBjoern A. Zeeb return (0); 39986b4cac81SBjoern A. Zeeb } 39996b4cac81SBjoern A. Zeeb 40006b4cac81SBjoern A. Zeeb void 40016b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_scan_completed(struct ieee80211_hw *hw, 40026b4cac81SBjoern A. Zeeb struct cfg80211_scan_info *info) 40036b4cac81SBjoern A. Zeeb { 40046b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 40056b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 40066b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 40076b4cac81SBjoern A. Zeeb 40086b4cac81SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 40096b4cac81SBjoern A. Zeeb ic = lhw->ic; 40106b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 40116b4cac81SBjoern A. Zeeb 40126b4cac81SBjoern A. Zeeb ieee80211_scan_done(ss->ss_vap); 40136b4cac81SBjoern A. Zeeb 40148ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 40156b4cac81SBjoern A. Zeeb free(lhw->hw_req, M_LKPI80211); 40166b4cac81SBjoern A. Zeeb lhw->hw_req = NULL; 4017a486fbbdSBjoern A. Zeeb lhw->scan_flags &= ~LKPI_LHW_SCAN_RUNNING; 40186b4cac81SBjoern A. Zeeb wakeup(lhw); 40198ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 40206b4cac81SBjoern A. Zeeb 40216b4cac81SBjoern A. Zeeb return; 40226b4cac81SBjoern A. Zeeb } 40236b4cac81SBjoern A. Zeeb 4024e30e05d3SBjoern A. Zeeb /* For %list see comment towards the end of the function. */ 40256b4cac81SBjoern A. Zeeb void 40266b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb, 4027e30e05d3SBjoern A. Zeeb struct ieee80211_sta *sta, struct napi_struct *napi __unused, 4028e30e05d3SBjoern A. Zeeb struct list_head *list __unused) 40296b4cac81SBjoern A. Zeeb { 40306b4cac81SBjoern A. Zeeb struct epoch_tracker et; 40316b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 40326b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 40336b4cac81SBjoern A. Zeeb struct mbuf *m; 40346b4cac81SBjoern A. Zeeb struct skb_shared_info *shinfo; 40356b4cac81SBjoern A. Zeeb struct ieee80211_rx_status *rx_status; 40366b4cac81SBjoern A. Zeeb struct ieee80211_rx_stats rx_stats; 40376b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 40386b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 40396b4cac81SBjoern A. Zeeb struct ieee80211_hdr *hdr; 40406b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 40419d9ba2b7SBjoern A. Zeeb int i, offset, ok; 4042170acccfSBjoern A. Zeeb int8_t rssi; 4043c0cadd99SBjoern A. Zeeb bool is_beacon; 40446b4cac81SBjoern A. Zeeb 40456b4cac81SBjoern A. Zeeb if (skb->len < 2) { 40466b4cac81SBjoern A. Zeeb /* Need 80211 stats here. */ 40476b4cac81SBjoern A. Zeeb IMPROVE(); 40486b4cac81SBjoern A. Zeeb goto err; 40496b4cac81SBjoern A. Zeeb } 40506b4cac81SBjoern A. Zeeb 40516b4cac81SBjoern A. Zeeb /* 40526b4cac81SBjoern A. Zeeb * For now do the data copy; we can later improve things. Might even 40536b4cac81SBjoern A. Zeeb * have an mbuf backing the skb data then? 40546b4cac81SBjoern A. Zeeb */ 40556b4cac81SBjoern A. Zeeb m = m_get2(skb->len, M_NOWAIT, MT_DATA, M_PKTHDR); 40566b4cac81SBjoern A. Zeeb if (m == NULL) 40576b4cac81SBjoern A. Zeeb goto err; 40586b4cac81SBjoern A. Zeeb m_copyback(m, 0, skb->tail - skb->data, skb->data); 40596b4cac81SBjoern A. Zeeb 40606b4cac81SBjoern A. Zeeb shinfo = skb_shinfo(skb); 40616b4cac81SBjoern A. Zeeb offset = m->m_len; 40626b4cac81SBjoern A. Zeeb for (i = 0; i < shinfo->nr_frags; i++) { 40636b4cac81SBjoern A. Zeeb m_copyback(m, offset, shinfo->frags[i].size, 40646b4cac81SBjoern A. Zeeb (uint8_t *)linux_page_address(shinfo->frags[i].page) + 40656b4cac81SBjoern A. Zeeb shinfo->frags[i].offset); 40666b4cac81SBjoern A. Zeeb offset += shinfo->frags[i].size; 40676b4cac81SBjoern A. Zeeb } 40686b4cac81SBjoern A. Zeeb 40696b4cac81SBjoern A. Zeeb rx_status = IEEE80211_SKB_RXCB(skb); 40706b4cac81SBjoern A. Zeeb 40716b4cac81SBjoern A. Zeeb hdr = (void *)skb->data; 4072c0cadd99SBjoern A. Zeeb is_beacon = ieee80211_is_beacon(hdr->frame_control); 4073c0cadd99SBjoern A. Zeeb 4074c0cadd99SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 40759d9ba2b7SBjoern A. Zeeb if (is_beacon && (linuxkpi_debug_80211 & D80211_TRACE_RX_BEACONS) == 0) 40766b4cac81SBjoern A. Zeeb goto no_trace_beacons; 40776b4cac81SBjoern A. Zeeb 40789d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 40796b4cac81SBjoern A. Zeeb printf("TRACE-RX: %s: skb %p a/l/d/t-len (%u/%u/%u/%u) " 4080c0cadd99SBjoern A. Zeeb "h %p d %p t %p e %p sh %p (%u) m %p plen %u len %u%s\n", 40816b4cac81SBjoern A. Zeeb __func__, skb, skb->_alloc_len, skb->len, skb->data_len, 40826b4cac81SBjoern A. Zeeb skb->truesize, skb->head, skb->data, skb->tail, skb->end, 40836b4cac81SBjoern A. Zeeb shinfo, shinfo->nr_frags, 4084c0cadd99SBjoern A. Zeeb m, m->m_pkthdr.len, m->m_len, is_beacon ? " beacon" : ""); 40856b4cac81SBjoern A. Zeeb 40869d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX_DUMP) 40876b4cac81SBjoern A. Zeeb hexdump(mtod(m, const void *), m->m_len, "RX (raw) ", 0); 40886b4cac81SBjoern A. Zeeb 40896b4cac81SBjoern A. Zeeb /* Implement a dump_rxcb() !!! */ 40909d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 4091c8dafefaSBjoern A. Zeeb printf("TRACE %s: RXCB: %ju %ju %u, %#0x, %u, %#0x, %#0x, " 409260970a32SBjoern A. Zeeb "%u band %u, %u { %d %d %d %d }, %d, %#x %#x %#x %#x %u %u %u\n", 40936b4cac81SBjoern A. Zeeb __func__, 4094c8dafefaSBjoern A. Zeeb (uintmax_t)rx_status->boottime_ns, 4095c8dafefaSBjoern A. Zeeb (uintmax_t)rx_status->mactime, 40966b4cac81SBjoern A. Zeeb rx_status->device_timestamp, 40976b4cac81SBjoern A. Zeeb rx_status->flag, 40986b4cac81SBjoern A. Zeeb rx_status->freq, 40996b4cac81SBjoern A. Zeeb rx_status->bw, 41006b4cac81SBjoern A. Zeeb rx_status->encoding, 41016b4cac81SBjoern A. Zeeb rx_status->ampdu_reference, 41026b4cac81SBjoern A. Zeeb rx_status->band, 41036b4cac81SBjoern A. Zeeb rx_status->chains, 41046b4cac81SBjoern A. Zeeb rx_status->chain_signal[0], 41056b4cac81SBjoern A. Zeeb rx_status->chain_signal[1], 41066b4cac81SBjoern A. Zeeb rx_status->chain_signal[2], 410760970a32SBjoern A. Zeeb rx_status->chain_signal[3], 41086b4cac81SBjoern A. Zeeb rx_status->signal, 41096b4cac81SBjoern A. Zeeb rx_status->enc_flags, 41106b4cac81SBjoern A. Zeeb rx_status->he_dcm, 41116b4cac81SBjoern A. Zeeb rx_status->he_gi, 41126b4cac81SBjoern A. Zeeb rx_status->he_ru, 41136b4cac81SBjoern A. Zeeb rx_status->zero_length_psdu_type, 41146b4cac81SBjoern A. Zeeb rx_status->nss, 41156b4cac81SBjoern A. Zeeb rx_status->rate_idx); 41166b4cac81SBjoern A. Zeeb no_trace_beacons: 41176b4cac81SBjoern A. Zeeb #endif 41186b4cac81SBjoern A. Zeeb 41196b4cac81SBjoern A. Zeeb memset(&rx_stats, 0, sizeof(rx_stats)); 41206b4cac81SBjoern A. Zeeb rx_stats.r_flags = IEEE80211_R_NF | IEEE80211_R_RSSI; 412160970a32SBjoern A. Zeeb /* XXX-BZ correct hardcoded rssi and noise floor, how? survey? */ 412260970a32SBjoern A. Zeeb rx_stats.c_nf = -96; 41236b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, SIGNAL_DBM) && 41246b4cac81SBjoern A. Zeeb !(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL)) 4125170acccfSBjoern A. Zeeb rssi = rx_status->signal; 41266b4cac81SBjoern A. Zeeb else 4127170acccfSBjoern A. Zeeb rssi = rx_stats.c_nf; 4128170acccfSBjoern A. Zeeb /* 4129170acccfSBjoern A. Zeeb * net80211 signal strength data are in .5 dBm units relative to 4130170acccfSBjoern A. Zeeb * the current noise floor (see comment in ieee80211_node.h). 4131170acccfSBjoern A. Zeeb */ 4132170acccfSBjoern A. Zeeb rssi -= rx_stats.c_nf; 4133170acccfSBjoern A. Zeeb rx_stats.c_rssi = rssi * 2; 41346b4cac81SBjoern A. Zeeb rx_stats.r_flags |= IEEE80211_R_BAND; 41356b4cac81SBjoern A. Zeeb rx_stats.c_band = 41366b4cac81SBjoern A. Zeeb lkpi_nl80211_band_to_net80211_band(rx_status->band); 41376b4cac81SBjoern A. Zeeb rx_stats.r_flags |= IEEE80211_R_FREQ | IEEE80211_R_IEEE; 41386b4cac81SBjoern A. Zeeb rx_stats.c_freq = rx_status->freq; 41396b4cac81SBjoern A. Zeeb rx_stats.c_ieee = ieee80211_mhz2ieee(rx_stats.c_freq, rx_stats.c_band); 41406b4cac81SBjoern A. Zeeb 41416b4cac81SBjoern A. Zeeb /* XXX (*sta_statistics)() to get to some of that? */ 41426b4cac81SBjoern A. Zeeb /* XXX-BZ dump the FreeBSD version of rx_stats as well! */ 41436b4cac81SBjoern A. Zeeb 41446b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 41456b4cac81SBjoern A. Zeeb ic = lhw->ic; 41466b4cac81SBjoern A. Zeeb 41476b4cac81SBjoern A. Zeeb ok = ieee80211_add_rx_params(m, &rx_stats); 41486b4cac81SBjoern A. Zeeb if (ok == 0) { 4149dbc06dd9SBjoern A. Zeeb m_freem(m); 41506b4cac81SBjoern A. Zeeb counter_u64_add(ic->ic_ierrors, 1); 41516b4cac81SBjoern A. Zeeb goto err; 41526b4cac81SBjoern A. Zeeb } 41536b4cac81SBjoern A. Zeeb 41546b4cac81SBjoern A. Zeeb if (sta != NULL) { 41556b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 41566b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(lsta->ni); 41576b4cac81SBjoern A. Zeeb } else { 4158c8dafefaSBjoern A. Zeeb struct ieee80211_frame_min *wh; 4159c8dafefaSBjoern A. Zeeb 41606b4cac81SBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame_min *); 41616b4cac81SBjoern A. Zeeb ni = ieee80211_find_rxnode(ic, wh); 41626b4cac81SBjoern A. Zeeb if (ni != NULL) 41636b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 41646b4cac81SBjoern A. Zeeb } 41656b4cac81SBjoern A. Zeeb 41666b4cac81SBjoern A. Zeeb if (ni != NULL) 41676b4cac81SBjoern A. Zeeb vap = ni->ni_vap; 41686b4cac81SBjoern A. Zeeb else 41696b4cac81SBjoern A. Zeeb /* 41706b4cac81SBjoern A. Zeeb * XXX-BZ can we improve this by looking at the frame hdr 41716b4cac81SBjoern A. Zeeb * or other meta-data passed up? 41726b4cac81SBjoern A. Zeeb */ 41736b4cac81SBjoern A. Zeeb vap = TAILQ_FIRST(&ic->ic_vaps); 41746b4cac81SBjoern A. Zeeb 41759d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 41769d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 4177c0cadd99SBjoern A. Zeeb printf("TRACE %s: sta %p lsta %p state %d ni %p vap %p%s\n", 4178c0cadd99SBjoern A. Zeeb __func__, sta, lsta, (lsta != NULL) ? lsta->state : -1, 4179c0cadd99SBjoern A. Zeeb ni, vap, is_beacon ? " beacon" : ""); 41809d9ba2b7SBjoern A. Zeeb #endif 41816b4cac81SBjoern A. Zeeb 4182c0cadd99SBjoern A. Zeeb if (ni != NULL && vap != NULL && is_beacon && 4183c8dafefaSBjoern A. Zeeb rx_status->device_timestamp > 0 && 4184c8dafefaSBjoern A. Zeeb m->m_pkthdr.len >= sizeof(struct ieee80211_frame)) { 4185c8dafefaSBjoern A. Zeeb struct lkpi_vif *lvif; 4186c8dafefaSBjoern A. Zeeb struct ieee80211_vif *vif; 4187c8dafefaSBjoern A. Zeeb struct ieee80211_frame *wh; 4188c8dafefaSBjoern A. Zeeb 4189c8dafefaSBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame *); 4190c8dafefaSBjoern A. Zeeb if (!IEEE80211_ADDR_EQ(wh->i_addr2, ni->ni_bssid)) 4191c8dafefaSBjoern A. Zeeb goto skip_device_ts; 4192c8dafefaSBjoern A. Zeeb 4193c8dafefaSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 4194c8dafefaSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 4195c8dafefaSBjoern A. Zeeb 4196c8dafefaSBjoern A. Zeeb IMPROVE("TIMING_BEACON_ONLY?"); 4197c8dafefaSBjoern A. Zeeb /* mac80211 specific (not net80211) so keep it here. */ 4198c8dafefaSBjoern A. Zeeb vif->bss_conf.sync_device_ts = rx_status->device_timestamp; 4199c8dafefaSBjoern A. Zeeb /* 4200c8dafefaSBjoern A. Zeeb * net80211 should take care of the other information (sync_tsf, 4201c8dafefaSBjoern A. Zeeb * sync_dtim_count) as otherwise we need to parse the beacon. 4202c8dafefaSBjoern A. Zeeb */ 4203c8dafefaSBjoern A. Zeeb } 4204c8dafefaSBjoern A. Zeeb skip_device_ts: 4205c8dafefaSBjoern A. Zeeb 42066b4cac81SBjoern A. Zeeb if (vap != NULL && vap->iv_state > IEEE80211_S_INIT && 42076b4cac81SBjoern A. Zeeb ieee80211_radiotap_active_vap(vap)) { 42086b4cac81SBjoern A. Zeeb struct lkpi_radiotap_rx_hdr *rtap; 42096b4cac81SBjoern A. Zeeb 42106b4cac81SBjoern A. Zeeb rtap = &lhw->rtap_rx; 42116b4cac81SBjoern A. Zeeb rtap->wr_tsft = rx_status->device_timestamp; 42126b4cac81SBjoern A. Zeeb rtap->wr_flags = 0; 42136b4cac81SBjoern A. Zeeb if (rx_status->enc_flags & RX_ENC_FLAG_SHORTPRE) 42146b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; 42156b4cac81SBjoern A. Zeeb if (rx_status->enc_flags & RX_ENC_FLAG_SHORT_GI) 42166b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTGI; 42176b4cac81SBjoern A. Zeeb #if 0 /* .. or it does not given we strip it below. */ 42186b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, RX_INCLUDES_FCS)) 42196b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_FCS; 42206b4cac81SBjoern A. Zeeb #endif 42216b4cac81SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_FAILED_FCS_CRC) 42226b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_BADFCS; 42236b4cac81SBjoern A. Zeeb rtap->wr_rate = 0; 42246b4cac81SBjoern A. Zeeb IMPROVE(); 42256b4cac81SBjoern A. Zeeb /* XXX TODO status->encoding / rate_index / bw */ 42266b4cac81SBjoern A. Zeeb rtap->wr_chan_freq = htole16(rx_stats.c_freq); 42276b4cac81SBjoern A. Zeeb if (ic->ic_curchan->ic_ieee == rx_stats.c_ieee) 42286b4cac81SBjoern A. Zeeb rtap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags); 4229170acccfSBjoern A. Zeeb rtap->wr_dbm_antsignal = rssi; 42306b4cac81SBjoern A. Zeeb rtap->wr_dbm_antnoise = rx_stats.c_nf; 42316b4cac81SBjoern A. Zeeb } 42326b4cac81SBjoern A. Zeeb 42336b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, RX_INCLUDES_FCS)) 42346b4cac81SBjoern A. Zeeb m_adj(m, -IEEE80211_CRC_LEN); 42356b4cac81SBjoern A. Zeeb 4236e30e05d3SBjoern A. Zeeb #if 0 4237e30e05d3SBjoern A. Zeeb if (list != NULL) { 4238e30e05d3SBjoern A. Zeeb /* 4239e30e05d3SBjoern A. Zeeb * Normally this would be queued up and delivered by 4240e30e05d3SBjoern A. Zeeb * netif_receive_skb_list(), napi_gro_receive(), or the like. 4241e30e05d3SBjoern A. Zeeb * See mt76::mac80211.c as only current possible consumer. 4242e30e05d3SBjoern A. Zeeb */ 4243e30e05d3SBjoern A. Zeeb IMPROVE("we simply pass the packet to net80211 to deal with."); 4244e30e05d3SBjoern A. Zeeb } 4245e30e05d3SBjoern A. Zeeb #endif 4246e30e05d3SBjoern A. Zeeb 42476b4cac81SBjoern A. Zeeb NET_EPOCH_ENTER(et); 42486b4cac81SBjoern A. Zeeb if (ni != NULL) { 42499d9ba2b7SBjoern A. Zeeb ok = ieee80211_input_mimo(ni, m); 42506b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 4251dbc06dd9SBjoern A. Zeeb if (ok < 0) 4252dbc06dd9SBjoern A. Zeeb m_freem(m); 42536b4cac81SBjoern A. Zeeb } else { 42549d9ba2b7SBjoern A. Zeeb ok = ieee80211_input_mimo_all(ic, m); 4255dbc06dd9SBjoern A. Zeeb /* mbuf got consumed. */ 42566b4cac81SBjoern A. Zeeb } 42576b4cac81SBjoern A. Zeeb NET_EPOCH_EXIT(et); 42586b4cac81SBjoern A. Zeeb 42599d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 42609d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 42619d9ba2b7SBjoern A. Zeeb printf("TRACE %s: handled frame type %#0x\n", __func__, ok); 42629d9ba2b7SBjoern A. Zeeb #endif 42636b4cac81SBjoern A. Zeeb 42646b4cac81SBjoern A. Zeeb IMPROVE(); 42656b4cac81SBjoern A. Zeeb 42666b4cac81SBjoern A. Zeeb err: 42676b4cac81SBjoern A. Zeeb /* The skb is ours so we can free it :-) */ 42686b4cac81SBjoern A. Zeeb kfree_skb(skb); 42696b4cac81SBjoern A. Zeeb } 42706b4cac81SBjoern A. Zeeb 42716b4cac81SBjoern A. Zeeb uint8_t 4272ec190d91SBjoern A. Zeeb linuxkpi_ieee80211_get_tid(struct ieee80211_hdr *hdr, bool nonqos_ok) 42736b4cac81SBjoern A. Zeeb { 42746b4cac81SBjoern A. Zeeb const struct ieee80211_frame *wh; 4275ec190d91SBjoern A. Zeeb uint8_t tid; 4276ec190d91SBjoern A. Zeeb 4277ec190d91SBjoern A. Zeeb /* Linux seems to assume this is a QOS-Data-Frame */ 4278ec190d91SBjoern A. Zeeb KASSERT(nonqos_ok || ieee80211_is_data_qos(hdr->frame_control), 4279ec190d91SBjoern A. Zeeb ("%s: hdr %p fc %#06x not qos_data\n", __func__, hdr, 4280ec190d91SBjoern A. Zeeb hdr->frame_control)); 42816b4cac81SBjoern A. Zeeb 42826b4cac81SBjoern A. Zeeb wh = (const struct ieee80211_frame *)hdr; 4283ec190d91SBjoern A. Zeeb tid = ieee80211_gettid(wh); 4284ec190d91SBjoern A. Zeeb KASSERT(nonqos_ok || tid == (tid & IEEE80211_QOS_TID), ("%s: tid %u " 4285ec190d91SBjoern A. Zeeb "not expected (%u?)\n", __func__, tid, IEEE80211_NONQOS_TID)); 4286ec190d91SBjoern A. Zeeb 4287ec190d91SBjoern A. Zeeb return (tid); 42886b4cac81SBjoern A. Zeeb } 42896b4cac81SBjoern A. Zeeb 42906b4cac81SBjoern A. Zeeb struct wiphy * 42916b4cac81SBjoern A. Zeeb linuxkpi_wiphy_new(const struct cfg80211_ops *ops, size_t priv_len) 42926b4cac81SBjoern A. Zeeb { 42936b4cac81SBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 42946b4cac81SBjoern A. Zeeb 42956b4cac81SBjoern A. Zeeb lwiphy = kzalloc(sizeof(*lwiphy) + priv_len, GFP_KERNEL); 42966b4cac81SBjoern A. Zeeb if (lwiphy == NULL) 42976b4cac81SBjoern A. Zeeb return (NULL); 42986b4cac81SBjoern A. Zeeb lwiphy->ops = ops; 42996b4cac81SBjoern A. Zeeb 43006b4cac81SBjoern A. Zeeb /* XXX TODO */ 43016b4cac81SBjoern A. Zeeb return (LWIPHY_TO_WIPHY(lwiphy)); 43026b4cac81SBjoern A. Zeeb } 43036b4cac81SBjoern A. Zeeb 43046b4cac81SBjoern A. Zeeb void 43056b4cac81SBjoern A. Zeeb linuxkpi_wiphy_free(struct wiphy *wiphy) 43066b4cac81SBjoern A. Zeeb { 43076b4cac81SBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 43086b4cac81SBjoern A. Zeeb 43096b4cac81SBjoern A. Zeeb if (wiphy == NULL) 43106b4cac81SBjoern A. Zeeb return; 43116b4cac81SBjoern A. Zeeb 43126b4cac81SBjoern A. Zeeb lwiphy = WIPHY_TO_LWIPHY(wiphy); 43136b4cac81SBjoern A. Zeeb kfree(lwiphy); 43146b4cac81SBjoern A. Zeeb } 43156b4cac81SBjoern A. Zeeb 43166b4cac81SBjoern A. Zeeb uint32_t 43176b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_channel_to_frequency(uint32_t channel, 43186b4cac81SBjoern A. Zeeb enum nl80211_band band) 43196b4cac81SBjoern A. Zeeb { 43206b4cac81SBjoern A. Zeeb 43216b4cac81SBjoern A. Zeeb switch (band) { 43226b4cac81SBjoern A. Zeeb case NL80211_BAND_2GHZ: 43236b4cac81SBjoern A. Zeeb return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_2GHZ)); 43246b4cac81SBjoern A. Zeeb break; 43256b4cac81SBjoern A. Zeeb case NL80211_BAND_5GHZ: 43266b4cac81SBjoern A. Zeeb return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_5GHZ)); 43276b4cac81SBjoern A. Zeeb break; 43286b4cac81SBjoern A. Zeeb default: 43296b4cac81SBjoern A. Zeeb /* XXX abort, retry, error, panic? */ 43306b4cac81SBjoern A. Zeeb break; 43316b4cac81SBjoern A. Zeeb } 43326b4cac81SBjoern A. Zeeb 43336b4cac81SBjoern A. Zeeb return (0); 43346b4cac81SBjoern A. Zeeb } 43356b4cac81SBjoern A. Zeeb 43366b4cac81SBjoern A. Zeeb uint32_t 43376b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_frequency_to_channel(uint32_t freq, uint32_t flags __unused) 43386b4cac81SBjoern A. Zeeb { 43396b4cac81SBjoern A. Zeeb 43406b4cac81SBjoern A. Zeeb return (ieee80211_mhz2ieee(freq, 0)); 43416b4cac81SBjoern A. Zeeb } 43426b4cac81SBjoern A. Zeeb 43436b4cac81SBjoern A. Zeeb static struct lkpi_sta * 43446b4cac81SBjoern A. Zeeb lkpi_find_lsta_by_ni(struct lkpi_vif *lvif, struct ieee80211_node *ni) 43456b4cac81SBjoern A. Zeeb { 43466b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta, *temp; 43476b4cac81SBjoern A. Zeeb 43486b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 43496b4cac81SBjoern A. Zeeb TAILQ_FOREACH_SAFE(lsta, &lvif->lsta_head, lsta_entry, temp) { 43506b4cac81SBjoern A. Zeeb if (lsta->ni == ni) { 43516b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 43526b4cac81SBjoern A. Zeeb return (lsta); 43536b4cac81SBjoern A. Zeeb } 43546b4cac81SBjoern A. Zeeb } 43556b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 43566b4cac81SBjoern A. Zeeb 43576b4cac81SBjoern A. Zeeb return (NULL); 43586b4cac81SBjoern A. Zeeb } 43596b4cac81SBjoern A. Zeeb 43606b4cac81SBjoern A. Zeeb struct ieee80211_sta * 43616b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_find_sta(struct ieee80211_vif *vif, const u8 *peer) 43626b4cac81SBjoern A. Zeeb { 43636b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 43646b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta, *temp; 43656b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 43666b4cac81SBjoern A. Zeeb 43676b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 43686b4cac81SBjoern A. Zeeb 43696b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 43706b4cac81SBjoern A. Zeeb TAILQ_FOREACH_SAFE(lsta, &lvif->lsta_head, lsta_entry, temp) { 43716b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 43726b4cac81SBjoern A. Zeeb if (IEEE80211_ADDR_EQ(sta->addr, peer)) { 43736b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 43746b4cac81SBjoern A. Zeeb return (sta); 43756b4cac81SBjoern A. Zeeb } 43766b4cac81SBjoern A. Zeeb } 43776b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 43786b4cac81SBjoern A. Zeeb return (NULL); 43796b4cac81SBjoern A. Zeeb } 43806b4cac81SBjoern A. Zeeb 43816b4cac81SBjoern A. Zeeb struct ieee80211_sta * 43822e183d99SBjoern A. Zeeb linuxkpi_ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw, 43832e183d99SBjoern A. Zeeb const uint8_t *addr, const uint8_t *ourvifaddr) 43846b4cac81SBjoern A. Zeeb { 43856b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 43866b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 43876b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 43886b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 43896b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 43906b4cac81SBjoern A. Zeeb 43916b4cac81SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 43926b4cac81SBjoern A. Zeeb sta = NULL; 43936b4cac81SBjoern A. Zeeb 43948891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 43956b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 43966b4cac81SBjoern A. Zeeb 43976b4cac81SBjoern A. Zeeb /* XXX-BZ check our address from the vif. */ 43986b4cac81SBjoern A. Zeeb 43996b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 44006b4cac81SBjoern A. Zeeb if (ourvifaddr != NULL && 44016b4cac81SBjoern A. Zeeb !IEEE80211_ADDR_EQ(vif->addr, ourvifaddr)) 44026b4cac81SBjoern A. Zeeb continue; 44036b4cac81SBjoern A. Zeeb sta = linuxkpi_ieee80211_find_sta(vif, addr); 44046b4cac81SBjoern A. Zeeb if (sta != NULL) 44056b4cac81SBjoern A. Zeeb break; 44066b4cac81SBjoern A. Zeeb } 44078891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 44086b4cac81SBjoern A. Zeeb 44096b4cac81SBjoern A. Zeeb if (sta != NULL) { 44106b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 44116b4cac81SBjoern A. Zeeb if (!lsta->added_to_drv) 44126b4cac81SBjoern A. Zeeb return (NULL); 44136b4cac81SBjoern A. Zeeb } 44146b4cac81SBjoern A. Zeeb 44156b4cac81SBjoern A. Zeeb return (sta); 44166b4cac81SBjoern A. Zeeb } 44176b4cac81SBjoern A. Zeeb 44186b4cac81SBjoern A. Zeeb struct sk_buff * 44196b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_tx_dequeue(struct ieee80211_hw *hw, 44206b4cac81SBjoern A. Zeeb struct ieee80211_txq *txq) 44216b4cac81SBjoern A. Zeeb { 44226b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 44230cbcfa19SBjoern A. Zeeb struct lkpi_vif *lvif; 44246b4cac81SBjoern A. Zeeb struct sk_buff *skb; 44256b4cac81SBjoern A. Zeeb 44260cbcfa19SBjoern A. Zeeb skb = NULL; 44276b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 44286b4cac81SBjoern A. Zeeb ltxq->seen_dequeue = true; 44296b4cac81SBjoern A. Zeeb 44300cbcfa19SBjoern A. Zeeb if (ltxq->stopped) 44310cbcfa19SBjoern A. Zeeb goto stopped; 44320cbcfa19SBjoern A. Zeeb 44330cbcfa19SBjoern A. Zeeb lvif = VIF_TO_LVIF(ltxq->txq.vif); 44340cbcfa19SBjoern A. Zeeb if (lvif->hw_queue_stopped[ltxq->txq.ac]) { 44350cbcfa19SBjoern A. Zeeb ltxq->stopped = true; 44360cbcfa19SBjoern A. Zeeb goto stopped; 44370cbcfa19SBjoern A. Zeeb } 44380cbcfa19SBjoern A. Zeeb 44396b4cac81SBjoern A. Zeeb skb = skb_dequeue(<xq->skbq); 44406b4cac81SBjoern A. Zeeb 44410cbcfa19SBjoern A. Zeeb stopped: 44426b4cac81SBjoern A. Zeeb return (skb); 44436b4cac81SBjoern A. Zeeb } 44446b4cac81SBjoern A. Zeeb 44456b4cac81SBjoern A. Zeeb void 44466b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_txq_get_depth(struct ieee80211_txq *txq, 444786220d3cSBjoern A. Zeeb unsigned long *frame_cnt, unsigned long *byte_cnt) 44486b4cac81SBjoern A. Zeeb { 44496b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 44506b4cac81SBjoern A. Zeeb struct sk_buff *skb; 445186220d3cSBjoern A. Zeeb unsigned long fc, bc; 44526b4cac81SBjoern A. Zeeb 44536b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 44546b4cac81SBjoern A. Zeeb 44556b4cac81SBjoern A. Zeeb fc = bc = 0; 44566b4cac81SBjoern A. Zeeb skb_queue_walk(<xq->skbq, skb) { 44576b4cac81SBjoern A. Zeeb fc++; 44586b4cac81SBjoern A. Zeeb bc += skb->len; 44596b4cac81SBjoern A. Zeeb } 44606b4cac81SBjoern A. Zeeb if (frame_cnt) 44616b4cac81SBjoern A. Zeeb *frame_cnt = fc; 44626b4cac81SBjoern A. Zeeb if (byte_cnt) 44636b4cac81SBjoern A. Zeeb *byte_cnt = bc; 44646b4cac81SBjoern A. Zeeb 44656b4cac81SBjoern A. Zeeb /* Validate that this is doing the correct thing. */ 44666b4cac81SBjoern A. Zeeb /* Should we keep track on en/dequeue? */ 44676b4cac81SBjoern A. Zeeb IMPROVE(); 44686b4cac81SBjoern A. Zeeb } 44696b4cac81SBjoern A. Zeeb 44706b4cac81SBjoern A. Zeeb /* 44716b4cac81SBjoern A. Zeeb * We are called from ieee80211_free_txskb() or ieee80211_tx_status(). 44726b4cac81SBjoern A. Zeeb * The latter tries to derive the success status from the info flags 44736b4cac81SBjoern A. Zeeb * passed back from the driver. rawx_mit() saves the ni on the m and the 44746b4cac81SBjoern A. Zeeb * m on the skb for us to be able to give feedback to net80211. 44756b4cac81SBjoern A. Zeeb */ 4476a8397571SBjoern A. Zeeb static void 4477a8397571SBjoern A. Zeeb _lkpi_ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb, 44786b4cac81SBjoern A. Zeeb int status) 44796b4cac81SBjoern A. Zeeb { 44806b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 44816b4cac81SBjoern A. Zeeb struct mbuf *m; 44826b4cac81SBjoern A. Zeeb 44836b4cac81SBjoern A. Zeeb m = skb->m; 44846b4cac81SBjoern A. Zeeb skb->m = NULL; 44856b4cac81SBjoern A. Zeeb 44866b4cac81SBjoern A. Zeeb if (m != NULL) { 44876b4cac81SBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 44886b4cac81SBjoern A. Zeeb /* Status: 0 is ok, != 0 is error. */ 44896b4cac81SBjoern A. Zeeb ieee80211_tx_complete(ni, m, status); 44906b4cac81SBjoern A. Zeeb /* ni & mbuf were consumed. */ 44916b4cac81SBjoern A. Zeeb } 4492a8397571SBjoern A. Zeeb } 44936b4cac81SBjoern A. Zeeb 4494a8397571SBjoern A. Zeeb void 4495a8397571SBjoern A. Zeeb linuxkpi_ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb, 4496a8397571SBjoern A. Zeeb int status) 4497a8397571SBjoern A. Zeeb { 4498a8397571SBjoern A. Zeeb 4499a8397571SBjoern A. Zeeb _lkpi_ieee80211_free_txskb(hw, skb, status); 45006b4cac81SBjoern A. Zeeb kfree_skb(skb); 45016b4cac81SBjoern A. Zeeb } 45026b4cac81SBjoern A. Zeeb 4503383b3e8fSBjoern A. Zeeb void 4504a8397571SBjoern A. Zeeb linuxkpi_ieee80211_tx_status_ext(struct ieee80211_hw *hw, 4505a8397571SBjoern A. Zeeb struct ieee80211_tx_status *txstat) 4506383b3e8fSBjoern A. Zeeb { 4507a8397571SBjoern A. Zeeb struct sk_buff *skb; 4508383b3e8fSBjoern A. Zeeb struct ieee80211_tx_info *info; 4509383b3e8fSBjoern A. Zeeb struct ieee80211_ratectl_tx_status txs; 4510383b3e8fSBjoern A. Zeeb struct ieee80211_node *ni; 4511383b3e8fSBjoern A. Zeeb int status; 4512383b3e8fSBjoern A. Zeeb 4513a8397571SBjoern A. Zeeb skb = txstat->skb; 4514383b3e8fSBjoern A. Zeeb if (skb->m != NULL) { 4515383b3e8fSBjoern A. Zeeb struct mbuf *m; 4516383b3e8fSBjoern A. Zeeb 4517383b3e8fSBjoern A. Zeeb m = skb->m; 4518383b3e8fSBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 4519383b3e8fSBjoern A. Zeeb memset(&txs, 0, sizeof(txs)); 4520383b3e8fSBjoern A. Zeeb } else { 4521383b3e8fSBjoern A. Zeeb ni = NULL; 4522383b3e8fSBjoern A. Zeeb } 4523383b3e8fSBjoern A. Zeeb 4524a8397571SBjoern A. Zeeb info = txstat->info; 4525383b3e8fSBjoern A. Zeeb if (info->flags & IEEE80211_TX_STAT_ACK) { 4526383b3e8fSBjoern A. Zeeb status = 0; /* No error. */ 4527383b3e8fSBjoern A. Zeeb txs.status = IEEE80211_RATECTL_TX_SUCCESS; 4528383b3e8fSBjoern A. Zeeb } else { 4529383b3e8fSBjoern A. Zeeb status = 1; 4530383b3e8fSBjoern A. Zeeb txs.status = IEEE80211_RATECTL_TX_FAIL_UNSPECIFIED; 4531383b3e8fSBjoern A. Zeeb } 4532383b3e8fSBjoern A. Zeeb 4533383b3e8fSBjoern A. Zeeb if (ni != NULL) { 4534e2c5ab09SJohn Baldwin int ridx __unused; 4535383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 4536383b3e8fSBjoern A. Zeeb int old_rate; 4537383b3e8fSBjoern A. Zeeb 4538383b3e8fSBjoern A. Zeeb old_rate = ni->ni_vap->iv_bss->ni_txrate; 4539383b3e8fSBjoern A. Zeeb #endif 4540383b3e8fSBjoern A. Zeeb txs.pktlen = skb->len; 4541383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_PKTLEN; 4542383b3e8fSBjoern A. Zeeb if (info->status.rates[0].count > 1) { 4543383b3e8fSBjoern A. Zeeb txs.long_retries = info->status.rates[0].count - 1; /* 1 + retries in drivers. */ 4544383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_LONG_RETRY; 4545383b3e8fSBjoern A. Zeeb } 4546383b3e8fSBjoern A. Zeeb #if 0 /* Unused in net80211 currently. */ 4547a8397571SBjoern A. Zeeb /* XXX-BZ convert check .flags for MCS/VHT/.. */ 4548383b3e8fSBjoern A. Zeeb txs.final_rate = info->status.rates[0].idx; 4549383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_FINAL_RATE; 4550383b3e8fSBjoern A. Zeeb #endif 4551adff403fSBjoern A. Zeeb if (info->status.flags & IEEE80211_TX_STATUS_ACK_SIGNAL_VALID) { 4552383b3e8fSBjoern A. Zeeb txs.rssi = info->status.ack_signal; /* XXX-BZ CONVERT? */ 4553383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_RSSI; 4554383b3e8fSBjoern A. Zeeb } 4555383b3e8fSBjoern A. Zeeb 4556383b3e8fSBjoern A. Zeeb IMPROVE("only update of rate matches but that requires us to get a proper rate"); 4557383b3e8fSBjoern A. Zeeb ieee80211_ratectl_tx_complete(ni, &txs); 4558383b3e8fSBjoern A. Zeeb ridx = ieee80211_ratectl_rate(ni->ni_vap->iv_bss, NULL, 0); 4559383b3e8fSBjoern A. Zeeb 4560383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 4561383b3e8fSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) { 4562383b3e8fSBjoern A. Zeeb printf("TX-RATE: %s: old %d new %d ridx %d, " 4563383b3e8fSBjoern A. Zeeb "long_retries %d\n", __func__, 4564383b3e8fSBjoern A. Zeeb old_rate, ni->ni_vap->iv_bss->ni_txrate, 4565383b3e8fSBjoern A. Zeeb ridx, txs.long_retries); 4566383b3e8fSBjoern A. Zeeb } 4567383b3e8fSBjoern A. Zeeb #endif 4568383b3e8fSBjoern A. Zeeb } 4569383b3e8fSBjoern A. Zeeb 4570383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 4571383b3e8fSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 4572383b3e8fSBjoern A. Zeeb printf("TX-STATUS: %s: hw %p skb %p status %d : flags %#x " 4573383b3e8fSBjoern A. Zeeb "band %u hw_queue %u tx_time_est %d : " 4574383b3e8fSBjoern A. Zeeb "rates [ %u %u %#x, %u %u %#x, %u %u %#x, %u %u %#x ] " 4575383b3e8fSBjoern A. Zeeb "ack_signal %u ampdu_ack_len %u ampdu_len %u antenna %u " 4576adff403fSBjoern A. Zeeb "tx_time %u flags %#x " 4577383b3e8fSBjoern A. Zeeb "status_driver_data [ %p %p ]\n", 4578383b3e8fSBjoern A. Zeeb __func__, hw, skb, status, info->flags, 4579383b3e8fSBjoern A. Zeeb info->band, info->hw_queue, info->tx_time_est, 4580383b3e8fSBjoern A. Zeeb info->status.rates[0].idx, info->status.rates[0].count, 4581383b3e8fSBjoern A. Zeeb info->status.rates[0].flags, 4582383b3e8fSBjoern A. Zeeb info->status.rates[1].idx, info->status.rates[1].count, 4583383b3e8fSBjoern A. Zeeb info->status.rates[1].flags, 4584383b3e8fSBjoern A. Zeeb info->status.rates[2].idx, info->status.rates[2].count, 4585383b3e8fSBjoern A. Zeeb info->status.rates[2].flags, 4586383b3e8fSBjoern A. Zeeb info->status.rates[3].idx, info->status.rates[3].count, 4587383b3e8fSBjoern A. Zeeb info->status.rates[3].flags, 4588383b3e8fSBjoern A. Zeeb info->status.ack_signal, info->status.ampdu_ack_len, 4589383b3e8fSBjoern A. Zeeb info->status.ampdu_len, info->status.antenna, 4590adff403fSBjoern A. Zeeb info->status.tx_time, info->status.flags, 4591383b3e8fSBjoern A. Zeeb info->status.status_driver_data[0], 4592383b3e8fSBjoern A. Zeeb info->status.status_driver_data[1]); 4593383b3e8fSBjoern A. Zeeb #endif 4594383b3e8fSBjoern A. Zeeb 4595a8397571SBjoern A. Zeeb if (txstat->free_list) { 4596a8397571SBjoern A. Zeeb _lkpi_ieee80211_free_txskb(hw, skb, status); 4597a8397571SBjoern A. Zeeb list_add_tail(&skb->list, txstat->free_list); 4598a8397571SBjoern A. Zeeb } else { 4599383b3e8fSBjoern A. Zeeb linuxkpi_ieee80211_free_txskb(hw, skb, status); 4600383b3e8fSBjoern A. Zeeb } 4601a8397571SBjoern A. Zeeb } 4602a8397571SBjoern A. Zeeb 4603a8397571SBjoern A. Zeeb void 4604a8397571SBjoern A. Zeeb linuxkpi_ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb) 4605a8397571SBjoern A. Zeeb { 4606a8397571SBjoern A. Zeeb struct ieee80211_tx_status status; 4607a8397571SBjoern A. Zeeb 4608a8397571SBjoern A. Zeeb memset(&status, 0, sizeof(status)); 4609a8397571SBjoern A. Zeeb status.info = IEEE80211_SKB_CB(skb); 4610a8397571SBjoern A. Zeeb status.skb = skb; 4611a8397571SBjoern A. Zeeb /* sta, n_rates, rates, free_list? */ 4612a8397571SBjoern A. Zeeb 4613a8397571SBjoern A. Zeeb ieee80211_tx_status_ext(hw, &status); 4614a8397571SBjoern A. Zeeb } 4615383b3e8fSBjoern A. Zeeb 46166b4cac81SBjoern A. Zeeb /* 46176b4cac81SBjoern A. Zeeb * This is an internal bandaid for the moment for the way we glue 46186b4cac81SBjoern A. Zeeb * skbs and mbufs together for TX. Once we have skbs backed by 46196b4cac81SBjoern A. Zeeb * mbufs this should go away. 46206b4cac81SBjoern A. Zeeb * This is a public function but kept on the private KPI (lkpi_) 46216b4cac81SBjoern A. Zeeb * and is not exposed by a header file. 46226b4cac81SBjoern A. Zeeb */ 46236b4cac81SBjoern A. Zeeb static void 46246b4cac81SBjoern A. Zeeb lkpi_ieee80211_free_skb_mbuf(void *p) 46256b4cac81SBjoern A. Zeeb { 46266b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 46276b4cac81SBjoern A. Zeeb struct mbuf *m; 46286b4cac81SBjoern A. Zeeb 46296b4cac81SBjoern A. Zeeb if (p == NULL) 46306b4cac81SBjoern A. Zeeb return; 46316b4cac81SBjoern A. Zeeb 46326b4cac81SBjoern A. Zeeb m = (struct mbuf *)p; 46336b4cac81SBjoern A. Zeeb M_ASSERTPKTHDR(m); 46346b4cac81SBjoern A. Zeeb 46356b4cac81SBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 46366b4cac81SBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = NULL; 46376b4cac81SBjoern A. Zeeb if (ni != NULL) 46386b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 46396b4cac81SBjoern A. Zeeb m_freem(m); 46406b4cac81SBjoern A. Zeeb } 46416b4cac81SBjoern A. Zeeb 46426b4cac81SBjoern A. Zeeb void 46436b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_queue_delayed_work(struct ieee80211_hw *hw, 46446b4cac81SBjoern A. Zeeb struct delayed_work *w, int delay) 46456b4cac81SBjoern A. Zeeb { 46466b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 46476b4cac81SBjoern A. Zeeb 46486b4cac81SBjoern A. Zeeb /* Need to make sure hw is in a stable (non-suspended) state. */ 46496b4cac81SBjoern A. Zeeb IMPROVE(); 46506b4cac81SBjoern A. Zeeb 46516b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 46526b4cac81SBjoern A. Zeeb queue_delayed_work(lhw->workq, w, delay); 46536b4cac81SBjoern A. Zeeb } 46546b4cac81SBjoern A. Zeeb 46556b4cac81SBjoern A. Zeeb void 46566b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_queue_work(struct ieee80211_hw *hw, 46576b4cac81SBjoern A. Zeeb struct work_struct *w) 46586b4cac81SBjoern A. Zeeb { 46596b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 46606b4cac81SBjoern A. Zeeb 46616b4cac81SBjoern A. Zeeb /* Need to make sure hw is in a stable (non-suspended) state. */ 46626b4cac81SBjoern A. Zeeb IMPROVE(); 46636b4cac81SBjoern A. Zeeb 46646b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 46656b4cac81SBjoern A. Zeeb queue_work(lhw->workq, w); 46666b4cac81SBjoern A. Zeeb } 46676b4cac81SBjoern A. Zeeb 46686b4cac81SBjoern A. Zeeb struct sk_buff * 4669ade774b1SBjoern A. Zeeb linuxkpi_ieee80211_probereq_get(struct ieee80211_hw *hw, uint8_t *addr, 4670ade774b1SBjoern A. Zeeb uint8_t *ssid, size_t ssid_len, size_t tailroom) 4671ade774b1SBjoern A. Zeeb { 4672ade774b1SBjoern A. Zeeb struct sk_buff *skb; 4673ade774b1SBjoern A. Zeeb struct ieee80211_frame *wh; 4674ade774b1SBjoern A. Zeeb uint8_t *p; 4675ade774b1SBjoern A. Zeeb size_t len; 4676ade774b1SBjoern A. Zeeb 4677ade774b1SBjoern A. Zeeb len = sizeof(*wh); 4678ade774b1SBjoern A. Zeeb len += 2 + ssid_len; 4679ade774b1SBjoern A. Zeeb 4680ade774b1SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + len + tailroom); 4681ade774b1SBjoern A. Zeeb if (skb == NULL) 4682ade774b1SBjoern A. Zeeb return (NULL); 4683ade774b1SBjoern A. Zeeb 4684ade774b1SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 4685ade774b1SBjoern A. Zeeb 4686ade774b1SBjoern A. Zeeb wh = skb_put_zero(skb, sizeof(*wh)); 4687ade774b1SBjoern A. Zeeb wh->i_fc[0] = IEEE80211_FC0_VERSION_0; 4688ade774b1SBjoern A. Zeeb wh->i_fc[0] |= IEEE80211_FC0_SUBTYPE_PROBE_REQ | IEEE80211_FC0_TYPE_MGT; 4689ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr1, ieee80211broadcastaddr); 4690ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr2, addr); 4691ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr3, ieee80211broadcastaddr); 4692ade774b1SBjoern A. Zeeb 4693ade774b1SBjoern A. Zeeb p = skb_put(skb, 2 + ssid_len); 4694ade774b1SBjoern A. Zeeb *p++ = IEEE80211_ELEMID_SSID; 4695ade774b1SBjoern A. Zeeb *p++ = ssid_len; 4696ade774b1SBjoern A. Zeeb if (ssid_len > 0) 4697ade774b1SBjoern A. Zeeb memcpy(p, ssid, ssid_len); 4698ade774b1SBjoern A. Zeeb 4699ade774b1SBjoern A. Zeeb return (skb); 4700ade774b1SBjoern A. Zeeb } 4701ade774b1SBjoern A. Zeeb 4702ade774b1SBjoern A. Zeeb struct sk_buff * 47036b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_pspoll_get(struct ieee80211_hw *hw, 47046b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif) 47056b4cac81SBjoern A. Zeeb { 47066b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 47076b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 47086b4cac81SBjoern A. Zeeb struct sk_buff *skb; 47096b4cac81SBjoern A. Zeeb struct ieee80211_frame_pspoll *psp; 47106b4cac81SBjoern A. Zeeb uint16_t v; 47116b4cac81SBjoern A. Zeeb 47126b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*psp)); 47136b4cac81SBjoern A. Zeeb if (skb == NULL) 47146b4cac81SBjoern A. Zeeb return (NULL); 47156b4cac81SBjoern A. Zeeb 47166b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 47176b4cac81SBjoern A. Zeeb 47186b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 47196b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 47206b4cac81SBjoern A. Zeeb 47216b4cac81SBjoern A. Zeeb psp = skb_put_zero(skb, sizeof(*psp)); 47226b4cac81SBjoern A. Zeeb psp->i_fc[0] = IEEE80211_FC0_VERSION_0; 47236b4cac81SBjoern A. Zeeb psp->i_fc[0] |= IEEE80211_FC0_SUBTYPE_PS_POLL | IEEE80211_FC0_TYPE_CTL; 4724616e1330SBjoern A. Zeeb v = htole16(vif->cfg.aid | 1<<15 | 1<<16); 47256b4cac81SBjoern A. Zeeb memcpy(&psp->i_aid, &v, sizeof(v)); 47266b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(psp->i_bssid, vap->iv_bss->ni_macaddr); 47276b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(psp->i_ta, vif->addr); 47286b4cac81SBjoern A. Zeeb 47296b4cac81SBjoern A. Zeeb return (skb); 47306b4cac81SBjoern A. Zeeb } 47316b4cac81SBjoern A. Zeeb 47326b4cac81SBjoern A. Zeeb struct sk_buff * 47336b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_nullfunc_get(struct ieee80211_hw *hw, 4734adff403fSBjoern A. Zeeb struct ieee80211_vif *vif, int linkid, bool qos) 47356b4cac81SBjoern A. Zeeb { 47366b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 47376b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 47386b4cac81SBjoern A. Zeeb struct sk_buff *skb; 47396b4cac81SBjoern A. Zeeb struct ieee80211_frame *nullf; 47406b4cac81SBjoern A. Zeeb 4741adff403fSBjoern A. Zeeb IMPROVE("linkid"); 4742adff403fSBjoern A. Zeeb 47436b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*nullf)); 47446b4cac81SBjoern A. Zeeb if (skb == NULL) 47456b4cac81SBjoern A. Zeeb return (NULL); 47466b4cac81SBjoern A. Zeeb 47476b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 47486b4cac81SBjoern A. Zeeb 47496b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 47506b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 47516b4cac81SBjoern A. Zeeb 47526b4cac81SBjoern A. Zeeb nullf = skb_put_zero(skb, sizeof(*nullf)); 47536b4cac81SBjoern A. Zeeb nullf->i_fc[0] = IEEE80211_FC0_VERSION_0; 47546b4cac81SBjoern A. Zeeb nullf->i_fc[0] |= IEEE80211_FC0_SUBTYPE_NODATA | IEEE80211_FC0_TYPE_DATA; 47556b4cac81SBjoern A. Zeeb nullf->i_fc[1] = IEEE80211_FC1_DIR_TODS; 47566b4cac81SBjoern A. Zeeb 47576b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr1, vap->iv_bss->ni_bssid); 47586b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr2, vif->addr); 47596b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr3, vap->iv_bss->ni_macaddr); 47606b4cac81SBjoern A. Zeeb 47616b4cac81SBjoern A. Zeeb return (skb); 47626b4cac81SBjoern A. Zeeb } 47636b4cac81SBjoern A. Zeeb 47646b4cac81SBjoern A. Zeeb struct wireless_dev * 47656b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_vif_to_wdev(struct ieee80211_vif *vif) 47666b4cac81SBjoern A. Zeeb { 47676b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 47686b4cac81SBjoern A. Zeeb 47696b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 47706b4cac81SBjoern A. Zeeb return (&lvif->wdev); 47716b4cac81SBjoern A. Zeeb } 47726b4cac81SBjoern A. Zeeb 47736b4cac81SBjoern A. Zeeb void 47746b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_connection_loss(struct ieee80211_vif *vif) 47756b4cac81SBjoern A. Zeeb { 47766b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 47776b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 47786b4cac81SBjoern A. Zeeb enum ieee80211_state nstate; 47796b4cac81SBjoern A. Zeeb int arg; 47806b4cac81SBjoern A. Zeeb 47816b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 47826b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 47836b4cac81SBjoern A. Zeeb 47846b4cac81SBjoern A. Zeeb /* 4785f3229b62SBjoern A. Zeeb * Go to init; otherwise we need to elaborately check state and 47866b4cac81SBjoern A. Zeeb * handle accordingly, e.g., if in RUN we could call iv_bmiss. 47876b4cac81SBjoern A. Zeeb * Let the statemachine handle all neccessary changes. 47886b4cac81SBjoern A. Zeeb */ 4789f3229b62SBjoern A. Zeeb nstate = IEEE80211_S_INIT; 4790bb81db90SBjoern A. Zeeb arg = 0; /* Not a valid reason. */ 47916b4cac81SBjoern A. Zeeb 47929d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 47939d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 47946b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: vif %p\n", __func__, vif); 47959d9ba2b7SBjoern A. Zeeb #endif 47966b4cac81SBjoern A. Zeeb ieee80211_new_state(vap, nstate, arg); 47976b4cac81SBjoern A. Zeeb } 47986b4cac81SBjoern A. Zeeb 4799bb81db90SBjoern A. Zeeb void 4800bb81db90SBjoern A. Zeeb linuxkpi_ieee80211_beacon_loss(struct ieee80211_vif *vif) 4801bb81db90SBjoern A. Zeeb { 4802bb81db90SBjoern A. Zeeb struct lkpi_vif *lvif; 4803bb81db90SBjoern A. Zeeb struct ieee80211vap *vap; 4804bb81db90SBjoern A. Zeeb 4805bb81db90SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 4806bb81db90SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 4807bb81db90SBjoern A. Zeeb 48089d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 48099d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE || vap->iv_state != IEEE80211_S_RUN) 4810bb81db90SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: vif %p vap %p state %s\n", __func__, 4811bb81db90SBjoern A. Zeeb vif, vap, ieee80211_state_name[vap->iv_state]); 48129d9ba2b7SBjoern A. Zeeb #endif 48133540911bSBjoern A. Zeeb ieee80211_beacon_miss(vap->iv_ic); 4814bb81db90SBjoern A. Zeeb } 4815bb81db90SBjoern A. Zeeb 48165edde07cSBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 48175edde07cSBjoern A. Zeeb 48185a9a0d78SBjoern A. Zeeb void 48195a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_stop_queue(struct ieee80211_hw *hw, int qnum) 48205a9a0d78SBjoern A. Zeeb { 48215a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 48225a9a0d78SBjoern A. Zeeb struct lkpi_vif *lvif; 48235a9a0d78SBjoern A. Zeeb struct ieee80211_vif *vif; 48245a9a0d78SBjoern A. Zeeb int ac_count, ac; 48255a9a0d78SBjoern A. Zeeb 48265a9a0d78SBjoern A. Zeeb KASSERT(qnum < hw->queues, ("%s: qnum %d >= hw->queues %d, hw %p\n", 48275a9a0d78SBjoern A. Zeeb __func__, qnum, hw->queues, hw)); 48285a9a0d78SBjoern A. Zeeb 48295a9a0d78SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 48305a9a0d78SBjoern A. Zeeb 48315a9a0d78SBjoern A. Zeeb /* See lkpi_ic_vap_create(). */ 48325a9a0d78SBjoern A. Zeeb if (hw->queues >= IEEE80211_NUM_ACS) 48335a9a0d78SBjoern A. Zeeb ac_count = IEEE80211_NUM_ACS; 48345a9a0d78SBjoern A. Zeeb else 48355a9a0d78SBjoern A. Zeeb ac_count = 1; 48365a9a0d78SBjoern A. Zeeb 48375a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 48385a9a0d78SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 48395a9a0d78SBjoern A. Zeeb 48405a9a0d78SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 48415a9a0d78SBjoern A. Zeeb for (ac = 0; ac < ac_count; ac++) { 48425a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 48435a9a0d78SBjoern A. Zeeb if (qnum == vif->hw_queue[ac]) { 48445a9a0d78SBjoern A. Zeeb /* 48455a9a0d78SBjoern A. Zeeb * For now log this to better understand 48465a9a0d78SBjoern A. Zeeb * how this is supposed to work. 48475a9a0d78SBjoern A. Zeeb */ 48485a9a0d78SBjoern A. Zeeb if (lvif->hw_queue_stopped[ac]) 48495a9a0d78SBjoern A. Zeeb ic_printf(lhw->ic, "%s:%d: lhw %p hw %p " 48505a9a0d78SBjoern A. Zeeb "lvif %p vif %p ac %d qnum %d already " 48515a9a0d78SBjoern A. Zeeb "stopped\n", __func__, __LINE__, 48525a9a0d78SBjoern A. Zeeb lhw, hw, lvif, vif, ac, qnum); 48535a9a0d78SBjoern A. Zeeb lvif->hw_queue_stopped[ac] = true; 48545a9a0d78SBjoern A. Zeeb } 48555a9a0d78SBjoern A. Zeeb } 48565a9a0d78SBjoern A. Zeeb } 48575a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 48585a9a0d78SBjoern A. Zeeb } 48595a9a0d78SBjoern A. Zeeb 48605a9a0d78SBjoern A. Zeeb void 48615a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_stop_queues(struct ieee80211_hw *hw) 48625a9a0d78SBjoern A. Zeeb { 48635a9a0d78SBjoern A. Zeeb int i; 48645a9a0d78SBjoern A. Zeeb 48655a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Locking; do we need further info?"); 48665a9a0d78SBjoern A. Zeeb for (i = 0; i < hw->queues; i++) 48675a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_stop_queue(hw, i); 48685a9a0d78SBjoern A. Zeeb } 48695a9a0d78SBjoern A. Zeeb 48705a9a0d78SBjoern A. Zeeb 48715a9a0d78SBjoern A. Zeeb static void 48725a9a0d78SBjoern A. Zeeb lkpi_ieee80211_wake_queues(struct ieee80211_hw *hw, int hwq) 48735a9a0d78SBjoern A. Zeeb { 48745a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 48755a9a0d78SBjoern A. Zeeb struct lkpi_vif *lvif; 48765a9a0d78SBjoern A. Zeeb struct lkpi_sta *lsta; 48775a9a0d78SBjoern A. Zeeb int ac_count, ac, tid; 48785a9a0d78SBjoern A. Zeeb 48795a9a0d78SBjoern A. Zeeb /* See lkpi_ic_vap_create(). */ 48805a9a0d78SBjoern A. Zeeb if (hw->queues >= IEEE80211_NUM_ACS) 48815a9a0d78SBjoern A. Zeeb ac_count = IEEE80211_NUM_ACS; 48825a9a0d78SBjoern A. Zeeb else 48835a9a0d78SBjoern A. Zeeb ac_count = 1; 48845a9a0d78SBjoern A. Zeeb 48855a9a0d78SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 48865a9a0d78SBjoern A. Zeeb 48875a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Locking"); 48885a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 48895a9a0d78SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 48905a9a0d78SBjoern A. Zeeb struct ieee80211_vif *vif; 48915a9a0d78SBjoern A. Zeeb 48925a9a0d78SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 48935a9a0d78SBjoern A. Zeeb for (ac = 0; ac < ac_count; ac++) { 48945a9a0d78SBjoern A. Zeeb 48955a9a0d78SBjoern A. Zeeb if (hwq == vif->hw_queue[ac]) { 48965a9a0d78SBjoern A. Zeeb 48975a9a0d78SBjoern A. Zeeb /* XXX-BZ what about software scan? */ 48985a9a0d78SBjoern A. Zeeb 48995a9a0d78SBjoern A. Zeeb /* 49005a9a0d78SBjoern A. Zeeb * For now log this to better understand 49015a9a0d78SBjoern A. Zeeb * how this is supposed to work. 49025a9a0d78SBjoern A. Zeeb */ 49035a9a0d78SBjoern A. Zeeb if (!lvif->hw_queue_stopped[ac]) 49045a9a0d78SBjoern A. Zeeb ic_printf(lhw->ic, "%s:%d: lhw %p hw %p " 49055a9a0d78SBjoern A. Zeeb "lvif %p vif %p ac %d hw_q not stopped\n", 49065a9a0d78SBjoern A. Zeeb __func__, __LINE__, 49075a9a0d78SBjoern A. Zeeb lhw, hw, lvif, vif, ac); 49085a9a0d78SBjoern A. Zeeb lvif->hw_queue_stopped[ac] = false; 49095a9a0d78SBjoern A. Zeeb 49105a9a0d78SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 49115a9a0d78SBjoern A. Zeeb TAILQ_FOREACH(lsta, &lvif->lsta_head, lsta_entry) { 49125a9a0d78SBjoern A. Zeeb struct ieee80211_sta *sta; 49135a9a0d78SBjoern A. Zeeb 49145a9a0d78SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 49155a9a0d78SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 49165a9a0d78SBjoern A. Zeeb struct lkpi_txq *ltxq; 49175a9a0d78SBjoern A. Zeeb 49185a9a0d78SBjoern A. Zeeb if (sta->txq[tid] == NULL) 49195a9a0d78SBjoern A. Zeeb continue; 49205a9a0d78SBjoern A. Zeeb 49215a9a0d78SBjoern A. Zeeb if (sta->txq[tid]->ac != ac) 49225a9a0d78SBjoern A. Zeeb continue; 49235a9a0d78SBjoern A. Zeeb 49245a9a0d78SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]); 49255a9a0d78SBjoern A. Zeeb if (!ltxq->stopped) 49265a9a0d78SBjoern A. Zeeb continue; 49275a9a0d78SBjoern A. Zeeb 49285a9a0d78SBjoern A. Zeeb ltxq->stopped = false; 49295a9a0d78SBjoern A. Zeeb 49305a9a0d78SBjoern A. Zeeb /* XXX-BZ see when this explodes with all the locking. taskq? */ 49315a9a0d78SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, sta->txq[tid]); 49325a9a0d78SBjoern A. Zeeb } 49335a9a0d78SBjoern A. Zeeb } 49345a9a0d78SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 49355a9a0d78SBjoern A. Zeeb } 49365a9a0d78SBjoern A. Zeeb } 49375a9a0d78SBjoern A. Zeeb } 49385a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 49395a9a0d78SBjoern A. Zeeb } 49405a9a0d78SBjoern A. Zeeb 49415a9a0d78SBjoern A. Zeeb void 49425a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_wake_queues(struct ieee80211_hw *hw) 49435a9a0d78SBjoern A. Zeeb { 49445a9a0d78SBjoern A. Zeeb int i; 49455a9a0d78SBjoern A. Zeeb 49465a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Is this all/enough here?"); 49475a9a0d78SBjoern A. Zeeb for (i = 0; i < hw->queues; i++) 49485a9a0d78SBjoern A. Zeeb lkpi_ieee80211_wake_queues(hw, i); 49495a9a0d78SBjoern A. Zeeb } 49505a9a0d78SBjoern A. Zeeb 49515a9a0d78SBjoern A. Zeeb void 49525a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_wake_queue(struct ieee80211_hw *hw, int qnum) 49535a9a0d78SBjoern A. Zeeb { 49545a9a0d78SBjoern A. Zeeb 49555a9a0d78SBjoern A. Zeeb KASSERT(qnum < hw->queues, ("%s: qnum %d >= hw->queues %d, hw %p\n", 49565a9a0d78SBjoern A. Zeeb __func__, qnum, hw->queues, hw)); 49575a9a0d78SBjoern A. Zeeb 49585a9a0d78SBjoern A. Zeeb lkpi_ieee80211_wake_queues(hw, qnum); 49595a9a0d78SBjoern A. Zeeb } 49605a9a0d78SBjoern A. Zeeb 49615a9a0d78SBjoern A. Zeeb /* This is just hardware queues. */ 49625a9a0d78SBjoern A. Zeeb void 49635a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_txq_schedule_start(struct ieee80211_hw *hw, uint8_t ac) 49645a9a0d78SBjoern A. Zeeb { 49655a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 49665a9a0d78SBjoern A. Zeeb 49675a9a0d78SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 49685a9a0d78SBjoern A. Zeeb 49695a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Are there reasons why we wouldn't schedule?"); 49705a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 49715a9a0d78SBjoern A. Zeeb if (++lhw->txq_generation[ac] == 0) 49725a9a0d78SBjoern A. Zeeb lhw->txq_generation[ac]++; 49735a9a0d78SBjoern A. Zeeb } 49745a9a0d78SBjoern A. Zeeb 49755a9a0d78SBjoern A. Zeeb struct ieee80211_txq * 49765a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_next_txq(struct ieee80211_hw *hw, uint8_t ac) 49775a9a0d78SBjoern A. Zeeb { 49785a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 49795a9a0d78SBjoern A. Zeeb struct ieee80211_txq *txq; 49805a9a0d78SBjoern A. Zeeb struct lkpi_txq *ltxq; 49815a9a0d78SBjoern A. Zeeb 49825a9a0d78SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 49835a9a0d78SBjoern A. Zeeb txq = NULL; 49845a9a0d78SBjoern A. Zeeb 49855a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 49865a9a0d78SBjoern A. Zeeb 49875a9a0d78SBjoern A. Zeeb /* Check that we are scheduled. */ 49885a9a0d78SBjoern A. Zeeb if (lhw->txq_generation[ac] == 0) 49895a9a0d78SBjoern A. Zeeb goto out; 49905a9a0d78SBjoern A. Zeeb 49915a9a0d78SBjoern A. Zeeb ltxq = TAILQ_FIRST(&lhw->scheduled_txqs[ac]); 49925a9a0d78SBjoern A. Zeeb if (ltxq == NULL) 49935a9a0d78SBjoern A. Zeeb goto out; 49945a9a0d78SBjoern A. Zeeb if (ltxq->txq_generation == lhw->txq_generation[ac]) 49955a9a0d78SBjoern A. Zeeb goto out; 49965a9a0d78SBjoern A. Zeeb 49975a9a0d78SBjoern A. Zeeb ltxq->txq_generation = lhw->txq_generation[ac]; 49985a9a0d78SBjoern A. Zeeb TAILQ_REMOVE(&lhw->scheduled_txqs[ac], ltxq, txq_entry); 49995a9a0d78SBjoern A. Zeeb txq = <xq->txq; 50005a9a0d78SBjoern A. Zeeb TAILQ_ELEM_INIT(ltxq, txq_entry); 50015a9a0d78SBjoern A. Zeeb 50025a9a0d78SBjoern A. Zeeb out: 50035a9a0d78SBjoern A. Zeeb return (txq); 50045a9a0d78SBjoern A. Zeeb } 50055a9a0d78SBjoern A. Zeeb 50065a9a0d78SBjoern A. Zeeb void linuxkpi_ieee80211_schedule_txq(struct ieee80211_hw *hw, 50075a9a0d78SBjoern A. Zeeb struct ieee80211_txq *txq, bool withoutpkts) 50085a9a0d78SBjoern A. Zeeb { 50095a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 50105a9a0d78SBjoern A. Zeeb struct lkpi_txq *ltxq; 50115a9a0d78SBjoern A. Zeeb 50125a9a0d78SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 50135a9a0d78SBjoern A. Zeeb 50145a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 50155a9a0d78SBjoern A. Zeeb 50165a9a0d78SBjoern A. Zeeb /* Only schedule if work to do or asked to anyway. */ 50175a9a0d78SBjoern A. Zeeb if (!withoutpkts && skb_queue_empty(<xq->skbq)) 50185a9a0d78SBjoern A. Zeeb goto out; 50195a9a0d78SBjoern A. Zeeb 50205a9a0d78SBjoern A. Zeeb /* Make sure we do not double-schedule. */ 50215a9a0d78SBjoern A. Zeeb if (ltxq->txq_entry.tqe_next != NULL) 50225a9a0d78SBjoern A. Zeeb goto out; 50235a9a0d78SBjoern A. Zeeb 50245a9a0d78SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 50255a9a0d78SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lhw->scheduled_txqs[txq->ac], ltxq, txq_entry); 50265a9a0d78SBjoern A. Zeeb out: 50275a9a0d78SBjoern A. Zeeb return; 50285a9a0d78SBjoern A. Zeeb } 50295a9a0d78SBjoern A. Zeeb 50305a9a0d78SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 50315a9a0d78SBjoern A. Zeeb 50325edde07cSBjoern A. Zeeb struct lkpi_cfg80211_bss { 50335edde07cSBjoern A. Zeeb u_int refcnt; 50345edde07cSBjoern A. Zeeb struct cfg80211_bss bss; 50355edde07cSBjoern A. Zeeb }; 50365edde07cSBjoern A. Zeeb 50375edde07cSBjoern A. Zeeb struct lkpi_cfg80211_get_bss_iter_lookup { 50385edde07cSBjoern A. Zeeb struct wiphy *wiphy; 50395edde07cSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 50405edde07cSBjoern A. Zeeb const uint8_t *bssid; 50415edde07cSBjoern A. Zeeb const uint8_t *ssid; 50425edde07cSBjoern A. Zeeb size_t ssid_len; 50435edde07cSBjoern A. Zeeb enum ieee80211_bss_type bss_type; 50445edde07cSBjoern A. Zeeb enum ieee80211_privacy privacy; 50455edde07cSBjoern A. Zeeb 50465edde07cSBjoern A. Zeeb /* 50475edde07cSBjoern A. Zeeb * Something to store a copy of the result as the net80211 scan cache 50485edde07cSBjoern A. Zeeb * is not refoucnted so a scan entry might go away any time. 50495edde07cSBjoern A. Zeeb */ 50505edde07cSBjoern A. Zeeb bool match; 50515edde07cSBjoern A. Zeeb struct cfg80211_bss *bss; 50525edde07cSBjoern A. Zeeb }; 50535edde07cSBjoern A. Zeeb 50545edde07cSBjoern A. Zeeb static void 50555edde07cSBjoern A. Zeeb lkpi_cfg80211_get_bss_iterf(void *arg, const struct ieee80211_scan_entry *se) 50565edde07cSBjoern A. Zeeb { 50575edde07cSBjoern A. Zeeb struct lkpi_cfg80211_get_bss_iter_lookup *lookup; 50585edde07cSBjoern A. Zeeb size_t ielen; 50595edde07cSBjoern A. Zeeb 50605edde07cSBjoern A. Zeeb lookup = arg; 50615edde07cSBjoern A. Zeeb 50625edde07cSBjoern A. Zeeb /* Do not try to find another match. */ 50635edde07cSBjoern A. Zeeb if (lookup->match) 50645edde07cSBjoern A. Zeeb return; 50655edde07cSBjoern A. Zeeb 50665edde07cSBjoern A. Zeeb /* Nothing to store result. */ 50675edde07cSBjoern A. Zeeb if (lookup->bss == NULL) 50685edde07cSBjoern A. Zeeb return; 50695edde07cSBjoern A. Zeeb 50705edde07cSBjoern A. Zeeb if (lookup->privacy != IEEE80211_PRIVACY_ANY) { 50715edde07cSBjoern A. Zeeb /* if (se->se_capinfo & IEEE80211_CAPINFO_PRIVACY) */ 50725edde07cSBjoern A. Zeeb /* We have no idea what to compare to as the drivers only request ANY */ 50735edde07cSBjoern A. Zeeb return; 50745edde07cSBjoern A. Zeeb } 50755edde07cSBjoern A. Zeeb 50765edde07cSBjoern A. Zeeb if (lookup->bss_type != IEEE80211_BSS_TYPE_ANY) { 50775edde07cSBjoern A. Zeeb /* if (se->se_capinfo & (IEEE80211_CAPINFO_IBSS|IEEE80211_CAPINFO_ESS)) */ 50785edde07cSBjoern A. Zeeb /* We have no idea what to compare to as the drivers only request ANY */ 50795edde07cSBjoern A. Zeeb return; 50805edde07cSBjoern A. Zeeb } 50815edde07cSBjoern A. Zeeb 50825edde07cSBjoern A. Zeeb if (lookup->chan != NULL) { 50835edde07cSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 50845edde07cSBjoern A. Zeeb 50855edde07cSBjoern A. Zeeb chan = linuxkpi_ieee80211_get_channel(lookup->wiphy, 50865edde07cSBjoern A. Zeeb se->se_chan->ic_freq); 50875edde07cSBjoern A. Zeeb if (chan == NULL || chan != lookup->chan) 50885edde07cSBjoern A. Zeeb return; 50895edde07cSBjoern A. Zeeb } 50905edde07cSBjoern A. Zeeb 50915edde07cSBjoern A. Zeeb if (lookup->bssid && !IEEE80211_ADDR_EQ(lookup->bssid, se->se_bssid)) 50925edde07cSBjoern A. Zeeb return; 50935edde07cSBjoern A. Zeeb 50945edde07cSBjoern A. Zeeb if (lookup->ssid) { 50955edde07cSBjoern A. Zeeb if (lookup->ssid_len != se->se_ssid[1] || 50965edde07cSBjoern A. Zeeb se->se_ssid[1] == 0) 50975edde07cSBjoern A. Zeeb return; 50985edde07cSBjoern A. Zeeb if (memcmp(lookup->ssid, se->se_ssid+2, lookup->ssid_len) != 0) 50995edde07cSBjoern A. Zeeb return; 51005edde07cSBjoern A. Zeeb } 51015edde07cSBjoern A. Zeeb 51025edde07cSBjoern A. Zeeb ielen = se->se_ies.len; 51035edde07cSBjoern A. Zeeb 51045edde07cSBjoern A. Zeeb lookup->bss->ies = malloc(sizeof(*lookup->bss->ies) + ielen, 51055edde07cSBjoern A. Zeeb M_LKPI80211, M_NOWAIT | M_ZERO); 51065edde07cSBjoern A. Zeeb if (lookup->bss->ies == NULL) 51075edde07cSBjoern A. Zeeb return; 51085edde07cSBjoern A. Zeeb 51095edde07cSBjoern A. Zeeb lookup->bss->ies->data = (uint8_t *)lookup->bss->ies + sizeof(*lookup->bss->ies); 51105edde07cSBjoern A. Zeeb lookup->bss->ies->len = ielen; 51115edde07cSBjoern A. Zeeb if (ielen) 51125edde07cSBjoern A. Zeeb memcpy(lookup->bss->ies->data, se->se_ies.data, ielen); 51135edde07cSBjoern A. Zeeb 51145edde07cSBjoern A. Zeeb lookup->match = true; 51155edde07cSBjoern A. Zeeb } 51165edde07cSBjoern A. Zeeb 51175edde07cSBjoern A. Zeeb struct cfg80211_bss * 51185edde07cSBjoern A. Zeeb linuxkpi_cfg80211_get_bss(struct wiphy *wiphy, struct linuxkpi_ieee80211_channel *chan, 51195edde07cSBjoern A. Zeeb const uint8_t *bssid, const uint8_t *ssid, size_t ssid_len, 51205edde07cSBjoern A. Zeeb enum ieee80211_bss_type bss_type, enum ieee80211_privacy privacy) 51215edde07cSBjoern A. Zeeb { 51225edde07cSBjoern A. Zeeb struct lkpi_cfg80211_bss *lbss; 51235edde07cSBjoern A. Zeeb struct lkpi_cfg80211_get_bss_iter_lookup lookup; 51245edde07cSBjoern A. Zeeb struct lkpi_hw *lhw; 51255edde07cSBjoern A. Zeeb struct ieee80211vap *vap; 51265edde07cSBjoern A. Zeeb 51275edde07cSBjoern A. Zeeb lhw = wiphy_priv(wiphy); 51285edde07cSBjoern A. Zeeb 51295edde07cSBjoern A. Zeeb /* Let's hope we can alloc. */ 51305edde07cSBjoern A. Zeeb lbss = malloc(sizeof(*lbss), M_LKPI80211, M_NOWAIT | M_ZERO); 51315edde07cSBjoern A. Zeeb if (lbss == NULL) { 51325edde07cSBjoern A. Zeeb ic_printf(lhw->ic, "%s: alloc failed.\n", __func__); 51335edde07cSBjoern A. Zeeb return (NULL); 51345edde07cSBjoern A. Zeeb } 51355edde07cSBjoern A. Zeeb 51365edde07cSBjoern A. Zeeb lookup.wiphy = wiphy; 51375edde07cSBjoern A. Zeeb lookup.chan = chan; 51385edde07cSBjoern A. Zeeb lookup.bssid = bssid; 51395edde07cSBjoern A. Zeeb lookup.ssid = ssid; 51405edde07cSBjoern A. Zeeb lookup.ssid_len = ssid_len; 51415edde07cSBjoern A. Zeeb lookup.bss_type = bss_type; 51425edde07cSBjoern A. Zeeb lookup.privacy = privacy; 51435edde07cSBjoern A. Zeeb lookup.match = false; 51445edde07cSBjoern A. Zeeb lookup.bss = &lbss->bss; 51455edde07cSBjoern A. Zeeb 51465edde07cSBjoern A. Zeeb IMPROVE("Iterate over all VAPs comparing perm_addr and addresses?"); 51475edde07cSBjoern A. Zeeb vap = TAILQ_FIRST(&lhw->ic->ic_vaps); 51485edde07cSBjoern A. Zeeb ieee80211_scan_iterate(vap, lkpi_cfg80211_get_bss_iterf, &lookup); 51495edde07cSBjoern A. Zeeb if (!lookup.match) { 51505edde07cSBjoern A. Zeeb free(lbss, M_LKPI80211); 51515edde07cSBjoern A. Zeeb return (NULL); 51525edde07cSBjoern A. Zeeb } 51535edde07cSBjoern A. Zeeb 51545edde07cSBjoern A. Zeeb refcount_init(&lbss->refcnt, 1); 51555edde07cSBjoern A. Zeeb return (&lbss->bss); 51565edde07cSBjoern A. Zeeb } 51575edde07cSBjoern A. Zeeb 51585edde07cSBjoern A. Zeeb void 51595edde07cSBjoern A. Zeeb linuxkpi_cfg80211_put_bss(struct wiphy *wiphy, struct cfg80211_bss *bss) 51605edde07cSBjoern A. Zeeb { 51615edde07cSBjoern A. Zeeb struct lkpi_cfg80211_bss *lbss; 51625edde07cSBjoern A. Zeeb 51635edde07cSBjoern A. Zeeb lbss = container_of(bss, struct lkpi_cfg80211_bss, bss); 51645edde07cSBjoern A. Zeeb 51655edde07cSBjoern A. Zeeb /* Free everything again on refcount ... */ 51665edde07cSBjoern A. Zeeb if (refcount_release(&lbss->refcnt)) { 51675edde07cSBjoern A. Zeeb free(lbss->bss.ies, M_LKPI80211); 51685edde07cSBjoern A. Zeeb free(lbss, M_LKPI80211); 51695edde07cSBjoern A. Zeeb } 51705edde07cSBjoern A. Zeeb } 51715edde07cSBjoern A. Zeeb 51725edde07cSBjoern A. Zeeb void 51735edde07cSBjoern A. Zeeb linuxkpi_cfg80211_bss_flush(struct wiphy *wiphy) 51745edde07cSBjoern A. Zeeb { 51755edde07cSBjoern A. Zeeb struct lkpi_hw *lhw; 51765edde07cSBjoern A. Zeeb struct ieee80211com *ic; 51775edde07cSBjoern A. Zeeb struct ieee80211vap *vap; 51785edde07cSBjoern A. Zeeb 51795edde07cSBjoern A. Zeeb lhw = wiphy_priv(wiphy); 51805edde07cSBjoern A. Zeeb ic = lhw->ic; 51815edde07cSBjoern A. Zeeb 51825edde07cSBjoern A. Zeeb /* 51835edde07cSBjoern A. Zeeb * If we haven't called ieee80211_ifattach() yet 51845edde07cSBjoern A. Zeeb * or there is no VAP, there are no scans to flush. 51855edde07cSBjoern A. Zeeb */ 51865edde07cSBjoern A. Zeeb if (ic == NULL || 51875edde07cSBjoern A. Zeeb (lhw->sc_flags & LKPI_MAC80211_DRV_STARTED) == 0) 51885edde07cSBjoern A. Zeeb return; 51895edde07cSBjoern A. Zeeb 51905edde07cSBjoern A. Zeeb /* Should only happen on the current one? Not seen it late enough. */ 51915edde07cSBjoern A. Zeeb IEEE80211_LOCK(ic); 51925edde07cSBjoern A. Zeeb TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) 51935edde07cSBjoern A. Zeeb ieee80211_scan_flush(vap); 51945edde07cSBjoern A. Zeeb IEEE80211_UNLOCK(ic); 51955edde07cSBjoern A. Zeeb } 51965edde07cSBjoern A. Zeeb 51975edde07cSBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 51985edde07cSBjoern A. Zeeb 51996b4cac81SBjoern A. Zeeb MODULE_VERSION(linuxkpi_wlan, 1); 52006b4cac81SBjoern A. Zeeb MODULE_DEPEND(linuxkpi_wlan, linuxkpi, 1, 1, 1); 52016b4cac81SBjoern A. Zeeb MODULE_DEPEND(linuxkpi_wlan, wlan, 1, 1, 1); 5202