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> 566b4cac81SBjoern A. Zeeb 576b4cac81SBjoern A. Zeeb #include <net/if.h> 586b4cac81SBjoern A. Zeeb #include <net/if_var.h> 596b4cac81SBjoern A. Zeeb #include <net/if_media.h> 606b4cac81SBjoern A. Zeeb #include <net/ethernet.h> 616b4cac81SBjoern A. Zeeb 626b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_var.h> 636b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_proto.h> 646b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_ratectl.h> 656b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_radiotap.h> 666b4cac81SBjoern A. Zeeb 676b4cac81SBjoern A. Zeeb #define LINUXKPI_NET80211 686b4cac81SBjoern A. Zeeb #include <net/mac80211.h> 696b4cac81SBjoern A. Zeeb 706b4cac81SBjoern A. Zeeb #include <linux/workqueue.h> 716b4cac81SBjoern A. Zeeb #include "linux_80211.h" 726b4cac81SBjoern A. Zeeb 736b4cac81SBjoern A. Zeeb static MALLOC_DEFINE(M_LKPI80211, "lkpi80211", "Linux KPI 80211 compat"); 746b4cac81SBjoern A. Zeeb 756b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 766b4cac81SBjoern A. Zeeb 776b4cac81SBjoern A. Zeeb int debug_80211; 786b4cac81SBjoern A. Zeeb SYSCTL_INT(_compat_linuxkpi, OID_AUTO, debug_80211, CTLFLAG_RWTUN, 796b4cac81SBjoern A. Zeeb &debug_80211, 0, "80211 debug Level"); 806b4cac81SBjoern A. Zeeb 816b4cac81SBjoern A. Zeeb #define LINUXKPI_DEBUG_80211 826b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 836b4cac81SBjoern A. Zeeb #ifndef D80211_TODO 846b4cac81SBjoern A. Zeeb #define D80211_TODO 0x1 856b4cac81SBjoern A. Zeeb #endif 866b4cac81SBjoern A. Zeeb #ifndef D80211_IMPROVE 876b4cac81SBjoern A. Zeeb #define D80211_IMPROVE 0x2 886b4cac81SBjoern A. Zeeb #endif 896b4cac81SBjoern A. Zeeb #define D80211_TRACE 0x10 906b4cac81SBjoern A. Zeeb #define D80211_TRACEOK 0x20 916b4cac81SBjoern A. Zeeb #define D80211_TRACE_TX 0x100 926b4cac81SBjoern A. Zeeb #define D80211_TRACE_TX_DUMP 0x200 936b4cac81SBjoern A. Zeeb #define D80211_TRACE_RX 0x1000 946b4cac81SBjoern A. Zeeb #define D80211_TRACE_RX_DUMP 0x2000 956b4cac81SBjoern A. Zeeb #define D80211_TRACE_RX_BEACONS 0x4000 966b4cac81SBjoern A. Zeeb #define D80211_TRACEX (D80211_TRACE_TX|D80211_TRACE_RX) 976b4cac81SBjoern A. Zeeb #define D80211_TRACEX_DUMP (D80211_TRACE_TX_DUMP|D80211_TRACE_RX_DUMP) 986b4cac81SBjoern A. Zeeb #define UNIMPLEMENTED if (debug_80211 & D80211_TODO) \ 996b4cac81SBjoern A. Zeeb printf("XXX-TODO %s:%d: UNIMPLEMENTED\n", __func__, __LINE__) 1006b4cac81SBjoern A. Zeeb #define TRACEOK() if (debug_80211 & D80211_TRACEOK) \ 1016b4cac81SBjoern A. Zeeb printf("XXX-TODO %s:%d: TRACEPOINT\n", __func__, __LINE__) 1026b4cac81SBjoern A. Zeeb #else 1036b4cac81SBjoern A. Zeeb #define UNIMPLEMENTED do { } while (0) 1046b4cac81SBjoern A. Zeeb #define TRACEOK() do { } while (0) 1056b4cac81SBjoern A. Zeeb #endif 1066b4cac81SBjoern A. Zeeb 1076b4cac81SBjoern A. Zeeb /* #define PREP_TX_INFO_DURATION (IEEE80211_TRANS_WAIT * 1000) */ 1086b4cac81SBjoern A. Zeeb #ifndef PREP_TX_INFO_DURATION 1096b4cac81SBjoern A. Zeeb #define PREP_TX_INFO_DURATION 0 /* Let the driver do its thing. */ 1106b4cac81SBjoern A. Zeeb #endif 1116b4cac81SBjoern A. Zeeb 1126b4cac81SBjoern A. Zeeb /* This is DSAP | SSAP | CTRL | ProtoID/OrgCode{3}. */ 1136b4cac81SBjoern A. Zeeb const uint8_t rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; 1146b4cac81SBjoern A. Zeeb 1154f61ef8bSBjoern A. Zeeb const uint8_t tid_to_mac80211_ac[] = { 1164f61ef8bSBjoern A. Zeeb IEEE80211_AC_BE, 1174f61ef8bSBjoern A. Zeeb IEEE80211_AC_BK, 1184f61ef8bSBjoern A. Zeeb IEEE80211_AC_BK, 1194f61ef8bSBjoern A. Zeeb IEEE80211_AC_BE, 1204f61ef8bSBjoern A. Zeeb IEEE80211_AC_VI, 1214f61ef8bSBjoern A. Zeeb IEEE80211_AC_VI, 1224f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO, 1234f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO, 1244f61ef8bSBjoern A. Zeeb #if 0 1254f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO, /* We treat MGMT as TID 8, which is set as AC_VO */ 1264f61ef8bSBjoern A. Zeeb #endif 1274f61ef8bSBjoern A. Zeeb }; 1284f61ef8bSBjoern A. Zeeb 1296b4cac81SBjoern A. Zeeb const struct cfg80211_ops linuxkpi_mac80211cfgops = { 1306b4cac81SBjoern A. Zeeb /* 1316b4cac81SBjoern A. Zeeb * XXX TODO need a "glue layer" to link cfg80211 ops to 1326b4cac81SBjoern A. Zeeb * mac80211 and to the driver or net80211. 1336b4cac81SBjoern A. Zeeb * Can we pass some on 1:1? Need to compare the (*f)(). 1346b4cac81SBjoern A. Zeeb */ 1356b4cac81SBjoern A. Zeeb }; 1366b4cac81SBjoern A. Zeeb 1376b4cac81SBjoern A. Zeeb static struct lkpi_sta *lkpi_find_lsta_by_ni(struct lkpi_vif *, 1386b4cac81SBjoern A. Zeeb struct ieee80211_node *); 1396b4cac81SBjoern A. Zeeb static void lkpi_80211_txq_task(void *, int); 1406b4cac81SBjoern A. Zeeb static void lkpi_ieee80211_free_skb_mbuf(void *); 1416b4cac81SBjoern A. Zeeb 1424f61ef8bSBjoern A. Zeeb static struct lkpi_sta * 1434f61ef8bSBjoern A. Zeeb lkpi_lsta_alloc(struct ieee80211vap *vap, const uint8_t mac[IEEE80211_ADDR_LEN], 1444f61ef8bSBjoern A. Zeeb struct ieee80211_hw *hw, struct ieee80211_node *ni) 1454f61ef8bSBjoern A. Zeeb { 1464f61ef8bSBjoern A. Zeeb struct lkpi_sta *lsta; 1474f61ef8bSBjoern A. Zeeb struct lkpi_vif *lvif; 1484f61ef8bSBjoern A. Zeeb struct ieee80211_vif *vif; 1494f61ef8bSBjoern A. Zeeb struct ieee80211_sta *sta; 1504f61ef8bSBjoern A. Zeeb int tid; 1514f61ef8bSBjoern A. Zeeb 1524f61ef8bSBjoern A. Zeeb lsta = malloc(sizeof(*lsta) + hw->sta_data_size, M_LKPI80211, 1534f61ef8bSBjoern A. Zeeb M_NOWAIT | M_ZERO); 1544f61ef8bSBjoern A. Zeeb if (lsta == NULL) 1554f61ef8bSBjoern A. Zeeb return (NULL); 1564f61ef8bSBjoern A. Zeeb 1574f61ef8bSBjoern A. Zeeb lsta->added_to_drv = false; 1584f61ef8bSBjoern A. Zeeb lsta->state = IEEE80211_STA_NOTEXIST; 1594f61ef8bSBjoern A. Zeeb #if 0 1604f61ef8bSBjoern A. Zeeb /* 1614f61ef8bSBjoern A. Zeeb * This needs to be done in node_init() as ieee80211_alloc_node() 1624f61ef8bSBjoern A. Zeeb * will initialise the refcount after us. 1634f61ef8bSBjoern A. Zeeb */ 1644f61ef8bSBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 1654f61ef8bSBjoern A. Zeeb #endif 1664f61ef8bSBjoern A. Zeeb /* The back-pointer "drv_data" to net80211_node let's us get lsta. */ 1674f61ef8bSBjoern A. Zeeb ni->ni_drv_data = lsta; 1684f61ef8bSBjoern A. Zeeb 1694f61ef8bSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 1704f61ef8bSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 1714f61ef8bSBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 1724f61ef8bSBjoern A. Zeeb 1734f61ef8bSBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->addr, mac); 1744f61ef8bSBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 1754f61ef8bSBjoern A. Zeeb struct lkpi_txq *ltxq; 1764f61ef8bSBjoern A. Zeeb 1774f61ef8bSBjoern A. Zeeb /* 1784f61ef8bSBjoern A. Zeeb * We are neither limiting ourselves to hw.queues here, 1794f61ef8bSBjoern A. Zeeb * nor do we check if driver wants IEEE80211_NUM_TIDS queue. 1804f61ef8bSBjoern A. Zeeb */ 1814f61ef8bSBjoern A. Zeeb 1824f61ef8bSBjoern A. Zeeb ltxq = malloc(sizeof(*ltxq) + hw->txq_data_size, 1834f61ef8bSBjoern A. Zeeb M_LKPI80211, M_NOWAIT | M_ZERO); 1844f61ef8bSBjoern A. Zeeb if (ltxq == NULL) 1854f61ef8bSBjoern A. Zeeb goto cleanup; 1864f61ef8bSBjoern A. Zeeb ltxq->seen_dequeue = false; 1874f61ef8bSBjoern A. Zeeb skb_queue_head_init(<xq->skbq); 1884f61ef8bSBjoern A. Zeeb /* iwlwifi//mvm/sta.c::tid_to_mac80211_ac[] */ 1894f61ef8bSBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) { 1904f61ef8bSBjoern A. Zeeb IMPROVE(); 1914f61ef8bSBjoern A. Zeeb ltxq->txq.ac = IEEE80211_AC_VO; 1924f61ef8bSBjoern A. Zeeb } else { 1934f61ef8bSBjoern A. Zeeb ltxq->txq.ac = tid_to_mac80211_ac[tid & 7]; 1944f61ef8bSBjoern A. Zeeb } 1954f61ef8bSBjoern A. Zeeb ltxq->txq.tid = tid; 1964f61ef8bSBjoern A. Zeeb ltxq->txq.sta = sta; 1974f61ef8bSBjoern A. Zeeb ltxq->txq.vif = vif; 1984f61ef8bSBjoern A. Zeeb sta->txq[tid] = <xq->txq; 1994f61ef8bSBjoern A. Zeeb } 2004f61ef8bSBjoern A. Zeeb 2014f61ef8bSBjoern A. Zeeb /* Deferred TX path. */ 2024f61ef8bSBjoern A. Zeeb mtx_init(&lsta->txq_mtx, "lsta_txq", NULL, MTX_DEF); 2034f61ef8bSBjoern A. Zeeb TASK_INIT(&lsta->txq_task, 0, lkpi_80211_txq_task, lsta); 2044f61ef8bSBjoern A. Zeeb mbufq_init(&lsta->txq, IFQ_MAXLEN); 2054f61ef8bSBjoern A. Zeeb 2064f61ef8bSBjoern A. Zeeb return (lsta); 2074f61ef8bSBjoern A. Zeeb 2084f61ef8bSBjoern A. Zeeb cleanup: 2094f61ef8bSBjoern A. Zeeb for (; tid >= 0; tid--) 2104f61ef8bSBjoern A. Zeeb free(sta->txq[tid], M_LKPI80211); 2114f61ef8bSBjoern A. Zeeb free(lsta, M_LKPI80211); 2124f61ef8bSBjoern A. Zeeb return (NULL); 2134f61ef8bSBjoern A. Zeeb } 2144f61ef8bSBjoern A. Zeeb 2156b4cac81SBjoern A. Zeeb static enum nl80211_band 2166b4cac81SBjoern A. Zeeb lkpi_net80211_chan_to_nl80211_band(struct ieee80211_channel *c) 2176b4cac81SBjoern A. Zeeb { 2186b4cac81SBjoern A. Zeeb 2196b4cac81SBjoern A. Zeeb if (IEEE80211_IS_CHAN_2GHZ(c)) 2206b4cac81SBjoern A. Zeeb return (NL80211_BAND_2GHZ); 2216b4cac81SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_5GHZ(c)) 2226b4cac81SBjoern A. Zeeb return (NL80211_BAND_5GHZ); 2236b4cac81SBjoern A. Zeeb #ifdef __notyet__ 2246b4cac81SBjoern A. Zeeb else if () 2256b4cac81SBjoern A. Zeeb return (NL80211_BAND_6GHZ); 2266b4cac81SBjoern A. Zeeb else if () 2276b4cac81SBjoern A. Zeeb return (NL80211_BAND_60GHZ); 2286b4cac81SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_GSM(c)) 2296b4cac81SBjoern A. Zeeb return (NL80211_BAND_XXX); 2306b4cac81SBjoern A. Zeeb #endif 2316b4cac81SBjoern A. Zeeb else 2326b4cac81SBjoern A. Zeeb panic("%s: unsupported band. c %p flags %#x\n", 2336b4cac81SBjoern A. Zeeb __func__, c, c->ic_flags); 2346b4cac81SBjoern A. Zeeb } 2356b4cac81SBjoern A. Zeeb 2366b4cac81SBjoern A. Zeeb static uint32_t 2376b4cac81SBjoern A. Zeeb lkpi_nl80211_band_to_net80211_band(enum nl80211_band band) 2386b4cac81SBjoern A. Zeeb { 2396b4cac81SBjoern A. Zeeb 2406b4cac81SBjoern A. Zeeb /* XXX-BZ this is just silly; net80211 is too convoluted. */ 2416b4cac81SBjoern A. Zeeb /* IEEE80211_CHAN_A / _G / .. doesn't really work either. */ 2426b4cac81SBjoern A. Zeeb switch (band) { 2436b4cac81SBjoern A. Zeeb case NL80211_BAND_2GHZ: 2446b4cac81SBjoern A. Zeeb return (IEEE80211_CHAN_2GHZ); 2456b4cac81SBjoern A. Zeeb break; 2466b4cac81SBjoern A. Zeeb case NL80211_BAND_5GHZ: 2476b4cac81SBjoern A. Zeeb return (IEEE80211_CHAN_5GHZ); 2486b4cac81SBjoern A. Zeeb break; 2496b4cac81SBjoern A. Zeeb case NL80211_BAND_60GHZ: 2506b4cac81SBjoern A. Zeeb break; 2516b4cac81SBjoern A. Zeeb case NL80211_BAND_6GHZ: 2526b4cac81SBjoern A. Zeeb break; 2536b4cac81SBjoern A. Zeeb default: 2546b4cac81SBjoern A. Zeeb panic("%s: unsupported band %u\n", __func__, band); 2556b4cac81SBjoern A. Zeeb break; 2566b4cac81SBjoern A. Zeeb } 2576b4cac81SBjoern A. Zeeb 2586b4cac81SBjoern A. Zeeb IMPROVE(); 2596b4cac81SBjoern A. Zeeb return (0x00); 2606b4cac81SBjoern A. Zeeb } 2616b4cac81SBjoern A. Zeeb 2626b4cac81SBjoern A. Zeeb static enum ieee80211_ac_numbers 2636b4cac81SBjoern A. Zeeb lkpi_ac_net_to_l80211(int ac) 2646b4cac81SBjoern A. Zeeb { 2656b4cac81SBjoern A. Zeeb 2666b4cac81SBjoern A. Zeeb switch (ac) { 2676b4cac81SBjoern A. Zeeb case WME_AC_VO: 2686b4cac81SBjoern A. Zeeb return (IEEE80211_AC_VO); 2696b4cac81SBjoern A. Zeeb case WME_AC_VI: 2706b4cac81SBjoern A. Zeeb return (IEEE80211_AC_VI); 2716b4cac81SBjoern A. Zeeb case WME_AC_BE: 2726b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BE); 2736b4cac81SBjoern A. Zeeb case WME_AC_BK: 2746b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BK); 2756b4cac81SBjoern A. Zeeb default: 2766b4cac81SBjoern A. Zeeb printf("%s: invalid WME_AC_* input: ac = %d\n", __func__, ac); 2776b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BE); 2786b4cac81SBjoern A. Zeeb } 2796b4cac81SBjoern A. Zeeb } 2806b4cac81SBjoern A. Zeeb 2816b4cac81SBjoern A. Zeeb static enum nl80211_iftype 2826b4cac81SBjoern A. Zeeb lkpi_opmode_to_vif_type(enum ieee80211_opmode opmode) 2836b4cac81SBjoern A. Zeeb { 2846b4cac81SBjoern A. Zeeb 2856b4cac81SBjoern A. Zeeb switch (opmode) { 2866b4cac81SBjoern A. Zeeb case IEEE80211_M_IBSS: 2876b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_ADHOC); 2886b4cac81SBjoern A. Zeeb break; 2896b4cac81SBjoern A. Zeeb case IEEE80211_M_STA: 2906b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_STATION); 2916b4cac81SBjoern A. Zeeb break; 2926b4cac81SBjoern A. Zeeb case IEEE80211_M_WDS: 2936b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_WDS); 2946b4cac81SBjoern A. Zeeb break; 2956b4cac81SBjoern A. Zeeb case IEEE80211_M_HOSTAP: 2966b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_AP); 2976b4cac81SBjoern A. Zeeb break; 2986b4cac81SBjoern A. Zeeb case IEEE80211_M_MONITOR: 2996b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_MONITOR); 3006b4cac81SBjoern A. Zeeb break; 3016b4cac81SBjoern A. Zeeb case IEEE80211_M_MBSS: 3026b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_MESH_POINT); 3036b4cac81SBjoern A. Zeeb break; 3046b4cac81SBjoern A. Zeeb case IEEE80211_M_AHDEMO: 3056b4cac81SBjoern A. Zeeb /* FALLTHROUGH */ 3066b4cac81SBjoern A. Zeeb default: 3076b4cac81SBjoern A. Zeeb printf("ERROR: %s: unsupported opmode %d\n", __func__, opmode); 3086b4cac81SBjoern A. Zeeb /* FALLTHROUGH */ 3096b4cac81SBjoern A. Zeeb } 3106b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_UNSPECIFIED); 3116b4cac81SBjoern A. Zeeb } 3126b4cac81SBjoern A. Zeeb 3136b4cac81SBjoern A. Zeeb #ifdef __notyet__ 3146b4cac81SBjoern A. Zeeb static uint32_t 3156b4cac81SBjoern A. Zeeb lkpi_l80211_to_net80211_cyphers(uint32_t wlan_cipher_suite) 3166b4cac81SBjoern A. Zeeb { 3176b4cac81SBjoern A. Zeeb 3186b4cac81SBjoern A. Zeeb switch (wlan_cipher_suite) { 3196b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP40: 3206b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_WEP); 3216b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP: 3226b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_TKIP); 3236b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP: 3246b4cac81SBjoern A. Zeeb return (IEEE80211_CIPHER_AES_CCM); 3256b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP104: 3266b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_WEP); 3276b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_AES_CMAC: 3286b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP: 3296b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP_256: 3306b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP_256: 3316b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_128: 3326b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_256: 3336b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_CMAC_256: 3346b4cac81SBjoern A. Zeeb printf("%s: unsupported WLAN Cipher Suite %#08x | %u\n", __func__, 3356b4cac81SBjoern A. Zeeb wlan_cipher_suite >> 8, wlan_cipher_suite & 0xff); 3366b4cac81SBjoern A. Zeeb break; 3376b4cac81SBjoern A. Zeeb default: 3386b4cac81SBjoern A. Zeeb printf("%s: unknown WLAN Cipher Suite %#08x | %u\n", __func__, 3396b4cac81SBjoern A. Zeeb wlan_cipher_suite >> 8, wlan_cipher_suite & 0xff); 3406b4cac81SBjoern A. Zeeb } 3416b4cac81SBjoern A. Zeeb 3426b4cac81SBjoern A. Zeeb return (0); 3436b4cac81SBjoern A. Zeeb } 3446b4cac81SBjoern A. Zeeb #endif 3456b4cac81SBjoern A. Zeeb 3466b4cac81SBjoern A. Zeeb #ifdef TRY_HW_CRYPTO 3476b4cac81SBjoern A. Zeeb static uint32_t 3486b4cac81SBjoern A. Zeeb lkpi_net80211_to_l80211_cipher_suite(uint32_t cipher, uint8_t keylen) 3496b4cac81SBjoern A. Zeeb { 3506b4cac81SBjoern A. Zeeb 3516b4cac81SBjoern A. Zeeb switch (cipher) { 3526b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_TKIP: 3536b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_TKIP); 3546b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_AES_CCM: 3556b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_CCMP); 3566b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_WEP: 3576b4cac81SBjoern A. Zeeb if (keylen < 8) 3586b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_WEP40); 3596b4cac81SBjoern A. Zeeb else 3606b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_WEP104); 3616b4cac81SBjoern A. Zeeb break; 3626b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_AES_OCB: 3636b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_TKIPMIC: 3646b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_CKIP: 3656b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_NONE: 3666b4cac81SBjoern A. Zeeb printf("%s: unsupported cipher %#010x\n", __func__, cipher); 3676b4cac81SBjoern A. Zeeb break; 3686b4cac81SBjoern A. Zeeb default: 3696b4cac81SBjoern A. Zeeb printf("%s: unknown cipher %#010x\n", __func__, cipher); 3706b4cac81SBjoern A. Zeeb }; 3716b4cac81SBjoern A. Zeeb return (0); 3726b4cac81SBjoern A. Zeeb } 3736b4cac81SBjoern A. Zeeb #endif 3746b4cac81SBjoern A. Zeeb 3756b4cac81SBjoern A. Zeeb #ifdef __notyet__ 3766b4cac81SBjoern A. Zeeb static enum ieee80211_sta_state 3776b4cac81SBjoern A. Zeeb lkpi_net80211_state_to_sta_state(enum ieee80211_state state) 3786b4cac81SBjoern A. Zeeb { 3796b4cac81SBjoern A. Zeeb 3806b4cac81SBjoern A. Zeeb /* 3816b4cac81SBjoern A. Zeeb * XXX-BZ The net80211 states are "try to ..", the lkpi8011 states are 3826b4cac81SBjoern A. Zeeb * "done". Also ASSOC/AUTHORIZED are both "RUN" then? 3836b4cac81SBjoern A. Zeeb */ 3846b4cac81SBjoern A. Zeeb switch (state) { 3856b4cac81SBjoern A. Zeeb case IEEE80211_S_INIT: 3866b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NOTEXIST); 3876b4cac81SBjoern A. Zeeb case IEEE80211_S_SCAN: 3886b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NONE); 3896b4cac81SBjoern A. Zeeb case IEEE80211_S_AUTH: 3906b4cac81SBjoern A. Zeeb return (IEEE80211_STA_AUTH); 3916b4cac81SBjoern A. Zeeb case IEEE80211_S_ASSOC: 3926b4cac81SBjoern A. Zeeb return (IEEE80211_STA_ASSOC); 3936b4cac81SBjoern A. Zeeb case IEEE80211_S_RUN: 3946b4cac81SBjoern A. Zeeb return (IEEE80211_STA_AUTHORIZED); 3956b4cac81SBjoern A. Zeeb case IEEE80211_S_CAC: 3966b4cac81SBjoern A. Zeeb case IEEE80211_S_CSA: 3976b4cac81SBjoern A. Zeeb case IEEE80211_S_SLEEP: 3986b4cac81SBjoern A. Zeeb default: 3996b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 4006b4cac81SBjoern A. Zeeb }; 4016b4cac81SBjoern A. Zeeb 4026b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NOTEXIST); 4036b4cac81SBjoern A. Zeeb } 4046b4cac81SBjoern A. Zeeb #endif 4056b4cac81SBjoern A. Zeeb 4066b4cac81SBjoern A. Zeeb static struct linuxkpi_ieee80211_channel * 4076b4cac81SBjoern A. Zeeb lkpi_find_lkpi80211_chan(struct lkpi_hw *lhw, 4086b4cac81SBjoern A. Zeeb struct ieee80211_channel *c) 4096b4cac81SBjoern A. Zeeb { 4106b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 4116b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 4126b4cac81SBjoern A. Zeeb enum nl80211_band band; 4136b4cac81SBjoern A. Zeeb int i, nchans; 4146b4cac81SBjoern A. Zeeb 4156b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 4166b4cac81SBjoern A. Zeeb band = lkpi_net80211_chan_to_nl80211_band(c); 4176b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[band] == NULL) 4186b4cac81SBjoern A. Zeeb return (NULL); 4196b4cac81SBjoern A. Zeeb 4206b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[band]->n_channels; 4216b4cac81SBjoern A. Zeeb if (nchans <= 0) 4226b4cac81SBjoern A. Zeeb return (NULL); 4236b4cac81SBjoern A. Zeeb 4246b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[band]->channels; 4256b4cac81SBjoern A. Zeeb for (i = 0; i < nchans; i++) { 4266b4cac81SBjoern A. Zeeb if (channels[i].hw_value == c->ic_ieee) 4276b4cac81SBjoern A. Zeeb return (&channels[i]); 4286b4cac81SBjoern A. Zeeb } 4296b4cac81SBjoern A. Zeeb 4306b4cac81SBjoern A. Zeeb return (NULL); 4316b4cac81SBjoern A. Zeeb } 4326b4cac81SBjoern A. Zeeb 4336b4cac81SBjoern A. Zeeb static struct linuxkpi_ieee80211_channel * 4346b4cac81SBjoern A. Zeeb lkpi_get_lkpi80211_chan(struct ieee80211com *ic, struct ieee80211_node *ni) 4356b4cac81SBjoern A. Zeeb { 4366b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 4376b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 4386b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 4396b4cac81SBjoern A. Zeeb 4406b4cac81SBjoern A. Zeeb chan = NULL; 4416b4cac81SBjoern A. Zeeb if (ni != NULL && ni->ni_chan != IEEE80211_CHAN_ANYC) 4426b4cac81SBjoern A. Zeeb c = ni->ni_chan; 4436b4cac81SBjoern A. Zeeb else if (ic->ic_bsschan != IEEE80211_CHAN_ANYC) 4446b4cac81SBjoern A. Zeeb c = ic->ic_bsschan; 4456b4cac81SBjoern A. Zeeb else if (ic->ic_curchan != IEEE80211_CHAN_ANYC) 4466b4cac81SBjoern A. Zeeb c = ic->ic_curchan; 4476b4cac81SBjoern A. Zeeb else 4486b4cac81SBjoern A. Zeeb c = NULL; 4496b4cac81SBjoern A. Zeeb 4506b4cac81SBjoern A. Zeeb if (c != NULL && c != IEEE80211_CHAN_ANYC) { 4516b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 4526b4cac81SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, c); 4536b4cac81SBjoern A. Zeeb } 4546b4cac81SBjoern A. Zeeb 4556b4cac81SBjoern A. Zeeb return (chan); 4566b4cac81SBjoern A. Zeeb } 4576b4cac81SBjoern A. Zeeb 4582e183d99SBjoern A. Zeeb struct linuxkpi_ieee80211_channel * 4592e183d99SBjoern A. Zeeb linuxkpi_ieee80211_get_channel(struct wiphy *wiphy, uint32_t freq) 4602e183d99SBjoern A. Zeeb { 4612e183d99SBjoern A. Zeeb enum nl80211_band band; 4622e183d99SBjoern A. Zeeb 4632e183d99SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 4642e183d99SBjoern A. Zeeb struct ieee80211_supported_band *supband; 4652e183d99SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 4662e183d99SBjoern A. Zeeb int i; 4672e183d99SBjoern A. Zeeb 4682e183d99SBjoern A. Zeeb supband = wiphy->bands[band]; 4692e183d99SBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 4702e183d99SBjoern A. Zeeb continue; 4712e183d99SBjoern A. Zeeb 4722e183d99SBjoern A. Zeeb channels = supband->channels; 4732e183d99SBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 4742e183d99SBjoern A. Zeeb if (channels[i].center_freq == freq) 4752e183d99SBjoern A. Zeeb return (&channels[i]); 4762e183d99SBjoern A. Zeeb } 4772e183d99SBjoern A. Zeeb } 4782e183d99SBjoern A. Zeeb 4792e183d99SBjoern A. Zeeb return (NULL); 4802e183d99SBjoern A. Zeeb } 4812e183d99SBjoern A. Zeeb 4826b4cac81SBjoern A. Zeeb #ifdef TRY_HW_CRYPTO 4836b4cac81SBjoern A. Zeeb static int 4846b4cac81SBjoern A. Zeeb _lkpi_iv_key_set_delete(struct ieee80211vap *vap, const struct ieee80211_key *k, 4856b4cac81SBjoern A. Zeeb enum set_key_cmd cmd) 4866b4cac81SBjoern A. Zeeb { 4876b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 4886b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 4896b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 4906b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 4916b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 4926b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 4936b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 4946b4cac81SBjoern A. Zeeb struct ieee80211_key_conf *kc; 4956b4cac81SBjoern A. Zeeb int error; 4966b4cac81SBjoern A. Zeeb 4976b4cac81SBjoern A. Zeeb /* XXX TODO Check (k->wk_flags & IEEE80211_KEY_SWENCRYPT) and don't upload to driver/hw? */ 4986b4cac81SBjoern A. Zeeb 4996b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 5006b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 5016b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 5026b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 5036b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 5046b4cac81SBjoern A. Zeeb 5056b4cac81SBjoern A. Zeeb memset(&kc, 0, sizeof(kc)); 5066b4cac81SBjoern A. Zeeb kc = malloc(sizeof(*kc) + k->wk_keylen, M_LKPI80211, M_WAITOK | M_ZERO); 5076b4cac81SBjoern A. Zeeb kc->cipher = lkpi_net80211_to_l80211_cipher_suite( 5086b4cac81SBjoern A. Zeeb k->wk_cipher->ic_cipher, k->wk_keylen); 5096b4cac81SBjoern A. Zeeb kc->keyidx = k->wk_keyix; 5106b4cac81SBjoern A. Zeeb #if 0 5116b4cac81SBjoern A. Zeeb kc->hw_key_idx = /* set by hw and needs to be passed for TX */; 5126b4cac81SBjoern A. Zeeb #endif 5136b4cac81SBjoern A. Zeeb atomic64_set(&kc->tx_pn, k->wk_keytsc); 5146b4cac81SBjoern A. Zeeb kc->keylen = k->wk_keylen; 5156b4cac81SBjoern A. Zeeb memcpy(kc->key, k->wk_key, k->wk_keylen); 5166b4cac81SBjoern A. Zeeb 5176b4cac81SBjoern A. Zeeb switch (kc->cipher) { 5186b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP: 5196b4cac81SBjoern A. Zeeb kc->iv_len = k->wk_cipher->ic_header; 5206b4cac81SBjoern A. Zeeb kc->icv_len = k->wk_cipher->ic_trailer; 5216b4cac81SBjoern A. Zeeb break; 5226b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP: 5236b4cac81SBjoern A. Zeeb default: 5246b4cac81SBjoern A. Zeeb IMPROVE(); 5256b4cac81SBjoern A. Zeeb return (0); 5266b4cac81SBjoern A. Zeeb }; 5276b4cac81SBjoern A. Zeeb 5286b4cac81SBjoern A. Zeeb ni = vap->iv_bss; 5296b4cac81SBjoern A. Zeeb sta = ieee80211_find_sta(vif, ni->ni_bssid); 5306b4cac81SBjoern A. Zeeb if (sta != NULL) { 5316b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 5326b4cac81SBjoern A. Zeeb 5336b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 5346b4cac81SBjoern A. Zeeb lsta->kc = kc; 5356b4cac81SBjoern A. Zeeb } 5366b4cac81SBjoern A. Zeeb 5376b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_set_key(hw, cmd, vif, sta, kc); 5386b4cac81SBjoern A. Zeeb if (error != 0) { 5396b4cac81SBjoern A. Zeeb /* XXX-BZ leaking kc currently */ 5406b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: set_key failed: %d\n", __func__, error); 5416b4cac81SBjoern A. Zeeb return (0); 5426b4cac81SBjoern A. Zeeb } else { 5436b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: set_key succeeded: keyidx %u hw_key_idx %u " 5446b4cac81SBjoern A. Zeeb "flags %#10x\n", __func__, 5456b4cac81SBjoern A. Zeeb kc->keyidx, kc->hw_key_idx, kc->flags); 5466b4cac81SBjoern A. Zeeb return (1); 5476b4cac81SBjoern A. Zeeb } 5486b4cac81SBjoern A. Zeeb } 5496b4cac81SBjoern A. Zeeb 5506b4cac81SBjoern A. Zeeb static int 5516b4cac81SBjoern A. Zeeb lkpi_iv_key_delete(struct ieee80211vap *vap, const struct ieee80211_key *k) 5526b4cac81SBjoern A. Zeeb { 5536b4cac81SBjoern A. Zeeb 5546b4cac81SBjoern A. Zeeb /* XXX-BZ one day we should replace this iterating over VIFs, or node list? */ 5556b4cac81SBjoern A. Zeeb return (_lkpi_iv_key_set_delete(vap, k, DISABLE_KEY)); 5566b4cac81SBjoern A. Zeeb } 5576b4cac81SBjoern A. Zeeb static int 5586b4cac81SBjoern A. Zeeb lkpi_iv_key_set(struct ieee80211vap *vap, const struct ieee80211_key *k) 5596b4cac81SBjoern A. Zeeb { 5606b4cac81SBjoern A. Zeeb 5616b4cac81SBjoern A. Zeeb return (_lkpi_iv_key_set_delete(vap, k, SET_KEY)); 5626b4cac81SBjoern A. Zeeb } 5636b4cac81SBjoern A. Zeeb #endif 5646b4cac81SBjoern A. Zeeb 5656b4cac81SBjoern A. Zeeb static u_int 5666b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast_copy(void *arg, struct sockaddr_dl *sdl, u_int cnt) 5676b4cac81SBjoern A. Zeeb { 5686b4cac81SBjoern A. Zeeb struct netdev_hw_addr_list *mc_list; 5696b4cac81SBjoern A. Zeeb struct netdev_hw_addr *addr; 5706b4cac81SBjoern A. Zeeb 5716b4cac81SBjoern A. Zeeb KASSERT(arg != NULL && sdl != NULL, ("%s: arg %p sdl %p cnt %u\n", 5726b4cac81SBjoern A. Zeeb __func__, arg, sdl, cnt)); 5736b4cac81SBjoern A. Zeeb 5746b4cac81SBjoern A. Zeeb mc_list = arg; 5756b4cac81SBjoern A. Zeeb /* If it is on the list already skip it. */ 5766b4cac81SBjoern A. Zeeb netdev_hw_addr_list_for_each(addr, mc_list) { 5776b4cac81SBjoern A. Zeeb if (!memcmp(addr->addr, LLADDR(sdl), sdl->sdl_alen)) 5786b4cac81SBjoern A. Zeeb return (0); 5796b4cac81SBjoern A. Zeeb } 5806b4cac81SBjoern A. Zeeb 5816b4cac81SBjoern A. Zeeb addr = malloc(sizeof(*addr), M_LKPI80211, M_NOWAIT | M_ZERO); 5826b4cac81SBjoern A. Zeeb if (addr == NULL) 5836b4cac81SBjoern A. Zeeb return (0); 5846b4cac81SBjoern A. Zeeb 5856b4cac81SBjoern A. Zeeb INIT_LIST_HEAD(&addr->addr_list); 5866b4cac81SBjoern A. Zeeb memcpy(addr->addr, LLADDR(sdl), sdl->sdl_alen); 5876b4cac81SBjoern A. Zeeb /* XXX this should be a netdev function? */ 5886b4cac81SBjoern A. Zeeb list_add(&addr->addr_list, &mc_list->addr_list); 5896b4cac81SBjoern A. Zeeb mc_list->count++; 5906b4cac81SBjoern A. Zeeb 5916b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE) 5926b4cac81SBjoern A. Zeeb printf("%s:%d: mc_list count %d: added %6D\n", 5936b4cac81SBjoern A. Zeeb __func__, __LINE__, mc_list->count, addr->addr, ":"); 5946b4cac81SBjoern A. Zeeb 5956b4cac81SBjoern A. Zeeb return (1); 5966b4cac81SBjoern A. Zeeb } 5976b4cac81SBjoern A. Zeeb 5986b4cac81SBjoern A. Zeeb static void 5996b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(struct ieee80211com *ic, bool force) 6006b4cac81SBjoern A. Zeeb { 6016b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 6026b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 6036b4cac81SBjoern A. Zeeb struct netdev_hw_addr_list mc_list; 6046b4cac81SBjoern A. Zeeb struct list_head *le, *next; 6056b4cac81SBjoern A. Zeeb struct netdev_hw_addr *addr; 6066b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 6076b4cac81SBjoern A. Zeeb u64 mc; 6086b4cac81SBjoern A. Zeeb unsigned int changed_flags, total_flags; 6096b4cac81SBjoern A. Zeeb 6106b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 6116b4cac81SBjoern A. Zeeb 6126b4cac81SBjoern A. Zeeb if (lhw->ops->prepare_multicast == NULL || 6136b4cac81SBjoern A. Zeeb lhw->ops->configure_filter == NULL) 6146b4cac81SBjoern A. Zeeb return; 6156b4cac81SBjoern A. Zeeb 6166b4cac81SBjoern A. Zeeb if (!lhw->update_mc && !force) 6176b4cac81SBjoern A. Zeeb return; 6186b4cac81SBjoern A. Zeeb 6196b4cac81SBjoern A. Zeeb changed_flags = total_flags = 0; 6206b4cac81SBjoern A. Zeeb mc_list.count = 0; 6216b4cac81SBjoern A. Zeeb INIT_LIST_HEAD(&mc_list.addr_list); 6226b4cac81SBjoern A. Zeeb if (ic->ic_allmulti == 0) { 6236b4cac81SBjoern A. Zeeb TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) 6246b4cac81SBjoern A. Zeeb if_foreach_llmaddr(vap->iv_ifp, 6256b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast_copy, &mc_list); 6266b4cac81SBjoern A. Zeeb } else { 6276b4cac81SBjoern A. Zeeb changed_flags |= FIF_ALLMULTI; 6286b4cac81SBjoern A. Zeeb } 6296b4cac81SBjoern A. Zeeb 6306b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 6316b4cac81SBjoern A. Zeeb mc = lkpi_80211_mo_prepare_multicast(hw, &mc_list); 6326b4cac81SBjoern A. Zeeb /* 6336b4cac81SBjoern A. Zeeb * XXX-BZ make sure to get this sorted what is a change, 6346b4cac81SBjoern A. Zeeb * what gets all set; what was already set? 6356b4cac81SBjoern A. Zeeb */ 6366b4cac81SBjoern A. Zeeb total_flags = changed_flags; 6376b4cac81SBjoern A. Zeeb lkpi_80211_mo_configure_filter(hw, changed_flags, &total_flags, mc); 6386b4cac81SBjoern A. Zeeb 6396b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE) 6406b4cac81SBjoern A. Zeeb printf("%s: changed_flags %#06x count %d total_flags %#010x\n", 6416b4cac81SBjoern A. Zeeb __func__, changed_flags, mc_list.count, total_flags); 6426b4cac81SBjoern A. Zeeb 6436b4cac81SBjoern A. Zeeb if (mc_list.count != 0) { 6446b4cac81SBjoern A. Zeeb list_for_each_safe(le, next, &mc_list.addr_list) { 6456b4cac81SBjoern A. Zeeb addr = list_entry(le, struct netdev_hw_addr, addr_list); 6466b4cac81SBjoern A. Zeeb free(addr, M_LKPI80211); 6476b4cac81SBjoern A. Zeeb mc_list.count--; 6486b4cac81SBjoern A. Zeeb } 6496b4cac81SBjoern A. Zeeb } 6506b4cac81SBjoern A. Zeeb KASSERT(mc_list.count == 0, ("%s: mc_list %p count %d != 0\n", 6516b4cac81SBjoern A. Zeeb __func__, &mc_list, mc_list.count)); 6526b4cac81SBjoern A. Zeeb } 6536b4cac81SBjoern A. Zeeb 654*fa8f007dSBjoern A. Zeeb static enum ieee80211_bss_changed 655*fa8f007dSBjoern A. Zeeb lkpi_update_dtim_tsf(struct ieee80211_vif *vif, struct ieee80211_node *ni, 656*fa8f007dSBjoern A. Zeeb struct ieee80211vap *vap, const char *_f, int _l) 657*fa8f007dSBjoern A. Zeeb { 658*fa8f007dSBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 659*fa8f007dSBjoern A. Zeeb 660*fa8f007dSBjoern A. Zeeb bss_changed = 0; 661*fa8f007dSBjoern A. Zeeb 662*fa8f007dSBjoern A. Zeeb if (debug_80211 & D80211_TRACE) 663*fa8f007dSBjoern A. Zeeb printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u " 664*fa8f007dSBjoern A. Zeeb "dtim_period %u sync_dtim_count %u sync_tsf %ju " 665*fa8f007dSBjoern A. Zeeb "sync_device_ts %u bss_changed %#08x\n", 666*fa8f007dSBjoern A. Zeeb __func__, __LINE__, _f, _l, 667*fa8f007dSBjoern A. Zeeb vif->bss_conf.assoc, vif->bss_conf.aid, 668*fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int, vif->bss_conf.dtim_period, 669*fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count, 670*fa8f007dSBjoern A. Zeeb (uintmax_t)vif->bss_conf.sync_tsf, 671*fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_device_ts, 672*fa8f007dSBjoern A. Zeeb bss_changed); 673*fa8f007dSBjoern A. Zeeb 674*fa8f007dSBjoern A. Zeeb if (vif->bss_conf.beacon_int != ni->ni_intval) { 675*fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int = ni->ni_intval; 676*fa8f007dSBjoern A. Zeeb /* iwlwifi FW bug workaround; iwl_mvm_mac_sta_state. */ 677*fa8f007dSBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16) 678*fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int = 16; 679*fa8f007dSBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INT; 680*fa8f007dSBjoern A. Zeeb } 681*fa8f007dSBjoern A. Zeeb if (vif->bss_conf.dtim_period != vap->iv_dtim_period && 682*fa8f007dSBjoern A. Zeeb vap->iv_dtim_period > 0) { 683*fa8f007dSBjoern A. Zeeb vif->bss_conf.dtim_period = vap->iv_dtim_period; 684*fa8f007dSBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INFO; 685*fa8f007dSBjoern A. Zeeb } 686*fa8f007dSBjoern A. Zeeb 687*fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count = vap->iv_dtim_count; 688*fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_tsf = le64toh(ni->ni_tstamp.tsf); 689*fa8f007dSBjoern A. Zeeb /* vif->bss_conf.sync_device_ts = set in linuxkpi_ieee80211_rx. */ 690*fa8f007dSBjoern A. Zeeb 691*fa8f007dSBjoern A. Zeeb if (debug_80211 & D80211_TRACE) 692*fa8f007dSBjoern A. Zeeb printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u " 693*fa8f007dSBjoern A. Zeeb "dtim_period %u sync_dtim_count %u sync_tsf %ju " 694*fa8f007dSBjoern A. Zeeb "sync_device_ts %u bss_changed %#08x\n", 695*fa8f007dSBjoern A. Zeeb __func__, __LINE__, _f, _l, 696*fa8f007dSBjoern A. Zeeb vif->bss_conf.assoc, vif->bss_conf.aid, 697*fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int, vif->bss_conf.dtim_period, 698*fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count, 699*fa8f007dSBjoern A. Zeeb (uintmax_t)vif->bss_conf.sync_tsf, 700*fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_device_ts, 701*fa8f007dSBjoern A. Zeeb bss_changed); 702*fa8f007dSBjoern A. Zeeb 703*fa8f007dSBjoern A. Zeeb return (bss_changed); 704*fa8f007dSBjoern A. Zeeb } 705*fa8f007dSBjoern A. Zeeb 7066b4cac81SBjoern A. Zeeb static void 7076b4cac81SBjoern A. Zeeb lkpi_stop_hw_scan(struct lkpi_hw *lhw, struct ieee80211_vif *vif) 7086b4cac81SBjoern A. Zeeb { 7096b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 7106b4cac81SBjoern A. Zeeb int error; 7116b4cac81SBjoern A. Zeeb 7126b4cac81SBjoern A. Zeeb if ((lhw->scan_flags & LKPI_SCAN_RUNNING) == 0) 7136b4cac81SBjoern A. Zeeb return; 7146b4cac81SBjoern A. Zeeb 7156b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 7166b4cac81SBjoern A. Zeeb 717bec76628SBjoern A. Zeeb IEEE80211_UNLOCK(lhw->ic); 718bec76628SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 7196b4cac81SBjoern A. Zeeb /* Need to cancel the scan. */ 7206b4cac81SBjoern A. Zeeb lkpi_80211_mo_cancel_hw_scan(hw, vif); 7216b4cac81SBjoern A. Zeeb 7226b4cac81SBjoern A. Zeeb /* Need to make sure we see ieee80211_scan_completed. */ 7236b4cac81SBjoern A. Zeeb error = msleep(lhw, &lhw->mtx, 0, "lhwscanstop", hz/2); 724bec76628SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 725bec76628SBjoern A. Zeeb IEEE80211_LOCK(lhw->ic); 7266b4cac81SBjoern A. Zeeb 7276b4cac81SBjoern A. Zeeb if ((lhw->scan_flags & LKPI_SCAN_RUNNING) != 0) 7286b4cac81SBjoern A. Zeeb ic_printf(lhw->ic, "%s: failed to cancel scan: %d (%p, %p)\n", 7296b4cac81SBjoern A. Zeeb __func__, error, lhw, vif); 7306b4cac81SBjoern A. Zeeb } 7316b4cac81SBjoern A. Zeeb 7326b4cac81SBjoern A. Zeeb static void 733086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(struct ieee80211_hw *hw, bool new) 734086be6a8SBjoern A. Zeeb { 735086be6a8SBjoern A. Zeeb struct lkpi_hw *lhw; 736086be6a8SBjoern A. Zeeb int error; 737086be6a8SBjoern A. Zeeb bool old; 738086be6a8SBjoern A. Zeeb 739086be6a8SBjoern A. Zeeb old = hw->conf.flags & IEEE80211_CONF_IDLE; 740086be6a8SBjoern A. Zeeb if (old == new) 741086be6a8SBjoern A. Zeeb return; 742086be6a8SBjoern A. Zeeb 743086be6a8SBjoern A. Zeeb hw->conf.flags ^= IEEE80211_CONF_IDLE; 744086be6a8SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_IDLE); 745086be6a8SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) { 746086be6a8SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 747086be6a8SBjoern A. Zeeb ic_printf(lhw->ic, "ERROR: %s: config %#0x returned %d\n", 748086be6a8SBjoern A. Zeeb __func__, IEEE80211_CONF_CHANGE_IDLE, error); 749086be6a8SBjoern A. Zeeb } 750086be6a8SBjoern A. Zeeb } 751086be6a8SBjoern A. Zeeb 752086be6a8SBjoern A. Zeeb static void 7536b4cac81SBjoern A. Zeeb lkpi_disassoc(struct ieee80211_sta *sta, struct ieee80211_vif *vif, 7546b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw) 7556b4cac81SBjoern A. Zeeb { 7566b4cac81SBjoern A. Zeeb sta->aid = 0; 7576b4cac81SBjoern A. Zeeb if (vif->bss_conf.assoc) { 7586b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 7596b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 7606b4cac81SBjoern A. Zeeb 7616b4cac81SBjoern A. Zeeb lhw->update_mc = true; 7626b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(lhw->ic, true); 7636b4cac81SBjoern A. Zeeb 7646b4cac81SBjoern A. Zeeb changed = 0; 7656b4cac81SBjoern A. Zeeb vif->bss_conf.assoc = false; 7666b4cac81SBjoern A. Zeeb vif->bss_conf.aid = 0; 7676b4cac81SBjoern A. Zeeb changed |= BSS_CHANGED_ASSOC; 7686b4cac81SBjoern A. Zeeb IMPROVE(); 7696b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 7706b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, 7716b4cac81SBjoern A. Zeeb changed); 772086be6a8SBjoern A. Zeeb 773086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true); 7746b4cac81SBjoern A. Zeeb } 7756b4cac81SBjoern A. Zeeb } 7766b4cac81SBjoern A. Zeeb 7776b4cac81SBjoern A. Zeeb static void 7786b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(struct ieee80211_hw *hw, struct ieee80211_sta *sta, 7796b4cac81SBjoern A. Zeeb bool dequeue_seen, bool no_emptyq) 7806b4cac81SBjoern A. Zeeb { 7816b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 7826b4cac81SBjoern A. Zeeb int tid; 7836b4cac81SBjoern A. Zeeb 7846b4cac81SBjoern A. Zeeb /* Wake up all queues to know they are allocated in the driver. */ 7856b4cac81SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 7866b4cac81SBjoern A. Zeeb 7876b4cac81SBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) { 7886b4cac81SBjoern A. Zeeb IMPROVE("station specific?"); 7896b4cac81SBjoern A. Zeeb if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ)) 7906b4cac81SBjoern A. Zeeb continue; 7916b4cac81SBjoern A. Zeeb } else if (tid >= hw->queues) 7926b4cac81SBjoern A. Zeeb continue; 7936b4cac81SBjoern A. Zeeb 7946b4cac81SBjoern A. Zeeb if (sta->txq[tid] == NULL) 7956b4cac81SBjoern A. Zeeb continue; 7966b4cac81SBjoern A. Zeeb 7976b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]); 7986b4cac81SBjoern A. Zeeb if (dequeue_seen && !ltxq->seen_dequeue) 7996b4cac81SBjoern A. Zeeb continue; 8006b4cac81SBjoern A. Zeeb 8016b4cac81SBjoern A. Zeeb if (no_emptyq && skb_queue_empty(<xq->skbq)) 8026b4cac81SBjoern A. Zeeb continue; 8036b4cac81SBjoern A. Zeeb 8046b4cac81SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, sta->txq[tid]); 8056b4cac81SBjoern A. Zeeb } 8066b4cac81SBjoern A. Zeeb } 8076b4cac81SBjoern A. Zeeb 8086b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 8096b4cac81SBjoern A. Zeeb 8106b4cac81SBjoern A. Zeeb static int 8116b4cac81SBjoern A. Zeeb lkpi_sta_state_do_nada(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 8126b4cac81SBjoern A. Zeeb { 8136b4cac81SBjoern A. Zeeb 8146b4cac81SBjoern A. Zeeb return (0); 8156b4cac81SBjoern A. Zeeb } 8166b4cac81SBjoern A. Zeeb 8176b4cac81SBjoern A. Zeeb /* lkpi_iv_newstate() handles the stop scan case generally. */ 8186b4cac81SBjoern A. Zeeb #define lkpi_sta_scan_to_init(_v, _n, _a) lkpi_sta_state_do_nada(_v, _n, _a) 8196b4cac81SBjoern A. Zeeb 8206b4cac81SBjoern A. Zeeb static int 8216b4cac81SBjoern A. Zeeb lkpi_sta_scan_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 8226b4cac81SBjoern A. Zeeb { 8236b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 8246b4cac81SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 8256b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 8266b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 8276b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 8286b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 8296b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 8306b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 8316b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 8326b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 8336b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 8346b4cac81SBjoern A. Zeeb uint32_t changed; 8356b4cac81SBjoern A. Zeeb int error; 8366b4cac81SBjoern A. Zeeb 8376b4cac81SBjoern A. Zeeb chan = lkpi_get_lkpi80211_chan(vap->iv_ic, vap->iv_bss); 8386b4cac81SBjoern A. Zeeb if (chan == NULL) { 8396b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: failed to get channel\n", __func__); 8406b4cac81SBjoern A. Zeeb return (ESRCH); 8416b4cac81SBjoern A. Zeeb } 8426b4cac81SBjoern A. Zeeb 8436b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 8446b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 8456b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 8466b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 8476b4cac81SBjoern A. Zeeb 8486b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 8496b4cac81SBjoern A. Zeeb 8506b4cac81SBjoern A. Zeeb /* Add chanctx (or if exists, change it). */ 8516b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 8526b4cac81SBjoern A. Zeeb conf = vif->chanctx_conf; 8536b4cac81SBjoern A. Zeeb IMPROVE("diff changes for changed, working on live copy, rcu"); 8546b4cac81SBjoern A. Zeeb } else { 8556b4cac81SBjoern A. Zeeb /* Keep separate alloc as in Linux this is rcu managed? */ 8566b4cac81SBjoern A. Zeeb conf = malloc(sizeof(*conf) + hw->chanctx_data_size, 8576b4cac81SBjoern A. Zeeb M_LKPI80211, M_WAITOK | M_ZERO); 8586b4cac81SBjoern A. Zeeb } 8596b4cac81SBjoern A. Zeeb 8606b4cac81SBjoern A. Zeeb conf->rx_chains_dynamic = 1; 8616b4cac81SBjoern A. Zeeb conf->rx_chains_static = 1; 8626b4cac81SBjoern A. Zeeb conf->radar_enabled = 8636b4cac81SBjoern A. Zeeb (chan->flags & IEEE80211_CHAN_RADAR) ? true : false; 8646b4cac81SBjoern A. Zeeb conf->def.chan = chan; 8656b4cac81SBjoern A. Zeeb conf->def.width = NL80211_CHAN_WIDTH_20_NOHT; 8666b4cac81SBjoern A. Zeeb conf->def.center_freq1 = chan->center_freq; 8676b4cac81SBjoern A. Zeeb conf->def.center_freq2 = 0; 8686b4cac81SBjoern A. Zeeb /* Responder ... */ 8696b4cac81SBjoern A. Zeeb conf->min_def.chan = chan; 8706b4cac81SBjoern A. Zeeb conf->min_def.width = NL80211_CHAN_WIDTH_20_NOHT; 8716b4cac81SBjoern A. Zeeb conf->min_def.center_freq1 = chan->center_freq; 8726b4cac81SBjoern A. Zeeb conf->min_def.center_freq2 = 0; 8736b4cac81SBjoern A. Zeeb IMPROVE("currently 20_NOHT only"); 8746b4cac81SBjoern A. Zeeb 8756b4cac81SBjoern A. Zeeb ni = NULL; 8766b4cac81SBjoern A. Zeeb error = 0; 8776b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 8786b4cac81SBjoern A. Zeeb changed = IEEE80211_CHANCTX_CHANGE_MIN_WIDTH; 8796b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_RADAR; 8806b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_RX_CHAINS; 8816b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_WIDTH; 8826b4cac81SBjoern A. Zeeb lkpi_80211_mo_change_chanctx(hw, conf, changed); 8836b4cac81SBjoern A. Zeeb } else { 8846b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_add_chanctx(hw, conf); 8856b4cac81SBjoern A. Zeeb if (error == 0 || error == EOPNOTSUPP) { 8866b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.chan = conf->def.chan; 8876b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.width = conf->def.width; 8886b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.center_freq1 = 8896b4cac81SBjoern A. Zeeb conf->def.center_freq1; 8906b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.center_freq2 = 8916b4cac81SBjoern A. Zeeb conf->def.center_freq2; 8926b4cac81SBjoern A. Zeeb } else { 8936b4cac81SBjoern A. Zeeb goto out; 8946b4cac81SBjoern A. Zeeb } 8956b4cac81SBjoern A. Zeeb /* Assign vif chanctx. */ 8966b4cac81SBjoern A. Zeeb if (error == 0) 8976b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_assign_vif_chanctx(hw, vif, conf); 8986b4cac81SBjoern A. Zeeb if (error == EOPNOTSUPP) 8996b4cac81SBjoern A. Zeeb error = 0; 9006b4cac81SBjoern A. Zeeb if (error != 0) { 9016b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 9026b4cac81SBjoern A. Zeeb free(conf, M_LKPI80211); 9036b4cac81SBjoern A. Zeeb goto out; 9046b4cac81SBjoern A. Zeeb } 9056b4cac81SBjoern A. Zeeb } 9066b4cac81SBjoern A. Zeeb IMPROVE("update radiotap chan fields too"); 9076b4cac81SBjoern A. Zeeb 9086b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 9096b4cac81SBjoern A. Zeeb 9106b4cac81SBjoern A. Zeeb /* Set bss info (bss_info_changed). */ 9116b4cac81SBjoern A. Zeeb bss_changed = 0; 9126b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(vif->bss_conf.bssid, ni->ni_bssid); 9136b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 9146b4cac81SBjoern A. Zeeb vif->bss_conf.txpower = ni->ni_txpower; 9156b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_TXPOWER; 9166b4cac81SBjoern A. Zeeb vif->bss_conf.idle = false; 9176b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_IDLE; 918c8dafefaSBjoern A. Zeeb 9196b4cac81SBjoern A. Zeeb /* Should almost assert it is this. */ 9206b4cac81SBjoern A. Zeeb vif->bss_conf.assoc = false; 9216b4cac81SBjoern A. Zeeb vif->bss_conf.aid = 0; 922*fa8f007dSBjoern A. Zeeb 923*fa8f007dSBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 924*fa8f007dSBjoern A. Zeeb 9256b4cac81SBjoern A. Zeeb /* RATES */ 9266b4cac81SBjoern A. Zeeb IMPROVE("bss info: not all needs to come now and rates are missing"); 9276b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 9286b4cac81SBjoern A. Zeeb 9296b4cac81SBjoern A. Zeeb /* Add (or adjust) sta and change state (from NOTEXIST) to NONE. */ 9306b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 9316b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 9326b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NOTEXIST, ("%s: lsta %p state not " 9336b4cac81SBjoern A. Zeeb "NOTEXIST: %#x\n", __func__, lsta, lsta->state)); 9346b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 9356b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_NONE); 9366b4cac81SBjoern A. Zeeb if (error != 0) { 9376b4cac81SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 9386b4cac81SBjoern A. Zeeb goto out; 9396b4cac81SBjoern A. Zeeb } 9406b4cac81SBjoern A. Zeeb #if 0 9416b4cac81SBjoern A. Zeeb lsta->added_to_drv = true; /* mo manages. */ 9426b4cac81SBjoern A. Zeeb #endif 9436b4cac81SBjoern A. Zeeb 9446b4cac81SBjoern A. Zeeb /* 9456b4cac81SBjoern A. Zeeb * Wakeup all queues now that sta is there so we have as much time to 9466b4cac81SBjoern A. Zeeb * possibly prepare the queue in the driver to be ready for the 1st 9476b4cac81SBjoern A. Zeeb * packet; lkpi_80211_txq_tx_one() still has a workaround as there 9486b4cac81SBjoern A. Zeeb * is no guarantee or way to check. 9496b4cac81SBjoern A. Zeeb */ 9506b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, false, false); 9516b4cac81SBjoern A. Zeeb 9526b4cac81SBjoern A. Zeeb { 9536b4cac81SBjoern A. Zeeb int i, count; 9546b4cac81SBjoern A. Zeeb 955500be2e8SBjoern A. Zeeb for (i = 3 * (hw->queues + 1); i > 0; i--) { 9566b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 9576b4cac81SBjoern A. Zeeb int tid; 9586b4cac81SBjoern A. Zeeb 9596b4cac81SBjoern A. Zeeb count = 0; 9606b4cac81SBjoern A. Zeeb /* Wake up all queues to know they are allocated in the driver. */ 9616b4cac81SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 9626b4cac81SBjoern A. Zeeb 9636b4cac81SBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) { 9646b4cac81SBjoern A. Zeeb IMPROVE("station specific?"); 9656b4cac81SBjoern A. Zeeb if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ)) 9666b4cac81SBjoern A. Zeeb continue; 9676b4cac81SBjoern A. Zeeb } else if (tid >= hw->queues) 9686b4cac81SBjoern A. Zeeb continue; 9696b4cac81SBjoern A. Zeeb 9706b4cac81SBjoern A. Zeeb if (sta->txq[tid] == NULL) 9716b4cac81SBjoern A. Zeeb continue; 9726b4cac81SBjoern A. Zeeb 9736b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]); 9746b4cac81SBjoern A. Zeeb if (!ltxq->seen_dequeue) 9756b4cac81SBjoern A. Zeeb count++; 9766b4cac81SBjoern A. Zeeb } 9776b4cac81SBjoern A. Zeeb if (count == 0) 9786b4cac81SBjoern A. Zeeb break; 9796b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 9806b4cac81SBjoern A. Zeeb if (count > 0) 981312ba38aSRuslan Makhmatkhanov ic_printf(vap->iv_ic, "%s: waiting for %d queues " 9826b4cac81SBjoern A. Zeeb "to be allocated by driver\n", __func__, count); 9836b4cac81SBjoern A. Zeeb #endif 984500be2e8SBjoern A. Zeeb pause("lkpi80211txq", hz/10); 9856b4cac81SBjoern A. Zeeb } 9866b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 9876b4cac81SBjoern A. Zeeb if (count > 0) 988312ba38aSRuslan Makhmatkhanov ic_printf(vap->iv_ic, "%s: %d queues still not " 9896b4cac81SBjoern A. Zeeb "allocated by driver\n", __func__, count); 9906b4cac81SBjoern A. Zeeb #endif 9916b4cac81SBjoern A. Zeeb } 9926b4cac81SBjoern A. Zeeb 9936b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 9946b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 9956b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 9966b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 9976b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 9986b4cac81SBjoern A. Zeeb 9996b4cac81SBjoern A. Zeeb /* 10006b4cac81SBjoern A. Zeeb * What is going to happen next: 10016b4cac81SBjoern A. Zeeb * - <twiddle> .. we should end up in "auth_to_assoc" 10026b4cac81SBjoern A. Zeeb * - event_callback 10036b4cac81SBjoern A. Zeeb * - update sta_state (NONE to AUTH) 10046b4cac81SBjoern A. Zeeb * - mgd_complete_tx 10056b4cac81SBjoern A. Zeeb * (ideally we'd do that on a callback for something else ...) 10066b4cac81SBjoern A. Zeeb */ 10076b4cac81SBjoern A. Zeeb 10086b4cac81SBjoern A. Zeeb out: 10096b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 10106b4cac81SBjoern A. Zeeb if (ni != NULL) 10116b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 10126b4cac81SBjoern A. Zeeb return (error); 10136b4cac81SBjoern A. Zeeb } 10146b4cac81SBjoern A. Zeeb 10156b4cac81SBjoern A. Zeeb static int 10166b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 10176b4cac81SBjoern A. Zeeb { 10186b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 10196b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 10206b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 10216b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 10226b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 10236b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 10246b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 10256b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 10266b4cac81SBjoern A. Zeeb int error; 10276b4cac81SBjoern A. Zeeb 10286b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 10296b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 10306b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 10316b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 10326b4cac81SBjoern A. Zeeb 10336b4cac81SBjoern A. Zeeb /* Keep ni around. */ 10346b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 10356b4cac81SBjoern A. Zeeb 10366b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 10376b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 10386b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 10396b4cac81SBjoern A. Zeeb 10406b4cac81SBjoern A. Zeeb /* flush, drop. */ 10416b4cac81SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 10426b4cac81SBjoern A. Zeeb 10436b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 10446b4cac81SBjoern A. Zeeb 10456b4cac81SBjoern A. Zeeb /* Call iv_newstate first so we get potential deauth packet out. */ 10466b4cac81SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 10476b4cac81SBjoern A. Zeeb if (error != 0) 10486b4cac81SBjoern A. Zeeb goto outni; 10496b4cac81SBjoern A. Zeeb 10506b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 10516b4cac81SBjoern A. Zeeb 10526b4cac81SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 10536b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 10546b4cac81SBjoern A. Zeeb 10556b4cac81SBjoern A. Zeeb /* flush, no drop */ 10566b4cac81SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 10576b4cac81SBjoern A. Zeeb 10586b4cac81SBjoern A. Zeeb /* Take the station and chan ctx down again. */ 10596b4cac81SBjoern A. Zeeb 10606b4cac81SBjoern A. Zeeb IMPROVE("event callback with failure?"); 10616b4cac81SBjoern A. Zeeb 10626b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 10636b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 10646b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 10656b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 10666b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 10676b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 10686b4cac81SBjoern A. Zeeb } 10696b4cac81SBjoern A. Zeeb 10706b4cac81SBjoern A. Zeeb #ifdef __not_yet__ 10716b4cac81SBjoern A. Zeeb /* sync_rx_queues */ 10726b4cac81SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 10736b4cac81SBjoern A. Zeeb 10746b4cac81SBjoern A. Zeeb /* sta_pre_rcu_remove */ 10756b4cac81SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 10766b4cac81SBjoern A. Zeeb #endif 10776b4cac81SBjoern A. Zeeb 10786b4cac81SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 10796b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 10806b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 10816b4cac81SBjoern A. Zeeb "NONE: %#x\n", __func__, lsta, lsta->state)); 10826b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_NOTEXIST); 10836b4cac81SBjoern A. Zeeb if (error != 0) { 10846b4cac81SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 10856b4cac81SBjoern A. Zeeb goto out; 10866b4cac81SBjoern A. Zeeb } 10876b4cac81SBjoern A. Zeeb #if 0 10886b4cac81SBjoern A. Zeeb lsta->added_to_drv = false; /* mo manages. */ 10896b4cac81SBjoern A. Zeeb #endif 10906b4cac81SBjoern A. Zeeb 10916b4cac81SBjoern A. Zeeb IMPROVE("Any bss_info changes to announce?"); 10926b4cac81SBjoern A. Zeeb 10936b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 10946b4cac81SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 10956b4cac81SBjoern A. Zeeb 10966b4cac81SBjoern A. Zeeb conf = vif->chanctx_conf; 10976b4cac81SBjoern A. Zeeb /* Remove vif context. */ 10986b4cac81SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->chanctx_conf); 10996b4cac81SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 11006b4cac81SBjoern A. Zeeb 11016b4cac81SBjoern A. Zeeb /* Remove chan ctx. */ 11026b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 11036b4cac81SBjoern A. Zeeb free(conf, M_LKPI80211); 11046b4cac81SBjoern A. Zeeb } 11056b4cac81SBjoern A. Zeeb 11066b4cac81SBjoern A. Zeeb /* No need to start a scan; ic_scan_start should do. */ 11076b4cac81SBjoern A. Zeeb 11086b4cac81SBjoern A. Zeeb error = EALREADY; 11096b4cac81SBjoern A. Zeeb out: 11106b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 11116b4cac81SBjoern A. Zeeb outni: 11126b4cac81SBjoern A. Zeeb if (ni != NULL) 11136b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 11146b4cac81SBjoern A. Zeeb return (error); 11156b4cac81SBjoern A. Zeeb } 11166b4cac81SBjoern A. Zeeb 11176b4cac81SBjoern A. Zeeb static int 11186b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 11196b4cac81SBjoern A. Zeeb { 11206b4cac81SBjoern A. Zeeb int error; 11216b4cac81SBjoern A. Zeeb 11226b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_scan(vap, nstate, arg); 11236b4cac81SBjoern A. Zeeb if (error == 0) 11246b4cac81SBjoern A. Zeeb error = lkpi_sta_scan_to_init(vap, nstate, arg); 11256b4cac81SBjoern A. Zeeb return (error); 11266b4cac81SBjoern A. Zeeb } 11276b4cac81SBjoern A. Zeeb 11286b4cac81SBjoern A. Zeeb static int 11296b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 11306b4cac81SBjoern A. Zeeb { 11316b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 11326b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 11336b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 11346b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 11356b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 11366b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 11376b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 11386b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 11396b4cac81SBjoern A. Zeeb int error; 11406b4cac81SBjoern A. Zeeb 11416b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 11426b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 11436b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 11446b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 11456b4cac81SBjoern A. Zeeb 11466b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 11476b4cac81SBjoern A. Zeeb ni = NULL; 11486b4cac81SBjoern A. Zeeb 11496b4cac81SBjoern A. Zeeb /* Finish auth. */ 11506b4cac81SBjoern A. Zeeb IMPROVE("event callback"); 11516b4cac81SBjoern A. Zeeb 11526b4cac81SBjoern A. Zeeb /* Update sta_state (NONE to AUTH). */ 11536b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 11546b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 11556b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 11566b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 11576b4cac81SBjoern A. Zeeb "NONE: %#x\n", __func__, lsta, lsta->state)); 11586b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 11596b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_AUTH); 11606b4cac81SBjoern A. Zeeb if (error != 0) 11616b4cac81SBjoern A. Zeeb goto out; 11626b4cac81SBjoern A. Zeeb 11636b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 11646b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 11656b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 11666b4cac81SBjoern A. Zeeb prep_tx_info.success = true; 11676b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 11686b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 11696b4cac81SBjoern A. Zeeb } 11706b4cac81SBjoern A. Zeeb 11716b4cac81SBjoern A. Zeeb /* Now start assoc. */ 11726b4cac81SBjoern A. Zeeb 11736b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 11746b4cac81SBjoern A. Zeeb if (!lsta->in_mgd) { 11756b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 11766b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 11776b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 11786b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 11796b4cac81SBjoern A. Zeeb } 11806b4cac81SBjoern A. Zeeb 11816b4cac81SBjoern A. Zeeb /* Wake tx queue to get packet out. */ 11826b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 11836b4cac81SBjoern A. Zeeb 11846b4cac81SBjoern A. Zeeb /* 11856b4cac81SBjoern A. Zeeb * <twiddle> .. we end up in "assoc_to_run" 11866b4cac81SBjoern A. Zeeb * - update sta_state (AUTH to ASSOC) 11876b4cac81SBjoern A. Zeeb * - conf_tx [all] 11886b4cac81SBjoern A. Zeeb * - bss_info_changed (assoc, aid, ssid, ..) 11896b4cac81SBjoern A. Zeeb * - change_chanctx (if needed) 11906b4cac81SBjoern A. Zeeb * - event_callback 11916b4cac81SBjoern A. Zeeb * - mgd_complete_tx 11926b4cac81SBjoern A. Zeeb */ 11936b4cac81SBjoern A. Zeeb 11946b4cac81SBjoern A. Zeeb out: 11956b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 11966b4cac81SBjoern A. Zeeb if (ni != NULL) 11976b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 11986b4cac81SBjoern A. Zeeb return (error); 11996b4cac81SBjoern A. Zeeb } 12006b4cac81SBjoern A. Zeeb 12016b4cac81SBjoern A. Zeeb /* auth_to_auth, assoc_to_assoc. */ 12026b4cac81SBjoern A. Zeeb static int 12036b4cac81SBjoern A. Zeeb lkpi_sta_a_to_a(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 12046b4cac81SBjoern A. Zeeb { 12056b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 12066b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 12076b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 12086b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 12096b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 12106b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 12116b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 12126b4cac81SBjoern A. Zeeb 12136b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 12146b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 12156b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 12166b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 12176b4cac81SBjoern A. Zeeb 12186b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 12196b4cac81SBjoern A. Zeeb 12206b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 12216b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 12226b4cac81SBjoern A. Zeeb 12236b4cac81SBjoern A. Zeeb IMPROVE("event callback?"); 12246b4cac81SBjoern A. Zeeb 12256b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 12266b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 12276b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 12286b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 12296b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 12306b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 12316b4cac81SBjoern A. Zeeb } 12326b4cac81SBjoern A. Zeeb 12336b4cac81SBjoern A. Zeeb /* Now start assoc. */ 12346b4cac81SBjoern A. Zeeb 12356b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 12366b4cac81SBjoern A. Zeeb if (!lsta->in_mgd) { 12376b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 12386b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 12396b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 12406b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 12416b4cac81SBjoern A. Zeeb } 12426b4cac81SBjoern A. Zeeb 12436b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 12446b4cac81SBjoern A. Zeeb if (ni != NULL) 12456b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 12466b4cac81SBjoern A. Zeeb 12476b4cac81SBjoern A. Zeeb return (0); 12486b4cac81SBjoern A. Zeeb } 12496b4cac81SBjoern A. Zeeb 12506b4cac81SBjoern A. Zeeb static int 12516b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 12526b4cac81SBjoern A. Zeeb { 12536b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 12546b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 12556b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 12566b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 12576b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 12586b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 12596b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 12606b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 12616b4cac81SBjoern A. Zeeb int error; 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 /* Keep ni around. */ 12696b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 12706b4cac81SBjoern A. Zeeb 12716b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 12726b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 12736b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 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 /* Update sta and change state (from AUTH) to NONE. */ 12846b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 12856b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 12866b4cac81SBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 12876b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_NONE); 12886b4cac81SBjoern A. Zeeb if (error != 0) 12896b4cac81SBjoern A. Zeeb goto out; 12906b4cac81SBjoern A. Zeeb 12916b4cac81SBjoern A. Zeeb IMPROVE("anything else?"); 12926b4cac81SBjoern A. Zeeb 12936b4cac81SBjoern A. Zeeb out: 12946b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 12956b4cac81SBjoern A. Zeeb if (ni != NULL) 12966b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 12976b4cac81SBjoern A. Zeeb return (error); 12986b4cac81SBjoern A. Zeeb } 12996b4cac81SBjoern A. Zeeb 13006b4cac81SBjoern A. Zeeb static int 13016b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 13026b4cac81SBjoern A. Zeeb { 13036b4cac81SBjoern A. Zeeb int error; 13046b4cac81SBjoern A. Zeeb 13056b4cac81SBjoern A. Zeeb error = lkpi_sta_assoc_to_auth(vap, nstate, arg); 13066b4cac81SBjoern A. Zeeb if (error == 0) 13076b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_scan(vap, nstate, arg); 13086b4cac81SBjoern A. Zeeb return (error); 13096b4cac81SBjoern A. Zeeb } 13106b4cac81SBjoern A. Zeeb 13116b4cac81SBjoern A. Zeeb static int 13126b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 13136b4cac81SBjoern A. Zeeb { 13146b4cac81SBjoern A. Zeeb int error; 13156b4cac81SBjoern A. Zeeb 13166b4cac81SBjoern A. Zeeb error = lkpi_sta_assoc_to_scan(vap, nstate, arg); 13176b4cac81SBjoern A. Zeeb if (error == 0) 13186b4cac81SBjoern A. Zeeb error = lkpi_sta_scan_to_init(vap, nstate, arg); 13196b4cac81SBjoern A. Zeeb return (error); 13206b4cac81SBjoern A. Zeeb } 13216b4cac81SBjoern A. Zeeb 13226b4cac81SBjoern A. Zeeb static int 13236b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 13246b4cac81SBjoern A. Zeeb { 13256b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 13266b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 13276b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 13286b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 13296b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 13306b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 13316b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 13326b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 13336b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 13346b4cac81SBjoern A. Zeeb int error; 13356b4cac81SBjoern A. Zeeb 13366b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 13376b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 13386b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 13396b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 13406b4cac81SBjoern A. Zeeb 13416b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 13426b4cac81SBjoern A. Zeeb ni = NULL; 13436b4cac81SBjoern A. Zeeb 13446b4cac81SBjoern A. Zeeb IMPROVE("ponder some of this moved to ic_newassoc, scan_assoc_success, " 13456b4cac81SBjoern A. Zeeb "and to lesser extend ieee80211_notify_node_join"); 13466b4cac81SBjoern A. Zeeb 13476b4cac81SBjoern A. Zeeb /* Finish assoc. */ 13486b4cac81SBjoern A. Zeeb /* Update sta_state (AUTH to ASSOC) and set aid. */ 13496b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 13506b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 13516b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 13526b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 13536b4cac81SBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 13546b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 13556b4cac81SBjoern A. Zeeb sta->aid = IEEE80211_NODE_AID(ni); 13566b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_ASSOC); 13576b4cac81SBjoern A. Zeeb if (error != 0) 13586b4cac81SBjoern A. Zeeb goto out; 13596b4cac81SBjoern A. Zeeb 13606b4cac81SBjoern A. Zeeb IMPROVE("wme / conf_tx [all]"); 13616b4cac81SBjoern A. Zeeb 13626b4cac81SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 13636b4cac81SBjoern A. Zeeb bss_changed = 0; 13646b4cac81SBjoern A. Zeeb if (!vif->bss_conf.assoc || vif->bss_conf.aid != IEEE80211_NODE_AID(ni)) { 13656b4cac81SBjoern A. Zeeb vif->bss_conf.assoc = true; 13666b4cac81SBjoern A. Zeeb vif->bss_conf.aid = IEEE80211_NODE_AID(ni); 13676b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_ASSOC; 13686b4cac81SBjoern A. Zeeb } 13696b4cac81SBjoern A. Zeeb /* We set SSID but this is not BSSID! */ 13706b4cac81SBjoern A. Zeeb vif->bss_conf.ssid_len = ni->ni_esslen; 13716b4cac81SBjoern A. Zeeb memcpy(vif->bss_conf.ssid, ni->ni_essid, ni->ni_esslen); 13726b4cac81SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_SHPREAMBLE) != 13736b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble) { 13746b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble ^= 1; 13756b4cac81SBjoern A. Zeeb /* bss_changed |= BSS_CHANGED_??? */ 13766b4cac81SBjoern A. Zeeb } 13776b4cac81SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_SHSLOT) != 13786b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot) { 13796b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot ^= 1; 13806b4cac81SBjoern A. Zeeb /* bss_changed |= BSS_CHANGED_??? */ 13816b4cac81SBjoern A. Zeeb } 13826b4cac81SBjoern A. Zeeb if ((ni->ni_flags & IEEE80211_NODE_QOS) != 13836b4cac81SBjoern A. Zeeb vif->bss_conf.qos) { 13846b4cac81SBjoern A. Zeeb vif->bss_conf.qos ^= 1; 13856b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 13866b4cac81SBjoern A. Zeeb } 1387*fa8f007dSBjoern A. Zeeb 1388*fa8f007dSBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 1389*fa8f007dSBjoern A. Zeeb 13906b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 13916b4cac81SBjoern A. Zeeb 13926b4cac81SBjoern A. Zeeb /* - change_chanctx (if needed) 13936b4cac81SBjoern A. Zeeb * - event_callback 13946b4cac81SBjoern A. Zeeb */ 13956b4cac81SBjoern A. Zeeb 13966b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 13976b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 13986b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 13996b4cac81SBjoern A. Zeeb prep_tx_info.success = true; 14006b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 14016b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 14026b4cac81SBjoern A. Zeeb } 14036b4cac81SBjoern A. Zeeb 1404086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, false); 1405086be6a8SBjoern A. Zeeb 14066b4cac81SBjoern A. Zeeb /* 14076b4cac81SBjoern A. Zeeb * And then: 14086b4cac81SBjoern A. Zeeb * - (more packets)? 14096b4cac81SBjoern A. Zeeb * - set_key 14106b4cac81SBjoern A. Zeeb * - set_default_unicast_key 14116b4cac81SBjoern A. Zeeb * - set_key (?) 14126b4cac81SBjoern A. Zeeb * - ipv6_addr_change (?) 14136b4cac81SBjoern A. Zeeb */ 14146b4cac81SBjoern A. Zeeb /* Prepare_multicast && configure_filter. */ 14156b4cac81SBjoern A. Zeeb lhw->update_mc = true; 14166b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(vap->iv_ic, true); 14176b4cac81SBjoern A. Zeeb 14186b4cac81SBjoern A. Zeeb if (!ieee80211_node_is_authorized(ni)) { 14196b4cac81SBjoern A. Zeeb IMPROVE("net80211 does not consider node authorized"); 14206b4cac81SBjoern A. Zeeb } 14216b4cac81SBjoern A. Zeeb 14226b4cac81SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTHORIZED). */ 14236b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 14246b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 14256b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 14266b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 14276b4cac81SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 14286b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 14296b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_AUTHORIZED); 14306b4cac81SBjoern A. Zeeb if (error != 0) { 14316b4cac81SBjoern A. Zeeb IMPROVE("undo some changes?"); 14326b4cac81SBjoern A. Zeeb goto out; 14336b4cac81SBjoern A. Zeeb } 14346b4cac81SBjoern A. Zeeb 14356b4cac81SBjoern A. Zeeb /* - drv_config (?) 14366b4cac81SBjoern A. Zeeb * - bss_info_changed 14376b4cac81SBjoern A. Zeeb * - set_rekey_data (?) 14386b4cac81SBjoern A. Zeeb * 14396b4cac81SBjoern A. Zeeb * And now we should be passing packets. 14406b4cac81SBjoern A. Zeeb */ 14416b4cac81SBjoern A. Zeeb IMPROVE("Need that bssid setting, and the keys"); 14426b4cac81SBjoern A. Zeeb 1443*fa8f007dSBjoern A. Zeeb bss_changed = 0; 1444*fa8f007dSBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 1445*fa8f007dSBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 1446*fa8f007dSBjoern A. Zeeb 14476b4cac81SBjoern A. Zeeb out: 14486b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 14496b4cac81SBjoern A. Zeeb if (ni != NULL) 14506b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 14516b4cac81SBjoern A. Zeeb return (error); 14526b4cac81SBjoern A. Zeeb } 14536b4cac81SBjoern A. Zeeb 14546b4cac81SBjoern A. Zeeb static int 14556b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 14566b4cac81SBjoern A. Zeeb { 14576b4cac81SBjoern A. Zeeb int error; 14586b4cac81SBjoern A. Zeeb 14596b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_assoc(vap, nstate, arg); 14606b4cac81SBjoern A. Zeeb if (error == 0) 14616b4cac81SBjoern A. Zeeb error = lkpi_sta_assoc_to_run(vap, nstate, arg); 14626b4cac81SBjoern A. Zeeb return (error); 14636b4cac81SBjoern A. Zeeb } 14646b4cac81SBjoern A. Zeeb 14656b4cac81SBjoern A. Zeeb static int 14666b4cac81SBjoern A. Zeeb lkpi_sta_run_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 14676b4cac81SBjoern A. Zeeb { 14686b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 14696b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 14706b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 14716b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 14726b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 14736b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 14746b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 14756b4cac81SBjoern A. Zeeb int error; 14766b4cac81SBjoern A. Zeeb 14776b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 14786b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 14796b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 14806b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 14816b4cac81SBjoern A. Zeeb 14826b4cac81SBjoern A. Zeeb /* Keep ni around. */ 14836b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 14846b4cac81SBjoern A. Zeeb 14856b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 14866b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 14876b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 14886b4cac81SBjoern A. Zeeb 14896b4cac81SBjoern A. Zeeb /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */ 14906b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 14916b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not " 14926b4cac81SBjoern A. Zeeb "AUTHORIZED: %#x\n", __func__, lsta, lsta->state)); 14936b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_ASSOC); 14946b4cac81SBjoern A. Zeeb if (error != 0) 14956b4cac81SBjoern A. Zeeb goto out; 14966b4cac81SBjoern A. Zeeb 14976b4cac81SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 14986b4cac81SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw); 14996b4cac81SBjoern A. Zeeb 15006b4cac81SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTH). */ 15016b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 15026b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 15036b4cac81SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 15046b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 15056b4cac81SBjoern A. Zeeb sta->aid = 0; 15066b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_AUTH); 15076b4cac81SBjoern A. Zeeb if (error != 0) 15086b4cac81SBjoern A. Zeeb goto out; 15096b4cac81SBjoern A. Zeeb 15106b4cac81SBjoern A. Zeeb IMPROVE("if ASSOC is final state, prep_tx_info?"); 15116b4cac81SBjoern A. Zeeb 15126b4cac81SBjoern A. Zeeb out: 15136b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 15146b4cac81SBjoern A. Zeeb if (ni != NULL) 15156b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 15166b4cac81SBjoern A. Zeeb return (error); 15176b4cac81SBjoern A. Zeeb } 15186b4cac81SBjoern A. Zeeb 15196b4cac81SBjoern A. Zeeb static int 15206b4cac81SBjoern A. Zeeb lkpi_sta_run_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 15216b4cac81SBjoern A. Zeeb { 15226b4cac81SBjoern A. Zeeb int error; 15236b4cac81SBjoern A. Zeeb 15246b4cac81SBjoern A. Zeeb error = lkpi_sta_run_to_assoc(vap, nstate, arg); 15256b4cac81SBjoern A. Zeeb if (error == 0) 15266b4cac81SBjoern A. Zeeb error = lkpi_sta_assoc_to_auth(vap, nstate, arg); 15276b4cac81SBjoern A. Zeeb return (error); 15286b4cac81SBjoern A. Zeeb } 15296b4cac81SBjoern A. Zeeb 15306b4cac81SBjoern A. Zeeb static int 15316b4cac81SBjoern A. Zeeb lkpi_sta_run_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 15326b4cac81SBjoern A. Zeeb { 15336b4cac81SBjoern A. Zeeb int error; 15346b4cac81SBjoern A. Zeeb 15356b4cac81SBjoern A. Zeeb error = lkpi_sta_run_to_auth(vap, nstate, arg); 15366b4cac81SBjoern A. Zeeb if (error == 0) 15376b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_scan(vap, nstate, arg); 15386b4cac81SBjoern A. Zeeb return (error); 15396b4cac81SBjoern A. Zeeb } 15406b4cac81SBjoern A. Zeeb 15416b4cac81SBjoern A. Zeeb static int 15426b4cac81SBjoern A. Zeeb lkpi_sta_run_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 15436b4cac81SBjoern A. Zeeb { 15446b4cac81SBjoern A. Zeeb int error; 15456b4cac81SBjoern A. Zeeb 15466b4cac81SBjoern A. Zeeb error = lkpi_sta_run_to_scan(vap, nstate, arg); 15476b4cac81SBjoern A. Zeeb if (error == 0) 15486b4cac81SBjoern A. Zeeb error = lkpi_sta_scan_to_init(vap, nstate, arg); 15496b4cac81SBjoern A. Zeeb return (error); 15506b4cac81SBjoern A. Zeeb } 15516b4cac81SBjoern A. Zeeb 15526b4cac81SBjoern A. Zeeb /* 15536b4cac81SBjoern A. Zeeb * The matches the documented state changes in net80211::sta_newstate(). 15546b4cac81SBjoern A. Zeeb * XXX (1) without CSA and SLEEP yet, * XXX (2) not all unhandled cases 15556b4cac81SBjoern A. Zeeb * there are "invalid" (so there is a room for failure here). 15566b4cac81SBjoern A. Zeeb */ 15576b4cac81SBjoern A. Zeeb struct fsm_state { 15586b4cac81SBjoern A. Zeeb /* INIT, SCAN, AUTH, ASSOC, CAC, RUN, CSA, SLEEP */ 15596b4cac81SBjoern A. Zeeb enum ieee80211_state ostate; 15606b4cac81SBjoern A. Zeeb enum ieee80211_state nstate; 15616b4cac81SBjoern A. Zeeb int (*handler)(struct ieee80211vap *, enum ieee80211_state, int); 15626b4cac81SBjoern A. Zeeb } sta_state_fsm[] = { 15636b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, 15646b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, /* scan_to_init */ 15656b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_INIT, lkpi_sta_auth_to_init }, /* not explicitly in sta_newstate() */ 15666b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_INIT, lkpi_sta_assoc_to_init }, 15676b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_INIT, lkpi_sta_run_to_init }, 15686b4cac81SBjoern A. Zeeb 15696b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_SCAN, lkpi_sta_state_do_nada }, 15706b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_SCAN, lkpi_sta_state_do_nada }, 15716b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_SCAN, lkpi_sta_auth_to_scan }, 15726b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_SCAN, lkpi_sta_assoc_to_scan }, 15736b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_SCAN, lkpi_sta_run_to_scan }, 15746b4cac81SBjoern A. Zeeb 15756b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, 15766b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, 15776b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_AUTH, lkpi_sta_a_to_a }, 15786b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_AUTH, lkpi_sta_assoc_to_auth }, 15796b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_AUTH, lkpi_sta_run_to_auth }, 15806b4cac81SBjoern A. Zeeb 15816b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_ASSOC, lkpi_sta_auth_to_assoc }, 15826b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_ASSOC, lkpi_sta_a_to_a }, 15836b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_ASSOC, lkpi_sta_run_to_assoc }, 15846b4cac81SBjoern A. Zeeb 15856b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_RUN, lkpi_sta_auth_to_run }, 15866b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_RUN, lkpi_sta_assoc_to_run }, 15876b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_RUN, lkpi_sta_state_do_nada }, 15886b4cac81SBjoern A. Zeeb 15896b4cac81SBjoern A. Zeeb /* Dummy at the end without handler. */ 15906b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_INIT, NULL }, 15916b4cac81SBjoern A. Zeeb }; 15926b4cac81SBjoern A. Zeeb 15936b4cac81SBjoern A. Zeeb static int 15946b4cac81SBjoern A. Zeeb lkpi_iv_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 15956b4cac81SBjoern A. Zeeb { 15966b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 15976b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 15986b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 15996b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 16006b4cac81SBjoern A. Zeeb struct fsm_state *s; 16016b4cac81SBjoern A. Zeeb enum ieee80211_state ostate; 16026b4cac81SBjoern A. Zeeb int error; 16036b4cac81SBjoern A. Zeeb 16046b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 16056b4cac81SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(ic); 16066b4cac81SBjoern A. Zeeb ostate = vap->iv_state; 16076b4cac81SBjoern A. Zeeb 16086b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE) 16096b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x\n", 16106b4cac81SBjoern A. Zeeb __func__, __LINE__, vap, nstate, arg); 16116b4cac81SBjoern A. Zeeb 16126b4cac81SBjoern A. Zeeb if (vap->iv_opmode == IEEE80211_M_STA) { 16136b4cac81SBjoern A. Zeeb 16146b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 16156b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 16166b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 16176b4cac81SBjoern A. Zeeb 16186b4cac81SBjoern A. Zeeb /* No need to replicate this in most state handlers. */ 16196b4cac81SBjoern A. Zeeb if (ostate == IEEE80211_S_SCAN && nstate != IEEE80211_S_SCAN) 16206b4cac81SBjoern A. Zeeb lkpi_stop_hw_scan(lhw, vif); 16216b4cac81SBjoern A. Zeeb 16226b4cac81SBjoern A. Zeeb s = sta_state_fsm; 16236b4cac81SBjoern A. Zeeb 16246b4cac81SBjoern A. Zeeb } else { 16256b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: only station mode currently supported: " 16266b4cac81SBjoern A. Zeeb "cap %p iv_opmode %d\n", __func__, vap, vap->iv_opmode); 16276b4cac81SBjoern A. Zeeb return (ENOSYS); 16286b4cac81SBjoern A. Zeeb } 16296b4cac81SBjoern A. Zeeb 16306b4cac81SBjoern A. Zeeb error = 0; 16316b4cac81SBjoern A. Zeeb for (; s->handler != NULL; s++) { 16326b4cac81SBjoern A. Zeeb if (ostate == s->ostate && nstate == s->nstate) { 16336b4cac81SBjoern A. Zeeb error = s->handler(vap, nstate, arg); 16346b4cac81SBjoern A. Zeeb break; 16356b4cac81SBjoern A. Zeeb } 16366b4cac81SBjoern A. Zeeb } 16376b4cac81SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(vap->iv_ic); 16386b4cac81SBjoern A. Zeeb 16396b4cac81SBjoern A. Zeeb if (s->handler == NULL) { 16406b4cac81SBjoern A. Zeeb IMPROVE("thurn this into a KASSERT\n"); 16416b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: unsupported state transition " 16426b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s)\n", __func__, 16436b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 16446b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 16456b4cac81SBjoern A. Zeeb return (ENOSYS); 16466b4cac81SBjoern A. Zeeb } 16476b4cac81SBjoern A. Zeeb 16486b4cac81SBjoern A. Zeeb if (error == EALREADY) { 16496b4cac81SBjoern A. Zeeb IMPROVE("make this a debug log later"); 16506b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: error %d during state transition " 16516b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s): iv_newstate already handled.\n", 16526b4cac81SBjoern A. Zeeb __func__, error, 16536b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 16546b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 16556b4cac81SBjoern A. Zeeb return (0); 16566b4cac81SBjoern A. Zeeb } 16576b4cac81SBjoern A. Zeeb 16586b4cac81SBjoern A. Zeeb if (error != 0) { 16596b4cac81SBjoern A. Zeeb /* XXX-BZ currently expected so ignore. */ 16606b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: error %d during state transition " 16616b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s)\n", __func__, error, 16626b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 16636b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 16646b4cac81SBjoern A. Zeeb /* return (error); */ 16656b4cac81SBjoern A. Zeeb } 16666b4cac81SBjoern A. Zeeb 16676b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE) 16686b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x calling net80211 parent\n", 16696b4cac81SBjoern A. Zeeb __func__, __LINE__, vap, nstate, arg); 16706b4cac81SBjoern A. Zeeb 16716b4cac81SBjoern A. Zeeb return (lvif->iv_newstate(vap, nstate, arg)); 16726b4cac81SBjoern A. Zeeb } 16736b4cac81SBjoern A. Zeeb 16746b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 16756b4cac81SBjoern A. Zeeb 16766b4cac81SBjoern A. Zeeb static int 16776b4cac81SBjoern A. Zeeb lkpi_ic_wme_update(struct ieee80211com *ic) 16786b4cac81SBjoern A. Zeeb { 16796b4cac81SBjoern A. Zeeb /* This needs queuing and go at the right moment. */ 16806b4cac81SBjoern A. Zeeb #ifdef WITH_WME_UPDATE 16816b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 16826b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 16836b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 16846b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 16856b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 16866b4cac81SBjoern A. Zeeb struct chanAccParams chp; 16876b4cac81SBjoern A. Zeeb struct wmeParams wmeparr[WME_NUM_AC]; 16886b4cac81SBjoern A. Zeeb struct ieee80211_tx_queue_params txqp; 16896b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 16906b4cac81SBjoern A. Zeeb int error; 16916b4cac81SBjoern A. Zeeb uint16_t ac; 16926b4cac81SBjoern A. Zeeb #endif 16936b4cac81SBjoern A. Zeeb 16946b4cac81SBjoern A. Zeeb IMPROVE(); 16956b4cac81SBjoern A. Zeeb KASSERT(WME_NUM_AC == IEEE80211_NUM_ACS, ("%s: WME_NUM_AC %d != " 16966b4cac81SBjoern A. Zeeb "IEEE80211_NUM_ACS %d\n", __func__, WME_NUM_AC, IEEE80211_NUM_ACS)); 16976b4cac81SBjoern A. Zeeb 16986b4cac81SBjoern A. Zeeb #ifdef WITH_WME_UPDATE 16996b4cac81SBjoern A. Zeeb vap = TAILQ_FIRST(&ic->ic_vaps); 17006b4cac81SBjoern A. Zeeb if (vap == NULL) 17016b4cac81SBjoern A. Zeeb return (0); 17026b4cac81SBjoern A. Zeeb 17036b4cac81SBjoern A. Zeeb /* We should factor this out into per-vap (*wme_update). */ 17046b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 17056b4cac81SBjoern A. Zeeb if (lhw->ops->conf_tx == NULL) 17066b4cac81SBjoern A. Zeeb return (0); 17076b4cac81SBjoern A. Zeeb 17086b4cac81SBjoern A. Zeeb /* XXX-BZ check amount of hw queues */ 17096b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 17106b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 17116b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 17126b4cac81SBjoern A. Zeeb 17136b4cac81SBjoern A. Zeeb ieee80211_wme_ic_getparams(ic, &chp); 17146b4cac81SBjoern A. Zeeb IEEE80211_LOCK(ic); 17156b4cac81SBjoern A. Zeeb for (ac = 0; ac < WME_NUM_AC; ac++) 17166b4cac81SBjoern A. Zeeb wmeparr[ac] = chp.cap_wmeParams[ac]; 17176b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(ic); 17186b4cac81SBjoern A. Zeeb 17196b4cac81SBjoern A. Zeeb /* Configure tx queues (conf_tx) & send BSS_CHANGED_QOS. */ 17206b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 17216b4cac81SBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 17226b4cac81SBjoern A. Zeeb struct wmeParams *wmep; 17236b4cac81SBjoern A. Zeeb 17246b4cac81SBjoern A. Zeeb /* XXX-BZ should keep this in lvif? */ 17256b4cac81SBjoern A. Zeeb wmep = &wmeparr[ac]; 17266b4cac81SBjoern A. Zeeb bzero(&txqp, sizeof(txqp)); 17276b4cac81SBjoern A. Zeeb txqp.cw_min = wmep->wmep_logcwmin; 17286b4cac81SBjoern A. Zeeb txqp.cw_max = wmep->wmep_logcwmax; 17296b4cac81SBjoern A. Zeeb txqp.txop = wmep->wmep_txopLimit; 17306b4cac81SBjoern A. Zeeb txqp.aifs = wmep->wmep_aifsn; 17316b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_conf_tx(hw, vif, ac, &txqp); 17326b4cac81SBjoern A. Zeeb if (error != 0) 17336b4cac81SBjoern A. Zeeb printf("%s: conf_tx ac %u failed %d\n", 17346b4cac81SBjoern A. Zeeb __func__, ac, error); 17356b4cac81SBjoern A. Zeeb } 17366b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 17376b4cac81SBjoern A. Zeeb changed = BSS_CHANGED_QOS; 17386b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 17396b4cac81SBjoern A. Zeeb #endif 17406b4cac81SBjoern A. Zeeb 17416b4cac81SBjoern A. Zeeb return (0); 17426b4cac81SBjoern A. Zeeb } 17436b4cac81SBjoern A. Zeeb 17446b4cac81SBjoern A. Zeeb static struct ieee80211vap * 17456b4cac81SBjoern A. Zeeb lkpi_ic_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], 17466b4cac81SBjoern A. Zeeb int unit, enum ieee80211_opmode opmode, int flags, 17476b4cac81SBjoern A. Zeeb const uint8_t bssid[IEEE80211_ADDR_LEN], 17486b4cac81SBjoern A. Zeeb const uint8_t mac[IEEE80211_ADDR_LEN]) 17496b4cac81SBjoern A. Zeeb { 17506b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 17516b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 17526b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 17536b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 17546b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 17556b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 17566b4cac81SBjoern A. Zeeb size_t len; 17576b4cac81SBjoern A. Zeeb int error; 17586b4cac81SBjoern A. Zeeb 17596b4cac81SBjoern A. Zeeb if (!TAILQ_EMPTY(&ic->ic_vaps)) /* 1 so far. Add <n> once this works. */ 17606b4cac81SBjoern A. Zeeb return (NULL); 17616b4cac81SBjoern A. Zeeb 17626b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 17636b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 17646b4cac81SBjoern A. Zeeb 17656b4cac81SBjoern A. Zeeb len = sizeof(*lvif); 17666b4cac81SBjoern A. Zeeb len += hw->vif_data_size; /* vif->drv_priv */ 17676b4cac81SBjoern A. Zeeb 17686b4cac81SBjoern A. Zeeb lvif = malloc(len, M_80211_VAP, M_WAITOK | M_ZERO); 17696b4cac81SBjoern A. Zeeb mtx_init(&lvif->mtx, "lvif", NULL, MTX_DEF); 17706b4cac81SBjoern A. Zeeb TAILQ_INIT(&lvif->lsta_head); 17716b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 17726b4cac81SBjoern A. Zeeb 17736b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 17746b4cac81SBjoern A. Zeeb memcpy(vif->addr, mac, IEEE80211_ADDR_LEN); 17756b4cac81SBjoern A. Zeeb vif->p2p = false; 17766b4cac81SBjoern A. Zeeb vif->probe_req_reg = false; 17776b4cac81SBjoern A. Zeeb vif->type = lkpi_opmode_to_vif_type(opmode); 17786b4cac81SBjoern A. Zeeb lvif->wdev.iftype = vif->type; 17796b4cac81SBjoern A. Zeeb /* Need to fill in other fields as well. */ 17806b4cac81SBjoern A. Zeeb IMPROVE(); 17816b4cac81SBjoern A. Zeeb 17826b4cac81SBjoern A. Zeeb /* XXX-BZ hardcoded for now! */ 17836b4cac81SBjoern A. Zeeb #if 1 17846b4cac81SBjoern A. Zeeb vif->chanctx_conf = NULL; 17856b4cac81SBjoern A. Zeeb vif->bss_conf.idle = true; 17866b4cac81SBjoern A. Zeeb vif->bss_conf.ps = false; 17876b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.width = NL80211_CHAN_WIDTH_20_NOHT; 17886b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble = false; /* vap->iv_flags IEEE80211_F_SHPREAMBLE */ 17896b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot = false; /* vap->iv_flags IEEE80211_F_SHSLOT */ 17906b4cac81SBjoern A. Zeeb vif->bss_conf.qos = false; 17916b4cac81SBjoern A. Zeeb vif->bss_conf.use_cts_prot = false; /* vap->iv_protmode */ 17926b4cac81SBjoern A. Zeeb vif->bss_conf.ht_operation_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONE; 17936b4cac81SBjoern A. Zeeb vif->bss_conf.assoc = false; 17946b4cac81SBjoern A. Zeeb vif->bss_conf.aid = 0; 17956b4cac81SBjoern A. Zeeb #endif 17966b4cac81SBjoern A. Zeeb #if 0 17976b4cac81SBjoern A. Zeeb vif->bss_conf.dtim_period = 0; /* IEEE80211_DTIM_DEFAULT ; must stay 0. */ 17986b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(vif->bss_conf.bssid, bssid); 17996b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = ic->ic_bintval; 18006b4cac81SBjoern A. Zeeb /* iwlwifi bug. */ 18016b4cac81SBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16) 18026b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = 16; 18036b4cac81SBjoern A. Zeeb #endif 18046b4cac81SBjoern A. Zeeb IMPROVE(); 18056b4cac81SBjoern A. Zeeb 18066b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_start(hw); 18076b4cac81SBjoern A. Zeeb if (error != 0) { 18086b4cac81SBjoern A. Zeeb printf("%s: failed to start hw: %d\n", __func__, error); 18096b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 18106b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 18116b4cac81SBjoern A. Zeeb return (NULL); 18126b4cac81SBjoern A. Zeeb } 18136b4cac81SBjoern A. Zeeb 18146b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_add_interface(hw, vif); 18156b4cac81SBjoern A. Zeeb if (error != 0) { 18166b4cac81SBjoern A. Zeeb IMPROVE(); /* XXX-BZ mo_stop()? */ 18176b4cac81SBjoern A. Zeeb printf("%s: failed to add interface: %d\n", __func__, error); 18186b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 18196b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 18206b4cac81SBjoern A. Zeeb return (NULL); 18216b4cac81SBjoern A. Zeeb } 18226b4cac81SBjoern A. Zeeb 18236b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 18246b4cac81SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lhw->lvif_head, lvif, lvif_entry); 18256b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 18266b4cac81SBjoern A. Zeeb 18276b4cac81SBjoern A. Zeeb /* Set bss_info. */ 18286b4cac81SBjoern A. Zeeb changed = 0; 18296b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 18306b4cac81SBjoern A. Zeeb 18316b4cac81SBjoern A. Zeeb /* conf_tx setup; default WME? */ 18326b4cac81SBjoern A. Zeeb 18336b4cac81SBjoern A. Zeeb /* Force MC init. */ 18346b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(ic, true); 18356b4cac81SBjoern A. Zeeb 18366b4cac81SBjoern A. Zeeb IMPROVE(); 18376b4cac81SBjoern A. Zeeb 18386b4cac81SBjoern A. Zeeb ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid); 18396b4cac81SBjoern A. Zeeb 18406b4cac81SBjoern A. Zeeb /* Override with LinuxKPI method so we can drive mac80211/cfg80211. */ 18416b4cac81SBjoern A. Zeeb lvif->iv_newstate = vap->iv_newstate; 18426b4cac81SBjoern A. Zeeb vap->iv_newstate = lkpi_iv_newstate; 18436b4cac81SBjoern A. Zeeb 18446b4cac81SBjoern A. Zeeb /* Key management. */ 18456b4cac81SBjoern A. Zeeb if (lhw->ops->set_key != NULL) { 18466b4cac81SBjoern A. Zeeb #ifdef TRY_HW_CRYPTO 18476b4cac81SBjoern A. Zeeb vap->iv_key_set = lkpi_iv_key_set; 18486b4cac81SBjoern A. Zeeb vap->iv_key_delete = lkpi_iv_key_delete; 18496b4cac81SBjoern A. Zeeb #endif 18506b4cac81SBjoern A. Zeeb } 18516b4cac81SBjoern A. Zeeb 18526b4cac81SBjoern A. Zeeb ieee80211_ratectl_init(vap); 18536b4cac81SBjoern A. Zeeb 18546b4cac81SBjoern A. Zeeb /* Complete setup. */ 18556b4cac81SBjoern A. Zeeb ieee80211_vap_attach(vap, ieee80211_media_change, 18566b4cac81SBjoern A. Zeeb ieee80211_media_status, mac); 18576b4cac81SBjoern A. Zeeb 18586b4cac81SBjoern A. Zeeb if (hw->max_listen_interval == 0) 18596b4cac81SBjoern A. Zeeb hw->max_listen_interval = 7 * (ic->ic_lintval / ic->ic_bintval); 18606b4cac81SBjoern A. Zeeb hw->conf.listen_interval = hw->max_listen_interval; 18616b4cac81SBjoern A. Zeeb ic->ic_set_channel(ic); 18626b4cac81SBjoern A. Zeeb 18636b4cac81SBjoern A. Zeeb /* XXX-BZ do we need to be able to update these? */ 18646b4cac81SBjoern A. Zeeb hw->wiphy->frag_threshold = vap->iv_fragthreshold; 18656b4cac81SBjoern A. Zeeb lkpi_80211_mo_set_frag_threshold(hw, vap->iv_fragthreshold); 18666b4cac81SBjoern A. Zeeb hw->wiphy->rts_threshold = vap->iv_rtsthreshold; 18676b4cac81SBjoern A. Zeeb lkpi_80211_mo_set_rts_threshold(hw, vap->iv_rtsthreshold); 18686b4cac81SBjoern A. Zeeb /* any others? */ 18696b4cac81SBjoern A. Zeeb IMPROVE(); 18706b4cac81SBjoern A. Zeeb 18716b4cac81SBjoern A. Zeeb return (vap); 18726b4cac81SBjoern A. Zeeb } 18736b4cac81SBjoern A. Zeeb 18746b4cac81SBjoern A. Zeeb static void 18756b4cac81SBjoern A. Zeeb lkpi_ic_vap_delete(struct ieee80211vap *vap) 18766b4cac81SBjoern A. Zeeb { 18776b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 18786b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 18796b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 18806b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 18816b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 18826b4cac81SBjoern A. Zeeb 18836b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 18846b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 18856b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 18866b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 18876b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 18886b4cac81SBjoern A. Zeeb 18896b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 18906b4cac81SBjoern A. Zeeb TAILQ_REMOVE(&lhw->lvif_head, lvif, lvif_entry); 18916b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 18926b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_interface(hw, vif); 18936b4cac81SBjoern A. Zeeb 18946b4cac81SBjoern A. Zeeb ieee80211_ratectl_deinit(vap); 18956b4cac81SBjoern A. Zeeb ieee80211_vap_detach(vap); 18966b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 18976b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 18986b4cac81SBjoern A. Zeeb } 18996b4cac81SBjoern A. Zeeb 19006b4cac81SBjoern A. Zeeb static void 19016b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast(struct ieee80211com *ic) 19026b4cac81SBjoern A. Zeeb { 19036b4cac81SBjoern A. Zeeb 19046b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(ic, false); 19056b4cac81SBjoern A. Zeeb TRACEOK(); 19066b4cac81SBjoern A. Zeeb } 19076b4cac81SBjoern A. Zeeb 19086b4cac81SBjoern A. Zeeb static void 19096b4cac81SBjoern A. Zeeb lkpi_ic_update_promisc(struct ieee80211com *ic) 19106b4cac81SBjoern A. Zeeb { 19116b4cac81SBjoern A. Zeeb 19126b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 19136b4cac81SBjoern A. Zeeb } 19146b4cac81SBjoern A. Zeeb 19156b4cac81SBjoern A. Zeeb static void 19166b4cac81SBjoern A. Zeeb lkpi_ic_update_chw(struct ieee80211com *ic) 19176b4cac81SBjoern A. Zeeb { 19186b4cac81SBjoern A. Zeeb 19196b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 19206b4cac81SBjoern A. Zeeb } 19216b4cac81SBjoern A. Zeeb 19226b4cac81SBjoern A. Zeeb /* Start / stop device. */ 19236b4cac81SBjoern A. Zeeb static void 19246b4cac81SBjoern A. Zeeb lkpi_ic_parent(struct ieee80211com *ic) 19256b4cac81SBjoern A. Zeeb { 19266b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 19276b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 19286b4cac81SBjoern A. Zeeb int error; 19296b4cac81SBjoern A. Zeeb bool start_all; 19306b4cac81SBjoern A. Zeeb 19316b4cac81SBjoern A. Zeeb IMPROVE(); 19326b4cac81SBjoern A. Zeeb 19336b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 19346b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 19356b4cac81SBjoern A. Zeeb start_all = false; 19366b4cac81SBjoern A. Zeeb 19376b4cac81SBjoern A. Zeeb if (ic->ic_nrunning > 0) { 19386b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_start(hw); 19396b4cac81SBjoern A. Zeeb if (error == 0) 19406b4cac81SBjoern A. Zeeb start_all = true; 19416b4cac81SBjoern A. Zeeb } else { 19426b4cac81SBjoern A. Zeeb lkpi_80211_mo_stop(hw); 19436b4cac81SBjoern A. Zeeb } 19446b4cac81SBjoern A. Zeeb 19456b4cac81SBjoern A. Zeeb if (start_all) 19466b4cac81SBjoern A. Zeeb ieee80211_start_all(ic); 19476b4cac81SBjoern A. Zeeb } 19486b4cac81SBjoern A. Zeeb 19496b4cac81SBjoern A. Zeeb bool 19506b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_is_ie_id_in_ie_buf(const u8 ie, const u8 *ie_ids, 19516b4cac81SBjoern A. Zeeb size_t ie_ids_len) 19526b4cac81SBjoern A. Zeeb { 19536b4cac81SBjoern A. Zeeb int i; 19546b4cac81SBjoern A. Zeeb 19556b4cac81SBjoern A. Zeeb for (i = 0; i < ie_ids_len; i++) { 19566b4cac81SBjoern A. Zeeb if (ie == *ie_ids) 19576b4cac81SBjoern A. Zeeb return (true); 19586b4cac81SBjoern A. Zeeb } 19596b4cac81SBjoern A. Zeeb 19606b4cac81SBjoern A. Zeeb return (false); 19616b4cac81SBjoern A. Zeeb } 19626b4cac81SBjoern A. Zeeb 19636b4cac81SBjoern A. Zeeb /* Return true if skipped; false if error. */ 19646b4cac81SBjoern A. Zeeb bool 19656b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ie_advance(size_t *xp, const u8 *ies, size_t ies_len) 19666b4cac81SBjoern A. Zeeb { 19676b4cac81SBjoern A. Zeeb size_t x; 19686b4cac81SBjoern A. Zeeb uint8_t l; 19696b4cac81SBjoern A. Zeeb 19706b4cac81SBjoern A. Zeeb x = *xp; 19716b4cac81SBjoern A. Zeeb 19726b4cac81SBjoern A. Zeeb KASSERT(x < ies_len, ("%s: x %zu ies_len %zu ies %p\n", 19736b4cac81SBjoern A. Zeeb __func__, x, ies_len, ies)); 19746b4cac81SBjoern A. Zeeb l = ies[x + 1]; 19756b4cac81SBjoern A. Zeeb x += 2 + l; 19766b4cac81SBjoern A. Zeeb 19776b4cac81SBjoern A. Zeeb if (x > ies_len) 19786b4cac81SBjoern A. Zeeb return (false); 19796b4cac81SBjoern A. Zeeb 19806b4cac81SBjoern A. Zeeb *xp = x; 19816b4cac81SBjoern A. Zeeb return (true); 19826b4cac81SBjoern A. Zeeb } 19836b4cac81SBjoern A. Zeeb 19846b4cac81SBjoern A. Zeeb static int 19856b4cac81SBjoern A. Zeeb lkpi_ieee80211_probereq_ie_alloc(struct ieee80211vap *vap, 19866b4cac81SBjoern A. Zeeb struct ieee80211com *ic, struct ieee80211_scan_ies *scan_ies, 19876b4cac81SBjoern A. Zeeb const uint8_t *ssid, size_t ssidlen) 19886b4cac81SBjoern A. Zeeb { 19896b4cac81SBjoern A. Zeeb 19906b4cac81SBjoern A. Zeeb return (ieee80211_probereq_ie(vap, ic, 19916b4cac81SBjoern A. Zeeb &scan_ies->common_ies, &scan_ies->common_ie_len, 19926b4cac81SBjoern A. Zeeb ssid, ssidlen, true)); 19936b4cac81SBjoern A. Zeeb } 19946b4cac81SBjoern A. Zeeb 19956b4cac81SBjoern A. Zeeb static void 19966b4cac81SBjoern A. Zeeb lkpi_ic_scan_start(struct ieee80211com *ic) 19976b4cac81SBjoern A. Zeeb { 19986b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 19996b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 20006b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 20016b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 20026b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 20036b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 20046b4cac81SBjoern A. Zeeb int error; 20056b4cac81SBjoern A. Zeeb 20066b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 20076b4cac81SBjoern A. Zeeb if ((lhw->scan_flags & LKPI_SCAN_RUNNING) != 0) { 20086b4cac81SBjoern A. Zeeb /* A scan is still running. */ 20096b4cac81SBjoern A. Zeeb return; 20106b4cac81SBjoern A. Zeeb } 20116b4cac81SBjoern A. Zeeb 20126b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 20136b4cac81SBjoern A. Zeeb vap = ss->ss_vap; 20146b4cac81SBjoern A. Zeeb if (vap->iv_state != IEEE80211_S_SCAN) { 2015d3ef7fb4SBjoern A. Zeeb IMPROVE("We need to be able to scan if not in S_SCAN"); 20166b4cac81SBjoern A. Zeeb return; 20176b4cac81SBjoern A. Zeeb } 20186b4cac81SBjoern A. Zeeb 20196b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 20206b4cac81SBjoern A. Zeeb if ((ic->ic_flags_ext & IEEE80211_FEXT_SCAN_OFFLOAD) == 0) { 2021d3ef7fb4SBjoern A. Zeeb sw_scan: 20226b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 20236b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 2024086be6a8SBjoern A. Zeeb 2025086be6a8SBjoern A. Zeeb if (vap->iv_state == IEEE80211_S_SCAN) 2026086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, false); 2027086be6a8SBjoern A. Zeeb 20286b4cac81SBjoern A. Zeeb lkpi_80211_mo_sw_scan_start(hw, vif, vif->addr); 20296b4cac81SBjoern A. Zeeb /* net80211::scan_start() handled PS for us. */ 20306b4cac81SBjoern A. Zeeb IMPROVE(); 20316b4cac81SBjoern A. Zeeb /* XXX Also means it is too late to flush queues? 20326b4cac81SBjoern A. Zeeb * need to check iv_sta_ps or overload? */ 20336b4cac81SBjoern A. Zeeb /* XXX want to adjust ss end time/ maxdwell? */ 20346b4cac81SBjoern A. Zeeb 20356b4cac81SBjoern A. Zeeb } else { 20366b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 20376b4cac81SBjoern A. Zeeb struct ieee80211_scan_request *hw_req; 20386b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *lc, **cpp; 20396b4cac81SBjoern A. Zeeb struct cfg80211_ssid *ssids; 20406b4cac81SBjoern A. Zeeb struct cfg80211_scan_6ghz_params *s6gp; 20416b4cac81SBjoern A. Zeeb size_t chan_len, nchan, ssids_len, s6ghzlen; 20426b4cac81SBjoern A. Zeeb int i; 20436b4cac81SBjoern A. Zeeb 20446b4cac81SBjoern A. Zeeb ssids_len = ss->ss_nssid * sizeof(*ssids);; 20456b4cac81SBjoern A. Zeeb s6ghzlen = 0 * (sizeof(*s6gp)); /* XXX-BZ */ 20466b4cac81SBjoern A. Zeeb 20476b4cac81SBjoern A. Zeeb nchan = 0; 20486b4cac81SBjoern A. Zeeb for (i = ss->ss_next; i < ss->ss_last; i++) 20496b4cac81SBjoern A. Zeeb nchan++; 20506b4cac81SBjoern A. Zeeb chan_len = nchan * (sizeof(lc) + sizeof(*lc)); 20516b4cac81SBjoern A. Zeeb 20526b4cac81SBjoern A. Zeeb KASSERT(lhw->hw_req == NULL, ("%s: ic %p lhw %p hw_req %p " 20536b4cac81SBjoern A. Zeeb "!= NULL\n", __func__, ic, lhw, lhw->hw_req)); 20546b4cac81SBjoern A. Zeeb lhw->hw_req = hw_req = malloc(sizeof(*hw_req) + ssids_len + 20556b4cac81SBjoern A. Zeeb s6ghzlen + chan_len, M_LKPI80211, M_WAITOK | M_ZERO); 20566b4cac81SBjoern A. Zeeb 20576b4cac81SBjoern A. Zeeb error = lkpi_ieee80211_probereq_ie_alloc(vap, ic, 20586b4cac81SBjoern A. Zeeb &hw_req->ies, NULL, -1); 20596b4cac81SBjoern A. Zeeb if (error != 0) 20606b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: probereq_ie returned %d\n", 20616b4cac81SBjoern A. Zeeb __func__, error); 20626b4cac81SBjoern A. Zeeb 20636b4cac81SBjoern A. Zeeb hw_req->req.flags = 0; /* XXX ??? */ 20646b4cac81SBjoern A. Zeeb /* hw_req->req.wdev */ 20656b4cac81SBjoern A. Zeeb hw_req->req.wiphy = hw->wiphy; 20666b4cac81SBjoern A. Zeeb hw_req->req.no_cck = false; /* XXX */ 20676b4cac81SBjoern A. Zeeb #if 0 20686b4cac81SBjoern A. Zeeb /* This seems to pessimise default scanning behaviour. */ 20696b4cac81SBjoern A. Zeeb hw_req->req.duration_mandatory = TICKS_2_USEC(ss->ss_mindwell); 20706b4cac81SBjoern A. Zeeb hw_req->req.duration = TICKS_2_USEC(ss->ss_maxdwell); 20716b4cac81SBjoern A. Zeeb #endif 20726b4cac81SBjoern A. Zeeb #ifdef __notyet__ 20736b4cac81SBjoern A. Zeeb hw_req->req.flags |= NL80211_SCAN_FLAG_RANDOM_ADDR; 20746b4cac81SBjoern A. Zeeb memcpy(hw_req->req.mac_addr, xxx, IEEE80211_ADDR_LEN); 20756b4cac81SBjoern A. Zeeb memset(hw_req->req.mac_addr_mask, 0xxx, IEEE80211_ADDR_LEN); 20766b4cac81SBjoern A. Zeeb #endif 20776b4cac81SBjoern A. Zeeb #if 0 20786b4cac81SBjoern A. Zeeb hw_req->req.ie_len = ; 20796b4cac81SBjoern A. Zeeb hw_req->req.ie = ; 20806b4cac81SBjoern A. Zeeb #endif 2081d3ef7fb4SBjoern A. Zeeb #if 0 2082d3ef7fb4SBjoern A. Zeeb hw->wiphy->max_scan_ie_len 2083d3ef7fb4SBjoern A. Zeeb hw->wiphy->max_scan_ssids 2084d3ef7fb4SBjoern A. Zeeb #endif 20856b4cac81SBjoern A. Zeeb 20866b4cac81SBjoern A. Zeeb hw_req->req.n_channels = nchan; 20876b4cac81SBjoern A. Zeeb cpp = (struct linuxkpi_ieee80211_channel **)(hw_req + 1); 20886b4cac81SBjoern A. Zeeb lc = (struct linuxkpi_ieee80211_channel *)(cpp + nchan); 20896b4cac81SBjoern A. Zeeb for (i = 0; i < nchan; i++) { 20906b4cac81SBjoern A. Zeeb *(cpp + i) = 20916b4cac81SBjoern A. Zeeb (struct linuxkpi_ieee80211_channel *)(lc + i); 20926b4cac81SBjoern A. Zeeb } 20936b4cac81SBjoern A. Zeeb for (i = 0; i < nchan; i++) { 20946b4cac81SBjoern A. Zeeb c = ss->ss_chans[ss->ss_next + i]; 20956b4cac81SBjoern A. Zeeb 20966b4cac81SBjoern A. Zeeb lc->hw_value = c->ic_ieee; 20976b4cac81SBjoern A. Zeeb lc->center_freq = c->ic_freq; 20986b4cac81SBjoern A. Zeeb /* lc->flags */ 20996b4cac81SBjoern A. Zeeb lc->band = lkpi_net80211_chan_to_nl80211_band(c); 21006b4cac81SBjoern A. Zeeb lc->max_power = c->ic_maxpower; 21016b4cac81SBjoern A. Zeeb /* lc-> ... */ 21026b4cac81SBjoern A. Zeeb lc++; 21036b4cac81SBjoern A. Zeeb } 21046b4cac81SBjoern A. Zeeb 21056b4cac81SBjoern A. Zeeb hw_req->req.n_ssids = ss->ss_nssid; 21066b4cac81SBjoern A. Zeeb if (hw_req->req.n_ssids > 0) { 21076b4cac81SBjoern A. Zeeb ssids = (struct cfg80211_ssid *)lc; 21086b4cac81SBjoern A. Zeeb hw_req->req.ssids = ssids; 21096b4cac81SBjoern A. Zeeb for (i = 0; i < ss->ss_nssid; i++) { 21106b4cac81SBjoern A. Zeeb ssids->ssid_len = ss->ss_ssid[i].len; 21116b4cac81SBjoern A. Zeeb memcpy(ssids->ssid, ss->ss_ssid[i].ssid, 21126b4cac81SBjoern A. Zeeb ss->ss_ssid[i].len); 21136b4cac81SBjoern A. Zeeb ssids++; 21146b4cac81SBjoern A. Zeeb } 21156b4cac81SBjoern A. Zeeb s6gp = (struct cfg80211_scan_6ghz_params *)ssids; 21166b4cac81SBjoern A. Zeeb } else { 21176b4cac81SBjoern A. Zeeb s6gp = (struct cfg80211_scan_6ghz_params *)lc; 21186b4cac81SBjoern A. Zeeb } 21196b4cac81SBjoern A. Zeeb 21206b4cac81SBjoern A. Zeeb /* 6GHz one day. */ 21216b4cac81SBjoern A. Zeeb hw_req->req.n_6ghz_params = 0; 21226b4cac81SBjoern A. Zeeb hw_req->req.scan_6ghz_params = NULL; 21236b4cac81SBjoern A. Zeeb hw_req->req.scan_6ghz = false; /* Weird boolean; not what you think. */ 21246b4cac81SBjoern A. Zeeb /* s6gp->... */ 21256b4cac81SBjoern A. Zeeb 21266b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 21276b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 21286b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_hw_scan(hw, vif, hw_req); 21296b4cac81SBjoern A. Zeeb if (error != 0) { 21306b4cac81SBjoern A. Zeeb free(hw_req->ies.common_ies, M_80211_VAP); 21316b4cac81SBjoern A. Zeeb free(hw_req, M_LKPI80211); 21326b4cac81SBjoern A. Zeeb lhw->hw_req = NULL; 2133d3ef7fb4SBjoern A. Zeeb 2134d3ef7fb4SBjoern A. Zeeb /* 2135d3ef7fb4SBjoern A. Zeeb * XXX-SIGH magic number. 2136d3ef7fb4SBjoern A. Zeeb * rtw88 has a magic "return 1" if offloading scan is 2137d3ef7fb4SBjoern A. Zeeb * not possible. Fall back to sw scan in that case. 2138d3ef7fb4SBjoern A. Zeeb */ 2139d3ef7fb4SBjoern A. Zeeb if (error == 1) 2140d3ef7fb4SBjoern A. Zeeb goto sw_scan; 2141d3ef7fb4SBjoern A. Zeeb 2142d3ef7fb4SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: hw_scan returned %d\n", 2143d3ef7fb4SBjoern A. Zeeb __func__, error); 2144d3ef7fb4SBjoern A. Zeeb ieee80211_cancel_scan(vap); 21456b4cac81SBjoern A. Zeeb } 21466b4cac81SBjoern A. Zeeb } 21476b4cac81SBjoern A. Zeeb } 21486b4cac81SBjoern A. Zeeb 21496b4cac81SBjoern A. Zeeb static void 21506b4cac81SBjoern A. Zeeb lkpi_ic_scan_end(struct ieee80211com *ic) 21516b4cac81SBjoern A. Zeeb { 21526b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 21536b4cac81SBjoern A. Zeeb 21546b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 21556b4cac81SBjoern A. Zeeb if ((lhw->scan_flags & LKPI_SCAN_RUNNING) == 0) { 21566b4cac81SBjoern A. Zeeb return; 21576b4cac81SBjoern A. Zeeb } 21586b4cac81SBjoern A. Zeeb 21596b4cac81SBjoern A. Zeeb if (ic->ic_flags_ext & IEEE80211_FEXT_SCAN_OFFLOAD) { 21606b4cac81SBjoern A. Zeeb /* Nothing to do. */ 21616b4cac81SBjoern A. Zeeb } else { 21626b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 21636b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 21646b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 21656b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 21666b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 21676b4cac81SBjoern A. Zeeb 21686b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 21696b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 21706b4cac81SBjoern A. Zeeb vap = ss->ss_vap; 21716b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 21726b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 21736b4cac81SBjoern A. Zeeb lkpi_80211_mo_sw_scan_complete(hw, vif); 21746b4cac81SBjoern A. Zeeb 21756b4cac81SBjoern A. Zeeb /* Send PS to stop buffering if n80211 does not for us? */ 2176086be6a8SBjoern A. Zeeb 2177086be6a8SBjoern A. Zeeb if (vap->iv_state == IEEE80211_S_SCAN) 2178086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true); 21796b4cac81SBjoern A. Zeeb } 21806b4cac81SBjoern A. Zeeb } 21816b4cac81SBjoern A. Zeeb 21826b4cac81SBjoern A. Zeeb static void 21836b4cac81SBjoern A. Zeeb lkpi_ic_scan_curchan_nada(struct ieee80211_scan_state *ss __unused, 21846b4cac81SBjoern A. Zeeb unsigned long maxdwell __unused) 21856b4cac81SBjoern A. Zeeb { 21866b4cac81SBjoern A. Zeeb } 21876b4cac81SBjoern A. Zeeb 21886b4cac81SBjoern A. Zeeb static void 21896b4cac81SBjoern A. Zeeb lkpi_ic_set_channel(struct ieee80211com *ic) 21906b4cac81SBjoern A. Zeeb { 21916b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 21926b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 21936b4cac81SBjoern A. Zeeb int error; 21946b4cac81SBjoern A. Zeeb 21956b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 21966b4cac81SBjoern A. Zeeb #ifdef __no_longer__ 21976b4cac81SBjoern A. Zeeb /* For now only be concerned if scanning. */ 21986b4cac81SBjoern A. Zeeb if ((lhw->scan_flags & LKPI_SCAN_RUNNING) == 0) { 21996b4cac81SBjoern A. Zeeb IMPROVE(); 22006b4cac81SBjoern A. Zeeb return; 22016b4cac81SBjoern A. Zeeb } 22026b4cac81SBjoern A. Zeeb #endif 22036b4cac81SBjoern A. Zeeb 22046b4cac81SBjoern A. Zeeb if (ic->ic_flags_ext & IEEE80211_FEXT_SCAN_OFFLOAD) { 22056b4cac81SBjoern A. Zeeb /* 22066b4cac81SBjoern A. Zeeb * AP scanning is taken care of by firmware, so only switch 22076b4cac81SBjoern A. Zeeb * channels in monitor mode (maybe, maybe not; to be 22086b4cac81SBjoern A. Zeeb * investigated at the right time). 22096b4cac81SBjoern A. Zeeb */ 22106b4cac81SBjoern A. Zeeb if (ic->ic_opmode == IEEE80211_M_MONITOR) { 22116b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 22126b4cac81SBjoern A. Zeeb } 22136b4cac81SBjoern A. Zeeb } else { 22146b4cac81SBjoern A. Zeeb struct ieee80211_channel *c = ic->ic_curchan; 22156b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 22166b4cac81SBjoern A. Zeeb struct cfg80211_chan_def chandef; 22176b4cac81SBjoern A. Zeeb 22186b4cac81SBjoern A. Zeeb if (c == NULL || c == IEEE80211_CHAN_ANYC || 22196b4cac81SBjoern A. Zeeb lhw->ops->config == NULL) { 22206b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: c %p ops->config %p\n", __func__, 22216b4cac81SBjoern A. Zeeb c, lhw->ops->config); 22226b4cac81SBjoern A. Zeeb return; 22236b4cac81SBjoern A. Zeeb } 22246b4cac81SBjoern A. Zeeb 22256b4cac81SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, c); 22266b4cac81SBjoern A. Zeeb if (chan == NULL) { 22276b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: c %p chan %p\n", __func__, 22286b4cac81SBjoern A. Zeeb c, chan); 22296b4cac81SBjoern A. Zeeb return; 22306b4cac81SBjoern A. Zeeb } 22316b4cac81SBjoern A. Zeeb 22326b4cac81SBjoern A. Zeeb memset(&chandef, 0, sizeof(chandef)); 22336b4cac81SBjoern A. Zeeb chandef.chan = chan; 22346b4cac81SBjoern A. Zeeb chandef.width = NL80211_CHAN_WIDTH_20_NOHT; 22356b4cac81SBjoern A. Zeeb chandef.center_freq1 = chandef.chan->center_freq; 22366b4cac81SBjoern A. Zeeb 22376b4cac81SBjoern A. Zeeb /* XXX max power for scanning? */ 22386b4cac81SBjoern A. Zeeb IMPROVE(); 22396b4cac81SBjoern A. Zeeb 22406b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 22416b4cac81SBjoern A. Zeeb hw->conf.chandef = chandef; 22426b4cac81SBjoern A. Zeeb 22436b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_CHANNEL); 22446b4cac81SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) { 22456b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: config %#0x returned %d\n", 22466b4cac81SBjoern A. Zeeb __func__, IEEE80211_CONF_CHANGE_CHANNEL, error); 22476b4cac81SBjoern A. Zeeb /* XXX should we unroll to the previous chandef? */ 22486b4cac81SBjoern A. Zeeb IMPROVE(); 22496b4cac81SBjoern A. Zeeb } else { 22506b4cac81SBjoern A. Zeeb /* Update radiotap channels as well. */ 22516b4cac81SBjoern A. Zeeb lhw->rtap_tx.wt_chan_freq = htole16(c->ic_freq); 22526b4cac81SBjoern A. Zeeb lhw->rtap_tx.wt_chan_flags = htole16(c->ic_flags); 22536b4cac81SBjoern A. Zeeb lhw->rtap_rx.wr_chan_freq = htole16(c->ic_freq); 22546b4cac81SBjoern A. Zeeb lhw->rtap_rx.wr_chan_flags = htole16(c->ic_flags); 22556b4cac81SBjoern A. Zeeb } 22566b4cac81SBjoern A. Zeeb 22576b4cac81SBjoern A. Zeeb /* Currently PS is hard coded off! Not sure it belongs here. */ 22586b4cac81SBjoern A. Zeeb IMPROVE(); 22596b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, SUPPORTS_PS) && 22606b4cac81SBjoern A. Zeeb (hw->conf.flags & IEEE80211_CONF_PS) != 0) { 22616b4cac81SBjoern A. Zeeb hw->conf.flags &= ~IEEE80211_CONF_PS; 22626b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_PS); 22636b4cac81SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) 22646b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: config %#0x returned " 22656b4cac81SBjoern A. Zeeb "%d\n", __func__, IEEE80211_CONF_CHANGE_PS, 22666b4cac81SBjoern A. Zeeb error); 22676b4cac81SBjoern A. Zeeb } 22686b4cac81SBjoern A. Zeeb } 22696b4cac81SBjoern A. Zeeb } 22706b4cac81SBjoern A. Zeeb 22716b4cac81SBjoern A. Zeeb static struct ieee80211_node * 22726b4cac81SBjoern A. Zeeb lkpi_ic_node_alloc(struct ieee80211vap *vap, 22736b4cac81SBjoern A. Zeeb const uint8_t mac[IEEE80211_ADDR_LEN]) 22746b4cac81SBjoern A. Zeeb { 22756b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 22766b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 22774f61ef8bSBjoern A. Zeeb struct ieee80211_node *ni; 22786b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 22796b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 22806b4cac81SBjoern A. Zeeb 22816b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 22826b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 22836b4cac81SBjoern A. Zeeb 22846b4cac81SBjoern A. Zeeb /* We keep allocations de-coupled so we can deal with the two worlds. */ 22854f61ef8bSBjoern A. Zeeb if (lhw->ic_node_alloc == NULL) 22864f61ef8bSBjoern A. Zeeb return (NULL); 22874f61ef8bSBjoern A. Zeeb 22886b4cac81SBjoern A. Zeeb ni = lhw->ic_node_alloc(vap, mac); 22896b4cac81SBjoern A. Zeeb if (ni == NULL) 22906b4cac81SBjoern A. Zeeb return (NULL); 22916b4cac81SBjoern A. Zeeb 22926b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 22934f61ef8bSBjoern A. Zeeb lsta = lkpi_lsta_alloc(vap, mac, hw, ni); 22946b4cac81SBjoern A. Zeeb if (lsta == NULL) { 22956b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL) 22966b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni); 22976b4cac81SBjoern A. Zeeb return (NULL); 22986b4cac81SBjoern A. Zeeb } 22996b4cac81SBjoern A. Zeeb 23006b4cac81SBjoern A. Zeeb return (ni); 23016b4cac81SBjoern A. Zeeb } 23026b4cac81SBjoern A. Zeeb 23036b4cac81SBjoern A. Zeeb static int 23046b4cac81SBjoern A. Zeeb lkpi_ic_node_init(struct ieee80211_node *ni) 23056b4cac81SBjoern A. Zeeb { 23066b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 23076b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 23086b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 23096b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 23106b4cac81SBjoern A. Zeeb int error; 23116b4cac81SBjoern A. Zeeb 23126b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 23136b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 23146b4cac81SBjoern A. Zeeb 23156b4cac81SBjoern A. Zeeb if (lhw->ic_node_init != NULL) { 23166b4cac81SBjoern A. Zeeb error = lhw->ic_node_init(ni); 23176b4cac81SBjoern A. Zeeb if (error != 0) 23186b4cac81SBjoern A. Zeeb return (error); 23196b4cac81SBjoern A. Zeeb } 23206b4cac81SBjoern A. Zeeb 23216b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(ni->ni_vap); 23226b4cac81SBjoern A. Zeeb 23236b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 23246b4cac81SBjoern A. Zeeb 23256b4cac81SBjoern A. Zeeb /* Now take the reference before linking it to the table. */ 23266b4cac81SBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 23276b4cac81SBjoern A. Zeeb 23286b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 23296b4cac81SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lvif->lsta_head, lsta, lsta_entry); 23306b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 23316b4cac81SBjoern A. Zeeb 23326b4cac81SBjoern A. Zeeb /* XXX-BZ Sync other state over. */ 23336b4cac81SBjoern A. Zeeb IMPROVE(); 23346b4cac81SBjoern A. Zeeb 23356b4cac81SBjoern A. Zeeb return (0); 23366b4cac81SBjoern A. Zeeb } 23376b4cac81SBjoern A. Zeeb 23386b4cac81SBjoern A. Zeeb static void 23396b4cac81SBjoern A. Zeeb lkpi_ic_node_cleanup(struct ieee80211_node *ni) 23406b4cac81SBjoern A. Zeeb { 23416b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 23426b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 23436b4cac81SBjoern A. Zeeb 23446b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 23456b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 23466b4cac81SBjoern A. Zeeb 23476b4cac81SBjoern A. Zeeb /* XXX-BZ remove from driver, ... */ 23486b4cac81SBjoern A. Zeeb IMPROVE(); 23496b4cac81SBjoern A. Zeeb 23506b4cac81SBjoern A. Zeeb if (lhw->ic_node_cleanup != NULL) 23516b4cac81SBjoern A. Zeeb lhw->ic_node_cleanup(ni); 23526b4cac81SBjoern A. Zeeb } 23536b4cac81SBjoern A. Zeeb 23546b4cac81SBjoern A. Zeeb static void 23556b4cac81SBjoern A. Zeeb lkpi_ic_node_free(struct ieee80211_node *ni) 23566b4cac81SBjoern A. Zeeb { 23576b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 23586b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 23596b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 23606b4cac81SBjoern A. Zeeb 23616b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 23626b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 23636b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 23646b4cac81SBjoern A. Zeeb 23656b4cac81SBjoern A. Zeeb /* XXX-BZ free resources, ... */ 23666b4cac81SBjoern A. Zeeb IMPROVE(); 23676b4cac81SBjoern A. Zeeb 23686b4cac81SBjoern A. Zeeb /* Flush mbufq (make sure to release ni refs!). */ 23696b4cac81SBjoern A. Zeeb #ifdef __notyet__ 23706b4cac81SBjoern A. Zeeb KASSERT(mbufq_len(&lsta->txq) == 0, ("%s: lsta %p has txq len %d != 0\n", 23716b4cac81SBjoern A. Zeeb __func__, lsta, mbufq_len(&lsta->txq))); 23726b4cac81SBjoern A. Zeeb #endif 23736b4cac81SBjoern A. Zeeb /* Drain taskq. */ 23746b4cac81SBjoern A. Zeeb 23756b4cac81SBjoern A. Zeeb /* Drain sta->txq[] */ 23766b4cac81SBjoern A. Zeeb mtx_destroy(&lsta->txq_mtx); 23776b4cac81SBjoern A. Zeeb 23786b4cac81SBjoern A. Zeeb /* Remove lsta if added_to_drv. */ 23796b4cac81SBjoern A. Zeeb /* Remove lsta from vif */ 23806b4cac81SBjoern A. Zeeb 23816b4cac81SBjoern A. Zeeb /* remove ref from lsta node... */ 23826b4cac81SBjoern A. Zeeb 23836b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL) 23846b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni); 23856b4cac81SBjoern A. Zeeb 23866b4cac81SBjoern A. Zeeb /* Free lsta. */ 23876b4cac81SBjoern A. Zeeb } 23886b4cac81SBjoern A. Zeeb 23896b4cac81SBjoern A. Zeeb static int 23906b4cac81SBjoern A. Zeeb lkpi_ic_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, 23916b4cac81SBjoern A. Zeeb const struct ieee80211_bpf_params *params __unused) 23926b4cac81SBjoern A. Zeeb { 23936b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 23946b4cac81SBjoern A. Zeeb 23956b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 23966b4cac81SBjoern A. Zeeb 23976b4cac81SBjoern A. Zeeb /* Queue the packet and enqueue the task to handle it. */ 23986b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_LOCK(lsta); 23996b4cac81SBjoern A. Zeeb mbufq_enqueue(&lsta->txq, m); 24006b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_UNLOCK(lsta); 24016b4cac81SBjoern A. Zeeb 24026b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_TX) 24036b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p ni %p %6D mbuf_qlen %d\n", 24046b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, ni, ni->ni_macaddr, ":", 24056b4cac81SBjoern A. Zeeb mbufq_len(&lsta->txq)); 24066b4cac81SBjoern A. Zeeb 24076b4cac81SBjoern A. Zeeb taskqueue_enqueue(taskqueue_thread, &lsta->txq_task); 24086b4cac81SBjoern A. Zeeb return (0); 24096b4cac81SBjoern A. Zeeb } 24106b4cac81SBjoern A. Zeeb 24116b4cac81SBjoern A. Zeeb static void 24126b4cac81SBjoern A. Zeeb lkpi_80211_txq_tx_one(struct lkpi_sta *lsta, struct mbuf *m) 24136b4cac81SBjoern A. Zeeb { 24146b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 24156b4cac81SBjoern A. Zeeb struct ieee80211_frame *wh; 24166b4cac81SBjoern A. Zeeb struct ieee80211_key *k; 24176b4cac81SBjoern A. Zeeb struct sk_buff *skb; 24186b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 24196b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 24206b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 24216b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 24226b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 24236b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 24246b4cac81SBjoern A. Zeeb struct ieee80211_tx_control control; 24256b4cac81SBjoern A. Zeeb struct ieee80211_tx_info *info; 24266b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 24276b4cac81SBjoern A. Zeeb void *buf; 24286b4cac81SBjoern A. Zeeb int ac; 24296b4cac81SBjoern A. Zeeb 24306b4cac81SBjoern A. Zeeb M_ASSERTPKTHDR(m); 24316b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 24326b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_TX_DUMP) 24336b4cac81SBjoern A. Zeeb hexdump(mtod(m, const void *), m->m_len, "RAW TX (plain) ", 0); 24346b4cac81SBjoern A. Zeeb #endif 24356b4cac81SBjoern A. Zeeb 24366b4cac81SBjoern A. Zeeb ni = lsta->ni; 24376b4cac81SBjoern A. Zeeb #ifndef TRY_HW_CRYPTO 24386b4cac81SBjoern A. Zeeb /* Encrypt the frame if need be; XXX-BZ info->control.hw_key. */ 24396b4cac81SBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame *); 24406b4cac81SBjoern A. Zeeb if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { 24416b4cac81SBjoern A. Zeeb /* Retrieve key for TX && do software encryption. */ 24426b4cac81SBjoern A. Zeeb k = ieee80211_crypto_encap(ni, m); 24436b4cac81SBjoern A. Zeeb if (k == NULL) { 24446b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 24456b4cac81SBjoern A. Zeeb m_freem(m); 24466b4cac81SBjoern A. Zeeb return; 24476b4cac81SBjoern A. Zeeb } 24486b4cac81SBjoern A. Zeeb } 24496b4cac81SBjoern A. Zeeb #endif 24506b4cac81SBjoern A. Zeeb 24516b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 24526b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 24536b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 24546b4cac81SBjoern A. Zeeb c = ni->ni_chan; 24556b4cac81SBjoern A. Zeeb 24566b4cac81SBjoern A. Zeeb if (ieee80211_radiotap_active_vap(ni->ni_vap)) { 24576b4cac81SBjoern A. Zeeb struct lkpi_radiotap_tx_hdr *rtap; 24586b4cac81SBjoern A. Zeeb 24596b4cac81SBjoern A. Zeeb rtap = &lhw->rtap_tx; 24606b4cac81SBjoern A. Zeeb rtap->wt_flags = 0; 24616b4cac81SBjoern A. Zeeb if (k != NULL) 24626b4cac81SBjoern A. Zeeb rtap->wt_flags |= IEEE80211_RADIOTAP_F_WEP; 24636b4cac81SBjoern A. Zeeb if (m->m_flags & M_FRAG) 24646b4cac81SBjoern A. Zeeb rtap->wt_flags |= IEEE80211_RADIOTAP_F_FRAG; 24656b4cac81SBjoern A. Zeeb IMPROVE(); 24666b4cac81SBjoern A. Zeeb rtap->wt_rate = 0; 24676b4cac81SBjoern A. Zeeb if (c != NULL && c != IEEE80211_CHAN_ANYC) { 24686b4cac81SBjoern A. Zeeb rtap->wt_chan_freq = htole16(c->ic_freq); 24696b4cac81SBjoern A. Zeeb rtap->wt_chan_flags = htole16(c->ic_flags); 24706b4cac81SBjoern A. Zeeb } 24716b4cac81SBjoern A. Zeeb 24726b4cac81SBjoern A. Zeeb ieee80211_radiotap_tx(ni->ni_vap, m); 24736b4cac81SBjoern A. Zeeb } 24746b4cac81SBjoern A. Zeeb 24756b4cac81SBjoern A. Zeeb /* 24766b4cac81SBjoern A. Zeeb * net80211 should handle hw->extra_tx_headroom. 24776b4cac81SBjoern A. Zeeb * Though for as long as we are copying we don't mind. 24783d09d310SBjoern A. Zeeb * XXX-BZ rtw88 asks for too much headroom for ipv6+tcp: 24793d09d310SBjoern A. Zeeb * https://lists.freebsd.org/archives/freebsd-transport/2022-February/000012.html 24806b4cac81SBjoern A. Zeeb */ 24816b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + m->m_pkthdr.len); 24826b4cac81SBjoern A. Zeeb if (skb == NULL) { 24836b4cac81SBjoern A. Zeeb printf("XXX ERROR %s: skb alloc failed\n", __func__); 24846b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 24856b4cac81SBjoern A. Zeeb m_freem(m); 24866b4cac81SBjoern A. Zeeb return; 24876b4cac81SBjoern A. Zeeb } 24886b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 24896b4cac81SBjoern A. Zeeb 24906b4cac81SBjoern A. Zeeb /* XXX-BZ we need a SKB version understanding mbuf. */ 24916b4cac81SBjoern A. Zeeb /* Save the mbuf for ieee80211_tx_complete(). */ 24926b4cac81SBjoern A. Zeeb skb->m_free_func = lkpi_ieee80211_free_skb_mbuf; 24936b4cac81SBjoern A. Zeeb skb->m = m; 24946b4cac81SBjoern A. Zeeb #if 0 24956b4cac81SBjoern A. Zeeb skb_put_data(skb, m->m_data, m->m_pkthdr.len); 24966b4cac81SBjoern A. Zeeb #else 24976b4cac81SBjoern A. Zeeb buf = skb_put(skb, m->m_pkthdr.len); 24986b4cac81SBjoern A. Zeeb m_copydata(m, 0, m->m_pkthdr.len, buf); 24996b4cac81SBjoern A. Zeeb #endif 25006b4cac81SBjoern A. Zeeb /* Save the ni. */ 25016b4cac81SBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = ni; 25026b4cac81SBjoern A. Zeeb 25036b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(ni->ni_vap); 25046b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 25056b4cac81SBjoern A. Zeeb 25066b4cac81SBjoern A. Zeeb /* XXX-BZ review this at some point [4] vs. [8] vs. [16](TID). */ 25076b4cac81SBjoern A. Zeeb ac = M_WME_GETAC(m); 25086b4cac81SBjoern A. Zeeb skb->priority = WME_AC_TO_TID(ac); 25096b4cac81SBjoern A. Zeeb ac = lkpi_ac_net_to_l80211(ac); 25106b4cac81SBjoern A. Zeeb skb_set_queue_mapping(skb, ac); 25116b4cac81SBjoern A. Zeeb 25126b4cac81SBjoern A. Zeeb info = IEEE80211_SKB_CB(skb); 25136b4cac81SBjoern A. Zeeb info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; 25146b4cac81SBjoern A. Zeeb /* Slight delay; probably only happens on scanning so fine? */ 25156b4cac81SBjoern A. Zeeb if (c == NULL || c == IEEE80211_CHAN_ANYC) 25166b4cac81SBjoern A. Zeeb c = ic->ic_curchan; 25176b4cac81SBjoern A. Zeeb info->band = lkpi_net80211_chan_to_nl80211_band(c); 25186b4cac81SBjoern A. Zeeb info->hw_queue = ac; /* XXX-BZ is this correct? */ 25196b4cac81SBjoern A. Zeeb if (m->m_flags & M_EAPOL) 25206b4cac81SBjoern A. Zeeb info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO; 25216b4cac81SBjoern A. Zeeb info->control.vif = vif; 25226b4cac81SBjoern A. Zeeb /* XXX-BZ info->control.rates */ 25236b4cac81SBjoern A. Zeeb 25246b4cac81SBjoern A. Zeeb lsta = lkpi_find_lsta_by_ni(lvif, ni); 25256b4cac81SBjoern A. Zeeb if (lsta != NULL) { 25266b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 25276b4cac81SBjoern A. Zeeb #ifdef TRY_HW_CRYPTO 25286b4cac81SBjoern A. Zeeb info->control.hw_key = lsta->kc; 25296b4cac81SBjoern A. Zeeb #endif 25306b4cac81SBjoern A. Zeeb } else { 25316b4cac81SBjoern A. Zeeb sta = NULL; 25326b4cac81SBjoern A. Zeeb } 25336b4cac81SBjoern A. Zeeb 25346b4cac81SBjoern A. Zeeb IMPROVE(); 25356b4cac81SBjoern A. Zeeb 25366b4cac81SBjoern A. Zeeb if (sta != NULL) { 25376b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 25386b4cac81SBjoern A. Zeeb 25396b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[ac]); /* XXX-BZ re-check */ 25406b4cac81SBjoern A. Zeeb /* 25416b4cac81SBjoern A. Zeeb * We currently do not use queues but do direct TX. 25426b4cac81SBjoern A. Zeeb * The exception to the rule is initial packets, as we cannot 25436b4cac81SBjoern A. Zeeb * TX until queues are allocated (at least for iwlwifi). 25446b4cac81SBjoern A. Zeeb * So we wake_tx_queue in newstate and register any dequeue 25456b4cac81SBjoern A. Zeeb * calls. In the time until then we queue packets and 25466b4cac81SBjoern A. Zeeb * let the driver deal with them. 25476b4cac81SBjoern A. Zeeb */ 25486b4cac81SBjoern A. Zeeb if (!ltxq->seen_dequeue) { 25496b4cac81SBjoern A. Zeeb 25506b4cac81SBjoern A. Zeeb /* Prevent an ordering problem, likely other issues. */ 25516b4cac81SBjoern A. Zeeb while (!skb_queue_empty(<xq->skbq)) { 25526b4cac81SBjoern A. Zeeb struct sk_buff *skb2; 25536b4cac81SBjoern A. Zeeb 25546b4cac81SBjoern A. Zeeb skb2 = skb_dequeue(<xq->skbq); 25556b4cac81SBjoern A. Zeeb if (skb2 != NULL) { 25566b4cac81SBjoern A. Zeeb memset(&control, 0, sizeof(control)); 25576b4cac81SBjoern A. Zeeb control.sta = sta; 25586b4cac81SBjoern A. Zeeb lkpi_80211_mo_tx(hw, &control, skb2); 25596b4cac81SBjoern A. Zeeb } 25606b4cac81SBjoern A. Zeeb } 25616b4cac81SBjoern A. Zeeb goto ops_tx; 25626b4cac81SBjoern A. Zeeb } 25636b4cac81SBjoern A. Zeeb if (0 && ltxq->seen_dequeue && skb_queue_empty(<xq->skbq)) 25646b4cac81SBjoern A. Zeeb goto ops_tx; 25656b4cac81SBjoern A. Zeeb 25666b4cac81SBjoern A. Zeeb skb_queue_tail(<xq->skbq, skb); 25676b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_TX) 25686b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p sta %p ni %p %6D skb %p lxtq %p " 25696b4cac81SBjoern A. Zeeb "qlen %u WAKE_TX_Q ac %d prio %u qmap %u\n", 25706b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, sta, ni, 25716b4cac81SBjoern A. Zeeb ni->ni_macaddr, ":", skb, ltxq, 25726b4cac81SBjoern A. Zeeb skb_queue_len(<xq->skbq), ac, 25736b4cac81SBjoern A. Zeeb skb->priority, skb->qmap); 25746b4cac81SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, sta->txq[ac]); /* XXX-BZ */ 25756b4cac81SBjoern A. Zeeb return; 25766b4cac81SBjoern A. Zeeb } 25776b4cac81SBjoern A. Zeeb 25786b4cac81SBjoern A. Zeeb ops_tx: 25796b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_TX) 25806b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p sta %p ni %p %6D skb %p TX ac %d prio %u qmap %u\n", 25816b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, sta, ni, ni->ni_macaddr, ":", 25826b4cac81SBjoern A. Zeeb skb, ac, skb->priority, skb->qmap); 25836b4cac81SBjoern A. Zeeb memset(&control, 0, sizeof(control)); 25846b4cac81SBjoern A. Zeeb control.sta = sta; 25856b4cac81SBjoern A. Zeeb 25866b4cac81SBjoern A. Zeeb lkpi_80211_mo_tx(hw, &control, skb); 25876b4cac81SBjoern A. Zeeb return; 25886b4cac81SBjoern A. Zeeb } 25896b4cac81SBjoern A. Zeeb 25906b4cac81SBjoern A. Zeeb static void 25916b4cac81SBjoern A. Zeeb lkpi_80211_txq_task(void *ctx, int pending) 25926b4cac81SBjoern A. Zeeb { 25936b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 25946b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 25956b4cac81SBjoern A. Zeeb struct mbufq mq; 25966b4cac81SBjoern A. Zeeb struct mbuf *m; 25976b4cac81SBjoern A. Zeeb 25986b4cac81SBjoern A. Zeeb lsta = ctx; 25996b4cac81SBjoern A. Zeeb ni = lsta->ni; 26006b4cac81SBjoern A. Zeeb 26016b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_TX) 26026b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p ni %p %6D pending %d mbuf_qlen %d\n", 26036b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, ni, ni->ni_macaddr, ":", 26046b4cac81SBjoern A. Zeeb pending, mbufq_len(&lsta->txq)); 26056b4cac81SBjoern A. Zeeb 26066b4cac81SBjoern A. Zeeb mbufq_init(&mq, IFQ_MAXLEN); 26076b4cac81SBjoern A. Zeeb 26086b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_LOCK(lsta); 26096b4cac81SBjoern A. Zeeb mbufq_concat(&mq, &lsta->txq); 26106b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_UNLOCK(lsta); 26116b4cac81SBjoern A. Zeeb 26126b4cac81SBjoern A. Zeeb m = mbufq_dequeue(&mq); 26136b4cac81SBjoern A. Zeeb while (m != NULL) { 26146b4cac81SBjoern A. Zeeb lkpi_80211_txq_tx_one(lsta, m); 26156b4cac81SBjoern A. Zeeb m = mbufq_dequeue(&mq); 26166b4cac81SBjoern A. Zeeb } 26176b4cac81SBjoern A. Zeeb } 26186b4cac81SBjoern A. Zeeb 26196b4cac81SBjoern A. Zeeb static int 26206b4cac81SBjoern A. Zeeb lkpi_ic_transmit(struct ieee80211com *ic, struct mbuf *m) 26216b4cac81SBjoern A. Zeeb { 26226b4cac81SBjoern A. Zeeb 26236b4cac81SBjoern A. Zeeb /* XXX TODO */ 26246b4cac81SBjoern A. Zeeb IMPROVE(); 26256b4cac81SBjoern A. Zeeb 26266b4cac81SBjoern A. Zeeb /* Quick and dirty cheating hack. */ 26276b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 26286b4cac81SBjoern A. Zeeb 26296b4cac81SBjoern A. Zeeb ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; 26306b4cac81SBjoern A. Zeeb return (lkpi_ic_raw_xmit(ni, m, NULL)); 26316b4cac81SBjoern A. Zeeb } 26326b4cac81SBjoern A. Zeeb 26336b4cac81SBjoern A. Zeeb static void 26346b4cac81SBjoern A. Zeeb lkpi_ic_getradiocaps(struct ieee80211com *ic, int maxchan, 26356b4cac81SBjoern A. Zeeb int *n, struct ieee80211_channel *c) 26366b4cac81SBjoern A. Zeeb { 26376b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 26386b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 26396b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 26406b4cac81SBjoern A. Zeeb uint8_t bands[IEEE80211_MODE_BYTES]; 26416b4cac81SBjoern A. Zeeb int chan_flags, error, i, nchans; 26426b4cac81SBjoern A. Zeeb 26436b4cac81SBjoern A. Zeeb /* Channels */ 26446b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 26456b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 26466b4cac81SBjoern A. Zeeb 26476b4cac81SBjoern A. Zeeb /* NL80211_BAND_2GHZ */ 26486b4cac81SBjoern A. Zeeb nchans = 0; 26496b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_2GHZ] != NULL) 26506b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[NL80211_BAND_2GHZ]->n_channels; 26516b4cac81SBjoern A. Zeeb if (nchans > 0) { 26526b4cac81SBjoern A. Zeeb memset(bands, 0, sizeof(bands)); 26536b4cac81SBjoern A. Zeeb chan_flags = 0; 26546b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11B); 26556b4cac81SBjoern A. Zeeb /* XXX-BZ unclear how to check for 11g. */ 26566b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11G); 26576b4cac81SBjoern A. Zeeb #ifdef __notyet__ 26586b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_2GHZ]->ht_cap.ht_supported) { 26596b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11NG); 26606b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_HT40; 26616b4cac81SBjoern A. Zeeb } 26626b4cac81SBjoern A. Zeeb #endif 26636b4cac81SBjoern A. Zeeb 26646b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[NL80211_BAND_2GHZ]->channels; 2665cee56e77SBjoern A. Zeeb for (i = 0; i < nchans && *n < maxchan; i++) { 26666b4cac81SBjoern A. Zeeb uint32_t nflags = 0; 26676b4cac81SBjoern A. Zeeb int cflags = chan_flags; 26686b4cac81SBjoern A. Zeeb 26696b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) { 26706b4cac81SBjoern A. Zeeb printf("%s: %s: Skipping disabled chan " 26716b4cac81SBjoern A. Zeeb "[%u/%u/%#x]\n", ic->ic_name, __func__, 26726b4cac81SBjoern A. Zeeb channels[i].hw_value, 26736b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags); 26746b4cac81SBjoern A. Zeeb continue; 26756b4cac81SBjoern A. Zeeb } 26766b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_IR) 26776b4cac81SBjoern A. Zeeb nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE); 26786b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_RADAR) 26796b4cac81SBjoern A. Zeeb nflags |= IEEE80211_CHAN_DFS; 26806b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ) 26816b4cac81SBjoern A. Zeeb cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80); 26826b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ) 26836b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_VHT80; 26846b4cac81SBjoern A. Zeeb /* XXX how to map the remaining enum ieee80211_channel_flags? */ 26856b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_HT40) 26866b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_HT40; 26876b4cac81SBjoern A. Zeeb 26886b4cac81SBjoern A. Zeeb error = ieee80211_add_channel_cbw(c, maxchan, n, 26896b4cac81SBjoern A. Zeeb channels[i].hw_value, channels[i].center_freq, 26906b4cac81SBjoern A. Zeeb channels[i].max_power, 26916b4cac81SBjoern A. Zeeb nflags, bands, chan_flags); 2692cee56e77SBjoern A. Zeeb /* net80211::ENOBUFS: *n >= maxchans */ 2693cee56e77SBjoern A. Zeeb if (error != 0 && error != ENOBUFS) 26946b4cac81SBjoern A. Zeeb printf("%s: %s: Adding chan %u/%u/%#x/%#x/%#x/%#x " 26956b4cac81SBjoern A. Zeeb "returned error %d\n", ic->ic_name, 26966b4cac81SBjoern A. Zeeb __func__, channels[i].hw_value, 26976b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags, 26986b4cac81SBjoern A. Zeeb nflags, chan_flags, cflags, error); 2699cee56e77SBjoern A. Zeeb if (error != 0) 27006b4cac81SBjoern A. Zeeb break; 27016b4cac81SBjoern A. Zeeb } 27026b4cac81SBjoern A. Zeeb } 27036b4cac81SBjoern A. Zeeb 27046b4cac81SBjoern A. Zeeb /* NL80211_BAND_5GHZ */ 27056b4cac81SBjoern A. Zeeb nchans = 0; 27066b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ] != NULL) 27076b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[NL80211_BAND_5GHZ]->n_channels; 27086b4cac81SBjoern A. Zeeb if (nchans > 0) { 27096b4cac81SBjoern A. Zeeb memset(bands, 0, sizeof(bands)); 27106b4cac81SBjoern A. Zeeb chan_flags = 0; 27116b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11A); 27126b4cac81SBjoern A. Zeeb #ifdef __not_yet__ 27136b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ]->ht_cap.ht_supported) { 27146b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11NA); 27156b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_HT40; 27166b4cac81SBjoern A. Zeeb } 27176b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.vht_supported){ 27186b4cac81SBjoern A. Zeeb 27196b4cac81SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_VHT; 27206b4cac81SBjoern A. Zeeb ic->ic_vhtcaps = 27216b4cac81SBjoern A. Zeeb hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap; 27226b4cac81SBjoern A. Zeeb 27236b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_VHT_5GHZ); 27246b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT80; 27256b4cac81SBjoern A. Zeeb if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160MHZ( 27266b4cac81SBjoern A. Zeeb ic->ic_vhtcaps)) 27276b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT160; 27286b4cac81SBjoern A. Zeeb if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160_80P80MHZ( 27296b4cac81SBjoern A. Zeeb ic->ic_vhtcaps)) 27306b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT80P80; 27316b4cac81SBjoern A. Zeeb } 27326b4cac81SBjoern A. Zeeb #endif 27336b4cac81SBjoern A. Zeeb 27346b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[NL80211_BAND_5GHZ]->channels; 2735cee56e77SBjoern A. Zeeb for (i = 0; i < nchans && *n < maxchan; i++) { 27366b4cac81SBjoern A. Zeeb uint32_t nflags = 0; 27376b4cac81SBjoern A. Zeeb int cflags = chan_flags; 27386b4cac81SBjoern A. Zeeb 27396b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) { 27406b4cac81SBjoern A. Zeeb printf("%s: %s: Skipping disabled chan " 27416b4cac81SBjoern A. Zeeb "[%u/%u/%#x]\n", ic->ic_name, __func__, 27426b4cac81SBjoern A. Zeeb channels[i].hw_value, 27436b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags); 27446b4cac81SBjoern A. Zeeb continue; 27456b4cac81SBjoern A. Zeeb } 27466b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_IR) 27476b4cac81SBjoern A. Zeeb nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE); 27486b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_RADAR) 27496b4cac81SBjoern A. Zeeb nflags |= IEEE80211_CHAN_DFS; 27506b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ) 27516b4cac81SBjoern A. Zeeb cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80); 27526b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ) 27536b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_VHT80; 27546b4cac81SBjoern A. Zeeb /* XXX hwo to map the remaining enum ieee80211_channel_flags? */ 27556b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_HT40) 27566b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_HT40; 27576b4cac81SBjoern A. Zeeb 27586b4cac81SBjoern A. Zeeb error = ieee80211_add_channel_cbw(c, maxchan, n, 27596b4cac81SBjoern A. Zeeb channels[i].hw_value, channels[i].center_freq, 27606b4cac81SBjoern A. Zeeb channels[i].max_power, 27616b4cac81SBjoern A. Zeeb nflags, bands, chan_flags); 2762cee56e77SBjoern A. Zeeb /* net80211::ENOBUFS: *n >= maxchans */ 2763cee56e77SBjoern A. Zeeb if (error != 0 && error != ENOBUFS) 27646b4cac81SBjoern A. Zeeb printf("%s: %s: Adding chan %u/%u/%#x/%#x/%#x/%#x " 27656b4cac81SBjoern A. Zeeb "returned error %d\n", ic->ic_name, 27666b4cac81SBjoern A. Zeeb __func__, channels[i].hw_value, 27676b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags, 27686b4cac81SBjoern A. Zeeb nflags, chan_flags, cflags, error); 2769cee56e77SBjoern A. Zeeb if (error != 0) 27706b4cac81SBjoern A. Zeeb break; 27716b4cac81SBjoern A. Zeeb } 27726b4cac81SBjoern A. Zeeb } 27736b4cac81SBjoern A. Zeeb } 27746b4cac81SBjoern A. Zeeb 27756b4cac81SBjoern A. Zeeb static void * 27766b4cac81SBjoern A. Zeeb lkpi_ieee80211_ifalloc(void) 27776b4cac81SBjoern A. Zeeb { 27786b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 27796b4cac81SBjoern A. Zeeb 27806b4cac81SBjoern A. Zeeb ic = malloc(sizeof(*ic), M_LKPI80211, M_WAITOK | M_ZERO); 27816b4cac81SBjoern A. Zeeb if (ic == NULL) 27826b4cac81SBjoern A. Zeeb return (NULL); 27836b4cac81SBjoern A. Zeeb 27846b4cac81SBjoern A. Zeeb /* Setting these happens later when we have device information. */ 27856b4cac81SBjoern A. Zeeb ic->ic_softc = NULL; 27866b4cac81SBjoern A. Zeeb ic->ic_name = "linuxkpi"; 27876b4cac81SBjoern A. Zeeb 27886b4cac81SBjoern A. Zeeb return (ic); 27896b4cac81SBjoern A. Zeeb } 27906b4cac81SBjoern A. Zeeb 27916b4cac81SBjoern A. Zeeb struct ieee80211_hw * 27926b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_alloc_hw(size_t priv_len, const struct ieee80211_ops *ops) 27936b4cac81SBjoern A. Zeeb { 27946b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 27956b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 27966b4cac81SBjoern A. Zeeb struct wiphy *wiphy; 27976b4cac81SBjoern A. Zeeb 27986b4cac81SBjoern A. Zeeb /* Get us and the driver data also allocated. */ 27996b4cac81SBjoern A. Zeeb wiphy = wiphy_new(&linuxkpi_mac80211cfgops, sizeof(*lhw) + priv_len); 28006b4cac81SBjoern A. Zeeb if (wiphy == NULL) 28016b4cac81SBjoern A. Zeeb return (NULL); 28026b4cac81SBjoern A. Zeeb 28036b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 28046b4cac81SBjoern A. Zeeb lhw->ops = ops; 2805652e22d3SBjoern A. Zeeb 28066b4cac81SBjoern A. Zeeb mtx_init(&lhw->mtx, "lhw", NULL, MTX_DEF | MTX_RECURSE); 28076b4cac81SBjoern A. Zeeb TAILQ_INIT(&lhw->lvif_head); 28086b4cac81SBjoern A. Zeeb 28096b4cac81SBjoern A. Zeeb /* 28106b4cac81SBjoern A. Zeeb * XXX-BZ TODO make sure there is a "_null" function to all ops 28116b4cac81SBjoern A. Zeeb * not initialized. 28126b4cac81SBjoern A. Zeeb */ 28136b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 28146b4cac81SBjoern A. Zeeb hw->wiphy = wiphy; 2815086be6a8SBjoern A. Zeeb hw->conf.flags |= IEEE80211_CONF_IDLE; 28166b4cac81SBjoern A. Zeeb hw->priv = (void *)(lhw + 1); 28176b4cac81SBjoern A. Zeeb 28186b4cac81SBjoern A. Zeeb /* BSD Specific. */ 28196b4cac81SBjoern A. Zeeb lhw->ic = lkpi_ieee80211_ifalloc(); 28206b4cac81SBjoern A. Zeeb if (lhw->ic == NULL) { 28216b4cac81SBjoern A. Zeeb ieee80211_free_hw(hw); 28226b4cac81SBjoern A. Zeeb return (NULL); 28236b4cac81SBjoern A. Zeeb } 28246b4cac81SBjoern A. Zeeb 28256b4cac81SBjoern A. Zeeb IMPROVE(); 28266b4cac81SBjoern A. Zeeb 28276b4cac81SBjoern A. Zeeb return (hw); 28286b4cac81SBjoern A. Zeeb } 28296b4cac81SBjoern A. Zeeb 28306b4cac81SBjoern A. Zeeb void 28316b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iffree(struct ieee80211_hw *hw) 28326b4cac81SBjoern A. Zeeb { 28336b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 28346b4cac81SBjoern A. Zeeb 28356b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 28366b4cac81SBjoern A. Zeeb free(lhw->ic, M_LKPI80211); 28376b4cac81SBjoern A. Zeeb lhw->ic = NULL; 28386b4cac81SBjoern A. Zeeb 28396b4cac81SBjoern A. Zeeb /* Cleanup more of lhw here or in wiphy_free()? */ 28406b4cac81SBjoern A. Zeeb mtx_destroy(&lhw->mtx); 28416b4cac81SBjoern A. Zeeb IMPROVE(); 28426b4cac81SBjoern A. Zeeb } 28436b4cac81SBjoern A. Zeeb 28446b4cac81SBjoern A. Zeeb void 28456b4cac81SBjoern A. Zeeb linuxkpi_set_ieee80211_dev(struct ieee80211_hw *hw, char *name) 28466b4cac81SBjoern A. Zeeb { 28476b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 28486b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 28496b4cac81SBjoern A. Zeeb 28506b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 28516b4cac81SBjoern A. Zeeb ic = lhw->ic; 28526b4cac81SBjoern A. Zeeb 28536b4cac81SBjoern A. Zeeb /* Now set a proper name before ieee80211_ifattach(). */ 28546b4cac81SBjoern A. Zeeb ic->ic_softc = lhw; 28556b4cac81SBjoern A. Zeeb ic->ic_name = name; 28566b4cac81SBjoern A. Zeeb 28576b4cac81SBjoern A. Zeeb /* XXX-BZ do we also need to set wiphy name? */ 28586b4cac81SBjoern A. Zeeb } 28596b4cac81SBjoern A. Zeeb 28606b4cac81SBjoern A. Zeeb struct ieee80211_hw * 28616b4cac81SBjoern A. Zeeb linuxkpi_wiphy_to_ieee80211_hw(struct wiphy *wiphy) 28626b4cac81SBjoern A. Zeeb { 28636b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 28646b4cac81SBjoern A. Zeeb 28656b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 28666b4cac81SBjoern A. Zeeb return (LHW_TO_HW(lhw)); 28676b4cac81SBjoern A. Zeeb } 28686b4cac81SBjoern A. Zeeb 28696b4cac81SBjoern A. Zeeb static void 28706b4cac81SBjoern A. Zeeb lkpi_radiotap_attach(struct lkpi_hw *lhw) 28716b4cac81SBjoern A. Zeeb { 28726b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 28736b4cac81SBjoern A. Zeeb 28746b4cac81SBjoern A. Zeeb ic = lhw->ic; 28756b4cac81SBjoern A. Zeeb ieee80211_radiotap_attach(ic, 28766b4cac81SBjoern A. Zeeb &lhw->rtap_tx.wt_ihdr, sizeof(lhw->rtap_tx), 28776b4cac81SBjoern A. Zeeb LKPI_RTAP_TX_FLAGS_PRESENT, 28786b4cac81SBjoern A. Zeeb &lhw->rtap_rx.wr_ihdr, sizeof(lhw->rtap_rx), 28796b4cac81SBjoern A. Zeeb LKPI_RTAP_RX_FLAGS_PRESENT); 28806b4cac81SBjoern A. Zeeb } 28816b4cac81SBjoern A. Zeeb 28822e183d99SBjoern A. Zeeb int 28836b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ifattach(struct ieee80211_hw *hw) 28846b4cac81SBjoern A. Zeeb { 28856b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 28866b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 2887c5b96b3eSBjoern A. Zeeb int band, i; 28886b4cac81SBjoern A. Zeeb 28896b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 28906b4cac81SBjoern A. Zeeb ic = lhw->ic; 28916b4cac81SBjoern A. Zeeb 2892652e22d3SBjoern A. Zeeb /* We do it this late as wiphy->dev should be set for the name. */ 2893652e22d3SBjoern A. Zeeb lhw->workq = alloc_ordered_workqueue(wiphy_name(hw->wiphy), 0); 2894652e22d3SBjoern A. Zeeb if (lhw->workq == NULL) 2895652e22d3SBjoern A. Zeeb return (-EAGAIN); 2896652e22d3SBjoern A. Zeeb 28976b4cac81SBjoern A. Zeeb /* XXX-BZ figure this out how they count his... */ 28986b4cac81SBjoern A. Zeeb if (!is_zero_ether_addr(hw->wiphy->perm_addr)) { 28996b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(ic->ic_macaddr, 29006b4cac81SBjoern A. Zeeb hw->wiphy->perm_addr); 29016b4cac81SBjoern A. Zeeb } else if (hw->wiphy->n_addresses > 0) { 29026b4cac81SBjoern A. Zeeb /* We take the first one. */ 29036b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(ic->ic_macaddr, 29046b4cac81SBjoern A. Zeeb hw->wiphy->addresses[0].addr); 29056b4cac81SBjoern A. Zeeb } else { 29066b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: warning, no hardware address!\n", __func__); 29076b4cac81SBjoern A. Zeeb } 29086b4cac81SBjoern A. Zeeb 29093d09d310SBjoern A. Zeeb #ifdef __not_yet__ 29103d09d310SBjoern A. Zeeb /* See comment in lkpi_80211_txq_tx_one(). */ 29116b4cac81SBjoern A. Zeeb ic->ic_headroom = hw->extra_tx_headroom; 29123d09d310SBjoern A. Zeeb #endif 29136b4cac81SBjoern A. Zeeb 29146b4cac81SBjoern A. Zeeb ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ 29156b4cac81SBjoern A. Zeeb ic->ic_opmode = IEEE80211_M_STA; 29166b4cac81SBjoern A. Zeeb 29176b4cac81SBjoern A. Zeeb /* Set device capabilities. */ 29186b4cac81SBjoern A. Zeeb /* XXX-BZ we need to get these from linux80211/drivers and convert. */ 29196b4cac81SBjoern A. Zeeb ic->ic_caps = 29206b4cac81SBjoern A. Zeeb IEEE80211_C_STA | 29216b4cac81SBjoern A. Zeeb IEEE80211_C_MONITOR | 29226b4cac81SBjoern A. Zeeb IEEE80211_C_WPA | /* WPA/RSN */ 29236b4cac81SBjoern A. Zeeb IEEE80211_C_WME | 29246b4cac81SBjoern A. Zeeb #if 0 29256b4cac81SBjoern A. Zeeb IEEE80211_C_PMGT | 29266b4cac81SBjoern A. Zeeb #endif 29276b4cac81SBjoern A. Zeeb IEEE80211_C_SHSLOT | /* short slot time supported */ 29286b4cac81SBjoern A. Zeeb IEEE80211_C_SHPREAMBLE /* short preamble supported */ 29296b4cac81SBjoern A. Zeeb ; 29306b4cac81SBjoern A. Zeeb #if 0 29316b4cac81SBjoern A. Zeeb /* Scanning is a different kind of beast to re-work. */ 29326b4cac81SBjoern A. Zeeb ic->ic_caps |= IEEE80211_C_BGSCAN; 29336b4cac81SBjoern A. Zeeb #endif 2934cc4e78d5SBjoern A. Zeeb if (lhw->ops->hw_scan) { 2935cc4e78d5SBjoern A. Zeeb /* 2936cc4e78d5SBjoern A. Zeeb * Advertise full-offload scanning. 2937cc4e78d5SBjoern A. Zeeb * 2938cc4e78d5SBjoern A. Zeeb * Not limiting to SINGLE_SCAN_ON_ALL_BANDS here as otherwise 2939cc4e78d5SBjoern A. Zeeb * we essentially disable hw_scan for all drivers not setting 2940cc4e78d5SBjoern A. Zeeb * the flag. 2941cc4e78d5SBjoern A. Zeeb */ 29426b4cac81SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_SCAN_OFFLOAD; 29436b4cac81SBjoern A. Zeeb } 29446b4cac81SBjoern A. Zeeb 29456b4cac81SBjoern A. Zeeb #ifdef __notyet__ 29466b4cac81SBjoern A. Zeeb ic->ic_htcaps = IEEE80211_HTC_HT /* HT operation */ 29476b4cac81SBjoern A. Zeeb | IEEE80211_HTC_AMPDU /* A-MPDU tx/rx */ 29486b4cac81SBjoern A. Zeeb | IEEE80211_HTC_AMSDU /* A-MSDU tx/rx */ 29496b4cac81SBjoern A. Zeeb | IEEE80211_HTCAP_MAXAMSDU_3839 29506b4cac81SBjoern A. Zeeb /* max A-MSDU length */ 29516b4cac81SBjoern A. Zeeb | IEEE80211_HTCAP_SMPS_OFF; /* SM power save off */ 29526b4cac81SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_SHORTGI20; 29536b4cac81SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_CHWIDTH40 | IEEE80211_HTCAP_SHORTGI40; 29546b4cac81SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_TXSTBC; 29556b4cac81SBjoern A. Zeeb #endif 29566b4cac81SBjoern A. Zeeb 29576b4cac81SBjoern A. Zeeb ic->ic_cryptocaps = 0; 29586b4cac81SBjoern A. Zeeb #ifdef TRY_HW_CRYPTO 29596b4cac81SBjoern A. Zeeb if (hw->wiphy->n_cipher_suites > 0) { 29606b4cac81SBjoern A. Zeeb for (i = 0; i < hw->wiphy->n_cipher_suites; i++) 29616b4cac81SBjoern A. Zeeb ic->ic_cryptocaps |= lkpi_l80211_to_net80211_cyphers( 29626b4cac81SBjoern A. Zeeb hw->wiphy->cipher_suites[i]); 29636b4cac81SBjoern A. Zeeb } 29646b4cac81SBjoern A. Zeeb #endif 29656b4cac81SBjoern A. Zeeb 29666b4cac81SBjoern A. Zeeb lkpi_ic_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans, 29676b4cac81SBjoern A. Zeeb ic->ic_channels); 29686b4cac81SBjoern A. Zeeb 29696b4cac81SBjoern A. Zeeb ieee80211_ifattach(ic); 29706b4cac81SBjoern A. Zeeb 29716b4cac81SBjoern A. Zeeb ic->ic_update_mcast = lkpi_ic_update_mcast; 29726b4cac81SBjoern A. Zeeb ic->ic_update_promisc = lkpi_ic_update_promisc; 29736b4cac81SBjoern A. Zeeb ic->ic_update_chw = lkpi_ic_update_chw; 29746b4cac81SBjoern A. Zeeb ic->ic_parent = lkpi_ic_parent; 29756b4cac81SBjoern A. Zeeb ic->ic_scan_start = lkpi_ic_scan_start; 29766b4cac81SBjoern A. Zeeb ic->ic_scan_end = lkpi_ic_scan_end; 29776b4cac81SBjoern A. Zeeb if (lhw->ops->hw_scan && 29786b4cac81SBjoern A. Zeeb ieee80211_hw_check(hw, SINGLE_SCAN_ON_ALL_BANDS)) 29796b4cac81SBjoern A. Zeeb ic->ic_scan_curchan = lkpi_ic_scan_curchan_nada; 29806b4cac81SBjoern A. Zeeb ic->ic_set_channel = lkpi_ic_set_channel; 29816b4cac81SBjoern A. Zeeb ic->ic_transmit = lkpi_ic_transmit; 29826b4cac81SBjoern A. Zeeb ic->ic_raw_xmit = lkpi_ic_raw_xmit; 29836b4cac81SBjoern A. Zeeb ic->ic_vap_create = lkpi_ic_vap_create; 29846b4cac81SBjoern A. Zeeb ic->ic_vap_delete = lkpi_ic_vap_delete; 29856b4cac81SBjoern A. Zeeb ic->ic_getradiocaps = lkpi_ic_getradiocaps; 29866b4cac81SBjoern A. Zeeb ic->ic_wme.wme_update = lkpi_ic_wme_update; 29876b4cac81SBjoern A. Zeeb 29886b4cac81SBjoern A. Zeeb lhw->ic_node_alloc = ic->ic_node_alloc; 29896b4cac81SBjoern A. Zeeb ic->ic_node_alloc = lkpi_ic_node_alloc; 29906b4cac81SBjoern A. Zeeb lhw->ic_node_init = ic->ic_node_init; 29916b4cac81SBjoern A. Zeeb ic->ic_node_init = lkpi_ic_node_init; 29926b4cac81SBjoern A. Zeeb lhw->ic_node_cleanup = ic->ic_node_cleanup; 29936b4cac81SBjoern A. Zeeb ic->ic_node_cleanup = lkpi_ic_node_cleanup; 29946b4cac81SBjoern A. Zeeb lhw->ic_node_free = ic->ic_node_free; 29956b4cac81SBjoern A. Zeeb ic->ic_node_free = lkpi_ic_node_free; 29966b4cac81SBjoern A. Zeeb 29976b4cac81SBjoern A. Zeeb lkpi_radiotap_attach(lhw); 29986b4cac81SBjoern A. Zeeb 2999c5b96b3eSBjoern A. Zeeb /* 3000c5b96b3eSBjoern A. Zeeb * Assign the first possible channel for now; seems Realtek drivers 3001c5b96b3eSBjoern A. Zeeb * expect one. 3002c5b96b3eSBjoern A. Zeeb */ 3003c5b96b3eSBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS && 3004c5b96b3eSBjoern A. Zeeb hw->conf.chandef.chan == NULL; band++) { 3005c5b96b3eSBjoern A. Zeeb struct ieee80211_supported_band *supband; 3006c5b96b3eSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 3007c5b96b3eSBjoern A. Zeeb 3008c5b96b3eSBjoern A. Zeeb supband = hw->wiphy->bands[band]; 3009c5b96b3eSBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 3010c5b96b3eSBjoern A. Zeeb continue; 3011c5b96b3eSBjoern A. Zeeb 3012c5b96b3eSBjoern A. Zeeb channels = supband->channels; 3013c5b96b3eSBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 3014c5b96b3eSBjoern A. Zeeb struct cfg80211_chan_def chandef; 3015c5b96b3eSBjoern A. Zeeb 3016c5b96b3eSBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) 3017c5b96b3eSBjoern A. Zeeb continue; 3018c5b96b3eSBjoern A. Zeeb 3019c5b96b3eSBjoern A. Zeeb memset(&chandef, 0, sizeof(chandef)); 3020c5b96b3eSBjoern A. Zeeb cfg80211_chandef_create(&chandef, &channels[i], 3021c5b96b3eSBjoern A. Zeeb NL80211_CHAN_NO_HT); 3022c5b96b3eSBjoern A. Zeeb hw->conf.chandef = chandef; 3023c5b96b3eSBjoern A. Zeeb break; 3024c5b96b3eSBjoern A. Zeeb } 3025c5b96b3eSBjoern A. Zeeb } 3026c5b96b3eSBjoern A. Zeeb 30276b4cac81SBjoern A. Zeeb if (bootverbose) 30286b4cac81SBjoern A. Zeeb ieee80211_announce(ic); 30292e183d99SBjoern A. Zeeb 30302e183d99SBjoern A. Zeeb return (0); 30316b4cac81SBjoern A. Zeeb } 30326b4cac81SBjoern A. Zeeb 30336b4cac81SBjoern A. Zeeb void 30346b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ifdetach(struct ieee80211_hw *hw) 30356b4cac81SBjoern A. Zeeb { 30366b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 30376b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 30386b4cac81SBjoern A. Zeeb 30396b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 30406b4cac81SBjoern A. Zeeb ic = lhw->ic; 30416b4cac81SBjoern A. Zeeb ieee80211_ifdetach(ic); 30426b4cac81SBjoern A. Zeeb } 30436b4cac81SBjoern A. Zeeb 30446b4cac81SBjoern A. Zeeb void 30456b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_interfaces(struct ieee80211_hw *hw, 30466b4cac81SBjoern A. Zeeb enum ieee80211_iface_iter flags, 30476b4cac81SBjoern A. Zeeb void(*iterfunc)(void *, uint8_t *, struct ieee80211_vif *), 30486b4cac81SBjoern A. Zeeb void *arg) 30496b4cac81SBjoern A. Zeeb { 30506b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 30516b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 30526b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 305361a68e50SBjoern A. Zeeb bool active, atomic, nin_drv; 30546b4cac81SBjoern A. Zeeb 30556b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 30566b4cac81SBjoern A. Zeeb 30576b4cac81SBjoern A. Zeeb if (flags & ~(IEEE80211_IFACE_ITER_NORMAL| 30586b4cac81SBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL| 305961a68e50SBjoern A. Zeeb IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER| 30606b4cac81SBjoern A. Zeeb IEEE80211_IFACE_ITER__ACTIVE|IEEE80211_IFACE_ITER__ATOMIC)) { 30616b4cac81SBjoern A. Zeeb ic_printf(lhw->ic, "XXX TODO %s flags(%#x) not yet supported.\n", 30626b4cac81SBjoern A. Zeeb __func__, flags); 30636b4cac81SBjoern A. Zeeb } 30646b4cac81SBjoern A. Zeeb 30656b4cac81SBjoern A. Zeeb active = (flags & IEEE80211_IFACE_ITER__ACTIVE) != 0; 30666b4cac81SBjoern A. Zeeb atomic = (flags & IEEE80211_IFACE_ITER__ATOMIC) != 0; 306761a68e50SBjoern A. Zeeb nin_drv = (flags & IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER) != 0; 30686b4cac81SBjoern A. Zeeb 30696b4cac81SBjoern A. Zeeb if (atomic) 30706b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 30716b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 30726b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 30736b4cac81SBjoern A. Zeeb 30746b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 30756b4cac81SBjoern A. Zeeb 30766b4cac81SBjoern A. Zeeb /* 30776b4cac81SBjoern A. Zeeb * If we want "active" interfaces, we need to distinguish on 30786b4cac81SBjoern A. Zeeb * whether the driver knows about them or not to be able to 30796b4cac81SBjoern A. Zeeb * handle the "resume" case correctly. Skip the ones the 30806b4cac81SBjoern A. Zeeb * driver does not know about. 30816b4cac81SBjoern A. Zeeb */ 30826b4cac81SBjoern A. Zeeb if (active && !lvif->added_to_drv && 30836b4cac81SBjoern A. Zeeb (flags & IEEE80211_IFACE_ITER_RESUME_ALL) != 0) 30846b4cac81SBjoern A. Zeeb continue; 30856b4cac81SBjoern A. Zeeb 30866b4cac81SBjoern A. Zeeb /* 308761a68e50SBjoern A. Zeeb * If we shall skip interfaces not added to the driver do so 308861a68e50SBjoern A. Zeeb * if we haven't yet. 308961a68e50SBjoern A. Zeeb */ 309061a68e50SBjoern A. Zeeb if (nin_drv && !lvif->added_to_drv) 309161a68e50SBjoern A. Zeeb continue; 309261a68e50SBjoern A. Zeeb 309361a68e50SBjoern A. Zeeb /* 30946b4cac81SBjoern A. Zeeb * Run the iterator function if we are either not asking 30956b4cac81SBjoern A. Zeeb * asking for active only or if the VAP is "running". 30966b4cac81SBjoern A. Zeeb */ 30976b4cac81SBjoern A. Zeeb /* XXX-BZ probably should have state in the lvif as well. */ 30986b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 30996b4cac81SBjoern A. Zeeb if (!active || (vap->iv_state != IEEE80211_S_INIT)) 31006b4cac81SBjoern A. Zeeb iterfunc(arg, vif->addr, vif); 31016b4cac81SBjoern A. Zeeb } 31026b4cac81SBjoern A. Zeeb if (atomic) 31036b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 31046b4cac81SBjoern A. Zeeb } 31056b4cac81SBjoern A. Zeeb 31066b4cac81SBjoern A. Zeeb void 31076b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_keys(struct ieee80211_hw *hw, 31086b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif, 31096b4cac81SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_vif *, 31106b4cac81SBjoern A. Zeeb struct ieee80211_sta *, struct ieee80211_key_conf *, void *), 31116b4cac81SBjoern A. Zeeb void *arg) 31126b4cac81SBjoern A. Zeeb { 31136b4cac81SBjoern A. Zeeb 31146b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 31156b4cac81SBjoern A. Zeeb } 31166b4cac81SBjoern A. Zeeb 31176b4cac81SBjoern A. Zeeb void 31186b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_chan_contexts(struct ieee80211_hw *hw, 31196b4cac81SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_chanctx_conf *, 31206b4cac81SBjoern A. Zeeb void *), 31216b4cac81SBjoern A. Zeeb void *arg) 31226b4cac81SBjoern A. Zeeb { 31236b4cac81SBjoern A. Zeeb 31246b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 31256b4cac81SBjoern A. Zeeb } 31266b4cac81SBjoern A. Zeeb 31276b4cac81SBjoern A. Zeeb void 31286b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_stations_atomic(struct ieee80211_hw *hw, 31296b4cac81SBjoern A. Zeeb void (*iterfunc)(void *, struct ieee80211_sta *), void *arg) 31306b4cac81SBjoern A. Zeeb { 31316b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 31326b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 31336b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 31346b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 31356b4cac81SBjoern A. Zeeb 31366b4cac81SBjoern A. Zeeb KASSERT(hw != NULL && iterfunc != NULL, 31376b4cac81SBjoern A. Zeeb ("%s: hw %p iterfunc %p arg %p\n", __func__, hw, iterfunc, arg)); 31386b4cac81SBjoern A. Zeeb 31396b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 31406b4cac81SBjoern A. Zeeb 31416b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 31426b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 31436b4cac81SBjoern A. Zeeb 31446b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 31456b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lsta, &lvif->lsta_head, lsta_entry) { 31466b4cac81SBjoern A. Zeeb if (!lsta->added_to_drv) 31476b4cac81SBjoern A. Zeeb continue; 31486b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 31496b4cac81SBjoern A. Zeeb iterfunc(arg, sta); 31506b4cac81SBjoern A. Zeeb } 31516b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 31526b4cac81SBjoern A. Zeeb } 31536b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 31546b4cac81SBjoern A. Zeeb } 31556b4cac81SBjoern A. Zeeb 31566b4cac81SBjoern A. Zeeb int 31576b4cac81SBjoern A. Zeeb linuxkpi_regulatory_set_wiphy_regd_sync(struct wiphy *wiphy, 31586b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_regdomain *regd) 31596b4cac81SBjoern A. Zeeb { 31606b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 31616b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 31626b4cac81SBjoern A. Zeeb struct ieee80211_regdomain *rd; 31636b4cac81SBjoern A. Zeeb 31646b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 31656b4cac81SBjoern A. Zeeb ic = lhw->ic; 31666b4cac81SBjoern A. Zeeb 31676b4cac81SBjoern A. Zeeb rd = &ic->ic_regdomain; 31686b4cac81SBjoern A. Zeeb if (rd->isocc[0] == '\0') { 31696b4cac81SBjoern A. Zeeb rd->isocc[0] = regd->alpha2[0]; 31706b4cac81SBjoern A. Zeeb rd->isocc[1] = regd->alpha2[1]; 31716b4cac81SBjoern A. Zeeb } 31726b4cac81SBjoern A. Zeeb 31736b4cac81SBjoern A. Zeeb TODO(); 31746b4cac81SBjoern A. Zeeb /* XXX-BZ finish the rest. */ 31756b4cac81SBjoern A. Zeeb 31766b4cac81SBjoern A. Zeeb return (0); 31776b4cac81SBjoern A. Zeeb } 31786b4cac81SBjoern A. Zeeb 31796b4cac81SBjoern A. Zeeb void 31806b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_scan_completed(struct ieee80211_hw *hw, 31816b4cac81SBjoern A. Zeeb struct cfg80211_scan_info *info) 31826b4cac81SBjoern A. Zeeb { 31836b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 31846b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 31856b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 31866b4cac81SBjoern A. Zeeb 31876b4cac81SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 31886b4cac81SBjoern A. Zeeb ic = lhw->ic; 31896b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 31906b4cac81SBjoern A. Zeeb 31916b4cac81SBjoern A. Zeeb ieee80211_scan_done(ss->ss_vap); 31926b4cac81SBjoern A. Zeeb 31936b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 31946b4cac81SBjoern A. Zeeb free(lhw->hw_req->ies.common_ies, M_80211_VAP); 31956b4cac81SBjoern A. Zeeb free(lhw->hw_req, M_LKPI80211); 31966b4cac81SBjoern A. Zeeb lhw->hw_req = NULL; 31976b4cac81SBjoern A. Zeeb lhw->scan_flags &= ~LKPI_SCAN_RUNNING; 31986b4cac81SBjoern A. Zeeb wakeup(lhw); 31996b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 32006b4cac81SBjoern A. Zeeb 32016b4cac81SBjoern A. Zeeb return; 32026b4cac81SBjoern A. Zeeb } 32036b4cac81SBjoern A. Zeeb 32046b4cac81SBjoern A. Zeeb void 32056b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb, 32066b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta, struct napi_struct *napi __unused) 32076b4cac81SBjoern A. Zeeb { 32086b4cac81SBjoern A. Zeeb struct epoch_tracker et; 32096b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 32106b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 32116b4cac81SBjoern A. Zeeb struct mbuf *m; 32126b4cac81SBjoern A. Zeeb struct skb_shared_info *shinfo; 32136b4cac81SBjoern A. Zeeb struct ieee80211_rx_status *rx_status; 32146b4cac81SBjoern A. Zeeb struct ieee80211_rx_stats rx_stats; 32156b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 32166b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 32176b4cac81SBjoern A. Zeeb struct ieee80211_hdr *hdr; 32186b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 32196b4cac81SBjoern A. Zeeb int i, offset, ok, type; 3220c0cadd99SBjoern A. Zeeb bool is_beacon; 32216b4cac81SBjoern A. Zeeb 32226b4cac81SBjoern A. Zeeb if (skb->len < 2) { 32236b4cac81SBjoern A. Zeeb /* Need 80211 stats here. */ 32246b4cac81SBjoern A. Zeeb IMPROVE(); 32256b4cac81SBjoern A. Zeeb goto err; 32266b4cac81SBjoern A. Zeeb } 32276b4cac81SBjoern A. Zeeb 32286b4cac81SBjoern A. Zeeb /* 32296b4cac81SBjoern A. Zeeb * For now do the data copy; we can later improve things. Might even 32306b4cac81SBjoern A. Zeeb * have an mbuf backing the skb data then? 32316b4cac81SBjoern A. Zeeb */ 32326b4cac81SBjoern A. Zeeb m = m_get2(skb->len, M_NOWAIT, MT_DATA, M_PKTHDR); 32336b4cac81SBjoern A. Zeeb if (m == NULL) 32346b4cac81SBjoern A. Zeeb goto err; 32356b4cac81SBjoern A. Zeeb m_copyback(m, 0, skb->tail - skb->data, skb->data); 32366b4cac81SBjoern A. Zeeb 32376b4cac81SBjoern A. Zeeb shinfo = skb_shinfo(skb); 32386b4cac81SBjoern A. Zeeb offset = m->m_len; 32396b4cac81SBjoern A. Zeeb for (i = 0; i < shinfo->nr_frags; i++) { 32406b4cac81SBjoern A. Zeeb m_copyback(m, offset, shinfo->frags[i].size, 32416b4cac81SBjoern A. Zeeb (uint8_t *)linux_page_address(shinfo->frags[i].page) + 32426b4cac81SBjoern A. Zeeb shinfo->frags[i].offset); 32436b4cac81SBjoern A. Zeeb offset += shinfo->frags[i].size; 32446b4cac81SBjoern A. Zeeb } 32456b4cac81SBjoern A. Zeeb 32466b4cac81SBjoern A. Zeeb rx_status = IEEE80211_SKB_RXCB(skb); 32476b4cac81SBjoern A. Zeeb 32486b4cac81SBjoern A. Zeeb hdr = (void *)skb->data; 3249c0cadd99SBjoern A. Zeeb is_beacon = ieee80211_is_beacon(hdr->frame_control); 3250c0cadd99SBjoern A. Zeeb 3251c0cadd99SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 3252c0cadd99SBjoern A. Zeeb if (is_beacon && (debug_80211 & D80211_TRACE_RX_BEACONS) == 0) 32536b4cac81SBjoern A. Zeeb goto no_trace_beacons; 32546b4cac81SBjoern A. Zeeb 32556b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_RX) 32566b4cac81SBjoern A. Zeeb printf("TRACE-RX: %s: skb %p a/l/d/t-len (%u/%u/%u/%u) " 3257c0cadd99SBjoern A. Zeeb "h %p d %p t %p e %p sh %p (%u) m %p plen %u len %u%s\n", 32586b4cac81SBjoern A. Zeeb __func__, skb, skb->_alloc_len, skb->len, skb->data_len, 32596b4cac81SBjoern A. Zeeb skb->truesize, skb->head, skb->data, skb->tail, skb->end, 32606b4cac81SBjoern A. Zeeb shinfo, shinfo->nr_frags, 3261c0cadd99SBjoern A. Zeeb m, m->m_pkthdr.len, m->m_len, is_beacon ? " beacon" : ""); 32626b4cac81SBjoern A. Zeeb 32636b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_RX_DUMP) 32646b4cac81SBjoern A. Zeeb hexdump(mtod(m, const void *), m->m_len, "RX (raw) ", 0); 32656b4cac81SBjoern A. Zeeb 32666b4cac81SBjoern A. Zeeb /* Implement a dump_rxcb() !!! */ 32676b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_RX) 3268c8dafefaSBjoern A. Zeeb printf("TRACE %s: RXCB: %ju %ju %u, %#0x, %u, %#0x, %#0x, " 32696b4cac81SBjoern A. Zeeb "%u band %u, %u %u %u %u, %u, %#x %#x %#x %#x %u %u %u\n", 32706b4cac81SBjoern A. Zeeb __func__, 3271c8dafefaSBjoern A. Zeeb (uintmax_t)rx_status->boottime_ns, 3272c8dafefaSBjoern A. Zeeb (uintmax_t)rx_status->mactime, 32736b4cac81SBjoern A. Zeeb rx_status->device_timestamp, 32746b4cac81SBjoern A. Zeeb rx_status->flag, 32756b4cac81SBjoern A. Zeeb rx_status->freq, 32766b4cac81SBjoern A. Zeeb rx_status->bw, 32776b4cac81SBjoern A. Zeeb rx_status->encoding, 32786b4cac81SBjoern A. Zeeb rx_status->ampdu_reference, 32796b4cac81SBjoern A. Zeeb rx_status->band, 32806b4cac81SBjoern A. Zeeb rx_status->chains, 32816b4cac81SBjoern A. Zeeb rx_status->chain_signal[0], 32826b4cac81SBjoern A. Zeeb rx_status->chain_signal[1], 32836b4cac81SBjoern A. Zeeb rx_status->chain_signal[2], 32846b4cac81SBjoern A. Zeeb rx_status->signal, 32856b4cac81SBjoern A. Zeeb rx_status->enc_flags, 32866b4cac81SBjoern A. Zeeb rx_status->he_dcm, 32876b4cac81SBjoern A. Zeeb rx_status->he_gi, 32886b4cac81SBjoern A. Zeeb rx_status->he_ru, 32896b4cac81SBjoern A. Zeeb rx_status->zero_length_psdu_type, 32906b4cac81SBjoern A. Zeeb rx_status->nss, 32916b4cac81SBjoern A. Zeeb rx_status->rate_idx); 32926b4cac81SBjoern A. Zeeb no_trace_beacons: 32936b4cac81SBjoern A. Zeeb #endif 32946b4cac81SBjoern A. Zeeb 32956b4cac81SBjoern A. Zeeb memset(&rx_stats, 0, sizeof(rx_stats)); 32966b4cac81SBjoern A. Zeeb rx_stats.r_flags = IEEE80211_R_NF | IEEE80211_R_RSSI; 32976b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, SIGNAL_DBM) && 32986b4cac81SBjoern A. Zeeb !(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL)) 32996b4cac81SBjoern A. Zeeb rx_stats.c_rssi = rx_status->signal; 33006b4cac81SBjoern A. Zeeb else 33016b4cac81SBjoern A. Zeeb rx_stats.c_rssi = 0; /* XXX */ 33026b4cac81SBjoern A. Zeeb rx_stats.c_nf = -96; /* XXX */ 33036b4cac81SBjoern A. Zeeb rx_stats.r_flags |= IEEE80211_R_BAND; 33046b4cac81SBjoern A. Zeeb rx_stats.c_band = 33056b4cac81SBjoern A. Zeeb lkpi_nl80211_band_to_net80211_band(rx_status->band); 33066b4cac81SBjoern A. Zeeb rx_stats.r_flags |= IEEE80211_R_FREQ | IEEE80211_R_IEEE; 33076b4cac81SBjoern A. Zeeb rx_stats.c_freq = rx_status->freq; 33086b4cac81SBjoern A. Zeeb rx_stats.c_ieee = ieee80211_mhz2ieee(rx_stats.c_freq, rx_stats.c_band); 33096b4cac81SBjoern A. Zeeb 33106b4cac81SBjoern A. Zeeb /* XXX-BZ correct hardcoded rssi and noise floor. */ 33116b4cac81SBjoern A. Zeeb /* XXX (*sta_statistics)() to get to some of that? */ 33126b4cac81SBjoern A. Zeeb /* XXX-BZ dump the FreeBSD version of rx_stats as well! */ 33136b4cac81SBjoern A. Zeeb 33146b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 33156b4cac81SBjoern A. Zeeb ic = lhw->ic; 33166b4cac81SBjoern A. Zeeb 33176b4cac81SBjoern A. Zeeb ok = ieee80211_add_rx_params(m, &rx_stats); 33186b4cac81SBjoern A. Zeeb if (ok == 0) { 33196b4cac81SBjoern A. Zeeb counter_u64_add(ic->ic_ierrors, 1); 33206b4cac81SBjoern A. Zeeb goto err; 33216b4cac81SBjoern A. Zeeb } 33226b4cac81SBjoern A. Zeeb 33236b4cac81SBjoern A. Zeeb if (sta != NULL) { 33246b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 33256b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(lsta->ni); 33266b4cac81SBjoern A. Zeeb } else { 3327c8dafefaSBjoern A. Zeeb struct ieee80211_frame_min *wh; 3328c8dafefaSBjoern A. Zeeb 33296b4cac81SBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame_min *); 33306b4cac81SBjoern A. Zeeb ni = ieee80211_find_rxnode(ic, wh); 33316b4cac81SBjoern A. Zeeb if (ni != NULL) 33326b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 33336b4cac81SBjoern A. Zeeb } 33346b4cac81SBjoern A. Zeeb 33356b4cac81SBjoern A. Zeeb if (ni != NULL) 33366b4cac81SBjoern A. Zeeb vap = ni->ni_vap; 33376b4cac81SBjoern A. Zeeb else 33386b4cac81SBjoern A. Zeeb /* 33396b4cac81SBjoern A. Zeeb * XXX-BZ can we improve this by looking at the frame hdr 33406b4cac81SBjoern A. Zeeb * or other meta-data passed up? 33416b4cac81SBjoern A. Zeeb */ 33426b4cac81SBjoern A. Zeeb vap = TAILQ_FIRST(&ic->ic_vaps); 33436b4cac81SBjoern A. Zeeb 33446b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_RX) 3345c0cadd99SBjoern A. Zeeb printf("TRACE %s: sta %p lsta %p state %d ni %p vap %p%s\n", 3346c0cadd99SBjoern A. Zeeb __func__, sta, lsta, (lsta != NULL) ? lsta->state : -1, 3347c0cadd99SBjoern A. Zeeb ni, vap, is_beacon ? " beacon" : ""); 33486b4cac81SBjoern A. Zeeb 3349c0cadd99SBjoern A. Zeeb if (ni != NULL && vap != NULL && is_beacon && 3350c8dafefaSBjoern A. Zeeb rx_status->device_timestamp > 0 && 3351c8dafefaSBjoern A. Zeeb m->m_pkthdr.len >= sizeof(struct ieee80211_frame)) { 3352c8dafefaSBjoern A. Zeeb struct lkpi_vif *lvif; 3353c8dafefaSBjoern A. Zeeb struct ieee80211_vif *vif; 3354c8dafefaSBjoern A. Zeeb struct ieee80211_frame *wh; 3355c8dafefaSBjoern A. Zeeb 3356c8dafefaSBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame *); 3357c8dafefaSBjoern A. Zeeb if (!IEEE80211_ADDR_EQ(wh->i_addr2, ni->ni_bssid)) 3358c8dafefaSBjoern A. Zeeb goto skip_device_ts; 3359c8dafefaSBjoern A. Zeeb 3360c8dafefaSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 3361c8dafefaSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 3362c8dafefaSBjoern A. Zeeb 3363c8dafefaSBjoern A. Zeeb IMPROVE("TIMING_BEACON_ONLY?"); 3364c8dafefaSBjoern A. Zeeb /* mac80211 specific (not net80211) so keep it here. */ 3365c8dafefaSBjoern A. Zeeb vif->bss_conf.sync_device_ts = rx_status->device_timestamp; 3366c8dafefaSBjoern A. Zeeb /* 3367c8dafefaSBjoern A. Zeeb * net80211 should take care of the other information (sync_tsf, 3368c8dafefaSBjoern A. Zeeb * sync_dtim_count) as otherwise we need to parse the beacon. 3369c8dafefaSBjoern A. Zeeb */ 3370c8dafefaSBjoern A. Zeeb } 3371c8dafefaSBjoern A. Zeeb skip_device_ts: 3372c8dafefaSBjoern A. Zeeb 33736b4cac81SBjoern A. Zeeb if (vap != NULL && vap->iv_state > IEEE80211_S_INIT && 33746b4cac81SBjoern A. Zeeb ieee80211_radiotap_active_vap(vap)) { 33756b4cac81SBjoern A. Zeeb struct lkpi_radiotap_rx_hdr *rtap; 33766b4cac81SBjoern A. Zeeb 33776b4cac81SBjoern A. Zeeb rtap = &lhw->rtap_rx; 33786b4cac81SBjoern A. Zeeb rtap->wr_tsft = rx_status->device_timestamp; 33796b4cac81SBjoern A. Zeeb rtap->wr_flags = 0; 33806b4cac81SBjoern A. Zeeb if (rx_status->enc_flags & RX_ENC_FLAG_SHORTPRE) 33816b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; 33826b4cac81SBjoern A. Zeeb if (rx_status->enc_flags & RX_ENC_FLAG_SHORT_GI) 33836b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTGI; 33846b4cac81SBjoern A. Zeeb #if 0 /* .. or it does not given we strip it below. */ 33856b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, RX_INCLUDES_FCS)) 33866b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_FCS; 33876b4cac81SBjoern A. Zeeb #endif 33886b4cac81SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_FAILED_FCS_CRC) 33896b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_BADFCS; 33906b4cac81SBjoern A. Zeeb rtap->wr_rate = 0; 33916b4cac81SBjoern A. Zeeb IMPROVE(); 33926b4cac81SBjoern A. Zeeb /* XXX TODO status->encoding / rate_index / bw */ 33936b4cac81SBjoern A. Zeeb rtap->wr_chan_freq = htole16(rx_stats.c_freq); 33946b4cac81SBjoern A. Zeeb if (ic->ic_curchan->ic_ieee == rx_stats.c_ieee) 33956b4cac81SBjoern A. Zeeb rtap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags); 33966b4cac81SBjoern A. Zeeb rtap->wr_dbm_antsignal = rx_stats.c_rssi; 33976b4cac81SBjoern A. Zeeb rtap->wr_dbm_antnoise = rx_stats.c_nf; 33986b4cac81SBjoern A. Zeeb } 33996b4cac81SBjoern A. Zeeb 34006b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, RX_INCLUDES_FCS)) 34016b4cac81SBjoern A. Zeeb m_adj(m, -IEEE80211_CRC_LEN); 34026b4cac81SBjoern A. Zeeb 34036b4cac81SBjoern A. Zeeb NET_EPOCH_ENTER(et); 34046b4cac81SBjoern A. Zeeb if (ni != NULL) { 34056b4cac81SBjoern A. Zeeb type = ieee80211_input_mimo(ni, m); 34066b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 34076b4cac81SBjoern A. Zeeb } else { 34086b4cac81SBjoern A. Zeeb type = ieee80211_input_mimo_all(ic, m); 34096b4cac81SBjoern A. Zeeb } 34106b4cac81SBjoern A. Zeeb NET_EPOCH_EXIT(et); 34116b4cac81SBjoern A. Zeeb 34126b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE_RX) 34136b4cac81SBjoern A. Zeeb printf("TRACE %s: handled frame type %#0x\n", __func__, type); 34146b4cac81SBjoern A. Zeeb 34156b4cac81SBjoern A. Zeeb IMPROVE(); 34166b4cac81SBjoern A. Zeeb 34176b4cac81SBjoern A. Zeeb err: 34186b4cac81SBjoern A. Zeeb /* The skb is ours so we can free it :-) */ 34196b4cac81SBjoern A. Zeeb kfree_skb(skb); 34206b4cac81SBjoern A. Zeeb } 34216b4cac81SBjoern A. Zeeb 34226b4cac81SBjoern A. Zeeb uint8_t 34236b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_get_tid(struct ieee80211_hdr *hdr) 34246b4cac81SBjoern A. Zeeb { 34256b4cac81SBjoern A. Zeeb const struct ieee80211_frame *wh; 34266b4cac81SBjoern A. Zeeb 34276b4cac81SBjoern A. Zeeb wh = (const struct ieee80211_frame *)hdr; 34286b4cac81SBjoern A. Zeeb return (ieee80211_gettid(wh)); 34296b4cac81SBjoern A. Zeeb } 34306b4cac81SBjoern A. Zeeb 34316b4cac81SBjoern A. Zeeb struct wiphy * 34326b4cac81SBjoern A. Zeeb linuxkpi_wiphy_new(const struct cfg80211_ops *ops, size_t priv_len) 34336b4cac81SBjoern A. Zeeb { 34346b4cac81SBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 34356b4cac81SBjoern A. Zeeb 34366b4cac81SBjoern A. Zeeb lwiphy = kzalloc(sizeof(*lwiphy) + priv_len, GFP_KERNEL); 34376b4cac81SBjoern A. Zeeb if (lwiphy == NULL) 34386b4cac81SBjoern A. Zeeb return (NULL); 34396b4cac81SBjoern A. Zeeb lwiphy->ops = ops; 34406b4cac81SBjoern A. Zeeb 34416b4cac81SBjoern A. Zeeb /* XXX TODO */ 34426b4cac81SBjoern A. Zeeb return (LWIPHY_TO_WIPHY(lwiphy)); 34436b4cac81SBjoern A. Zeeb } 34446b4cac81SBjoern A. Zeeb 34456b4cac81SBjoern A. Zeeb void 34466b4cac81SBjoern A. Zeeb linuxkpi_wiphy_free(struct wiphy *wiphy) 34476b4cac81SBjoern A. Zeeb { 34486b4cac81SBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 34496b4cac81SBjoern A. Zeeb 34506b4cac81SBjoern A. Zeeb if (wiphy == NULL) 34516b4cac81SBjoern A. Zeeb return; 34526b4cac81SBjoern A. Zeeb 34536b4cac81SBjoern A. Zeeb lwiphy = WIPHY_TO_LWIPHY(wiphy); 34546b4cac81SBjoern A. Zeeb kfree(lwiphy); 34556b4cac81SBjoern A. Zeeb } 34566b4cac81SBjoern A. Zeeb 34576b4cac81SBjoern A. Zeeb uint32_t 34586b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_channel_to_frequency(uint32_t channel, 34596b4cac81SBjoern A. Zeeb enum nl80211_band band) 34606b4cac81SBjoern A. Zeeb { 34616b4cac81SBjoern A. Zeeb 34626b4cac81SBjoern A. Zeeb switch (band) { 34636b4cac81SBjoern A. Zeeb case NL80211_BAND_2GHZ: 34646b4cac81SBjoern A. Zeeb return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_2GHZ)); 34656b4cac81SBjoern A. Zeeb break; 34666b4cac81SBjoern A. Zeeb case NL80211_BAND_5GHZ: 34676b4cac81SBjoern A. Zeeb return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_5GHZ)); 34686b4cac81SBjoern A. Zeeb break; 34696b4cac81SBjoern A. Zeeb default: 34706b4cac81SBjoern A. Zeeb /* XXX abort, retry, error, panic? */ 34716b4cac81SBjoern A. Zeeb break; 34726b4cac81SBjoern A. Zeeb } 34736b4cac81SBjoern A. Zeeb 34746b4cac81SBjoern A. Zeeb return (0); 34756b4cac81SBjoern A. Zeeb } 34766b4cac81SBjoern A. Zeeb 34776b4cac81SBjoern A. Zeeb uint32_t 34786b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_frequency_to_channel(uint32_t freq, uint32_t flags __unused) 34796b4cac81SBjoern A. Zeeb { 34806b4cac81SBjoern A. Zeeb 34816b4cac81SBjoern A. Zeeb return (ieee80211_mhz2ieee(freq, 0)); 34826b4cac81SBjoern A. Zeeb } 34836b4cac81SBjoern A. Zeeb 34846b4cac81SBjoern A. Zeeb static struct lkpi_sta * 34856b4cac81SBjoern A. Zeeb lkpi_find_lsta_by_ni(struct lkpi_vif *lvif, struct ieee80211_node *ni) 34866b4cac81SBjoern A. Zeeb { 34876b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta, *temp; 34886b4cac81SBjoern A. Zeeb 34896b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 34906b4cac81SBjoern A. Zeeb TAILQ_FOREACH_SAFE(lsta, &lvif->lsta_head, lsta_entry, temp) { 34916b4cac81SBjoern A. Zeeb if (lsta->ni == ni) { 34926b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 34936b4cac81SBjoern A. Zeeb return (lsta); 34946b4cac81SBjoern A. Zeeb } 34956b4cac81SBjoern A. Zeeb } 34966b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 34976b4cac81SBjoern A. Zeeb 34986b4cac81SBjoern A. Zeeb return (NULL); 34996b4cac81SBjoern A. Zeeb } 35006b4cac81SBjoern A. Zeeb 35016b4cac81SBjoern A. Zeeb struct ieee80211_sta * 35026b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_find_sta(struct ieee80211_vif *vif, const u8 *peer) 35036b4cac81SBjoern A. Zeeb { 35046b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 35056b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta, *temp; 35066b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 35076b4cac81SBjoern A. Zeeb 35086b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 35096b4cac81SBjoern A. Zeeb 35106b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 35116b4cac81SBjoern A. Zeeb TAILQ_FOREACH_SAFE(lsta, &lvif->lsta_head, lsta_entry, temp) { 35126b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 35136b4cac81SBjoern A. Zeeb if (IEEE80211_ADDR_EQ(sta->addr, peer)) { 35146b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 35156b4cac81SBjoern A. Zeeb return (sta); 35166b4cac81SBjoern A. Zeeb } 35176b4cac81SBjoern A. Zeeb } 35186b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 35196b4cac81SBjoern A. Zeeb return (NULL); 35206b4cac81SBjoern A. Zeeb } 35216b4cac81SBjoern A. Zeeb 35226b4cac81SBjoern A. Zeeb struct ieee80211_sta * 35232e183d99SBjoern A. Zeeb linuxkpi_ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw, 35242e183d99SBjoern A. Zeeb const uint8_t *addr, const uint8_t *ourvifaddr) 35256b4cac81SBjoern A. Zeeb { 35266b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 35276b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 35286b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 35296b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 35306b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 35316b4cac81SBjoern A. Zeeb 35326b4cac81SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 35336b4cac81SBjoern A. Zeeb sta = NULL; 35346b4cac81SBjoern A. Zeeb 35356b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 35366b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 35376b4cac81SBjoern A. Zeeb 35386b4cac81SBjoern A. Zeeb /* XXX-BZ check our address from the vif. */ 35396b4cac81SBjoern A. Zeeb 35406b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 35416b4cac81SBjoern A. Zeeb if (ourvifaddr != NULL && 35426b4cac81SBjoern A. Zeeb !IEEE80211_ADDR_EQ(vif->addr, ourvifaddr)) 35436b4cac81SBjoern A. Zeeb continue; 35446b4cac81SBjoern A. Zeeb sta = linuxkpi_ieee80211_find_sta(vif, addr); 35456b4cac81SBjoern A. Zeeb if (sta != NULL) 35466b4cac81SBjoern A. Zeeb break; 35476b4cac81SBjoern A. Zeeb } 35486b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 35496b4cac81SBjoern A. Zeeb 35506b4cac81SBjoern A. Zeeb if (sta != NULL) { 35516b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 35526b4cac81SBjoern A. Zeeb if (!lsta->added_to_drv) 35536b4cac81SBjoern A. Zeeb return (NULL); 35546b4cac81SBjoern A. Zeeb } 35556b4cac81SBjoern A. Zeeb 35566b4cac81SBjoern A. Zeeb return (sta); 35576b4cac81SBjoern A. Zeeb } 35586b4cac81SBjoern A. Zeeb 35596b4cac81SBjoern A. Zeeb struct sk_buff * 35606b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_tx_dequeue(struct ieee80211_hw *hw, 35616b4cac81SBjoern A. Zeeb struct ieee80211_txq *txq) 35626b4cac81SBjoern A. Zeeb { 35636b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 35646b4cac81SBjoern A. Zeeb struct sk_buff *skb; 35656b4cac81SBjoern A. Zeeb 35666b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 35676b4cac81SBjoern A. Zeeb ltxq->seen_dequeue = true; 35686b4cac81SBjoern A. Zeeb 35696b4cac81SBjoern A. Zeeb skb = skb_dequeue(<xq->skbq); 35706b4cac81SBjoern A. Zeeb 35716b4cac81SBjoern A. Zeeb return (skb); 35726b4cac81SBjoern A. Zeeb } 35736b4cac81SBjoern A. Zeeb 35746b4cac81SBjoern A. Zeeb void 35756b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_txq_get_depth(struct ieee80211_txq *txq, 35766b4cac81SBjoern A. Zeeb uint64_t *frame_cnt, uint64_t *byte_cnt) 35776b4cac81SBjoern A. Zeeb { 35786b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 35796b4cac81SBjoern A. Zeeb struct sk_buff *skb; 35806b4cac81SBjoern A. Zeeb uint64_t fc, bc; 35816b4cac81SBjoern A. Zeeb 35826b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 35836b4cac81SBjoern A. Zeeb 35846b4cac81SBjoern A. Zeeb fc = bc = 0; 35856b4cac81SBjoern A. Zeeb skb_queue_walk(<xq->skbq, skb) { 35866b4cac81SBjoern A. Zeeb fc++; 35876b4cac81SBjoern A. Zeeb bc += skb->len; 35886b4cac81SBjoern A. Zeeb } 35896b4cac81SBjoern A. Zeeb if (frame_cnt) 35906b4cac81SBjoern A. Zeeb *frame_cnt = fc; 35916b4cac81SBjoern A. Zeeb if (byte_cnt) 35926b4cac81SBjoern A. Zeeb *byte_cnt = bc; 35936b4cac81SBjoern A. Zeeb 35946b4cac81SBjoern A. Zeeb /* Validate that this is doing the correct thing. */ 35956b4cac81SBjoern A. Zeeb /* Should we keep track on en/dequeue? */ 35966b4cac81SBjoern A. Zeeb IMPROVE(); 35976b4cac81SBjoern A. Zeeb } 35986b4cac81SBjoern A. Zeeb 35996b4cac81SBjoern A. Zeeb /* 36006b4cac81SBjoern A. Zeeb * We are called from ieee80211_free_txskb() or ieee80211_tx_status(). 36016b4cac81SBjoern A. Zeeb * The latter tries to derive the success status from the info flags 36026b4cac81SBjoern A. Zeeb * passed back from the driver. rawx_mit() saves the ni on the m and the 36036b4cac81SBjoern A. Zeeb * m on the skb for us to be able to give feedback to net80211. 36046b4cac81SBjoern A. Zeeb */ 36056b4cac81SBjoern A. Zeeb void 36066b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb, 36076b4cac81SBjoern A. Zeeb int status) 36086b4cac81SBjoern A. Zeeb { 36096b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 36106b4cac81SBjoern A. Zeeb struct mbuf *m; 36116b4cac81SBjoern A. Zeeb 36126b4cac81SBjoern A. Zeeb m = skb->m; 36136b4cac81SBjoern A. Zeeb skb->m = NULL; 36146b4cac81SBjoern A. Zeeb 36156b4cac81SBjoern A. Zeeb if (m != NULL) { 36166b4cac81SBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 36176b4cac81SBjoern A. Zeeb /* Status: 0 is ok, != 0 is error. */ 36186b4cac81SBjoern A. Zeeb ieee80211_tx_complete(ni, m, status); 36196b4cac81SBjoern A. Zeeb /* ni & mbuf were consumed. */ 36206b4cac81SBjoern A. Zeeb } 36216b4cac81SBjoern A. Zeeb 36226b4cac81SBjoern A. Zeeb kfree_skb(skb); 36236b4cac81SBjoern A. Zeeb } 36246b4cac81SBjoern A. Zeeb 36256b4cac81SBjoern A. Zeeb /* 36266b4cac81SBjoern A. Zeeb * This is an internal bandaid for the moment for the way we glue 36276b4cac81SBjoern A. Zeeb * skbs and mbufs together for TX. Once we have skbs backed by 36286b4cac81SBjoern A. Zeeb * mbufs this should go away. 36296b4cac81SBjoern A. Zeeb * This is a public function but kept on the private KPI (lkpi_) 36306b4cac81SBjoern A. Zeeb * and is not exposed by a header file. 36316b4cac81SBjoern A. Zeeb */ 36326b4cac81SBjoern A. Zeeb static void 36336b4cac81SBjoern A. Zeeb lkpi_ieee80211_free_skb_mbuf(void *p) 36346b4cac81SBjoern A. Zeeb { 36356b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 36366b4cac81SBjoern A. Zeeb struct mbuf *m; 36376b4cac81SBjoern A. Zeeb 36386b4cac81SBjoern A. Zeeb if (p == NULL) 36396b4cac81SBjoern A. Zeeb return; 36406b4cac81SBjoern A. Zeeb 36416b4cac81SBjoern A. Zeeb m = (struct mbuf *)p; 36426b4cac81SBjoern A. Zeeb M_ASSERTPKTHDR(m); 36436b4cac81SBjoern A. Zeeb 36446b4cac81SBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 36456b4cac81SBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = NULL; 36466b4cac81SBjoern A. Zeeb if (ni != NULL) 36476b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 36486b4cac81SBjoern A. Zeeb m_freem(m); 36496b4cac81SBjoern A. Zeeb } 36506b4cac81SBjoern A. Zeeb 36516b4cac81SBjoern A. Zeeb void 36526b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_queue_delayed_work(struct ieee80211_hw *hw, 36536b4cac81SBjoern A. Zeeb struct delayed_work *w, int delay) 36546b4cac81SBjoern A. Zeeb { 36556b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 36566b4cac81SBjoern A. Zeeb 36576b4cac81SBjoern A. Zeeb /* Need to make sure hw is in a stable (non-suspended) state. */ 36586b4cac81SBjoern A. Zeeb IMPROVE(); 36596b4cac81SBjoern A. Zeeb 36606b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 36616b4cac81SBjoern A. Zeeb queue_delayed_work(lhw->workq, w, delay); 36626b4cac81SBjoern A. Zeeb } 36636b4cac81SBjoern A. Zeeb 36646b4cac81SBjoern A. Zeeb void 36656b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_queue_work(struct ieee80211_hw *hw, 36666b4cac81SBjoern A. Zeeb struct work_struct *w) 36676b4cac81SBjoern A. Zeeb { 36686b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 36696b4cac81SBjoern A. Zeeb 36706b4cac81SBjoern A. Zeeb /* Need to make sure hw is in a stable (non-suspended) state. */ 36716b4cac81SBjoern A. Zeeb IMPROVE(); 36726b4cac81SBjoern A. Zeeb 36736b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 36746b4cac81SBjoern A. Zeeb queue_work(lhw->workq, w); 36756b4cac81SBjoern A. Zeeb } 36766b4cac81SBjoern A. Zeeb 36776b4cac81SBjoern A. Zeeb struct sk_buff * 36786b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_pspoll_get(struct ieee80211_hw *hw, 36796b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif) 36806b4cac81SBjoern A. Zeeb { 36816b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 36826b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 36836b4cac81SBjoern A. Zeeb struct sk_buff *skb; 36846b4cac81SBjoern A. Zeeb struct ieee80211_frame_pspoll *psp; 36856b4cac81SBjoern A. Zeeb uint16_t v; 36866b4cac81SBjoern A. Zeeb 36876b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*psp)); 36886b4cac81SBjoern A. Zeeb if (skb == NULL) 36896b4cac81SBjoern A. Zeeb return (NULL); 36906b4cac81SBjoern A. Zeeb 36916b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 36926b4cac81SBjoern A. Zeeb 36936b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 36946b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 36956b4cac81SBjoern A. Zeeb 36966b4cac81SBjoern A. Zeeb psp = skb_put_zero(skb, sizeof(*psp)); 36976b4cac81SBjoern A. Zeeb psp->i_fc[0] = IEEE80211_FC0_VERSION_0; 36986b4cac81SBjoern A. Zeeb psp->i_fc[0] |= IEEE80211_FC0_SUBTYPE_PS_POLL | IEEE80211_FC0_TYPE_CTL; 36996b4cac81SBjoern A. Zeeb v = htole16(vif->bss_conf.aid | 1<<15 | 1<<16); 37006b4cac81SBjoern A. Zeeb memcpy(&psp->i_aid, &v, sizeof(v)); 37016b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(psp->i_bssid, vap->iv_bss->ni_macaddr); 37026b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(psp->i_ta, vif->addr); 37036b4cac81SBjoern A. Zeeb 37046b4cac81SBjoern A. Zeeb return (skb); 37056b4cac81SBjoern A. Zeeb } 37066b4cac81SBjoern A. Zeeb 37076b4cac81SBjoern A. Zeeb struct sk_buff * 37086b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_nullfunc_get(struct ieee80211_hw *hw, 37096b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif, bool qos) 37106b4cac81SBjoern A. Zeeb { 37116b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 37126b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 37136b4cac81SBjoern A. Zeeb struct sk_buff *skb; 37146b4cac81SBjoern A. Zeeb struct ieee80211_frame *nullf; 37156b4cac81SBjoern A. Zeeb 37166b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*nullf)); 37176b4cac81SBjoern A. Zeeb if (skb == NULL) 37186b4cac81SBjoern A. Zeeb return (NULL); 37196b4cac81SBjoern A. Zeeb 37206b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 37216b4cac81SBjoern A. Zeeb 37226b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 37236b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 37246b4cac81SBjoern A. Zeeb 37256b4cac81SBjoern A. Zeeb nullf = skb_put_zero(skb, sizeof(*nullf)); 37266b4cac81SBjoern A. Zeeb nullf->i_fc[0] = IEEE80211_FC0_VERSION_0; 37276b4cac81SBjoern A. Zeeb nullf->i_fc[0] |= IEEE80211_FC0_SUBTYPE_NODATA | IEEE80211_FC0_TYPE_DATA; 37286b4cac81SBjoern A. Zeeb nullf->i_fc[1] = IEEE80211_FC1_DIR_TODS; 37296b4cac81SBjoern A. Zeeb 37306b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr1, vap->iv_bss->ni_bssid); 37316b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr2, vif->addr); 37326b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr3, vap->iv_bss->ni_macaddr); 37336b4cac81SBjoern A. Zeeb 37346b4cac81SBjoern A. Zeeb return (skb); 37356b4cac81SBjoern A. Zeeb } 37366b4cac81SBjoern A. Zeeb 37376b4cac81SBjoern A. Zeeb struct wireless_dev * 37386b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_vif_to_wdev(struct ieee80211_vif *vif) 37396b4cac81SBjoern A. Zeeb { 37406b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 37416b4cac81SBjoern A. Zeeb 37426b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 37436b4cac81SBjoern A. Zeeb return (&lvif->wdev); 37446b4cac81SBjoern A. Zeeb } 37456b4cac81SBjoern A. Zeeb 37466b4cac81SBjoern A. Zeeb void 37476b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_connection_loss(struct ieee80211_vif *vif) 37486b4cac81SBjoern A. Zeeb { 37496b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 37506b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 37516b4cac81SBjoern A. Zeeb enum ieee80211_state nstate; 37526b4cac81SBjoern A. Zeeb int arg; 37536b4cac81SBjoern A. Zeeb 37546b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 37556b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 37566b4cac81SBjoern A. Zeeb 37576b4cac81SBjoern A. Zeeb /* 3758f3229b62SBjoern A. Zeeb * Go to init; otherwise we need to elaborately check state and 37596b4cac81SBjoern A. Zeeb * handle accordingly, e.g., if in RUN we could call iv_bmiss. 37606b4cac81SBjoern A. Zeeb * Let the statemachine handle all neccessary changes. 37616b4cac81SBjoern A. Zeeb */ 3762f3229b62SBjoern A. Zeeb nstate = IEEE80211_S_INIT; 3763bb81db90SBjoern A. Zeeb arg = 0; /* Not a valid reason. */ 37646b4cac81SBjoern A. Zeeb 37656b4cac81SBjoern A. Zeeb if (debug_80211 & D80211_TRACE) 37666b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: vif %p\n", __func__, vif); 37676b4cac81SBjoern A. Zeeb ieee80211_new_state(vap, nstate, arg); 37686b4cac81SBjoern A. Zeeb } 37696b4cac81SBjoern A. Zeeb 3770bb81db90SBjoern A. Zeeb void 3771bb81db90SBjoern A. Zeeb linuxkpi_ieee80211_beacon_loss(struct ieee80211_vif *vif) 3772bb81db90SBjoern A. Zeeb { 3773bb81db90SBjoern A. Zeeb struct lkpi_vif *lvif; 3774bb81db90SBjoern A. Zeeb struct ieee80211vap *vap; 3775bb81db90SBjoern A. Zeeb enum ieee80211_state nstate; 3776bb81db90SBjoern A. Zeeb int arg; 3777bb81db90SBjoern A. Zeeb 3778bb81db90SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 3779bb81db90SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 3780bb81db90SBjoern A. Zeeb 3781bb81db90SBjoern A. Zeeb /* 3782bb81db90SBjoern A. Zeeb * Go to scan; otherwise we need to elaborately check state and 3783bb81db90SBjoern A. Zeeb * handle accordingly, e.g., if in RUN we could call iv_bmiss. 3784bb81db90SBjoern A. Zeeb * Let the statemachine handle all neccessary changes. 3785bb81db90SBjoern A. Zeeb */ 3786bb81db90SBjoern A. Zeeb nstate = IEEE80211_S_SCAN; 3787bb81db90SBjoern A. Zeeb arg = 0; 3788bb81db90SBjoern A. Zeeb 3789bb81db90SBjoern A. Zeeb /* We should be in RUN. Can we assert that? */ 3790bb81db90SBjoern A. Zeeb if (debug_80211 & D80211_TRACE || vap->iv_state != IEEE80211_S_RUN) 3791bb81db90SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: vif %p vap %p state %s\n", __func__, 3792bb81db90SBjoern A. Zeeb vif, vap, ieee80211_state_name[vap->iv_state]); 3793bb81db90SBjoern A. Zeeb ieee80211_new_state(vap, nstate, arg); 3794bb81db90SBjoern A. Zeeb } 3795bb81db90SBjoern A. Zeeb 37966b4cac81SBjoern A. Zeeb MODULE_VERSION(linuxkpi_wlan, 1); 37976b4cac81SBjoern A. Zeeb MODULE_DEPEND(linuxkpi_wlan, linuxkpi, 1, 1, 1); 37986b4cac81SBjoern A. Zeeb MODULE_DEPEND(linuxkpi_wlan, wlan, 1, 1, 1); 3799