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> 64*9fb91463SBjoern 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 */ 74*9fb91463SBjoern A. Zeeb /* #define LKPI_80211_VHT */ 75*9fb91463SBjoern A. Zeeb /* #define LKPI_80211_HT */ 76*9fb91463SBjoern A. Zeeb #if defined(LKPI_80211_VHT) && !defined(LKPI_80211_HT) 77*9fb91463SBjoern A. Zeeb #define LKPI_80211_HT 78*9fb91463SBjoern 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 152*9fb91463SBjoern A. Zeeb #if defined(LKPI_80211_HT) 153*9fb91463SBjoern A. Zeeb static void 154*9fb91463SBjoern A. Zeeb lkpi_sta_sync_ht_from_ni(struct ieee80211_sta *sta, struct ieee80211_node *ni, int *ht_rx_nss) 155*9fb91463SBjoern A. Zeeb { 156*9fb91463SBjoern A. Zeeb struct ieee80211vap *vap; 157*9fb91463SBjoern A. Zeeb uint8_t *ie; 158*9fb91463SBjoern A. Zeeb struct ieee80211_ht_cap *htcap; 159*9fb91463SBjoern A. Zeeb int i, rx_nss; 160*9fb91463SBjoern A. Zeeb 161*9fb91463SBjoern A. Zeeb if ((ni->ni_flags & IEEE80211_NODE_HT) == 0) 162*9fb91463SBjoern A. Zeeb return; 163*9fb91463SBjoern A. Zeeb 164*9fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_HT(ni->ni_chan) && 165*9fb91463SBjoern A. Zeeb IEEE80211_IS_CHAN_HT40(ni->ni_chan)) 166*9fb91463SBjoern A. Zeeb sta->deflink.bandwidth = IEEE80211_STA_RX_BW_40; 167*9fb91463SBjoern A. Zeeb 168*9fb91463SBjoern A. Zeeb sta->deflink.ht_cap.ht_supported = true; 169*9fb91463SBjoern A. Zeeb 170*9fb91463SBjoern A. Zeeb /* htcap->ampdu_params_info */ 171*9fb91463SBjoern A. Zeeb vap = ni->ni_vap; 172*9fb91463SBjoern A. Zeeb sta->deflink.ht_cap.ampdu_density = _IEEE80211_MASKSHIFT(ni->ni_htparam, IEEE80211_HTCAP_MPDUDENSITY); 173*9fb91463SBjoern A. Zeeb if (sta->deflink.ht_cap.ampdu_density > vap->iv_ampdu_density) 174*9fb91463SBjoern A. Zeeb sta->deflink.ht_cap.ampdu_density = vap->iv_ampdu_density; 175*9fb91463SBjoern A. Zeeb sta->deflink.ht_cap.ampdu_factor = _IEEE80211_MASKSHIFT(ni->ni_htparam, IEEE80211_HTCAP_MAXRXAMPDU); 176*9fb91463SBjoern A. Zeeb if (sta->deflink.ht_cap.ampdu_factor > vap->iv_ampdu_rxmax) 177*9fb91463SBjoern A. Zeeb sta->deflink.ht_cap.ampdu_factor = vap->iv_ampdu_rxmax; 178*9fb91463SBjoern A. Zeeb 179*9fb91463SBjoern A. Zeeb ie = ni->ni_ies.htcap_ie; 180*9fb91463SBjoern A. Zeeb KASSERT(ie != NULL, ("%s: HT but no htcap_ie on ni %p\n", __func__, ni)); 181*9fb91463SBjoern A. Zeeb if (ie[0] == IEEE80211_ELEMID_VENDOR) 182*9fb91463SBjoern A. Zeeb ie += 4; 183*9fb91463SBjoern A. Zeeb ie += 2; 184*9fb91463SBjoern A. Zeeb htcap = (struct ieee80211_ht_cap *)ie; 185*9fb91463SBjoern A. Zeeb sta->deflink.ht_cap.cap = htcap->cap_info; 186*9fb91463SBjoern A. Zeeb sta->deflink.ht_cap.mcs = htcap->mcs; 187*9fb91463SBjoern A. Zeeb 188*9fb91463SBjoern A. Zeeb rx_nss = 0; 189*9fb91463SBjoern A. Zeeb for (i = 0; i < nitems(htcap->mcs.rx_mask); i++) { 190*9fb91463SBjoern A. Zeeb if (htcap->mcs.rx_mask[i]) 191*9fb91463SBjoern A. Zeeb rx_nss++; 192*9fb91463SBjoern A. Zeeb } 193*9fb91463SBjoern A. Zeeb if (ht_rx_nss != NULL) 194*9fb91463SBjoern A. Zeeb *ht_rx_nss = rx_nss; 195*9fb91463SBjoern A. Zeeb 196*9fb91463SBjoern A. Zeeb IMPROVE("sta->wme, sta->deflink.agg.max*"); 197*9fb91463SBjoern A. Zeeb } 198*9fb91463SBjoern A. Zeeb #endif 199*9fb91463SBjoern A. Zeeb 200*9fb91463SBjoern A. Zeeb #if defined(LKPI_80211_VHT) 201*9fb91463SBjoern A. Zeeb static void 202*9fb91463SBjoern A. Zeeb lkpi_sta_sync_vht_from_ni(struct ieee80211_sta *sta, struct ieee80211_node *ni, int *vht_rx_nss) 203*9fb91463SBjoern A. Zeeb { 204*9fb91463SBjoern A. Zeeb 205*9fb91463SBjoern A. Zeeb if ((ni->ni_flags & IEEE80211_NODE_VHT) == 0) 206*9fb91463SBjoern A. Zeeb return; 207*9fb91463SBjoern A. Zeeb 208*9fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_VHT(ni->ni_chan)) { 209*9fb91463SBjoern A. Zeeb #ifdef __notyet__ 210*9fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_VHT80P80(ni->ni_chan)) { 211*9fb91463SBjoern A. Zeeb sta->deflink.bandwidth = IEEE80211_STA_RX_BW_160; /* XXX? */ 212*9fb91463SBjoern A. Zeeb } else 213*9fb91463SBjoern A. Zeeb #endif 214*9fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_VHT160(ni->ni_chan)) 215*9fb91463SBjoern A. Zeeb sta->deflink.bandwidth = IEEE80211_STA_RX_BW_160; 216*9fb91463SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_VHT80(ni->ni_chan)) 217*9fb91463SBjoern A. Zeeb sta->deflink.bandwidth = IEEE80211_STA_RX_BW_80; 218*9fb91463SBjoern A. Zeeb } 219*9fb91463SBjoern A. Zeeb 220*9fb91463SBjoern A. Zeeb IMPROVE("VHT sync ni to sta"); 221*9fb91463SBjoern A. Zeeb return; 222*9fb91463SBjoern A. Zeeb } 223*9fb91463SBjoern A. Zeeb #endif 224*9fb91463SBjoern 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; 279*9fb91463SBjoern A. Zeeb int ht_rx_nss; 280*9fb91463SBjoern 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); 3324f61ef8bSBjoern A. Zeeb sta->txq[tid] = <xq->txq; 3334f61ef8bSBjoern A. Zeeb } 3344f61ef8bSBjoern A. Zeeb 335b6b352e4SBjoern A. Zeeb /* Deflink information. */ 336b6b352e4SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 337b6b352e4SBjoern A. Zeeb struct ieee80211_supported_band *supband; 338b6b352e4SBjoern A. Zeeb 339b6b352e4SBjoern A. Zeeb supband = hw->wiphy->bands[band]; 340b6b352e4SBjoern A. Zeeb if (supband == NULL) 341b6b352e4SBjoern A. Zeeb continue; 342b6b352e4SBjoern A. Zeeb 343b6b352e4SBjoern A. Zeeb for (i = 0; i < supband->n_bitrates; i++) { 344b6b352e4SBjoern A. Zeeb 345b6b352e4SBjoern A. Zeeb IMPROVE("Further supband->bitrates[i]* checks?"); 346b6b352e4SBjoern A. Zeeb /* or should we get them from the ni? */ 347b6b352e4SBjoern A. Zeeb sta->deflink.supp_rates[band] |= BIT(i); 348b6b352e4SBjoern A. Zeeb } 349b6b352e4SBjoern A. Zeeb } 350*9fb91463SBjoern A. Zeeb 3516ffb7bd4SBjoern A. Zeeb sta->deflink.smps_mode = IEEE80211_SMPS_OFF; 352*9fb91463SBjoern A. Zeeb sta->deflink.bandwidth = IEEE80211_STA_RX_BW_20; 353*9fb91463SBjoern A. Zeeb sta->deflink.rx_nss = 0; 354*9fb91463SBjoern A. Zeeb 355*9fb91463SBjoern A. Zeeb ht_rx_nss = 0; 356*9fb91463SBjoern A. Zeeb #if defined(LKPI_80211_HT) 357*9fb91463SBjoern A. Zeeb lkpi_sta_sync_ht_from_ni(sta, ni, &ht_rx_nss); 358*9fb91463SBjoern A. Zeeb #endif 359*9fb91463SBjoern A. Zeeb vht_rx_nss = 0; 360*9fb91463SBjoern A. Zeeb #if defined(LKPI_80211_VHT) 361*9fb91463SBjoern A. Zeeb lkpi_sta_sync_vht_from_ni(sta, ni, &vht_rx_nss); 362*9fb91463SBjoern A. Zeeb #endif 363*9fb91463SBjoern A. Zeeb 364*9fb91463SBjoern A. Zeeb sta->deflink.rx_nss = MAX(ht_rx_nss, sta->deflink.rx_nss); 365*9fb91463SBjoern A. Zeeb sta->deflink.rx_nss = MAX(vht_rx_nss, sta->deflink.rx_nss); 366*9fb91463SBjoern A. Zeeb IMPROVE("he, ... smps_mode, .."); 367b6b352e4SBjoern A. Zeeb 3686ffb7bd4SBjoern A. Zeeb /* Link configuration. */ 3696ffb7bd4SBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->deflink.addr, sta->addr); 3706ffb7bd4SBjoern A. Zeeb sta->link[0] = &sta->deflink; 3716ffb7bd4SBjoern A. Zeeb for (i = 1; i < nitems(sta->link); i++) { 3726ffb7bd4SBjoern A. Zeeb IMPROVE("more links; only link[0] = deflink currently."); 3736ffb7bd4SBjoern A. Zeeb } 3746ffb7bd4SBjoern A. Zeeb 3754f61ef8bSBjoern A. Zeeb /* Deferred TX path. */ 3764f61ef8bSBjoern A. Zeeb mtx_init(&lsta->txq_mtx, "lsta_txq", NULL, MTX_DEF); 3774f61ef8bSBjoern A. Zeeb TASK_INIT(&lsta->txq_task, 0, lkpi_80211_txq_task, lsta); 3784f61ef8bSBjoern A. Zeeb mbufq_init(&lsta->txq, IFQ_MAXLEN); 3794f61ef8bSBjoern A. Zeeb 3804f61ef8bSBjoern A. Zeeb return (lsta); 3814f61ef8bSBjoern A. Zeeb 3824f61ef8bSBjoern A. Zeeb cleanup: 3834f61ef8bSBjoern A. Zeeb for (; tid >= 0; tid--) 3844f61ef8bSBjoern A. Zeeb free(sta->txq[tid], M_LKPI80211); 3854f61ef8bSBjoern A. Zeeb free(lsta, M_LKPI80211); 3864f61ef8bSBjoern A. Zeeb return (NULL); 3874f61ef8bSBjoern A. Zeeb } 3884f61ef8bSBjoern A. Zeeb 3896b4cac81SBjoern A. Zeeb static enum nl80211_band 3906b4cac81SBjoern A. Zeeb lkpi_net80211_chan_to_nl80211_band(struct ieee80211_channel *c) 3916b4cac81SBjoern A. Zeeb { 3926b4cac81SBjoern A. Zeeb 3936b4cac81SBjoern A. Zeeb if (IEEE80211_IS_CHAN_2GHZ(c)) 3946b4cac81SBjoern A. Zeeb return (NL80211_BAND_2GHZ); 3956b4cac81SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_5GHZ(c)) 3966b4cac81SBjoern A. Zeeb return (NL80211_BAND_5GHZ); 3976b4cac81SBjoern A. Zeeb #ifdef __notyet__ 3986b4cac81SBjoern A. Zeeb else if () 3996b4cac81SBjoern A. Zeeb return (NL80211_BAND_6GHZ); 4006b4cac81SBjoern A. Zeeb else if () 4016b4cac81SBjoern A. Zeeb return (NL80211_BAND_60GHZ); 4026b4cac81SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_GSM(c)) 4036b4cac81SBjoern A. Zeeb return (NL80211_BAND_XXX); 4046b4cac81SBjoern A. Zeeb #endif 4056b4cac81SBjoern A. Zeeb else 4066b4cac81SBjoern A. Zeeb panic("%s: unsupported band. c %p flags %#x\n", 4076b4cac81SBjoern A. Zeeb __func__, c, c->ic_flags); 4086b4cac81SBjoern A. Zeeb } 4096b4cac81SBjoern A. Zeeb 4106b4cac81SBjoern A. Zeeb static uint32_t 4116b4cac81SBjoern A. Zeeb lkpi_nl80211_band_to_net80211_band(enum nl80211_band band) 4126b4cac81SBjoern A. Zeeb { 4136b4cac81SBjoern A. Zeeb 4146b4cac81SBjoern A. Zeeb /* XXX-BZ this is just silly; net80211 is too convoluted. */ 4156b4cac81SBjoern A. Zeeb /* IEEE80211_CHAN_A / _G / .. doesn't really work either. */ 4166b4cac81SBjoern A. Zeeb switch (band) { 4176b4cac81SBjoern A. Zeeb case NL80211_BAND_2GHZ: 4186b4cac81SBjoern A. Zeeb return (IEEE80211_CHAN_2GHZ); 4196b4cac81SBjoern A. Zeeb break; 4206b4cac81SBjoern A. Zeeb case NL80211_BAND_5GHZ: 4216b4cac81SBjoern A. Zeeb return (IEEE80211_CHAN_5GHZ); 4226b4cac81SBjoern A. Zeeb break; 4236b4cac81SBjoern A. Zeeb case NL80211_BAND_60GHZ: 4246b4cac81SBjoern A. Zeeb break; 4256b4cac81SBjoern A. Zeeb case NL80211_BAND_6GHZ: 4266b4cac81SBjoern A. Zeeb break; 4276b4cac81SBjoern A. Zeeb default: 4286b4cac81SBjoern A. Zeeb panic("%s: unsupported band %u\n", __func__, band); 4296b4cac81SBjoern A. Zeeb break; 4306b4cac81SBjoern A. Zeeb } 4316b4cac81SBjoern A. Zeeb 4326b4cac81SBjoern A. Zeeb IMPROVE(); 4336b4cac81SBjoern A. Zeeb return (0x00); 4346b4cac81SBjoern A. Zeeb } 4356b4cac81SBjoern A. Zeeb 436e3a0b120SBjoern A. Zeeb #if 0 4376b4cac81SBjoern A. Zeeb static enum ieee80211_ac_numbers 4386b4cac81SBjoern A. Zeeb lkpi_ac_net_to_l80211(int ac) 4396b4cac81SBjoern A. Zeeb { 4406b4cac81SBjoern A. Zeeb 4416b4cac81SBjoern A. Zeeb switch (ac) { 4426b4cac81SBjoern A. Zeeb case WME_AC_VO: 4436b4cac81SBjoern A. Zeeb return (IEEE80211_AC_VO); 4446b4cac81SBjoern A. Zeeb case WME_AC_VI: 4456b4cac81SBjoern A. Zeeb return (IEEE80211_AC_VI); 4466b4cac81SBjoern A. Zeeb case WME_AC_BE: 4476b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BE); 4486b4cac81SBjoern A. Zeeb case WME_AC_BK: 4496b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BK); 4506b4cac81SBjoern A. Zeeb default: 4516b4cac81SBjoern A. Zeeb printf("%s: invalid WME_AC_* input: ac = %d\n", __func__, ac); 4526b4cac81SBjoern A. Zeeb return (IEEE80211_AC_BE); 4536b4cac81SBjoern A. Zeeb } 4546b4cac81SBjoern A. Zeeb } 455e3a0b120SBjoern A. Zeeb #endif 4566b4cac81SBjoern A. Zeeb 4576b4cac81SBjoern A. Zeeb static enum nl80211_iftype 4586b4cac81SBjoern A. Zeeb lkpi_opmode_to_vif_type(enum ieee80211_opmode opmode) 4596b4cac81SBjoern A. Zeeb { 4606b4cac81SBjoern A. Zeeb 4616b4cac81SBjoern A. Zeeb switch (opmode) { 4626b4cac81SBjoern A. Zeeb case IEEE80211_M_IBSS: 4636b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_ADHOC); 4646b4cac81SBjoern A. Zeeb break; 4656b4cac81SBjoern A. Zeeb case IEEE80211_M_STA: 4666b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_STATION); 4676b4cac81SBjoern A. Zeeb break; 4686b4cac81SBjoern A. Zeeb case IEEE80211_M_WDS: 4696b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_WDS); 4706b4cac81SBjoern A. Zeeb break; 4716b4cac81SBjoern A. Zeeb case IEEE80211_M_HOSTAP: 4726b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_AP); 4736b4cac81SBjoern A. Zeeb break; 4746b4cac81SBjoern A. Zeeb case IEEE80211_M_MONITOR: 4756b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_MONITOR); 4766b4cac81SBjoern A. Zeeb break; 4776b4cac81SBjoern A. Zeeb case IEEE80211_M_MBSS: 4786b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_MESH_POINT); 4796b4cac81SBjoern A. Zeeb break; 4806b4cac81SBjoern A. Zeeb case IEEE80211_M_AHDEMO: 4816b4cac81SBjoern A. Zeeb /* FALLTHROUGH */ 4826b4cac81SBjoern A. Zeeb default: 4836b4cac81SBjoern A. Zeeb printf("ERROR: %s: unsupported opmode %d\n", __func__, opmode); 4846b4cac81SBjoern A. Zeeb /* FALLTHROUGH */ 4856b4cac81SBjoern A. Zeeb } 4866b4cac81SBjoern A. Zeeb return (NL80211_IFTYPE_UNSPECIFIED); 4876b4cac81SBjoern A. Zeeb } 4886b4cac81SBjoern A. Zeeb 489b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 4906b4cac81SBjoern A. Zeeb static uint32_t 4916b4cac81SBjoern A. Zeeb lkpi_l80211_to_net80211_cyphers(uint32_t wlan_cipher_suite) 4926b4cac81SBjoern A. Zeeb { 4936b4cac81SBjoern A. Zeeb 4946b4cac81SBjoern A. Zeeb switch (wlan_cipher_suite) { 4956b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP40: 4966b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_WEP); 4976b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP: 4986b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_TKIP); 4996b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP: 5006b4cac81SBjoern A. Zeeb return (IEEE80211_CIPHER_AES_CCM); 5016b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_WEP104: 5026b4cac81SBjoern A. Zeeb return (IEEE80211_CRYPTO_WEP); 5036b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_AES_CMAC: 5046b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP: 5056b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_GCMP_256: 5066b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP_256: 5076b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_128: 5086b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_GMAC_256: 5096b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_BIP_CMAC_256: 5106b4cac81SBjoern A. Zeeb printf("%s: unsupported WLAN Cipher Suite %#08x | %u\n", __func__, 5116b4cac81SBjoern A. Zeeb wlan_cipher_suite >> 8, wlan_cipher_suite & 0xff); 5126b4cac81SBjoern A. Zeeb break; 5136b4cac81SBjoern A. Zeeb default: 5146b4cac81SBjoern A. Zeeb printf("%s: unknown WLAN Cipher Suite %#08x | %u\n", __func__, 5156b4cac81SBjoern A. Zeeb wlan_cipher_suite >> 8, wlan_cipher_suite & 0xff); 5166b4cac81SBjoern A. Zeeb } 5176b4cac81SBjoern A. Zeeb 5186b4cac81SBjoern A. Zeeb return (0); 5196b4cac81SBjoern A. Zeeb } 5206b4cac81SBjoern A. Zeeb 5216b4cac81SBjoern A. Zeeb static uint32_t 5226b4cac81SBjoern A. Zeeb lkpi_net80211_to_l80211_cipher_suite(uint32_t cipher, uint8_t keylen) 5236b4cac81SBjoern A. Zeeb { 5246b4cac81SBjoern A. Zeeb 5256b4cac81SBjoern A. Zeeb switch (cipher) { 5266b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_TKIP: 5276b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_TKIP); 5286b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_AES_CCM: 5296b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_CCMP); 5306b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_WEP: 5316b4cac81SBjoern A. Zeeb if (keylen < 8) 5326b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_WEP40); 5336b4cac81SBjoern A. Zeeb else 5346b4cac81SBjoern A. Zeeb return (WLAN_CIPHER_SUITE_WEP104); 5356b4cac81SBjoern A. Zeeb break; 5366b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_AES_OCB: 5376b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_TKIPMIC: 5386b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_CKIP: 5396b4cac81SBjoern A. Zeeb case IEEE80211_CIPHER_NONE: 5406b4cac81SBjoern A. Zeeb printf("%s: unsupported cipher %#010x\n", __func__, cipher); 5416b4cac81SBjoern A. Zeeb break; 5426b4cac81SBjoern A. Zeeb default: 5436b4cac81SBjoern A. Zeeb printf("%s: unknown cipher %#010x\n", __func__, cipher); 5446b4cac81SBjoern A. Zeeb }; 5456b4cac81SBjoern A. Zeeb return (0); 5466b4cac81SBjoern A. Zeeb } 5476b4cac81SBjoern A. Zeeb #endif 5486b4cac81SBjoern A. Zeeb 5496b4cac81SBjoern A. Zeeb #ifdef __notyet__ 5506b4cac81SBjoern A. Zeeb static enum ieee80211_sta_state 5516b4cac81SBjoern A. Zeeb lkpi_net80211_state_to_sta_state(enum ieee80211_state state) 5526b4cac81SBjoern A. Zeeb { 5536b4cac81SBjoern A. Zeeb 5546b4cac81SBjoern A. Zeeb /* 5556b4cac81SBjoern A. Zeeb * XXX-BZ The net80211 states are "try to ..", the lkpi8011 states are 5566b4cac81SBjoern A. Zeeb * "done". Also ASSOC/AUTHORIZED are both "RUN" then? 5576b4cac81SBjoern A. Zeeb */ 5586b4cac81SBjoern A. Zeeb switch (state) { 5596b4cac81SBjoern A. Zeeb case IEEE80211_S_INIT: 5606b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NOTEXIST); 5616b4cac81SBjoern A. Zeeb case IEEE80211_S_SCAN: 5626b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NONE); 5636b4cac81SBjoern A. Zeeb case IEEE80211_S_AUTH: 5646b4cac81SBjoern A. Zeeb return (IEEE80211_STA_AUTH); 5656b4cac81SBjoern A. Zeeb case IEEE80211_S_ASSOC: 5666b4cac81SBjoern A. Zeeb return (IEEE80211_STA_ASSOC); 5676b4cac81SBjoern A. Zeeb case IEEE80211_S_RUN: 5686b4cac81SBjoern A. Zeeb return (IEEE80211_STA_AUTHORIZED); 5696b4cac81SBjoern A. Zeeb case IEEE80211_S_CAC: 5706b4cac81SBjoern A. Zeeb case IEEE80211_S_CSA: 5716b4cac81SBjoern A. Zeeb case IEEE80211_S_SLEEP: 5726b4cac81SBjoern A. Zeeb default: 5736b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 5746b4cac81SBjoern A. Zeeb }; 5756b4cac81SBjoern A. Zeeb 5766b4cac81SBjoern A. Zeeb return (IEEE80211_STA_NOTEXIST); 5776b4cac81SBjoern A. Zeeb } 5786b4cac81SBjoern A. Zeeb #endif 5796b4cac81SBjoern A. Zeeb 5806b4cac81SBjoern A. Zeeb static struct linuxkpi_ieee80211_channel * 5816b4cac81SBjoern A. Zeeb lkpi_find_lkpi80211_chan(struct lkpi_hw *lhw, 5826b4cac81SBjoern A. Zeeb struct ieee80211_channel *c) 5836b4cac81SBjoern A. Zeeb { 5846b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 5856b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 5866b4cac81SBjoern A. Zeeb enum nl80211_band band; 5876b4cac81SBjoern A. Zeeb int i, nchans; 5886b4cac81SBjoern A. Zeeb 5896b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 5906b4cac81SBjoern A. Zeeb band = lkpi_net80211_chan_to_nl80211_band(c); 5916b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[band] == NULL) 5926b4cac81SBjoern A. Zeeb return (NULL); 5936b4cac81SBjoern A. Zeeb 5946b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[band]->n_channels; 5956b4cac81SBjoern A. Zeeb if (nchans <= 0) 5966b4cac81SBjoern A. Zeeb return (NULL); 5976b4cac81SBjoern A. Zeeb 5986b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[band]->channels; 5996b4cac81SBjoern A. Zeeb for (i = 0; i < nchans; i++) { 6006b4cac81SBjoern A. Zeeb if (channels[i].hw_value == c->ic_ieee) 6016b4cac81SBjoern A. Zeeb return (&channels[i]); 6026b4cac81SBjoern A. Zeeb } 6036b4cac81SBjoern A. Zeeb 6046b4cac81SBjoern A. Zeeb return (NULL); 6056b4cac81SBjoern A. Zeeb } 6066b4cac81SBjoern A. Zeeb 6076b4cac81SBjoern A. Zeeb static struct linuxkpi_ieee80211_channel * 6086b4cac81SBjoern A. Zeeb lkpi_get_lkpi80211_chan(struct ieee80211com *ic, struct ieee80211_node *ni) 6096b4cac81SBjoern A. Zeeb { 6106b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 6116b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 6126b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 6136b4cac81SBjoern A. Zeeb 6146b4cac81SBjoern A. Zeeb chan = NULL; 6156b4cac81SBjoern A. Zeeb if (ni != NULL && ni->ni_chan != IEEE80211_CHAN_ANYC) 6166b4cac81SBjoern A. Zeeb c = ni->ni_chan; 6176b4cac81SBjoern A. Zeeb else if (ic->ic_bsschan != IEEE80211_CHAN_ANYC) 6186b4cac81SBjoern A. Zeeb c = ic->ic_bsschan; 6196b4cac81SBjoern A. Zeeb else if (ic->ic_curchan != IEEE80211_CHAN_ANYC) 6206b4cac81SBjoern A. Zeeb c = ic->ic_curchan; 6216b4cac81SBjoern A. Zeeb else 6226b4cac81SBjoern A. Zeeb c = NULL; 6236b4cac81SBjoern A. Zeeb 6246b4cac81SBjoern A. Zeeb if (c != NULL && c != IEEE80211_CHAN_ANYC) { 6256b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 6266b4cac81SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, c); 6276b4cac81SBjoern A. Zeeb } 6286b4cac81SBjoern A. Zeeb 6296b4cac81SBjoern A. Zeeb return (chan); 6306b4cac81SBjoern A. Zeeb } 6316b4cac81SBjoern A. Zeeb 6322e183d99SBjoern A. Zeeb struct linuxkpi_ieee80211_channel * 6332e183d99SBjoern A. Zeeb linuxkpi_ieee80211_get_channel(struct wiphy *wiphy, uint32_t freq) 6342e183d99SBjoern A. Zeeb { 6352e183d99SBjoern A. Zeeb enum nl80211_band band; 6362e183d99SBjoern A. Zeeb 6372e183d99SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 6382e183d99SBjoern A. Zeeb struct ieee80211_supported_band *supband; 6392e183d99SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 6402e183d99SBjoern A. Zeeb int i; 6412e183d99SBjoern A. Zeeb 6422e183d99SBjoern A. Zeeb supband = wiphy->bands[band]; 6432e183d99SBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 6442e183d99SBjoern A. Zeeb continue; 6452e183d99SBjoern A. Zeeb 6462e183d99SBjoern A. Zeeb channels = supband->channels; 6472e183d99SBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 6482e183d99SBjoern A. Zeeb if (channels[i].center_freq == freq) 6492e183d99SBjoern A. Zeeb return (&channels[i]); 6502e183d99SBjoern A. Zeeb } 6512e183d99SBjoern A. Zeeb } 6522e183d99SBjoern A. Zeeb 6532e183d99SBjoern A. Zeeb return (NULL); 6542e183d99SBjoern A. Zeeb } 6552e183d99SBjoern A. Zeeb 656b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 6576b4cac81SBjoern A. Zeeb static int 6586b4cac81SBjoern A. Zeeb _lkpi_iv_key_set_delete(struct ieee80211vap *vap, const struct ieee80211_key *k, 6596b4cac81SBjoern A. Zeeb enum set_key_cmd cmd) 6606b4cac81SBjoern A. Zeeb { 6616b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 6626b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 6636b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 6646b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 6656b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 6666b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 6676b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 6686b4cac81SBjoern A. Zeeb struct ieee80211_key_conf *kc; 6696b4cac81SBjoern A. Zeeb int error; 6706b4cac81SBjoern A. Zeeb 6716b4cac81SBjoern A. Zeeb /* XXX TODO Check (k->wk_flags & IEEE80211_KEY_SWENCRYPT) and don't upload to driver/hw? */ 6726b4cac81SBjoern A. Zeeb 6736b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 6746b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 6756b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 6766b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 6776b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 6786b4cac81SBjoern A. Zeeb 6796b4cac81SBjoern A. Zeeb memset(&kc, 0, sizeof(kc)); 6806b4cac81SBjoern A. Zeeb kc = malloc(sizeof(*kc) + k->wk_keylen, M_LKPI80211, M_WAITOK | M_ZERO); 6816b4cac81SBjoern A. Zeeb kc->cipher = lkpi_net80211_to_l80211_cipher_suite( 6826b4cac81SBjoern A. Zeeb k->wk_cipher->ic_cipher, k->wk_keylen); 6836b4cac81SBjoern A. Zeeb kc->keyidx = k->wk_keyix; 6846b4cac81SBjoern A. Zeeb #if 0 6856b4cac81SBjoern A. Zeeb kc->hw_key_idx = /* set by hw and needs to be passed for TX */; 6866b4cac81SBjoern A. Zeeb #endif 6876b4cac81SBjoern A. Zeeb atomic64_set(&kc->tx_pn, k->wk_keytsc); 6886b4cac81SBjoern A. Zeeb kc->keylen = k->wk_keylen; 6896b4cac81SBjoern A. Zeeb memcpy(kc->key, k->wk_key, k->wk_keylen); 6906b4cac81SBjoern A. Zeeb 6916b4cac81SBjoern A. Zeeb switch (kc->cipher) { 6926b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_CCMP: 6936b4cac81SBjoern A. Zeeb kc->iv_len = k->wk_cipher->ic_header; 6946b4cac81SBjoern A. Zeeb kc->icv_len = k->wk_cipher->ic_trailer; 6956b4cac81SBjoern A. Zeeb break; 6966b4cac81SBjoern A. Zeeb case WLAN_CIPHER_SUITE_TKIP: 6976b4cac81SBjoern A. Zeeb default: 6986b4cac81SBjoern A. Zeeb IMPROVE(); 6996b4cac81SBjoern A. Zeeb return (0); 7006b4cac81SBjoern A. Zeeb }; 7016b4cac81SBjoern A. Zeeb 7026b4cac81SBjoern A. Zeeb ni = vap->iv_bss; 7036b4cac81SBjoern A. Zeeb sta = ieee80211_find_sta(vif, ni->ni_bssid); 7046b4cac81SBjoern A. Zeeb if (sta != NULL) { 7056b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 7066b4cac81SBjoern A. Zeeb 7076b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 7086b4cac81SBjoern A. Zeeb lsta->kc = kc; 7096b4cac81SBjoern A. Zeeb } 7106b4cac81SBjoern A. Zeeb 7116b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_set_key(hw, cmd, vif, sta, kc); 7126b4cac81SBjoern A. Zeeb if (error != 0) { 7136b4cac81SBjoern A. Zeeb /* XXX-BZ leaking kc currently */ 7146b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: set_key failed: %d\n", __func__, error); 7156b4cac81SBjoern A. Zeeb return (0); 7166b4cac81SBjoern A. Zeeb } else { 7176b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: set_key succeeded: keyidx %u hw_key_idx %u " 7186b4cac81SBjoern A. Zeeb "flags %#10x\n", __func__, 7196b4cac81SBjoern A. Zeeb kc->keyidx, kc->hw_key_idx, kc->flags); 7206b4cac81SBjoern A. Zeeb return (1); 7216b4cac81SBjoern A. Zeeb } 7226b4cac81SBjoern A. Zeeb } 7236b4cac81SBjoern A. Zeeb 7246b4cac81SBjoern A. Zeeb static int 7256b4cac81SBjoern A. Zeeb lkpi_iv_key_delete(struct ieee80211vap *vap, const struct ieee80211_key *k) 7266b4cac81SBjoern A. Zeeb { 7276b4cac81SBjoern A. Zeeb 7286b4cac81SBjoern A. Zeeb /* XXX-BZ one day we should replace this iterating over VIFs, or node list? */ 7296b4cac81SBjoern A. Zeeb return (_lkpi_iv_key_set_delete(vap, k, DISABLE_KEY)); 7306b4cac81SBjoern A. Zeeb } 7316b4cac81SBjoern A. Zeeb static int 7326b4cac81SBjoern A. Zeeb lkpi_iv_key_set(struct ieee80211vap *vap, const struct ieee80211_key *k) 7336b4cac81SBjoern A. Zeeb { 7346b4cac81SBjoern A. Zeeb 7356b4cac81SBjoern A. Zeeb return (_lkpi_iv_key_set_delete(vap, k, SET_KEY)); 7366b4cac81SBjoern A. Zeeb } 7376b4cac81SBjoern A. Zeeb #endif 7386b4cac81SBjoern A. Zeeb 7396b4cac81SBjoern A. Zeeb static u_int 7406b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast_copy(void *arg, struct sockaddr_dl *sdl, u_int cnt) 7416b4cac81SBjoern A. Zeeb { 7426b4cac81SBjoern A. Zeeb struct netdev_hw_addr_list *mc_list; 7436b4cac81SBjoern A. Zeeb struct netdev_hw_addr *addr; 7446b4cac81SBjoern A. Zeeb 7456b4cac81SBjoern A. Zeeb KASSERT(arg != NULL && sdl != NULL, ("%s: arg %p sdl %p cnt %u\n", 7466b4cac81SBjoern A. Zeeb __func__, arg, sdl, cnt)); 7476b4cac81SBjoern A. Zeeb 7486b4cac81SBjoern A. Zeeb mc_list = arg; 7496b4cac81SBjoern A. Zeeb /* If it is on the list already skip it. */ 7506b4cac81SBjoern A. Zeeb netdev_hw_addr_list_for_each(addr, mc_list) { 7516b4cac81SBjoern A. Zeeb if (!memcmp(addr->addr, LLADDR(sdl), sdl->sdl_alen)) 7526b4cac81SBjoern A. Zeeb return (0); 7536b4cac81SBjoern A. Zeeb } 7546b4cac81SBjoern A. Zeeb 7556b4cac81SBjoern A. Zeeb addr = malloc(sizeof(*addr), M_LKPI80211, M_NOWAIT | M_ZERO); 7566b4cac81SBjoern A. Zeeb if (addr == NULL) 7576b4cac81SBjoern A. Zeeb return (0); 7586b4cac81SBjoern A. Zeeb 7596b4cac81SBjoern A. Zeeb INIT_LIST_HEAD(&addr->addr_list); 7606b4cac81SBjoern A. Zeeb memcpy(addr->addr, LLADDR(sdl), sdl->sdl_alen); 7616b4cac81SBjoern A. Zeeb /* XXX this should be a netdev function? */ 7626b4cac81SBjoern A. Zeeb list_add(&addr->addr_list, &mc_list->addr_list); 7636b4cac81SBjoern A. Zeeb mc_list->count++; 7646b4cac81SBjoern A. Zeeb 7659d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 7669d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 7676b4cac81SBjoern A. Zeeb printf("%s:%d: mc_list count %d: added %6D\n", 7686b4cac81SBjoern A. Zeeb __func__, __LINE__, mc_list->count, addr->addr, ":"); 7699d9ba2b7SBjoern A. Zeeb #endif 7706b4cac81SBjoern A. Zeeb 7716b4cac81SBjoern A. Zeeb return (1); 7726b4cac81SBjoern A. Zeeb } 7736b4cac81SBjoern A. Zeeb 7746b4cac81SBjoern A. Zeeb static void 7756b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(struct ieee80211com *ic, bool force) 7766b4cac81SBjoern A. Zeeb { 7776b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 7786b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 7796b4cac81SBjoern A. Zeeb struct netdev_hw_addr_list mc_list; 7806b4cac81SBjoern A. Zeeb struct list_head *le, *next; 7816b4cac81SBjoern A. Zeeb struct netdev_hw_addr *addr; 7826b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 7836b4cac81SBjoern A. Zeeb u64 mc; 7846b4cac81SBjoern A. Zeeb unsigned int changed_flags, total_flags; 7856b4cac81SBjoern A. Zeeb 7866b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 7876b4cac81SBjoern A. Zeeb 7886b4cac81SBjoern A. Zeeb if (lhw->ops->prepare_multicast == NULL || 7896b4cac81SBjoern A. Zeeb lhw->ops->configure_filter == NULL) 7906b4cac81SBjoern A. Zeeb return; 7916b4cac81SBjoern A. Zeeb 7926b4cac81SBjoern A. Zeeb if (!lhw->update_mc && !force) 7936b4cac81SBjoern A. Zeeb return; 7946b4cac81SBjoern A. Zeeb 7956b4cac81SBjoern A. Zeeb changed_flags = total_flags = 0; 7966b4cac81SBjoern A. Zeeb mc_list.count = 0; 7976b4cac81SBjoern A. Zeeb INIT_LIST_HEAD(&mc_list.addr_list); 7986b4cac81SBjoern A. Zeeb if (ic->ic_allmulti == 0) { 7996b4cac81SBjoern A. Zeeb TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) 8006b4cac81SBjoern A. Zeeb if_foreach_llmaddr(vap->iv_ifp, 8016b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast_copy, &mc_list); 8026b4cac81SBjoern A. Zeeb } else { 8036b4cac81SBjoern A. Zeeb changed_flags |= FIF_ALLMULTI; 8046b4cac81SBjoern A. Zeeb } 8056b4cac81SBjoern A. Zeeb 8066b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 8076b4cac81SBjoern A. Zeeb mc = lkpi_80211_mo_prepare_multicast(hw, &mc_list); 8086b4cac81SBjoern A. Zeeb /* 8096b4cac81SBjoern A. Zeeb * XXX-BZ make sure to get this sorted what is a change, 8106b4cac81SBjoern A. Zeeb * what gets all set; what was already set? 8116b4cac81SBjoern A. Zeeb */ 8126b4cac81SBjoern A. Zeeb total_flags = changed_flags; 8136b4cac81SBjoern A. Zeeb lkpi_80211_mo_configure_filter(hw, changed_flags, &total_flags, mc); 8146b4cac81SBjoern A. Zeeb 8159d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 8169d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 8176b4cac81SBjoern A. Zeeb printf("%s: changed_flags %#06x count %d total_flags %#010x\n", 8186b4cac81SBjoern A. Zeeb __func__, changed_flags, mc_list.count, total_flags); 8199d9ba2b7SBjoern A. Zeeb #endif 8206b4cac81SBjoern A. Zeeb 8216b4cac81SBjoern A. Zeeb if (mc_list.count != 0) { 8226b4cac81SBjoern A. Zeeb list_for_each_safe(le, next, &mc_list.addr_list) { 8236b4cac81SBjoern A. Zeeb addr = list_entry(le, struct netdev_hw_addr, addr_list); 8246b4cac81SBjoern A. Zeeb free(addr, M_LKPI80211); 8256b4cac81SBjoern A. Zeeb mc_list.count--; 8266b4cac81SBjoern A. Zeeb } 8276b4cac81SBjoern A. Zeeb } 8286b4cac81SBjoern A. Zeeb KASSERT(mc_list.count == 0, ("%s: mc_list %p count %d != 0\n", 8296b4cac81SBjoern A. Zeeb __func__, &mc_list, mc_list.count)); 8306b4cac81SBjoern A. Zeeb } 8316b4cac81SBjoern A. Zeeb 832fa8f007dSBjoern A. Zeeb static enum ieee80211_bss_changed 833fa8f007dSBjoern A. Zeeb lkpi_update_dtim_tsf(struct ieee80211_vif *vif, struct ieee80211_node *ni, 834fa8f007dSBjoern A. Zeeb struct ieee80211vap *vap, const char *_f, int _l) 835fa8f007dSBjoern A. Zeeb { 836fa8f007dSBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 837fa8f007dSBjoern A. Zeeb 838fa8f007dSBjoern A. Zeeb bss_changed = 0; 839fa8f007dSBjoern A. Zeeb 8409d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 8419d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 842fa8f007dSBjoern A. Zeeb printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u " 843fa8f007dSBjoern A. Zeeb "dtim_period %u sync_dtim_count %u sync_tsf %ju " 844fa8f007dSBjoern A. Zeeb "sync_device_ts %u bss_changed %#08x\n", 845fa8f007dSBjoern A. Zeeb __func__, __LINE__, _f, _l, 846616e1330SBjoern A. Zeeb vif->cfg.assoc, vif->cfg.aid, 847fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int, vif->bss_conf.dtim_period, 848fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count, 849fa8f007dSBjoern A. Zeeb (uintmax_t)vif->bss_conf.sync_tsf, 850fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_device_ts, 851fa8f007dSBjoern A. Zeeb bss_changed); 8529d9ba2b7SBjoern A. Zeeb #endif 853fa8f007dSBjoern A. Zeeb 854fa8f007dSBjoern A. Zeeb if (vif->bss_conf.beacon_int != ni->ni_intval) { 855fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int = ni->ni_intval; 856fa8f007dSBjoern A. Zeeb /* iwlwifi FW bug workaround; iwl_mvm_mac_sta_state. */ 857fa8f007dSBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16) 858fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int = 16; 859fa8f007dSBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INT; 860fa8f007dSBjoern A. Zeeb } 861fa8f007dSBjoern A. Zeeb if (vif->bss_conf.dtim_period != vap->iv_dtim_period && 862fa8f007dSBjoern A. Zeeb vap->iv_dtim_period > 0) { 863fa8f007dSBjoern A. Zeeb vif->bss_conf.dtim_period = vap->iv_dtim_period; 864fa8f007dSBjoern A. Zeeb bss_changed |= BSS_CHANGED_BEACON_INFO; 865fa8f007dSBjoern A. Zeeb } 866fa8f007dSBjoern A. Zeeb 867fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count = vap->iv_dtim_count; 868fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_tsf = le64toh(ni->ni_tstamp.tsf); 869fa8f007dSBjoern A. Zeeb /* vif->bss_conf.sync_device_ts = set in linuxkpi_ieee80211_rx. */ 870fa8f007dSBjoern A. Zeeb 8719d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 8729d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 873fa8f007dSBjoern A. Zeeb printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u " 874fa8f007dSBjoern A. Zeeb "dtim_period %u sync_dtim_count %u sync_tsf %ju " 875fa8f007dSBjoern A. Zeeb "sync_device_ts %u bss_changed %#08x\n", 876fa8f007dSBjoern A. Zeeb __func__, __LINE__, _f, _l, 877616e1330SBjoern A. Zeeb vif->cfg.assoc, vif->cfg.aid, 878fa8f007dSBjoern A. Zeeb vif->bss_conf.beacon_int, vif->bss_conf.dtim_period, 879fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_dtim_count, 880fa8f007dSBjoern A. Zeeb (uintmax_t)vif->bss_conf.sync_tsf, 881fa8f007dSBjoern A. Zeeb vif->bss_conf.sync_device_ts, 882fa8f007dSBjoern A. Zeeb bss_changed); 8839d9ba2b7SBjoern A. Zeeb #endif 884fa8f007dSBjoern A. Zeeb 885fa8f007dSBjoern A. Zeeb return (bss_changed); 886fa8f007dSBjoern A. Zeeb } 887fa8f007dSBjoern A. Zeeb 8886b4cac81SBjoern A. Zeeb static void 8896b4cac81SBjoern A. Zeeb lkpi_stop_hw_scan(struct lkpi_hw *lhw, struct ieee80211_vif *vif) 8906b4cac81SBjoern A. Zeeb { 8916b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 8926b4cac81SBjoern A. Zeeb int error; 8938ac540d3SBjoern A. Zeeb bool cancel; 8946b4cac81SBjoern A. Zeeb 8958ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 8968ac540d3SBjoern A. Zeeb cancel = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0; 8978ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 8988ac540d3SBjoern A. Zeeb if (!cancel) 8996b4cac81SBjoern A. Zeeb return; 9006b4cac81SBjoern A. Zeeb 9016b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 9026b4cac81SBjoern A. Zeeb 903bec76628SBjoern A. Zeeb IEEE80211_UNLOCK(lhw->ic); 904bec76628SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 9056b4cac81SBjoern A. Zeeb /* Need to cancel the scan. */ 9066b4cac81SBjoern A. Zeeb lkpi_80211_mo_cancel_hw_scan(hw, vif); 9078ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 9086b4cac81SBjoern A. Zeeb 9096b4cac81SBjoern A. Zeeb /* Need to make sure we see ieee80211_scan_completed. */ 9108ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 9118ac540d3SBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) 9128ac540d3SBjoern A. Zeeb error = msleep(lhw, &lhw->scan_mtx, 0, "lhwscanstop", hz/2); 9138ac540d3SBjoern A. Zeeb cancel = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0; 9148ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 9158ac540d3SBjoern A. Zeeb 916bec76628SBjoern A. Zeeb IEEE80211_LOCK(lhw->ic); 9176b4cac81SBjoern A. Zeeb 9188ac540d3SBjoern A. Zeeb if (cancel) 9196b4cac81SBjoern A. Zeeb ic_printf(lhw->ic, "%s: failed to cancel scan: %d (%p, %p)\n", 9206b4cac81SBjoern A. Zeeb __func__, error, lhw, vif); 9216b4cac81SBjoern A. Zeeb } 9226b4cac81SBjoern A. Zeeb 9236b4cac81SBjoern A. Zeeb static void 924086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(struct ieee80211_hw *hw, bool new) 925086be6a8SBjoern A. Zeeb { 926086be6a8SBjoern A. Zeeb struct lkpi_hw *lhw; 927086be6a8SBjoern A. Zeeb int error; 928086be6a8SBjoern A. Zeeb bool old; 929086be6a8SBjoern A. Zeeb 930086be6a8SBjoern A. Zeeb old = hw->conf.flags & IEEE80211_CONF_IDLE; 931086be6a8SBjoern A. Zeeb if (old == new) 932086be6a8SBjoern A. Zeeb return; 933086be6a8SBjoern A. Zeeb 934086be6a8SBjoern A. Zeeb hw->conf.flags ^= IEEE80211_CONF_IDLE; 935086be6a8SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_IDLE); 936086be6a8SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) { 937086be6a8SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 938086be6a8SBjoern A. Zeeb ic_printf(lhw->ic, "ERROR: %s: config %#0x returned %d\n", 939086be6a8SBjoern A. Zeeb __func__, IEEE80211_CONF_CHANGE_IDLE, error); 940086be6a8SBjoern A. Zeeb } 941086be6a8SBjoern A. Zeeb } 942086be6a8SBjoern A. Zeeb 943086be6a8SBjoern A. Zeeb static void 9446b4cac81SBjoern A. Zeeb lkpi_disassoc(struct ieee80211_sta *sta, struct ieee80211_vif *vif, 9456b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw) 9466b4cac81SBjoern A. Zeeb { 9476b4cac81SBjoern A. Zeeb sta->aid = 0; 948616e1330SBjoern A. Zeeb if (vif->cfg.assoc) { 9496b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 9506b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 9516b4cac81SBjoern A. Zeeb 9526b4cac81SBjoern A. Zeeb lhw->update_mc = true; 9536b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(lhw->ic, true); 9546b4cac81SBjoern A. Zeeb 9556b4cac81SBjoern A. Zeeb changed = 0; 956616e1330SBjoern A. Zeeb vif->cfg.assoc = false; 957616e1330SBjoern A. Zeeb vif->cfg.aid = 0; 9586b4cac81SBjoern A. Zeeb changed |= BSS_CHANGED_ASSOC; 959d9f59799SBjoern A. Zeeb /* 960d9f59799SBjoern A. Zeeb * This will remove the sta from firmware for iwlwifi. 961d9f59799SBjoern A. Zeeb * So confusing that they use state and flags and ... ^%$%#%$^. 962d9f59799SBjoern A. Zeeb */ 9636b4cac81SBjoern A. Zeeb IMPROVE(); 9646b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 9656b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, 9666b4cac81SBjoern A. Zeeb changed); 967086be6a8SBjoern A. Zeeb 968086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true); 9696b4cac81SBjoern A. Zeeb } 9706b4cac81SBjoern A. Zeeb } 9716b4cac81SBjoern A. Zeeb 9726b4cac81SBjoern A. Zeeb static void 9736b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(struct ieee80211_hw *hw, struct ieee80211_sta *sta, 9746b4cac81SBjoern A. Zeeb bool dequeue_seen, bool no_emptyq) 9756b4cac81SBjoern A. Zeeb { 9766b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 9776b4cac81SBjoern A. Zeeb int tid; 9786b4cac81SBjoern A. Zeeb 9796b4cac81SBjoern A. Zeeb /* Wake up all queues to know they are allocated in the driver. */ 9806b4cac81SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 9816b4cac81SBjoern A. Zeeb 9826b4cac81SBjoern A. Zeeb if (tid == IEEE80211_NUM_TIDS) { 9836b4cac81SBjoern A. Zeeb IMPROVE("station specific?"); 9846b4cac81SBjoern A. Zeeb if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ)) 9856b4cac81SBjoern A. Zeeb continue; 9866b4cac81SBjoern A. Zeeb } else if (tid >= hw->queues) 9876b4cac81SBjoern A. Zeeb continue; 9886b4cac81SBjoern A. Zeeb 9896b4cac81SBjoern A. Zeeb if (sta->txq[tid] == NULL) 9906b4cac81SBjoern A. Zeeb continue; 9916b4cac81SBjoern A. Zeeb 9926b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]); 9936b4cac81SBjoern A. Zeeb if (dequeue_seen && !ltxq->seen_dequeue) 9946b4cac81SBjoern A. Zeeb continue; 9956b4cac81SBjoern A. Zeeb 9966b4cac81SBjoern A. Zeeb if (no_emptyq && skb_queue_empty(<xq->skbq)) 9976b4cac81SBjoern A. Zeeb continue; 9986b4cac81SBjoern A. Zeeb 9996b4cac81SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, sta->txq[tid]); 10006b4cac81SBjoern A. Zeeb } 10016b4cac81SBjoern A. Zeeb } 10026b4cac81SBjoern A. Zeeb 10036b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 10046b4cac81SBjoern A. Zeeb 10056b4cac81SBjoern A. Zeeb static int 10066b4cac81SBjoern A. Zeeb lkpi_sta_state_do_nada(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 10076b4cac81SBjoern A. Zeeb { 10086b4cac81SBjoern A. Zeeb 10096b4cac81SBjoern A. Zeeb return (0); 10106b4cac81SBjoern A. Zeeb } 10116b4cac81SBjoern A. Zeeb 10126b4cac81SBjoern A. Zeeb /* lkpi_iv_newstate() handles the stop scan case generally. */ 10136b4cac81SBjoern A. Zeeb #define lkpi_sta_scan_to_init(_v, _n, _a) lkpi_sta_state_do_nada(_v, _n, _a) 10146b4cac81SBjoern A. Zeeb 10156b4cac81SBjoern A. Zeeb static int 10166b4cac81SBjoern A. Zeeb lkpi_sta_scan_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 10176b4cac81SBjoern A. Zeeb { 10186b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 1019c5e25798SBjoern A. Zeeb struct lkpi_chanctx *lchanctx; 10206b4cac81SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 10216b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 10226b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 10236b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 10246b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 10256b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 10266b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 10276b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 10286b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 10296b4cac81SBjoern A. Zeeb uint32_t changed; 10306b4cac81SBjoern A. Zeeb int error; 10316b4cac81SBjoern A. Zeeb 10326b4cac81SBjoern A. Zeeb chan = lkpi_get_lkpi80211_chan(vap->iv_ic, vap->iv_bss); 10336b4cac81SBjoern A. Zeeb if (chan == NULL) { 10346b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: failed to get channel\n", __func__); 10356b4cac81SBjoern A. Zeeb return (ESRCH); 10366b4cac81SBjoern A. Zeeb } 10376b4cac81SBjoern A. Zeeb 10386b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 10396b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 10406b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 10416b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 10426b4cac81SBjoern A. Zeeb 1043d9f59799SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 1044d9f59799SBjoern A. Zeeb 10456b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 10468ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 10476b4cac81SBjoern A. Zeeb 10486b4cac81SBjoern A. Zeeb /* Add chanctx (or if exists, change it). */ 10496b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 10506b4cac81SBjoern A. Zeeb conf = vif->chanctx_conf; 1051c5e25798SBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(conf); 10526b4cac81SBjoern A. Zeeb IMPROVE("diff changes for changed, working on live copy, rcu"); 10536b4cac81SBjoern A. Zeeb } else { 10546b4cac81SBjoern A. Zeeb /* Keep separate alloc as in Linux this is rcu managed? */ 1055c5e25798SBjoern A. Zeeb lchanctx = malloc(sizeof(*lchanctx) + hw->chanctx_data_size, 10566b4cac81SBjoern A. Zeeb M_LKPI80211, M_WAITOK | M_ZERO); 1057c5e25798SBjoern A. Zeeb conf = &lchanctx->conf; 10586b4cac81SBjoern A. Zeeb } 10596b4cac81SBjoern A. Zeeb 10606b4cac81SBjoern A. Zeeb conf->rx_chains_dynamic = 1; 10616b4cac81SBjoern A. Zeeb conf->rx_chains_static = 1; 10626b4cac81SBjoern A. Zeeb conf->radar_enabled = 10636b4cac81SBjoern A. Zeeb (chan->flags & IEEE80211_CHAN_RADAR) ? true : false; 10646b4cac81SBjoern A. Zeeb conf->def.chan = chan; 10656b4cac81SBjoern A. Zeeb conf->def.width = NL80211_CHAN_WIDTH_20_NOHT; 10666b4cac81SBjoern A. Zeeb conf->def.center_freq1 = chan->center_freq; 10676b4cac81SBjoern A. Zeeb conf->def.center_freq2 = 0; 1068*9fb91463SBjoern A. Zeeb IMPROVE("Check vht_cap from band not just chan?"); 1069*9fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 1070*9fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_HT(ni->ni_chan)) { 1071*9fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_HT40(ni->ni_chan)) { 1072*9fb91463SBjoern A. Zeeb conf->def.width = NL80211_CHAN_WIDTH_40; 1073*9fb91463SBjoern A. Zeeb } else 1074*9fb91463SBjoern A. Zeeb conf->def.width = NL80211_CHAN_WIDTH_20; 1075*9fb91463SBjoern A. Zeeb } 1076*9fb91463SBjoern A. Zeeb #endif 1077*9fb91463SBjoern A. Zeeb #ifdef LKPI_80211_VHT 1078*9fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_VHT(ni->ni_chan)) { 1079*9fb91463SBjoern A. Zeeb #ifdef __notyet__ 1080*9fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_VHT80P80(ni->ni_chan)) { 1081*9fb91463SBjoern A. Zeeb conf->def.width = NL80211_CHAN_WIDTH_80P80; 1082*9fb91463SBjoern A. Zeeb conf->def.center_freq2 = 0; /* XXX */ 1083*9fb91463SBjoern A. Zeeb } else 1084*9fb91463SBjoern A. Zeeb #endif 1085*9fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_VHT160(ni->ni_chan)) 1086*9fb91463SBjoern A. Zeeb conf->def.width = NL80211_CHAN_WIDTH_160; 1087*9fb91463SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_VHT80(ni->ni_chan)) 1088*9fb91463SBjoern A. Zeeb conf->def.width = NL80211_CHAN_WIDTH_80; 1089*9fb91463SBjoern A. Zeeb } 1090*9fb91463SBjoern A. Zeeb #endif 10916b4cac81SBjoern A. Zeeb /* Responder ... */ 10926b4cac81SBjoern A. Zeeb conf->min_def.chan = chan; 10936b4cac81SBjoern A. Zeeb conf->min_def.width = NL80211_CHAN_WIDTH_20_NOHT; 10946b4cac81SBjoern A. Zeeb conf->min_def.center_freq1 = chan->center_freq; 10956b4cac81SBjoern A. Zeeb conf->min_def.center_freq2 = 0; 1096*9fb91463SBjoern A. Zeeb IMPROVE("currently 20_NOHT min_def only"); 10976b4cac81SBjoern A. Zeeb 10986ffb7bd4SBjoern A. Zeeb /* Set bss info (bss_info_changed). */ 10996ffb7bd4SBjoern A. Zeeb bss_changed = 0; 11006ffb7bd4SBjoern A. Zeeb vif->bss_conf.bssid = ni->ni_bssid; 11016ffb7bd4SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 11026ffb7bd4SBjoern A. Zeeb vif->bss_conf.txpower = ni->ni_txpower; 11036ffb7bd4SBjoern A. Zeeb bss_changed |= BSS_CHANGED_TXPOWER; 11046ffb7bd4SBjoern A. Zeeb vif->cfg.idle = false; 11056ffb7bd4SBjoern A. Zeeb bss_changed |= BSS_CHANGED_IDLE; 11066ffb7bd4SBjoern A. Zeeb 11076ffb7bd4SBjoern A. Zeeb /* vif->bss_conf.basic_rates ? Where exactly? */ 11086ffb7bd4SBjoern A. Zeeb 11096ffb7bd4SBjoern A. Zeeb /* Should almost assert it is this. */ 11106ffb7bd4SBjoern A. Zeeb vif->cfg.assoc = false; 11116ffb7bd4SBjoern A. Zeeb vif->cfg.aid = 0; 11126ffb7bd4SBjoern A. Zeeb 11136ffb7bd4SBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 11146ffb7bd4SBjoern A. Zeeb 11156b4cac81SBjoern A. Zeeb error = 0; 11166b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 11176b4cac81SBjoern A. Zeeb changed = IEEE80211_CHANCTX_CHANGE_MIN_WIDTH; 11186b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_RADAR; 11196b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_RX_CHAINS; 11206b4cac81SBjoern A. Zeeb changed |= IEEE80211_CHANCTX_CHANGE_WIDTH; 11216b4cac81SBjoern A. Zeeb lkpi_80211_mo_change_chanctx(hw, conf, changed); 11226b4cac81SBjoern A. Zeeb } else { 11236b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_add_chanctx(hw, conf); 11246b4cac81SBjoern A. Zeeb if (error == 0 || error == EOPNOTSUPP) { 11256b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.chan = conf->def.chan; 11266b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.width = conf->def.width; 11276b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.center_freq1 = 11286b4cac81SBjoern A. Zeeb conf->def.center_freq1; 1129*9fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 1130*9fb91463SBjoern A. Zeeb if (vif->bss_conf.chandef.width == NL80211_CHAN_WIDTH_40) { 1131*9fb91463SBjoern A. Zeeb /* Note: it is 10 not 20. */ 1132*9fb91463SBjoern A. Zeeb if (IEEE80211_IS_CHAN_HT40U(ni->ni_chan)) 1133*9fb91463SBjoern A. Zeeb vif->bss_conf.chandef.center_freq1 += 10; 1134*9fb91463SBjoern A. Zeeb else if (IEEE80211_IS_CHAN_HT40D(ni->ni_chan)) 1135*9fb91463SBjoern A. Zeeb vif->bss_conf.chandef.center_freq1 -= 10; 1136*9fb91463SBjoern A. Zeeb } 1137*9fb91463SBjoern A. Zeeb #endif 11386b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.center_freq2 = 11396b4cac81SBjoern A. Zeeb conf->def.center_freq2; 11406b4cac81SBjoern A. Zeeb } else { 1141018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_add_chanctx " 1142018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 11436b4cac81SBjoern A. Zeeb goto out; 11446b4cac81SBjoern A. Zeeb } 11456ffb7bd4SBjoern A. Zeeb 11466ffb7bd4SBjoern A. Zeeb vif->bss_conf.chanctx_conf = conf; 11476ffb7bd4SBjoern A. Zeeb 11486b4cac81SBjoern A. Zeeb /* Assign vif chanctx. */ 11496b4cac81SBjoern A. Zeeb if (error == 0) 115068541546SBjoern A. Zeeb error = lkpi_80211_mo_assign_vif_chanctx(hw, vif, 115168541546SBjoern A. Zeeb &vif->bss_conf, conf); 11526b4cac81SBjoern A. Zeeb if (error == EOPNOTSUPP) 11536b4cac81SBjoern A. Zeeb error = 0; 11546b4cac81SBjoern A. Zeeb if (error != 0) { 1155018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_assign_vif_chanctx " 1156018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 11576b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 1158c5e25798SBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(conf); 1159c5e25798SBjoern A. Zeeb free(lchanctx, M_LKPI80211); 11606b4cac81SBjoern A. Zeeb goto out; 11616b4cac81SBjoern A. Zeeb } 11626b4cac81SBjoern A. Zeeb } 11636b4cac81SBjoern A. Zeeb IMPROVE("update radiotap chan fields too"); 11646b4cac81SBjoern A. Zeeb 11656b4cac81SBjoern A. Zeeb /* RATES */ 11666b4cac81SBjoern A. Zeeb IMPROVE("bss info: not all needs to come now and rates are missing"); 11676b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 11686b4cac81SBjoern A. Zeeb 1169d9f59799SBjoern A. Zeeb /* 1170d9f59799SBjoern A. Zeeb * This is a bandaid for now. If we went through (*iv_update_bss)() 1171d9f59799SBjoern A. Zeeb * and then removed the lsta we end up here without a lsta and have 1172d9f59799SBjoern A. Zeeb * to manually allocate and link it in as lkpi_ic_node_alloc()/init() 1173d9f59799SBjoern A. Zeeb * would normally do. 1174d9f59799SBjoern A. Zeeb * XXX-BZ I do not like this but currently we have no good way of 1175d9f59799SBjoern A. Zeeb * intercepting the bss swap and state changes and packets going out 1176d9f59799SBjoern A. Zeeb * workflow so live with this. It is a compat layer after all. 1177d9f59799SBjoern A. Zeeb */ 1178d9f59799SBjoern A. Zeeb if (ni->ni_drv_data == NULL) { 1179d9f59799SBjoern A. Zeeb lsta = lkpi_lsta_alloc(vap, ni->ni_macaddr, hw, ni); 1180d9f59799SBjoern A. Zeeb if (lsta == NULL) { 1181d9f59799SBjoern A. Zeeb error = ENOMEM; 1182018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: lkpi_lsta_alloc " 1183018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 1184d9f59799SBjoern A. Zeeb goto out; 1185d9f59799SBjoern A. Zeeb } 1186d9f59799SBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 1187d9f59799SBjoern A. Zeeb } else { 11886b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 1189d9f59799SBjoern A. Zeeb } 1190e24e8103SBjoern A. Zeeb 1191e24e8103SBjoern A. Zeeb /* Insert the [l]sta into the list of known stations. */ 1192e24e8103SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 1193e24e8103SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lvif->lsta_head, lsta, lsta_entry); 1194e24e8103SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 1195e24e8103SBjoern A. Zeeb 1196d9f59799SBjoern A. Zeeb /* Add (or adjust) sta and change state (from NOTEXIST) to NONE. */ 11976b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 11986b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NOTEXIST, ("%s: lsta %p state not " 11996b4cac81SBjoern A. Zeeb "NOTEXIST: %#x\n", __func__, lsta, lsta->state)); 1200e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE); 12016b4cac81SBjoern A. Zeeb if (error != 0) { 12026b4cac81SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 1203018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NONE) " 1204018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 12056b4cac81SBjoern A. Zeeb goto out; 12066b4cac81SBjoern A. Zeeb } 12076b4cac81SBjoern A. Zeeb #if 0 12086b4cac81SBjoern A. Zeeb lsta->added_to_drv = true; /* mo manages. */ 12096b4cac81SBjoern A. Zeeb #endif 12106b4cac81SBjoern A. Zeeb 12119d9ba2b7SBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 12129d9ba2b7SBjoern A. Zeeb 12136b4cac81SBjoern A. Zeeb /* 12146b4cac81SBjoern A. Zeeb * Wakeup all queues now that sta is there so we have as much time to 12156b4cac81SBjoern A. Zeeb * possibly prepare the queue in the driver to be ready for the 1st 12166b4cac81SBjoern A. Zeeb * packet; lkpi_80211_txq_tx_one() still has a workaround as there 12176b4cac81SBjoern A. Zeeb * is no guarantee or way to check. 1218d9f59799SBjoern A. Zeeb * XXX-BZ and by now we know that this does not work on all drivers 1219d9f59799SBjoern A. Zeeb * for all queues. 12206b4cac81SBjoern A. Zeeb */ 1221e7fe0373SBjoern A. Zeeb lkpi_wake_tx_queues(hw, LSTA_TO_STA(lsta), false, false); 12226b4cac81SBjoern A. Zeeb 12236b4cac81SBjoern A. Zeeb /* Start mgd_prepare_tx. */ 12246b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 12256b4cac81SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 12266b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 12276b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 12286b4cac81SBjoern A. Zeeb 12296b4cac81SBjoern A. Zeeb /* 12306b4cac81SBjoern A. Zeeb * What is going to happen next: 12316b4cac81SBjoern A. Zeeb * - <twiddle> .. we should end up in "auth_to_assoc" 12326b4cac81SBjoern A. Zeeb * - event_callback 12336b4cac81SBjoern A. Zeeb * - update sta_state (NONE to AUTH) 12346b4cac81SBjoern A. Zeeb * - mgd_complete_tx 12356b4cac81SBjoern A. Zeeb * (ideally we'd do that on a callback for something else ...) 12366b4cac81SBjoern A. Zeeb */ 12376b4cac81SBjoern A. Zeeb 12386b4cac81SBjoern A. Zeeb out: 12398ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 12406b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 12416b4cac81SBjoern A. Zeeb if (ni != NULL) 12426b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 12436b4cac81SBjoern A. Zeeb return (error); 12446b4cac81SBjoern A. Zeeb } 12456b4cac81SBjoern A. Zeeb 12466b4cac81SBjoern A. Zeeb static int 12476b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 12486b4cac81SBjoern A. Zeeb { 12496b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 12506b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 12516b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 12526b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 12536b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 12546b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 12556b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 12566b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 12576b4cac81SBjoern A. Zeeb int error; 12586b4cac81SBjoern A. Zeeb 12596b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 12606b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 12616b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 12626b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 12636b4cac81SBjoern A. Zeeb 12646b4cac81SBjoern A. Zeeb /* Keep ni around. */ 12656b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 12666b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 12676b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 12686b4cac81SBjoern A. Zeeb 126967674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 12706b4cac81SBjoern A. Zeeb 12716b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 12728ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 12736b4cac81SBjoern A. Zeeb 1274d9f59799SBjoern A. Zeeb /* flush, drop. */ 1275d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1276d9f59799SBjoern A. Zeeb 12776b4cac81SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 12786b4cac81SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 12796b4cac81SBjoern A. Zeeb 12806b4cac81SBjoern A. Zeeb /* flush, no drop */ 12816b4cac81SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 12826b4cac81SBjoern A. Zeeb 12836b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 12846b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 12856b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 12866b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 12876b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 12886b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 12896b4cac81SBjoern A. Zeeb } 12906b4cac81SBjoern A. Zeeb 12916b4cac81SBjoern A. Zeeb /* sync_rx_queues */ 12926b4cac81SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 12936b4cac81SBjoern A. Zeeb 12946b4cac81SBjoern A. Zeeb /* sta_pre_rcu_remove */ 12956b4cac81SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 1296d9f59799SBjoern A. Zeeb 1297d9f59799SBjoern A. Zeeb /* Take the station down. */ 12986b4cac81SBjoern A. Zeeb 12996b4cac81SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 13006b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 13016b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 1302d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg)); 1303e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST); 13046b4cac81SBjoern A. Zeeb if (error != 0) { 13056b4cac81SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 1306018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NOTEXIST) " 1307018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 13086b4cac81SBjoern A. Zeeb goto out; 13096b4cac81SBjoern A. Zeeb } 13106b4cac81SBjoern A. Zeeb #if 0 13116b4cac81SBjoern A. Zeeb lsta->added_to_drv = false; /* mo manages. */ 13126b4cac81SBjoern A. Zeeb #endif 13136b4cac81SBjoern A. Zeeb 131467674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 13156b4cac81SBjoern A. Zeeb 1316d9f59799SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif); 1317d9f59799SBjoern A. Zeeb 1318d9f59799SBjoern A. Zeeb /* conf_tx */ 1319d9f59799SBjoern A. Zeeb 1320d9f59799SBjoern A. Zeeb /* Take the chan ctx down. */ 13216b4cac81SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 1322c5e25798SBjoern A. Zeeb struct lkpi_chanctx *lchanctx; 13236b4cac81SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 13246b4cac81SBjoern A. Zeeb 13256b4cac81SBjoern A. Zeeb conf = vif->chanctx_conf; 13266b4cac81SBjoern A. Zeeb /* Remove vif context. */ 132768541546SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->bss_conf, &vif->chanctx_conf); 13286b4cac81SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 13296b4cac81SBjoern A. Zeeb 13306b4cac81SBjoern A. Zeeb /* Remove chan ctx. */ 13316b4cac81SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 1332c5e25798SBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(conf); 1333c5e25798SBjoern A. Zeeb free(lchanctx, M_LKPI80211); 13346b4cac81SBjoern A. Zeeb } 13356b4cac81SBjoern A. Zeeb 13366b4cac81SBjoern A. Zeeb out: 13378ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 13386b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 13396b4cac81SBjoern A. Zeeb if (ni != NULL) 13406b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 13416b4cac81SBjoern A. Zeeb return (error); 13426b4cac81SBjoern A. Zeeb } 13436b4cac81SBjoern A. Zeeb 13446b4cac81SBjoern A. Zeeb static int 13456b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 13466b4cac81SBjoern A. Zeeb { 13476b4cac81SBjoern A. Zeeb int error; 13486b4cac81SBjoern A. Zeeb 13496b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_scan(vap, nstate, arg); 13506b4cac81SBjoern A. Zeeb if (error == 0) 13516b4cac81SBjoern A. Zeeb error = lkpi_sta_scan_to_init(vap, nstate, arg); 13526b4cac81SBjoern A. Zeeb return (error); 13536b4cac81SBjoern A. Zeeb } 13546b4cac81SBjoern A. Zeeb 13556b4cac81SBjoern A. Zeeb static int 13566b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 13576b4cac81SBjoern A. Zeeb { 13586b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 13596b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 13606b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 13616b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 13626b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 13636b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 13646b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 13656b4cac81SBjoern A. Zeeb int error; 13666b4cac81SBjoern A. Zeeb 13676b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 13686b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 13696b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 13706b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 13716b4cac81SBjoern A. Zeeb 13726b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 13738ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 13746b4cac81SBjoern A. Zeeb ni = NULL; 13756b4cac81SBjoern A. Zeeb 13766b4cac81SBjoern A. Zeeb /* Finish auth. */ 13776b4cac81SBjoern A. Zeeb IMPROVE("event callback"); 13786b4cac81SBjoern A. Zeeb 13796b4cac81SBjoern A. Zeeb /* Update sta_state (NONE to AUTH). */ 13806b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 13816b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 13826b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 13836b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 13846b4cac81SBjoern A. Zeeb "NONE: %#x\n", __func__, lsta, lsta->state)); 1385e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH); 1386018d93ecSBjoern A. Zeeb if (error != 0) { 1387018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTH) " 1388018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 13896b4cac81SBjoern A. Zeeb goto out; 1390018d93ecSBjoern A. Zeeb } 13916b4cac81SBjoern A. Zeeb 13926b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 13936b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 13946b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 13956b4cac81SBjoern A. Zeeb prep_tx_info.success = true; 13966b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 13976b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 13986b4cac81SBjoern A. Zeeb } 13996b4cac81SBjoern A. Zeeb 14006b4cac81SBjoern A. Zeeb /* Now start assoc. */ 14016b4cac81SBjoern A. Zeeb 14026b4cac81SBjoern A. Zeeb /* Start mgd_prepare_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.duration = PREP_TX_INFO_DURATION; 14066b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 14076b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 14086b4cac81SBjoern A. Zeeb } 14096b4cac81SBjoern A. Zeeb 14106b4cac81SBjoern A. Zeeb /* Wake tx queue to get packet out. */ 1411e7fe0373SBjoern A. Zeeb lkpi_wake_tx_queues(hw, LSTA_TO_STA(lsta), true, true); 14126b4cac81SBjoern A. Zeeb 14136b4cac81SBjoern A. Zeeb /* 14146b4cac81SBjoern A. Zeeb * <twiddle> .. we end up in "assoc_to_run" 14156b4cac81SBjoern A. Zeeb * - update sta_state (AUTH to ASSOC) 14166b4cac81SBjoern A. Zeeb * - conf_tx [all] 14176b4cac81SBjoern A. Zeeb * - bss_info_changed (assoc, aid, ssid, ..) 14186b4cac81SBjoern A. Zeeb * - change_chanctx (if needed) 14196b4cac81SBjoern A. Zeeb * - event_callback 14206b4cac81SBjoern A. Zeeb * - mgd_complete_tx 14216b4cac81SBjoern A. Zeeb */ 14226b4cac81SBjoern A. Zeeb 14236b4cac81SBjoern A. Zeeb out: 14248ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 14256b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 14266b4cac81SBjoern A. Zeeb if (ni != NULL) 14276b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 14286b4cac81SBjoern A. Zeeb return (error); 14296b4cac81SBjoern A. Zeeb } 14306b4cac81SBjoern A. Zeeb 14316b4cac81SBjoern A. Zeeb /* auth_to_auth, assoc_to_assoc. */ 14326b4cac81SBjoern A. Zeeb static int 14336b4cac81SBjoern A. Zeeb lkpi_sta_a_to_a(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 14346b4cac81SBjoern A. Zeeb { 14356b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 14366b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 14376b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 14386b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 14396b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 14406b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 14416b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 14426b4cac81SBjoern A. Zeeb 14436b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 14446b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 14456b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 14466b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 14476b4cac81SBjoern A. Zeeb 14486b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 14496b4cac81SBjoern A. Zeeb 14506b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 14518ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 14526b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 14536b4cac81SBjoern A. Zeeb 14546b4cac81SBjoern A. Zeeb IMPROVE("event callback?"); 14556b4cac81SBjoern A. Zeeb 14566b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 14576b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 14586b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 14596b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 14606b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 14616b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 14626b4cac81SBjoern A. Zeeb } 14636b4cac81SBjoern A. Zeeb 14646b4cac81SBjoern A. Zeeb /* Now start assoc. */ 14656b4cac81SBjoern A. Zeeb 14666b4cac81SBjoern A. Zeeb /* Start mgd_prepare_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.duration = PREP_TX_INFO_DURATION; 14706b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 14716b4cac81SBjoern A. Zeeb lsta->in_mgd = true; 14726b4cac81SBjoern A. Zeeb } 14736b4cac81SBjoern A. Zeeb 14748ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 14756b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 14766b4cac81SBjoern A. Zeeb if (ni != NULL) 14776b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 14786b4cac81SBjoern A. Zeeb 14796b4cac81SBjoern A. Zeeb return (0); 14806b4cac81SBjoern A. Zeeb } 14816b4cac81SBjoern A. Zeeb 14826b4cac81SBjoern A. Zeeb static int 1483d9f59799SBjoern A. Zeeb _lkpi_sta_assoc_to_down(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 14846b4cac81SBjoern A. Zeeb { 14856b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 14866b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 14876b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 14886b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 14896b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 14906b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 14916b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 14926b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 1493d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 14946b4cac81SBjoern A. Zeeb int error; 14956b4cac81SBjoern A. Zeeb 14966b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 14976b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 14986b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 14996b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 15006b4cac81SBjoern A. Zeeb 15016b4cac81SBjoern A. Zeeb /* Keep ni around. */ 15026b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 15036b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 15046b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 15056b4cac81SBjoern A. Zeeb 150667674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1507d9f59799SBjoern A. Zeeb 1508d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 15098ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1510d9f59799SBjoern A. Zeeb 1511d9f59799SBjoern A. Zeeb /* flush, drop. */ 1512d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1513d9f59799SBjoern A. Zeeb 1514d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?"); 1515d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) && 1516d9f59799SBjoern A. Zeeb !lsta->in_mgd) { 1517d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1518d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 1519d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 1520d9f59799SBjoern A. Zeeb lsta->in_mgd = true; 1521d9f59799SBjoern A. Zeeb } 1522d9f59799SBjoern A. Zeeb 15238ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 1524d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1525d9f59799SBjoern A. Zeeb 1526d9f59799SBjoern A. Zeeb /* Call iv_newstate first so we get potential DISASSOC packet out. */ 1527d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 1528018d93ecSBjoern A. Zeeb if (error != 0) { 1529018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: iv_newstate(%p, %d, %d) " 1530018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, vap, nstate, arg, error); 1531d9f59799SBjoern A. Zeeb goto outni; 1532018d93ecSBjoern A. Zeeb } 1533d9f59799SBjoern A. Zeeb 1534d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 15358ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1536d9f59799SBjoern A. Zeeb 153767674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1538d9f59799SBjoern A. Zeeb 1539d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 1540d9f59799SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 1541d9f59799SBjoern A. Zeeb 1542d9f59799SBjoern A. Zeeb /* flush, no drop */ 1543d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 1544d9f59799SBjoern A. Zeeb 15456b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 15466b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 15476b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 15486b4cac81SBjoern A. Zeeb prep_tx_info.success = false; 15496b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 15506b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 15516b4cac81SBjoern A. Zeeb } 15526b4cac81SBjoern A. Zeeb 1553d9f59799SBjoern A. Zeeb /* sync_rx_queues */ 1554d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 1555d9f59799SBjoern A. Zeeb 1556d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */ 1557d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 1558d9f59799SBjoern A. Zeeb 1559d9f59799SBjoern A. Zeeb /* Take the station down. */ 1560d9f59799SBjoern A. Zeeb 15616b4cac81SBjoern A. Zeeb /* Update sta and change state (from AUTH) to NONE. */ 15626b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 15636b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 15646b4cac81SBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 1565e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE); 1566018d93ecSBjoern A. Zeeb if (error != 0) { 1567018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NONE) " 1568018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 15696b4cac81SBjoern A. Zeeb goto out; 1570018d93ecSBjoern A. Zeeb } 15716b4cac81SBjoern A. Zeeb 157267674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 15736b4cac81SBjoern A. Zeeb 157416e688b2SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 157516e688b2SBjoern A. Zeeb /* 157616e688b2SBjoern A. Zeeb * We need to do this now, before sta changes to IEEE80211_STA_NOTEXIST 157716e688b2SBjoern A. Zeeb * as otherwise drivers (iwlwifi at least) will silently not remove 157816e688b2SBjoern A. Zeeb * the sta from the firmware and when we will add a new one trigger 157916e688b2SBjoern A. Zeeb * a fw assert. 158016e688b2SBjoern A. Zeeb */ 158116e688b2SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw); 158216e688b2SBjoern A. Zeeb 1583d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 1584d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 1585d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 1586d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg)); 1587e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST); 1588d9f59799SBjoern A. Zeeb if (error != 0) { 1589d9f59799SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 1590018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NOTEXIST) " 1591018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 1592d9f59799SBjoern A. Zeeb goto out; 1593d9f59799SBjoern A. Zeeb } 1594d9f59799SBjoern A. Zeeb 159516e688b2SBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); /* sta no longer save to use. */ 1596d9f59799SBjoern A. Zeeb 1597d9f59799SBjoern A. Zeeb IMPROVE("Any bss_info changes to announce?"); 1598d9f59799SBjoern A. Zeeb bss_changed = 0; 1599d9f59799SBjoern A. Zeeb vif->bss_conf.qos = 0; 1600d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 1601616e1330SBjoern A. Zeeb vif->cfg.ssid_len = 0; 1602616e1330SBjoern A. Zeeb memset(vif->cfg.ssid, '\0', sizeof(vif->cfg.ssid)); 1603d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 1604d9f59799SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 1605d9f59799SBjoern A. Zeeb 1606d9f59799SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif); 1607d9f59799SBjoern A. Zeeb 1608d9f59799SBjoern A. Zeeb /* conf_tx */ 1609d9f59799SBjoern A. Zeeb 1610d9f59799SBjoern A. Zeeb /* Take the chan ctx down. */ 1611d9f59799SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 1612c5e25798SBjoern A. Zeeb struct lkpi_chanctx *lchanctx; 1613d9f59799SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 1614d9f59799SBjoern A. Zeeb 1615d9f59799SBjoern A. Zeeb conf = vif->chanctx_conf; 1616d9f59799SBjoern A. Zeeb /* Remove vif context. */ 161768541546SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->bss_conf, &vif->chanctx_conf); 1618d9f59799SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 1619d9f59799SBjoern A. Zeeb 1620d9f59799SBjoern A. Zeeb /* Remove chan ctx. */ 1621d9f59799SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 1622c5e25798SBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(conf); 1623c5e25798SBjoern A. Zeeb free(lchanctx, M_LKPI80211); 1624d9f59799SBjoern A. Zeeb } 1625d9f59799SBjoern A. Zeeb 1626d9f59799SBjoern A. Zeeb error = EALREADY; 16276b4cac81SBjoern A. Zeeb out: 16288ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 16296b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1630d9f59799SBjoern A. Zeeb outni: 16316b4cac81SBjoern A. Zeeb if (ni != NULL) 16326b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 16336b4cac81SBjoern A. Zeeb return (error); 16346b4cac81SBjoern A. Zeeb } 16356b4cac81SBjoern A. Zeeb 16366b4cac81SBjoern A. Zeeb static int 1637d9f59799SBjoern A. Zeeb lkpi_sta_assoc_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 1638d9f59799SBjoern A. Zeeb { 1639d9f59799SBjoern A. Zeeb int error; 1640d9f59799SBjoern A. Zeeb 1641d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg); 1642d9f59799SBjoern A. Zeeb if (error != 0 && error != EALREADY) 1643d9f59799SBjoern A. Zeeb return (error); 1644d9f59799SBjoern A. Zeeb 1645d9f59799SBjoern A. Zeeb /* At this point iv_bss is long a new node! */ 1646d9f59799SBjoern A. Zeeb 1647d9f59799SBjoern A. Zeeb error |= lkpi_sta_scan_to_auth(vap, nstate, 0); 1648d9f59799SBjoern A. Zeeb return (error); 1649d9f59799SBjoern A. Zeeb } 1650d9f59799SBjoern A. Zeeb 1651d9f59799SBjoern A. Zeeb static int 16526b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 16536b4cac81SBjoern A. Zeeb { 16546b4cac81SBjoern A. Zeeb int error; 16556b4cac81SBjoern A. Zeeb 1656d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg); 16576b4cac81SBjoern A. Zeeb return (error); 16586b4cac81SBjoern A. Zeeb } 16596b4cac81SBjoern A. Zeeb 16606b4cac81SBjoern A. Zeeb static int 16616b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 16626b4cac81SBjoern A. Zeeb { 16636b4cac81SBjoern A. Zeeb int error; 16646b4cac81SBjoern A. Zeeb 1665d9f59799SBjoern A. Zeeb error = _lkpi_sta_assoc_to_down(vap, nstate, arg); 16666b4cac81SBjoern A. Zeeb return (error); 16676b4cac81SBjoern A. Zeeb } 16686b4cac81SBjoern A. Zeeb 16696b4cac81SBjoern A. Zeeb static int 16706b4cac81SBjoern A. Zeeb lkpi_sta_assoc_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 16716b4cac81SBjoern A. Zeeb { 16726b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 16736b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 16746b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 16756b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 16766b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 16776b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 16786b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 16796b4cac81SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 16806b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 16816b4cac81SBjoern A. Zeeb int error; 16826b4cac81SBjoern A. Zeeb 16836b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 16846b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 16856b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 16866b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 16876b4cac81SBjoern A. Zeeb 16886b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 16898ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 16909597f7cbSBjoern A. Zeeb ni = NULL; 16916b4cac81SBjoern A. Zeeb 16926b4cac81SBjoern A. Zeeb IMPROVE("ponder some of this moved to ic_newassoc, scan_assoc_success, " 16936b4cac81SBjoern A. Zeeb "and to lesser extend ieee80211_notify_node_join"); 16946b4cac81SBjoern A. Zeeb 16959597f7cbSBjoern A. Zeeb /* Finish assoc. */ 16969597f7cbSBjoern A. Zeeb /* Update sta_state (AUTH to ASSOC) and set aid. */ 16976b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 16986b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 16996b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 17009597f7cbSBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 17019597f7cbSBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 17026b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 17039597f7cbSBjoern A. Zeeb sta->aid = IEEE80211_NODE_AID(ni); 17044a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 17054a67f1dfSBjoern A. Zeeb if (vap->iv_flags & IEEE80211_F_WME) 17064a67f1dfSBjoern A. Zeeb sta->wme = true; 17074a67f1dfSBjoern A. Zeeb #endif 1708e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC); 1709018d93ecSBjoern A. Zeeb if (error != 0) { 1710018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(ASSOC) " 1711018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 17129597f7cbSBjoern A. Zeeb goto out; 1713018d93ecSBjoern A. Zeeb } 17146b4cac81SBjoern A. Zeeb 17156b4cac81SBjoern A. Zeeb IMPROVE("wme / conf_tx [all]"); 17166b4cac81SBjoern A. Zeeb 17176b4cac81SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 17186b4cac81SBjoern A. Zeeb bss_changed = 0; 17194a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 17204a67f1dfSBjoern A. Zeeb bss_changed |= lkpi_wme_update(lhw, vap, true); 17214a67f1dfSBjoern A. Zeeb #endif 1722616e1330SBjoern A. Zeeb if (!vif->cfg.assoc || vif->cfg.aid != IEEE80211_NODE_AID(ni)) { 1723616e1330SBjoern A. Zeeb vif->cfg.assoc = true; 1724616e1330SBjoern A. Zeeb vif->cfg.aid = IEEE80211_NODE_AID(ni); 17256b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_ASSOC; 17266b4cac81SBjoern A. Zeeb } 17276b4cac81SBjoern A. Zeeb /* We set SSID but this is not BSSID! */ 1728616e1330SBjoern A. Zeeb vif->cfg.ssid_len = ni->ni_esslen; 1729616e1330SBjoern A. Zeeb memcpy(vif->cfg.ssid, ni->ni_essid, ni->ni_esslen); 17306b4cac81SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_SHPREAMBLE) != 17316b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble) { 17326b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble ^= 1; 17336b4cac81SBjoern A. Zeeb /* bss_changed |= BSS_CHANGED_??? */ 17346b4cac81SBjoern A. Zeeb } 17356b4cac81SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_SHSLOT) != 17366b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot) { 17376b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot ^= 1; 17386b4cac81SBjoern A. Zeeb /* bss_changed |= BSS_CHANGED_??? */ 17396b4cac81SBjoern A. Zeeb } 17406b4cac81SBjoern A. Zeeb if ((ni->ni_flags & IEEE80211_NODE_QOS) != 17416b4cac81SBjoern A. Zeeb vif->bss_conf.qos) { 17426b4cac81SBjoern A. Zeeb vif->bss_conf.qos ^= 1; 17436b4cac81SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 17446b4cac81SBjoern A. Zeeb } 1745fa8f007dSBjoern A. Zeeb 1746fa8f007dSBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 1747fa8f007dSBjoern A. Zeeb 17486b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 17496b4cac81SBjoern A. Zeeb 17506b4cac81SBjoern A. Zeeb /* - change_chanctx (if needed) 17516b4cac81SBjoern A. Zeeb * - event_callback 17526b4cac81SBjoern A. Zeeb */ 17536b4cac81SBjoern A. Zeeb 17546b4cac81SBjoern A. Zeeb /* End mgd_complete_tx. */ 17556b4cac81SBjoern A. Zeeb if (lsta->in_mgd) { 17566b4cac81SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 17576b4cac81SBjoern A. Zeeb prep_tx_info.success = true; 17586b4cac81SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 17596b4cac81SBjoern A. Zeeb lsta->in_mgd = false; 17606b4cac81SBjoern A. Zeeb } 17616b4cac81SBjoern A. Zeeb 1762086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, false); 1763086be6a8SBjoern A. Zeeb 17646b4cac81SBjoern A. Zeeb /* 17656b4cac81SBjoern A. Zeeb * And then: 17666b4cac81SBjoern A. Zeeb * - (more packets)? 17676b4cac81SBjoern A. Zeeb * - set_key 17686b4cac81SBjoern A. Zeeb * - set_default_unicast_key 17696b4cac81SBjoern A. Zeeb * - set_key (?) 17706b4cac81SBjoern A. Zeeb * - ipv6_addr_change (?) 17716b4cac81SBjoern A. Zeeb */ 17726b4cac81SBjoern A. Zeeb /* Prepare_multicast && configure_filter. */ 17736b4cac81SBjoern A. Zeeb lhw->update_mc = true; 17746b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(vap->iv_ic, true); 17756b4cac81SBjoern A. Zeeb 17766b4cac81SBjoern A. Zeeb if (!ieee80211_node_is_authorized(ni)) { 17776b4cac81SBjoern A. Zeeb IMPROVE("net80211 does not consider node authorized"); 17786b4cac81SBjoern A. Zeeb } 17796b4cac81SBjoern A. Zeeb 1780*9fb91463SBjoern A. Zeeb #if defined(LKPI_80211_HT) 1781*9fb91463SBjoern A. Zeeb IMPROVE("Is this the right spot, has net80211 done all updates already?"); 1782*9fb91463SBjoern A. Zeeb lkpi_sta_sync_ht_from_ni(sta, ni, NULL); 1783*9fb91463SBjoern A. Zeeb #endif 1784*9fb91463SBjoern A. Zeeb 17856b4cac81SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTHORIZED). */ 17866b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 17876b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 17886b4cac81SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 1789e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTHORIZED); 17906b4cac81SBjoern A. Zeeb if (error != 0) { 17916b4cac81SBjoern A. Zeeb IMPROVE("undo some changes?"); 1792018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTHORIZED) " 1793018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 17946b4cac81SBjoern A. Zeeb goto out; 17956b4cac81SBjoern A. Zeeb } 17966b4cac81SBjoern A. Zeeb 17976b4cac81SBjoern A. Zeeb /* - drv_config (?) 17986b4cac81SBjoern A. Zeeb * - bss_info_changed 17996b4cac81SBjoern A. Zeeb * - set_rekey_data (?) 18006b4cac81SBjoern A. Zeeb * 18016b4cac81SBjoern A. Zeeb * And now we should be passing packets. 18026b4cac81SBjoern A. Zeeb */ 18036b4cac81SBjoern A. Zeeb IMPROVE("Need that bssid setting, and the keys"); 18046b4cac81SBjoern A. Zeeb 1805fa8f007dSBjoern A. Zeeb bss_changed = 0; 1806fa8f007dSBjoern A. Zeeb bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__); 1807fa8f007dSBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 1808fa8f007dSBjoern A. Zeeb 18096b4cac81SBjoern A. Zeeb out: 18108ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 18116b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 18126b4cac81SBjoern A. Zeeb if (ni != NULL) 18136b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 18146b4cac81SBjoern A. Zeeb return (error); 18156b4cac81SBjoern A. Zeeb } 18166b4cac81SBjoern A. Zeeb 18176b4cac81SBjoern A. Zeeb static int 18186b4cac81SBjoern A. Zeeb lkpi_sta_auth_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 18196b4cac81SBjoern A. Zeeb { 18206b4cac81SBjoern A. Zeeb int error; 18216b4cac81SBjoern A. Zeeb 18226b4cac81SBjoern A. Zeeb error = lkpi_sta_auth_to_assoc(vap, nstate, arg); 18236b4cac81SBjoern A. Zeeb if (error == 0) 18246b4cac81SBjoern A. Zeeb error = lkpi_sta_assoc_to_run(vap, nstate, arg); 18256b4cac81SBjoern A. Zeeb return (error); 18266b4cac81SBjoern A. Zeeb } 18276b4cac81SBjoern A. Zeeb 18286b4cac81SBjoern A. Zeeb static int 18296b4cac81SBjoern A. Zeeb lkpi_sta_run_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 18306b4cac81SBjoern A. Zeeb { 18316b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 18326b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 18336b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 18346b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 18356b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 18366b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 18376b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 1838d9f59799SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 1839d9f59799SBjoern A. Zeeb #if 0 1840d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 1841d9f59799SBjoern A. Zeeb #endif 18426b4cac81SBjoern A. Zeeb int error; 18436b4cac81SBjoern A. Zeeb 18446b4cac81SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 18456b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 18466b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 18476b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 18486b4cac81SBjoern A. Zeeb 18496b4cac81SBjoern A. Zeeb /* Keep ni around. */ 18506b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 18516b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 18526b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 18536b4cac81SBjoern A. Zeeb 185467674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1855d9f59799SBjoern A. Zeeb 1856d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 18578ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1858d9f59799SBjoern A. Zeeb 1859d9f59799SBjoern A. Zeeb /* flush, drop. */ 1860d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1861d9f59799SBjoern A. Zeeb 1862d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?"); 1863d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) && 1864d9f59799SBjoern A. Zeeb !lsta->in_mgd) { 1865d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1866d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 1867d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 1868d9f59799SBjoern A. Zeeb lsta->in_mgd = true; 1869d9f59799SBjoern A. Zeeb } 1870d9f59799SBjoern A. Zeeb 18718ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 1872d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1873d9f59799SBjoern A. Zeeb 1874d9f59799SBjoern A. Zeeb /* Call iv_newstate first so we get potential DISASSOC packet out. */ 1875d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 1876018d93ecSBjoern A. Zeeb if (error != 0) { 1877018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: iv_newstate(%p, %d, %d) " 1878018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, vap, nstate, arg, error); 1879d9f59799SBjoern A. Zeeb goto outni; 1880018d93ecSBjoern A. Zeeb } 1881d9f59799SBjoern A. Zeeb 1882d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 18838ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1884d9f59799SBjoern A. Zeeb 188567674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1886d9f59799SBjoern A. Zeeb 1887d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 1888d9f59799SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 1889d9f59799SBjoern A. Zeeb 1890d9f59799SBjoern A. Zeeb /* flush, no drop */ 1891d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 1892d9f59799SBjoern A. Zeeb 1893d9f59799SBjoern A. Zeeb /* End mgd_complete_tx. */ 1894d9f59799SBjoern A. Zeeb if (lsta->in_mgd) { 1895d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1896d9f59799SBjoern A. Zeeb prep_tx_info.success = false; 1897d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 1898d9f59799SBjoern A. Zeeb lsta->in_mgd = false; 1899d9f59799SBjoern A. Zeeb } 1900d9f59799SBjoern A. Zeeb 1901d9f59799SBjoern A. Zeeb #if 0 1902d9f59799SBjoern A. Zeeb /* sync_rx_queues */ 1903d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 1904d9f59799SBjoern A. Zeeb 1905d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */ 1906d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 1907d9f59799SBjoern A. Zeeb #endif 1908d9f59799SBjoern A. Zeeb 1909d9f59799SBjoern A. Zeeb /* Take the station down. */ 1910d9f59799SBjoern A. Zeeb 19116b4cac81SBjoern A. Zeeb /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */ 19126b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 19136b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not " 19146b4cac81SBjoern A. Zeeb "AUTHORIZED: %#x\n", __func__, lsta, lsta->state)); 1915e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC); 1916018d93ecSBjoern A. Zeeb if (error != 0) { 1917018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(ASSOC) " 1918018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 19196b4cac81SBjoern A. Zeeb goto out; 1920018d93ecSBjoern A. Zeeb } 19216b4cac81SBjoern A. Zeeb 192267674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 19236b4cac81SBjoern A. Zeeb 19246b4cac81SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTH). */ 19256b4cac81SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 19266b4cac81SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 19276b4cac81SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 1928e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH); 1929018d93ecSBjoern A. Zeeb if (error != 0) { 1930018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTH) " 1931018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 19326b4cac81SBjoern A. Zeeb goto out; 1933018d93ecSBjoern A. Zeeb } 19346b4cac81SBjoern A. Zeeb 193567674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 19366b4cac81SBjoern A. Zeeb 1937d9f59799SBjoern A. Zeeb #if 0 1938d9f59799SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 1939d9f59799SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw); 1940d9f59799SBjoern A. Zeeb #endif 1941d9f59799SBjoern A. Zeeb 1942d9f59799SBjoern A. Zeeb error = EALREADY; 19436b4cac81SBjoern A. Zeeb out: 19448ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 19456b4cac81SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1946d9f59799SBjoern A. Zeeb outni: 19476b4cac81SBjoern A. Zeeb if (ni != NULL) 19486b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 19496b4cac81SBjoern A. Zeeb return (error); 19506b4cac81SBjoern A. Zeeb } 19516b4cac81SBjoern A. Zeeb 19526b4cac81SBjoern A. Zeeb static int 1953d9f59799SBjoern A. Zeeb lkpi_sta_run_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 1954d9f59799SBjoern A. Zeeb { 1955d9f59799SBjoern A. Zeeb struct lkpi_hw *lhw; 1956d9f59799SBjoern A. Zeeb struct ieee80211_hw *hw; 1957d9f59799SBjoern A. Zeeb struct lkpi_vif *lvif; 1958d9f59799SBjoern A. Zeeb struct ieee80211_vif *vif; 1959d9f59799SBjoern A. Zeeb struct ieee80211_node *ni; 1960d9f59799SBjoern A. Zeeb struct lkpi_sta *lsta; 1961d9f59799SBjoern A. Zeeb struct ieee80211_sta *sta; 1962d9f59799SBjoern A. Zeeb struct ieee80211_prep_tx_info prep_tx_info; 1963d9f59799SBjoern A. Zeeb enum ieee80211_bss_changed bss_changed; 1964d9f59799SBjoern A. Zeeb int error; 1965d9f59799SBjoern A. Zeeb 1966d9f59799SBjoern A. Zeeb lhw = vap->iv_ic->ic_softc; 1967d9f59799SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 1968d9f59799SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 1969d9f59799SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 1970d9f59799SBjoern A. Zeeb 1971d9f59799SBjoern A. Zeeb /* Keep ni around. */ 1972d9f59799SBjoern A. Zeeb ni = ieee80211_ref_node(vap->iv_bss); 1973d9f59799SBjoern A. Zeeb lsta = ni->ni_drv_data; 1974d9f59799SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 1975d9f59799SBjoern A. Zeeb 197667674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 1977d9f59799SBjoern A. Zeeb 1978d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 19798ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 1980d9f59799SBjoern A. Zeeb 1981d9f59799SBjoern A. Zeeb /* flush, drop. */ 1982d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true); 1983d9f59799SBjoern A. Zeeb 1984d9f59799SBjoern A. Zeeb IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?"); 1985d9f59799SBjoern A. Zeeb if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) && 1986d9f59799SBjoern A. Zeeb !lsta->in_mgd) { 1987d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 1988d9f59799SBjoern A. Zeeb prep_tx_info.duration = PREP_TX_INFO_DURATION; 1989d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info); 1990d9f59799SBjoern A. Zeeb lsta->in_mgd = true; 1991d9f59799SBjoern A. Zeeb } 1992d9f59799SBjoern A. Zeeb 19938ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 1994d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 1995d9f59799SBjoern A. Zeeb 1996d9f59799SBjoern A. Zeeb /* Call iv_newstate first so we get potential DISASSOC packet out. */ 1997d9f59799SBjoern A. Zeeb error = lvif->iv_newstate(vap, nstate, arg); 1998018d93ecSBjoern A. Zeeb if (error != 0) { 1999018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: iv_newstate(%p, %d, %d) " 2000018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, vap, nstate, arg, error); 2001d9f59799SBjoern A. Zeeb goto outni; 2002018d93ecSBjoern A. Zeeb } 2003d9f59799SBjoern A. Zeeb 2004d9f59799SBjoern A. Zeeb IEEE80211_UNLOCK(vap->iv_ic); 20058ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 2006d9f59799SBjoern A. Zeeb 200767674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 2008d9f59799SBjoern A. Zeeb 2009d9f59799SBjoern A. Zeeb /* Wake tx queues to get packet(s) out. */ 2010d9f59799SBjoern A. Zeeb lkpi_wake_tx_queues(hw, sta, true, true); 2011d9f59799SBjoern A. Zeeb 2012d9f59799SBjoern A. Zeeb /* flush, no drop */ 2013d9f59799SBjoern A. Zeeb lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false); 2014d9f59799SBjoern A. Zeeb 2015d9f59799SBjoern A. Zeeb /* End mgd_complete_tx. */ 2016d9f59799SBjoern A. Zeeb if (lsta->in_mgd) { 2017d9f59799SBjoern A. Zeeb memset(&prep_tx_info, 0, sizeof(prep_tx_info)); 2018d9f59799SBjoern A. Zeeb prep_tx_info.success = false; 2019d9f59799SBjoern A. Zeeb lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info); 2020d9f59799SBjoern A. Zeeb lsta->in_mgd = false; 2021d9f59799SBjoern A. Zeeb } 2022d9f59799SBjoern A. Zeeb 2023d9f59799SBjoern A. Zeeb /* sync_rx_queues */ 2024d9f59799SBjoern A. Zeeb lkpi_80211_mo_sync_rx_queues(hw); 2025d9f59799SBjoern A. Zeeb 2026d9f59799SBjoern A. Zeeb /* sta_pre_rcu_remove */ 2027d9f59799SBjoern A. Zeeb lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta); 2028d9f59799SBjoern A. Zeeb 2029d9f59799SBjoern A. Zeeb /* Take the station down. */ 2030d9f59799SBjoern A. Zeeb 2031d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */ 2032d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 2033d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not " 2034d9f59799SBjoern A. Zeeb "AUTHORIZED: %#x\n", __func__, lsta, lsta->state)); 2035e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC); 2036018d93ecSBjoern A. Zeeb if (error != 0) { 2037018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(ASSOC) " 2038018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 2039d9f59799SBjoern A. Zeeb goto out; 2040018d93ecSBjoern A. Zeeb } 2041d9f59799SBjoern A. Zeeb 204267674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 2043d9f59799SBjoern A. Zeeb 2044d9f59799SBjoern A. Zeeb /* Update sta_state (ASSOC to AUTH). */ 2045d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 2046d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not " 2047d9f59799SBjoern A. Zeeb "ASSOC: %#x\n", __func__, lsta, lsta->state)); 2048e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH); 2049018d93ecSBjoern A. Zeeb if (error != 0) { 2050018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTH) " 2051018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 2052d9f59799SBjoern A. Zeeb goto out; 2053018d93ecSBjoern A. Zeeb } 2054d9f59799SBjoern A. Zeeb 205567674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 2056d9f59799SBjoern A. Zeeb 2057d9f59799SBjoern A. Zeeb /* Update sta and change state (from AUTH) to NONE. */ 2058d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 2059d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not " 2060d9f59799SBjoern A. Zeeb "AUTH: %#x\n", __func__, lsta, lsta->state)); 2061e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE); 2062018d93ecSBjoern A. Zeeb if (error != 0) { 2063018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NONE) " 2064018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 2065d9f59799SBjoern A. Zeeb goto out; 2066018d93ecSBjoern A. Zeeb } 2067d9f59799SBjoern A. Zeeb 206867674c1cSBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); 2069d9f59799SBjoern A. Zeeb 207016e688b2SBjoern A. Zeeb /* Update bss info (bss_info_changed) (assoc, aid, ..). */ 207116e688b2SBjoern A. Zeeb /* 207216e688b2SBjoern A. Zeeb * One would expect this to happen when going off AUTHORIZED. 207316e688b2SBjoern A. Zeeb * See comment there; removes the sta from fw. 207416e688b2SBjoern A. Zeeb */ 207516e688b2SBjoern A. Zeeb lkpi_disassoc(sta, vif, lhw); 207616e688b2SBjoern A. Zeeb 2077d9f59799SBjoern A. Zeeb /* Adjust sta and change state (from NONE) to NOTEXIST. */ 2078d9f59799SBjoern A. Zeeb KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni)); 2079d9f59799SBjoern A. Zeeb KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not " 2080d9f59799SBjoern A. Zeeb "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg)); 2081e7fe0373SBjoern A. Zeeb error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST); 2082d9f59799SBjoern A. Zeeb if (error != 0) { 2083d9f59799SBjoern A. Zeeb IMPROVE("do we need to undo the chan ctx?"); 2084018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NOTEXIST) " 2085018d93ecSBjoern A. Zeeb "failed: %d\n", __func__, __LINE__, error); 2086d9f59799SBjoern A. Zeeb goto out; 2087d9f59799SBjoern A. Zeeb } 2088d9f59799SBjoern A. Zeeb 208916e688b2SBjoern A. Zeeb lkpi_lsta_dump(lsta, ni, __func__, __LINE__); /* sta no longer save to use. */ 2090d9f59799SBjoern A. Zeeb 2091d9f59799SBjoern A. Zeeb IMPROVE("Any bss_info changes to announce?"); 2092d9f59799SBjoern A. Zeeb bss_changed = 0; 2093d9f59799SBjoern A. Zeeb vif->bss_conf.qos = 0; 2094d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_QOS; 2095616e1330SBjoern A. Zeeb vif->cfg.ssid_len = 0; 2096616e1330SBjoern A. Zeeb memset(vif->cfg.ssid, '\0', sizeof(vif->cfg.ssid)); 2097d9f59799SBjoern A. Zeeb bss_changed |= BSS_CHANGED_BSSID; 2098d9f59799SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed); 2099d9f59799SBjoern A. Zeeb 2100d9f59799SBjoern A. Zeeb lkpi_lsta_remove(lsta, lvif); 2101d9f59799SBjoern A. Zeeb 2102d9f59799SBjoern A. Zeeb /* conf_tx */ 2103d9f59799SBjoern A. Zeeb 2104d9f59799SBjoern A. Zeeb /* Take the chan ctx down. */ 2105d9f59799SBjoern A. Zeeb if (vif->chanctx_conf != NULL) { 2106c5e25798SBjoern A. Zeeb struct lkpi_chanctx *lchanctx; 2107d9f59799SBjoern A. Zeeb struct ieee80211_chanctx_conf *conf; 2108d9f59799SBjoern A. Zeeb 2109d9f59799SBjoern A. Zeeb conf = vif->chanctx_conf; 2110d9f59799SBjoern A. Zeeb /* Remove vif context. */ 211168541546SBjoern A. Zeeb lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->bss_conf, &vif->chanctx_conf); 2112d9f59799SBjoern A. Zeeb /* NB: vif->chanctx_conf is NULL now. */ 2113d9f59799SBjoern A. Zeeb 2114d9f59799SBjoern A. Zeeb /* Remove chan ctx. */ 2115d9f59799SBjoern A. Zeeb lkpi_80211_mo_remove_chanctx(hw, conf); 2116c5e25798SBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(conf); 2117c5e25798SBjoern A. Zeeb free(lchanctx, M_LKPI80211); 2118d9f59799SBjoern A. Zeeb } 2119d9f59799SBjoern A. Zeeb 2120d9f59799SBjoern A. Zeeb error = EALREADY; 2121d9f59799SBjoern A. Zeeb out: 21228ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 2123d9f59799SBjoern A. Zeeb IEEE80211_LOCK(vap->iv_ic); 2124d9f59799SBjoern A. Zeeb outni: 2125d9f59799SBjoern A. Zeeb if (ni != NULL) 2126d9f59799SBjoern A. Zeeb ieee80211_free_node(ni); 2127d9f59799SBjoern A. Zeeb return (error); 2128d9f59799SBjoern A. Zeeb } 2129d9f59799SBjoern A. Zeeb 2130d9f59799SBjoern A. Zeeb static int 2131d9f59799SBjoern A. Zeeb lkpi_sta_run_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 2132d9f59799SBjoern A. Zeeb { 2133d9f59799SBjoern A. Zeeb 2134d9f59799SBjoern A. Zeeb return (lkpi_sta_run_to_init(vap, nstate, arg)); 2135d9f59799SBjoern A. Zeeb } 2136d9f59799SBjoern A. Zeeb 2137d9f59799SBjoern A. Zeeb static int 21386b4cac81SBjoern A. Zeeb lkpi_sta_run_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 21396b4cac81SBjoern A. Zeeb { 21406b4cac81SBjoern A. Zeeb int error; 21416b4cac81SBjoern A. Zeeb 2142d9f59799SBjoern A. Zeeb error = lkpi_sta_run_to_init(vap, nstate, arg); 2143d9f59799SBjoern A. Zeeb if (error != 0 && error != EALREADY) 2144d9f59799SBjoern A. Zeeb return (error); 2145d9f59799SBjoern A. Zeeb 2146d9f59799SBjoern A. Zeeb /* At this point iv_bss is long a new node! */ 2147d9f59799SBjoern A. Zeeb 2148d9f59799SBjoern A. Zeeb error |= lkpi_sta_scan_to_auth(vap, nstate, 0); 21496b4cac81SBjoern A. Zeeb return (error); 21506b4cac81SBjoern A. Zeeb } 21516b4cac81SBjoern A. Zeeb 2152d9f59799SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 21536b4cac81SBjoern A. Zeeb 21546b4cac81SBjoern A. Zeeb /* 21556b4cac81SBjoern A. Zeeb * The matches the documented state changes in net80211::sta_newstate(). 21566b4cac81SBjoern A. Zeeb * XXX (1) without CSA and SLEEP yet, * XXX (2) not all unhandled cases 21576b4cac81SBjoern A. Zeeb * there are "invalid" (so there is a room for failure here). 21586b4cac81SBjoern A. Zeeb */ 21596b4cac81SBjoern A. Zeeb struct fsm_state { 21606b4cac81SBjoern A. Zeeb /* INIT, SCAN, AUTH, ASSOC, CAC, RUN, CSA, SLEEP */ 21616b4cac81SBjoern A. Zeeb enum ieee80211_state ostate; 21626b4cac81SBjoern A. Zeeb enum ieee80211_state nstate; 21636b4cac81SBjoern A. Zeeb int (*handler)(struct ieee80211vap *, enum ieee80211_state, int); 21646b4cac81SBjoern A. Zeeb } sta_state_fsm[] = { 21656b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, 21666b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, /* scan_to_init */ 21676b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_INIT, lkpi_sta_auth_to_init }, /* not explicitly in sta_newstate() */ 2168d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_INIT, lkpi_sta_assoc_to_init }, /* Send DEAUTH. */ 2169d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_INIT, lkpi_sta_run_to_init }, /* Send DISASSOC. */ 21706b4cac81SBjoern A. Zeeb 21716b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_SCAN, lkpi_sta_state_do_nada }, 21726b4cac81SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_SCAN, lkpi_sta_state_do_nada }, 21736b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_SCAN, lkpi_sta_auth_to_scan }, 21746b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_SCAN, lkpi_sta_assoc_to_scan }, 2175d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_SCAN, lkpi_sta_run_to_scan }, /* Beacon miss. */ 21766b4cac81SBjoern A. Zeeb 2177d9f59799SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, /* Send AUTH. */ 2178d9f59799SBjoern A. Zeeb { IEEE80211_S_SCAN, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, /* Send AUTH. */ 2179d9f59799SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_AUTH, lkpi_sta_a_to_a }, /* Send ?AUTH. */ 2180d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_AUTH, lkpi_sta_assoc_to_auth }, /* Send ?AUTH. */ 2181d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_AUTH, lkpi_sta_run_to_auth }, /* Send ?AUTH. */ 21826b4cac81SBjoern A. Zeeb 2183d9f59799SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_ASSOC, lkpi_sta_auth_to_assoc }, /* Send ASSOCREQ. */ 2184d9f59799SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_ASSOC, lkpi_sta_a_to_a }, /* Send ASSOCREQ. */ 2185d9f59799SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_ASSOC, lkpi_sta_run_to_assoc }, /* Send ASSOCREQ/REASSOCREQ. */ 21866b4cac81SBjoern A. Zeeb 21876b4cac81SBjoern A. Zeeb { IEEE80211_S_AUTH, IEEE80211_S_RUN, lkpi_sta_auth_to_run }, 21886b4cac81SBjoern A. Zeeb { IEEE80211_S_ASSOC, IEEE80211_S_RUN, lkpi_sta_assoc_to_run }, 21896b4cac81SBjoern A. Zeeb { IEEE80211_S_RUN, IEEE80211_S_RUN, lkpi_sta_state_do_nada }, 21906b4cac81SBjoern A. Zeeb 21916b4cac81SBjoern A. Zeeb /* Dummy at the end without handler. */ 21926b4cac81SBjoern A. Zeeb { IEEE80211_S_INIT, IEEE80211_S_INIT, NULL }, 21936b4cac81SBjoern A. Zeeb }; 21946b4cac81SBjoern A. Zeeb 21956b4cac81SBjoern A. Zeeb static int 21966b4cac81SBjoern A. Zeeb lkpi_iv_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 21976b4cac81SBjoern A. Zeeb { 21986b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 21996b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 22006b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 22016b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 22026b4cac81SBjoern A. Zeeb struct fsm_state *s; 22036b4cac81SBjoern A. Zeeb enum ieee80211_state ostate; 22046b4cac81SBjoern A. Zeeb int error; 22056b4cac81SBjoern A. Zeeb 22066b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 22076b4cac81SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(ic); 22086b4cac81SBjoern A. Zeeb ostate = vap->iv_state; 22096b4cac81SBjoern A. Zeeb 22109d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 22119d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 22126b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x\n", 22136b4cac81SBjoern A. Zeeb __func__, __LINE__, vap, nstate, arg); 22149d9ba2b7SBjoern A. Zeeb #endif 22156b4cac81SBjoern A. Zeeb 22166b4cac81SBjoern A. Zeeb if (vap->iv_opmode == IEEE80211_M_STA) { 22176b4cac81SBjoern A. Zeeb 22186b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 22196b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 22206b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 22216b4cac81SBjoern A. Zeeb 22226b4cac81SBjoern A. Zeeb /* No need to replicate this in most state handlers. */ 22236b4cac81SBjoern A. Zeeb if (ostate == IEEE80211_S_SCAN && nstate != IEEE80211_S_SCAN) 22246b4cac81SBjoern A. Zeeb lkpi_stop_hw_scan(lhw, vif); 22256b4cac81SBjoern A. Zeeb 22266b4cac81SBjoern A. Zeeb s = sta_state_fsm; 22276b4cac81SBjoern A. Zeeb 22286b4cac81SBjoern A. Zeeb } else { 22296b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: only station mode currently supported: " 22306b4cac81SBjoern A. Zeeb "cap %p iv_opmode %d\n", __func__, vap, vap->iv_opmode); 22316b4cac81SBjoern A. Zeeb return (ENOSYS); 22326b4cac81SBjoern A. Zeeb } 22336b4cac81SBjoern A. Zeeb 22346b4cac81SBjoern A. Zeeb error = 0; 22356b4cac81SBjoern A. Zeeb for (; s->handler != NULL; s++) { 22366b4cac81SBjoern A. Zeeb if (ostate == s->ostate && nstate == s->nstate) { 22379d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 22389d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 2239d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: new state %d (%s) ->" 2240d9f59799SBjoern A. Zeeb " %d (%s): arg %d.\n", __func__, 2241d9f59799SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 2242d9f59799SBjoern A. Zeeb nstate, ieee80211_state_name[nstate], arg); 22439d9ba2b7SBjoern A. Zeeb #endif 22446b4cac81SBjoern A. Zeeb error = s->handler(vap, nstate, arg); 22456b4cac81SBjoern A. Zeeb break; 22466b4cac81SBjoern A. Zeeb } 22476b4cac81SBjoern A. Zeeb } 22486b4cac81SBjoern A. Zeeb IEEE80211_LOCK_ASSERT(vap->iv_ic); 22496b4cac81SBjoern A. Zeeb 22506b4cac81SBjoern A. Zeeb if (s->handler == NULL) { 2251d9f59799SBjoern A. Zeeb IMPROVE("turn this into a KASSERT\n"); 22526b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: unsupported state transition " 22536b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s)\n", __func__, 22546b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 22556b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 22566b4cac81SBjoern A. Zeeb return (ENOSYS); 22576b4cac81SBjoern A. Zeeb } 22586b4cac81SBjoern A. Zeeb 22596b4cac81SBjoern A. Zeeb if (error == EALREADY) { 22609d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 22619d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 2262d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: state transition %d (%s) -> " 2263d9f59799SBjoern A. Zeeb "%d (%s): iv_newstate already handled: %d.\n", 2264d9f59799SBjoern A. Zeeb __func__, ostate, ieee80211_state_name[ostate], 2265d9f59799SBjoern A. Zeeb nstate, ieee80211_state_name[nstate], error); 22669d9ba2b7SBjoern A. Zeeb #endif 22676b4cac81SBjoern A. Zeeb return (0); 22686b4cac81SBjoern A. Zeeb } 22696b4cac81SBjoern A. Zeeb 22706b4cac81SBjoern A. Zeeb if (error != 0) { 22716b4cac81SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: error %d during state transition " 22726b4cac81SBjoern A. Zeeb "%d (%s) -> %d (%s)\n", __func__, error, 22736b4cac81SBjoern A. Zeeb ostate, ieee80211_state_name[ostate], 22746b4cac81SBjoern A. Zeeb nstate, ieee80211_state_name[nstate]); 227545c27ad5SBjoern A. Zeeb return (error); 22766b4cac81SBjoern A. Zeeb } 22776b4cac81SBjoern A. Zeeb 22789d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 22799d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 2280d9f59799SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x " 2281d9f59799SBjoern A. Zeeb "calling net80211 parent\n", 22826b4cac81SBjoern A. Zeeb __func__, __LINE__, vap, nstate, arg); 22839d9ba2b7SBjoern A. Zeeb #endif 22846b4cac81SBjoern A. Zeeb 22856b4cac81SBjoern A. Zeeb return (lvif->iv_newstate(vap, nstate, arg)); 22866b4cac81SBjoern A. Zeeb } 22876b4cac81SBjoern A. Zeeb 22886b4cac81SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 22896b4cac81SBjoern A. Zeeb 2290d9f59799SBjoern A. Zeeb /* 2291d9f59799SBjoern A. Zeeb * We overload (*iv_update_bss) as otherwise we have cases in, e.g., 2292d9f59799SBjoern A. Zeeb * net80211::ieee80211_sta_join1() where vap->iv_bss gets replaced by a 2293d9f59799SBjoern A. Zeeb * new node without us knowing and thus our ni/lsta are out of sync. 2294d9f59799SBjoern A. Zeeb */ 2295d9f59799SBjoern A. Zeeb static struct ieee80211_node * 2296d9f59799SBjoern A. Zeeb lkpi_iv_update_bss(struct ieee80211vap *vap, struct ieee80211_node *ni) 2297d9f59799SBjoern A. Zeeb { 2298d9f59799SBjoern A. Zeeb struct lkpi_vif *lvif; 2299d9f59799SBjoern A. Zeeb struct ieee80211_node *obss; 2300d9f59799SBjoern A. Zeeb struct lkpi_sta *lsta; 2301ed3ef56bSBjoern A. Zeeb struct ieee80211_sta *sta; 2302d9f59799SBjoern A. Zeeb 2303d9f59799SBjoern A. Zeeb obss = vap->iv_bss; 2304d9f59799SBjoern A. Zeeb 23059d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 23069d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE) 23079d9ba2b7SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: obss %p ni_drv_data %p " 23089d9ba2b7SBjoern A. Zeeb "ni %p ni_drv_data %p\n", __func__, 23099d9ba2b7SBjoern A. Zeeb obss, (obss != NULL) ? obss->ni_drv_data : NULL, 23109d9ba2b7SBjoern A. Zeeb ni, (ni != NULL) ? ni->ni_drv_data : NULL); 23119d9ba2b7SBjoern A. Zeeb #endif 23129d9ba2b7SBjoern A. Zeeb 2313d9f59799SBjoern A. Zeeb /* Nothing to copy from. Just return. */ 2314d9f59799SBjoern A. Zeeb if (obss == NULL || obss->ni_drv_data == NULL) 2315d9f59799SBjoern A. Zeeb goto out; 2316d9f59799SBjoern A. Zeeb 2317d9f59799SBjoern A. Zeeb /* Nothing to copy to. Just return. */ 2318d9f59799SBjoern A. Zeeb IMPROVE("clearing the obss might still be needed?"); 2319d9f59799SBjoern A. Zeeb if (ni == NULL) 2320d9f59799SBjoern A. Zeeb goto out; 2321d9f59799SBjoern A. Zeeb 2322d9f59799SBjoern A. Zeeb /* Nothing changed? panic? */ 2323d9f59799SBjoern A. Zeeb if (obss == ni) 2324d9f59799SBjoern A. Zeeb goto out; 2325d9f59799SBjoern A. Zeeb 2326d9f59799SBjoern A. Zeeb lsta = obss->ni_drv_data; 2327d9f59799SBjoern A. Zeeb obss->ni_drv_data = ni->ni_drv_data; 2328d9f59799SBjoern A. Zeeb ni->ni_drv_data = lsta; 2329ed3ef56bSBjoern A. Zeeb if (lsta != NULL) { 2330d9f59799SBjoern A. Zeeb lsta->ni = ni; 2331ed3ef56bSBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 2332ed3ef56bSBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->addr, lsta->ni->ni_macaddr); 23336ffb7bd4SBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->deflink.addr, sta->addr); 2334ed3ef56bSBjoern A. Zeeb } 2335d9f59799SBjoern A. Zeeb lsta = obss->ni_drv_data; 2336ed3ef56bSBjoern A. Zeeb if (lsta != NULL) { 2337d9f59799SBjoern A. Zeeb lsta->ni = obss; 2338ed3ef56bSBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 2339ed3ef56bSBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->addr, lsta->ni->ni_macaddr); 23406ffb7bd4SBjoern A. Zeeb IEEE80211_ADDR_COPY(sta->deflink.addr, sta->addr); 2341ed3ef56bSBjoern A. Zeeb } 2342d9f59799SBjoern A. Zeeb 2343d9f59799SBjoern A. Zeeb out: 2344ed3ef56bSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 2345d9f59799SBjoern A. Zeeb return (lvif->iv_update_bss(vap, ni)); 2346d9f59799SBjoern A. Zeeb } 2347d9f59799SBjoern A. Zeeb 23484a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 23496b4cac81SBjoern A. Zeeb static int 23504a67f1dfSBjoern A. Zeeb lkpi_wme_update(struct lkpi_hw *lhw, struct ieee80211vap *vap, bool planned) 23516b4cac81SBjoern A. Zeeb { 23524a67f1dfSBjoern A. Zeeb struct ieee80211com *ic; 23536b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 23546b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 23556b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 23566b4cac81SBjoern A. Zeeb struct chanAccParams chp; 23576b4cac81SBjoern A. Zeeb struct wmeParams wmeparr[WME_NUM_AC]; 23586b4cac81SBjoern A. Zeeb struct ieee80211_tx_queue_params txqp; 23596b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 23606b4cac81SBjoern A. Zeeb int error; 23616b4cac81SBjoern A. Zeeb uint16_t ac; 23626b4cac81SBjoern A. Zeeb 23636b4cac81SBjoern A. Zeeb IMPROVE(); 23646b4cac81SBjoern A. Zeeb KASSERT(WME_NUM_AC == IEEE80211_NUM_ACS, ("%s: WME_NUM_AC %d != " 23656b4cac81SBjoern A. Zeeb "IEEE80211_NUM_ACS %d\n", __func__, WME_NUM_AC, IEEE80211_NUM_ACS)); 23666b4cac81SBjoern A. Zeeb 23676b4cac81SBjoern A. Zeeb if (vap == NULL) 23686b4cac81SBjoern A. Zeeb return (0); 23696b4cac81SBjoern A. Zeeb 23704a67f1dfSBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WME) == 0) 23714a67f1dfSBjoern A. Zeeb return (0); 23724a67f1dfSBjoern A. Zeeb 23736b4cac81SBjoern A. Zeeb if (lhw->ops->conf_tx == NULL) 23746b4cac81SBjoern A. Zeeb return (0); 23756b4cac81SBjoern A. Zeeb 23764a67f1dfSBjoern A. Zeeb if (!planned && (vap->iv_state != IEEE80211_S_RUN)) { 23774a67f1dfSBjoern A. Zeeb lhw->update_wme = true; 23784a67f1dfSBjoern A. Zeeb return (0); 23794a67f1dfSBjoern A. Zeeb } 23804a67f1dfSBjoern A. Zeeb lhw->update_wme = false; 23816b4cac81SBjoern A. Zeeb 23824a67f1dfSBjoern A. Zeeb ic = lhw->ic; 23836b4cac81SBjoern A. Zeeb ieee80211_wme_ic_getparams(ic, &chp); 23846b4cac81SBjoern A. Zeeb IEEE80211_LOCK(ic); 23856b4cac81SBjoern A. Zeeb for (ac = 0; ac < WME_NUM_AC; ac++) 23866b4cac81SBjoern A. Zeeb wmeparr[ac] = chp.cap_wmeParams[ac]; 23876b4cac81SBjoern A. Zeeb IEEE80211_UNLOCK(ic); 23886b4cac81SBjoern A. Zeeb 23894a67f1dfSBjoern A. Zeeb hw = LHW_TO_HW(lhw); 23904a67f1dfSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 23914a67f1dfSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 23924a67f1dfSBjoern A. Zeeb 23936b4cac81SBjoern A. Zeeb /* Configure tx queues (conf_tx) & send BSS_CHANGED_QOS. */ 23946b4cac81SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 23956b4cac81SBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 23966b4cac81SBjoern A. Zeeb struct wmeParams *wmep; 23976b4cac81SBjoern A. Zeeb 23986b4cac81SBjoern A. Zeeb wmep = &wmeparr[ac]; 23996b4cac81SBjoern A. Zeeb bzero(&txqp, sizeof(txqp)); 24006b4cac81SBjoern A. Zeeb txqp.cw_min = wmep->wmep_logcwmin; 24016b4cac81SBjoern A. Zeeb txqp.cw_max = wmep->wmep_logcwmax; 24026b4cac81SBjoern A. Zeeb txqp.txop = wmep->wmep_txopLimit; 24036b4cac81SBjoern A. Zeeb txqp.aifs = wmep->wmep_aifsn; 240468541546SBjoern A. Zeeb error = lkpi_80211_mo_conf_tx(hw, vif, /* link_id */0, ac, &txqp); 24056b4cac81SBjoern A. Zeeb if (error != 0) 24063f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: conf_tx ac %u failed %d\n", 24076b4cac81SBjoern A. Zeeb __func__, ac, error); 24086b4cac81SBjoern A. Zeeb } 24096b4cac81SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 24106b4cac81SBjoern A. Zeeb changed = BSS_CHANGED_QOS; 24114a67f1dfSBjoern A. Zeeb if (!planned) 24126b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 24134a67f1dfSBjoern A. Zeeb 24144a67f1dfSBjoern A. Zeeb return (changed); 24154a67f1dfSBjoern A. Zeeb } 24166b4cac81SBjoern A. Zeeb #endif 24176b4cac81SBjoern A. Zeeb 24184a67f1dfSBjoern A. Zeeb static int 24194a67f1dfSBjoern A. Zeeb lkpi_ic_wme_update(struct ieee80211com *ic) 24204a67f1dfSBjoern A. Zeeb { 24214a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 24224a67f1dfSBjoern A. Zeeb struct ieee80211vap *vap; 24234a67f1dfSBjoern A. Zeeb struct lkpi_hw *lhw; 24244a67f1dfSBjoern A. Zeeb 24254a67f1dfSBjoern A. Zeeb IMPROVE("Use the per-VAP callback in net80211."); 24264a67f1dfSBjoern A. Zeeb vap = TAILQ_FIRST(&ic->ic_vaps); 24274a67f1dfSBjoern A. Zeeb if (vap == NULL) 24286b4cac81SBjoern A. Zeeb return (0); 24294a67f1dfSBjoern A. Zeeb 24304a67f1dfSBjoern A. Zeeb lhw = ic->ic_softc; 24314a67f1dfSBjoern A. Zeeb 24324a67f1dfSBjoern A. Zeeb lkpi_wme_update(lhw, vap, false); 24334a67f1dfSBjoern A. Zeeb #endif 24344a67f1dfSBjoern A. Zeeb return (0); /* unused */ 24356b4cac81SBjoern A. Zeeb } 24366b4cac81SBjoern A. Zeeb 24376b4cac81SBjoern A. Zeeb static struct ieee80211vap * 24386b4cac81SBjoern A. Zeeb lkpi_ic_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], 24396b4cac81SBjoern A. Zeeb int unit, enum ieee80211_opmode opmode, int flags, 24406b4cac81SBjoern A. Zeeb const uint8_t bssid[IEEE80211_ADDR_LEN], 24416b4cac81SBjoern A. Zeeb const uint8_t mac[IEEE80211_ADDR_LEN]) 24426b4cac81SBjoern A. Zeeb { 24436b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 24446b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 24456b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 24466b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 24476b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 2448a6042e17SBjoern A. Zeeb struct ieee80211_tx_queue_params txqp; 24496b4cac81SBjoern A. Zeeb enum ieee80211_bss_changed changed; 24506b4cac81SBjoern A. Zeeb size_t len; 2451e3a0b120SBjoern A. Zeeb int error, i; 2452a6042e17SBjoern A. Zeeb uint16_t ac; 24536b4cac81SBjoern A. Zeeb 24546b4cac81SBjoern A. Zeeb if (!TAILQ_EMPTY(&ic->ic_vaps)) /* 1 so far. Add <n> once this works. */ 24556b4cac81SBjoern A. Zeeb return (NULL); 24566b4cac81SBjoern A. Zeeb 24576b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 24586b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 24596b4cac81SBjoern A. Zeeb 24606b4cac81SBjoern A. Zeeb len = sizeof(*lvif); 24616b4cac81SBjoern A. Zeeb len += hw->vif_data_size; /* vif->drv_priv */ 24626b4cac81SBjoern A. Zeeb 24636b4cac81SBjoern A. Zeeb lvif = malloc(len, M_80211_VAP, M_WAITOK | M_ZERO); 24646b4cac81SBjoern A. Zeeb mtx_init(&lvif->mtx, "lvif", NULL, MTX_DEF); 24656b4cac81SBjoern A. Zeeb TAILQ_INIT(&lvif->lsta_head); 24666b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 24676b4cac81SBjoern A. Zeeb 24686b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 24696b4cac81SBjoern A. Zeeb memcpy(vif->addr, mac, IEEE80211_ADDR_LEN); 24706b4cac81SBjoern A. Zeeb vif->p2p = false; 24716b4cac81SBjoern A. Zeeb vif->probe_req_reg = false; 24726b4cac81SBjoern A. Zeeb vif->type = lkpi_opmode_to_vif_type(opmode); 24736b4cac81SBjoern A. Zeeb lvif->wdev.iftype = vif->type; 24746b4cac81SBjoern A. Zeeb /* Need to fill in other fields as well. */ 24756b4cac81SBjoern A. Zeeb IMPROVE(); 24766b4cac81SBjoern A. Zeeb 24776b4cac81SBjoern A. Zeeb /* XXX-BZ hardcoded for now! */ 24786b4cac81SBjoern A. Zeeb #if 1 24796b4cac81SBjoern A. Zeeb vif->chanctx_conf = NULL; 2480adff403fSBjoern A. Zeeb vif->bss_conf.vif = vif; 24816ffb7bd4SBjoern A. Zeeb /* vap->iv_myaddr is not set until net80211::vap_setup or vap_attach. */ 24826ffb7bd4SBjoern A. Zeeb IEEE80211_ADDR_COPY(vif->bss_conf.addr, mac); 24836ffb7bd4SBjoern A. Zeeb vif->bss_conf.link_id = 0; /* Non-MLO operation. */ 24846b4cac81SBjoern A. Zeeb vif->bss_conf.chandef.width = NL80211_CHAN_WIDTH_20_NOHT; 24856b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_preamble = false; /* vap->iv_flags IEEE80211_F_SHPREAMBLE */ 24866b4cac81SBjoern A. Zeeb vif->bss_conf.use_short_slot = false; /* vap->iv_flags IEEE80211_F_SHSLOT */ 24876b4cac81SBjoern A. Zeeb vif->bss_conf.qos = false; 24886b4cac81SBjoern A. Zeeb vif->bss_conf.use_cts_prot = false; /* vap->iv_protmode */ 24896b4cac81SBjoern A. Zeeb vif->bss_conf.ht_operation_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONE; 2490616e1330SBjoern A. Zeeb vif->cfg.aid = 0; 2491616e1330SBjoern A. Zeeb vif->cfg.assoc = false; 2492616e1330SBjoern A. Zeeb vif->cfg.idle = true; 2493616e1330SBjoern A. Zeeb vif->cfg.ps = false; 24946ffb7bd4SBjoern A. Zeeb IMPROVE("Check other fields and then figure out whats is left elsewhere of them"); 2495caaa79c3SBjoern A. Zeeb /* 2496caaa79c3SBjoern A. Zeeb * We need to initialize it to something as the bss_info_changed call 2497caaa79c3SBjoern A. Zeeb * will try to copy from it in iwlwifi and NULL is a panic. 2498caaa79c3SBjoern A. Zeeb * We will set the proper one in scan_to_auth() before being assoc. 2499caaa79c3SBjoern A. Zeeb */ 25006ffb7bd4SBjoern A. Zeeb vif->bss_conf.bssid = ieee80211broadcastaddr; 25016b4cac81SBjoern A. Zeeb #endif 25026b4cac81SBjoern A. Zeeb #if 0 25036b4cac81SBjoern A. Zeeb vif->bss_conf.dtim_period = 0; /* IEEE80211_DTIM_DEFAULT ; must stay 0. */ 25046b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(vif->bss_conf.bssid, bssid); 25056b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = ic->ic_bintval; 25066b4cac81SBjoern A. Zeeb /* iwlwifi bug. */ 25076b4cac81SBjoern A. Zeeb if (vif->bss_conf.beacon_int < 16) 25086b4cac81SBjoern A. Zeeb vif->bss_conf.beacon_int = 16; 25096b4cac81SBjoern A. Zeeb #endif 2510e3a0b120SBjoern A. Zeeb 25116ffb7bd4SBjoern A. Zeeb /* Link Config */ 25126ffb7bd4SBjoern A. Zeeb vif->link_conf[0] = &vif->bss_conf; 25136ffb7bd4SBjoern A. Zeeb for (i = 0; i < nitems(vif->link_conf); i++) { 25146ffb7bd4SBjoern A. Zeeb IMPROVE("more than 1 link one day"); 25156ffb7bd4SBjoern A. Zeeb } 25166ffb7bd4SBjoern A. Zeeb 2517e3a0b120SBjoern A. Zeeb /* Setup queue defaults; driver may override in (*add_interface). */ 2518e3a0b120SBjoern A. Zeeb for (i = 0; i < IEEE80211_NUM_ACS; i++) { 2519e3a0b120SBjoern A. Zeeb if (ieee80211_hw_check(hw, QUEUE_CONTROL)) 2520e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = IEEE80211_INVAL_HW_QUEUE; 2521e3a0b120SBjoern A. Zeeb else if (hw->queues >= IEEE80211_NUM_ACS) 2522e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = i; 2523e3a0b120SBjoern A. Zeeb else 2524e3a0b120SBjoern A. Zeeb vif->hw_queue[i] = 0; 25250cbcfa19SBjoern A. Zeeb 25260cbcfa19SBjoern A. Zeeb /* Initialize the queue to running. Stopped? */ 25270cbcfa19SBjoern A. Zeeb lvif->hw_queue_stopped[i] = false; 2528e3a0b120SBjoern A. Zeeb } 2529e3a0b120SBjoern A. Zeeb vif->cab_queue = IEEE80211_INVAL_HW_QUEUE; 2530e3a0b120SBjoern A. Zeeb 25316b4cac81SBjoern A. Zeeb IMPROVE(); 25326b4cac81SBjoern A. Zeeb 25336b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_start(hw); 25346b4cac81SBjoern A. Zeeb if (error != 0) { 25353f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: failed to start hw: %d\n", __func__, error); 25366b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 25376b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 25386b4cac81SBjoern A. Zeeb return (NULL); 25396b4cac81SBjoern A. Zeeb } 25406b4cac81SBjoern A. Zeeb 25416b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_add_interface(hw, vif); 25426b4cac81SBjoern A. Zeeb if (error != 0) { 25436b4cac81SBjoern A. Zeeb IMPROVE(); /* XXX-BZ mo_stop()? */ 25443f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: failed to add interface: %d\n", __func__, error); 25456b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 25466b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 25476b4cac81SBjoern A. Zeeb return (NULL); 25486b4cac81SBjoern A. Zeeb } 25496b4cac81SBjoern A. Zeeb 25508891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 25516b4cac81SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lhw->lvif_head, lvif, lvif_entry); 25528891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 25536b4cac81SBjoern A. Zeeb 25546b4cac81SBjoern A. Zeeb /* Set bss_info. */ 25556b4cac81SBjoern A. Zeeb changed = 0; 25566b4cac81SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 25576b4cac81SBjoern A. Zeeb 2558a6042e17SBjoern A. Zeeb /* Configure tx queues (conf_tx), default WME & send BSS_CHANGED_QOS. */ 2559a6042e17SBjoern A. Zeeb IMPROVE("Hardcoded values; to fix see 802.11-2016, 9.4.2.29 EDCA Parameter Set element"); 2560a6042e17SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 2561a6042e17SBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 2562a6042e17SBjoern A. Zeeb 2563a6042e17SBjoern A. Zeeb bzero(&txqp, sizeof(txqp)); 2564a6042e17SBjoern A. Zeeb txqp.cw_min = 15; 2565a6042e17SBjoern A. Zeeb txqp.cw_max = 1023; 2566a6042e17SBjoern A. Zeeb txqp.txop = 0; 2567a6042e17SBjoern A. Zeeb txqp.aifs = 2; 2568a6042e17SBjoern A. Zeeb error = lkpi_80211_mo_conf_tx(hw, vif, /* link_id */0, ac, &txqp); 2569a6042e17SBjoern A. Zeeb if (error != 0) 2570a6042e17SBjoern A. Zeeb ic_printf(ic, "%s: conf_tx ac %u failed %d\n", 2571a6042e17SBjoern A. Zeeb __func__, ac, error); 2572a6042e17SBjoern A. Zeeb } 2573a6042e17SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 2574a6042e17SBjoern A. Zeeb changed = BSS_CHANGED_QOS; 2575a6042e17SBjoern A. Zeeb lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed); 25766b4cac81SBjoern A. Zeeb 25776b4cac81SBjoern A. Zeeb /* Force MC init. */ 25786b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(ic, true); 25796b4cac81SBjoern A. Zeeb 25806b4cac81SBjoern A. Zeeb IMPROVE(); 25816b4cac81SBjoern A. Zeeb 25826b4cac81SBjoern A. Zeeb ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid); 25836b4cac81SBjoern A. Zeeb 25846b4cac81SBjoern A. Zeeb /* Override with LinuxKPI method so we can drive mac80211/cfg80211. */ 25856b4cac81SBjoern A. Zeeb lvif->iv_newstate = vap->iv_newstate; 25866b4cac81SBjoern A. Zeeb vap->iv_newstate = lkpi_iv_newstate; 2587d9f59799SBjoern A. Zeeb lvif->iv_update_bss = vap->iv_update_bss; 2588d9f59799SBjoern A. Zeeb vap->iv_update_bss = lkpi_iv_update_bss; 25896b4cac81SBjoern A. Zeeb 25906b4cac81SBjoern A. Zeeb /* Key management. */ 25916b4cac81SBjoern A. Zeeb if (lhw->ops->set_key != NULL) { 2592b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 25936b4cac81SBjoern A. Zeeb vap->iv_key_set = lkpi_iv_key_set; 25946b4cac81SBjoern A. Zeeb vap->iv_key_delete = lkpi_iv_key_delete; 25956b4cac81SBjoern A. Zeeb #endif 25966b4cac81SBjoern A. Zeeb } 25976b4cac81SBjoern A. Zeeb 2598*9fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 2599*9fb91463SBjoern A. Zeeb /* Stay with the iv_ampdu_rxmax,limit / iv_ampdu_density defaults until later. */ 2600*9fb91463SBjoern A. Zeeb #endif 2601*9fb91463SBjoern A. Zeeb 26026b4cac81SBjoern A. Zeeb ieee80211_ratectl_init(vap); 26036b4cac81SBjoern A. Zeeb 26046b4cac81SBjoern A. Zeeb /* Complete setup. */ 26056b4cac81SBjoern A. Zeeb ieee80211_vap_attach(vap, ieee80211_media_change, 26066b4cac81SBjoern A. Zeeb ieee80211_media_status, mac); 26076b4cac81SBjoern A. Zeeb 26086b4cac81SBjoern A. Zeeb if (hw->max_listen_interval == 0) 26096b4cac81SBjoern A. Zeeb hw->max_listen_interval = 7 * (ic->ic_lintval / ic->ic_bintval); 26106b4cac81SBjoern A. Zeeb hw->conf.listen_interval = hw->max_listen_interval; 26116b4cac81SBjoern A. Zeeb ic->ic_set_channel(ic); 26126b4cac81SBjoern A. Zeeb 26136b4cac81SBjoern A. Zeeb /* XXX-BZ do we need to be able to update these? */ 26146b4cac81SBjoern A. Zeeb hw->wiphy->frag_threshold = vap->iv_fragthreshold; 26156b4cac81SBjoern A. Zeeb lkpi_80211_mo_set_frag_threshold(hw, vap->iv_fragthreshold); 26166b4cac81SBjoern A. Zeeb hw->wiphy->rts_threshold = vap->iv_rtsthreshold; 26176b4cac81SBjoern A. Zeeb lkpi_80211_mo_set_rts_threshold(hw, vap->iv_rtsthreshold); 26186b4cac81SBjoern A. Zeeb /* any others? */ 26196b4cac81SBjoern A. Zeeb IMPROVE(); 26206b4cac81SBjoern A. Zeeb 26216b4cac81SBjoern A. Zeeb return (vap); 26226b4cac81SBjoern A. Zeeb } 26236b4cac81SBjoern A. Zeeb 26244b0af114SBjoern A. Zeeb void 26254b0af114SBjoern A. Zeeb linuxkpi_ieee80211_unregister_hw(struct ieee80211_hw *hw) 26264b0af114SBjoern A. Zeeb { 26274b0af114SBjoern A. Zeeb 26284b0af114SBjoern A. Zeeb wiphy_unregister(hw->wiphy); 26294b0af114SBjoern A. Zeeb linuxkpi_ieee80211_ifdetach(hw); 26304b0af114SBjoern A. Zeeb 26314b0af114SBjoern A. Zeeb IMPROVE(); 26324b0af114SBjoern A. Zeeb } 26334b0af114SBjoern A. Zeeb 26344b0af114SBjoern A. Zeeb void 26354b0af114SBjoern A. Zeeb linuxkpi_ieee80211_restart_hw(struct ieee80211_hw *hw) 26364b0af114SBjoern A. Zeeb { 26374b0af114SBjoern A. Zeeb 26384b0af114SBjoern A. Zeeb TODO(); 26394b0af114SBjoern A. Zeeb } 26404b0af114SBjoern A. Zeeb 26416b4cac81SBjoern A. Zeeb static void 26426b4cac81SBjoern A. Zeeb lkpi_ic_vap_delete(struct ieee80211vap *vap) 26436b4cac81SBjoern A. Zeeb { 26446b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 26456b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 26466b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 26476b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 26486b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 26496b4cac81SBjoern A. Zeeb 26506b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 26516b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 26526b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 26536b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 26546b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 26556b4cac81SBjoern A. Zeeb 26568891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 26576b4cac81SBjoern A. Zeeb TAILQ_REMOVE(&lhw->lvif_head, lvif, lvif_entry); 26588891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 26596b4cac81SBjoern A. Zeeb 26606b4cac81SBjoern A. Zeeb ieee80211_ratectl_deinit(vap); 26616b4cac81SBjoern A. Zeeb ieee80211_vap_detach(vap); 2662dbf76919SBjoern A. Zeeb 2663dbf76919SBjoern A. Zeeb IMPROVE("clear up other bits in this state"); 2664dbf76919SBjoern A. Zeeb 2665dbf76919SBjoern A. Zeeb lkpi_80211_mo_remove_interface(hw, vif); 2666dbf76919SBjoern A. Zeeb 26676c38c6b1SBjoern A. Zeeb /* Single VAP, so we can do this here. */ 26686c38c6b1SBjoern A. Zeeb lkpi_80211_mo_stop(hw); 26696c38c6b1SBjoern A. Zeeb 26706b4cac81SBjoern A. Zeeb mtx_destroy(&lvif->mtx); 26716b4cac81SBjoern A. Zeeb free(lvif, M_80211_VAP); 26726b4cac81SBjoern A. Zeeb } 26736b4cac81SBjoern A. Zeeb 26746b4cac81SBjoern A. Zeeb static void 26756b4cac81SBjoern A. Zeeb lkpi_ic_update_mcast(struct ieee80211com *ic) 26766b4cac81SBjoern A. Zeeb { 26776b4cac81SBjoern A. Zeeb 26786b4cac81SBjoern A. Zeeb lkpi_update_mcast_filter(ic, false); 26796b4cac81SBjoern A. Zeeb TRACEOK(); 26806b4cac81SBjoern A. Zeeb } 26816b4cac81SBjoern A. Zeeb 26826b4cac81SBjoern A. Zeeb static void 26836b4cac81SBjoern A. Zeeb lkpi_ic_update_promisc(struct ieee80211com *ic) 26846b4cac81SBjoern A. Zeeb { 26856b4cac81SBjoern A. Zeeb 26866b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 26876b4cac81SBjoern A. Zeeb } 26886b4cac81SBjoern A. Zeeb 26896b4cac81SBjoern A. Zeeb static void 26906b4cac81SBjoern A. Zeeb lkpi_ic_update_chw(struct ieee80211com *ic) 26916b4cac81SBjoern A. Zeeb { 26926b4cac81SBjoern A. Zeeb 26936b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 26946b4cac81SBjoern A. Zeeb } 26956b4cac81SBjoern A. Zeeb 26966b4cac81SBjoern A. Zeeb /* Start / stop device. */ 26976b4cac81SBjoern A. Zeeb static void 26986b4cac81SBjoern A. Zeeb lkpi_ic_parent(struct ieee80211com *ic) 26996b4cac81SBjoern A. Zeeb { 27006b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 27018d58a057SBjoern A. Zeeb #ifdef HW_START_STOP 27026b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 27036b4cac81SBjoern A. Zeeb int error; 27048d58a057SBjoern A. Zeeb #endif 27056b4cac81SBjoern A. Zeeb bool start_all; 27066b4cac81SBjoern A. Zeeb 27076b4cac81SBjoern A. Zeeb IMPROVE(); 27086b4cac81SBjoern A. Zeeb 27096b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 27108d58a057SBjoern A. Zeeb #ifdef HW_START_STOP 27116b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 27128d58a057SBjoern A. Zeeb #endif 27136b4cac81SBjoern A. Zeeb start_all = false; 27146b4cac81SBjoern A. Zeeb 27158ac540d3SBjoern A. Zeeb /* IEEE80211_UNLOCK(ic); */ 27168ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK(lhw); 27176b4cac81SBjoern A. Zeeb if (ic->ic_nrunning > 0) { 27188d58a057SBjoern A. Zeeb #ifdef HW_START_STOP 27196b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_start(hw); 27206b4cac81SBjoern A. Zeeb if (error == 0) 27218d58a057SBjoern A. Zeeb #endif 27226b4cac81SBjoern A. Zeeb start_all = true; 27236b4cac81SBjoern A. Zeeb } else { 27248d58a057SBjoern A. Zeeb #ifdef HW_START_STOP 27256b4cac81SBjoern A. Zeeb lkpi_80211_mo_stop(hw); 27268d58a057SBjoern A. Zeeb #endif 27276b4cac81SBjoern A. Zeeb } 27288ac540d3SBjoern A. Zeeb LKPI_80211_LHW_UNLOCK(lhw); 27298ac540d3SBjoern A. Zeeb /* IEEE80211_LOCK(ic); */ 27306b4cac81SBjoern A. Zeeb 27316b4cac81SBjoern A. Zeeb if (start_all) 27326b4cac81SBjoern A. Zeeb ieee80211_start_all(ic); 27336b4cac81SBjoern A. Zeeb } 27346b4cac81SBjoern A. Zeeb 27356b4cac81SBjoern A. Zeeb bool 27366b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_is_ie_id_in_ie_buf(const u8 ie, const u8 *ie_ids, 27376b4cac81SBjoern A. Zeeb size_t ie_ids_len) 27386b4cac81SBjoern A. Zeeb { 27396b4cac81SBjoern A. Zeeb int i; 27406b4cac81SBjoern A. Zeeb 27416b4cac81SBjoern A. Zeeb for (i = 0; i < ie_ids_len; i++) { 27426b4cac81SBjoern A. Zeeb if (ie == *ie_ids) 27436b4cac81SBjoern A. Zeeb return (true); 27446b4cac81SBjoern A. Zeeb } 27456b4cac81SBjoern A. Zeeb 27466b4cac81SBjoern A. Zeeb return (false); 27476b4cac81SBjoern A. Zeeb } 27486b4cac81SBjoern A. Zeeb 27496b4cac81SBjoern A. Zeeb /* Return true if skipped; false if error. */ 27506b4cac81SBjoern A. Zeeb bool 27516b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ie_advance(size_t *xp, const u8 *ies, size_t ies_len) 27526b4cac81SBjoern A. Zeeb { 27536b4cac81SBjoern A. Zeeb size_t x; 27546b4cac81SBjoern A. Zeeb uint8_t l; 27556b4cac81SBjoern A. Zeeb 27566b4cac81SBjoern A. Zeeb x = *xp; 27576b4cac81SBjoern A. Zeeb 27586b4cac81SBjoern A. Zeeb KASSERT(x < ies_len, ("%s: x %zu ies_len %zu ies %p\n", 27596b4cac81SBjoern A. Zeeb __func__, x, ies_len, ies)); 27606b4cac81SBjoern A. Zeeb l = ies[x + 1]; 27616b4cac81SBjoern A. Zeeb x += 2 + l; 27626b4cac81SBjoern A. Zeeb 27636b4cac81SBjoern A. Zeeb if (x > ies_len) 27646b4cac81SBjoern A. Zeeb return (false); 27656b4cac81SBjoern A. Zeeb 27666b4cac81SBjoern A. Zeeb *xp = x; 27676b4cac81SBjoern A. Zeeb return (true); 27686b4cac81SBjoern A. Zeeb } 27696b4cac81SBjoern A. Zeeb 2770d9945d78SBjoern A. Zeeb static uint8_t * 2771d9945d78SBjoern A. Zeeb lkpi_scan_ies_add(uint8_t *p, struct ieee80211_scan_ies *scan_ies, 2772d9945d78SBjoern A. Zeeb uint32_t band_mask, struct ieee80211vap *vap, struct ieee80211_hw *hw) 27736b4cac81SBjoern A. Zeeb { 2774d9945d78SBjoern A. Zeeb struct ieee80211_supported_band *supband; 2775d9945d78SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 27763dd98026SBjoern A. Zeeb struct ieee80211com *ic; 2777d9945d78SBjoern A. Zeeb const struct ieee80211_channel *chan; 2778d9945d78SBjoern A. Zeeb const struct ieee80211_rateset *rs; 2779d9945d78SBjoern A. Zeeb uint8_t *pb; 2780d9945d78SBjoern A. Zeeb int band, i; 27816b4cac81SBjoern A. Zeeb 27823dd98026SBjoern A. Zeeb ic = vap->iv_ic; 2783d9945d78SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 2784d9945d78SBjoern A. Zeeb if ((band_mask & (1 << band)) == 0) 2785d9945d78SBjoern A. Zeeb continue; 2786d9945d78SBjoern A. Zeeb 2787d9945d78SBjoern A. Zeeb supband = hw->wiphy->bands[band]; 2788d9945d78SBjoern A. Zeeb /* 2789d9945d78SBjoern A. Zeeb * This should not happen; 2790d9945d78SBjoern A. Zeeb * band_mask is a bitmask of valid bands to scan on. 2791d9945d78SBjoern A. Zeeb */ 2792d9945d78SBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 2793d9945d78SBjoern A. Zeeb continue; 2794d9945d78SBjoern A. Zeeb 2795d9945d78SBjoern A. Zeeb /* Find a first channel to get the mode and rates from. */ 2796d9945d78SBjoern A. Zeeb channels = supband->channels; 2797d9945d78SBjoern A. Zeeb chan = NULL; 2798d9945d78SBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 2799d9945d78SBjoern A. Zeeb 2800d9945d78SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) 2801d9945d78SBjoern A. Zeeb continue; 2802d9945d78SBjoern A. Zeeb 28033dd98026SBjoern A. Zeeb chan = ieee80211_find_channel(ic, 2804d9945d78SBjoern A. Zeeb channels[i].center_freq, 0); 2805d9945d78SBjoern A. Zeeb if (chan != NULL) 2806d9945d78SBjoern A. Zeeb break; 2807d9945d78SBjoern A. Zeeb } 2808d9945d78SBjoern A. Zeeb 2809d9945d78SBjoern A. Zeeb /* This really should not happen. */ 2810d9945d78SBjoern A. Zeeb if (chan == NULL) 2811d9945d78SBjoern A. Zeeb continue; 2812d9945d78SBjoern A. Zeeb 2813d9945d78SBjoern A. Zeeb pb = p; 28143dd98026SBjoern A. Zeeb rs = ieee80211_get_suprates(ic, chan); /* calls chan2mode */ 2815d9945d78SBjoern A. Zeeb p = ieee80211_add_rates(p, rs); 2816d9945d78SBjoern A. Zeeb p = ieee80211_add_xrates(p, rs); 2817d9945d78SBjoern A. Zeeb 28183dd98026SBjoern A. Zeeb #if defined(LKPI_80211_HT) 28193dd98026SBjoern A. Zeeb if ((vap->iv_flags_ht & IEEE80211_FHT_HT) != 0) { 28203dd98026SBjoern A. Zeeb struct ieee80211_channel *c; 28213dd98026SBjoern A. Zeeb 28223dd98026SBjoern A. Zeeb c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan, 28233dd98026SBjoern A. Zeeb vap->iv_flags_ht); 28243dd98026SBjoern A. Zeeb p = ieee80211_add_htcap_ch(p, vap, c); 28253dd98026SBjoern A. Zeeb } 28263dd98026SBjoern A. Zeeb #endif 28273dd98026SBjoern A. Zeeb #if defined(LKPI_80211_VHT) 28283dd98026SBjoern A. Zeeb if ((vap->iv_vht_flags & IEEE80211_FVHT_VHT) != 0) { 28293dd98026SBjoern A. Zeeb struct ieee80211_channel *c; 28303dd98026SBjoern A. Zeeb 28313dd98026SBjoern A. Zeeb c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan, 28323dd98026SBjoern A. Zeeb vap->iv_flags_ht); 28333dd98026SBjoern A. Zeeb c = ieee80211_vht_adjust_channel(ic, c, 28343dd98026SBjoern A. Zeeb vap->iv_vht_flags); 28353dd98026SBjoern A. Zeeb p = ieee80211_add_vhtcap_ch(p, vap, c); 28363dd98026SBjoern A. Zeeb } 28373dd98026SBjoern A. Zeeb #endif 28383dd98026SBjoern A. Zeeb 2839d9945d78SBjoern A. Zeeb scan_ies->ies[band] = pb; 2840d9945d78SBjoern A. Zeeb scan_ies->len[band] = p - pb; 2841d9945d78SBjoern A. Zeeb } 2842d9945d78SBjoern A. Zeeb 2843d9945d78SBjoern A. Zeeb /* Add common_ies */ 2844d9945d78SBjoern A. Zeeb pb = p; 2845d9945d78SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WPA1) != 0 && 2846d9945d78SBjoern A. Zeeb vap->iv_wpa_ie != NULL) { 2847d9945d78SBjoern A. Zeeb memcpy(p, vap->iv_wpa_ie, 2 + vap->iv_wpa_ie[1]); 2848d9945d78SBjoern A. Zeeb p += 2 + vap->iv_wpa_ie[1]; 2849d9945d78SBjoern A. Zeeb } 2850d9945d78SBjoern A. Zeeb if (vap->iv_appie_probereq != NULL) { 2851d9945d78SBjoern A. Zeeb memcpy(p, vap->iv_appie_probereq->ie_data, 2852d9945d78SBjoern A. Zeeb vap->iv_appie_probereq->ie_len); 2853d9945d78SBjoern A. Zeeb p += vap->iv_appie_probereq->ie_len; 2854d9945d78SBjoern A. Zeeb } 2855d9945d78SBjoern A. Zeeb scan_ies->common_ies = pb; 2856d9945d78SBjoern A. Zeeb scan_ies->common_ie_len = p - pb; 2857d9945d78SBjoern A. Zeeb 2858d9945d78SBjoern A. Zeeb return (p); 28596b4cac81SBjoern A. Zeeb } 28606b4cac81SBjoern A. Zeeb 28616b4cac81SBjoern A. Zeeb static void 28626b4cac81SBjoern A. Zeeb lkpi_ic_scan_start(struct ieee80211com *ic) 28636b4cac81SBjoern A. Zeeb { 28646b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 28656b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 28666b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 28676b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 28686b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 28696b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 28706b4cac81SBjoern A. Zeeb int error; 28718ac540d3SBjoern A. Zeeb bool is_hw_scan; 28726b4cac81SBjoern A. Zeeb 28736b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 28748ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 2875a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) { 28766b4cac81SBjoern A. Zeeb /* A scan is still running. */ 28778ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 28786b4cac81SBjoern A. Zeeb return; 28796b4cac81SBjoern A. Zeeb } 28808ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 28818ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 28826b4cac81SBjoern A. Zeeb 28836b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 28846b4cac81SBjoern A. Zeeb vap = ss->ss_vap; 28856b4cac81SBjoern A. Zeeb if (vap->iv_state != IEEE80211_S_SCAN) { 2886d3ef7fb4SBjoern A. Zeeb IMPROVE("We need to be able to scan if not in S_SCAN"); 28876b4cac81SBjoern A. Zeeb return; 28886b4cac81SBjoern A. Zeeb } 28896b4cac81SBjoern A. Zeeb 28906b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 28918ac540d3SBjoern A. Zeeb if (!is_hw_scan) { 2892a486fbbdSBjoern A. Zeeb /* If hw_scan is cleared clear FEXT_SCAN_OFFLOAD too. */ 2893a486fbbdSBjoern A. Zeeb vap->iv_flags_ext &= ~IEEE80211_FEXT_SCAN_OFFLOAD; 2894d3ef7fb4SBjoern A. Zeeb sw_scan: 28956b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 28966b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 2897086be6a8SBjoern A. Zeeb 2898086be6a8SBjoern A. Zeeb if (vap->iv_state == IEEE80211_S_SCAN) 2899086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, false); 2900086be6a8SBjoern A. Zeeb 29016b4cac81SBjoern A. Zeeb lkpi_80211_mo_sw_scan_start(hw, vif, vif->addr); 29026b4cac81SBjoern A. Zeeb /* net80211::scan_start() handled PS for us. */ 29036b4cac81SBjoern A. Zeeb IMPROVE(); 29046b4cac81SBjoern A. Zeeb /* XXX Also means it is too late to flush queues? 29056b4cac81SBjoern A. Zeeb * need to check iv_sta_ps or overload? */ 29066b4cac81SBjoern A. Zeeb /* XXX want to adjust ss end time/ maxdwell? */ 29076b4cac81SBjoern A. Zeeb 29086b4cac81SBjoern A. Zeeb } else { 29096b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 29106b4cac81SBjoern A. Zeeb struct ieee80211_scan_request *hw_req; 29116b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *lc, **cpp; 29126b4cac81SBjoern A. Zeeb struct cfg80211_ssid *ssids; 29136b4cac81SBjoern A. Zeeb struct cfg80211_scan_6ghz_params *s6gp; 29146b4cac81SBjoern A. Zeeb size_t chan_len, nchan, ssids_len, s6ghzlen; 2915d9945d78SBjoern A. Zeeb int band, i, ssid_count, common_ie_len; 2916d9945d78SBjoern A. Zeeb uint32_t band_mask; 2917d9945d78SBjoern A. Zeeb uint8_t *ie, *ieend; 29183206587aSBjoern A. Zeeb bool running; 2919d9945d78SBjoern A. Zeeb 2920d9945d78SBjoern A. Zeeb ssid_count = min(ss->ss_nssid, hw->wiphy->max_scan_ssids); 2921d9945d78SBjoern A. Zeeb ssids_len = ssid_count * sizeof(*ssids); 29226b4cac81SBjoern A. Zeeb s6ghzlen = 0 * (sizeof(*s6gp)); /* XXX-BZ */ 29236b4cac81SBjoern A. Zeeb 2924d9945d78SBjoern A. Zeeb band_mask = 0; 29256b4cac81SBjoern A. Zeeb nchan = 0; 2926d9945d78SBjoern A. Zeeb for (i = ss->ss_next; i < ss->ss_last; i++) { 29276b4cac81SBjoern A. Zeeb nchan++; 2928d9945d78SBjoern A. Zeeb band = lkpi_net80211_chan_to_nl80211_band( 2929d9945d78SBjoern A. Zeeb ss->ss_chans[ss->ss_next + i]); 2930d9945d78SBjoern A. Zeeb band_mask |= (1 << band); 2931d9945d78SBjoern A. Zeeb } 29323206587aSBjoern A. Zeeb 29333206587aSBjoern A. Zeeb if (!ieee80211_hw_check(hw, SINGLE_SCAN_ON_ALL_BANDS)) { 29343206587aSBjoern A. Zeeb IMPROVE("individual band scans not yet supported, only scanning first band"); 29353206587aSBjoern A. Zeeb /* In theory net80211 should drive this. */ 29363206587aSBjoern A. Zeeb /* Probably we need to add local logic for now; 29373206587aSBjoern A. Zeeb * need to deal with scan_complete 29383206587aSBjoern A. Zeeb * and cancel_scan and keep local state. 29393206587aSBjoern A. Zeeb * Also cut the nchan down above. 29403206587aSBjoern A. Zeeb */ 29413206587aSBjoern A. Zeeb /* XXX-BZ ath10k does not set this but still does it? &$%^ */ 29423206587aSBjoern A. Zeeb } 29433206587aSBjoern A. Zeeb 29446b4cac81SBjoern A. Zeeb chan_len = nchan * (sizeof(lc) + sizeof(*lc)); 29456b4cac81SBjoern A. Zeeb 2946d9945d78SBjoern A. Zeeb common_ie_len = 0; 2947d9945d78SBjoern A. Zeeb if ((vap->iv_flags & IEEE80211_F_WPA1) != 0 && 2948d9945d78SBjoern A. Zeeb vap->iv_wpa_ie != NULL) 2949d9945d78SBjoern A. Zeeb common_ie_len += vap->iv_wpa_ie[1]; 2950d9945d78SBjoern A. Zeeb if (vap->iv_appie_probereq != NULL) 2951d9945d78SBjoern A. Zeeb common_ie_len += vap->iv_appie_probereq->ie_len; 2952d9945d78SBjoern A. Zeeb 2953d9945d78SBjoern A. Zeeb /* We would love to check this at an earlier stage... */ 2954d9945d78SBjoern A. Zeeb if (common_ie_len > hw->wiphy->max_scan_ie_len) { 2955d9945d78SBjoern A. Zeeb ic_printf(ic, "WARNING: %s: common_ie_len %d > " 2956d9945d78SBjoern A. Zeeb "wiphy->max_scan_ie_len %d\n", __func__, 2957d9945d78SBjoern A. Zeeb common_ie_len, hw->wiphy->max_scan_ie_len); 2958d9945d78SBjoern A. Zeeb } 2959d9945d78SBjoern A. Zeeb 29603206587aSBjoern A. Zeeb hw_req = malloc(sizeof(*hw_req) + ssids_len + 2961d9945d78SBjoern A. Zeeb s6ghzlen + chan_len + lhw->supbands * lhw->scan_ie_len + 2962d9945d78SBjoern A. Zeeb common_ie_len, M_LKPI80211, M_WAITOK | M_ZERO); 29636b4cac81SBjoern A. Zeeb 29646b4cac81SBjoern A. Zeeb hw_req->req.flags = 0; /* XXX ??? */ 29656b4cac81SBjoern A. Zeeb /* hw_req->req.wdev */ 29666b4cac81SBjoern A. Zeeb hw_req->req.wiphy = hw->wiphy; 29676b4cac81SBjoern A. Zeeb hw_req->req.no_cck = false; /* XXX */ 29686b4cac81SBjoern A. Zeeb #if 0 29696b4cac81SBjoern A. Zeeb /* This seems to pessimise default scanning behaviour. */ 29706b4cac81SBjoern A. Zeeb hw_req->req.duration_mandatory = TICKS_2_USEC(ss->ss_mindwell); 29716b4cac81SBjoern A. Zeeb hw_req->req.duration = TICKS_2_USEC(ss->ss_maxdwell); 29726b4cac81SBjoern A. Zeeb #endif 29736b4cac81SBjoern A. Zeeb #ifdef __notyet__ 29746b4cac81SBjoern A. Zeeb hw_req->req.flags |= NL80211_SCAN_FLAG_RANDOM_ADDR; 29756b4cac81SBjoern A. Zeeb memcpy(hw_req->req.mac_addr, xxx, IEEE80211_ADDR_LEN); 29766b4cac81SBjoern A. Zeeb memset(hw_req->req.mac_addr_mask, 0xxx, IEEE80211_ADDR_LEN); 29776b4cac81SBjoern A. Zeeb #endif 2978e1e90be0SBjoern A. Zeeb eth_broadcast_addr(hw_req->req.bssid); 29796b4cac81SBjoern A. Zeeb 29806b4cac81SBjoern A. Zeeb hw_req->req.n_channels = nchan; 29816b4cac81SBjoern A. Zeeb cpp = (struct linuxkpi_ieee80211_channel **)(hw_req + 1); 29826b4cac81SBjoern A. Zeeb lc = (struct linuxkpi_ieee80211_channel *)(cpp + nchan); 29836b4cac81SBjoern A. Zeeb for (i = 0; i < nchan; i++) { 29846b4cac81SBjoern A. Zeeb *(cpp + i) = 29856b4cac81SBjoern A. Zeeb (struct linuxkpi_ieee80211_channel *)(lc + i); 29866b4cac81SBjoern A. Zeeb } 29876b4cac81SBjoern A. Zeeb for (i = 0; i < nchan; i++) { 29886b4cac81SBjoern A. Zeeb c = ss->ss_chans[ss->ss_next + i]; 29896b4cac81SBjoern A. Zeeb 29906b4cac81SBjoern A. Zeeb lc->hw_value = c->ic_ieee; 29913206587aSBjoern A. Zeeb lc->center_freq = c->ic_freq; /* XXX */ 29926b4cac81SBjoern A. Zeeb /* lc->flags */ 29936b4cac81SBjoern A. Zeeb lc->band = lkpi_net80211_chan_to_nl80211_band(c); 29946b4cac81SBjoern A. Zeeb lc->max_power = c->ic_maxpower; 29956b4cac81SBjoern A. Zeeb /* lc-> ... */ 29966b4cac81SBjoern A. Zeeb lc++; 29976b4cac81SBjoern A. Zeeb } 29986b4cac81SBjoern A. Zeeb 2999d9945d78SBjoern A. Zeeb hw_req->req.n_ssids = ssid_count; 30006b4cac81SBjoern A. Zeeb if (hw_req->req.n_ssids > 0) { 30016b4cac81SBjoern A. Zeeb ssids = (struct cfg80211_ssid *)lc; 30026b4cac81SBjoern A. Zeeb hw_req->req.ssids = ssids; 3003d9945d78SBjoern A. Zeeb for (i = 0; i < ssid_count; i++) { 30046b4cac81SBjoern A. Zeeb ssids->ssid_len = ss->ss_ssid[i].len; 30056b4cac81SBjoern A. Zeeb memcpy(ssids->ssid, ss->ss_ssid[i].ssid, 30066b4cac81SBjoern A. Zeeb ss->ss_ssid[i].len); 30076b4cac81SBjoern A. Zeeb ssids++; 30086b4cac81SBjoern A. Zeeb } 30096b4cac81SBjoern A. Zeeb s6gp = (struct cfg80211_scan_6ghz_params *)ssids; 30106b4cac81SBjoern A. Zeeb } else { 30116b4cac81SBjoern A. Zeeb s6gp = (struct cfg80211_scan_6ghz_params *)lc; 30126b4cac81SBjoern A. Zeeb } 30136b4cac81SBjoern A. Zeeb 30146b4cac81SBjoern A. Zeeb /* 6GHz one day. */ 30156b4cac81SBjoern A. Zeeb hw_req->req.n_6ghz_params = 0; 30166b4cac81SBjoern A. Zeeb hw_req->req.scan_6ghz_params = NULL; 30176b4cac81SBjoern A. Zeeb hw_req->req.scan_6ghz = false; /* Weird boolean; not what you think. */ 30186b4cac81SBjoern A. Zeeb /* s6gp->... */ 30196b4cac81SBjoern A. Zeeb 3020d9945d78SBjoern A. Zeeb ie = ieend = (uint8_t *)s6gp; 3021d9945d78SBjoern A. Zeeb /* Copy per-band IEs, copy common IEs */ 3022d9945d78SBjoern A. Zeeb ieend = lkpi_scan_ies_add(ie, &hw_req->ies, band_mask, vap, hw); 3023d9945d78SBjoern A. Zeeb hw_req->req.ie = ie; 3024d9945d78SBjoern A. Zeeb hw_req->req.ie_len = ieend - ie; 3025d9945d78SBjoern A. Zeeb 30266b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 30276b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 30283206587aSBjoern A. Zeeb 30293206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 30303206587aSBjoern A. Zeeb /* Re-check under lock. */ 30313206587aSBjoern A. Zeeb running = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0; 30323206587aSBjoern A. Zeeb if (!running) { 30333206587aSBjoern A. Zeeb KASSERT(lhw->hw_req == NULL, ("%s: ic %p lhw %p hw_req %p " 30343206587aSBjoern A. Zeeb "!= NULL\n", __func__, ic, lhw, lhw->hw_req)); 30353206587aSBjoern A. Zeeb 30363206587aSBjoern A. Zeeb lhw->scan_flags |= LKPI_LHW_SCAN_RUNNING; 30373206587aSBjoern A. Zeeb lhw->hw_req = hw_req; 30383206587aSBjoern A. Zeeb } 30393206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 30403206587aSBjoern A. Zeeb if (running) { 30413206587aSBjoern A. Zeeb free(hw_req, M_LKPI80211); 30423206587aSBjoern A. Zeeb return; 30433206587aSBjoern A. Zeeb } 30443206587aSBjoern A. Zeeb 30456b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_hw_scan(hw, vif, hw_req); 30466b4cac81SBjoern A. Zeeb if (error != 0) { 3047d9945d78SBjoern A. Zeeb ieee80211_cancel_scan(vap); 3048d9945d78SBjoern A. Zeeb 30493206587aSBjoern A. Zeeb /* 30503206587aSBjoern A. Zeeb * ieee80211_scan_completed must be called in either 30513206587aSBjoern A. Zeeb * case of error or none. So let the free happen there 30523206587aSBjoern A. Zeeb * and only there. 30533206587aSBjoern A. Zeeb * That would be fine in theory but in practice drivers 30543206587aSBjoern A. Zeeb * behave differently: 30553206587aSBjoern A. Zeeb * ath10k does not return hw_scan until after scan_complete 30563206587aSBjoern A. Zeeb * and can then still return an error. 30573206587aSBjoern A. Zeeb * rtw88 can return 1 or -EBUSY without scan_complete 30583206587aSBjoern A. Zeeb * iwlwifi can return various errors before scan starts 30593206587aSBjoern A. Zeeb * ... 30603206587aSBjoern A. Zeeb * So we cannot rely on that behaviour and have to check 30613206587aSBjoern A. Zeeb * and balance between both code paths. 30623206587aSBjoern A. Zeeb */ 30633206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 30643206587aSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) { 30653206587aSBjoern A. Zeeb free(lhw->hw_req, M_LKPI80211); 30666b4cac81SBjoern A. Zeeb lhw->hw_req = NULL; 30673206587aSBjoern A. Zeeb lhw->scan_flags &= ~LKPI_LHW_SCAN_RUNNING; 30683206587aSBjoern A. Zeeb } 30693206587aSBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 3070d3ef7fb4SBjoern A. Zeeb 3071d3ef7fb4SBjoern A. Zeeb /* 3072d3ef7fb4SBjoern A. Zeeb * XXX-SIGH magic number. 3073d3ef7fb4SBjoern A. Zeeb * rtw88 has a magic "return 1" if offloading scan is 3074d3ef7fb4SBjoern A. Zeeb * not possible. Fall back to sw scan in that case. 3075d3ef7fb4SBjoern A. Zeeb */ 3076196cfd0bSBjoern A. Zeeb if (error == 1) { 30778ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 3078a486fbbdSBjoern A. Zeeb lhw->scan_flags &= ~LKPI_LHW_SCAN_HW; 30798ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 30803206587aSBjoern A. Zeeb /* 30813206587aSBjoern A. Zeeb * XXX If we clear this now and later a driver 30823206587aSBjoern A. Zeeb * thinks it * can do a hw_scan again, we will 30833206587aSBjoern A. Zeeb * currently not re-enable it? 30843206587aSBjoern A. Zeeb */ 30853206587aSBjoern A. Zeeb vap->iv_flags_ext &= ~IEEE80211_FEXT_SCAN_OFFLOAD; 3086196cfd0bSBjoern A. Zeeb ieee80211_start_scan(vap, 3087196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_ACTIVE | 3088196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_NOPICK | 3089196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_ONCE, 3090196cfd0bSBjoern A. Zeeb IEEE80211_SCAN_FOREVER, 3091196cfd0bSBjoern A. Zeeb ss->ss_mindwell ? ss->ss_mindwell : msecs_to_ticks(20), 3092196cfd0bSBjoern A. Zeeb ss->ss_maxdwell ? ss->ss_maxdwell : msecs_to_ticks(200), 3093196cfd0bSBjoern A. Zeeb vap->iv_des_nssid, vap->iv_des_ssid); 3094d3ef7fb4SBjoern A. Zeeb goto sw_scan; 3095196cfd0bSBjoern A. Zeeb } 3096d3ef7fb4SBjoern A. Zeeb 3097d3ef7fb4SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: hw_scan returned %d\n", 3098d3ef7fb4SBjoern A. Zeeb __func__, error); 30996b4cac81SBjoern A. Zeeb } 31006b4cac81SBjoern A. Zeeb } 31016b4cac81SBjoern A. Zeeb } 31026b4cac81SBjoern A. Zeeb 31036b4cac81SBjoern A. Zeeb static void 31046b4cac81SBjoern A. Zeeb lkpi_ic_scan_end(struct ieee80211com *ic) 31056b4cac81SBjoern A. Zeeb { 31066b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 31078ac540d3SBjoern A. Zeeb bool is_hw_scan; 31086b4cac81SBjoern A. Zeeb 31096b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 31108ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 3111a486fbbdSBjoern A. Zeeb if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) == 0) { 31128ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 31136b4cac81SBjoern A. Zeeb return; 31146b4cac81SBjoern A. Zeeb } 31158ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 31168ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 31176b4cac81SBjoern A. Zeeb 31188ac540d3SBjoern A. Zeeb if (!is_hw_scan) { 3119a486fbbdSBjoern A. Zeeb struct ieee80211_scan_state *ss; 3120a486fbbdSBjoern A. Zeeb struct ieee80211vap *vap; 31216b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 31226b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 31236b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 31246b4cac81SBjoern A. Zeeb 3125a486fbbdSBjoern A. Zeeb ss = ic->ic_scan; 3126a486fbbdSBjoern A. Zeeb vap = ss->ss_vap; 31276b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 31286b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 31296b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 3130a486fbbdSBjoern A. Zeeb 31316b4cac81SBjoern A. Zeeb lkpi_80211_mo_sw_scan_complete(hw, vif); 31326b4cac81SBjoern A. Zeeb 31336b4cac81SBjoern A. Zeeb /* Send PS to stop buffering if n80211 does not for us? */ 3134086be6a8SBjoern A. Zeeb 3135086be6a8SBjoern A. Zeeb if (vap->iv_state == IEEE80211_S_SCAN) 3136086be6a8SBjoern A. Zeeb lkpi_hw_conf_idle(hw, true); 31376b4cac81SBjoern A. Zeeb } 31386b4cac81SBjoern A. Zeeb } 31396b4cac81SBjoern A. Zeeb 31406b4cac81SBjoern A. Zeeb static void 3141a486fbbdSBjoern A. Zeeb lkpi_ic_scan_curchan(struct ieee80211_scan_state *ss, 3142a486fbbdSBjoern A. Zeeb unsigned long maxdwell) 3143a486fbbdSBjoern A. Zeeb { 3144a486fbbdSBjoern A. Zeeb struct lkpi_hw *lhw; 31458ac540d3SBjoern A. Zeeb bool is_hw_scan; 3146a486fbbdSBjoern A. Zeeb 3147a486fbbdSBjoern A. Zeeb lhw = ss->ss_ic->ic_softc; 31488ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 31498ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 31508ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 31518ac540d3SBjoern A. Zeeb if (!is_hw_scan) 3152a486fbbdSBjoern A. Zeeb lhw->ic_scan_curchan(ss, maxdwell); 3153a486fbbdSBjoern A. Zeeb } 3154a486fbbdSBjoern A. Zeeb 3155a486fbbdSBjoern A. Zeeb static void 3156a486fbbdSBjoern A. Zeeb lkpi_ic_scan_mindwell(struct ieee80211_scan_state *ss) 3157a486fbbdSBjoern A. Zeeb { 3158a486fbbdSBjoern A. Zeeb struct lkpi_hw *lhw; 31598ac540d3SBjoern A. Zeeb bool is_hw_scan; 3160a486fbbdSBjoern A. Zeeb 3161a486fbbdSBjoern A. Zeeb lhw = ss->ss_ic->ic_softc; 31628ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 31638ac540d3SBjoern A. Zeeb is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0; 31648ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 31658ac540d3SBjoern A. Zeeb if (!is_hw_scan) 3166a486fbbdSBjoern A. Zeeb lhw->ic_scan_mindwell(ss); 3167a486fbbdSBjoern A. Zeeb } 3168a486fbbdSBjoern A. Zeeb 3169a486fbbdSBjoern A. Zeeb static void 31706b4cac81SBjoern A. Zeeb lkpi_ic_set_channel(struct ieee80211com *ic) 31716b4cac81SBjoern A. Zeeb { 31726b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 31736b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 3174b2cf3c21SBjoern A. Zeeb struct ieee80211_channel *c; 3175b2cf3c21SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 31766b4cac81SBjoern A. Zeeb int error; 31778ac540d3SBjoern A. Zeeb bool hw_scan_running; 31786b4cac81SBjoern A. Zeeb 31796b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 3180b2cf3c21SBjoern A. Zeeb 3181b2cf3c21SBjoern A. Zeeb /* If we do not support (*config)() save us the work. */ 3182b2cf3c21SBjoern A. Zeeb if (lhw->ops->config == NULL) 31836b4cac81SBjoern A. Zeeb return; 31846b4cac81SBjoern A. Zeeb 3185a486fbbdSBjoern A. Zeeb /* If we have a hw_scan running do not switch channels. */ 31868ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 31878ac540d3SBjoern A. Zeeb hw_scan_running = 31888ac540d3SBjoern A. Zeeb (lhw->scan_flags & (LKPI_LHW_SCAN_RUNNING|LKPI_LHW_SCAN_HW)) == 31898ac540d3SBjoern A. Zeeb (LKPI_LHW_SCAN_RUNNING|LKPI_LHW_SCAN_HW); 31908ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 31918ac540d3SBjoern A. Zeeb if (hw_scan_running) 3192a486fbbdSBjoern A. Zeeb return; 3193a486fbbdSBjoern A. Zeeb 3194b2cf3c21SBjoern A. Zeeb c = ic->ic_curchan; 3195b2cf3c21SBjoern A. Zeeb if (c == NULL || c == IEEE80211_CHAN_ANYC) { 31966b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: c %p ops->config %p\n", __func__, 31976b4cac81SBjoern A. Zeeb c, lhw->ops->config); 31986b4cac81SBjoern A. Zeeb return; 31996b4cac81SBjoern A. Zeeb } 32006b4cac81SBjoern A. Zeeb 32016b4cac81SBjoern A. Zeeb chan = lkpi_find_lkpi80211_chan(lhw, c); 32026b4cac81SBjoern A. Zeeb if (chan == NULL) { 32036b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: c %p chan %p\n", __func__, 32046b4cac81SBjoern A. Zeeb c, chan); 32056b4cac81SBjoern A. Zeeb return; 32066b4cac81SBjoern A. Zeeb } 32076b4cac81SBjoern A. Zeeb 32086b4cac81SBjoern A. Zeeb /* XXX max power for scanning? */ 32096b4cac81SBjoern A. Zeeb IMPROVE(); 32106b4cac81SBjoern A. Zeeb 32116b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 32124a07abdeSBjoern A. Zeeb cfg80211_chandef_create(&hw->conf.chandef, chan, 3213*9fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 3214*9fb91463SBjoern A. Zeeb (ic->ic_htcaps & IEEE80211_HTC_HT) ? 0 : 3215*9fb91463SBjoern A. Zeeb #endif 32164a07abdeSBjoern A. Zeeb NL80211_CHAN_NO_HT); 32176b4cac81SBjoern A. Zeeb 32186b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_CHANNEL); 32196b4cac81SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) { 32206b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: config %#0x returned %d\n", 32216b4cac81SBjoern A. Zeeb __func__, IEEE80211_CONF_CHANGE_CHANNEL, error); 32226b4cac81SBjoern A. Zeeb /* XXX should we unroll to the previous chandef? */ 32236b4cac81SBjoern A. Zeeb IMPROVE(); 32246b4cac81SBjoern A. Zeeb } else { 32256b4cac81SBjoern A. Zeeb /* Update radiotap channels as well. */ 32266b4cac81SBjoern A. Zeeb lhw->rtap_tx.wt_chan_freq = htole16(c->ic_freq); 32276b4cac81SBjoern A. Zeeb lhw->rtap_tx.wt_chan_flags = htole16(c->ic_flags); 32286b4cac81SBjoern A. Zeeb lhw->rtap_rx.wr_chan_freq = htole16(c->ic_freq); 32296b4cac81SBjoern A. Zeeb lhw->rtap_rx.wr_chan_flags = htole16(c->ic_flags); 32306b4cac81SBjoern A. Zeeb } 32316b4cac81SBjoern A. Zeeb 32326b4cac81SBjoern A. Zeeb /* Currently PS is hard coded off! Not sure it belongs here. */ 32336b4cac81SBjoern A. Zeeb IMPROVE(); 32346b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, SUPPORTS_PS) && 32356b4cac81SBjoern A. Zeeb (hw->conf.flags & IEEE80211_CONF_PS) != 0) { 32366b4cac81SBjoern A. Zeeb hw->conf.flags &= ~IEEE80211_CONF_PS; 32376b4cac81SBjoern A. Zeeb error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_PS); 32386b4cac81SBjoern A. Zeeb if (error != 0 && error != EOPNOTSUPP) 32396b4cac81SBjoern A. Zeeb ic_printf(ic, "ERROR: %s: config %#0x returned " 32406b4cac81SBjoern A. Zeeb "%d\n", __func__, IEEE80211_CONF_CHANGE_PS, 32416b4cac81SBjoern A. Zeeb error); 32426b4cac81SBjoern A. Zeeb } 32436b4cac81SBjoern A. Zeeb } 32446b4cac81SBjoern A. Zeeb 32456b4cac81SBjoern A. Zeeb static struct ieee80211_node * 32466b4cac81SBjoern A. Zeeb lkpi_ic_node_alloc(struct ieee80211vap *vap, 32476b4cac81SBjoern A. Zeeb const uint8_t mac[IEEE80211_ADDR_LEN]) 32486b4cac81SBjoern A. Zeeb { 32496b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 32506b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 32514f61ef8bSBjoern A. Zeeb struct ieee80211_node *ni; 32526b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 32536b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 32546b4cac81SBjoern A. Zeeb 32556b4cac81SBjoern A. Zeeb ic = vap->iv_ic; 32566b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 32576b4cac81SBjoern A. Zeeb 32586b4cac81SBjoern A. Zeeb /* We keep allocations de-coupled so we can deal with the two worlds. */ 32594f61ef8bSBjoern A. Zeeb if (lhw->ic_node_alloc == NULL) 32604f61ef8bSBjoern A. Zeeb return (NULL); 32614f61ef8bSBjoern A. Zeeb 32626b4cac81SBjoern A. Zeeb ni = lhw->ic_node_alloc(vap, mac); 32636b4cac81SBjoern A. Zeeb if (ni == NULL) 32646b4cac81SBjoern A. Zeeb return (NULL); 32656b4cac81SBjoern A. Zeeb 32666b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 32674f61ef8bSBjoern A. Zeeb lsta = lkpi_lsta_alloc(vap, mac, hw, ni); 32686b4cac81SBjoern A. Zeeb if (lsta == NULL) { 32696b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL) 32706b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni); 32716b4cac81SBjoern A. Zeeb return (NULL); 32726b4cac81SBjoern A. Zeeb } 32736b4cac81SBjoern A. Zeeb 32746b4cac81SBjoern A. Zeeb return (ni); 32756b4cac81SBjoern A. Zeeb } 32766b4cac81SBjoern A. Zeeb 32776b4cac81SBjoern A. Zeeb static int 32786b4cac81SBjoern A. Zeeb lkpi_ic_node_init(struct ieee80211_node *ni) 32796b4cac81SBjoern A. Zeeb { 32806b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 32816b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 32826b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 32836b4cac81SBjoern A. Zeeb int error; 32846b4cac81SBjoern A. Zeeb 32856b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 32866b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 32876b4cac81SBjoern A. Zeeb 32886b4cac81SBjoern A. Zeeb if (lhw->ic_node_init != NULL) { 32896b4cac81SBjoern A. Zeeb error = lhw->ic_node_init(ni); 32906b4cac81SBjoern A. Zeeb if (error != 0) 32916b4cac81SBjoern A. Zeeb return (error); 32926b4cac81SBjoern A. Zeeb } 32936b4cac81SBjoern A. Zeeb 32946b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 32956b4cac81SBjoern A. Zeeb 32966b4cac81SBjoern A. Zeeb /* Now take the reference before linking it to the table. */ 32976b4cac81SBjoern A. Zeeb lsta->ni = ieee80211_ref_node(ni); 32986b4cac81SBjoern A. Zeeb 32996b4cac81SBjoern A. Zeeb /* XXX-BZ Sync other state over. */ 33006b4cac81SBjoern A. Zeeb IMPROVE(); 33016b4cac81SBjoern A. Zeeb 33026b4cac81SBjoern A. Zeeb return (0); 33036b4cac81SBjoern A. Zeeb } 33046b4cac81SBjoern A. Zeeb 33056b4cac81SBjoern A. Zeeb static void 33066b4cac81SBjoern A. Zeeb lkpi_ic_node_cleanup(struct ieee80211_node *ni) 33076b4cac81SBjoern A. Zeeb { 33086b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 33096b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 33106b4cac81SBjoern A. Zeeb 33116b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 33126b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 33136b4cac81SBjoern A. Zeeb 33146b4cac81SBjoern A. Zeeb /* XXX-BZ remove from driver, ... */ 33156b4cac81SBjoern A. Zeeb IMPROVE(); 33166b4cac81SBjoern A. Zeeb 33176b4cac81SBjoern A. Zeeb if (lhw->ic_node_cleanup != NULL) 33186b4cac81SBjoern A. Zeeb lhw->ic_node_cleanup(ni); 33196b4cac81SBjoern A. Zeeb } 33206b4cac81SBjoern A. Zeeb 33216b4cac81SBjoern A. Zeeb static void 33226b4cac81SBjoern A. Zeeb lkpi_ic_node_free(struct ieee80211_node *ni) 33236b4cac81SBjoern A. Zeeb { 33246b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 33256b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 33266b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 33276b4cac81SBjoern A. Zeeb 33286b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 33296b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 33306b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 3331d9f59799SBjoern A. Zeeb if (lsta == NULL) 3332d9f59799SBjoern A. Zeeb goto out; 33336b4cac81SBjoern A. Zeeb 33346b4cac81SBjoern A. Zeeb /* XXX-BZ free resources, ... */ 33356b4cac81SBjoern A. Zeeb IMPROVE(); 33366b4cac81SBjoern A. Zeeb 33376b4cac81SBjoern A. Zeeb /* Flush mbufq (make sure to release ni refs!). */ 33386b4cac81SBjoern A. Zeeb #ifdef __notyet__ 33396b4cac81SBjoern A. Zeeb KASSERT(mbufq_len(&lsta->txq) == 0, ("%s: lsta %p has txq len %d != 0\n", 33406b4cac81SBjoern A. Zeeb __func__, lsta, mbufq_len(&lsta->txq))); 33416b4cac81SBjoern A. Zeeb #endif 33426b4cac81SBjoern A. Zeeb /* Drain taskq. */ 33436b4cac81SBjoern A. Zeeb 33446b4cac81SBjoern A. Zeeb /* Drain sta->txq[] */ 33456b4cac81SBjoern A. Zeeb mtx_destroy(&lsta->txq_mtx); 33466b4cac81SBjoern A. Zeeb 33476b4cac81SBjoern A. Zeeb /* Remove lsta if added_to_drv. */ 3348e24e8103SBjoern A. Zeeb 33496b4cac81SBjoern A. Zeeb /* Remove lsta from vif */ 3350e24e8103SBjoern A. Zeeb /* Remove ref from lsta node... */ 3351d9f59799SBjoern A. Zeeb /* Free lsta. */ 3352e24e8103SBjoern A. Zeeb lkpi_lsta_remove(lsta, VAP_TO_LVIF(ni->ni_vap)); 3353d9f59799SBjoern A. Zeeb 3354d9f59799SBjoern A. Zeeb out: 33556b4cac81SBjoern A. Zeeb if (lhw->ic_node_free != NULL) 33566b4cac81SBjoern A. Zeeb lhw->ic_node_free(ni); 33576b4cac81SBjoern A. Zeeb } 33586b4cac81SBjoern A. Zeeb 33596b4cac81SBjoern A. Zeeb static int 33606b4cac81SBjoern A. Zeeb lkpi_ic_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, 33616b4cac81SBjoern A. Zeeb const struct ieee80211_bpf_params *params __unused) 33626b4cac81SBjoern A. Zeeb { 33636b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 33646b4cac81SBjoern A. Zeeb 33656b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 33666b4cac81SBjoern A. Zeeb 33676b4cac81SBjoern A. Zeeb /* Queue the packet and enqueue the task to handle it. */ 33686b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_LOCK(lsta); 33696b4cac81SBjoern A. Zeeb mbufq_enqueue(&lsta->txq, m); 33706b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_UNLOCK(lsta); 33716b4cac81SBjoern A. Zeeb 33729d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 33739d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 33746b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p ni %p %6D mbuf_qlen %d\n", 33756b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, ni, ni->ni_macaddr, ":", 33766b4cac81SBjoern A. Zeeb mbufq_len(&lsta->txq)); 33779d9ba2b7SBjoern A. Zeeb #endif 33786b4cac81SBjoern A. Zeeb 33796b4cac81SBjoern A. Zeeb taskqueue_enqueue(taskqueue_thread, &lsta->txq_task); 33806b4cac81SBjoern A. Zeeb return (0); 33816b4cac81SBjoern A. Zeeb } 33826b4cac81SBjoern A. Zeeb 33836b4cac81SBjoern A. Zeeb static void 33846b4cac81SBjoern A. Zeeb lkpi_80211_txq_tx_one(struct lkpi_sta *lsta, struct mbuf *m) 33856b4cac81SBjoern A. Zeeb { 33866b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 3387b35f6cd0SBjoern A. Zeeb #ifndef LKPI_80211_HW_CRYPTO 33886b4cac81SBjoern A. Zeeb struct ieee80211_frame *wh; 3389b35f6cd0SBjoern A. Zeeb #endif 33906b4cac81SBjoern A. Zeeb struct ieee80211_key *k; 33916b4cac81SBjoern A. Zeeb struct sk_buff *skb; 33926b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 33936b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 33946b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 33956b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 33966b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 33976b4cac81SBjoern A. Zeeb struct ieee80211_channel *c; 33986b4cac81SBjoern A. Zeeb struct ieee80211_tx_control control; 33996b4cac81SBjoern A. Zeeb struct ieee80211_tx_info *info; 34006b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 3401e3a0b120SBjoern A. Zeeb struct ieee80211_hdr *hdr; 34026b4cac81SBjoern A. Zeeb void *buf; 3403e3a0b120SBjoern A. Zeeb uint8_t ac, tid; 34046b4cac81SBjoern A. Zeeb 34056b4cac81SBjoern A. Zeeb M_ASSERTPKTHDR(m); 34066b4cac81SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 34079d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX_DUMP) 34086b4cac81SBjoern A. Zeeb hexdump(mtod(m, const void *), m->m_len, "RAW TX (plain) ", 0); 34096b4cac81SBjoern A. Zeeb #endif 34106b4cac81SBjoern A. Zeeb 34116b4cac81SBjoern A. Zeeb ni = lsta->ni; 3412b35f6cd0SBjoern A. Zeeb k = NULL; 3413b35f6cd0SBjoern A. Zeeb #ifndef LKPI_80211_HW_CRYPTO 34146b4cac81SBjoern A. Zeeb /* Encrypt the frame if need be; XXX-BZ info->control.hw_key. */ 34156b4cac81SBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame *); 34166b4cac81SBjoern A. Zeeb if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { 34176b4cac81SBjoern A. Zeeb /* Retrieve key for TX && do software encryption. */ 34186b4cac81SBjoern A. Zeeb k = ieee80211_crypto_encap(ni, m); 34196b4cac81SBjoern A. Zeeb if (k == NULL) { 34206b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 34216b4cac81SBjoern A. Zeeb m_freem(m); 34226b4cac81SBjoern A. Zeeb return; 34236b4cac81SBjoern A. Zeeb } 34246b4cac81SBjoern A. Zeeb } 34256b4cac81SBjoern A. Zeeb #endif 34266b4cac81SBjoern A. Zeeb 34276b4cac81SBjoern A. Zeeb ic = ni->ni_ic; 34286b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 34296b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 34306b4cac81SBjoern A. Zeeb c = ni->ni_chan; 34316b4cac81SBjoern A. Zeeb 34326b4cac81SBjoern A. Zeeb if (ieee80211_radiotap_active_vap(ni->ni_vap)) { 34336b4cac81SBjoern A. Zeeb struct lkpi_radiotap_tx_hdr *rtap; 34346b4cac81SBjoern A. Zeeb 34356b4cac81SBjoern A. Zeeb rtap = &lhw->rtap_tx; 34366b4cac81SBjoern A. Zeeb rtap->wt_flags = 0; 34376b4cac81SBjoern A. Zeeb if (k != NULL) 34386b4cac81SBjoern A. Zeeb rtap->wt_flags |= IEEE80211_RADIOTAP_F_WEP; 34396b4cac81SBjoern A. Zeeb if (m->m_flags & M_FRAG) 34406b4cac81SBjoern A. Zeeb rtap->wt_flags |= IEEE80211_RADIOTAP_F_FRAG; 34416b4cac81SBjoern A. Zeeb IMPROVE(); 34426b4cac81SBjoern A. Zeeb rtap->wt_rate = 0; 34436b4cac81SBjoern A. Zeeb if (c != NULL && c != IEEE80211_CHAN_ANYC) { 34446b4cac81SBjoern A. Zeeb rtap->wt_chan_freq = htole16(c->ic_freq); 34456b4cac81SBjoern A. Zeeb rtap->wt_chan_flags = htole16(c->ic_flags); 34466b4cac81SBjoern A. Zeeb } 34476b4cac81SBjoern A. Zeeb 34486b4cac81SBjoern A. Zeeb ieee80211_radiotap_tx(ni->ni_vap, m); 34496b4cac81SBjoern A. Zeeb } 34506b4cac81SBjoern A. Zeeb 34516b4cac81SBjoern A. Zeeb /* 34526b4cac81SBjoern A. Zeeb * net80211 should handle hw->extra_tx_headroom. 34536b4cac81SBjoern A. Zeeb * Though for as long as we are copying we don't mind. 34543d09d310SBjoern A. Zeeb * XXX-BZ rtw88 asks for too much headroom for ipv6+tcp: 34553d09d310SBjoern A. Zeeb * https://lists.freebsd.org/archives/freebsd-transport/2022-February/000012.html 34566b4cac81SBjoern A. Zeeb */ 34576b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + m->m_pkthdr.len); 34586b4cac81SBjoern A. Zeeb if (skb == NULL) { 34593f0083c4SBjoern A. Zeeb ic_printf(ic, "ERROR %s: skb alloc failed\n", __func__); 34606b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 34616b4cac81SBjoern A. Zeeb m_freem(m); 34626b4cac81SBjoern A. Zeeb return; 34636b4cac81SBjoern A. Zeeb } 34646b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 34656b4cac81SBjoern A. Zeeb 34666b4cac81SBjoern A. Zeeb /* XXX-BZ we need a SKB version understanding mbuf. */ 34676b4cac81SBjoern A. Zeeb /* Save the mbuf for ieee80211_tx_complete(). */ 34686b4cac81SBjoern A. Zeeb skb->m_free_func = lkpi_ieee80211_free_skb_mbuf; 34696b4cac81SBjoern A. Zeeb skb->m = m; 34706b4cac81SBjoern A. Zeeb #if 0 34716b4cac81SBjoern A. Zeeb skb_put_data(skb, m->m_data, m->m_pkthdr.len); 34726b4cac81SBjoern A. Zeeb #else 34736b4cac81SBjoern A. Zeeb buf = skb_put(skb, m->m_pkthdr.len); 34746b4cac81SBjoern A. Zeeb m_copydata(m, 0, m->m_pkthdr.len, buf); 34756b4cac81SBjoern A. Zeeb #endif 34766b4cac81SBjoern A. Zeeb /* Save the ni. */ 34776b4cac81SBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = ni; 34786b4cac81SBjoern A. Zeeb 34796b4cac81SBjoern A. Zeeb lvif = VAP_TO_LVIF(ni->ni_vap); 34806b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 34816b4cac81SBjoern A. Zeeb 3482e3a0b120SBjoern A. Zeeb hdr = (void *)skb->data; 3483e3a0b120SBjoern A. Zeeb tid = linuxkpi_ieee80211_get_tid(hdr, true); 3484e3a0b120SBjoern A. Zeeb if (tid == IEEE80211_NONQOS_TID) { /* == IEEE80211_NUM_TIDS */ 3485e3a0b120SBjoern A. Zeeb skb->priority = 0; 3486e3a0b120SBjoern A. Zeeb ac = IEEE80211_AC_BE; 3487e3a0b120SBjoern A. Zeeb } else { 3488e3a0b120SBjoern A. Zeeb skb->priority = tid & IEEE80211_QOS_CTL_TID_MASK; 3489fb3c249eSBjoern A. Zeeb ac = ieee80211e_up_to_ac[tid & 7]; 3490e3a0b120SBjoern A. Zeeb } 34916b4cac81SBjoern A. Zeeb skb_set_queue_mapping(skb, ac); 34926b4cac81SBjoern A. Zeeb 34936b4cac81SBjoern A. Zeeb info = IEEE80211_SKB_CB(skb); 34946b4cac81SBjoern A. Zeeb info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; 34956b4cac81SBjoern A. Zeeb /* Slight delay; probably only happens on scanning so fine? */ 34966b4cac81SBjoern A. Zeeb if (c == NULL || c == IEEE80211_CHAN_ANYC) 34976b4cac81SBjoern A. Zeeb c = ic->ic_curchan; 34986b4cac81SBjoern A. Zeeb info->band = lkpi_net80211_chan_to_nl80211_band(c); 3499e3a0b120SBjoern A. Zeeb info->hw_queue = vif->hw_queue[ac]; 35006b4cac81SBjoern A. Zeeb if (m->m_flags & M_EAPOL) 35016b4cac81SBjoern A. Zeeb info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO; 35026b4cac81SBjoern A. Zeeb info->control.vif = vif; 35036b4cac81SBjoern A. Zeeb /* XXX-BZ info->control.rates */ 3504*9fb91463SBjoern A. Zeeb #ifdef __notyet__ 3505*9fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 3506*9fb91463SBjoern A. Zeeb info->control.rts_cts_rate_idx= 3507*9fb91463SBjoern A. Zeeb info->control.use_rts= /* RTS */ 3508*9fb91463SBjoern A. Zeeb info->control.use_cts_prot= /* RTS/CTS*/ 3509*9fb91463SBjoern A. Zeeb #endif 3510*9fb91463SBjoern A. Zeeb #endif 35116b4cac81SBjoern A. Zeeb 35126b4cac81SBjoern A. Zeeb lsta = lkpi_find_lsta_by_ni(lvif, ni); 35136b4cac81SBjoern A. Zeeb if (lsta != NULL) { 35146b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 3515b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 35166b4cac81SBjoern A. Zeeb info->control.hw_key = lsta->kc; 35176b4cac81SBjoern A. Zeeb #endif 35186b4cac81SBjoern A. Zeeb } else { 35196b4cac81SBjoern A. Zeeb sta = NULL; 35206b4cac81SBjoern A. Zeeb } 35216b4cac81SBjoern A. Zeeb 35226b4cac81SBjoern A. Zeeb IMPROVE(); 35236b4cac81SBjoern A. Zeeb 35246b4cac81SBjoern A. Zeeb if (sta != NULL) { 35256b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 35266b4cac81SBjoern A. Zeeb 3527e3a0b120SBjoern A. Zeeb ltxq = NULL; 3528e3a0b120SBjoern A. Zeeb if (!ieee80211_is_data_present(hdr->frame_control)) { 3529e3a0b120SBjoern A. Zeeb if (vif->type == NL80211_IFTYPE_STATION && 3530e3a0b120SBjoern A. Zeeb lsta->added_to_drv && 3531e3a0b120SBjoern A. Zeeb sta->txq[IEEE80211_NUM_TIDS] != NULL) 3532d0d29110SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[IEEE80211_NUM_TIDS]); 3533e3a0b120SBjoern A. Zeeb } else if (lsta->added_to_drv && 3534e3a0b120SBjoern A. Zeeb sta->txq[skb->priority] != NULL) { 3535e3a0b120SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[skb->priority]); 3536e3a0b120SBjoern A. Zeeb } 3537e3a0b120SBjoern A. Zeeb if (ltxq == NULL) 3538d0d29110SBjoern A. Zeeb goto ops_tx; 3539e3a0b120SBjoern A. Zeeb 3540d0d29110SBjoern A. Zeeb KASSERT(ltxq != NULL, ("%s: lsta %p sta %p m %p skb %p " 3541d0d29110SBjoern A. Zeeb "ltxq %p != NULL\n", __func__, lsta, sta, m, skb, ltxq)); 3542d0d29110SBjoern A. Zeeb 35436b4cac81SBjoern A. Zeeb skb_queue_tail(<xq->skbq, skb); 35449d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 35459d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 3546d0d29110SBjoern A. Zeeb printf("%s:%d mo_wake_tx_queue :: %d %u lsta %p sta %p " 3547d0d29110SBjoern A. Zeeb "ni %p %6D skb %p lxtq %p { qlen %u, ac %d tid %u } " 3548d0d29110SBjoern A. Zeeb "WAKE_TX_Q ac %d prio %u qmap %u\n", 3549fb6eaf74SBjoern A. Zeeb __func__, __LINE__, 3550d0d29110SBjoern A. Zeeb curthread->td_tid, (unsigned int)ticks, 3551d0d29110SBjoern A. Zeeb lsta, sta, ni, ni->ni_macaddr, ":", skb, ltxq, 3552d0d29110SBjoern A. Zeeb skb_queue_len(<xq->skbq), ltxq->txq.ac, 3553d0d29110SBjoern A. Zeeb ltxq->txq.tid, ac, skb->priority, skb->qmap); 35549d9ba2b7SBjoern A. Zeeb #endif 3555d0d29110SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, <xq->txq); 35566b4cac81SBjoern A. Zeeb return; 35576b4cac81SBjoern A. Zeeb } 35586b4cac81SBjoern A. Zeeb 35596b4cac81SBjoern A. Zeeb ops_tx: 35609d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 35619d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 3562d0d29110SBjoern A. Zeeb printf("%s:%d mo_tx :: lsta %p sta %p ni %p %6D skb %p " 3563d0d29110SBjoern A. Zeeb "TX ac %d prio %u qmap %u\n", 35646b4cac81SBjoern A. Zeeb __func__, __LINE__, lsta, sta, ni, ni->ni_macaddr, ":", 35656b4cac81SBjoern A. Zeeb skb, ac, skb->priority, skb->qmap); 35669d9ba2b7SBjoern A. Zeeb #endif 35676b4cac81SBjoern A. Zeeb memset(&control, 0, sizeof(control)); 35686b4cac81SBjoern A. Zeeb control.sta = sta; 35696b4cac81SBjoern A. Zeeb 35706b4cac81SBjoern A. Zeeb lkpi_80211_mo_tx(hw, &control, skb); 35716b4cac81SBjoern A. Zeeb return; 35726b4cac81SBjoern A. Zeeb } 35736b4cac81SBjoern A. Zeeb 35746b4cac81SBjoern A. Zeeb static void 35756b4cac81SBjoern A. Zeeb lkpi_80211_txq_task(void *ctx, int pending) 35766b4cac81SBjoern A. Zeeb { 35776b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 35786b4cac81SBjoern A. Zeeb struct mbufq mq; 35796b4cac81SBjoern A. Zeeb struct mbuf *m; 35806b4cac81SBjoern A. Zeeb 35816b4cac81SBjoern A. Zeeb lsta = ctx; 35826b4cac81SBjoern A. Zeeb 35839d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 35849d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 35856b4cac81SBjoern A. Zeeb printf("%s:%d lsta %p ni %p %6D pending %d mbuf_qlen %d\n", 35869d9ba2b7SBjoern A. Zeeb __func__, __LINE__, lsta, lsta->ni, lsta->ni->ni_macaddr, ":", 35876b4cac81SBjoern A. Zeeb pending, mbufq_len(&lsta->txq)); 35889d9ba2b7SBjoern A. Zeeb #endif 35896b4cac81SBjoern A. Zeeb 35906b4cac81SBjoern A. Zeeb mbufq_init(&mq, IFQ_MAXLEN); 35916b4cac81SBjoern A. Zeeb 35926b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_LOCK(lsta); 35936b4cac81SBjoern A. Zeeb mbufq_concat(&mq, &lsta->txq); 35946b4cac81SBjoern A. Zeeb LKPI_80211_LSTA_UNLOCK(lsta); 35956b4cac81SBjoern A. Zeeb 35966b4cac81SBjoern A. Zeeb m = mbufq_dequeue(&mq); 35976b4cac81SBjoern A. Zeeb while (m != NULL) { 35986b4cac81SBjoern A. Zeeb lkpi_80211_txq_tx_one(lsta, m); 35996b4cac81SBjoern A. Zeeb m = mbufq_dequeue(&mq); 36006b4cac81SBjoern A. Zeeb } 36016b4cac81SBjoern A. Zeeb } 36026b4cac81SBjoern A. Zeeb 36036b4cac81SBjoern A. Zeeb static int 36046b4cac81SBjoern A. Zeeb lkpi_ic_transmit(struct ieee80211com *ic, struct mbuf *m) 36056b4cac81SBjoern A. Zeeb { 36066b4cac81SBjoern A. Zeeb 36076b4cac81SBjoern A. Zeeb /* XXX TODO */ 36086b4cac81SBjoern A. Zeeb IMPROVE(); 36096b4cac81SBjoern A. Zeeb 36106b4cac81SBjoern A. Zeeb /* Quick and dirty cheating hack. */ 36116b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 36126b4cac81SBjoern A. Zeeb 36136b4cac81SBjoern A. Zeeb ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; 36146b4cac81SBjoern A. Zeeb return (lkpi_ic_raw_xmit(ni, m, NULL)); 36156b4cac81SBjoern A. Zeeb } 36166b4cac81SBjoern A. Zeeb 3617*9fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 3618*9fb91463SBjoern A. Zeeb static int 3619*9fb91463SBjoern A. Zeeb lkpi_ic_recv_action(struct ieee80211_node *ni, const struct ieee80211_frame *wh, 3620*9fb91463SBjoern A. Zeeb const uint8_t *frm, const uint8_t *efrm) 3621*9fb91463SBjoern A. Zeeb { 3622*9fb91463SBjoern A. Zeeb struct ieee80211com *ic; 3623*9fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 3624*9fb91463SBjoern A. Zeeb 3625*9fb91463SBjoern A. Zeeb ic = ni->ni_ic; 3626*9fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 3627*9fb91463SBjoern A. Zeeb 3628*9fb91463SBjoern A. Zeeb IMPROVE_HT(); 3629*9fb91463SBjoern A. Zeeb 3630*9fb91463SBjoern A. Zeeb return (lhw->ic_recv_action(ni, wh, frm, efrm)); 3631*9fb91463SBjoern A. Zeeb } 3632*9fb91463SBjoern A. Zeeb 3633*9fb91463SBjoern A. Zeeb static int 3634*9fb91463SBjoern A. Zeeb lkpi_ic_send_action(struct ieee80211_node *ni, int category, int action, void *sa) 3635*9fb91463SBjoern A. Zeeb { 3636*9fb91463SBjoern A. Zeeb struct ieee80211com *ic; 3637*9fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 3638*9fb91463SBjoern A. Zeeb 3639*9fb91463SBjoern A. Zeeb ic = ni->ni_ic; 3640*9fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 3641*9fb91463SBjoern A. Zeeb 3642*9fb91463SBjoern A. Zeeb IMPROVE_HT(); 3643*9fb91463SBjoern A. Zeeb 3644*9fb91463SBjoern A. Zeeb return (lhw->ic_send_action(ni, category, action, sa)); 3645*9fb91463SBjoern A. Zeeb } 3646*9fb91463SBjoern A. Zeeb 3647*9fb91463SBjoern A. Zeeb 3648*9fb91463SBjoern A. Zeeb static int 3649*9fb91463SBjoern A. Zeeb lkpi_ic_ampdu_enable(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap) 3650*9fb91463SBjoern A. Zeeb { 3651*9fb91463SBjoern A. Zeeb struct ieee80211com *ic; 3652*9fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 3653*9fb91463SBjoern A. Zeeb 3654*9fb91463SBjoern A. Zeeb ic = ni->ni_ic; 3655*9fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 3656*9fb91463SBjoern A. Zeeb 3657*9fb91463SBjoern A. Zeeb IMPROVE_HT(); 3658*9fb91463SBjoern A. Zeeb 3659*9fb91463SBjoern A. Zeeb return (lhw->ic_ampdu_enable(ni, tap)); 3660*9fb91463SBjoern A. Zeeb } 3661*9fb91463SBjoern A. Zeeb 3662*9fb91463SBjoern A. Zeeb static int 3663*9fb91463SBjoern A. Zeeb lkpi_ic_addba_request(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 3664*9fb91463SBjoern A. Zeeb int dialogtoken, int baparamset, int batimeout) 3665*9fb91463SBjoern A. Zeeb { 3666*9fb91463SBjoern A. Zeeb struct ieee80211com *ic; 3667*9fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 3668*9fb91463SBjoern A. Zeeb 3669*9fb91463SBjoern A. Zeeb ic = ni->ni_ic; 3670*9fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 3671*9fb91463SBjoern A. Zeeb 3672*9fb91463SBjoern A. Zeeb IMPROVE_HT(); 3673*9fb91463SBjoern A. Zeeb 3674*9fb91463SBjoern A. Zeeb return (lhw->ic_addba_request(ni, tap, dialogtoken, baparamset, batimeout)); 3675*9fb91463SBjoern A. Zeeb } 3676*9fb91463SBjoern A. Zeeb 3677*9fb91463SBjoern A. Zeeb static int 3678*9fb91463SBjoern A. Zeeb lkpi_ic_addba_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 3679*9fb91463SBjoern A. Zeeb int status, int baparamset, int batimeout) 3680*9fb91463SBjoern A. Zeeb { 3681*9fb91463SBjoern A. Zeeb struct ieee80211com *ic; 3682*9fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 3683*9fb91463SBjoern A. Zeeb 3684*9fb91463SBjoern A. Zeeb ic = ni->ni_ic; 3685*9fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 3686*9fb91463SBjoern A. Zeeb 3687*9fb91463SBjoern A. Zeeb IMPROVE_HT(); 3688*9fb91463SBjoern A. Zeeb 3689*9fb91463SBjoern A. Zeeb return (lhw->ic_addba_response(ni, tap, status, baparamset, batimeout)); 3690*9fb91463SBjoern A. Zeeb } 3691*9fb91463SBjoern A. Zeeb 3692*9fb91463SBjoern A. Zeeb static void 3693*9fb91463SBjoern A. Zeeb lkpi_ic_addba_stop(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap) 3694*9fb91463SBjoern A. Zeeb { 3695*9fb91463SBjoern A. Zeeb struct ieee80211com *ic; 3696*9fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 3697*9fb91463SBjoern A. Zeeb 3698*9fb91463SBjoern A. Zeeb ic = ni->ni_ic; 3699*9fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 3700*9fb91463SBjoern A. Zeeb 3701*9fb91463SBjoern A. Zeeb IMPROVE_HT(); 3702*9fb91463SBjoern A. Zeeb 3703*9fb91463SBjoern A. Zeeb lhw->ic_addba_stop(ni, tap); 3704*9fb91463SBjoern A. Zeeb } 3705*9fb91463SBjoern A. Zeeb 3706*9fb91463SBjoern A. Zeeb static void 3707*9fb91463SBjoern A. Zeeb lkpi_ic_addba_response_timeout(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap) 3708*9fb91463SBjoern A. Zeeb { 3709*9fb91463SBjoern A. Zeeb struct ieee80211com *ic; 3710*9fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 3711*9fb91463SBjoern A. Zeeb 3712*9fb91463SBjoern A. Zeeb ic = ni->ni_ic; 3713*9fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 3714*9fb91463SBjoern A. Zeeb 3715*9fb91463SBjoern A. Zeeb IMPROVE_HT(); 3716*9fb91463SBjoern A. Zeeb 3717*9fb91463SBjoern A. Zeeb lhw->ic_addba_response_timeout(ni, tap); 3718*9fb91463SBjoern A. Zeeb } 3719*9fb91463SBjoern A. Zeeb 3720*9fb91463SBjoern A. Zeeb static void 3721*9fb91463SBjoern A. Zeeb lkpi_ic_bar_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap, 3722*9fb91463SBjoern A. Zeeb int status) 3723*9fb91463SBjoern A. Zeeb { 3724*9fb91463SBjoern A. Zeeb struct ieee80211com *ic; 3725*9fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 3726*9fb91463SBjoern A. Zeeb 3727*9fb91463SBjoern A. Zeeb ic = ni->ni_ic; 3728*9fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 3729*9fb91463SBjoern A. Zeeb 3730*9fb91463SBjoern A. Zeeb IMPROVE_HT(); 3731*9fb91463SBjoern A. Zeeb 3732*9fb91463SBjoern A. Zeeb lhw->ic_bar_response(ni, tap, status); 3733*9fb91463SBjoern A. Zeeb } 3734*9fb91463SBjoern A. Zeeb 3735*9fb91463SBjoern A. Zeeb static int 3736*9fb91463SBjoern A. Zeeb lkpi_ic_ampdu_rx_start(struct ieee80211_node *ni, struct ieee80211_rx_ampdu *rap, 3737*9fb91463SBjoern A. Zeeb int baparamset, int batimeout, int baseqctl) 3738*9fb91463SBjoern A. Zeeb { 3739*9fb91463SBjoern A. Zeeb struct ieee80211com *ic; 3740*9fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 3741*9fb91463SBjoern A. Zeeb struct ieee80211_hw *hw; 3742*9fb91463SBjoern A. Zeeb struct ieee80211vap *vap; 3743*9fb91463SBjoern A. Zeeb struct lkpi_vif *lvif; 3744*9fb91463SBjoern A. Zeeb struct ieee80211_vif *vif; 3745*9fb91463SBjoern A. Zeeb struct lkpi_sta *lsta; 3746*9fb91463SBjoern A. Zeeb struct ieee80211_sta *sta; 3747*9fb91463SBjoern A. Zeeb struct ieee80211_ampdu_params params; 3748*9fb91463SBjoern A. Zeeb int error; 3749*9fb91463SBjoern A. Zeeb 3750*9fb91463SBjoern A. Zeeb ic = ni->ni_ic; 3751*9fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 3752*9fb91463SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 3753*9fb91463SBjoern A. Zeeb vap = ni->ni_vap; 3754*9fb91463SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 3755*9fb91463SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 3756*9fb91463SBjoern A. Zeeb lsta = ni->ni_drv_data; 3757*9fb91463SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 3758*9fb91463SBjoern A. Zeeb 3759*9fb91463SBjoern A. Zeeb params.sta = sta; 3760*9fb91463SBjoern A. Zeeb params.action = IEEE80211_AMPDU_RX_START; 3761*9fb91463SBjoern A. Zeeb params.buf_size = _IEEE80211_MASKSHIFT(le16toh(baparamset), IEEE80211_BAPS_BUFSIZ); 3762*9fb91463SBjoern A. Zeeb if (params.buf_size == 0) 3763*9fb91463SBjoern A. Zeeb params.buf_size = IEEE80211_MAX_AMPDU_BUF_HT; 3764*9fb91463SBjoern A. Zeeb else 3765*9fb91463SBjoern A. Zeeb params.buf_size = min(params.buf_size, IEEE80211_MAX_AMPDU_BUF_HT); 3766*9fb91463SBjoern A. Zeeb if (params.buf_size > hw->max_rx_aggregation_subframes) 3767*9fb91463SBjoern A. Zeeb params.buf_size = hw->max_rx_aggregation_subframes; 3768*9fb91463SBjoern A. Zeeb params.timeout = le16toh(batimeout); 3769*9fb91463SBjoern A. Zeeb params.ssn = _IEEE80211_MASKSHIFT(le16toh(baseqctl), IEEE80211_BASEQ_START); 3770*9fb91463SBjoern A. Zeeb params.tid = _IEEE80211_MASKSHIFT(le16toh(baparamset), IEEE80211_BAPS_TID); 3771*9fb91463SBjoern A. Zeeb params.amsdu = false; 3772*9fb91463SBjoern A. Zeeb 3773*9fb91463SBjoern A. Zeeb IMPROVE_HT("Do we need to distinguish based on SUPPORTS_REORDERING_BUFFER?"); 3774*9fb91463SBjoern A. Zeeb 3775*9fb91463SBjoern A. Zeeb /* This may call kalloc. Make sure we can sleep. */ 3776*9fb91463SBjoern A. Zeeb error = lkpi_80211_mo_ampdu_action(hw, vif, ¶ms); 3777*9fb91463SBjoern A. Zeeb if (error != 0) { 3778*9fb91463SBjoern A. Zeeb ic_printf(ic, "%s: mo_ampdu_action returned %d. ni %p rap %p\n", 3779*9fb91463SBjoern A. Zeeb __func__, error, ni, rap); 3780*9fb91463SBjoern A. Zeeb return (error); 3781*9fb91463SBjoern A. Zeeb } 3782*9fb91463SBjoern A. Zeeb IMPROVE_HT("net80211 is missing the error check on return and assumes success"); 3783*9fb91463SBjoern A. Zeeb 3784*9fb91463SBjoern A. Zeeb error = lhw->ic_ampdu_rx_start(ni, rap, baparamset, batimeout, baseqctl); 3785*9fb91463SBjoern A. Zeeb return (error); 3786*9fb91463SBjoern A. Zeeb } 3787*9fb91463SBjoern A. Zeeb 3788*9fb91463SBjoern A. Zeeb static void 3789*9fb91463SBjoern A. Zeeb lkpi_ic_ampdu_rx_stop(struct ieee80211_node *ni, struct ieee80211_rx_ampdu *rap) 3790*9fb91463SBjoern A. Zeeb { 3791*9fb91463SBjoern A. Zeeb struct ieee80211com *ic; 3792*9fb91463SBjoern A. Zeeb struct lkpi_hw *lhw; 3793*9fb91463SBjoern A. Zeeb struct ieee80211_hw *hw; 3794*9fb91463SBjoern A. Zeeb struct ieee80211vap *vap; 3795*9fb91463SBjoern A. Zeeb struct lkpi_vif *lvif; 3796*9fb91463SBjoern A. Zeeb struct ieee80211_vif *vif; 3797*9fb91463SBjoern A. Zeeb struct lkpi_sta *lsta; 3798*9fb91463SBjoern A. Zeeb struct ieee80211_sta *sta; 3799*9fb91463SBjoern A. Zeeb struct ieee80211_ampdu_params params; 3800*9fb91463SBjoern A. Zeeb int error; 3801*9fb91463SBjoern A. Zeeb uint8_t tid; 3802*9fb91463SBjoern A. Zeeb 3803*9fb91463SBjoern A. Zeeb ic = ni->ni_ic; 3804*9fb91463SBjoern A. Zeeb lhw = ic->ic_softc; 3805*9fb91463SBjoern A. Zeeb 3806*9fb91463SBjoern A. Zeeb /* 3807*9fb91463SBjoern A. Zeeb * We should not (cannot) call into mac80211 ops with AMPDU_RX_STOP if 3808*9fb91463SBjoern A. Zeeb * we did not START. Some drivers pass it down to firmware which will 3809*9fb91463SBjoern A. Zeeb * simply barf and net80211 calls ieee80211_ht_node_cleanup() from 3810*9fb91463SBjoern A. Zeeb * ieee80211_ht_node_init() amongst others which will iterate over all 3811*9fb91463SBjoern A. Zeeb * tid and call ic_ampdu_rx_stop() unconditionally. 3812*9fb91463SBjoern A. Zeeb * XXX net80211 should probably be more "gentle" in these cases and 3813*9fb91463SBjoern A. Zeeb * track some state itself. 3814*9fb91463SBjoern A. Zeeb */ 3815*9fb91463SBjoern A. Zeeb if ((rap->rxa_flags & IEEE80211_AGGR_RUNNING) == 0) 3816*9fb91463SBjoern A. Zeeb goto net80211_only; 3817*9fb91463SBjoern A. Zeeb 3818*9fb91463SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 3819*9fb91463SBjoern A. Zeeb vap = ni->ni_vap; 3820*9fb91463SBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 3821*9fb91463SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 3822*9fb91463SBjoern A. Zeeb lsta = ni->ni_drv_data; 3823*9fb91463SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 3824*9fb91463SBjoern A. Zeeb 3825*9fb91463SBjoern A. Zeeb IMPROVE_HT("This really should be passed from ht_recv_action_ba_delba."); 3826*9fb91463SBjoern A. Zeeb for (tid = 0; tid < WME_NUM_TID; tid++) { 3827*9fb91463SBjoern A. Zeeb if (&ni->ni_rx_ampdu[tid] == rap) 3828*9fb91463SBjoern A. Zeeb break; 3829*9fb91463SBjoern A. Zeeb } 3830*9fb91463SBjoern A. Zeeb 3831*9fb91463SBjoern A. Zeeb params.sta = sta; 3832*9fb91463SBjoern A. Zeeb params.action = IEEE80211_AMPDU_RX_STOP; 3833*9fb91463SBjoern A. Zeeb params.buf_size = 0; 3834*9fb91463SBjoern A. Zeeb params.timeout = 0; 3835*9fb91463SBjoern A. Zeeb params.ssn = 0; 3836*9fb91463SBjoern A. Zeeb params.tid = tid; 3837*9fb91463SBjoern A. Zeeb params.amsdu = false; 3838*9fb91463SBjoern A. Zeeb 3839*9fb91463SBjoern A. Zeeb error = lkpi_80211_mo_ampdu_action(hw, vif, ¶ms); 3840*9fb91463SBjoern A. Zeeb if (error != 0) 3841*9fb91463SBjoern A. Zeeb ic_printf(ic, "%s: mo_ampdu_action returned %d. ni %p rap %p\n", 3842*9fb91463SBjoern A. Zeeb __func__, error, ni, rap); 3843*9fb91463SBjoern A. Zeeb 3844*9fb91463SBjoern A. Zeeb net80211_only: 3845*9fb91463SBjoern A. Zeeb lhw->ic_ampdu_rx_stop(ni, rap); 3846*9fb91463SBjoern A. Zeeb } 3847*9fb91463SBjoern A. Zeeb #endif 3848*9fb91463SBjoern A. Zeeb 3849*9fb91463SBjoern A. Zeeb static void 3850*9fb91463SBjoern A. Zeeb lkpi_ic_getradiocaps_ht(struct ieee80211com *ic, struct ieee80211_hw *hw, 3851*9fb91463SBjoern A. Zeeb uint8_t *bands, int *chan_flags, enum nl80211_band band) 3852*9fb91463SBjoern A. Zeeb { 3853*9fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 3854*9fb91463SBjoern A. Zeeb struct ieee80211_sta_ht_cap *ht_cap; 3855*9fb91463SBjoern A. Zeeb 3856*9fb91463SBjoern A. Zeeb ht_cap = &hw->wiphy->bands[band]->ht_cap; 3857*9fb91463SBjoern A. Zeeb if (!ht_cap->ht_supported) 3858*9fb91463SBjoern A. Zeeb return; 3859*9fb91463SBjoern A. Zeeb 3860*9fb91463SBjoern A. Zeeb switch (band) { 3861*9fb91463SBjoern A. Zeeb case NL80211_BAND_2GHZ: 3862*9fb91463SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11NG); 3863*9fb91463SBjoern A. Zeeb break; 3864*9fb91463SBjoern A. Zeeb case NL80211_BAND_5GHZ: 3865*9fb91463SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11NA); 3866*9fb91463SBjoern A. Zeeb break; 3867*9fb91463SBjoern A. Zeeb default: 3868*9fb91463SBjoern A. Zeeb IMPROVE("Unsupported band %d", band); 3869*9fb91463SBjoern A. Zeeb return; 3870*9fb91463SBjoern A. Zeeb } 3871*9fb91463SBjoern A. Zeeb 3872*9fb91463SBjoern A. Zeeb ic->ic_htcaps = IEEE80211_HTC_HT; /* HT operation */ 3873*9fb91463SBjoern A. Zeeb 3874*9fb91463SBjoern A. Zeeb /* 3875*9fb91463SBjoern A. Zeeb * Rather than manually checking each flag and 3876*9fb91463SBjoern A. Zeeb * translating IEEE80211_HT_CAP_ to IEEE80211_HTCAP_, 3877*9fb91463SBjoern A. Zeeb * simply copy the 16bits. 3878*9fb91463SBjoern A. Zeeb */ 3879*9fb91463SBjoern A. Zeeb ic->ic_htcaps |= ht_cap->cap; 3880*9fb91463SBjoern A. Zeeb 3881*9fb91463SBjoern A. Zeeb /* Then deal with the other flags. */ 3882*9fb91463SBjoern A. Zeeb if (ieee80211_hw_check(hw, AMPDU_AGGREGATION)) 3883*9fb91463SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTC_AMPDU; 3884*9fb91463SBjoern A. Zeeb #ifdef __notyet__ 3885*9fb91463SBjoern A. Zeeb if (ieee80211_hw_check(hw, TX_AMSDU)) 3886*9fb91463SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTC_AMSDU; 3887*9fb91463SBjoern A. Zeeb if (ieee80211_hw_check(hw, SUPPORTS_AMSDU_IN_AMPDU)) 3888*9fb91463SBjoern A. Zeeb ic->ic_htcaps |= (IEEE80211_HTC_RX_AMSDU_AMPDU | 3889*9fb91463SBjoern A. Zeeb IEEE80211_HTC_TX_AMSDU_AMPDU); 3890*9fb91463SBjoern A. Zeeb #endif 3891*9fb91463SBjoern A. Zeeb 3892*9fb91463SBjoern A. Zeeb IMPROVE("PS, ampdu_*, ht_cap.mcs.tx_params, ..."); 3893*9fb91463SBjoern A. Zeeb ic->ic_htcaps |= IEEE80211_HTCAP_SMPS_OFF; 3894*9fb91463SBjoern A. Zeeb 3895*9fb91463SBjoern A. Zeeb /* Only add HT40 channels if supported. */ 3896*9fb91463SBjoern A. Zeeb if ((ic->ic_htcaps & IEEE80211_HTCAP_CHWIDTH40) != 0 && 3897*9fb91463SBjoern A. Zeeb chan_flags != NULL) 3898*9fb91463SBjoern A. Zeeb *chan_flags |= NET80211_CBW_FLAG_HT40; 3899*9fb91463SBjoern A. Zeeb #endif 3900*9fb91463SBjoern A. Zeeb } 3901*9fb91463SBjoern A. Zeeb 39026b4cac81SBjoern A. Zeeb static void 39036b4cac81SBjoern A. Zeeb lkpi_ic_getradiocaps(struct ieee80211com *ic, int maxchan, 39046b4cac81SBjoern A. Zeeb int *n, struct ieee80211_channel *c) 39056b4cac81SBjoern A. Zeeb { 39066b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 39076b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 39086b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 39096b4cac81SBjoern A. Zeeb uint8_t bands[IEEE80211_MODE_BYTES]; 39106b4cac81SBjoern A. Zeeb int chan_flags, error, i, nchans; 39116b4cac81SBjoern A. Zeeb 39126b4cac81SBjoern A. Zeeb /* Channels */ 39136b4cac81SBjoern A. Zeeb lhw = ic->ic_softc; 39146b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 39156b4cac81SBjoern A. Zeeb 39166b4cac81SBjoern A. Zeeb /* NL80211_BAND_2GHZ */ 39176b4cac81SBjoern A. Zeeb nchans = 0; 39186b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_2GHZ] != NULL) 39196b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[NL80211_BAND_2GHZ]->n_channels; 39206b4cac81SBjoern A. Zeeb if (nchans > 0) { 39216b4cac81SBjoern A. Zeeb memset(bands, 0, sizeof(bands)); 39226b4cac81SBjoern A. Zeeb chan_flags = 0; 39236b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11B); 39246b4cac81SBjoern A. Zeeb /* XXX-BZ unclear how to check for 11g. */ 3925*9fb91463SBjoern A. Zeeb 3926*9fb91463SBjoern A. Zeeb IMPROVE("the bitrates may have flags?"); 39276b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11G); 3928*9fb91463SBjoern A. Zeeb 3929*9fb91463SBjoern A. Zeeb lkpi_ic_getradiocaps_ht(ic, hw, bands, &chan_flags, 3930*9fb91463SBjoern A. Zeeb NL80211_BAND_2GHZ); 39316b4cac81SBjoern A. Zeeb 39326b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[NL80211_BAND_2GHZ]->channels; 3933cee56e77SBjoern A. Zeeb for (i = 0; i < nchans && *n < maxchan; i++) { 39346b4cac81SBjoern A. Zeeb uint32_t nflags = 0; 39356b4cac81SBjoern A. Zeeb int cflags = chan_flags; 39366b4cac81SBjoern A. Zeeb 39376b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) { 39383f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Skipping disabled chan " 39393f0083c4SBjoern A. Zeeb "[%u/%u/%#x]\n", __func__, 39406b4cac81SBjoern A. Zeeb channels[i].hw_value, 39416b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags); 39426b4cac81SBjoern A. Zeeb continue; 39436b4cac81SBjoern A. Zeeb } 39446b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_IR) 39456b4cac81SBjoern A. Zeeb nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE); 39466b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_RADAR) 39476b4cac81SBjoern A. Zeeb nflags |= IEEE80211_CHAN_DFS; 39486b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ) 39496b4cac81SBjoern A. Zeeb cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80); 39506b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ) 39516b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_VHT80; 39526b4cac81SBjoern A. Zeeb /* XXX how to map the remaining enum ieee80211_channel_flags? */ 39536b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_HT40) 39546b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_HT40; 39556b4cac81SBjoern A. Zeeb 39566b4cac81SBjoern A. Zeeb error = ieee80211_add_channel_cbw(c, maxchan, n, 39576b4cac81SBjoern A. Zeeb channels[i].hw_value, channels[i].center_freq, 39586b4cac81SBjoern A. Zeeb channels[i].max_power, 39595856761fSBjoern A. Zeeb nflags, bands, cflags); 3960cee56e77SBjoern A. Zeeb /* net80211::ENOBUFS: *n >= maxchans */ 3961cee56e77SBjoern A. Zeeb if (error != 0 && error != ENOBUFS) 39623f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Adding chan %u/%u/%#x/%#x/%#x/%#x " 39633f0083c4SBjoern A. Zeeb "returned error %d\n", 39646b4cac81SBjoern A. Zeeb __func__, channels[i].hw_value, 39656b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags, 39666b4cac81SBjoern A. Zeeb nflags, chan_flags, cflags, error); 3967cee56e77SBjoern A. Zeeb if (error != 0) 39686b4cac81SBjoern A. Zeeb break; 39696b4cac81SBjoern A. Zeeb } 39706b4cac81SBjoern A. Zeeb } 39716b4cac81SBjoern A. Zeeb 39726b4cac81SBjoern A. Zeeb /* NL80211_BAND_5GHZ */ 39736b4cac81SBjoern A. Zeeb nchans = 0; 39746b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ] != NULL) 39756b4cac81SBjoern A. Zeeb nchans = hw->wiphy->bands[NL80211_BAND_5GHZ]->n_channels; 39766b4cac81SBjoern A. Zeeb if (nchans > 0) { 39776b4cac81SBjoern A. Zeeb memset(bands, 0, sizeof(bands)); 39786b4cac81SBjoern A. Zeeb chan_flags = 0; 39796b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_11A); 3980*9fb91463SBjoern A. Zeeb 3981*9fb91463SBjoern A. Zeeb lkpi_ic_getradiocaps_ht(ic, hw, bands, &chan_flags, 3982*9fb91463SBjoern A. Zeeb NL80211_BAND_5GHZ); 3983*9fb91463SBjoern A. Zeeb 3984*9fb91463SBjoern A. Zeeb #ifdef LKPI_80211_VHT 39856b4cac81SBjoern A. Zeeb if (hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.vht_supported){ 39866b4cac81SBjoern A. Zeeb 39876b4cac81SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_VHT; 3988562adbe1SBjoern A. Zeeb ic->ic_vht_cap.vht_cap_info = 39896b4cac81SBjoern A. Zeeb hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap; 39906b4cac81SBjoern A. Zeeb 39916b4cac81SBjoern A. Zeeb setbit(bands, IEEE80211_MODE_VHT_5GHZ); 39926b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT80; 39936b4cac81SBjoern A. Zeeb if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160MHZ( 3994562adbe1SBjoern A. Zeeb ic->ic_vht_cap.vht_cap_info)) 39956b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT160; 39966b4cac81SBjoern A. Zeeb if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160_80P80MHZ( 3997562adbe1SBjoern A. Zeeb ic->ic_vht_cap.vht_cap_info)) 39986b4cac81SBjoern A. Zeeb chan_flags |= NET80211_CBW_FLAG_VHT80P80; 39996b4cac81SBjoern A. Zeeb } 40006b4cac81SBjoern A. Zeeb #endif 40016b4cac81SBjoern A. Zeeb 40026b4cac81SBjoern A. Zeeb channels = hw->wiphy->bands[NL80211_BAND_5GHZ]->channels; 4003cee56e77SBjoern A. Zeeb for (i = 0; i < nchans && *n < maxchan; i++) { 40046b4cac81SBjoern A. Zeeb uint32_t nflags = 0; 40056b4cac81SBjoern A. Zeeb int cflags = chan_flags; 40066b4cac81SBjoern A. Zeeb 40076b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) { 40083f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Skipping disabled chan " 40093f0083c4SBjoern A. Zeeb "[%u/%u/%#x]\n", __func__, 40106b4cac81SBjoern A. Zeeb channels[i].hw_value, 40116b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags); 40126b4cac81SBjoern A. Zeeb continue; 40136b4cac81SBjoern A. Zeeb } 40146b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_IR) 40156b4cac81SBjoern A. Zeeb nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE); 40166b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_RADAR) 40176b4cac81SBjoern A. Zeeb nflags |= IEEE80211_CHAN_DFS; 40186b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ) 40196b4cac81SBjoern A. Zeeb cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80); 40206b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ) 40216b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_VHT80; 40226b4cac81SBjoern A. Zeeb /* XXX hwo to map the remaining enum ieee80211_channel_flags? */ 40236b4cac81SBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_NO_HT40) 40246b4cac81SBjoern A. Zeeb cflags &= ~NET80211_CBW_FLAG_HT40; 40256b4cac81SBjoern A. Zeeb 40266b4cac81SBjoern A. Zeeb error = ieee80211_add_channel_cbw(c, maxchan, n, 40276b4cac81SBjoern A. Zeeb channels[i].hw_value, channels[i].center_freq, 40286b4cac81SBjoern A. Zeeb channels[i].max_power, 40295856761fSBjoern A. Zeeb nflags, bands, cflags); 4030cee56e77SBjoern A. Zeeb /* net80211::ENOBUFS: *n >= maxchans */ 4031cee56e77SBjoern A. Zeeb if (error != 0 && error != ENOBUFS) 40323f0083c4SBjoern A. Zeeb ic_printf(ic, "%s: Adding chan %u/%u/%#x/%#x/%#x/%#x " 40333f0083c4SBjoern A. Zeeb "returned error %d\n", 40346b4cac81SBjoern A. Zeeb __func__, channels[i].hw_value, 40356b4cac81SBjoern A. Zeeb channels[i].center_freq, channels[i].flags, 40366b4cac81SBjoern A. Zeeb nflags, chan_flags, cflags, error); 4037cee56e77SBjoern A. Zeeb if (error != 0) 40386b4cac81SBjoern A. Zeeb break; 40396b4cac81SBjoern A. Zeeb } 40406b4cac81SBjoern A. Zeeb } 40416b4cac81SBjoern A. Zeeb } 40426b4cac81SBjoern A. Zeeb 40436b4cac81SBjoern A. Zeeb static void * 40446b4cac81SBjoern A. Zeeb lkpi_ieee80211_ifalloc(void) 40456b4cac81SBjoern A. Zeeb { 40466b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 40476b4cac81SBjoern A. Zeeb 40486b4cac81SBjoern A. Zeeb ic = malloc(sizeof(*ic), M_LKPI80211, M_WAITOK | M_ZERO); 40496b4cac81SBjoern A. Zeeb if (ic == NULL) 40506b4cac81SBjoern A. Zeeb return (NULL); 40516b4cac81SBjoern A. Zeeb 40526b4cac81SBjoern A. Zeeb /* Setting these happens later when we have device information. */ 40536b4cac81SBjoern A. Zeeb ic->ic_softc = NULL; 40546b4cac81SBjoern A. Zeeb ic->ic_name = "linuxkpi"; 40556b4cac81SBjoern A. Zeeb 40566b4cac81SBjoern A. Zeeb return (ic); 40576b4cac81SBjoern A. Zeeb } 40586b4cac81SBjoern A. Zeeb 40596b4cac81SBjoern A. Zeeb struct ieee80211_hw * 40606b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_alloc_hw(size_t priv_len, const struct ieee80211_ops *ops) 40616b4cac81SBjoern A. Zeeb { 40626b4cac81SBjoern A. Zeeb struct ieee80211_hw *hw; 40636b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 40646b4cac81SBjoern A. Zeeb struct wiphy *wiphy; 4065a5ae63edSBjoern A. Zeeb int ac; 40666b4cac81SBjoern A. Zeeb 40676b4cac81SBjoern A. Zeeb /* Get us and the driver data also allocated. */ 40686b4cac81SBjoern A. Zeeb wiphy = wiphy_new(&linuxkpi_mac80211cfgops, sizeof(*lhw) + priv_len); 40696b4cac81SBjoern A. Zeeb if (wiphy == NULL) 40706b4cac81SBjoern A. Zeeb return (NULL); 40716b4cac81SBjoern A. Zeeb 40726b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 40736b4cac81SBjoern A. Zeeb lhw->ops = ops; 4074652e22d3SBjoern A. Zeeb 40758ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK_INIT(lhw); 40768ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK_INIT(lhw); 40778891c455SBjoern A. Zeeb sx_init_flags(&lhw->lvif_sx, "lhw-lvif", SX_RECURSE | SX_DUPOK); 40786b4cac81SBjoern A. Zeeb TAILQ_INIT(&lhw->lvif_head); 4079a5ae63edSBjoern A. Zeeb for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 4080a5ae63edSBjoern A. Zeeb lhw->txq_generation[ac] = 1; 4081a5ae63edSBjoern A. Zeeb TAILQ_INIT(&lhw->scheduled_txqs[ac]); 4082a5ae63edSBjoern A. Zeeb } 40836b4cac81SBjoern A. Zeeb 40846b4cac81SBjoern A. Zeeb /* 40856b4cac81SBjoern A. Zeeb * XXX-BZ TODO make sure there is a "_null" function to all ops 40866b4cac81SBjoern A. Zeeb * not initialized. 40876b4cac81SBjoern A. Zeeb */ 40886b4cac81SBjoern A. Zeeb hw = LHW_TO_HW(lhw); 40896b4cac81SBjoern A. Zeeb hw->wiphy = wiphy; 4090086be6a8SBjoern A. Zeeb hw->conf.flags |= IEEE80211_CONF_IDLE; 40916b4cac81SBjoern A. Zeeb hw->priv = (void *)(lhw + 1); 40926b4cac81SBjoern A. Zeeb 40936b4cac81SBjoern A. Zeeb /* BSD Specific. */ 40946b4cac81SBjoern A. Zeeb lhw->ic = lkpi_ieee80211_ifalloc(); 40956b4cac81SBjoern A. Zeeb if (lhw->ic == NULL) { 40966b4cac81SBjoern A. Zeeb ieee80211_free_hw(hw); 40976b4cac81SBjoern A. Zeeb return (NULL); 40986b4cac81SBjoern A. Zeeb } 40996b4cac81SBjoern A. Zeeb 41006b4cac81SBjoern A. Zeeb IMPROVE(); 41016b4cac81SBjoern A. Zeeb 41026b4cac81SBjoern A. Zeeb return (hw); 41036b4cac81SBjoern A. Zeeb } 41046b4cac81SBjoern A. Zeeb 41056b4cac81SBjoern A. Zeeb void 41066b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iffree(struct ieee80211_hw *hw) 41076b4cac81SBjoern A. Zeeb { 41086b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 41096b4cac81SBjoern A. Zeeb 41106b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 41116b4cac81SBjoern A. Zeeb free(lhw->ic, M_LKPI80211); 41126b4cac81SBjoern A. Zeeb lhw->ic = NULL; 41136b4cac81SBjoern A. Zeeb 41146b4cac81SBjoern A. Zeeb /* Cleanup more of lhw here or in wiphy_free()? */ 41158891c455SBjoern A. Zeeb sx_destroy(&lhw->lvif_sx); 41168ac540d3SBjoern A. Zeeb LKPI_80211_LHW_LOCK_DESTROY(lhw); 41178ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK_DESTROY(lhw); 41186b4cac81SBjoern A. Zeeb IMPROVE(); 41196b4cac81SBjoern A. Zeeb } 41206b4cac81SBjoern A. Zeeb 41216b4cac81SBjoern A. Zeeb void 41226b4cac81SBjoern A. Zeeb linuxkpi_set_ieee80211_dev(struct ieee80211_hw *hw, char *name) 41236b4cac81SBjoern A. Zeeb { 41246b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 41256b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 41266b4cac81SBjoern A. Zeeb 41276b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 41286b4cac81SBjoern A. Zeeb ic = lhw->ic; 41296b4cac81SBjoern A. Zeeb 41306b4cac81SBjoern A. Zeeb /* Now set a proper name before ieee80211_ifattach(). */ 41316b4cac81SBjoern A. Zeeb ic->ic_softc = lhw; 41326b4cac81SBjoern A. Zeeb ic->ic_name = name; 41336b4cac81SBjoern A. Zeeb 41346b4cac81SBjoern A. Zeeb /* XXX-BZ do we also need to set wiphy name? */ 41356b4cac81SBjoern A. Zeeb } 41366b4cac81SBjoern A. Zeeb 41376b4cac81SBjoern A. Zeeb struct ieee80211_hw * 41386b4cac81SBjoern A. Zeeb linuxkpi_wiphy_to_ieee80211_hw(struct wiphy *wiphy) 41396b4cac81SBjoern A. Zeeb { 41406b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 41416b4cac81SBjoern A. Zeeb 41426b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 41436b4cac81SBjoern A. Zeeb return (LHW_TO_HW(lhw)); 41446b4cac81SBjoern A. Zeeb } 41456b4cac81SBjoern A. Zeeb 41466b4cac81SBjoern A. Zeeb static void 41476b4cac81SBjoern A. Zeeb lkpi_radiotap_attach(struct lkpi_hw *lhw) 41486b4cac81SBjoern A. Zeeb { 41496b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 41506b4cac81SBjoern A. Zeeb 41516b4cac81SBjoern A. Zeeb ic = lhw->ic; 41526b4cac81SBjoern A. Zeeb ieee80211_radiotap_attach(ic, 41536b4cac81SBjoern A. Zeeb &lhw->rtap_tx.wt_ihdr, sizeof(lhw->rtap_tx), 41546b4cac81SBjoern A. Zeeb LKPI_RTAP_TX_FLAGS_PRESENT, 41556b4cac81SBjoern A. Zeeb &lhw->rtap_rx.wr_ihdr, sizeof(lhw->rtap_rx), 41566b4cac81SBjoern A. Zeeb LKPI_RTAP_RX_FLAGS_PRESENT); 41576b4cac81SBjoern A. Zeeb } 41586b4cac81SBjoern A. Zeeb 41592e183d99SBjoern A. Zeeb int 41606b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ifattach(struct ieee80211_hw *hw) 41616b4cac81SBjoern A. Zeeb { 41626b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 41636b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 4164c5b96b3eSBjoern A. Zeeb int band, i; 41656b4cac81SBjoern A. Zeeb 41666b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 41676b4cac81SBjoern A. Zeeb ic = lhw->ic; 41686b4cac81SBjoern A. Zeeb 4169652e22d3SBjoern A. Zeeb /* We do it this late as wiphy->dev should be set for the name. */ 4170652e22d3SBjoern A. Zeeb lhw->workq = alloc_ordered_workqueue(wiphy_name(hw->wiphy), 0); 4171652e22d3SBjoern A. Zeeb if (lhw->workq == NULL) 4172652e22d3SBjoern A. Zeeb return (-EAGAIN); 4173652e22d3SBjoern A. Zeeb 41746b4cac81SBjoern A. Zeeb /* XXX-BZ figure this out how they count his... */ 41756b4cac81SBjoern A. Zeeb if (!is_zero_ether_addr(hw->wiphy->perm_addr)) { 41766b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(ic->ic_macaddr, 41776b4cac81SBjoern A. Zeeb hw->wiphy->perm_addr); 41786b4cac81SBjoern A. Zeeb } else if (hw->wiphy->n_addresses > 0) { 41796b4cac81SBjoern A. Zeeb /* We take the first one. */ 41806b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(ic->ic_macaddr, 41816b4cac81SBjoern A. Zeeb hw->wiphy->addresses[0].addr); 41826b4cac81SBjoern A. Zeeb } else { 41836b4cac81SBjoern A. Zeeb ic_printf(ic, "%s: warning, no hardware address!\n", __func__); 41846b4cac81SBjoern A. Zeeb } 41856b4cac81SBjoern A. Zeeb 41863d09d310SBjoern A. Zeeb #ifdef __not_yet__ 41873d09d310SBjoern A. Zeeb /* See comment in lkpi_80211_txq_tx_one(). */ 41886b4cac81SBjoern A. Zeeb ic->ic_headroom = hw->extra_tx_headroom; 41893d09d310SBjoern A. Zeeb #endif 41906b4cac81SBjoern A. Zeeb 41916b4cac81SBjoern A. Zeeb ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ 41926b4cac81SBjoern A. Zeeb ic->ic_opmode = IEEE80211_M_STA; 41936b4cac81SBjoern A. Zeeb 41946b4cac81SBjoern A. Zeeb /* Set device capabilities. */ 41956b4cac81SBjoern A. Zeeb /* XXX-BZ we need to get these from linux80211/drivers and convert. */ 41966b4cac81SBjoern A. Zeeb ic->ic_caps = 41976b4cac81SBjoern A. Zeeb IEEE80211_C_STA | 41986b4cac81SBjoern A. Zeeb IEEE80211_C_MONITOR | 41996b4cac81SBjoern A. Zeeb IEEE80211_C_WPA | /* WPA/RSN */ 42004a67f1dfSBjoern A. Zeeb #ifdef LKPI_80211_WME 42016b4cac81SBjoern A. Zeeb IEEE80211_C_WME | 42024a67f1dfSBjoern A. Zeeb #endif 42036b4cac81SBjoern A. Zeeb #if 0 42046b4cac81SBjoern A. Zeeb IEEE80211_C_PMGT | 42056b4cac81SBjoern A. Zeeb #endif 42066b4cac81SBjoern A. Zeeb IEEE80211_C_SHSLOT | /* short slot time supported */ 42076b4cac81SBjoern A. Zeeb IEEE80211_C_SHPREAMBLE /* short preamble supported */ 42086b4cac81SBjoern A. Zeeb ; 42096b4cac81SBjoern A. Zeeb #if 0 42106b4cac81SBjoern A. Zeeb /* Scanning is a different kind of beast to re-work. */ 42116b4cac81SBjoern A. Zeeb ic->ic_caps |= IEEE80211_C_BGSCAN; 42126b4cac81SBjoern A. Zeeb #endif 4213cc4e78d5SBjoern A. Zeeb if (lhw->ops->hw_scan) { 4214cc4e78d5SBjoern A. Zeeb /* 4215cc4e78d5SBjoern A. Zeeb * Advertise full-offload scanning. 4216cc4e78d5SBjoern A. Zeeb * 4217cc4e78d5SBjoern A. Zeeb * Not limiting to SINGLE_SCAN_ON_ALL_BANDS here as otherwise 4218cc4e78d5SBjoern A. Zeeb * we essentially disable hw_scan for all drivers not setting 4219cc4e78d5SBjoern A. Zeeb * the flag. 4220cc4e78d5SBjoern A. Zeeb */ 42216b4cac81SBjoern A. Zeeb ic->ic_flags_ext |= IEEE80211_FEXT_SCAN_OFFLOAD; 4222a486fbbdSBjoern A. Zeeb lhw->scan_flags |= LKPI_LHW_SCAN_HW; 42236b4cac81SBjoern A. Zeeb } 42246b4cac81SBjoern A. Zeeb 4225527687a9SBjoern A. Zeeb /* 4226527687a9SBjoern A. Zeeb * The wiphy variables report bitmasks of avail antennas. 4227527687a9SBjoern A. Zeeb * (*get_antenna) get the current bitmask sets which can be 4228527687a9SBjoern A. Zeeb * altered by (*set_antenna) for some drivers. 4229527687a9SBjoern A. Zeeb * XXX-BZ will the count alone do us much good long-term in net80211? 4230527687a9SBjoern A. Zeeb */ 4231527687a9SBjoern A. Zeeb if (hw->wiphy->available_antennas_rx || 4232527687a9SBjoern A. Zeeb hw->wiphy->available_antennas_tx) { 4233527687a9SBjoern A. Zeeb uint32_t rxs, txs; 4234527687a9SBjoern A. Zeeb 4235527687a9SBjoern A. Zeeb if (lkpi_80211_mo_get_antenna(hw, &txs, &rxs) == 0) { 4236527687a9SBjoern A. Zeeb ic->ic_rxstream = bitcount32(rxs); 4237527687a9SBjoern A. Zeeb ic->ic_txstream = bitcount32(txs); 4238527687a9SBjoern A. Zeeb } 4239527687a9SBjoern A. Zeeb } 4240527687a9SBjoern A. Zeeb 42416b4cac81SBjoern A. Zeeb ic->ic_cryptocaps = 0; 4242b35f6cd0SBjoern A. Zeeb #ifdef LKPI_80211_HW_CRYPTO 42436b4cac81SBjoern A. Zeeb if (hw->wiphy->n_cipher_suites > 0) { 42446b4cac81SBjoern A. Zeeb for (i = 0; i < hw->wiphy->n_cipher_suites; i++) 42456b4cac81SBjoern A. Zeeb ic->ic_cryptocaps |= lkpi_l80211_to_net80211_cyphers( 42466b4cac81SBjoern A. Zeeb hw->wiphy->cipher_suites[i]); 42476b4cac81SBjoern A. Zeeb } 42486b4cac81SBjoern A. Zeeb #endif 42496b4cac81SBjoern A. Zeeb 42506b4cac81SBjoern A. Zeeb lkpi_ic_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans, 42516b4cac81SBjoern A. Zeeb ic->ic_channels); 42526b4cac81SBjoern A. Zeeb 42536b4cac81SBjoern A. Zeeb ieee80211_ifattach(ic); 42546b4cac81SBjoern A. Zeeb 42556b4cac81SBjoern A. Zeeb ic->ic_update_mcast = lkpi_ic_update_mcast; 42566b4cac81SBjoern A. Zeeb ic->ic_update_promisc = lkpi_ic_update_promisc; 42576b4cac81SBjoern A. Zeeb ic->ic_update_chw = lkpi_ic_update_chw; 42586b4cac81SBjoern A. Zeeb ic->ic_parent = lkpi_ic_parent; 42596b4cac81SBjoern A. Zeeb ic->ic_scan_start = lkpi_ic_scan_start; 42606b4cac81SBjoern A. Zeeb ic->ic_scan_end = lkpi_ic_scan_end; 42616b4cac81SBjoern A. Zeeb ic->ic_set_channel = lkpi_ic_set_channel; 42626b4cac81SBjoern A. Zeeb ic->ic_transmit = lkpi_ic_transmit; 42636b4cac81SBjoern A. Zeeb ic->ic_raw_xmit = lkpi_ic_raw_xmit; 42646b4cac81SBjoern A. Zeeb ic->ic_vap_create = lkpi_ic_vap_create; 42656b4cac81SBjoern A. Zeeb ic->ic_vap_delete = lkpi_ic_vap_delete; 42666b4cac81SBjoern A. Zeeb ic->ic_getradiocaps = lkpi_ic_getradiocaps; 42676b4cac81SBjoern A. Zeeb ic->ic_wme.wme_update = lkpi_ic_wme_update; 42686b4cac81SBjoern A. Zeeb 4269a486fbbdSBjoern A. Zeeb lhw->ic_scan_curchan = ic->ic_scan_curchan; 4270a486fbbdSBjoern A. Zeeb ic->ic_scan_curchan = lkpi_ic_scan_curchan; 4271a486fbbdSBjoern A. Zeeb lhw->ic_scan_mindwell = ic->ic_scan_mindwell; 4272a486fbbdSBjoern A. Zeeb ic->ic_scan_mindwell = lkpi_ic_scan_mindwell; 4273a486fbbdSBjoern A. Zeeb 42746b4cac81SBjoern A. Zeeb lhw->ic_node_alloc = ic->ic_node_alloc; 42756b4cac81SBjoern A. Zeeb ic->ic_node_alloc = lkpi_ic_node_alloc; 42766b4cac81SBjoern A. Zeeb lhw->ic_node_init = ic->ic_node_init; 42776b4cac81SBjoern A. Zeeb ic->ic_node_init = lkpi_ic_node_init; 42786b4cac81SBjoern A. Zeeb lhw->ic_node_cleanup = ic->ic_node_cleanup; 42796b4cac81SBjoern A. Zeeb ic->ic_node_cleanup = lkpi_ic_node_cleanup; 42806b4cac81SBjoern A. Zeeb lhw->ic_node_free = ic->ic_node_free; 42816b4cac81SBjoern A. Zeeb ic->ic_node_free = lkpi_ic_node_free; 42826b4cac81SBjoern A. Zeeb 4283*9fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 4284*9fb91463SBjoern A. Zeeb lhw->ic_recv_action = ic->ic_recv_action; 4285*9fb91463SBjoern A. Zeeb ic->ic_recv_action = lkpi_ic_recv_action; 4286*9fb91463SBjoern A. Zeeb lhw->ic_send_action = ic->ic_send_action; 4287*9fb91463SBjoern A. Zeeb ic->ic_send_action = lkpi_ic_send_action; 4288*9fb91463SBjoern A. Zeeb 4289*9fb91463SBjoern A. Zeeb lhw->ic_ampdu_enable = ic->ic_ampdu_enable; 4290*9fb91463SBjoern A. Zeeb ic->ic_ampdu_enable = lkpi_ic_ampdu_enable; 4291*9fb91463SBjoern A. Zeeb 4292*9fb91463SBjoern A. Zeeb lhw->ic_addba_request = ic->ic_addba_request; 4293*9fb91463SBjoern A. Zeeb ic->ic_addba_request = lkpi_ic_addba_request; 4294*9fb91463SBjoern A. Zeeb lhw->ic_addba_response = ic->ic_addba_response; 4295*9fb91463SBjoern A. Zeeb ic->ic_addba_response = lkpi_ic_addba_response; 4296*9fb91463SBjoern A. Zeeb lhw->ic_addba_stop = ic->ic_addba_stop; 4297*9fb91463SBjoern A. Zeeb ic->ic_addba_stop = lkpi_ic_addba_stop; 4298*9fb91463SBjoern A. Zeeb lhw->ic_addba_response_timeout = ic->ic_addba_response_timeout; 4299*9fb91463SBjoern A. Zeeb ic->ic_addba_response_timeout = lkpi_ic_addba_response_timeout; 4300*9fb91463SBjoern A. Zeeb 4301*9fb91463SBjoern A. Zeeb lhw->ic_bar_response = ic->ic_bar_response; 4302*9fb91463SBjoern A. Zeeb ic->ic_bar_response = lkpi_ic_bar_response; 4303*9fb91463SBjoern A. Zeeb 4304*9fb91463SBjoern A. Zeeb lhw->ic_ampdu_rx_start = ic->ic_ampdu_rx_start; 4305*9fb91463SBjoern A. Zeeb ic->ic_ampdu_rx_start = lkpi_ic_ampdu_rx_start; 4306*9fb91463SBjoern A. Zeeb lhw->ic_ampdu_rx_stop = ic->ic_ampdu_rx_stop; 4307*9fb91463SBjoern A. Zeeb ic->ic_ampdu_rx_stop = lkpi_ic_ampdu_rx_stop; 4308*9fb91463SBjoern A. Zeeb #endif 4309*9fb91463SBjoern A. Zeeb 43106b4cac81SBjoern A. Zeeb lkpi_radiotap_attach(lhw); 43116b4cac81SBjoern A. Zeeb 4312c5b96b3eSBjoern A. Zeeb /* 4313c5b96b3eSBjoern A. Zeeb * Assign the first possible channel for now; seems Realtek drivers 4314c5b96b3eSBjoern A. Zeeb * expect one. 4315d9945d78SBjoern A. Zeeb * Also remember the amount of bands we support and the most rates 4316d9945d78SBjoern A. Zeeb * in any band so we can scale [(ext) sup rates] IE(s) accordingly. 4317c5b96b3eSBjoern A. Zeeb */ 4318d9945d78SBjoern A. Zeeb lhw->supbands = lhw->max_rates = 0; 4319f454a4a1SBjoern A. Zeeb for (band = 0; band < NUM_NL80211_BANDS; band++) { 4320c5b96b3eSBjoern A. Zeeb struct ieee80211_supported_band *supband; 4321c5b96b3eSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *channels; 4322c5b96b3eSBjoern A. Zeeb 4323c5b96b3eSBjoern A. Zeeb supband = hw->wiphy->bands[band]; 4324c5b96b3eSBjoern A. Zeeb if (supband == NULL || supband->n_channels == 0) 4325c5b96b3eSBjoern A. Zeeb continue; 4326c5b96b3eSBjoern A. Zeeb 4327d9945d78SBjoern A. Zeeb lhw->supbands++; 4328d9945d78SBjoern A. Zeeb lhw->max_rates = max(lhw->max_rates, supband->n_bitrates); 4329d9945d78SBjoern A. Zeeb 4330f454a4a1SBjoern A. Zeeb /* If we have a channel, we need to keep counting supbands. */ 4331f454a4a1SBjoern A. Zeeb if (hw->conf.chandef.chan != NULL) 4332f454a4a1SBjoern A. Zeeb continue; 4333f454a4a1SBjoern A. Zeeb 4334c5b96b3eSBjoern A. Zeeb channels = supband->channels; 4335c5b96b3eSBjoern A. Zeeb for (i = 0; i < supband->n_channels; i++) { 4336c5b96b3eSBjoern A. Zeeb 4337c5b96b3eSBjoern A. Zeeb if (channels[i].flags & IEEE80211_CHAN_DISABLED) 4338c5b96b3eSBjoern A. Zeeb continue; 4339c5b96b3eSBjoern A. Zeeb 43404a07abdeSBjoern A. Zeeb cfg80211_chandef_create(&hw->conf.chandef, &channels[i], 4341*9fb91463SBjoern A. Zeeb #ifdef LKPI_80211_HT 4342*9fb91463SBjoern A. Zeeb (ic->ic_htcaps & IEEE80211_HTC_HT) ? 0 : 4343*9fb91463SBjoern A. Zeeb #endif 4344c5b96b3eSBjoern A. Zeeb NL80211_CHAN_NO_HT); 4345c5b96b3eSBjoern A. Zeeb break; 4346c5b96b3eSBjoern A. Zeeb } 4347c5b96b3eSBjoern A. Zeeb } 4348c5b96b3eSBjoern A. Zeeb 4349d9945d78SBjoern A. Zeeb IMPROVE("see net80211::ieee80211_chan_init vs. wiphy->bands[].bitrates possibly in lkpi_ic_getradiocaps?"); 4350d9945d78SBjoern A. Zeeb 4351d9945d78SBjoern A. Zeeb /* Make sure we do not support more than net80211 is willing to take. */ 4352d9945d78SBjoern A. Zeeb if (lhw->max_rates > IEEE80211_RATE_MAXSIZE) { 4353d9945d78SBjoern A. Zeeb ic_printf(ic, "%s: limiting max_rates %d to %d!\n", __func__, 4354d9945d78SBjoern A. Zeeb lhw->max_rates, IEEE80211_RATE_MAXSIZE); 4355d9945d78SBjoern A. Zeeb lhw->max_rates = IEEE80211_RATE_MAXSIZE; 4356d9945d78SBjoern A. Zeeb } 4357d9945d78SBjoern A. Zeeb 4358d9945d78SBjoern A. Zeeb /* 4359d9945d78SBjoern A. Zeeb * The maximum supported bitrates on any band + size for 4360d9945d78SBjoern A. Zeeb * DSSS Parameter Set give our per-band IE size. 4361d9945d78SBjoern A. Zeeb * SSID is the responsibility of the driver and goes on the side. 4362d9945d78SBjoern A. Zeeb * The user specified bits coming from the vap go into the 4363d9945d78SBjoern A. Zeeb * "common ies" fields. 4364d9945d78SBjoern A. Zeeb */ 4365d9945d78SBjoern A. Zeeb lhw->scan_ie_len = 2 + IEEE80211_RATE_SIZE; 4366d9945d78SBjoern A. Zeeb if (lhw->max_rates > IEEE80211_RATE_SIZE) 4367d9945d78SBjoern A. Zeeb lhw->scan_ie_len += 2 + (lhw->max_rates - IEEE80211_RATE_SIZE); 436878ca45dfSBjoern A. Zeeb 436978ca45dfSBjoern A. Zeeb if (hw->wiphy->features & NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) { 4370d9945d78SBjoern A. Zeeb /* 437178ca45dfSBjoern A. Zeeb * net80211 does not seem to support the DSSS Parameter Set but 437278ca45dfSBjoern A. Zeeb * some of the drivers insert it so calculate the extra fixed 437378ca45dfSBjoern A. Zeeb * space in. 4374d9945d78SBjoern A. Zeeb */ 4375d9945d78SBjoern A. Zeeb lhw->scan_ie_len += 2 + 1; 437678ca45dfSBjoern A. Zeeb } 4377d9945d78SBjoern A. Zeeb 4378*9fb91463SBjoern A. Zeeb #if defined(LKPI_80211_HT) 4379*9fb91463SBjoern A. Zeeb if ((ic->ic_htcaps & IEEE80211_HTC_HT) != 0) 4380*9fb91463SBjoern A. Zeeb lhw->scan_ie_len += sizeof(struct ieee80211_ie_htcap); 4381*9fb91463SBjoern A. Zeeb #endif 4382*9fb91463SBjoern A. Zeeb #if defined(LKPI_80211_VHT) 4383*9fb91463SBjoern A. Zeeb if ((ic->ic_flags_ext & IEEE80211_FEXT_VHT) != 0) 4384*9fb91463SBjoern A. Zeeb lhw->scan_ie_len += 2 + sizeof(struct ieee80211_vht_cap); 4385*9fb91463SBjoern A. Zeeb #endif 4386*9fb91463SBjoern A. Zeeb 4387d9945d78SBjoern A. Zeeb /* Reduce the max_scan_ie_len "left" by the amount we consume already. */ 438878ca45dfSBjoern A. Zeeb if (hw->wiphy->max_scan_ie_len > 0) { 438978ca45dfSBjoern A. Zeeb if (lhw->scan_ie_len > hw->wiphy->max_scan_ie_len) 439078ca45dfSBjoern A. Zeeb goto err; 4391d9945d78SBjoern A. Zeeb hw->wiphy->max_scan_ie_len -= lhw->scan_ie_len; 439278ca45dfSBjoern A. Zeeb } 4393d9945d78SBjoern A. Zeeb 43946b4cac81SBjoern A. Zeeb if (bootverbose) 43956b4cac81SBjoern A. Zeeb ieee80211_announce(ic); 43962e183d99SBjoern A. Zeeb 43972e183d99SBjoern A. Zeeb return (0); 439878ca45dfSBjoern A. Zeeb err: 439978ca45dfSBjoern A. Zeeb IMPROVE("TODO FIXME CLEANUP"); 440078ca45dfSBjoern A. Zeeb return (-EAGAIN); 44016b4cac81SBjoern A. Zeeb } 44026b4cac81SBjoern A. Zeeb 44036b4cac81SBjoern A. Zeeb void 44046b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_ifdetach(struct ieee80211_hw *hw) 44056b4cac81SBjoern A. Zeeb { 44066b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 44076b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 44086b4cac81SBjoern A. Zeeb 44096b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 44106b4cac81SBjoern A. Zeeb ic = lhw->ic; 44116b4cac81SBjoern A. Zeeb ieee80211_ifdetach(ic); 44126b4cac81SBjoern A. Zeeb } 44136b4cac81SBjoern A. Zeeb 44146b4cac81SBjoern A. Zeeb void 44156b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_interfaces(struct ieee80211_hw *hw, 44166b4cac81SBjoern A. Zeeb enum ieee80211_iface_iter flags, 44176b4cac81SBjoern A. Zeeb void(*iterfunc)(void *, uint8_t *, struct ieee80211_vif *), 44186b4cac81SBjoern A. Zeeb void *arg) 44196b4cac81SBjoern A. Zeeb { 44206b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 44216b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 44226b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 442361a68e50SBjoern A. Zeeb bool active, atomic, nin_drv; 44246b4cac81SBjoern A. Zeeb 44256b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 44266b4cac81SBjoern A. Zeeb 44276b4cac81SBjoern A. Zeeb if (flags & ~(IEEE80211_IFACE_ITER_NORMAL| 44286b4cac81SBjoern A. Zeeb IEEE80211_IFACE_ITER_RESUME_ALL| 442961a68e50SBjoern A. Zeeb IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER| 4430adff403fSBjoern A. Zeeb IEEE80211_IFACE_ITER_ACTIVE|IEEE80211_IFACE_ITER__ATOMIC)) { 44316b4cac81SBjoern A. Zeeb ic_printf(lhw->ic, "XXX TODO %s flags(%#x) not yet supported.\n", 44326b4cac81SBjoern A. Zeeb __func__, flags); 44336b4cac81SBjoern A. Zeeb } 44346b4cac81SBjoern A. Zeeb 4435adff403fSBjoern A. Zeeb active = (flags & IEEE80211_IFACE_ITER_ACTIVE) != 0; 44366b4cac81SBjoern A. Zeeb atomic = (flags & IEEE80211_IFACE_ITER__ATOMIC) != 0; 443761a68e50SBjoern A. Zeeb nin_drv = (flags & IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER) != 0; 44386b4cac81SBjoern A. Zeeb 44396b4cac81SBjoern A. Zeeb if (atomic) 44408891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 44416b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 44426b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 44436b4cac81SBjoern A. Zeeb 44446b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 44456b4cac81SBjoern A. Zeeb 44466b4cac81SBjoern A. Zeeb /* 44476b4cac81SBjoern A. Zeeb * If we want "active" interfaces, we need to distinguish on 44486b4cac81SBjoern A. Zeeb * whether the driver knows about them or not to be able to 44496b4cac81SBjoern A. Zeeb * handle the "resume" case correctly. Skip the ones the 44506b4cac81SBjoern A. Zeeb * driver does not know about. 44516b4cac81SBjoern A. Zeeb */ 44526b4cac81SBjoern A. Zeeb if (active && !lvif->added_to_drv && 44536b4cac81SBjoern A. Zeeb (flags & IEEE80211_IFACE_ITER_RESUME_ALL) != 0) 44546b4cac81SBjoern A. Zeeb continue; 44556b4cac81SBjoern A. Zeeb 44566b4cac81SBjoern A. Zeeb /* 445761a68e50SBjoern A. Zeeb * If we shall skip interfaces not added to the driver do so 445861a68e50SBjoern A. Zeeb * if we haven't yet. 445961a68e50SBjoern A. Zeeb */ 446061a68e50SBjoern A. Zeeb if (nin_drv && !lvif->added_to_drv) 446161a68e50SBjoern A. Zeeb continue; 446261a68e50SBjoern A. Zeeb 446361a68e50SBjoern A. Zeeb /* 44646b4cac81SBjoern A. Zeeb * Run the iterator function if we are either not asking 44656b4cac81SBjoern A. Zeeb * asking for active only or if the VAP is "running". 44666b4cac81SBjoern A. Zeeb */ 44676b4cac81SBjoern A. Zeeb /* XXX-BZ probably should have state in the lvif as well. */ 44686b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 44696b4cac81SBjoern A. Zeeb if (!active || (vap->iv_state != IEEE80211_S_INIT)) 44706b4cac81SBjoern A. Zeeb iterfunc(arg, vif->addr, vif); 44716b4cac81SBjoern A. Zeeb } 44726b4cac81SBjoern A. Zeeb if (atomic) 44738891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 44746b4cac81SBjoern A. Zeeb } 44756b4cac81SBjoern A. Zeeb 44766b4cac81SBjoern A. Zeeb void 44776b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_keys(struct ieee80211_hw *hw, 44786b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif, 44796b4cac81SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_vif *, 44806b4cac81SBjoern A. Zeeb struct ieee80211_sta *, struct ieee80211_key_conf *, void *), 44816b4cac81SBjoern A. Zeeb void *arg) 44826b4cac81SBjoern A. Zeeb { 44836b4cac81SBjoern A. Zeeb 44846b4cac81SBjoern A. Zeeb UNIMPLEMENTED; 44856b4cac81SBjoern A. Zeeb } 44866b4cac81SBjoern A. Zeeb 44876b4cac81SBjoern A. Zeeb void 44886b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_chan_contexts(struct ieee80211_hw *hw, 44896b4cac81SBjoern A. Zeeb void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_chanctx_conf *, 44906b4cac81SBjoern A. Zeeb void *), 44916b4cac81SBjoern A. Zeeb void *arg) 44926b4cac81SBjoern A. Zeeb { 4493c5e25798SBjoern A. Zeeb struct lkpi_hw *lhw; 4494c5e25798SBjoern A. Zeeb struct lkpi_vif *lvif; 4495c5e25798SBjoern A. Zeeb struct ieee80211_vif *vif; 4496c5e25798SBjoern A. Zeeb struct lkpi_chanctx *lchanctx; 44976b4cac81SBjoern A. Zeeb 4498c5e25798SBjoern A. Zeeb KASSERT(hw != NULL && iterfunc != NULL, 4499c5e25798SBjoern A. Zeeb ("%s: hw %p iterfunc %p arg %p\n", __func__, hw, iterfunc, arg)); 4500c5e25798SBjoern A. Zeeb 4501c5e25798SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 4502c5e25798SBjoern A. Zeeb 4503c5e25798SBjoern A. Zeeb IMPROVE("lchanctx should be its own list somewhere"); 4504c5e25798SBjoern A. Zeeb 4505c5e25798SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 4506c5e25798SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 4507c5e25798SBjoern A. Zeeb 4508c5e25798SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 4509c5e25798SBjoern A. Zeeb if (vif->chanctx_conf == NULL) 4510c5e25798SBjoern A. Zeeb continue; 4511c5e25798SBjoern A. Zeeb 4512c5e25798SBjoern A. Zeeb lchanctx = CHANCTX_CONF_TO_LCHANCTX(vif->chanctx_conf); 4513c5e25798SBjoern A. Zeeb if (!lchanctx->added_to_drv) 4514c5e25798SBjoern A. Zeeb continue; 4515c5e25798SBjoern A. Zeeb 4516c5e25798SBjoern A. Zeeb iterfunc(hw, &lchanctx->conf, arg); 4517c5e25798SBjoern A. Zeeb } 4518c5e25798SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 45196b4cac81SBjoern A. Zeeb } 45206b4cac81SBjoern A. Zeeb 45216b4cac81SBjoern A. Zeeb void 45226b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_iterate_stations_atomic(struct ieee80211_hw *hw, 45236b4cac81SBjoern A. Zeeb void (*iterfunc)(void *, struct ieee80211_sta *), void *arg) 45246b4cac81SBjoern A. Zeeb { 45256b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 45266b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 45276b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 45286b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 45296b4cac81SBjoern A. Zeeb 45306b4cac81SBjoern A. Zeeb KASSERT(hw != NULL && iterfunc != NULL, 45316b4cac81SBjoern A. Zeeb ("%s: hw %p iterfunc %p arg %p\n", __func__, hw, iterfunc, arg)); 45326b4cac81SBjoern A. Zeeb 45336b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 45346b4cac81SBjoern A. Zeeb 45358891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 45366b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 45376b4cac81SBjoern A. Zeeb 45386b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 45396b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lsta, &lvif->lsta_head, lsta_entry) { 45406b4cac81SBjoern A. Zeeb if (!lsta->added_to_drv) 45416b4cac81SBjoern A. Zeeb continue; 45426b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 45436b4cac81SBjoern A. Zeeb iterfunc(arg, sta); 45446b4cac81SBjoern A. Zeeb } 45456b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 45466b4cac81SBjoern A. Zeeb } 45478891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 45486b4cac81SBjoern A. Zeeb } 45496b4cac81SBjoern A. Zeeb 4550673d62fcSBjoern A. Zeeb struct linuxkpi_ieee80211_regdomain * 4551673d62fcSBjoern A. Zeeb lkpi_get_linuxkpi_ieee80211_regdomain(size_t n) 4552673d62fcSBjoern A. Zeeb { 4553673d62fcSBjoern A. Zeeb struct linuxkpi_ieee80211_regdomain *regd; 4554673d62fcSBjoern A. Zeeb 4555673d62fcSBjoern A. Zeeb regd = kzalloc(sizeof(*regd) + n * sizeof(struct ieee80211_reg_rule), 4556673d62fcSBjoern A. Zeeb GFP_KERNEL); 4557673d62fcSBjoern A. Zeeb return (regd); 4558673d62fcSBjoern A. Zeeb } 4559673d62fcSBjoern A. Zeeb 45606b4cac81SBjoern A. Zeeb int 45616b4cac81SBjoern A. Zeeb linuxkpi_regulatory_set_wiphy_regd_sync(struct wiphy *wiphy, 45626b4cac81SBjoern A. Zeeb struct linuxkpi_ieee80211_regdomain *regd) 45636b4cac81SBjoern A. Zeeb { 45646b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 45656b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 45666b4cac81SBjoern A. Zeeb struct ieee80211_regdomain *rd; 45676b4cac81SBjoern A. Zeeb 45686b4cac81SBjoern A. Zeeb lhw = wiphy_priv(wiphy); 45696b4cac81SBjoern A. Zeeb ic = lhw->ic; 45706b4cac81SBjoern A. Zeeb 45716b4cac81SBjoern A. Zeeb rd = &ic->ic_regdomain; 45726b4cac81SBjoern A. Zeeb if (rd->isocc[0] == '\0') { 45736b4cac81SBjoern A. Zeeb rd->isocc[0] = regd->alpha2[0]; 45746b4cac81SBjoern A. Zeeb rd->isocc[1] = regd->alpha2[1]; 45756b4cac81SBjoern A. Zeeb } 45766b4cac81SBjoern A. Zeeb 45776b4cac81SBjoern A. Zeeb TODO(); 45786b4cac81SBjoern A. Zeeb /* XXX-BZ finish the rest. */ 45796b4cac81SBjoern A. Zeeb 45806b4cac81SBjoern A. Zeeb return (0); 45816b4cac81SBjoern A. Zeeb } 45826b4cac81SBjoern A. Zeeb 45836b4cac81SBjoern A. Zeeb void 45846b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_scan_completed(struct ieee80211_hw *hw, 45856b4cac81SBjoern A. Zeeb struct cfg80211_scan_info *info) 45866b4cac81SBjoern A. Zeeb { 45876b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 45886b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 45896b4cac81SBjoern A. Zeeb struct ieee80211_scan_state *ss; 45906b4cac81SBjoern A. Zeeb 45916b4cac81SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 45926b4cac81SBjoern A. Zeeb ic = lhw->ic; 45936b4cac81SBjoern A. Zeeb ss = ic->ic_scan; 45946b4cac81SBjoern A. Zeeb 45956b4cac81SBjoern A. Zeeb ieee80211_scan_done(ss->ss_vap); 45966b4cac81SBjoern A. Zeeb 45978ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_LOCK(lhw); 45986b4cac81SBjoern A. Zeeb free(lhw->hw_req, M_LKPI80211); 45996b4cac81SBjoern A. Zeeb lhw->hw_req = NULL; 4600a486fbbdSBjoern A. Zeeb lhw->scan_flags &= ~LKPI_LHW_SCAN_RUNNING; 46016b4cac81SBjoern A. Zeeb wakeup(lhw); 46028ac540d3SBjoern A. Zeeb LKPI_80211_LHW_SCAN_UNLOCK(lhw); 46036b4cac81SBjoern A. Zeeb 46046b4cac81SBjoern A. Zeeb return; 46056b4cac81SBjoern A. Zeeb } 46066b4cac81SBjoern A. Zeeb 4607e30e05d3SBjoern A. Zeeb /* For %list see comment towards the end of the function. */ 46086b4cac81SBjoern A. Zeeb void 46096b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb, 4610e30e05d3SBjoern A. Zeeb struct ieee80211_sta *sta, struct napi_struct *napi __unused, 4611e30e05d3SBjoern A. Zeeb struct list_head *list __unused) 46126b4cac81SBjoern A. Zeeb { 46136b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 46146b4cac81SBjoern A. Zeeb struct ieee80211com *ic; 46156b4cac81SBjoern A. Zeeb struct mbuf *m; 46166b4cac81SBjoern A. Zeeb struct skb_shared_info *shinfo; 46176b4cac81SBjoern A. Zeeb struct ieee80211_rx_status *rx_status; 46186b4cac81SBjoern A. Zeeb struct ieee80211_rx_stats rx_stats; 46196b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 46206b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 46216b4cac81SBjoern A. Zeeb struct ieee80211_hdr *hdr; 46226b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 46239d9ba2b7SBjoern A. Zeeb int i, offset, ok; 4624170acccfSBjoern A. Zeeb int8_t rssi; 4625c0cadd99SBjoern A. Zeeb bool is_beacon; 46266b4cac81SBjoern A. Zeeb 46276b4cac81SBjoern A. Zeeb if (skb->len < 2) { 46286b4cac81SBjoern A. Zeeb /* Need 80211 stats here. */ 46296b4cac81SBjoern A. Zeeb IMPROVE(); 46306b4cac81SBjoern A. Zeeb goto err; 46316b4cac81SBjoern A. Zeeb } 46326b4cac81SBjoern A. Zeeb 46336b4cac81SBjoern A. Zeeb /* 46346b4cac81SBjoern A. Zeeb * For now do the data copy; we can later improve things. Might even 46356b4cac81SBjoern A. Zeeb * have an mbuf backing the skb data then? 46366b4cac81SBjoern A. Zeeb */ 46376b4cac81SBjoern A. Zeeb m = m_get2(skb->len, M_NOWAIT, MT_DATA, M_PKTHDR); 46386b4cac81SBjoern A. Zeeb if (m == NULL) 46396b4cac81SBjoern A. Zeeb goto err; 46406b4cac81SBjoern A. Zeeb m_copyback(m, 0, skb->tail - skb->data, skb->data); 46416b4cac81SBjoern A. Zeeb 46426b4cac81SBjoern A. Zeeb shinfo = skb_shinfo(skb); 46436b4cac81SBjoern A. Zeeb offset = m->m_len; 46446b4cac81SBjoern A. Zeeb for (i = 0; i < shinfo->nr_frags; i++) { 46456b4cac81SBjoern A. Zeeb m_copyback(m, offset, shinfo->frags[i].size, 46466b4cac81SBjoern A. Zeeb (uint8_t *)linux_page_address(shinfo->frags[i].page) + 46476b4cac81SBjoern A. Zeeb shinfo->frags[i].offset); 46486b4cac81SBjoern A. Zeeb offset += shinfo->frags[i].size; 46496b4cac81SBjoern A. Zeeb } 46506b4cac81SBjoern A. Zeeb 46516b4cac81SBjoern A. Zeeb rx_status = IEEE80211_SKB_RXCB(skb); 46526b4cac81SBjoern A. Zeeb 46536b4cac81SBjoern A. Zeeb hdr = (void *)skb->data; 4654c0cadd99SBjoern A. Zeeb is_beacon = ieee80211_is_beacon(hdr->frame_control); 4655c0cadd99SBjoern A. Zeeb 4656c0cadd99SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 46579d9ba2b7SBjoern A. Zeeb if (is_beacon && (linuxkpi_debug_80211 & D80211_TRACE_RX_BEACONS) == 0) 46586b4cac81SBjoern A. Zeeb goto no_trace_beacons; 46596b4cac81SBjoern A. Zeeb 46609d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 46616b4cac81SBjoern A. Zeeb printf("TRACE-RX: %s: skb %p a/l/d/t-len (%u/%u/%u/%u) " 4662c0cadd99SBjoern A. Zeeb "h %p d %p t %p e %p sh %p (%u) m %p plen %u len %u%s\n", 46636b4cac81SBjoern A. Zeeb __func__, skb, skb->_alloc_len, skb->len, skb->data_len, 46646b4cac81SBjoern A. Zeeb skb->truesize, skb->head, skb->data, skb->tail, skb->end, 46656b4cac81SBjoern A. Zeeb shinfo, shinfo->nr_frags, 4666c0cadd99SBjoern A. Zeeb m, m->m_pkthdr.len, m->m_len, is_beacon ? " beacon" : ""); 46676b4cac81SBjoern A. Zeeb 46689d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX_DUMP) 46696b4cac81SBjoern A. Zeeb hexdump(mtod(m, const void *), m->m_len, "RX (raw) ", 0); 46706b4cac81SBjoern A. Zeeb 46716b4cac81SBjoern A. Zeeb /* Implement a dump_rxcb() !!! */ 46729d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 4673c8dafefaSBjoern A. Zeeb printf("TRACE %s: RXCB: %ju %ju %u, %#0x, %u, %#0x, %#0x, " 467460970a32SBjoern A. Zeeb "%u band %u, %u { %d %d %d %d }, %d, %#x %#x %#x %#x %u %u %u\n", 46756b4cac81SBjoern A. Zeeb __func__, 4676c8dafefaSBjoern A. Zeeb (uintmax_t)rx_status->boottime_ns, 4677c8dafefaSBjoern A. Zeeb (uintmax_t)rx_status->mactime, 46786b4cac81SBjoern A. Zeeb rx_status->device_timestamp, 46796b4cac81SBjoern A. Zeeb rx_status->flag, 46806b4cac81SBjoern A. Zeeb rx_status->freq, 46816b4cac81SBjoern A. Zeeb rx_status->bw, 46826b4cac81SBjoern A. Zeeb rx_status->encoding, 46836b4cac81SBjoern A. Zeeb rx_status->ampdu_reference, 46846b4cac81SBjoern A. Zeeb rx_status->band, 46856b4cac81SBjoern A. Zeeb rx_status->chains, 46866b4cac81SBjoern A. Zeeb rx_status->chain_signal[0], 46876b4cac81SBjoern A. Zeeb rx_status->chain_signal[1], 46886b4cac81SBjoern A. Zeeb rx_status->chain_signal[2], 468960970a32SBjoern A. Zeeb rx_status->chain_signal[3], 46906b4cac81SBjoern A. Zeeb rx_status->signal, 46916b4cac81SBjoern A. Zeeb rx_status->enc_flags, 46926b4cac81SBjoern A. Zeeb rx_status->he_dcm, 46936b4cac81SBjoern A. Zeeb rx_status->he_gi, 46946b4cac81SBjoern A. Zeeb rx_status->he_ru, 46956b4cac81SBjoern A. Zeeb rx_status->zero_length_psdu_type, 46966b4cac81SBjoern A. Zeeb rx_status->nss, 46976b4cac81SBjoern A. Zeeb rx_status->rate_idx); 46986b4cac81SBjoern A. Zeeb no_trace_beacons: 46996b4cac81SBjoern A. Zeeb #endif 47006b4cac81SBjoern A. Zeeb 47016b4cac81SBjoern A. Zeeb memset(&rx_stats, 0, sizeof(rx_stats)); 47026b4cac81SBjoern A. Zeeb rx_stats.r_flags = IEEE80211_R_NF | IEEE80211_R_RSSI; 470360970a32SBjoern A. Zeeb /* XXX-BZ correct hardcoded rssi and noise floor, how? survey? */ 470460970a32SBjoern A. Zeeb rx_stats.c_nf = -96; 47056b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, SIGNAL_DBM) && 47066b4cac81SBjoern A. Zeeb !(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL)) 4707170acccfSBjoern A. Zeeb rssi = rx_status->signal; 47086b4cac81SBjoern A. Zeeb else 4709170acccfSBjoern A. Zeeb rssi = rx_stats.c_nf; 4710170acccfSBjoern A. Zeeb /* 4711170acccfSBjoern A. Zeeb * net80211 signal strength data are in .5 dBm units relative to 4712170acccfSBjoern A. Zeeb * the current noise floor (see comment in ieee80211_node.h). 4713170acccfSBjoern A. Zeeb */ 4714170acccfSBjoern A. Zeeb rssi -= rx_stats.c_nf; 4715170acccfSBjoern A. Zeeb rx_stats.c_rssi = rssi * 2; 47166b4cac81SBjoern A. Zeeb rx_stats.r_flags |= IEEE80211_R_BAND; 47176b4cac81SBjoern A. Zeeb rx_stats.c_band = 47186b4cac81SBjoern A. Zeeb lkpi_nl80211_band_to_net80211_band(rx_status->band); 47196b4cac81SBjoern A. Zeeb rx_stats.r_flags |= IEEE80211_R_FREQ | IEEE80211_R_IEEE; 47206b4cac81SBjoern A. Zeeb rx_stats.c_freq = rx_status->freq; 47216b4cac81SBjoern A. Zeeb rx_stats.c_ieee = ieee80211_mhz2ieee(rx_stats.c_freq, rx_stats.c_band); 47226b4cac81SBjoern A. Zeeb 47236b4cac81SBjoern A. Zeeb /* XXX (*sta_statistics)() to get to some of that? */ 47246b4cac81SBjoern A. Zeeb /* XXX-BZ dump the FreeBSD version of rx_stats as well! */ 47256b4cac81SBjoern A. Zeeb 47266b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 47276b4cac81SBjoern A. Zeeb ic = lhw->ic; 47286b4cac81SBjoern A. Zeeb 47296b4cac81SBjoern A. Zeeb ok = ieee80211_add_rx_params(m, &rx_stats); 47306b4cac81SBjoern A. Zeeb if (ok == 0) { 4731dbc06dd9SBjoern A. Zeeb m_freem(m); 47326b4cac81SBjoern A. Zeeb counter_u64_add(ic->ic_ierrors, 1); 47336b4cac81SBjoern A. Zeeb goto err; 47346b4cac81SBjoern A. Zeeb } 47356b4cac81SBjoern A. Zeeb 47366b4cac81SBjoern A. Zeeb if (sta != NULL) { 47376b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 47386b4cac81SBjoern A. Zeeb ni = ieee80211_ref_node(lsta->ni); 47396b4cac81SBjoern A. Zeeb } else { 4740c8dafefaSBjoern A. Zeeb struct ieee80211_frame_min *wh; 4741c8dafefaSBjoern A. Zeeb 47426b4cac81SBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame_min *); 47436b4cac81SBjoern A. Zeeb ni = ieee80211_find_rxnode(ic, wh); 47446b4cac81SBjoern A. Zeeb if (ni != NULL) 47456b4cac81SBjoern A. Zeeb lsta = ni->ni_drv_data; 47466b4cac81SBjoern A. Zeeb } 47476b4cac81SBjoern A. Zeeb 47486b4cac81SBjoern A. Zeeb if (ni != NULL) 47496b4cac81SBjoern A. Zeeb vap = ni->ni_vap; 47506b4cac81SBjoern A. Zeeb else 47516b4cac81SBjoern A. Zeeb /* 47526b4cac81SBjoern A. Zeeb * XXX-BZ can we improve this by looking at the frame hdr 47536b4cac81SBjoern A. Zeeb * or other meta-data passed up? 47546b4cac81SBjoern A. Zeeb */ 47556b4cac81SBjoern A. Zeeb vap = TAILQ_FIRST(&ic->ic_vaps); 47566b4cac81SBjoern A. Zeeb 47579d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 47589d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 4759c0cadd99SBjoern A. Zeeb printf("TRACE %s: sta %p lsta %p state %d ni %p vap %p%s\n", 4760c0cadd99SBjoern A. Zeeb __func__, sta, lsta, (lsta != NULL) ? lsta->state : -1, 4761c0cadd99SBjoern A. Zeeb ni, vap, is_beacon ? " beacon" : ""); 47629d9ba2b7SBjoern A. Zeeb #endif 47636b4cac81SBjoern A. Zeeb 4764c0cadd99SBjoern A. Zeeb if (ni != NULL && vap != NULL && is_beacon && 4765c8dafefaSBjoern A. Zeeb rx_status->device_timestamp > 0 && 4766c8dafefaSBjoern A. Zeeb m->m_pkthdr.len >= sizeof(struct ieee80211_frame)) { 4767c8dafefaSBjoern A. Zeeb struct lkpi_vif *lvif; 4768c8dafefaSBjoern A. Zeeb struct ieee80211_vif *vif; 4769c8dafefaSBjoern A. Zeeb struct ieee80211_frame *wh; 4770c8dafefaSBjoern A. Zeeb 4771c8dafefaSBjoern A. Zeeb wh = mtod(m, struct ieee80211_frame *); 4772c8dafefaSBjoern A. Zeeb if (!IEEE80211_ADDR_EQ(wh->i_addr2, ni->ni_bssid)) 4773c8dafefaSBjoern A. Zeeb goto skip_device_ts; 4774c8dafefaSBjoern A. Zeeb 4775c8dafefaSBjoern A. Zeeb lvif = VAP_TO_LVIF(vap); 4776c8dafefaSBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 4777c8dafefaSBjoern A. Zeeb 4778c8dafefaSBjoern A. Zeeb IMPROVE("TIMING_BEACON_ONLY?"); 4779c8dafefaSBjoern A. Zeeb /* mac80211 specific (not net80211) so keep it here. */ 4780c8dafefaSBjoern A. Zeeb vif->bss_conf.sync_device_ts = rx_status->device_timestamp; 4781c8dafefaSBjoern A. Zeeb /* 4782c8dafefaSBjoern A. Zeeb * net80211 should take care of the other information (sync_tsf, 4783c8dafefaSBjoern A. Zeeb * sync_dtim_count) as otherwise we need to parse the beacon. 4784c8dafefaSBjoern A. Zeeb */ 4785c8dafefaSBjoern A. Zeeb skip_device_ts: 4786*9fb91463SBjoern A. Zeeb ; 4787*9fb91463SBjoern A. Zeeb } 4788c8dafefaSBjoern A. Zeeb 47896b4cac81SBjoern A. Zeeb if (vap != NULL && vap->iv_state > IEEE80211_S_INIT && 47906b4cac81SBjoern A. Zeeb ieee80211_radiotap_active_vap(vap)) { 47916b4cac81SBjoern A. Zeeb struct lkpi_radiotap_rx_hdr *rtap; 47926b4cac81SBjoern A. Zeeb 47936b4cac81SBjoern A. Zeeb rtap = &lhw->rtap_rx; 47946b4cac81SBjoern A. Zeeb rtap->wr_tsft = rx_status->device_timestamp; 47956b4cac81SBjoern A. Zeeb rtap->wr_flags = 0; 47966b4cac81SBjoern A. Zeeb if (rx_status->enc_flags & RX_ENC_FLAG_SHORTPRE) 47976b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; 47986b4cac81SBjoern A. Zeeb if (rx_status->enc_flags & RX_ENC_FLAG_SHORT_GI) 47996b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTGI; 48006b4cac81SBjoern A. Zeeb #if 0 /* .. or it does not given we strip it below. */ 48016b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, RX_INCLUDES_FCS)) 48026b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_FCS; 48036b4cac81SBjoern A. Zeeb #endif 48046b4cac81SBjoern A. Zeeb if (rx_status->flag & RX_FLAG_FAILED_FCS_CRC) 48056b4cac81SBjoern A. Zeeb rtap->wr_flags |= IEEE80211_RADIOTAP_F_BADFCS; 48066b4cac81SBjoern A. Zeeb rtap->wr_rate = 0; 48076b4cac81SBjoern A. Zeeb IMPROVE(); 48086b4cac81SBjoern A. Zeeb /* XXX TODO status->encoding / rate_index / bw */ 48096b4cac81SBjoern A. Zeeb rtap->wr_chan_freq = htole16(rx_stats.c_freq); 48106b4cac81SBjoern A. Zeeb if (ic->ic_curchan->ic_ieee == rx_stats.c_ieee) 48116b4cac81SBjoern A. Zeeb rtap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags); 4812170acccfSBjoern A. Zeeb rtap->wr_dbm_antsignal = rssi; 48136b4cac81SBjoern A. Zeeb rtap->wr_dbm_antnoise = rx_stats.c_nf; 48146b4cac81SBjoern A. Zeeb } 48156b4cac81SBjoern A. Zeeb 48166b4cac81SBjoern A. Zeeb if (ieee80211_hw_check(hw, RX_INCLUDES_FCS)) 48176b4cac81SBjoern A. Zeeb m_adj(m, -IEEE80211_CRC_LEN); 48186b4cac81SBjoern A. Zeeb 4819e30e05d3SBjoern A. Zeeb #if 0 4820e30e05d3SBjoern A. Zeeb if (list != NULL) { 4821e30e05d3SBjoern A. Zeeb /* 4822e30e05d3SBjoern A. Zeeb * Normally this would be queued up and delivered by 4823e30e05d3SBjoern A. Zeeb * netif_receive_skb_list(), napi_gro_receive(), or the like. 4824e30e05d3SBjoern A. Zeeb * See mt76::mac80211.c as only current possible consumer. 4825e30e05d3SBjoern A. Zeeb */ 4826e30e05d3SBjoern A. Zeeb IMPROVE("we simply pass the packet to net80211 to deal with."); 4827e30e05d3SBjoern A. Zeeb } 4828e30e05d3SBjoern A. Zeeb #endif 4829e30e05d3SBjoern A. Zeeb 48306b4cac81SBjoern A. Zeeb if (ni != NULL) { 48319d9ba2b7SBjoern A. Zeeb ok = ieee80211_input_mimo(ni, m); 48326b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 4833dbc06dd9SBjoern A. Zeeb if (ok < 0) 4834dbc06dd9SBjoern A. Zeeb m_freem(m); 48356b4cac81SBjoern A. Zeeb } else { 48369d9ba2b7SBjoern A. Zeeb ok = ieee80211_input_mimo_all(ic, m); 4837dbc06dd9SBjoern A. Zeeb /* mbuf got consumed. */ 48386b4cac81SBjoern A. Zeeb } 48396b4cac81SBjoern A. Zeeb 48409d9ba2b7SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 48419d9ba2b7SBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_RX) 48429d9ba2b7SBjoern A. Zeeb printf("TRACE %s: handled frame type %#0x\n", __func__, ok); 48439d9ba2b7SBjoern A. Zeeb #endif 48446b4cac81SBjoern A. Zeeb 48456b4cac81SBjoern A. Zeeb IMPROVE(); 48466b4cac81SBjoern A. Zeeb 48476b4cac81SBjoern A. Zeeb err: 48486b4cac81SBjoern A. Zeeb /* The skb is ours so we can free it :-) */ 48496b4cac81SBjoern A. Zeeb kfree_skb(skb); 48506b4cac81SBjoern A. Zeeb } 48516b4cac81SBjoern A. Zeeb 48526b4cac81SBjoern A. Zeeb uint8_t 4853ec190d91SBjoern A. Zeeb linuxkpi_ieee80211_get_tid(struct ieee80211_hdr *hdr, bool nonqos_ok) 48546b4cac81SBjoern A. Zeeb { 48556b4cac81SBjoern A. Zeeb const struct ieee80211_frame *wh; 4856ec190d91SBjoern A. Zeeb uint8_t tid; 4857ec190d91SBjoern A. Zeeb 4858ec190d91SBjoern A. Zeeb /* Linux seems to assume this is a QOS-Data-Frame */ 4859ec190d91SBjoern A. Zeeb KASSERT(nonqos_ok || ieee80211_is_data_qos(hdr->frame_control), 4860ec190d91SBjoern A. Zeeb ("%s: hdr %p fc %#06x not qos_data\n", __func__, hdr, 4861ec190d91SBjoern A. Zeeb hdr->frame_control)); 48626b4cac81SBjoern A. Zeeb 48636b4cac81SBjoern A. Zeeb wh = (const struct ieee80211_frame *)hdr; 4864ec190d91SBjoern A. Zeeb tid = ieee80211_gettid(wh); 4865ec190d91SBjoern A. Zeeb KASSERT(nonqos_ok || tid == (tid & IEEE80211_QOS_TID), ("%s: tid %u " 4866ec190d91SBjoern A. Zeeb "not expected (%u?)\n", __func__, tid, IEEE80211_NONQOS_TID)); 4867ec190d91SBjoern A. Zeeb 4868ec190d91SBjoern A. Zeeb return (tid); 48696b4cac81SBjoern A. Zeeb } 48706b4cac81SBjoern A. Zeeb 48716b4cac81SBjoern A. Zeeb struct wiphy * 48726b4cac81SBjoern A. Zeeb linuxkpi_wiphy_new(const struct cfg80211_ops *ops, size_t priv_len) 48736b4cac81SBjoern A. Zeeb { 48746b4cac81SBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 48756b4cac81SBjoern A. Zeeb 48766b4cac81SBjoern A. Zeeb lwiphy = kzalloc(sizeof(*lwiphy) + priv_len, GFP_KERNEL); 48776b4cac81SBjoern A. Zeeb if (lwiphy == NULL) 48786b4cac81SBjoern A. Zeeb return (NULL); 48796b4cac81SBjoern A. Zeeb lwiphy->ops = ops; 48806b4cac81SBjoern A. Zeeb 48816b4cac81SBjoern A. Zeeb /* XXX TODO */ 48826b4cac81SBjoern A. Zeeb return (LWIPHY_TO_WIPHY(lwiphy)); 48836b4cac81SBjoern A. Zeeb } 48846b4cac81SBjoern A. Zeeb 48856b4cac81SBjoern A. Zeeb void 48866b4cac81SBjoern A. Zeeb linuxkpi_wiphy_free(struct wiphy *wiphy) 48876b4cac81SBjoern A. Zeeb { 48886b4cac81SBjoern A. Zeeb struct lkpi_wiphy *lwiphy; 48896b4cac81SBjoern A. Zeeb 48906b4cac81SBjoern A. Zeeb if (wiphy == NULL) 48916b4cac81SBjoern A. Zeeb return; 48926b4cac81SBjoern A. Zeeb 48936b4cac81SBjoern A. Zeeb lwiphy = WIPHY_TO_LWIPHY(wiphy); 48946b4cac81SBjoern A. Zeeb kfree(lwiphy); 48956b4cac81SBjoern A. Zeeb } 48966b4cac81SBjoern A. Zeeb 48976b4cac81SBjoern A. Zeeb uint32_t 48986b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_channel_to_frequency(uint32_t channel, 48996b4cac81SBjoern A. Zeeb enum nl80211_band band) 49006b4cac81SBjoern A. Zeeb { 49016b4cac81SBjoern A. Zeeb 49026b4cac81SBjoern A. Zeeb switch (band) { 49036b4cac81SBjoern A. Zeeb case NL80211_BAND_2GHZ: 49046b4cac81SBjoern A. Zeeb return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_2GHZ)); 49056b4cac81SBjoern A. Zeeb break; 49066b4cac81SBjoern A. Zeeb case NL80211_BAND_5GHZ: 49076b4cac81SBjoern A. Zeeb return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_5GHZ)); 49086b4cac81SBjoern A. Zeeb break; 49096b4cac81SBjoern A. Zeeb default: 49106b4cac81SBjoern A. Zeeb /* XXX abort, retry, error, panic? */ 49116b4cac81SBjoern A. Zeeb break; 49126b4cac81SBjoern A. Zeeb } 49136b4cac81SBjoern A. Zeeb 49146b4cac81SBjoern A. Zeeb return (0); 49156b4cac81SBjoern A. Zeeb } 49166b4cac81SBjoern A. Zeeb 49176b4cac81SBjoern A. Zeeb uint32_t 49186b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_frequency_to_channel(uint32_t freq, uint32_t flags __unused) 49196b4cac81SBjoern A. Zeeb { 49206b4cac81SBjoern A. Zeeb 49216b4cac81SBjoern A. Zeeb return (ieee80211_mhz2ieee(freq, 0)); 49226b4cac81SBjoern A. Zeeb } 49236b4cac81SBjoern A. Zeeb 49246b4cac81SBjoern A. Zeeb static struct lkpi_sta * 49256b4cac81SBjoern A. Zeeb lkpi_find_lsta_by_ni(struct lkpi_vif *lvif, struct ieee80211_node *ni) 49266b4cac81SBjoern A. Zeeb { 49276b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta, *temp; 49286b4cac81SBjoern A. Zeeb 49296b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 49306b4cac81SBjoern A. Zeeb TAILQ_FOREACH_SAFE(lsta, &lvif->lsta_head, lsta_entry, temp) { 49316b4cac81SBjoern A. Zeeb if (lsta->ni == ni) { 49326b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 49336b4cac81SBjoern A. Zeeb return (lsta); 49346b4cac81SBjoern A. Zeeb } 49356b4cac81SBjoern A. Zeeb } 49366b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 49376b4cac81SBjoern A. Zeeb 49386b4cac81SBjoern A. Zeeb return (NULL); 49396b4cac81SBjoern A. Zeeb } 49406b4cac81SBjoern A. Zeeb 49416b4cac81SBjoern A. Zeeb struct ieee80211_sta * 49426b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_find_sta(struct ieee80211_vif *vif, const u8 *peer) 49436b4cac81SBjoern A. Zeeb { 49446b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 49456b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta, *temp; 49466b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 49476b4cac81SBjoern A. Zeeb 49486b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 49496b4cac81SBjoern A. Zeeb 49506b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 49516b4cac81SBjoern A. Zeeb TAILQ_FOREACH_SAFE(lsta, &lvif->lsta_head, lsta_entry, temp) { 49526b4cac81SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 49536b4cac81SBjoern A. Zeeb if (IEEE80211_ADDR_EQ(sta->addr, peer)) { 49546b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 49556b4cac81SBjoern A. Zeeb return (sta); 49566b4cac81SBjoern A. Zeeb } 49576b4cac81SBjoern A. Zeeb } 49586b4cac81SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 49596b4cac81SBjoern A. Zeeb return (NULL); 49606b4cac81SBjoern A. Zeeb } 49616b4cac81SBjoern A. Zeeb 49626b4cac81SBjoern A. Zeeb struct ieee80211_sta * 49632e183d99SBjoern A. Zeeb linuxkpi_ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw, 49642e183d99SBjoern A. Zeeb const uint8_t *addr, const uint8_t *ourvifaddr) 49656b4cac81SBjoern A. Zeeb { 49666b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 49676b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 49686b4cac81SBjoern A. Zeeb struct lkpi_sta *lsta; 49696b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif; 49706b4cac81SBjoern A. Zeeb struct ieee80211_sta *sta; 49716b4cac81SBjoern A. Zeeb 49726b4cac81SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 49736b4cac81SBjoern A. Zeeb sta = NULL; 49746b4cac81SBjoern A. Zeeb 49758891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 49766b4cac81SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 49776b4cac81SBjoern A. Zeeb 49786b4cac81SBjoern A. Zeeb /* XXX-BZ check our address from the vif. */ 49796b4cac81SBjoern A. Zeeb 49806b4cac81SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 49816b4cac81SBjoern A. Zeeb if (ourvifaddr != NULL && 49826b4cac81SBjoern A. Zeeb !IEEE80211_ADDR_EQ(vif->addr, ourvifaddr)) 49836b4cac81SBjoern A. Zeeb continue; 49846b4cac81SBjoern A. Zeeb sta = linuxkpi_ieee80211_find_sta(vif, addr); 49856b4cac81SBjoern A. Zeeb if (sta != NULL) 49866b4cac81SBjoern A. Zeeb break; 49876b4cac81SBjoern A. Zeeb } 49888891c455SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 49896b4cac81SBjoern A. Zeeb 49906b4cac81SBjoern A. Zeeb if (sta != NULL) { 49916b4cac81SBjoern A. Zeeb lsta = STA_TO_LSTA(sta); 49926b4cac81SBjoern A. Zeeb if (!lsta->added_to_drv) 49936b4cac81SBjoern A. Zeeb return (NULL); 49946b4cac81SBjoern A. Zeeb } 49956b4cac81SBjoern A. Zeeb 49966b4cac81SBjoern A. Zeeb return (sta); 49976b4cac81SBjoern A. Zeeb } 49986b4cac81SBjoern A. Zeeb 49996b4cac81SBjoern A. Zeeb struct sk_buff * 50006b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_tx_dequeue(struct ieee80211_hw *hw, 50016b4cac81SBjoern A. Zeeb struct ieee80211_txq *txq) 50026b4cac81SBjoern A. Zeeb { 50036b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 50040cbcfa19SBjoern A. Zeeb struct lkpi_vif *lvif; 50056b4cac81SBjoern A. Zeeb struct sk_buff *skb; 50066b4cac81SBjoern A. Zeeb 50070cbcfa19SBjoern A. Zeeb skb = NULL; 50086b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 50096b4cac81SBjoern A. Zeeb ltxq->seen_dequeue = true; 50106b4cac81SBjoern A. Zeeb 50110cbcfa19SBjoern A. Zeeb if (ltxq->stopped) 50120cbcfa19SBjoern A. Zeeb goto stopped; 50130cbcfa19SBjoern A. Zeeb 50140cbcfa19SBjoern A. Zeeb lvif = VIF_TO_LVIF(ltxq->txq.vif); 50150cbcfa19SBjoern A. Zeeb if (lvif->hw_queue_stopped[ltxq->txq.ac]) { 50160cbcfa19SBjoern A. Zeeb ltxq->stopped = true; 50170cbcfa19SBjoern A. Zeeb goto stopped; 50180cbcfa19SBjoern A. Zeeb } 50190cbcfa19SBjoern A. Zeeb 50206b4cac81SBjoern A. Zeeb skb = skb_dequeue(<xq->skbq); 50216b4cac81SBjoern A. Zeeb 50220cbcfa19SBjoern A. Zeeb stopped: 50236b4cac81SBjoern A. Zeeb return (skb); 50246b4cac81SBjoern A. Zeeb } 50256b4cac81SBjoern A. Zeeb 50266b4cac81SBjoern A. Zeeb void 50276b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_txq_get_depth(struct ieee80211_txq *txq, 502886220d3cSBjoern A. Zeeb unsigned long *frame_cnt, unsigned long *byte_cnt) 50296b4cac81SBjoern A. Zeeb { 50306b4cac81SBjoern A. Zeeb struct lkpi_txq *ltxq; 50316b4cac81SBjoern A. Zeeb struct sk_buff *skb; 503286220d3cSBjoern A. Zeeb unsigned long fc, bc; 50336b4cac81SBjoern A. Zeeb 50346b4cac81SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 50356b4cac81SBjoern A. Zeeb 50366b4cac81SBjoern A. Zeeb fc = bc = 0; 50376b4cac81SBjoern A. Zeeb skb_queue_walk(<xq->skbq, skb) { 50386b4cac81SBjoern A. Zeeb fc++; 50396b4cac81SBjoern A. Zeeb bc += skb->len; 50406b4cac81SBjoern A. Zeeb } 50416b4cac81SBjoern A. Zeeb if (frame_cnt) 50426b4cac81SBjoern A. Zeeb *frame_cnt = fc; 50436b4cac81SBjoern A. Zeeb if (byte_cnt) 50446b4cac81SBjoern A. Zeeb *byte_cnt = bc; 50456b4cac81SBjoern A. Zeeb 50466b4cac81SBjoern A. Zeeb /* Validate that this is doing the correct thing. */ 50476b4cac81SBjoern A. Zeeb /* Should we keep track on en/dequeue? */ 50486b4cac81SBjoern A. Zeeb IMPROVE(); 50496b4cac81SBjoern A. Zeeb } 50506b4cac81SBjoern A. Zeeb 50516b4cac81SBjoern A. Zeeb /* 50526b4cac81SBjoern A. Zeeb * We are called from ieee80211_free_txskb() or ieee80211_tx_status(). 50536b4cac81SBjoern A. Zeeb * The latter tries to derive the success status from the info flags 50546b4cac81SBjoern A. Zeeb * passed back from the driver. rawx_mit() saves the ni on the m and the 50556b4cac81SBjoern A. Zeeb * m on the skb for us to be able to give feedback to net80211. 50566b4cac81SBjoern A. Zeeb */ 5057a8397571SBjoern A. Zeeb static void 5058a8397571SBjoern A. Zeeb _lkpi_ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb, 50596b4cac81SBjoern A. Zeeb int status) 50606b4cac81SBjoern A. Zeeb { 50616b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 50626b4cac81SBjoern A. Zeeb struct mbuf *m; 50636b4cac81SBjoern A. Zeeb 50646b4cac81SBjoern A. Zeeb m = skb->m; 50656b4cac81SBjoern A. Zeeb skb->m = NULL; 50666b4cac81SBjoern A. Zeeb 50676b4cac81SBjoern A. Zeeb if (m != NULL) { 50686b4cac81SBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 50696b4cac81SBjoern A. Zeeb /* Status: 0 is ok, != 0 is error. */ 50706b4cac81SBjoern A. Zeeb ieee80211_tx_complete(ni, m, status); 50716b4cac81SBjoern A. Zeeb /* ni & mbuf were consumed. */ 50726b4cac81SBjoern A. Zeeb } 5073a8397571SBjoern A. Zeeb } 50746b4cac81SBjoern A. Zeeb 5075a8397571SBjoern A. Zeeb void 5076a8397571SBjoern A. Zeeb linuxkpi_ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb, 5077a8397571SBjoern A. Zeeb int status) 5078a8397571SBjoern A. Zeeb { 5079a8397571SBjoern A. Zeeb 5080a8397571SBjoern A. Zeeb _lkpi_ieee80211_free_txskb(hw, skb, status); 50816b4cac81SBjoern A. Zeeb kfree_skb(skb); 50826b4cac81SBjoern A. Zeeb } 50836b4cac81SBjoern A. Zeeb 5084383b3e8fSBjoern A. Zeeb void 5085a8397571SBjoern A. Zeeb linuxkpi_ieee80211_tx_status_ext(struct ieee80211_hw *hw, 5086a8397571SBjoern A. Zeeb struct ieee80211_tx_status *txstat) 5087383b3e8fSBjoern A. Zeeb { 5088a8397571SBjoern A. Zeeb struct sk_buff *skb; 5089383b3e8fSBjoern A. Zeeb struct ieee80211_tx_info *info; 5090383b3e8fSBjoern A. Zeeb struct ieee80211_ratectl_tx_status txs; 5091383b3e8fSBjoern A. Zeeb struct ieee80211_node *ni; 5092383b3e8fSBjoern A. Zeeb int status; 5093383b3e8fSBjoern A. Zeeb 5094a8397571SBjoern A. Zeeb skb = txstat->skb; 5095383b3e8fSBjoern A. Zeeb if (skb->m != NULL) { 5096383b3e8fSBjoern A. Zeeb struct mbuf *m; 5097383b3e8fSBjoern A. Zeeb 5098383b3e8fSBjoern A. Zeeb m = skb->m; 5099383b3e8fSBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 5100383b3e8fSBjoern A. Zeeb memset(&txs, 0, sizeof(txs)); 5101383b3e8fSBjoern A. Zeeb } else { 5102383b3e8fSBjoern A. Zeeb ni = NULL; 5103383b3e8fSBjoern A. Zeeb } 5104383b3e8fSBjoern A. Zeeb 5105a8397571SBjoern A. Zeeb info = txstat->info; 5106383b3e8fSBjoern A. Zeeb if (info->flags & IEEE80211_TX_STAT_ACK) { 5107383b3e8fSBjoern A. Zeeb status = 0; /* No error. */ 5108383b3e8fSBjoern A. Zeeb txs.status = IEEE80211_RATECTL_TX_SUCCESS; 5109383b3e8fSBjoern A. Zeeb } else { 5110383b3e8fSBjoern A. Zeeb status = 1; 5111383b3e8fSBjoern A. Zeeb txs.status = IEEE80211_RATECTL_TX_FAIL_UNSPECIFIED; 5112383b3e8fSBjoern A. Zeeb } 5113383b3e8fSBjoern A. Zeeb 5114383b3e8fSBjoern A. Zeeb if (ni != NULL) { 5115e2c5ab09SJohn Baldwin int ridx __unused; 5116383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 5117383b3e8fSBjoern A. Zeeb int old_rate; 5118383b3e8fSBjoern A. Zeeb 5119383b3e8fSBjoern A. Zeeb old_rate = ni->ni_vap->iv_bss->ni_txrate; 5120383b3e8fSBjoern A. Zeeb #endif 5121383b3e8fSBjoern A. Zeeb txs.pktlen = skb->len; 5122383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_PKTLEN; 5123383b3e8fSBjoern A. Zeeb if (info->status.rates[0].count > 1) { 5124383b3e8fSBjoern A. Zeeb txs.long_retries = info->status.rates[0].count - 1; /* 1 + retries in drivers. */ 5125383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_LONG_RETRY; 5126383b3e8fSBjoern A. Zeeb } 5127383b3e8fSBjoern A. Zeeb #if 0 /* Unused in net80211 currently. */ 5128a8397571SBjoern A. Zeeb /* XXX-BZ convert check .flags for MCS/VHT/.. */ 5129383b3e8fSBjoern A. Zeeb txs.final_rate = info->status.rates[0].idx; 5130383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_FINAL_RATE; 5131383b3e8fSBjoern A. Zeeb #endif 5132adff403fSBjoern A. Zeeb if (info->status.flags & IEEE80211_TX_STATUS_ACK_SIGNAL_VALID) { 5133383b3e8fSBjoern A. Zeeb txs.rssi = info->status.ack_signal; /* XXX-BZ CONVERT? */ 5134383b3e8fSBjoern A. Zeeb txs.flags |= IEEE80211_RATECTL_STATUS_RSSI; 5135383b3e8fSBjoern A. Zeeb } 5136383b3e8fSBjoern A. Zeeb 5137383b3e8fSBjoern A. Zeeb IMPROVE("only update of rate matches but that requires us to get a proper rate"); 5138383b3e8fSBjoern A. Zeeb ieee80211_ratectl_tx_complete(ni, &txs); 5139383b3e8fSBjoern A. Zeeb ridx = ieee80211_ratectl_rate(ni->ni_vap->iv_bss, NULL, 0); 5140383b3e8fSBjoern A. Zeeb 5141383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 5142383b3e8fSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) { 5143383b3e8fSBjoern A. Zeeb printf("TX-RATE: %s: old %d new %d ridx %d, " 5144383b3e8fSBjoern A. Zeeb "long_retries %d\n", __func__, 5145383b3e8fSBjoern A. Zeeb old_rate, ni->ni_vap->iv_bss->ni_txrate, 5146383b3e8fSBjoern A. Zeeb ridx, txs.long_retries); 5147383b3e8fSBjoern A. Zeeb } 5148383b3e8fSBjoern A. Zeeb #endif 5149383b3e8fSBjoern A. Zeeb } 5150383b3e8fSBjoern A. Zeeb 5151383b3e8fSBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 5152383b3e8fSBjoern A. Zeeb if (linuxkpi_debug_80211 & D80211_TRACE_TX) 5153383b3e8fSBjoern A. Zeeb printf("TX-STATUS: %s: hw %p skb %p status %d : flags %#x " 5154383b3e8fSBjoern A. Zeeb "band %u hw_queue %u tx_time_est %d : " 5155383b3e8fSBjoern A. Zeeb "rates [ %u %u %#x, %u %u %#x, %u %u %#x, %u %u %#x ] " 5156383b3e8fSBjoern A. Zeeb "ack_signal %u ampdu_ack_len %u ampdu_len %u antenna %u " 5157adff403fSBjoern A. Zeeb "tx_time %u flags %#x " 5158383b3e8fSBjoern A. Zeeb "status_driver_data [ %p %p ]\n", 5159383b3e8fSBjoern A. Zeeb __func__, hw, skb, status, info->flags, 5160383b3e8fSBjoern A. Zeeb info->band, info->hw_queue, info->tx_time_est, 5161383b3e8fSBjoern A. Zeeb info->status.rates[0].idx, info->status.rates[0].count, 5162383b3e8fSBjoern A. Zeeb info->status.rates[0].flags, 5163383b3e8fSBjoern A. Zeeb info->status.rates[1].idx, info->status.rates[1].count, 5164383b3e8fSBjoern A. Zeeb info->status.rates[1].flags, 5165383b3e8fSBjoern A. Zeeb info->status.rates[2].idx, info->status.rates[2].count, 5166383b3e8fSBjoern A. Zeeb info->status.rates[2].flags, 5167383b3e8fSBjoern A. Zeeb info->status.rates[3].idx, info->status.rates[3].count, 5168383b3e8fSBjoern A. Zeeb info->status.rates[3].flags, 5169383b3e8fSBjoern A. Zeeb info->status.ack_signal, info->status.ampdu_ack_len, 5170383b3e8fSBjoern A. Zeeb info->status.ampdu_len, info->status.antenna, 5171adff403fSBjoern A. Zeeb info->status.tx_time, info->status.flags, 5172383b3e8fSBjoern A. Zeeb info->status.status_driver_data[0], 5173383b3e8fSBjoern A. Zeeb info->status.status_driver_data[1]); 5174383b3e8fSBjoern A. Zeeb #endif 5175383b3e8fSBjoern A. Zeeb 5176a8397571SBjoern A. Zeeb if (txstat->free_list) { 5177a8397571SBjoern A. Zeeb _lkpi_ieee80211_free_txskb(hw, skb, status); 5178a8397571SBjoern A. Zeeb list_add_tail(&skb->list, txstat->free_list); 5179a8397571SBjoern A. Zeeb } else { 5180383b3e8fSBjoern A. Zeeb linuxkpi_ieee80211_free_txskb(hw, skb, status); 5181383b3e8fSBjoern A. Zeeb } 5182a8397571SBjoern A. Zeeb } 5183a8397571SBjoern A. Zeeb 5184a8397571SBjoern A. Zeeb void 5185a8397571SBjoern A. Zeeb linuxkpi_ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb) 5186a8397571SBjoern A. Zeeb { 5187a8397571SBjoern A. Zeeb struct ieee80211_tx_status status; 5188a8397571SBjoern A. Zeeb 5189a8397571SBjoern A. Zeeb memset(&status, 0, sizeof(status)); 5190a8397571SBjoern A. Zeeb status.info = IEEE80211_SKB_CB(skb); 5191a8397571SBjoern A. Zeeb status.skb = skb; 5192a8397571SBjoern A. Zeeb /* sta, n_rates, rates, free_list? */ 5193a8397571SBjoern A. Zeeb 5194a8397571SBjoern A. Zeeb ieee80211_tx_status_ext(hw, &status); 5195a8397571SBjoern A. Zeeb } 5196383b3e8fSBjoern A. Zeeb 51976b4cac81SBjoern A. Zeeb /* 51986b4cac81SBjoern A. Zeeb * This is an internal bandaid for the moment for the way we glue 51996b4cac81SBjoern A. Zeeb * skbs and mbufs together for TX. Once we have skbs backed by 52006b4cac81SBjoern A. Zeeb * mbufs this should go away. 52016b4cac81SBjoern A. Zeeb * This is a public function but kept on the private KPI (lkpi_) 52026b4cac81SBjoern A. Zeeb * and is not exposed by a header file. 52036b4cac81SBjoern A. Zeeb */ 52046b4cac81SBjoern A. Zeeb static void 52056b4cac81SBjoern A. Zeeb lkpi_ieee80211_free_skb_mbuf(void *p) 52066b4cac81SBjoern A. Zeeb { 52076b4cac81SBjoern A. Zeeb struct ieee80211_node *ni; 52086b4cac81SBjoern A. Zeeb struct mbuf *m; 52096b4cac81SBjoern A. Zeeb 52106b4cac81SBjoern A. Zeeb if (p == NULL) 52116b4cac81SBjoern A. Zeeb return; 52126b4cac81SBjoern A. Zeeb 52136b4cac81SBjoern A. Zeeb m = (struct mbuf *)p; 52146b4cac81SBjoern A. Zeeb M_ASSERTPKTHDR(m); 52156b4cac81SBjoern A. Zeeb 52166b4cac81SBjoern A. Zeeb ni = m->m_pkthdr.PH_loc.ptr; 52176b4cac81SBjoern A. Zeeb m->m_pkthdr.PH_loc.ptr = NULL; 52186b4cac81SBjoern A. Zeeb if (ni != NULL) 52196b4cac81SBjoern A. Zeeb ieee80211_free_node(ni); 52206b4cac81SBjoern A. Zeeb m_freem(m); 52216b4cac81SBjoern A. Zeeb } 52226b4cac81SBjoern A. Zeeb 52236b4cac81SBjoern A. Zeeb void 52246b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_queue_delayed_work(struct ieee80211_hw *hw, 52256b4cac81SBjoern A. Zeeb struct delayed_work *w, int delay) 52266b4cac81SBjoern A. Zeeb { 52276b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 52286b4cac81SBjoern A. Zeeb 52296b4cac81SBjoern A. Zeeb /* Need to make sure hw is in a stable (non-suspended) state. */ 52306b4cac81SBjoern A. Zeeb IMPROVE(); 52316b4cac81SBjoern A. Zeeb 52326b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 52336b4cac81SBjoern A. Zeeb queue_delayed_work(lhw->workq, w, delay); 52346b4cac81SBjoern A. Zeeb } 52356b4cac81SBjoern A. Zeeb 52366b4cac81SBjoern A. Zeeb void 52376b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_queue_work(struct ieee80211_hw *hw, 52386b4cac81SBjoern A. Zeeb struct work_struct *w) 52396b4cac81SBjoern A. Zeeb { 52406b4cac81SBjoern A. Zeeb struct lkpi_hw *lhw; 52416b4cac81SBjoern A. Zeeb 52426b4cac81SBjoern A. Zeeb /* Need to make sure hw is in a stable (non-suspended) state. */ 52436b4cac81SBjoern A. Zeeb IMPROVE(); 52446b4cac81SBjoern A. Zeeb 52456b4cac81SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 52466b4cac81SBjoern A. Zeeb queue_work(lhw->workq, w); 52476b4cac81SBjoern A. Zeeb } 52486b4cac81SBjoern A. Zeeb 52496b4cac81SBjoern A. Zeeb struct sk_buff * 5250ade774b1SBjoern A. Zeeb linuxkpi_ieee80211_probereq_get(struct ieee80211_hw *hw, uint8_t *addr, 5251ade774b1SBjoern A. Zeeb uint8_t *ssid, size_t ssid_len, size_t tailroom) 5252ade774b1SBjoern A. Zeeb { 5253ade774b1SBjoern A. Zeeb struct sk_buff *skb; 5254ade774b1SBjoern A. Zeeb struct ieee80211_frame *wh; 5255ade774b1SBjoern A. Zeeb uint8_t *p; 5256ade774b1SBjoern A. Zeeb size_t len; 5257ade774b1SBjoern A. Zeeb 5258ade774b1SBjoern A. Zeeb len = sizeof(*wh); 5259ade774b1SBjoern A. Zeeb len += 2 + ssid_len; 5260ade774b1SBjoern A. Zeeb 5261ade774b1SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + len + tailroom); 5262ade774b1SBjoern A. Zeeb if (skb == NULL) 5263ade774b1SBjoern A. Zeeb return (NULL); 5264ade774b1SBjoern A. Zeeb 5265ade774b1SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 5266ade774b1SBjoern A. Zeeb 5267ade774b1SBjoern A. Zeeb wh = skb_put_zero(skb, sizeof(*wh)); 5268ade774b1SBjoern A. Zeeb wh->i_fc[0] = IEEE80211_FC0_VERSION_0; 5269ade774b1SBjoern A. Zeeb wh->i_fc[0] |= IEEE80211_FC0_SUBTYPE_PROBE_REQ | IEEE80211_FC0_TYPE_MGT; 5270ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr1, ieee80211broadcastaddr); 5271ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr2, addr); 5272ade774b1SBjoern A. Zeeb IEEE80211_ADDR_COPY(wh->i_addr3, ieee80211broadcastaddr); 5273ade774b1SBjoern A. Zeeb 5274ade774b1SBjoern A. Zeeb p = skb_put(skb, 2 + ssid_len); 5275ade774b1SBjoern A. Zeeb *p++ = IEEE80211_ELEMID_SSID; 5276ade774b1SBjoern A. Zeeb *p++ = ssid_len; 5277ade774b1SBjoern A. Zeeb if (ssid_len > 0) 5278ade774b1SBjoern A. Zeeb memcpy(p, ssid, ssid_len); 5279ade774b1SBjoern A. Zeeb 5280ade774b1SBjoern A. Zeeb return (skb); 5281ade774b1SBjoern A. Zeeb } 5282ade774b1SBjoern A. Zeeb 5283ade774b1SBjoern A. Zeeb struct sk_buff * 52846b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_pspoll_get(struct ieee80211_hw *hw, 52856b4cac81SBjoern A. Zeeb struct ieee80211_vif *vif) 52866b4cac81SBjoern A. Zeeb { 52876b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 52886b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 52896b4cac81SBjoern A. Zeeb struct sk_buff *skb; 52906b4cac81SBjoern A. Zeeb struct ieee80211_frame_pspoll *psp; 52916b4cac81SBjoern A. Zeeb uint16_t v; 52926b4cac81SBjoern A. Zeeb 52936b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*psp)); 52946b4cac81SBjoern A. Zeeb if (skb == NULL) 52956b4cac81SBjoern A. Zeeb return (NULL); 52966b4cac81SBjoern A. Zeeb 52976b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 52986b4cac81SBjoern A. Zeeb 52996b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 53006b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 53016b4cac81SBjoern A. Zeeb 53026b4cac81SBjoern A. Zeeb psp = skb_put_zero(skb, sizeof(*psp)); 53036b4cac81SBjoern A. Zeeb psp->i_fc[0] = IEEE80211_FC0_VERSION_0; 53046b4cac81SBjoern A. Zeeb psp->i_fc[0] |= IEEE80211_FC0_SUBTYPE_PS_POLL | IEEE80211_FC0_TYPE_CTL; 5305616e1330SBjoern A. Zeeb v = htole16(vif->cfg.aid | 1<<15 | 1<<16); 53066b4cac81SBjoern A. Zeeb memcpy(&psp->i_aid, &v, sizeof(v)); 53076b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(psp->i_bssid, vap->iv_bss->ni_macaddr); 53086b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(psp->i_ta, vif->addr); 53096b4cac81SBjoern A. Zeeb 53106b4cac81SBjoern A. Zeeb return (skb); 53116b4cac81SBjoern A. Zeeb } 53126b4cac81SBjoern A. Zeeb 53136b4cac81SBjoern A. Zeeb struct sk_buff * 53146b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_nullfunc_get(struct ieee80211_hw *hw, 5315adff403fSBjoern A. Zeeb struct ieee80211_vif *vif, int linkid, bool qos) 53166b4cac81SBjoern A. Zeeb { 53176b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 53186b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 53196b4cac81SBjoern A. Zeeb struct sk_buff *skb; 53206b4cac81SBjoern A. Zeeb struct ieee80211_frame *nullf; 53216b4cac81SBjoern A. Zeeb 5322adff403fSBjoern A. Zeeb IMPROVE("linkid"); 5323adff403fSBjoern A. Zeeb 53246b4cac81SBjoern A. Zeeb skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*nullf)); 53256b4cac81SBjoern A. Zeeb if (skb == NULL) 53266b4cac81SBjoern A. Zeeb return (NULL); 53276b4cac81SBjoern A. Zeeb 53286b4cac81SBjoern A. Zeeb skb_reserve(skb, hw->extra_tx_headroom); 53296b4cac81SBjoern A. Zeeb 53306b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 53316b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 53326b4cac81SBjoern A. Zeeb 53336b4cac81SBjoern A. Zeeb nullf = skb_put_zero(skb, sizeof(*nullf)); 53346b4cac81SBjoern A. Zeeb nullf->i_fc[0] = IEEE80211_FC0_VERSION_0; 53356b4cac81SBjoern A. Zeeb nullf->i_fc[0] |= IEEE80211_FC0_SUBTYPE_NODATA | IEEE80211_FC0_TYPE_DATA; 53366b4cac81SBjoern A. Zeeb nullf->i_fc[1] = IEEE80211_FC1_DIR_TODS; 53376b4cac81SBjoern A. Zeeb 53386b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr1, vap->iv_bss->ni_bssid); 53396b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr2, vif->addr); 53406b4cac81SBjoern A. Zeeb IEEE80211_ADDR_COPY(nullf->i_addr3, vap->iv_bss->ni_macaddr); 53416b4cac81SBjoern A. Zeeb 53426b4cac81SBjoern A. Zeeb return (skb); 53436b4cac81SBjoern A. Zeeb } 53446b4cac81SBjoern A. Zeeb 53456b4cac81SBjoern A. Zeeb struct wireless_dev * 53466b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_vif_to_wdev(struct ieee80211_vif *vif) 53476b4cac81SBjoern A. Zeeb { 53486b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 53496b4cac81SBjoern A. Zeeb 53506b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 53516b4cac81SBjoern A. Zeeb return (&lvif->wdev); 53526b4cac81SBjoern A. Zeeb } 53536b4cac81SBjoern A. Zeeb 53546b4cac81SBjoern A. Zeeb void 53556b4cac81SBjoern A. Zeeb linuxkpi_ieee80211_connection_loss(struct ieee80211_vif *vif) 53566b4cac81SBjoern A. Zeeb { 53576b4cac81SBjoern A. Zeeb struct lkpi_vif *lvif; 53586b4cac81SBjoern A. Zeeb struct ieee80211vap *vap; 53596b4cac81SBjoern A. Zeeb enum ieee80211_state nstate; 53606b4cac81SBjoern A. Zeeb int arg; 53616b4cac81SBjoern A. Zeeb 53626b4cac81SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 53636b4cac81SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 53646b4cac81SBjoern A. Zeeb 53656b4cac81SBjoern A. Zeeb /* 5366f3229b62SBjoern A. Zeeb * Go to init; otherwise we need to elaborately check state and 53676b4cac81SBjoern A. Zeeb * handle accordingly, e.g., if in RUN we could call iv_bmiss. 53686b4cac81SBjoern A. Zeeb * Let the statemachine handle all neccessary changes. 53696b4cac81SBjoern A. Zeeb */ 5370f3229b62SBjoern A. Zeeb nstate = IEEE80211_S_INIT; 5371bb81db90SBjoern A. Zeeb arg = 0; /* Not a valid reason. */ 53726b4cac81SBjoern A. Zeeb 5373018d93ecSBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: vif %p vap %p state %s\n", __func__, 5374018d93ecSBjoern A. Zeeb vif, vap, ieee80211_state_name[vap->iv_state]); 53756b4cac81SBjoern A. Zeeb ieee80211_new_state(vap, nstate, arg); 53766b4cac81SBjoern A. Zeeb } 53776b4cac81SBjoern A. Zeeb 5378bb81db90SBjoern A. Zeeb void 5379bb81db90SBjoern A. Zeeb linuxkpi_ieee80211_beacon_loss(struct ieee80211_vif *vif) 5380bb81db90SBjoern A. Zeeb { 5381bb81db90SBjoern A. Zeeb struct lkpi_vif *lvif; 5382bb81db90SBjoern A. Zeeb struct ieee80211vap *vap; 5383bb81db90SBjoern A. Zeeb 5384bb81db90SBjoern A. Zeeb lvif = VIF_TO_LVIF(vif); 5385bb81db90SBjoern A. Zeeb vap = LVIF_TO_VAP(lvif); 5386bb81db90SBjoern A. Zeeb 5387bb81db90SBjoern A. Zeeb ic_printf(vap->iv_ic, "%s: vif %p vap %p state %s\n", __func__, 5388bb81db90SBjoern A. Zeeb vif, vap, ieee80211_state_name[vap->iv_state]); 53893540911bSBjoern A. Zeeb ieee80211_beacon_miss(vap->iv_ic); 5390bb81db90SBjoern A. Zeeb } 5391bb81db90SBjoern A. Zeeb 53925edde07cSBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 53935edde07cSBjoern A. Zeeb 53945a9a0d78SBjoern A. Zeeb void 53955a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_stop_queue(struct ieee80211_hw *hw, int qnum) 53965a9a0d78SBjoern A. Zeeb { 53975a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 53985a9a0d78SBjoern A. Zeeb struct lkpi_vif *lvif; 53995a9a0d78SBjoern A. Zeeb struct ieee80211_vif *vif; 54005a9a0d78SBjoern A. Zeeb int ac_count, ac; 54015a9a0d78SBjoern A. Zeeb 54025a9a0d78SBjoern A. Zeeb KASSERT(qnum < hw->queues, ("%s: qnum %d >= hw->queues %d, hw %p\n", 54035a9a0d78SBjoern A. Zeeb __func__, qnum, hw->queues, hw)); 54045a9a0d78SBjoern A. Zeeb 54055a9a0d78SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 54065a9a0d78SBjoern A. Zeeb 54075a9a0d78SBjoern A. Zeeb /* See lkpi_ic_vap_create(). */ 54085a9a0d78SBjoern A. Zeeb if (hw->queues >= IEEE80211_NUM_ACS) 54095a9a0d78SBjoern A. Zeeb ac_count = IEEE80211_NUM_ACS; 54105a9a0d78SBjoern A. Zeeb else 54115a9a0d78SBjoern A. Zeeb ac_count = 1; 54125a9a0d78SBjoern A. Zeeb 54135a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 54145a9a0d78SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 54155a9a0d78SBjoern A. Zeeb 54165a9a0d78SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 54175a9a0d78SBjoern A. Zeeb for (ac = 0; ac < ac_count; ac++) { 54185a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 54195a9a0d78SBjoern A. Zeeb if (qnum == vif->hw_queue[ac]) { 54200d2cb6a6SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 54215a9a0d78SBjoern A. Zeeb /* 54225a9a0d78SBjoern A. Zeeb * For now log this to better understand 54235a9a0d78SBjoern A. Zeeb * how this is supposed to work. 54245a9a0d78SBjoern A. Zeeb */ 54250d2cb6a6SBjoern A. Zeeb if (lvif->hw_queue_stopped[ac] && 54260d2cb6a6SBjoern A. Zeeb (linuxkpi_debug_80211 & D80211_IMPROVE_TXQ) != 0) 54275a9a0d78SBjoern A. Zeeb ic_printf(lhw->ic, "%s:%d: lhw %p hw %p " 54285a9a0d78SBjoern A. Zeeb "lvif %p vif %p ac %d qnum %d already " 54295a9a0d78SBjoern A. Zeeb "stopped\n", __func__, __LINE__, 54305a9a0d78SBjoern A. Zeeb lhw, hw, lvif, vif, ac, qnum); 54310d2cb6a6SBjoern A. Zeeb #endif 54325a9a0d78SBjoern A. Zeeb lvif->hw_queue_stopped[ac] = true; 54335a9a0d78SBjoern A. Zeeb } 54345a9a0d78SBjoern A. Zeeb } 54355a9a0d78SBjoern A. Zeeb } 54365a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 54375a9a0d78SBjoern A. Zeeb } 54385a9a0d78SBjoern A. Zeeb 54395a9a0d78SBjoern A. Zeeb void 54405a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_stop_queues(struct ieee80211_hw *hw) 54415a9a0d78SBjoern A. Zeeb { 54425a9a0d78SBjoern A. Zeeb int i; 54435a9a0d78SBjoern A. Zeeb 54445a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Locking; do we need further info?"); 54455a9a0d78SBjoern A. Zeeb for (i = 0; i < hw->queues; i++) 54465a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_stop_queue(hw, i); 54475a9a0d78SBjoern A. Zeeb } 54485a9a0d78SBjoern A. Zeeb 54495a9a0d78SBjoern A. Zeeb 54505a9a0d78SBjoern A. Zeeb static void 54515a9a0d78SBjoern A. Zeeb lkpi_ieee80211_wake_queues(struct ieee80211_hw *hw, int hwq) 54525a9a0d78SBjoern A. Zeeb { 54535a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 54545a9a0d78SBjoern A. Zeeb struct lkpi_vif *lvif; 54555a9a0d78SBjoern A. Zeeb struct lkpi_sta *lsta; 54565a9a0d78SBjoern A. Zeeb int ac_count, ac, tid; 54575a9a0d78SBjoern A. Zeeb 54585a9a0d78SBjoern A. Zeeb /* See lkpi_ic_vap_create(). */ 54595a9a0d78SBjoern A. Zeeb if (hw->queues >= IEEE80211_NUM_ACS) 54605a9a0d78SBjoern A. Zeeb ac_count = IEEE80211_NUM_ACS; 54615a9a0d78SBjoern A. Zeeb else 54625a9a0d78SBjoern A. Zeeb ac_count = 1; 54635a9a0d78SBjoern A. Zeeb 54645a9a0d78SBjoern A. Zeeb lhw = wiphy_priv(hw->wiphy); 54655a9a0d78SBjoern A. Zeeb 54665a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Locking"); 54675a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_LOCK(lhw); 54685a9a0d78SBjoern A. Zeeb TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) { 54695a9a0d78SBjoern A. Zeeb struct ieee80211_vif *vif; 54705a9a0d78SBjoern A. Zeeb 54715a9a0d78SBjoern A. Zeeb vif = LVIF_TO_VIF(lvif); 54725a9a0d78SBjoern A. Zeeb for (ac = 0; ac < ac_count; ac++) { 54735a9a0d78SBjoern A. Zeeb 54745a9a0d78SBjoern A. Zeeb if (hwq == vif->hw_queue[ac]) { 54755a9a0d78SBjoern A. Zeeb 54765a9a0d78SBjoern A. Zeeb /* XXX-BZ what about software scan? */ 54775a9a0d78SBjoern A. Zeeb 54780d2cb6a6SBjoern A. Zeeb #ifdef LINUXKPI_DEBUG_80211 54795a9a0d78SBjoern A. Zeeb /* 54805a9a0d78SBjoern A. Zeeb * For now log this to better understand 54815a9a0d78SBjoern A. Zeeb * how this is supposed to work. 54825a9a0d78SBjoern A. Zeeb */ 54830d2cb6a6SBjoern A. Zeeb if (!lvif->hw_queue_stopped[ac] && 54840d2cb6a6SBjoern A. Zeeb (linuxkpi_debug_80211 & D80211_IMPROVE_TXQ) != 0) 54855a9a0d78SBjoern A. Zeeb ic_printf(lhw->ic, "%s:%d: lhw %p hw %p " 54865a9a0d78SBjoern A. Zeeb "lvif %p vif %p ac %d hw_q not stopped\n", 54875a9a0d78SBjoern A. Zeeb __func__, __LINE__, 54885a9a0d78SBjoern A. Zeeb lhw, hw, lvif, vif, ac); 54890d2cb6a6SBjoern A. Zeeb #endif 54905a9a0d78SBjoern A. Zeeb lvif->hw_queue_stopped[ac] = false; 54915a9a0d78SBjoern A. Zeeb 54925a9a0d78SBjoern A. Zeeb LKPI_80211_LVIF_LOCK(lvif); 54935a9a0d78SBjoern A. Zeeb TAILQ_FOREACH(lsta, &lvif->lsta_head, lsta_entry) { 54945a9a0d78SBjoern A. Zeeb struct ieee80211_sta *sta; 54955a9a0d78SBjoern A. Zeeb 54965a9a0d78SBjoern A. Zeeb sta = LSTA_TO_STA(lsta); 54975a9a0d78SBjoern A. Zeeb for (tid = 0; tid < nitems(sta->txq); tid++) { 54985a9a0d78SBjoern A. Zeeb struct lkpi_txq *ltxq; 54995a9a0d78SBjoern A. Zeeb 55005a9a0d78SBjoern A. Zeeb if (sta->txq[tid] == NULL) 55015a9a0d78SBjoern A. Zeeb continue; 55025a9a0d78SBjoern A. Zeeb 55035a9a0d78SBjoern A. Zeeb if (sta->txq[tid]->ac != ac) 55045a9a0d78SBjoern A. Zeeb continue; 55055a9a0d78SBjoern A. Zeeb 55065a9a0d78SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(sta->txq[tid]); 55075a9a0d78SBjoern A. Zeeb if (!ltxq->stopped) 55085a9a0d78SBjoern A. Zeeb continue; 55095a9a0d78SBjoern A. Zeeb 55105a9a0d78SBjoern A. Zeeb ltxq->stopped = false; 55115a9a0d78SBjoern A. Zeeb 55125a9a0d78SBjoern A. Zeeb /* XXX-BZ see when this explodes with all the locking. taskq? */ 55135a9a0d78SBjoern A. Zeeb lkpi_80211_mo_wake_tx_queue(hw, sta->txq[tid]); 55145a9a0d78SBjoern A. Zeeb } 55155a9a0d78SBjoern A. Zeeb } 55165a9a0d78SBjoern A. Zeeb LKPI_80211_LVIF_UNLOCK(lvif); 55175a9a0d78SBjoern A. Zeeb } 55185a9a0d78SBjoern A. Zeeb } 55195a9a0d78SBjoern A. Zeeb } 55205a9a0d78SBjoern A. Zeeb LKPI_80211_LHW_LVIF_UNLOCK(lhw); 55215a9a0d78SBjoern A. Zeeb } 55225a9a0d78SBjoern A. Zeeb 55235a9a0d78SBjoern A. Zeeb void 55245a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_wake_queues(struct ieee80211_hw *hw) 55255a9a0d78SBjoern A. Zeeb { 55265a9a0d78SBjoern A. Zeeb int i; 55275a9a0d78SBjoern A. Zeeb 55285a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Is this all/enough here?"); 55295a9a0d78SBjoern A. Zeeb for (i = 0; i < hw->queues; i++) 55305a9a0d78SBjoern A. Zeeb lkpi_ieee80211_wake_queues(hw, i); 55315a9a0d78SBjoern A. Zeeb } 55325a9a0d78SBjoern A. Zeeb 55335a9a0d78SBjoern A. Zeeb void 55345a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_wake_queue(struct ieee80211_hw *hw, int qnum) 55355a9a0d78SBjoern A. Zeeb { 55365a9a0d78SBjoern A. Zeeb 55375a9a0d78SBjoern A. Zeeb KASSERT(qnum < hw->queues, ("%s: qnum %d >= hw->queues %d, hw %p\n", 55385a9a0d78SBjoern A. Zeeb __func__, qnum, hw->queues, hw)); 55395a9a0d78SBjoern A. Zeeb 55405a9a0d78SBjoern A. Zeeb lkpi_ieee80211_wake_queues(hw, qnum); 55415a9a0d78SBjoern A. Zeeb } 55425a9a0d78SBjoern A. Zeeb 55435a9a0d78SBjoern A. Zeeb /* This is just hardware queues. */ 55445a9a0d78SBjoern A. Zeeb void 55455a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_txq_schedule_start(struct ieee80211_hw *hw, uint8_t ac) 55465a9a0d78SBjoern A. Zeeb { 55475a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 55485a9a0d78SBjoern A. Zeeb 55495a9a0d78SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 55505a9a0d78SBjoern A. Zeeb 55515a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("Are there reasons why we wouldn't schedule?"); 55525a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 55535a9a0d78SBjoern A. Zeeb if (++lhw->txq_generation[ac] == 0) 55545a9a0d78SBjoern A. Zeeb lhw->txq_generation[ac]++; 55555a9a0d78SBjoern A. Zeeb } 55565a9a0d78SBjoern A. Zeeb 55575a9a0d78SBjoern A. Zeeb struct ieee80211_txq * 55585a9a0d78SBjoern A. Zeeb linuxkpi_ieee80211_next_txq(struct ieee80211_hw *hw, uint8_t ac) 55595a9a0d78SBjoern A. Zeeb { 55605a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 55615a9a0d78SBjoern A. Zeeb struct ieee80211_txq *txq; 55625a9a0d78SBjoern A. Zeeb struct lkpi_txq *ltxq; 55635a9a0d78SBjoern A. Zeeb 55645a9a0d78SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 55655a9a0d78SBjoern A. Zeeb txq = NULL; 55665a9a0d78SBjoern A. Zeeb 55675a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 55685a9a0d78SBjoern A. Zeeb 55695a9a0d78SBjoern A. Zeeb /* Check that we are scheduled. */ 55705a9a0d78SBjoern A. Zeeb if (lhw->txq_generation[ac] == 0) 55715a9a0d78SBjoern A. Zeeb goto out; 55725a9a0d78SBjoern A. Zeeb 55735a9a0d78SBjoern A. Zeeb ltxq = TAILQ_FIRST(&lhw->scheduled_txqs[ac]); 55745a9a0d78SBjoern A. Zeeb if (ltxq == NULL) 55755a9a0d78SBjoern A. Zeeb goto out; 55765a9a0d78SBjoern A. Zeeb if (ltxq->txq_generation == lhw->txq_generation[ac]) 55775a9a0d78SBjoern A. Zeeb goto out; 55785a9a0d78SBjoern A. Zeeb 55795a9a0d78SBjoern A. Zeeb ltxq->txq_generation = lhw->txq_generation[ac]; 55805a9a0d78SBjoern A. Zeeb TAILQ_REMOVE(&lhw->scheduled_txqs[ac], ltxq, txq_entry); 55815a9a0d78SBjoern A. Zeeb txq = <xq->txq; 55825a9a0d78SBjoern A. Zeeb TAILQ_ELEM_INIT(ltxq, txq_entry); 55835a9a0d78SBjoern A. Zeeb 55845a9a0d78SBjoern A. Zeeb out: 55855a9a0d78SBjoern A. Zeeb return (txq); 55865a9a0d78SBjoern A. Zeeb } 55875a9a0d78SBjoern A. Zeeb 55885a9a0d78SBjoern A. Zeeb void linuxkpi_ieee80211_schedule_txq(struct ieee80211_hw *hw, 55895a9a0d78SBjoern A. Zeeb struct ieee80211_txq *txq, bool withoutpkts) 55905a9a0d78SBjoern A. Zeeb { 55915a9a0d78SBjoern A. Zeeb struct lkpi_hw *lhw; 55925a9a0d78SBjoern A. Zeeb struct lkpi_txq *ltxq; 55935a9a0d78SBjoern A. Zeeb 55945a9a0d78SBjoern A. Zeeb ltxq = TXQ_TO_LTXQ(txq); 55955a9a0d78SBjoern A. Zeeb 55965a9a0d78SBjoern A. Zeeb IMPROVE_TXQ("LOCKING"); 55975a9a0d78SBjoern A. Zeeb 55985a9a0d78SBjoern A. Zeeb /* Only schedule if work to do or asked to anyway. */ 55995a9a0d78SBjoern A. Zeeb if (!withoutpkts && skb_queue_empty(<xq->skbq)) 56005a9a0d78SBjoern A. Zeeb goto out; 56015a9a0d78SBjoern A. Zeeb 56025a9a0d78SBjoern A. Zeeb /* Make sure we do not double-schedule. */ 56035a9a0d78SBjoern A. Zeeb if (ltxq->txq_entry.tqe_next != NULL) 56045a9a0d78SBjoern A. Zeeb goto out; 56055a9a0d78SBjoern A. Zeeb 56065a9a0d78SBjoern A. Zeeb lhw = HW_TO_LHW(hw); 56075a9a0d78SBjoern A. Zeeb TAILQ_INSERT_TAIL(&lhw->scheduled_txqs[txq->ac], ltxq, txq_entry); 56085a9a0d78SBjoern A. Zeeb out: 56095a9a0d78SBjoern A. Zeeb return; 56105a9a0d78SBjoern A. Zeeb } 56115a9a0d78SBjoern A. Zeeb 56125a9a0d78SBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 56135a9a0d78SBjoern A. Zeeb 56145edde07cSBjoern A. Zeeb struct lkpi_cfg80211_bss { 56155edde07cSBjoern A. Zeeb u_int refcnt; 56165edde07cSBjoern A. Zeeb struct cfg80211_bss bss; 56175edde07cSBjoern A. Zeeb }; 56185edde07cSBjoern A. Zeeb 56195edde07cSBjoern A. Zeeb struct lkpi_cfg80211_get_bss_iter_lookup { 56205edde07cSBjoern A. Zeeb struct wiphy *wiphy; 56215edde07cSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 56225edde07cSBjoern A. Zeeb const uint8_t *bssid; 56235edde07cSBjoern A. Zeeb const uint8_t *ssid; 56245edde07cSBjoern A. Zeeb size_t ssid_len; 56255edde07cSBjoern A. Zeeb enum ieee80211_bss_type bss_type; 56265edde07cSBjoern A. Zeeb enum ieee80211_privacy privacy; 56275edde07cSBjoern A. Zeeb 56285edde07cSBjoern A. Zeeb /* 56295edde07cSBjoern A. Zeeb * Something to store a copy of the result as the net80211 scan cache 56305edde07cSBjoern A. Zeeb * is not refoucnted so a scan entry might go away any time. 56315edde07cSBjoern A. Zeeb */ 56325edde07cSBjoern A. Zeeb bool match; 56335edde07cSBjoern A. Zeeb struct cfg80211_bss *bss; 56345edde07cSBjoern A. Zeeb }; 56355edde07cSBjoern A. Zeeb 56365edde07cSBjoern A. Zeeb static void 56375edde07cSBjoern A. Zeeb lkpi_cfg80211_get_bss_iterf(void *arg, const struct ieee80211_scan_entry *se) 56385edde07cSBjoern A. Zeeb { 56395edde07cSBjoern A. Zeeb struct lkpi_cfg80211_get_bss_iter_lookup *lookup; 56405edde07cSBjoern A. Zeeb size_t ielen; 56415edde07cSBjoern A. Zeeb 56425edde07cSBjoern A. Zeeb lookup = arg; 56435edde07cSBjoern A. Zeeb 56445edde07cSBjoern A. Zeeb /* Do not try to find another match. */ 56455edde07cSBjoern A. Zeeb if (lookup->match) 56465edde07cSBjoern A. Zeeb return; 56475edde07cSBjoern A. Zeeb 56485edde07cSBjoern A. Zeeb /* Nothing to store result. */ 56495edde07cSBjoern A. Zeeb if (lookup->bss == NULL) 56505edde07cSBjoern A. Zeeb return; 56515edde07cSBjoern A. Zeeb 56525edde07cSBjoern A. Zeeb if (lookup->privacy != IEEE80211_PRIVACY_ANY) { 56535edde07cSBjoern A. Zeeb /* if (se->se_capinfo & IEEE80211_CAPINFO_PRIVACY) */ 56545edde07cSBjoern A. Zeeb /* We have no idea what to compare to as the drivers only request ANY */ 56555edde07cSBjoern A. Zeeb return; 56565edde07cSBjoern A. Zeeb } 56575edde07cSBjoern A. Zeeb 56585edde07cSBjoern A. Zeeb if (lookup->bss_type != IEEE80211_BSS_TYPE_ANY) { 56595edde07cSBjoern A. Zeeb /* if (se->se_capinfo & (IEEE80211_CAPINFO_IBSS|IEEE80211_CAPINFO_ESS)) */ 56605edde07cSBjoern A. Zeeb /* We have no idea what to compare to as the drivers only request ANY */ 56615edde07cSBjoern A. Zeeb return; 56625edde07cSBjoern A. Zeeb } 56635edde07cSBjoern A. Zeeb 56645edde07cSBjoern A. Zeeb if (lookup->chan != NULL) { 56655edde07cSBjoern A. Zeeb struct linuxkpi_ieee80211_channel *chan; 56665edde07cSBjoern A. Zeeb 56675edde07cSBjoern A. Zeeb chan = linuxkpi_ieee80211_get_channel(lookup->wiphy, 56685edde07cSBjoern A. Zeeb se->se_chan->ic_freq); 56695edde07cSBjoern A. Zeeb if (chan == NULL || chan != lookup->chan) 56705edde07cSBjoern A. Zeeb return; 56715edde07cSBjoern A. Zeeb } 56725edde07cSBjoern A. Zeeb 56735edde07cSBjoern A. Zeeb if (lookup->bssid && !IEEE80211_ADDR_EQ(lookup->bssid, se->se_bssid)) 56745edde07cSBjoern A. Zeeb return; 56755edde07cSBjoern A. Zeeb 56765edde07cSBjoern A. Zeeb if (lookup->ssid) { 56775edde07cSBjoern A. Zeeb if (lookup->ssid_len != se->se_ssid[1] || 56785edde07cSBjoern A. Zeeb se->se_ssid[1] == 0) 56795edde07cSBjoern A. Zeeb return; 56805edde07cSBjoern A. Zeeb if (memcmp(lookup->ssid, se->se_ssid+2, lookup->ssid_len) != 0) 56815edde07cSBjoern A. Zeeb return; 56825edde07cSBjoern A. Zeeb } 56835edde07cSBjoern A. Zeeb 56845edde07cSBjoern A. Zeeb ielen = se->se_ies.len; 56855edde07cSBjoern A. Zeeb 56865edde07cSBjoern A. Zeeb lookup->bss->ies = malloc(sizeof(*lookup->bss->ies) + ielen, 56875edde07cSBjoern A. Zeeb M_LKPI80211, M_NOWAIT | M_ZERO); 56885edde07cSBjoern A. Zeeb if (lookup->bss->ies == NULL) 56895edde07cSBjoern A. Zeeb return; 56905edde07cSBjoern A. Zeeb 56915edde07cSBjoern A. Zeeb lookup->bss->ies->data = (uint8_t *)lookup->bss->ies + sizeof(*lookup->bss->ies); 56925edde07cSBjoern A. Zeeb lookup->bss->ies->len = ielen; 56935edde07cSBjoern A. Zeeb if (ielen) 56945edde07cSBjoern A. Zeeb memcpy(lookup->bss->ies->data, se->se_ies.data, ielen); 56955edde07cSBjoern A. Zeeb 56965edde07cSBjoern A. Zeeb lookup->match = true; 56975edde07cSBjoern A. Zeeb } 56985edde07cSBjoern A. Zeeb 56995edde07cSBjoern A. Zeeb struct cfg80211_bss * 57005edde07cSBjoern A. Zeeb linuxkpi_cfg80211_get_bss(struct wiphy *wiphy, struct linuxkpi_ieee80211_channel *chan, 57015edde07cSBjoern A. Zeeb const uint8_t *bssid, const uint8_t *ssid, size_t ssid_len, 57025edde07cSBjoern A. Zeeb enum ieee80211_bss_type bss_type, enum ieee80211_privacy privacy) 57035edde07cSBjoern A. Zeeb { 57045edde07cSBjoern A. Zeeb struct lkpi_cfg80211_bss *lbss; 57055edde07cSBjoern A. Zeeb struct lkpi_cfg80211_get_bss_iter_lookup lookup; 57065edde07cSBjoern A. Zeeb struct lkpi_hw *lhw; 57075edde07cSBjoern A. Zeeb struct ieee80211vap *vap; 57085edde07cSBjoern A. Zeeb 57095edde07cSBjoern A. Zeeb lhw = wiphy_priv(wiphy); 57105edde07cSBjoern A. Zeeb 57115edde07cSBjoern A. Zeeb /* Let's hope we can alloc. */ 57125edde07cSBjoern A. Zeeb lbss = malloc(sizeof(*lbss), M_LKPI80211, M_NOWAIT | M_ZERO); 57135edde07cSBjoern A. Zeeb if (lbss == NULL) { 57145edde07cSBjoern A. Zeeb ic_printf(lhw->ic, "%s: alloc failed.\n", __func__); 57155edde07cSBjoern A. Zeeb return (NULL); 57165edde07cSBjoern A. Zeeb } 57175edde07cSBjoern A. Zeeb 57185edde07cSBjoern A. Zeeb lookup.wiphy = wiphy; 57195edde07cSBjoern A. Zeeb lookup.chan = chan; 57205edde07cSBjoern A. Zeeb lookup.bssid = bssid; 57215edde07cSBjoern A. Zeeb lookup.ssid = ssid; 57225edde07cSBjoern A. Zeeb lookup.ssid_len = ssid_len; 57235edde07cSBjoern A. Zeeb lookup.bss_type = bss_type; 57245edde07cSBjoern A. Zeeb lookup.privacy = privacy; 57255edde07cSBjoern A. Zeeb lookup.match = false; 57265edde07cSBjoern A. Zeeb lookup.bss = &lbss->bss; 57275edde07cSBjoern A. Zeeb 57285edde07cSBjoern A. Zeeb IMPROVE("Iterate over all VAPs comparing perm_addr and addresses?"); 57295edde07cSBjoern A. Zeeb vap = TAILQ_FIRST(&lhw->ic->ic_vaps); 57305edde07cSBjoern A. Zeeb ieee80211_scan_iterate(vap, lkpi_cfg80211_get_bss_iterf, &lookup); 57315edde07cSBjoern A. Zeeb if (!lookup.match) { 57325edde07cSBjoern A. Zeeb free(lbss, M_LKPI80211); 57335edde07cSBjoern A. Zeeb return (NULL); 57345edde07cSBjoern A. Zeeb } 57355edde07cSBjoern A. Zeeb 57365edde07cSBjoern A. Zeeb refcount_init(&lbss->refcnt, 1); 57375edde07cSBjoern A. Zeeb return (&lbss->bss); 57385edde07cSBjoern A. Zeeb } 57395edde07cSBjoern A. Zeeb 57405edde07cSBjoern A. Zeeb void 57415edde07cSBjoern A. Zeeb linuxkpi_cfg80211_put_bss(struct wiphy *wiphy, struct cfg80211_bss *bss) 57425edde07cSBjoern A. Zeeb { 57435edde07cSBjoern A. Zeeb struct lkpi_cfg80211_bss *lbss; 57445edde07cSBjoern A. Zeeb 57455edde07cSBjoern A. Zeeb lbss = container_of(bss, struct lkpi_cfg80211_bss, bss); 57465edde07cSBjoern A. Zeeb 57475edde07cSBjoern A. Zeeb /* Free everything again on refcount ... */ 57485edde07cSBjoern A. Zeeb if (refcount_release(&lbss->refcnt)) { 57495edde07cSBjoern A. Zeeb free(lbss->bss.ies, M_LKPI80211); 57505edde07cSBjoern A. Zeeb free(lbss, M_LKPI80211); 57515edde07cSBjoern A. Zeeb } 57525edde07cSBjoern A. Zeeb } 57535edde07cSBjoern A. Zeeb 57545edde07cSBjoern A. Zeeb void 57555edde07cSBjoern A. Zeeb linuxkpi_cfg80211_bss_flush(struct wiphy *wiphy) 57565edde07cSBjoern A. Zeeb { 57575edde07cSBjoern A. Zeeb struct lkpi_hw *lhw; 57585edde07cSBjoern A. Zeeb struct ieee80211com *ic; 57595edde07cSBjoern A. Zeeb struct ieee80211vap *vap; 57605edde07cSBjoern A. Zeeb 57615edde07cSBjoern A. Zeeb lhw = wiphy_priv(wiphy); 57625edde07cSBjoern A. Zeeb ic = lhw->ic; 57635edde07cSBjoern A. Zeeb 57645edde07cSBjoern A. Zeeb /* 57655edde07cSBjoern A. Zeeb * If we haven't called ieee80211_ifattach() yet 57665edde07cSBjoern A. Zeeb * or there is no VAP, there are no scans to flush. 57675edde07cSBjoern A. Zeeb */ 57685edde07cSBjoern A. Zeeb if (ic == NULL || 57695edde07cSBjoern A. Zeeb (lhw->sc_flags & LKPI_MAC80211_DRV_STARTED) == 0) 57705edde07cSBjoern A. Zeeb return; 57715edde07cSBjoern A. Zeeb 57725edde07cSBjoern A. Zeeb /* Should only happen on the current one? Not seen it late enough. */ 57735edde07cSBjoern A. Zeeb IEEE80211_LOCK(ic); 57745edde07cSBjoern A. Zeeb TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) 57755edde07cSBjoern A. Zeeb ieee80211_scan_flush(vap); 57765edde07cSBjoern A. Zeeb IEEE80211_UNLOCK(ic); 57775edde07cSBjoern A. Zeeb } 57785edde07cSBjoern A. Zeeb 57795edde07cSBjoern A. Zeeb /* -------------------------------------------------------------------------- */ 57805edde07cSBjoern A. Zeeb 57816b4cac81SBjoern A. Zeeb MODULE_VERSION(linuxkpi_wlan, 1); 57826b4cac81SBjoern A. Zeeb MODULE_DEPEND(linuxkpi_wlan, linuxkpi, 1, 1, 1); 57836b4cac81SBjoern A. Zeeb MODULE_DEPEND(linuxkpi_wlan, wlan, 1, 1, 1); 5784