16b4cac81SBjoern A. Zeeb /*- 28ac540d3SBjoern A. Zeeb * Copyright (c) 2020-2023 The FreeBSD Foundation 3086be6a8SBjoern A. Zeeb * Copyright (c) 2020-2022 Bjoern A. Zeeb 46b4cac81SBjoern A. Zeeb * 56b4cac81SBjoern A. Zeeb * This software was developed by Björn Zeeb under sponsorship from 66b4cac81SBjoern A. Zeeb * the FreeBSD Foundation. 76b4cac81SBjoern A. Zeeb * 86b4cac81SBjoern A. Zeeb * Redistribution and use in source and binary forms, with or without 96b4cac81SBjoern A. Zeeb * modification, are permitted provided that the following conditions 106b4cac81SBjoern A. Zeeb * are met: 116b4cac81SBjoern A. Zeeb * 1. Redistributions of source code must retain the above copyright 126b4cac81SBjoern A. Zeeb * notice, this list of conditions and the following disclaimer. 136b4cac81SBjoern A. Zeeb * 2. Redistributions in binary form must reproduce the above copyright 146b4cac81SBjoern A. Zeeb * notice, this list of conditions and the following disclaimer in the 156b4cac81SBjoern A. Zeeb * documentation and/or other materials provided with the distribution. 166b4cac81SBjoern A. Zeeb * 176b4cac81SBjoern A. Zeeb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 186b4cac81SBjoern A. Zeeb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 196b4cac81SBjoern A. Zeeb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 206b4cac81SBjoern A. Zeeb * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 216b4cac81SBjoern A. Zeeb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 226b4cac81SBjoern A. Zeeb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 236b4cac81SBjoern A. Zeeb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 246b4cac81SBjoern A. Zeeb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 256b4cac81SBjoern A. Zeeb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 266b4cac81SBjoern A. Zeeb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 276b4cac81SBjoern A. Zeeb * SUCH DAMAGE. 286b4cac81SBjoern A. Zeeb */ 296b4cac81SBjoern A. Zeeb 306b4cac81SBjoern A. Zeeb /* 316b4cac81SBjoern A. Zeeb * Public functions are called linuxkpi_*(). 326b4cac81SBjoern A. Zeeb * Internal (static) functions are called lkpi_*(). 336b4cac81SBjoern A. Zeeb * 346b4cac81SBjoern A. Zeeb * The internal structures holding metadata over public structures are also 356b4cac81SBjoern A. Zeeb * called lkpi_xxx (usually with a member at the end called xxx). 366b4cac81SBjoern A. Zeeb * Note: we do not replicate the structure names but the general variable names 376b4cac81SBjoern A. Zeeb * for these (e.g., struct hw -> struct lkpi_hw, struct sta -> struct lkpi_sta). 386b4cac81SBjoern A. Zeeb * There are macros to access one from the other. 396b4cac81SBjoern A. Zeeb * We call the internal versions lxxx (e.g., hw -> lhw, sta -> lsta). 406b4cac81SBjoern A. Zeeb */ 416b4cac81SBjoern A. Zeeb 426b4cac81SBjoern A. Zeeb #include <sys/param.h> 436b4cac81SBjoern A. Zeeb #include <sys/types.h> 446b4cac81SBjoern A. Zeeb #include <sys/kernel.h> 456b4cac81SBjoern A. Zeeb #include <sys/errno.h> 466b4cac81SBjoern A. Zeeb #include <sys/malloc.h> 476b4cac81SBjoern A. Zeeb #include <sys/module.h> 486b4cac81SBjoern A. Zeeb #include <sys/mutex.h> 496b4cac81SBjoern A. Zeeb #include <sys/socket.h> 506b4cac81SBjoern A. Zeeb #include <sys/sysctl.h> 516b4cac81SBjoern A. Zeeb #include <sys/queue.h> 526b4cac81SBjoern A. Zeeb #include <sys/taskqueue.h> 53527687a9SBjoern A. Zeeb #include <sys/libkern.h> 546b4cac81SBjoern A. Zeeb 556b4cac81SBjoern A. Zeeb #include <net/if.h> 566b4cac81SBjoern A. Zeeb #include <net/if_var.h> 576b4cac81SBjoern A. Zeeb #include <net/if_media.h> 586b4cac81SBjoern A. Zeeb #include <net/ethernet.h> 596b4cac81SBjoern A. Zeeb 606b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_var.h> 616b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_proto.h> 626b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_ratectl.h> 636b4cac81SBjoern A. Zeeb #include <net80211/ieee80211_radiotap.h> 649fb91463SBjoern A. Zeeb #include <net80211/ieee80211_vht.h> 656b4cac81SBjoern A. Zeeb 666b4cac81SBjoern A. Zeeb #define LINUXKPI_NET80211 676b4cac81SBjoern A. Zeeb #include <net/mac80211.h> 686b4cac81SBjoern A. Zeeb 696b4cac81SBjoern A. Zeeb #include <linux/workqueue.h> 706b4cac81SBjoern A. Zeeb #include "linux_80211.h" 716b4cac81SBjoern A. Zeeb 724a67f1dfSBjoern A. Zeeb #define LKPI_80211_WME 73b35f6cd0SBjoern A. Zeeb /* #define LKPI_80211_HW_CRYPTO */ 749fb91463SBjoern A. Zeeb /* #define LKPI_80211_VHT */ 759fb91463SBjoern A. Zeeb /* #define LKPI_80211_HT */ 769fb91463SBjoern A. Zeeb #if defined(LKPI_80211_VHT) && !defined(LKPI_80211_HT) 779fb91463SBjoern A. Zeeb #define LKPI_80211_HT 789fb91463SBjoern A. Zeeb #endif 79b35f6cd0SBjoern A. Zeeb 806b4cac81SBjoern A. Zeeb static MALLOC_DEFINE(M_LKPI80211, "lkpi80211", "LinuxKPI 80211 compat"); 816b4cac81SBjoern A. Zeeb 825a9a0d78SBjoern A. Zeeb /* XXX-BZ really want this and others in queue.h */ 835a9a0d78SBjoern A. Zeeb #define TAILQ_ELEM_INIT(elm, field) do { \ 845a9a0d78SBjoern A. Zeeb (elm)->field.tqe_next = NULL; \ 855a9a0d78SBjoern A. Zeeb (elm)->field.tqe_prev = NULL; \ 865a9a0d78SBjoern A. Zeeb } while (0) 875a9a0d78SBjoern A. Zeeb 886b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 896b4cac81SBjoern A. Zeeb 909d9ba2b7SBjoern A. Zeeb /* Keep public for as long as header files are using it too. */ 919d9ba2b7SBjoern A. Zeeb int linuxkpi_debug_80211; 926b4cac81SBjoern A. Zeeb 936b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 949d9ba2b7SBjoern A. Zeeb SYSCTL_DECL(_compat_linuxkpi); 959d9ba2b7SBjoern A. Zeeb SYSCTL_NODE(_compat_linuxkpi, OID_AUTO, 80211, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 969d9ba2b7SBjoern A. Zeeb "LinuxKPI 802.11 compatibility layer"); 979d9ba2b7SBjoern A. Zeeb 989d9ba2b7SBjoern A. Zeeb SYSCTL_INT(_compat_linuxkpi_80211, OID_AUTO, debug, CTLFLAG_RWTUN, 999d9ba2b7SBjoern A. Zeeb &linuxkpi_debug_80211, 0, "LinuxKPI 802.11 debug level"); 1009d9ba2b7SBjoern A. Zeeb 1019d9ba2b7SBjoern A. Zeeb #define UNIMPLEMENTED if (linuxkpi_debug_80211 & D80211_TODO) \ 1026b4cac81SBjoern A. Zeeb printf("XXX-TODO %s:%d: UNIMPLEMENTED\n", __func__, __LINE__) 1039d9ba2b7SBjoern A. Zeeb #define TRACEOK() if (linuxkpi_debug_80211 & D80211_TRACEOK) \ 1046b4cac81SBjoern A. Zeeb printf("XXX-TODO %s:%d: TRACEPOINT\n", __func__, __LINE__) 1056b4cac81SBjoern A. Zeeb #else 1066b4cac81SBjoern A. Zeeb #define UNIMPLEMENTED do { } while (0) 1076b4cac81SBjoern A. Zeeb #define TRACEOK() do { } while (0) 1086b4cac81SBjoern A. Zeeb #endif 1096b4cac81SBjoern A. Zeeb 1106b4cac81SBjoern A. Zeeb /* #define PREP_TX_INFO_DURATION (IEEE80211_TRANS_WAIT * 1000) */ 1116b4cac81SBjoern A. Zeeb #ifndef PREP_TX_INFO_DURATION 1126b4cac81SBjoern A. Zeeb #define PREP_TX_INFO_DURATION 0 /* Let the driver do its thing. */ 1136b4cac81SBjoern A. Zeeb #endif 1146b4cac81SBjoern A. Zeeb 1156b4cac81SBjoern A. Zeeb /* This is DSAP | SSAP | CTRL | ProtoID/OrgCode{3}. */ 1166b4cac81SBjoern A. Zeeb const uint8_t rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; 1176b4cac81SBjoern A. Zeeb 118b0f73768SBjoern A. Zeeb /* IEEE 802.11-05/0257r1 */ 119b0f73768SBjoern A. Zeeb const uint8_t bridge_tunnel_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; 120b0f73768SBjoern A. Zeeb 121fb3c249eSBjoern A. Zeeb /* IEEE 802.11e Table 20i-UP-to-AC mappings. */ 122fb3c249eSBjoern A. Zeeb static const uint8_t ieee80211e_up_to_ac[] = { 1234f61ef8bSBjoern A. Zeeb IEEE80211_AC_BE, 1244f61ef8bSBjoern A. Zeeb IEEE80211_AC_BK, 1254f61ef8bSBjoern A. Zeeb IEEE80211_AC_BK, 1264f61ef8bSBjoern A. Zeeb IEEE80211_AC_BE, 1274f61ef8bSBjoern A. Zeeb IEEE80211_AC_VI, 1284f61ef8bSBjoern A. Zeeb IEEE80211_AC_VI, 1294f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO, 1304f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO, 1314f61ef8bSBjoern A. Zeeb #if 0 1324f61ef8bSBjoern A. Zeeb IEEE80211_AC_VO, /* We treat MGMT as TID 8, which is set as AC_VO */ 1334f61ef8bSBjoern A. Zeeb #endif 1344f61ef8bSBjoern A. Zeeb }; 1354f61ef8bSBjoern A. Zeeb 1366b4cac81SBjoern A. Zeeb const struct cfg80211_ops linuxkpi_mac80211cfgops = { 1376b4cac81SBjoern A. Zeeb /* 1386b4cac81SBjoern A. Zeeb * XXX TODO need a "glue layer" to link cfg80211 ops to 1396b4cac81SBjoern A. Zeeb * mac80211 and to the driver or net80211. 1406b4cac81SBjoern A. Zeeb * Can we pass some on 1:1? Need to compare the (*f)(). 1416b4cac81SBjoern A. Zeeb */ 1426b4cac81SBjoern A. Zeeb }; 1436b4cac81SBjoern A. Zeeb 1446b4cac81SBjoern A. Zeeb static struct lkpi_sta *lkpi_find_lsta_by_ni(struct lkpi_vif *, 1456b4cac81SBjoern A. Zeeb struct ieee80211_node *); 1466b4cac81SBjoern A. Zeeb static void lkpi_80211_txq_task(void *, int); 1476b4cac81SBjoern A. Zeeb static void lkpi_ieee80211_free_skb_mbuf(void *); 1484a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 1494a67f1dfSBjoern A. Zeeb static int lkpi_wme_update(struct lkpi_hw *, struct ieee80211vap *, bool); 1504a67f1dfSBjoern A. Zeeb #endif 1516b4cac81SBjoern A. Zeeb 1529fb91463SBjoern A. Zeeb #if defined(LKPI_80211_HT) 1539fb91463SBjoern A. Zeeb static void 1549fb91463SBjoern A. Zeeb lkpi_sta_sync_ht_from_ni(struct ieee80211_sta *sta, struct ieee80211_node *ni, int *ht_rx_nss) 1559fb91463SBjoern A. Zeeb { 1569fb91463SBjoern A. Zeeb struct ieee80211vap *vap; 1579fb91463SBjoern A. Zeeb uint8_t *ie; 1589fb91463SBjoern A. Zeeb struct ieee80211_ht_cap *htcap; 1599fb91463SBjoern A. Zeeb int i, rx_nss; 1609fb91463SBjoern A. Zeeb 1619fb91463SBjoern A. Zeeb if ((ni->ni_flags & IEEE80211_NODE_HT) == 0) 1629fb91463SBjoern A. Zeeb return; 1639fb91463SBjoern A. Zeeb 1649fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_HT(ni->ni_chan) && 1659fb91463SBjoern A. Zeeb IEEE80211_IS_CHAN_HT40(ni->ni_chan)) 1669fb91463SBjoern A. Zeeb sta->deflink.bandwidth = IEEE80211_STA_RX_BW_40; 1679fb91463SBjoern A. Zeeb 1689fb91463SBjoern A. Zeeb sta->deflink.ht_cap.ht_supported = true; 1699fb91463SBjoern A. Zeeb 1709fb91463SBjoern A. Zeeb /* htcap->ampdu_params_info */ 1719fb91463SBjoern A. Zeeb vap = ni->ni_vap; 1729fb91463SBjoern A. Zeeb sta->deflink.ht_cap.ampdu_density = _IEEE80211_MASKSHIFT(ni->ni_htparam, IEEE80211_HTCAP_MPDUDENSITY); 1739fb91463SBjoern A. Zeeb if (sta->deflink.ht_cap.ampdu_density > vap->iv_ampdu_density) 1749fb91463SBjoern A. Zeeb sta->deflink.ht_cap.ampdu_density = vap->iv_ampdu_density; 1759fb91463SBjoern A. Zeeb sta->deflink.ht_cap.ampdu_factor = _IEEE80211_MASKSHIFT(ni->ni_htparam, IEEE80211_HTCAP_MAXRXAMPDU); 1769fb91463SBjoern A. Zeeb if (sta->deflink.ht_cap.ampdu_factor > vap->iv_ampdu_rxmax) 1779fb91463SBjoern A. Zeeb sta->deflink.ht_cap.ampdu_factor = vap->iv_ampdu_rxmax; 1789fb91463SBjoern A. Zeeb 1799fb91463SBjoern A. Zeeb ie = ni->ni_ies.htcap_ie; 1809fb91463SBjoern A. Zeeb KASSERT(ie != NULL, ("%s: HT but no htcap_ie on ni %p\n", __func__, ni)); 1819fb91463SBjoern A. Zeeb if (ie[0] == IEEE80211_ELEMID_VENDOR) 1829fb91463SBjoern A. Zeeb ie += 4; 1839fb91463SBjoern A. Zeeb ie += 2; 1849fb91463SBjoern A. Zeeb htcap = (struct ieee80211_ht_cap *)ie; 1859fb91463SBjoern A. Zeeb sta->deflink.ht_cap.cap = htcap->cap_info; 1869fb91463SBjoern A. Zeeb sta->deflink.ht_cap.mcs = htcap->mcs; 1879fb91463SBjoern A. Zeeb 1889fb91463SBjoern A. Zeeb rx_nss = 0; 1899fb91463SBjoern A. Zeeb for (i = 0; i < nitems(htcap->mcs.rx_mask); i++) { 1909fb91463SBjoern A. Zeeb if (htcap->mcs.rx_mask[i]) 1919fb91463SBjoern A. Zeeb rx_nss++; 1929fb91463SBjoern A. Zeeb } 1939fb91463SBjoern A. Zeeb if (ht_rx_nss != NULL) 1949fb91463SBjoern A. Zeeb *ht_rx_nss = rx_nss; 1959fb91463SBjoern A. Zeeb 1969fb91463SBjoern A. Zeeb IMPROVE("sta->wme, sta->deflink.agg.max*"); 1979fb91463SBjoern A. Zeeb } 1989fb91463SBjoern A. Zeeb #endif 1999fb91463SBjoern A. Zeeb 2009fb91463SBjoern A. Zeeb #if defined(LKPI_80211_VHT) 2019fb91463SBjoern A. Zeeb static void 2029fb91463SBjoern A. Zeeb lkpi_sta_sync_vht_from_ni(struct ieee80211_sta *sta, struct ieee80211_node *ni, int *vht_rx_nss) 2039fb91463SBjoern A. Zeeb { 2049fb91463SBjoern A. Zeeb 2059fb91463SBjoern A. Zeeb if ((ni->ni_flags & IEEE80211_NODE_VHT) == 0) 2069fb91463SBjoern A. Zeeb return; 2079fb91463SBjoern A. Zeeb 2089fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_VHT(ni->ni_chan)) { 2099fb91463SBjoern A. Zeeb #ifdef __notyet__ 2109fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_VHT80P80(ni->ni_chan)) { 2119fb91463SBjoern A. Zeeb sta->deflink.bandwidth = IEEE80211_STA_RX_BW_160; /* XXX? */ 2129fb91463SBjoern A. Zeeb } else 2139fb91463SBjoern A. Zeeb #endif 2149fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_VHT160(ni->ni_chan)) 2159fb91463SBjoern A. Zeeb sta->deflink.bandwidth = IEEE80211_STA_RX_BW_160; 2169fb91463SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_VHT80(ni->ni_chan)) 2179fb91463SBjoern A. Zeeb sta->deflink.bandwidth = IEEE80211_STA_RX_BW_80; 2189fb91463SBjoern A. Zeeb } 2199fb91463SBjoern A. Zeeb 2209fb91463SBjoern A. Zeeb IMPROVE("VHT sync ni to sta"); 2219fb91463SBjoern A. Zeeb return; 2229fb91463SBjoern A. Zeeb } 2239fb91463SBjoern A. Zeeb #endif 2249fb91463SBjoern A. Zeeb 225d9f59799SBjoern A. Zeeb static void 22667674c1cSBjoern A. Zeeb lkpi_lsta_dump(struct lkpi_sta *lsta, struct ieee80211_node *ni, 22767674c1cSBjoern A. Zeeb const char *_f, int _l) 228d9f59799SBjoern A. Zeeb { 229d9f59799SBjoern A. Zeeb 2309d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 2319d9ba2b7SBjoern A. Zeeb if ((linuxkpi_debug_80211 & D80211_TRACE_STA) == 0) 232d9f59799SBjoern A. Zeeb return; 233d9f59799SBjoern A. Zeeb if (lsta == NULL) 234d9f59799SBjoern A. Zeeb return; 235d9f59799SBjoern A. Zeeb 236d9f59799SBjoern A. Zeeb printf("%s:%d lsta %p ni %p sta %p\n", 23767674c1cSBjoern A. Zeeb _f, _l, lsta, ni, &lsta->sta); 23867674c1cSBjoern A. Zeeb if (ni != NULL) 23967674c1cSBjoern A. Zeeb ieee80211_dump_node(NULL, ni); 240d9f59799SBjoern A. Zeeb printf("\ttxq_task txq len %d mtx\n", mbufq_len(&lsta->txq)); 241d9f59799SBjoern A. Zeeb printf("\tkc %p state %d added_to_drv %d in_mgd %d\n", 242d9f59799SBjoern A. Zeeb lsta->kc, lsta->state, lsta->added_to_drv, lsta->in_mgd); 2439d9ba2b7SBjoern A. Zeeb #endif 244d9f59799SBjoern A. Zeeb } 245d9f59799SBjoern A. Zeeb 246d9f59799SBjoern A. Zeeb static void 247d9f59799SBjoern A. Zeeb lkpi_lsta_remove(struct lkpi_sta *lsta, struct lkpi_vif *lvif) 248d9f59799SBjoern A. Zeeb { 249d9f59799SBjoern A. Zeeb struct ieee80211_node *ni; 250d9f59799SBjoern A. Zeeb 2513689f8aeSColin Percival IMPROVE("XXX-BZ remove tqe_prev check once ni-sta-state-sync is fixed"); 2523689f8aeSColin Percival 253d9f59799SBjoern A. Zeeb ni = lsta->ni; 254d9f59799SBjoern A. Zeeb 255d9f59799SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 2563689f8aeSColin Percival if (lsta->lsta_entry.tqe_prev != NULL) 257d9f59799SBjoern A. Zeeb TAILQ_REMOVE(&lvif->lsta_head, lsta, lsta_entry); 258d9f59799SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 259d9f59799SBjoern A. Zeeb 260d9f59799SBjoern A. Zeeb lsta->ni = NULL; 261d9f59799SBjoern A. Zeeb ni->ni_drv_data = NULL; 262e24e8103SBjoern A. Zeeb if (ni != NULL) 263d9f59799SBjoern A. Zeeb ieee80211_free_node(ni); 264d9f59799SBjoern A. Zeeb 265e24e8103SBjoern A. Zeeb IMPROVE("more from lkpi_ic_node_free() should happen here."); 266e24e8103SBjoern A. Zeeb 267e24e8103SBjoern A. Zeeb free(lsta, M_LKPI80211); 268d9f59799SBjoern A. Zeeb } 269d9f59799SBjoern A. Zeeb 2704f61ef8bSBjoern A. Zeeb static struct lkpi_sta * 2714f61ef8bSBjoern A. Zeeb lkpi_lsta_alloc(struct ieee80211vap *vap, const uint8_t mac[IEEE80211_ADDR_LEN], 2724f61ef8bSBjoern A. Zeeb struct ieee80211_hw *hw, struct ieee80211_node *ni) 2734f61ef8bSBjoern A. Zeeb { 2744f61ef8bSBjoern A. Zeeb struct lkpi_sta *lsta; 2754f61ef8bSBjoern A. Zeeb struct lkpi_vif *lvif; 2764f61ef8bSBjoern A. Zeeb struct ieee80211_vif *vif; 2774f61ef8bSBjoern A. Zeeb struct ieee80211_sta *sta; 278b6b352e4SBjoern A. Zeeb int band, i, tid; 2799fb91463SBjoern A. Zeeb int ht_rx_nss; 2809fb91463SBjoern A. Zeeb int vht_rx_nss; 2814f61ef8bSBjoern A. Zeeb 2824f61ef8bSBjoern A. Zeeb lsta = malloc(sizeof(*lsta) + hw->sta_data_size, M_LKPI80211, 2834f61ef8bSBjoern A. Zeeb M_NOWAIT | M_ZERO); 2844f61ef8bSBjoern A. Zeeb if (lsta == NULL) 2854f61ef8bSBjoern A. Zeeb return (NULL); 2864f61ef8bSBjoern A. Zeeb 2874f61ef8bSBjoern A. Zeeb lsta->added_to_drv = false; 2884f61ef8bSBjoern A. Zeeb lsta->state = IEEE80211_STA_NOTEXIST; 2894f61ef8bSBjoern A. Zeeb #if 0 2904f61ef8bSBjoern A. Zeeb /* 2914f61ef8bSBjoern A. Zeeb * This needs to be done in node_init() as ieee80211_alloc_node() 2924f61ef8bSBjoern A. Zeeb * will initialise the refcount after us. 2934f61ef8bSBjoern A. Zeeb */ 2944f61ef8bSBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 2954f61ef8bSBjoern A. Zeeb #endif 2964f61ef8bSBjoern A. Zeeb /* The back-pointer "drv_data" to net80211_node let's us get lsta. */ 2974f61ef8bSBjoern A. Zeeb ni->ni_drv_data = lsta; 2984f61ef8bSBjoern A. Zeeb 2994f61ef8bSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 3004f61ef8bSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 3014f61ef8bSBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 3024f61ef8bSBjoern A. Zeeb 3034f61ef8bSBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->addr, mac); 304b6b352e4SBjoern A. Zeeb 305b6b352e4SBjoern A. Zeeb /* TXQ */ 3064f61ef8bSBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 3074f61ef8bSBjoern A. Zeeb struct lkpi_txq *ltxq; 3084f61ef8bSBjoern A. Zeeb 309d0d29110SBjoern A. Zeeb /* We are not limiting ourselves to hw.queues here. */ 3104f61ef8bSBjoern A. Zeeb ltxq = malloc(sizeof(*ltxq) + hw->txq_data_size, 3114f61ef8bSBjoern A. Zeeb M_LKPI80211, M_NOWAIT | M_ZERO); 3124f61ef8bSBjoern A. Zeeb if (ltxq == NULL) 3134f61ef8bSBjoern A. Zeeb goto cleanup; 3144f61ef8bSBjoern A. Zeeb /* iwlwifi//mvm/sta.c::tid_to_mac80211_ac[] */ 3154f61ef8bSBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) { 316d0d29110SBjoern A. Zeeb if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ)) { 317d0d29110SBjoern A. Zeeb free(ltxq, M_LKPI80211); 318d0d29110SBjoern A. Zeeb continue; 319d0d29110SBjoern A. Zeeb } 320d0d29110SBjoern A. Zeeb IMPROVE("AP/if we support non-STA here too"); 3214f61ef8bSBjoern A. Zeeb ltxq->txq.ac = IEEE80211_AC_VO; 3224f61ef8bSBjoern A. Zeeb } else { 323fb3c249eSBjoern A. Zeeb ltxq->txq.ac = ieee80211e_up_to_ac[tid & 7]; 3244f61ef8bSBjoern A. Zeeb } 325d0d29110SBjoern A. Zeeb ltxq->seen_dequeue = false; 3260cbcfa19SBjoern A. Zeeb ltxq->stopped = false; 327d0d29110SBjoern A. Zeeb ltxq->txq.vif = vif; 3284f61ef8bSBjoern A. Zeeb ltxq->txq.tid = tid; 3294f61ef8bSBjoern A. Zeeb ltxq->txq.sta = sta; 3300cbcfa19SBjoern A. Zeeb TAILQ_ELEM_INIT(ltxq, txq_entry); 331d0d29110SBjoern A. Zeeb skb_queue_head_init(<xq->skbq); 332*eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_LOCK_INIT(ltxq); 3334f61ef8bSBjoern A. Zeeb sta->txq[tid] = <xq->txq; 3344f61ef8bSBjoern A. Zeeb } 3354f61ef8bSBjoern A. Zeeb 336b6b352e4SBjoern A. Zeeb /* Deflink information. */ 337b6b352e4SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 338b6b352e4SBjoern A. Zeeb struct ieee80211_supported_band *supband; 339b6b352e4SBjoern A. Zeeb 340b6b352e4SBjoern A. Zeeb supband = hw->wiphy->bands[band]; 341b6b352e4SBjoern A. Zeeb if (supband == NULL) 342b6b352e4SBjoern A. Zeeb continue; 343b6b352e4SBjoern A. Zeeb 344b6b352e4SBjoern A. Zeeb for (i = 0; i < supband->n_bitrates; i++) { 345b6b352e4SBjoern A. Zeeb 346b6b352e4SBjoern A. Zeeb IMPROVE("Further supband->bitrates[i]* checks?"); 347b6b352e4SBjoern A. Zeeb /* or should we get them from the ni? */ 348b6b352e4SBjoern A. Zeeb sta->deflink.supp_rates[band] |= BIT(i); 349b6b352e4SBjoern A. Zeeb } 350b6b352e4SBjoern A. Zeeb } 3519fb91463SBjoern A. Zeeb 3526ffb7bd4SBjoern A. Zeeb sta->deflink.smps_mode = IEEE80211_SMPS_OFF; 3539fb91463SBjoern A. Zeeb sta->deflink.bandwidth = IEEE80211_STA_RX_BW_20; 3549fb91463SBjoern A. Zeeb sta->deflink.rx_nss = 0; 3559fb91463SBjoern A. Zeeb 3569fb91463SBjoern A. Zeeb ht_rx_nss = 0; 3579fb91463SBjoern A. Zeeb #if defined(LKPI_80211_HT) 3589fb91463SBjoern A. Zeeb lkpi_sta_sync_ht_from_ni(sta, ni, &ht_rx_nss); 3599fb91463SBjoern A. Zeeb #endif 3609fb91463SBjoern A. Zeeb vht_rx_nss = 0; 3619fb91463SBjoern A. Zeeb #if defined(LKPI_80211_VHT) 3629fb91463SBjoern A. Zeeb lkpi_sta_sync_vht_from_ni(sta, ni, &vht_rx_nss); 3639fb91463SBjoern A. Zeeb #endif 3649fb91463SBjoern A. Zeeb 3659fb91463SBjoern A. Zeeb sta->deflink.rx_nss = MAX(ht_rx_nss, sta->deflink.rx_nss); 3669fb91463SBjoern A. Zeeb sta->deflink.rx_nss = MAX(vht_rx_nss, sta->deflink.rx_nss); 3679fb91463SBjoern A. Zeeb IMPROVE("he, ... smps_mode, .."); 368b6b352e4SBjoern A. Zeeb 3696ffb7bd4SBjoern A. Zeeb /* Link configuration. */ 3706ffb7bd4SBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->deflink.addr, sta->addr); 3716ffb7bd4SBjoern A. Zeeb sta->link[0] = &sta->deflink; 3726ffb7bd4SBjoern A. Zeeb for (i = 1; i < nitems(sta->link); i++) { 3736ffb7bd4SBjoern A. Zeeb IMPROVE("more links; only link[0] = deflink currently."); 3746ffb7bd4SBjoern A. Zeeb } 3756ffb7bd4SBjoern A. Zeeb 3764f61ef8bSBjoern A. Zeeb /* Deferred TX path. */ 3774f61ef8bSBjoern A. Zeeb mtx_init(&lsta->txq_mtx, "lsta_txq", NULL, MTX_DEF); 3784f61ef8bSBjoern A. Zeeb TASK_INIT(&lsta->txq_task, 0, lkpi_80211_txq_task, lsta); 3794f61ef8bSBjoern A. Zeeb mbufq_init(&lsta->txq, IFQ_MAXLEN); 3804f61ef8bSBjoern A. Zeeb 3814f61ef8bSBjoern A. Zeeb return (lsta); 3824f61ef8bSBjoern A. Zeeb 3834f61ef8bSBjoern A. Zeeb cleanup: 384*eac3646fSBjoern A. Zeeb for (; tid >= 0; tid--) { 385*eac3646fSBjoern A. Zeeb struct lkpi_txq *ltxq; 386*eac3646fSBjoern A. Zeeb 387*eac3646fSBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]); 388*eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_LOCK_DESTROY(ltxq); 3894f61ef8bSBjoern A. Zeeb free(sta->txq[tid], M_LKPI80211); 390*eac3646fSBjoern A. Zeeb } 3914f61ef8bSBjoern A. Zeeb free(lsta, M_LKPI80211); 3924f61ef8bSBjoern A. Zeeb return (NULL); 3934f61ef8bSBjoern A. Zeeb } 3944f61ef8bSBjoern A. Zeeb 3956b4cac81SBjoern A. Zeeb static enum nl80211_band 3966b4cac81SBjoern A. Zeeb lkpi_net80211_chan_to_nl80211_band(struct ieee80211_channel *c) 3976b4cac81SBjoern A. Zeeb { 3986b4cac81SBjoern A. Zeeb 3996b4cac81SBjoern A. Zeeb if (IEEE80211_IS_CHAN_2GHZ(c)) 4006b4cac81SBjoern A. Zeeb return (NL80211_BAND_2GHZ); 4016b4cac81SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_5GHZ(c)) 4026b4cac81SBjoern A. Zeeb return (NL80211_BAND_5GHZ); 4036b4cac81SBjoern A. Zeeb #ifdef __notyet__ 4046b4cac81SBjoern A. Zeeb else if () 4056b4cac81SBjoern A. Zeeb return (NL80211_BAND_6GHZ); 4066b4cac81SBjoern A. Zeeb else if () 4076b4cac81SBjoern A. Zeeb return (NL80211_BAND_60GHZ); 4086b4cac81SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_GSM(c)) 4096b4cac81SBjoern A. Zeeb return (NL80211_BAND_XXX); 4106b4cac81SBjoern A. Zeeb #endif 4116b4cac81SBjoern A. Zeeb else 4126b4cac81SBjoern A. Zeeb panic("%s: unsupported band. c %p flags %#x\n", 4136b4cac81SBjoern A. Zeeb __func__, c, c->ic_flags); 4146b4cac81SBjoern A. Zeeb } 4156b4cac81SBjoern A. Zeeb 4166b4cac81SBjoern A. Zeeb static uint32_t 4176b4cac81SBjoern A. Zeeb lkpi_nl80211_band_to_net80211_band(enum nl80211_band band) 4186b4cac81SBjoern A. Zeeb { 4196b4cac81SBjoern A. Zeeb 4206b4cac81SBjoern A. Zeeb /* XXX-BZ this is just silly; net80211 is too convoluted. */ 4216b4cac81SBjoern A. Zeeb /* IEEE80211_CHAN_A / _G / .. doesn't really work either. */ 4226b4cac81SBjoern A. Zeeb switch (band) { 4236b4cac81SBjoern A. Zeeb case NL80211_BAND_2GHZ: 4246b4cac81SBjoern A. Zeeb return (IEEE80211_CHAN_2GHZ); 4256b4cac81SBjoern A. Zeeb break; 4266b4cac81SBjoern A. Zeeb case NL80211_BAND_5GHZ: 4276b4cac81SBjoern A. Zeeb return (IEEE80211_CHAN_5GHZ); 4286b4cac81SBjoern A. Zeeb break; 4296b4cac81SBjoern A. Zeeb case NL80211_BAND_60GHZ: 4306b4cac81SBjoern A. Zeeb break; 4316b4cac81SBjoern A. Zeeb case NL80211_BAND_6GHZ: 4326b4cac81SBjoern A. Zeeb break; 4336b4cac81SBjoern A. Zeeb default: 4346b4cac81SBjoern A. Zeeb panic("%s: unsupported band %u\n", __func__, band); 4356b4cac81SBjoern A. Zeeb break; 4366b4cac81SBjoern A. Zeeb } 4376b4cac81SBjoern A. Zeeb 4386b4cac81SBjoern A. Zeeb IMPROVE(); 4396b4cac81SBjoern A. Zeeb return (0x00); 4406b4cac81SBjoern A. Zeeb } 4416b4cac81SBjoern A. Zeeb 442e3a0b120SBjoern A. Zeeb #if 0 4436b4cac81SBjoern A. Zeeb static enum ieee80211_ac_numbers 4446b4cac81SBjoern A. Zeeb lkpi_ac_net_to_l80211(int ac) 4456b4cac81SBjoern A. Zeeb { 4466b4cac81SBjoern A. Zeeb 4476b4cac81SBjoern A. Zeeb switch (ac) { 4486b4cac81SBjoern A. Zeeb case WME_AC_VO: 4496b4cac81SBjoern A. Zeeb return (IEEE80211_AC_VO); 4506b4cac81SBjoern A. Zeeb case WME_AC_VI: 4516b4cac81SBjoern A. Zeeb return (IEEE80211_AC_VI); 4526b4cac81SBjoern A. Zeeb case WME_AC_BE: 4536b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BE); 4546b4cac81SBjoern A. Zeeb case WME_AC_BK: 4556b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BK); 4566b4cac81SBjoern A. Zeeb default: 4576b4cac81SBjoern A. Zeeb printf("%s: invalid WME_AC_* input: ac = %d\n", __func__, ac); 4586b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BE); 4596b4cac81SBjoern A. Zeeb } 4606b4cac81SBjoern A. Zeeb } 461e3a0b120SBjoern A. Zeeb #endif 4626b4cac81SBjoern A. Zeeb 4636b4cac81SBjoern A. Zeeb static enum nl80211_iftype 4646b4cac81SBjoern A. Zeeb lkpi_opmode_to_vif_type(enum ieee80211_opmode opmode) 4656b4cac81SBjoern A. Zeeb { 4666b4cac81SBjoern A. Zeeb 4676b4cac81SBjoern A. Zeeb switch (opmode) { 4686b4cac81SBjoern A. Zeeb case IEEE80211_M_IBSS: 4696b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_ADHOC); 4706b4cac81SBjoern A. Zeeb break; 4716b4cac81SBjoern A. Zeeb case IEEE80211_M_STA: 4726b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_STATION); 4736b4cac81SBjoern A. Zeeb break; 4746b4cac81SBjoern A. Zeeb case IEEE80211_M_WDS: 4756b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_WDS); 4766b4cac81SBjoern A. Zeeb break; 4776b4cac81SBjoern A. Zeeb case IEEE80211_M_HOSTAP: 4786b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_AP); 4796b4cac81SBjoern A. Zeeb break; 4806b4cac81SBjoern A. Zeeb case IEEE80211_M_MONITOR: 4816b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_MONITOR); 4826b4cac81SBjoern A. Zeeb break; 4836b4cac81SBjoern A. Zeeb case IEEE80211_M_MBSS: 4846b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_MESH_POINT); 4856b4cac81SBjoern A. Zeeb break; 4866b4cac81SBjoern A. Zeeb case IEEE80211_M_AHDEMO: 4876b4cac81SBjoern A. Zeeb /* FALLTHROUGH */ 4886b4cac81SBjoern A. Zeeb default: 4896b4cac81SBjoern A. Zeeb printf("ERROR: %s: unsupported opmode %d\n", __func__, opmode); 4906b4cac81SBjoern A. Zeeb /* FALLTHROUGH */ 4916b4cac81SBjoern A. Zeeb } 4926b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_UNSPECIFIED); 4936b4cac81SBjoern A. Zeeb } 4946b4cac81SBjoern A. Zeeb 495b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 4966b4cac81SBjoern A. Zeeb static uint32_t 4976b4cac81SBjoern A. Zeeb lkpi_l80211_to_net80211_cyphers(uint32_t wlan_cipher_suite) 4986b4cac81SBjoern A. Zeeb { 4996b4cac81SBjoern A. Zeeb 5006b4cac81SBjoern A. Zeeb switch (wlan_cipher_suite) { 5016b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP40: 5026b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_WEP); 5036b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP: 5046b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_TKIP); 5056b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP: 5066b4cac81SBjoern A. Zeeb return (IEEE80211_CIPHER_AES_CCM); 5076b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP104: 5086b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_WEP); 5096b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_AES_CMAC: 5106b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP: 5116b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP_256: 5126b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP_256: 5136b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_128: 5146b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_256: 5156b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_CMAC_256: 5166b4cac81SBjoern A. Zeeb printf("%s: unsupported WLAN Cipher Suite %#08x | %u\n", __func__, 5176b4cac81SBjoern A. Zeeb wlan_cipher_suite >> 8, wlan_cipher_suite & 0xff); 5186b4cac81SBjoern A. Zeeb break; 5196b4cac81SBjoern A. Zeeb default: 5206b4cac81SBjoern A. Zeeb printf("%s: unknown WLAN Cipher Suite %#08x | %u\n", __func__, 5216b4cac81SBjoern A. Zeeb wlan_cipher_suite >> 8, wlan_cipher_suite & 0xff); 5226b4cac81SBjoern A. Zeeb } 5236b4cac81SBjoern A. Zeeb 5246b4cac81SBjoern A. Zeeb return (0); 5256b4cac81SBjoern A. Zeeb } 5266b4cac81SBjoern A. Zeeb 5276b4cac81SBjoern A. Zeeb static uint32_t 5286b4cac81SBjoern A. Zeeb lkpi_net80211_to_l80211_cipher_suite(uint32_t cipher, uint8_t keylen) 5296b4cac81SBjoern A. Zeeb { 5306b4cac81SBjoern A. Zeeb 5316b4cac81SBjoern A. Zeeb switch (cipher) { 5326b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_TKIP: 5336b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_TKIP); 5346b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_AES_CCM: 5356b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_CCMP); 5366b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_WEP: 5376b4cac81SBjoern A. Zeeb if (keylen < 8) 5386b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_WEP40); 5396b4cac81SBjoern A. Zeeb else 5406b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_WEP104); 5416b4cac81SBjoern A. Zeeb break; 5426b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_AES_OCB: 5436b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_TKIPMIC: 5446b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_CKIP: 5456b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_NONE: 5466b4cac81SBjoern A. Zeeb printf("%s: unsupported cipher %#010x\n", __func__, cipher); 5476b4cac81SBjoern A. Zeeb break; 5486b4cac81SBjoern A. Zeeb default: 5496b4cac81SBjoern A. Zeeb printf("%s: unknown cipher %#010x\n", __func__, cipher); 5506b4cac81SBjoern A. Zeeb }; 5516b4cac81SBjoern A. Zeeb return (0); 5526b4cac81SBjoern A. Zeeb } 5536b4cac81SBjoern A. Zeeb #endif 5546b4cac81SBjoern A. Zeeb 5556b4cac81SBjoern A. Zeeb #ifdef __notyet__ 5566b4cac81SBjoern A. Zeeb static enum ieee80211_sta_state 5576b4cac81SBjoern A. Zeeb lkpi_net80211_state_to_sta_state(enum ieee80211_state state) 5586b4cac81SBjoern A. Zeeb { 5596b4cac81SBjoern A. Zeeb 5606b4cac81SBjoern A. Zeeb /* 5616b4cac81SBjoern A. Zeeb * XXX-BZ The net80211 states are "try to ..", the lkpi8011 states are 5626b4cac81SBjoern A. Zeeb * "done". Also ASSOC/AUTHORIZED are both "RUN" then? 5636b4cac81SBjoern A. Zeeb */ 5646b4cac81SBjoern A. Zeeb switch (state) { 5656b4cac81SBjoern A. Zeeb case IEEE80211_S_INIT: 5666b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NOTEXIST); 5676b4cac81SBjoern A. Zeeb case IEEE80211_S_SCAN: 5686b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NONE); 5696b4cac81SBjoern A. Zeeb case IEEE80211_S_AUTH: 5706b4cac81SBjoern A. Zeeb return (IEEE80211_STA_AUTH); 5716b4cac81SBjoern A. Zeeb case IEEE80211_S_ASSOC: 5726b4cac81SBjoern A. Zeeb return (IEEE80211_STA_ASSOC); 5736b4cac81SBjoern A. Zeeb case IEEE80211_S_RUN: 5746b4cac81SBjoern A. Zeeb return (IEEE80211_STA_AUTHORIZED); 5756b4cac81SBjoern A. Zeeb case IEEE80211_S_CAC: 5766b4cac81SBjoern A. Zeeb case IEEE80211_S_CSA: 5776b4cac81SBjoern A. Zeeb case IEEE80211_S_SLEEP: 5786b4cac81SBjoern A. Zeeb default: 5796b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 5806b4cac81SBjoern A. Zeeb }; 5816b4cac81SBjoern A. Zeeb 5826b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NOTEXIST); 5836b4cac81SBjoern A. Zeeb } 5846b4cac81SBjoern A. Zeeb #endif 5856b4cac81SBjoern A. Zeeb 5866b4cac81SBjoern A. Zeeb static struct linuxkpi_ieee80211_channel * 5876b4cac81SBjoern A. Zeeb lkpi_find_lkpi80211_chan(struct lkpi_hw *lhw, 5886b4cac81SBjoern A. Zeeb struct ieee80211_channel *c) 5896b4cac81SBjoern A. Zeeb { 5906b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 5916b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 5926b4cac81SBjoern A. Zeeb enum nl80211_band band; 5936b4cac81SBjoern A. Zeeb int i, nchans; 5946b4cac81SBjoern A. Zeeb 5956b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 5966b4cac81SBjoern A. Zeeb band = lkpi_net80211_chan_to_nl80211_band(c); 5976b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[band] == NULL) 5986b4cac81SBjoern A. Zeeb return (NULL); 5996b4cac81SBjoern A. Zeeb 6006b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[band]->n_channels; 6016b4cac81SBjoern A. Zeeb if (nchans <= 0) 6026b4cac81SBjoern A. Zeeb return (NULL); 6036b4cac81SBjoern A. Zeeb 6046b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[band]->channels; 6056b4cac81SBjoern A. Zeeb for (i = 0; i < nchans; i++) { 6066b4cac81SBjoern A. Zeeb if (channels[i].hw_value == c->ic_ieee) 6076b4cac81SBjoern A. Zeeb return (&channels[i]); 6086b4cac81SBjoern A. Zeeb } 6096b4cac81SBjoern A. Zeeb 6106b4cac81SBjoern A. Zeeb return (NULL); 6116b4cac81SBjoern A. Zeeb } 6126b4cac81SBjoern A. Zeeb 6136b4cac81SBjoern A. Zeeb static struct linuxkpi_ieee80211_channel * 6146b4cac81SBjoern A. Zeeb lkpi_get_lkpi80211_chan(struct ieee80211com *ic, struct ieee80211_node *ni) 6156b4cac81SBjoern A. Zeeb { 6166b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 6176b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 6186b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 6196b4cac81SBjoern A. Zeeb 6206b4cac81SBjoern A. Zeeb chan = NULL; 6216b4cac81SBjoern A. Zeeb if (ni != NULL && ni->ni_chan != IEEE80211_CHAN_ANYC) 6226b4cac81SBjoern A. Zeeb c = ni->ni_chan; 6236b4cac81SBjoern A. Zeeb else if (ic->ic_bsschan != IEEE80211_CHAN_ANYC) 6246b4cac81SBjoern A. Zeeb c = ic->ic_bsschan; 6256b4cac81SBjoern A. Zeeb else if (ic->ic_curchan != IEEE80211_CHAN_ANYC) 6266b4cac81SBjoern A. Zeeb c = ic->ic_curchan; 6276b4cac81SBjoern A. Zeeb else 6286b4cac81SBjoern A. Zeeb c = NULL; 6296b4cac81SBjoern A. Zeeb 6306b4cac81SBjoern A. Zeeb if (c != NULL && c != IEEE80211_CHAN_ANYC) { 6316b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 6326b4cac81SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, c); 6336b4cac81SBjoern A. Zeeb } 6346b4cac81SBjoern A. Zeeb 6356b4cac81SBjoern A. Zeeb return (chan); 6366b4cac81SBjoern A. Zeeb } 6376b4cac81SBjoern A. Zeeb 6382e183d99SBjoern A. Zeeb struct linuxkpi_ieee80211_channel * 6392e183d99SBjoern A. Zeeb linuxkpi_ieee80211_get_channel(struct wiphy *wiphy, uint32_t freq) 6402e183d99SBjoern A. Zeeb { 6412e183d99SBjoern A. Zeeb enum nl80211_band band; 6422e183d99SBjoern A. Zeeb 6432e183d99SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 6442e183d99SBjoern A. Zeeb struct ieee80211_supported_band *supband; 6452e183d99SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 6462e183d99SBjoern A. Zeeb int i; 6472e183d99SBjoern A. Zeeb 6482e183d99SBjoern A. Zeeb supband = wiphy->bands[band]; 6492e183d99SBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 6502e183d99SBjoern A. Zeeb continue; 6512e183d99SBjoern A. Zeeb 6522e183d99SBjoern A. Zeeb channels = supband->channels; 6532e183d99SBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 6542e183d99SBjoern A. Zeeb if (channels[i].center_freq == freq) 6552e183d99SBjoern A. Zeeb return (&channels[i]); 6562e183d99SBjoern A. Zeeb } 6572e183d99SBjoern A. Zeeb } 6582e183d99SBjoern A. Zeeb 6592e183d99SBjoern A. Zeeb return (NULL); 6602e183d99SBjoern A. Zeeb } 6612e183d99SBjoern A. Zeeb 662b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 6636b4cac81SBjoern A. Zeeb static int 6646b4cac81SBjoern A. Zeeb _lkpi_iv_key_set_delete(struct ieee80211vap *vap, const struct ieee80211_key *k, 6656b4cac81SBjoern A. Zeeb enum set_key_cmd cmd) 6666b4cac81SBjoern A. Zeeb { 6676b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 6686b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 6696b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 6706b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 6716b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 6726b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 6736b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 6746b4cac81SBjoern A. Zeeb struct ieee80211_key_conf *kc; 6756b4cac81SBjoern A. Zeeb int error; 6766b4cac81SBjoern A. Zeeb 6776b4cac81SBjoern A. Zeeb /* XXX TODO Check (k->wk_flags & IEEE80211_KEY_SWENCRYPT) and don't upload to driver/hw? */ 6786b4cac81SBjoern A. Zeeb 6796b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 6806b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 6816b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 6826b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 6836b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 6846b4cac81SBjoern A. Zeeb 6856b4cac81SBjoern A. Zeeb memset(&kc, 0, sizeof(kc)); 6866b4cac81SBjoern A. Zeeb kc = malloc(sizeof(*kc) + k->wk_keylen, M_LKPI80211, M_WAITOK | M_ZERO); 6876b4cac81SBjoern A. Zeeb kc->cipher = lkpi_net80211_to_l80211_cipher_suite( 6886b4cac81SBjoern A. Zeeb k->wk_cipher->ic_cipher, k->wk_keylen); 6896b4cac81SBjoern A. Zeeb kc->keyidx = k->wk_keyix; 6906b4cac81SBjoern A. Zeeb #if 0 6916b4cac81SBjoern A. Zeeb kc->hw_key_idx = /* set by hw and needs to be passed for TX */; 6926b4cac81SBjoern A. Zeeb #endif 6936b4cac81SBjoern A. Zeeb atomic64_set(&kc->tx_pn, k->wk_keytsc); 6946b4cac81SBjoern A. Zeeb kc->keylen = k->wk_keylen; 6956b4cac81SBjoern A. Zeeb memcpy(kc->key, k->wk_key, k->wk_keylen); 6966b4cac81SBjoern A. Zeeb 6976b4cac81SBjoern A. Zeeb switch (kc->cipher) { 6986b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP: 6996b4cac81SBjoern A. Zeeb kc->iv_len = k->wk_cipher->ic_header; 7006b4cac81SBjoern A. Zeeb kc->icv_len = k->wk_cipher->ic_trailer; 7016b4cac81SBjoern A. Zeeb break; 7026b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP: 7036b4cac81SBjoern A. Zeeb default: 7046b4cac81SBjoern A. Zeeb IMPROVE(); 7056b4cac81SBjoern A. Zeeb return (0); 7066b4cac81SBjoern A. Zeeb }; 7076b4cac81SBjoern A. Zeeb 7086b4cac81SBjoern A. Zeeb ni = vap->iv_bss; 7096b4cac81SBjoern A. Zeeb sta = ieee80211_find_sta(vif, ni->ni_bssid); 7106b4cac81SBjoern A. Zeeb if (sta != NULL) { 7116b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 7126b4cac81SBjoern A. Zeeb 7136b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 7146b4cac81SBjoern A. Zeeb lsta->kc = kc; 7156b4cac81SBjoern A. Zeeb } 7166b4cac81SBjoern A. Zeeb 7176b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_set_key(hw, cmd, vif, sta, kc); 7186b4cac81SBjoern A. Zeeb if (error != 0) { 7196b4cac81SBjoern A. Zeeb /* XXX-BZ leaking kc currently */ 7206b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: set_key failed: %d\n", __func__, error); 7216b4cac81SBjoern A. Zeeb return (0); 7226b4cac81SBjoern A. Zeeb } else { 7236b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: set_key succeeded: keyidx %u hw_key_idx %u " 7246b4cac81SBjoern A. Zeeb "flags %#10x\n", __func__, 7256b4cac81SBjoern A. Zeeb kc->keyidx, kc->hw_key_idx, kc->flags); 7266b4cac81SBjoern A. Zeeb return (1); 7276b4cac81SBjoern A. Zeeb } 7286b4cac81SBjoern A. Zeeb } 7296b4cac81SBjoern A. Zeeb 7306b4cac81SBjoern A. Zeeb static int 7316b4cac81SBjoern A. Zeeb lkpi_iv_key_delete(struct ieee80211vap *vap, const struct ieee80211_key *k) 7326b4cac81SBjoern A. Zeeb { 7336b4cac81SBjoern A. Zeeb 7346b4cac81SBjoern A. Zeeb /* XXX-BZ one day we should replace this iterating over VIFs, or node list? */ 7356b4cac81SBjoern A. Zeeb return (_lkpi_iv_key_set_delete(vap, k, DISABLE_KEY)); 7366b4cac81SBjoern A. Zeeb } 7376b4cac81SBjoern A. Zeeb static int 7386b4cac81SBjoern A. Zeeb lkpi_iv_key_set(struct ieee80211vap *vap, const struct ieee80211_key *k) 7396b4cac81SBjoern A. Zeeb { 7406b4cac81SBjoern A. Zeeb 7416b4cac81SBjoern A. Zeeb return (_lkpi_iv_key_set_delete(vap, k, SET_KEY)); 7426b4cac81SBjoern A. Zeeb } 7436b4cac81SBjoern A. Zeeb #endif 7446b4cac81SBjoern A. Zeeb 7456b4cac81SBjoern A. Zeeb static u_int 7466b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast_copy(void *arg, struct sockaddr_dl *sdl, u_int cnt) 7476b4cac81SBjoern A. Zeeb { 7486b4cac81SBjoern A. Zeeb struct netdev_hw_addr_list *mc_list; 7496b4cac81SBjoern A. Zeeb struct netdev_hw_addr *addr; 7506b4cac81SBjoern A. Zeeb 7516b4cac81SBjoern A. Zeeb KASSERT(arg != NULL && sdl != NULL, ("%s: arg %p sdl %p cnt %u\n", 7526b4cac81SBjoern A. Zeeb __func__, arg, sdl, cnt)); 7536b4cac81SBjoern A. Zeeb 7546b4cac81SBjoern A. Zeeb mc_list = arg; 7556b4cac81SBjoern A. Zeeb /* If it is on the list already skip it. */ 7566b4cac81SBjoern A. Zeeb netdev_hw_addr_list_for_each(addr, mc_list) { 7576b4cac81SBjoern A. Zeeb if (!memcmp(addr->addr, LLADDR(sdl), sdl->sdl_alen)) 7586b4cac81SBjoern A. Zeeb return (0); 7596b4cac81SBjoern A. Zeeb } 7606b4cac81SBjoern A. Zeeb 7616b4cac81SBjoern A. Zeeb addr = malloc(sizeof(*addr), M_LKPI80211, M_NOWAIT | M_ZERO); 7626b4cac81SBjoern A. Zeeb if (addr == NULL) 7636b4cac81SBjoern A. Zeeb return (0); 7646b4cac81SBjoern A. Zeeb 7656b4cac81SBjoern A. Zeeb INIT_LIST_HEAD(&addr->addr_list); 7666b4cac81SBjoern A. Zeeb memcpy(addr->addr, LLADDR(sdl), sdl->sdl_alen); 7676b4cac81SBjoern A. Zeeb /* XXX this should be a netdev function? */ 7686b4cac81SBjoern A. Zeeb list_add(&addr->addr_list, &mc_list->addr_list); 7696b4cac81SBjoern A. Zeeb mc_list->count++; 7706b4cac81SBjoern A. Zeeb 7719d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 7729d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 7736b4cac81SBjoern A. Zeeb printf("%s:%d: mc_list count %d: added %6D\n", 7746b4cac81SBjoern A. Zeeb __func__, __LINE__, mc_list->count, addr->addr, ":"); 7759d9ba2b7SBjoern A. Zeeb #endif 7766b4cac81SBjoern A. Zeeb 7776b4cac81SBjoern A. Zeeb return (1); 7786b4cac81SBjoern A. Zeeb } 7796b4cac81SBjoern A. Zeeb 7806b4cac81SBjoern A. Zeeb static void 7816b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(struct ieee80211com *ic, bool force) 7826b4cac81SBjoern A. Zeeb { 7836b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 7846b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 7856b4cac81SBjoern A. Zeeb struct netdev_hw_addr_list mc_list; 7866b4cac81SBjoern A. Zeeb struct list_head *le, *next; 7876b4cac81SBjoern A. Zeeb struct netdev_hw_addr *addr; 7886b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 7896b4cac81SBjoern A. Zeeb u64 mc; 7906b4cac81SBjoern A. Zeeb unsigned int changed_flags, total_flags; 7916b4cac81SBjoern A. Zeeb 7926b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 7936b4cac81SBjoern A. Zeeb 7946b4cac81SBjoern A. Zeeb if (lhw->ops->prepare_multicast == NULL || 7956b4cac81SBjoern A. Zeeb lhw->ops->configure_filter == NULL) 7966b4cac81SBjoern A. Zeeb return; 7976b4cac81SBjoern A. Zeeb 7986b4cac81SBjoern A. Zeeb if (!lhw->update_mc && !force) 7996b4cac81SBjoern A. Zeeb return; 8006b4cac81SBjoern A. Zeeb 8016b4cac81SBjoern A. Zeeb changed_flags = total_flags = 0; 8026b4cac81SBjoern A. Zeeb mc_list.count = 0; 8036b4cac81SBjoern A. Zeeb INIT_LIST_HEAD(&mc_list.addr_list); 8046b4cac81SBjoern A. Zeeb if (ic->ic_allmulti == 0) { 8056b4cac81SBjoern A. Zeeb TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) 8066b4cac81SBjoern A. Zeeb if_foreach_llmaddr(vap->iv_ifp, 8076b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast_copy, &mc_list); 8086b4cac81SBjoern A. Zeeb } else { 8096b4cac81SBjoern A. Zeeb changed_flags |= FIF_ALLMULTI; 8106b4cac81SBjoern A. Zeeb } 8116b4cac81SBjoern A. Zeeb 8126b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 8136b4cac81SBjoern A. Zeeb mc = lkpi_80211_mo_prepare_multicast(hw, &mc_list); 8146b4cac81SBjoern A. Zeeb /* 8156b4cac81SBjoern A. Zeeb * XXX-BZ make sure to get this sorted what is a change, 8166b4cac81SBjoern A. Zeeb * what gets all set; what was already set? 8176b4cac81SBjoern A. Zeeb */ 8186b4cac81SBjoern A. Zeeb total_flags = changed_flags; 8196b4cac81SBjoern A. Zeeb lkpi_80211_mo_configure_filter(hw, changed_flags, &total_flags, mc); 8206b4cac81SBjoern A. Zeeb 8219d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 8229d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 8236b4cac81SBjoern A. Zeeb printf("%s: changed_flags %#06x count %d total_flags %#010x\n", 8246b4cac81SBjoern A. Zeeb __func__, changed_flags, mc_list.count, total_flags); 8259d9ba2b7SBjoern A. Zeeb #endif 8266b4cac81SBjoern A. Zeeb 8276b4cac81SBjoern A. Zeeb if (mc_list.count != 0) { 8286b4cac81SBjoern A. Zeeb list_for_each_safe(le, next, &mc_list.addr_list) { 8296b4cac81SBjoern A. Zeeb addr = list_entry(le, struct netdev_hw_addr, addr_list); 8306b4cac81SBjoern A. Zeeb free(addr, M_LKPI80211); 8316b4cac81SBjoern A. Zeeb mc_list.count--; 8326b4cac81SBjoern A. Zeeb } 8336b4cac81SBjoern A. Zeeb } 8346b4cac81SBjoern A. Zeeb KASSERT(mc_list.count == 0, ("%s: mc_list %p count %d != 0\n", 8356b4cac81SBjoern A. Zeeb __func__, &mc_list, mc_list.count)); 8366b4cac81SBjoern A. Zeeb } 8376b4cac81SBjoern A. Zeeb 838fa8f007dSBjoern A. Zeeb static enum ieee80211_bss_changed 839fa8f007dSBjoern A. Zeeb lkpi_update_dtim_tsf(struct ieee80211_vif *vif, struct ieee80211_node *ni, 840fa8f007dSBjoern A. Zeeb struct ieee80211vap *vap, const char *_f, int _l) 841fa8f007dSBjoern A. Zeeb { 842fa8f007dSBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 843fa8f007dSBjoern A. Zeeb 844fa8f007dSBjoern A. Zeeb bss_changed = 0; 845fa8f007dSBjoern A. Zeeb 8469d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 8479d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 848fa8f007dSBjoern A. Zeeb printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u " 849fa8f007dSBjoern A. Zeeb "dtim_period %u sync_dtim_count %u sync_tsf %ju " 850fa8f007dSBjoern A. Zeeb "sync_device_ts %u bss_changed %#08x\n", 851fa8f007dSBjoern A. Zeeb __func__, __LINE__, _f, _l, 852616e1330SBjoern A. Zeeb vif->cfg.assoc, vif->cfg.aid, 853fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int, vif->bss_conf.dtim_period, 854fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count, 855fa8f007dSBjoern A. Zeeb (uintmax_t)vif->bss_conf.sync_tsf, 856fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_device_ts, 857fa8f007dSBjoern A. Zeeb bss_changed); 8589d9ba2b7SBjoern A. Zeeb #endif 859fa8f007dSBjoern A. Zeeb 860fa8f007dSBjoern A. Zeeb if (vif->bss_conf.beacon_int != ni->ni_intval) { 861fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int = ni->ni_intval; 862fa8f007dSBjoern A. Zeeb /* iwlwifi FW bug workaround; iwl_mvm_mac_sta_state. */ 863fa8f007dSBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16) 864fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int = 16; 865fa8f007dSBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INT; 866fa8f007dSBjoern A. Zeeb } 867fa8f007dSBjoern A. Zeeb if (vif->bss_conf.dtim_period != vap->iv_dtim_period && 868fa8f007dSBjoern A. Zeeb vap->iv_dtim_period > 0) { 869fa8f007dSBjoern A. Zeeb vif->bss_conf.dtim_period = vap->iv_dtim_period; 870fa8f007dSBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INFO; 871fa8f007dSBjoern A. Zeeb } 872fa8f007dSBjoern A. Zeeb 873fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count = vap->iv_dtim_count; 874fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_tsf = le64toh(ni->ni_tstamp.tsf); 875fa8f007dSBjoern A. Zeeb /* vif->bss_conf.sync_device_ts = set in linuxkpi_ieee80211_rx. */ 876fa8f007dSBjoern A. Zeeb 8779d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 8789d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 879fa8f007dSBjoern A. Zeeb printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u " 880fa8f007dSBjoern A. Zeeb "dtim_period %u sync_dtim_count %u sync_tsf %ju " 881fa8f007dSBjoern A. Zeeb "sync_device_ts %u bss_changed %#08x\n", 882fa8f007dSBjoern A. Zeeb __func__, __LINE__, _f, _l, 883616e1330SBjoern A. Zeeb vif->cfg.assoc, vif->cfg.aid, 884fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int, vif->bss_conf.dtim_period, 885fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count, 886fa8f007dSBjoern A. Zeeb (uintmax_t)vif->bss_conf.sync_tsf, 887fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_device_ts, 888fa8f007dSBjoern A. Zeeb bss_changed); 8899d9ba2b7SBjoern A. Zeeb #endif 890fa8f007dSBjoern A. Zeeb 891fa8f007dSBjoern A. Zeeb return (bss_changed); 892fa8f007dSBjoern A. Zeeb } 893fa8f007dSBjoern A. Zeeb 8946b4cac81SBjoern A. Zeeb static void 8956b4cac81SBjoern A. Zeeb lkpi_stop_hw_scan(struct lkpi_hw *lhw, struct ieee80211_vif *vif) 8966b4cac81SBjoern A. Zeeb { 8976b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 8986b4cac81SBjoern A. Zeeb int error; 8998ac540d3SBjoern A. Zeeb bool cancel; 9006b4cac81SBjoern A. Zeeb 9018ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 9028ac540d3SBjoern A. Zeeb cancel = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0; 9038ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 9048ac540d3SBjoern A. Zeeb if (!cancel) 9056b4cac81SBjoern A. Zeeb return; 9066b4cac81SBjoern A. Zeeb 9076b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 9086b4cac81SBjoern A. Zeeb 909bec76628SBjoern A. Zeeb IEEE80211_UNLOCK(lhw->ic); 910bec76628SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 9116b4cac81SBjoern A. Zeeb /* Need to cancel the scan. */ 9126b4cac81SBjoern A. Zeeb lkpi_80211_mo_cancel_hw_scan(hw, vif); 9138ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 9146b4cac81SBjoern A. Zeeb 9156b4cac81SBjoern A. Zeeb /* Need to make sure we see ieee80211_scan_completed. */ 9168ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 9178ac540d3SBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) 9188ac540d3SBjoern A. Zeeb error = msleep(lhw, &lhw->scan_mtx, 0, "lhwscanstop", hz/2); 9198ac540d3SBjoern A. Zeeb cancel = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0; 9208ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 9218ac540d3SBjoern A. Zeeb 922bec76628SBjoern A. Zeeb IEEE80211_LOCK(lhw->ic); 9236b4cac81SBjoern A. Zeeb 9248ac540d3SBjoern A. Zeeb if (cancel) 9256b4cac81SBjoern A. Zeeb ic_printf(lhw->ic, "%s: failed to cancel scan: %d (%p, %p)\n", 9266b4cac81SBjoern A. Zeeb __func__, error, lhw, vif); 9276b4cac81SBjoern A. Zeeb } 9286b4cac81SBjoern A. Zeeb 9296b4cac81SBjoern A. Zeeb static void 930086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(struct ieee80211_hw *hw, bool new) 931086be6a8SBjoern A. Zeeb { 932086be6a8SBjoern A. Zeeb struct lkpi_hw *lhw; 933086be6a8SBjoern A. Zeeb int error; 934086be6a8SBjoern A. Zeeb bool old; 935086be6a8SBjoern A. Zeeb 936086be6a8SBjoern A. Zeeb old = hw->conf.flags & IEEE80211_CONF_IDLE; 937086be6a8SBjoern A. Zeeb if (old == new) 938086be6a8SBjoern A. Zeeb return; 939086be6a8SBjoern A. Zeeb 940086be6a8SBjoern A. Zeeb hw->conf.flags ^= IEEE80211_CONF_IDLE; 941086be6a8SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_IDLE); 942086be6a8SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) { 943086be6a8SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 944086be6a8SBjoern A. Zeeb ic_printf(lhw->ic, "ERROR: %s: config %#0x returned %d\n", 945086be6a8SBjoern A. Zeeb __func__, IEEE80211_CONF_CHANGE_IDLE, error); 946086be6a8SBjoern A. Zeeb } 947086be6a8SBjoern A. Zeeb } 948086be6a8SBjoern A. Zeeb 949086be6a8SBjoern A. Zeeb static void 9506b4cac81SBjoern A. Zeeb lkpi_disassoc(struct ieee80211_sta *sta, struct ieee80211_vif *vif, 9516b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw) 9526b4cac81SBjoern A. Zeeb { 9536b4cac81SBjoern A. Zeeb sta->aid = 0; 954616e1330SBjoern A. Zeeb if (vif->cfg.assoc) { 9556b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 9566b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 9576b4cac81SBjoern A. Zeeb 9586b4cac81SBjoern A. Zeeb lhw->update_mc = true; 9596b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(lhw->ic, true); 9606b4cac81SBjoern A. Zeeb 9616b4cac81SBjoern A. Zeeb changed = 0; 962616e1330SBjoern A. Zeeb vif->cfg.assoc = false; 963616e1330SBjoern A. Zeeb vif->cfg.aid = 0; 9646b4cac81SBjoern A. Zeeb changed |= BSS_CHANGED_ASSOC; 965d9f59799SBjoern A. Zeeb /* 966d9f59799SBjoern A. Zeeb * This will remove the sta from firmware for iwlwifi. 967d9f59799SBjoern A. Zeeb * So confusing that they use state and flags and ... ^%$%#%$^. 968d9f59799SBjoern A. Zeeb */ 9696b4cac81SBjoern A. Zeeb IMPROVE(); 9706b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 9716b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, 9726b4cac81SBjoern A. Zeeb changed); 973086be6a8SBjoern A. Zeeb 974086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true); 9756b4cac81SBjoern A. Zeeb } 9766b4cac81SBjoern A. Zeeb } 9776b4cac81SBjoern A. Zeeb 9786b4cac81SBjoern A. Zeeb static void 9796b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(struct ieee80211_hw *hw, struct ieee80211_sta *sta, 9806b4cac81SBjoern A. Zeeb bool dequeue_seen, bool no_emptyq) 9816b4cac81SBjoern A. Zeeb { 9826b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 9836b4cac81SBjoern A. Zeeb int tid; 984*eac3646fSBjoern A. Zeeb bool ltxq_empty; 9856b4cac81SBjoern A. Zeeb 9866b4cac81SBjoern A. Zeeb /* Wake up all queues to know they are allocated in the driver. */ 9876b4cac81SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 9886b4cac81SBjoern A. Zeeb 9896b4cac81SBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) { 9906b4cac81SBjoern A. Zeeb IMPROVE("station specific?"); 9916b4cac81SBjoern A. Zeeb if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ)) 9926b4cac81SBjoern A. Zeeb continue; 9936b4cac81SBjoern A. Zeeb } else if (tid >= hw->queues) 9946b4cac81SBjoern A. Zeeb continue; 9956b4cac81SBjoern A. Zeeb 9966b4cac81SBjoern A. Zeeb if (sta->txq[tid] == NULL) 9976b4cac81SBjoern A. Zeeb continue; 9986b4cac81SBjoern A. Zeeb 9996b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]); 10006b4cac81SBjoern A. Zeeb if (dequeue_seen && !ltxq->seen_dequeue) 10016b4cac81SBjoern A. Zeeb continue; 10026b4cac81SBjoern A. Zeeb 1003*eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_LOCK(ltxq); 1004*eac3646fSBjoern A. Zeeb ltxq_empty = skb_queue_empty(<xq->skbq); 1005*eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_UNLOCK(ltxq); 1006*eac3646fSBjoern A. Zeeb if (no_emptyq && ltxq_empty) 10076b4cac81SBjoern A. Zeeb continue; 10086b4cac81SBjoern A. Zeeb 10096b4cac81SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, sta->txq[tid]); 10106b4cac81SBjoern A. Zeeb } 10116b4cac81SBjoern A. Zeeb } 10126b4cac81SBjoern A. Zeeb 10136b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 10146b4cac81SBjoern A. Zeeb 10156b4cac81SBjoern A. Zeeb static int 10166b4cac81SBjoern A. Zeeb lkpi_sta_state_do_nada(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 10176b4cac81SBjoern A. Zeeb { 10186b4cac81SBjoern A. Zeeb 10196b4cac81SBjoern A. Zeeb return (0); 10206b4cac81SBjoern A. Zeeb } 10216b4cac81SBjoern A. Zeeb 10226b4cac81SBjoern A. Zeeb /* lkpi_iv_newstate() handles the stop scan case generally. */ 10236b4cac81SBjoern A. Zeeb #define lkpi_sta_scan_to_init(_v, _n, _a) lkpi_sta_state_do_nada(_v, _n, _a) 10246b4cac81SBjoern A. Zeeb 10256b4cac81SBjoern A. Zeeb static int 10266b4cac81SBjoern A. Zeeb lkpi_sta_scan_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 10276b4cac81SBjoern A. Zeeb { 10286b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 1029c5e25798SBjoern A. Zeeb struct lkpi_chanctx *lchanctx; 10306b4cac81SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 10316b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 10326b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 10336b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 10346b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 10356b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 10366b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 10376b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 10386b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 10396b4cac81SBjoern A. Zeeb uint32_t changed; 10406b4cac81SBjoern A. Zeeb int error; 10416b4cac81SBjoern A. Zeeb 10426b4cac81SBjoern A. Zeeb chan = lkpi_get_lkpi80211_chan(vap->iv_ic, vap->iv_bss); 10436b4cac81SBjoern A. Zeeb if (chan == NULL) { 10446b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: failed to get channel\n", __func__); 10456b4cac81SBjoern A. Zeeb return (ESRCH); 10466b4cac81SBjoern A. Zeeb } 10476b4cac81SBjoern A. Zeeb 10486b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 10496b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 10506b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 10516b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 10526b4cac81SBjoern A. Zeeb 1053d9f59799SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 1054d9f59799SBjoern A. Zeeb 10556b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 10568ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 10576b4cac81SBjoern A. Zeeb 10586b4cac81SBjoern A. Zeeb /* Add chanctx (or if exists, change it). */ 10596b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 10606b4cac81SBjoern A. Zeeb conf = vif->chanctx_conf; 1061c5e25798SBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(conf); 10626b4cac81SBjoern A. Zeeb IMPROVE("diff changes for changed, working on live copy, rcu"); 10636b4cac81SBjoern A. Zeeb } else { 10646b4cac81SBjoern A. Zeeb /* Keep separate alloc as in Linux this is rcu managed? */ 1065c5e25798SBjoern A. Zeeb lchanctx = malloc(sizeof(*lchanctx) + hw->chanctx_data_size, 10666b4cac81SBjoern A. Zeeb M_LKPI80211, M_WAITOK | M_ZERO); 1067c5e25798SBjoern A. Zeeb conf = &lchanctx->conf; 10686b4cac81SBjoern A. Zeeb } 10696b4cac81SBjoern A. Zeeb 10706b4cac81SBjoern A. Zeeb conf->rx_chains_dynamic = 1; 10716b4cac81SBjoern A. Zeeb conf->rx_chains_static = 1; 10726b4cac81SBjoern A. Zeeb conf->radar_enabled = 10736b4cac81SBjoern A. Zeeb (chan->flags & IEEE80211_CHAN_RADAR) ? true : false; 10746b4cac81SBjoern A. Zeeb conf->def.chan = chan; 10756b4cac81SBjoern A. Zeeb conf->def.width = NL80211_CHAN_WIDTH_20_NOHT; 10766b4cac81SBjoern A. Zeeb conf->def.center_freq1 = chan->center_freq; 10776b4cac81SBjoern A. Zeeb conf->def.center_freq2 = 0; 10789fb91463SBjoern A. Zeeb IMPROVE("Check vht_cap from band not just chan?"); 10799fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 10809fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_HT(ni->ni_chan)) { 10819fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_HT40(ni->ni_chan)) { 10829fb91463SBjoern A. Zeeb conf->def.width = NL80211_CHAN_WIDTH_40; 10839fb91463SBjoern A. Zeeb } else 10849fb91463SBjoern A. Zeeb conf->def.width = NL80211_CHAN_WIDTH_20; 10859fb91463SBjoern A. Zeeb } 10869fb91463SBjoern A. Zeeb #endif 10879fb91463SBjoern A. Zeeb #ifdef LKPI_80211_VHT 10889fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_VHT(ni->ni_chan)) { 10899fb91463SBjoern A. Zeeb #ifdef __notyet__ 10909fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_VHT80P80(ni->ni_chan)) { 10919fb91463SBjoern A. Zeeb conf->def.width = NL80211_CHAN_WIDTH_80P80; 10929fb91463SBjoern A. Zeeb conf->def.center_freq2 = 0; /* XXX */ 10939fb91463SBjoern A. Zeeb } else 10949fb91463SBjoern A. Zeeb #endif 10959fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_VHT160(ni->ni_chan)) 10969fb91463SBjoern A. Zeeb conf->def.width = NL80211_CHAN_WIDTH_160; 10979fb91463SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_VHT80(ni->ni_chan)) 10989fb91463SBjoern A. Zeeb conf->def.width = NL80211_CHAN_WIDTH_80; 10999fb91463SBjoern A. Zeeb } 11009fb91463SBjoern A. Zeeb #endif 11016b4cac81SBjoern A. Zeeb /* Responder ... */ 11026b4cac81SBjoern A. Zeeb conf->min_def.chan = chan; 11036b4cac81SBjoern A. Zeeb conf->min_def.width = NL80211_CHAN_WIDTH_20_NOHT; 11046b4cac81SBjoern A. Zeeb conf->min_def.center_freq1 = chan->center_freq; 11056b4cac81SBjoern A. Zeeb conf->min_def.center_freq2 = 0; 11069fb91463SBjoern A. Zeeb IMPROVE("currently 20_NOHT min_def only"); 11076b4cac81SBjoern A. Zeeb 11086ffb7bd4SBjoern A. Zeeb /* Set bss info (bss_info_changed). */ 11096ffb7bd4SBjoern A. Zeeb bss_changed = 0; 11106ffb7bd4SBjoern A. Zeeb vif->bss_conf.bssid = ni->ni_bssid; 11116ffb7bd4SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 11126ffb7bd4SBjoern A. Zeeb vif->bss_conf.txpower = ni->ni_txpower; 11136ffb7bd4SBjoern A. Zeeb bss_changed |= BSS_CHANGED_TXPOWER; 11146ffb7bd4SBjoern A. Zeeb vif->cfg.idle = false; 11156ffb7bd4SBjoern A. Zeeb bss_changed |= BSS_CHANGED_IDLE; 11166ffb7bd4SBjoern A. Zeeb 11176ffb7bd4SBjoern A. Zeeb /* vif->bss_conf.basic_rates ? Where exactly? */ 11186ffb7bd4SBjoern A. Zeeb 11196ffb7bd4SBjoern A. Zeeb /* Should almost assert it is this. */ 11206ffb7bd4SBjoern A. Zeeb vif->cfg.assoc = false; 11216ffb7bd4SBjoern A. Zeeb vif->cfg.aid = 0; 11226ffb7bd4SBjoern A. Zeeb 11236ffb7bd4SBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 11246ffb7bd4SBjoern A. Zeeb 11256b4cac81SBjoern A. Zeeb error = 0; 11266b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 11276b4cac81SBjoern A. Zeeb changed = IEEE80211_CHANCTX_CHANGE_MIN_WIDTH; 11286b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_RADAR; 11296b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_RX_CHAINS; 11306b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_WIDTH; 11316b4cac81SBjoern A. Zeeb lkpi_80211_mo_change_chanctx(hw, conf, changed); 11326b4cac81SBjoern A. Zeeb } else { 11336b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_add_chanctx(hw, conf); 11346b4cac81SBjoern A. Zeeb if (error == 0 || error == EOPNOTSUPP) { 11356b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.chan = conf->def.chan; 11366b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.width = conf->def.width; 11376b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.center_freq1 = 11386b4cac81SBjoern A. Zeeb conf->def.center_freq1; 11399fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 11409fb91463SBjoern A. Zeeb if (vif->bss_conf.chandef.width == NL80211_CHAN_WIDTH_40) { 11419fb91463SBjoern A. Zeeb /* Note: it is 10 not 20. */ 11429fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_HT40U(ni->ni_chan)) 11439fb91463SBjoern A. Zeeb vif->bss_conf.chandef.center_freq1 += 10; 11449fb91463SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_HT40D(ni->ni_chan)) 11459fb91463SBjoern A. Zeeb vif->bss_conf.chandef.center_freq1 -= 10; 11469fb91463SBjoern A. Zeeb } 11479fb91463SBjoern A. Zeeb #endif 11486b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.center_freq2 = 11496b4cac81SBjoern A. Zeeb conf->def.center_freq2; 11506b4cac81SBjoern A. Zeeb } else { 1151018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_add_chanctx " 1152018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 11536b4cac81SBjoern A. Zeeb goto out; 11546b4cac81SBjoern A. Zeeb } 11556ffb7bd4SBjoern A. Zeeb 11566ffb7bd4SBjoern A. Zeeb vif->bss_conf.chanctx_conf = conf; 11576ffb7bd4SBjoern A. Zeeb 11586b4cac81SBjoern A. Zeeb /* Assign vif chanctx. */ 11596b4cac81SBjoern A. Zeeb if (error == 0) 116068541546SBjoern A. Zeeb error = lkpi_80211_mo_assign_vif_chanctx(hw, vif, 116168541546SBjoern A. Zeeb &vif->bss_conf, conf); 11626b4cac81SBjoern A. Zeeb if (error == EOPNOTSUPP) 11636b4cac81SBjoern A. Zeeb error = 0; 11646b4cac81SBjoern A. Zeeb if (error != 0) { 1165018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_assign_vif_chanctx " 1166018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 11676b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 1168c5e25798SBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(conf); 1169c5e25798SBjoern A. Zeeb free(lchanctx, M_LKPI80211); 11706b4cac81SBjoern A. Zeeb goto out; 11716b4cac81SBjoern A. Zeeb } 11726b4cac81SBjoern A. Zeeb } 11736b4cac81SBjoern A. Zeeb IMPROVE("update radiotap chan fields too"); 11746b4cac81SBjoern A. Zeeb 11756b4cac81SBjoern A. Zeeb /* RATES */ 11766b4cac81SBjoern A. Zeeb IMPROVE("bss info: not all needs to come now and rates are missing"); 11776b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 11786b4cac81SBjoern A. Zeeb 1179d9f59799SBjoern A. Zeeb /* 1180d9f59799SBjoern A. Zeeb * This is a bandaid for now. If we went through (*iv_update_bss)() 1181d9f59799SBjoern A. Zeeb * and then removed the lsta we end up here without a lsta and have 1182d9f59799SBjoern A. Zeeb * to manually allocate and link it in as lkpi_ic_node_alloc()/init() 1183d9f59799SBjoern A. Zeeb * would normally do. 1184d9f59799SBjoern A. Zeeb * XXX-BZ I do not like this but currently we have no good way of 1185d9f59799SBjoern A. Zeeb * intercepting the bss swap and state changes and packets going out 1186d9f59799SBjoern A. Zeeb * workflow so live with this. It is a compat layer after all. 1187d9f59799SBjoern A. Zeeb */ 1188d9f59799SBjoern A. Zeeb if (ni->ni_drv_data == NULL) { 1189d9f59799SBjoern A. Zeeb lsta = lkpi_lsta_alloc(vap, ni->ni_macaddr, hw, ni); 1190d9f59799SBjoern A. Zeeb if (lsta == NULL) { 1191d9f59799SBjoern A. Zeeb error = ENOMEM; 1192018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lkpi_lsta_alloc " 1193018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 1194d9f59799SBjoern A. Zeeb goto out; 1195d9f59799SBjoern A. Zeeb } 1196d9f59799SBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 1197d9f59799SBjoern A. Zeeb } else { 11986b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 1199d9f59799SBjoern A. Zeeb } 1200e24e8103SBjoern A. Zeeb 1201e24e8103SBjoern A. Zeeb /* Insert the [l]sta into the list of known stations. */ 1202e24e8103SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 1203e24e8103SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lvif->lsta_head, lsta, lsta_entry); 1204e24e8103SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 1205e24e8103SBjoern A. Zeeb 1206d9f59799SBjoern A. Zeeb /* Add (or adjust) sta and change state (from NOTEXIST) to NONE. */ 12076b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 12086b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NOTEXIST, ("%s: lsta %p state not " 12096b4cac81SBjoern A. Zeeb "NOTEXIST: %#x\n", __func__, lsta, lsta->state)); 1210e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE); 12116b4cac81SBjoern A. Zeeb if (error != 0) { 12126b4cac81SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 1213018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NONE) " 1214018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 12156b4cac81SBjoern A. Zeeb goto out; 12166b4cac81SBjoern A. Zeeb } 12176b4cac81SBjoern A. Zeeb #if 0 12186b4cac81SBjoern A. Zeeb lsta->added_to_drv = true; /* mo manages. */ 12196b4cac81SBjoern A. Zeeb #endif 12206b4cac81SBjoern A. Zeeb 12219d9ba2b7SBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 12229d9ba2b7SBjoern A. Zeeb 12236b4cac81SBjoern A. Zeeb /* 12246b4cac81SBjoern A. Zeeb * Wakeup all queues now that sta is there so we have as much time to 12256b4cac81SBjoern A. Zeeb * possibly prepare the queue in the driver to be ready for the 1st 12266b4cac81SBjoern A. Zeeb * packet; lkpi_80211_txq_tx_one() still has a workaround as there 12276b4cac81SBjoern A. Zeeb * is no guarantee or way to check. 1228d9f59799SBjoern A. Zeeb * XXX-BZ and by now we know that this does not work on all drivers 1229d9f59799SBjoern A. Zeeb * for all queues. 12306b4cac81SBjoern A. Zeeb */ 1231e7fe0373SBjoern A. Zeeb lkpi_wake_tx_queues(hw, LSTA_TO_STA(lsta), false, false); 12326b4cac81SBjoern A. Zeeb 12336b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 12346b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 12356b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 12366b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 12376b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 12386b4cac81SBjoern A. Zeeb 12396b4cac81SBjoern A. Zeeb /* 12406b4cac81SBjoern A. Zeeb * What is going to happen next: 12416b4cac81SBjoern A. Zeeb * - <twiddle> .. we should end up in "auth_to_assoc" 12426b4cac81SBjoern A. Zeeb * - event_callback 12436b4cac81SBjoern A. Zeeb * - update sta_state (NONE to AUTH) 12446b4cac81SBjoern A. Zeeb * - mgd_complete_tx 12456b4cac81SBjoern A. Zeeb * (ideally we'd do that on a callback for something else ...) 12466b4cac81SBjoern A. Zeeb */ 12476b4cac81SBjoern A. Zeeb 12486b4cac81SBjoern A. Zeeb out: 12498ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 12506b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 12516b4cac81SBjoern A. Zeeb if (ni != NULL) 12526b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 12536b4cac81SBjoern A. Zeeb return (error); 12546b4cac81SBjoern A. Zeeb } 12556b4cac81SBjoern A. Zeeb 12566b4cac81SBjoern A. Zeeb static int 12576b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 12586b4cac81SBjoern A. Zeeb { 12596b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 12606b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 12616b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 12626b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 12636b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 12646b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 12656b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 12666b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 12676b4cac81SBjoern A. Zeeb int error; 12686b4cac81SBjoern A. Zeeb 12696b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 12706b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 12716b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 12726b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 12736b4cac81SBjoern A. Zeeb 12746b4cac81SBjoern A. Zeeb /* Keep ni around. */ 12756b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 12766b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 12776b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 12786b4cac81SBjoern A. Zeeb 127967674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 12806b4cac81SBjoern A. Zeeb 12816b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 12828ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 12836b4cac81SBjoern A. Zeeb 1284d9f59799SBjoern A. Zeeb /* flush, drop. */ 1285d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1286d9f59799SBjoern A. Zeeb 12876b4cac81SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 12886b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 12896b4cac81SBjoern A. Zeeb 12906b4cac81SBjoern A. Zeeb /* flush, no drop */ 12916b4cac81SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 12926b4cac81SBjoern A. Zeeb 12936b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 12946b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 12956b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 12966b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 12976b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 12986b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 12996b4cac81SBjoern A. Zeeb } 13006b4cac81SBjoern A. Zeeb 13016b4cac81SBjoern A. Zeeb /* sync_rx_queues */ 13026b4cac81SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 13036b4cac81SBjoern A. Zeeb 13046b4cac81SBjoern A. Zeeb /* sta_pre_rcu_remove */ 13056b4cac81SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 1306d9f59799SBjoern A. Zeeb 1307d9f59799SBjoern A. Zeeb /* Take the station down. */ 13086b4cac81SBjoern A. Zeeb 13096b4cac81SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 13106b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 13116b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 1312d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg)); 1313e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST); 13146b4cac81SBjoern A. Zeeb if (error != 0) { 13156b4cac81SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 1316018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NOTEXIST) " 1317018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 13186b4cac81SBjoern A. Zeeb goto out; 13196b4cac81SBjoern A. Zeeb } 13206b4cac81SBjoern A. Zeeb #if 0 13216b4cac81SBjoern A. Zeeb lsta->added_to_drv = false; /* mo manages. */ 13226b4cac81SBjoern A. Zeeb #endif 13236b4cac81SBjoern A. Zeeb 132467674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 13256b4cac81SBjoern A. Zeeb 1326d9f59799SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif); 1327d9f59799SBjoern A. Zeeb 1328d9f59799SBjoern A. Zeeb /* conf_tx */ 1329d9f59799SBjoern A. Zeeb 1330d9f59799SBjoern A. Zeeb /* Take the chan ctx down. */ 13316b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 1332c5e25798SBjoern A. Zeeb struct lkpi_chanctx *lchanctx; 13336b4cac81SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 13346b4cac81SBjoern A. Zeeb 13356b4cac81SBjoern A. Zeeb conf = vif->chanctx_conf; 13366b4cac81SBjoern A. Zeeb /* Remove vif context. */ 133768541546SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->bss_conf, &vif->chanctx_conf); 13386b4cac81SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 13396b4cac81SBjoern A. Zeeb 13406b4cac81SBjoern A. Zeeb /* Remove chan ctx. */ 13416b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 1342c5e25798SBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(conf); 1343c5e25798SBjoern A. Zeeb free(lchanctx, M_LKPI80211); 13446b4cac81SBjoern A. Zeeb } 13456b4cac81SBjoern A. Zeeb 13466b4cac81SBjoern A. Zeeb out: 13478ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 13486b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 13496b4cac81SBjoern A. Zeeb if (ni != NULL) 13506b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 13516b4cac81SBjoern A. Zeeb return (error); 13526b4cac81SBjoern A. Zeeb } 13536b4cac81SBjoern A. Zeeb 13546b4cac81SBjoern A. Zeeb static int 13556b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 13566b4cac81SBjoern A. Zeeb { 13576b4cac81SBjoern A. Zeeb int error; 13586b4cac81SBjoern A. Zeeb 13596b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_scan(vap, nstate, arg); 13606b4cac81SBjoern A. Zeeb if (error == 0) 13616b4cac81SBjoern A. Zeeb error = lkpi_sta_scan_to_init(vap, nstate, arg); 13626b4cac81SBjoern A. Zeeb return (error); 13636b4cac81SBjoern A. Zeeb } 13646b4cac81SBjoern A. Zeeb 13656b4cac81SBjoern A. Zeeb static int 13666b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 13676b4cac81SBjoern A. Zeeb { 13686b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 13696b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 13706b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 13716b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 13726b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 13736b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 13746b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 13756b4cac81SBjoern A. Zeeb int error; 13766b4cac81SBjoern A. Zeeb 13776b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 13786b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 13796b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 13806b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 13816b4cac81SBjoern A. Zeeb 13826b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 13838ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 13846b4cac81SBjoern A. Zeeb ni = NULL; 13856b4cac81SBjoern A. Zeeb 13866b4cac81SBjoern A. Zeeb /* Finish auth. */ 13876b4cac81SBjoern A. Zeeb IMPROVE("event callback"); 13886b4cac81SBjoern A. Zeeb 13896b4cac81SBjoern A. Zeeb /* Update sta_state (NONE to AUTH). */ 13906b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 13916b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 13926b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 13936b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 13946b4cac81SBjoern A. Zeeb "NONE: %#x\n", __func__, lsta, lsta->state)); 1395e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH); 1396018d93ecSBjoern A. Zeeb if (error != 0) { 1397018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTH) " 1398018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 13996b4cac81SBjoern A. Zeeb goto out; 1400018d93ecSBjoern A. Zeeb } 14016b4cac81SBjoern A. Zeeb 14026b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 14036b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 14046b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 14056b4cac81SBjoern A. Zeeb prep_tx_info.success = true; 14066b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 14076b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 14086b4cac81SBjoern A. Zeeb } 14096b4cac81SBjoern A. Zeeb 14106b4cac81SBjoern A. Zeeb /* Now start assoc. */ 14116b4cac81SBjoern A. Zeeb 14126b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 14136b4cac81SBjoern A. Zeeb if (!lsta->in_mgd) { 14146b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 14156b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 14166b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 14176b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 14186b4cac81SBjoern A. Zeeb } 14196b4cac81SBjoern A. Zeeb 14206b4cac81SBjoern A. Zeeb /* Wake tx queue to get packet out. */ 1421e7fe0373SBjoern A. Zeeb lkpi_wake_tx_queues(hw, LSTA_TO_STA(lsta), true, true); 14226b4cac81SBjoern A. Zeeb 14236b4cac81SBjoern A. Zeeb /* 14246b4cac81SBjoern A. Zeeb * <twiddle> .. we end up in "assoc_to_run" 14256b4cac81SBjoern A. Zeeb * - update sta_state (AUTH to ASSOC) 14266b4cac81SBjoern A. Zeeb * - conf_tx [all] 14276b4cac81SBjoern A. Zeeb * - bss_info_changed (assoc, aid, ssid, ..) 14286b4cac81SBjoern A. Zeeb * - change_chanctx (if needed) 14296b4cac81SBjoern A. Zeeb * - event_callback 14306b4cac81SBjoern A. Zeeb * - mgd_complete_tx 14316b4cac81SBjoern A. Zeeb */ 14326b4cac81SBjoern A. Zeeb 14336b4cac81SBjoern A. Zeeb out: 14348ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 14356b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 14366b4cac81SBjoern A. Zeeb if (ni != NULL) 14376b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 14386b4cac81SBjoern A. Zeeb return (error); 14396b4cac81SBjoern A. Zeeb } 14406b4cac81SBjoern A. Zeeb 14416b4cac81SBjoern A. Zeeb /* auth_to_auth, assoc_to_assoc. */ 14426b4cac81SBjoern A. Zeeb static int 14436b4cac81SBjoern A. Zeeb lkpi_sta_a_to_a(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 14446b4cac81SBjoern A. Zeeb { 14456b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 14466b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 14476b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 14486b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 14496b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 14506b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 14516b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 14526b4cac81SBjoern A. Zeeb 14536b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 14546b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 14556b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 14566b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 14576b4cac81SBjoern A. Zeeb 14586b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 14596b4cac81SBjoern A. Zeeb 14606b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 14618ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 14626b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 14636b4cac81SBjoern A. Zeeb 14646b4cac81SBjoern A. Zeeb IMPROVE("event callback?"); 14656b4cac81SBjoern A. Zeeb 14666b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 14676b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 14686b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 14696b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 14706b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 14716b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 14726b4cac81SBjoern A. Zeeb } 14736b4cac81SBjoern A. Zeeb 14746b4cac81SBjoern A. Zeeb /* Now start assoc. */ 14756b4cac81SBjoern A. Zeeb 14766b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 14776b4cac81SBjoern A. Zeeb if (!lsta->in_mgd) { 14786b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 14796b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 14806b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 14816b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 14826b4cac81SBjoern A. Zeeb } 14836b4cac81SBjoern A. Zeeb 14848ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 14856b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 14866b4cac81SBjoern A. Zeeb if (ni != NULL) 14876b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 14886b4cac81SBjoern A. Zeeb 14896b4cac81SBjoern A. Zeeb return (0); 14906b4cac81SBjoern A. Zeeb } 14916b4cac81SBjoern A. Zeeb 14926b4cac81SBjoern A. Zeeb static int 1493d9f59799SBjoern A. Zeeb _lkpi_sta_assoc_to_down(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 14946b4cac81SBjoern A. Zeeb { 14956b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 14966b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 14976b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 14986b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 14996b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 15006b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 15016b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 15026b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 1503d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 15046b4cac81SBjoern A. Zeeb int error; 15056b4cac81SBjoern A. Zeeb 15066b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 15076b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 15086b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 15096b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 15106b4cac81SBjoern A. Zeeb 15116b4cac81SBjoern A. Zeeb /* Keep ni around. */ 15126b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 15136b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 15146b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 15156b4cac81SBjoern A. Zeeb 151667674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1517d9f59799SBjoern A. Zeeb 1518d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 15198ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1520d9f59799SBjoern A. Zeeb 1521d9f59799SBjoern A. Zeeb /* flush, drop. */ 1522d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1523d9f59799SBjoern A. Zeeb 1524d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?"); 1525d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) && 1526d9f59799SBjoern A. Zeeb !lsta->in_mgd) { 1527d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1528d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 1529d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 1530d9f59799SBjoern A. Zeeb lsta->in_mgd = true; 1531d9f59799SBjoern A. Zeeb } 1532d9f59799SBjoern A. Zeeb 15338ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 1534d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1535d9f59799SBjoern A. Zeeb 1536d9f59799SBjoern A. Zeeb /* Call iv_newstate first so we get potential DISASSOC packet out. */ 1537d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 1538018d93ecSBjoern A. Zeeb if (error != 0) { 1539018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: iv_newstate(%p, %d, %d) " 1540018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, vap, nstate, arg, error); 1541d9f59799SBjoern A. Zeeb goto outni; 1542018d93ecSBjoern A. Zeeb } 1543d9f59799SBjoern A. Zeeb 1544d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 15458ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1546d9f59799SBjoern A. Zeeb 154767674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1548d9f59799SBjoern A. Zeeb 1549d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 1550d9f59799SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 1551d9f59799SBjoern A. Zeeb 1552d9f59799SBjoern A. Zeeb /* flush, no drop */ 1553d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 1554d9f59799SBjoern A. Zeeb 15556b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 15566b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 15576b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 15586b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 15596b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 15606b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 15616b4cac81SBjoern A. Zeeb } 15626b4cac81SBjoern A. Zeeb 1563d9f59799SBjoern A. Zeeb /* sync_rx_queues */ 1564d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 1565d9f59799SBjoern A. Zeeb 1566d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */ 1567d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 1568d9f59799SBjoern A. Zeeb 1569d9f59799SBjoern A. Zeeb /* Take the station down. */ 1570d9f59799SBjoern A. Zeeb 15716b4cac81SBjoern A. Zeeb /* Update sta and change state (from AUTH) to NONE. */ 15726b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 15736b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 15746b4cac81SBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 1575e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE); 1576018d93ecSBjoern A. Zeeb if (error != 0) { 1577018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NONE) " 1578018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 15796b4cac81SBjoern A. Zeeb goto out; 1580018d93ecSBjoern A. Zeeb } 15816b4cac81SBjoern A. Zeeb 158267674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 15836b4cac81SBjoern A. Zeeb 158416e688b2SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 158516e688b2SBjoern A. Zeeb /* 158616e688b2SBjoern A. Zeeb * We need to do this now, before sta changes to IEEE80211_STA_NOTEXIST 158716e688b2SBjoern A. Zeeb * as otherwise drivers (iwlwifi at least) will silently not remove 158816e688b2SBjoern A. Zeeb * the sta from the firmware and when we will add a new one trigger 158916e688b2SBjoern A. Zeeb * a fw assert. 159016e688b2SBjoern A. Zeeb */ 159116e688b2SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw); 159216e688b2SBjoern A. Zeeb 1593d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 1594d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 1595d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 1596d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg)); 1597e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST); 1598d9f59799SBjoern A. Zeeb if (error != 0) { 1599d9f59799SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 1600018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NOTEXIST) " 1601018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 1602d9f59799SBjoern A. Zeeb goto out; 1603d9f59799SBjoern A. Zeeb } 1604d9f59799SBjoern A. Zeeb 160516e688b2SBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); /* sta no longer save to use. */ 1606d9f59799SBjoern A. Zeeb 1607d9f59799SBjoern A. Zeeb IMPROVE("Any bss_info changes to announce?"); 1608d9f59799SBjoern A. Zeeb bss_changed = 0; 1609d9f59799SBjoern A. Zeeb vif->bss_conf.qos = 0; 1610d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 1611616e1330SBjoern A. Zeeb vif->cfg.ssid_len = 0; 1612616e1330SBjoern A. Zeeb memset(vif->cfg.ssid, '\0', sizeof(vif->cfg.ssid)); 1613d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 1614d9f59799SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 1615d9f59799SBjoern A. Zeeb 1616d9f59799SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif); 1617d9f59799SBjoern A. Zeeb 1618d9f59799SBjoern A. Zeeb /* conf_tx */ 1619d9f59799SBjoern A. Zeeb 1620d9f59799SBjoern A. Zeeb /* Take the chan ctx down. */ 1621d9f59799SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 1622c5e25798SBjoern A. Zeeb struct lkpi_chanctx *lchanctx; 1623d9f59799SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 1624d9f59799SBjoern A. Zeeb 1625d9f59799SBjoern A. Zeeb conf = vif->chanctx_conf; 1626d9f59799SBjoern A. Zeeb /* Remove vif context. */ 162768541546SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->bss_conf, &vif->chanctx_conf); 1628d9f59799SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 1629d9f59799SBjoern A. Zeeb 1630d9f59799SBjoern A. Zeeb /* Remove chan ctx. */ 1631d9f59799SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 1632c5e25798SBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(conf); 1633c5e25798SBjoern A. Zeeb free(lchanctx, M_LKPI80211); 1634d9f59799SBjoern A. Zeeb } 1635d9f59799SBjoern A. Zeeb 1636d9f59799SBjoern A. Zeeb error = EALREADY; 16376b4cac81SBjoern A. Zeeb out: 16388ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 16396b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1640d9f59799SBjoern A. Zeeb outni: 16416b4cac81SBjoern A. Zeeb if (ni != NULL) 16426b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 16436b4cac81SBjoern A. Zeeb return (error); 16446b4cac81SBjoern A. Zeeb } 16456b4cac81SBjoern A. Zeeb 16466b4cac81SBjoern A. Zeeb static int 1647d9f59799SBjoern A. Zeeb lkpi_sta_assoc_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 1648d9f59799SBjoern A. Zeeb { 1649d9f59799SBjoern A. Zeeb int error; 1650d9f59799SBjoern A. Zeeb 1651d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg); 1652d9f59799SBjoern A. Zeeb if (error != 0 && error != EALREADY) 1653d9f59799SBjoern A. Zeeb return (error); 1654d9f59799SBjoern A. Zeeb 1655d9f59799SBjoern A. Zeeb /* At this point iv_bss is long a new node! */ 1656d9f59799SBjoern A. Zeeb 1657d9f59799SBjoern A. Zeeb error |= lkpi_sta_scan_to_auth(vap, nstate, 0); 1658d9f59799SBjoern A. Zeeb return (error); 1659d9f59799SBjoern A. Zeeb } 1660d9f59799SBjoern A. Zeeb 1661d9f59799SBjoern A. Zeeb static int 16626b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 16636b4cac81SBjoern A. Zeeb { 16646b4cac81SBjoern A. Zeeb int error; 16656b4cac81SBjoern A. Zeeb 1666d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg); 16676b4cac81SBjoern A. Zeeb return (error); 16686b4cac81SBjoern A. Zeeb } 16696b4cac81SBjoern A. Zeeb 16706b4cac81SBjoern A. Zeeb static int 16716b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 16726b4cac81SBjoern A. Zeeb { 16736b4cac81SBjoern A. Zeeb int error; 16746b4cac81SBjoern A. Zeeb 1675d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg); 16766b4cac81SBjoern A. Zeeb return (error); 16776b4cac81SBjoern A. Zeeb } 16786b4cac81SBjoern A. Zeeb 16796b4cac81SBjoern A. Zeeb static int 16806b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 16816b4cac81SBjoern A. Zeeb { 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 ieee80211_node *ni; 16876b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 16886b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 16896b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 16906b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 16916b4cac81SBjoern A. Zeeb int error; 16926b4cac81SBjoern A. Zeeb 16936b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 16946b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 16956b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 16966b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 16976b4cac81SBjoern A. Zeeb 16986b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 16998ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 17009597f7cbSBjoern A. Zeeb ni = NULL; 17016b4cac81SBjoern A. Zeeb 17026b4cac81SBjoern A. Zeeb IMPROVE("ponder some of this moved to ic_newassoc, scan_assoc_success, " 17036b4cac81SBjoern A. Zeeb "and to lesser extend ieee80211_notify_node_join"); 17046b4cac81SBjoern A. Zeeb 17059597f7cbSBjoern A. Zeeb /* Finish assoc. */ 17069597f7cbSBjoern A. Zeeb /* Update sta_state (AUTH to ASSOC) and set aid. */ 17076b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 17086b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 17096b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 17109597f7cbSBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 17119597f7cbSBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 17126b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 17139597f7cbSBjoern A. Zeeb sta->aid = IEEE80211_NODE_AID(ni); 17144a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 17154a67f1dfSBjoern A. Zeeb if (vap->iv_flags & IEEE80211_F_WME) 17164a67f1dfSBjoern A. Zeeb sta->wme = true; 17174a67f1dfSBjoern A. Zeeb #endif 1718e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC); 1719018d93ecSBjoern A. Zeeb if (error != 0) { 1720018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(ASSOC) " 1721018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 17229597f7cbSBjoern A. Zeeb goto out; 1723018d93ecSBjoern A. Zeeb } 17246b4cac81SBjoern A. Zeeb 17256b4cac81SBjoern A. Zeeb IMPROVE("wme / conf_tx [all]"); 17266b4cac81SBjoern A. Zeeb 17276b4cac81SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 17286b4cac81SBjoern A. Zeeb bss_changed = 0; 17294a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 17304a67f1dfSBjoern A. Zeeb bss_changed |= lkpi_wme_update(lhw, vap, true); 17314a67f1dfSBjoern A. Zeeb #endif 1732616e1330SBjoern A. Zeeb if (!vif->cfg.assoc || vif->cfg.aid != IEEE80211_NODE_AID(ni)) { 1733616e1330SBjoern A. Zeeb vif->cfg.assoc = true; 1734616e1330SBjoern A. Zeeb vif->cfg.aid = IEEE80211_NODE_AID(ni); 17356b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_ASSOC; 17366b4cac81SBjoern A. Zeeb } 17376b4cac81SBjoern A. Zeeb /* We set SSID but this is not BSSID! */ 1738616e1330SBjoern A. Zeeb vif->cfg.ssid_len = ni->ni_esslen; 1739616e1330SBjoern A. Zeeb memcpy(vif->cfg.ssid, ni->ni_essid, ni->ni_esslen); 17406b4cac81SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_SHPREAMBLE) != 17416b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble) { 17426b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble ^= 1; 17436b4cac81SBjoern A. Zeeb /* bss_changed |= BSS_CHANGED_??? */ 17446b4cac81SBjoern A. Zeeb } 17456b4cac81SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_SHSLOT) != 17466b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot) { 17476b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot ^= 1; 17486b4cac81SBjoern A. Zeeb /* bss_changed |= BSS_CHANGED_??? */ 17496b4cac81SBjoern A. Zeeb } 17506b4cac81SBjoern A. Zeeb if ((ni->ni_flags & IEEE80211_NODE_QOS) != 17516b4cac81SBjoern A. Zeeb vif->bss_conf.qos) { 17526b4cac81SBjoern A. Zeeb vif->bss_conf.qos ^= 1; 17536b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 17546b4cac81SBjoern A. Zeeb } 1755fa8f007dSBjoern A. Zeeb 1756fa8f007dSBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 1757fa8f007dSBjoern A. Zeeb 17586b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 17596b4cac81SBjoern A. Zeeb 17606b4cac81SBjoern A. Zeeb /* - change_chanctx (if needed) 17616b4cac81SBjoern A. Zeeb * - event_callback 17626b4cac81SBjoern A. Zeeb */ 17636b4cac81SBjoern A. Zeeb 17646b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 17656b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 17666b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 17676b4cac81SBjoern A. Zeeb prep_tx_info.success = true; 17686b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 17696b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 17706b4cac81SBjoern A. Zeeb } 17716b4cac81SBjoern A. Zeeb 1772086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, false); 1773086be6a8SBjoern A. Zeeb 17746b4cac81SBjoern A. Zeeb /* 17756b4cac81SBjoern A. Zeeb * And then: 17766b4cac81SBjoern A. Zeeb * - (more packets)? 17776b4cac81SBjoern A. Zeeb * - set_key 17786b4cac81SBjoern A. Zeeb * - set_default_unicast_key 17796b4cac81SBjoern A. Zeeb * - set_key (?) 17806b4cac81SBjoern A. Zeeb * - ipv6_addr_change (?) 17816b4cac81SBjoern A. Zeeb */ 17826b4cac81SBjoern A. Zeeb /* Prepare_multicast && configure_filter. */ 17836b4cac81SBjoern A. Zeeb lhw->update_mc = true; 17846b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(vap->iv_ic, true); 17856b4cac81SBjoern A. Zeeb 17866b4cac81SBjoern A. Zeeb if (!ieee80211_node_is_authorized(ni)) { 17876b4cac81SBjoern A. Zeeb IMPROVE("net80211 does not consider node authorized"); 17886b4cac81SBjoern A. Zeeb } 17896b4cac81SBjoern A. Zeeb 17909fb91463SBjoern A. Zeeb #if defined(LKPI_80211_HT) 17919fb91463SBjoern A. Zeeb IMPROVE("Is this the right spot, has net80211 done all updates already?"); 17929fb91463SBjoern A. Zeeb lkpi_sta_sync_ht_from_ni(sta, ni, NULL); 17939fb91463SBjoern A. Zeeb #endif 17949fb91463SBjoern A. Zeeb 17956b4cac81SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTHORIZED). */ 17966b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 17976b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 17986b4cac81SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 1799e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTHORIZED); 18006b4cac81SBjoern A. Zeeb if (error != 0) { 18016b4cac81SBjoern A. Zeeb IMPROVE("undo some changes?"); 1802018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTHORIZED) " 1803018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 18046b4cac81SBjoern A. Zeeb goto out; 18056b4cac81SBjoern A. Zeeb } 18066b4cac81SBjoern A. Zeeb 18076b4cac81SBjoern A. Zeeb /* - drv_config (?) 18086b4cac81SBjoern A. Zeeb * - bss_info_changed 18096b4cac81SBjoern A. Zeeb * - set_rekey_data (?) 18106b4cac81SBjoern A. Zeeb * 18116b4cac81SBjoern A. Zeeb * And now we should be passing packets. 18126b4cac81SBjoern A. Zeeb */ 18136b4cac81SBjoern A. Zeeb IMPROVE("Need that bssid setting, and the keys"); 18146b4cac81SBjoern A. Zeeb 1815fa8f007dSBjoern A. Zeeb bss_changed = 0; 1816fa8f007dSBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 1817fa8f007dSBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 1818fa8f007dSBjoern A. Zeeb 18196b4cac81SBjoern A. Zeeb out: 18208ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 18216b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 18226b4cac81SBjoern A. Zeeb if (ni != NULL) 18236b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 18246b4cac81SBjoern A. Zeeb return (error); 18256b4cac81SBjoern A. Zeeb } 18266b4cac81SBjoern A. Zeeb 18276b4cac81SBjoern A. Zeeb static int 18286b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 18296b4cac81SBjoern A. Zeeb { 18306b4cac81SBjoern A. Zeeb int error; 18316b4cac81SBjoern A. Zeeb 18326b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_assoc(vap, nstate, arg); 18336b4cac81SBjoern A. Zeeb if (error == 0) 18346b4cac81SBjoern A. Zeeb error = lkpi_sta_assoc_to_run(vap, nstate, arg); 18356b4cac81SBjoern A. Zeeb return (error); 18366b4cac81SBjoern A. Zeeb } 18376b4cac81SBjoern A. Zeeb 18386b4cac81SBjoern A. Zeeb static int 18396b4cac81SBjoern A. Zeeb lkpi_sta_run_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 18406b4cac81SBjoern A. Zeeb { 18416b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 18426b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 18436b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 18446b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 18456b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 18466b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 18476b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 1848d9f59799SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 1849d9f59799SBjoern A. Zeeb #if 0 1850d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 1851d9f59799SBjoern A. Zeeb #endif 18526b4cac81SBjoern A. Zeeb int error; 18536b4cac81SBjoern A. Zeeb 18546b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 18556b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 18566b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 18576b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 18586b4cac81SBjoern A. Zeeb 18596b4cac81SBjoern A. Zeeb /* Keep ni around. */ 18606b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 18616b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 18626b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 18636b4cac81SBjoern A. Zeeb 186467674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1865d9f59799SBjoern A. Zeeb 1866d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 18678ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1868d9f59799SBjoern A. Zeeb 1869d9f59799SBjoern A. Zeeb /* flush, drop. */ 1870d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1871d9f59799SBjoern A. Zeeb 1872d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?"); 1873d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) && 1874d9f59799SBjoern A. Zeeb !lsta->in_mgd) { 1875d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1876d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 1877d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 1878d9f59799SBjoern A. Zeeb lsta->in_mgd = true; 1879d9f59799SBjoern A. Zeeb } 1880d9f59799SBjoern A. Zeeb 18818ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 1882d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1883d9f59799SBjoern A. Zeeb 1884d9f59799SBjoern A. Zeeb /* Call iv_newstate first so we get potential DISASSOC packet out. */ 1885d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 1886018d93ecSBjoern A. Zeeb if (error != 0) { 1887018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: iv_newstate(%p, %d, %d) " 1888018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, vap, nstate, arg, error); 1889d9f59799SBjoern A. Zeeb goto outni; 1890018d93ecSBjoern A. Zeeb } 1891d9f59799SBjoern A. Zeeb 1892d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 18938ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1894d9f59799SBjoern A. Zeeb 189567674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1896d9f59799SBjoern A. Zeeb 1897d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 1898d9f59799SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 1899d9f59799SBjoern A. Zeeb 1900d9f59799SBjoern A. Zeeb /* flush, no drop */ 1901d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 1902d9f59799SBjoern A. Zeeb 1903d9f59799SBjoern A. Zeeb /* End mgd_complete_tx. */ 1904d9f59799SBjoern A. Zeeb if (lsta->in_mgd) { 1905d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1906d9f59799SBjoern A. Zeeb prep_tx_info.success = false; 1907d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 1908d9f59799SBjoern A. Zeeb lsta->in_mgd = false; 1909d9f59799SBjoern A. Zeeb } 1910d9f59799SBjoern A. Zeeb 1911d9f59799SBjoern A. Zeeb #if 0 1912d9f59799SBjoern A. Zeeb /* sync_rx_queues */ 1913d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 1914d9f59799SBjoern A. Zeeb 1915d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */ 1916d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 1917d9f59799SBjoern A. Zeeb #endif 1918d9f59799SBjoern A. Zeeb 1919d9f59799SBjoern A. Zeeb /* Take the station down. */ 1920d9f59799SBjoern A. Zeeb 19216b4cac81SBjoern A. Zeeb /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */ 19226b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 19236b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not " 19246b4cac81SBjoern A. Zeeb "AUTHORIZED: %#x\n", __func__, lsta, lsta->state)); 1925e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC); 1926018d93ecSBjoern A. Zeeb if (error != 0) { 1927018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(ASSOC) " 1928018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 19296b4cac81SBjoern A. Zeeb goto out; 1930018d93ecSBjoern A. Zeeb } 19316b4cac81SBjoern A. Zeeb 193267674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 19336b4cac81SBjoern A. Zeeb 19346b4cac81SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTH). */ 19356b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 19366b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 19376b4cac81SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 1938e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH); 1939018d93ecSBjoern A. Zeeb if (error != 0) { 1940018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTH) " 1941018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 19426b4cac81SBjoern A. Zeeb goto out; 1943018d93ecSBjoern A. Zeeb } 19446b4cac81SBjoern A. Zeeb 194567674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 19466b4cac81SBjoern A. Zeeb 1947d9f59799SBjoern A. Zeeb #if 0 1948d9f59799SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 1949d9f59799SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw); 1950d9f59799SBjoern A. Zeeb #endif 1951d9f59799SBjoern A. Zeeb 1952d9f59799SBjoern A. Zeeb error = EALREADY; 19536b4cac81SBjoern A. Zeeb out: 19548ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 19556b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1956d9f59799SBjoern A. Zeeb outni: 19576b4cac81SBjoern A. Zeeb if (ni != NULL) 19586b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 19596b4cac81SBjoern A. Zeeb return (error); 19606b4cac81SBjoern A. Zeeb } 19616b4cac81SBjoern A. Zeeb 19626b4cac81SBjoern A. Zeeb static int 1963d9f59799SBjoern A. Zeeb lkpi_sta_run_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 1964d9f59799SBjoern A. Zeeb { 1965d9f59799SBjoern A. Zeeb struct lkpi_hw *lhw; 1966d9f59799SBjoern A. Zeeb struct ieee80211_hw *hw; 1967d9f59799SBjoern A. Zeeb struct lkpi_vif *lvif; 1968d9f59799SBjoern A. Zeeb struct ieee80211_vif *vif; 1969d9f59799SBjoern A. Zeeb struct ieee80211_node *ni; 1970d9f59799SBjoern A. Zeeb struct lkpi_sta *lsta; 1971d9f59799SBjoern A. Zeeb struct ieee80211_sta *sta; 1972d9f59799SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 1973d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 1974d9f59799SBjoern A. Zeeb int error; 1975d9f59799SBjoern A. Zeeb 1976d9f59799SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 1977d9f59799SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 1978d9f59799SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 1979d9f59799SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 1980d9f59799SBjoern A. Zeeb 1981d9f59799SBjoern A. Zeeb /* Keep ni around. */ 1982d9f59799SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 1983d9f59799SBjoern A. Zeeb lsta = ni->ni_drv_data; 1984d9f59799SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 1985d9f59799SBjoern A. Zeeb 198667674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1987d9f59799SBjoern A. Zeeb 1988d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 19898ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1990d9f59799SBjoern A. Zeeb 1991d9f59799SBjoern A. Zeeb /* flush, drop. */ 1992d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1993d9f59799SBjoern A. Zeeb 1994d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?"); 1995d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) && 1996d9f59799SBjoern A. Zeeb !lsta->in_mgd) { 1997d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1998d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 1999d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 2000d9f59799SBjoern A. Zeeb lsta->in_mgd = true; 2001d9f59799SBjoern A. Zeeb } 2002d9f59799SBjoern A. Zeeb 20038ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 2004d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 2005d9f59799SBjoern A. Zeeb 2006d9f59799SBjoern A. Zeeb /* Call iv_newstate first so we get potential DISASSOC packet out. */ 2007d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 2008018d93ecSBjoern A. Zeeb if (error != 0) { 2009018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: iv_newstate(%p, %d, %d) " 2010018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, vap, nstate, arg, error); 2011d9f59799SBjoern A. Zeeb goto outni; 2012018d93ecSBjoern A. Zeeb } 2013d9f59799SBjoern A. Zeeb 2014d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 20158ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 2016d9f59799SBjoern A. Zeeb 201767674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 2018d9f59799SBjoern A. Zeeb 2019d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 2020d9f59799SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 2021d9f59799SBjoern A. Zeeb 2022d9f59799SBjoern A. Zeeb /* flush, no drop */ 2023d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 2024d9f59799SBjoern A. Zeeb 2025d9f59799SBjoern A. Zeeb /* End mgd_complete_tx. */ 2026d9f59799SBjoern A. Zeeb if (lsta->in_mgd) { 2027d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 2028d9f59799SBjoern A. Zeeb prep_tx_info.success = false; 2029d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 2030d9f59799SBjoern A. Zeeb lsta->in_mgd = false; 2031d9f59799SBjoern A. Zeeb } 2032d9f59799SBjoern A. Zeeb 2033d9f59799SBjoern A. Zeeb /* sync_rx_queues */ 2034d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 2035d9f59799SBjoern A. Zeeb 2036d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */ 2037d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 2038d9f59799SBjoern A. Zeeb 2039d9f59799SBjoern A. Zeeb /* Take the station down. */ 2040d9f59799SBjoern A. Zeeb 2041d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */ 2042d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 2043d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not " 2044d9f59799SBjoern A. Zeeb "AUTHORIZED: %#x\n", __func__, lsta, lsta->state)); 2045e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC); 2046018d93ecSBjoern A. Zeeb if (error != 0) { 2047018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(ASSOC) " 2048018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 2049d9f59799SBjoern A. Zeeb goto out; 2050018d93ecSBjoern A. Zeeb } 2051d9f59799SBjoern A. Zeeb 205267674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 2053d9f59799SBjoern A. Zeeb 2054d9f59799SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTH). */ 2055d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 2056d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 2057d9f59799SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 2058e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH); 2059018d93ecSBjoern A. Zeeb if (error != 0) { 2060018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTH) " 2061018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 2062d9f59799SBjoern A. Zeeb goto out; 2063018d93ecSBjoern A. Zeeb } 2064d9f59799SBjoern A. Zeeb 206567674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 2066d9f59799SBjoern A. Zeeb 2067d9f59799SBjoern A. Zeeb /* Update sta and change state (from AUTH) to NONE. */ 2068d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 2069d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 2070d9f59799SBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 2071e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE); 2072018d93ecSBjoern A. Zeeb if (error != 0) { 2073018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NONE) " 2074018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 2075d9f59799SBjoern A. Zeeb goto out; 2076018d93ecSBjoern A. Zeeb } 2077d9f59799SBjoern A. Zeeb 207867674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 2079d9f59799SBjoern A. Zeeb 208016e688b2SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 208116e688b2SBjoern A. Zeeb /* 208216e688b2SBjoern A. Zeeb * One would expect this to happen when going off AUTHORIZED. 208316e688b2SBjoern A. Zeeb * See comment there; removes the sta from fw. 208416e688b2SBjoern A. Zeeb */ 208516e688b2SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw); 208616e688b2SBjoern A. Zeeb 2087d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 2088d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 2089d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 2090d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg)); 2091e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST); 2092d9f59799SBjoern A. Zeeb if (error != 0) { 2093d9f59799SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 2094018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NOTEXIST) " 2095018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 2096d9f59799SBjoern A. Zeeb goto out; 2097d9f59799SBjoern A. Zeeb } 2098d9f59799SBjoern A. Zeeb 209916e688b2SBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); /* sta no longer save to use. */ 2100d9f59799SBjoern A. Zeeb 2101d9f59799SBjoern A. Zeeb IMPROVE("Any bss_info changes to announce?"); 2102d9f59799SBjoern A. Zeeb bss_changed = 0; 2103d9f59799SBjoern A. Zeeb vif->bss_conf.qos = 0; 2104d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 2105616e1330SBjoern A. Zeeb vif->cfg.ssid_len = 0; 2106616e1330SBjoern A. Zeeb memset(vif->cfg.ssid, '\0', sizeof(vif->cfg.ssid)); 2107d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 2108d9f59799SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 2109d9f59799SBjoern A. Zeeb 2110d9f59799SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif); 2111d9f59799SBjoern A. Zeeb 2112d9f59799SBjoern A. Zeeb /* conf_tx */ 2113d9f59799SBjoern A. Zeeb 2114d9f59799SBjoern A. Zeeb /* Take the chan ctx down. */ 2115d9f59799SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 2116c5e25798SBjoern A. Zeeb struct lkpi_chanctx *lchanctx; 2117d9f59799SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 2118d9f59799SBjoern A. Zeeb 2119d9f59799SBjoern A. Zeeb conf = vif->chanctx_conf; 2120d9f59799SBjoern A. Zeeb /* Remove vif context. */ 212168541546SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->bss_conf, &vif->chanctx_conf); 2122d9f59799SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 2123d9f59799SBjoern A. Zeeb 2124d9f59799SBjoern A. Zeeb /* Remove chan ctx. */ 2125d9f59799SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 2126c5e25798SBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(conf); 2127c5e25798SBjoern A. Zeeb free(lchanctx, M_LKPI80211); 2128d9f59799SBjoern A. Zeeb } 2129d9f59799SBjoern A. Zeeb 2130d9f59799SBjoern A. Zeeb error = EALREADY; 2131d9f59799SBjoern A. Zeeb out: 21328ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 2133d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 2134d9f59799SBjoern A. Zeeb outni: 2135d9f59799SBjoern A. Zeeb if (ni != NULL) 2136d9f59799SBjoern A. Zeeb ieee80211_free_node(ni); 2137d9f59799SBjoern A. Zeeb return (error); 2138d9f59799SBjoern A. Zeeb } 2139d9f59799SBjoern A. Zeeb 2140d9f59799SBjoern A. Zeeb static int 2141d9f59799SBjoern A. Zeeb lkpi_sta_run_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 2142d9f59799SBjoern A. Zeeb { 2143d9f59799SBjoern A. Zeeb 2144d9f59799SBjoern A. Zeeb return (lkpi_sta_run_to_init(vap, nstate, arg)); 2145d9f59799SBjoern A. Zeeb } 2146d9f59799SBjoern A. Zeeb 2147d9f59799SBjoern A. Zeeb static int 21486b4cac81SBjoern A. Zeeb lkpi_sta_run_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 21496b4cac81SBjoern A. Zeeb { 21506b4cac81SBjoern A. Zeeb int error; 21516b4cac81SBjoern A. Zeeb 2152d9f59799SBjoern A. Zeeb error = lkpi_sta_run_to_init(vap, nstate, arg); 2153d9f59799SBjoern A. Zeeb if (error != 0 && error != EALREADY) 2154d9f59799SBjoern A. Zeeb return (error); 2155d9f59799SBjoern A. Zeeb 2156d9f59799SBjoern A. Zeeb /* At this point iv_bss is long a new node! */ 2157d9f59799SBjoern A. Zeeb 2158d9f59799SBjoern A. Zeeb error |= lkpi_sta_scan_to_auth(vap, nstate, 0); 21596b4cac81SBjoern A. Zeeb return (error); 21606b4cac81SBjoern A. Zeeb } 21616b4cac81SBjoern A. Zeeb 2162d9f59799SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 21636b4cac81SBjoern A. Zeeb 21646b4cac81SBjoern A. Zeeb /* 21656b4cac81SBjoern A. Zeeb * The matches the documented state changes in net80211::sta_newstate(). 21666b4cac81SBjoern A. Zeeb * XXX (1) without CSA and SLEEP yet, * XXX (2) not all unhandled cases 21676b4cac81SBjoern A. Zeeb * there are "invalid" (so there is a room for failure here). 21686b4cac81SBjoern A. Zeeb */ 21696b4cac81SBjoern A. Zeeb struct fsm_state { 21706b4cac81SBjoern A. Zeeb /* INIT, SCAN, AUTH, ASSOC, CAC, RUN, CSA, SLEEP */ 21716b4cac81SBjoern A. Zeeb enum ieee80211_state ostate; 21726b4cac81SBjoern A. Zeeb enum ieee80211_state nstate; 21736b4cac81SBjoern A. Zeeb int (*handler)(struct ieee80211vap *, enum ieee80211_state, int); 21746b4cac81SBjoern A. Zeeb } sta_state_fsm[] = { 21756b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, 21766b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, /* scan_to_init */ 21776b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_INIT, lkpi_sta_auth_to_init }, /* not explicitly in sta_newstate() */ 2178d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_INIT, lkpi_sta_assoc_to_init }, /* Send DEAUTH. */ 2179d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_INIT, lkpi_sta_run_to_init }, /* Send DISASSOC. */ 21806b4cac81SBjoern A. Zeeb 21816b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_SCAN, lkpi_sta_state_do_nada }, 21826b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_SCAN, lkpi_sta_state_do_nada }, 21836b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_SCAN, lkpi_sta_auth_to_scan }, 21846b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_SCAN, lkpi_sta_assoc_to_scan }, 2185d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_SCAN, lkpi_sta_run_to_scan }, /* Beacon miss. */ 21866b4cac81SBjoern A. Zeeb 2187d9f59799SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, /* Send AUTH. */ 2188d9f59799SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, /* Send AUTH. */ 2189d9f59799SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_AUTH, lkpi_sta_a_to_a }, /* Send ?AUTH. */ 2190d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_AUTH, lkpi_sta_assoc_to_auth }, /* Send ?AUTH. */ 2191d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_AUTH, lkpi_sta_run_to_auth }, /* Send ?AUTH. */ 21926b4cac81SBjoern A. Zeeb 2193d9f59799SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_ASSOC, lkpi_sta_auth_to_assoc }, /* Send ASSOCREQ. */ 2194d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_ASSOC, lkpi_sta_a_to_a }, /* Send ASSOCREQ. */ 2195d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_ASSOC, lkpi_sta_run_to_assoc }, /* Send ASSOCREQ/REASSOCREQ. */ 21966b4cac81SBjoern A. Zeeb 21976b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_RUN, lkpi_sta_auth_to_run }, 21986b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_RUN, lkpi_sta_assoc_to_run }, 21996b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_RUN, lkpi_sta_state_do_nada }, 22006b4cac81SBjoern A. Zeeb 22016b4cac81SBjoern A. Zeeb /* Dummy at the end without handler. */ 22026b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_INIT, NULL }, 22036b4cac81SBjoern A. Zeeb }; 22046b4cac81SBjoern A. Zeeb 22056b4cac81SBjoern A. Zeeb static int 22066b4cac81SBjoern A. Zeeb lkpi_iv_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 22076b4cac81SBjoern A. Zeeb { 22086b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 22096b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 22106b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 22116b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 22126b4cac81SBjoern A. Zeeb struct fsm_state *s; 22136b4cac81SBjoern A. Zeeb enum ieee80211_state ostate; 22146b4cac81SBjoern A. Zeeb int error; 22156b4cac81SBjoern A. Zeeb 22166b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 22176b4cac81SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(ic); 22186b4cac81SBjoern A. Zeeb ostate = vap->iv_state; 22196b4cac81SBjoern A. Zeeb 22209d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 22219d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 22226b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x\n", 22236b4cac81SBjoern A. Zeeb __func__, __LINE__, vap, nstate, arg); 22249d9ba2b7SBjoern A. Zeeb #endif 22256b4cac81SBjoern A. Zeeb 22266b4cac81SBjoern A. Zeeb if (vap->iv_opmode == IEEE80211_M_STA) { 22276b4cac81SBjoern A. Zeeb 22286b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 22296b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 22306b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 22316b4cac81SBjoern A. Zeeb 22326b4cac81SBjoern A. Zeeb /* No need to replicate this in most state handlers. */ 22336b4cac81SBjoern A. Zeeb if (ostate == IEEE80211_S_SCAN && nstate != IEEE80211_S_SCAN) 22346b4cac81SBjoern A. Zeeb lkpi_stop_hw_scan(lhw, vif); 22356b4cac81SBjoern A. Zeeb 22366b4cac81SBjoern A. Zeeb s = sta_state_fsm; 22376b4cac81SBjoern A. Zeeb 22386b4cac81SBjoern A. Zeeb } else { 22396b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: only station mode currently supported: " 22406b4cac81SBjoern A. Zeeb "cap %p iv_opmode %d\n", __func__, vap, vap->iv_opmode); 22416b4cac81SBjoern A. Zeeb return (ENOSYS); 22426b4cac81SBjoern A. Zeeb } 22436b4cac81SBjoern A. Zeeb 22446b4cac81SBjoern A. Zeeb error = 0; 22456b4cac81SBjoern A. Zeeb for (; s->handler != NULL; s++) { 22466b4cac81SBjoern A. Zeeb if (ostate == s->ostate && nstate == s->nstate) { 22479d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 22489d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 2249d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: new state %d (%s) ->" 2250d9f59799SBjoern A. Zeeb " %d (%s): arg %d.\n", __func__, 2251d9f59799SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 2252d9f59799SBjoern A. Zeeb nstate, ieee80211_state_name[nstate], arg); 22539d9ba2b7SBjoern A. Zeeb #endif 22546b4cac81SBjoern A. Zeeb error = s->handler(vap, nstate, arg); 22556b4cac81SBjoern A. Zeeb break; 22566b4cac81SBjoern A. Zeeb } 22576b4cac81SBjoern A. Zeeb } 22586b4cac81SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(vap->iv_ic); 22596b4cac81SBjoern A. Zeeb 22606b4cac81SBjoern A. Zeeb if (s->handler == NULL) { 2261d9f59799SBjoern A. Zeeb IMPROVE("turn this into a KASSERT\n"); 22626b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: unsupported state transition " 22636b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s)\n", __func__, 22646b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 22656b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 22666b4cac81SBjoern A. Zeeb return (ENOSYS); 22676b4cac81SBjoern A. Zeeb } 22686b4cac81SBjoern A. Zeeb 22696b4cac81SBjoern A. Zeeb if (error == EALREADY) { 22709d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 22719d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 2272d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: state transition %d (%s) -> " 2273d9f59799SBjoern A. Zeeb "%d (%s): iv_newstate already handled: %d.\n", 2274d9f59799SBjoern A. Zeeb __func__, ostate, ieee80211_state_name[ostate], 2275d9f59799SBjoern A. Zeeb nstate, ieee80211_state_name[nstate], error); 22769d9ba2b7SBjoern A. Zeeb #endif 22776b4cac81SBjoern A. Zeeb return (0); 22786b4cac81SBjoern A. Zeeb } 22796b4cac81SBjoern A. Zeeb 22806b4cac81SBjoern A. Zeeb if (error != 0) { 22816b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: error %d during state transition " 22826b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s)\n", __func__, error, 22836b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 22846b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 228545c27ad5SBjoern A. Zeeb return (error); 22866b4cac81SBjoern A. Zeeb } 22876b4cac81SBjoern A. Zeeb 22889d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 22899d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 2290d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x " 2291d9f59799SBjoern A. Zeeb "calling net80211 parent\n", 22926b4cac81SBjoern A. Zeeb __func__, __LINE__, vap, nstate, arg); 22939d9ba2b7SBjoern A. Zeeb #endif 22946b4cac81SBjoern A. Zeeb 22956b4cac81SBjoern A. Zeeb return (lvif->iv_newstate(vap, nstate, arg)); 22966b4cac81SBjoern A. Zeeb } 22976b4cac81SBjoern A. Zeeb 22986b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 22996b4cac81SBjoern A. Zeeb 2300d9f59799SBjoern A. Zeeb /* 2301d9f59799SBjoern A. Zeeb * We overload (*iv_update_bss) as otherwise we have cases in, e.g., 2302d9f59799SBjoern A. Zeeb * net80211::ieee80211_sta_join1() where vap->iv_bss gets replaced by a 2303d9f59799SBjoern A. Zeeb * new node without us knowing and thus our ni/lsta are out of sync. 2304d9f59799SBjoern A. Zeeb */ 2305d9f59799SBjoern A. Zeeb static struct ieee80211_node * 2306d9f59799SBjoern A. Zeeb lkpi_iv_update_bss(struct ieee80211vap *vap, struct ieee80211_node *ni) 2307d9f59799SBjoern A. Zeeb { 2308d9f59799SBjoern A. Zeeb struct lkpi_vif *lvif; 2309d9f59799SBjoern A. Zeeb struct ieee80211_node *obss; 2310d9f59799SBjoern A. Zeeb struct lkpi_sta *lsta; 2311ed3ef56bSBjoern A. Zeeb struct ieee80211_sta *sta; 2312d9f59799SBjoern A. Zeeb 2313d9f59799SBjoern A. Zeeb obss = vap->iv_bss; 2314d9f59799SBjoern A. Zeeb 23159d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 23169d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 23179d9ba2b7SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: obss %p ni_drv_data %p " 23189d9ba2b7SBjoern A. Zeeb "ni %p ni_drv_data %p\n", __func__, 23199d9ba2b7SBjoern A. Zeeb obss, (obss != NULL) ? obss->ni_drv_data : NULL, 23209d9ba2b7SBjoern A. Zeeb ni, (ni != NULL) ? ni->ni_drv_data : NULL); 23219d9ba2b7SBjoern A. Zeeb #endif 23229d9ba2b7SBjoern A. Zeeb 2323d9f59799SBjoern A. Zeeb /* Nothing to copy from. Just return. */ 2324d9f59799SBjoern A. Zeeb if (obss == NULL || obss->ni_drv_data == NULL) 2325d9f59799SBjoern A. Zeeb goto out; 2326d9f59799SBjoern A. Zeeb 2327d9f59799SBjoern A. Zeeb /* Nothing to copy to. Just return. */ 2328d9f59799SBjoern A. Zeeb IMPROVE("clearing the obss might still be needed?"); 2329d9f59799SBjoern A. Zeeb if (ni == NULL) 2330d9f59799SBjoern A. Zeeb goto out; 2331d9f59799SBjoern A. Zeeb 2332d9f59799SBjoern A. Zeeb /* Nothing changed? panic? */ 2333d9f59799SBjoern A. Zeeb if (obss == ni) 2334d9f59799SBjoern A. Zeeb goto out; 2335d9f59799SBjoern A. Zeeb 2336d9f59799SBjoern A. Zeeb lsta = obss->ni_drv_data; 2337d9f59799SBjoern A. Zeeb obss->ni_drv_data = ni->ni_drv_data; 2338d9f59799SBjoern A. Zeeb ni->ni_drv_data = lsta; 2339ed3ef56bSBjoern A. Zeeb if (lsta != NULL) { 2340d9f59799SBjoern A. Zeeb lsta->ni = ni; 2341ed3ef56bSBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 2342ed3ef56bSBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->addr, lsta->ni->ni_macaddr); 23436ffb7bd4SBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->deflink.addr, sta->addr); 2344ed3ef56bSBjoern A. Zeeb } 2345d9f59799SBjoern A. Zeeb lsta = obss->ni_drv_data; 2346ed3ef56bSBjoern A. Zeeb if (lsta != NULL) { 2347d9f59799SBjoern A. Zeeb lsta->ni = obss; 2348ed3ef56bSBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 2349ed3ef56bSBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->addr, lsta->ni->ni_macaddr); 23506ffb7bd4SBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->deflink.addr, sta->addr); 2351ed3ef56bSBjoern A. Zeeb } 2352d9f59799SBjoern A. Zeeb 2353d9f59799SBjoern A. Zeeb out: 2354ed3ef56bSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 2355d9f59799SBjoern A. Zeeb return (lvif->iv_update_bss(vap, ni)); 2356d9f59799SBjoern A. Zeeb } 2357d9f59799SBjoern A. Zeeb 23584a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 23596b4cac81SBjoern A. Zeeb static int 23604a67f1dfSBjoern A. Zeeb lkpi_wme_update(struct lkpi_hw *lhw, struct ieee80211vap *vap, bool planned) 23616b4cac81SBjoern A. Zeeb { 23624a67f1dfSBjoern A. Zeeb struct ieee80211com *ic; 23636b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 23646b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 23656b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 23666b4cac81SBjoern A. Zeeb struct chanAccParams chp; 23676b4cac81SBjoern A. Zeeb struct wmeParams wmeparr[WME_NUM_AC]; 23686b4cac81SBjoern A. Zeeb struct ieee80211_tx_queue_params txqp; 23696b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 23706b4cac81SBjoern A. Zeeb int error; 23716b4cac81SBjoern A. Zeeb uint16_t ac; 23726b4cac81SBjoern A. Zeeb 23736b4cac81SBjoern A. Zeeb IMPROVE(); 23746b4cac81SBjoern A. Zeeb KASSERT(WME_NUM_AC == IEEE80211_NUM_ACS, ("%s: WME_NUM_AC %d != " 23756b4cac81SBjoern A. Zeeb "IEEE80211_NUM_ACS %d\n", __func__, WME_NUM_AC, IEEE80211_NUM_ACS)); 23766b4cac81SBjoern A. Zeeb 23776b4cac81SBjoern A. Zeeb if (vap == NULL) 23786b4cac81SBjoern A. Zeeb return (0); 23796b4cac81SBjoern A. Zeeb 23804a67f1dfSBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WME) == 0) 23814a67f1dfSBjoern A. Zeeb return (0); 23824a67f1dfSBjoern A. Zeeb 23836b4cac81SBjoern A. Zeeb if (lhw->ops->conf_tx == NULL) 23846b4cac81SBjoern A. Zeeb return (0); 23856b4cac81SBjoern A. Zeeb 23864a67f1dfSBjoern A. Zeeb if (!planned && (vap->iv_state != IEEE80211_S_RUN)) { 23874a67f1dfSBjoern A. Zeeb lhw->update_wme = true; 23884a67f1dfSBjoern A. Zeeb return (0); 23894a67f1dfSBjoern A. Zeeb } 23904a67f1dfSBjoern A. Zeeb lhw->update_wme = false; 23916b4cac81SBjoern A. Zeeb 23924a67f1dfSBjoern A. Zeeb ic = lhw->ic; 23936b4cac81SBjoern A. Zeeb ieee80211_wme_ic_getparams(ic, &chp); 23946b4cac81SBjoern A. Zeeb IEEE80211_LOCK(ic); 23956b4cac81SBjoern A. Zeeb for (ac = 0; ac < WME_NUM_AC; ac++) 23966b4cac81SBjoern A. Zeeb wmeparr[ac] = chp.cap_wmeParams[ac]; 23976b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(ic); 23986b4cac81SBjoern A. Zeeb 23994a67f1dfSBjoern A. Zeeb hw = LHW_TO_HW(lhw); 24004a67f1dfSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 24014a67f1dfSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 24024a67f1dfSBjoern A. Zeeb 24036b4cac81SBjoern A. Zeeb /* Configure tx queues (conf_tx) & send BSS_CHANGED_QOS. */ 24046b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 24056b4cac81SBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 24066b4cac81SBjoern A. Zeeb struct wmeParams *wmep; 24076b4cac81SBjoern A. Zeeb 24086b4cac81SBjoern A. Zeeb wmep = &wmeparr[ac]; 24096b4cac81SBjoern A. Zeeb bzero(&txqp, sizeof(txqp)); 24106b4cac81SBjoern A. Zeeb txqp.cw_min = wmep->wmep_logcwmin; 24116b4cac81SBjoern A. Zeeb txqp.cw_max = wmep->wmep_logcwmax; 24126b4cac81SBjoern A. Zeeb txqp.txop = wmep->wmep_txopLimit; 24136b4cac81SBjoern A. Zeeb txqp.aifs = wmep->wmep_aifsn; 241468541546SBjoern A. Zeeb error = lkpi_80211_mo_conf_tx(hw, vif, /* link_id */0, ac, &txqp); 24156b4cac81SBjoern A. Zeeb if (error != 0) 24163f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: conf_tx ac %u failed %d\n", 24176b4cac81SBjoern A. Zeeb __func__, ac, error); 24186b4cac81SBjoern A. Zeeb } 24196b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 24206b4cac81SBjoern A. Zeeb changed = BSS_CHANGED_QOS; 24214a67f1dfSBjoern A. Zeeb if (!planned) 24226b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 24234a67f1dfSBjoern A. Zeeb 24244a67f1dfSBjoern A. Zeeb return (changed); 24254a67f1dfSBjoern A. Zeeb } 24266b4cac81SBjoern A. Zeeb #endif 24276b4cac81SBjoern A. Zeeb 24284a67f1dfSBjoern A. Zeeb static int 24294a67f1dfSBjoern A. Zeeb lkpi_ic_wme_update(struct ieee80211com *ic) 24304a67f1dfSBjoern A. Zeeb { 24314a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 24324a67f1dfSBjoern A. Zeeb struct ieee80211vap *vap; 24334a67f1dfSBjoern A. Zeeb struct lkpi_hw *lhw; 24344a67f1dfSBjoern A. Zeeb 24354a67f1dfSBjoern A. Zeeb IMPROVE("Use the per-VAP callback in net80211."); 24364a67f1dfSBjoern A. Zeeb vap = TAILQ_FIRST(&ic->ic_vaps); 24374a67f1dfSBjoern A. Zeeb if (vap == NULL) 24386b4cac81SBjoern A. Zeeb return (0); 24394a67f1dfSBjoern A. Zeeb 24404a67f1dfSBjoern A. Zeeb lhw = ic->ic_softc; 24414a67f1dfSBjoern A. Zeeb 24424a67f1dfSBjoern A. Zeeb lkpi_wme_update(lhw, vap, false); 24434a67f1dfSBjoern A. Zeeb #endif 24444a67f1dfSBjoern A. Zeeb return (0); /* unused */ 24456b4cac81SBjoern A. Zeeb } 24466b4cac81SBjoern A. Zeeb 24476b4cac81SBjoern A. Zeeb static struct ieee80211vap * 24486b4cac81SBjoern A. Zeeb lkpi_ic_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], 24496b4cac81SBjoern A. Zeeb int unit, enum ieee80211_opmode opmode, int flags, 24506b4cac81SBjoern A. Zeeb const uint8_t bssid[IEEE80211_ADDR_LEN], 24516b4cac81SBjoern A. Zeeb const uint8_t mac[IEEE80211_ADDR_LEN]) 24526b4cac81SBjoern A. Zeeb { 24536b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 24546b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 24556b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 24566b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 24576b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 2458a6042e17SBjoern A. Zeeb struct ieee80211_tx_queue_params txqp; 24596b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 24606b4cac81SBjoern A. Zeeb size_t len; 2461e3a0b120SBjoern A. Zeeb int error, i; 2462a6042e17SBjoern A. Zeeb uint16_t ac; 24636b4cac81SBjoern A. Zeeb 24646b4cac81SBjoern A. Zeeb if (!TAILQ_EMPTY(&ic->ic_vaps)) /* 1 so far. Add <n> once this works. */ 24656b4cac81SBjoern A. Zeeb return (NULL); 24666b4cac81SBjoern A. Zeeb 24676b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 24686b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 24696b4cac81SBjoern A. Zeeb 24706b4cac81SBjoern A. Zeeb len = sizeof(*lvif); 24716b4cac81SBjoern A. Zeeb len += hw->vif_data_size; /* vif->drv_priv */ 24726b4cac81SBjoern A. Zeeb 24736b4cac81SBjoern A. Zeeb lvif = malloc(len, M_80211_VAP, M_WAITOK | M_ZERO); 24746b4cac81SBjoern A. Zeeb mtx_init(&lvif->mtx, "lvif", NULL, MTX_DEF); 24756b4cac81SBjoern A. Zeeb TAILQ_INIT(&lvif->lsta_head); 24766b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 24776b4cac81SBjoern A. Zeeb 24786b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 24796b4cac81SBjoern A. Zeeb memcpy(vif->addr, mac, IEEE80211_ADDR_LEN); 24806b4cac81SBjoern A. Zeeb vif->p2p = false; 24816b4cac81SBjoern A. Zeeb vif->probe_req_reg = false; 24826b4cac81SBjoern A. Zeeb vif->type = lkpi_opmode_to_vif_type(opmode); 24836b4cac81SBjoern A. Zeeb lvif->wdev.iftype = vif->type; 24846b4cac81SBjoern A. Zeeb /* Need to fill in other fields as well. */ 24856b4cac81SBjoern A. Zeeb IMPROVE(); 24866b4cac81SBjoern A. Zeeb 24876b4cac81SBjoern A. Zeeb /* XXX-BZ hardcoded for now! */ 24886b4cac81SBjoern A. Zeeb #if 1 24896b4cac81SBjoern A. Zeeb vif->chanctx_conf = NULL; 2490adff403fSBjoern A. Zeeb vif->bss_conf.vif = vif; 24916ffb7bd4SBjoern A. Zeeb /* vap->iv_myaddr is not set until net80211::vap_setup or vap_attach. */ 24926ffb7bd4SBjoern A. Zeeb IEEE80211_ADDR_COPY(vif->bss_conf.addr, mac); 24936ffb7bd4SBjoern A. Zeeb vif->bss_conf.link_id = 0; /* Non-MLO operation. */ 24946b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.width = NL80211_CHAN_WIDTH_20_NOHT; 24956b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble = false; /* vap->iv_flags IEEE80211_F_SHPREAMBLE */ 24966b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot = false; /* vap->iv_flags IEEE80211_F_SHSLOT */ 24976b4cac81SBjoern A. Zeeb vif->bss_conf.qos = false; 24986b4cac81SBjoern A. Zeeb vif->bss_conf.use_cts_prot = false; /* vap->iv_protmode */ 24996b4cac81SBjoern A. Zeeb vif->bss_conf.ht_operation_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONE; 2500616e1330SBjoern A. Zeeb vif->cfg.aid = 0; 2501616e1330SBjoern A. Zeeb vif->cfg.assoc = false; 2502616e1330SBjoern A. Zeeb vif->cfg.idle = true; 2503616e1330SBjoern A. Zeeb vif->cfg.ps = false; 25046ffb7bd4SBjoern A. Zeeb IMPROVE("Check other fields and then figure out whats is left elsewhere of them"); 2505caaa79c3SBjoern A. Zeeb /* 2506caaa79c3SBjoern A. Zeeb * We need to initialize it to something as the bss_info_changed call 2507caaa79c3SBjoern A. Zeeb * will try to copy from it in iwlwifi and NULL is a panic. 2508caaa79c3SBjoern A. Zeeb * We will set the proper one in scan_to_auth() before being assoc. 2509caaa79c3SBjoern A. Zeeb */ 25106ffb7bd4SBjoern A. Zeeb vif->bss_conf.bssid = ieee80211broadcastaddr; 25116b4cac81SBjoern A. Zeeb #endif 25126b4cac81SBjoern A. Zeeb #if 0 25136b4cac81SBjoern A. Zeeb vif->bss_conf.dtim_period = 0; /* IEEE80211_DTIM_DEFAULT ; must stay 0. */ 25146b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(vif->bss_conf.bssid, bssid); 25156b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = ic->ic_bintval; 25166b4cac81SBjoern A. Zeeb /* iwlwifi bug. */ 25176b4cac81SBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16) 25186b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = 16; 25196b4cac81SBjoern A. Zeeb #endif 2520e3a0b120SBjoern A. Zeeb 25216ffb7bd4SBjoern A. Zeeb /* Link Config */ 25226ffb7bd4SBjoern A. Zeeb vif->link_conf[0] = &vif->bss_conf; 25236ffb7bd4SBjoern A. Zeeb for (i = 0; i < nitems(vif->link_conf); i++) { 25246ffb7bd4SBjoern A. Zeeb IMPROVE("more than 1 link one day"); 25256ffb7bd4SBjoern A. Zeeb } 25266ffb7bd4SBjoern A. Zeeb 2527e3a0b120SBjoern A. Zeeb /* Setup queue defaults; driver may override in (*add_interface). */ 2528e3a0b120SBjoern A. Zeeb for (i = 0; i < IEEE80211_NUM_ACS; i++) { 2529e3a0b120SBjoern A. Zeeb if (ieee80211_hw_check(hw, QUEUE_CONTROL)) 2530e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = IEEE80211_INVAL_HW_QUEUE; 2531e3a0b120SBjoern A. Zeeb else if (hw->queues >= IEEE80211_NUM_ACS) 2532e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = i; 2533e3a0b120SBjoern A. Zeeb else 2534e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = 0; 25350cbcfa19SBjoern A. Zeeb 25360cbcfa19SBjoern A. Zeeb /* Initialize the queue to running. Stopped? */ 25370cbcfa19SBjoern A. Zeeb lvif->hw_queue_stopped[i] = false; 2538e3a0b120SBjoern A. Zeeb } 2539e3a0b120SBjoern A. Zeeb vif->cab_queue = IEEE80211_INVAL_HW_QUEUE; 2540e3a0b120SBjoern A. Zeeb 25416b4cac81SBjoern A. Zeeb IMPROVE(); 25426b4cac81SBjoern A. Zeeb 25436b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_start(hw); 25446b4cac81SBjoern A. Zeeb if (error != 0) { 25453f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: failed to start hw: %d\n", __func__, error); 25466b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 25476b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 25486b4cac81SBjoern A. Zeeb return (NULL); 25496b4cac81SBjoern A. Zeeb } 25506b4cac81SBjoern A. Zeeb 25516b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_add_interface(hw, vif); 25526b4cac81SBjoern A. Zeeb if (error != 0) { 25536b4cac81SBjoern A. Zeeb IMPROVE(); /* XXX-BZ mo_stop()? */ 25543f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: failed to add interface: %d\n", __func__, error); 25556b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 25566b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 25576b4cac81SBjoern A. Zeeb return (NULL); 25586b4cac81SBjoern A. Zeeb } 25596b4cac81SBjoern A. Zeeb 25608891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 25616b4cac81SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lhw->lvif_head, lvif, lvif_entry); 25628891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 25636b4cac81SBjoern A. Zeeb 25646b4cac81SBjoern A. Zeeb /* Set bss_info. */ 25656b4cac81SBjoern A. Zeeb changed = 0; 25666b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 25676b4cac81SBjoern A. Zeeb 2568a6042e17SBjoern A. Zeeb /* Configure tx queues (conf_tx), default WME & send BSS_CHANGED_QOS. */ 2569a6042e17SBjoern A. Zeeb IMPROVE("Hardcoded values; to fix see 802.11-2016, 9.4.2.29 EDCA Parameter Set element"); 2570a6042e17SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 2571a6042e17SBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 2572a6042e17SBjoern A. Zeeb 2573a6042e17SBjoern A. Zeeb bzero(&txqp, sizeof(txqp)); 2574a6042e17SBjoern A. Zeeb txqp.cw_min = 15; 2575a6042e17SBjoern A. Zeeb txqp.cw_max = 1023; 2576a6042e17SBjoern A. Zeeb txqp.txop = 0; 2577a6042e17SBjoern A. Zeeb txqp.aifs = 2; 2578a6042e17SBjoern A. Zeeb error = lkpi_80211_mo_conf_tx(hw, vif, /* link_id */0, ac, &txqp); 2579a6042e17SBjoern A. Zeeb if (error != 0) 2580a6042e17SBjoern A. Zeeb ic_printf(ic, "%s: conf_tx ac %u failed %d\n", 2581a6042e17SBjoern A. Zeeb __func__, ac, error); 2582a6042e17SBjoern A. Zeeb } 2583a6042e17SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 2584a6042e17SBjoern A. Zeeb changed = BSS_CHANGED_QOS; 2585a6042e17SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 25866b4cac81SBjoern A. Zeeb 25876b4cac81SBjoern A. Zeeb /* Force MC init. */ 25886b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(ic, true); 25896b4cac81SBjoern A. Zeeb 25906b4cac81SBjoern A. Zeeb IMPROVE(); 25916b4cac81SBjoern A. Zeeb 25926b4cac81SBjoern A. Zeeb ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid); 25936b4cac81SBjoern A. Zeeb 25946b4cac81SBjoern A. Zeeb /* Override with LinuxKPI method so we can drive mac80211/cfg80211. */ 25956b4cac81SBjoern A. Zeeb lvif->iv_newstate = vap->iv_newstate; 25966b4cac81SBjoern A. Zeeb vap->iv_newstate = lkpi_iv_newstate; 2597d9f59799SBjoern A. Zeeb lvif->iv_update_bss = vap->iv_update_bss; 2598d9f59799SBjoern A. Zeeb vap->iv_update_bss = lkpi_iv_update_bss; 25996b4cac81SBjoern A. Zeeb 26006b4cac81SBjoern A. Zeeb /* Key management. */ 26016b4cac81SBjoern A. Zeeb if (lhw->ops->set_key != NULL) { 2602b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 26036b4cac81SBjoern A. Zeeb vap->iv_key_set = lkpi_iv_key_set; 26046b4cac81SBjoern A. Zeeb vap->iv_key_delete = lkpi_iv_key_delete; 26056b4cac81SBjoern A. Zeeb #endif 26066b4cac81SBjoern A. Zeeb } 26076b4cac81SBjoern A. Zeeb 26089fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 26099fb91463SBjoern A. Zeeb /* Stay with the iv_ampdu_rxmax,limit / iv_ampdu_density defaults until later. */ 26109fb91463SBjoern A. Zeeb #endif 26119fb91463SBjoern A. Zeeb 26126b4cac81SBjoern A. Zeeb ieee80211_ratectl_init(vap); 26136b4cac81SBjoern A. Zeeb 26146b4cac81SBjoern A. Zeeb /* Complete setup. */ 26156b4cac81SBjoern A. Zeeb ieee80211_vap_attach(vap, ieee80211_media_change, 26166b4cac81SBjoern A. Zeeb ieee80211_media_status, mac); 26176b4cac81SBjoern A. Zeeb 26186b4cac81SBjoern A. Zeeb if (hw->max_listen_interval == 0) 26196b4cac81SBjoern A. Zeeb hw->max_listen_interval = 7 * (ic->ic_lintval / ic->ic_bintval); 26206b4cac81SBjoern A. Zeeb hw->conf.listen_interval = hw->max_listen_interval; 26216b4cac81SBjoern A. Zeeb ic->ic_set_channel(ic); 26226b4cac81SBjoern A. Zeeb 26236b4cac81SBjoern A. Zeeb /* XXX-BZ do we need to be able to update these? */ 26246b4cac81SBjoern A. Zeeb hw->wiphy->frag_threshold = vap->iv_fragthreshold; 26256b4cac81SBjoern A. Zeeb lkpi_80211_mo_set_frag_threshold(hw, vap->iv_fragthreshold); 26266b4cac81SBjoern A. Zeeb hw->wiphy->rts_threshold = vap->iv_rtsthreshold; 26276b4cac81SBjoern A. Zeeb lkpi_80211_mo_set_rts_threshold(hw, vap->iv_rtsthreshold); 26286b4cac81SBjoern A. Zeeb /* any others? */ 26296b4cac81SBjoern A. Zeeb IMPROVE(); 26306b4cac81SBjoern A. Zeeb 26316b4cac81SBjoern A. Zeeb return (vap); 26326b4cac81SBjoern A. Zeeb } 26336b4cac81SBjoern A. Zeeb 26344b0af114SBjoern A. Zeeb void 26354b0af114SBjoern A. Zeeb linuxkpi_ieee80211_unregister_hw(struct ieee80211_hw *hw) 26364b0af114SBjoern A. Zeeb { 26374b0af114SBjoern A. Zeeb 26384b0af114SBjoern A. Zeeb wiphy_unregister(hw->wiphy); 26394b0af114SBjoern A. Zeeb linuxkpi_ieee80211_ifdetach(hw); 26404b0af114SBjoern A. Zeeb 26414b0af114SBjoern A. Zeeb IMPROVE(); 26424b0af114SBjoern A. Zeeb } 26434b0af114SBjoern A. Zeeb 26444b0af114SBjoern A. Zeeb void 26454b0af114SBjoern A. Zeeb linuxkpi_ieee80211_restart_hw(struct ieee80211_hw *hw) 26464b0af114SBjoern A. Zeeb { 26474b0af114SBjoern A. Zeeb 26484b0af114SBjoern A. Zeeb TODO(); 26494b0af114SBjoern A. Zeeb } 26504b0af114SBjoern A. Zeeb 26516b4cac81SBjoern A. Zeeb static void 26526b4cac81SBjoern A. Zeeb lkpi_ic_vap_delete(struct ieee80211vap *vap) 26536b4cac81SBjoern A. Zeeb { 26546b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 26556b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 26566b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 26576b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 26586b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 26596b4cac81SBjoern A. Zeeb 26606b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 26616b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 26626b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 26636b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 26646b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 26656b4cac81SBjoern A. Zeeb 26668891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 26676b4cac81SBjoern A. Zeeb TAILQ_REMOVE(&lhw->lvif_head, lvif, lvif_entry); 26688891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 26696b4cac81SBjoern A. Zeeb 26706b4cac81SBjoern A. Zeeb ieee80211_ratectl_deinit(vap); 26716b4cac81SBjoern A. Zeeb ieee80211_vap_detach(vap); 2672dbf76919SBjoern A. Zeeb 2673dbf76919SBjoern A. Zeeb IMPROVE("clear up other bits in this state"); 2674dbf76919SBjoern A. Zeeb 2675dbf76919SBjoern A. Zeeb lkpi_80211_mo_remove_interface(hw, vif); 2676dbf76919SBjoern A. Zeeb 26776c38c6b1SBjoern A. Zeeb /* Single VAP, so we can do this here. */ 26786c38c6b1SBjoern A. Zeeb lkpi_80211_mo_stop(hw); 26796c38c6b1SBjoern A. Zeeb 26806b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 26816b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 26826b4cac81SBjoern A. Zeeb } 26836b4cac81SBjoern A. Zeeb 26846b4cac81SBjoern A. Zeeb static void 26856b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast(struct ieee80211com *ic) 26866b4cac81SBjoern A. Zeeb { 26876b4cac81SBjoern A. Zeeb 26886b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(ic, false); 26896b4cac81SBjoern A. Zeeb TRACEOK(); 26906b4cac81SBjoern A. Zeeb } 26916b4cac81SBjoern A. Zeeb 26926b4cac81SBjoern A. Zeeb static void 26936b4cac81SBjoern A. Zeeb lkpi_ic_update_promisc(struct ieee80211com *ic) 26946b4cac81SBjoern A. Zeeb { 26956b4cac81SBjoern A. Zeeb 26966b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 26976b4cac81SBjoern A. Zeeb } 26986b4cac81SBjoern A. Zeeb 26996b4cac81SBjoern A. Zeeb static void 27006b4cac81SBjoern A. Zeeb lkpi_ic_update_chw(struct ieee80211com *ic) 27016b4cac81SBjoern A. Zeeb { 27026b4cac81SBjoern A. Zeeb 27036b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 27046b4cac81SBjoern A. Zeeb } 27056b4cac81SBjoern A. Zeeb 27066b4cac81SBjoern A. Zeeb /* Start / stop device. */ 27076b4cac81SBjoern A. Zeeb static void 27086b4cac81SBjoern A. Zeeb lkpi_ic_parent(struct ieee80211com *ic) 27096b4cac81SBjoern A. Zeeb { 27106b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 27118d58a057SBjoern A. Zeeb #ifdef HW_START_STOP 27126b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 27136b4cac81SBjoern A. Zeeb int error; 27148d58a057SBjoern A. Zeeb #endif 27156b4cac81SBjoern A. Zeeb bool start_all; 27166b4cac81SBjoern A. Zeeb 27176b4cac81SBjoern A. Zeeb IMPROVE(); 27186b4cac81SBjoern A. Zeeb 27196b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 27208d58a057SBjoern A. Zeeb #ifdef HW_START_STOP 27216b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 27228d58a057SBjoern A. Zeeb #endif 27236b4cac81SBjoern A. Zeeb start_all = false; 27246b4cac81SBjoern A. Zeeb 27258ac540d3SBjoern A. Zeeb /* IEEE80211_UNLOCK(ic); */ 27268ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 27276b4cac81SBjoern A. Zeeb if (ic->ic_nrunning > 0) { 27288d58a057SBjoern A. Zeeb #ifdef HW_START_STOP 27296b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_start(hw); 27306b4cac81SBjoern A. Zeeb if (error == 0) 27318d58a057SBjoern A. Zeeb #endif 27326b4cac81SBjoern A. Zeeb start_all = true; 27336b4cac81SBjoern A. Zeeb } else { 27348d58a057SBjoern A. Zeeb #ifdef HW_START_STOP 27356b4cac81SBjoern A. Zeeb lkpi_80211_mo_stop(hw); 27368d58a057SBjoern A. Zeeb #endif 27376b4cac81SBjoern A. Zeeb } 27388ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 27398ac540d3SBjoern A. Zeeb /* IEEE80211_LOCK(ic); */ 27406b4cac81SBjoern A. Zeeb 27416b4cac81SBjoern A. Zeeb if (start_all) 27426b4cac81SBjoern A. Zeeb ieee80211_start_all(ic); 27436b4cac81SBjoern A. Zeeb } 27446b4cac81SBjoern A. Zeeb 27456b4cac81SBjoern A. Zeeb bool 27466b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_is_ie_id_in_ie_buf(const u8 ie, const u8 *ie_ids, 27476b4cac81SBjoern A. Zeeb size_t ie_ids_len) 27486b4cac81SBjoern A. Zeeb { 27496b4cac81SBjoern A. Zeeb int i; 27506b4cac81SBjoern A. Zeeb 27516b4cac81SBjoern A. Zeeb for (i = 0; i < ie_ids_len; i++) { 27526b4cac81SBjoern A. Zeeb if (ie == *ie_ids) 27536b4cac81SBjoern A. Zeeb return (true); 27546b4cac81SBjoern A. Zeeb } 27556b4cac81SBjoern A. Zeeb 27566b4cac81SBjoern A. Zeeb return (false); 27576b4cac81SBjoern A. Zeeb } 27586b4cac81SBjoern A. Zeeb 27596b4cac81SBjoern A. Zeeb /* Return true if skipped; false if error. */ 27606b4cac81SBjoern A. Zeeb bool 27616b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ie_advance(size_t *xp, const u8 *ies, size_t ies_len) 27626b4cac81SBjoern A. Zeeb { 27636b4cac81SBjoern A. Zeeb size_t x; 27646b4cac81SBjoern A. Zeeb uint8_t l; 27656b4cac81SBjoern A. Zeeb 27666b4cac81SBjoern A. Zeeb x = *xp; 27676b4cac81SBjoern A. Zeeb 27686b4cac81SBjoern A. Zeeb KASSERT(x < ies_len, ("%s: x %zu ies_len %zu ies %p\n", 27696b4cac81SBjoern A. Zeeb __func__, x, ies_len, ies)); 27706b4cac81SBjoern A. Zeeb l = ies[x + 1]; 27716b4cac81SBjoern A. Zeeb x += 2 + l; 27726b4cac81SBjoern A. Zeeb 27736b4cac81SBjoern A. Zeeb if (x > ies_len) 27746b4cac81SBjoern A. Zeeb return (false); 27756b4cac81SBjoern A. Zeeb 27766b4cac81SBjoern A. Zeeb *xp = x; 27776b4cac81SBjoern A. Zeeb return (true); 27786b4cac81SBjoern A. Zeeb } 27796b4cac81SBjoern A. Zeeb 2780d9945d78SBjoern A. Zeeb static uint8_t * 2781d9945d78SBjoern A. Zeeb lkpi_scan_ies_add(uint8_t *p, struct ieee80211_scan_ies *scan_ies, 2782d9945d78SBjoern A. Zeeb uint32_t band_mask, struct ieee80211vap *vap, struct ieee80211_hw *hw) 27836b4cac81SBjoern A. Zeeb { 2784d9945d78SBjoern A. Zeeb struct ieee80211_supported_band *supband; 2785d9945d78SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 27863dd98026SBjoern A. Zeeb struct ieee80211com *ic; 2787d9945d78SBjoern A. Zeeb const struct ieee80211_channel *chan; 2788d9945d78SBjoern A. Zeeb const struct ieee80211_rateset *rs; 2789d9945d78SBjoern A. Zeeb uint8_t *pb; 2790d9945d78SBjoern A. Zeeb int band, i; 27916b4cac81SBjoern A. Zeeb 27923dd98026SBjoern A. Zeeb ic = vap->iv_ic; 2793d9945d78SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 2794d9945d78SBjoern A. Zeeb if ((band_mask & (1 << band)) == 0) 2795d9945d78SBjoern A. Zeeb continue; 2796d9945d78SBjoern A. Zeeb 2797d9945d78SBjoern A. Zeeb supband = hw->wiphy->bands[band]; 2798d9945d78SBjoern A. Zeeb /* 2799d9945d78SBjoern A. Zeeb * This should not happen; 2800d9945d78SBjoern A. Zeeb * band_mask is a bitmask of valid bands to scan on. 2801d9945d78SBjoern A. Zeeb */ 2802d9945d78SBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 2803d9945d78SBjoern A. Zeeb continue; 2804d9945d78SBjoern A. Zeeb 2805d9945d78SBjoern A. Zeeb /* Find a first channel to get the mode and rates from. */ 2806d9945d78SBjoern A. Zeeb channels = supband->channels; 2807d9945d78SBjoern A. Zeeb chan = NULL; 2808d9945d78SBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 2809d9945d78SBjoern A. Zeeb 2810d9945d78SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) 2811d9945d78SBjoern A. Zeeb continue; 2812d9945d78SBjoern A. Zeeb 28133dd98026SBjoern A. Zeeb chan = ieee80211_find_channel(ic, 2814d9945d78SBjoern A. Zeeb channels[i].center_freq, 0); 2815d9945d78SBjoern A. Zeeb if (chan != NULL) 2816d9945d78SBjoern A. Zeeb break; 2817d9945d78SBjoern A. Zeeb } 2818d9945d78SBjoern A. Zeeb 2819d9945d78SBjoern A. Zeeb /* This really should not happen. */ 2820d9945d78SBjoern A. Zeeb if (chan == NULL) 2821d9945d78SBjoern A. Zeeb continue; 2822d9945d78SBjoern A. Zeeb 2823d9945d78SBjoern A. Zeeb pb = p; 28243dd98026SBjoern A. Zeeb rs = ieee80211_get_suprates(ic, chan); /* calls chan2mode */ 2825d9945d78SBjoern A. Zeeb p = ieee80211_add_rates(p, rs); 2826d9945d78SBjoern A. Zeeb p = ieee80211_add_xrates(p, rs); 2827d9945d78SBjoern A. Zeeb 28283dd98026SBjoern A. Zeeb #if defined(LKPI_80211_HT) 28293dd98026SBjoern A. Zeeb if ((vap->iv_flags_ht & IEEE80211_FHT_HT) != 0) { 28303dd98026SBjoern A. Zeeb struct ieee80211_channel *c; 28313dd98026SBjoern A. Zeeb 28323dd98026SBjoern A. Zeeb c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan, 28333dd98026SBjoern A. Zeeb vap->iv_flags_ht); 28343dd98026SBjoern A. Zeeb p = ieee80211_add_htcap_ch(p, vap, c); 28353dd98026SBjoern A. Zeeb } 28363dd98026SBjoern A. Zeeb #endif 28373dd98026SBjoern A. Zeeb #if defined(LKPI_80211_VHT) 28383dd98026SBjoern A. Zeeb if ((vap->iv_vht_flags & IEEE80211_FVHT_VHT) != 0) { 28393dd98026SBjoern A. Zeeb struct ieee80211_channel *c; 28403dd98026SBjoern A. Zeeb 28413dd98026SBjoern A. Zeeb c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan, 28423dd98026SBjoern A. Zeeb vap->iv_flags_ht); 28433dd98026SBjoern A. Zeeb c = ieee80211_vht_adjust_channel(ic, c, 28443dd98026SBjoern A. Zeeb vap->iv_vht_flags); 28453dd98026SBjoern A. Zeeb p = ieee80211_add_vhtcap_ch(p, vap, c); 28463dd98026SBjoern A. Zeeb } 28473dd98026SBjoern A. Zeeb #endif 28483dd98026SBjoern A. Zeeb 2849d9945d78SBjoern A. Zeeb scan_ies->ies[band] = pb; 2850d9945d78SBjoern A. Zeeb scan_ies->len[band] = p - pb; 2851d9945d78SBjoern A. Zeeb } 2852d9945d78SBjoern A. Zeeb 2853d9945d78SBjoern A. Zeeb /* Add common_ies */ 2854d9945d78SBjoern A. Zeeb pb = p; 2855d9945d78SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WPA1) != 0 && 2856d9945d78SBjoern A. Zeeb vap->iv_wpa_ie != NULL) { 2857d9945d78SBjoern A. Zeeb memcpy(p, vap->iv_wpa_ie, 2 + vap->iv_wpa_ie[1]); 2858d9945d78SBjoern A. Zeeb p += 2 + vap->iv_wpa_ie[1]; 2859d9945d78SBjoern A. Zeeb } 2860d9945d78SBjoern A. Zeeb if (vap->iv_appie_probereq != NULL) { 2861d9945d78SBjoern A. Zeeb memcpy(p, vap->iv_appie_probereq->ie_data, 2862d9945d78SBjoern A. Zeeb vap->iv_appie_probereq->ie_len); 2863d9945d78SBjoern A. Zeeb p += vap->iv_appie_probereq->ie_len; 2864d9945d78SBjoern A. Zeeb } 2865d9945d78SBjoern A. Zeeb scan_ies->common_ies = pb; 2866d9945d78SBjoern A. Zeeb scan_ies->common_ie_len = p - pb; 2867d9945d78SBjoern A. Zeeb 2868d9945d78SBjoern A. Zeeb return (p); 28696b4cac81SBjoern A. Zeeb } 28706b4cac81SBjoern A. Zeeb 28716b4cac81SBjoern A. Zeeb static void 28726b4cac81SBjoern A. Zeeb lkpi_ic_scan_start(struct ieee80211com *ic) 28736b4cac81SBjoern A. Zeeb { 28746b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 28756b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 28766b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 28776b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 28786b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 28796b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 28806b4cac81SBjoern A. Zeeb int error; 28818ac540d3SBjoern A. Zeeb bool is_hw_scan; 28826b4cac81SBjoern A. Zeeb 28836b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 28848ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 2885a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) { 28866b4cac81SBjoern A. Zeeb /* A scan is still running. */ 28878ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 28886b4cac81SBjoern A. Zeeb return; 28896b4cac81SBjoern A. Zeeb } 28908ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 28918ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 28926b4cac81SBjoern A. Zeeb 28936b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 28946b4cac81SBjoern A. Zeeb vap = ss->ss_vap; 28956b4cac81SBjoern A. Zeeb if (vap->iv_state != IEEE80211_S_SCAN) { 2896d3ef7fb4SBjoern A. Zeeb IMPROVE("We need to be able to scan if not in S_SCAN"); 28976b4cac81SBjoern A. Zeeb return; 28986b4cac81SBjoern A. Zeeb } 28996b4cac81SBjoern A. Zeeb 29006b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 29018ac540d3SBjoern A. Zeeb if (!is_hw_scan) { 2902a486fbbdSBjoern A. Zeeb /* If hw_scan is cleared clear FEXT_SCAN_OFFLOAD too. */ 2903a486fbbdSBjoern A. Zeeb vap->iv_flags_ext &= ~IEEE80211_FEXT_SCAN_OFFLOAD; 2904d3ef7fb4SBjoern A. Zeeb sw_scan: 29056b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 29066b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 2907086be6a8SBjoern A. Zeeb 2908086be6a8SBjoern A. Zeeb if (vap->iv_state == IEEE80211_S_SCAN) 2909086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, false); 2910086be6a8SBjoern A. Zeeb 29116b4cac81SBjoern A. Zeeb lkpi_80211_mo_sw_scan_start(hw, vif, vif->addr); 29126b4cac81SBjoern A. Zeeb /* net80211::scan_start() handled PS for us. */ 29136b4cac81SBjoern A. Zeeb IMPROVE(); 29146b4cac81SBjoern A. Zeeb /* XXX Also means it is too late to flush queues? 29156b4cac81SBjoern A. Zeeb * need to check iv_sta_ps or overload? */ 29166b4cac81SBjoern A. Zeeb /* XXX want to adjust ss end time/ maxdwell? */ 29176b4cac81SBjoern A. Zeeb 29186b4cac81SBjoern A. Zeeb } else { 29196b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 29206b4cac81SBjoern A. Zeeb struct ieee80211_scan_request *hw_req; 29216b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *lc, **cpp; 29226b4cac81SBjoern A. Zeeb struct cfg80211_ssid *ssids; 29236b4cac81SBjoern A. Zeeb struct cfg80211_scan_6ghz_params *s6gp; 29246b4cac81SBjoern A. Zeeb size_t chan_len, nchan, ssids_len, s6ghzlen; 2925d9945d78SBjoern A. Zeeb int band, i, ssid_count, common_ie_len; 2926d9945d78SBjoern A. Zeeb uint32_t band_mask; 2927d9945d78SBjoern A. Zeeb uint8_t *ie, *ieend; 29283206587aSBjoern A. Zeeb bool running; 2929d9945d78SBjoern A. Zeeb 2930d9945d78SBjoern A. Zeeb ssid_count = min(ss->ss_nssid, hw->wiphy->max_scan_ssids); 2931d9945d78SBjoern A. Zeeb ssids_len = ssid_count * sizeof(*ssids); 29326b4cac81SBjoern A. Zeeb s6ghzlen = 0 * (sizeof(*s6gp)); /* XXX-BZ */ 29336b4cac81SBjoern A. Zeeb 2934d9945d78SBjoern A. Zeeb band_mask = 0; 29356b4cac81SBjoern A. Zeeb nchan = 0; 2936d9945d78SBjoern A. Zeeb for (i = ss->ss_next; i < ss->ss_last; i++) { 29376b4cac81SBjoern A. Zeeb nchan++; 2938d9945d78SBjoern A. Zeeb band = lkpi_net80211_chan_to_nl80211_band( 2939d9945d78SBjoern A. Zeeb ss->ss_chans[ss->ss_next + i]); 2940d9945d78SBjoern A. Zeeb band_mask |= (1 << band); 2941d9945d78SBjoern A. Zeeb } 29423206587aSBjoern A. Zeeb 29433206587aSBjoern A. Zeeb if (!ieee80211_hw_check(hw, SINGLE_SCAN_ON_ALL_BANDS)) { 29443206587aSBjoern A. Zeeb IMPROVE("individual band scans not yet supported, only scanning first band"); 29453206587aSBjoern A. Zeeb /* In theory net80211 should drive this. */ 29463206587aSBjoern A. Zeeb /* Probably we need to add local logic for now; 29473206587aSBjoern A. Zeeb * need to deal with scan_complete 29483206587aSBjoern A. Zeeb * and cancel_scan and keep local state. 29493206587aSBjoern A. Zeeb * Also cut the nchan down above. 29503206587aSBjoern A. Zeeb */ 29513206587aSBjoern A. Zeeb /* XXX-BZ ath10k does not set this but still does it? &$%^ */ 29523206587aSBjoern A. Zeeb } 29533206587aSBjoern A. Zeeb 29546b4cac81SBjoern A. Zeeb chan_len = nchan * (sizeof(lc) + sizeof(*lc)); 29556b4cac81SBjoern A. Zeeb 2956d9945d78SBjoern A. Zeeb common_ie_len = 0; 2957d9945d78SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WPA1) != 0 && 2958d9945d78SBjoern A. Zeeb vap->iv_wpa_ie != NULL) 2959d9945d78SBjoern A. Zeeb common_ie_len += vap->iv_wpa_ie[1]; 2960d9945d78SBjoern A. Zeeb if (vap->iv_appie_probereq != NULL) 2961d9945d78SBjoern A. Zeeb common_ie_len += vap->iv_appie_probereq->ie_len; 2962d9945d78SBjoern A. Zeeb 2963d9945d78SBjoern A. Zeeb /* We would love to check this at an earlier stage... */ 2964d9945d78SBjoern A. Zeeb if (common_ie_len > hw->wiphy->max_scan_ie_len) { 2965d9945d78SBjoern A. Zeeb ic_printf(ic, "WARNING: %s: common_ie_len %d > " 2966d9945d78SBjoern A. Zeeb "wiphy->max_scan_ie_len %d\n", __func__, 2967d9945d78SBjoern A. Zeeb common_ie_len, hw->wiphy->max_scan_ie_len); 2968d9945d78SBjoern A. Zeeb } 2969d9945d78SBjoern A. Zeeb 29703206587aSBjoern A. Zeeb hw_req = malloc(sizeof(*hw_req) + ssids_len + 2971d9945d78SBjoern A. Zeeb s6ghzlen + chan_len + lhw->supbands * lhw->scan_ie_len + 2972d9945d78SBjoern A. Zeeb common_ie_len, M_LKPI80211, M_WAITOK | M_ZERO); 29736b4cac81SBjoern A. Zeeb 29746b4cac81SBjoern A. Zeeb hw_req->req.flags = 0; /* XXX ??? */ 29756b4cac81SBjoern A. Zeeb /* hw_req->req.wdev */ 29766b4cac81SBjoern A. Zeeb hw_req->req.wiphy = hw->wiphy; 29776b4cac81SBjoern A. Zeeb hw_req->req.no_cck = false; /* XXX */ 29786b4cac81SBjoern A. Zeeb #if 0 29796b4cac81SBjoern A. Zeeb /* This seems to pessimise default scanning behaviour. */ 29806b4cac81SBjoern A. Zeeb hw_req->req.duration_mandatory = TICKS_2_USEC(ss->ss_mindwell); 29816b4cac81SBjoern A. Zeeb hw_req->req.duration = TICKS_2_USEC(ss->ss_maxdwell); 29826b4cac81SBjoern A. Zeeb #endif 29836b4cac81SBjoern A. Zeeb #ifdef __notyet__ 29846b4cac81SBjoern A. Zeeb hw_req->req.flags |= NL80211_SCAN_FLAG_RANDOM_ADDR; 29856b4cac81SBjoern A. Zeeb memcpy(hw_req->req.mac_addr, xxx, IEEE80211_ADDR_LEN); 29866b4cac81SBjoern A. Zeeb memset(hw_req->req.mac_addr_mask, 0xxx, IEEE80211_ADDR_LEN); 29876b4cac81SBjoern A. Zeeb #endif 2988e1e90be0SBjoern A. Zeeb eth_broadcast_addr(hw_req->req.bssid); 29896b4cac81SBjoern A. Zeeb 29906b4cac81SBjoern A. Zeeb hw_req->req.n_channels = nchan; 29916b4cac81SBjoern A. Zeeb cpp = (struct linuxkpi_ieee80211_channel **)(hw_req + 1); 29926b4cac81SBjoern A. Zeeb lc = (struct linuxkpi_ieee80211_channel *)(cpp + nchan); 29936b4cac81SBjoern A. Zeeb for (i = 0; i < nchan; i++) { 29946b4cac81SBjoern A. Zeeb *(cpp + i) = 29956b4cac81SBjoern A. Zeeb (struct linuxkpi_ieee80211_channel *)(lc + i); 29966b4cac81SBjoern A. Zeeb } 29976b4cac81SBjoern A. Zeeb for (i = 0; i < nchan; i++) { 29986b4cac81SBjoern A. Zeeb c = ss->ss_chans[ss->ss_next + i]; 29996b4cac81SBjoern A. Zeeb 30006b4cac81SBjoern A. Zeeb lc->hw_value = c->ic_ieee; 30013206587aSBjoern A. Zeeb lc->center_freq = c->ic_freq; /* XXX */ 30026b4cac81SBjoern A. Zeeb /* lc->flags */ 30036b4cac81SBjoern A. Zeeb lc->band = lkpi_net80211_chan_to_nl80211_band(c); 30046b4cac81SBjoern A. Zeeb lc->max_power = c->ic_maxpower; 30056b4cac81SBjoern A. Zeeb /* lc-> ... */ 30066b4cac81SBjoern A. Zeeb lc++; 30076b4cac81SBjoern A. Zeeb } 30086b4cac81SBjoern A. Zeeb 3009d9945d78SBjoern A. Zeeb hw_req->req.n_ssids = ssid_count; 30106b4cac81SBjoern A. Zeeb if (hw_req->req.n_ssids > 0) { 30116b4cac81SBjoern A. Zeeb ssids = (struct cfg80211_ssid *)lc; 30126b4cac81SBjoern A. Zeeb hw_req->req.ssids = ssids; 3013d9945d78SBjoern A. Zeeb for (i = 0; i < ssid_count; i++) { 30146b4cac81SBjoern A. Zeeb ssids->ssid_len = ss->ss_ssid[i].len; 30156b4cac81SBjoern A. Zeeb memcpy(ssids->ssid, ss->ss_ssid[i].ssid, 30166b4cac81SBjoern A. Zeeb ss->ss_ssid[i].len); 30176b4cac81SBjoern A. Zeeb ssids++; 30186b4cac81SBjoern A. Zeeb } 30196b4cac81SBjoern A. Zeeb s6gp = (struct cfg80211_scan_6ghz_params *)ssids; 30206b4cac81SBjoern A. Zeeb } else { 30216b4cac81SBjoern A. Zeeb s6gp = (struct cfg80211_scan_6ghz_params *)lc; 30226b4cac81SBjoern A. Zeeb } 30236b4cac81SBjoern A. Zeeb 30246b4cac81SBjoern A. Zeeb /* 6GHz one day. */ 30256b4cac81SBjoern A. Zeeb hw_req->req.n_6ghz_params = 0; 30266b4cac81SBjoern A. Zeeb hw_req->req.scan_6ghz_params = NULL; 30276b4cac81SBjoern A. Zeeb hw_req->req.scan_6ghz = false; /* Weird boolean; not what you think. */ 30286b4cac81SBjoern A. Zeeb /* s6gp->... */ 30296b4cac81SBjoern A. Zeeb 3030d9945d78SBjoern A. Zeeb ie = ieend = (uint8_t *)s6gp; 3031d9945d78SBjoern A. Zeeb /* Copy per-band IEs, copy common IEs */ 3032d9945d78SBjoern A. Zeeb ieend = lkpi_scan_ies_add(ie, &hw_req->ies, band_mask, vap, hw); 3033d9945d78SBjoern A. Zeeb hw_req->req.ie = ie; 3034d9945d78SBjoern A. Zeeb hw_req->req.ie_len = ieend - ie; 3035d9945d78SBjoern A. Zeeb 30366b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 30376b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 30383206587aSBjoern A. Zeeb 30393206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 30403206587aSBjoern A. Zeeb /* Re-check under lock. */ 30413206587aSBjoern A. Zeeb running = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0; 30423206587aSBjoern A. Zeeb if (!running) { 30433206587aSBjoern A. Zeeb KASSERT(lhw->hw_req == NULL, ("%s: ic %p lhw %p hw_req %p " 30443206587aSBjoern A. Zeeb "!= NULL\n", __func__, ic, lhw, lhw->hw_req)); 30453206587aSBjoern A. Zeeb 30463206587aSBjoern A. Zeeb lhw->scan_flags |= LKPI_LHW_SCAN_RUNNING; 30473206587aSBjoern A. Zeeb lhw->hw_req = hw_req; 30483206587aSBjoern A. Zeeb } 30493206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 30503206587aSBjoern A. Zeeb if (running) { 30513206587aSBjoern A. Zeeb free(hw_req, M_LKPI80211); 30523206587aSBjoern A. Zeeb return; 30533206587aSBjoern A. Zeeb } 30543206587aSBjoern A. Zeeb 30556b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_hw_scan(hw, vif, hw_req); 30566b4cac81SBjoern A. Zeeb if (error != 0) { 3057d9945d78SBjoern A. Zeeb ieee80211_cancel_scan(vap); 3058d9945d78SBjoern A. Zeeb 30593206587aSBjoern A. Zeeb /* 30603206587aSBjoern A. Zeeb * ieee80211_scan_completed must be called in either 30613206587aSBjoern A. Zeeb * case of error or none. So let the free happen there 30623206587aSBjoern A. Zeeb * and only there. 30633206587aSBjoern A. Zeeb * That would be fine in theory but in practice drivers 30643206587aSBjoern A. Zeeb * behave differently: 30653206587aSBjoern A. Zeeb * ath10k does not return hw_scan until after scan_complete 30663206587aSBjoern A. Zeeb * and can then still return an error. 30673206587aSBjoern A. Zeeb * rtw88 can return 1 or -EBUSY without scan_complete 30683206587aSBjoern A. Zeeb * iwlwifi can return various errors before scan starts 30693206587aSBjoern A. Zeeb * ... 30703206587aSBjoern A. Zeeb * So we cannot rely on that behaviour and have to check 30713206587aSBjoern A. Zeeb * and balance between both code paths. 30723206587aSBjoern A. Zeeb */ 30733206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 30743206587aSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) { 30753206587aSBjoern A. Zeeb free(lhw->hw_req, M_LKPI80211); 30766b4cac81SBjoern A. Zeeb lhw->hw_req = NULL; 30773206587aSBjoern A. Zeeb lhw->scan_flags &= ~LKPI_LHW_SCAN_RUNNING; 30783206587aSBjoern A. Zeeb } 30793206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 3080d3ef7fb4SBjoern A. Zeeb 3081d3ef7fb4SBjoern A. Zeeb /* 3082d3ef7fb4SBjoern A. Zeeb * XXX-SIGH magic number. 3083d3ef7fb4SBjoern A. Zeeb * rtw88 has a magic "return 1" if offloading scan is 3084d3ef7fb4SBjoern A. Zeeb * not possible. Fall back to sw scan in that case. 3085d3ef7fb4SBjoern A. Zeeb */ 3086196cfd0bSBjoern A. Zeeb if (error == 1) { 30878ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 3088a486fbbdSBjoern A. Zeeb lhw->scan_flags &= ~LKPI_LHW_SCAN_HW; 30898ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 30903206587aSBjoern A. Zeeb /* 30913206587aSBjoern A. Zeeb * XXX If we clear this now and later a driver 30923206587aSBjoern A. Zeeb * thinks it * can do a hw_scan again, we will 30933206587aSBjoern A. Zeeb * currently not re-enable it? 30943206587aSBjoern A. Zeeb */ 30953206587aSBjoern A. Zeeb vap->iv_flags_ext &= ~IEEE80211_FEXT_SCAN_OFFLOAD; 3096196cfd0bSBjoern A. Zeeb ieee80211_start_scan(vap, 3097196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_ACTIVE | 3098196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_NOPICK | 3099196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_ONCE, 3100196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_FOREVER, 3101196cfd0bSBjoern A. Zeeb ss->ss_mindwell ? ss->ss_mindwell : msecs_to_ticks(20), 3102196cfd0bSBjoern A. Zeeb ss->ss_maxdwell ? ss->ss_maxdwell : msecs_to_ticks(200), 3103196cfd0bSBjoern A. Zeeb vap->iv_des_nssid, vap->iv_des_ssid); 3104d3ef7fb4SBjoern A. Zeeb goto sw_scan; 3105196cfd0bSBjoern A. Zeeb } 3106d3ef7fb4SBjoern A. Zeeb 3107d3ef7fb4SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: hw_scan returned %d\n", 3108d3ef7fb4SBjoern A. Zeeb __func__, error); 31096b4cac81SBjoern A. Zeeb } 31106b4cac81SBjoern A. Zeeb } 31116b4cac81SBjoern A. Zeeb } 31126b4cac81SBjoern A. Zeeb 31136b4cac81SBjoern A. Zeeb static void 31146b4cac81SBjoern A. Zeeb lkpi_ic_scan_end(struct ieee80211com *ic) 31156b4cac81SBjoern A. Zeeb { 31166b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 31178ac540d3SBjoern A. Zeeb bool is_hw_scan; 31186b4cac81SBjoern A. Zeeb 31196b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 31208ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 3121a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) == 0) { 31228ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 31236b4cac81SBjoern A. Zeeb return; 31246b4cac81SBjoern A. Zeeb } 31258ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 31268ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 31276b4cac81SBjoern A. Zeeb 31288ac540d3SBjoern A. Zeeb if (!is_hw_scan) { 3129a486fbbdSBjoern A. Zeeb struct ieee80211_scan_state *ss; 3130a486fbbdSBjoern A. Zeeb struct ieee80211vap *vap; 31316b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 31326b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 31336b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 31346b4cac81SBjoern A. Zeeb 3135a486fbbdSBjoern A. Zeeb ss = ic->ic_scan; 3136a486fbbdSBjoern A. Zeeb vap = ss->ss_vap; 31376b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 31386b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 31396b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 3140a486fbbdSBjoern A. Zeeb 31416b4cac81SBjoern A. Zeeb lkpi_80211_mo_sw_scan_complete(hw, vif); 31426b4cac81SBjoern A. Zeeb 31436b4cac81SBjoern A. Zeeb /* Send PS to stop buffering if n80211 does not for us? */ 3144086be6a8SBjoern A. Zeeb 3145086be6a8SBjoern A. Zeeb if (vap->iv_state == IEEE80211_S_SCAN) 3146086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true); 31476b4cac81SBjoern A. Zeeb } 31486b4cac81SBjoern A. Zeeb } 31496b4cac81SBjoern A. Zeeb 31506b4cac81SBjoern A. Zeeb static void 3151a486fbbdSBjoern A. Zeeb lkpi_ic_scan_curchan(struct ieee80211_scan_state *ss, 3152a486fbbdSBjoern A. Zeeb unsigned long maxdwell) 3153a486fbbdSBjoern A. Zeeb { 3154a486fbbdSBjoern A. Zeeb struct lkpi_hw *lhw; 31558ac540d3SBjoern A. Zeeb bool is_hw_scan; 3156a486fbbdSBjoern A. Zeeb 3157a486fbbdSBjoern A. Zeeb lhw = ss->ss_ic->ic_softc; 31588ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 31598ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 31608ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 31618ac540d3SBjoern A. Zeeb if (!is_hw_scan) 3162a486fbbdSBjoern A. Zeeb lhw->ic_scan_curchan(ss, maxdwell); 3163a486fbbdSBjoern A. Zeeb } 3164a486fbbdSBjoern A. Zeeb 3165a486fbbdSBjoern A. Zeeb static void 3166a486fbbdSBjoern A. Zeeb lkpi_ic_scan_mindwell(struct ieee80211_scan_state *ss) 3167a486fbbdSBjoern A. Zeeb { 3168a486fbbdSBjoern A. Zeeb struct lkpi_hw *lhw; 31698ac540d3SBjoern A. Zeeb bool is_hw_scan; 3170a486fbbdSBjoern A. Zeeb 3171a486fbbdSBjoern A. Zeeb lhw = ss->ss_ic->ic_softc; 31728ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 31738ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 31748ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 31758ac540d3SBjoern A. Zeeb if (!is_hw_scan) 3176a486fbbdSBjoern A. Zeeb lhw->ic_scan_mindwell(ss); 3177a486fbbdSBjoern A. Zeeb } 3178a486fbbdSBjoern A. Zeeb 3179a486fbbdSBjoern A. Zeeb static void 31806b4cac81SBjoern A. Zeeb lkpi_ic_set_channel(struct ieee80211com *ic) 31816b4cac81SBjoern A. Zeeb { 31826b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 31836b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 3184b2cf3c21SBjoern A. Zeeb struct ieee80211_channel *c; 3185b2cf3c21SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 31866b4cac81SBjoern A. Zeeb int error; 31878ac540d3SBjoern A. Zeeb bool hw_scan_running; 31886b4cac81SBjoern A. Zeeb 31896b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 3190b2cf3c21SBjoern A. Zeeb 3191b2cf3c21SBjoern A. Zeeb /* If we do not support (*config)() save us the work. */ 3192b2cf3c21SBjoern A. Zeeb if (lhw->ops->config == NULL) 31936b4cac81SBjoern A. Zeeb return; 31946b4cac81SBjoern A. Zeeb 3195a486fbbdSBjoern A. Zeeb /* If we have a hw_scan running do not switch channels. */ 31968ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 31978ac540d3SBjoern A. Zeeb hw_scan_running = 31988ac540d3SBjoern A. Zeeb (lhw->scan_flags & (LKPI_LHW_SCAN_RUNNING|LKPI_LHW_SCAN_HW)) == 31998ac540d3SBjoern A. Zeeb (LKPI_LHW_SCAN_RUNNING|LKPI_LHW_SCAN_HW); 32008ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 32018ac540d3SBjoern A. Zeeb if (hw_scan_running) 3202a486fbbdSBjoern A. Zeeb return; 3203a486fbbdSBjoern A. Zeeb 3204b2cf3c21SBjoern A. Zeeb c = ic->ic_curchan; 3205b2cf3c21SBjoern A. Zeeb if (c == NULL || c == IEEE80211_CHAN_ANYC) { 32066b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: c %p ops->config %p\n", __func__, 32076b4cac81SBjoern A. Zeeb c, lhw->ops->config); 32086b4cac81SBjoern A. Zeeb return; 32096b4cac81SBjoern A. Zeeb } 32106b4cac81SBjoern A. Zeeb 32116b4cac81SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, c); 32126b4cac81SBjoern A. Zeeb if (chan == NULL) { 32136b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: c %p chan %p\n", __func__, 32146b4cac81SBjoern A. Zeeb c, chan); 32156b4cac81SBjoern A. Zeeb return; 32166b4cac81SBjoern A. Zeeb } 32176b4cac81SBjoern A. Zeeb 32186b4cac81SBjoern A. Zeeb /* XXX max power for scanning? */ 32196b4cac81SBjoern A. Zeeb IMPROVE(); 32206b4cac81SBjoern A. Zeeb 32216b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 32224a07abdeSBjoern A. Zeeb cfg80211_chandef_create(&hw->conf.chandef, chan, 32239fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 32249fb91463SBjoern A. Zeeb (ic->ic_htcaps & IEEE80211_HTC_HT) ? 0 : 32259fb91463SBjoern A. Zeeb #endif 32264a07abdeSBjoern A. Zeeb NL80211_CHAN_NO_HT); 32276b4cac81SBjoern A. Zeeb 32286b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_CHANNEL); 32296b4cac81SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) { 32306b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: config %#0x returned %d\n", 32316b4cac81SBjoern A. Zeeb __func__, IEEE80211_CONF_CHANGE_CHANNEL, error); 32326b4cac81SBjoern A. Zeeb /* XXX should we unroll to the previous chandef? */ 32336b4cac81SBjoern A. Zeeb IMPROVE(); 32346b4cac81SBjoern A. Zeeb } else { 32356b4cac81SBjoern A. Zeeb /* Update radiotap channels as well. */ 32366b4cac81SBjoern A. Zeeb lhw->rtap_tx.wt_chan_freq = htole16(c->ic_freq); 32376b4cac81SBjoern A. Zeeb lhw->rtap_tx.wt_chan_flags = htole16(c->ic_flags); 32386b4cac81SBjoern A. Zeeb lhw->rtap_rx.wr_chan_freq = htole16(c->ic_freq); 32396b4cac81SBjoern A. Zeeb lhw->rtap_rx.wr_chan_flags = htole16(c->ic_flags); 32406b4cac81SBjoern A. Zeeb } 32416b4cac81SBjoern A. Zeeb 32426b4cac81SBjoern A. Zeeb /* Currently PS is hard coded off! Not sure it belongs here. */ 32436b4cac81SBjoern A. Zeeb IMPROVE(); 32446b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, SUPPORTS_PS) && 32456b4cac81SBjoern A. Zeeb (hw->conf.flags & IEEE80211_CONF_PS) != 0) { 32466b4cac81SBjoern A. Zeeb hw->conf.flags &= ~IEEE80211_CONF_PS; 32476b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_PS); 32486b4cac81SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) 32496b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: config %#0x returned " 32506b4cac81SBjoern A. Zeeb "%d\n", __func__, IEEE80211_CONF_CHANGE_PS, 32516b4cac81SBjoern A. Zeeb error); 32526b4cac81SBjoern A. Zeeb } 32536b4cac81SBjoern A. Zeeb } 32546b4cac81SBjoern A. Zeeb 32556b4cac81SBjoern A. Zeeb static struct ieee80211_node * 32566b4cac81SBjoern A. Zeeb lkpi_ic_node_alloc(struct ieee80211vap *vap, 32576b4cac81SBjoern A. Zeeb const uint8_t mac[IEEE80211_ADDR_LEN]) 32586b4cac81SBjoern A. Zeeb { 32596b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 32606b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 32614f61ef8bSBjoern A. Zeeb struct ieee80211_node *ni; 32626b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 32636b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 32646b4cac81SBjoern A. Zeeb 32656b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 32666b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 32676b4cac81SBjoern A. Zeeb 32686b4cac81SBjoern A. Zeeb /* We keep allocations de-coupled so we can deal with the two worlds. */ 32694f61ef8bSBjoern A. Zeeb if (lhw->ic_node_alloc == NULL) 32704f61ef8bSBjoern A. Zeeb return (NULL); 32714f61ef8bSBjoern A. Zeeb 32726b4cac81SBjoern A. Zeeb ni = lhw->ic_node_alloc(vap, mac); 32736b4cac81SBjoern A. Zeeb if (ni == NULL) 32746b4cac81SBjoern A. Zeeb return (NULL); 32756b4cac81SBjoern A. Zeeb 32766b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 32774f61ef8bSBjoern A. Zeeb lsta = lkpi_lsta_alloc(vap, mac, hw, ni); 32786b4cac81SBjoern A. Zeeb if (lsta == NULL) { 32796b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL) 32806b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni); 32816b4cac81SBjoern A. Zeeb return (NULL); 32826b4cac81SBjoern A. Zeeb } 32836b4cac81SBjoern A. Zeeb 32846b4cac81SBjoern A. Zeeb return (ni); 32856b4cac81SBjoern A. Zeeb } 32866b4cac81SBjoern A. Zeeb 32876b4cac81SBjoern A. Zeeb static int 32886b4cac81SBjoern A. Zeeb lkpi_ic_node_init(struct ieee80211_node *ni) 32896b4cac81SBjoern A. Zeeb { 32906b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 32916b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 32926b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 32936b4cac81SBjoern A. Zeeb int error; 32946b4cac81SBjoern A. Zeeb 32956b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 32966b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 32976b4cac81SBjoern A. Zeeb 32986b4cac81SBjoern A. Zeeb if (lhw->ic_node_init != NULL) { 32996b4cac81SBjoern A. Zeeb error = lhw->ic_node_init(ni); 33006b4cac81SBjoern A. Zeeb if (error != 0) 33016b4cac81SBjoern A. Zeeb return (error); 33026b4cac81SBjoern A. Zeeb } 33036b4cac81SBjoern A. Zeeb 33046b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 33056b4cac81SBjoern A. Zeeb 33066b4cac81SBjoern A. Zeeb /* Now take the reference before linking it to the table. */ 33076b4cac81SBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 33086b4cac81SBjoern A. Zeeb 33096b4cac81SBjoern A. Zeeb /* XXX-BZ Sync other state over. */ 33106b4cac81SBjoern A. Zeeb IMPROVE(); 33116b4cac81SBjoern A. Zeeb 33126b4cac81SBjoern A. Zeeb return (0); 33136b4cac81SBjoern A. Zeeb } 33146b4cac81SBjoern A. Zeeb 33156b4cac81SBjoern A. Zeeb static void 33166b4cac81SBjoern A. Zeeb lkpi_ic_node_cleanup(struct ieee80211_node *ni) 33176b4cac81SBjoern A. Zeeb { 33186b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 33196b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 33206b4cac81SBjoern A. Zeeb 33216b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 33226b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 33236b4cac81SBjoern A. Zeeb 33246b4cac81SBjoern A. Zeeb /* XXX-BZ remove from driver, ... */ 33256b4cac81SBjoern A. Zeeb IMPROVE(); 33266b4cac81SBjoern A. Zeeb 33276b4cac81SBjoern A. Zeeb if (lhw->ic_node_cleanup != NULL) 33286b4cac81SBjoern A. Zeeb lhw->ic_node_cleanup(ni); 33296b4cac81SBjoern A. Zeeb } 33306b4cac81SBjoern A. Zeeb 33316b4cac81SBjoern A. Zeeb static void 33326b4cac81SBjoern A. Zeeb lkpi_ic_node_free(struct ieee80211_node *ni) 33336b4cac81SBjoern A. Zeeb { 33346b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 33356b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 33366b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 33376b4cac81SBjoern A. Zeeb 33386b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 33396b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 33406b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 3341d9f59799SBjoern A. Zeeb if (lsta == NULL) 3342d9f59799SBjoern A. Zeeb goto out; 33436b4cac81SBjoern A. Zeeb 33446b4cac81SBjoern A. Zeeb /* XXX-BZ free resources, ... */ 33456b4cac81SBjoern A. Zeeb IMPROVE(); 33466b4cac81SBjoern A. Zeeb 33476b4cac81SBjoern A. Zeeb /* Flush mbufq (make sure to release ni refs!). */ 33486b4cac81SBjoern A. Zeeb #ifdef __notyet__ 33496b4cac81SBjoern A. Zeeb KASSERT(mbufq_len(&lsta->txq) == 0, ("%s: lsta %p has txq len %d != 0\n", 33506b4cac81SBjoern A. Zeeb __func__, lsta, mbufq_len(&lsta->txq))); 33516b4cac81SBjoern A. Zeeb #endif 33526b4cac81SBjoern A. Zeeb /* Drain taskq. */ 33536b4cac81SBjoern A. Zeeb 33546b4cac81SBjoern A. Zeeb /* Drain sta->txq[] */ 33556b4cac81SBjoern A. Zeeb mtx_destroy(&lsta->txq_mtx); 33566b4cac81SBjoern A. Zeeb 33576b4cac81SBjoern A. Zeeb /* Remove lsta if added_to_drv. */ 3358e24e8103SBjoern A. Zeeb 33596b4cac81SBjoern A. Zeeb /* Remove lsta from vif */ 3360e24e8103SBjoern A. Zeeb /* Remove ref from lsta node... */ 3361d9f59799SBjoern A. Zeeb /* Free lsta. */ 3362e24e8103SBjoern A. Zeeb lkpi_lsta_remove(lsta, VAP_TO_LVIF(ni->ni_vap)); 3363d9f59799SBjoern A. Zeeb 3364d9f59799SBjoern A. Zeeb out: 33656b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL) 33666b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni); 33676b4cac81SBjoern A. Zeeb } 33686b4cac81SBjoern A. Zeeb 33696b4cac81SBjoern A. Zeeb static int 33706b4cac81SBjoern A. Zeeb lkpi_ic_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, 33716b4cac81SBjoern A. Zeeb const struct ieee80211_bpf_params *params __unused) 33726b4cac81SBjoern A. Zeeb { 33736b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 33746b4cac81SBjoern A. Zeeb 33756b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 33766b4cac81SBjoern A. Zeeb 33776b4cac81SBjoern A. Zeeb /* Queue the packet and enqueue the task to handle it. */ 33786b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_LOCK(lsta); 33796b4cac81SBjoern A. Zeeb mbufq_enqueue(&lsta->txq, m); 33806b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_UNLOCK(lsta); 33816b4cac81SBjoern A. Zeeb 33829d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 33839d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 33846b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p ni %p %6D mbuf_qlen %d\n", 33856b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, ni, ni->ni_macaddr, ":", 33866b4cac81SBjoern A. Zeeb mbufq_len(&lsta->txq)); 33879d9ba2b7SBjoern A. Zeeb #endif 33886b4cac81SBjoern A. Zeeb 33896b4cac81SBjoern A. Zeeb taskqueue_enqueue(taskqueue_thread, &lsta->txq_task); 33906b4cac81SBjoern A. Zeeb return (0); 33916b4cac81SBjoern A. Zeeb } 33926b4cac81SBjoern A. Zeeb 33936b4cac81SBjoern A. Zeeb static void 33946b4cac81SBjoern A. Zeeb lkpi_80211_txq_tx_one(struct lkpi_sta *lsta, struct mbuf *m) 33956b4cac81SBjoern A. Zeeb { 33966b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 3397b35f6cd0SBjoern A. Zeeb #ifndef LKPI_80211_HW_CRYPTO 33986b4cac81SBjoern A. Zeeb struct ieee80211_frame *wh; 3399b35f6cd0SBjoern A. Zeeb #endif 34006b4cac81SBjoern A. Zeeb struct ieee80211_key *k; 34016b4cac81SBjoern A. Zeeb struct sk_buff *skb; 34026b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 34036b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 34046b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 34056b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 34066b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 34076b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 34086b4cac81SBjoern A. Zeeb struct ieee80211_tx_control control; 34096b4cac81SBjoern A. Zeeb struct ieee80211_tx_info *info; 34106b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 3411e3a0b120SBjoern A. Zeeb struct ieee80211_hdr *hdr; 34126b4cac81SBjoern A. Zeeb void *buf; 3413e3a0b120SBjoern A. Zeeb uint8_t ac, tid; 34146b4cac81SBjoern A. Zeeb 34156b4cac81SBjoern A. Zeeb M_ASSERTPKTHDR(m); 34166b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 34179d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX_DUMP) 34186b4cac81SBjoern A. Zeeb hexdump(mtod(m, const void *), m->m_len, "RAW TX (plain) ", 0); 34196b4cac81SBjoern A. Zeeb #endif 34206b4cac81SBjoern A. Zeeb 34216b4cac81SBjoern A. Zeeb ni = lsta->ni; 3422b35f6cd0SBjoern A. Zeeb k = NULL; 3423b35f6cd0SBjoern A. Zeeb #ifndef LKPI_80211_HW_CRYPTO 34246b4cac81SBjoern A. Zeeb /* Encrypt the frame if need be; XXX-BZ info->control.hw_key. */ 34256b4cac81SBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame *); 34266b4cac81SBjoern A. Zeeb if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { 34276b4cac81SBjoern A. Zeeb /* Retrieve key for TX && do software encryption. */ 34286b4cac81SBjoern A. Zeeb k = ieee80211_crypto_encap(ni, m); 34296b4cac81SBjoern A. Zeeb if (k == NULL) { 34306b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 34316b4cac81SBjoern A. Zeeb m_freem(m); 34326b4cac81SBjoern A. Zeeb return; 34336b4cac81SBjoern A. Zeeb } 34346b4cac81SBjoern A. Zeeb } 34356b4cac81SBjoern A. Zeeb #endif 34366b4cac81SBjoern A. Zeeb 34376b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 34386b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 34396b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 34406b4cac81SBjoern A. Zeeb c = ni->ni_chan; 34416b4cac81SBjoern A. Zeeb 34426b4cac81SBjoern A. Zeeb if (ieee80211_radiotap_active_vap(ni->ni_vap)) { 34436b4cac81SBjoern A. Zeeb struct lkpi_radiotap_tx_hdr *rtap; 34446b4cac81SBjoern A. Zeeb 34456b4cac81SBjoern A. Zeeb rtap = &lhw->rtap_tx; 34466b4cac81SBjoern A. Zeeb rtap->wt_flags = 0; 34476b4cac81SBjoern A. Zeeb if (k != NULL) 34486b4cac81SBjoern A. Zeeb rtap->wt_flags |= IEEE80211_RADIOTAP_F_WEP; 34496b4cac81SBjoern A. Zeeb if (m->m_flags & M_FRAG) 34506b4cac81SBjoern A. Zeeb rtap->wt_flags |= IEEE80211_RADIOTAP_F_FRAG; 34516b4cac81SBjoern A. Zeeb IMPROVE(); 34526b4cac81SBjoern A. Zeeb rtap->wt_rate = 0; 34536b4cac81SBjoern A. Zeeb if (c != NULL && c != IEEE80211_CHAN_ANYC) { 34546b4cac81SBjoern A. Zeeb rtap->wt_chan_freq = htole16(c->ic_freq); 34556b4cac81SBjoern A. Zeeb rtap->wt_chan_flags = htole16(c->ic_flags); 34566b4cac81SBjoern A. Zeeb } 34576b4cac81SBjoern A. Zeeb 34586b4cac81SBjoern A. Zeeb ieee80211_radiotap_tx(ni->ni_vap, m); 34596b4cac81SBjoern A. Zeeb } 34606b4cac81SBjoern A. Zeeb 34616b4cac81SBjoern A. Zeeb /* 34626b4cac81SBjoern A. Zeeb * net80211 should handle hw->extra_tx_headroom. 34636b4cac81SBjoern A. Zeeb * Though for as long as we are copying we don't mind. 34643d09d310SBjoern A. Zeeb * XXX-BZ rtw88 asks for too much headroom for ipv6+tcp: 34653d09d310SBjoern A. Zeeb * https://lists.freebsd.org/archives/freebsd-transport/2022-February/000012.html 34666b4cac81SBjoern A. Zeeb */ 34676b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + m->m_pkthdr.len); 34686b4cac81SBjoern A. Zeeb if (skb == NULL) { 34693f0083c4SBjoern A. Zeeb ic_printf(ic, "ERROR %s: skb alloc failed\n", __func__); 34706b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 34716b4cac81SBjoern A. Zeeb m_freem(m); 34726b4cac81SBjoern A. Zeeb return; 34736b4cac81SBjoern A. Zeeb } 34746b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 34756b4cac81SBjoern A. Zeeb 34766b4cac81SBjoern A. Zeeb /* XXX-BZ we need a SKB version understanding mbuf. */ 34776b4cac81SBjoern A. Zeeb /* Save the mbuf for ieee80211_tx_complete(). */ 34786b4cac81SBjoern A. Zeeb skb->m_free_func = lkpi_ieee80211_free_skb_mbuf; 34796b4cac81SBjoern A. Zeeb skb->m = m; 34806b4cac81SBjoern A. Zeeb #if 0 34816b4cac81SBjoern A. Zeeb skb_put_data(skb, m->m_data, m->m_pkthdr.len); 34826b4cac81SBjoern A. Zeeb #else 34836b4cac81SBjoern A. Zeeb buf = skb_put(skb, m->m_pkthdr.len); 34846b4cac81SBjoern A. Zeeb m_copydata(m, 0, m->m_pkthdr.len, buf); 34856b4cac81SBjoern A. Zeeb #endif 34866b4cac81SBjoern A. Zeeb /* Save the ni. */ 34876b4cac81SBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = ni; 34886b4cac81SBjoern A. Zeeb 34896b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(ni->ni_vap); 34906b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 34916b4cac81SBjoern A. Zeeb 3492e3a0b120SBjoern A. Zeeb hdr = (void *)skb->data; 3493e3a0b120SBjoern A. Zeeb tid = linuxkpi_ieee80211_get_tid(hdr, true); 3494e3a0b120SBjoern A. Zeeb if (tid == IEEE80211_NONQOS_TID) { /* == IEEE80211_NUM_TIDS */ 3495e3a0b120SBjoern A. Zeeb skb->priority = 0; 3496e3a0b120SBjoern A. Zeeb ac = IEEE80211_AC_BE; 3497e3a0b120SBjoern A. Zeeb } else { 3498e3a0b120SBjoern A. Zeeb skb->priority = tid & IEEE80211_QOS_CTL_TID_MASK; 3499fb3c249eSBjoern A. Zeeb ac = ieee80211e_up_to_ac[tid & 7]; 3500e3a0b120SBjoern A. Zeeb } 35016b4cac81SBjoern A. Zeeb skb_set_queue_mapping(skb, ac); 35026b4cac81SBjoern A. Zeeb 35036b4cac81SBjoern A. Zeeb info = IEEE80211_SKB_CB(skb); 35046b4cac81SBjoern A. Zeeb info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; 35056b4cac81SBjoern A. Zeeb /* Slight delay; probably only happens on scanning so fine? */ 35066b4cac81SBjoern A. Zeeb if (c == NULL || c == IEEE80211_CHAN_ANYC) 35076b4cac81SBjoern A. Zeeb c = ic->ic_curchan; 35086b4cac81SBjoern A. Zeeb info->band = lkpi_net80211_chan_to_nl80211_band(c); 3509e3a0b120SBjoern A. Zeeb info->hw_queue = vif->hw_queue[ac]; 35106b4cac81SBjoern A. Zeeb if (m->m_flags & M_EAPOL) 35116b4cac81SBjoern A. Zeeb info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO; 35126b4cac81SBjoern A. Zeeb info->control.vif = vif; 35136b4cac81SBjoern A. Zeeb /* XXX-BZ info->control.rates */ 35149fb91463SBjoern A. Zeeb #ifdef __notyet__ 35159fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 35169fb91463SBjoern A. Zeeb info->control.rts_cts_rate_idx= 35179fb91463SBjoern A. Zeeb info->control.use_rts= /* RTS */ 35189fb91463SBjoern A. Zeeb info->control.use_cts_prot= /* RTS/CTS*/ 35199fb91463SBjoern A. Zeeb #endif 35209fb91463SBjoern A. Zeeb #endif 35216b4cac81SBjoern A. Zeeb 35226b4cac81SBjoern A. Zeeb lsta = lkpi_find_lsta_by_ni(lvif, ni); 35236b4cac81SBjoern A. Zeeb if (lsta != NULL) { 35246b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 3525b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 35266b4cac81SBjoern A. Zeeb info->control.hw_key = lsta->kc; 35276b4cac81SBjoern A. Zeeb #endif 35286b4cac81SBjoern A. Zeeb } else { 35296b4cac81SBjoern A. Zeeb sta = NULL; 35306b4cac81SBjoern A. Zeeb } 35316b4cac81SBjoern A. Zeeb 35326b4cac81SBjoern A. Zeeb IMPROVE(); 35336b4cac81SBjoern A. Zeeb 35346b4cac81SBjoern A. Zeeb if (sta != NULL) { 35356b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 35366b4cac81SBjoern A. Zeeb 3537e3a0b120SBjoern A. Zeeb ltxq = NULL; 3538e3a0b120SBjoern A. Zeeb if (!ieee80211_is_data_present(hdr->frame_control)) { 3539e3a0b120SBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_STATION && 3540e3a0b120SBjoern A. Zeeb lsta->added_to_drv && 3541e3a0b120SBjoern A. Zeeb sta->txq[IEEE80211_NUM_TIDS] != NULL) 3542d0d29110SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[IEEE80211_NUM_TIDS]); 3543e3a0b120SBjoern A. Zeeb } else if (lsta->added_to_drv && 3544e3a0b120SBjoern A. Zeeb sta->txq[skb->priority] != NULL) { 3545e3a0b120SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[skb->priority]); 3546e3a0b120SBjoern A. Zeeb } 3547e3a0b120SBjoern A. Zeeb if (ltxq == NULL) 3548d0d29110SBjoern A. Zeeb goto ops_tx; 3549e3a0b120SBjoern A. Zeeb 3550d0d29110SBjoern A. Zeeb KASSERT(ltxq != NULL, ("%s: lsta %p sta %p m %p skb %p " 3551d0d29110SBjoern A. Zeeb "ltxq %p != NULL\n", __func__, lsta, sta, m, skb, ltxq)); 3552d0d29110SBjoern A. Zeeb 3553*eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_LOCK(ltxq); 35546b4cac81SBjoern A. Zeeb skb_queue_tail(<xq->skbq, skb); 35559d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 35569d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 3557d0d29110SBjoern A. Zeeb printf("%s:%d mo_wake_tx_queue :: %d %u lsta %p sta %p " 3558d0d29110SBjoern A. Zeeb "ni %p %6D skb %p lxtq %p { qlen %u, ac %d tid %u } " 3559d0d29110SBjoern A. Zeeb "WAKE_TX_Q ac %d prio %u qmap %u\n", 3560fb6eaf74SBjoern A. Zeeb __func__, __LINE__, 3561d0d29110SBjoern A. Zeeb curthread->td_tid, (unsigned int)ticks, 3562d0d29110SBjoern A. Zeeb lsta, sta, ni, ni->ni_macaddr, ":", skb, ltxq, 3563d0d29110SBjoern A. Zeeb skb_queue_len(<xq->skbq), ltxq->txq.ac, 3564d0d29110SBjoern A. Zeeb ltxq->txq.tid, ac, skb->priority, skb->qmap); 35659d9ba2b7SBjoern A. Zeeb #endif 3566*eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_UNLOCK(ltxq); 3567d0d29110SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, <xq->txq); 35686b4cac81SBjoern A. Zeeb return; 35696b4cac81SBjoern A. Zeeb } 35706b4cac81SBjoern A. Zeeb 35716b4cac81SBjoern A. Zeeb ops_tx: 35729d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 35739d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 3574d0d29110SBjoern A. Zeeb printf("%s:%d mo_tx :: lsta %p sta %p ni %p %6D skb %p " 3575d0d29110SBjoern A. Zeeb "TX ac %d prio %u qmap %u\n", 35766b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, sta, ni, ni->ni_macaddr, ":", 35776b4cac81SBjoern A. Zeeb skb, ac, skb->priority, skb->qmap); 35789d9ba2b7SBjoern A. Zeeb #endif 35796b4cac81SBjoern A. Zeeb memset(&control, 0, sizeof(control)); 35806b4cac81SBjoern A. Zeeb control.sta = sta; 35816b4cac81SBjoern A. Zeeb 35826b4cac81SBjoern A. Zeeb lkpi_80211_mo_tx(hw, &control, skb); 35836b4cac81SBjoern A. Zeeb return; 35846b4cac81SBjoern A. Zeeb } 35856b4cac81SBjoern A. Zeeb 35866b4cac81SBjoern A. Zeeb static void 35876b4cac81SBjoern A. Zeeb lkpi_80211_txq_task(void *ctx, int pending) 35886b4cac81SBjoern A. Zeeb { 35896b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 35906b4cac81SBjoern A. Zeeb struct mbufq mq; 35916b4cac81SBjoern A. Zeeb struct mbuf *m; 35926b4cac81SBjoern A. Zeeb 35936b4cac81SBjoern A. Zeeb lsta = ctx; 35946b4cac81SBjoern A. Zeeb 35959d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 35969d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 35976b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p ni %p %6D pending %d mbuf_qlen %d\n", 35989d9ba2b7SBjoern A. Zeeb __func__, __LINE__, lsta, lsta->ni, lsta->ni->ni_macaddr, ":", 35996b4cac81SBjoern A. Zeeb pending, mbufq_len(&lsta->txq)); 36009d9ba2b7SBjoern A. Zeeb #endif 36016b4cac81SBjoern A. Zeeb 36026b4cac81SBjoern A. Zeeb mbufq_init(&mq, IFQ_MAXLEN); 36036b4cac81SBjoern A. Zeeb 36046b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_LOCK(lsta); 36056b4cac81SBjoern A. Zeeb mbufq_concat(&mq, &lsta->txq); 36066b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_UNLOCK(lsta); 36076b4cac81SBjoern A. Zeeb 36086b4cac81SBjoern A. Zeeb m = mbufq_dequeue(&mq); 36096b4cac81SBjoern A. Zeeb while (m != NULL) { 36106b4cac81SBjoern A. Zeeb lkpi_80211_txq_tx_one(lsta, m); 36116b4cac81SBjoern A. Zeeb m = mbufq_dequeue(&mq); 36126b4cac81SBjoern A. Zeeb } 36136b4cac81SBjoern A. Zeeb } 36146b4cac81SBjoern A. Zeeb 36156b4cac81SBjoern A. Zeeb static int 36166b4cac81SBjoern A. Zeeb lkpi_ic_transmit(struct ieee80211com *ic, struct mbuf *m) 36176b4cac81SBjoern A. Zeeb { 36186b4cac81SBjoern A. Zeeb 36196b4cac81SBjoern A. Zeeb /* XXX TODO */ 36206b4cac81SBjoern A. Zeeb IMPROVE(); 36216b4cac81SBjoern A. Zeeb 36226b4cac81SBjoern A. Zeeb /* Quick and dirty cheating hack. */ 36236b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 36246b4cac81SBjoern A. Zeeb 36256b4cac81SBjoern A. Zeeb ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; 36266b4cac81SBjoern A. Zeeb return (lkpi_ic_raw_xmit(ni, m, NULL)); 36276b4cac81SBjoern A. Zeeb } 36286b4cac81SBjoern A. Zeeb 36299fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 36309fb91463SBjoern A. Zeeb static int 36319fb91463SBjoern A. Zeeb lkpi_ic_recv_action(struct ieee80211_node *ni, const struct ieee80211_frame *wh, 36329fb91463SBjoern A. Zeeb const uint8_t *frm, const uint8_t *efrm) 36339fb91463SBjoern A. Zeeb { 36349fb91463SBjoern A. Zeeb struct ieee80211com *ic; 36359fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 36369fb91463SBjoern A. Zeeb 36379fb91463SBjoern A. Zeeb ic = ni->ni_ic; 36389fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 36399fb91463SBjoern A. Zeeb 36409fb91463SBjoern A. Zeeb IMPROVE_HT(); 36419fb91463SBjoern A. Zeeb 36429fb91463SBjoern A. Zeeb return (lhw->ic_recv_action(ni, wh, frm, efrm)); 36439fb91463SBjoern A. Zeeb } 36449fb91463SBjoern A. Zeeb 36459fb91463SBjoern A. Zeeb static int 36469fb91463SBjoern A. Zeeb lkpi_ic_send_action(struct ieee80211_node *ni, int category, int action, void *sa) 36479fb91463SBjoern A. Zeeb { 36489fb91463SBjoern A. Zeeb struct ieee80211com *ic; 36499fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 36509fb91463SBjoern A. Zeeb 36519fb91463SBjoern A. Zeeb ic = ni->ni_ic; 36529fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 36539fb91463SBjoern A. Zeeb 36549fb91463SBjoern A. Zeeb IMPROVE_HT(); 36559fb91463SBjoern A. Zeeb 36569fb91463SBjoern A. Zeeb return (lhw->ic_send_action(ni, category, action, sa)); 36579fb91463SBjoern A. Zeeb } 36589fb91463SBjoern A. Zeeb 36599fb91463SBjoern A. Zeeb 36609fb91463SBjoern A. Zeeb static int 36619fb91463SBjoern A. Zeeb lkpi_ic_ampdu_enable(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap) 36629fb91463SBjoern A. Zeeb { 36639fb91463SBjoern A. Zeeb struct ieee80211com *ic; 36649fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 36659fb91463SBjoern A. Zeeb 36669fb91463SBjoern A. Zeeb ic = ni->ni_ic; 36679fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 36689fb91463SBjoern A. Zeeb 36699fb91463SBjoern A. Zeeb IMPROVE_HT(); 36709fb91463SBjoern A. Zeeb 36719fb91463SBjoern A. Zeeb return (lhw->ic_ampdu_enable(ni, tap)); 36729fb91463SBjoern A. Zeeb } 36739fb91463SBjoern A. Zeeb 36749fb91463SBjoern A. Zeeb static int 36759fb91463SBjoern A. Zeeb lkpi_ic_addba_request(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 36769fb91463SBjoern A. Zeeb int dialogtoken, int baparamset, int batimeout) 36779fb91463SBjoern A. Zeeb { 36789fb91463SBjoern A. Zeeb struct ieee80211com *ic; 36799fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 36809fb91463SBjoern A. Zeeb 36819fb91463SBjoern A. Zeeb ic = ni->ni_ic; 36829fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 36839fb91463SBjoern A. Zeeb 36849fb91463SBjoern A. Zeeb IMPROVE_HT(); 36859fb91463SBjoern A. Zeeb 36869fb91463SBjoern A. Zeeb return (lhw->ic_addba_request(ni, tap, dialogtoken, baparamset, batimeout)); 36879fb91463SBjoern A. Zeeb } 36889fb91463SBjoern A. Zeeb 36899fb91463SBjoern A. Zeeb static int 36909fb91463SBjoern A. Zeeb lkpi_ic_addba_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 36919fb91463SBjoern A. Zeeb int status, int baparamset, int batimeout) 36929fb91463SBjoern A. Zeeb { 36939fb91463SBjoern A. Zeeb struct ieee80211com *ic; 36949fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 36959fb91463SBjoern A. Zeeb 36969fb91463SBjoern A. Zeeb ic = ni->ni_ic; 36979fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 36989fb91463SBjoern A. Zeeb 36999fb91463SBjoern A. Zeeb IMPROVE_HT(); 37009fb91463SBjoern A. Zeeb 37019fb91463SBjoern A. Zeeb return (lhw->ic_addba_response(ni, tap, status, baparamset, batimeout)); 37029fb91463SBjoern A. Zeeb } 37039fb91463SBjoern A. Zeeb 37049fb91463SBjoern A. Zeeb static void 37059fb91463SBjoern A. Zeeb lkpi_ic_addba_stop(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap) 37069fb91463SBjoern A. Zeeb { 37079fb91463SBjoern A. Zeeb struct ieee80211com *ic; 37089fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 37099fb91463SBjoern A. Zeeb 37109fb91463SBjoern A. Zeeb ic = ni->ni_ic; 37119fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 37129fb91463SBjoern A. Zeeb 37139fb91463SBjoern A. Zeeb IMPROVE_HT(); 37149fb91463SBjoern A. Zeeb 37159fb91463SBjoern A. Zeeb lhw->ic_addba_stop(ni, tap); 37169fb91463SBjoern A. Zeeb } 37179fb91463SBjoern A. Zeeb 37189fb91463SBjoern A. Zeeb static void 37199fb91463SBjoern A. Zeeb lkpi_ic_addba_response_timeout(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap) 37209fb91463SBjoern A. Zeeb { 37219fb91463SBjoern A. Zeeb struct ieee80211com *ic; 37229fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 37239fb91463SBjoern A. Zeeb 37249fb91463SBjoern A. Zeeb ic = ni->ni_ic; 37259fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 37269fb91463SBjoern A. Zeeb 37279fb91463SBjoern A. Zeeb IMPROVE_HT(); 37289fb91463SBjoern A. Zeeb 37299fb91463SBjoern A. Zeeb lhw->ic_addba_response_timeout(ni, tap); 37309fb91463SBjoern A. Zeeb } 37319fb91463SBjoern A. Zeeb 37329fb91463SBjoern A. Zeeb static void 37339fb91463SBjoern A. Zeeb lkpi_ic_bar_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 37349fb91463SBjoern A. Zeeb int status) 37359fb91463SBjoern A. Zeeb { 37369fb91463SBjoern A. Zeeb struct ieee80211com *ic; 37379fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 37389fb91463SBjoern A. Zeeb 37399fb91463SBjoern A. Zeeb ic = ni->ni_ic; 37409fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 37419fb91463SBjoern A. Zeeb 37429fb91463SBjoern A. Zeeb IMPROVE_HT(); 37439fb91463SBjoern A. Zeeb 37449fb91463SBjoern A. Zeeb lhw->ic_bar_response(ni, tap, status); 37459fb91463SBjoern A. Zeeb } 37469fb91463SBjoern A. Zeeb 37479fb91463SBjoern A. Zeeb static int 37489fb91463SBjoern A. Zeeb lkpi_ic_ampdu_rx_start(struct ieee80211_node *ni, struct ieee80211_rx_ampdu *rap, 37499fb91463SBjoern A. Zeeb int baparamset, int batimeout, int baseqctl) 37509fb91463SBjoern A. Zeeb { 37519fb91463SBjoern A. Zeeb struct ieee80211com *ic; 37529fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 37539fb91463SBjoern A. Zeeb struct ieee80211_hw *hw; 37549fb91463SBjoern A. Zeeb struct ieee80211vap *vap; 37559fb91463SBjoern A. Zeeb struct lkpi_vif *lvif; 37569fb91463SBjoern A. Zeeb struct ieee80211_vif *vif; 37579fb91463SBjoern A. Zeeb struct lkpi_sta *lsta; 37589fb91463SBjoern A. Zeeb struct ieee80211_sta *sta; 37599fb91463SBjoern A. Zeeb struct ieee80211_ampdu_params params; 37609fb91463SBjoern A. Zeeb int error; 37619fb91463SBjoern A. Zeeb 37629fb91463SBjoern A. Zeeb ic = ni->ni_ic; 37639fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 37649fb91463SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 37659fb91463SBjoern A. Zeeb vap = ni->ni_vap; 37669fb91463SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 37679fb91463SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 37689fb91463SBjoern A. Zeeb lsta = ni->ni_drv_data; 37699fb91463SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 37709fb91463SBjoern A. Zeeb 37719fb91463SBjoern A. Zeeb params.sta = sta; 37729fb91463SBjoern A. Zeeb params.action = IEEE80211_AMPDU_RX_START; 37739fb91463SBjoern A. Zeeb params.buf_size = _IEEE80211_MASKSHIFT(le16toh(baparamset), IEEE80211_BAPS_BUFSIZ); 37749fb91463SBjoern A. Zeeb if (params.buf_size == 0) 37759fb91463SBjoern A. Zeeb params.buf_size = IEEE80211_MAX_AMPDU_BUF_HT; 37769fb91463SBjoern A. Zeeb else 37779fb91463SBjoern A. Zeeb params.buf_size = min(params.buf_size, IEEE80211_MAX_AMPDU_BUF_HT); 37789fb91463SBjoern A. Zeeb if (params.buf_size > hw->max_rx_aggregation_subframes) 37799fb91463SBjoern A. Zeeb params.buf_size = hw->max_rx_aggregation_subframes; 37809fb91463SBjoern A. Zeeb params.timeout = le16toh(batimeout); 37819fb91463SBjoern A. Zeeb params.ssn = _IEEE80211_MASKSHIFT(le16toh(baseqctl), IEEE80211_BASEQ_START); 37829fb91463SBjoern A. Zeeb params.tid = _IEEE80211_MASKSHIFT(le16toh(baparamset), IEEE80211_BAPS_TID); 37839fb91463SBjoern A. Zeeb params.amsdu = false; 37849fb91463SBjoern A. Zeeb 37859fb91463SBjoern A. Zeeb IMPROVE_HT("Do we need to distinguish based on SUPPORTS_REORDERING_BUFFER?"); 37869fb91463SBjoern A. Zeeb 37879fb91463SBjoern A. Zeeb /* This may call kalloc. Make sure we can sleep. */ 37889fb91463SBjoern A. Zeeb error = lkpi_80211_mo_ampdu_action(hw, vif, ¶ms); 37899fb91463SBjoern A. Zeeb if (error != 0) { 37909fb91463SBjoern A. Zeeb ic_printf(ic, "%s: mo_ampdu_action returned %d. ni %p rap %p\n", 37919fb91463SBjoern A. Zeeb __func__, error, ni, rap); 37929fb91463SBjoern A. Zeeb return (error); 37939fb91463SBjoern A. Zeeb } 37949fb91463SBjoern A. Zeeb IMPROVE_HT("net80211 is missing the error check on return and assumes success"); 37959fb91463SBjoern A. Zeeb 37969fb91463SBjoern A. Zeeb error = lhw->ic_ampdu_rx_start(ni, rap, baparamset, batimeout, baseqctl); 37979fb91463SBjoern A. Zeeb return (error); 37989fb91463SBjoern A. Zeeb } 37999fb91463SBjoern A. Zeeb 38009fb91463SBjoern A. Zeeb static void 38019fb91463SBjoern A. Zeeb lkpi_ic_ampdu_rx_stop(struct ieee80211_node *ni, struct ieee80211_rx_ampdu *rap) 38029fb91463SBjoern A. Zeeb { 38039fb91463SBjoern A. Zeeb struct ieee80211com *ic; 38049fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 38059fb91463SBjoern A. Zeeb struct ieee80211_hw *hw; 38069fb91463SBjoern A. Zeeb struct ieee80211vap *vap; 38079fb91463SBjoern A. Zeeb struct lkpi_vif *lvif; 38089fb91463SBjoern A. Zeeb struct ieee80211_vif *vif; 38099fb91463SBjoern A. Zeeb struct lkpi_sta *lsta; 38109fb91463SBjoern A. Zeeb struct ieee80211_sta *sta; 38119fb91463SBjoern A. Zeeb struct ieee80211_ampdu_params params; 38129fb91463SBjoern A. Zeeb int error; 38139fb91463SBjoern A. Zeeb uint8_t tid; 38149fb91463SBjoern A. Zeeb 38159fb91463SBjoern A. Zeeb ic = ni->ni_ic; 38169fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 38179fb91463SBjoern A. Zeeb 38189fb91463SBjoern A. Zeeb /* 38199fb91463SBjoern A. Zeeb * We should not (cannot) call into mac80211 ops with AMPDU_RX_STOP if 38209fb91463SBjoern A. Zeeb * we did not START. Some drivers pass it down to firmware which will 38219fb91463SBjoern A. Zeeb * simply barf and net80211 calls ieee80211_ht_node_cleanup() from 38229fb91463SBjoern A. Zeeb * ieee80211_ht_node_init() amongst others which will iterate over all 38239fb91463SBjoern A. Zeeb * tid and call ic_ampdu_rx_stop() unconditionally. 38249fb91463SBjoern A. Zeeb * XXX net80211 should probably be more "gentle" in these cases and 38259fb91463SBjoern A. Zeeb * track some state itself. 38269fb91463SBjoern A. Zeeb */ 38279fb91463SBjoern A. Zeeb if ((rap->rxa_flags & IEEE80211_AGGR_RUNNING) == 0) 38289fb91463SBjoern A. Zeeb goto net80211_only; 38299fb91463SBjoern A. Zeeb 38309fb91463SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 38319fb91463SBjoern A. Zeeb vap = ni->ni_vap; 38329fb91463SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 38339fb91463SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 38349fb91463SBjoern A. Zeeb lsta = ni->ni_drv_data; 38359fb91463SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 38369fb91463SBjoern A. Zeeb 38379fb91463SBjoern A. Zeeb IMPROVE_HT("This really should be passed from ht_recv_action_ba_delba."); 38389fb91463SBjoern A. Zeeb for (tid = 0; tid < WME_NUM_TID; tid++) { 38399fb91463SBjoern A. Zeeb if (&ni->ni_rx_ampdu[tid] == rap) 38409fb91463SBjoern A. Zeeb break; 38419fb91463SBjoern A. Zeeb } 38429fb91463SBjoern A. Zeeb 38439fb91463SBjoern A. Zeeb params.sta = sta; 38449fb91463SBjoern A. Zeeb params.action = IEEE80211_AMPDU_RX_STOP; 38459fb91463SBjoern A. Zeeb params.buf_size = 0; 38469fb91463SBjoern A. Zeeb params.timeout = 0; 38479fb91463SBjoern A. Zeeb params.ssn = 0; 38489fb91463SBjoern A. Zeeb params.tid = tid; 38499fb91463SBjoern A. Zeeb params.amsdu = false; 38509fb91463SBjoern A. Zeeb 38519fb91463SBjoern A. Zeeb error = lkpi_80211_mo_ampdu_action(hw, vif, ¶ms); 38529fb91463SBjoern A. Zeeb if (error != 0) 38539fb91463SBjoern A. Zeeb ic_printf(ic, "%s: mo_ampdu_action returned %d. ni %p rap %p\n", 38549fb91463SBjoern A. Zeeb __func__, error, ni, rap); 38559fb91463SBjoern A. Zeeb 38569fb91463SBjoern A. Zeeb net80211_only: 38579fb91463SBjoern A. Zeeb lhw->ic_ampdu_rx_stop(ni, rap); 38589fb91463SBjoern A. Zeeb } 38599fb91463SBjoern A. Zeeb #endif 38609fb91463SBjoern A. Zeeb 38619fb91463SBjoern A. Zeeb static void 38629fb91463SBjoern A. Zeeb lkpi_ic_getradiocaps_ht(struct ieee80211com *ic, struct ieee80211_hw *hw, 38639fb91463SBjoern A. Zeeb uint8_t *bands, int *chan_flags, enum nl80211_band band) 38649fb91463SBjoern A. Zeeb { 38659fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 38669fb91463SBjoern A. Zeeb struct ieee80211_sta_ht_cap *ht_cap; 38679fb91463SBjoern A. Zeeb 38689fb91463SBjoern A. Zeeb ht_cap = &hw->wiphy->bands[band]->ht_cap; 38699fb91463SBjoern A. Zeeb if (!ht_cap->ht_supported) 38709fb91463SBjoern A. Zeeb return; 38719fb91463SBjoern A. Zeeb 38729fb91463SBjoern A. Zeeb switch (band) { 38739fb91463SBjoern A. Zeeb case NL80211_BAND_2GHZ: 38749fb91463SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11NG); 38759fb91463SBjoern A. Zeeb break; 38769fb91463SBjoern A. Zeeb case NL80211_BAND_5GHZ: 38779fb91463SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11NA); 38789fb91463SBjoern A. Zeeb break; 38799fb91463SBjoern A. Zeeb default: 38809fb91463SBjoern A. Zeeb IMPROVE("Unsupported band %d", band); 38819fb91463SBjoern A. Zeeb return; 38829fb91463SBjoern A. Zeeb } 38839fb91463SBjoern A. Zeeb 38849fb91463SBjoern A. Zeeb ic->ic_htcaps = IEEE80211_HTC_HT; /* HT operation */ 38859fb91463SBjoern A. Zeeb 38869fb91463SBjoern A. Zeeb /* 38879fb91463SBjoern A. Zeeb * Rather than manually checking each flag and 38889fb91463SBjoern A. Zeeb * translating IEEE80211_HT_CAP_ to IEEE80211_HTCAP_, 38899fb91463SBjoern A. Zeeb * simply copy the 16bits. 38909fb91463SBjoern A. Zeeb */ 38919fb91463SBjoern A. Zeeb ic->ic_htcaps |= ht_cap->cap; 38929fb91463SBjoern A. Zeeb 38939fb91463SBjoern A. Zeeb /* Then deal with the other flags. */ 38949fb91463SBjoern A. Zeeb if (ieee80211_hw_check(hw, AMPDU_AGGREGATION)) 38959fb91463SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTC_AMPDU; 38969fb91463SBjoern A. Zeeb #ifdef __notyet__ 38979fb91463SBjoern A. Zeeb if (ieee80211_hw_check(hw, TX_AMSDU)) 38989fb91463SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTC_AMSDU; 38999fb91463SBjoern A. Zeeb if (ieee80211_hw_check(hw, SUPPORTS_AMSDU_IN_AMPDU)) 39009fb91463SBjoern A. Zeeb ic->ic_htcaps |= (IEEE80211_HTC_RX_AMSDU_AMPDU | 39019fb91463SBjoern A. Zeeb IEEE80211_HTC_TX_AMSDU_AMPDU); 39029fb91463SBjoern A. Zeeb #endif 39039fb91463SBjoern A. Zeeb 39049fb91463SBjoern A. Zeeb IMPROVE("PS, ampdu_*, ht_cap.mcs.tx_params, ..."); 39059fb91463SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_SMPS_OFF; 39069fb91463SBjoern A. Zeeb 39079fb91463SBjoern A. Zeeb /* Only add HT40 channels if supported. */ 39089fb91463SBjoern A. Zeeb if ((ic->ic_htcaps & IEEE80211_HTCAP_CHWIDTH40) != 0 && 39099fb91463SBjoern A. Zeeb chan_flags != NULL) 39109fb91463SBjoern A. Zeeb *chan_flags |= NET80211_CBW_FLAG_HT40; 39119fb91463SBjoern A. Zeeb #endif 39129fb91463SBjoern A. Zeeb } 39139fb91463SBjoern A. Zeeb 39146b4cac81SBjoern A. Zeeb static void 39156b4cac81SBjoern A. Zeeb lkpi_ic_getradiocaps(struct ieee80211com *ic, int maxchan, 39166b4cac81SBjoern A. Zeeb int *n, struct ieee80211_channel *c) 39176b4cac81SBjoern A. Zeeb { 39186b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 39196b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 39206b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 39216b4cac81SBjoern A. Zeeb uint8_t bands[IEEE80211_MODE_BYTES]; 39226b4cac81SBjoern A. Zeeb int chan_flags, error, i, nchans; 39236b4cac81SBjoern A. Zeeb 39246b4cac81SBjoern A. Zeeb /* Channels */ 39256b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 39266b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 39276b4cac81SBjoern A. Zeeb 39286b4cac81SBjoern A. Zeeb /* NL80211_BAND_2GHZ */ 39296b4cac81SBjoern A. Zeeb nchans = 0; 39306b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_2GHZ] != NULL) 39316b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[NL80211_BAND_2GHZ]->n_channels; 39326b4cac81SBjoern A. Zeeb if (nchans > 0) { 39336b4cac81SBjoern A. Zeeb memset(bands, 0, sizeof(bands)); 39346b4cac81SBjoern A. Zeeb chan_flags = 0; 39356b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11B); 39366b4cac81SBjoern A. Zeeb /* XXX-BZ unclear how to check for 11g. */ 39379fb91463SBjoern A. Zeeb 39389fb91463SBjoern A. Zeeb IMPROVE("the bitrates may have flags?"); 39396b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11G); 39409fb91463SBjoern A. Zeeb 39419fb91463SBjoern A. Zeeb lkpi_ic_getradiocaps_ht(ic, hw, bands, &chan_flags, 39429fb91463SBjoern A. Zeeb NL80211_BAND_2GHZ); 39436b4cac81SBjoern A. Zeeb 39446b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[NL80211_BAND_2GHZ]->channels; 3945cee56e77SBjoern A. Zeeb for (i = 0; i < nchans && *n < maxchan; i++) { 39466b4cac81SBjoern A. Zeeb uint32_t nflags = 0; 39476b4cac81SBjoern A. Zeeb int cflags = chan_flags; 39486b4cac81SBjoern A. Zeeb 39496b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) { 39503f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Skipping disabled chan " 39513f0083c4SBjoern A. Zeeb "[%u/%u/%#x]\n", __func__, 39526b4cac81SBjoern A. Zeeb channels[i].hw_value, 39536b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags); 39546b4cac81SBjoern A. Zeeb continue; 39556b4cac81SBjoern A. Zeeb } 39566b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_IR) 39576b4cac81SBjoern A. Zeeb nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE); 39586b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_RADAR) 39596b4cac81SBjoern A. Zeeb nflags |= IEEE80211_CHAN_DFS; 39606b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ) 39616b4cac81SBjoern A. Zeeb cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80); 39626b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ) 39636b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_VHT80; 39646b4cac81SBjoern A. Zeeb /* XXX how to map the remaining enum ieee80211_channel_flags? */ 39656b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_HT40) 39666b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_HT40; 39676b4cac81SBjoern A. Zeeb 39686b4cac81SBjoern A. Zeeb error = ieee80211_add_channel_cbw(c, maxchan, n, 39696b4cac81SBjoern A. Zeeb channels[i].hw_value, channels[i].center_freq, 39706b4cac81SBjoern A. Zeeb channels[i].max_power, 39715856761fSBjoern A. Zeeb nflags, bands, cflags); 3972cee56e77SBjoern A. Zeeb /* net80211::ENOBUFS: *n >= maxchans */ 3973cee56e77SBjoern A. Zeeb if (error != 0 && error != ENOBUFS) 39743f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Adding chan %u/%u/%#x/%#x/%#x/%#x " 39753f0083c4SBjoern A. Zeeb "returned error %d\n", 39766b4cac81SBjoern A. Zeeb __func__, channels[i].hw_value, 39776b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags, 39786b4cac81SBjoern A. Zeeb nflags, chan_flags, cflags, error); 3979cee56e77SBjoern A. Zeeb if (error != 0) 39806b4cac81SBjoern A. Zeeb break; 39816b4cac81SBjoern A. Zeeb } 39826b4cac81SBjoern A. Zeeb } 39836b4cac81SBjoern A. Zeeb 39846b4cac81SBjoern A. Zeeb /* NL80211_BAND_5GHZ */ 39856b4cac81SBjoern A. Zeeb nchans = 0; 39866b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ] != NULL) 39876b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[NL80211_BAND_5GHZ]->n_channels; 39886b4cac81SBjoern A. Zeeb if (nchans > 0) { 39896b4cac81SBjoern A. Zeeb memset(bands, 0, sizeof(bands)); 39906b4cac81SBjoern A. Zeeb chan_flags = 0; 39916b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11A); 39929fb91463SBjoern A. Zeeb 39939fb91463SBjoern A. Zeeb lkpi_ic_getradiocaps_ht(ic, hw, bands, &chan_flags, 39949fb91463SBjoern A. Zeeb NL80211_BAND_5GHZ); 39959fb91463SBjoern A. Zeeb 39969fb91463SBjoern A. Zeeb #ifdef LKPI_80211_VHT 39976b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.vht_supported){ 39986b4cac81SBjoern A. Zeeb 39996b4cac81SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_VHT; 4000562adbe1SBjoern A. Zeeb ic->ic_vht_cap.vht_cap_info = 40016b4cac81SBjoern A. Zeeb hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap; 40026b4cac81SBjoern A. Zeeb 40036b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_VHT_5GHZ); 40046b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT80; 40056b4cac81SBjoern A. Zeeb if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160MHZ( 4006562adbe1SBjoern A. Zeeb ic->ic_vht_cap.vht_cap_info)) 40076b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT160; 40086b4cac81SBjoern A. Zeeb if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160_80P80MHZ( 4009562adbe1SBjoern A. Zeeb ic->ic_vht_cap.vht_cap_info)) 40106b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT80P80; 40116b4cac81SBjoern A. Zeeb } 40126b4cac81SBjoern A. Zeeb #endif 40136b4cac81SBjoern A. Zeeb 40146b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[NL80211_BAND_5GHZ]->channels; 4015cee56e77SBjoern A. Zeeb for (i = 0; i < nchans && *n < maxchan; i++) { 40166b4cac81SBjoern A. Zeeb uint32_t nflags = 0; 40176b4cac81SBjoern A. Zeeb int cflags = chan_flags; 40186b4cac81SBjoern A. Zeeb 40196b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) { 40203f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Skipping disabled chan " 40213f0083c4SBjoern A. Zeeb "[%u/%u/%#x]\n", __func__, 40226b4cac81SBjoern A. Zeeb channels[i].hw_value, 40236b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags); 40246b4cac81SBjoern A. Zeeb continue; 40256b4cac81SBjoern A. Zeeb } 40266b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_IR) 40276b4cac81SBjoern A. Zeeb nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE); 40286b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_RADAR) 40296b4cac81SBjoern A. Zeeb nflags |= IEEE80211_CHAN_DFS; 40306b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ) 40316b4cac81SBjoern A. Zeeb cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80); 40326b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ) 40336b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_VHT80; 40346b4cac81SBjoern A. Zeeb /* XXX hwo to map the remaining enum ieee80211_channel_flags? */ 40356b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_HT40) 40366b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_HT40; 40376b4cac81SBjoern A. Zeeb 40386b4cac81SBjoern A. Zeeb error = ieee80211_add_channel_cbw(c, maxchan, n, 40396b4cac81SBjoern A. Zeeb channels[i].hw_value, channels[i].center_freq, 40406b4cac81SBjoern A. Zeeb channels[i].max_power, 40415856761fSBjoern A. Zeeb nflags, bands, cflags); 4042cee56e77SBjoern A. Zeeb /* net80211::ENOBUFS: *n >= maxchans */ 4043cee56e77SBjoern A. Zeeb if (error != 0 && error != ENOBUFS) 40443f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Adding chan %u/%u/%#x/%#x/%#x/%#x " 40453f0083c4SBjoern A. Zeeb "returned error %d\n", 40466b4cac81SBjoern A. Zeeb __func__, channels[i].hw_value, 40476b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags, 40486b4cac81SBjoern A. Zeeb nflags, chan_flags, cflags, error); 4049cee56e77SBjoern A. Zeeb if (error != 0) 40506b4cac81SBjoern A. Zeeb break; 40516b4cac81SBjoern A. Zeeb } 40526b4cac81SBjoern A. Zeeb } 40536b4cac81SBjoern A. Zeeb } 40546b4cac81SBjoern A. Zeeb 40556b4cac81SBjoern A. Zeeb static void * 40566b4cac81SBjoern A. Zeeb lkpi_ieee80211_ifalloc(void) 40576b4cac81SBjoern A. Zeeb { 40586b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 40596b4cac81SBjoern A. Zeeb 40606b4cac81SBjoern A. Zeeb ic = malloc(sizeof(*ic), M_LKPI80211, M_WAITOK | M_ZERO); 40616b4cac81SBjoern A. Zeeb if (ic == NULL) 40626b4cac81SBjoern A. Zeeb return (NULL); 40636b4cac81SBjoern A. Zeeb 40646b4cac81SBjoern A. Zeeb /* Setting these happens later when we have device information. */ 40656b4cac81SBjoern A. Zeeb ic->ic_softc = NULL; 40666b4cac81SBjoern A. Zeeb ic->ic_name = "linuxkpi"; 40676b4cac81SBjoern A. Zeeb 40686b4cac81SBjoern A. Zeeb return (ic); 40696b4cac81SBjoern A. Zeeb } 40706b4cac81SBjoern A. Zeeb 40716b4cac81SBjoern A. Zeeb struct ieee80211_hw * 40726b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_alloc_hw(size_t priv_len, const struct ieee80211_ops *ops) 40736b4cac81SBjoern A. Zeeb { 40746b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 40756b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 40766b4cac81SBjoern A. Zeeb struct wiphy *wiphy; 4077a5ae63edSBjoern A. Zeeb int ac; 40786b4cac81SBjoern A. Zeeb 40796b4cac81SBjoern A. Zeeb /* Get us and the driver data also allocated. */ 40806b4cac81SBjoern A. Zeeb wiphy = wiphy_new(&linuxkpi_mac80211cfgops, sizeof(*lhw) + priv_len); 40816b4cac81SBjoern A. Zeeb if (wiphy == NULL) 40826b4cac81SBjoern A. Zeeb return (NULL); 40836b4cac81SBjoern A. Zeeb 40846b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 40856b4cac81SBjoern A. Zeeb lhw->ops = ops; 4086652e22d3SBjoern A. Zeeb 40878ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK_INIT(lhw); 40888ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK_INIT(lhw); 4089*eac3646fSBjoern A. Zeeb LKPI_80211_LHW_TXQ_LOCK_INIT(lhw); 40908891c455SBjoern A. Zeeb sx_init_flags(&lhw->lvif_sx, "lhw-lvif", SX_RECURSE | SX_DUPOK); 40916b4cac81SBjoern A. Zeeb TAILQ_INIT(&lhw->lvif_head); 4092a5ae63edSBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 4093a5ae63edSBjoern A. Zeeb lhw->txq_generation[ac] = 1; 4094a5ae63edSBjoern A. Zeeb TAILQ_INIT(&lhw->scheduled_txqs[ac]); 4095a5ae63edSBjoern A. Zeeb } 40966b4cac81SBjoern A. Zeeb 40976b4cac81SBjoern A. Zeeb /* 40986b4cac81SBjoern A. Zeeb * XXX-BZ TODO make sure there is a "_null" function to all ops 40996b4cac81SBjoern A. Zeeb * not initialized. 41006b4cac81SBjoern A. Zeeb */ 41016b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 41026b4cac81SBjoern A. Zeeb hw->wiphy = wiphy; 4103086be6a8SBjoern A. Zeeb hw->conf.flags |= IEEE80211_CONF_IDLE; 41046b4cac81SBjoern A. Zeeb hw->priv = (void *)(lhw + 1); 41056b4cac81SBjoern A. Zeeb 41066b4cac81SBjoern A. Zeeb /* BSD Specific. */ 41076b4cac81SBjoern A. Zeeb lhw->ic = lkpi_ieee80211_ifalloc(); 41086b4cac81SBjoern A. Zeeb if (lhw->ic == NULL) { 41096b4cac81SBjoern A. Zeeb ieee80211_free_hw(hw); 41106b4cac81SBjoern A. Zeeb return (NULL); 41116b4cac81SBjoern A. Zeeb } 41126b4cac81SBjoern A. Zeeb 41136b4cac81SBjoern A. Zeeb IMPROVE(); 41146b4cac81SBjoern A. Zeeb 41156b4cac81SBjoern A. Zeeb return (hw); 41166b4cac81SBjoern A. Zeeb } 41176b4cac81SBjoern A. Zeeb 41186b4cac81SBjoern A. Zeeb void 41196b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iffree(struct ieee80211_hw *hw) 41206b4cac81SBjoern A. Zeeb { 41216b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 41226b4cac81SBjoern A. Zeeb 41236b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 41246b4cac81SBjoern A. Zeeb free(lhw->ic, M_LKPI80211); 41256b4cac81SBjoern A. Zeeb lhw->ic = NULL; 41266b4cac81SBjoern A. Zeeb 41276b4cac81SBjoern A. Zeeb /* Cleanup more of lhw here or in wiphy_free()? */ 4128*eac3646fSBjoern A. Zeeb LKPI_80211_LHW_TXQ_LOCK_DESTROY(lhw); 41298ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK_DESTROY(lhw); 4130*eac3646fSBjoern A. Zeeb LKPI_80211_LHW_LOCK_DESTROY(lhw); 4131*eac3646fSBjoern A. Zeeb sx_destroy(&lhw->lvif_sx); 41326b4cac81SBjoern A. Zeeb IMPROVE(); 41336b4cac81SBjoern A. Zeeb } 41346b4cac81SBjoern A. Zeeb 41356b4cac81SBjoern A. Zeeb void 41366b4cac81SBjoern A. Zeeb linuxkpi_set_ieee80211_dev(struct ieee80211_hw *hw, char *name) 41376b4cac81SBjoern A. Zeeb { 41386b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 41396b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 41406b4cac81SBjoern A. Zeeb 41416b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 41426b4cac81SBjoern A. Zeeb ic = lhw->ic; 41436b4cac81SBjoern A. Zeeb 41446b4cac81SBjoern A. Zeeb /* Now set a proper name before ieee80211_ifattach(). */ 41456b4cac81SBjoern A. Zeeb ic->ic_softc = lhw; 41466b4cac81SBjoern A. Zeeb ic->ic_name = name; 41476b4cac81SBjoern A. Zeeb 41486b4cac81SBjoern A. Zeeb /* XXX-BZ do we also need to set wiphy name? */ 41496b4cac81SBjoern A. Zeeb } 41506b4cac81SBjoern A. Zeeb 41516b4cac81SBjoern A. Zeeb struct ieee80211_hw * 41526b4cac81SBjoern A. Zeeb linuxkpi_wiphy_to_ieee80211_hw(struct wiphy *wiphy) 41536b4cac81SBjoern A. Zeeb { 41546b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 41556b4cac81SBjoern A. Zeeb 41566b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 41576b4cac81SBjoern A. Zeeb return (LHW_TO_HW(lhw)); 41586b4cac81SBjoern A. Zeeb } 41596b4cac81SBjoern A. Zeeb 41606b4cac81SBjoern A. Zeeb static void 41616b4cac81SBjoern A. Zeeb lkpi_radiotap_attach(struct lkpi_hw *lhw) 41626b4cac81SBjoern A. Zeeb { 41636b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 41646b4cac81SBjoern A. Zeeb 41656b4cac81SBjoern A. Zeeb ic = lhw->ic; 41666b4cac81SBjoern A. Zeeb ieee80211_radiotap_attach(ic, 41676b4cac81SBjoern A. Zeeb &lhw->rtap_tx.wt_ihdr, sizeof(lhw->rtap_tx), 41686b4cac81SBjoern A. Zeeb LKPI_RTAP_TX_FLAGS_PRESENT, 41696b4cac81SBjoern A. Zeeb &lhw->rtap_rx.wr_ihdr, sizeof(lhw->rtap_rx), 41706b4cac81SBjoern A. Zeeb LKPI_RTAP_RX_FLAGS_PRESENT); 41716b4cac81SBjoern A. Zeeb } 41726b4cac81SBjoern A. Zeeb 41732e183d99SBjoern A. Zeeb int 41746b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ifattach(struct ieee80211_hw *hw) 41756b4cac81SBjoern A. Zeeb { 41766b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 41776b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 4178c5b96b3eSBjoern A. Zeeb int band, i; 41796b4cac81SBjoern A. Zeeb 41806b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 41816b4cac81SBjoern A. Zeeb ic = lhw->ic; 41826b4cac81SBjoern A. Zeeb 4183652e22d3SBjoern A. Zeeb /* We do it this late as wiphy->dev should be set for the name. */ 4184652e22d3SBjoern A. Zeeb lhw->workq = alloc_ordered_workqueue(wiphy_name(hw->wiphy), 0); 4185652e22d3SBjoern A. Zeeb if (lhw->workq == NULL) 4186652e22d3SBjoern A. Zeeb return (-EAGAIN); 4187652e22d3SBjoern A. Zeeb 41886b4cac81SBjoern A. Zeeb /* XXX-BZ figure this out how they count his... */ 41896b4cac81SBjoern A. Zeeb if (!is_zero_ether_addr(hw->wiphy->perm_addr)) { 41906b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(ic->ic_macaddr, 41916b4cac81SBjoern A. Zeeb hw->wiphy->perm_addr); 41926b4cac81SBjoern A. Zeeb } else if (hw->wiphy->n_addresses > 0) { 41936b4cac81SBjoern A. Zeeb /* We take the first one. */ 41946b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(ic->ic_macaddr, 41956b4cac81SBjoern A. Zeeb hw->wiphy->addresses[0].addr); 41966b4cac81SBjoern A. Zeeb } else { 41976b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: warning, no hardware address!\n", __func__); 41986b4cac81SBjoern A. Zeeb } 41996b4cac81SBjoern A. Zeeb 42003d09d310SBjoern A. Zeeb #ifdef __not_yet__ 42013d09d310SBjoern A. Zeeb /* See comment in lkpi_80211_txq_tx_one(). */ 42026b4cac81SBjoern A. Zeeb ic->ic_headroom = hw->extra_tx_headroom; 42033d09d310SBjoern A. Zeeb #endif 42046b4cac81SBjoern A. Zeeb 42056b4cac81SBjoern A. Zeeb ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ 42066b4cac81SBjoern A. Zeeb ic->ic_opmode = IEEE80211_M_STA; 42076b4cac81SBjoern A. Zeeb 42086b4cac81SBjoern A. Zeeb /* Set device capabilities. */ 42096b4cac81SBjoern A. Zeeb /* XXX-BZ we need to get these from linux80211/drivers and convert. */ 42106b4cac81SBjoern A. Zeeb ic->ic_caps = 42116b4cac81SBjoern A. Zeeb IEEE80211_C_STA | 42126b4cac81SBjoern A. Zeeb IEEE80211_C_MONITOR | 42136b4cac81SBjoern A. Zeeb IEEE80211_C_WPA | /* WPA/RSN */ 42144a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 42156b4cac81SBjoern A. Zeeb IEEE80211_C_WME | 42164a67f1dfSBjoern A. Zeeb #endif 42176b4cac81SBjoern A. Zeeb #if 0 42186b4cac81SBjoern A. Zeeb IEEE80211_C_PMGT | 42196b4cac81SBjoern A. Zeeb #endif 42206b4cac81SBjoern A. Zeeb IEEE80211_C_SHSLOT | /* short slot time supported */ 42216b4cac81SBjoern A. Zeeb IEEE80211_C_SHPREAMBLE /* short preamble supported */ 42226b4cac81SBjoern A. Zeeb ; 42236b4cac81SBjoern A. Zeeb #if 0 42246b4cac81SBjoern A. Zeeb /* Scanning is a different kind of beast to re-work. */ 42256b4cac81SBjoern A. Zeeb ic->ic_caps |= IEEE80211_C_BGSCAN; 42266b4cac81SBjoern A. Zeeb #endif 4227cc4e78d5SBjoern A. Zeeb if (lhw->ops->hw_scan) { 4228cc4e78d5SBjoern A. Zeeb /* 4229cc4e78d5SBjoern A. Zeeb * Advertise full-offload scanning. 4230cc4e78d5SBjoern A. Zeeb * 4231cc4e78d5SBjoern A. Zeeb * Not limiting to SINGLE_SCAN_ON_ALL_BANDS here as otherwise 4232cc4e78d5SBjoern A. Zeeb * we essentially disable hw_scan for all drivers not setting 4233cc4e78d5SBjoern A. Zeeb * the flag. 4234cc4e78d5SBjoern A. Zeeb */ 42356b4cac81SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_SCAN_OFFLOAD; 4236a486fbbdSBjoern A. Zeeb lhw->scan_flags |= LKPI_LHW_SCAN_HW; 42376b4cac81SBjoern A. Zeeb } 42386b4cac81SBjoern A. Zeeb 4239527687a9SBjoern A. Zeeb /* 4240527687a9SBjoern A. Zeeb * The wiphy variables report bitmasks of avail antennas. 4241527687a9SBjoern A. Zeeb * (*get_antenna) get the current bitmask sets which can be 4242527687a9SBjoern A. Zeeb * altered by (*set_antenna) for some drivers. 4243527687a9SBjoern A. Zeeb * XXX-BZ will the count alone do us much good long-term in net80211? 4244527687a9SBjoern A. Zeeb */ 4245527687a9SBjoern A. Zeeb if (hw->wiphy->available_antennas_rx || 4246527687a9SBjoern A. Zeeb hw->wiphy->available_antennas_tx) { 4247527687a9SBjoern A. Zeeb uint32_t rxs, txs; 4248527687a9SBjoern A. Zeeb 4249527687a9SBjoern A. Zeeb if (lkpi_80211_mo_get_antenna(hw, &txs, &rxs) == 0) { 4250527687a9SBjoern A. Zeeb ic->ic_rxstream = bitcount32(rxs); 4251527687a9SBjoern A. Zeeb ic->ic_txstream = bitcount32(txs); 4252527687a9SBjoern A. Zeeb } 4253527687a9SBjoern A. Zeeb } 4254527687a9SBjoern A. Zeeb 42556b4cac81SBjoern A. Zeeb ic->ic_cryptocaps = 0; 4256b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 42576b4cac81SBjoern A. Zeeb if (hw->wiphy->n_cipher_suites > 0) { 42586b4cac81SBjoern A. Zeeb for (i = 0; i < hw->wiphy->n_cipher_suites; i++) 42596b4cac81SBjoern A. Zeeb ic->ic_cryptocaps |= lkpi_l80211_to_net80211_cyphers( 42606b4cac81SBjoern A. Zeeb hw->wiphy->cipher_suites[i]); 42616b4cac81SBjoern A. Zeeb } 42626b4cac81SBjoern A. Zeeb #endif 42636b4cac81SBjoern A. Zeeb 42646b4cac81SBjoern A. Zeeb lkpi_ic_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans, 42656b4cac81SBjoern A. Zeeb ic->ic_channels); 42666b4cac81SBjoern A. Zeeb 42676b4cac81SBjoern A. Zeeb ieee80211_ifattach(ic); 42686b4cac81SBjoern A. Zeeb 42696b4cac81SBjoern A. Zeeb ic->ic_update_mcast = lkpi_ic_update_mcast; 42706b4cac81SBjoern A. Zeeb ic->ic_update_promisc = lkpi_ic_update_promisc; 42716b4cac81SBjoern A. Zeeb ic->ic_update_chw = lkpi_ic_update_chw; 42726b4cac81SBjoern A. Zeeb ic->ic_parent = lkpi_ic_parent; 42736b4cac81SBjoern A. Zeeb ic->ic_scan_start = lkpi_ic_scan_start; 42746b4cac81SBjoern A. Zeeb ic->ic_scan_end = lkpi_ic_scan_end; 42756b4cac81SBjoern A. Zeeb ic->ic_set_channel = lkpi_ic_set_channel; 42766b4cac81SBjoern A. Zeeb ic->ic_transmit = lkpi_ic_transmit; 42776b4cac81SBjoern A. Zeeb ic->ic_raw_xmit = lkpi_ic_raw_xmit; 42786b4cac81SBjoern A. Zeeb ic->ic_vap_create = lkpi_ic_vap_create; 42796b4cac81SBjoern A. Zeeb ic->ic_vap_delete = lkpi_ic_vap_delete; 42806b4cac81SBjoern A. Zeeb ic->ic_getradiocaps = lkpi_ic_getradiocaps; 42816b4cac81SBjoern A. Zeeb ic->ic_wme.wme_update = lkpi_ic_wme_update; 42826b4cac81SBjoern A. Zeeb 4283a486fbbdSBjoern A. Zeeb lhw->ic_scan_curchan = ic->ic_scan_curchan; 4284a486fbbdSBjoern A. Zeeb ic->ic_scan_curchan = lkpi_ic_scan_curchan; 4285a486fbbdSBjoern A. Zeeb lhw->ic_scan_mindwell = ic->ic_scan_mindwell; 4286a486fbbdSBjoern A. Zeeb ic->ic_scan_mindwell = lkpi_ic_scan_mindwell; 4287a486fbbdSBjoern A. Zeeb 42886b4cac81SBjoern A. Zeeb lhw->ic_node_alloc = ic->ic_node_alloc; 42896b4cac81SBjoern A. Zeeb ic->ic_node_alloc = lkpi_ic_node_alloc; 42906b4cac81SBjoern A. Zeeb lhw->ic_node_init = ic->ic_node_init; 42916b4cac81SBjoern A. Zeeb ic->ic_node_init = lkpi_ic_node_init; 42926b4cac81SBjoern A. Zeeb lhw->ic_node_cleanup = ic->ic_node_cleanup; 42936b4cac81SBjoern A. Zeeb ic->ic_node_cleanup = lkpi_ic_node_cleanup; 42946b4cac81SBjoern A. Zeeb lhw->ic_node_free = ic->ic_node_free; 42956b4cac81SBjoern A. Zeeb ic->ic_node_free = lkpi_ic_node_free; 42966b4cac81SBjoern A. Zeeb 42979fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 42989fb91463SBjoern A. Zeeb lhw->ic_recv_action = ic->ic_recv_action; 42999fb91463SBjoern A. Zeeb ic->ic_recv_action = lkpi_ic_recv_action; 43009fb91463SBjoern A. Zeeb lhw->ic_send_action = ic->ic_send_action; 43019fb91463SBjoern A. Zeeb ic->ic_send_action = lkpi_ic_send_action; 43029fb91463SBjoern A. Zeeb 43039fb91463SBjoern A. Zeeb lhw->ic_ampdu_enable = ic->ic_ampdu_enable; 43049fb91463SBjoern A. Zeeb ic->ic_ampdu_enable = lkpi_ic_ampdu_enable; 43059fb91463SBjoern A. Zeeb 43069fb91463SBjoern A. Zeeb lhw->ic_addba_request = ic->ic_addba_request; 43079fb91463SBjoern A. Zeeb ic->ic_addba_request = lkpi_ic_addba_request; 43089fb91463SBjoern A. Zeeb lhw->ic_addba_response = ic->ic_addba_response; 43099fb91463SBjoern A. Zeeb ic->ic_addba_response = lkpi_ic_addba_response; 43109fb91463SBjoern A. Zeeb lhw->ic_addba_stop = ic->ic_addba_stop; 43119fb91463SBjoern A. Zeeb ic->ic_addba_stop = lkpi_ic_addba_stop; 43129fb91463SBjoern A. Zeeb lhw->ic_addba_response_timeout = ic->ic_addba_response_timeout; 43139fb91463SBjoern A. Zeeb ic->ic_addba_response_timeout = lkpi_ic_addba_response_timeout; 43149fb91463SBjoern A. Zeeb 43159fb91463SBjoern A. Zeeb lhw->ic_bar_response = ic->ic_bar_response; 43169fb91463SBjoern A. Zeeb ic->ic_bar_response = lkpi_ic_bar_response; 43179fb91463SBjoern A. Zeeb 43189fb91463SBjoern A. Zeeb lhw->ic_ampdu_rx_start = ic->ic_ampdu_rx_start; 43199fb91463SBjoern A. Zeeb ic->ic_ampdu_rx_start = lkpi_ic_ampdu_rx_start; 43209fb91463SBjoern A. Zeeb lhw->ic_ampdu_rx_stop = ic->ic_ampdu_rx_stop; 43219fb91463SBjoern A. Zeeb ic->ic_ampdu_rx_stop = lkpi_ic_ampdu_rx_stop; 43229fb91463SBjoern A. Zeeb #endif 43239fb91463SBjoern A. Zeeb 43246b4cac81SBjoern A. Zeeb lkpi_radiotap_attach(lhw); 43256b4cac81SBjoern A. Zeeb 4326c5b96b3eSBjoern A. Zeeb /* 4327c5b96b3eSBjoern A. Zeeb * Assign the first possible channel for now; seems Realtek drivers 4328c5b96b3eSBjoern A. Zeeb * expect one. 4329d9945d78SBjoern A. Zeeb * Also remember the amount of bands we support and the most rates 4330d9945d78SBjoern A. Zeeb * in any band so we can scale [(ext) sup rates] IE(s) accordingly. 4331c5b96b3eSBjoern A. Zeeb */ 4332d9945d78SBjoern A. Zeeb lhw->supbands = lhw->max_rates = 0; 4333f454a4a1SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 4334c5b96b3eSBjoern A. Zeeb struct ieee80211_supported_band *supband; 4335c5b96b3eSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 4336c5b96b3eSBjoern A. Zeeb 4337c5b96b3eSBjoern A. Zeeb supband = hw->wiphy->bands[band]; 4338c5b96b3eSBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 4339c5b96b3eSBjoern A. Zeeb continue; 4340c5b96b3eSBjoern A. Zeeb 4341d9945d78SBjoern A. Zeeb lhw->supbands++; 4342d9945d78SBjoern A. Zeeb lhw->max_rates = max(lhw->max_rates, supband->n_bitrates); 4343d9945d78SBjoern A. Zeeb 4344f454a4a1SBjoern A. Zeeb /* If we have a channel, we need to keep counting supbands. */ 4345f454a4a1SBjoern A. Zeeb if (hw->conf.chandef.chan != NULL) 4346f454a4a1SBjoern A. Zeeb continue; 4347f454a4a1SBjoern A. Zeeb 4348c5b96b3eSBjoern A. Zeeb channels = supband->channels; 4349c5b96b3eSBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 4350c5b96b3eSBjoern A. Zeeb 4351c5b96b3eSBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) 4352c5b96b3eSBjoern A. Zeeb continue; 4353c5b96b3eSBjoern A. Zeeb 43544a07abdeSBjoern A. Zeeb cfg80211_chandef_create(&hw->conf.chandef, &channels[i], 43559fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 43569fb91463SBjoern A. Zeeb (ic->ic_htcaps & IEEE80211_HTC_HT) ? 0 : 43579fb91463SBjoern A. Zeeb #endif 4358c5b96b3eSBjoern A. Zeeb NL80211_CHAN_NO_HT); 4359c5b96b3eSBjoern A. Zeeb break; 4360c5b96b3eSBjoern A. Zeeb } 4361c5b96b3eSBjoern A. Zeeb } 4362c5b96b3eSBjoern A. Zeeb 4363d9945d78SBjoern A. Zeeb IMPROVE("see net80211::ieee80211_chan_init vs. wiphy->bands[].bitrates possibly in lkpi_ic_getradiocaps?"); 4364d9945d78SBjoern A. Zeeb 4365d9945d78SBjoern A. Zeeb /* Make sure we do not support more than net80211 is willing to take. */ 4366d9945d78SBjoern A. Zeeb if (lhw->max_rates > IEEE80211_RATE_MAXSIZE) { 4367d9945d78SBjoern A. Zeeb ic_printf(ic, "%s: limiting max_rates %d to %d!\n", __func__, 4368d9945d78SBjoern A. Zeeb lhw->max_rates, IEEE80211_RATE_MAXSIZE); 4369d9945d78SBjoern A. Zeeb lhw->max_rates = IEEE80211_RATE_MAXSIZE; 4370d9945d78SBjoern A. Zeeb } 4371d9945d78SBjoern A. Zeeb 4372d9945d78SBjoern A. Zeeb /* 4373d9945d78SBjoern A. Zeeb * The maximum supported bitrates on any band + size for 4374d9945d78SBjoern A. Zeeb * DSSS Parameter Set give our per-band IE size. 4375d9945d78SBjoern A. Zeeb * SSID is the responsibility of the driver and goes on the side. 4376d9945d78SBjoern A. Zeeb * The user specified bits coming from the vap go into the 4377d9945d78SBjoern A. Zeeb * "common ies" fields. 4378d9945d78SBjoern A. Zeeb */ 4379d9945d78SBjoern A. Zeeb lhw->scan_ie_len = 2 + IEEE80211_RATE_SIZE; 4380d9945d78SBjoern A. Zeeb if (lhw->max_rates > IEEE80211_RATE_SIZE) 4381d9945d78SBjoern A. Zeeb lhw->scan_ie_len += 2 + (lhw->max_rates - IEEE80211_RATE_SIZE); 438278ca45dfSBjoern A. Zeeb 438378ca45dfSBjoern A. Zeeb if (hw->wiphy->features & NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) { 4384d9945d78SBjoern A. Zeeb /* 438578ca45dfSBjoern A. Zeeb * net80211 does not seem to support the DSSS Parameter Set but 438678ca45dfSBjoern A. Zeeb * some of the drivers insert it so calculate the extra fixed 438778ca45dfSBjoern A. Zeeb * space in. 4388d9945d78SBjoern A. Zeeb */ 4389d9945d78SBjoern A. Zeeb lhw->scan_ie_len += 2 + 1; 439078ca45dfSBjoern A. Zeeb } 4391d9945d78SBjoern A. Zeeb 43929fb91463SBjoern A. Zeeb #if defined(LKPI_80211_HT) 43939fb91463SBjoern A. Zeeb if ((ic->ic_htcaps & IEEE80211_HTC_HT) != 0) 43949fb91463SBjoern A. Zeeb lhw->scan_ie_len += sizeof(struct ieee80211_ie_htcap); 43959fb91463SBjoern A. Zeeb #endif 43969fb91463SBjoern A. Zeeb #if defined(LKPI_80211_VHT) 43979fb91463SBjoern A. Zeeb if ((ic->ic_flags_ext & IEEE80211_FEXT_VHT) != 0) 43989fb91463SBjoern A. Zeeb lhw->scan_ie_len += 2 + sizeof(struct ieee80211_vht_cap); 43999fb91463SBjoern A. Zeeb #endif 44009fb91463SBjoern A. Zeeb 4401d9945d78SBjoern A. Zeeb /* Reduce the max_scan_ie_len "left" by the amount we consume already. */ 440278ca45dfSBjoern A. Zeeb if (hw->wiphy->max_scan_ie_len > 0) { 440378ca45dfSBjoern A. Zeeb if (lhw->scan_ie_len > hw->wiphy->max_scan_ie_len) 440478ca45dfSBjoern A. Zeeb goto err; 4405d9945d78SBjoern A. Zeeb hw->wiphy->max_scan_ie_len -= lhw->scan_ie_len; 440678ca45dfSBjoern A. Zeeb } 4407d9945d78SBjoern A. Zeeb 44086b4cac81SBjoern A. Zeeb if (bootverbose) 44096b4cac81SBjoern A. Zeeb ieee80211_announce(ic); 44102e183d99SBjoern A. Zeeb 44112e183d99SBjoern A. Zeeb return (0); 441278ca45dfSBjoern A. Zeeb err: 441378ca45dfSBjoern A. Zeeb IMPROVE("TODO FIXME CLEANUP"); 441478ca45dfSBjoern A. Zeeb return (-EAGAIN); 44156b4cac81SBjoern A. Zeeb } 44166b4cac81SBjoern A. Zeeb 44176b4cac81SBjoern A. Zeeb void 44186b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ifdetach(struct ieee80211_hw *hw) 44196b4cac81SBjoern A. Zeeb { 44206b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 44216b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 44226b4cac81SBjoern A. Zeeb 44236b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 44246b4cac81SBjoern A. Zeeb ic = lhw->ic; 44256b4cac81SBjoern A. Zeeb ieee80211_ifdetach(ic); 44266b4cac81SBjoern A. Zeeb } 44276b4cac81SBjoern A. Zeeb 44286b4cac81SBjoern A. Zeeb void 44296b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_interfaces(struct ieee80211_hw *hw, 44306b4cac81SBjoern A. Zeeb enum ieee80211_iface_iter flags, 44316b4cac81SBjoern A. Zeeb void(*iterfunc)(void *, uint8_t *, struct ieee80211_vif *), 44326b4cac81SBjoern A. Zeeb void *arg) 44336b4cac81SBjoern A. Zeeb { 44346b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 44356b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 44366b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 443761a68e50SBjoern A. Zeeb bool active, atomic, nin_drv; 44386b4cac81SBjoern A. Zeeb 44396b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 44406b4cac81SBjoern A. Zeeb 44416b4cac81SBjoern A. Zeeb if (flags & ~(IEEE80211_IFACE_ITER_NORMAL| 44426b4cac81SBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL| 444361a68e50SBjoern A. Zeeb IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER| 4444adff403fSBjoern A. Zeeb IEEE80211_IFACE_ITER_ACTIVE|IEEE80211_IFACE_ITER__ATOMIC)) { 44456b4cac81SBjoern A. Zeeb ic_printf(lhw->ic, "XXX TODO %s flags(%#x) not yet supported.\n", 44466b4cac81SBjoern A. Zeeb __func__, flags); 44476b4cac81SBjoern A. Zeeb } 44486b4cac81SBjoern A. Zeeb 4449adff403fSBjoern A. Zeeb active = (flags & IEEE80211_IFACE_ITER_ACTIVE) != 0; 44506b4cac81SBjoern A. Zeeb atomic = (flags & IEEE80211_IFACE_ITER__ATOMIC) != 0; 445161a68e50SBjoern A. Zeeb nin_drv = (flags & IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER) != 0; 44526b4cac81SBjoern A. Zeeb 44536b4cac81SBjoern A. Zeeb if (atomic) 44548891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 44556b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 44566b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 44576b4cac81SBjoern A. Zeeb 44586b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 44596b4cac81SBjoern A. Zeeb 44606b4cac81SBjoern A. Zeeb /* 44616b4cac81SBjoern A. Zeeb * If we want "active" interfaces, we need to distinguish on 44626b4cac81SBjoern A. Zeeb * whether the driver knows about them or not to be able to 44636b4cac81SBjoern A. Zeeb * handle the "resume" case correctly. Skip the ones the 44646b4cac81SBjoern A. Zeeb * driver does not know about. 44656b4cac81SBjoern A. Zeeb */ 44666b4cac81SBjoern A. Zeeb if (active && !lvif->added_to_drv && 44676b4cac81SBjoern A. Zeeb (flags & IEEE80211_IFACE_ITER_RESUME_ALL) != 0) 44686b4cac81SBjoern A. Zeeb continue; 44696b4cac81SBjoern A. Zeeb 44706b4cac81SBjoern A. Zeeb /* 447161a68e50SBjoern A. Zeeb * If we shall skip interfaces not added to the driver do so 447261a68e50SBjoern A. Zeeb * if we haven't yet. 447361a68e50SBjoern A. Zeeb */ 447461a68e50SBjoern A. Zeeb if (nin_drv && !lvif->added_to_drv) 447561a68e50SBjoern A. Zeeb continue; 447661a68e50SBjoern A. Zeeb 447761a68e50SBjoern A. Zeeb /* 44786b4cac81SBjoern A. Zeeb * Run the iterator function if we are either not asking 44796b4cac81SBjoern A. Zeeb * asking for active only or if the VAP is "running". 44806b4cac81SBjoern A. Zeeb */ 44816b4cac81SBjoern A. Zeeb /* XXX-BZ probably should have state in the lvif as well. */ 44826b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 44836b4cac81SBjoern A. Zeeb if (!active || (vap->iv_state != IEEE80211_S_INIT)) 44846b4cac81SBjoern A. Zeeb iterfunc(arg, vif->addr, vif); 44856b4cac81SBjoern A. Zeeb } 44866b4cac81SBjoern A. Zeeb if (atomic) 44878891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 44886b4cac81SBjoern A. Zeeb } 44896b4cac81SBjoern A. Zeeb 44906b4cac81SBjoern A. Zeeb void 44916b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_keys(struct ieee80211_hw *hw, 44926b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif, 44936b4cac81SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_vif *, 44946b4cac81SBjoern A. Zeeb struct ieee80211_sta *, struct ieee80211_key_conf *, void *), 44956b4cac81SBjoern A. Zeeb void *arg) 44966b4cac81SBjoern A. Zeeb { 44976b4cac81SBjoern A. Zeeb 44986b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 44996b4cac81SBjoern A. Zeeb } 45006b4cac81SBjoern A. Zeeb 45016b4cac81SBjoern A. Zeeb void 45026b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_chan_contexts(struct ieee80211_hw *hw, 45036b4cac81SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_chanctx_conf *, 45046b4cac81SBjoern A. Zeeb void *), 45056b4cac81SBjoern A. Zeeb void *arg) 45066b4cac81SBjoern A. Zeeb { 4507c5e25798SBjoern A. Zeeb struct lkpi_hw *lhw; 4508c5e25798SBjoern A. Zeeb struct lkpi_vif *lvif; 4509c5e25798SBjoern A. Zeeb struct ieee80211_vif *vif; 4510c5e25798SBjoern A. Zeeb struct lkpi_chanctx *lchanctx; 45116b4cac81SBjoern A. Zeeb 4512c5e25798SBjoern A. Zeeb KASSERT(hw != NULL && iterfunc != NULL, 4513c5e25798SBjoern A. Zeeb ("%s: hw %p iterfunc %p arg %p\n", __func__, hw, iterfunc, arg)); 4514c5e25798SBjoern A. Zeeb 4515c5e25798SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 4516c5e25798SBjoern A. Zeeb 4517c5e25798SBjoern A. Zeeb IMPROVE("lchanctx should be its own list somewhere"); 4518c5e25798SBjoern A. Zeeb 4519c5e25798SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 4520c5e25798SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 4521c5e25798SBjoern A. Zeeb 4522c5e25798SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 4523c5e25798SBjoern A. Zeeb if (vif->chanctx_conf == NULL) 4524c5e25798SBjoern A. Zeeb continue; 4525c5e25798SBjoern A. Zeeb 4526c5e25798SBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(vif->chanctx_conf); 4527c5e25798SBjoern A. Zeeb if (!lchanctx->added_to_drv) 4528c5e25798SBjoern A. Zeeb continue; 4529c5e25798SBjoern A. Zeeb 4530c5e25798SBjoern A. Zeeb iterfunc(hw, &lchanctx->conf, arg); 4531c5e25798SBjoern A. Zeeb } 4532c5e25798SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 45336b4cac81SBjoern A. Zeeb } 45346b4cac81SBjoern A. Zeeb 45356b4cac81SBjoern A. Zeeb void 45366b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_stations_atomic(struct ieee80211_hw *hw, 45376b4cac81SBjoern A. Zeeb void (*iterfunc)(void *, struct ieee80211_sta *), void *arg) 45386b4cac81SBjoern A. Zeeb { 45396b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 45406b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 45416b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 45426b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 45436b4cac81SBjoern A. Zeeb 45446b4cac81SBjoern A. Zeeb KASSERT(hw != NULL && iterfunc != NULL, 45456b4cac81SBjoern A. Zeeb ("%s: hw %p iterfunc %p arg %p\n", __func__, hw, iterfunc, arg)); 45466b4cac81SBjoern A. Zeeb 45476b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 45486b4cac81SBjoern A. Zeeb 45498891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 45506b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 45516b4cac81SBjoern A. Zeeb 45526b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 45536b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lsta, &lvif->lsta_head, lsta_entry) { 45546b4cac81SBjoern A. Zeeb if (!lsta->added_to_drv) 45556b4cac81SBjoern A. Zeeb continue; 45566b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 45576b4cac81SBjoern A. Zeeb iterfunc(arg, sta); 45586b4cac81SBjoern A. Zeeb } 45596b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 45606b4cac81SBjoern A. Zeeb } 45618891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 45626b4cac81SBjoern A. Zeeb } 45636b4cac81SBjoern A. Zeeb 4564673d62fcSBjoern A. Zeeb struct linuxkpi_ieee80211_regdomain * 4565673d62fcSBjoern A. Zeeb lkpi_get_linuxkpi_ieee80211_regdomain(size_t n) 4566673d62fcSBjoern A. Zeeb { 4567673d62fcSBjoern A. Zeeb struct linuxkpi_ieee80211_regdomain *regd; 4568673d62fcSBjoern A. Zeeb 4569673d62fcSBjoern A. Zeeb regd = kzalloc(sizeof(*regd) + n * sizeof(struct ieee80211_reg_rule), 4570673d62fcSBjoern A. Zeeb GFP_KERNEL); 4571673d62fcSBjoern A. Zeeb return (regd); 4572673d62fcSBjoern A. Zeeb } 4573673d62fcSBjoern A. Zeeb 45746b4cac81SBjoern A. Zeeb int 45756b4cac81SBjoern A. Zeeb linuxkpi_regulatory_set_wiphy_regd_sync(struct wiphy *wiphy, 45766b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_regdomain *regd) 45776b4cac81SBjoern A. Zeeb { 45786b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 45796b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 45806b4cac81SBjoern A. Zeeb struct ieee80211_regdomain *rd; 45816b4cac81SBjoern A. Zeeb 45826b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 45836b4cac81SBjoern A. Zeeb ic = lhw->ic; 45846b4cac81SBjoern A. Zeeb 45856b4cac81SBjoern A. Zeeb rd = &ic->ic_regdomain; 45866b4cac81SBjoern A. Zeeb if (rd->isocc[0] == '\0') { 45876b4cac81SBjoern A. Zeeb rd->isocc[0] = regd->alpha2[0]; 45886b4cac81SBjoern A. Zeeb rd->isocc[1] = regd->alpha2[1]; 45896b4cac81SBjoern A. Zeeb } 45906b4cac81SBjoern A. Zeeb 45916b4cac81SBjoern A. Zeeb TODO(); 45926b4cac81SBjoern A. Zeeb /* XXX-BZ finish the rest. */ 45936b4cac81SBjoern A. Zeeb 45946b4cac81SBjoern A. Zeeb return (0); 45956b4cac81SBjoern A. Zeeb } 45966b4cac81SBjoern A. Zeeb 45976b4cac81SBjoern A. Zeeb void 45986b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_scan_completed(struct ieee80211_hw *hw, 45996b4cac81SBjoern A. Zeeb struct cfg80211_scan_info *info) 46006b4cac81SBjoern A. Zeeb { 46016b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 46026b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 46036b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 46046b4cac81SBjoern A. Zeeb 46056b4cac81SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 46066b4cac81SBjoern A. Zeeb ic = lhw->ic; 46076b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 46086b4cac81SBjoern A. Zeeb 46096b4cac81SBjoern A. Zeeb ieee80211_scan_done(ss->ss_vap); 46106b4cac81SBjoern A. Zeeb 46118ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 46126b4cac81SBjoern A. Zeeb free(lhw->hw_req, M_LKPI80211); 46136b4cac81SBjoern A. Zeeb lhw->hw_req = NULL; 4614a486fbbdSBjoern A. Zeeb lhw->scan_flags &= ~LKPI_LHW_SCAN_RUNNING; 46156b4cac81SBjoern A. Zeeb wakeup(lhw); 46168ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 46176b4cac81SBjoern A. Zeeb 46186b4cac81SBjoern A. Zeeb return; 46196b4cac81SBjoern A. Zeeb } 46206b4cac81SBjoern A. Zeeb 4621e30e05d3SBjoern A. Zeeb /* For %list see comment towards the end of the function. */ 46226b4cac81SBjoern A. Zeeb void 46236b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb, 4624e30e05d3SBjoern A. Zeeb struct ieee80211_sta *sta, struct napi_struct *napi __unused, 4625e30e05d3SBjoern A. Zeeb struct list_head *list __unused) 46266b4cac81SBjoern A. Zeeb { 46276b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 46286b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 46296b4cac81SBjoern A. Zeeb struct mbuf *m; 46306b4cac81SBjoern A. Zeeb struct skb_shared_info *shinfo; 46316b4cac81SBjoern A. Zeeb struct ieee80211_rx_status *rx_status; 46326b4cac81SBjoern A. Zeeb struct ieee80211_rx_stats rx_stats; 46336b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 46346b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 46356b4cac81SBjoern A. Zeeb struct ieee80211_hdr *hdr; 46366b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 46379d9ba2b7SBjoern A. Zeeb int i, offset, ok; 4638170acccfSBjoern A. Zeeb int8_t rssi; 4639c0cadd99SBjoern A. Zeeb bool is_beacon; 46406b4cac81SBjoern A. Zeeb 46416b4cac81SBjoern A. Zeeb if (skb->len < 2) { 46426b4cac81SBjoern A. Zeeb /* Need 80211 stats here. */ 46436b4cac81SBjoern A. Zeeb IMPROVE(); 46446b4cac81SBjoern A. Zeeb goto err; 46456b4cac81SBjoern A. Zeeb } 46466b4cac81SBjoern A. Zeeb 46476b4cac81SBjoern A. Zeeb /* 46486b4cac81SBjoern A. Zeeb * For now do the data copy; we can later improve things. Might even 46496b4cac81SBjoern A. Zeeb * have an mbuf backing the skb data then? 46506b4cac81SBjoern A. Zeeb */ 46516b4cac81SBjoern A. Zeeb m = m_get2(skb->len, M_NOWAIT, MT_DATA, M_PKTHDR); 46526b4cac81SBjoern A. Zeeb if (m == NULL) 46536b4cac81SBjoern A. Zeeb goto err; 46546b4cac81SBjoern A. Zeeb m_copyback(m, 0, skb->tail - skb->data, skb->data); 46556b4cac81SBjoern A. Zeeb 46566b4cac81SBjoern A. Zeeb shinfo = skb_shinfo(skb); 46576b4cac81SBjoern A. Zeeb offset = m->m_len; 46586b4cac81SBjoern A. Zeeb for (i = 0; i < shinfo->nr_frags; i++) { 46596b4cac81SBjoern A. Zeeb m_copyback(m, offset, shinfo->frags[i].size, 46606b4cac81SBjoern A. Zeeb (uint8_t *)linux_page_address(shinfo->frags[i].page) + 46616b4cac81SBjoern A. Zeeb shinfo->frags[i].offset); 46626b4cac81SBjoern A. Zeeb offset += shinfo->frags[i].size; 46636b4cac81SBjoern A. Zeeb } 46646b4cac81SBjoern A. Zeeb 46656b4cac81SBjoern A. Zeeb rx_status = IEEE80211_SKB_RXCB(skb); 46666b4cac81SBjoern A. Zeeb 46676b4cac81SBjoern A. Zeeb hdr = (void *)skb->data; 4668c0cadd99SBjoern A. Zeeb is_beacon = ieee80211_is_beacon(hdr->frame_control); 4669c0cadd99SBjoern A. Zeeb 4670c0cadd99SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 46719d9ba2b7SBjoern A. Zeeb if (is_beacon && (linuxkpi_debug_80211 & D80211_TRACE_RX_BEACONS) == 0) 46726b4cac81SBjoern A. Zeeb goto no_trace_beacons; 46736b4cac81SBjoern A. Zeeb 46749d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 46756b4cac81SBjoern A. Zeeb printf("TRACE-RX: %s: skb %p a/l/d/t-len (%u/%u/%u/%u) " 4676c0cadd99SBjoern A. Zeeb "h %p d %p t %p e %p sh %p (%u) m %p plen %u len %u%s\n", 46776b4cac81SBjoern A. Zeeb __func__, skb, skb->_alloc_len, skb->len, skb->data_len, 46786b4cac81SBjoern A. Zeeb skb->truesize, skb->head, skb->data, skb->tail, skb->end, 46796b4cac81SBjoern A. Zeeb shinfo, shinfo->nr_frags, 4680c0cadd99SBjoern A. Zeeb m, m->m_pkthdr.len, m->m_len, is_beacon ? " beacon" : ""); 46816b4cac81SBjoern A. Zeeb 46829d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX_DUMP) 46836b4cac81SBjoern A. Zeeb hexdump(mtod(m, const void *), m->m_len, "RX (raw) ", 0); 46846b4cac81SBjoern A. Zeeb 46856b4cac81SBjoern A. Zeeb /* Implement a dump_rxcb() !!! */ 46869d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 4687c8dafefaSBjoern A. Zeeb printf("TRACE %s: RXCB: %ju %ju %u, %#0x, %u, %#0x, %#0x, " 468860970a32SBjoern A. Zeeb "%u band %u, %u { %d %d %d %d }, %d, %#x %#x %#x %#x %u %u %u\n", 46896b4cac81SBjoern A. Zeeb __func__, 4690c8dafefaSBjoern A. Zeeb (uintmax_t)rx_status->boottime_ns, 4691c8dafefaSBjoern A. Zeeb (uintmax_t)rx_status->mactime, 46926b4cac81SBjoern A. Zeeb rx_status->device_timestamp, 46936b4cac81SBjoern A. Zeeb rx_status->flag, 46946b4cac81SBjoern A. Zeeb rx_status->freq, 46956b4cac81SBjoern A. Zeeb rx_status->bw, 46966b4cac81SBjoern A. Zeeb rx_status->encoding, 46976b4cac81SBjoern A. Zeeb rx_status->ampdu_reference, 46986b4cac81SBjoern A. Zeeb rx_status->band, 46996b4cac81SBjoern A. Zeeb rx_status->chains, 47006b4cac81SBjoern A. Zeeb rx_status->chain_signal[0], 47016b4cac81SBjoern A. Zeeb rx_status->chain_signal[1], 47026b4cac81SBjoern A. Zeeb rx_status->chain_signal[2], 470360970a32SBjoern A. Zeeb rx_status->chain_signal[3], 47046b4cac81SBjoern A. Zeeb rx_status->signal, 47056b4cac81SBjoern A. Zeeb rx_status->enc_flags, 47066b4cac81SBjoern A. Zeeb rx_status->he_dcm, 47076b4cac81SBjoern A. Zeeb rx_status->he_gi, 47086b4cac81SBjoern A. Zeeb rx_status->he_ru, 47096b4cac81SBjoern A. Zeeb rx_status->zero_length_psdu_type, 47106b4cac81SBjoern A. Zeeb rx_status->nss, 47116b4cac81SBjoern A. Zeeb rx_status->rate_idx); 47126b4cac81SBjoern A. Zeeb no_trace_beacons: 47136b4cac81SBjoern A. Zeeb #endif 47146b4cac81SBjoern A. Zeeb 47156b4cac81SBjoern A. Zeeb memset(&rx_stats, 0, sizeof(rx_stats)); 47166b4cac81SBjoern A. Zeeb rx_stats.r_flags = IEEE80211_R_NF | IEEE80211_R_RSSI; 471760970a32SBjoern A. Zeeb /* XXX-BZ correct hardcoded rssi and noise floor, how? survey? */ 471860970a32SBjoern A. Zeeb rx_stats.c_nf = -96; 47196b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, SIGNAL_DBM) && 47206b4cac81SBjoern A. Zeeb !(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL)) 4721170acccfSBjoern A. Zeeb rssi = rx_status->signal; 47226b4cac81SBjoern A. Zeeb else 4723170acccfSBjoern A. Zeeb rssi = rx_stats.c_nf; 4724170acccfSBjoern A. Zeeb /* 4725170acccfSBjoern A. Zeeb * net80211 signal strength data are in .5 dBm units relative to 4726170acccfSBjoern A. Zeeb * the current noise floor (see comment in ieee80211_node.h). 4727170acccfSBjoern A. Zeeb */ 4728170acccfSBjoern A. Zeeb rssi -= rx_stats.c_nf; 4729170acccfSBjoern A. Zeeb rx_stats.c_rssi = rssi * 2; 47306b4cac81SBjoern A. Zeeb rx_stats.r_flags |= IEEE80211_R_BAND; 47316b4cac81SBjoern A. Zeeb rx_stats.c_band = 47326b4cac81SBjoern A. Zeeb lkpi_nl80211_band_to_net80211_band(rx_status->band); 47336b4cac81SBjoern A. Zeeb rx_stats.r_flags |= IEEE80211_R_FREQ | IEEE80211_R_IEEE; 47346b4cac81SBjoern A. Zeeb rx_stats.c_freq = rx_status->freq; 47356b4cac81SBjoern A. Zeeb rx_stats.c_ieee = ieee80211_mhz2ieee(rx_stats.c_freq, rx_stats.c_band); 47366b4cac81SBjoern A. Zeeb 47376b4cac81SBjoern A. Zeeb /* XXX (*sta_statistics)() to get to some of that? */ 47386b4cac81SBjoern A. Zeeb /* XXX-BZ dump the FreeBSD version of rx_stats as well! */ 47396b4cac81SBjoern A. Zeeb 47406b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 47416b4cac81SBjoern A. Zeeb ic = lhw->ic; 47426b4cac81SBjoern A. Zeeb 47436b4cac81SBjoern A. Zeeb ok = ieee80211_add_rx_params(m, &rx_stats); 47446b4cac81SBjoern A. Zeeb if (ok == 0) { 4745dbc06dd9SBjoern A. Zeeb m_freem(m); 47466b4cac81SBjoern A. Zeeb counter_u64_add(ic->ic_ierrors, 1); 47476b4cac81SBjoern A. Zeeb goto err; 47486b4cac81SBjoern A. Zeeb } 47496b4cac81SBjoern A. Zeeb 47506b4cac81SBjoern A. Zeeb if (sta != NULL) { 47516b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 47526b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(lsta->ni); 47536b4cac81SBjoern A. Zeeb } else { 4754c8dafefaSBjoern A. Zeeb struct ieee80211_frame_min *wh; 4755c8dafefaSBjoern A. Zeeb 47566b4cac81SBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame_min *); 47576b4cac81SBjoern A. Zeeb ni = ieee80211_find_rxnode(ic, wh); 47586b4cac81SBjoern A. Zeeb if (ni != NULL) 47596b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 47606b4cac81SBjoern A. Zeeb } 47616b4cac81SBjoern A. Zeeb 47626b4cac81SBjoern A. Zeeb if (ni != NULL) 47636b4cac81SBjoern A. Zeeb vap = ni->ni_vap; 47646b4cac81SBjoern A. Zeeb else 47656b4cac81SBjoern A. Zeeb /* 47666b4cac81SBjoern A. Zeeb * XXX-BZ can we improve this by looking at the frame hdr 47676b4cac81SBjoern A. Zeeb * or other meta-data passed up? 47686b4cac81SBjoern A. Zeeb */ 47696b4cac81SBjoern A. Zeeb vap = TAILQ_FIRST(&ic->ic_vaps); 47706b4cac81SBjoern A. Zeeb 47719d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 47729d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 4773c0cadd99SBjoern A. Zeeb printf("TRACE %s: sta %p lsta %p state %d ni %p vap %p%s\n", 4774c0cadd99SBjoern A. Zeeb __func__, sta, lsta, (lsta != NULL) ? lsta->state : -1, 4775c0cadd99SBjoern A. Zeeb ni, vap, is_beacon ? " beacon" : ""); 47769d9ba2b7SBjoern A. Zeeb #endif 47776b4cac81SBjoern A. Zeeb 4778c0cadd99SBjoern A. Zeeb if (ni != NULL && vap != NULL && is_beacon && 4779c8dafefaSBjoern A. Zeeb rx_status->device_timestamp > 0 && 4780c8dafefaSBjoern A. Zeeb m->m_pkthdr.len >= sizeof(struct ieee80211_frame)) { 4781c8dafefaSBjoern A. Zeeb struct lkpi_vif *lvif; 4782c8dafefaSBjoern A. Zeeb struct ieee80211_vif *vif; 4783c8dafefaSBjoern A. Zeeb struct ieee80211_frame *wh; 4784c8dafefaSBjoern A. Zeeb 4785c8dafefaSBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame *); 4786c8dafefaSBjoern A. Zeeb if (!IEEE80211_ADDR_EQ(wh->i_addr2, ni->ni_bssid)) 4787c8dafefaSBjoern A. Zeeb goto skip_device_ts; 4788c8dafefaSBjoern A. Zeeb 4789c8dafefaSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 4790c8dafefaSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 4791c8dafefaSBjoern A. Zeeb 4792c8dafefaSBjoern A. Zeeb IMPROVE("TIMING_BEACON_ONLY?"); 4793c8dafefaSBjoern A. Zeeb /* mac80211 specific (not net80211) so keep it here. */ 4794c8dafefaSBjoern A. Zeeb vif->bss_conf.sync_device_ts = rx_status->device_timestamp; 4795c8dafefaSBjoern A. Zeeb /* 4796c8dafefaSBjoern A. Zeeb * net80211 should take care of the other information (sync_tsf, 4797c8dafefaSBjoern A. Zeeb * sync_dtim_count) as otherwise we need to parse the beacon. 4798c8dafefaSBjoern A. Zeeb */ 4799c8dafefaSBjoern A. Zeeb skip_device_ts: 48009fb91463SBjoern A. Zeeb ; 48019fb91463SBjoern A. Zeeb } 4802c8dafefaSBjoern A. Zeeb 48036b4cac81SBjoern A. Zeeb if (vap != NULL && vap->iv_state > IEEE80211_S_INIT && 48046b4cac81SBjoern A. Zeeb ieee80211_radiotap_active_vap(vap)) { 48056b4cac81SBjoern A. Zeeb struct lkpi_radiotap_rx_hdr *rtap; 48066b4cac81SBjoern A. Zeeb 48076b4cac81SBjoern A. Zeeb rtap = &lhw->rtap_rx; 48086b4cac81SBjoern A. Zeeb rtap->wr_tsft = rx_status->device_timestamp; 48096b4cac81SBjoern A. Zeeb rtap->wr_flags = 0; 48106b4cac81SBjoern A. Zeeb if (rx_status->enc_flags & RX_ENC_FLAG_SHORTPRE) 48116b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; 48126b4cac81SBjoern A. Zeeb if (rx_status->enc_flags & RX_ENC_FLAG_SHORT_GI) 48136b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTGI; 48146b4cac81SBjoern A. Zeeb #if 0 /* .. or it does not given we strip it below. */ 48156b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, RX_INCLUDES_FCS)) 48166b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_FCS; 48176b4cac81SBjoern A. Zeeb #endif 48186b4cac81SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_FAILED_FCS_CRC) 48196b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_BADFCS; 48206b4cac81SBjoern A. Zeeb rtap->wr_rate = 0; 48216b4cac81SBjoern A. Zeeb IMPROVE(); 48226b4cac81SBjoern A. Zeeb /* XXX TODO status->encoding / rate_index / bw */ 48236b4cac81SBjoern A. Zeeb rtap->wr_chan_freq = htole16(rx_stats.c_freq); 48246b4cac81SBjoern A. Zeeb if (ic->ic_curchan->ic_ieee == rx_stats.c_ieee) 48256b4cac81SBjoern A. Zeeb rtap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags); 4826170acccfSBjoern A. Zeeb rtap->wr_dbm_antsignal = rssi; 48276b4cac81SBjoern A. Zeeb rtap->wr_dbm_antnoise = rx_stats.c_nf; 48286b4cac81SBjoern A. Zeeb } 48296b4cac81SBjoern A. Zeeb 48306b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, RX_INCLUDES_FCS)) 48316b4cac81SBjoern A. Zeeb m_adj(m, -IEEE80211_CRC_LEN); 48326b4cac81SBjoern A. Zeeb 4833e30e05d3SBjoern A. Zeeb #if 0 4834e30e05d3SBjoern A. Zeeb if (list != NULL) { 4835e30e05d3SBjoern A. Zeeb /* 4836e30e05d3SBjoern A. Zeeb * Normally this would be queued up and delivered by 4837e30e05d3SBjoern A. Zeeb * netif_receive_skb_list(), napi_gro_receive(), or the like. 4838e30e05d3SBjoern A. Zeeb * See mt76::mac80211.c as only current possible consumer. 4839e30e05d3SBjoern A. Zeeb */ 4840e30e05d3SBjoern A. Zeeb IMPROVE("we simply pass the packet to net80211 to deal with."); 4841e30e05d3SBjoern A. Zeeb } 4842e30e05d3SBjoern A. Zeeb #endif 4843e30e05d3SBjoern A. Zeeb 48446b4cac81SBjoern A. Zeeb if (ni != NULL) { 48459d9ba2b7SBjoern A. Zeeb ok = ieee80211_input_mimo(ni, m); 48466b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 4847dbc06dd9SBjoern A. Zeeb if (ok < 0) 4848dbc06dd9SBjoern A. Zeeb m_freem(m); 48496b4cac81SBjoern A. Zeeb } else { 48509d9ba2b7SBjoern A. Zeeb ok = ieee80211_input_mimo_all(ic, m); 4851dbc06dd9SBjoern A. Zeeb /* mbuf got consumed. */ 48526b4cac81SBjoern A. Zeeb } 48536b4cac81SBjoern A. Zeeb 48549d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 48559d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 48569d9ba2b7SBjoern A. Zeeb printf("TRACE %s: handled frame type %#0x\n", __func__, ok); 48579d9ba2b7SBjoern A. Zeeb #endif 48586b4cac81SBjoern A. Zeeb 48596b4cac81SBjoern A. Zeeb IMPROVE(); 48606b4cac81SBjoern A. Zeeb 48616b4cac81SBjoern A. Zeeb err: 48626b4cac81SBjoern A. Zeeb /* The skb is ours so we can free it :-) */ 48636b4cac81SBjoern A. Zeeb kfree_skb(skb); 48646b4cac81SBjoern A. Zeeb } 48656b4cac81SBjoern A. Zeeb 48666b4cac81SBjoern A. Zeeb uint8_t 4867ec190d91SBjoern A. Zeeb linuxkpi_ieee80211_get_tid(struct ieee80211_hdr *hdr, bool nonqos_ok) 48686b4cac81SBjoern A. Zeeb { 48696b4cac81SBjoern A. Zeeb const struct ieee80211_frame *wh; 4870ec190d91SBjoern A. Zeeb uint8_t tid; 4871ec190d91SBjoern A. Zeeb 4872ec190d91SBjoern A. Zeeb /* Linux seems to assume this is a QOS-Data-Frame */ 4873ec190d91SBjoern A. Zeeb KASSERT(nonqos_ok || ieee80211_is_data_qos(hdr->frame_control), 4874ec190d91SBjoern A. Zeeb ("%s: hdr %p fc %#06x not qos_data\n", __func__, hdr, 4875ec190d91SBjoern A. Zeeb hdr->frame_control)); 48766b4cac81SBjoern A. Zeeb 48776b4cac81SBjoern A. Zeeb wh = (const struct ieee80211_frame *)hdr; 4878ec190d91SBjoern A. Zeeb tid = ieee80211_gettid(wh); 4879ec190d91SBjoern A. Zeeb KASSERT(nonqos_ok || tid == (tid & IEEE80211_QOS_TID), ("%s: tid %u " 4880ec190d91SBjoern A. Zeeb "not expected (%u?)\n", __func__, tid, IEEE80211_NONQOS_TID)); 4881ec190d91SBjoern A. Zeeb 4882ec190d91SBjoern A. Zeeb return (tid); 48836b4cac81SBjoern A. Zeeb } 48846b4cac81SBjoern A. Zeeb 48856b4cac81SBjoern A. Zeeb struct wiphy * 48866b4cac81SBjoern A. Zeeb linuxkpi_wiphy_new(const struct cfg80211_ops *ops, size_t priv_len) 48876b4cac81SBjoern A. Zeeb { 48886b4cac81SBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 48896b4cac81SBjoern A. Zeeb 48906b4cac81SBjoern A. Zeeb lwiphy = kzalloc(sizeof(*lwiphy) + priv_len, GFP_KERNEL); 48916b4cac81SBjoern A. Zeeb if (lwiphy == NULL) 48926b4cac81SBjoern A. Zeeb return (NULL); 48936b4cac81SBjoern A. Zeeb lwiphy->ops = ops; 48946b4cac81SBjoern A. Zeeb 48956b4cac81SBjoern A. Zeeb /* XXX TODO */ 48966b4cac81SBjoern A. Zeeb return (LWIPHY_TO_WIPHY(lwiphy)); 48976b4cac81SBjoern A. Zeeb } 48986b4cac81SBjoern A. Zeeb 48996b4cac81SBjoern A. Zeeb void 49006b4cac81SBjoern A. Zeeb linuxkpi_wiphy_free(struct wiphy *wiphy) 49016b4cac81SBjoern A. Zeeb { 49026b4cac81SBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 49036b4cac81SBjoern A. Zeeb 49046b4cac81SBjoern A. Zeeb if (wiphy == NULL) 49056b4cac81SBjoern A. Zeeb return; 49066b4cac81SBjoern A. Zeeb 49076b4cac81SBjoern A. Zeeb lwiphy = WIPHY_TO_LWIPHY(wiphy); 49086b4cac81SBjoern A. Zeeb kfree(lwiphy); 49096b4cac81SBjoern A. Zeeb } 49106b4cac81SBjoern A. Zeeb 49116b4cac81SBjoern A. Zeeb uint32_t 49126b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_channel_to_frequency(uint32_t channel, 49136b4cac81SBjoern A. Zeeb enum nl80211_band band) 49146b4cac81SBjoern A. Zeeb { 49156b4cac81SBjoern A. Zeeb 49166b4cac81SBjoern A. Zeeb switch (band) { 49176b4cac81SBjoern A. Zeeb case NL80211_BAND_2GHZ: 49186b4cac81SBjoern A. Zeeb return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_2GHZ)); 49196b4cac81SBjoern A. Zeeb break; 49206b4cac81SBjoern A. Zeeb case NL80211_BAND_5GHZ: 49216b4cac81SBjoern A. Zeeb return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_5GHZ)); 49226b4cac81SBjoern A. Zeeb break; 49236b4cac81SBjoern A. Zeeb default: 49246b4cac81SBjoern A. Zeeb /* XXX abort, retry, error, panic? */ 49256b4cac81SBjoern A. Zeeb break; 49266b4cac81SBjoern A. Zeeb } 49276b4cac81SBjoern A. Zeeb 49286b4cac81SBjoern A. Zeeb return (0); 49296b4cac81SBjoern A. Zeeb } 49306b4cac81SBjoern A. Zeeb 49316b4cac81SBjoern A. Zeeb uint32_t 49326b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_frequency_to_channel(uint32_t freq, uint32_t flags __unused) 49336b4cac81SBjoern A. Zeeb { 49346b4cac81SBjoern A. Zeeb 49356b4cac81SBjoern A. Zeeb return (ieee80211_mhz2ieee(freq, 0)); 49366b4cac81SBjoern A. Zeeb } 49376b4cac81SBjoern A. Zeeb 49386b4cac81SBjoern A. Zeeb static struct lkpi_sta * 49396b4cac81SBjoern A. Zeeb lkpi_find_lsta_by_ni(struct lkpi_vif *lvif, struct ieee80211_node *ni) 49406b4cac81SBjoern A. Zeeb { 49416b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta, *temp; 49426b4cac81SBjoern A. Zeeb 49436b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 49446b4cac81SBjoern A. Zeeb TAILQ_FOREACH_SAFE(lsta, &lvif->lsta_head, lsta_entry, temp) { 49456b4cac81SBjoern A. Zeeb if (lsta->ni == ni) { 49466b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 49476b4cac81SBjoern A. Zeeb return (lsta); 49486b4cac81SBjoern A. Zeeb } 49496b4cac81SBjoern A. Zeeb } 49506b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 49516b4cac81SBjoern A. Zeeb 49526b4cac81SBjoern A. Zeeb return (NULL); 49536b4cac81SBjoern A. Zeeb } 49546b4cac81SBjoern A. Zeeb 49556b4cac81SBjoern A. Zeeb struct ieee80211_sta * 49566b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_find_sta(struct ieee80211_vif *vif, const u8 *peer) 49576b4cac81SBjoern A. Zeeb { 49586b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 49596b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta, *temp; 49606b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 49616b4cac81SBjoern A. Zeeb 49626b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 49636b4cac81SBjoern A. Zeeb 49646b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 49656b4cac81SBjoern A. Zeeb TAILQ_FOREACH_SAFE(lsta, &lvif->lsta_head, lsta_entry, temp) { 49666b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 49676b4cac81SBjoern A. Zeeb if (IEEE80211_ADDR_EQ(sta->addr, peer)) { 49686b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 49696b4cac81SBjoern A. Zeeb return (sta); 49706b4cac81SBjoern A. Zeeb } 49716b4cac81SBjoern A. Zeeb } 49726b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 49736b4cac81SBjoern A. Zeeb return (NULL); 49746b4cac81SBjoern A. Zeeb } 49756b4cac81SBjoern A. Zeeb 49766b4cac81SBjoern A. Zeeb struct ieee80211_sta * 49772e183d99SBjoern A. Zeeb linuxkpi_ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw, 49782e183d99SBjoern A. Zeeb const uint8_t *addr, const uint8_t *ourvifaddr) 49796b4cac81SBjoern A. Zeeb { 49806b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 49816b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 49826b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 49836b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 49846b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 49856b4cac81SBjoern A. Zeeb 49866b4cac81SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 49876b4cac81SBjoern A. Zeeb sta = NULL; 49886b4cac81SBjoern A. Zeeb 49898891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 49906b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 49916b4cac81SBjoern A. Zeeb 49926b4cac81SBjoern A. Zeeb /* XXX-BZ check our address from the vif. */ 49936b4cac81SBjoern A. Zeeb 49946b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 49956b4cac81SBjoern A. Zeeb if (ourvifaddr != NULL && 49966b4cac81SBjoern A. Zeeb !IEEE80211_ADDR_EQ(vif->addr, ourvifaddr)) 49976b4cac81SBjoern A. Zeeb continue; 49986b4cac81SBjoern A. Zeeb sta = linuxkpi_ieee80211_find_sta(vif, addr); 49996b4cac81SBjoern A. Zeeb if (sta != NULL) 50006b4cac81SBjoern A. Zeeb break; 50016b4cac81SBjoern A. Zeeb } 50028891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 50036b4cac81SBjoern A. Zeeb 50046b4cac81SBjoern A. Zeeb if (sta != NULL) { 50056b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 50066b4cac81SBjoern A. Zeeb if (!lsta->added_to_drv) 50076b4cac81SBjoern A. Zeeb return (NULL); 50086b4cac81SBjoern A. Zeeb } 50096b4cac81SBjoern A. Zeeb 50106b4cac81SBjoern A. Zeeb return (sta); 50116b4cac81SBjoern A. Zeeb } 50126b4cac81SBjoern A. Zeeb 50136b4cac81SBjoern A. Zeeb struct sk_buff * 50146b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_tx_dequeue(struct ieee80211_hw *hw, 50156b4cac81SBjoern A. Zeeb struct ieee80211_txq *txq) 50166b4cac81SBjoern A. Zeeb { 50176b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 50180cbcfa19SBjoern A. Zeeb struct lkpi_vif *lvif; 50196b4cac81SBjoern A. Zeeb struct sk_buff *skb; 50206b4cac81SBjoern A. Zeeb 50210cbcfa19SBjoern A. Zeeb skb = NULL; 50226b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 50236b4cac81SBjoern A. Zeeb ltxq->seen_dequeue = true; 50246b4cac81SBjoern A. Zeeb 50250cbcfa19SBjoern A. Zeeb if (ltxq->stopped) 50260cbcfa19SBjoern A. Zeeb goto stopped; 50270cbcfa19SBjoern A. Zeeb 50280cbcfa19SBjoern A. Zeeb lvif = VIF_TO_LVIF(ltxq->txq.vif); 50290cbcfa19SBjoern A. Zeeb if (lvif->hw_queue_stopped[ltxq->txq.ac]) { 50300cbcfa19SBjoern A. Zeeb ltxq->stopped = true; 50310cbcfa19SBjoern A. Zeeb goto stopped; 50320cbcfa19SBjoern A. Zeeb } 50330cbcfa19SBjoern A. Zeeb 5034*eac3646fSBjoern A. Zeeb IMPROVE("hw(TX_FRAG_LIST)"); 5035*eac3646fSBjoern A. Zeeb 5036*eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_LOCK(ltxq); 50376b4cac81SBjoern A. Zeeb skb = skb_dequeue(<xq->skbq); 5038*eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_UNLOCK(ltxq); 50396b4cac81SBjoern A. Zeeb 50400cbcfa19SBjoern A. Zeeb stopped: 50416b4cac81SBjoern A. Zeeb return (skb); 50426b4cac81SBjoern A. Zeeb } 50436b4cac81SBjoern A. Zeeb 50446b4cac81SBjoern A. Zeeb void 50456b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_txq_get_depth(struct ieee80211_txq *txq, 504686220d3cSBjoern A. Zeeb unsigned long *frame_cnt, unsigned long *byte_cnt) 50476b4cac81SBjoern A. Zeeb { 50486b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 50496b4cac81SBjoern A. Zeeb struct sk_buff *skb; 505086220d3cSBjoern A. Zeeb unsigned long fc, bc; 50516b4cac81SBjoern A. Zeeb 50526b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 50536b4cac81SBjoern A. Zeeb 50546b4cac81SBjoern A. Zeeb fc = bc = 0; 5055*eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_LOCK(ltxq); 50566b4cac81SBjoern A. Zeeb skb_queue_walk(<xq->skbq, skb) { 50576b4cac81SBjoern A. Zeeb fc++; 50586b4cac81SBjoern A. Zeeb bc += skb->len; 50596b4cac81SBjoern A. Zeeb } 5060*eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_UNLOCK(ltxq); 50616b4cac81SBjoern A. Zeeb if (frame_cnt) 50626b4cac81SBjoern A. Zeeb *frame_cnt = fc; 50636b4cac81SBjoern A. Zeeb if (byte_cnt) 50646b4cac81SBjoern A. Zeeb *byte_cnt = bc; 50656b4cac81SBjoern A. Zeeb 50666b4cac81SBjoern A. Zeeb /* Validate that this is doing the correct thing. */ 50676b4cac81SBjoern A. Zeeb /* Should we keep track on en/dequeue? */ 50686b4cac81SBjoern A. Zeeb IMPROVE(); 50696b4cac81SBjoern A. Zeeb } 50706b4cac81SBjoern A. Zeeb 50716b4cac81SBjoern A. Zeeb /* 50726b4cac81SBjoern A. Zeeb * We are called from ieee80211_free_txskb() or ieee80211_tx_status(). 50736b4cac81SBjoern A. Zeeb * The latter tries to derive the success status from the info flags 50746b4cac81SBjoern A. Zeeb * passed back from the driver. rawx_mit() saves the ni on the m and the 50756b4cac81SBjoern A. Zeeb * m on the skb for us to be able to give feedback to net80211. 50766b4cac81SBjoern A. Zeeb */ 5077a8397571SBjoern A. Zeeb static void 5078a8397571SBjoern A. Zeeb _lkpi_ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb, 50796b4cac81SBjoern A. Zeeb int status) 50806b4cac81SBjoern A. Zeeb { 50816b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 50826b4cac81SBjoern A. Zeeb struct mbuf *m; 50836b4cac81SBjoern A. Zeeb 50846b4cac81SBjoern A. Zeeb m = skb->m; 50856b4cac81SBjoern A. Zeeb skb->m = NULL; 50866b4cac81SBjoern A. Zeeb 50876b4cac81SBjoern A. Zeeb if (m != NULL) { 50886b4cac81SBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 50896b4cac81SBjoern A. Zeeb /* Status: 0 is ok, != 0 is error. */ 50906b4cac81SBjoern A. Zeeb ieee80211_tx_complete(ni, m, status); 50916b4cac81SBjoern A. Zeeb /* ni & mbuf were consumed. */ 50926b4cac81SBjoern A. Zeeb } 5093a8397571SBjoern A. Zeeb } 50946b4cac81SBjoern A. Zeeb 5095a8397571SBjoern A. Zeeb void 5096a8397571SBjoern A. Zeeb linuxkpi_ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb, 5097a8397571SBjoern A. Zeeb int status) 5098a8397571SBjoern A. Zeeb { 5099a8397571SBjoern A. Zeeb 5100a8397571SBjoern A. Zeeb _lkpi_ieee80211_free_txskb(hw, skb, status); 51016b4cac81SBjoern A. Zeeb kfree_skb(skb); 51026b4cac81SBjoern A. Zeeb } 51036b4cac81SBjoern A. Zeeb 5104383b3e8fSBjoern A. Zeeb void 5105a8397571SBjoern A. Zeeb linuxkpi_ieee80211_tx_status_ext(struct ieee80211_hw *hw, 5106a8397571SBjoern A. Zeeb struct ieee80211_tx_status *txstat) 5107383b3e8fSBjoern A. Zeeb { 5108a8397571SBjoern A. Zeeb struct sk_buff *skb; 5109383b3e8fSBjoern A. Zeeb struct ieee80211_tx_info *info; 5110383b3e8fSBjoern A. Zeeb struct ieee80211_ratectl_tx_status txs; 5111383b3e8fSBjoern A. Zeeb struct ieee80211_node *ni; 5112383b3e8fSBjoern A. Zeeb int status; 5113383b3e8fSBjoern A. Zeeb 5114a8397571SBjoern A. Zeeb skb = txstat->skb; 5115383b3e8fSBjoern A. Zeeb if (skb->m != NULL) { 5116383b3e8fSBjoern A. Zeeb struct mbuf *m; 5117383b3e8fSBjoern A. Zeeb 5118383b3e8fSBjoern A. Zeeb m = skb->m; 5119383b3e8fSBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 5120383b3e8fSBjoern A. Zeeb memset(&txs, 0, sizeof(txs)); 5121383b3e8fSBjoern A. Zeeb } else { 5122383b3e8fSBjoern A. Zeeb ni = NULL; 5123383b3e8fSBjoern A. Zeeb } 5124383b3e8fSBjoern A. Zeeb 5125a8397571SBjoern A. Zeeb info = txstat->info; 5126383b3e8fSBjoern A. Zeeb if (info->flags & IEEE80211_TX_STAT_ACK) { 5127383b3e8fSBjoern A. Zeeb status = 0; /* No error. */ 5128383b3e8fSBjoern A. Zeeb txs.status = IEEE80211_RATECTL_TX_SUCCESS; 5129383b3e8fSBjoern A. Zeeb } else { 5130383b3e8fSBjoern A. Zeeb status = 1; 5131383b3e8fSBjoern A. Zeeb txs.status = IEEE80211_RATECTL_TX_FAIL_UNSPECIFIED; 5132383b3e8fSBjoern A. Zeeb } 5133383b3e8fSBjoern A. Zeeb 5134383b3e8fSBjoern A. Zeeb if (ni != NULL) { 5135e2c5ab09SJohn Baldwin int ridx __unused; 5136383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 5137383b3e8fSBjoern A. Zeeb int old_rate; 5138383b3e8fSBjoern A. Zeeb 5139383b3e8fSBjoern A. Zeeb old_rate = ni->ni_vap->iv_bss->ni_txrate; 5140383b3e8fSBjoern A. Zeeb #endif 5141383b3e8fSBjoern A. Zeeb txs.pktlen = skb->len; 5142383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_PKTLEN; 5143383b3e8fSBjoern A. Zeeb if (info->status.rates[0].count > 1) { 5144383b3e8fSBjoern A. Zeeb txs.long_retries = info->status.rates[0].count - 1; /* 1 + retries in drivers. */ 5145383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_LONG_RETRY; 5146383b3e8fSBjoern A. Zeeb } 5147383b3e8fSBjoern A. Zeeb #if 0 /* Unused in net80211 currently. */ 5148a8397571SBjoern A. Zeeb /* XXX-BZ convert check .flags for MCS/VHT/.. */ 5149383b3e8fSBjoern A. Zeeb txs.final_rate = info->status.rates[0].idx; 5150383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_FINAL_RATE; 5151383b3e8fSBjoern A. Zeeb #endif 5152adff403fSBjoern A. Zeeb if (info->status.flags & IEEE80211_TX_STATUS_ACK_SIGNAL_VALID) { 5153383b3e8fSBjoern A. Zeeb txs.rssi = info->status.ack_signal; /* XXX-BZ CONVERT? */ 5154383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_RSSI; 5155383b3e8fSBjoern A. Zeeb } 5156383b3e8fSBjoern A. Zeeb 5157383b3e8fSBjoern A. Zeeb IMPROVE("only update of rate matches but that requires us to get a proper rate"); 5158383b3e8fSBjoern A. Zeeb ieee80211_ratectl_tx_complete(ni, &txs); 5159383b3e8fSBjoern A. Zeeb ridx = ieee80211_ratectl_rate(ni->ni_vap->iv_bss, NULL, 0); 5160383b3e8fSBjoern A. Zeeb 5161383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 5162383b3e8fSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) { 5163383b3e8fSBjoern A. Zeeb printf("TX-RATE: %s: old %d new %d ridx %d, " 5164383b3e8fSBjoern A. Zeeb "long_retries %d\n", __func__, 5165383b3e8fSBjoern A. Zeeb old_rate, ni->ni_vap->iv_bss->ni_txrate, 5166383b3e8fSBjoern A. Zeeb ridx, txs.long_retries); 5167383b3e8fSBjoern A. Zeeb } 5168383b3e8fSBjoern A. Zeeb #endif 5169383b3e8fSBjoern A. Zeeb } 5170383b3e8fSBjoern A. Zeeb 5171383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 5172383b3e8fSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 5173383b3e8fSBjoern A. Zeeb printf("TX-STATUS: %s: hw %p skb %p status %d : flags %#x " 5174383b3e8fSBjoern A. Zeeb "band %u hw_queue %u tx_time_est %d : " 5175383b3e8fSBjoern A. Zeeb "rates [ %u %u %#x, %u %u %#x, %u %u %#x, %u %u %#x ] " 5176383b3e8fSBjoern A. Zeeb "ack_signal %u ampdu_ack_len %u ampdu_len %u antenna %u " 5177adff403fSBjoern A. Zeeb "tx_time %u flags %#x " 5178383b3e8fSBjoern A. Zeeb "status_driver_data [ %p %p ]\n", 5179383b3e8fSBjoern A. Zeeb __func__, hw, skb, status, info->flags, 5180383b3e8fSBjoern A. Zeeb info->band, info->hw_queue, info->tx_time_est, 5181383b3e8fSBjoern A. Zeeb info->status.rates[0].idx, info->status.rates[0].count, 5182383b3e8fSBjoern A. Zeeb info->status.rates[0].flags, 5183383b3e8fSBjoern A. Zeeb info->status.rates[1].idx, info->status.rates[1].count, 5184383b3e8fSBjoern A. Zeeb info->status.rates[1].flags, 5185383b3e8fSBjoern A. Zeeb info->status.rates[2].idx, info->status.rates[2].count, 5186383b3e8fSBjoern A. Zeeb info->status.rates[2].flags, 5187383b3e8fSBjoern A. Zeeb info->status.rates[3].idx, info->status.rates[3].count, 5188383b3e8fSBjoern A. Zeeb info->status.rates[3].flags, 5189383b3e8fSBjoern A. Zeeb info->status.ack_signal, info->status.ampdu_ack_len, 5190383b3e8fSBjoern A. Zeeb info->status.ampdu_len, info->status.antenna, 5191adff403fSBjoern A. Zeeb info->status.tx_time, info->status.flags, 5192383b3e8fSBjoern A. Zeeb info->status.status_driver_data[0], 5193383b3e8fSBjoern A. Zeeb info->status.status_driver_data[1]); 5194383b3e8fSBjoern A. Zeeb #endif 5195383b3e8fSBjoern A. Zeeb 5196a8397571SBjoern A. Zeeb if (txstat->free_list) { 5197a8397571SBjoern A. Zeeb _lkpi_ieee80211_free_txskb(hw, skb, status); 5198a8397571SBjoern A. Zeeb list_add_tail(&skb->list, txstat->free_list); 5199a8397571SBjoern A. Zeeb } else { 5200383b3e8fSBjoern A. Zeeb linuxkpi_ieee80211_free_txskb(hw, skb, status); 5201383b3e8fSBjoern A. Zeeb } 5202a8397571SBjoern A. Zeeb } 5203a8397571SBjoern A. Zeeb 5204a8397571SBjoern A. Zeeb void 5205a8397571SBjoern A. Zeeb linuxkpi_ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb) 5206a8397571SBjoern A. Zeeb { 5207a8397571SBjoern A. Zeeb struct ieee80211_tx_status status; 5208a8397571SBjoern A. Zeeb 5209a8397571SBjoern A. Zeeb memset(&status, 0, sizeof(status)); 5210a8397571SBjoern A. Zeeb status.info = IEEE80211_SKB_CB(skb); 5211a8397571SBjoern A. Zeeb status.skb = skb; 5212a8397571SBjoern A. Zeeb /* sta, n_rates, rates, free_list? */ 5213a8397571SBjoern A. Zeeb 5214a8397571SBjoern A. Zeeb ieee80211_tx_status_ext(hw, &status); 5215a8397571SBjoern A. Zeeb } 5216383b3e8fSBjoern A. Zeeb 52176b4cac81SBjoern A. Zeeb /* 52186b4cac81SBjoern A. Zeeb * This is an internal bandaid for the moment for the way we glue 52196b4cac81SBjoern A. Zeeb * skbs and mbufs together for TX. Once we have skbs backed by 52206b4cac81SBjoern A. Zeeb * mbufs this should go away. 52216b4cac81SBjoern A. Zeeb * This is a public function but kept on the private KPI (lkpi_) 52226b4cac81SBjoern A. Zeeb * and is not exposed by a header file. 52236b4cac81SBjoern A. Zeeb */ 52246b4cac81SBjoern A. Zeeb static void 52256b4cac81SBjoern A. Zeeb lkpi_ieee80211_free_skb_mbuf(void *p) 52266b4cac81SBjoern A. Zeeb { 52276b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 52286b4cac81SBjoern A. Zeeb struct mbuf *m; 52296b4cac81SBjoern A. Zeeb 52306b4cac81SBjoern A. Zeeb if (p == NULL) 52316b4cac81SBjoern A. Zeeb return; 52326b4cac81SBjoern A. Zeeb 52336b4cac81SBjoern A. Zeeb m = (struct mbuf *)p; 52346b4cac81SBjoern A. Zeeb M_ASSERTPKTHDR(m); 52356b4cac81SBjoern A. Zeeb 52366b4cac81SBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 52376b4cac81SBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = NULL; 52386b4cac81SBjoern A. Zeeb if (ni != NULL) 52396b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 52406b4cac81SBjoern A. Zeeb m_freem(m); 52416b4cac81SBjoern A. Zeeb } 52426b4cac81SBjoern A. Zeeb 52436b4cac81SBjoern A. Zeeb void 52446b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_queue_delayed_work(struct ieee80211_hw *hw, 52456b4cac81SBjoern A. Zeeb struct delayed_work *w, int delay) 52466b4cac81SBjoern A. Zeeb { 52476b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 52486b4cac81SBjoern A. Zeeb 52496b4cac81SBjoern A. Zeeb /* Need to make sure hw is in a stable (non-suspended) state. */ 52506b4cac81SBjoern A. Zeeb IMPROVE(); 52516b4cac81SBjoern A. Zeeb 52526b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 52536b4cac81SBjoern A. Zeeb queue_delayed_work(lhw->workq, w, delay); 52546b4cac81SBjoern A. Zeeb } 52556b4cac81SBjoern A. Zeeb 52566b4cac81SBjoern A. Zeeb void 52576b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_queue_work(struct ieee80211_hw *hw, 52586b4cac81SBjoern A. Zeeb struct work_struct *w) 52596b4cac81SBjoern A. Zeeb { 52606b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 52616b4cac81SBjoern A. Zeeb 52626b4cac81SBjoern A. Zeeb /* Need to make sure hw is in a stable (non-suspended) state. */ 52636b4cac81SBjoern A. Zeeb IMPROVE(); 52646b4cac81SBjoern A. Zeeb 52656b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 52666b4cac81SBjoern A. Zeeb queue_work(lhw->workq, w); 52676b4cac81SBjoern A. Zeeb } 52686b4cac81SBjoern A. Zeeb 52696b4cac81SBjoern A. Zeeb struct sk_buff * 5270ade774b1SBjoern A. Zeeb linuxkpi_ieee80211_probereq_get(struct ieee80211_hw *hw, uint8_t *addr, 5271ade774b1SBjoern A. Zeeb uint8_t *ssid, size_t ssid_len, size_t tailroom) 5272ade774b1SBjoern A. Zeeb { 5273ade774b1SBjoern A. Zeeb struct sk_buff *skb; 5274ade774b1SBjoern A. Zeeb struct ieee80211_frame *wh; 5275ade774b1SBjoern A. Zeeb uint8_t *p; 5276ade774b1SBjoern A. Zeeb size_t len; 5277ade774b1SBjoern A. Zeeb 5278ade774b1SBjoern A. Zeeb len = sizeof(*wh); 5279ade774b1SBjoern A. Zeeb len += 2 + ssid_len; 5280ade774b1SBjoern A. Zeeb 5281ade774b1SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + len + tailroom); 5282ade774b1SBjoern A. Zeeb if (skb == NULL) 5283ade774b1SBjoern A. Zeeb return (NULL); 5284ade774b1SBjoern A. Zeeb 5285ade774b1SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 5286ade774b1SBjoern A. Zeeb 5287ade774b1SBjoern A. Zeeb wh = skb_put_zero(skb, sizeof(*wh)); 5288ade774b1SBjoern A. Zeeb wh->i_fc[0] = IEEE80211_FC0_VERSION_0; 5289ade774b1SBjoern A. Zeeb wh->i_fc[0] |= IEEE80211_FC0_SUBTYPE_PROBE_REQ | IEEE80211_FC0_TYPE_MGT; 5290ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr1, ieee80211broadcastaddr); 5291ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr2, addr); 5292ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr3, ieee80211broadcastaddr); 5293ade774b1SBjoern A. Zeeb 5294ade774b1SBjoern A. Zeeb p = skb_put(skb, 2 + ssid_len); 5295ade774b1SBjoern A. Zeeb *p++ = IEEE80211_ELEMID_SSID; 5296ade774b1SBjoern A. Zeeb *p++ = ssid_len; 5297ade774b1SBjoern A. Zeeb if (ssid_len > 0) 5298ade774b1SBjoern A. Zeeb memcpy(p, ssid, ssid_len); 5299ade774b1SBjoern A. Zeeb 5300ade774b1SBjoern A. Zeeb return (skb); 5301ade774b1SBjoern A. Zeeb } 5302ade774b1SBjoern A. Zeeb 5303ade774b1SBjoern A. Zeeb struct sk_buff * 53046b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_pspoll_get(struct ieee80211_hw *hw, 53056b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif) 53066b4cac81SBjoern A. Zeeb { 53076b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 53086b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 53096b4cac81SBjoern A. Zeeb struct sk_buff *skb; 53106b4cac81SBjoern A. Zeeb struct ieee80211_frame_pspoll *psp; 53116b4cac81SBjoern A. Zeeb uint16_t v; 53126b4cac81SBjoern A. Zeeb 53136b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*psp)); 53146b4cac81SBjoern A. Zeeb if (skb == NULL) 53156b4cac81SBjoern A. Zeeb return (NULL); 53166b4cac81SBjoern A. Zeeb 53176b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 53186b4cac81SBjoern A. Zeeb 53196b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 53206b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 53216b4cac81SBjoern A. Zeeb 53226b4cac81SBjoern A. Zeeb psp = skb_put_zero(skb, sizeof(*psp)); 53236b4cac81SBjoern A. Zeeb psp->i_fc[0] = IEEE80211_FC0_VERSION_0; 53246b4cac81SBjoern A. Zeeb psp->i_fc[0] |= IEEE80211_FC0_SUBTYPE_PS_POLL | IEEE80211_FC0_TYPE_CTL; 5325616e1330SBjoern A. Zeeb v = htole16(vif->cfg.aid | 1<<15 | 1<<16); 53266b4cac81SBjoern A. Zeeb memcpy(&psp->i_aid, &v, sizeof(v)); 53276b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(psp->i_bssid, vap->iv_bss->ni_macaddr); 53286b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(psp->i_ta, vif->addr); 53296b4cac81SBjoern A. Zeeb 53306b4cac81SBjoern A. Zeeb return (skb); 53316b4cac81SBjoern A. Zeeb } 53326b4cac81SBjoern A. Zeeb 53336b4cac81SBjoern A. Zeeb struct sk_buff * 53346b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_nullfunc_get(struct ieee80211_hw *hw, 5335adff403fSBjoern A. Zeeb struct ieee80211_vif *vif, int linkid, bool qos) 53366b4cac81SBjoern A. Zeeb { 53376b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 53386b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 53396b4cac81SBjoern A. Zeeb struct sk_buff *skb; 53406b4cac81SBjoern A. Zeeb struct ieee80211_frame *nullf; 53416b4cac81SBjoern A. Zeeb 5342adff403fSBjoern A. Zeeb IMPROVE("linkid"); 5343adff403fSBjoern A. Zeeb 53446b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*nullf)); 53456b4cac81SBjoern A. Zeeb if (skb == NULL) 53466b4cac81SBjoern A. Zeeb return (NULL); 53476b4cac81SBjoern A. Zeeb 53486b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 53496b4cac81SBjoern A. Zeeb 53506b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 53516b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 53526b4cac81SBjoern A. Zeeb 53536b4cac81SBjoern A. Zeeb nullf = skb_put_zero(skb, sizeof(*nullf)); 53546b4cac81SBjoern A. Zeeb nullf->i_fc[0] = IEEE80211_FC0_VERSION_0; 53556b4cac81SBjoern A. Zeeb nullf->i_fc[0] |= IEEE80211_FC0_SUBTYPE_NODATA | IEEE80211_FC0_TYPE_DATA; 53566b4cac81SBjoern A. Zeeb nullf->i_fc[1] = IEEE80211_FC1_DIR_TODS; 53576b4cac81SBjoern A. Zeeb 53586b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr1, vap->iv_bss->ni_bssid); 53596b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr2, vif->addr); 53606b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr3, vap->iv_bss->ni_macaddr); 53616b4cac81SBjoern A. Zeeb 53626b4cac81SBjoern A. Zeeb return (skb); 53636b4cac81SBjoern A. Zeeb } 53646b4cac81SBjoern A. Zeeb 53656b4cac81SBjoern A. Zeeb struct wireless_dev * 53666b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_vif_to_wdev(struct ieee80211_vif *vif) 53676b4cac81SBjoern A. Zeeb { 53686b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 53696b4cac81SBjoern A. Zeeb 53706b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 53716b4cac81SBjoern A. Zeeb return (&lvif->wdev); 53726b4cac81SBjoern A. Zeeb } 53736b4cac81SBjoern A. Zeeb 53746b4cac81SBjoern A. Zeeb void 53756b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_connection_loss(struct ieee80211_vif *vif) 53766b4cac81SBjoern A. Zeeb { 53776b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 53786b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 53796b4cac81SBjoern A. Zeeb enum ieee80211_state nstate; 53806b4cac81SBjoern A. Zeeb int arg; 53816b4cac81SBjoern A. Zeeb 53826b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 53836b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 53846b4cac81SBjoern A. Zeeb 53856b4cac81SBjoern A. Zeeb /* 5386f3229b62SBjoern A. Zeeb * Go to init; otherwise we need to elaborately check state and 53876b4cac81SBjoern A. Zeeb * handle accordingly, e.g., if in RUN we could call iv_bmiss. 53886b4cac81SBjoern A. Zeeb * Let the statemachine handle all neccessary changes. 53896b4cac81SBjoern A. Zeeb */ 5390f3229b62SBjoern A. Zeeb nstate = IEEE80211_S_INIT; 5391bb81db90SBjoern A. Zeeb arg = 0; /* Not a valid reason. */ 53926b4cac81SBjoern A. Zeeb 5393018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: vif %p vap %p state %s\n", __func__, 5394018d93ecSBjoern A. Zeeb vif, vap, ieee80211_state_name[vap->iv_state]); 53956b4cac81SBjoern A. Zeeb ieee80211_new_state(vap, nstate, arg); 53966b4cac81SBjoern A. Zeeb } 53976b4cac81SBjoern A. Zeeb 5398bb81db90SBjoern A. Zeeb void 5399bb81db90SBjoern A. Zeeb linuxkpi_ieee80211_beacon_loss(struct ieee80211_vif *vif) 5400bb81db90SBjoern A. Zeeb { 5401bb81db90SBjoern A. Zeeb struct lkpi_vif *lvif; 5402bb81db90SBjoern A. Zeeb struct ieee80211vap *vap; 5403bb81db90SBjoern A. Zeeb 5404bb81db90SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 5405bb81db90SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 5406bb81db90SBjoern A. Zeeb 5407bb81db90SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: vif %p vap %p state %s\n", __func__, 5408bb81db90SBjoern A. Zeeb vif, vap, ieee80211_state_name[vap->iv_state]); 54093540911bSBjoern A. Zeeb ieee80211_beacon_miss(vap->iv_ic); 5410bb81db90SBjoern A. Zeeb } 5411bb81db90SBjoern A. Zeeb 54125edde07cSBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 54135edde07cSBjoern A. Zeeb 54145a9a0d78SBjoern A. Zeeb void 54155a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_stop_queue(struct ieee80211_hw *hw, int qnum) 54165a9a0d78SBjoern A. Zeeb { 54175a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 54185a9a0d78SBjoern A. Zeeb struct lkpi_vif *lvif; 54195a9a0d78SBjoern A. Zeeb struct ieee80211_vif *vif; 54205a9a0d78SBjoern A. Zeeb int ac_count, ac; 54215a9a0d78SBjoern A. Zeeb 54225a9a0d78SBjoern A. Zeeb KASSERT(qnum < hw->queues, ("%s: qnum %d >= hw->queues %d, hw %p\n", 54235a9a0d78SBjoern A. Zeeb __func__, qnum, hw->queues, hw)); 54245a9a0d78SBjoern A. Zeeb 54255a9a0d78SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 54265a9a0d78SBjoern A. Zeeb 54275a9a0d78SBjoern A. Zeeb /* See lkpi_ic_vap_create(). */ 54285a9a0d78SBjoern A. Zeeb if (hw->queues >= IEEE80211_NUM_ACS) 54295a9a0d78SBjoern A. Zeeb ac_count = IEEE80211_NUM_ACS; 54305a9a0d78SBjoern A. Zeeb else 54315a9a0d78SBjoern A. Zeeb ac_count = 1; 54325a9a0d78SBjoern A. Zeeb 54335a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 54345a9a0d78SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 54355a9a0d78SBjoern A. Zeeb 54365a9a0d78SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 54375a9a0d78SBjoern A. Zeeb for (ac = 0; ac < ac_count; ac++) { 54385a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 54395a9a0d78SBjoern A. Zeeb if (qnum == vif->hw_queue[ac]) { 54400d2cb6a6SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 54415a9a0d78SBjoern A. Zeeb /* 54425a9a0d78SBjoern A. Zeeb * For now log this to better understand 54435a9a0d78SBjoern A. Zeeb * how this is supposed to work. 54445a9a0d78SBjoern A. Zeeb */ 54450d2cb6a6SBjoern A. Zeeb if (lvif->hw_queue_stopped[ac] && 54460d2cb6a6SBjoern A. Zeeb (linuxkpi_debug_80211 & D80211_IMPROVE_TXQ) != 0) 54475a9a0d78SBjoern A. Zeeb ic_printf(lhw->ic, "%s:%d: lhw %p hw %p " 54485a9a0d78SBjoern A. Zeeb "lvif %p vif %p ac %d qnum %d already " 54495a9a0d78SBjoern A. Zeeb "stopped\n", __func__, __LINE__, 54505a9a0d78SBjoern A. Zeeb lhw, hw, lvif, vif, ac, qnum); 54510d2cb6a6SBjoern A. Zeeb #endif 54525a9a0d78SBjoern A. Zeeb lvif->hw_queue_stopped[ac] = true; 54535a9a0d78SBjoern A. Zeeb } 54545a9a0d78SBjoern A. Zeeb } 54555a9a0d78SBjoern A. Zeeb } 54565a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 54575a9a0d78SBjoern A. Zeeb } 54585a9a0d78SBjoern A. Zeeb 54595a9a0d78SBjoern A. Zeeb void 54605a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_stop_queues(struct ieee80211_hw *hw) 54615a9a0d78SBjoern A. Zeeb { 54625a9a0d78SBjoern A. Zeeb int i; 54635a9a0d78SBjoern A. Zeeb 54645a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Locking; do we need further info?"); 54655a9a0d78SBjoern A. Zeeb for (i = 0; i < hw->queues; i++) 54665a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_stop_queue(hw, i); 54675a9a0d78SBjoern A. Zeeb } 54685a9a0d78SBjoern A. Zeeb 54695a9a0d78SBjoern A. Zeeb 54705a9a0d78SBjoern A. Zeeb static void 54715a9a0d78SBjoern A. Zeeb lkpi_ieee80211_wake_queues(struct ieee80211_hw *hw, int hwq) 54725a9a0d78SBjoern A. Zeeb { 54735a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 54745a9a0d78SBjoern A. Zeeb struct lkpi_vif *lvif; 54755a9a0d78SBjoern A. Zeeb struct lkpi_sta *lsta; 54765a9a0d78SBjoern A. Zeeb int ac_count, ac, tid; 54775a9a0d78SBjoern A. Zeeb 54785a9a0d78SBjoern A. Zeeb /* See lkpi_ic_vap_create(). */ 54795a9a0d78SBjoern A. Zeeb if (hw->queues >= IEEE80211_NUM_ACS) 54805a9a0d78SBjoern A. Zeeb ac_count = IEEE80211_NUM_ACS; 54815a9a0d78SBjoern A. Zeeb else 54825a9a0d78SBjoern A. Zeeb ac_count = 1; 54835a9a0d78SBjoern A. Zeeb 54845a9a0d78SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 54855a9a0d78SBjoern A. Zeeb 54865a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Locking"); 54875a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 54885a9a0d78SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 54895a9a0d78SBjoern A. Zeeb struct ieee80211_vif *vif; 54905a9a0d78SBjoern A. Zeeb 54915a9a0d78SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 54925a9a0d78SBjoern A. Zeeb for (ac = 0; ac < ac_count; ac++) { 54935a9a0d78SBjoern A. Zeeb 54945a9a0d78SBjoern A. Zeeb if (hwq == vif->hw_queue[ac]) { 54955a9a0d78SBjoern A. Zeeb 54965a9a0d78SBjoern A. Zeeb /* XXX-BZ what about software scan? */ 54975a9a0d78SBjoern A. Zeeb 54980d2cb6a6SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 54995a9a0d78SBjoern A. Zeeb /* 55005a9a0d78SBjoern A. Zeeb * For now log this to better understand 55015a9a0d78SBjoern A. Zeeb * how this is supposed to work. 55025a9a0d78SBjoern A. Zeeb */ 55030d2cb6a6SBjoern A. Zeeb if (!lvif->hw_queue_stopped[ac] && 55040d2cb6a6SBjoern A. Zeeb (linuxkpi_debug_80211 & D80211_IMPROVE_TXQ) != 0) 55055a9a0d78SBjoern A. Zeeb ic_printf(lhw->ic, "%s:%d: lhw %p hw %p " 55065a9a0d78SBjoern A. Zeeb "lvif %p vif %p ac %d hw_q not stopped\n", 55075a9a0d78SBjoern A. Zeeb __func__, __LINE__, 55085a9a0d78SBjoern A. Zeeb lhw, hw, lvif, vif, ac); 55090d2cb6a6SBjoern A. Zeeb #endif 55105a9a0d78SBjoern A. Zeeb lvif->hw_queue_stopped[ac] = false; 55115a9a0d78SBjoern A. Zeeb 55125a9a0d78SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 55135a9a0d78SBjoern A. Zeeb TAILQ_FOREACH(lsta, &lvif->lsta_head, lsta_entry) { 55145a9a0d78SBjoern A. Zeeb struct ieee80211_sta *sta; 55155a9a0d78SBjoern A. Zeeb 55165a9a0d78SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 55175a9a0d78SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 55185a9a0d78SBjoern A. Zeeb struct lkpi_txq *ltxq; 55195a9a0d78SBjoern A. Zeeb 55205a9a0d78SBjoern A. Zeeb if (sta->txq[tid] == NULL) 55215a9a0d78SBjoern A. Zeeb continue; 55225a9a0d78SBjoern A. Zeeb 55235a9a0d78SBjoern A. Zeeb if (sta->txq[tid]->ac != ac) 55245a9a0d78SBjoern A. Zeeb continue; 55255a9a0d78SBjoern A. Zeeb 55265a9a0d78SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]); 55275a9a0d78SBjoern A. Zeeb if (!ltxq->stopped) 55285a9a0d78SBjoern A. Zeeb continue; 55295a9a0d78SBjoern A. Zeeb 55305a9a0d78SBjoern A. Zeeb ltxq->stopped = false; 55315a9a0d78SBjoern A. Zeeb 55325a9a0d78SBjoern A. Zeeb /* XXX-BZ see when this explodes with all the locking. taskq? */ 55335a9a0d78SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, sta->txq[tid]); 55345a9a0d78SBjoern A. Zeeb } 55355a9a0d78SBjoern A. Zeeb } 55365a9a0d78SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 55375a9a0d78SBjoern A. Zeeb } 55385a9a0d78SBjoern A. Zeeb } 55395a9a0d78SBjoern A. Zeeb } 55405a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 55415a9a0d78SBjoern A. Zeeb } 55425a9a0d78SBjoern A. Zeeb 55435a9a0d78SBjoern A. Zeeb void 55445a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_wake_queues(struct ieee80211_hw *hw) 55455a9a0d78SBjoern A. Zeeb { 55465a9a0d78SBjoern A. Zeeb int i; 55475a9a0d78SBjoern A. Zeeb 55485a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Is this all/enough here?"); 55495a9a0d78SBjoern A. Zeeb for (i = 0; i < hw->queues; i++) 55505a9a0d78SBjoern A. Zeeb lkpi_ieee80211_wake_queues(hw, i); 55515a9a0d78SBjoern A. Zeeb } 55525a9a0d78SBjoern A. Zeeb 55535a9a0d78SBjoern A. Zeeb void 55545a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_wake_queue(struct ieee80211_hw *hw, int qnum) 55555a9a0d78SBjoern A. Zeeb { 55565a9a0d78SBjoern A. Zeeb 55575a9a0d78SBjoern A. Zeeb KASSERT(qnum < hw->queues, ("%s: qnum %d >= hw->queues %d, hw %p\n", 55585a9a0d78SBjoern A. Zeeb __func__, qnum, hw->queues, hw)); 55595a9a0d78SBjoern A. Zeeb 55605a9a0d78SBjoern A. Zeeb lkpi_ieee80211_wake_queues(hw, qnum); 55615a9a0d78SBjoern A. Zeeb } 55625a9a0d78SBjoern A. Zeeb 55635a9a0d78SBjoern A. Zeeb /* This is just hardware queues. */ 55645a9a0d78SBjoern A. Zeeb void 55655a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_txq_schedule_start(struct ieee80211_hw *hw, uint8_t ac) 55665a9a0d78SBjoern A. Zeeb { 55675a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 55685a9a0d78SBjoern A. Zeeb 55695a9a0d78SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 55705a9a0d78SBjoern A. Zeeb 55715a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Are there reasons why we wouldn't schedule?"); 55725a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 55735a9a0d78SBjoern A. Zeeb if (++lhw->txq_generation[ac] == 0) 55745a9a0d78SBjoern A. Zeeb lhw->txq_generation[ac]++; 55755a9a0d78SBjoern A. Zeeb } 55765a9a0d78SBjoern A. Zeeb 55775a9a0d78SBjoern A. Zeeb struct ieee80211_txq * 55785a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_next_txq(struct ieee80211_hw *hw, uint8_t ac) 55795a9a0d78SBjoern A. Zeeb { 55805a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 55815a9a0d78SBjoern A. Zeeb struct ieee80211_txq *txq; 55825a9a0d78SBjoern A. Zeeb struct lkpi_txq *ltxq; 55835a9a0d78SBjoern A. Zeeb 55845a9a0d78SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 55855a9a0d78SBjoern A. Zeeb txq = NULL; 55865a9a0d78SBjoern A. Zeeb 55875a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 55885a9a0d78SBjoern A. Zeeb 55895a9a0d78SBjoern A. Zeeb /* Check that we are scheduled. */ 55905a9a0d78SBjoern A. Zeeb if (lhw->txq_generation[ac] == 0) 55915a9a0d78SBjoern A. Zeeb goto out; 55925a9a0d78SBjoern A. Zeeb 55935a9a0d78SBjoern A. Zeeb ltxq = TAILQ_FIRST(&lhw->scheduled_txqs[ac]); 55945a9a0d78SBjoern A. Zeeb if (ltxq == NULL) 55955a9a0d78SBjoern A. Zeeb goto out; 55965a9a0d78SBjoern A. Zeeb if (ltxq->txq_generation == lhw->txq_generation[ac]) 55975a9a0d78SBjoern A. Zeeb goto out; 55985a9a0d78SBjoern A. Zeeb 55995a9a0d78SBjoern A. Zeeb ltxq->txq_generation = lhw->txq_generation[ac]; 56005a9a0d78SBjoern A. Zeeb TAILQ_REMOVE(&lhw->scheduled_txqs[ac], ltxq, txq_entry); 56015a9a0d78SBjoern A. Zeeb txq = <xq->txq; 56025a9a0d78SBjoern A. Zeeb TAILQ_ELEM_INIT(ltxq, txq_entry); 56035a9a0d78SBjoern A. Zeeb 56045a9a0d78SBjoern A. Zeeb out: 56055a9a0d78SBjoern A. Zeeb return (txq); 56065a9a0d78SBjoern A. Zeeb } 56075a9a0d78SBjoern A. Zeeb 56085a9a0d78SBjoern A. Zeeb void linuxkpi_ieee80211_schedule_txq(struct ieee80211_hw *hw, 56095a9a0d78SBjoern A. Zeeb struct ieee80211_txq *txq, bool withoutpkts) 56105a9a0d78SBjoern A. Zeeb { 56115a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 56125a9a0d78SBjoern A. Zeeb struct lkpi_txq *ltxq; 5613*eac3646fSBjoern A. Zeeb bool ltxq_empty; 56145a9a0d78SBjoern A. Zeeb 56155a9a0d78SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 56165a9a0d78SBjoern A. Zeeb 56175a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 56185a9a0d78SBjoern A. Zeeb 56195a9a0d78SBjoern A. Zeeb /* Only schedule if work to do or asked to anyway. */ 5620*eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_LOCK(ltxq); 5621*eac3646fSBjoern A. Zeeb ltxq_empty = skb_queue_empty(<xq->skbq); 5622*eac3646fSBjoern A. Zeeb LKPI_80211_LTXQ_UNLOCK(ltxq); 5623*eac3646fSBjoern A. Zeeb if (!withoutpkts && ltxq_empty) 56245a9a0d78SBjoern A. Zeeb goto out; 56255a9a0d78SBjoern A. Zeeb 56265a9a0d78SBjoern A. Zeeb /* Make sure we do not double-schedule. */ 56275a9a0d78SBjoern A. Zeeb if (ltxq->txq_entry.tqe_next != NULL) 56285a9a0d78SBjoern A. Zeeb goto out; 56295a9a0d78SBjoern A. Zeeb 56305a9a0d78SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 56315a9a0d78SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lhw->scheduled_txqs[txq->ac], ltxq, txq_entry); 56325a9a0d78SBjoern A. Zeeb out: 56335a9a0d78SBjoern A. Zeeb return; 56345a9a0d78SBjoern A. Zeeb } 56355a9a0d78SBjoern A. Zeeb 5636*eac3646fSBjoern A. Zeeb void 5637*eac3646fSBjoern A. Zeeb linuxkpi_ieee80211_handle_wake_tx_queue(struct ieee80211_hw *hw, 5638*eac3646fSBjoern A. Zeeb struct ieee80211_txq *txq) 5639*eac3646fSBjoern A. Zeeb { 5640*eac3646fSBjoern A. Zeeb struct lkpi_hw *lhw; 5641*eac3646fSBjoern A. Zeeb struct ieee80211_txq *ntxq; 5642*eac3646fSBjoern A. Zeeb struct ieee80211_tx_control control; 5643*eac3646fSBjoern A. Zeeb struct sk_buff *skb; 5644*eac3646fSBjoern A. Zeeb 5645*eac3646fSBjoern A. Zeeb lhw = HW_TO_LHW(hw); 5646*eac3646fSBjoern A. Zeeb 5647*eac3646fSBjoern A. Zeeb LKPI_80211_LHW_TXQ_LOCK(lhw); 5648*eac3646fSBjoern A. Zeeb ieee80211_txq_schedule_start(hw, txq->ac); 5649*eac3646fSBjoern A. Zeeb do { 5650*eac3646fSBjoern A. Zeeb ntxq = ieee80211_next_txq(hw, txq->ac); 5651*eac3646fSBjoern A. Zeeb if (ntxq == NULL) 5652*eac3646fSBjoern A. Zeeb break; 5653*eac3646fSBjoern A. Zeeb 5654*eac3646fSBjoern A. Zeeb memset(&control, 0, sizeof(control)); 5655*eac3646fSBjoern A. Zeeb control.sta = ntxq->sta; 5656*eac3646fSBjoern A. Zeeb do { 5657*eac3646fSBjoern A. Zeeb skb = linuxkpi_ieee80211_tx_dequeue(hw, ntxq); 5658*eac3646fSBjoern A. Zeeb if (skb == NULL) 5659*eac3646fSBjoern A. Zeeb break; 5660*eac3646fSBjoern A. Zeeb lkpi_80211_mo_tx(hw, &control, skb); 5661*eac3646fSBjoern A. Zeeb } while(1); 5662*eac3646fSBjoern A. Zeeb 5663*eac3646fSBjoern A. Zeeb ieee80211_return_txq(hw, ntxq, false); 5664*eac3646fSBjoern A. Zeeb } while (1); 5665*eac3646fSBjoern A. Zeeb ieee80211_txq_schedule_end(hw, txq->ac); 5666*eac3646fSBjoern A. Zeeb LKPI_80211_LHW_TXQ_UNLOCK(lhw); 5667*eac3646fSBjoern A. Zeeb } 5668*eac3646fSBjoern A. Zeeb 56695a9a0d78SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 56705a9a0d78SBjoern A. Zeeb 56715edde07cSBjoern A. Zeeb struct lkpi_cfg80211_bss { 56725edde07cSBjoern A. Zeeb u_int refcnt; 56735edde07cSBjoern A. Zeeb struct cfg80211_bss bss; 56745edde07cSBjoern A. Zeeb }; 56755edde07cSBjoern A. Zeeb 56765edde07cSBjoern A. Zeeb struct lkpi_cfg80211_get_bss_iter_lookup { 56775edde07cSBjoern A. Zeeb struct wiphy *wiphy; 56785edde07cSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 56795edde07cSBjoern A. Zeeb const uint8_t *bssid; 56805edde07cSBjoern A. Zeeb const uint8_t *ssid; 56815edde07cSBjoern A. Zeeb size_t ssid_len; 56825edde07cSBjoern A. Zeeb enum ieee80211_bss_type bss_type; 56835edde07cSBjoern A. Zeeb enum ieee80211_privacy privacy; 56845edde07cSBjoern A. Zeeb 56855edde07cSBjoern A. Zeeb /* 56865edde07cSBjoern A. Zeeb * Something to store a copy of the result as the net80211 scan cache 56875edde07cSBjoern A. Zeeb * is not refoucnted so a scan entry might go away any time. 56885edde07cSBjoern A. Zeeb */ 56895edde07cSBjoern A. Zeeb bool match; 56905edde07cSBjoern A. Zeeb struct cfg80211_bss *bss; 56915edde07cSBjoern A. Zeeb }; 56925edde07cSBjoern A. Zeeb 56935edde07cSBjoern A. Zeeb static void 56945edde07cSBjoern A. Zeeb lkpi_cfg80211_get_bss_iterf(void *arg, const struct ieee80211_scan_entry *se) 56955edde07cSBjoern A. Zeeb { 56965edde07cSBjoern A. Zeeb struct lkpi_cfg80211_get_bss_iter_lookup *lookup; 56975edde07cSBjoern A. Zeeb size_t ielen; 56985edde07cSBjoern A. Zeeb 56995edde07cSBjoern A. Zeeb lookup = arg; 57005edde07cSBjoern A. Zeeb 57015edde07cSBjoern A. Zeeb /* Do not try to find another match. */ 57025edde07cSBjoern A. Zeeb if (lookup->match) 57035edde07cSBjoern A. Zeeb return; 57045edde07cSBjoern A. Zeeb 57055edde07cSBjoern A. Zeeb /* Nothing to store result. */ 57065edde07cSBjoern A. Zeeb if (lookup->bss == NULL) 57075edde07cSBjoern A. Zeeb return; 57085edde07cSBjoern A. Zeeb 57095edde07cSBjoern A. Zeeb if (lookup->privacy != IEEE80211_PRIVACY_ANY) { 57105edde07cSBjoern A. Zeeb /* if (se->se_capinfo & IEEE80211_CAPINFO_PRIVACY) */ 57115edde07cSBjoern A. Zeeb /* We have no idea what to compare to as the drivers only request ANY */ 57125edde07cSBjoern A. Zeeb return; 57135edde07cSBjoern A. Zeeb } 57145edde07cSBjoern A. Zeeb 57155edde07cSBjoern A. Zeeb if (lookup->bss_type != IEEE80211_BSS_TYPE_ANY) { 57165edde07cSBjoern A. Zeeb /* if (se->se_capinfo & (IEEE80211_CAPINFO_IBSS|IEEE80211_CAPINFO_ESS)) */ 57175edde07cSBjoern A. Zeeb /* We have no idea what to compare to as the drivers only request ANY */ 57185edde07cSBjoern A. Zeeb return; 57195edde07cSBjoern A. Zeeb } 57205edde07cSBjoern A. Zeeb 57215edde07cSBjoern A. Zeeb if (lookup->chan != NULL) { 57225edde07cSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 57235edde07cSBjoern A. Zeeb 57245edde07cSBjoern A. Zeeb chan = linuxkpi_ieee80211_get_channel(lookup->wiphy, 57255edde07cSBjoern A. Zeeb se->se_chan->ic_freq); 57265edde07cSBjoern A. Zeeb if (chan == NULL || chan != lookup->chan) 57275edde07cSBjoern A. Zeeb return; 57285edde07cSBjoern A. Zeeb } 57295edde07cSBjoern A. Zeeb 57305edde07cSBjoern A. Zeeb if (lookup->bssid && !IEEE80211_ADDR_EQ(lookup->bssid, se->se_bssid)) 57315edde07cSBjoern A. Zeeb return; 57325edde07cSBjoern A. Zeeb 57335edde07cSBjoern A. Zeeb if (lookup->ssid) { 57345edde07cSBjoern A. Zeeb if (lookup->ssid_len != se->se_ssid[1] || 57355edde07cSBjoern A. Zeeb se->se_ssid[1] == 0) 57365edde07cSBjoern A. Zeeb return; 57375edde07cSBjoern A. Zeeb if (memcmp(lookup->ssid, se->se_ssid+2, lookup->ssid_len) != 0) 57385edde07cSBjoern A. Zeeb return; 57395edde07cSBjoern A. Zeeb } 57405edde07cSBjoern A. Zeeb 57415edde07cSBjoern A. Zeeb ielen = se->se_ies.len; 57425edde07cSBjoern A. Zeeb 57435edde07cSBjoern A. Zeeb lookup->bss->ies = malloc(sizeof(*lookup->bss->ies) + ielen, 57445edde07cSBjoern A. Zeeb M_LKPI80211, M_NOWAIT | M_ZERO); 57455edde07cSBjoern A. Zeeb if (lookup->bss->ies == NULL) 57465edde07cSBjoern A. Zeeb return; 57475edde07cSBjoern A. Zeeb 57485edde07cSBjoern A. Zeeb lookup->bss->ies->data = (uint8_t *)lookup->bss->ies + sizeof(*lookup->bss->ies); 57495edde07cSBjoern A. Zeeb lookup->bss->ies->len = ielen; 57505edde07cSBjoern A. Zeeb if (ielen) 57515edde07cSBjoern A. Zeeb memcpy(lookup->bss->ies->data, se->se_ies.data, ielen); 57525edde07cSBjoern A. Zeeb 57535edde07cSBjoern A. Zeeb lookup->match = true; 57545edde07cSBjoern A. Zeeb } 57555edde07cSBjoern A. Zeeb 57565edde07cSBjoern A. Zeeb struct cfg80211_bss * 57575edde07cSBjoern A. Zeeb linuxkpi_cfg80211_get_bss(struct wiphy *wiphy, struct linuxkpi_ieee80211_channel *chan, 57585edde07cSBjoern A. Zeeb const uint8_t *bssid, const uint8_t *ssid, size_t ssid_len, 57595edde07cSBjoern A. Zeeb enum ieee80211_bss_type bss_type, enum ieee80211_privacy privacy) 57605edde07cSBjoern A. Zeeb { 57615edde07cSBjoern A. Zeeb struct lkpi_cfg80211_bss *lbss; 57625edde07cSBjoern A. Zeeb struct lkpi_cfg80211_get_bss_iter_lookup lookup; 57635edde07cSBjoern A. Zeeb struct lkpi_hw *lhw; 57645edde07cSBjoern A. Zeeb struct ieee80211vap *vap; 57655edde07cSBjoern A. Zeeb 57665edde07cSBjoern A. Zeeb lhw = wiphy_priv(wiphy); 57675edde07cSBjoern A. Zeeb 57685edde07cSBjoern A. Zeeb /* Let's hope we can alloc. */ 57695edde07cSBjoern A. Zeeb lbss = malloc(sizeof(*lbss), M_LKPI80211, M_NOWAIT | M_ZERO); 57705edde07cSBjoern A. Zeeb if (lbss == NULL) { 57715edde07cSBjoern A. Zeeb ic_printf(lhw->ic, "%s: alloc failed.\n", __func__); 57725edde07cSBjoern A. Zeeb return (NULL); 57735edde07cSBjoern A. Zeeb } 57745edde07cSBjoern A. Zeeb 57755edde07cSBjoern A. Zeeb lookup.wiphy = wiphy; 57765edde07cSBjoern A. Zeeb lookup.chan = chan; 57775edde07cSBjoern A. Zeeb lookup.bssid = bssid; 57785edde07cSBjoern A. Zeeb lookup.ssid = ssid; 57795edde07cSBjoern A. Zeeb lookup.ssid_len = ssid_len; 57805edde07cSBjoern A. Zeeb lookup.bss_type = bss_type; 57815edde07cSBjoern A. Zeeb lookup.privacy = privacy; 57825edde07cSBjoern A. Zeeb lookup.match = false; 57835edde07cSBjoern A. Zeeb lookup.bss = &lbss->bss; 57845edde07cSBjoern A. Zeeb 57855edde07cSBjoern A. Zeeb IMPROVE("Iterate over all VAPs comparing perm_addr and addresses?"); 57865edde07cSBjoern A. Zeeb vap = TAILQ_FIRST(&lhw->ic->ic_vaps); 57875edde07cSBjoern A. Zeeb ieee80211_scan_iterate(vap, lkpi_cfg80211_get_bss_iterf, &lookup); 57885edde07cSBjoern A. Zeeb if (!lookup.match) { 57895edde07cSBjoern A. Zeeb free(lbss, M_LKPI80211); 57905edde07cSBjoern A. Zeeb return (NULL); 57915edde07cSBjoern A. Zeeb } 57925edde07cSBjoern A. Zeeb 57935edde07cSBjoern A. Zeeb refcount_init(&lbss->refcnt, 1); 57945edde07cSBjoern A. Zeeb return (&lbss->bss); 57955edde07cSBjoern A. Zeeb } 57965edde07cSBjoern A. Zeeb 57975edde07cSBjoern A. Zeeb void 57985edde07cSBjoern A. Zeeb linuxkpi_cfg80211_put_bss(struct wiphy *wiphy, struct cfg80211_bss *bss) 57995edde07cSBjoern A. Zeeb { 58005edde07cSBjoern A. Zeeb struct lkpi_cfg80211_bss *lbss; 58015edde07cSBjoern A. Zeeb 58025edde07cSBjoern A. Zeeb lbss = container_of(bss, struct lkpi_cfg80211_bss, bss); 58035edde07cSBjoern A. Zeeb 58045edde07cSBjoern A. Zeeb /* Free everything again on refcount ... */ 58055edde07cSBjoern A. Zeeb if (refcount_release(&lbss->refcnt)) { 58065edde07cSBjoern A. Zeeb free(lbss->bss.ies, M_LKPI80211); 58075edde07cSBjoern A. Zeeb free(lbss, M_LKPI80211); 58085edde07cSBjoern A. Zeeb } 58095edde07cSBjoern A. Zeeb } 58105edde07cSBjoern A. Zeeb 58115edde07cSBjoern A. Zeeb void 58125edde07cSBjoern A. Zeeb linuxkpi_cfg80211_bss_flush(struct wiphy *wiphy) 58135edde07cSBjoern A. Zeeb { 58145edde07cSBjoern A. Zeeb struct lkpi_hw *lhw; 58155edde07cSBjoern A. Zeeb struct ieee80211com *ic; 58165edde07cSBjoern A. Zeeb struct ieee80211vap *vap; 58175edde07cSBjoern A. Zeeb 58185edde07cSBjoern A. Zeeb lhw = wiphy_priv(wiphy); 58195edde07cSBjoern A. Zeeb ic = lhw->ic; 58205edde07cSBjoern A. Zeeb 58215edde07cSBjoern A. Zeeb /* 58225edde07cSBjoern A. Zeeb * If we haven't called ieee80211_ifattach() yet 58235edde07cSBjoern A. Zeeb * or there is no VAP, there are no scans to flush. 58245edde07cSBjoern A. Zeeb */ 58255edde07cSBjoern A. Zeeb if (ic == NULL || 58265edde07cSBjoern A. Zeeb (lhw->sc_flags & LKPI_MAC80211_DRV_STARTED) == 0) 58275edde07cSBjoern A. Zeeb return; 58285edde07cSBjoern A. Zeeb 58295edde07cSBjoern A. Zeeb /* Should only happen on the current one? Not seen it late enough. */ 58305edde07cSBjoern A. Zeeb IEEE80211_LOCK(ic); 58315edde07cSBjoern A. Zeeb TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) 58325edde07cSBjoern A. Zeeb ieee80211_scan_flush(vap); 58335edde07cSBjoern A. Zeeb IEEE80211_UNLOCK(ic); 58345edde07cSBjoern A. Zeeb } 58355edde07cSBjoern A. Zeeb 58365edde07cSBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 58375edde07cSBjoern A. Zeeb 58386b4cac81SBjoern A. Zeeb MODULE_VERSION(linuxkpi_wlan, 1); 58396b4cac81SBjoern A. Zeeb MODULE_DEPEND(linuxkpi_wlan, linuxkpi, 1, 1, 1); 58406b4cac81SBjoern A. Zeeb MODULE_DEPEND(linuxkpi_wlan, wlan, 1, 1, 1); 5841