16b4cac81SBjoern A. Zeeb /*- 22e183d99SBjoern A. Zeeb * Copyright (c) 2020-2022 The FreeBSD Foundation 3086be6a8SBjoern A. Zeeb * Copyright (c) 2020-2022 Bjoern A. Zeeb 46b4cac81SBjoern A. Zeeb * 56b4cac81SBjoern A. Zeeb * This software was developed by Björn Zeeb under sponsorship from 66b4cac81SBjoern A. Zeeb * the FreeBSD Foundation. 76b4cac81SBjoern A. Zeeb * 86b4cac81SBjoern A. Zeeb * Redistribution and use in source and binary forms, with or without 96b4cac81SBjoern A. Zeeb * modification, are permitted provided that the following conditions 106b4cac81SBjoern A. Zeeb * are met: 116b4cac81SBjoern A. Zeeb * 1. Redistributions of source code must retain the above copyright 126b4cac81SBjoern A. Zeeb * notice, this list of conditions and the following disclaimer. 136b4cac81SBjoern A. Zeeb * 2. Redistributions in binary form must reproduce the above copyright 146b4cac81SBjoern A. Zeeb * notice, this list of conditions and the following disclaimer in the 156b4cac81SBjoern A. Zeeb * documentation and/or other materials provided with the distribution. 166b4cac81SBjoern A. Zeeb * 176b4cac81SBjoern A. Zeeb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 186b4cac81SBjoern A. Zeeb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 196b4cac81SBjoern A. Zeeb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 206b4cac81SBjoern A. Zeeb * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 216b4cac81SBjoern A. Zeeb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 226b4cac81SBjoern A. Zeeb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 236b4cac81SBjoern A. Zeeb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 246b4cac81SBjoern A. Zeeb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 256b4cac81SBjoern A. Zeeb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 266b4cac81SBjoern A. Zeeb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 276b4cac81SBjoern A. Zeeb * SUCH DAMAGE. 286b4cac81SBjoern A. Zeeb */ 296b4cac81SBjoern A. Zeeb 306b4cac81SBjoern A. Zeeb /* 316b4cac81SBjoern A. Zeeb * Public functions are called linuxkpi_*(). 326b4cac81SBjoern A. Zeeb * Internal (static) functions are called lkpi_*(). 336b4cac81SBjoern A. Zeeb * 346b4cac81SBjoern A. Zeeb * The internal structures holding metadata over public structures are also 356b4cac81SBjoern A. Zeeb * called lkpi_xxx (usually with a member at the end called xxx). 366b4cac81SBjoern A. Zeeb * Note: we do not replicate the structure names but the general variable names 376b4cac81SBjoern A. Zeeb * for these (e.g., struct hw -> struct lkpi_hw, struct sta -> struct lkpi_sta). 386b4cac81SBjoern A. Zeeb * There are macros to access one from the other. 396b4cac81SBjoern A. Zeeb * We call the internal versions lxxx (e.g., hw -> lhw, sta -> lsta). 406b4cac81SBjoern A. Zeeb */ 416b4cac81SBjoern A. Zeeb 426b4cac81SBjoern A. Zeeb #include <sys/cdefs.h> 436b4cac81SBjoern A. Zeeb __FBSDID("$FreeBSD$"); 446b4cac81SBjoern A. Zeeb 456b4cac81SBjoern A. Zeeb #include <sys/param.h> 466b4cac81SBjoern A. Zeeb #include <sys/types.h> 476b4cac81SBjoern A. Zeeb #include <sys/kernel.h> 486b4cac81SBjoern A. Zeeb #include <sys/errno.h> 496b4cac81SBjoern A. Zeeb #include <sys/malloc.h> 506b4cac81SBjoern A. Zeeb #include <sys/module.h> 516b4cac81SBjoern A. Zeeb #include <sys/mutex.h> 526b4cac81SBjoern A. Zeeb #include <sys/socket.h> 536b4cac81SBjoern A. Zeeb #include <sys/sysctl.h> 546b4cac81SBjoern A. Zeeb #include <sys/queue.h> 556b4cac81SBjoern A. Zeeb #include <sys/taskqueue.h> 56527687a9SBjoern A. Zeeb #include <sys/libkern.h> 576b4cac81SBjoern A. Zeeb 586b4cac81SBjoern A. Zeeb #include <net/if.h> 596b4cac81SBjoern A. Zeeb #include <net/if_var.h> 606b4cac81SBjoern A. Zeeb #include <net/if_media.h> 616b4cac81SBjoern A. Zeeb #include <net/ethernet.h> 626b4cac81SBjoern A. Zeeb 636b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_var.h> 646b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_proto.h> 656b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_ratectl.h> 666b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_radiotap.h> 676b4cac81SBjoern A. Zeeb 686b4cac81SBjoern A. Zeeb #define LINUXKPI_NET80211 696b4cac81SBjoern A. Zeeb #include <net/mac80211.h> 706b4cac81SBjoern A. Zeeb 716b4cac81SBjoern A. Zeeb #include <linux/workqueue.h> 726b4cac81SBjoern A. Zeeb #include "linux_80211.h" 736b4cac81SBjoern A. Zeeb 74b35f6cd0SBjoern A. Zeeb /* #define LKPI_80211_HW_CRYPTO */ 75b35f6cd0SBjoern A. Zeeb 766b4cac81SBjoern A. Zeeb static MALLOC_DEFINE(M_LKPI80211, "lkpi80211", "LinuxKPI 80211 compat"); 776b4cac81SBjoern A. Zeeb 786b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 796b4cac81SBjoern A. Zeeb 809d9ba2b7SBjoern A. Zeeb /* Keep public for as long as header files are using it too. */ 819d9ba2b7SBjoern A. Zeeb int linuxkpi_debug_80211; 826b4cac81SBjoern A. Zeeb 836b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 849d9ba2b7SBjoern A. Zeeb SYSCTL_DECL(_compat_linuxkpi); 859d9ba2b7SBjoern A. Zeeb SYSCTL_NODE(_compat_linuxkpi, OID_AUTO, 80211, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 869d9ba2b7SBjoern A. Zeeb "LinuxKPI 802.11 compatibility layer"); 879d9ba2b7SBjoern A. Zeeb 889d9ba2b7SBjoern A. Zeeb SYSCTL_INT(_compat_linuxkpi_80211, OID_AUTO, debug, CTLFLAG_RWTUN, 899d9ba2b7SBjoern A. Zeeb &linuxkpi_debug_80211, 0, "LinuxKPI 802.11 debug level"); 909d9ba2b7SBjoern A. Zeeb 919d9ba2b7SBjoern A. Zeeb #define UNIMPLEMENTED if (linuxkpi_debug_80211 & D80211_TODO) \ 926b4cac81SBjoern A. Zeeb printf("XXX-TODO %s:%d: UNIMPLEMENTED\n", __func__, __LINE__) 939d9ba2b7SBjoern A. Zeeb #define TRACEOK() if (linuxkpi_debug_80211 & D80211_TRACEOK) \ 946b4cac81SBjoern A. Zeeb printf("XXX-TODO %s:%d: TRACEPOINT\n", __func__, __LINE__) 956b4cac81SBjoern A. Zeeb #else 966b4cac81SBjoern A. Zeeb #define UNIMPLEMENTED do { } while (0) 976b4cac81SBjoern A. Zeeb #define TRACEOK() do { } while (0) 986b4cac81SBjoern A. Zeeb #endif 996b4cac81SBjoern A. Zeeb 1006b4cac81SBjoern A. Zeeb /* #define PREP_TX_INFO_DURATION (IEEE80211_TRANS_WAIT * 1000) */ 1016b4cac81SBjoern A. Zeeb #ifndef PREP_TX_INFO_DURATION 1026b4cac81SBjoern A. Zeeb #define PREP_TX_INFO_DURATION 0 /* Let the driver do its thing. */ 1036b4cac81SBjoern A. Zeeb #endif 1046b4cac81SBjoern A. Zeeb 105caaa79c3SBjoern A. Zeeb /* c.f. ieee80211_ioctl.c */ 106caaa79c3SBjoern A. Zeeb static const uint8_t zerobssid[IEEE80211_ADDR_LEN]; 107caaa79c3SBjoern A. Zeeb 1086b4cac81SBjoern A. Zeeb /* This is DSAP | SSAP | CTRL | ProtoID/OrgCode{3}. */ 1096b4cac81SBjoern A. Zeeb const uint8_t rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; 1106b4cac81SBjoern A. Zeeb 111b0f73768SBjoern A. Zeeb /* IEEE 802.11-05/0257r1 */ 112b0f73768SBjoern A. Zeeb const uint8_t bridge_tunnel_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; 113b0f73768SBjoern A. Zeeb 1144f61ef8bSBjoern A. Zeeb const uint8_t tid_to_mac80211_ac[] = { 1154f61ef8bSBjoern A. Zeeb IEEE80211_AC_BE, 1164f61ef8bSBjoern A. Zeeb IEEE80211_AC_BK, 1174f61ef8bSBjoern A. Zeeb IEEE80211_AC_BK, 1184f61ef8bSBjoern A. Zeeb IEEE80211_AC_BE, 1194f61ef8bSBjoern A. Zeeb IEEE80211_AC_VI, 1204f61ef8bSBjoern A. Zeeb IEEE80211_AC_VI, 1214f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO, 1224f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO, 1234f61ef8bSBjoern A. Zeeb #if 0 1244f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO, /* We treat MGMT as TID 8, which is set as AC_VO */ 1254f61ef8bSBjoern A. Zeeb #endif 1264f61ef8bSBjoern A. Zeeb }; 1274f61ef8bSBjoern A. Zeeb 1286b4cac81SBjoern A. Zeeb const struct cfg80211_ops linuxkpi_mac80211cfgops = { 1296b4cac81SBjoern A. Zeeb /* 1306b4cac81SBjoern A. Zeeb * XXX TODO need a "glue layer" to link cfg80211 ops to 1316b4cac81SBjoern A. Zeeb * mac80211 and to the driver or net80211. 1326b4cac81SBjoern A. Zeeb * Can we pass some on 1:1? Need to compare the (*f)(). 1336b4cac81SBjoern A. Zeeb */ 1346b4cac81SBjoern A. Zeeb }; 1356b4cac81SBjoern A. Zeeb 1366b4cac81SBjoern A. Zeeb static struct lkpi_sta *lkpi_find_lsta_by_ni(struct lkpi_vif *, 1376b4cac81SBjoern A. Zeeb struct ieee80211_node *); 1386b4cac81SBjoern A. Zeeb static void lkpi_80211_txq_task(void *, int); 1396b4cac81SBjoern A. Zeeb static void lkpi_ieee80211_free_skb_mbuf(void *); 1406b4cac81SBjoern A. Zeeb 141d9f59799SBjoern A. Zeeb static void 14267674c1cSBjoern A. Zeeb lkpi_lsta_dump(struct lkpi_sta *lsta, struct ieee80211_node *ni, 14367674c1cSBjoern A. Zeeb const char *_f, int _l) 144d9f59799SBjoern A. Zeeb { 145d9f59799SBjoern A. Zeeb 1469d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 1479d9ba2b7SBjoern A. Zeeb if ((linuxkpi_debug_80211 & D80211_TRACE_STA) == 0) 148d9f59799SBjoern A. Zeeb return; 149d9f59799SBjoern A. Zeeb if (lsta == NULL) 150d9f59799SBjoern A. Zeeb return; 151d9f59799SBjoern A. Zeeb 152d9f59799SBjoern A. Zeeb printf("%s:%d lsta %p ni %p sta %p\n", 15367674c1cSBjoern A. Zeeb _f, _l, lsta, ni, &lsta->sta); 15467674c1cSBjoern A. Zeeb if (ni != NULL) 15567674c1cSBjoern A. Zeeb ieee80211_dump_node(NULL, ni); 156d9f59799SBjoern A. Zeeb printf("\ttxq_task txq len %d mtx\n", mbufq_len(&lsta->txq)); 157d9f59799SBjoern A. Zeeb printf("\tkc %p state %d added_to_drv %d in_mgd %d\n", 158d9f59799SBjoern A. Zeeb lsta->kc, lsta->state, lsta->added_to_drv, lsta->in_mgd); 1599d9ba2b7SBjoern A. Zeeb #endif 160d9f59799SBjoern A. Zeeb } 161d9f59799SBjoern A. Zeeb 162d9f59799SBjoern A. Zeeb static void 163d9f59799SBjoern A. Zeeb lkpi_lsta_remove(struct lkpi_sta *lsta, struct lkpi_vif *lvif) 164d9f59799SBjoern A. Zeeb { 165d9f59799SBjoern A. Zeeb struct ieee80211_node *ni; 166d9f59799SBjoern A. Zeeb 167d9f59799SBjoern A. Zeeb ni = lsta->ni; 168d9f59799SBjoern A. Zeeb 169d9f59799SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 170d9f59799SBjoern A. Zeeb TAILQ_REMOVE(&lvif->lsta_head, lsta, lsta_entry); 171d9f59799SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 172d9f59799SBjoern A. Zeeb 173d9f59799SBjoern A. Zeeb lsta->ni = NULL; 174d9f59799SBjoern A. Zeeb ni->ni_drv_data = NULL; 175e24e8103SBjoern A. Zeeb if (ni != NULL) 176d9f59799SBjoern A. Zeeb ieee80211_free_node(ni); 177d9f59799SBjoern A. Zeeb 178e24e8103SBjoern A. Zeeb IMPROVE("more from lkpi_ic_node_free() should happen here."); 179e24e8103SBjoern A. Zeeb 180e24e8103SBjoern A. Zeeb free(lsta, M_LKPI80211); 181d9f59799SBjoern A. Zeeb } 182d9f59799SBjoern A. Zeeb 1834f61ef8bSBjoern A. Zeeb static struct lkpi_sta * 1844f61ef8bSBjoern A. Zeeb lkpi_lsta_alloc(struct ieee80211vap *vap, const uint8_t mac[IEEE80211_ADDR_LEN], 1854f61ef8bSBjoern A. Zeeb struct ieee80211_hw *hw, struct ieee80211_node *ni) 1864f61ef8bSBjoern A. Zeeb { 1874f61ef8bSBjoern A. Zeeb struct lkpi_sta *lsta; 1884f61ef8bSBjoern A. Zeeb struct lkpi_vif *lvif; 1894f61ef8bSBjoern A. Zeeb struct ieee80211_vif *vif; 1904f61ef8bSBjoern A. Zeeb struct ieee80211_sta *sta; 1914f61ef8bSBjoern A. Zeeb int tid; 1924f61ef8bSBjoern A. Zeeb 1934f61ef8bSBjoern A. Zeeb lsta = malloc(sizeof(*lsta) + hw->sta_data_size, M_LKPI80211, 1944f61ef8bSBjoern A. Zeeb M_NOWAIT | M_ZERO); 1954f61ef8bSBjoern A. Zeeb if (lsta == NULL) 1964f61ef8bSBjoern A. Zeeb return (NULL); 1974f61ef8bSBjoern A. Zeeb 1984f61ef8bSBjoern A. Zeeb lsta->added_to_drv = false; 1994f61ef8bSBjoern A. Zeeb lsta->state = IEEE80211_STA_NOTEXIST; 2004f61ef8bSBjoern A. Zeeb #if 0 2014f61ef8bSBjoern A. Zeeb /* 2024f61ef8bSBjoern A. Zeeb * This needs to be done in node_init() as ieee80211_alloc_node() 2034f61ef8bSBjoern A. Zeeb * will initialise the refcount after us. 2044f61ef8bSBjoern A. Zeeb */ 2054f61ef8bSBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 2064f61ef8bSBjoern A. Zeeb #endif 2074f61ef8bSBjoern A. Zeeb /* The back-pointer "drv_data" to net80211_node let's us get lsta. */ 2084f61ef8bSBjoern A. Zeeb ni->ni_drv_data = lsta; 2094f61ef8bSBjoern A. Zeeb 2104f61ef8bSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 2114f61ef8bSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 2124f61ef8bSBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 2134f61ef8bSBjoern A. Zeeb 2144f61ef8bSBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->addr, mac); 2154f61ef8bSBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 2164f61ef8bSBjoern A. Zeeb struct lkpi_txq *ltxq; 2174f61ef8bSBjoern A. Zeeb 218d0d29110SBjoern A. Zeeb /* We are not limiting ourselves to hw.queues here. */ 2194f61ef8bSBjoern A. Zeeb ltxq = malloc(sizeof(*ltxq) + hw->txq_data_size, 2204f61ef8bSBjoern A. Zeeb M_LKPI80211, M_NOWAIT | M_ZERO); 2214f61ef8bSBjoern A. Zeeb if (ltxq == NULL) 2224f61ef8bSBjoern A. Zeeb goto cleanup; 2234f61ef8bSBjoern A. Zeeb /* iwlwifi//mvm/sta.c::tid_to_mac80211_ac[] */ 2244f61ef8bSBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) { 225d0d29110SBjoern A. Zeeb if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ)) { 226d0d29110SBjoern A. Zeeb free(ltxq, M_LKPI80211); 227d0d29110SBjoern A. Zeeb continue; 228d0d29110SBjoern A. Zeeb } 229d0d29110SBjoern A. Zeeb IMPROVE("AP/if we support non-STA here too"); 2304f61ef8bSBjoern A. Zeeb ltxq->txq.ac = IEEE80211_AC_VO; 2314f61ef8bSBjoern A. Zeeb } else { 2324f61ef8bSBjoern A. Zeeb ltxq->txq.ac = tid_to_mac80211_ac[tid & 7]; 2334f61ef8bSBjoern A. Zeeb } 234d0d29110SBjoern A. Zeeb ltxq->seen_dequeue = false; 235d0d29110SBjoern A. Zeeb ltxq->txq.vif = vif; 2364f61ef8bSBjoern A. Zeeb ltxq->txq.tid = tid; 2374f61ef8bSBjoern A. Zeeb ltxq->txq.sta = sta; 238d0d29110SBjoern A. Zeeb skb_queue_head_init(<xq->skbq); 2394f61ef8bSBjoern A. Zeeb sta->txq[tid] = <xq->txq; 2404f61ef8bSBjoern A. Zeeb } 2414f61ef8bSBjoern A. Zeeb 2424f61ef8bSBjoern A. Zeeb /* Deferred TX path. */ 2434f61ef8bSBjoern A. Zeeb mtx_init(&lsta->txq_mtx, "lsta_txq", NULL, MTX_DEF); 2444f61ef8bSBjoern A. Zeeb TASK_INIT(&lsta->txq_task, 0, lkpi_80211_txq_task, lsta); 2454f61ef8bSBjoern A. Zeeb mbufq_init(&lsta->txq, IFQ_MAXLEN); 2464f61ef8bSBjoern A. Zeeb 2474f61ef8bSBjoern A. Zeeb return (lsta); 2484f61ef8bSBjoern A. Zeeb 2494f61ef8bSBjoern A. Zeeb cleanup: 2504f61ef8bSBjoern A. Zeeb for (; tid >= 0; tid--) 2514f61ef8bSBjoern A. Zeeb free(sta->txq[tid], M_LKPI80211); 2524f61ef8bSBjoern A. Zeeb free(lsta, M_LKPI80211); 2534f61ef8bSBjoern A. Zeeb return (NULL); 2544f61ef8bSBjoern A. Zeeb } 2554f61ef8bSBjoern A. Zeeb 2566b4cac81SBjoern A. Zeeb static enum nl80211_band 2576b4cac81SBjoern A. Zeeb lkpi_net80211_chan_to_nl80211_band(struct ieee80211_channel *c) 2586b4cac81SBjoern A. Zeeb { 2596b4cac81SBjoern A. Zeeb 2606b4cac81SBjoern A. Zeeb if (IEEE80211_IS_CHAN_2GHZ(c)) 2616b4cac81SBjoern A. Zeeb return (NL80211_BAND_2GHZ); 2626b4cac81SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_5GHZ(c)) 2636b4cac81SBjoern A. Zeeb return (NL80211_BAND_5GHZ); 2646b4cac81SBjoern A. Zeeb #ifdef __notyet__ 2656b4cac81SBjoern A. Zeeb else if () 2666b4cac81SBjoern A. Zeeb return (NL80211_BAND_6GHZ); 2676b4cac81SBjoern A. Zeeb else if () 2686b4cac81SBjoern A. Zeeb return (NL80211_BAND_60GHZ); 2696b4cac81SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_GSM(c)) 2706b4cac81SBjoern A. Zeeb return (NL80211_BAND_XXX); 2716b4cac81SBjoern A. Zeeb #endif 2726b4cac81SBjoern A. Zeeb else 2736b4cac81SBjoern A. Zeeb panic("%s: unsupported band. c %p flags %#x\n", 2746b4cac81SBjoern A. Zeeb __func__, c, c->ic_flags); 2756b4cac81SBjoern A. Zeeb } 2766b4cac81SBjoern A. Zeeb 2776b4cac81SBjoern A. Zeeb static uint32_t 2786b4cac81SBjoern A. Zeeb lkpi_nl80211_band_to_net80211_band(enum nl80211_band band) 2796b4cac81SBjoern A. Zeeb { 2806b4cac81SBjoern A. Zeeb 2816b4cac81SBjoern A. Zeeb /* XXX-BZ this is just silly; net80211 is too convoluted. */ 2826b4cac81SBjoern A. Zeeb /* IEEE80211_CHAN_A / _G / .. doesn't really work either. */ 2836b4cac81SBjoern A. Zeeb switch (band) { 2846b4cac81SBjoern A. Zeeb case NL80211_BAND_2GHZ: 2856b4cac81SBjoern A. Zeeb return (IEEE80211_CHAN_2GHZ); 2866b4cac81SBjoern A. Zeeb break; 2876b4cac81SBjoern A. Zeeb case NL80211_BAND_5GHZ: 2886b4cac81SBjoern A. Zeeb return (IEEE80211_CHAN_5GHZ); 2896b4cac81SBjoern A. Zeeb break; 2906b4cac81SBjoern A. Zeeb case NL80211_BAND_60GHZ: 2916b4cac81SBjoern A. Zeeb break; 2926b4cac81SBjoern A. Zeeb case NL80211_BAND_6GHZ: 2936b4cac81SBjoern A. Zeeb break; 2946b4cac81SBjoern A. Zeeb default: 2956b4cac81SBjoern A. Zeeb panic("%s: unsupported band %u\n", __func__, band); 2966b4cac81SBjoern A. Zeeb break; 2976b4cac81SBjoern A. Zeeb } 2986b4cac81SBjoern A. Zeeb 2996b4cac81SBjoern A. Zeeb IMPROVE(); 3006b4cac81SBjoern A. Zeeb return (0x00); 3016b4cac81SBjoern A. Zeeb } 3026b4cac81SBjoern A. Zeeb 303e3a0b120SBjoern A. Zeeb #if 0 3046b4cac81SBjoern A. Zeeb static enum ieee80211_ac_numbers 3056b4cac81SBjoern A. Zeeb lkpi_ac_net_to_l80211(int ac) 3066b4cac81SBjoern A. Zeeb { 3076b4cac81SBjoern A. Zeeb 3086b4cac81SBjoern A. Zeeb switch (ac) { 3096b4cac81SBjoern A. Zeeb case WME_AC_VO: 3106b4cac81SBjoern A. Zeeb return (IEEE80211_AC_VO); 3116b4cac81SBjoern A. Zeeb case WME_AC_VI: 3126b4cac81SBjoern A. Zeeb return (IEEE80211_AC_VI); 3136b4cac81SBjoern A. Zeeb case WME_AC_BE: 3146b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BE); 3156b4cac81SBjoern A. Zeeb case WME_AC_BK: 3166b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BK); 3176b4cac81SBjoern A. Zeeb default: 3186b4cac81SBjoern A. Zeeb printf("%s: invalid WME_AC_* input: ac = %d\n", __func__, ac); 3196b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BE); 3206b4cac81SBjoern A. Zeeb } 3216b4cac81SBjoern A. Zeeb } 322e3a0b120SBjoern A. Zeeb #endif 3236b4cac81SBjoern A. Zeeb 3246b4cac81SBjoern A. Zeeb static enum nl80211_iftype 3256b4cac81SBjoern A. Zeeb lkpi_opmode_to_vif_type(enum ieee80211_opmode opmode) 3266b4cac81SBjoern A. Zeeb { 3276b4cac81SBjoern A. Zeeb 3286b4cac81SBjoern A. Zeeb switch (opmode) { 3296b4cac81SBjoern A. Zeeb case IEEE80211_M_IBSS: 3306b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_ADHOC); 3316b4cac81SBjoern A. Zeeb break; 3326b4cac81SBjoern A. Zeeb case IEEE80211_M_STA: 3336b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_STATION); 3346b4cac81SBjoern A. Zeeb break; 3356b4cac81SBjoern A. Zeeb case IEEE80211_M_WDS: 3366b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_WDS); 3376b4cac81SBjoern A. Zeeb break; 3386b4cac81SBjoern A. Zeeb case IEEE80211_M_HOSTAP: 3396b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_AP); 3406b4cac81SBjoern A. Zeeb break; 3416b4cac81SBjoern A. Zeeb case IEEE80211_M_MONITOR: 3426b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_MONITOR); 3436b4cac81SBjoern A. Zeeb break; 3446b4cac81SBjoern A. Zeeb case IEEE80211_M_MBSS: 3456b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_MESH_POINT); 3466b4cac81SBjoern A. Zeeb break; 3476b4cac81SBjoern A. Zeeb case IEEE80211_M_AHDEMO: 3486b4cac81SBjoern A. Zeeb /* FALLTHROUGH */ 3496b4cac81SBjoern A. Zeeb default: 3506b4cac81SBjoern A. Zeeb printf("ERROR: %s: unsupported opmode %d\n", __func__, opmode); 3516b4cac81SBjoern A. Zeeb /* FALLTHROUGH */ 3526b4cac81SBjoern A. Zeeb } 3536b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_UNSPECIFIED); 3546b4cac81SBjoern A. Zeeb } 3556b4cac81SBjoern A. Zeeb 356b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 3576b4cac81SBjoern A. Zeeb static uint32_t 3586b4cac81SBjoern A. Zeeb lkpi_l80211_to_net80211_cyphers(uint32_t wlan_cipher_suite) 3596b4cac81SBjoern A. Zeeb { 3606b4cac81SBjoern A. Zeeb 3616b4cac81SBjoern A. Zeeb switch (wlan_cipher_suite) { 3626b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP40: 3636b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_WEP); 3646b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP: 3656b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_TKIP); 3666b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP: 3676b4cac81SBjoern A. Zeeb return (IEEE80211_CIPHER_AES_CCM); 3686b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP104: 3696b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_WEP); 3706b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_AES_CMAC: 3716b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP: 3726b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP_256: 3736b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP_256: 3746b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_128: 3756b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_256: 3766b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_CMAC_256: 3776b4cac81SBjoern A. Zeeb printf("%s: unsupported WLAN Cipher Suite %#08x | %u\n", __func__, 3786b4cac81SBjoern A. Zeeb wlan_cipher_suite >> 8, wlan_cipher_suite & 0xff); 3796b4cac81SBjoern A. Zeeb break; 3806b4cac81SBjoern A. Zeeb default: 3816b4cac81SBjoern A. Zeeb printf("%s: unknown WLAN Cipher Suite %#08x | %u\n", __func__, 3826b4cac81SBjoern A. Zeeb wlan_cipher_suite >> 8, wlan_cipher_suite & 0xff); 3836b4cac81SBjoern A. Zeeb } 3846b4cac81SBjoern A. Zeeb 3856b4cac81SBjoern A. Zeeb return (0); 3866b4cac81SBjoern A. Zeeb } 3876b4cac81SBjoern A. Zeeb 3886b4cac81SBjoern A. Zeeb static uint32_t 3896b4cac81SBjoern A. Zeeb lkpi_net80211_to_l80211_cipher_suite(uint32_t cipher, uint8_t keylen) 3906b4cac81SBjoern A. Zeeb { 3916b4cac81SBjoern A. Zeeb 3926b4cac81SBjoern A. Zeeb switch (cipher) { 3936b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_TKIP: 3946b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_TKIP); 3956b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_AES_CCM: 3966b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_CCMP); 3976b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_WEP: 3986b4cac81SBjoern A. Zeeb if (keylen < 8) 3996b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_WEP40); 4006b4cac81SBjoern A. Zeeb else 4016b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_WEP104); 4026b4cac81SBjoern A. Zeeb break; 4036b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_AES_OCB: 4046b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_TKIPMIC: 4056b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_CKIP: 4066b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_NONE: 4076b4cac81SBjoern A. Zeeb printf("%s: unsupported cipher %#010x\n", __func__, cipher); 4086b4cac81SBjoern A. Zeeb break; 4096b4cac81SBjoern A. Zeeb default: 4106b4cac81SBjoern A. Zeeb printf("%s: unknown cipher %#010x\n", __func__, cipher); 4116b4cac81SBjoern A. Zeeb }; 4126b4cac81SBjoern A. Zeeb return (0); 4136b4cac81SBjoern A. Zeeb } 4146b4cac81SBjoern A. Zeeb #endif 4156b4cac81SBjoern A. Zeeb 4166b4cac81SBjoern A. Zeeb #ifdef __notyet__ 4176b4cac81SBjoern A. Zeeb static enum ieee80211_sta_state 4186b4cac81SBjoern A. Zeeb lkpi_net80211_state_to_sta_state(enum ieee80211_state state) 4196b4cac81SBjoern A. Zeeb { 4206b4cac81SBjoern A. Zeeb 4216b4cac81SBjoern A. Zeeb /* 4226b4cac81SBjoern A. Zeeb * XXX-BZ The net80211 states are "try to ..", the lkpi8011 states are 4236b4cac81SBjoern A. Zeeb * "done". Also ASSOC/AUTHORIZED are both "RUN" then? 4246b4cac81SBjoern A. Zeeb */ 4256b4cac81SBjoern A. Zeeb switch (state) { 4266b4cac81SBjoern A. Zeeb case IEEE80211_S_INIT: 4276b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NOTEXIST); 4286b4cac81SBjoern A. Zeeb case IEEE80211_S_SCAN: 4296b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NONE); 4306b4cac81SBjoern A. Zeeb case IEEE80211_S_AUTH: 4316b4cac81SBjoern A. Zeeb return (IEEE80211_STA_AUTH); 4326b4cac81SBjoern A. Zeeb case IEEE80211_S_ASSOC: 4336b4cac81SBjoern A. Zeeb return (IEEE80211_STA_ASSOC); 4346b4cac81SBjoern A. Zeeb case IEEE80211_S_RUN: 4356b4cac81SBjoern A. Zeeb return (IEEE80211_STA_AUTHORIZED); 4366b4cac81SBjoern A. Zeeb case IEEE80211_S_CAC: 4376b4cac81SBjoern A. Zeeb case IEEE80211_S_CSA: 4386b4cac81SBjoern A. Zeeb case IEEE80211_S_SLEEP: 4396b4cac81SBjoern A. Zeeb default: 4406b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 4416b4cac81SBjoern A. Zeeb }; 4426b4cac81SBjoern A. Zeeb 4436b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NOTEXIST); 4446b4cac81SBjoern A. Zeeb } 4456b4cac81SBjoern A. Zeeb #endif 4466b4cac81SBjoern A. Zeeb 4476b4cac81SBjoern A. Zeeb static struct linuxkpi_ieee80211_channel * 4486b4cac81SBjoern A. Zeeb lkpi_find_lkpi80211_chan(struct lkpi_hw *lhw, 4496b4cac81SBjoern A. Zeeb struct ieee80211_channel *c) 4506b4cac81SBjoern A. Zeeb { 4516b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 4526b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 4536b4cac81SBjoern A. Zeeb enum nl80211_band band; 4546b4cac81SBjoern A. Zeeb int i, nchans; 4556b4cac81SBjoern A. Zeeb 4566b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 4576b4cac81SBjoern A. Zeeb band = lkpi_net80211_chan_to_nl80211_band(c); 4586b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[band] == NULL) 4596b4cac81SBjoern A. Zeeb return (NULL); 4606b4cac81SBjoern A. Zeeb 4616b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[band]->n_channels; 4626b4cac81SBjoern A. Zeeb if (nchans <= 0) 4636b4cac81SBjoern A. Zeeb return (NULL); 4646b4cac81SBjoern A. Zeeb 4656b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[band]->channels; 4666b4cac81SBjoern A. Zeeb for (i = 0; i < nchans; i++) { 4676b4cac81SBjoern A. Zeeb if (channels[i].hw_value == c->ic_ieee) 4686b4cac81SBjoern A. Zeeb return (&channels[i]); 4696b4cac81SBjoern A. Zeeb } 4706b4cac81SBjoern A. Zeeb 4716b4cac81SBjoern A. Zeeb return (NULL); 4726b4cac81SBjoern A. Zeeb } 4736b4cac81SBjoern A. Zeeb 4746b4cac81SBjoern A. Zeeb static struct linuxkpi_ieee80211_channel * 4756b4cac81SBjoern A. Zeeb lkpi_get_lkpi80211_chan(struct ieee80211com *ic, struct ieee80211_node *ni) 4766b4cac81SBjoern A. Zeeb { 4776b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 4786b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 4796b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 4806b4cac81SBjoern A. Zeeb 4816b4cac81SBjoern A. Zeeb chan = NULL; 4826b4cac81SBjoern A. Zeeb if (ni != NULL && ni->ni_chan != IEEE80211_CHAN_ANYC) 4836b4cac81SBjoern A. Zeeb c = ni->ni_chan; 4846b4cac81SBjoern A. Zeeb else if (ic->ic_bsschan != IEEE80211_CHAN_ANYC) 4856b4cac81SBjoern A. Zeeb c = ic->ic_bsschan; 4866b4cac81SBjoern A. Zeeb else if (ic->ic_curchan != IEEE80211_CHAN_ANYC) 4876b4cac81SBjoern A. Zeeb c = ic->ic_curchan; 4886b4cac81SBjoern A. Zeeb else 4896b4cac81SBjoern A. Zeeb c = NULL; 4906b4cac81SBjoern A. Zeeb 4916b4cac81SBjoern A. Zeeb if (c != NULL && c != IEEE80211_CHAN_ANYC) { 4926b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 4936b4cac81SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, c); 4946b4cac81SBjoern A. Zeeb } 4956b4cac81SBjoern A. Zeeb 4966b4cac81SBjoern A. Zeeb return (chan); 4976b4cac81SBjoern A. Zeeb } 4986b4cac81SBjoern A. Zeeb 4992e183d99SBjoern A. Zeeb struct linuxkpi_ieee80211_channel * 5002e183d99SBjoern A. Zeeb linuxkpi_ieee80211_get_channel(struct wiphy *wiphy, uint32_t freq) 5012e183d99SBjoern A. Zeeb { 5022e183d99SBjoern A. Zeeb enum nl80211_band band; 5032e183d99SBjoern A. Zeeb 5042e183d99SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 5052e183d99SBjoern A. Zeeb struct ieee80211_supported_band *supband; 5062e183d99SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 5072e183d99SBjoern A. Zeeb int i; 5082e183d99SBjoern A. Zeeb 5092e183d99SBjoern A. Zeeb supband = wiphy->bands[band]; 5102e183d99SBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 5112e183d99SBjoern A. Zeeb continue; 5122e183d99SBjoern A. Zeeb 5132e183d99SBjoern A. Zeeb channels = supband->channels; 5142e183d99SBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 5152e183d99SBjoern A. Zeeb if (channels[i].center_freq == freq) 5162e183d99SBjoern A. Zeeb return (&channels[i]); 5172e183d99SBjoern A. Zeeb } 5182e183d99SBjoern A. Zeeb } 5192e183d99SBjoern A. Zeeb 5202e183d99SBjoern A. Zeeb return (NULL); 5212e183d99SBjoern A. Zeeb } 5222e183d99SBjoern A. Zeeb 523d8dd6b32SBjoern A. Zeeb void 524d8dd6b32SBjoern A. Zeeb linuxkpi_cfg80211_bss_flush(struct wiphy *wiphy) 525d8dd6b32SBjoern A. Zeeb { 526d8dd6b32SBjoern A. Zeeb struct lkpi_hw *lhw; 527d8dd6b32SBjoern A. Zeeb struct ieee80211com *ic; 528d8dd6b32SBjoern A. Zeeb struct ieee80211vap *vap; 529d8dd6b32SBjoern A. Zeeb 530d8dd6b32SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 531d8dd6b32SBjoern A. Zeeb ic = lhw->ic; 532d8dd6b32SBjoern A. Zeeb 533d8dd6b32SBjoern A. Zeeb /* 534d8dd6b32SBjoern A. Zeeb * If we haven't called ieee80211_ifattach() yet 535d8dd6b32SBjoern A. Zeeb * or there is no VAP, there are no scans to flush. 536d8dd6b32SBjoern A. Zeeb */ 537d8dd6b32SBjoern A. Zeeb if (ic == NULL || 538d8dd6b32SBjoern A. Zeeb (lhw->sc_flags & LKPI_MAC80211_DRV_STARTED) == 0) 539d8dd6b32SBjoern A. Zeeb return; 540d8dd6b32SBjoern A. Zeeb 541d8dd6b32SBjoern A. Zeeb /* Should only happen on the current one? Not seen it late enough. */ 542d8dd6b32SBjoern A. Zeeb IEEE80211_LOCK(ic); 543d8dd6b32SBjoern A. Zeeb TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) 544d8dd6b32SBjoern A. Zeeb ieee80211_scan_flush(vap); 545d8dd6b32SBjoern A. Zeeb IEEE80211_UNLOCK(ic); 546d8dd6b32SBjoern A. Zeeb } 547d8dd6b32SBjoern A. Zeeb 548b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 5496b4cac81SBjoern A. Zeeb static int 5506b4cac81SBjoern A. Zeeb _lkpi_iv_key_set_delete(struct ieee80211vap *vap, const struct ieee80211_key *k, 5516b4cac81SBjoern A. Zeeb enum set_key_cmd cmd) 5526b4cac81SBjoern A. Zeeb { 5536b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 5546b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 5556b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 5566b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 5576b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 5586b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 5596b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 5606b4cac81SBjoern A. Zeeb struct ieee80211_key_conf *kc; 5616b4cac81SBjoern A. Zeeb int error; 5626b4cac81SBjoern A. Zeeb 5636b4cac81SBjoern A. Zeeb /* XXX TODO Check (k->wk_flags & IEEE80211_KEY_SWENCRYPT) and don't upload to driver/hw? */ 5646b4cac81SBjoern A. Zeeb 5656b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 5666b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 5676b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 5686b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 5696b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 5706b4cac81SBjoern A. Zeeb 5716b4cac81SBjoern A. Zeeb memset(&kc, 0, sizeof(kc)); 5726b4cac81SBjoern A. Zeeb kc = malloc(sizeof(*kc) + k->wk_keylen, M_LKPI80211, M_WAITOK | M_ZERO); 5736b4cac81SBjoern A. Zeeb kc->cipher = lkpi_net80211_to_l80211_cipher_suite( 5746b4cac81SBjoern A. Zeeb k->wk_cipher->ic_cipher, k->wk_keylen); 5756b4cac81SBjoern A. Zeeb kc->keyidx = k->wk_keyix; 5766b4cac81SBjoern A. Zeeb #if 0 5776b4cac81SBjoern A. Zeeb kc->hw_key_idx = /* set by hw and needs to be passed for TX */; 5786b4cac81SBjoern A. Zeeb #endif 5796b4cac81SBjoern A. Zeeb atomic64_set(&kc->tx_pn, k->wk_keytsc); 5806b4cac81SBjoern A. Zeeb kc->keylen = k->wk_keylen; 5816b4cac81SBjoern A. Zeeb memcpy(kc->key, k->wk_key, k->wk_keylen); 5826b4cac81SBjoern A. Zeeb 5836b4cac81SBjoern A. Zeeb switch (kc->cipher) { 5846b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP: 5856b4cac81SBjoern A. Zeeb kc->iv_len = k->wk_cipher->ic_header; 5866b4cac81SBjoern A. Zeeb kc->icv_len = k->wk_cipher->ic_trailer; 5876b4cac81SBjoern A. Zeeb break; 5886b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP: 5896b4cac81SBjoern A. Zeeb default: 5906b4cac81SBjoern A. Zeeb IMPROVE(); 5916b4cac81SBjoern A. Zeeb return (0); 5926b4cac81SBjoern A. Zeeb }; 5936b4cac81SBjoern A. Zeeb 5946b4cac81SBjoern A. Zeeb ni = vap->iv_bss; 5956b4cac81SBjoern A. Zeeb sta = ieee80211_find_sta(vif, ni->ni_bssid); 5966b4cac81SBjoern A. Zeeb if (sta != NULL) { 5976b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 5986b4cac81SBjoern A. Zeeb 5996b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 6006b4cac81SBjoern A. Zeeb lsta->kc = kc; 6016b4cac81SBjoern A. Zeeb } 6026b4cac81SBjoern A. Zeeb 6036b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_set_key(hw, cmd, vif, sta, kc); 6046b4cac81SBjoern A. Zeeb if (error != 0) { 6056b4cac81SBjoern A. Zeeb /* XXX-BZ leaking kc currently */ 6066b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: set_key failed: %d\n", __func__, error); 6076b4cac81SBjoern A. Zeeb return (0); 6086b4cac81SBjoern A. Zeeb } else { 6096b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: set_key succeeded: keyidx %u hw_key_idx %u " 6106b4cac81SBjoern A. Zeeb "flags %#10x\n", __func__, 6116b4cac81SBjoern A. Zeeb kc->keyidx, kc->hw_key_idx, kc->flags); 6126b4cac81SBjoern A. Zeeb return (1); 6136b4cac81SBjoern A. Zeeb } 6146b4cac81SBjoern A. Zeeb } 6156b4cac81SBjoern A. Zeeb 6166b4cac81SBjoern A. Zeeb static int 6176b4cac81SBjoern A. Zeeb lkpi_iv_key_delete(struct ieee80211vap *vap, const struct ieee80211_key *k) 6186b4cac81SBjoern A. Zeeb { 6196b4cac81SBjoern A. Zeeb 6206b4cac81SBjoern A. Zeeb /* XXX-BZ one day we should replace this iterating over VIFs, or node list? */ 6216b4cac81SBjoern A. Zeeb return (_lkpi_iv_key_set_delete(vap, k, DISABLE_KEY)); 6226b4cac81SBjoern A. Zeeb } 6236b4cac81SBjoern A. Zeeb static int 6246b4cac81SBjoern A. Zeeb lkpi_iv_key_set(struct ieee80211vap *vap, const struct ieee80211_key *k) 6256b4cac81SBjoern A. Zeeb { 6266b4cac81SBjoern A. Zeeb 6276b4cac81SBjoern A. Zeeb return (_lkpi_iv_key_set_delete(vap, k, SET_KEY)); 6286b4cac81SBjoern A. Zeeb } 6296b4cac81SBjoern A. Zeeb #endif 6306b4cac81SBjoern A. Zeeb 6316b4cac81SBjoern A. Zeeb static u_int 6326b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast_copy(void *arg, struct sockaddr_dl *sdl, u_int cnt) 6336b4cac81SBjoern A. Zeeb { 6346b4cac81SBjoern A. Zeeb struct netdev_hw_addr_list *mc_list; 6356b4cac81SBjoern A. Zeeb struct netdev_hw_addr *addr; 6366b4cac81SBjoern A. Zeeb 6376b4cac81SBjoern A. Zeeb KASSERT(arg != NULL && sdl != NULL, ("%s: arg %p sdl %p cnt %u\n", 6386b4cac81SBjoern A. Zeeb __func__, arg, sdl, cnt)); 6396b4cac81SBjoern A. Zeeb 6406b4cac81SBjoern A. Zeeb mc_list = arg; 6416b4cac81SBjoern A. Zeeb /* If it is on the list already skip it. */ 6426b4cac81SBjoern A. Zeeb netdev_hw_addr_list_for_each(addr, mc_list) { 6436b4cac81SBjoern A. Zeeb if (!memcmp(addr->addr, LLADDR(sdl), sdl->sdl_alen)) 6446b4cac81SBjoern A. Zeeb return (0); 6456b4cac81SBjoern A. Zeeb } 6466b4cac81SBjoern A. Zeeb 6476b4cac81SBjoern A. Zeeb addr = malloc(sizeof(*addr), M_LKPI80211, M_NOWAIT | M_ZERO); 6486b4cac81SBjoern A. Zeeb if (addr == NULL) 6496b4cac81SBjoern A. Zeeb return (0); 6506b4cac81SBjoern A. Zeeb 6516b4cac81SBjoern A. Zeeb INIT_LIST_HEAD(&addr->addr_list); 6526b4cac81SBjoern A. Zeeb memcpy(addr->addr, LLADDR(sdl), sdl->sdl_alen); 6536b4cac81SBjoern A. Zeeb /* XXX this should be a netdev function? */ 6546b4cac81SBjoern A. Zeeb list_add(&addr->addr_list, &mc_list->addr_list); 6556b4cac81SBjoern A. Zeeb mc_list->count++; 6566b4cac81SBjoern A. Zeeb 6579d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 6589d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 6596b4cac81SBjoern A. Zeeb printf("%s:%d: mc_list count %d: added %6D\n", 6606b4cac81SBjoern A. Zeeb __func__, __LINE__, mc_list->count, addr->addr, ":"); 6619d9ba2b7SBjoern A. Zeeb #endif 6626b4cac81SBjoern A. Zeeb 6636b4cac81SBjoern A. Zeeb return (1); 6646b4cac81SBjoern A. Zeeb } 6656b4cac81SBjoern A. Zeeb 6666b4cac81SBjoern A. Zeeb static void 6676b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(struct ieee80211com *ic, bool force) 6686b4cac81SBjoern A. Zeeb { 6696b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 6706b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 6716b4cac81SBjoern A. Zeeb struct netdev_hw_addr_list mc_list; 6726b4cac81SBjoern A. Zeeb struct list_head *le, *next; 6736b4cac81SBjoern A. Zeeb struct netdev_hw_addr *addr; 6746b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 6756b4cac81SBjoern A. Zeeb u64 mc; 6766b4cac81SBjoern A. Zeeb unsigned int changed_flags, total_flags; 6776b4cac81SBjoern A. Zeeb 6786b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 6796b4cac81SBjoern A. Zeeb 6806b4cac81SBjoern A. Zeeb if (lhw->ops->prepare_multicast == NULL || 6816b4cac81SBjoern A. Zeeb lhw->ops->configure_filter == NULL) 6826b4cac81SBjoern A. Zeeb return; 6836b4cac81SBjoern A. Zeeb 6846b4cac81SBjoern A. Zeeb if (!lhw->update_mc && !force) 6856b4cac81SBjoern A. Zeeb return; 6866b4cac81SBjoern A. Zeeb 6876b4cac81SBjoern A. Zeeb changed_flags = total_flags = 0; 6886b4cac81SBjoern A. Zeeb mc_list.count = 0; 6896b4cac81SBjoern A. Zeeb INIT_LIST_HEAD(&mc_list.addr_list); 6906b4cac81SBjoern A. Zeeb if (ic->ic_allmulti == 0) { 6916b4cac81SBjoern A. Zeeb TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) 6926b4cac81SBjoern A. Zeeb if_foreach_llmaddr(vap->iv_ifp, 6936b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast_copy, &mc_list); 6946b4cac81SBjoern A. Zeeb } else { 6956b4cac81SBjoern A. Zeeb changed_flags |= FIF_ALLMULTI; 6966b4cac81SBjoern A. Zeeb } 6976b4cac81SBjoern A. Zeeb 6986b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 6996b4cac81SBjoern A. Zeeb mc = lkpi_80211_mo_prepare_multicast(hw, &mc_list); 7006b4cac81SBjoern A. Zeeb /* 7016b4cac81SBjoern A. Zeeb * XXX-BZ make sure to get this sorted what is a change, 7026b4cac81SBjoern A. Zeeb * what gets all set; what was already set? 7036b4cac81SBjoern A. Zeeb */ 7046b4cac81SBjoern A. Zeeb total_flags = changed_flags; 7056b4cac81SBjoern A. Zeeb lkpi_80211_mo_configure_filter(hw, changed_flags, &total_flags, mc); 7066b4cac81SBjoern A. Zeeb 7079d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 7089d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 7096b4cac81SBjoern A. Zeeb printf("%s: changed_flags %#06x count %d total_flags %#010x\n", 7106b4cac81SBjoern A. Zeeb __func__, changed_flags, mc_list.count, total_flags); 7119d9ba2b7SBjoern A. Zeeb #endif 7126b4cac81SBjoern A. Zeeb 7136b4cac81SBjoern A. Zeeb if (mc_list.count != 0) { 7146b4cac81SBjoern A. Zeeb list_for_each_safe(le, next, &mc_list.addr_list) { 7156b4cac81SBjoern A. Zeeb addr = list_entry(le, struct netdev_hw_addr, addr_list); 7166b4cac81SBjoern A. Zeeb free(addr, M_LKPI80211); 7176b4cac81SBjoern A. Zeeb mc_list.count--; 7186b4cac81SBjoern A. Zeeb } 7196b4cac81SBjoern A. Zeeb } 7206b4cac81SBjoern A. Zeeb KASSERT(mc_list.count == 0, ("%s: mc_list %p count %d != 0\n", 7216b4cac81SBjoern A. Zeeb __func__, &mc_list, mc_list.count)); 7226b4cac81SBjoern A. Zeeb } 7236b4cac81SBjoern A. Zeeb 724fa8f007dSBjoern A. Zeeb static enum ieee80211_bss_changed 725fa8f007dSBjoern A. Zeeb lkpi_update_dtim_tsf(struct ieee80211_vif *vif, struct ieee80211_node *ni, 726fa8f007dSBjoern A. Zeeb struct ieee80211vap *vap, const char *_f, int _l) 727fa8f007dSBjoern A. Zeeb { 728fa8f007dSBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 729fa8f007dSBjoern A. Zeeb 730fa8f007dSBjoern A. Zeeb bss_changed = 0; 731fa8f007dSBjoern A. Zeeb 7329d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 7339d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 734fa8f007dSBjoern A. Zeeb printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u " 735fa8f007dSBjoern A. Zeeb "dtim_period %u sync_dtim_count %u sync_tsf %ju " 736fa8f007dSBjoern A. Zeeb "sync_device_ts %u bss_changed %#08x\n", 737fa8f007dSBjoern A. Zeeb __func__, __LINE__, _f, _l, 738fa8f007dSBjoern A. Zeeb vif->bss_conf.assoc, vif->bss_conf.aid, 739fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int, vif->bss_conf.dtim_period, 740fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count, 741fa8f007dSBjoern A. Zeeb (uintmax_t)vif->bss_conf.sync_tsf, 742fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_device_ts, 743fa8f007dSBjoern A. Zeeb bss_changed); 7449d9ba2b7SBjoern A. Zeeb #endif 745fa8f007dSBjoern A. Zeeb 746fa8f007dSBjoern A. Zeeb if (vif->bss_conf.beacon_int != ni->ni_intval) { 747fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int = ni->ni_intval; 748fa8f007dSBjoern A. Zeeb /* iwlwifi FW bug workaround; iwl_mvm_mac_sta_state. */ 749fa8f007dSBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16) 750fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int = 16; 751fa8f007dSBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INT; 752fa8f007dSBjoern A. Zeeb } 753fa8f007dSBjoern A. Zeeb if (vif->bss_conf.dtim_period != vap->iv_dtim_period && 754fa8f007dSBjoern A. Zeeb vap->iv_dtim_period > 0) { 755fa8f007dSBjoern A. Zeeb vif->bss_conf.dtim_period = vap->iv_dtim_period; 756fa8f007dSBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INFO; 757fa8f007dSBjoern A. Zeeb } 758fa8f007dSBjoern A. Zeeb 759fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count = vap->iv_dtim_count; 760fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_tsf = le64toh(ni->ni_tstamp.tsf); 761fa8f007dSBjoern A. Zeeb /* vif->bss_conf.sync_device_ts = set in linuxkpi_ieee80211_rx. */ 762fa8f007dSBjoern A. Zeeb 7639d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 7649d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 765fa8f007dSBjoern A. Zeeb printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u " 766fa8f007dSBjoern A. Zeeb "dtim_period %u sync_dtim_count %u sync_tsf %ju " 767fa8f007dSBjoern A. Zeeb "sync_device_ts %u bss_changed %#08x\n", 768fa8f007dSBjoern A. Zeeb __func__, __LINE__, _f, _l, 769fa8f007dSBjoern A. Zeeb vif->bss_conf.assoc, vif->bss_conf.aid, 770fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int, vif->bss_conf.dtim_period, 771fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count, 772fa8f007dSBjoern A. Zeeb (uintmax_t)vif->bss_conf.sync_tsf, 773fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_device_ts, 774fa8f007dSBjoern A. Zeeb bss_changed); 7759d9ba2b7SBjoern A. Zeeb #endif 776fa8f007dSBjoern A. Zeeb 777fa8f007dSBjoern A. Zeeb return (bss_changed); 778fa8f007dSBjoern A. Zeeb } 779fa8f007dSBjoern A. Zeeb 7806b4cac81SBjoern A. Zeeb static void 7816b4cac81SBjoern A. Zeeb lkpi_stop_hw_scan(struct lkpi_hw *lhw, struct ieee80211_vif *vif) 7826b4cac81SBjoern A. Zeeb { 7836b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 7846b4cac81SBjoern A. Zeeb int error; 7856b4cac81SBjoern A. Zeeb 786a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) == 0) 7876b4cac81SBjoern A. Zeeb return; 7886b4cac81SBjoern A. Zeeb 7896b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 7906b4cac81SBjoern A. Zeeb 791bec76628SBjoern A. Zeeb IEEE80211_UNLOCK(lhw->ic); 792bec76628SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 7936b4cac81SBjoern A. Zeeb /* Need to cancel the scan. */ 7946b4cac81SBjoern A. Zeeb lkpi_80211_mo_cancel_hw_scan(hw, vif); 7956b4cac81SBjoern A. Zeeb 7966b4cac81SBjoern A. Zeeb /* Need to make sure we see ieee80211_scan_completed. */ 7976b4cac81SBjoern A. Zeeb error = msleep(lhw, &lhw->mtx, 0, "lhwscanstop", hz/2); 798bec76628SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 799bec76628SBjoern A. Zeeb IEEE80211_LOCK(lhw->ic); 8006b4cac81SBjoern A. Zeeb 801a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) 8026b4cac81SBjoern A. Zeeb ic_printf(lhw->ic, "%s: failed to cancel scan: %d (%p, %p)\n", 8036b4cac81SBjoern A. Zeeb __func__, error, lhw, vif); 8046b4cac81SBjoern A. Zeeb } 8056b4cac81SBjoern A. Zeeb 8066b4cac81SBjoern A. Zeeb static void 807086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(struct ieee80211_hw *hw, bool new) 808086be6a8SBjoern A. Zeeb { 809086be6a8SBjoern A. Zeeb struct lkpi_hw *lhw; 810086be6a8SBjoern A. Zeeb int error; 811086be6a8SBjoern A. Zeeb bool old; 812086be6a8SBjoern A. Zeeb 813086be6a8SBjoern A. Zeeb old = hw->conf.flags & IEEE80211_CONF_IDLE; 814086be6a8SBjoern A. Zeeb if (old == new) 815086be6a8SBjoern A. Zeeb return; 816086be6a8SBjoern A. Zeeb 817086be6a8SBjoern A. Zeeb hw->conf.flags ^= IEEE80211_CONF_IDLE; 818086be6a8SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_IDLE); 819086be6a8SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) { 820086be6a8SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 821086be6a8SBjoern A. Zeeb ic_printf(lhw->ic, "ERROR: %s: config %#0x returned %d\n", 822086be6a8SBjoern A. Zeeb __func__, IEEE80211_CONF_CHANGE_IDLE, error); 823086be6a8SBjoern A. Zeeb } 824086be6a8SBjoern A. Zeeb } 825086be6a8SBjoern A. Zeeb 826086be6a8SBjoern A. Zeeb static void 8276b4cac81SBjoern A. Zeeb lkpi_disassoc(struct ieee80211_sta *sta, struct ieee80211_vif *vif, 8286b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw) 8296b4cac81SBjoern A. Zeeb { 8306b4cac81SBjoern A. Zeeb sta->aid = 0; 8316b4cac81SBjoern A. Zeeb if (vif->bss_conf.assoc) { 8326b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 8336b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 8346b4cac81SBjoern A. Zeeb 8356b4cac81SBjoern A. Zeeb lhw->update_mc = true; 8366b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(lhw->ic, true); 8376b4cac81SBjoern A. Zeeb 8386b4cac81SBjoern A. Zeeb changed = 0; 8396b4cac81SBjoern A. Zeeb vif->bss_conf.assoc = false; 8406b4cac81SBjoern A. Zeeb vif->bss_conf.aid = 0; 8416b4cac81SBjoern A. Zeeb changed |= BSS_CHANGED_ASSOC; 842d9f59799SBjoern A. Zeeb /* 843d9f59799SBjoern A. Zeeb * This will remove the sta from firmware for iwlwifi. 844d9f59799SBjoern A. Zeeb * So confusing that they use state and flags and ... ^%$%#%$^. 845d9f59799SBjoern A. Zeeb */ 8466b4cac81SBjoern A. Zeeb IMPROVE(); 8476b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 8486b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, 8496b4cac81SBjoern A. Zeeb changed); 850086be6a8SBjoern A. Zeeb 851086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true); 8526b4cac81SBjoern A. Zeeb } 8536b4cac81SBjoern A. Zeeb } 8546b4cac81SBjoern A. Zeeb 8556b4cac81SBjoern A. Zeeb static void 8566b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(struct ieee80211_hw *hw, struct ieee80211_sta *sta, 8576b4cac81SBjoern A. Zeeb bool dequeue_seen, bool no_emptyq) 8586b4cac81SBjoern A. Zeeb { 8596b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 8606b4cac81SBjoern A. Zeeb int tid; 8616b4cac81SBjoern A. Zeeb 8626b4cac81SBjoern A. Zeeb /* Wake up all queues to know they are allocated in the driver. */ 8636b4cac81SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 8646b4cac81SBjoern A. Zeeb 8656b4cac81SBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) { 8666b4cac81SBjoern A. Zeeb IMPROVE("station specific?"); 8676b4cac81SBjoern A. Zeeb if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ)) 8686b4cac81SBjoern A. Zeeb continue; 8696b4cac81SBjoern A. Zeeb } else if (tid >= hw->queues) 8706b4cac81SBjoern A. Zeeb continue; 8716b4cac81SBjoern A. Zeeb 8726b4cac81SBjoern A. Zeeb if (sta->txq[tid] == NULL) 8736b4cac81SBjoern A. Zeeb continue; 8746b4cac81SBjoern A. Zeeb 8756b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]); 8766b4cac81SBjoern A. Zeeb if (dequeue_seen && !ltxq->seen_dequeue) 8776b4cac81SBjoern A. Zeeb continue; 8786b4cac81SBjoern A. Zeeb 8796b4cac81SBjoern A. Zeeb if (no_emptyq && skb_queue_empty(<xq->skbq)) 8806b4cac81SBjoern A. Zeeb continue; 8816b4cac81SBjoern A. Zeeb 8826b4cac81SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, sta->txq[tid]); 8836b4cac81SBjoern A. Zeeb } 8846b4cac81SBjoern A. Zeeb } 8856b4cac81SBjoern A. Zeeb 8866b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 8876b4cac81SBjoern A. Zeeb 8886b4cac81SBjoern A. Zeeb static int 8896b4cac81SBjoern A. Zeeb lkpi_sta_state_do_nada(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 8906b4cac81SBjoern A. Zeeb { 8916b4cac81SBjoern A. Zeeb 8926b4cac81SBjoern A. Zeeb return (0); 8936b4cac81SBjoern A. Zeeb } 8946b4cac81SBjoern A. Zeeb 8956b4cac81SBjoern A. Zeeb /* lkpi_iv_newstate() handles the stop scan case generally. */ 8966b4cac81SBjoern A. Zeeb #define lkpi_sta_scan_to_init(_v, _n, _a) lkpi_sta_state_do_nada(_v, _n, _a) 8976b4cac81SBjoern A. Zeeb 8986b4cac81SBjoern A. Zeeb static int 8996b4cac81SBjoern A. Zeeb lkpi_sta_scan_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 9006b4cac81SBjoern A. Zeeb { 9016b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 9026b4cac81SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 9036b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 9046b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 9056b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 9066b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 9076b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 9086b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 9096b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 9106b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 9116b4cac81SBjoern A. Zeeb uint32_t changed; 9126b4cac81SBjoern A. Zeeb int error; 9136b4cac81SBjoern A. Zeeb 9146b4cac81SBjoern A. Zeeb chan = lkpi_get_lkpi80211_chan(vap->iv_ic, vap->iv_bss); 9156b4cac81SBjoern A. Zeeb if (chan == NULL) { 9166b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: failed to get channel\n", __func__); 9176b4cac81SBjoern A. Zeeb return (ESRCH); 9186b4cac81SBjoern A. Zeeb } 9196b4cac81SBjoern A. Zeeb 9206b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 9216b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 9226b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 9236b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 9246b4cac81SBjoern A. Zeeb 925d9f59799SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 926d9f59799SBjoern A. Zeeb 9276b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 9286b4cac81SBjoern A. Zeeb 9296b4cac81SBjoern A. Zeeb /* Add chanctx (or if exists, change it). */ 9306b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 9316b4cac81SBjoern A. Zeeb conf = vif->chanctx_conf; 9326b4cac81SBjoern A. Zeeb IMPROVE("diff changes for changed, working on live copy, rcu"); 9336b4cac81SBjoern A. Zeeb } else { 9346b4cac81SBjoern A. Zeeb /* Keep separate alloc as in Linux this is rcu managed? */ 9356b4cac81SBjoern A. Zeeb conf = malloc(sizeof(*conf) + hw->chanctx_data_size, 9366b4cac81SBjoern A. Zeeb M_LKPI80211, M_WAITOK | M_ZERO); 9376b4cac81SBjoern A. Zeeb } 9386b4cac81SBjoern A. Zeeb 9396b4cac81SBjoern A. Zeeb conf->rx_chains_dynamic = 1; 9406b4cac81SBjoern A. Zeeb conf->rx_chains_static = 1; 9416b4cac81SBjoern A. Zeeb conf->radar_enabled = 9426b4cac81SBjoern A. Zeeb (chan->flags & IEEE80211_CHAN_RADAR) ? true : false; 9436b4cac81SBjoern A. Zeeb conf->def.chan = chan; 9446b4cac81SBjoern A. Zeeb conf->def.width = NL80211_CHAN_WIDTH_20_NOHT; 9456b4cac81SBjoern A. Zeeb conf->def.center_freq1 = chan->center_freq; 9466b4cac81SBjoern A. Zeeb conf->def.center_freq2 = 0; 9476b4cac81SBjoern A. Zeeb /* Responder ... */ 9486b4cac81SBjoern A. Zeeb conf->min_def.chan = chan; 9496b4cac81SBjoern A. Zeeb conf->min_def.width = NL80211_CHAN_WIDTH_20_NOHT; 9506b4cac81SBjoern A. Zeeb conf->min_def.center_freq1 = chan->center_freq; 9516b4cac81SBjoern A. Zeeb conf->min_def.center_freq2 = 0; 9526b4cac81SBjoern A. Zeeb IMPROVE("currently 20_NOHT only"); 9536b4cac81SBjoern A. Zeeb 9546b4cac81SBjoern A. Zeeb error = 0; 9556b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 9566b4cac81SBjoern A. Zeeb changed = IEEE80211_CHANCTX_CHANGE_MIN_WIDTH; 9576b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_RADAR; 9586b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_RX_CHAINS; 9596b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_WIDTH; 9606b4cac81SBjoern A. Zeeb lkpi_80211_mo_change_chanctx(hw, conf, changed); 9616b4cac81SBjoern A. Zeeb } else { 9626b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_add_chanctx(hw, conf); 9636b4cac81SBjoern A. Zeeb if (error == 0 || error == EOPNOTSUPP) { 9646b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.chan = conf->def.chan; 9656b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.width = conf->def.width; 9666b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.center_freq1 = 9676b4cac81SBjoern A. Zeeb conf->def.center_freq1; 9686b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.center_freq2 = 9696b4cac81SBjoern A. Zeeb conf->def.center_freq2; 9706b4cac81SBjoern A. Zeeb } else { 9716b4cac81SBjoern A. Zeeb goto out; 9726b4cac81SBjoern A. Zeeb } 9736b4cac81SBjoern A. Zeeb /* Assign vif chanctx. */ 9746b4cac81SBjoern A. Zeeb if (error == 0) 9756b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_assign_vif_chanctx(hw, vif, conf); 9766b4cac81SBjoern A. Zeeb if (error == EOPNOTSUPP) 9776b4cac81SBjoern A. Zeeb error = 0; 9786b4cac81SBjoern A. Zeeb if (error != 0) { 9796b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 9806b4cac81SBjoern A. Zeeb free(conf, M_LKPI80211); 9816b4cac81SBjoern A. Zeeb goto out; 9826b4cac81SBjoern A. Zeeb } 9836b4cac81SBjoern A. Zeeb } 9846b4cac81SBjoern A. Zeeb IMPROVE("update radiotap chan fields too"); 9856b4cac81SBjoern A. Zeeb 9866b4cac81SBjoern A. Zeeb /* Set bss info (bss_info_changed). */ 9876b4cac81SBjoern A. Zeeb bss_changed = 0; 988caaa79c3SBjoern A. Zeeb vif->bss_conf.bssid = ni->ni_bssid; 9896b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 9906b4cac81SBjoern A. Zeeb vif->bss_conf.txpower = ni->ni_txpower; 9916b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_TXPOWER; 9926b4cac81SBjoern A. Zeeb vif->bss_conf.idle = false; 9936b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_IDLE; 994c8dafefaSBjoern A. Zeeb 9956b4cac81SBjoern A. Zeeb /* Should almost assert it is this. */ 9966b4cac81SBjoern A. Zeeb vif->bss_conf.assoc = false; 9976b4cac81SBjoern A. Zeeb vif->bss_conf.aid = 0; 998fa8f007dSBjoern A. Zeeb 999fa8f007dSBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 1000fa8f007dSBjoern A. Zeeb 10016b4cac81SBjoern A. Zeeb /* RATES */ 10026b4cac81SBjoern A. Zeeb IMPROVE("bss info: not all needs to come now and rates are missing"); 10036b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 10046b4cac81SBjoern A. Zeeb 1005d9f59799SBjoern A. Zeeb /* 1006d9f59799SBjoern A. Zeeb * This is a bandaid for now. If we went through (*iv_update_bss)() 1007d9f59799SBjoern A. Zeeb * and then removed the lsta we end up here without a lsta and have 1008d9f59799SBjoern A. Zeeb * to manually allocate and link it in as lkpi_ic_node_alloc()/init() 1009d9f59799SBjoern A. Zeeb * would normally do. 1010d9f59799SBjoern A. Zeeb * XXX-BZ I do not like this but currently we have no good way of 1011d9f59799SBjoern A. Zeeb * intercepting the bss swap and state changes and packets going out 1012d9f59799SBjoern A. Zeeb * workflow so live with this. It is a compat layer after all. 1013d9f59799SBjoern A. Zeeb */ 1014d9f59799SBjoern A. Zeeb if (ni->ni_drv_data == NULL) { 1015d9f59799SBjoern A. Zeeb lsta = lkpi_lsta_alloc(vap, ni->ni_macaddr, hw, ni); 1016d9f59799SBjoern A. Zeeb if (lsta == NULL) { 1017d9f59799SBjoern A. Zeeb error = ENOMEM; 1018d9f59799SBjoern A. Zeeb goto out; 1019d9f59799SBjoern A. Zeeb } 1020d9f59799SBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 1021d9f59799SBjoern A. Zeeb } else { 10226b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 1023d9f59799SBjoern A. Zeeb } 1024e24e8103SBjoern A. Zeeb 1025e24e8103SBjoern A. Zeeb /* Insert the [l]sta into the list of known stations. */ 1026e24e8103SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 1027e24e8103SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lvif->lsta_head, lsta, lsta_entry); 1028e24e8103SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 1029e24e8103SBjoern A. Zeeb 1030d9f59799SBjoern A. Zeeb /* Add (or adjust) sta and change state (from NOTEXIST) to NONE. */ 10316b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 10326b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NOTEXIST, ("%s: lsta %p state not " 10336b4cac81SBjoern A. Zeeb "NOTEXIST: %#x\n", __func__, lsta, lsta->state)); 1034*e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE); 10356b4cac81SBjoern A. Zeeb if (error != 0) { 10366b4cac81SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 10376b4cac81SBjoern A. Zeeb goto out; 10386b4cac81SBjoern A. Zeeb } 10396b4cac81SBjoern A. Zeeb #if 0 10406b4cac81SBjoern A. Zeeb lsta->added_to_drv = true; /* mo manages. */ 10416b4cac81SBjoern A. Zeeb #endif 10426b4cac81SBjoern A. Zeeb 10439d9ba2b7SBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 10449d9ba2b7SBjoern A. Zeeb 10456b4cac81SBjoern A. Zeeb /* 10466b4cac81SBjoern A. Zeeb * Wakeup all queues now that sta is there so we have as much time to 10476b4cac81SBjoern A. Zeeb * possibly prepare the queue in the driver to be ready for the 1st 10486b4cac81SBjoern A. Zeeb * packet; lkpi_80211_txq_tx_one() still has a workaround as there 10496b4cac81SBjoern A. Zeeb * is no guarantee or way to check. 1050d9f59799SBjoern A. Zeeb * XXX-BZ and by now we know that this does not work on all drivers 1051d9f59799SBjoern A. Zeeb * for all queues. 10526b4cac81SBjoern A. Zeeb */ 1053*e7fe0373SBjoern A. Zeeb lkpi_wake_tx_queues(hw, LSTA_TO_STA(lsta), false, false); 10546b4cac81SBjoern A. Zeeb 10556b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 10566b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 10576b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 10586b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 10596b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 10606b4cac81SBjoern A. Zeeb 10616b4cac81SBjoern A. Zeeb /* 10626b4cac81SBjoern A. Zeeb * What is going to happen next: 10636b4cac81SBjoern A. Zeeb * - <twiddle> .. we should end up in "auth_to_assoc" 10646b4cac81SBjoern A. Zeeb * - event_callback 10656b4cac81SBjoern A. Zeeb * - update sta_state (NONE to AUTH) 10666b4cac81SBjoern A. Zeeb * - mgd_complete_tx 10676b4cac81SBjoern A. Zeeb * (ideally we'd do that on a callback for something else ...) 10686b4cac81SBjoern A. Zeeb */ 10696b4cac81SBjoern A. Zeeb 10706b4cac81SBjoern A. Zeeb out: 10716b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 10726b4cac81SBjoern A. Zeeb if (ni != NULL) 10736b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 10746b4cac81SBjoern A. Zeeb return (error); 10756b4cac81SBjoern A. Zeeb } 10766b4cac81SBjoern A. Zeeb 10776b4cac81SBjoern A. Zeeb static int 10786b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 10796b4cac81SBjoern A. Zeeb { 10806b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 10816b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 10826b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 10836b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 10846b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 10856b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 10866b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 10876b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 10886b4cac81SBjoern A. Zeeb int error; 10896b4cac81SBjoern A. Zeeb 10906b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 10916b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 10926b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 10936b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 10946b4cac81SBjoern A. Zeeb 10956b4cac81SBjoern A. Zeeb /* Keep ni around. */ 10966b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 10976b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 10986b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 10996b4cac81SBjoern A. Zeeb 110067674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 11016b4cac81SBjoern A. Zeeb 11026b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 11036b4cac81SBjoern A. Zeeb 1104d9f59799SBjoern A. Zeeb /* flush, drop. */ 1105d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1106d9f59799SBjoern A. Zeeb 11076b4cac81SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 11086b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 11096b4cac81SBjoern A. Zeeb 11106b4cac81SBjoern A. Zeeb /* flush, no drop */ 11116b4cac81SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 11126b4cac81SBjoern A. Zeeb 11136b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 11146b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 11156b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 11166b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 11176b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 11186b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 11196b4cac81SBjoern A. Zeeb } 11206b4cac81SBjoern A. Zeeb 11216b4cac81SBjoern A. Zeeb /* sync_rx_queues */ 11226b4cac81SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 11236b4cac81SBjoern A. Zeeb 11246b4cac81SBjoern A. Zeeb /* sta_pre_rcu_remove */ 11256b4cac81SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 1126d9f59799SBjoern A. Zeeb 1127d9f59799SBjoern A. Zeeb /* Take the station down. */ 11286b4cac81SBjoern A. Zeeb 11296b4cac81SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 11306b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 11316b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 1132d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg)); 1133*e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST); 11346b4cac81SBjoern A. Zeeb if (error != 0) { 11356b4cac81SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 11366b4cac81SBjoern A. Zeeb goto out; 11376b4cac81SBjoern A. Zeeb } 11386b4cac81SBjoern A. Zeeb #if 0 11396b4cac81SBjoern A. Zeeb lsta->added_to_drv = false; /* mo manages. */ 11406b4cac81SBjoern A. Zeeb #endif 11416b4cac81SBjoern A. Zeeb 114267674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 11436b4cac81SBjoern A. Zeeb 1144d9f59799SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif); 1145d9f59799SBjoern A. Zeeb 1146d9f59799SBjoern A. Zeeb /* conf_tx */ 1147d9f59799SBjoern A. Zeeb 1148d9f59799SBjoern A. Zeeb /* Take the chan ctx down. */ 11496b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 11506b4cac81SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 11516b4cac81SBjoern A. Zeeb 11526b4cac81SBjoern A. Zeeb conf = vif->chanctx_conf; 11536b4cac81SBjoern A. Zeeb /* Remove vif context. */ 11546b4cac81SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->chanctx_conf); 11556b4cac81SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 11566b4cac81SBjoern A. Zeeb 11576b4cac81SBjoern A. Zeeb /* Remove chan ctx. */ 11586b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 11596b4cac81SBjoern A. Zeeb free(conf, M_LKPI80211); 11606b4cac81SBjoern A. Zeeb } 11616b4cac81SBjoern A. Zeeb 11626b4cac81SBjoern A. Zeeb out: 11636b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 11646b4cac81SBjoern A. Zeeb if (ni != NULL) 11656b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 11666b4cac81SBjoern A. Zeeb return (error); 11676b4cac81SBjoern A. Zeeb } 11686b4cac81SBjoern A. Zeeb 11696b4cac81SBjoern A. Zeeb static int 11706b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 11716b4cac81SBjoern A. Zeeb { 11726b4cac81SBjoern A. Zeeb int error; 11736b4cac81SBjoern A. Zeeb 11746b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_scan(vap, nstate, arg); 11756b4cac81SBjoern A. Zeeb if (error == 0) 11766b4cac81SBjoern A. Zeeb error = lkpi_sta_scan_to_init(vap, nstate, arg); 11776b4cac81SBjoern A. Zeeb return (error); 11786b4cac81SBjoern A. Zeeb } 11796b4cac81SBjoern A. Zeeb 11806b4cac81SBjoern A. Zeeb static int 11816b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 11826b4cac81SBjoern A. Zeeb { 11836b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 11846b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 11856b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 11866b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 11876b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 11886b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 11896b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 11906b4cac81SBjoern A. Zeeb int error; 11916b4cac81SBjoern A. Zeeb 11926b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 11936b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 11946b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 11956b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 11966b4cac81SBjoern A. Zeeb 11976b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 11986b4cac81SBjoern A. Zeeb ni = NULL; 11996b4cac81SBjoern A. Zeeb 12006b4cac81SBjoern A. Zeeb /* Finish auth. */ 12016b4cac81SBjoern A. Zeeb IMPROVE("event callback"); 12026b4cac81SBjoern A. Zeeb 12036b4cac81SBjoern A. Zeeb /* Update sta_state (NONE to AUTH). */ 12046b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 12056b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 12066b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 12076b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 12086b4cac81SBjoern A. Zeeb "NONE: %#x\n", __func__, lsta, lsta->state)); 1209*e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH); 12106b4cac81SBjoern A. Zeeb if (error != 0) 12116b4cac81SBjoern A. Zeeb goto out; 12126b4cac81SBjoern A. Zeeb 12136b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 12146b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 12156b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 12166b4cac81SBjoern A. Zeeb prep_tx_info.success = true; 12176b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 12186b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 12196b4cac81SBjoern A. Zeeb } 12206b4cac81SBjoern A. Zeeb 12216b4cac81SBjoern A. Zeeb /* Now start assoc. */ 12226b4cac81SBjoern A. Zeeb 12236b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 12246b4cac81SBjoern A. Zeeb if (!lsta->in_mgd) { 12256b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 12266b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 12276b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 12286b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 12296b4cac81SBjoern A. Zeeb } 12306b4cac81SBjoern A. Zeeb 12316b4cac81SBjoern A. Zeeb /* Wake tx queue to get packet out. */ 1232*e7fe0373SBjoern A. Zeeb lkpi_wake_tx_queues(hw, LSTA_TO_STA(lsta), true, true); 12336b4cac81SBjoern A. Zeeb 12346b4cac81SBjoern A. Zeeb /* 12356b4cac81SBjoern A. Zeeb * <twiddle> .. we end up in "assoc_to_run" 12366b4cac81SBjoern A. Zeeb * - update sta_state (AUTH to ASSOC) 12376b4cac81SBjoern A. Zeeb * - conf_tx [all] 12386b4cac81SBjoern A. Zeeb * - bss_info_changed (assoc, aid, ssid, ..) 12396b4cac81SBjoern A. Zeeb * - change_chanctx (if needed) 12406b4cac81SBjoern A. Zeeb * - event_callback 12416b4cac81SBjoern A. Zeeb * - mgd_complete_tx 12426b4cac81SBjoern A. Zeeb */ 12436b4cac81SBjoern A. Zeeb 12446b4cac81SBjoern A. Zeeb out: 12456b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 12466b4cac81SBjoern A. Zeeb if (ni != NULL) 12476b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 12486b4cac81SBjoern A. Zeeb return (error); 12496b4cac81SBjoern A. Zeeb } 12506b4cac81SBjoern A. Zeeb 12516b4cac81SBjoern A. Zeeb /* auth_to_auth, assoc_to_assoc. */ 12526b4cac81SBjoern A. Zeeb static int 12536b4cac81SBjoern A. Zeeb lkpi_sta_a_to_a(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 12546b4cac81SBjoern A. Zeeb { 12556b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 12566b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 12576b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 12586b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 12596b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 12606b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 12616b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 12626b4cac81SBjoern A. Zeeb 12636b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 12646b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 12656b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 12666b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 12676b4cac81SBjoern A. Zeeb 12686b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 12696b4cac81SBjoern A. Zeeb 12706b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 12716b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 12726b4cac81SBjoern A. Zeeb 12736b4cac81SBjoern A. Zeeb IMPROVE("event callback?"); 12746b4cac81SBjoern A. Zeeb 12756b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 12766b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 12776b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 12786b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 12796b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 12806b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 12816b4cac81SBjoern A. Zeeb } 12826b4cac81SBjoern A. Zeeb 12836b4cac81SBjoern A. Zeeb /* Now start assoc. */ 12846b4cac81SBjoern A. Zeeb 12856b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 12866b4cac81SBjoern A. Zeeb if (!lsta->in_mgd) { 12876b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 12886b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 12896b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 12906b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 12916b4cac81SBjoern A. Zeeb } 12926b4cac81SBjoern A. Zeeb 12936b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 12946b4cac81SBjoern A. Zeeb if (ni != NULL) 12956b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 12966b4cac81SBjoern A. Zeeb 12976b4cac81SBjoern A. Zeeb return (0); 12986b4cac81SBjoern A. Zeeb } 12996b4cac81SBjoern A. Zeeb 13006b4cac81SBjoern A. Zeeb static int 1301d9f59799SBjoern A. Zeeb _lkpi_sta_assoc_to_down(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 13026b4cac81SBjoern A. Zeeb { 13036b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 13046b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 13056b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 13066b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 13076b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 13086b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 13096b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 13106b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 1311d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 13126b4cac81SBjoern A. Zeeb int error; 13136b4cac81SBjoern A. Zeeb 13146b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 13156b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 13166b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 13176b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 13186b4cac81SBjoern A. Zeeb 13196b4cac81SBjoern A. Zeeb /* Keep ni around. */ 13206b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 13216b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 13226b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 13236b4cac81SBjoern A. Zeeb 132467674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1325d9f59799SBjoern A. Zeeb 1326d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 1327d9f59799SBjoern A. Zeeb 1328d9f59799SBjoern A. Zeeb /* flush, drop. */ 1329d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1330d9f59799SBjoern A. Zeeb 1331d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?"); 1332d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) && 1333d9f59799SBjoern A. Zeeb !lsta->in_mgd) { 1334d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1335d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 1336d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 1337d9f59799SBjoern A. Zeeb lsta->in_mgd = true; 1338d9f59799SBjoern A. Zeeb } 1339d9f59799SBjoern A. Zeeb 1340d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1341d9f59799SBjoern A. Zeeb 1342d9f59799SBjoern A. Zeeb /* Call iv_newstate first so we get potential DISASSOC packet out. */ 1343d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 1344d9f59799SBjoern A. Zeeb if (error != 0) 1345d9f59799SBjoern A. Zeeb goto outni; 1346d9f59799SBjoern A. Zeeb 1347d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 1348d9f59799SBjoern A. Zeeb 134967674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1350d9f59799SBjoern A. Zeeb 1351d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 1352d9f59799SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 1353d9f59799SBjoern A. Zeeb 1354d9f59799SBjoern A. Zeeb /* flush, no drop */ 1355d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 1356d9f59799SBjoern A. Zeeb 13576b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 13586b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 13596b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 13606b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 13616b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 13626b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 13636b4cac81SBjoern A. Zeeb } 13646b4cac81SBjoern A. Zeeb 1365d9f59799SBjoern A. Zeeb /* sync_rx_queues */ 1366d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 1367d9f59799SBjoern A. Zeeb 1368d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */ 1369d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 1370d9f59799SBjoern A. Zeeb 1371d9f59799SBjoern A. Zeeb /* Take the station down. */ 1372d9f59799SBjoern A. Zeeb 13736b4cac81SBjoern A. Zeeb /* Update sta and change state (from AUTH) to NONE. */ 13746b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 13756b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 13766b4cac81SBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 1377*e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE); 13786b4cac81SBjoern A. Zeeb if (error != 0) 13796b4cac81SBjoern A. Zeeb goto out; 13806b4cac81SBjoern A. Zeeb 138167674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 13826b4cac81SBjoern A. Zeeb 1383d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 1384d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 1385d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 1386d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg)); 1387*e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST); 1388d9f59799SBjoern A. Zeeb if (error != 0) { 1389d9f59799SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 1390d9f59799SBjoern A. Zeeb goto out; 1391d9f59799SBjoern A. Zeeb } 1392d9f59799SBjoern A. Zeeb #if 0 1393d9f59799SBjoern A. Zeeb lsta->added_to_drv = false; /* mo manages. */ 1394d9f59799SBjoern A. Zeeb #endif 1395d9f59799SBjoern A. Zeeb 139667674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1397d9f59799SBjoern A. Zeeb 1398d9f59799SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 1399d9f59799SBjoern A. Zeeb /* We need to do this now, can only do after sta is IEEE80211_STA_NOTEXIST. */ 1400d9f59799SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw); 1401d9f59799SBjoern A. Zeeb 1402d9f59799SBjoern A. Zeeb IMPROVE("Any bss_info changes to announce?"); 1403d9f59799SBjoern A. Zeeb bss_changed = 0; 1404d9f59799SBjoern A. Zeeb vif->bss_conf.qos = 0; 1405d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 1406d9f59799SBjoern A. Zeeb vif->bss_conf.ssid_len = 0; 1407d9f59799SBjoern A. Zeeb memset(vif->bss_conf.ssid, '\0', sizeof(vif->bss_conf.ssid)); 1408d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 1409d9f59799SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 1410d9f59799SBjoern A. Zeeb 1411d9f59799SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif); 1412d9f59799SBjoern A. Zeeb 1413d9f59799SBjoern A. Zeeb /* conf_tx */ 1414d9f59799SBjoern A. Zeeb 1415d9f59799SBjoern A. Zeeb /* Take the chan ctx down. */ 1416d9f59799SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 1417d9f59799SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 1418d9f59799SBjoern A. Zeeb 1419d9f59799SBjoern A. Zeeb conf = vif->chanctx_conf; 1420d9f59799SBjoern A. Zeeb /* Remove vif context. */ 1421d9f59799SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->chanctx_conf); 1422d9f59799SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 1423d9f59799SBjoern A. Zeeb 1424d9f59799SBjoern A. Zeeb /* Remove chan ctx. */ 1425d9f59799SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 1426d9f59799SBjoern A. Zeeb free(conf, M_LKPI80211); 1427d9f59799SBjoern A. Zeeb } 1428d9f59799SBjoern A. Zeeb 1429d9f59799SBjoern A. Zeeb error = EALREADY; 14306b4cac81SBjoern A. Zeeb out: 14316b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1432d9f59799SBjoern A. Zeeb outni: 14336b4cac81SBjoern A. Zeeb if (ni != NULL) 14346b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 14356b4cac81SBjoern A. Zeeb return (error); 14366b4cac81SBjoern A. Zeeb } 14376b4cac81SBjoern A. Zeeb 14386b4cac81SBjoern A. Zeeb static int 1439d9f59799SBjoern A. Zeeb lkpi_sta_assoc_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 1440d9f59799SBjoern A. Zeeb { 1441d9f59799SBjoern A. Zeeb int error; 1442d9f59799SBjoern A. Zeeb 1443d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg); 1444d9f59799SBjoern A. Zeeb if (error != 0 && error != EALREADY) 1445d9f59799SBjoern A. Zeeb return (error); 1446d9f59799SBjoern A. Zeeb 1447d9f59799SBjoern A. Zeeb /* At this point iv_bss is long a new node! */ 1448d9f59799SBjoern A. Zeeb 1449d9f59799SBjoern A. Zeeb error |= lkpi_sta_scan_to_auth(vap, nstate, 0); 1450d9f59799SBjoern A. Zeeb return (error); 1451d9f59799SBjoern A. Zeeb } 1452d9f59799SBjoern A. Zeeb 1453d9f59799SBjoern A. Zeeb static int 14546b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 14556b4cac81SBjoern A. Zeeb { 14566b4cac81SBjoern A. Zeeb int error; 14576b4cac81SBjoern A. Zeeb 1458d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg); 14596b4cac81SBjoern A. Zeeb return (error); 14606b4cac81SBjoern A. Zeeb } 14616b4cac81SBjoern A. Zeeb 14626b4cac81SBjoern A. Zeeb static int 14636b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 14646b4cac81SBjoern A. Zeeb { 14656b4cac81SBjoern A. Zeeb int error; 14666b4cac81SBjoern A. Zeeb 1467d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg); 14686b4cac81SBjoern A. Zeeb return (error); 14696b4cac81SBjoern A. Zeeb } 14706b4cac81SBjoern A. Zeeb 14716b4cac81SBjoern A. Zeeb static int 14726b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 14736b4cac81SBjoern A. Zeeb { 14746b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 14756b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 14766b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 14776b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 14786b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 14796b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 14806b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 14816b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 14826b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 14836b4cac81SBjoern A. Zeeb int error; 14846b4cac81SBjoern A. Zeeb 14856b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 14866b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 14876b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 14886b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 14896b4cac81SBjoern A. Zeeb 14906b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 14919597f7cbSBjoern A. Zeeb ni = NULL; 14926b4cac81SBjoern A. Zeeb 14936b4cac81SBjoern A. Zeeb IMPROVE("ponder some of this moved to ic_newassoc, scan_assoc_success, " 14946b4cac81SBjoern A. Zeeb "and to lesser extend ieee80211_notify_node_join"); 14956b4cac81SBjoern A. Zeeb 14969597f7cbSBjoern A. Zeeb /* Finish assoc. */ 14979597f7cbSBjoern A. Zeeb /* Update sta_state (AUTH to ASSOC) and set aid. */ 14986b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 14996b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 15006b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 15019597f7cbSBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 15029597f7cbSBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 15036b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 15049597f7cbSBjoern A. Zeeb sta->aid = IEEE80211_NODE_AID(ni); 1505*e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC); 15069597f7cbSBjoern A. Zeeb if (error != 0) 15079597f7cbSBjoern A. Zeeb goto out; 15086b4cac81SBjoern A. Zeeb 15096b4cac81SBjoern A. Zeeb IMPROVE("wme / conf_tx [all]"); 15106b4cac81SBjoern A. Zeeb 15116b4cac81SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 15126b4cac81SBjoern A. Zeeb bss_changed = 0; 15136b4cac81SBjoern A. Zeeb if (!vif->bss_conf.assoc || vif->bss_conf.aid != IEEE80211_NODE_AID(ni)) { 15146b4cac81SBjoern A. Zeeb vif->bss_conf.assoc = true; 15156b4cac81SBjoern A. Zeeb vif->bss_conf.aid = IEEE80211_NODE_AID(ni); 15166b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_ASSOC; 15176b4cac81SBjoern A. Zeeb } 15186b4cac81SBjoern A. Zeeb /* We set SSID but this is not BSSID! */ 15196b4cac81SBjoern A. Zeeb vif->bss_conf.ssid_len = ni->ni_esslen; 15206b4cac81SBjoern A. Zeeb memcpy(vif->bss_conf.ssid, ni->ni_essid, ni->ni_esslen); 15216b4cac81SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_SHPREAMBLE) != 15226b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble) { 15236b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble ^= 1; 15246b4cac81SBjoern A. Zeeb /* bss_changed |= BSS_CHANGED_??? */ 15256b4cac81SBjoern A. Zeeb } 15266b4cac81SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_SHSLOT) != 15276b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot) { 15286b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot ^= 1; 15296b4cac81SBjoern A. Zeeb /* bss_changed |= BSS_CHANGED_??? */ 15306b4cac81SBjoern A. Zeeb } 15316b4cac81SBjoern A. Zeeb if ((ni->ni_flags & IEEE80211_NODE_QOS) != 15326b4cac81SBjoern A. Zeeb vif->bss_conf.qos) { 15336b4cac81SBjoern A. Zeeb vif->bss_conf.qos ^= 1; 15346b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 15356b4cac81SBjoern A. Zeeb } 1536fa8f007dSBjoern A. Zeeb 1537fa8f007dSBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 1538fa8f007dSBjoern A. Zeeb 15396b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 15406b4cac81SBjoern A. Zeeb 15416b4cac81SBjoern A. Zeeb /* - change_chanctx (if needed) 15426b4cac81SBjoern A. Zeeb * - event_callback 15436b4cac81SBjoern A. Zeeb */ 15446b4cac81SBjoern A. Zeeb 15456b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 15466b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 15476b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 15486b4cac81SBjoern A. Zeeb prep_tx_info.success = true; 15496b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 15506b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 15516b4cac81SBjoern A. Zeeb } 15526b4cac81SBjoern A. Zeeb 1553086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, false); 1554086be6a8SBjoern A. Zeeb 15556b4cac81SBjoern A. Zeeb /* 15566b4cac81SBjoern A. Zeeb * And then: 15576b4cac81SBjoern A. Zeeb * - (more packets)? 15586b4cac81SBjoern A. Zeeb * - set_key 15596b4cac81SBjoern A. Zeeb * - set_default_unicast_key 15606b4cac81SBjoern A. Zeeb * - set_key (?) 15616b4cac81SBjoern A. Zeeb * - ipv6_addr_change (?) 15626b4cac81SBjoern A. Zeeb */ 15636b4cac81SBjoern A. Zeeb /* Prepare_multicast && configure_filter. */ 15646b4cac81SBjoern A. Zeeb lhw->update_mc = true; 15656b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(vap->iv_ic, true); 15666b4cac81SBjoern A. Zeeb 15676b4cac81SBjoern A. Zeeb if (!ieee80211_node_is_authorized(ni)) { 15686b4cac81SBjoern A. Zeeb IMPROVE("net80211 does not consider node authorized"); 15696b4cac81SBjoern A. Zeeb } 15706b4cac81SBjoern A. Zeeb 15716b4cac81SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTHORIZED). */ 15726b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 15736b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 15746b4cac81SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 1575*e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTHORIZED); 15766b4cac81SBjoern A. Zeeb if (error != 0) { 15776b4cac81SBjoern A. Zeeb IMPROVE("undo some changes?"); 15786b4cac81SBjoern A. Zeeb goto out; 15796b4cac81SBjoern A. Zeeb } 15806b4cac81SBjoern A. Zeeb 15816b4cac81SBjoern A. Zeeb /* - drv_config (?) 15826b4cac81SBjoern A. Zeeb * - bss_info_changed 15836b4cac81SBjoern A. Zeeb * - set_rekey_data (?) 15846b4cac81SBjoern A. Zeeb * 15856b4cac81SBjoern A. Zeeb * And now we should be passing packets. 15866b4cac81SBjoern A. Zeeb */ 15876b4cac81SBjoern A. Zeeb IMPROVE("Need that bssid setting, and the keys"); 15886b4cac81SBjoern A. Zeeb 1589fa8f007dSBjoern A. Zeeb bss_changed = 0; 1590fa8f007dSBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 1591fa8f007dSBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 1592fa8f007dSBjoern A. Zeeb 15936b4cac81SBjoern A. Zeeb out: 15946b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 15956b4cac81SBjoern A. Zeeb if (ni != NULL) 15966b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 15976b4cac81SBjoern A. Zeeb return (error); 15986b4cac81SBjoern A. Zeeb } 15996b4cac81SBjoern A. Zeeb 16006b4cac81SBjoern A. Zeeb static int 16016b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 16026b4cac81SBjoern A. Zeeb { 16036b4cac81SBjoern A. Zeeb int error; 16046b4cac81SBjoern A. Zeeb 16056b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_assoc(vap, nstate, arg); 16066b4cac81SBjoern A. Zeeb if (error == 0) 16076b4cac81SBjoern A. Zeeb error = lkpi_sta_assoc_to_run(vap, nstate, arg); 16086b4cac81SBjoern A. Zeeb return (error); 16096b4cac81SBjoern A. Zeeb } 16106b4cac81SBjoern A. Zeeb 16116b4cac81SBjoern A. Zeeb static int 16126b4cac81SBjoern A. Zeeb lkpi_sta_run_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 16136b4cac81SBjoern A. Zeeb { 16146b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 16156b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 16166b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 16176b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 16186b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 16196b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 16206b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 1621d9f59799SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 1622d9f59799SBjoern A. Zeeb #if 0 1623d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 1624d9f59799SBjoern A. Zeeb #endif 16256b4cac81SBjoern A. Zeeb int error; 16266b4cac81SBjoern A. Zeeb 16276b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 16286b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 16296b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 16306b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 16316b4cac81SBjoern A. Zeeb 16326b4cac81SBjoern A. Zeeb /* Keep ni around. */ 16336b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 16346b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 16356b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 16366b4cac81SBjoern A. Zeeb 163767674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1638d9f59799SBjoern A. Zeeb 1639d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 1640d9f59799SBjoern A. Zeeb 1641d9f59799SBjoern A. Zeeb /* flush, drop. */ 1642d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1643d9f59799SBjoern A. Zeeb 1644d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?"); 1645d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) && 1646d9f59799SBjoern A. Zeeb !lsta->in_mgd) { 1647d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1648d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 1649d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 1650d9f59799SBjoern A. Zeeb lsta->in_mgd = true; 1651d9f59799SBjoern A. Zeeb } 1652d9f59799SBjoern A. Zeeb 1653d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1654d9f59799SBjoern A. Zeeb 1655d9f59799SBjoern A. Zeeb /* Call iv_newstate first so we get potential DISASSOC packet out. */ 1656d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 1657d9f59799SBjoern A. Zeeb if (error != 0) 1658d9f59799SBjoern A. Zeeb goto outni; 1659d9f59799SBjoern A. Zeeb 1660d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 1661d9f59799SBjoern A. Zeeb 166267674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1663d9f59799SBjoern A. Zeeb 1664d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 1665d9f59799SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 1666d9f59799SBjoern A. Zeeb 1667d9f59799SBjoern A. Zeeb /* flush, no drop */ 1668d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 1669d9f59799SBjoern A. Zeeb 1670d9f59799SBjoern A. Zeeb /* End mgd_complete_tx. */ 1671d9f59799SBjoern A. Zeeb if (lsta->in_mgd) { 1672d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1673d9f59799SBjoern A. Zeeb prep_tx_info.success = false; 1674d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 1675d9f59799SBjoern A. Zeeb lsta->in_mgd = false; 1676d9f59799SBjoern A. Zeeb } 1677d9f59799SBjoern A. Zeeb 1678d9f59799SBjoern A. Zeeb #if 0 1679d9f59799SBjoern A. Zeeb /* sync_rx_queues */ 1680d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 1681d9f59799SBjoern A. Zeeb 1682d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */ 1683d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 1684d9f59799SBjoern A. Zeeb #endif 1685d9f59799SBjoern A. Zeeb 1686d9f59799SBjoern A. Zeeb /* Take the station down. */ 1687d9f59799SBjoern A. Zeeb 16886b4cac81SBjoern A. Zeeb /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */ 16896b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 16906b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not " 16916b4cac81SBjoern A. Zeeb "AUTHORIZED: %#x\n", __func__, lsta, lsta->state)); 1692*e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC); 16936b4cac81SBjoern A. Zeeb if (error != 0) 16946b4cac81SBjoern A. Zeeb goto out; 16956b4cac81SBjoern A. Zeeb 169667674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 16976b4cac81SBjoern A. Zeeb 16986b4cac81SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTH). */ 16996b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 17006b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 17016b4cac81SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 1702*e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH); 17036b4cac81SBjoern A. Zeeb if (error != 0) 17046b4cac81SBjoern A. Zeeb goto out; 17056b4cac81SBjoern A. Zeeb 170667674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 17076b4cac81SBjoern A. Zeeb 1708d9f59799SBjoern A. Zeeb #if 0 1709d9f59799SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 1710d9f59799SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw); 1711d9f59799SBjoern A. Zeeb #endif 1712d9f59799SBjoern A. Zeeb 1713d9f59799SBjoern A. Zeeb error = EALREADY; 17146b4cac81SBjoern A. Zeeb out: 17156b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1716d9f59799SBjoern A. Zeeb outni: 17176b4cac81SBjoern A. Zeeb if (ni != NULL) 17186b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 17196b4cac81SBjoern A. Zeeb return (error); 17206b4cac81SBjoern A. Zeeb } 17216b4cac81SBjoern A. Zeeb 17226b4cac81SBjoern A. Zeeb static int 1723d9f59799SBjoern A. Zeeb lkpi_sta_run_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 1724d9f59799SBjoern A. Zeeb { 1725d9f59799SBjoern A. Zeeb struct lkpi_hw *lhw; 1726d9f59799SBjoern A. Zeeb struct ieee80211_hw *hw; 1727d9f59799SBjoern A. Zeeb struct lkpi_vif *lvif; 1728d9f59799SBjoern A. Zeeb struct ieee80211_vif *vif; 1729d9f59799SBjoern A. Zeeb struct ieee80211_node *ni; 1730d9f59799SBjoern A. Zeeb struct lkpi_sta *lsta; 1731d9f59799SBjoern A. Zeeb struct ieee80211_sta *sta; 1732d9f59799SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 1733d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 1734d9f59799SBjoern A. Zeeb int error; 1735d9f59799SBjoern A. Zeeb 1736d9f59799SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 1737d9f59799SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 1738d9f59799SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 1739d9f59799SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 1740d9f59799SBjoern A. Zeeb 1741d9f59799SBjoern A. Zeeb /* Keep ni around. */ 1742d9f59799SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 1743d9f59799SBjoern A. Zeeb lsta = ni->ni_drv_data; 1744d9f59799SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 1745d9f59799SBjoern A. Zeeb 174667674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1747d9f59799SBjoern A. Zeeb 1748d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 1749d9f59799SBjoern A. Zeeb 1750d9f59799SBjoern A. Zeeb /* flush, drop. */ 1751d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1752d9f59799SBjoern A. Zeeb 1753d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?"); 1754d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) && 1755d9f59799SBjoern A. Zeeb !lsta->in_mgd) { 1756d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1757d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 1758d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 1759d9f59799SBjoern A. Zeeb lsta->in_mgd = true; 1760d9f59799SBjoern A. Zeeb } 1761d9f59799SBjoern A. Zeeb 1762d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1763d9f59799SBjoern A. Zeeb 1764d9f59799SBjoern A. Zeeb /* Call iv_newstate first so we get potential DISASSOC packet out. */ 1765d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 1766d9f59799SBjoern A. Zeeb if (error != 0) 1767d9f59799SBjoern A. Zeeb goto outni; 1768d9f59799SBjoern A. Zeeb 1769d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 1770d9f59799SBjoern A. Zeeb 177167674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1772d9f59799SBjoern A. Zeeb 1773d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 1774d9f59799SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 1775d9f59799SBjoern A. Zeeb 1776d9f59799SBjoern A. Zeeb /* flush, no drop */ 1777d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 1778d9f59799SBjoern A. Zeeb 1779d9f59799SBjoern A. Zeeb /* End mgd_complete_tx. */ 1780d9f59799SBjoern A. Zeeb if (lsta->in_mgd) { 1781d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1782d9f59799SBjoern A. Zeeb prep_tx_info.success = false; 1783d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 1784d9f59799SBjoern A. Zeeb lsta->in_mgd = false; 1785d9f59799SBjoern A. Zeeb } 1786d9f59799SBjoern A. Zeeb 1787d9f59799SBjoern A. Zeeb /* sync_rx_queues */ 1788d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 1789d9f59799SBjoern A. Zeeb 1790d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */ 1791d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 1792d9f59799SBjoern A. Zeeb 1793d9f59799SBjoern A. Zeeb /* Take the station down. */ 1794d9f59799SBjoern A. Zeeb 1795d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */ 1796d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 1797d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not " 1798d9f59799SBjoern A. Zeeb "AUTHORIZED: %#x\n", __func__, lsta, lsta->state)); 1799*e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC); 1800d9f59799SBjoern A. Zeeb if (error != 0) 1801d9f59799SBjoern A. Zeeb goto out; 1802d9f59799SBjoern A. Zeeb 180367674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1804d9f59799SBjoern A. Zeeb 1805d9f59799SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTH). */ 1806d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 1807d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 1808d9f59799SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 1809*e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH); 1810d9f59799SBjoern A. Zeeb if (error != 0) 1811d9f59799SBjoern A. Zeeb goto out; 1812d9f59799SBjoern A. Zeeb 181367674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1814d9f59799SBjoern A. Zeeb 1815d9f59799SBjoern A. Zeeb /* Update sta and change state (from AUTH) to NONE. */ 1816d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 1817d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 1818d9f59799SBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 1819*e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE); 1820d9f59799SBjoern A. Zeeb if (error != 0) 1821d9f59799SBjoern A. Zeeb goto out; 1822d9f59799SBjoern A. Zeeb 182367674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1824d9f59799SBjoern A. Zeeb 1825d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 1826d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 1827d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 1828d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg)); 1829*e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST); 1830d9f59799SBjoern A. Zeeb if (error != 0) { 1831d9f59799SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 1832d9f59799SBjoern A. Zeeb goto out; 1833d9f59799SBjoern A. Zeeb } 1834d9f59799SBjoern A. Zeeb #if 0 1835d9f59799SBjoern A. Zeeb lsta->added_to_drv = false; /* mo manages. */ 1836d9f59799SBjoern A. Zeeb #endif 1837d9f59799SBjoern A. Zeeb 183867674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1839d9f59799SBjoern A. Zeeb 1840d9f59799SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 1841d9f59799SBjoern A. Zeeb /* 1842d9f59799SBjoern A. Zeeb * One would expect this to happen when going off AUTHORIZED. 1843d9f59799SBjoern A. Zeeb * See comment there; removes the sta from fw. 1844d9f59799SBjoern A. Zeeb */ 1845d9f59799SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw); 1846d9f59799SBjoern A. Zeeb 1847d9f59799SBjoern A. Zeeb IMPROVE("Any bss_info changes to announce?"); 1848d9f59799SBjoern A. Zeeb bss_changed = 0; 1849d9f59799SBjoern A. Zeeb vif->bss_conf.qos = 0; 1850d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 1851d9f59799SBjoern A. Zeeb vif->bss_conf.ssid_len = 0; 1852d9f59799SBjoern A. Zeeb memset(vif->bss_conf.ssid, '\0', sizeof(vif->bss_conf.ssid)); 1853d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 1854d9f59799SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 1855d9f59799SBjoern A. Zeeb 1856d9f59799SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif); 1857d9f59799SBjoern A. Zeeb 1858d9f59799SBjoern A. Zeeb /* conf_tx */ 1859d9f59799SBjoern A. Zeeb 1860d9f59799SBjoern A. Zeeb /* Take the chan ctx down. */ 1861d9f59799SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 1862d9f59799SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 1863d9f59799SBjoern A. Zeeb 1864d9f59799SBjoern A. Zeeb conf = vif->chanctx_conf; 1865d9f59799SBjoern A. Zeeb /* Remove vif context. */ 1866d9f59799SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->chanctx_conf); 1867d9f59799SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 1868d9f59799SBjoern A. Zeeb 1869d9f59799SBjoern A. Zeeb /* Remove chan ctx. */ 1870d9f59799SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 1871d9f59799SBjoern A. Zeeb free(conf, M_LKPI80211); 1872d9f59799SBjoern A. Zeeb } 1873d9f59799SBjoern A. Zeeb 1874d9f59799SBjoern A. Zeeb error = EALREADY; 1875d9f59799SBjoern A. Zeeb out: 1876d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1877d9f59799SBjoern A. Zeeb outni: 1878d9f59799SBjoern A. Zeeb if (ni != NULL) 1879d9f59799SBjoern A. Zeeb ieee80211_free_node(ni); 1880d9f59799SBjoern A. Zeeb return (error); 1881d9f59799SBjoern A. Zeeb } 1882d9f59799SBjoern A. Zeeb 1883d9f59799SBjoern A. Zeeb static int 1884d9f59799SBjoern A. Zeeb lkpi_sta_run_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 1885d9f59799SBjoern A. Zeeb { 1886d9f59799SBjoern A. Zeeb 1887d9f59799SBjoern A. Zeeb return (lkpi_sta_run_to_init(vap, nstate, arg)); 1888d9f59799SBjoern A. Zeeb } 1889d9f59799SBjoern A. Zeeb 1890d9f59799SBjoern A. Zeeb static int 18916b4cac81SBjoern A. Zeeb lkpi_sta_run_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 18926b4cac81SBjoern A. Zeeb { 18936b4cac81SBjoern A. Zeeb int error; 18946b4cac81SBjoern A. Zeeb 1895d9f59799SBjoern A. Zeeb error = lkpi_sta_run_to_init(vap, nstate, arg); 1896d9f59799SBjoern A. Zeeb if (error != 0 && error != EALREADY) 1897d9f59799SBjoern A. Zeeb return (error); 1898d9f59799SBjoern A. Zeeb 1899d9f59799SBjoern A. Zeeb /* At this point iv_bss is long a new node! */ 1900d9f59799SBjoern A. Zeeb 1901d9f59799SBjoern A. Zeeb error |= lkpi_sta_scan_to_auth(vap, nstate, 0); 19026b4cac81SBjoern A. Zeeb return (error); 19036b4cac81SBjoern A. Zeeb } 19046b4cac81SBjoern A. Zeeb 1905d9f59799SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 19066b4cac81SBjoern A. Zeeb 19076b4cac81SBjoern A. Zeeb /* 19086b4cac81SBjoern A. Zeeb * The matches the documented state changes in net80211::sta_newstate(). 19096b4cac81SBjoern A. Zeeb * XXX (1) without CSA and SLEEP yet, * XXX (2) not all unhandled cases 19106b4cac81SBjoern A. Zeeb * there are "invalid" (so there is a room for failure here). 19116b4cac81SBjoern A. Zeeb */ 19126b4cac81SBjoern A. Zeeb struct fsm_state { 19136b4cac81SBjoern A. Zeeb /* INIT, SCAN, AUTH, ASSOC, CAC, RUN, CSA, SLEEP */ 19146b4cac81SBjoern A. Zeeb enum ieee80211_state ostate; 19156b4cac81SBjoern A. Zeeb enum ieee80211_state nstate; 19166b4cac81SBjoern A. Zeeb int (*handler)(struct ieee80211vap *, enum ieee80211_state, int); 19176b4cac81SBjoern A. Zeeb } sta_state_fsm[] = { 19186b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, 19196b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, /* scan_to_init */ 19206b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_INIT, lkpi_sta_auth_to_init }, /* not explicitly in sta_newstate() */ 1921d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_INIT, lkpi_sta_assoc_to_init }, /* Send DEAUTH. */ 1922d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_INIT, lkpi_sta_run_to_init }, /* Send DISASSOC. */ 19236b4cac81SBjoern A. Zeeb 19246b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_SCAN, lkpi_sta_state_do_nada }, 19256b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_SCAN, lkpi_sta_state_do_nada }, 19266b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_SCAN, lkpi_sta_auth_to_scan }, 19276b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_SCAN, lkpi_sta_assoc_to_scan }, 1928d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_SCAN, lkpi_sta_run_to_scan }, /* Beacon miss. */ 19296b4cac81SBjoern A. Zeeb 1930d9f59799SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, /* Send AUTH. */ 1931d9f59799SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, /* Send AUTH. */ 1932d9f59799SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_AUTH, lkpi_sta_a_to_a }, /* Send ?AUTH. */ 1933d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_AUTH, lkpi_sta_assoc_to_auth }, /* Send ?AUTH. */ 1934d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_AUTH, lkpi_sta_run_to_auth }, /* Send ?AUTH. */ 19356b4cac81SBjoern A. Zeeb 1936d9f59799SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_ASSOC, lkpi_sta_auth_to_assoc }, /* Send ASSOCREQ. */ 1937d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_ASSOC, lkpi_sta_a_to_a }, /* Send ASSOCREQ. */ 1938d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_ASSOC, lkpi_sta_run_to_assoc }, /* Send ASSOCREQ/REASSOCREQ. */ 19396b4cac81SBjoern A. Zeeb 19406b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_RUN, lkpi_sta_auth_to_run }, 19416b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_RUN, lkpi_sta_assoc_to_run }, 19426b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_RUN, lkpi_sta_state_do_nada }, 19436b4cac81SBjoern A. Zeeb 19446b4cac81SBjoern A. Zeeb /* Dummy at the end without handler. */ 19456b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_INIT, NULL }, 19466b4cac81SBjoern A. Zeeb }; 19476b4cac81SBjoern A. Zeeb 19486b4cac81SBjoern A. Zeeb static int 19496b4cac81SBjoern A. Zeeb lkpi_iv_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 19506b4cac81SBjoern A. Zeeb { 19516b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 19526b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 19536b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 19546b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 19556b4cac81SBjoern A. Zeeb struct fsm_state *s; 19566b4cac81SBjoern A. Zeeb enum ieee80211_state ostate; 19576b4cac81SBjoern A. Zeeb int error; 19586b4cac81SBjoern A. Zeeb 19596b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 19606b4cac81SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(ic); 19616b4cac81SBjoern A. Zeeb ostate = vap->iv_state; 19626b4cac81SBjoern A. Zeeb 19639d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 19649d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 19656b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x\n", 19666b4cac81SBjoern A. Zeeb __func__, __LINE__, vap, nstate, arg); 19679d9ba2b7SBjoern A. Zeeb #endif 19686b4cac81SBjoern A. Zeeb 19696b4cac81SBjoern A. Zeeb if (vap->iv_opmode == IEEE80211_M_STA) { 19706b4cac81SBjoern A. Zeeb 19716b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 19726b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 19736b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 19746b4cac81SBjoern A. Zeeb 19756b4cac81SBjoern A. Zeeb /* No need to replicate this in most state handlers. */ 19766b4cac81SBjoern A. Zeeb if (ostate == IEEE80211_S_SCAN && nstate != IEEE80211_S_SCAN) 19776b4cac81SBjoern A. Zeeb lkpi_stop_hw_scan(lhw, vif); 19786b4cac81SBjoern A. Zeeb 19796b4cac81SBjoern A. Zeeb s = sta_state_fsm; 19806b4cac81SBjoern A. Zeeb 19816b4cac81SBjoern A. Zeeb } else { 19826b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: only station mode currently supported: " 19836b4cac81SBjoern A. Zeeb "cap %p iv_opmode %d\n", __func__, vap, vap->iv_opmode); 19846b4cac81SBjoern A. Zeeb return (ENOSYS); 19856b4cac81SBjoern A. Zeeb } 19866b4cac81SBjoern A. Zeeb 19876b4cac81SBjoern A. Zeeb error = 0; 19886b4cac81SBjoern A. Zeeb for (; s->handler != NULL; s++) { 19896b4cac81SBjoern A. Zeeb if (ostate == s->ostate && nstate == s->nstate) { 19909d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 19919d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 1992d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: new state %d (%s) ->" 1993d9f59799SBjoern A. Zeeb " %d (%s): arg %d.\n", __func__, 1994d9f59799SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 1995d9f59799SBjoern A. Zeeb nstate, ieee80211_state_name[nstate], arg); 19969d9ba2b7SBjoern A. Zeeb #endif 19976b4cac81SBjoern A. Zeeb error = s->handler(vap, nstate, arg); 19986b4cac81SBjoern A. Zeeb break; 19996b4cac81SBjoern A. Zeeb } 20006b4cac81SBjoern A. Zeeb } 20016b4cac81SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(vap->iv_ic); 20026b4cac81SBjoern A. Zeeb 20036b4cac81SBjoern A. Zeeb if (s->handler == NULL) { 2004d9f59799SBjoern A. Zeeb IMPROVE("turn this into a KASSERT\n"); 20056b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: unsupported state transition " 20066b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s)\n", __func__, 20076b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 20086b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 20096b4cac81SBjoern A. Zeeb return (ENOSYS); 20106b4cac81SBjoern A. Zeeb } 20116b4cac81SBjoern A. Zeeb 20126b4cac81SBjoern A. Zeeb if (error == EALREADY) { 20139d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 20149d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 2015d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: state transition %d (%s) -> " 2016d9f59799SBjoern A. Zeeb "%d (%s): iv_newstate already handled: %d.\n", 2017d9f59799SBjoern A. Zeeb __func__, ostate, ieee80211_state_name[ostate], 2018d9f59799SBjoern A. Zeeb nstate, ieee80211_state_name[nstate], error); 20199d9ba2b7SBjoern A. Zeeb #endif 20206b4cac81SBjoern A. Zeeb return (0); 20216b4cac81SBjoern A. Zeeb } 20226b4cac81SBjoern A. Zeeb 20236b4cac81SBjoern A. Zeeb if (error != 0) { 20246b4cac81SBjoern A. Zeeb /* XXX-BZ currently expected so ignore. */ 20256b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: error %d during state transition " 20266b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s)\n", __func__, error, 20276b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 20286b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 20296b4cac81SBjoern A. Zeeb /* return (error); */ 20306b4cac81SBjoern A. Zeeb } 20316b4cac81SBjoern A. Zeeb 20329d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 20339d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 2034d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x " 2035d9f59799SBjoern A. Zeeb "calling net80211 parent\n", 20366b4cac81SBjoern A. Zeeb __func__, __LINE__, vap, nstate, arg); 20379d9ba2b7SBjoern A. Zeeb #endif 20386b4cac81SBjoern A. Zeeb 20396b4cac81SBjoern A. Zeeb return (lvif->iv_newstate(vap, nstate, arg)); 20406b4cac81SBjoern A. Zeeb } 20416b4cac81SBjoern A. Zeeb 20426b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 20436b4cac81SBjoern A. Zeeb 2044d9f59799SBjoern A. Zeeb /* 2045d9f59799SBjoern A. Zeeb * We overload (*iv_update_bss) as otherwise we have cases in, e.g., 2046d9f59799SBjoern A. Zeeb * net80211::ieee80211_sta_join1() where vap->iv_bss gets replaced by a 2047d9f59799SBjoern A. Zeeb * new node without us knowing and thus our ni/lsta are out of sync. 2048d9f59799SBjoern A. Zeeb */ 2049d9f59799SBjoern A. Zeeb static struct ieee80211_node * 2050d9f59799SBjoern A. Zeeb lkpi_iv_update_bss(struct ieee80211vap *vap, struct ieee80211_node *ni) 2051d9f59799SBjoern A. Zeeb { 2052d9f59799SBjoern A. Zeeb struct lkpi_vif *lvif; 2053d9f59799SBjoern A. Zeeb struct ieee80211_node *obss; 2054d9f59799SBjoern A. Zeeb struct lkpi_sta *lsta; 2055ed3ef56bSBjoern A. Zeeb struct ieee80211_sta *sta; 2056d9f59799SBjoern A. Zeeb 2057d9f59799SBjoern A. Zeeb obss = vap->iv_bss; 2058d9f59799SBjoern A. Zeeb 20599d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 20609d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 20619d9ba2b7SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: obss %p ni_drv_data %p " 20629d9ba2b7SBjoern A. Zeeb "ni %p ni_drv_data %p\n", __func__, 20639d9ba2b7SBjoern A. Zeeb obss, (obss != NULL) ? obss->ni_drv_data : NULL, 20649d9ba2b7SBjoern A. Zeeb ni, (ni != NULL) ? ni->ni_drv_data : NULL); 20659d9ba2b7SBjoern A. Zeeb #endif 20669d9ba2b7SBjoern A. Zeeb 2067d9f59799SBjoern A. Zeeb /* Nothing to copy from. Just return. */ 2068d9f59799SBjoern A. Zeeb if (obss == NULL || obss->ni_drv_data == NULL) 2069d9f59799SBjoern A. Zeeb goto out; 2070d9f59799SBjoern A. Zeeb 2071d9f59799SBjoern A. Zeeb /* Nothing to copy to. Just return. */ 2072d9f59799SBjoern A. Zeeb IMPROVE("clearing the obss might still be needed?"); 2073d9f59799SBjoern A. Zeeb if (ni == NULL) 2074d9f59799SBjoern A. Zeeb goto out; 2075d9f59799SBjoern A. Zeeb 2076d9f59799SBjoern A. Zeeb /* Nothing changed? panic? */ 2077d9f59799SBjoern A. Zeeb if (obss == ni) 2078d9f59799SBjoern A. Zeeb goto out; 2079d9f59799SBjoern A. Zeeb 2080d9f59799SBjoern A. Zeeb lsta = obss->ni_drv_data; 2081d9f59799SBjoern A. Zeeb obss->ni_drv_data = ni->ni_drv_data; 2082d9f59799SBjoern A. Zeeb ni->ni_drv_data = lsta; 2083ed3ef56bSBjoern A. Zeeb if (lsta != NULL) { 2084d9f59799SBjoern A. Zeeb lsta->ni = ni; 2085ed3ef56bSBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 2086ed3ef56bSBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->addr, lsta->ni->ni_macaddr); 2087ed3ef56bSBjoern A. Zeeb } 2088d9f59799SBjoern A. Zeeb lsta = obss->ni_drv_data; 2089ed3ef56bSBjoern A. Zeeb if (lsta != NULL) { 2090d9f59799SBjoern A. Zeeb lsta->ni = obss; 2091ed3ef56bSBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 2092ed3ef56bSBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->addr, lsta->ni->ni_macaddr); 2093ed3ef56bSBjoern A. Zeeb } 2094d9f59799SBjoern A. Zeeb 2095d9f59799SBjoern A. Zeeb out: 2096ed3ef56bSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 2097d9f59799SBjoern A. Zeeb return (lvif->iv_update_bss(vap, ni)); 2098d9f59799SBjoern A. Zeeb } 2099d9f59799SBjoern A. Zeeb 21006b4cac81SBjoern A. Zeeb static int 21016b4cac81SBjoern A. Zeeb lkpi_ic_wme_update(struct ieee80211com *ic) 21026b4cac81SBjoern A. Zeeb { 21036b4cac81SBjoern A. Zeeb /* This needs queuing and go at the right moment. */ 21046b4cac81SBjoern A. Zeeb #ifdef WITH_WME_UPDATE 21056b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 21066b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 21076b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 21086b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 21096b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 21106b4cac81SBjoern A. Zeeb struct chanAccParams chp; 21116b4cac81SBjoern A. Zeeb struct wmeParams wmeparr[WME_NUM_AC]; 21126b4cac81SBjoern A. Zeeb struct ieee80211_tx_queue_params txqp; 21136b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 21146b4cac81SBjoern A. Zeeb int error; 21156b4cac81SBjoern A. Zeeb uint16_t ac; 21166b4cac81SBjoern A. Zeeb #endif 21176b4cac81SBjoern A. Zeeb 21186b4cac81SBjoern A. Zeeb IMPROVE(); 21196b4cac81SBjoern A. Zeeb KASSERT(WME_NUM_AC == IEEE80211_NUM_ACS, ("%s: WME_NUM_AC %d != " 21206b4cac81SBjoern A. Zeeb "IEEE80211_NUM_ACS %d\n", __func__, WME_NUM_AC, IEEE80211_NUM_ACS)); 21216b4cac81SBjoern A. Zeeb 21226b4cac81SBjoern A. Zeeb #ifdef WITH_WME_UPDATE 21236b4cac81SBjoern A. Zeeb vap = TAILQ_FIRST(&ic->ic_vaps); 21246b4cac81SBjoern A. Zeeb if (vap == NULL) 21256b4cac81SBjoern A. Zeeb return (0); 21266b4cac81SBjoern A. Zeeb 21276b4cac81SBjoern A. Zeeb /* We should factor this out into per-vap (*wme_update). */ 21286b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 21296b4cac81SBjoern A. Zeeb if (lhw->ops->conf_tx == NULL) 21306b4cac81SBjoern A. Zeeb return (0); 21316b4cac81SBjoern A. Zeeb 21326b4cac81SBjoern A. Zeeb /* XXX-BZ check amount of hw queues */ 21336b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 21346b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 21356b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 21366b4cac81SBjoern A. Zeeb 21376b4cac81SBjoern A. Zeeb ieee80211_wme_ic_getparams(ic, &chp); 21386b4cac81SBjoern A. Zeeb IEEE80211_LOCK(ic); 21396b4cac81SBjoern A. Zeeb for (ac = 0; ac < WME_NUM_AC; ac++) 21406b4cac81SBjoern A. Zeeb wmeparr[ac] = chp.cap_wmeParams[ac]; 21416b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(ic); 21426b4cac81SBjoern A. Zeeb 21436b4cac81SBjoern A. Zeeb /* Configure tx queues (conf_tx) & send BSS_CHANGED_QOS. */ 21446b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 21456b4cac81SBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 21466b4cac81SBjoern A. Zeeb struct wmeParams *wmep; 21476b4cac81SBjoern A. Zeeb 21486b4cac81SBjoern A. Zeeb /* XXX-BZ should keep this in lvif? */ 21496b4cac81SBjoern A. Zeeb wmep = &wmeparr[ac]; 21506b4cac81SBjoern A. Zeeb bzero(&txqp, sizeof(txqp)); 21516b4cac81SBjoern A. Zeeb txqp.cw_min = wmep->wmep_logcwmin; 21526b4cac81SBjoern A. Zeeb txqp.cw_max = wmep->wmep_logcwmax; 21536b4cac81SBjoern A. Zeeb txqp.txop = wmep->wmep_txopLimit; 21546b4cac81SBjoern A. Zeeb txqp.aifs = wmep->wmep_aifsn; 21556b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_conf_tx(hw, vif, ac, &txqp); 21566b4cac81SBjoern A. Zeeb if (error != 0) 21576b4cac81SBjoern A. Zeeb printf("%s: conf_tx ac %u failed %d\n", 21586b4cac81SBjoern A. Zeeb __func__, ac, error); 21596b4cac81SBjoern A. Zeeb } 21606b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 21616b4cac81SBjoern A. Zeeb changed = BSS_CHANGED_QOS; 21626b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 21636b4cac81SBjoern A. Zeeb #endif 21646b4cac81SBjoern A. Zeeb 21656b4cac81SBjoern A. Zeeb return (0); 21666b4cac81SBjoern A. Zeeb } 21676b4cac81SBjoern A. Zeeb 21686b4cac81SBjoern A. Zeeb static struct ieee80211vap * 21696b4cac81SBjoern A. Zeeb lkpi_ic_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], 21706b4cac81SBjoern A. Zeeb int unit, enum ieee80211_opmode opmode, int flags, 21716b4cac81SBjoern A. Zeeb const uint8_t bssid[IEEE80211_ADDR_LEN], 21726b4cac81SBjoern A. Zeeb const uint8_t mac[IEEE80211_ADDR_LEN]) 21736b4cac81SBjoern A. Zeeb { 21746b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 21756b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 21766b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 21776b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 21786b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 21796b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 21806b4cac81SBjoern A. Zeeb size_t len; 2181e3a0b120SBjoern A. Zeeb int error, i; 21826b4cac81SBjoern A. Zeeb 21836b4cac81SBjoern A. Zeeb if (!TAILQ_EMPTY(&ic->ic_vaps)) /* 1 so far. Add <n> once this works. */ 21846b4cac81SBjoern A. Zeeb return (NULL); 21856b4cac81SBjoern A. Zeeb 21866b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 21876b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 21886b4cac81SBjoern A. Zeeb 21896b4cac81SBjoern A. Zeeb len = sizeof(*lvif); 21906b4cac81SBjoern A. Zeeb len += hw->vif_data_size; /* vif->drv_priv */ 21916b4cac81SBjoern A. Zeeb 21926b4cac81SBjoern A. Zeeb lvif = malloc(len, M_80211_VAP, M_WAITOK | M_ZERO); 21936b4cac81SBjoern A. Zeeb mtx_init(&lvif->mtx, "lvif", NULL, MTX_DEF); 21946b4cac81SBjoern A. Zeeb TAILQ_INIT(&lvif->lsta_head); 21956b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 21966b4cac81SBjoern A. Zeeb 21976b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 21986b4cac81SBjoern A. Zeeb memcpy(vif->addr, mac, IEEE80211_ADDR_LEN); 21996b4cac81SBjoern A. Zeeb vif->p2p = false; 22006b4cac81SBjoern A. Zeeb vif->probe_req_reg = false; 22016b4cac81SBjoern A. Zeeb vif->type = lkpi_opmode_to_vif_type(opmode); 22026b4cac81SBjoern A. Zeeb lvif->wdev.iftype = vif->type; 22036b4cac81SBjoern A. Zeeb /* Need to fill in other fields as well. */ 22046b4cac81SBjoern A. Zeeb IMPROVE(); 22056b4cac81SBjoern A. Zeeb 22066b4cac81SBjoern A. Zeeb /* XXX-BZ hardcoded for now! */ 22076b4cac81SBjoern A. Zeeb #if 1 22086b4cac81SBjoern A. Zeeb vif->chanctx_conf = NULL; 22096b4cac81SBjoern A. Zeeb vif->bss_conf.idle = true; 22106b4cac81SBjoern A. Zeeb vif->bss_conf.ps = false; 22116b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.width = NL80211_CHAN_WIDTH_20_NOHT; 22126b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble = false; /* vap->iv_flags IEEE80211_F_SHPREAMBLE */ 22136b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot = false; /* vap->iv_flags IEEE80211_F_SHSLOT */ 22146b4cac81SBjoern A. Zeeb vif->bss_conf.qos = false; 22156b4cac81SBjoern A. Zeeb vif->bss_conf.use_cts_prot = false; /* vap->iv_protmode */ 22166b4cac81SBjoern A. Zeeb vif->bss_conf.ht_operation_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONE; 22176b4cac81SBjoern A. Zeeb vif->bss_conf.assoc = false; 22186b4cac81SBjoern A. Zeeb vif->bss_conf.aid = 0; 2219caaa79c3SBjoern A. Zeeb /* 2220caaa79c3SBjoern A. Zeeb * We need to initialize it to something as the bss_info_changed call 2221caaa79c3SBjoern A. Zeeb * will try to copy from it in iwlwifi and NULL is a panic. 2222caaa79c3SBjoern A. Zeeb * We will set the proper one in scan_to_auth() before being assoc. 2223caaa79c3SBjoern A. Zeeb * NB: the logic there with using an array as bssid_override and checking 2224caaa79c3SBjoern A. Zeeb * for non-NULL later is flawed but in their workflow does not seem to 2225caaa79c3SBjoern A. Zeeb * matter. 2226caaa79c3SBjoern A. Zeeb */ 2227caaa79c3SBjoern A. Zeeb vif->bss_conf.bssid = zerobssid; 22286b4cac81SBjoern A. Zeeb #endif 22296b4cac81SBjoern A. Zeeb #if 0 22306b4cac81SBjoern A. Zeeb vif->bss_conf.dtim_period = 0; /* IEEE80211_DTIM_DEFAULT ; must stay 0. */ 22316b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(vif->bss_conf.bssid, bssid); 22326b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = ic->ic_bintval; 22336b4cac81SBjoern A. Zeeb /* iwlwifi bug. */ 22346b4cac81SBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16) 22356b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = 16; 22366b4cac81SBjoern A. Zeeb #endif 2237e3a0b120SBjoern A. Zeeb 2238e3a0b120SBjoern A. Zeeb /* Setup queue defaults; driver may override in (*add_interface). */ 2239e3a0b120SBjoern A. Zeeb for (i = 0; i < IEEE80211_NUM_ACS; i++) { 2240e3a0b120SBjoern A. Zeeb if (ieee80211_hw_check(hw, QUEUE_CONTROL)) 2241e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = IEEE80211_INVAL_HW_QUEUE; 2242e3a0b120SBjoern A. Zeeb else if (hw->queues >= IEEE80211_NUM_ACS) 2243e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = i; 2244e3a0b120SBjoern A. Zeeb else 2245e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = 0; 2246e3a0b120SBjoern A. Zeeb } 2247e3a0b120SBjoern A. Zeeb vif->cab_queue = IEEE80211_INVAL_HW_QUEUE; 2248e3a0b120SBjoern A. Zeeb 22496b4cac81SBjoern A. Zeeb IMPROVE(); 22506b4cac81SBjoern A. Zeeb 22516b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_start(hw); 22526b4cac81SBjoern A. Zeeb if (error != 0) { 22536b4cac81SBjoern A. Zeeb printf("%s: failed to start hw: %d\n", __func__, error); 22546b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 22556b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 22566b4cac81SBjoern A. Zeeb return (NULL); 22576b4cac81SBjoern A. Zeeb } 22586b4cac81SBjoern A. Zeeb 22596b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_add_interface(hw, vif); 22606b4cac81SBjoern A. Zeeb if (error != 0) { 22616b4cac81SBjoern A. Zeeb IMPROVE(); /* XXX-BZ mo_stop()? */ 22626b4cac81SBjoern A. Zeeb printf("%s: failed to add interface: %d\n", __func__, error); 22636b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 22646b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 22656b4cac81SBjoern A. Zeeb return (NULL); 22666b4cac81SBjoern A. Zeeb } 22676b4cac81SBjoern A. Zeeb 22688891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 22696b4cac81SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lhw->lvif_head, lvif, lvif_entry); 22708891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 22716b4cac81SBjoern A. Zeeb 22726b4cac81SBjoern A. Zeeb /* Set bss_info. */ 22736b4cac81SBjoern A. Zeeb changed = 0; 22746b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 22756b4cac81SBjoern A. Zeeb 22766b4cac81SBjoern A. Zeeb /* conf_tx setup; default WME? */ 22776b4cac81SBjoern A. Zeeb 22786b4cac81SBjoern A. Zeeb /* Force MC init. */ 22796b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(ic, true); 22806b4cac81SBjoern A. Zeeb 22816b4cac81SBjoern A. Zeeb IMPROVE(); 22826b4cac81SBjoern A. Zeeb 22836b4cac81SBjoern A. Zeeb ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid); 22846b4cac81SBjoern A. Zeeb 22856b4cac81SBjoern A. Zeeb /* Override with LinuxKPI method so we can drive mac80211/cfg80211. */ 22866b4cac81SBjoern A. Zeeb lvif->iv_newstate = vap->iv_newstate; 22876b4cac81SBjoern A. Zeeb vap->iv_newstate = lkpi_iv_newstate; 2288d9f59799SBjoern A. Zeeb lvif->iv_update_bss = vap->iv_update_bss; 2289d9f59799SBjoern A. Zeeb vap->iv_update_bss = lkpi_iv_update_bss; 22906b4cac81SBjoern A. Zeeb 22916b4cac81SBjoern A. Zeeb /* Key management. */ 22926b4cac81SBjoern A. Zeeb if (lhw->ops->set_key != NULL) { 2293b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 22946b4cac81SBjoern A. Zeeb vap->iv_key_set = lkpi_iv_key_set; 22956b4cac81SBjoern A. Zeeb vap->iv_key_delete = lkpi_iv_key_delete; 22966b4cac81SBjoern A. Zeeb #endif 22976b4cac81SBjoern A. Zeeb } 22986b4cac81SBjoern A. Zeeb 22996b4cac81SBjoern A. Zeeb ieee80211_ratectl_init(vap); 23006b4cac81SBjoern A. Zeeb 23016b4cac81SBjoern A. Zeeb /* Complete setup. */ 23026b4cac81SBjoern A. Zeeb ieee80211_vap_attach(vap, ieee80211_media_change, 23036b4cac81SBjoern A. Zeeb ieee80211_media_status, mac); 23046b4cac81SBjoern A. Zeeb 23056b4cac81SBjoern A. Zeeb if (hw->max_listen_interval == 0) 23066b4cac81SBjoern A. Zeeb hw->max_listen_interval = 7 * (ic->ic_lintval / ic->ic_bintval); 23076b4cac81SBjoern A. Zeeb hw->conf.listen_interval = hw->max_listen_interval; 23086b4cac81SBjoern A. Zeeb ic->ic_set_channel(ic); 23096b4cac81SBjoern A. Zeeb 23106b4cac81SBjoern A. Zeeb /* XXX-BZ do we need to be able to update these? */ 23116b4cac81SBjoern A. Zeeb hw->wiphy->frag_threshold = vap->iv_fragthreshold; 23126b4cac81SBjoern A. Zeeb lkpi_80211_mo_set_frag_threshold(hw, vap->iv_fragthreshold); 23136b4cac81SBjoern A. Zeeb hw->wiphy->rts_threshold = vap->iv_rtsthreshold; 23146b4cac81SBjoern A. Zeeb lkpi_80211_mo_set_rts_threshold(hw, vap->iv_rtsthreshold); 23156b4cac81SBjoern A. Zeeb /* any others? */ 23166b4cac81SBjoern A. Zeeb IMPROVE(); 23176b4cac81SBjoern A. Zeeb 23186b4cac81SBjoern A. Zeeb return (vap); 23196b4cac81SBjoern A. Zeeb } 23206b4cac81SBjoern A. Zeeb 23216b4cac81SBjoern A. Zeeb static void 23226b4cac81SBjoern A. Zeeb lkpi_ic_vap_delete(struct ieee80211vap *vap) 23236b4cac81SBjoern A. Zeeb { 23246b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 23256b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 23266b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 23276b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 23286b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 23296b4cac81SBjoern A. Zeeb 23306b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 23316b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 23326b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 23336b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 23346b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 23356b4cac81SBjoern A. Zeeb 23368891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 23376b4cac81SBjoern A. Zeeb TAILQ_REMOVE(&lhw->lvif_head, lvif, lvif_entry); 23388891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 23396b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_interface(hw, vif); 23406b4cac81SBjoern A. Zeeb 23416b4cac81SBjoern A. Zeeb ieee80211_ratectl_deinit(vap); 23426b4cac81SBjoern A. Zeeb ieee80211_vap_detach(vap); 23436b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 23446b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 23456b4cac81SBjoern A. Zeeb } 23466b4cac81SBjoern A. Zeeb 23476b4cac81SBjoern A. Zeeb static void 23486b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast(struct ieee80211com *ic) 23496b4cac81SBjoern A. Zeeb { 23506b4cac81SBjoern A. Zeeb 23516b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(ic, false); 23526b4cac81SBjoern A. Zeeb TRACEOK(); 23536b4cac81SBjoern A. Zeeb } 23546b4cac81SBjoern A. Zeeb 23556b4cac81SBjoern A. Zeeb static void 23566b4cac81SBjoern A. Zeeb lkpi_ic_update_promisc(struct ieee80211com *ic) 23576b4cac81SBjoern A. Zeeb { 23586b4cac81SBjoern A. Zeeb 23596b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 23606b4cac81SBjoern A. Zeeb } 23616b4cac81SBjoern A. Zeeb 23626b4cac81SBjoern A. Zeeb static void 23636b4cac81SBjoern A. Zeeb lkpi_ic_update_chw(struct ieee80211com *ic) 23646b4cac81SBjoern A. Zeeb { 23656b4cac81SBjoern A. Zeeb 23666b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 23676b4cac81SBjoern A. Zeeb } 23686b4cac81SBjoern A. Zeeb 23696b4cac81SBjoern A. Zeeb /* Start / stop device. */ 23706b4cac81SBjoern A. Zeeb static void 23716b4cac81SBjoern A. Zeeb lkpi_ic_parent(struct ieee80211com *ic) 23726b4cac81SBjoern A. Zeeb { 23736b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 23746b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 23756b4cac81SBjoern A. Zeeb int error; 23766b4cac81SBjoern A. Zeeb bool start_all; 23776b4cac81SBjoern A. Zeeb 23786b4cac81SBjoern A. Zeeb IMPROVE(); 23796b4cac81SBjoern A. Zeeb 23806b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 23816b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 23826b4cac81SBjoern A. Zeeb start_all = false; 23836b4cac81SBjoern A. Zeeb 23846b4cac81SBjoern A. Zeeb if (ic->ic_nrunning > 0) { 23856b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_start(hw); 23866b4cac81SBjoern A. Zeeb if (error == 0) 23876b4cac81SBjoern A. Zeeb start_all = true; 23886b4cac81SBjoern A. Zeeb } else { 23896b4cac81SBjoern A. Zeeb lkpi_80211_mo_stop(hw); 23906b4cac81SBjoern A. Zeeb } 23916b4cac81SBjoern A. Zeeb 23926b4cac81SBjoern A. Zeeb if (start_all) 23936b4cac81SBjoern A. Zeeb ieee80211_start_all(ic); 23946b4cac81SBjoern A. Zeeb } 23956b4cac81SBjoern A. Zeeb 23966b4cac81SBjoern A. Zeeb bool 23976b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_is_ie_id_in_ie_buf(const u8 ie, const u8 *ie_ids, 23986b4cac81SBjoern A. Zeeb size_t ie_ids_len) 23996b4cac81SBjoern A. Zeeb { 24006b4cac81SBjoern A. Zeeb int i; 24016b4cac81SBjoern A. Zeeb 24026b4cac81SBjoern A. Zeeb for (i = 0; i < ie_ids_len; i++) { 24036b4cac81SBjoern A. Zeeb if (ie == *ie_ids) 24046b4cac81SBjoern A. Zeeb return (true); 24056b4cac81SBjoern A. Zeeb } 24066b4cac81SBjoern A. Zeeb 24076b4cac81SBjoern A. Zeeb return (false); 24086b4cac81SBjoern A. Zeeb } 24096b4cac81SBjoern A. Zeeb 24106b4cac81SBjoern A. Zeeb /* Return true if skipped; false if error. */ 24116b4cac81SBjoern A. Zeeb bool 24126b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ie_advance(size_t *xp, const u8 *ies, size_t ies_len) 24136b4cac81SBjoern A. Zeeb { 24146b4cac81SBjoern A. Zeeb size_t x; 24156b4cac81SBjoern A. Zeeb uint8_t l; 24166b4cac81SBjoern A. Zeeb 24176b4cac81SBjoern A. Zeeb x = *xp; 24186b4cac81SBjoern A. Zeeb 24196b4cac81SBjoern A. Zeeb KASSERT(x < ies_len, ("%s: x %zu ies_len %zu ies %p\n", 24206b4cac81SBjoern A. Zeeb __func__, x, ies_len, ies)); 24216b4cac81SBjoern A. Zeeb l = ies[x + 1]; 24226b4cac81SBjoern A. Zeeb x += 2 + l; 24236b4cac81SBjoern A. Zeeb 24246b4cac81SBjoern A. Zeeb if (x > ies_len) 24256b4cac81SBjoern A. Zeeb return (false); 24266b4cac81SBjoern A. Zeeb 24276b4cac81SBjoern A. Zeeb *xp = x; 24286b4cac81SBjoern A. Zeeb return (true); 24296b4cac81SBjoern A. Zeeb } 24306b4cac81SBjoern A. Zeeb 2431d9945d78SBjoern A. Zeeb static uint8_t * 2432d9945d78SBjoern A. Zeeb lkpi_scan_ies_add(uint8_t *p, struct ieee80211_scan_ies *scan_ies, 2433d9945d78SBjoern A. Zeeb uint32_t band_mask, struct ieee80211vap *vap, struct ieee80211_hw *hw) 24346b4cac81SBjoern A. Zeeb { 2435d9945d78SBjoern A. Zeeb struct ieee80211_supported_band *supband; 2436d9945d78SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 2437d9945d78SBjoern A. Zeeb const struct ieee80211_channel *chan; 2438d9945d78SBjoern A. Zeeb const struct ieee80211_rateset *rs; 2439d9945d78SBjoern A. Zeeb uint8_t *pb; 2440d9945d78SBjoern A. Zeeb int band, i; 24416b4cac81SBjoern A. Zeeb 2442d9945d78SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 2443d9945d78SBjoern A. Zeeb if ((band_mask & (1 << band)) == 0) 2444d9945d78SBjoern A. Zeeb continue; 2445d9945d78SBjoern A. Zeeb 2446d9945d78SBjoern A. Zeeb supband = hw->wiphy->bands[band]; 2447d9945d78SBjoern A. Zeeb /* 2448d9945d78SBjoern A. Zeeb * This should not happen; 2449d9945d78SBjoern A. Zeeb * band_mask is a bitmask of valid bands to scan on. 2450d9945d78SBjoern A. Zeeb */ 2451d9945d78SBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 2452d9945d78SBjoern A. Zeeb continue; 2453d9945d78SBjoern A. Zeeb 2454d9945d78SBjoern A. Zeeb /* Find a first channel to get the mode and rates from. */ 2455d9945d78SBjoern A. Zeeb channels = supband->channels; 2456d9945d78SBjoern A. Zeeb chan = NULL; 2457d9945d78SBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 2458d9945d78SBjoern A. Zeeb 2459d9945d78SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) 2460d9945d78SBjoern A. Zeeb continue; 2461d9945d78SBjoern A. Zeeb 2462d9945d78SBjoern A. Zeeb chan = ieee80211_find_channel(vap->iv_ic, 2463d9945d78SBjoern A. Zeeb channels[i].center_freq, 0); 2464d9945d78SBjoern A. Zeeb if (chan != NULL) 2465d9945d78SBjoern A. Zeeb break; 2466d9945d78SBjoern A. Zeeb } 2467d9945d78SBjoern A. Zeeb 2468d9945d78SBjoern A. Zeeb /* This really should not happen. */ 2469d9945d78SBjoern A. Zeeb if (chan == NULL) 2470d9945d78SBjoern A. Zeeb continue; 2471d9945d78SBjoern A. Zeeb 2472d9945d78SBjoern A. Zeeb pb = p; 2473d9945d78SBjoern A. Zeeb rs = ieee80211_get_suprates(vap->iv_ic, chan); /* calls chan2mode */ 2474d9945d78SBjoern A. Zeeb p = ieee80211_add_rates(p, rs); 2475d9945d78SBjoern A. Zeeb p = ieee80211_add_xrates(p, rs); 2476d9945d78SBjoern A. Zeeb 2477d9945d78SBjoern A. Zeeb scan_ies->ies[band] = pb; 2478d9945d78SBjoern A. Zeeb scan_ies->len[band] = p - pb; 2479d9945d78SBjoern A. Zeeb } 2480d9945d78SBjoern A. Zeeb 2481d9945d78SBjoern A. Zeeb /* Add common_ies */ 2482d9945d78SBjoern A. Zeeb pb = p; 2483d9945d78SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WPA1) != 0 && 2484d9945d78SBjoern A. Zeeb vap->iv_wpa_ie != NULL) { 2485d9945d78SBjoern A. Zeeb memcpy(p, vap->iv_wpa_ie, 2 + vap->iv_wpa_ie[1]); 2486d9945d78SBjoern A. Zeeb p += 2 + vap->iv_wpa_ie[1]; 2487d9945d78SBjoern A. Zeeb } 2488d9945d78SBjoern A. Zeeb if (vap->iv_appie_probereq != NULL) { 2489d9945d78SBjoern A. Zeeb memcpy(p, vap->iv_appie_probereq->ie_data, 2490d9945d78SBjoern A. Zeeb vap->iv_appie_probereq->ie_len); 2491d9945d78SBjoern A. Zeeb p += vap->iv_appie_probereq->ie_len; 2492d9945d78SBjoern A. Zeeb } 2493d9945d78SBjoern A. Zeeb scan_ies->common_ies = pb; 2494d9945d78SBjoern A. Zeeb scan_ies->common_ie_len = p - pb; 2495d9945d78SBjoern A. Zeeb 2496d9945d78SBjoern A. Zeeb return (p); 24976b4cac81SBjoern A. Zeeb } 24986b4cac81SBjoern A. Zeeb 24996b4cac81SBjoern A. Zeeb static void 25006b4cac81SBjoern A. Zeeb lkpi_ic_scan_start(struct ieee80211com *ic) 25016b4cac81SBjoern A. Zeeb { 25026b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 25036b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 25046b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 25056b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 25066b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 25076b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 25086b4cac81SBjoern A. Zeeb int error; 25096b4cac81SBjoern A. Zeeb 25106b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 2511a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) { 25126b4cac81SBjoern A. Zeeb /* A scan is still running. */ 25136b4cac81SBjoern A. Zeeb return; 25146b4cac81SBjoern A. Zeeb } 25156b4cac81SBjoern A. Zeeb 25166b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 25176b4cac81SBjoern A. Zeeb vap = ss->ss_vap; 25186b4cac81SBjoern A. Zeeb if (vap->iv_state != IEEE80211_S_SCAN) { 2519d3ef7fb4SBjoern A. Zeeb IMPROVE("We need to be able to scan if not in S_SCAN"); 25206b4cac81SBjoern A. Zeeb return; 25216b4cac81SBjoern A. Zeeb } 25226b4cac81SBjoern A. Zeeb 25236b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 2524a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_HW) == 0) { 2525a486fbbdSBjoern A. Zeeb /* If hw_scan is cleared clear FEXT_SCAN_OFFLOAD too. */ 2526a486fbbdSBjoern A. Zeeb vap->iv_flags_ext &= ~IEEE80211_FEXT_SCAN_OFFLOAD; 2527d3ef7fb4SBjoern A. Zeeb sw_scan: 25286b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 25296b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 2530086be6a8SBjoern A. Zeeb 2531086be6a8SBjoern A. Zeeb if (vap->iv_state == IEEE80211_S_SCAN) 2532086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, false); 2533086be6a8SBjoern A. Zeeb 25346b4cac81SBjoern A. Zeeb lkpi_80211_mo_sw_scan_start(hw, vif, vif->addr); 25356b4cac81SBjoern A. Zeeb /* net80211::scan_start() handled PS for us. */ 25366b4cac81SBjoern A. Zeeb IMPROVE(); 25376b4cac81SBjoern A. Zeeb /* XXX Also means it is too late to flush queues? 25386b4cac81SBjoern A. Zeeb * need to check iv_sta_ps or overload? */ 25396b4cac81SBjoern A. Zeeb /* XXX want to adjust ss end time/ maxdwell? */ 25406b4cac81SBjoern A. Zeeb 25416b4cac81SBjoern A. Zeeb } else { 25426b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 25436b4cac81SBjoern A. Zeeb struct ieee80211_scan_request *hw_req; 25446b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *lc, **cpp; 25456b4cac81SBjoern A. Zeeb struct cfg80211_ssid *ssids; 25466b4cac81SBjoern A. Zeeb struct cfg80211_scan_6ghz_params *s6gp; 25476b4cac81SBjoern A. Zeeb size_t chan_len, nchan, ssids_len, s6ghzlen; 2548d9945d78SBjoern A. Zeeb int band, i, ssid_count, common_ie_len; 2549d9945d78SBjoern A. Zeeb uint32_t band_mask; 2550d9945d78SBjoern A. Zeeb uint8_t *ie, *ieend; 25516b4cac81SBjoern A. Zeeb 2552d9945d78SBjoern A. Zeeb if (!ieee80211_hw_check(hw, SINGLE_SCAN_ON_ALL_BANDS)) { 2553d9945d78SBjoern A. Zeeb IMPROVE("individual band scans not yet supported"); 2554d9945d78SBjoern A. Zeeb /* In theory net80211 would have to drive this. */ 2555d9945d78SBjoern A. Zeeb return; 2556d9945d78SBjoern A. Zeeb } 2557d9945d78SBjoern A. Zeeb 2558d9945d78SBjoern A. Zeeb ssid_count = min(ss->ss_nssid, hw->wiphy->max_scan_ssids); 2559d9945d78SBjoern A. Zeeb ssids_len = ssid_count * sizeof(*ssids); 25606b4cac81SBjoern A. Zeeb s6ghzlen = 0 * (sizeof(*s6gp)); /* XXX-BZ */ 25616b4cac81SBjoern A. Zeeb 2562d9945d78SBjoern A. Zeeb band_mask = 0; 25636b4cac81SBjoern A. Zeeb nchan = 0; 2564d9945d78SBjoern A. Zeeb for (i = ss->ss_next; i < ss->ss_last; i++) { 25656b4cac81SBjoern A. Zeeb nchan++; 2566d9945d78SBjoern A. Zeeb band = lkpi_net80211_chan_to_nl80211_band( 2567d9945d78SBjoern A. Zeeb ss->ss_chans[ss->ss_next + i]); 2568d9945d78SBjoern A. Zeeb band_mask |= (1 << band); 2569d9945d78SBjoern A. Zeeb } 25706b4cac81SBjoern A. Zeeb chan_len = nchan * (sizeof(lc) + sizeof(*lc)); 25716b4cac81SBjoern A. Zeeb 2572d9945d78SBjoern A. Zeeb common_ie_len = 0; 2573d9945d78SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WPA1) != 0 && 2574d9945d78SBjoern A. Zeeb vap->iv_wpa_ie != NULL) 2575d9945d78SBjoern A. Zeeb common_ie_len += vap->iv_wpa_ie[1]; 2576d9945d78SBjoern A. Zeeb if (vap->iv_appie_probereq != NULL) 2577d9945d78SBjoern A. Zeeb common_ie_len += vap->iv_appie_probereq->ie_len; 2578d9945d78SBjoern A. Zeeb 2579d9945d78SBjoern A. Zeeb /* We would love to check this at an earlier stage... */ 2580d9945d78SBjoern A. Zeeb if (common_ie_len > hw->wiphy->max_scan_ie_len) { 2581d9945d78SBjoern A. Zeeb ic_printf(ic, "WARNING: %s: common_ie_len %d > " 2582d9945d78SBjoern A. Zeeb "wiphy->max_scan_ie_len %d\n", __func__, 2583d9945d78SBjoern A. Zeeb common_ie_len, hw->wiphy->max_scan_ie_len); 2584d9945d78SBjoern A. Zeeb } 2585d9945d78SBjoern A. Zeeb 25866b4cac81SBjoern A. Zeeb KASSERT(lhw->hw_req == NULL, ("%s: ic %p lhw %p hw_req %p " 25876b4cac81SBjoern A. Zeeb "!= NULL\n", __func__, ic, lhw, lhw->hw_req)); 25886b4cac81SBjoern A. Zeeb 2589d9945d78SBjoern A. Zeeb lhw->hw_req = hw_req = malloc(sizeof(*hw_req) + ssids_len + 2590d9945d78SBjoern A. Zeeb s6ghzlen + chan_len + lhw->supbands * lhw->scan_ie_len + 2591d9945d78SBjoern A. Zeeb common_ie_len, M_LKPI80211, M_WAITOK | M_ZERO); 25926b4cac81SBjoern A. Zeeb 25936b4cac81SBjoern A. Zeeb hw_req->req.flags = 0; /* XXX ??? */ 25946b4cac81SBjoern A. Zeeb /* hw_req->req.wdev */ 25956b4cac81SBjoern A. Zeeb hw_req->req.wiphy = hw->wiphy; 25966b4cac81SBjoern A. Zeeb hw_req->req.no_cck = false; /* XXX */ 25976b4cac81SBjoern A. Zeeb #if 0 25986b4cac81SBjoern A. Zeeb /* This seems to pessimise default scanning behaviour. */ 25996b4cac81SBjoern A. Zeeb hw_req->req.duration_mandatory = TICKS_2_USEC(ss->ss_mindwell); 26006b4cac81SBjoern A. Zeeb hw_req->req.duration = TICKS_2_USEC(ss->ss_maxdwell); 26016b4cac81SBjoern A. Zeeb #endif 26026b4cac81SBjoern A. Zeeb #ifdef __notyet__ 26036b4cac81SBjoern A. Zeeb hw_req->req.flags |= NL80211_SCAN_FLAG_RANDOM_ADDR; 26046b4cac81SBjoern A. Zeeb memcpy(hw_req->req.mac_addr, xxx, IEEE80211_ADDR_LEN); 26056b4cac81SBjoern A. Zeeb memset(hw_req->req.mac_addr_mask, 0xxx, IEEE80211_ADDR_LEN); 26066b4cac81SBjoern A. Zeeb #endif 26076b4cac81SBjoern A. Zeeb 26086b4cac81SBjoern A. Zeeb hw_req->req.n_channels = nchan; 26096b4cac81SBjoern A. Zeeb cpp = (struct linuxkpi_ieee80211_channel **)(hw_req + 1); 26106b4cac81SBjoern A. Zeeb lc = (struct linuxkpi_ieee80211_channel *)(cpp + nchan); 26116b4cac81SBjoern A. Zeeb for (i = 0; i < nchan; i++) { 26126b4cac81SBjoern A. Zeeb *(cpp + i) = 26136b4cac81SBjoern A. Zeeb (struct linuxkpi_ieee80211_channel *)(lc + i); 26146b4cac81SBjoern A. Zeeb } 26156b4cac81SBjoern A. Zeeb for (i = 0; i < nchan; i++) { 26166b4cac81SBjoern A. Zeeb c = ss->ss_chans[ss->ss_next + i]; 26176b4cac81SBjoern A. Zeeb 26186b4cac81SBjoern A. Zeeb lc->hw_value = c->ic_ieee; 26196b4cac81SBjoern A. Zeeb lc->center_freq = c->ic_freq; 26206b4cac81SBjoern A. Zeeb /* lc->flags */ 26216b4cac81SBjoern A. Zeeb lc->band = lkpi_net80211_chan_to_nl80211_band(c); 26226b4cac81SBjoern A. Zeeb lc->max_power = c->ic_maxpower; 26236b4cac81SBjoern A. Zeeb /* lc-> ... */ 26246b4cac81SBjoern A. Zeeb lc++; 26256b4cac81SBjoern A. Zeeb } 26266b4cac81SBjoern A. Zeeb 2627d9945d78SBjoern A. Zeeb hw_req->req.n_ssids = ssid_count; 26286b4cac81SBjoern A. Zeeb if (hw_req->req.n_ssids > 0) { 26296b4cac81SBjoern A. Zeeb ssids = (struct cfg80211_ssid *)lc; 26306b4cac81SBjoern A. Zeeb hw_req->req.ssids = ssids; 2631d9945d78SBjoern A. Zeeb for (i = 0; i < ssid_count; i++) { 26326b4cac81SBjoern A. Zeeb ssids->ssid_len = ss->ss_ssid[i].len; 26336b4cac81SBjoern A. Zeeb memcpy(ssids->ssid, ss->ss_ssid[i].ssid, 26346b4cac81SBjoern A. Zeeb ss->ss_ssid[i].len); 26356b4cac81SBjoern A. Zeeb ssids++; 26366b4cac81SBjoern A. Zeeb } 26376b4cac81SBjoern A. Zeeb s6gp = (struct cfg80211_scan_6ghz_params *)ssids; 26386b4cac81SBjoern A. Zeeb } else { 26396b4cac81SBjoern A. Zeeb s6gp = (struct cfg80211_scan_6ghz_params *)lc; 26406b4cac81SBjoern A. Zeeb } 26416b4cac81SBjoern A. Zeeb 26426b4cac81SBjoern A. Zeeb /* 6GHz one day. */ 26436b4cac81SBjoern A. Zeeb hw_req->req.n_6ghz_params = 0; 26446b4cac81SBjoern A. Zeeb hw_req->req.scan_6ghz_params = NULL; 26456b4cac81SBjoern A. Zeeb hw_req->req.scan_6ghz = false; /* Weird boolean; not what you think. */ 26466b4cac81SBjoern A. Zeeb /* s6gp->... */ 26476b4cac81SBjoern A. Zeeb 2648d9945d78SBjoern A. Zeeb ie = ieend = (uint8_t *)s6gp; 2649d9945d78SBjoern A. Zeeb /* Copy per-band IEs, copy common IEs */ 2650d9945d78SBjoern A. Zeeb ieend = lkpi_scan_ies_add(ie, &hw_req->ies, band_mask, vap, hw); 2651d9945d78SBjoern A. Zeeb hw_req->req.ie = ie; 2652d9945d78SBjoern A. Zeeb hw_req->req.ie_len = ieend - ie; 2653d9945d78SBjoern A. Zeeb 26546b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 26556b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 26566b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_hw_scan(hw, vif, hw_req); 26576b4cac81SBjoern A. Zeeb if (error != 0) { 2658d9945d78SBjoern A. Zeeb ieee80211_cancel_scan(vap); 2659d9945d78SBjoern A. Zeeb 26606b4cac81SBjoern A. Zeeb free(hw_req, M_LKPI80211); 26616b4cac81SBjoern A. Zeeb lhw->hw_req = NULL; 2662d3ef7fb4SBjoern A. Zeeb 2663d3ef7fb4SBjoern A. Zeeb /* 2664d3ef7fb4SBjoern A. Zeeb * XXX-SIGH magic number. 2665d3ef7fb4SBjoern A. Zeeb * rtw88 has a magic "return 1" if offloading scan is 2666d3ef7fb4SBjoern A. Zeeb * not possible. Fall back to sw scan in that case. 2667d3ef7fb4SBjoern A. Zeeb */ 2668196cfd0bSBjoern A. Zeeb if (error == 1) { 2669a486fbbdSBjoern A. Zeeb lhw->scan_flags &= ~LKPI_LHW_SCAN_HW; 2670196cfd0bSBjoern A. Zeeb ieee80211_start_scan(vap, 2671196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_ACTIVE | 2672196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_NOPICK | 2673196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_ONCE, 2674196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_FOREVER, 2675196cfd0bSBjoern A. Zeeb ss->ss_mindwell ? ss->ss_mindwell : msecs_to_ticks(20), 2676196cfd0bSBjoern A. Zeeb ss->ss_maxdwell ? ss->ss_maxdwell : msecs_to_ticks(200), 2677196cfd0bSBjoern A. Zeeb vap->iv_des_nssid, vap->iv_des_ssid); 2678d3ef7fb4SBjoern A. Zeeb goto sw_scan; 2679196cfd0bSBjoern A. Zeeb } 2680d3ef7fb4SBjoern A. Zeeb 2681d3ef7fb4SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: hw_scan returned %d\n", 2682d3ef7fb4SBjoern A. Zeeb __func__, error); 26836b4cac81SBjoern A. Zeeb } 26846b4cac81SBjoern A. Zeeb } 26856b4cac81SBjoern A. Zeeb } 26866b4cac81SBjoern A. Zeeb 26876b4cac81SBjoern A. Zeeb static void 26886b4cac81SBjoern A. Zeeb lkpi_ic_scan_end(struct ieee80211com *ic) 26896b4cac81SBjoern A. Zeeb { 26906b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 26916b4cac81SBjoern A. Zeeb 26926b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 2693a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) == 0) { 26946b4cac81SBjoern A. Zeeb return; 26956b4cac81SBjoern A. Zeeb } 26966b4cac81SBjoern A. Zeeb 2697a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_HW) == 0) { 2698a486fbbdSBjoern A. Zeeb struct ieee80211_scan_state *ss; 2699a486fbbdSBjoern A. Zeeb struct ieee80211vap *vap; 27006b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 27016b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 27026b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 27036b4cac81SBjoern A. Zeeb 2704a486fbbdSBjoern A. Zeeb ss = ic->ic_scan; 2705a486fbbdSBjoern A. Zeeb vap = ss->ss_vap; 27066b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 27076b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 27086b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 2709a486fbbdSBjoern A. Zeeb 27106b4cac81SBjoern A. Zeeb lkpi_80211_mo_sw_scan_complete(hw, vif); 27116b4cac81SBjoern A. Zeeb 27126b4cac81SBjoern A. Zeeb /* Send PS to stop buffering if n80211 does not for us? */ 2713086be6a8SBjoern A. Zeeb 2714086be6a8SBjoern A. Zeeb if (vap->iv_state == IEEE80211_S_SCAN) 2715086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true); 27166b4cac81SBjoern A. Zeeb } 27176b4cac81SBjoern A. Zeeb } 27186b4cac81SBjoern A. Zeeb 27196b4cac81SBjoern A. Zeeb static void 2720a486fbbdSBjoern A. Zeeb lkpi_ic_scan_curchan(struct ieee80211_scan_state *ss, 2721a486fbbdSBjoern A. Zeeb unsigned long maxdwell) 2722a486fbbdSBjoern A. Zeeb { 2723a486fbbdSBjoern A. Zeeb struct lkpi_hw *lhw; 2724a486fbbdSBjoern A. Zeeb 2725a486fbbdSBjoern A. Zeeb lhw = ss->ss_ic->ic_softc; 2726a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_HW) == 0) 2727a486fbbdSBjoern A. Zeeb lhw->ic_scan_curchan(ss, maxdwell); 2728a486fbbdSBjoern A. Zeeb } 2729a486fbbdSBjoern A. Zeeb 2730a486fbbdSBjoern A. Zeeb static void 2731a486fbbdSBjoern A. Zeeb lkpi_ic_scan_mindwell(struct ieee80211_scan_state *ss) 2732a486fbbdSBjoern A. Zeeb { 2733a486fbbdSBjoern A. Zeeb struct lkpi_hw *lhw; 2734a486fbbdSBjoern A. Zeeb 2735a486fbbdSBjoern A. Zeeb lhw = ss->ss_ic->ic_softc; 2736a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_HW) == 0) 2737a486fbbdSBjoern A. Zeeb lhw->ic_scan_mindwell(ss); 2738a486fbbdSBjoern A. Zeeb } 2739a486fbbdSBjoern A. Zeeb 2740a486fbbdSBjoern A. Zeeb static void 27416b4cac81SBjoern A. Zeeb lkpi_ic_set_channel(struct ieee80211com *ic) 27426b4cac81SBjoern A. Zeeb { 27436b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 27446b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 2745b2cf3c21SBjoern A. Zeeb struct ieee80211_channel *c; 2746b2cf3c21SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 27476b4cac81SBjoern A. Zeeb int error; 27486b4cac81SBjoern A. Zeeb 27496b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 2750b2cf3c21SBjoern A. Zeeb 2751b2cf3c21SBjoern A. Zeeb /* If we do not support (*config)() save us the work. */ 2752b2cf3c21SBjoern A. Zeeb if (lhw->ops->config == NULL) 27536b4cac81SBjoern A. Zeeb return; 27546b4cac81SBjoern A. Zeeb 2755a486fbbdSBjoern A. Zeeb /* If we have a hw_scan running do not switch channels. */ 2756a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & (LKPI_LHW_SCAN_RUNNING|LKPI_LHW_SCAN_HW)) == 2757a486fbbdSBjoern A. Zeeb (LKPI_LHW_SCAN_RUNNING|LKPI_LHW_SCAN_HW)) 2758a486fbbdSBjoern A. Zeeb return; 2759a486fbbdSBjoern A. Zeeb 2760b2cf3c21SBjoern A. Zeeb c = ic->ic_curchan; 2761b2cf3c21SBjoern A. Zeeb if (c == NULL || c == IEEE80211_CHAN_ANYC) { 27626b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: c %p ops->config %p\n", __func__, 27636b4cac81SBjoern A. Zeeb c, lhw->ops->config); 27646b4cac81SBjoern A. Zeeb return; 27656b4cac81SBjoern A. Zeeb } 27666b4cac81SBjoern A. Zeeb 27676b4cac81SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, c); 27686b4cac81SBjoern A. Zeeb if (chan == NULL) { 27696b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: c %p chan %p\n", __func__, 27706b4cac81SBjoern A. Zeeb c, chan); 27716b4cac81SBjoern A. Zeeb return; 27726b4cac81SBjoern A. Zeeb } 27736b4cac81SBjoern A. Zeeb 27746b4cac81SBjoern A. Zeeb /* XXX max power for scanning? */ 27756b4cac81SBjoern A. Zeeb IMPROVE(); 27766b4cac81SBjoern A. Zeeb 27776b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 27784a07abdeSBjoern A. Zeeb cfg80211_chandef_create(&hw->conf.chandef, chan, 27794a07abdeSBjoern A. Zeeb NL80211_CHAN_NO_HT); 27806b4cac81SBjoern A. Zeeb 27816b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_CHANNEL); 27826b4cac81SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) { 27836b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: config %#0x returned %d\n", 27846b4cac81SBjoern A. Zeeb __func__, IEEE80211_CONF_CHANGE_CHANNEL, error); 27856b4cac81SBjoern A. Zeeb /* XXX should we unroll to the previous chandef? */ 27866b4cac81SBjoern A. Zeeb IMPROVE(); 27876b4cac81SBjoern A. Zeeb } else { 27886b4cac81SBjoern A. Zeeb /* Update radiotap channels as well. */ 27896b4cac81SBjoern A. Zeeb lhw->rtap_tx.wt_chan_freq = htole16(c->ic_freq); 27906b4cac81SBjoern A. Zeeb lhw->rtap_tx.wt_chan_flags = htole16(c->ic_flags); 27916b4cac81SBjoern A. Zeeb lhw->rtap_rx.wr_chan_freq = htole16(c->ic_freq); 27926b4cac81SBjoern A. Zeeb lhw->rtap_rx.wr_chan_flags = htole16(c->ic_flags); 27936b4cac81SBjoern A. Zeeb } 27946b4cac81SBjoern A. Zeeb 27956b4cac81SBjoern A. Zeeb /* Currently PS is hard coded off! Not sure it belongs here. */ 27966b4cac81SBjoern A. Zeeb IMPROVE(); 27976b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, SUPPORTS_PS) && 27986b4cac81SBjoern A. Zeeb (hw->conf.flags & IEEE80211_CONF_PS) != 0) { 27996b4cac81SBjoern A. Zeeb hw->conf.flags &= ~IEEE80211_CONF_PS; 28006b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_PS); 28016b4cac81SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) 28026b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: config %#0x returned " 28036b4cac81SBjoern A. Zeeb "%d\n", __func__, IEEE80211_CONF_CHANGE_PS, 28046b4cac81SBjoern A. Zeeb error); 28056b4cac81SBjoern A. Zeeb } 28066b4cac81SBjoern A. Zeeb } 28076b4cac81SBjoern A. Zeeb 28086b4cac81SBjoern A. Zeeb static struct ieee80211_node * 28096b4cac81SBjoern A. Zeeb lkpi_ic_node_alloc(struct ieee80211vap *vap, 28106b4cac81SBjoern A. Zeeb const uint8_t mac[IEEE80211_ADDR_LEN]) 28116b4cac81SBjoern A. Zeeb { 28126b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 28136b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 28144f61ef8bSBjoern A. Zeeb struct ieee80211_node *ni; 28156b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 28166b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 28176b4cac81SBjoern A. Zeeb 28186b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 28196b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 28206b4cac81SBjoern A. Zeeb 28216b4cac81SBjoern A. Zeeb /* We keep allocations de-coupled so we can deal with the two worlds. */ 28224f61ef8bSBjoern A. Zeeb if (lhw->ic_node_alloc == NULL) 28234f61ef8bSBjoern A. Zeeb return (NULL); 28244f61ef8bSBjoern A. Zeeb 28256b4cac81SBjoern A. Zeeb ni = lhw->ic_node_alloc(vap, mac); 28266b4cac81SBjoern A. Zeeb if (ni == NULL) 28276b4cac81SBjoern A. Zeeb return (NULL); 28286b4cac81SBjoern A. Zeeb 28296b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 28304f61ef8bSBjoern A. Zeeb lsta = lkpi_lsta_alloc(vap, mac, hw, ni); 28316b4cac81SBjoern A. Zeeb if (lsta == NULL) { 28326b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL) 28336b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni); 28346b4cac81SBjoern A. Zeeb return (NULL); 28356b4cac81SBjoern A. Zeeb } 28366b4cac81SBjoern A. Zeeb 28376b4cac81SBjoern A. Zeeb return (ni); 28386b4cac81SBjoern A. Zeeb } 28396b4cac81SBjoern A. Zeeb 28406b4cac81SBjoern A. Zeeb static int 28416b4cac81SBjoern A. Zeeb lkpi_ic_node_init(struct ieee80211_node *ni) 28426b4cac81SBjoern A. Zeeb { 28436b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 28446b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 28456b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 28466b4cac81SBjoern A. Zeeb int error; 28476b4cac81SBjoern A. Zeeb 28486b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 28496b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 28506b4cac81SBjoern A. Zeeb 28516b4cac81SBjoern A. Zeeb if (lhw->ic_node_init != NULL) { 28526b4cac81SBjoern A. Zeeb error = lhw->ic_node_init(ni); 28536b4cac81SBjoern A. Zeeb if (error != 0) 28546b4cac81SBjoern A. Zeeb return (error); 28556b4cac81SBjoern A. Zeeb } 28566b4cac81SBjoern A. Zeeb 28576b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 28586b4cac81SBjoern A. Zeeb 28596b4cac81SBjoern A. Zeeb /* Now take the reference before linking it to the table. */ 28606b4cac81SBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 28616b4cac81SBjoern A. Zeeb 28626b4cac81SBjoern A. Zeeb /* XXX-BZ Sync other state over. */ 28636b4cac81SBjoern A. Zeeb IMPROVE(); 28646b4cac81SBjoern A. Zeeb 28656b4cac81SBjoern A. Zeeb return (0); 28666b4cac81SBjoern A. Zeeb } 28676b4cac81SBjoern A. Zeeb 28686b4cac81SBjoern A. Zeeb static void 28696b4cac81SBjoern A. Zeeb lkpi_ic_node_cleanup(struct ieee80211_node *ni) 28706b4cac81SBjoern A. Zeeb { 28716b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 28726b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 28736b4cac81SBjoern A. Zeeb 28746b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 28756b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 28766b4cac81SBjoern A. Zeeb 28776b4cac81SBjoern A. Zeeb /* XXX-BZ remove from driver, ... */ 28786b4cac81SBjoern A. Zeeb IMPROVE(); 28796b4cac81SBjoern A. Zeeb 28806b4cac81SBjoern A. Zeeb if (lhw->ic_node_cleanup != NULL) 28816b4cac81SBjoern A. Zeeb lhw->ic_node_cleanup(ni); 28826b4cac81SBjoern A. Zeeb } 28836b4cac81SBjoern A. Zeeb 28846b4cac81SBjoern A. Zeeb static void 28856b4cac81SBjoern A. Zeeb lkpi_ic_node_free(struct ieee80211_node *ni) 28866b4cac81SBjoern A. Zeeb { 28876b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 28886b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 28896b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 28906b4cac81SBjoern A. Zeeb 28916b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 28926b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 28936b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 2894d9f59799SBjoern A. Zeeb if (lsta == NULL) 2895d9f59799SBjoern A. Zeeb goto out; 28966b4cac81SBjoern A. Zeeb 28976b4cac81SBjoern A. Zeeb /* XXX-BZ free resources, ... */ 28986b4cac81SBjoern A. Zeeb IMPROVE(); 28996b4cac81SBjoern A. Zeeb 29006b4cac81SBjoern A. Zeeb /* Flush mbufq (make sure to release ni refs!). */ 29016b4cac81SBjoern A. Zeeb #ifdef __notyet__ 29026b4cac81SBjoern A. Zeeb KASSERT(mbufq_len(&lsta->txq) == 0, ("%s: lsta %p has txq len %d != 0\n", 29036b4cac81SBjoern A. Zeeb __func__, lsta, mbufq_len(&lsta->txq))); 29046b4cac81SBjoern A. Zeeb #endif 29056b4cac81SBjoern A. Zeeb /* Drain taskq. */ 29066b4cac81SBjoern A. Zeeb 29076b4cac81SBjoern A. Zeeb /* Drain sta->txq[] */ 29086b4cac81SBjoern A. Zeeb mtx_destroy(&lsta->txq_mtx); 29096b4cac81SBjoern A. Zeeb 29106b4cac81SBjoern A. Zeeb /* Remove lsta if added_to_drv. */ 2911e24e8103SBjoern A. Zeeb 29126b4cac81SBjoern A. Zeeb /* Remove lsta from vif */ 2913e24e8103SBjoern A. Zeeb /* Remove ref from lsta node... */ 2914d9f59799SBjoern A. Zeeb /* Free lsta. */ 2915e24e8103SBjoern A. Zeeb lkpi_lsta_remove(lsta, VAP_TO_LVIF(ni->ni_vap)); 2916d9f59799SBjoern A. Zeeb 2917d9f59799SBjoern A. Zeeb out: 29186b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL) 29196b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni); 29206b4cac81SBjoern A. Zeeb } 29216b4cac81SBjoern A. Zeeb 29226b4cac81SBjoern A. Zeeb static int 29236b4cac81SBjoern A. Zeeb lkpi_ic_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, 29246b4cac81SBjoern A. Zeeb const struct ieee80211_bpf_params *params __unused) 29256b4cac81SBjoern A. Zeeb { 29266b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 29276b4cac81SBjoern A. Zeeb 29286b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 29296b4cac81SBjoern A. Zeeb 29306b4cac81SBjoern A. Zeeb /* Queue the packet and enqueue the task to handle it. */ 29316b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_LOCK(lsta); 29326b4cac81SBjoern A. Zeeb mbufq_enqueue(&lsta->txq, m); 29336b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_UNLOCK(lsta); 29346b4cac81SBjoern A. Zeeb 29359d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 29369d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 29376b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p ni %p %6D mbuf_qlen %d\n", 29386b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, ni, ni->ni_macaddr, ":", 29396b4cac81SBjoern A. Zeeb mbufq_len(&lsta->txq)); 29409d9ba2b7SBjoern A. Zeeb #endif 29416b4cac81SBjoern A. Zeeb 29426b4cac81SBjoern A. Zeeb taskqueue_enqueue(taskqueue_thread, &lsta->txq_task); 29436b4cac81SBjoern A. Zeeb return (0); 29446b4cac81SBjoern A. Zeeb } 29456b4cac81SBjoern A. Zeeb 29466b4cac81SBjoern A. Zeeb static void 29476b4cac81SBjoern A. Zeeb lkpi_80211_txq_tx_one(struct lkpi_sta *lsta, struct mbuf *m) 29486b4cac81SBjoern A. Zeeb { 29496b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 2950b35f6cd0SBjoern A. Zeeb #ifndef LKPI_80211_HW_CRYPTO 29516b4cac81SBjoern A. Zeeb struct ieee80211_frame *wh; 2952b35f6cd0SBjoern A. Zeeb #endif 29536b4cac81SBjoern A. Zeeb struct ieee80211_key *k; 29546b4cac81SBjoern A. Zeeb struct sk_buff *skb; 29556b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 29566b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 29576b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 29586b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 29596b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 29606b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 29616b4cac81SBjoern A. Zeeb struct ieee80211_tx_control control; 29626b4cac81SBjoern A. Zeeb struct ieee80211_tx_info *info; 29636b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 2964e3a0b120SBjoern A. Zeeb struct ieee80211_hdr *hdr; 29656b4cac81SBjoern A. Zeeb void *buf; 2966e3a0b120SBjoern A. Zeeb uint8_t ac, tid; 29676b4cac81SBjoern A. Zeeb 29686b4cac81SBjoern A. Zeeb M_ASSERTPKTHDR(m); 29696b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 29709d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX_DUMP) 29716b4cac81SBjoern A. Zeeb hexdump(mtod(m, const void *), m->m_len, "RAW TX (plain) ", 0); 29726b4cac81SBjoern A. Zeeb #endif 29736b4cac81SBjoern A. Zeeb 29746b4cac81SBjoern A. Zeeb ni = lsta->ni; 2975b35f6cd0SBjoern A. Zeeb k = NULL; 2976b35f6cd0SBjoern A. Zeeb #ifndef LKPI_80211_HW_CRYPTO 29776b4cac81SBjoern A. Zeeb /* Encrypt the frame if need be; XXX-BZ info->control.hw_key. */ 29786b4cac81SBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame *); 29796b4cac81SBjoern A. Zeeb if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { 29806b4cac81SBjoern A. Zeeb /* Retrieve key for TX && do software encryption. */ 29816b4cac81SBjoern A. Zeeb k = ieee80211_crypto_encap(ni, m); 29826b4cac81SBjoern A. Zeeb if (k == NULL) { 29836b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 29846b4cac81SBjoern A. Zeeb m_freem(m); 29856b4cac81SBjoern A. Zeeb return; 29866b4cac81SBjoern A. Zeeb } 29876b4cac81SBjoern A. Zeeb } 29886b4cac81SBjoern A. Zeeb #endif 29896b4cac81SBjoern A. Zeeb 29906b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 29916b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 29926b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 29936b4cac81SBjoern A. Zeeb c = ni->ni_chan; 29946b4cac81SBjoern A. Zeeb 29956b4cac81SBjoern A. Zeeb if (ieee80211_radiotap_active_vap(ni->ni_vap)) { 29966b4cac81SBjoern A. Zeeb struct lkpi_radiotap_tx_hdr *rtap; 29976b4cac81SBjoern A. Zeeb 29986b4cac81SBjoern A. Zeeb rtap = &lhw->rtap_tx; 29996b4cac81SBjoern A. Zeeb rtap->wt_flags = 0; 30006b4cac81SBjoern A. Zeeb if (k != NULL) 30016b4cac81SBjoern A. Zeeb rtap->wt_flags |= IEEE80211_RADIOTAP_F_WEP; 30026b4cac81SBjoern A. Zeeb if (m->m_flags & M_FRAG) 30036b4cac81SBjoern A. Zeeb rtap->wt_flags |= IEEE80211_RADIOTAP_F_FRAG; 30046b4cac81SBjoern A. Zeeb IMPROVE(); 30056b4cac81SBjoern A. Zeeb rtap->wt_rate = 0; 30066b4cac81SBjoern A. Zeeb if (c != NULL && c != IEEE80211_CHAN_ANYC) { 30076b4cac81SBjoern A. Zeeb rtap->wt_chan_freq = htole16(c->ic_freq); 30086b4cac81SBjoern A. Zeeb rtap->wt_chan_flags = htole16(c->ic_flags); 30096b4cac81SBjoern A. Zeeb } 30106b4cac81SBjoern A. Zeeb 30116b4cac81SBjoern A. Zeeb ieee80211_radiotap_tx(ni->ni_vap, m); 30126b4cac81SBjoern A. Zeeb } 30136b4cac81SBjoern A. Zeeb 30146b4cac81SBjoern A. Zeeb /* 30156b4cac81SBjoern A. Zeeb * net80211 should handle hw->extra_tx_headroom. 30166b4cac81SBjoern A. Zeeb * Though for as long as we are copying we don't mind. 30173d09d310SBjoern A. Zeeb * XXX-BZ rtw88 asks for too much headroom for ipv6+tcp: 30183d09d310SBjoern A. Zeeb * https://lists.freebsd.org/archives/freebsd-transport/2022-February/000012.html 30196b4cac81SBjoern A. Zeeb */ 30206b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + m->m_pkthdr.len); 30216b4cac81SBjoern A. Zeeb if (skb == NULL) { 30226b4cac81SBjoern A. Zeeb printf("XXX ERROR %s: skb alloc failed\n", __func__); 30236b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 30246b4cac81SBjoern A. Zeeb m_freem(m); 30256b4cac81SBjoern A. Zeeb return; 30266b4cac81SBjoern A. Zeeb } 30276b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 30286b4cac81SBjoern A. Zeeb 30296b4cac81SBjoern A. Zeeb /* XXX-BZ we need a SKB version understanding mbuf. */ 30306b4cac81SBjoern A. Zeeb /* Save the mbuf for ieee80211_tx_complete(). */ 30316b4cac81SBjoern A. Zeeb skb->m_free_func = lkpi_ieee80211_free_skb_mbuf; 30326b4cac81SBjoern A. Zeeb skb->m = m; 30336b4cac81SBjoern A. Zeeb #if 0 30346b4cac81SBjoern A. Zeeb skb_put_data(skb, m->m_data, m->m_pkthdr.len); 30356b4cac81SBjoern A. Zeeb #else 30366b4cac81SBjoern A. Zeeb buf = skb_put(skb, m->m_pkthdr.len); 30376b4cac81SBjoern A. Zeeb m_copydata(m, 0, m->m_pkthdr.len, buf); 30386b4cac81SBjoern A. Zeeb #endif 30396b4cac81SBjoern A. Zeeb /* Save the ni. */ 30406b4cac81SBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = ni; 30416b4cac81SBjoern A. Zeeb 30426b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(ni->ni_vap); 30436b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 30446b4cac81SBjoern A. Zeeb 3045e3a0b120SBjoern A. Zeeb hdr = (void *)skb->data; 3046e3a0b120SBjoern A. Zeeb tid = linuxkpi_ieee80211_get_tid(hdr, true); 3047e3a0b120SBjoern A. Zeeb if (tid == IEEE80211_NONQOS_TID) { /* == IEEE80211_NUM_TIDS */ 3048e3a0b120SBjoern A. Zeeb skb->priority = 0; 3049e3a0b120SBjoern A. Zeeb ac = IEEE80211_AC_BE; 3050e3a0b120SBjoern A. Zeeb } else { 3051e3a0b120SBjoern A. Zeeb skb->priority = tid & IEEE80211_QOS_CTL_TID_MASK; 3052e3a0b120SBjoern A. Zeeb ac = tid_to_mac80211_ac[tid & 7]; 3053e3a0b120SBjoern A. Zeeb } 30546b4cac81SBjoern A. Zeeb skb_set_queue_mapping(skb, ac); 30556b4cac81SBjoern A. Zeeb 30566b4cac81SBjoern A. Zeeb info = IEEE80211_SKB_CB(skb); 30576b4cac81SBjoern A. Zeeb info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; 30586b4cac81SBjoern A. Zeeb /* Slight delay; probably only happens on scanning so fine? */ 30596b4cac81SBjoern A. Zeeb if (c == NULL || c == IEEE80211_CHAN_ANYC) 30606b4cac81SBjoern A. Zeeb c = ic->ic_curchan; 30616b4cac81SBjoern A. Zeeb info->band = lkpi_net80211_chan_to_nl80211_band(c); 3062e3a0b120SBjoern A. Zeeb info->hw_queue = vif->hw_queue[ac]; 30636b4cac81SBjoern A. Zeeb if (m->m_flags & M_EAPOL) 30646b4cac81SBjoern A. Zeeb info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO; 30656b4cac81SBjoern A. Zeeb info->control.vif = vif; 30666b4cac81SBjoern A. Zeeb /* XXX-BZ info->control.rates */ 30676b4cac81SBjoern A. Zeeb 30686b4cac81SBjoern A. Zeeb lsta = lkpi_find_lsta_by_ni(lvif, ni); 30696b4cac81SBjoern A. Zeeb if (lsta != NULL) { 30706b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 3071b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 30726b4cac81SBjoern A. Zeeb info->control.hw_key = lsta->kc; 30736b4cac81SBjoern A. Zeeb #endif 30746b4cac81SBjoern A. Zeeb } else { 30756b4cac81SBjoern A. Zeeb sta = NULL; 30766b4cac81SBjoern A. Zeeb } 30776b4cac81SBjoern A. Zeeb 30786b4cac81SBjoern A. Zeeb IMPROVE(); 30796b4cac81SBjoern A. Zeeb 30806b4cac81SBjoern A. Zeeb if (sta != NULL) { 30816b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 30826b4cac81SBjoern A. Zeeb 3083e3a0b120SBjoern A. Zeeb ltxq = NULL; 3084e3a0b120SBjoern A. Zeeb if (!ieee80211_is_data_present(hdr->frame_control)) { 3085e3a0b120SBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_STATION && 3086e3a0b120SBjoern A. Zeeb lsta->added_to_drv && 3087e3a0b120SBjoern A. Zeeb sta->txq[IEEE80211_NUM_TIDS] != NULL) 3088d0d29110SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[IEEE80211_NUM_TIDS]); 3089e3a0b120SBjoern A. Zeeb } else if (lsta->added_to_drv && 3090e3a0b120SBjoern A. Zeeb sta->txq[skb->priority] != NULL) { 3091e3a0b120SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[skb->priority]); 3092e3a0b120SBjoern A. Zeeb } 3093e3a0b120SBjoern A. Zeeb if (ltxq == NULL) 3094d0d29110SBjoern A. Zeeb goto ops_tx; 3095e3a0b120SBjoern A. Zeeb 3096d0d29110SBjoern A. Zeeb KASSERT(ltxq != NULL, ("%s: lsta %p sta %p m %p skb %p " 3097d0d29110SBjoern A. Zeeb "ltxq %p != NULL\n", __func__, lsta, sta, m, skb, ltxq)); 3098d0d29110SBjoern A. Zeeb 30996b4cac81SBjoern A. Zeeb skb_queue_tail(<xq->skbq, skb); 31009d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 31019d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 3102d0d29110SBjoern A. Zeeb printf("%s:%d mo_wake_tx_queue :: %d %u lsta %p sta %p " 3103d0d29110SBjoern A. Zeeb "ni %p %6D skb %p lxtq %p { qlen %u, ac %d tid %u } " 3104d0d29110SBjoern A. Zeeb "WAKE_TX_Q ac %d prio %u qmap %u\n", 3105fb6eaf74SBjoern A. Zeeb __func__, __LINE__, 3106d0d29110SBjoern A. Zeeb curthread->td_tid, (unsigned int)ticks, 3107d0d29110SBjoern A. Zeeb lsta, sta, ni, ni->ni_macaddr, ":", skb, ltxq, 3108d0d29110SBjoern A. Zeeb skb_queue_len(<xq->skbq), ltxq->txq.ac, 3109d0d29110SBjoern A. Zeeb ltxq->txq.tid, ac, skb->priority, skb->qmap); 31109d9ba2b7SBjoern A. Zeeb #endif 3111d0d29110SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, <xq->txq); 31126b4cac81SBjoern A. Zeeb return; 31136b4cac81SBjoern A. Zeeb } 31146b4cac81SBjoern A. Zeeb 31156b4cac81SBjoern A. Zeeb ops_tx: 31169d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 31179d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 3118d0d29110SBjoern A. Zeeb printf("%s:%d mo_tx :: lsta %p sta %p ni %p %6D skb %p " 3119d0d29110SBjoern A. Zeeb "TX ac %d prio %u qmap %u\n", 31206b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, sta, ni, ni->ni_macaddr, ":", 31216b4cac81SBjoern A. Zeeb skb, ac, skb->priority, skb->qmap); 31229d9ba2b7SBjoern A. Zeeb #endif 31236b4cac81SBjoern A. Zeeb memset(&control, 0, sizeof(control)); 31246b4cac81SBjoern A. Zeeb control.sta = sta; 31256b4cac81SBjoern A. Zeeb 31266b4cac81SBjoern A. Zeeb lkpi_80211_mo_tx(hw, &control, skb); 31276b4cac81SBjoern A. Zeeb return; 31286b4cac81SBjoern A. Zeeb } 31296b4cac81SBjoern A. Zeeb 31306b4cac81SBjoern A. Zeeb static void 31316b4cac81SBjoern A. Zeeb lkpi_80211_txq_task(void *ctx, int pending) 31326b4cac81SBjoern A. Zeeb { 31336b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 31346b4cac81SBjoern A. Zeeb struct mbufq mq; 31356b4cac81SBjoern A. Zeeb struct mbuf *m; 31366b4cac81SBjoern A. Zeeb 31376b4cac81SBjoern A. Zeeb lsta = ctx; 31386b4cac81SBjoern A. Zeeb 31399d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 31409d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 31416b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p ni %p %6D pending %d mbuf_qlen %d\n", 31429d9ba2b7SBjoern A. Zeeb __func__, __LINE__, lsta, lsta->ni, lsta->ni->ni_macaddr, ":", 31436b4cac81SBjoern A. Zeeb pending, mbufq_len(&lsta->txq)); 31449d9ba2b7SBjoern A. Zeeb #endif 31456b4cac81SBjoern A. Zeeb 31466b4cac81SBjoern A. Zeeb mbufq_init(&mq, IFQ_MAXLEN); 31476b4cac81SBjoern A. Zeeb 31486b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_LOCK(lsta); 31496b4cac81SBjoern A. Zeeb mbufq_concat(&mq, &lsta->txq); 31506b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_UNLOCK(lsta); 31516b4cac81SBjoern A. Zeeb 31526b4cac81SBjoern A. Zeeb m = mbufq_dequeue(&mq); 31536b4cac81SBjoern A. Zeeb while (m != NULL) { 31546b4cac81SBjoern A. Zeeb lkpi_80211_txq_tx_one(lsta, m); 31556b4cac81SBjoern A. Zeeb m = mbufq_dequeue(&mq); 31566b4cac81SBjoern A. Zeeb } 31576b4cac81SBjoern A. Zeeb } 31586b4cac81SBjoern A. Zeeb 31596b4cac81SBjoern A. Zeeb static int 31606b4cac81SBjoern A. Zeeb lkpi_ic_transmit(struct ieee80211com *ic, struct mbuf *m) 31616b4cac81SBjoern A. Zeeb { 31626b4cac81SBjoern A. Zeeb 31636b4cac81SBjoern A. Zeeb /* XXX TODO */ 31646b4cac81SBjoern A. Zeeb IMPROVE(); 31656b4cac81SBjoern A. Zeeb 31666b4cac81SBjoern A. Zeeb /* Quick and dirty cheating hack. */ 31676b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 31686b4cac81SBjoern A. Zeeb 31696b4cac81SBjoern A. Zeeb ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; 31706b4cac81SBjoern A. Zeeb return (lkpi_ic_raw_xmit(ni, m, NULL)); 31716b4cac81SBjoern A. Zeeb } 31726b4cac81SBjoern A. Zeeb 31736b4cac81SBjoern A. Zeeb static void 31746b4cac81SBjoern A. Zeeb lkpi_ic_getradiocaps(struct ieee80211com *ic, int maxchan, 31756b4cac81SBjoern A. Zeeb int *n, struct ieee80211_channel *c) 31766b4cac81SBjoern A. Zeeb { 31776b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 31786b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 31796b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 31806b4cac81SBjoern A. Zeeb uint8_t bands[IEEE80211_MODE_BYTES]; 31816b4cac81SBjoern A. Zeeb int chan_flags, error, i, nchans; 31826b4cac81SBjoern A. Zeeb 31836b4cac81SBjoern A. Zeeb /* Channels */ 31846b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 31856b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 31866b4cac81SBjoern A. Zeeb 31876b4cac81SBjoern A. Zeeb /* NL80211_BAND_2GHZ */ 31886b4cac81SBjoern A. Zeeb nchans = 0; 31896b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_2GHZ] != NULL) 31906b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[NL80211_BAND_2GHZ]->n_channels; 31916b4cac81SBjoern A. Zeeb if (nchans > 0) { 31926b4cac81SBjoern A. Zeeb memset(bands, 0, sizeof(bands)); 31936b4cac81SBjoern A. Zeeb chan_flags = 0; 31946b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11B); 31956b4cac81SBjoern A. Zeeb /* XXX-BZ unclear how to check for 11g. */ 31966b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11G); 31976b4cac81SBjoern A. Zeeb #ifdef __notyet__ 31986b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_2GHZ]->ht_cap.ht_supported) { 31996b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11NG); 32006b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_HT40; 32016b4cac81SBjoern A. Zeeb } 32026b4cac81SBjoern A. Zeeb #endif 32036b4cac81SBjoern A. Zeeb 32046b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[NL80211_BAND_2GHZ]->channels; 3205cee56e77SBjoern A. Zeeb for (i = 0; i < nchans && *n < maxchan; i++) { 32066b4cac81SBjoern A. Zeeb uint32_t nflags = 0; 32076b4cac81SBjoern A. Zeeb int cflags = chan_flags; 32086b4cac81SBjoern A. Zeeb 32096b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) { 32106b4cac81SBjoern A. Zeeb printf("%s: %s: Skipping disabled chan " 32116b4cac81SBjoern A. Zeeb "[%u/%u/%#x]\n", ic->ic_name, __func__, 32126b4cac81SBjoern A. Zeeb channels[i].hw_value, 32136b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags); 32146b4cac81SBjoern A. Zeeb continue; 32156b4cac81SBjoern A. Zeeb } 32166b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_IR) 32176b4cac81SBjoern A. Zeeb nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE); 32186b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_RADAR) 32196b4cac81SBjoern A. Zeeb nflags |= IEEE80211_CHAN_DFS; 32206b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ) 32216b4cac81SBjoern A. Zeeb cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80); 32226b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ) 32236b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_VHT80; 32246b4cac81SBjoern A. Zeeb /* XXX how to map the remaining enum ieee80211_channel_flags? */ 32256b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_HT40) 32266b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_HT40; 32276b4cac81SBjoern A. Zeeb 32286b4cac81SBjoern A. Zeeb error = ieee80211_add_channel_cbw(c, maxchan, n, 32296b4cac81SBjoern A. Zeeb channels[i].hw_value, channels[i].center_freq, 32306b4cac81SBjoern A. Zeeb channels[i].max_power, 32316b4cac81SBjoern A. Zeeb nflags, bands, chan_flags); 3232cee56e77SBjoern A. Zeeb /* net80211::ENOBUFS: *n >= maxchans */ 3233cee56e77SBjoern A. Zeeb if (error != 0 && error != ENOBUFS) 32346b4cac81SBjoern A. Zeeb printf("%s: %s: Adding chan %u/%u/%#x/%#x/%#x/%#x " 32356b4cac81SBjoern A. Zeeb "returned error %d\n", ic->ic_name, 32366b4cac81SBjoern A. Zeeb __func__, channels[i].hw_value, 32376b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags, 32386b4cac81SBjoern A. Zeeb nflags, chan_flags, cflags, error); 3239cee56e77SBjoern A. Zeeb if (error != 0) 32406b4cac81SBjoern A. Zeeb break; 32416b4cac81SBjoern A. Zeeb } 32426b4cac81SBjoern A. Zeeb } 32436b4cac81SBjoern A. Zeeb 32446b4cac81SBjoern A. Zeeb /* NL80211_BAND_5GHZ */ 32456b4cac81SBjoern A. Zeeb nchans = 0; 32466b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ] != NULL) 32476b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[NL80211_BAND_5GHZ]->n_channels; 32486b4cac81SBjoern A. Zeeb if (nchans > 0) { 32496b4cac81SBjoern A. Zeeb memset(bands, 0, sizeof(bands)); 32506b4cac81SBjoern A. Zeeb chan_flags = 0; 32516b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11A); 32526b4cac81SBjoern A. Zeeb #ifdef __not_yet__ 32536b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ]->ht_cap.ht_supported) { 32546b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11NA); 32556b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_HT40; 32566b4cac81SBjoern A. Zeeb } 32576b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.vht_supported){ 32586b4cac81SBjoern A. Zeeb 32596b4cac81SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_VHT; 32606b4cac81SBjoern A. Zeeb ic->ic_vhtcaps = 32616b4cac81SBjoern A. Zeeb hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap; 32626b4cac81SBjoern A. Zeeb 32636b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_VHT_5GHZ); 32646b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT80; 32656b4cac81SBjoern A. Zeeb if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160MHZ( 32666b4cac81SBjoern A. Zeeb ic->ic_vhtcaps)) 32676b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT160; 32686b4cac81SBjoern A. Zeeb if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160_80P80MHZ( 32696b4cac81SBjoern A. Zeeb ic->ic_vhtcaps)) 32706b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT80P80; 32716b4cac81SBjoern A. Zeeb } 32726b4cac81SBjoern A. Zeeb #endif 32736b4cac81SBjoern A. Zeeb 32746b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[NL80211_BAND_5GHZ]->channels; 3275cee56e77SBjoern A. Zeeb for (i = 0; i < nchans && *n < maxchan; i++) { 32766b4cac81SBjoern A. Zeeb uint32_t nflags = 0; 32776b4cac81SBjoern A. Zeeb int cflags = chan_flags; 32786b4cac81SBjoern A. Zeeb 32796b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) { 32806b4cac81SBjoern A. Zeeb printf("%s: %s: Skipping disabled chan " 32816b4cac81SBjoern A. Zeeb "[%u/%u/%#x]\n", ic->ic_name, __func__, 32826b4cac81SBjoern A. Zeeb channels[i].hw_value, 32836b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags); 32846b4cac81SBjoern A. Zeeb continue; 32856b4cac81SBjoern A. Zeeb } 32866b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_IR) 32876b4cac81SBjoern A. Zeeb nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE); 32886b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_RADAR) 32896b4cac81SBjoern A. Zeeb nflags |= IEEE80211_CHAN_DFS; 32906b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ) 32916b4cac81SBjoern A. Zeeb cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80); 32926b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ) 32936b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_VHT80; 32946b4cac81SBjoern A. Zeeb /* XXX hwo to map the remaining enum ieee80211_channel_flags? */ 32956b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_HT40) 32966b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_HT40; 32976b4cac81SBjoern A. Zeeb 32986b4cac81SBjoern A. Zeeb error = ieee80211_add_channel_cbw(c, maxchan, n, 32996b4cac81SBjoern A. Zeeb channels[i].hw_value, channels[i].center_freq, 33006b4cac81SBjoern A. Zeeb channels[i].max_power, 33016b4cac81SBjoern A. Zeeb nflags, bands, chan_flags); 3302cee56e77SBjoern A. Zeeb /* net80211::ENOBUFS: *n >= maxchans */ 3303cee56e77SBjoern A. Zeeb if (error != 0 && error != ENOBUFS) 33046b4cac81SBjoern A. Zeeb printf("%s: %s: Adding chan %u/%u/%#x/%#x/%#x/%#x " 33056b4cac81SBjoern A. Zeeb "returned error %d\n", ic->ic_name, 33066b4cac81SBjoern A. Zeeb __func__, channels[i].hw_value, 33076b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags, 33086b4cac81SBjoern A. Zeeb nflags, chan_flags, cflags, error); 3309cee56e77SBjoern A. Zeeb if (error != 0) 33106b4cac81SBjoern A. Zeeb break; 33116b4cac81SBjoern A. Zeeb } 33126b4cac81SBjoern A. Zeeb } 33136b4cac81SBjoern A. Zeeb } 33146b4cac81SBjoern A. Zeeb 33156b4cac81SBjoern A. Zeeb static void * 33166b4cac81SBjoern A. Zeeb lkpi_ieee80211_ifalloc(void) 33176b4cac81SBjoern A. Zeeb { 33186b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 33196b4cac81SBjoern A. Zeeb 33206b4cac81SBjoern A. Zeeb ic = malloc(sizeof(*ic), M_LKPI80211, M_WAITOK | M_ZERO); 33216b4cac81SBjoern A. Zeeb if (ic == NULL) 33226b4cac81SBjoern A. Zeeb return (NULL); 33236b4cac81SBjoern A. Zeeb 33246b4cac81SBjoern A. Zeeb /* Setting these happens later when we have device information. */ 33256b4cac81SBjoern A. Zeeb ic->ic_softc = NULL; 33266b4cac81SBjoern A. Zeeb ic->ic_name = "linuxkpi"; 33276b4cac81SBjoern A. Zeeb 33286b4cac81SBjoern A. Zeeb return (ic); 33296b4cac81SBjoern A. Zeeb } 33306b4cac81SBjoern A. Zeeb 33316b4cac81SBjoern A. Zeeb struct ieee80211_hw * 33326b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_alloc_hw(size_t priv_len, const struct ieee80211_ops *ops) 33336b4cac81SBjoern A. Zeeb { 33346b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 33356b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 33366b4cac81SBjoern A. Zeeb struct wiphy *wiphy; 33376b4cac81SBjoern A. Zeeb 33386b4cac81SBjoern A. Zeeb /* Get us and the driver data also allocated. */ 33396b4cac81SBjoern A. Zeeb wiphy = wiphy_new(&linuxkpi_mac80211cfgops, sizeof(*lhw) + priv_len); 33406b4cac81SBjoern A. Zeeb if (wiphy == NULL) 33416b4cac81SBjoern A. Zeeb return (NULL); 33426b4cac81SBjoern A. Zeeb 33436b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 33446b4cac81SBjoern A. Zeeb lhw->ops = ops; 3345652e22d3SBjoern A. Zeeb 33466b4cac81SBjoern A. Zeeb mtx_init(&lhw->mtx, "lhw", NULL, MTX_DEF | MTX_RECURSE); 33478891c455SBjoern A. Zeeb sx_init_flags(&lhw->lvif_sx, "lhw-lvif", SX_RECURSE | SX_DUPOK); 33486b4cac81SBjoern A. Zeeb TAILQ_INIT(&lhw->lvif_head); 33496b4cac81SBjoern A. Zeeb 33506b4cac81SBjoern A. Zeeb /* 33516b4cac81SBjoern A. Zeeb * XXX-BZ TODO make sure there is a "_null" function to all ops 33526b4cac81SBjoern A. Zeeb * not initialized. 33536b4cac81SBjoern A. Zeeb */ 33546b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 33556b4cac81SBjoern A. Zeeb hw->wiphy = wiphy; 3356086be6a8SBjoern A. Zeeb hw->conf.flags |= IEEE80211_CONF_IDLE; 33576b4cac81SBjoern A. Zeeb hw->priv = (void *)(lhw + 1); 33586b4cac81SBjoern A. Zeeb 33596b4cac81SBjoern A. Zeeb /* BSD Specific. */ 33606b4cac81SBjoern A. Zeeb lhw->ic = lkpi_ieee80211_ifalloc(); 33616b4cac81SBjoern A. Zeeb if (lhw->ic == NULL) { 33626b4cac81SBjoern A. Zeeb ieee80211_free_hw(hw); 33636b4cac81SBjoern A. Zeeb return (NULL); 33646b4cac81SBjoern A. Zeeb } 33656b4cac81SBjoern A. Zeeb 33666b4cac81SBjoern A. Zeeb IMPROVE(); 33676b4cac81SBjoern A. Zeeb 33686b4cac81SBjoern A. Zeeb return (hw); 33696b4cac81SBjoern A. Zeeb } 33706b4cac81SBjoern A. Zeeb 33716b4cac81SBjoern A. Zeeb void 33726b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iffree(struct ieee80211_hw *hw) 33736b4cac81SBjoern A. Zeeb { 33746b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 33756b4cac81SBjoern A. Zeeb 33766b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 33776b4cac81SBjoern A. Zeeb free(lhw->ic, M_LKPI80211); 33786b4cac81SBjoern A. Zeeb lhw->ic = NULL; 33796b4cac81SBjoern A. Zeeb 33806b4cac81SBjoern A. Zeeb /* Cleanup more of lhw here or in wiphy_free()? */ 33818891c455SBjoern A. Zeeb sx_destroy(&lhw->lvif_sx); 33826b4cac81SBjoern A. Zeeb mtx_destroy(&lhw->mtx); 33836b4cac81SBjoern A. Zeeb IMPROVE(); 33846b4cac81SBjoern A. Zeeb } 33856b4cac81SBjoern A. Zeeb 33866b4cac81SBjoern A. Zeeb void 33876b4cac81SBjoern A. Zeeb linuxkpi_set_ieee80211_dev(struct ieee80211_hw *hw, char *name) 33886b4cac81SBjoern A. Zeeb { 33896b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 33906b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 33916b4cac81SBjoern A. Zeeb 33926b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 33936b4cac81SBjoern A. Zeeb ic = lhw->ic; 33946b4cac81SBjoern A. Zeeb 33956b4cac81SBjoern A. Zeeb /* Now set a proper name before ieee80211_ifattach(). */ 33966b4cac81SBjoern A. Zeeb ic->ic_softc = lhw; 33976b4cac81SBjoern A. Zeeb ic->ic_name = name; 33986b4cac81SBjoern A. Zeeb 33996b4cac81SBjoern A. Zeeb /* XXX-BZ do we also need to set wiphy name? */ 34006b4cac81SBjoern A. Zeeb } 34016b4cac81SBjoern A. Zeeb 34026b4cac81SBjoern A. Zeeb struct ieee80211_hw * 34036b4cac81SBjoern A. Zeeb linuxkpi_wiphy_to_ieee80211_hw(struct wiphy *wiphy) 34046b4cac81SBjoern A. Zeeb { 34056b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 34066b4cac81SBjoern A. Zeeb 34076b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 34086b4cac81SBjoern A. Zeeb return (LHW_TO_HW(lhw)); 34096b4cac81SBjoern A. Zeeb } 34106b4cac81SBjoern A. Zeeb 34116b4cac81SBjoern A. Zeeb static void 34126b4cac81SBjoern A. Zeeb lkpi_radiotap_attach(struct lkpi_hw *lhw) 34136b4cac81SBjoern A. Zeeb { 34146b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 34156b4cac81SBjoern A. Zeeb 34166b4cac81SBjoern A. Zeeb ic = lhw->ic; 34176b4cac81SBjoern A. Zeeb ieee80211_radiotap_attach(ic, 34186b4cac81SBjoern A. Zeeb &lhw->rtap_tx.wt_ihdr, sizeof(lhw->rtap_tx), 34196b4cac81SBjoern A. Zeeb LKPI_RTAP_TX_FLAGS_PRESENT, 34206b4cac81SBjoern A. Zeeb &lhw->rtap_rx.wr_ihdr, sizeof(lhw->rtap_rx), 34216b4cac81SBjoern A. Zeeb LKPI_RTAP_RX_FLAGS_PRESENT); 34226b4cac81SBjoern A. Zeeb } 34236b4cac81SBjoern A. Zeeb 34242e183d99SBjoern A. Zeeb int 34256b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ifattach(struct ieee80211_hw *hw) 34266b4cac81SBjoern A. Zeeb { 34276b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 34286b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 3429c5b96b3eSBjoern A. Zeeb int band, i; 34306b4cac81SBjoern A. Zeeb 34316b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 34326b4cac81SBjoern A. Zeeb ic = lhw->ic; 34336b4cac81SBjoern A. Zeeb 3434652e22d3SBjoern A. Zeeb /* We do it this late as wiphy->dev should be set for the name. */ 3435652e22d3SBjoern A. Zeeb lhw->workq = alloc_ordered_workqueue(wiphy_name(hw->wiphy), 0); 3436652e22d3SBjoern A. Zeeb if (lhw->workq == NULL) 3437652e22d3SBjoern A. Zeeb return (-EAGAIN); 3438652e22d3SBjoern A. Zeeb 34396b4cac81SBjoern A. Zeeb /* XXX-BZ figure this out how they count his... */ 34406b4cac81SBjoern A. Zeeb if (!is_zero_ether_addr(hw->wiphy->perm_addr)) { 34416b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(ic->ic_macaddr, 34426b4cac81SBjoern A. Zeeb hw->wiphy->perm_addr); 34436b4cac81SBjoern A. Zeeb } else if (hw->wiphy->n_addresses > 0) { 34446b4cac81SBjoern A. Zeeb /* We take the first one. */ 34456b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(ic->ic_macaddr, 34466b4cac81SBjoern A. Zeeb hw->wiphy->addresses[0].addr); 34476b4cac81SBjoern A. Zeeb } else { 34486b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: warning, no hardware address!\n", __func__); 34496b4cac81SBjoern A. Zeeb } 34506b4cac81SBjoern A. Zeeb 34513d09d310SBjoern A. Zeeb #ifdef __not_yet__ 34523d09d310SBjoern A. Zeeb /* See comment in lkpi_80211_txq_tx_one(). */ 34536b4cac81SBjoern A. Zeeb ic->ic_headroom = hw->extra_tx_headroom; 34543d09d310SBjoern A. Zeeb #endif 34556b4cac81SBjoern A. Zeeb 34566b4cac81SBjoern A. Zeeb ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ 34576b4cac81SBjoern A. Zeeb ic->ic_opmode = IEEE80211_M_STA; 34586b4cac81SBjoern A. Zeeb 34596b4cac81SBjoern A. Zeeb /* Set device capabilities. */ 34606b4cac81SBjoern A. Zeeb /* XXX-BZ we need to get these from linux80211/drivers and convert. */ 34616b4cac81SBjoern A. Zeeb ic->ic_caps = 34626b4cac81SBjoern A. Zeeb IEEE80211_C_STA | 34636b4cac81SBjoern A. Zeeb IEEE80211_C_MONITOR | 34646b4cac81SBjoern A. Zeeb IEEE80211_C_WPA | /* WPA/RSN */ 34656b4cac81SBjoern A. Zeeb IEEE80211_C_WME | 34666b4cac81SBjoern A. Zeeb #if 0 34676b4cac81SBjoern A. Zeeb IEEE80211_C_PMGT | 34686b4cac81SBjoern A. Zeeb #endif 34696b4cac81SBjoern A. Zeeb IEEE80211_C_SHSLOT | /* short slot time supported */ 34706b4cac81SBjoern A. Zeeb IEEE80211_C_SHPREAMBLE /* short preamble supported */ 34716b4cac81SBjoern A. Zeeb ; 34726b4cac81SBjoern A. Zeeb #if 0 34736b4cac81SBjoern A. Zeeb /* Scanning is a different kind of beast to re-work. */ 34746b4cac81SBjoern A. Zeeb ic->ic_caps |= IEEE80211_C_BGSCAN; 34756b4cac81SBjoern A. Zeeb #endif 3476cc4e78d5SBjoern A. Zeeb if (lhw->ops->hw_scan) { 3477cc4e78d5SBjoern A. Zeeb /* 3478cc4e78d5SBjoern A. Zeeb * Advertise full-offload scanning. 3479cc4e78d5SBjoern A. Zeeb * 3480cc4e78d5SBjoern A. Zeeb * Not limiting to SINGLE_SCAN_ON_ALL_BANDS here as otherwise 3481cc4e78d5SBjoern A. Zeeb * we essentially disable hw_scan for all drivers not setting 3482cc4e78d5SBjoern A. Zeeb * the flag. 3483cc4e78d5SBjoern A. Zeeb */ 34846b4cac81SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_SCAN_OFFLOAD; 3485a486fbbdSBjoern A. Zeeb lhw->scan_flags |= LKPI_LHW_SCAN_HW; 34866b4cac81SBjoern A. Zeeb } 34876b4cac81SBjoern A. Zeeb 34886b4cac81SBjoern A. Zeeb #ifdef __notyet__ 34896b4cac81SBjoern A. Zeeb ic->ic_htcaps = IEEE80211_HTC_HT /* HT operation */ 34906b4cac81SBjoern A. Zeeb | IEEE80211_HTC_AMPDU /* A-MPDU tx/rx */ 34916b4cac81SBjoern A. Zeeb | IEEE80211_HTC_AMSDU /* A-MSDU tx/rx */ 34926b4cac81SBjoern A. Zeeb | IEEE80211_HTCAP_MAXAMSDU_3839 34936b4cac81SBjoern A. Zeeb /* max A-MSDU length */ 34946b4cac81SBjoern A. Zeeb | IEEE80211_HTCAP_SMPS_OFF; /* SM power save off */ 34956b4cac81SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_SHORTGI20; 34966b4cac81SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_CHWIDTH40 | IEEE80211_HTCAP_SHORTGI40; 34976b4cac81SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_TXSTBC; 34986b4cac81SBjoern A. Zeeb #endif 34996b4cac81SBjoern A. Zeeb 3500527687a9SBjoern A. Zeeb /* 3501527687a9SBjoern A. Zeeb * The wiphy variables report bitmasks of avail antennas. 3502527687a9SBjoern A. Zeeb * (*get_antenna) get the current bitmask sets which can be 3503527687a9SBjoern A. Zeeb * altered by (*set_antenna) for some drivers. 3504527687a9SBjoern A. Zeeb * XXX-BZ will the count alone do us much good long-term in net80211? 3505527687a9SBjoern A. Zeeb */ 3506527687a9SBjoern A. Zeeb if (hw->wiphy->available_antennas_rx || 3507527687a9SBjoern A. Zeeb hw->wiphy->available_antennas_tx) { 3508527687a9SBjoern A. Zeeb uint32_t rxs, txs; 3509527687a9SBjoern A. Zeeb 3510527687a9SBjoern A. Zeeb if (lkpi_80211_mo_get_antenna(hw, &txs, &rxs) == 0) { 3511527687a9SBjoern A. Zeeb ic->ic_rxstream = bitcount32(rxs); 3512527687a9SBjoern A. Zeeb ic->ic_txstream = bitcount32(txs); 3513527687a9SBjoern A. Zeeb } 3514527687a9SBjoern A. Zeeb } 3515527687a9SBjoern A. Zeeb 35166b4cac81SBjoern A. Zeeb ic->ic_cryptocaps = 0; 3517b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 35186b4cac81SBjoern A. Zeeb if (hw->wiphy->n_cipher_suites > 0) { 35196b4cac81SBjoern A. Zeeb for (i = 0; i < hw->wiphy->n_cipher_suites; i++) 35206b4cac81SBjoern A. Zeeb ic->ic_cryptocaps |= lkpi_l80211_to_net80211_cyphers( 35216b4cac81SBjoern A. Zeeb hw->wiphy->cipher_suites[i]); 35226b4cac81SBjoern A. Zeeb } 35236b4cac81SBjoern A. Zeeb #endif 35246b4cac81SBjoern A. Zeeb 35256b4cac81SBjoern A. Zeeb lkpi_ic_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans, 35266b4cac81SBjoern A. Zeeb ic->ic_channels); 35276b4cac81SBjoern A. Zeeb 35286b4cac81SBjoern A. Zeeb ieee80211_ifattach(ic); 35296b4cac81SBjoern A. Zeeb 35306b4cac81SBjoern A. Zeeb ic->ic_update_mcast = lkpi_ic_update_mcast; 35316b4cac81SBjoern A. Zeeb ic->ic_update_promisc = lkpi_ic_update_promisc; 35326b4cac81SBjoern A. Zeeb ic->ic_update_chw = lkpi_ic_update_chw; 35336b4cac81SBjoern A. Zeeb ic->ic_parent = lkpi_ic_parent; 35346b4cac81SBjoern A. Zeeb ic->ic_scan_start = lkpi_ic_scan_start; 35356b4cac81SBjoern A. Zeeb ic->ic_scan_end = lkpi_ic_scan_end; 35366b4cac81SBjoern A. Zeeb ic->ic_set_channel = lkpi_ic_set_channel; 35376b4cac81SBjoern A. Zeeb ic->ic_transmit = lkpi_ic_transmit; 35386b4cac81SBjoern A. Zeeb ic->ic_raw_xmit = lkpi_ic_raw_xmit; 35396b4cac81SBjoern A. Zeeb ic->ic_vap_create = lkpi_ic_vap_create; 35406b4cac81SBjoern A. Zeeb ic->ic_vap_delete = lkpi_ic_vap_delete; 35416b4cac81SBjoern A. Zeeb ic->ic_getradiocaps = lkpi_ic_getradiocaps; 35426b4cac81SBjoern A. Zeeb ic->ic_wme.wme_update = lkpi_ic_wme_update; 35436b4cac81SBjoern A. Zeeb 3544a486fbbdSBjoern A. Zeeb lhw->ic_scan_curchan = ic->ic_scan_curchan; 3545a486fbbdSBjoern A. Zeeb ic->ic_scan_curchan = lkpi_ic_scan_curchan; 3546a486fbbdSBjoern A. Zeeb lhw->ic_scan_mindwell = ic->ic_scan_mindwell; 3547a486fbbdSBjoern A. Zeeb ic->ic_scan_mindwell = lkpi_ic_scan_mindwell; 3548a486fbbdSBjoern A. Zeeb 35496b4cac81SBjoern A. Zeeb lhw->ic_node_alloc = ic->ic_node_alloc; 35506b4cac81SBjoern A. Zeeb ic->ic_node_alloc = lkpi_ic_node_alloc; 35516b4cac81SBjoern A. Zeeb lhw->ic_node_init = ic->ic_node_init; 35526b4cac81SBjoern A. Zeeb ic->ic_node_init = lkpi_ic_node_init; 35536b4cac81SBjoern A. Zeeb lhw->ic_node_cleanup = ic->ic_node_cleanup; 35546b4cac81SBjoern A. Zeeb ic->ic_node_cleanup = lkpi_ic_node_cleanup; 35556b4cac81SBjoern A. Zeeb lhw->ic_node_free = ic->ic_node_free; 35566b4cac81SBjoern A. Zeeb ic->ic_node_free = lkpi_ic_node_free; 35576b4cac81SBjoern A. Zeeb 35586b4cac81SBjoern A. Zeeb lkpi_radiotap_attach(lhw); 35596b4cac81SBjoern A. Zeeb 3560c5b96b3eSBjoern A. Zeeb /* 3561c5b96b3eSBjoern A. Zeeb * Assign the first possible channel for now; seems Realtek drivers 3562c5b96b3eSBjoern A. Zeeb * expect one. 3563d9945d78SBjoern A. Zeeb * Also remember the amount of bands we support and the most rates 3564d9945d78SBjoern A. Zeeb * in any band so we can scale [(ext) sup rates] IE(s) accordingly. 3565c5b96b3eSBjoern A. Zeeb */ 3566d9945d78SBjoern A. Zeeb lhw->supbands = lhw->max_rates = 0; 3567c5b96b3eSBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS && 3568c5b96b3eSBjoern A. Zeeb hw->conf.chandef.chan == NULL; band++) { 3569c5b96b3eSBjoern A. Zeeb struct ieee80211_supported_band *supband; 3570c5b96b3eSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 3571c5b96b3eSBjoern A. Zeeb 3572c5b96b3eSBjoern A. Zeeb supband = hw->wiphy->bands[band]; 3573c5b96b3eSBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 3574c5b96b3eSBjoern A. Zeeb continue; 3575c5b96b3eSBjoern A. Zeeb 3576d9945d78SBjoern A. Zeeb lhw->supbands++; 3577d9945d78SBjoern A. Zeeb lhw->max_rates = max(lhw->max_rates, supband->n_bitrates); 3578d9945d78SBjoern A. Zeeb 3579c5b96b3eSBjoern A. Zeeb channels = supband->channels; 3580c5b96b3eSBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 3581c5b96b3eSBjoern A. Zeeb 3582c5b96b3eSBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) 3583c5b96b3eSBjoern A. Zeeb continue; 3584c5b96b3eSBjoern A. Zeeb 35854a07abdeSBjoern A. Zeeb cfg80211_chandef_create(&hw->conf.chandef, &channels[i], 3586c5b96b3eSBjoern A. Zeeb NL80211_CHAN_NO_HT); 3587c5b96b3eSBjoern A. Zeeb break; 3588c5b96b3eSBjoern A. Zeeb } 3589c5b96b3eSBjoern A. Zeeb } 3590c5b96b3eSBjoern A. Zeeb 3591d9945d78SBjoern A. Zeeb IMPROVE("see net80211::ieee80211_chan_init vs. wiphy->bands[].bitrates possibly in lkpi_ic_getradiocaps?"); 3592d9945d78SBjoern A. Zeeb 3593d9945d78SBjoern A. Zeeb /* Make sure we do not support more than net80211 is willing to take. */ 3594d9945d78SBjoern A. Zeeb if (lhw->max_rates > IEEE80211_RATE_MAXSIZE) { 3595d9945d78SBjoern A. Zeeb ic_printf(ic, "%s: limiting max_rates %d to %d!\n", __func__, 3596d9945d78SBjoern A. Zeeb lhw->max_rates, IEEE80211_RATE_MAXSIZE); 3597d9945d78SBjoern A. Zeeb lhw->max_rates = IEEE80211_RATE_MAXSIZE; 3598d9945d78SBjoern A. Zeeb } 3599d9945d78SBjoern A. Zeeb 3600d9945d78SBjoern A. Zeeb /* 3601d9945d78SBjoern A. Zeeb * The maximum supported bitrates on any band + size for 3602d9945d78SBjoern A. Zeeb * DSSS Parameter Set give our per-band IE size. 3603d9945d78SBjoern A. Zeeb * XXX-BZ FIXME add HT VHT ... later 3604d9945d78SBjoern A. Zeeb * SSID is the responsibility of the driver and goes on the side. 3605d9945d78SBjoern A. Zeeb * The user specified bits coming from the vap go into the 3606d9945d78SBjoern A. Zeeb * "common ies" fields. 3607d9945d78SBjoern A. Zeeb */ 3608d9945d78SBjoern A. Zeeb lhw->scan_ie_len = 2 + IEEE80211_RATE_SIZE; 3609d9945d78SBjoern A. Zeeb if (lhw->max_rates > IEEE80211_RATE_SIZE) 3610d9945d78SBjoern A. Zeeb lhw->scan_ie_len += 2 + (lhw->max_rates - IEEE80211_RATE_SIZE); 3611d9945d78SBjoern A. Zeeb /* 3612d9945d78SBjoern A. Zeeb * net80211 does not seem to support the DSSS Parameter Set but some of 3613d9945d78SBjoern A. Zeeb * the drivers insert it so calculate the extra fixed space in. 3614d9945d78SBjoern A. Zeeb */ 3615d9945d78SBjoern A. Zeeb lhw->scan_ie_len += 2 + 1; 3616d9945d78SBjoern A. Zeeb 3617d9945d78SBjoern A. Zeeb /* Reduce the max_scan_ie_len "left" by the amount we consume already. */ 3618d9945d78SBjoern A. Zeeb if (hw->wiphy->max_scan_ie_len > 0) 3619d9945d78SBjoern A. Zeeb hw->wiphy->max_scan_ie_len -= lhw->scan_ie_len; 3620d9945d78SBjoern A. Zeeb 36216b4cac81SBjoern A. Zeeb if (bootverbose) 36226b4cac81SBjoern A. Zeeb ieee80211_announce(ic); 36232e183d99SBjoern A. Zeeb 36242e183d99SBjoern A. Zeeb return (0); 36256b4cac81SBjoern A. Zeeb } 36266b4cac81SBjoern A. Zeeb 36276b4cac81SBjoern A. Zeeb void 36286b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ifdetach(struct ieee80211_hw *hw) 36296b4cac81SBjoern A. Zeeb { 36306b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 36316b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 36326b4cac81SBjoern A. Zeeb 36336b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 36346b4cac81SBjoern A. Zeeb ic = lhw->ic; 36356b4cac81SBjoern A. Zeeb ieee80211_ifdetach(ic); 36366b4cac81SBjoern A. Zeeb } 36376b4cac81SBjoern A. Zeeb 36386b4cac81SBjoern A. Zeeb void 36396b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_interfaces(struct ieee80211_hw *hw, 36406b4cac81SBjoern A. Zeeb enum ieee80211_iface_iter flags, 36416b4cac81SBjoern A. Zeeb void(*iterfunc)(void *, uint8_t *, struct ieee80211_vif *), 36426b4cac81SBjoern A. Zeeb void *arg) 36436b4cac81SBjoern A. Zeeb { 36446b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 36456b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 36466b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 364761a68e50SBjoern A. Zeeb bool active, atomic, nin_drv; 36486b4cac81SBjoern A. Zeeb 36496b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 36506b4cac81SBjoern A. Zeeb 36516b4cac81SBjoern A. Zeeb if (flags & ~(IEEE80211_IFACE_ITER_NORMAL| 36526b4cac81SBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL| 365361a68e50SBjoern A. Zeeb IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER| 36546b4cac81SBjoern A. Zeeb IEEE80211_IFACE_ITER__ACTIVE|IEEE80211_IFACE_ITER__ATOMIC)) { 36556b4cac81SBjoern A. Zeeb ic_printf(lhw->ic, "XXX TODO %s flags(%#x) not yet supported.\n", 36566b4cac81SBjoern A. Zeeb __func__, flags); 36576b4cac81SBjoern A. Zeeb } 36586b4cac81SBjoern A. Zeeb 36596b4cac81SBjoern A. Zeeb active = (flags & IEEE80211_IFACE_ITER__ACTIVE) != 0; 36606b4cac81SBjoern A. Zeeb atomic = (flags & IEEE80211_IFACE_ITER__ATOMIC) != 0; 366161a68e50SBjoern A. Zeeb nin_drv = (flags & IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER) != 0; 36626b4cac81SBjoern A. Zeeb 36636b4cac81SBjoern A. Zeeb if (atomic) 36648891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 36656b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 36666b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 36676b4cac81SBjoern A. Zeeb 36686b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 36696b4cac81SBjoern A. Zeeb 36706b4cac81SBjoern A. Zeeb /* 36716b4cac81SBjoern A. Zeeb * If we want "active" interfaces, we need to distinguish on 36726b4cac81SBjoern A. Zeeb * whether the driver knows about them or not to be able to 36736b4cac81SBjoern A. Zeeb * handle the "resume" case correctly. Skip the ones the 36746b4cac81SBjoern A. Zeeb * driver does not know about. 36756b4cac81SBjoern A. Zeeb */ 36766b4cac81SBjoern A. Zeeb if (active && !lvif->added_to_drv && 36776b4cac81SBjoern A. Zeeb (flags & IEEE80211_IFACE_ITER_RESUME_ALL) != 0) 36786b4cac81SBjoern A. Zeeb continue; 36796b4cac81SBjoern A. Zeeb 36806b4cac81SBjoern A. Zeeb /* 368161a68e50SBjoern A. Zeeb * If we shall skip interfaces not added to the driver do so 368261a68e50SBjoern A. Zeeb * if we haven't yet. 368361a68e50SBjoern A. Zeeb */ 368461a68e50SBjoern A. Zeeb if (nin_drv && !lvif->added_to_drv) 368561a68e50SBjoern A. Zeeb continue; 368661a68e50SBjoern A. Zeeb 368761a68e50SBjoern A. Zeeb /* 36886b4cac81SBjoern A. Zeeb * Run the iterator function if we are either not asking 36896b4cac81SBjoern A. Zeeb * asking for active only or if the VAP is "running". 36906b4cac81SBjoern A. Zeeb */ 36916b4cac81SBjoern A. Zeeb /* XXX-BZ probably should have state in the lvif as well. */ 36926b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 36936b4cac81SBjoern A. Zeeb if (!active || (vap->iv_state != IEEE80211_S_INIT)) 36946b4cac81SBjoern A. Zeeb iterfunc(arg, vif->addr, vif); 36956b4cac81SBjoern A. Zeeb } 36966b4cac81SBjoern A. Zeeb if (atomic) 36978891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 36986b4cac81SBjoern A. Zeeb } 36996b4cac81SBjoern A. Zeeb 37006b4cac81SBjoern A. Zeeb void 37016b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_keys(struct ieee80211_hw *hw, 37026b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif, 37036b4cac81SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_vif *, 37046b4cac81SBjoern A. Zeeb struct ieee80211_sta *, struct ieee80211_key_conf *, void *), 37056b4cac81SBjoern A. Zeeb void *arg) 37066b4cac81SBjoern A. Zeeb { 37076b4cac81SBjoern A. Zeeb 37086b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 37096b4cac81SBjoern A. Zeeb } 37106b4cac81SBjoern A. Zeeb 37116b4cac81SBjoern A. Zeeb void 37126b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_chan_contexts(struct ieee80211_hw *hw, 37136b4cac81SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_chanctx_conf *, 37146b4cac81SBjoern A. Zeeb void *), 37156b4cac81SBjoern A. Zeeb void *arg) 37166b4cac81SBjoern A. Zeeb { 37176b4cac81SBjoern A. Zeeb 37186b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 37196b4cac81SBjoern A. Zeeb } 37206b4cac81SBjoern A. Zeeb 37216b4cac81SBjoern A. Zeeb void 37226b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_stations_atomic(struct ieee80211_hw *hw, 37236b4cac81SBjoern A. Zeeb void (*iterfunc)(void *, struct ieee80211_sta *), void *arg) 37246b4cac81SBjoern A. Zeeb { 37256b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 37266b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 37276b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 37286b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 37296b4cac81SBjoern A. Zeeb 37306b4cac81SBjoern A. Zeeb KASSERT(hw != NULL && iterfunc != NULL, 37316b4cac81SBjoern A. Zeeb ("%s: hw %p iterfunc %p arg %p\n", __func__, hw, iterfunc, arg)); 37326b4cac81SBjoern A. Zeeb 37336b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 37346b4cac81SBjoern A. Zeeb 37358891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 37366b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 37376b4cac81SBjoern A. Zeeb 37386b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 37396b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lsta, &lvif->lsta_head, lsta_entry) { 37406b4cac81SBjoern A. Zeeb if (!lsta->added_to_drv) 37416b4cac81SBjoern A. Zeeb continue; 37426b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 37436b4cac81SBjoern A. Zeeb iterfunc(arg, sta); 37446b4cac81SBjoern A. Zeeb } 37456b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 37466b4cac81SBjoern A. Zeeb } 37478891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 37486b4cac81SBjoern A. Zeeb } 37496b4cac81SBjoern A. Zeeb 37506b4cac81SBjoern A. Zeeb int 37516b4cac81SBjoern A. Zeeb linuxkpi_regulatory_set_wiphy_regd_sync(struct wiphy *wiphy, 37526b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_regdomain *regd) 37536b4cac81SBjoern A. Zeeb { 37546b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 37556b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 37566b4cac81SBjoern A. Zeeb struct ieee80211_regdomain *rd; 37576b4cac81SBjoern A. Zeeb 37586b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 37596b4cac81SBjoern A. Zeeb ic = lhw->ic; 37606b4cac81SBjoern A. Zeeb 37616b4cac81SBjoern A. Zeeb rd = &ic->ic_regdomain; 37626b4cac81SBjoern A. Zeeb if (rd->isocc[0] == '\0') { 37636b4cac81SBjoern A. Zeeb rd->isocc[0] = regd->alpha2[0]; 37646b4cac81SBjoern A. Zeeb rd->isocc[1] = regd->alpha2[1]; 37656b4cac81SBjoern A. Zeeb } 37666b4cac81SBjoern A. Zeeb 37676b4cac81SBjoern A. Zeeb TODO(); 37686b4cac81SBjoern A. Zeeb /* XXX-BZ finish the rest. */ 37696b4cac81SBjoern A. Zeeb 37706b4cac81SBjoern A. Zeeb return (0); 37716b4cac81SBjoern A. Zeeb } 37726b4cac81SBjoern A. Zeeb 37736b4cac81SBjoern A. Zeeb void 37746b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_scan_completed(struct ieee80211_hw *hw, 37756b4cac81SBjoern A. Zeeb struct cfg80211_scan_info *info) 37766b4cac81SBjoern A. Zeeb { 37776b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 37786b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 37796b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 37806b4cac81SBjoern A. Zeeb 37816b4cac81SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 37826b4cac81SBjoern A. Zeeb ic = lhw->ic; 37836b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 37846b4cac81SBjoern A. Zeeb 37856b4cac81SBjoern A. Zeeb ieee80211_scan_done(ss->ss_vap); 37866b4cac81SBjoern A. Zeeb 37876b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 37886b4cac81SBjoern A. Zeeb free(lhw->hw_req, M_LKPI80211); 37896b4cac81SBjoern A. Zeeb lhw->hw_req = NULL; 3790a486fbbdSBjoern A. Zeeb lhw->scan_flags &= ~LKPI_LHW_SCAN_RUNNING; 37916b4cac81SBjoern A. Zeeb wakeup(lhw); 37926b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 37936b4cac81SBjoern A. Zeeb 37946b4cac81SBjoern A. Zeeb return; 37956b4cac81SBjoern A. Zeeb } 37966b4cac81SBjoern A. Zeeb 37976b4cac81SBjoern A. Zeeb void 37986b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb, 37996b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta, struct napi_struct *napi __unused) 38006b4cac81SBjoern A. Zeeb { 38016b4cac81SBjoern A. Zeeb struct epoch_tracker et; 38026b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 38036b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 38046b4cac81SBjoern A. Zeeb struct mbuf *m; 38056b4cac81SBjoern A. Zeeb struct skb_shared_info *shinfo; 38066b4cac81SBjoern A. Zeeb struct ieee80211_rx_status *rx_status; 38076b4cac81SBjoern A. Zeeb struct ieee80211_rx_stats rx_stats; 38086b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 38096b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 38106b4cac81SBjoern A. Zeeb struct ieee80211_hdr *hdr; 38116b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 38129d9ba2b7SBjoern A. Zeeb int i, offset, ok; 3813170acccfSBjoern A. Zeeb int8_t rssi; 3814c0cadd99SBjoern A. Zeeb bool is_beacon; 38156b4cac81SBjoern A. Zeeb 38166b4cac81SBjoern A. Zeeb if (skb->len < 2) { 38176b4cac81SBjoern A. Zeeb /* Need 80211 stats here. */ 38186b4cac81SBjoern A. Zeeb IMPROVE(); 38196b4cac81SBjoern A. Zeeb goto err; 38206b4cac81SBjoern A. Zeeb } 38216b4cac81SBjoern A. Zeeb 38226b4cac81SBjoern A. Zeeb /* 38236b4cac81SBjoern A. Zeeb * For now do the data copy; we can later improve things. Might even 38246b4cac81SBjoern A. Zeeb * have an mbuf backing the skb data then? 38256b4cac81SBjoern A. Zeeb */ 38266b4cac81SBjoern A. Zeeb m = m_get2(skb->len, M_NOWAIT, MT_DATA, M_PKTHDR); 38276b4cac81SBjoern A. Zeeb if (m == NULL) 38286b4cac81SBjoern A. Zeeb goto err; 38296b4cac81SBjoern A. Zeeb m_copyback(m, 0, skb->tail - skb->data, skb->data); 38306b4cac81SBjoern A. Zeeb 38316b4cac81SBjoern A. Zeeb shinfo = skb_shinfo(skb); 38326b4cac81SBjoern A. Zeeb offset = m->m_len; 38336b4cac81SBjoern A. Zeeb for (i = 0; i < shinfo->nr_frags; i++) { 38346b4cac81SBjoern A. Zeeb m_copyback(m, offset, shinfo->frags[i].size, 38356b4cac81SBjoern A. Zeeb (uint8_t *)linux_page_address(shinfo->frags[i].page) + 38366b4cac81SBjoern A. Zeeb shinfo->frags[i].offset); 38376b4cac81SBjoern A. Zeeb offset += shinfo->frags[i].size; 38386b4cac81SBjoern A. Zeeb } 38396b4cac81SBjoern A. Zeeb 38406b4cac81SBjoern A. Zeeb rx_status = IEEE80211_SKB_RXCB(skb); 38416b4cac81SBjoern A. Zeeb 38426b4cac81SBjoern A. Zeeb hdr = (void *)skb->data; 3843c0cadd99SBjoern A. Zeeb is_beacon = ieee80211_is_beacon(hdr->frame_control); 3844c0cadd99SBjoern A. Zeeb 3845c0cadd99SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 38469d9ba2b7SBjoern A. Zeeb if (is_beacon && (linuxkpi_debug_80211 & D80211_TRACE_RX_BEACONS) == 0) 38476b4cac81SBjoern A. Zeeb goto no_trace_beacons; 38486b4cac81SBjoern A. Zeeb 38499d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 38506b4cac81SBjoern A. Zeeb printf("TRACE-RX: %s: skb %p a/l/d/t-len (%u/%u/%u/%u) " 3851c0cadd99SBjoern A. Zeeb "h %p d %p t %p e %p sh %p (%u) m %p plen %u len %u%s\n", 38526b4cac81SBjoern A. Zeeb __func__, skb, skb->_alloc_len, skb->len, skb->data_len, 38536b4cac81SBjoern A. Zeeb skb->truesize, skb->head, skb->data, skb->tail, skb->end, 38546b4cac81SBjoern A. Zeeb shinfo, shinfo->nr_frags, 3855c0cadd99SBjoern A. Zeeb m, m->m_pkthdr.len, m->m_len, is_beacon ? " beacon" : ""); 38566b4cac81SBjoern A. Zeeb 38579d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX_DUMP) 38586b4cac81SBjoern A. Zeeb hexdump(mtod(m, const void *), m->m_len, "RX (raw) ", 0); 38596b4cac81SBjoern A. Zeeb 38606b4cac81SBjoern A. Zeeb /* Implement a dump_rxcb() !!! */ 38619d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 3862c8dafefaSBjoern A. Zeeb printf("TRACE %s: RXCB: %ju %ju %u, %#0x, %u, %#0x, %#0x, " 386360970a32SBjoern A. Zeeb "%u band %u, %u { %d %d %d %d }, %d, %#x %#x %#x %#x %u %u %u\n", 38646b4cac81SBjoern A. Zeeb __func__, 3865c8dafefaSBjoern A. Zeeb (uintmax_t)rx_status->boottime_ns, 3866c8dafefaSBjoern A. Zeeb (uintmax_t)rx_status->mactime, 38676b4cac81SBjoern A. Zeeb rx_status->device_timestamp, 38686b4cac81SBjoern A. Zeeb rx_status->flag, 38696b4cac81SBjoern A. Zeeb rx_status->freq, 38706b4cac81SBjoern A. Zeeb rx_status->bw, 38716b4cac81SBjoern A. Zeeb rx_status->encoding, 38726b4cac81SBjoern A. Zeeb rx_status->ampdu_reference, 38736b4cac81SBjoern A. Zeeb rx_status->band, 38746b4cac81SBjoern A. Zeeb rx_status->chains, 38756b4cac81SBjoern A. Zeeb rx_status->chain_signal[0], 38766b4cac81SBjoern A. Zeeb rx_status->chain_signal[1], 38776b4cac81SBjoern A. Zeeb rx_status->chain_signal[2], 387860970a32SBjoern A. Zeeb rx_status->chain_signal[3], 38796b4cac81SBjoern A. Zeeb rx_status->signal, 38806b4cac81SBjoern A. Zeeb rx_status->enc_flags, 38816b4cac81SBjoern A. Zeeb rx_status->he_dcm, 38826b4cac81SBjoern A. Zeeb rx_status->he_gi, 38836b4cac81SBjoern A. Zeeb rx_status->he_ru, 38846b4cac81SBjoern A. Zeeb rx_status->zero_length_psdu_type, 38856b4cac81SBjoern A. Zeeb rx_status->nss, 38866b4cac81SBjoern A. Zeeb rx_status->rate_idx); 38876b4cac81SBjoern A. Zeeb no_trace_beacons: 38886b4cac81SBjoern A. Zeeb #endif 38896b4cac81SBjoern A. Zeeb 38906b4cac81SBjoern A. Zeeb memset(&rx_stats, 0, sizeof(rx_stats)); 38916b4cac81SBjoern A. Zeeb rx_stats.r_flags = IEEE80211_R_NF | IEEE80211_R_RSSI; 389260970a32SBjoern A. Zeeb /* XXX-BZ correct hardcoded rssi and noise floor, how? survey? */ 389360970a32SBjoern A. Zeeb rx_stats.c_nf = -96; 38946b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, SIGNAL_DBM) && 38956b4cac81SBjoern A. Zeeb !(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL)) 3896170acccfSBjoern A. Zeeb rssi = rx_status->signal; 38976b4cac81SBjoern A. Zeeb else 3898170acccfSBjoern A. Zeeb rssi = rx_stats.c_nf; 3899170acccfSBjoern A. Zeeb /* 3900170acccfSBjoern A. Zeeb * net80211 signal strength data are in .5 dBm units relative to 3901170acccfSBjoern A. Zeeb * the current noise floor (see comment in ieee80211_node.h). 3902170acccfSBjoern A. Zeeb */ 3903170acccfSBjoern A. Zeeb rssi -= rx_stats.c_nf; 3904170acccfSBjoern A. Zeeb rx_stats.c_rssi = rssi * 2; 39056b4cac81SBjoern A. Zeeb rx_stats.r_flags |= IEEE80211_R_BAND; 39066b4cac81SBjoern A. Zeeb rx_stats.c_band = 39076b4cac81SBjoern A. Zeeb lkpi_nl80211_band_to_net80211_band(rx_status->band); 39086b4cac81SBjoern A. Zeeb rx_stats.r_flags |= IEEE80211_R_FREQ | IEEE80211_R_IEEE; 39096b4cac81SBjoern A. Zeeb rx_stats.c_freq = rx_status->freq; 39106b4cac81SBjoern A. Zeeb rx_stats.c_ieee = ieee80211_mhz2ieee(rx_stats.c_freq, rx_stats.c_band); 39116b4cac81SBjoern A. Zeeb 39126b4cac81SBjoern A. Zeeb /* XXX (*sta_statistics)() to get to some of that? */ 39136b4cac81SBjoern A. Zeeb /* XXX-BZ dump the FreeBSD version of rx_stats as well! */ 39146b4cac81SBjoern A. Zeeb 39156b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 39166b4cac81SBjoern A. Zeeb ic = lhw->ic; 39176b4cac81SBjoern A. Zeeb 39186b4cac81SBjoern A. Zeeb ok = ieee80211_add_rx_params(m, &rx_stats); 39196b4cac81SBjoern A. Zeeb if (ok == 0) { 3920dbc06dd9SBjoern A. Zeeb m_freem(m); 39216b4cac81SBjoern A. Zeeb counter_u64_add(ic->ic_ierrors, 1); 39226b4cac81SBjoern A. Zeeb goto err; 39236b4cac81SBjoern A. Zeeb } 39246b4cac81SBjoern A. Zeeb 39256b4cac81SBjoern A. Zeeb if (sta != NULL) { 39266b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 39276b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(lsta->ni); 39286b4cac81SBjoern A. Zeeb } else { 3929c8dafefaSBjoern A. Zeeb struct ieee80211_frame_min *wh; 3930c8dafefaSBjoern A. Zeeb 39316b4cac81SBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame_min *); 39326b4cac81SBjoern A. Zeeb ni = ieee80211_find_rxnode(ic, wh); 39336b4cac81SBjoern A. Zeeb if (ni != NULL) 39346b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 39356b4cac81SBjoern A. Zeeb } 39366b4cac81SBjoern A. Zeeb 39376b4cac81SBjoern A. Zeeb if (ni != NULL) 39386b4cac81SBjoern A. Zeeb vap = ni->ni_vap; 39396b4cac81SBjoern A. Zeeb else 39406b4cac81SBjoern A. Zeeb /* 39416b4cac81SBjoern A. Zeeb * XXX-BZ can we improve this by looking at the frame hdr 39426b4cac81SBjoern A. Zeeb * or other meta-data passed up? 39436b4cac81SBjoern A. Zeeb */ 39446b4cac81SBjoern A. Zeeb vap = TAILQ_FIRST(&ic->ic_vaps); 39456b4cac81SBjoern A. Zeeb 39469d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 39479d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 3948c0cadd99SBjoern A. Zeeb printf("TRACE %s: sta %p lsta %p state %d ni %p vap %p%s\n", 3949c0cadd99SBjoern A. Zeeb __func__, sta, lsta, (lsta != NULL) ? lsta->state : -1, 3950c0cadd99SBjoern A. Zeeb ni, vap, is_beacon ? " beacon" : ""); 39519d9ba2b7SBjoern A. Zeeb #endif 39526b4cac81SBjoern A. Zeeb 3953c0cadd99SBjoern A. Zeeb if (ni != NULL && vap != NULL && is_beacon && 3954c8dafefaSBjoern A. Zeeb rx_status->device_timestamp > 0 && 3955c8dafefaSBjoern A. Zeeb m->m_pkthdr.len >= sizeof(struct ieee80211_frame)) { 3956c8dafefaSBjoern A. Zeeb struct lkpi_vif *lvif; 3957c8dafefaSBjoern A. Zeeb struct ieee80211_vif *vif; 3958c8dafefaSBjoern A. Zeeb struct ieee80211_frame *wh; 3959c8dafefaSBjoern A. Zeeb 3960c8dafefaSBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame *); 3961c8dafefaSBjoern A. Zeeb if (!IEEE80211_ADDR_EQ(wh->i_addr2, ni->ni_bssid)) 3962c8dafefaSBjoern A. Zeeb goto skip_device_ts; 3963c8dafefaSBjoern A. Zeeb 3964c8dafefaSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 3965c8dafefaSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 3966c8dafefaSBjoern A. Zeeb 3967c8dafefaSBjoern A. Zeeb IMPROVE("TIMING_BEACON_ONLY?"); 3968c8dafefaSBjoern A. Zeeb /* mac80211 specific (not net80211) so keep it here. */ 3969c8dafefaSBjoern A. Zeeb vif->bss_conf.sync_device_ts = rx_status->device_timestamp; 3970c8dafefaSBjoern A. Zeeb /* 3971c8dafefaSBjoern A. Zeeb * net80211 should take care of the other information (sync_tsf, 3972c8dafefaSBjoern A. Zeeb * sync_dtim_count) as otherwise we need to parse the beacon. 3973c8dafefaSBjoern A. Zeeb */ 3974c8dafefaSBjoern A. Zeeb } 3975c8dafefaSBjoern A. Zeeb skip_device_ts: 3976c8dafefaSBjoern A. Zeeb 39776b4cac81SBjoern A. Zeeb if (vap != NULL && vap->iv_state > IEEE80211_S_INIT && 39786b4cac81SBjoern A. Zeeb ieee80211_radiotap_active_vap(vap)) { 39796b4cac81SBjoern A. Zeeb struct lkpi_radiotap_rx_hdr *rtap; 39806b4cac81SBjoern A. Zeeb 39816b4cac81SBjoern A. Zeeb rtap = &lhw->rtap_rx; 39826b4cac81SBjoern A. Zeeb rtap->wr_tsft = rx_status->device_timestamp; 39836b4cac81SBjoern A. Zeeb rtap->wr_flags = 0; 39846b4cac81SBjoern A. Zeeb if (rx_status->enc_flags & RX_ENC_FLAG_SHORTPRE) 39856b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; 39866b4cac81SBjoern A. Zeeb if (rx_status->enc_flags & RX_ENC_FLAG_SHORT_GI) 39876b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTGI; 39886b4cac81SBjoern A. Zeeb #if 0 /* .. or it does not given we strip it below. */ 39896b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, RX_INCLUDES_FCS)) 39906b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_FCS; 39916b4cac81SBjoern A. Zeeb #endif 39926b4cac81SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_FAILED_FCS_CRC) 39936b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_BADFCS; 39946b4cac81SBjoern A. Zeeb rtap->wr_rate = 0; 39956b4cac81SBjoern A. Zeeb IMPROVE(); 39966b4cac81SBjoern A. Zeeb /* XXX TODO status->encoding / rate_index / bw */ 39976b4cac81SBjoern A. Zeeb rtap->wr_chan_freq = htole16(rx_stats.c_freq); 39986b4cac81SBjoern A. Zeeb if (ic->ic_curchan->ic_ieee == rx_stats.c_ieee) 39996b4cac81SBjoern A. Zeeb rtap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags); 4000170acccfSBjoern A. Zeeb rtap->wr_dbm_antsignal = rssi; 40016b4cac81SBjoern A. Zeeb rtap->wr_dbm_antnoise = rx_stats.c_nf; 40026b4cac81SBjoern A. Zeeb } 40036b4cac81SBjoern A. Zeeb 40046b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, RX_INCLUDES_FCS)) 40056b4cac81SBjoern A. Zeeb m_adj(m, -IEEE80211_CRC_LEN); 40066b4cac81SBjoern A. Zeeb 40076b4cac81SBjoern A. Zeeb NET_EPOCH_ENTER(et); 40086b4cac81SBjoern A. Zeeb if (ni != NULL) { 40099d9ba2b7SBjoern A. Zeeb ok = ieee80211_input_mimo(ni, m); 40106b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 4011dbc06dd9SBjoern A. Zeeb if (ok < 0) 4012dbc06dd9SBjoern A. Zeeb m_freem(m); 40136b4cac81SBjoern A. Zeeb } else { 40149d9ba2b7SBjoern A. Zeeb ok = ieee80211_input_mimo_all(ic, m); 4015dbc06dd9SBjoern A. Zeeb /* mbuf got consumed. */ 40166b4cac81SBjoern A. Zeeb } 40176b4cac81SBjoern A. Zeeb NET_EPOCH_EXIT(et); 40186b4cac81SBjoern A. Zeeb 40199d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 40209d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 40219d9ba2b7SBjoern A. Zeeb printf("TRACE %s: handled frame type %#0x\n", __func__, ok); 40229d9ba2b7SBjoern A. Zeeb #endif 40236b4cac81SBjoern A. Zeeb 40246b4cac81SBjoern A. Zeeb IMPROVE(); 40256b4cac81SBjoern A. Zeeb 40266b4cac81SBjoern A. Zeeb err: 40276b4cac81SBjoern A. Zeeb /* The skb is ours so we can free it :-) */ 40286b4cac81SBjoern A. Zeeb kfree_skb(skb); 40296b4cac81SBjoern A. Zeeb } 40306b4cac81SBjoern A. Zeeb 40316b4cac81SBjoern A. Zeeb uint8_t 4032ec190d91SBjoern A. Zeeb linuxkpi_ieee80211_get_tid(struct ieee80211_hdr *hdr, bool nonqos_ok) 40336b4cac81SBjoern A. Zeeb { 40346b4cac81SBjoern A. Zeeb const struct ieee80211_frame *wh; 4035ec190d91SBjoern A. Zeeb uint8_t tid; 4036ec190d91SBjoern A. Zeeb 4037ec190d91SBjoern A. Zeeb /* Linux seems to assume this is a QOS-Data-Frame */ 4038ec190d91SBjoern A. Zeeb KASSERT(nonqos_ok || ieee80211_is_data_qos(hdr->frame_control), 4039ec190d91SBjoern A. Zeeb ("%s: hdr %p fc %#06x not qos_data\n", __func__, hdr, 4040ec190d91SBjoern A. Zeeb hdr->frame_control)); 40416b4cac81SBjoern A. Zeeb 40426b4cac81SBjoern A. Zeeb wh = (const struct ieee80211_frame *)hdr; 4043ec190d91SBjoern A. Zeeb tid = ieee80211_gettid(wh); 4044ec190d91SBjoern A. Zeeb KASSERT(nonqos_ok || tid == (tid & IEEE80211_QOS_TID), ("%s: tid %u " 4045ec190d91SBjoern A. Zeeb "not expected (%u?)\n", __func__, tid, IEEE80211_NONQOS_TID)); 4046ec190d91SBjoern A. Zeeb 4047ec190d91SBjoern A. Zeeb return (tid); 40486b4cac81SBjoern A. Zeeb } 40496b4cac81SBjoern A. Zeeb 40506b4cac81SBjoern A. Zeeb struct wiphy * 40516b4cac81SBjoern A. Zeeb linuxkpi_wiphy_new(const struct cfg80211_ops *ops, size_t priv_len) 40526b4cac81SBjoern A. Zeeb { 40536b4cac81SBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 40546b4cac81SBjoern A. Zeeb 40556b4cac81SBjoern A. Zeeb lwiphy = kzalloc(sizeof(*lwiphy) + priv_len, GFP_KERNEL); 40566b4cac81SBjoern A. Zeeb if (lwiphy == NULL) 40576b4cac81SBjoern A. Zeeb return (NULL); 40586b4cac81SBjoern A. Zeeb lwiphy->ops = ops; 40596b4cac81SBjoern A. Zeeb 40606b4cac81SBjoern A. Zeeb /* XXX TODO */ 40616b4cac81SBjoern A. Zeeb return (LWIPHY_TO_WIPHY(lwiphy)); 40626b4cac81SBjoern A. Zeeb } 40636b4cac81SBjoern A. Zeeb 40646b4cac81SBjoern A. Zeeb void 40656b4cac81SBjoern A. Zeeb linuxkpi_wiphy_free(struct wiphy *wiphy) 40666b4cac81SBjoern A. Zeeb { 40676b4cac81SBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 40686b4cac81SBjoern A. Zeeb 40696b4cac81SBjoern A. Zeeb if (wiphy == NULL) 40706b4cac81SBjoern A. Zeeb return; 40716b4cac81SBjoern A. Zeeb 40726b4cac81SBjoern A. Zeeb lwiphy = WIPHY_TO_LWIPHY(wiphy); 40736b4cac81SBjoern A. Zeeb kfree(lwiphy); 40746b4cac81SBjoern A. Zeeb } 40756b4cac81SBjoern A. Zeeb 40766b4cac81SBjoern A. Zeeb uint32_t 40776b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_channel_to_frequency(uint32_t channel, 40786b4cac81SBjoern A. Zeeb enum nl80211_band band) 40796b4cac81SBjoern A. Zeeb { 40806b4cac81SBjoern A. Zeeb 40816b4cac81SBjoern A. Zeeb switch (band) { 40826b4cac81SBjoern A. Zeeb case NL80211_BAND_2GHZ: 40836b4cac81SBjoern A. Zeeb return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_2GHZ)); 40846b4cac81SBjoern A. Zeeb break; 40856b4cac81SBjoern A. Zeeb case NL80211_BAND_5GHZ: 40866b4cac81SBjoern A. Zeeb return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_5GHZ)); 40876b4cac81SBjoern A. Zeeb break; 40886b4cac81SBjoern A. Zeeb default: 40896b4cac81SBjoern A. Zeeb /* XXX abort, retry, error, panic? */ 40906b4cac81SBjoern A. Zeeb break; 40916b4cac81SBjoern A. Zeeb } 40926b4cac81SBjoern A. Zeeb 40936b4cac81SBjoern A. Zeeb return (0); 40946b4cac81SBjoern A. Zeeb } 40956b4cac81SBjoern A. Zeeb 40966b4cac81SBjoern A. Zeeb uint32_t 40976b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_frequency_to_channel(uint32_t freq, uint32_t flags __unused) 40986b4cac81SBjoern A. Zeeb { 40996b4cac81SBjoern A. Zeeb 41006b4cac81SBjoern A. Zeeb return (ieee80211_mhz2ieee(freq, 0)); 41016b4cac81SBjoern A. Zeeb } 41026b4cac81SBjoern A. Zeeb 41036b4cac81SBjoern A. Zeeb static struct lkpi_sta * 41046b4cac81SBjoern A. Zeeb lkpi_find_lsta_by_ni(struct lkpi_vif *lvif, struct ieee80211_node *ni) 41056b4cac81SBjoern A. Zeeb { 41066b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta, *temp; 41076b4cac81SBjoern A. Zeeb 41086b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 41096b4cac81SBjoern A. Zeeb TAILQ_FOREACH_SAFE(lsta, &lvif->lsta_head, lsta_entry, temp) { 41106b4cac81SBjoern A. Zeeb if (lsta->ni == ni) { 41116b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 41126b4cac81SBjoern A. Zeeb return (lsta); 41136b4cac81SBjoern A. Zeeb } 41146b4cac81SBjoern A. Zeeb } 41156b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 41166b4cac81SBjoern A. Zeeb 41176b4cac81SBjoern A. Zeeb return (NULL); 41186b4cac81SBjoern A. Zeeb } 41196b4cac81SBjoern A. Zeeb 41206b4cac81SBjoern A. Zeeb struct ieee80211_sta * 41216b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_find_sta(struct ieee80211_vif *vif, const u8 *peer) 41226b4cac81SBjoern A. Zeeb { 41236b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 41246b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta, *temp; 41256b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 41266b4cac81SBjoern A. Zeeb 41276b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 41286b4cac81SBjoern A. Zeeb 41296b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 41306b4cac81SBjoern A. Zeeb TAILQ_FOREACH_SAFE(lsta, &lvif->lsta_head, lsta_entry, temp) { 41316b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 41326b4cac81SBjoern A. Zeeb if (IEEE80211_ADDR_EQ(sta->addr, peer)) { 41336b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 41346b4cac81SBjoern A. Zeeb return (sta); 41356b4cac81SBjoern A. Zeeb } 41366b4cac81SBjoern A. Zeeb } 41376b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 41386b4cac81SBjoern A. Zeeb return (NULL); 41396b4cac81SBjoern A. Zeeb } 41406b4cac81SBjoern A. Zeeb 41416b4cac81SBjoern A. Zeeb struct ieee80211_sta * 41422e183d99SBjoern A. Zeeb linuxkpi_ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw, 41432e183d99SBjoern A. Zeeb const uint8_t *addr, const uint8_t *ourvifaddr) 41446b4cac81SBjoern A. Zeeb { 41456b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 41466b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 41476b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 41486b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 41496b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 41506b4cac81SBjoern A. Zeeb 41516b4cac81SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 41526b4cac81SBjoern A. Zeeb sta = NULL; 41536b4cac81SBjoern A. Zeeb 41548891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 41556b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 41566b4cac81SBjoern A. Zeeb 41576b4cac81SBjoern A. Zeeb /* XXX-BZ check our address from the vif. */ 41586b4cac81SBjoern A. Zeeb 41596b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 41606b4cac81SBjoern A. Zeeb if (ourvifaddr != NULL && 41616b4cac81SBjoern A. Zeeb !IEEE80211_ADDR_EQ(vif->addr, ourvifaddr)) 41626b4cac81SBjoern A. Zeeb continue; 41636b4cac81SBjoern A. Zeeb sta = linuxkpi_ieee80211_find_sta(vif, addr); 41646b4cac81SBjoern A. Zeeb if (sta != NULL) 41656b4cac81SBjoern A. Zeeb break; 41666b4cac81SBjoern A. Zeeb } 41678891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 41686b4cac81SBjoern A. Zeeb 41696b4cac81SBjoern A. Zeeb if (sta != NULL) { 41706b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 41716b4cac81SBjoern A. Zeeb if (!lsta->added_to_drv) 41726b4cac81SBjoern A. Zeeb return (NULL); 41736b4cac81SBjoern A. Zeeb } 41746b4cac81SBjoern A. Zeeb 41756b4cac81SBjoern A. Zeeb return (sta); 41766b4cac81SBjoern A. Zeeb } 41776b4cac81SBjoern A. Zeeb 41786b4cac81SBjoern A. Zeeb struct sk_buff * 41796b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_tx_dequeue(struct ieee80211_hw *hw, 41806b4cac81SBjoern A. Zeeb struct ieee80211_txq *txq) 41816b4cac81SBjoern A. Zeeb { 41826b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 41836b4cac81SBjoern A. Zeeb struct sk_buff *skb; 41846b4cac81SBjoern A. Zeeb 41856b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 41866b4cac81SBjoern A. Zeeb ltxq->seen_dequeue = true; 41876b4cac81SBjoern A. Zeeb 41886b4cac81SBjoern A. Zeeb skb = skb_dequeue(<xq->skbq); 41896b4cac81SBjoern A. Zeeb 41906b4cac81SBjoern A. Zeeb return (skb); 41916b4cac81SBjoern A. Zeeb } 41926b4cac81SBjoern A. Zeeb 41936b4cac81SBjoern A. Zeeb void 41946b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_txq_get_depth(struct ieee80211_txq *txq, 419586220d3cSBjoern A. Zeeb unsigned long *frame_cnt, unsigned long *byte_cnt) 41966b4cac81SBjoern A. Zeeb { 41976b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 41986b4cac81SBjoern A. Zeeb struct sk_buff *skb; 419986220d3cSBjoern A. Zeeb unsigned long fc, bc; 42006b4cac81SBjoern A. Zeeb 42016b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 42026b4cac81SBjoern A. Zeeb 42036b4cac81SBjoern A. Zeeb fc = bc = 0; 42046b4cac81SBjoern A. Zeeb skb_queue_walk(<xq->skbq, skb) { 42056b4cac81SBjoern A. Zeeb fc++; 42066b4cac81SBjoern A. Zeeb bc += skb->len; 42076b4cac81SBjoern A. Zeeb } 42086b4cac81SBjoern A. Zeeb if (frame_cnt) 42096b4cac81SBjoern A. Zeeb *frame_cnt = fc; 42106b4cac81SBjoern A. Zeeb if (byte_cnt) 42116b4cac81SBjoern A. Zeeb *byte_cnt = bc; 42126b4cac81SBjoern A. Zeeb 42136b4cac81SBjoern A. Zeeb /* Validate that this is doing the correct thing. */ 42146b4cac81SBjoern A. Zeeb /* Should we keep track on en/dequeue? */ 42156b4cac81SBjoern A. Zeeb IMPROVE(); 42166b4cac81SBjoern A. Zeeb } 42176b4cac81SBjoern A. Zeeb 42186b4cac81SBjoern A. Zeeb /* 42196b4cac81SBjoern A. Zeeb * We are called from ieee80211_free_txskb() or ieee80211_tx_status(). 42206b4cac81SBjoern A. Zeeb * The latter tries to derive the success status from the info flags 42216b4cac81SBjoern A. Zeeb * passed back from the driver. rawx_mit() saves the ni on the m and the 42226b4cac81SBjoern A. Zeeb * m on the skb for us to be able to give feedback to net80211. 42236b4cac81SBjoern A. Zeeb */ 42246b4cac81SBjoern A. Zeeb void 42256b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb, 42266b4cac81SBjoern A. Zeeb int status) 42276b4cac81SBjoern A. Zeeb { 42286b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 42296b4cac81SBjoern A. Zeeb struct mbuf *m; 42306b4cac81SBjoern A. Zeeb 42316b4cac81SBjoern A. Zeeb m = skb->m; 42326b4cac81SBjoern A. Zeeb skb->m = NULL; 42336b4cac81SBjoern A. Zeeb 42346b4cac81SBjoern A. Zeeb if (m != NULL) { 42356b4cac81SBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 42366b4cac81SBjoern A. Zeeb /* Status: 0 is ok, != 0 is error. */ 42376b4cac81SBjoern A. Zeeb ieee80211_tx_complete(ni, m, status); 42386b4cac81SBjoern A. Zeeb /* ni & mbuf were consumed. */ 42396b4cac81SBjoern A. Zeeb } 42406b4cac81SBjoern A. Zeeb 42416b4cac81SBjoern A. Zeeb kfree_skb(skb); 42426b4cac81SBjoern A. Zeeb } 42436b4cac81SBjoern A. Zeeb 4244383b3e8fSBjoern A. Zeeb void 4245383b3e8fSBjoern A. Zeeb linuxkpi_ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb) 4246383b3e8fSBjoern A. Zeeb { 4247383b3e8fSBjoern A. Zeeb struct ieee80211_tx_info *info; 4248383b3e8fSBjoern A. Zeeb struct ieee80211_ratectl_tx_status txs; 4249383b3e8fSBjoern A. Zeeb struct ieee80211_node *ni; 4250383b3e8fSBjoern A. Zeeb int status; 4251383b3e8fSBjoern A. Zeeb 4252383b3e8fSBjoern A. Zeeb info = IEEE80211_SKB_CB(skb); 4253383b3e8fSBjoern A. Zeeb 4254383b3e8fSBjoern A. Zeeb if (skb->m != NULL) { 4255383b3e8fSBjoern A. Zeeb struct mbuf *m; 4256383b3e8fSBjoern A. Zeeb 4257383b3e8fSBjoern A. Zeeb m = skb->m; 4258383b3e8fSBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 4259383b3e8fSBjoern A. Zeeb memset(&txs, 0, sizeof(txs)); 4260383b3e8fSBjoern A. Zeeb } else { 4261383b3e8fSBjoern A. Zeeb ni = NULL; 4262383b3e8fSBjoern A. Zeeb } 4263383b3e8fSBjoern A. Zeeb 4264383b3e8fSBjoern A. Zeeb if (info->flags & IEEE80211_TX_STAT_ACK) { 4265383b3e8fSBjoern A. Zeeb status = 0; /* No error. */ 4266383b3e8fSBjoern A. Zeeb txs.status = IEEE80211_RATECTL_TX_SUCCESS; 4267383b3e8fSBjoern A. Zeeb } else { 4268383b3e8fSBjoern A. Zeeb status = 1; 4269383b3e8fSBjoern A. Zeeb txs.status = IEEE80211_RATECTL_TX_FAIL_UNSPECIFIED; 4270383b3e8fSBjoern A. Zeeb } 4271383b3e8fSBjoern A. Zeeb 4272383b3e8fSBjoern A. Zeeb if (ni != NULL) { 4273e2c5ab09SJohn Baldwin int ridx __unused; 4274383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 4275383b3e8fSBjoern A. Zeeb int old_rate; 4276383b3e8fSBjoern A. Zeeb 4277383b3e8fSBjoern A. Zeeb old_rate = ni->ni_vap->iv_bss->ni_txrate; 4278383b3e8fSBjoern A. Zeeb #endif 4279383b3e8fSBjoern A. Zeeb txs.pktlen = skb->len; 4280383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_PKTLEN; 4281383b3e8fSBjoern A. Zeeb if (info->status.rates[0].count > 1) { 4282383b3e8fSBjoern A. Zeeb txs.long_retries = info->status.rates[0].count - 1; /* 1 + retries in drivers. */ 4283383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_LONG_RETRY; 4284383b3e8fSBjoern A. Zeeb } 4285383b3e8fSBjoern A. Zeeb #if 0 /* Unused in net80211 currently. */ 4286383b3e8fSBjoern A. Zeeb /* XXX-BZ conver;t check .flags for MCS/VHT/.. */ 4287383b3e8fSBjoern A. Zeeb txs.final_rate = info->status.rates[0].idx; 4288383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_FINAL_RATE; 4289383b3e8fSBjoern A. Zeeb #endif 4290383b3e8fSBjoern A. Zeeb if (info->status.is_valid_ack_signal) { 4291383b3e8fSBjoern A. Zeeb txs.rssi = info->status.ack_signal; /* XXX-BZ CONVERT? */ 4292383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_RSSI; 4293383b3e8fSBjoern A. Zeeb } 4294383b3e8fSBjoern A. Zeeb 4295383b3e8fSBjoern A. Zeeb IMPROVE("only update of rate matches but that requires us to get a proper rate"); 4296383b3e8fSBjoern A. Zeeb ieee80211_ratectl_tx_complete(ni, &txs); 4297383b3e8fSBjoern A. Zeeb ridx = ieee80211_ratectl_rate(ni->ni_vap->iv_bss, NULL, 0); 4298383b3e8fSBjoern A. Zeeb 4299383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 4300383b3e8fSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) { 4301383b3e8fSBjoern A. Zeeb printf("TX-RATE: %s: old %d new %d ridx %d, " 4302383b3e8fSBjoern A. Zeeb "long_retries %d\n", __func__, 4303383b3e8fSBjoern A. Zeeb old_rate, ni->ni_vap->iv_bss->ni_txrate, 4304383b3e8fSBjoern A. Zeeb ridx, txs.long_retries); 4305383b3e8fSBjoern A. Zeeb } 4306383b3e8fSBjoern A. Zeeb #endif 4307383b3e8fSBjoern A. Zeeb } 4308383b3e8fSBjoern A. Zeeb 4309383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 4310383b3e8fSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 4311383b3e8fSBjoern A. Zeeb printf("TX-STATUS: %s: hw %p skb %p status %d : flags %#x " 4312383b3e8fSBjoern A. Zeeb "band %u hw_queue %u tx_time_est %d : " 4313383b3e8fSBjoern A. Zeeb "rates [ %u %u %#x, %u %u %#x, %u %u %#x, %u %u %#x ] " 4314383b3e8fSBjoern A. Zeeb "ack_signal %u ampdu_ack_len %u ampdu_len %u antenna %u " 4315383b3e8fSBjoern A. Zeeb "tx_time %u is_valid_ack_signal %u " 4316383b3e8fSBjoern A. Zeeb "status_driver_data [ %p %p ]\n", 4317383b3e8fSBjoern A. Zeeb __func__, hw, skb, status, info->flags, 4318383b3e8fSBjoern A. Zeeb info->band, info->hw_queue, info->tx_time_est, 4319383b3e8fSBjoern A. Zeeb info->status.rates[0].idx, info->status.rates[0].count, 4320383b3e8fSBjoern A. Zeeb info->status.rates[0].flags, 4321383b3e8fSBjoern A. Zeeb info->status.rates[1].idx, info->status.rates[1].count, 4322383b3e8fSBjoern A. Zeeb info->status.rates[1].flags, 4323383b3e8fSBjoern A. Zeeb info->status.rates[2].idx, info->status.rates[2].count, 4324383b3e8fSBjoern A. Zeeb info->status.rates[2].flags, 4325383b3e8fSBjoern A. Zeeb info->status.rates[3].idx, info->status.rates[3].count, 4326383b3e8fSBjoern A. Zeeb info->status.rates[3].flags, 4327383b3e8fSBjoern A. Zeeb info->status.ack_signal, info->status.ampdu_ack_len, 4328383b3e8fSBjoern A. Zeeb info->status.ampdu_len, info->status.antenna, 4329383b3e8fSBjoern A. Zeeb info->status.tx_time, info->status.is_valid_ack_signal, 4330383b3e8fSBjoern A. Zeeb info->status.status_driver_data[0], 4331383b3e8fSBjoern A. Zeeb info->status.status_driver_data[1]); 4332383b3e8fSBjoern A. Zeeb #endif 4333383b3e8fSBjoern A. Zeeb 4334383b3e8fSBjoern A. Zeeb linuxkpi_ieee80211_free_txskb(hw, skb, status); 4335383b3e8fSBjoern A. Zeeb } 4336383b3e8fSBjoern A. Zeeb 43376b4cac81SBjoern A. Zeeb /* 43386b4cac81SBjoern A. Zeeb * This is an internal bandaid for the moment for the way we glue 43396b4cac81SBjoern A. Zeeb * skbs and mbufs together for TX. Once we have skbs backed by 43406b4cac81SBjoern A. Zeeb * mbufs this should go away. 43416b4cac81SBjoern A. Zeeb * This is a public function but kept on the private KPI (lkpi_) 43426b4cac81SBjoern A. Zeeb * and is not exposed by a header file. 43436b4cac81SBjoern A. Zeeb */ 43446b4cac81SBjoern A. Zeeb static void 43456b4cac81SBjoern A. Zeeb lkpi_ieee80211_free_skb_mbuf(void *p) 43466b4cac81SBjoern A. Zeeb { 43476b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 43486b4cac81SBjoern A. Zeeb struct mbuf *m; 43496b4cac81SBjoern A. Zeeb 43506b4cac81SBjoern A. Zeeb if (p == NULL) 43516b4cac81SBjoern A. Zeeb return; 43526b4cac81SBjoern A. Zeeb 43536b4cac81SBjoern A. Zeeb m = (struct mbuf *)p; 43546b4cac81SBjoern A. Zeeb M_ASSERTPKTHDR(m); 43556b4cac81SBjoern A. Zeeb 43566b4cac81SBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 43576b4cac81SBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = NULL; 43586b4cac81SBjoern A. Zeeb if (ni != NULL) 43596b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 43606b4cac81SBjoern A. Zeeb m_freem(m); 43616b4cac81SBjoern A. Zeeb } 43626b4cac81SBjoern A. Zeeb 43636b4cac81SBjoern A. Zeeb void 43646b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_queue_delayed_work(struct ieee80211_hw *hw, 43656b4cac81SBjoern A. Zeeb struct delayed_work *w, int delay) 43666b4cac81SBjoern A. Zeeb { 43676b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 43686b4cac81SBjoern A. Zeeb 43696b4cac81SBjoern A. Zeeb /* Need to make sure hw is in a stable (non-suspended) state. */ 43706b4cac81SBjoern A. Zeeb IMPROVE(); 43716b4cac81SBjoern A. Zeeb 43726b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 43736b4cac81SBjoern A. Zeeb queue_delayed_work(lhw->workq, w, delay); 43746b4cac81SBjoern A. Zeeb } 43756b4cac81SBjoern A. Zeeb 43766b4cac81SBjoern A. Zeeb void 43776b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_queue_work(struct ieee80211_hw *hw, 43786b4cac81SBjoern A. Zeeb struct work_struct *w) 43796b4cac81SBjoern A. Zeeb { 43806b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 43816b4cac81SBjoern A. Zeeb 43826b4cac81SBjoern A. Zeeb /* Need to make sure hw is in a stable (non-suspended) state. */ 43836b4cac81SBjoern A. Zeeb IMPROVE(); 43846b4cac81SBjoern A. Zeeb 43856b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 43866b4cac81SBjoern A. Zeeb queue_work(lhw->workq, w); 43876b4cac81SBjoern A. Zeeb } 43886b4cac81SBjoern A. Zeeb 43896b4cac81SBjoern A. Zeeb struct sk_buff * 4390ade774b1SBjoern A. Zeeb linuxkpi_ieee80211_probereq_get(struct ieee80211_hw *hw, uint8_t *addr, 4391ade774b1SBjoern A. Zeeb uint8_t *ssid, size_t ssid_len, size_t tailroom) 4392ade774b1SBjoern A. Zeeb { 4393ade774b1SBjoern A. Zeeb struct sk_buff *skb; 4394ade774b1SBjoern A. Zeeb struct ieee80211_frame *wh; 4395ade774b1SBjoern A. Zeeb uint8_t *p; 4396ade774b1SBjoern A. Zeeb size_t len; 4397ade774b1SBjoern A. Zeeb 4398ade774b1SBjoern A. Zeeb len = sizeof(*wh); 4399ade774b1SBjoern A. Zeeb len += 2 + ssid_len; 4400ade774b1SBjoern A. Zeeb 4401ade774b1SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + len + tailroom); 4402ade774b1SBjoern A. Zeeb if (skb == NULL) 4403ade774b1SBjoern A. Zeeb return (NULL); 4404ade774b1SBjoern A. Zeeb 4405ade774b1SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 4406ade774b1SBjoern A. Zeeb 4407ade774b1SBjoern A. Zeeb wh = skb_put_zero(skb, sizeof(*wh)); 4408ade774b1SBjoern A. Zeeb wh->i_fc[0] = IEEE80211_FC0_VERSION_0; 4409ade774b1SBjoern A. Zeeb wh->i_fc[0] |= IEEE80211_FC0_SUBTYPE_PROBE_REQ | IEEE80211_FC0_TYPE_MGT; 4410ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr1, ieee80211broadcastaddr); 4411ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr2, addr); 4412ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr3, ieee80211broadcastaddr); 4413ade774b1SBjoern A. Zeeb 4414ade774b1SBjoern A. Zeeb p = skb_put(skb, 2 + ssid_len); 4415ade774b1SBjoern A. Zeeb *p++ = IEEE80211_ELEMID_SSID; 4416ade774b1SBjoern A. Zeeb *p++ = ssid_len; 4417ade774b1SBjoern A. Zeeb if (ssid_len > 0) 4418ade774b1SBjoern A. Zeeb memcpy(p, ssid, ssid_len); 4419ade774b1SBjoern A. Zeeb 4420ade774b1SBjoern A. Zeeb return (skb); 4421ade774b1SBjoern A. Zeeb } 4422ade774b1SBjoern A. Zeeb 4423ade774b1SBjoern A. Zeeb struct sk_buff * 44246b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_pspoll_get(struct ieee80211_hw *hw, 44256b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif) 44266b4cac81SBjoern A. Zeeb { 44276b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 44286b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 44296b4cac81SBjoern A. Zeeb struct sk_buff *skb; 44306b4cac81SBjoern A. Zeeb struct ieee80211_frame_pspoll *psp; 44316b4cac81SBjoern A. Zeeb uint16_t v; 44326b4cac81SBjoern A. Zeeb 44336b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*psp)); 44346b4cac81SBjoern A. Zeeb if (skb == NULL) 44356b4cac81SBjoern A. Zeeb return (NULL); 44366b4cac81SBjoern A. Zeeb 44376b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 44386b4cac81SBjoern A. Zeeb 44396b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 44406b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 44416b4cac81SBjoern A. Zeeb 44426b4cac81SBjoern A. Zeeb psp = skb_put_zero(skb, sizeof(*psp)); 44436b4cac81SBjoern A. Zeeb psp->i_fc[0] = IEEE80211_FC0_VERSION_0; 44446b4cac81SBjoern A. Zeeb psp->i_fc[0] |= IEEE80211_FC0_SUBTYPE_PS_POLL | IEEE80211_FC0_TYPE_CTL; 44456b4cac81SBjoern A. Zeeb v = htole16(vif->bss_conf.aid | 1<<15 | 1<<16); 44466b4cac81SBjoern A. Zeeb memcpy(&psp->i_aid, &v, sizeof(v)); 44476b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(psp->i_bssid, vap->iv_bss->ni_macaddr); 44486b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(psp->i_ta, vif->addr); 44496b4cac81SBjoern A. Zeeb 44506b4cac81SBjoern A. Zeeb return (skb); 44516b4cac81SBjoern A. Zeeb } 44526b4cac81SBjoern A. Zeeb 44536b4cac81SBjoern A. Zeeb struct sk_buff * 44546b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_nullfunc_get(struct ieee80211_hw *hw, 44556b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif, bool qos) 44566b4cac81SBjoern A. Zeeb { 44576b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 44586b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 44596b4cac81SBjoern A. Zeeb struct sk_buff *skb; 44606b4cac81SBjoern A. Zeeb struct ieee80211_frame *nullf; 44616b4cac81SBjoern A. Zeeb 44626b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*nullf)); 44636b4cac81SBjoern A. Zeeb if (skb == NULL) 44646b4cac81SBjoern A. Zeeb return (NULL); 44656b4cac81SBjoern A. Zeeb 44666b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 44676b4cac81SBjoern A. Zeeb 44686b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 44696b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 44706b4cac81SBjoern A. Zeeb 44716b4cac81SBjoern A. Zeeb nullf = skb_put_zero(skb, sizeof(*nullf)); 44726b4cac81SBjoern A. Zeeb nullf->i_fc[0] = IEEE80211_FC0_VERSION_0; 44736b4cac81SBjoern A. Zeeb nullf->i_fc[0] |= IEEE80211_FC0_SUBTYPE_NODATA | IEEE80211_FC0_TYPE_DATA; 44746b4cac81SBjoern A. Zeeb nullf->i_fc[1] = IEEE80211_FC1_DIR_TODS; 44756b4cac81SBjoern A. Zeeb 44766b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr1, vap->iv_bss->ni_bssid); 44776b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr2, vif->addr); 44786b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr3, vap->iv_bss->ni_macaddr); 44796b4cac81SBjoern A. Zeeb 44806b4cac81SBjoern A. Zeeb return (skb); 44816b4cac81SBjoern A. Zeeb } 44826b4cac81SBjoern A. Zeeb 44836b4cac81SBjoern A. Zeeb struct wireless_dev * 44846b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_vif_to_wdev(struct ieee80211_vif *vif) 44856b4cac81SBjoern A. Zeeb { 44866b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 44876b4cac81SBjoern A. Zeeb 44886b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 44896b4cac81SBjoern A. Zeeb return (&lvif->wdev); 44906b4cac81SBjoern A. Zeeb } 44916b4cac81SBjoern A. Zeeb 44926b4cac81SBjoern A. Zeeb void 44936b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_connection_loss(struct ieee80211_vif *vif) 44946b4cac81SBjoern A. Zeeb { 44956b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 44966b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 44976b4cac81SBjoern A. Zeeb enum ieee80211_state nstate; 44986b4cac81SBjoern A. Zeeb int arg; 44996b4cac81SBjoern A. Zeeb 45006b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 45016b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 45026b4cac81SBjoern A. Zeeb 45036b4cac81SBjoern A. Zeeb /* 4504f3229b62SBjoern A. Zeeb * Go to init; otherwise we need to elaborately check state and 45056b4cac81SBjoern A. Zeeb * handle accordingly, e.g., if in RUN we could call iv_bmiss. 45066b4cac81SBjoern A. Zeeb * Let the statemachine handle all neccessary changes. 45076b4cac81SBjoern A. Zeeb */ 4508f3229b62SBjoern A. Zeeb nstate = IEEE80211_S_INIT; 4509bb81db90SBjoern A. Zeeb arg = 0; /* Not a valid reason. */ 45106b4cac81SBjoern A. Zeeb 45119d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 45129d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 45136b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: vif %p\n", __func__, vif); 45149d9ba2b7SBjoern A. Zeeb #endif 45156b4cac81SBjoern A. Zeeb ieee80211_new_state(vap, nstate, arg); 45166b4cac81SBjoern A. Zeeb } 45176b4cac81SBjoern A. Zeeb 4518bb81db90SBjoern A. Zeeb void 4519bb81db90SBjoern A. Zeeb linuxkpi_ieee80211_beacon_loss(struct ieee80211_vif *vif) 4520bb81db90SBjoern A. Zeeb { 4521bb81db90SBjoern A. Zeeb struct lkpi_vif *lvif; 4522bb81db90SBjoern A. Zeeb struct ieee80211vap *vap; 4523bb81db90SBjoern A. Zeeb 4524bb81db90SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 4525bb81db90SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 4526bb81db90SBjoern A. Zeeb 45279d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 45289d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE || vap->iv_state != IEEE80211_S_RUN) 4529bb81db90SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: vif %p vap %p state %s\n", __func__, 4530bb81db90SBjoern A. Zeeb vif, vap, ieee80211_state_name[vap->iv_state]); 45319d9ba2b7SBjoern A. Zeeb #endif 45323540911bSBjoern A. Zeeb ieee80211_beacon_miss(vap->iv_ic); 4533bb81db90SBjoern A. Zeeb } 4534bb81db90SBjoern A. Zeeb 45356b4cac81SBjoern A. Zeeb MODULE_VERSION(linuxkpi_wlan, 1); 45366b4cac81SBjoern A. Zeeb MODULE_DEPEND(linuxkpi_wlan, linuxkpi, 1, 1, 1); 45376b4cac81SBjoern A. Zeeb MODULE_DEPEND(linuxkpi_wlan, wlan, 1, 1, 1); 4538