2 * Copyright (c) 2020-2022 The FreeBSD Foundation
3 * Copyright (c) 2020-2022 Bjoern A. Zeeb
5 * This software was developed by Björn Zeeb under sponsorship from
6 * the FreeBSD Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Public functions are called linuxkpi_*().
32 * Internal (static) functions are called lkpi_*().
34 * The internal structures holding metadata over public structures are also
35 * called lkpi_xxx (usually with a member at the end called xxx).
36 * Note: we do not replicate the structure names but the general variable names
37 * for these (e.g., struct hw -> struct lkpi_hw, struct sta -> struct lkpi_sta).
38 * There are macros to access one from the other.
39 * We call the internal versions lxxx (e.g., hw -> lhw, sta -> lsta).
42 #include <sys/cdefs.h>
43 __FBSDID("$FreeBSD$");
45 #include <sys/param.h>
46 #include <sys/types.h>
47 #include <sys/kernel.h>
48 #include <sys/errno.h>
49 #include <sys/malloc.h>
50 #include <sys/module.h>
51 #include <sys/mutex.h>
52 #include <sys/socket.h>
53 #include <sys/sysctl.h>
54 #include <sys/queue.h>
55 #include <sys/taskqueue.h>
58 #include <net/if_var.h>
59 #include <net/if_media.h>
60 #include <net/ethernet.h>
62 #include <net80211/ieee80211_var.h>
63 #include <net80211/ieee80211_proto.h>
64 #include <net80211/ieee80211_ratectl.h>
65 #include <net80211/ieee80211_radiotap.h>
67 #define LINUXKPI_NET80211
68 #include <net/mac80211.h>
70 #include <linux/workqueue.h>
71 #include "linux_80211.h"
73 static MALLOC_DEFINE(M_LKPI80211, "lkpi80211", "LinuxKPI 80211 compat");
75 /* -------------------------------------------------------------------------- */
77 /* Keep public for as long as header files are using it too. */
78 int linuxkpi_debug_80211;
80 #ifdef LINUXKPI_DEBUG_80211
81 SYSCTL_DECL(_compat_linuxkpi);
82 SYSCTL_NODE(_compat_linuxkpi, OID_AUTO, 80211, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
83 "LinuxKPI 802.11 compatibility layer");
85 SYSCTL_INT(_compat_linuxkpi_80211, OID_AUTO, debug, CTLFLAG_RWTUN,
86 &linuxkpi_debug_80211, 0, "LinuxKPI 802.11 debug level");
89 #define D80211_TODO 0x1
91 #ifndef D80211_IMPROVE
92 #define D80211_IMPROVE 0x2
94 #define D80211_TRACE 0x10
95 #define D80211_TRACEOK 0x20
96 #define D80211_TRACE_TX 0x100
97 #define D80211_TRACE_TX_DUMP 0x200
98 #define D80211_TRACE_RX 0x1000
99 #define D80211_TRACE_RX_DUMP 0x2000
100 #define D80211_TRACE_RX_BEACONS 0x4000
101 #define D80211_TRACEX (D80211_TRACE_TX|D80211_TRACE_RX)
102 #define D80211_TRACEX_DUMP (D80211_TRACE_TX_DUMP|D80211_TRACE_RX_DUMP)
103 #define D80211_TRACE_STA 0x10000
104 #define UNIMPLEMENTED if (linuxkpi_debug_80211 & D80211_TODO) \
105 printf("XXX-TODO %s:%d: UNIMPLEMENTED\n", __func__, __LINE__)
106 #define TRACEOK() if (linuxkpi_debug_80211 & D80211_TRACEOK) \
107 printf("XXX-TODO %s:%d: TRACEPOINT\n", __func__, __LINE__)
109 #define UNIMPLEMENTED do { } while (0)
110 #define TRACEOK() do { } while (0)
113 /* #define PREP_TX_INFO_DURATION (IEEE80211_TRANS_WAIT * 1000) */
114 #ifndef PREP_TX_INFO_DURATION
115 #define PREP_TX_INFO_DURATION 0 /* Let the driver do its thing. */
118 /* This is DSAP | SSAP | CTRL | ProtoID/OrgCode{3}. */
119 const uint8_t rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
121 const uint8_t tid_to_mac80211_ac[] = {
131 IEEE80211_AC_VO, /* We treat MGMT as TID 8, which is set as AC_VO */
135 const struct cfg80211_ops linuxkpi_mac80211cfgops = {
137 * XXX TODO need a "glue layer" to link cfg80211 ops to
138 * mac80211 and to the driver or net80211.
139 * Can we pass some on 1:1? Need to compare the (*f)().
143 static struct lkpi_sta *lkpi_find_lsta_by_ni(struct lkpi_vif *,
144 struct ieee80211_node *);
145 static void lkpi_80211_txq_task(void *, int);
146 static void lkpi_ieee80211_free_skb_mbuf(void *);
149 lkpi_lsta_dump(struct lkpi_sta *lsta, struct ieee80211_node *ni,
150 const char *_f, int _l)
153 #ifdef LINUXKPI_DEBUG_80211
154 if ((linuxkpi_debug_80211 & D80211_TRACE_STA) == 0)
159 printf("%s:%d lsta %p ni %p sta %p\n",
160 _f, _l, lsta, ni, &lsta->sta);
162 ieee80211_dump_node(NULL, ni);
163 printf("\ttxq_task txq len %d mtx\n", mbufq_len(&lsta->txq));
164 printf("\tkc %p state %d added_to_drv %d in_mgd %d\n",
165 lsta->kc, lsta->state, lsta->added_to_drv, lsta->in_mgd);
170 lkpi_lsta_remove(struct lkpi_sta *lsta, struct lkpi_vif *lvif)
172 struct ieee80211_node *ni;
176 LKPI_80211_LVIF_LOCK(lvif);
177 TAILQ_REMOVE(&lvif->lsta_head, lsta, lsta_entry);
178 LKPI_80211_LVIF_UNLOCK(lvif);
181 ni->ni_drv_data = NULL;
182 ieee80211_free_node(ni);
184 IMPROVE("free lsta here? We won't have a pointer to it from the node anymore.");
187 static struct lkpi_sta *
188 lkpi_lsta_alloc(struct ieee80211vap *vap, const uint8_t mac[IEEE80211_ADDR_LEN],
189 struct ieee80211_hw *hw, struct ieee80211_node *ni)
191 struct lkpi_sta *lsta;
192 struct lkpi_vif *lvif;
193 struct ieee80211_vif *vif;
194 struct ieee80211_sta *sta;
197 lsta = malloc(sizeof(*lsta) + hw->sta_data_size, M_LKPI80211,
202 lsta->added_to_drv = false;
203 lsta->state = IEEE80211_STA_NOTEXIST;
206 * This needs to be done in node_init() as ieee80211_alloc_node()
207 * will initialise the refcount after us.
209 lsta->ni = ieee80211_ref_node(ni);
211 /* The back-pointer "drv_data" to net80211_node let's us get lsta. */
212 ni->ni_drv_data = lsta;
214 lvif = VAP_TO_LVIF(vap);
215 vif = LVIF_TO_VIF(lvif);
216 sta = LSTA_TO_STA(lsta);
218 IEEE80211_ADDR_COPY(sta->addr, mac);
219 for (tid = 0; tid < nitems(sta->txq); tid++) {
220 struct lkpi_txq *ltxq;
223 * We are neither limiting ourselves to hw.queues here,
224 * nor do we check if driver wants IEEE80211_NUM_TIDS queue.
227 ltxq = malloc(sizeof(*ltxq) + hw->txq_data_size,
228 M_LKPI80211, M_NOWAIT | M_ZERO);
231 ltxq->seen_dequeue = false;
232 skb_queue_head_init(<xq->skbq);
233 /* iwlwifi//mvm/sta.c::tid_to_mac80211_ac[] */
234 if (tid == IEEE80211_NUM_TIDS) {
236 ltxq->txq.ac = IEEE80211_AC_VO;
238 ltxq->txq.ac = tid_to_mac80211_ac[tid & 7];
243 sta->txq[tid] = <xq->txq;
246 /* Deferred TX path. */
247 mtx_init(&lsta->txq_mtx, "lsta_txq", NULL, MTX_DEF);
248 TASK_INIT(&lsta->txq_task, 0, lkpi_80211_txq_task, lsta);
249 mbufq_init(&lsta->txq, IFQ_MAXLEN);
254 for (; tid >= 0; tid--)
255 free(sta->txq[tid], M_LKPI80211);
256 free(lsta, M_LKPI80211);
260 static enum nl80211_band
261 lkpi_net80211_chan_to_nl80211_band(struct ieee80211_channel *c)
264 if (IEEE80211_IS_CHAN_2GHZ(c))
265 return (NL80211_BAND_2GHZ);
266 else if (IEEE80211_IS_CHAN_5GHZ(c))
267 return (NL80211_BAND_5GHZ);
270 return (NL80211_BAND_6GHZ);
272 return (NL80211_BAND_60GHZ);
273 else if (IEEE80211_IS_CHAN_GSM(c))
274 return (NL80211_BAND_XXX);
277 panic("%s: unsupported band. c %p flags %#x\n",
278 __func__, c, c->ic_flags);
282 lkpi_nl80211_band_to_net80211_band(enum nl80211_band band)
285 /* XXX-BZ this is just silly; net80211 is too convoluted. */
286 /* IEEE80211_CHAN_A / _G / .. doesn't really work either. */
288 case NL80211_BAND_2GHZ:
289 return (IEEE80211_CHAN_2GHZ);
291 case NL80211_BAND_5GHZ:
292 return (IEEE80211_CHAN_5GHZ);
294 case NL80211_BAND_60GHZ:
296 case NL80211_BAND_6GHZ:
299 panic("%s: unsupported band %u\n", __func__, band);
307 static enum ieee80211_ac_numbers
308 lkpi_ac_net_to_l80211(int ac)
313 return (IEEE80211_AC_VO);
315 return (IEEE80211_AC_VI);
317 return (IEEE80211_AC_BE);
319 return (IEEE80211_AC_BK);
321 printf("%s: invalid WME_AC_* input: ac = %d\n", __func__, ac);
322 return (IEEE80211_AC_BE);
326 static enum nl80211_iftype
327 lkpi_opmode_to_vif_type(enum ieee80211_opmode opmode)
331 case IEEE80211_M_IBSS:
332 return (NL80211_IFTYPE_ADHOC);
334 case IEEE80211_M_STA:
335 return (NL80211_IFTYPE_STATION);
337 case IEEE80211_M_WDS:
338 return (NL80211_IFTYPE_WDS);
340 case IEEE80211_M_HOSTAP:
341 return (NL80211_IFTYPE_AP);
343 case IEEE80211_M_MONITOR:
344 return (NL80211_IFTYPE_MONITOR);
346 case IEEE80211_M_MBSS:
347 return (NL80211_IFTYPE_MESH_POINT);
349 case IEEE80211_M_AHDEMO:
352 printf("ERROR: %s: unsupported opmode %d\n", __func__, opmode);
355 return (NL80211_IFTYPE_UNSPECIFIED);
360 lkpi_l80211_to_net80211_cyphers(uint32_t wlan_cipher_suite)
363 switch (wlan_cipher_suite) {
364 case WLAN_CIPHER_SUITE_WEP40:
365 return (IEEE80211_CRYPTO_WEP);
366 case WLAN_CIPHER_SUITE_TKIP:
367 return (IEEE80211_CRYPTO_TKIP);
368 case WLAN_CIPHER_SUITE_CCMP:
369 return (IEEE80211_CIPHER_AES_CCM);
370 case WLAN_CIPHER_SUITE_WEP104:
371 return (IEEE80211_CRYPTO_WEP);
372 case WLAN_CIPHER_SUITE_AES_CMAC:
373 case WLAN_CIPHER_SUITE_GCMP:
374 case WLAN_CIPHER_SUITE_GCMP_256:
375 case WLAN_CIPHER_SUITE_CCMP_256:
376 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
377 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
378 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
379 printf("%s: unsupported WLAN Cipher Suite %#08x | %u\n", __func__,
380 wlan_cipher_suite >> 8, wlan_cipher_suite & 0xff);
383 printf("%s: unknown WLAN Cipher Suite %#08x | %u\n", __func__,
384 wlan_cipher_suite >> 8, wlan_cipher_suite & 0xff);
393 lkpi_net80211_to_l80211_cipher_suite(uint32_t cipher, uint8_t keylen)
397 case IEEE80211_CIPHER_TKIP:
398 return (WLAN_CIPHER_SUITE_TKIP);
399 case IEEE80211_CIPHER_AES_CCM:
400 return (WLAN_CIPHER_SUITE_CCMP);
401 case IEEE80211_CIPHER_WEP:
403 return (WLAN_CIPHER_SUITE_WEP40);
405 return (WLAN_CIPHER_SUITE_WEP104);
407 case IEEE80211_CIPHER_AES_OCB:
408 case IEEE80211_CIPHER_TKIPMIC:
409 case IEEE80211_CIPHER_CKIP:
410 case IEEE80211_CIPHER_NONE:
411 printf("%s: unsupported cipher %#010x\n", __func__, cipher);
414 printf("%s: unknown cipher %#010x\n", __func__, cipher);
421 static enum ieee80211_sta_state
422 lkpi_net80211_state_to_sta_state(enum ieee80211_state state)
426 * XXX-BZ The net80211 states are "try to ..", the lkpi8011 states are
427 * "done". Also ASSOC/AUTHORIZED are both "RUN" then?
430 case IEEE80211_S_INIT:
431 return (IEEE80211_STA_NOTEXIST);
432 case IEEE80211_S_SCAN:
433 return (IEEE80211_STA_NONE);
434 case IEEE80211_S_AUTH:
435 return (IEEE80211_STA_AUTH);
436 case IEEE80211_S_ASSOC:
437 return (IEEE80211_STA_ASSOC);
438 case IEEE80211_S_RUN:
439 return (IEEE80211_STA_AUTHORIZED);
440 case IEEE80211_S_CAC:
441 case IEEE80211_S_CSA:
442 case IEEE80211_S_SLEEP:
447 return (IEEE80211_STA_NOTEXIST);
451 static struct linuxkpi_ieee80211_channel *
452 lkpi_find_lkpi80211_chan(struct lkpi_hw *lhw,
453 struct ieee80211_channel *c)
455 struct ieee80211_hw *hw;
456 struct linuxkpi_ieee80211_channel *channels;
457 enum nl80211_band band;
461 band = lkpi_net80211_chan_to_nl80211_band(c);
462 if (hw->wiphy->bands[band] == NULL)
465 nchans = hw->wiphy->bands[band]->n_channels;
469 channels = hw->wiphy->bands[band]->channels;
470 for (i = 0; i < nchans; i++) {
471 if (channels[i].hw_value == c->ic_ieee)
472 return (&channels[i]);
478 static struct linuxkpi_ieee80211_channel *
479 lkpi_get_lkpi80211_chan(struct ieee80211com *ic, struct ieee80211_node *ni)
481 struct linuxkpi_ieee80211_channel *chan;
482 struct ieee80211_channel *c;
486 if (ni != NULL && ni->ni_chan != IEEE80211_CHAN_ANYC)
488 else if (ic->ic_bsschan != IEEE80211_CHAN_ANYC)
490 else if (ic->ic_curchan != IEEE80211_CHAN_ANYC)
495 if (c != NULL && c != IEEE80211_CHAN_ANYC) {
497 chan = lkpi_find_lkpi80211_chan(lhw, c);
503 struct linuxkpi_ieee80211_channel *
504 linuxkpi_ieee80211_get_channel(struct wiphy *wiphy, uint32_t freq)
506 enum nl80211_band band;
508 for (band = 0; band < NUM_NL80211_BANDS; band++) {
509 struct ieee80211_supported_band *supband;
510 struct linuxkpi_ieee80211_channel *channels;
513 supband = wiphy->bands[band];
514 if (supband == NULL || supband->n_channels == 0)
517 channels = supband->channels;
518 for (i = 0; i < supband->n_channels; i++) {
519 if (channels[i].center_freq == freq)
520 return (&channels[i]);
529 _lkpi_iv_key_set_delete(struct ieee80211vap *vap, const struct ieee80211_key *k,
530 enum set_key_cmd cmd)
532 struct ieee80211com *ic;
534 struct ieee80211_hw *hw;
535 struct lkpi_vif *lvif;
536 struct ieee80211_vif *vif;
537 struct ieee80211_sta *sta;
538 struct ieee80211_node *ni;
539 struct ieee80211_key_conf *kc;
542 /* XXX TODO Check (k->wk_flags & IEEE80211_KEY_SWENCRYPT) and don't upload to driver/hw? */
547 lvif = VAP_TO_LVIF(vap);
548 vif = LVIF_TO_VIF(lvif);
550 memset(&kc, 0, sizeof(kc));
551 kc = malloc(sizeof(*kc) + k->wk_keylen, M_LKPI80211, M_WAITOK | M_ZERO);
552 kc->cipher = lkpi_net80211_to_l80211_cipher_suite(
553 k->wk_cipher->ic_cipher, k->wk_keylen);
554 kc->keyidx = k->wk_keyix;
556 kc->hw_key_idx = /* set by hw and needs to be passed for TX */;
558 atomic64_set(&kc->tx_pn, k->wk_keytsc);
559 kc->keylen = k->wk_keylen;
560 memcpy(kc->key, k->wk_key, k->wk_keylen);
562 switch (kc->cipher) {
563 case WLAN_CIPHER_SUITE_CCMP:
564 kc->iv_len = k->wk_cipher->ic_header;
565 kc->icv_len = k->wk_cipher->ic_trailer;
567 case WLAN_CIPHER_SUITE_TKIP:
574 sta = ieee80211_find_sta(vif, ni->ni_bssid);
576 struct lkpi_sta *lsta;
578 lsta = STA_TO_LSTA(sta);
582 error = lkpi_80211_mo_set_key(hw, cmd, vif, sta, kc);
584 /* XXX-BZ leaking kc currently */
585 ic_printf(ic, "%s: set_key failed: %d\n", __func__, error);
588 ic_printf(ic, "%s: set_key succeeded: keyidx %u hw_key_idx %u "
589 "flags %#10x\n", __func__,
590 kc->keyidx, kc->hw_key_idx, kc->flags);
596 lkpi_iv_key_delete(struct ieee80211vap *vap, const struct ieee80211_key *k)
599 /* XXX-BZ one day we should replace this iterating over VIFs, or node list? */
600 return (_lkpi_iv_key_set_delete(vap, k, DISABLE_KEY));
603 lkpi_iv_key_set(struct ieee80211vap *vap, const struct ieee80211_key *k)
606 return (_lkpi_iv_key_set_delete(vap, k, SET_KEY));
611 lkpi_ic_update_mcast_copy(void *arg, struct sockaddr_dl *sdl, u_int cnt)
613 struct netdev_hw_addr_list *mc_list;
614 struct netdev_hw_addr *addr;
616 KASSERT(arg != NULL && sdl != NULL, ("%s: arg %p sdl %p cnt %u\n",
617 __func__, arg, sdl, cnt));
620 /* If it is on the list already skip it. */
621 netdev_hw_addr_list_for_each(addr, mc_list) {
622 if (!memcmp(addr->addr, LLADDR(sdl), sdl->sdl_alen))
626 addr = malloc(sizeof(*addr), M_LKPI80211, M_NOWAIT | M_ZERO);
630 INIT_LIST_HEAD(&addr->addr_list);
631 memcpy(addr->addr, LLADDR(sdl), sdl->sdl_alen);
632 /* XXX this should be a netdev function? */
633 list_add(&addr->addr_list, &mc_list->addr_list);
636 #ifdef LINUXKPI_DEBUG_80211
637 if (linuxkpi_debug_80211 & D80211_TRACE)
638 printf("%s:%d: mc_list count %d: added %6D\n",
639 __func__, __LINE__, mc_list->count, addr->addr, ":");
646 lkpi_update_mcast_filter(struct ieee80211com *ic, bool force)
649 struct ieee80211_hw *hw;
650 struct netdev_hw_addr_list mc_list;
651 struct list_head *le, *next;
652 struct netdev_hw_addr *addr;
653 struct ieee80211vap *vap;
655 unsigned int changed_flags, total_flags;
659 if (lhw->ops->prepare_multicast == NULL ||
660 lhw->ops->configure_filter == NULL)
663 if (!lhw->update_mc && !force)
666 changed_flags = total_flags = 0;
668 INIT_LIST_HEAD(&mc_list.addr_list);
669 if (ic->ic_allmulti == 0) {
670 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
671 if_foreach_llmaddr(vap->iv_ifp,
672 lkpi_ic_update_mcast_copy, &mc_list);
674 changed_flags |= FIF_ALLMULTI;
678 mc = lkpi_80211_mo_prepare_multicast(hw, &mc_list);
680 * XXX-BZ make sure to get this sorted what is a change,
681 * what gets all set; what was already set?
683 total_flags = changed_flags;
684 lkpi_80211_mo_configure_filter(hw, changed_flags, &total_flags, mc);
686 #ifdef LINUXKPI_DEBUG_80211
687 if (linuxkpi_debug_80211 & D80211_TRACE)
688 printf("%s: changed_flags %#06x count %d total_flags %#010x\n",
689 __func__, changed_flags, mc_list.count, total_flags);
692 if (mc_list.count != 0) {
693 list_for_each_safe(le, next, &mc_list.addr_list) {
694 addr = list_entry(le, struct netdev_hw_addr, addr_list);
695 free(addr, M_LKPI80211);
699 KASSERT(mc_list.count == 0, ("%s: mc_list %p count %d != 0\n",
700 __func__, &mc_list, mc_list.count));
703 static enum ieee80211_bss_changed
704 lkpi_update_dtim_tsf(struct ieee80211_vif *vif, struct ieee80211_node *ni,
705 struct ieee80211vap *vap, const char *_f, int _l)
707 enum ieee80211_bss_changed bss_changed;
711 #ifdef LINUXKPI_DEBUG_80211
712 if (linuxkpi_debug_80211 & D80211_TRACE)
713 printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u "
714 "dtim_period %u sync_dtim_count %u sync_tsf %ju "
715 "sync_device_ts %u bss_changed %#08x\n",
716 __func__, __LINE__, _f, _l,
717 vif->bss_conf.assoc, vif->bss_conf.aid,
718 vif->bss_conf.beacon_int, vif->bss_conf.dtim_period,
719 vif->bss_conf.sync_dtim_count,
720 (uintmax_t)vif->bss_conf.sync_tsf,
721 vif->bss_conf.sync_device_ts,
725 if (vif->bss_conf.beacon_int != ni->ni_intval) {
726 vif->bss_conf.beacon_int = ni->ni_intval;
727 /* iwlwifi FW bug workaround; iwl_mvm_mac_sta_state. */
728 if (vif->bss_conf.beacon_int < 16)
729 vif->bss_conf.beacon_int = 16;
730 bss_changed |= BSS_CHANGED_BEACON_INT;
732 if (vif->bss_conf.dtim_period != vap->iv_dtim_period &&
733 vap->iv_dtim_period > 0) {
734 vif->bss_conf.dtim_period = vap->iv_dtim_period;
735 bss_changed |= BSS_CHANGED_BEACON_INFO;
738 vif->bss_conf.sync_dtim_count = vap->iv_dtim_count;
739 vif->bss_conf.sync_tsf = le64toh(ni->ni_tstamp.tsf);
740 /* vif->bss_conf.sync_device_ts = set in linuxkpi_ieee80211_rx. */
742 #ifdef LINUXKPI_DEBUG_80211
743 if (linuxkpi_debug_80211 & D80211_TRACE)
744 printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u "
745 "dtim_period %u sync_dtim_count %u sync_tsf %ju "
746 "sync_device_ts %u bss_changed %#08x\n",
747 __func__, __LINE__, _f, _l,
748 vif->bss_conf.assoc, vif->bss_conf.aid,
749 vif->bss_conf.beacon_int, vif->bss_conf.dtim_period,
750 vif->bss_conf.sync_dtim_count,
751 (uintmax_t)vif->bss_conf.sync_tsf,
752 vif->bss_conf.sync_device_ts,
756 return (bss_changed);
760 lkpi_stop_hw_scan(struct lkpi_hw *lhw, struct ieee80211_vif *vif)
762 struct ieee80211_hw *hw;
765 if ((lhw->scan_flags & LKPI_SCAN_RUNNING) == 0)
770 IEEE80211_UNLOCK(lhw->ic);
771 LKPI_80211_LHW_LOCK(lhw);
772 /* Need to cancel the scan. */
773 lkpi_80211_mo_cancel_hw_scan(hw, vif);
775 /* Need to make sure we see ieee80211_scan_completed. */
776 error = msleep(lhw, &lhw->mtx, 0, "lhwscanstop", hz/2);
777 LKPI_80211_LHW_UNLOCK(lhw);
778 IEEE80211_LOCK(lhw->ic);
780 if ((lhw->scan_flags & LKPI_SCAN_RUNNING) != 0)
781 ic_printf(lhw->ic, "%s: failed to cancel scan: %d (%p, %p)\n",
782 __func__, error, lhw, vif);
786 lkpi_hw_conf_idle(struct ieee80211_hw *hw, bool new)
792 old = hw->conf.flags & IEEE80211_CONF_IDLE;
796 hw->conf.flags ^= IEEE80211_CONF_IDLE;
797 error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_IDLE);
798 if (error != 0 && error != EOPNOTSUPP) {
800 ic_printf(lhw->ic, "ERROR: %s: config %#0x returned %d\n",
801 __func__, IEEE80211_CONF_CHANGE_IDLE, error);
806 lkpi_disassoc(struct ieee80211_sta *sta, struct ieee80211_vif *vif,
810 if (vif->bss_conf.assoc) {
811 struct ieee80211_hw *hw;
812 enum ieee80211_bss_changed changed;
814 lhw->update_mc = true;
815 lkpi_update_mcast_filter(lhw->ic, true);
818 vif->bss_conf.assoc = false;
819 vif->bss_conf.aid = 0;
820 changed |= BSS_CHANGED_ASSOC;
822 * This will remove the sta from firmware for iwlwifi.
823 * So confusing that they use state and flags and ... ^%$%#%$^.
827 lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf,
830 lkpi_hw_conf_idle(hw, true);
835 lkpi_wake_tx_queues(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
836 bool dequeue_seen, bool no_emptyq)
838 struct lkpi_txq *ltxq;
841 /* Wake up all queues to know they are allocated in the driver. */
842 for (tid = 0; tid < nitems(sta->txq); tid++) {
844 if (tid == IEEE80211_NUM_TIDS) {
845 IMPROVE("station specific?");
846 if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ))
848 } else if (tid >= hw->queues)
851 if (sta->txq[tid] == NULL)
854 ltxq = TXQ_TO_LTXQ(sta->txq[tid]);
855 if (dequeue_seen && !ltxq->seen_dequeue)
858 if (no_emptyq && skb_queue_empty(<xq->skbq))
861 lkpi_80211_mo_wake_tx_queue(hw, sta->txq[tid]);
865 /* -------------------------------------------------------------------------- */
868 lkpi_sta_state_do_nada(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
874 /* lkpi_iv_newstate() handles the stop scan case generally. */
875 #define lkpi_sta_scan_to_init(_v, _n, _a) lkpi_sta_state_do_nada(_v, _n, _a)
878 lkpi_sta_scan_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
880 struct linuxkpi_ieee80211_channel *chan;
881 struct ieee80211_chanctx_conf *conf;
883 struct ieee80211_hw *hw;
884 struct lkpi_vif *lvif;
885 struct ieee80211_vif *vif;
886 struct ieee80211_node *ni;
887 struct lkpi_sta *lsta;
888 struct ieee80211_sta *sta;
889 enum ieee80211_bss_changed bss_changed;
890 struct ieee80211_prep_tx_info prep_tx_info;
894 chan = lkpi_get_lkpi80211_chan(vap->iv_ic, vap->iv_bss);
896 ic_printf(vap->iv_ic, "%s: failed to get channel\n", __func__);
900 lhw = vap->iv_ic->ic_softc;
902 lvif = VAP_TO_LVIF(vap);
903 vif = LVIF_TO_VIF(lvif);
905 ni = ieee80211_ref_node(vap->iv_bss);
907 IEEE80211_UNLOCK(vap->iv_ic);
909 /* Add chanctx (or if exists, change it). */
910 if (vif->chanctx_conf != NULL) {
911 conf = vif->chanctx_conf;
912 IMPROVE("diff changes for changed, working on live copy, rcu");
914 /* Keep separate alloc as in Linux this is rcu managed? */
915 conf = malloc(sizeof(*conf) + hw->chanctx_data_size,
916 M_LKPI80211, M_WAITOK | M_ZERO);
919 conf->rx_chains_dynamic = 1;
920 conf->rx_chains_static = 1;
921 conf->radar_enabled =
922 (chan->flags & IEEE80211_CHAN_RADAR) ? true : false;
923 conf->def.chan = chan;
924 conf->def.width = NL80211_CHAN_WIDTH_20_NOHT;
925 conf->def.center_freq1 = chan->center_freq;
926 conf->def.center_freq2 = 0;
928 conf->min_def.chan = chan;
929 conf->min_def.width = NL80211_CHAN_WIDTH_20_NOHT;
930 conf->min_def.center_freq1 = chan->center_freq;
931 conf->min_def.center_freq2 = 0;
932 IMPROVE("currently 20_NOHT only");
935 if (vif->chanctx_conf != NULL) {
936 changed = IEEE80211_CHANCTX_CHANGE_MIN_WIDTH;
937 changed |= IEEE80211_CHANCTX_CHANGE_RADAR;
938 changed |= IEEE80211_CHANCTX_CHANGE_RX_CHAINS;
939 changed |= IEEE80211_CHANCTX_CHANGE_WIDTH;
940 lkpi_80211_mo_change_chanctx(hw, conf, changed);
942 error = lkpi_80211_mo_add_chanctx(hw, conf);
943 if (error == 0 || error == EOPNOTSUPP) {
944 vif->bss_conf.chandef.chan = conf->def.chan;
945 vif->bss_conf.chandef.width = conf->def.width;
946 vif->bss_conf.chandef.center_freq1 =
947 conf->def.center_freq1;
948 vif->bss_conf.chandef.center_freq2 =
949 conf->def.center_freq2;
953 /* Assign vif chanctx. */
955 error = lkpi_80211_mo_assign_vif_chanctx(hw, vif, conf);
956 if (error == EOPNOTSUPP)
959 lkpi_80211_mo_remove_chanctx(hw, conf);
960 free(conf, M_LKPI80211);
964 IMPROVE("update radiotap chan fields too");
966 /* Set bss info (bss_info_changed). */
968 IEEE80211_ADDR_COPY(vif->bss_conf.bssid, ni->ni_bssid);
969 bss_changed |= BSS_CHANGED_BSSID;
970 vif->bss_conf.txpower = ni->ni_txpower;
971 bss_changed |= BSS_CHANGED_TXPOWER;
972 vif->bss_conf.idle = false;
973 bss_changed |= BSS_CHANGED_IDLE;
975 /* Should almost assert it is this. */
976 vif->bss_conf.assoc = false;
977 vif->bss_conf.aid = 0;
979 bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__);
982 IMPROVE("bss info: not all needs to come now and rates are missing");
983 lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed);
986 * This is a bandaid for now. If we went through (*iv_update_bss)()
987 * and then removed the lsta we end up here without a lsta and have
988 * to manually allocate and link it in as lkpi_ic_node_alloc()/init()
990 * XXX-BZ I do not like this but currently we have no good way of
991 * intercepting the bss swap and state changes and packets going out
992 * workflow so live with this. It is a compat layer after all.
994 if (ni->ni_drv_data == NULL) {
995 lsta = lkpi_lsta_alloc(vap, ni->ni_macaddr, hw, ni);
1000 lsta->ni = ieee80211_ref_node(ni);
1001 LKPI_80211_LVIF_LOCK(lvif);
1002 TAILQ_INSERT_TAIL(&lvif->lsta_head, lsta, lsta_entry);
1003 LKPI_80211_LVIF_UNLOCK(lvif);
1005 lsta = ni->ni_drv_data;
1007 /* Add (or adjust) sta and change state (from NOTEXIST) to NONE. */
1008 KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
1009 KASSERT(lsta->state == IEEE80211_STA_NOTEXIST, ("%s: lsta %p state not "
1010 "NOTEXIST: %#x\n", __func__, lsta, lsta->state));
1011 sta = LSTA_TO_STA(lsta);
1012 error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_NONE);
1014 IMPROVE("do we need to undo the chan ctx?");
1018 lsta->added_to_drv = true; /* mo manages. */
1021 lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
1024 * Wakeup all queues now that sta is there so we have as much time to
1025 * possibly prepare the queue in the driver to be ready for the 1st
1026 * packet; lkpi_80211_txq_tx_one() still has a workaround as there
1027 * is no guarantee or way to check.
1028 * XXX-BZ and by now we know that this does not work on all drivers
1031 lkpi_wake_tx_queues(hw, sta, false, false);
1036 for (i = 3 * (hw->queues + 1); i > 0; i--) {
1037 struct lkpi_txq *ltxq;
1041 /* Wake up all queues to know they are allocated in the driver. */
1042 for (tid = 0; tid < nitems(sta->txq); tid++) {
1044 if (tid == IEEE80211_NUM_TIDS) {
1045 IMPROVE("station specific?");
1046 if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ))
1048 } else if (tid >= hw->queues)
1051 if (sta->txq[tid] == NULL)
1054 ltxq = TXQ_TO_LTXQ(sta->txq[tid]);
1055 if (!ltxq->seen_dequeue)
1060 #ifdef LINUXKPI_DEBUG_80211
1062 ic_printf(vap->iv_ic, "%s: waiting for %d queues "
1063 "to be allocated by driver\n", __func__, count);
1065 pause("lkpi80211txq", hz/10);
1067 #ifdef LINUXKPI_DEBUG_80211
1069 ic_printf(vap->iv_ic, "%s: %d queues still not "
1070 "allocated by driver\n", __func__, count);
1074 /* Start mgd_prepare_tx. */
1075 memset(&prep_tx_info, 0, sizeof(prep_tx_info));
1076 prep_tx_info.duration = PREP_TX_INFO_DURATION;
1077 lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info);
1078 lsta->in_mgd = true;
1081 * What is going to happen next:
1082 * - <twiddle> .. we should end up in "auth_to_assoc"
1084 * - update sta_state (NONE to AUTH)
1086 * (ideally we'd do that on a callback for something else ...)
1090 IEEE80211_LOCK(vap->iv_ic);
1092 ieee80211_free_node(ni);
1097 lkpi_sta_auth_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
1099 struct lkpi_hw *lhw;
1100 struct ieee80211_hw *hw;
1101 struct lkpi_vif *lvif;
1102 struct ieee80211_vif *vif;
1103 struct ieee80211_node *ni;
1104 struct lkpi_sta *lsta;
1105 struct ieee80211_sta *sta;
1106 struct ieee80211_prep_tx_info prep_tx_info;
1109 lhw = vap->iv_ic->ic_softc;
1110 hw = LHW_TO_HW(lhw);
1111 lvif = VAP_TO_LVIF(vap);
1112 vif = LVIF_TO_VIF(lvif);
1114 /* Keep ni around. */
1115 ni = ieee80211_ref_node(vap->iv_bss);
1116 lsta = ni->ni_drv_data;
1117 sta = LSTA_TO_STA(lsta);
1119 lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
1121 IEEE80211_UNLOCK(vap->iv_ic);
1124 lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true);
1126 /* Wake tx queues to get packet(s) out. */
1127 lkpi_wake_tx_queues(hw, sta, true, true);
1129 /* flush, no drop */
1130 lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false);
1132 /* End mgd_complete_tx. */
1134 memset(&prep_tx_info, 0, sizeof(prep_tx_info));
1135 prep_tx_info.success = false;
1136 lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info);
1137 lsta->in_mgd = false;
1140 /* sync_rx_queues */
1141 lkpi_80211_mo_sync_rx_queues(hw);
1143 /* sta_pre_rcu_remove */
1144 lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta);
1146 /* Take the station down. */
1148 /* Adjust sta and change state (from NONE) to NOTEXIST. */
1149 KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
1150 KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not "
1151 "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg));
1152 error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_NOTEXIST);
1154 IMPROVE("do we need to undo the chan ctx?");
1158 lsta->added_to_drv = false; /* mo manages. */
1161 lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
1163 lkpi_lsta_remove(lsta, lvif);
1167 /* Take the chan ctx down. */
1168 if (vif->chanctx_conf != NULL) {
1169 struct ieee80211_chanctx_conf *conf;
1171 conf = vif->chanctx_conf;
1172 /* Remove vif context. */
1173 lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->chanctx_conf);
1174 /* NB: vif->chanctx_conf is NULL now. */
1176 /* Remove chan ctx. */
1177 lkpi_80211_mo_remove_chanctx(hw, conf);
1178 free(conf, M_LKPI80211);
1182 IEEE80211_LOCK(vap->iv_ic);
1184 ieee80211_free_node(ni);
1189 lkpi_sta_auth_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
1193 error = lkpi_sta_auth_to_scan(vap, nstate, arg);
1195 error = lkpi_sta_scan_to_init(vap, nstate, arg);
1200 lkpi_sta_auth_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
1202 struct lkpi_hw *lhw;
1203 struct ieee80211_hw *hw;
1204 struct lkpi_vif *lvif;
1205 struct ieee80211_vif *vif;
1206 struct ieee80211_node *ni;
1207 struct lkpi_sta *lsta;
1208 struct ieee80211_sta *sta;
1209 struct ieee80211_prep_tx_info prep_tx_info;
1212 lhw = vap->iv_ic->ic_softc;
1213 hw = LHW_TO_HW(lhw);
1214 lvif = VAP_TO_LVIF(vap);
1215 vif = LVIF_TO_VIF(lvif);
1217 IEEE80211_UNLOCK(vap->iv_ic);
1221 IMPROVE("event callback");
1223 /* Update sta_state (NONE to AUTH). */
1224 ni = ieee80211_ref_node(vap->iv_bss);
1225 lsta = ni->ni_drv_data;
1226 KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
1227 KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not "
1228 "NONE: %#x\n", __func__, lsta, lsta->state));
1229 sta = LSTA_TO_STA(lsta);
1230 error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_AUTH);
1234 /* End mgd_complete_tx. */
1236 memset(&prep_tx_info, 0, sizeof(prep_tx_info));
1237 prep_tx_info.success = true;
1238 lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info);
1239 lsta->in_mgd = false;
1242 /* Now start assoc. */
1244 /* Start mgd_prepare_tx. */
1245 if (!lsta->in_mgd) {
1246 memset(&prep_tx_info, 0, sizeof(prep_tx_info));
1247 prep_tx_info.duration = PREP_TX_INFO_DURATION;
1248 lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info);
1249 lsta->in_mgd = true;
1252 /* Wake tx queue to get packet out. */
1253 lkpi_wake_tx_queues(hw, sta, true, true);
1256 * <twiddle> .. we end up in "assoc_to_run"
1257 * - update sta_state (AUTH to ASSOC)
1259 * - bss_info_changed (assoc, aid, ssid, ..)
1260 * - change_chanctx (if needed)
1266 IEEE80211_LOCK(vap->iv_ic);
1268 ieee80211_free_node(ni);
1272 /* auth_to_auth, assoc_to_assoc. */
1274 lkpi_sta_a_to_a(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
1276 struct lkpi_hw *lhw;
1277 struct ieee80211_hw *hw;
1278 struct lkpi_vif *lvif;
1279 struct ieee80211_vif *vif;
1280 struct ieee80211_node *ni;
1281 struct lkpi_sta *lsta;
1282 struct ieee80211_prep_tx_info prep_tx_info;
1284 lhw = vap->iv_ic->ic_softc;
1285 hw = LHW_TO_HW(lhw);
1286 lvif = VAP_TO_LVIF(vap);
1287 vif = LVIF_TO_VIF(lvif);
1289 ni = ieee80211_ref_node(vap->iv_bss);
1291 IEEE80211_UNLOCK(vap->iv_ic);
1292 lsta = ni->ni_drv_data;
1294 IMPROVE("event callback?");
1296 /* End mgd_complete_tx. */
1298 memset(&prep_tx_info, 0, sizeof(prep_tx_info));
1299 prep_tx_info.success = false;
1300 lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info);
1301 lsta->in_mgd = false;
1304 /* Now start assoc. */
1306 /* Start mgd_prepare_tx. */
1307 if (!lsta->in_mgd) {
1308 memset(&prep_tx_info, 0, sizeof(prep_tx_info));
1309 prep_tx_info.duration = PREP_TX_INFO_DURATION;
1310 lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info);
1311 lsta->in_mgd = true;
1314 IEEE80211_LOCK(vap->iv_ic);
1316 ieee80211_free_node(ni);
1322 _lkpi_sta_assoc_to_down(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
1324 struct lkpi_hw *lhw;
1325 struct ieee80211_hw *hw;
1326 struct lkpi_vif *lvif;
1327 struct ieee80211_vif *vif;
1328 struct ieee80211_node *ni;
1329 struct lkpi_sta *lsta;
1330 struct ieee80211_sta *sta;
1331 struct ieee80211_prep_tx_info prep_tx_info;
1332 enum ieee80211_bss_changed bss_changed;
1335 lhw = vap->iv_ic->ic_softc;
1336 hw = LHW_TO_HW(lhw);
1337 lvif = VAP_TO_LVIF(vap);
1338 vif = LVIF_TO_VIF(lvif);
1340 /* Keep ni around. */
1341 ni = ieee80211_ref_node(vap->iv_bss);
1342 lsta = ni->ni_drv_data;
1343 sta = LSTA_TO_STA(lsta);
1345 lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
1347 IEEE80211_UNLOCK(vap->iv_ic);
1350 lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true);
1352 IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?");
1353 if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) &&
1355 memset(&prep_tx_info, 0, sizeof(prep_tx_info));
1356 prep_tx_info.duration = PREP_TX_INFO_DURATION;
1357 lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info);
1358 lsta->in_mgd = true;
1361 IEEE80211_LOCK(vap->iv_ic);
1363 /* Call iv_newstate first so we get potential DISASSOC packet out. */
1364 error = lvif->iv_newstate(vap, nstate, arg);
1368 IEEE80211_UNLOCK(vap->iv_ic);
1370 lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
1372 /* Wake tx queues to get packet(s) out. */
1373 lkpi_wake_tx_queues(hw, sta, true, true);
1375 /* flush, no drop */
1376 lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false);
1378 /* End mgd_complete_tx. */
1380 memset(&prep_tx_info, 0, sizeof(prep_tx_info));
1381 prep_tx_info.success = false;
1382 lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info);
1383 lsta->in_mgd = false;
1386 /* sync_rx_queues */
1387 lkpi_80211_mo_sync_rx_queues(hw);
1389 /* sta_pre_rcu_remove */
1390 lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta);
1392 /* Take the station down. */
1394 /* Update sta and change state (from AUTH) to NONE. */
1395 KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
1396 KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not "
1397 "AUTH: %#x\n", __func__, lsta, lsta->state));
1398 error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_NONE);
1402 lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
1404 /* Adjust sta and change state (from NONE) to NOTEXIST. */
1405 KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
1406 KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not "
1407 "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg));
1408 error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_NOTEXIST);
1410 IMPROVE("do we need to undo the chan ctx?");
1414 lsta->added_to_drv = false; /* mo manages. */
1417 lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
1419 /* Update bss info (bss_info_changed) (assoc, aid, ..). */
1420 /* We need to do this now, can only do after sta is IEEE80211_STA_NOTEXIST. */
1421 lkpi_disassoc(sta, vif, lhw);
1423 IMPROVE("Any bss_info changes to announce?");
1425 vif->bss_conf.qos = 0;
1426 bss_changed |= BSS_CHANGED_QOS;
1427 vif->bss_conf.ssid_len = 0;
1428 memset(vif->bss_conf.ssid, '\0', sizeof(vif->bss_conf.ssid));
1429 bss_changed |= BSS_CHANGED_BSSID;
1430 lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed);
1432 lkpi_lsta_remove(lsta, lvif);
1436 /* Take the chan ctx down. */
1437 if (vif->chanctx_conf != NULL) {
1438 struct ieee80211_chanctx_conf *conf;
1440 conf = vif->chanctx_conf;
1441 /* Remove vif context. */
1442 lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->chanctx_conf);
1443 /* NB: vif->chanctx_conf is NULL now. */
1445 /* Remove chan ctx. */
1446 lkpi_80211_mo_remove_chanctx(hw, conf);
1447 free(conf, M_LKPI80211);
1452 IEEE80211_LOCK(vap->iv_ic);
1455 ieee80211_free_node(ni);
1460 lkpi_sta_assoc_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
1464 error = _lkpi_sta_assoc_to_down(vap, nstate, arg);
1465 if (error != 0 && error != EALREADY)
1468 /* At this point iv_bss is long a new node! */
1470 error |= lkpi_sta_scan_to_auth(vap, nstate, 0);
1475 lkpi_sta_assoc_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
1479 error = _lkpi_sta_assoc_to_down(vap, nstate, arg);
1484 lkpi_sta_assoc_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
1488 error = _lkpi_sta_assoc_to_down(vap, nstate, arg);
1493 lkpi_sta_assoc_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
1495 struct lkpi_hw *lhw;
1496 struct ieee80211_hw *hw;
1497 struct lkpi_vif *lvif;
1498 struct ieee80211_vif *vif;
1499 struct ieee80211_node *ni;
1500 struct lkpi_sta *lsta;
1501 struct ieee80211_sta *sta;
1502 struct ieee80211_prep_tx_info prep_tx_info;
1503 enum ieee80211_bss_changed bss_changed;
1506 lhw = vap->iv_ic->ic_softc;
1507 hw = LHW_TO_HW(lhw);
1508 lvif = VAP_TO_LVIF(vap);
1509 vif = LVIF_TO_VIF(lvif);
1511 IEEE80211_UNLOCK(vap->iv_ic);
1514 IMPROVE("ponder some of this moved to ic_newassoc, scan_assoc_success, "
1515 "and to lesser extend ieee80211_notify_node_join");
1518 /* Update sta_state (AUTH to ASSOC) and set aid. */
1519 ni = ieee80211_ref_node(vap->iv_bss);
1520 lsta = ni->ni_drv_data;
1521 KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
1522 KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not "
1523 "AUTH: %#x\n", __func__, lsta, lsta->state));
1524 sta = LSTA_TO_STA(lsta);
1525 sta->aid = IEEE80211_NODE_AID(ni);
1526 error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_ASSOC);
1530 IMPROVE("wme / conf_tx [all]");
1532 /* Update bss info (bss_info_changed) (assoc, aid, ..). */
1534 if (!vif->bss_conf.assoc || vif->bss_conf.aid != IEEE80211_NODE_AID(ni)) {
1535 vif->bss_conf.assoc = true;
1536 vif->bss_conf.aid = IEEE80211_NODE_AID(ni);
1537 bss_changed |= BSS_CHANGED_ASSOC;
1539 /* We set SSID but this is not BSSID! */
1540 vif->bss_conf.ssid_len = ni->ni_esslen;
1541 memcpy(vif->bss_conf.ssid, ni->ni_essid, ni->ni_esslen);
1542 if ((vap->iv_flags & IEEE80211_F_SHPREAMBLE) !=
1543 vif->bss_conf.use_short_preamble) {
1544 vif->bss_conf.use_short_preamble ^= 1;
1545 /* bss_changed |= BSS_CHANGED_??? */
1547 if ((vap->iv_flags & IEEE80211_F_SHSLOT) !=
1548 vif->bss_conf.use_short_slot) {
1549 vif->bss_conf.use_short_slot ^= 1;
1550 /* bss_changed |= BSS_CHANGED_??? */
1552 if ((ni->ni_flags & IEEE80211_NODE_QOS) !=
1553 vif->bss_conf.qos) {
1554 vif->bss_conf.qos ^= 1;
1555 bss_changed |= BSS_CHANGED_QOS;
1558 bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__);
1560 lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed);
1562 /* - change_chanctx (if needed)
1566 /* End mgd_complete_tx. */
1568 memset(&prep_tx_info, 0, sizeof(prep_tx_info));
1569 prep_tx_info.success = true;
1570 lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info);
1571 lsta->in_mgd = false;
1574 lkpi_hw_conf_idle(hw, false);
1580 * - set_default_unicast_key
1582 * - ipv6_addr_change (?)
1584 /* Prepare_multicast && configure_filter. */
1585 lhw->update_mc = true;
1586 lkpi_update_mcast_filter(vap->iv_ic, true);
1588 if (!ieee80211_node_is_authorized(ni)) {
1589 IMPROVE("net80211 does not consider node authorized");
1592 /* Update sta_state (ASSOC to AUTHORIZED). */
1593 ni = ieee80211_ref_node(vap->iv_bss);
1594 lsta = ni->ni_drv_data;
1595 KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
1596 KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not "
1597 "ASSOC: %#x\n", __func__, lsta, lsta->state));
1598 sta = LSTA_TO_STA(lsta);
1599 error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_AUTHORIZED);
1601 IMPROVE("undo some changes?");
1606 * - bss_info_changed
1607 * - set_rekey_data (?)
1609 * And now we should be passing packets.
1611 IMPROVE("Need that bssid setting, and the keys");
1614 bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__);
1615 lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed);
1618 IEEE80211_LOCK(vap->iv_ic);
1620 ieee80211_free_node(ni);
1625 lkpi_sta_auth_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
1629 error = lkpi_sta_auth_to_assoc(vap, nstate, arg);
1631 error = lkpi_sta_assoc_to_run(vap, nstate, arg);
1636 lkpi_sta_run_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
1638 struct lkpi_hw *lhw;
1639 struct ieee80211_hw *hw;
1640 struct lkpi_vif *lvif;
1641 struct ieee80211_vif *vif;
1642 struct ieee80211_node *ni;
1643 struct lkpi_sta *lsta;
1644 struct ieee80211_sta *sta;
1645 struct ieee80211_prep_tx_info prep_tx_info;
1647 enum ieee80211_bss_changed bss_changed;
1651 lhw = vap->iv_ic->ic_softc;
1652 hw = LHW_TO_HW(lhw);
1653 lvif = VAP_TO_LVIF(vap);
1654 vif = LVIF_TO_VIF(lvif);
1656 /* Keep ni around. */
1657 ni = ieee80211_ref_node(vap->iv_bss);
1658 lsta = ni->ni_drv_data;
1659 sta = LSTA_TO_STA(lsta);
1661 lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
1663 IEEE80211_UNLOCK(vap->iv_ic);
1666 lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true);
1668 IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?");
1669 if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) &&
1671 memset(&prep_tx_info, 0, sizeof(prep_tx_info));
1672 prep_tx_info.duration = PREP_TX_INFO_DURATION;
1673 lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info);
1674 lsta->in_mgd = true;
1677 IEEE80211_LOCK(vap->iv_ic);
1679 /* Call iv_newstate first so we get potential DISASSOC packet out. */
1680 error = lvif->iv_newstate(vap, nstate, arg);
1684 IEEE80211_UNLOCK(vap->iv_ic);
1686 lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
1688 /* Wake tx queues to get packet(s) out. */
1689 lkpi_wake_tx_queues(hw, sta, true, true);
1691 /* flush, no drop */
1692 lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false);
1694 /* End mgd_complete_tx. */
1696 memset(&prep_tx_info, 0, sizeof(prep_tx_info));
1697 prep_tx_info.success = false;
1698 lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info);
1699 lsta->in_mgd = false;
1703 /* sync_rx_queues */
1704 lkpi_80211_mo_sync_rx_queues(hw);
1706 /* sta_pre_rcu_remove */
1707 lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta);
1710 /* Take the station down. */
1712 /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */
1713 KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
1714 KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not "
1715 "AUTHORIZED: %#x\n", __func__, lsta, lsta->state));
1716 error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_ASSOC);
1720 lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
1722 /* Update sta_state (ASSOC to AUTH). */
1723 KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
1724 KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not "
1725 "ASSOC: %#x\n", __func__, lsta, lsta->state));
1726 error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_AUTH);
1730 lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
1733 /* Update bss info (bss_info_changed) (assoc, aid, ..). */
1734 lkpi_disassoc(sta, vif, lhw);
1739 IEEE80211_LOCK(vap->iv_ic);
1742 ieee80211_free_node(ni);
1747 lkpi_sta_run_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
1749 struct lkpi_hw *lhw;
1750 struct ieee80211_hw *hw;
1751 struct lkpi_vif *lvif;
1752 struct ieee80211_vif *vif;
1753 struct ieee80211_node *ni;
1754 struct lkpi_sta *lsta;
1755 struct ieee80211_sta *sta;
1756 struct ieee80211_prep_tx_info prep_tx_info;
1757 enum ieee80211_bss_changed bss_changed;
1760 lhw = vap->iv_ic->ic_softc;
1761 hw = LHW_TO_HW(lhw);
1762 lvif = VAP_TO_LVIF(vap);
1763 vif = LVIF_TO_VIF(lvif);
1765 /* Keep ni around. */
1766 ni = ieee80211_ref_node(vap->iv_bss);
1767 lsta = ni->ni_drv_data;
1768 sta = LSTA_TO_STA(lsta);
1770 lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
1772 IEEE80211_UNLOCK(vap->iv_ic);
1775 lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true);
1777 IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?");
1778 if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) &&
1780 memset(&prep_tx_info, 0, sizeof(prep_tx_info));
1781 prep_tx_info.duration = PREP_TX_INFO_DURATION;
1782 lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info);
1783 lsta->in_mgd = true;
1786 IEEE80211_LOCK(vap->iv_ic);
1788 /* Call iv_newstate first so we get potential DISASSOC packet out. */
1789 error = lvif->iv_newstate(vap, nstate, arg);
1793 IEEE80211_UNLOCK(vap->iv_ic);
1795 lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
1797 /* Wake tx queues to get packet(s) out. */
1798 lkpi_wake_tx_queues(hw, sta, true, true);
1800 /* flush, no drop */
1801 lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false);
1803 /* End mgd_complete_tx. */
1805 memset(&prep_tx_info, 0, sizeof(prep_tx_info));
1806 prep_tx_info.success = false;
1807 lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info);
1808 lsta->in_mgd = false;
1811 /* sync_rx_queues */
1812 lkpi_80211_mo_sync_rx_queues(hw);
1814 /* sta_pre_rcu_remove */
1815 lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta);
1817 /* Take the station down. */
1819 /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */
1820 KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
1821 KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not "
1822 "AUTHORIZED: %#x\n", __func__, lsta, lsta->state));
1823 error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_ASSOC);
1827 lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
1829 /* Update sta_state (ASSOC to AUTH). */
1830 KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
1831 KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not "
1832 "ASSOC: %#x\n", __func__, lsta, lsta->state));
1833 error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_AUTH);
1837 lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
1839 /* Update sta and change state (from AUTH) to NONE. */
1840 KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
1841 KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not "
1842 "AUTH: %#x\n", __func__, lsta, lsta->state));
1843 error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_NONE);
1847 lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
1849 /* Adjust sta and change state (from NONE) to NOTEXIST. */
1850 KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
1851 KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not "
1852 "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg));
1853 error = lkpi_80211_mo_sta_state(hw, vif, sta, IEEE80211_STA_NOTEXIST);
1855 IMPROVE("do we need to undo the chan ctx?");
1859 lsta->added_to_drv = false; /* mo manages. */
1862 lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
1864 /* Update bss info (bss_info_changed) (assoc, aid, ..). */
1866 * One would expect this to happen when going off AUTHORIZED.
1867 * See comment there; removes the sta from fw.
1869 lkpi_disassoc(sta, vif, lhw);
1871 IMPROVE("Any bss_info changes to announce?");
1873 vif->bss_conf.qos = 0;
1874 bss_changed |= BSS_CHANGED_QOS;
1875 vif->bss_conf.ssid_len = 0;
1876 memset(vif->bss_conf.ssid, '\0', sizeof(vif->bss_conf.ssid));
1877 bss_changed |= BSS_CHANGED_BSSID;
1878 lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed);
1880 lkpi_lsta_remove(lsta, lvif);
1884 /* Take the chan ctx down. */
1885 if (vif->chanctx_conf != NULL) {
1886 struct ieee80211_chanctx_conf *conf;
1888 conf = vif->chanctx_conf;
1889 /* Remove vif context. */
1890 lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->chanctx_conf);
1891 /* NB: vif->chanctx_conf is NULL now. */
1893 /* Remove chan ctx. */
1894 lkpi_80211_mo_remove_chanctx(hw, conf);
1895 free(conf, M_LKPI80211);
1900 IEEE80211_LOCK(vap->iv_ic);
1903 ieee80211_free_node(ni);
1908 lkpi_sta_run_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
1911 return (lkpi_sta_run_to_init(vap, nstate, arg));
1915 lkpi_sta_run_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
1919 error = lkpi_sta_run_to_init(vap, nstate, arg);
1920 if (error != 0 && error != EALREADY)
1923 /* At this point iv_bss is long a new node! */
1925 error |= lkpi_sta_scan_to_auth(vap, nstate, 0);
1929 /* -------------------------------------------------------------------------- */
1932 * The matches the documented state changes in net80211::sta_newstate().
1933 * XXX (1) without CSA and SLEEP yet, * XXX (2) not all unhandled cases
1934 * there are "invalid" (so there is a room for failure here).
1937 /* INIT, SCAN, AUTH, ASSOC, CAC, RUN, CSA, SLEEP */
1938 enum ieee80211_state ostate;
1939 enum ieee80211_state nstate;
1940 int (*handler)(struct ieee80211vap *, enum ieee80211_state, int);
1941 } sta_state_fsm[] = {
1942 { IEEE80211_S_INIT, IEEE80211_S_INIT, lkpi_sta_state_do_nada },
1943 { IEEE80211_S_SCAN, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, /* scan_to_init */
1944 { IEEE80211_S_AUTH, IEEE80211_S_INIT, lkpi_sta_auth_to_init }, /* not explicitly in sta_newstate() */
1945 { IEEE80211_S_ASSOC, IEEE80211_S_INIT, lkpi_sta_assoc_to_init }, /* Send DEAUTH. */
1946 { IEEE80211_S_RUN, IEEE80211_S_INIT, lkpi_sta_run_to_init }, /* Send DISASSOC. */
1948 { IEEE80211_S_INIT, IEEE80211_S_SCAN, lkpi_sta_state_do_nada },
1949 { IEEE80211_S_SCAN, IEEE80211_S_SCAN, lkpi_sta_state_do_nada },
1950 { IEEE80211_S_AUTH, IEEE80211_S_SCAN, lkpi_sta_auth_to_scan },
1951 { IEEE80211_S_ASSOC, IEEE80211_S_SCAN, lkpi_sta_assoc_to_scan },
1952 { IEEE80211_S_RUN, IEEE80211_S_SCAN, lkpi_sta_run_to_scan }, /* Beacon miss. */
1954 { IEEE80211_S_INIT, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, /* Send AUTH. */
1955 { IEEE80211_S_SCAN, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, /* Send AUTH. */
1956 { IEEE80211_S_AUTH, IEEE80211_S_AUTH, lkpi_sta_a_to_a }, /* Send ?AUTH. */
1957 { IEEE80211_S_ASSOC, IEEE80211_S_AUTH, lkpi_sta_assoc_to_auth }, /* Send ?AUTH. */
1958 { IEEE80211_S_RUN, IEEE80211_S_AUTH, lkpi_sta_run_to_auth }, /* Send ?AUTH. */
1960 { IEEE80211_S_AUTH, IEEE80211_S_ASSOC, lkpi_sta_auth_to_assoc }, /* Send ASSOCREQ. */
1961 { IEEE80211_S_ASSOC, IEEE80211_S_ASSOC, lkpi_sta_a_to_a }, /* Send ASSOCREQ. */
1962 { IEEE80211_S_RUN, IEEE80211_S_ASSOC, lkpi_sta_run_to_assoc }, /* Send ASSOCREQ/REASSOCREQ. */
1964 { IEEE80211_S_AUTH, IEEE80211_S_RUN, lkpi_sta_auth_to_run },
1965 { IEEE80211_S_ASSOC, IEEE80211_S_RUN, lkpi_sta_assoc_to_run },
1966 { IEEE80211_S_RUN, IEEE80211_S_RUN, lkpi_sta_state_do_nada },
1968 /* Dummy at the end without handler. */
1969 { IEEE80211_S_INIT, IEEE80211_S_INIT, NULL },
1973 lkpi_iv_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
1975 struct ieee80211com *ic;
1976 struct lkpi_hw *lhw;
1977 struct lkpi_vif *lvif;
1978 struct ieee80211_vif *vif;
1979 struct fsm_state *s;
1980 enum ieee80211_state ostate;
1984 IEEE80211_LOCK_ASSERT(ic);
1985 ostate = vap->iv_state;
1987 #ifdef LINUXKPI_DEBUG_80211
1988 if (linuxkpi_debug_80211 & D80211_TRACE)
1989 ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x\n",
1990 __func__, __LINE__, vap, nstate, arg);
1993 if (vap->iv_opmode == IEEE80211_M_STA) {
1996 lvif = VAP_TO_LVIF(vap);
1997 vif = LVIF_TO_VIF(lvif);
1999 /* No need to replicate this in most state handlers. */
2000 if (ostate == IEEE80211_S_SCAN && nstate != IEEE80211_S_SCAN)
2001 lkpi_stop_hw_scan(lhw, vif);
2006 ic_printf(vap->iv_ic, "%s: only station mode currently supported: "
2007 "cap %p iv_opmode %d\n", __func__, vap, vap->iv_opmode);
2012 for (; s->handler != NULL; s++) {
2013 if (ostate == s->ostate && nstate == s->nstate) {
2014 #ifdef LINUXKPI_DEBUG_80211
2015 if (linuxkpi_debug_80211 & D80211_TRACE)
2016 ic_printf(vap->iv_ic, "%s: new state %d (%s) ->"
2017 " %d (%s): arg %d.\n", __func__,
2018 ostate, ieee80211_state_name[ostate],
2019 nstate, ieee80211_state_name[nstate], arg);
2021 error = s->handler(vap, nstate, arg);
2025 IEEE80211_LOCK_ASSERT(vap->iv_ic);
2027 if (s->handler == NULL) {
2028 IMPROVE("turn this into a KASSERT\n");
2029 ic_printf(vap->iv_ic, "%s: unsupported state transition "
2030 "%d (%s) -> %d (%s)\n", __func__,
2031 ostate, ieee80211_state_name[ostate],
2032 nstate, ieee80211_state_name[nstate]);
2036 if (error == EALREADY) {
2037 #ifdef LINUXKPI_DEBUG_80211
2038 if (linuxkpi_debug_80211 & D80211_TRACE)
2039 ic_printf(vap->iv_ic, "%s: state transition %d (%s) -> "
2040 "%d (%s): iv_newstate already handled: %d.\n",
2041 __func__, ostate, ieee80211_state_name[ostate],
2042 nstate, ieee80211_state_name[nstate], error);
2048 /* XXX-BZ currently expected so ignore. */
2049 ic_printf(vap->iv_ic, "%s: error %d during state transition "
2050 "%d (%s) -> %d (%s)\n", __func__, error,
2051 ostate, ieee80211_state_name[ostate],
2052 nstate, ieee80211_state_name[nstate]);
2053 /* return (error); */
2056 #ifdef LINUXKPI_DEBUG_80211
2057 if (linuxkpi_debug_80211 & D80211_TRACE)
2058 ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x "
2059 "calling net80211 parent\n",
2060 __func__, __LINE__, vap, nstate, arg);
2063 return (lvif->iv_newstate(vap, nstate, arg));
2066 /* -------------------------------------------------------------------------- */
2069 * We overload (*iv_update_bss) as otherwise we have cases in, e.g.,
2070 * net80211::ieee80211_sta_join1() where vap->iv_bss gets replaced by a
2071 * new node without us knowing and thus our ni/lsta are out of sync.
2073 static struct ieee80211_node *
2074 lkpi_iv_update_bss(struct ieee80211vap *vap, struct ieee80211_node *ni)
2076 struct lkpi_vif *lvif;
2077 struct ieee80211_node *obss;
2078 struct lkpi_sta *lsta;
2080 lvif = VAP_TO_LVIF(vap);
2083 #ifdef LINUXKPI_DEBUG_80211
2084 if (linuxkpi_debug_80211 & D80211_TRACE)
2085 ic_printf(vap->iv_ic, "%s: obss %p ni_drv_data %p "
2086 "ni %p ni_drv_data %p\n", __func__,
2087 obss, (obss != NULL) ? obss->ni_drv_data : NULL,
2088 ni, (ni != NULL) ? ni->ni_drv_data : NULL);
2091 /* Nothing to copy from. Just return. */
2092 if (obss == NULL || obss->ni_drv_data == NULL)
2095 /* Nothing to copy to. Just return. */
2096 IMPROVE("clearing the obss might still be needed?");
2100 /* Nothing changed? panic? */
2104 lsta = obss->ni_drv_data;
2105 obss->ni_drv_data = ni->ni_drv_data;
2106 ni->ni_drv_data = lsta;
2109 lsta = obss->ni_drv_data;
2114 return (lvif->iv_update_bss(vap, ni));
2118 lkpi_ic_wme_update(struct ieee80211com *ic)
2120 /* This needs queuing and go at the right moment. */
2121 #ifdef WITH_WME_UPDATE
2122 struct ieee80211vap *vap;
2123 struct lkpi_hw *lhw;
2124 struct ieee80211_hw *hw;
2125 struct lkpi_vif *lvif;
2126 struct ieee80211_vif *vif;
2127 struct chanAccParams chp;
2128 struct wmeParams wmeparr[WME_NUM_AC];
2129 struct ieee80211_tx_queue_params txqp;
2130 enum ieee80211_bss_changed changed;
2136 KASSERT(WME_NUM_AC == IEEE80211_NUM_ACS, ("%s: WME_NUM_AC %d != "
2137 "IEEE80211_NUM_ACS %d\n", __func__, WME_NUM_AC, IEEE80211_NUM_ACS));
2139 #ifdef WITH_WME_UPDATE
2140 vap = TAILQ_FIRST(&ic->ic_vaps);
2144 /* We should factor this out into per-vap (*wme_update). */
2146 if (lhw->ops->conf_tx == NULL)
2149 /* XXX-BZ check amount of hw queues */
2150 hw = LHW_TO_HW(lhw);
2151 lvif = VAP_TO_LVIF(vap);
2152 vif = LVIF_TO_VIF(lvif);
2154 ieee80211_wme_ic_getparams(ic, &chp);
2156 for (ac = 0; ac < WME_NUM_AC; ac++)
2157 wmeparr[ac] = chp.cap_wmeParams[ac];
2158 IEEE80211_UNLOCK(ic);
2160 /* Configure tx queues (conf_tx) & send BSS_CHANGED_QOS. */
2161 LKPI_80211_LHW_LOCK(lhw);
2162 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2163 struct wmeParams *wmep;
2165 /* XXX-BZ should keep this in lvif? */
2166 wmep = &wmeparr[ac];
2167 bzero(&txqp, sizeof(txqp));
2168 txqp.cw_min = wmep->wmep_logcwmin;
2169 txqp.cw_max = wmep->wmep_logcwmax;
2170 txqp.txop = wmep->wmep_txopLimit;
2171 txqp.aifs = wmep->wmep_aifsn;
2172 error = lkpi_80211_mo_conf_tx(hw, vif, ac, &txqp);
2174 printf("%s: conf_tx ac %u failed %d\n",
2175 __func__, ac, error);
2177 LKPI_80211_LHW_UNLOCK(lhw);
2178 changed = BSS_CHANGED_QOS;
2179 lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed);
2185 static struct ieee80211vap *
2186 lkpi_ic_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ],
2187 int unit, enum ieee80211_opmode opmode, int flags,
2188 const uint8_t bssid[IEEE80211_ADDR_LEN],
2189 const uint8_t mac[IEEE80211_ADDR_LEN])
2191 struct lkpi_hw *lhw;
2192 struct ieee80211_hw *hw;
2193 struct lkpi_vif *lvif;
2194 struct ieee80211vap *vap;
2195 struct ieee80211_vif *vif;
2196 enum ieee80211_bss_changed changed;
2200 if (!TAILQ_EMPTY(&ic->ic_vaps)) /* 1 so far. Add <n> once this works. */
2204 hw = LHW_TO_HW(lhw);
2206 len = sizeof(*lvif);
2207 len += hw->vif_data_size; /* vif->drv_priv */
2209 lvif = malloc(len, M_80211_VAP, M_WAITOK | M_ZERO);
2210 mtx_init(&lvif->mtx, "lvif", NULL, MTX_DEF);
2211 TAILQ_INIT(&lvif->lsta_head);
2212 vap = LVIF_TO_VAP(lvif);
2214 vif = LVIF_TO_VIF(lvif);
2215 memcpy(vif->addr, mac, IEEE80211_ADDR_LEN);
2217 vif->probe_req_reg = false;
2218 vif->type = lkpi_opmode_to_vif_type(opmode);
2219 lvif->wdev.iftype = vif->type;
2220 /* Need to fill in other fields as well. */
2223 /* XXX-BZ hardcoded for now! */
2225 vif->chanctx_conf = NULL;
2226 vif->bss_conf.idle = true;
2227 vif->bss_conf.ps = false;
2228 vif->bss_conf.chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
2229 vif->bss_conf.use_short_preamble = false; /* vap->iv_flags IEEE80211_F_SHPREAMBLE */
2230 vif->bss_conf.use_short_slot = false; /* vap->iv_flags IEEE80211_F_SHSLOT */
2231 vif->bss_conf.qos = false;
2232 vif->bss_conf.use_cts_prot = false; /* vap->iv_protmode */
2233 vif->bss_conf.ht_operation_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
2234 vif->bss_conf.assoc = false;
2235 vif->bss_conf.aid = 0;
2238 vif->bss_conf.dtim_period = 0; /* IEEE80211_DTIM_DEFAULT ; must stay 0. */
2239 IEEE80211_ADDR_COPY(vif->bss_conf.bssid, bssid);
2240 vif->bss_conf.beacon_int = ic->ic_bintval;
2242 if (vif->bss_conf.beacon_int < 16)
2243 vif->bss_conf.beacon_int = 16;
2247 error = lkpi_80211_mo_start(hw);
2249 printf("%s: failed to start hw: %d\n", __func__, error);
2250 mtx_destroy(&lvif->mtx);
2251 free(lvif, M_80211_VAP);
2255 error = lkpi_80211_mo_add_interface(hw, vif);
2257 IMPROVE(); /* XXX-BZ mo_stop()? */
2258 printf("%s: failed to add interface: %d\n", __func__, error);
2259 mtx_destroy(&lvif->mtx);
2260 free(lvif, M_80211_VAP);
2264 LKPI_80211_LHW_LOCK(lhw);
2265 TAILQ_INSERT_TAIL(&lhw->lvif_head, lvif, lvif_entry);
2266 LKPI_80211_LHW_UNLOCK(lhw);
2270 lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed);
2272 /* conf_tx setup; default WME? */
2274 /* Force MC init. */
2275 lkpi_update_mcast_filter(ic, true);
2279 ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid);
2281 /* Override with LinuxKPI method so we can drive mac80211/cfg80211. */
2282 lvif->iv_newstate = vap->iv_newstate;
2283 vap->iv_newstate = lkpi_iv_newstate;
2284 lvif->iv_update_bss = vap->iv_update_bss;
2285 vap->iv_update_bss = lkpi_iv_update_bss;
2287 /* Key management. */
2288 if (lhw->ops->set_key != NULL) {
2289 #ifdef TRY_HW_CRYPTO
2290 vap->iv_key_set = lkpi_iv_key_set;
2291 vap->iv_key_delete = lkpi_iv_key_delete;
2295 ieee80211_ratectl_init(vap);
2297 /* Complete setup. */
2298 ieee80211_vap_attach(vap, ieee80211_media_change,
2299 ieee80211_media_status, mac);
2301 if (hw->max_listen_interval == 0)
2302 hw->max_listen_interval = 7 * (ic->ic_lintval / ic->ic_bintval);
2303 hw->conf.listen_interval = hw->max_listen_interval;
2304 ic->ic_set_channel(ic);
2306 /* XXX-BZ do we need to be able to update these? */
2307 hw->wiphy->frag_threshold = vap->iv_fragthreshold;
2308 lkpi_80211_mo_set_frag_threshold(hw, vap->iv_fragthreshold);
2309 hw->wiphy->rts_threshold = vap->iv_rtsthreshold;
2310 lkpi_80211_mo_set_rts_threshold(hw, vap->iv_rtsthreshold);
2318 lkpi_ic_vap_delete(struct ieee80211vap *vap)
2320 struct ieee80211com *ic;
2321 struct lkpi_hw *lhw;
2322 struct ieee80211_hw *hw;
2323 struct lkpi_vif *lvif;
2324 struct ieee80211_vif *vif;
2326 lvif = VAP_TO_LVIF(vap);
2327 vif = LVIF_TO_VIF(lvif);
2330 hw = LHW_TO_HW(lhw);
2332 LKPI_80211_LHW_LOCK(lhw);
2333 TAILQ_REMOVE(&lhw->lvif_head, lvif, lvif_entry);
2334 LKPI_80211_LHW_UNLOCK(lhw);
2335 lkpi_80211_mo_remove_interface(hw, vif);
2337 ieee80211_ratectl_deinit(vap);
2338 ieee80211_vap_detach(vap);
2339 mtx_destroy(&lvif->mtx);
2340 free(lvif, M_80211_VAP);
2344 lkpi_ic_update_mcast(struct ieee80211com *ic)
2347 lkpi_update_mcast_filter(ic, false);
2352 lkpi_ic_update_promisc(struct ieee80211com *ic)
2359 lkpi_ic_update_chw(struct ieee80211com *ic)
2365 /* Start / stop device. */
2367 lkpi_ic_parent(struct ieee80211com *ic)
2369 struct lkpi_hw *lhw;
2370 struct ieee80211_hw *hw;
2377 hw = LHW_TO_HW(lhw);
2380 if (ic->ic_nrunning > 0) {
2381 error = lkpi_80211_mo_start(hw);
2385 lkpi_80211_mo_stop(hw);
2389 ieee80211_start_all(ic);
2393 linuxkpi_ieee80211_is_ie_id_in_ie_buf(const u8 ie, const u8 *ie_ids,
2398 for (i = 0; i < ie_ids_len; i++) {
2406 /* Return true if skipped; false if error. */
2408 linuxkpi_ieee80211_ie_advance(size_t *xp, const u8 *ies, size_t ies_len)
2415 KASSERT(x < ies_len, ("%s: x %zu ies_len %zu ies %p\n",
2416 __func__, x, ies_len, ies));
2428 lkpi_ieee80211_probereq_ie_alloc(struct ieee80211vap *vap,
2429 struct ieee80211com *ic, struct ieee80211_scan_ies *scan_ies,
2430 const uint8_t *ssid, size_t ssidlen)
2433 return (ieee80211_probereq_ie(vap, ic,
2434 &scan_ies->common_ies, &scan_ies->common_ie_len,
2435 ssid, ssidlen, true));
2439 lkpi_ic_scan_start(struct ieee80211com *ic)
2441 struct lkpi_hw *lhw;
2442 struct ieee80211_hw *hw;
2443 struct lkpi_vif *lvif;
2444 struct ieee80211_vif *vif;
2445 struct ieee80211_scan_state *ss;
2446 struct ieee80211vap *vap;
2450 if ((lhw->scan_flags & LKPI_SCAN_RUNNING) != 0) {
2451 /* A scan is still running. */
2457 if (vap->iv_state != IEEE80211_S_SCAN) {
2458 IMPROVE("We need to be able to scan if not in S_SCAN");
2462 hw = LHW_TO_HW(lhw);
2463 if ((vap->iv_flags_ext & IEEE80211_FEXT_SCAN_OFFLOAD) == 0) {
2465 lvif = VAP_TO_LVIF(vap);
2466 vif = LVIF_TO_VIF(lvif);
2468 if (vap->iv_state == IEEE80211_S_SCAN)
2469 lkpi_hw_conf_idle(hw, false);
2471 lkpi_80211_mo_sw_scan_start(hw, vif, vif->addr);
2472 /* net80211::scan_start() handled PS for us. */
2474 /* XXX Also means it is too late to flush queues?
2475 * need to check iv_sta_ps or overload? */
2476 /* XXX want to adjust ss end time/ maxdwell? */
2479 struct ieee80211_channel *c;
2480 struct ieee80211_scan_request *hw_req;
2481 struct linuxkpi_ieee80211_channel *lc, **cpp;
2482 struct cfg80211_ssid *ssids;
2483 struct cfg80211_scan_6ghz_params *s6gp;
2484 size_t chan_len, nchan, ssids_len, s6ghzlen;
2487 ssids_len = ss->ss_nssid * sizeof(*ssids);;
2488 s6ghzlen = 0 * (sizeof(*s6gp)); /* XXX-BZ */
2491 for (i = ss->ss_next; i < ss->ss_last; i++)
2493 chan_len = nchan * (sizeof(lc) + sizeof(*lc));
2495 KASSERT(lhw->hw_req == NULL, ("%s: ic %p lhw %p hw_req %p "
2496 "!= NULL\n", __func__, ic, lhw, lhw->hw_req));
2497 lhw->hw_req = hw_req = malloc(sizeof(*hw_req) + ssids_len +
2498 s6ghzlen + chan_len, M_LKPI80211, M_WAITOK | M_ZERO);
2500 error = lkpi_ieee80211_probereq_ie_alloc(vap, ic,
2501 &hw_req->ies, NULL, -1);
2503 ic_printf(ic, "ERROR: %s: probereq_ie returned %d\n",
2506 hw_req->req.flags = 0; /* XXX ??? */
2507 /* hw_req->req.wdev */
2508 hw_req->req.wiphy = hw->wiphy;
2509 hw_req->req.no_cck = false; /* XXX */
2511 /* This seems to pessimise default scanning behaviour. */
2512 hw_req->req.duration_mandatory = TICKS_2_USEC(ss->ss_mindwell);
2513 hw_req->req.duration = TICKS_2_USEC(ss->ss_maxdwell);
2516 hw_req->req.flags |= NL80211_SCAN_FLAG_RANDOM_ADDR;
2517 memcpy(hw_req->req.mac_addr, xxx, IEEE80211_ADDR_LEN);
2518 memset(hw_req->req.mac_addr_mask, 0xxx, IEEE80211_ADDR_LEN);
2521 hw_req->req.ie_len = ;
2525 hw->wiphy->max_scan_ie_len
2526 hw->wiphy->max_scan_ssids
2529 hw_req->req.n_channels = nchan;
2530 cpp = (struct linuxkpi_ieee80211_channel **)(hw_req + 1);
2531 lc = (struct linuxkpi_ieee80211_channel *)(cpp + nchan);
2532 for (i = 0; i < nchan; i++) {
2534 (struct linuxkpi_ieee80211_channel *)(lc + i);
2536 for (i = 0; i < nchan; i++) {
2537 c = ss->ss_chans[ss->ss_next + i];
2539 lc->hw_value = c->ic_ieee;
2540 lc->center_freq = c->ic_freq;
2542 lc->band = lkpi_net80211_chan_to_nl80211_band(c);
2543 lc->max_power = c->ic_maxpower;
2548 hw_req->req.n_ssids = ss->ss_nssid;
2549 if (hw_req->req.n_ssids > 0) {
2550 ssids = (struct cfg80211_ssid *)lc;
2551 hw_req->req.ssids = ssids;
2552 for (i = 0; i < ss->ss_nssid; i++) {
2553 ssids->ssid_len = ss->ss_ssid[i].len;
2554 memcpy(ssids->ssid, ss->ss_ssid[i].ssid,
2555 ss->ss_ssid[i].len);
2558 s6gp = (struct cfg80211_scan_6ghz_params *)ssids;
2560 s6gp = (struct cfg80211_scan_6ghz_params *)lc;
2564 hw_req->req.n_6ghz_params = 0;
2565 hw_req->req.scan_6ghz_params = NULL;
2566 hw_req->req.scan_6ghz = false; /* Weird boolean; not what you think. */
2569 lvif = VAP_TO_LVIF(vap);
2570 vif = LVIF_TO_VIF(lvif);
2571 error = lkpi_80211_mo_hw_scan(hw, vif, hw_req);
2573 free(hw_req->ies.common_ies, M_80211_VAP);
2574 free(hw_req, M_LKPI80211);
2577 ieee80211_cancel_scan(vap);
2579 * XXX-SIGH magic number.
2580 * rtw88 has a magic "return 1" if offloading scan is
2581 * not possible. Fall back to sw scan in that case.
2584 vap->iv_flags_ext &= ~IEEE80211_FEXT_SCAN_OFFLOAD;
2585 ieee80211_start_scan(vap,
2586 IEEE80211_SCAN_ACTIVE |
2587 IEEE80211_SCAN_NOPICK |
2588 IEEE80211_SCAN_ONCE,
2589 IEEE80211_SCAN_FOREVER,
2590 ss->ss_mindwell ? ss->ss_mindwell : msecs_to_ticks(20),
2591 ss->ss_maxdwell ? ss->ss_maxdwell : msecs_to_ticks(200),
2592 vap->iv_des_nssid, vap->iv_des_ssid);
2596 ic_printf(ic, "ERROR: %s: hw_scan returned %d\n",
2603 lkpi_ic_scan_end(struct ieee80211com *ic)
2605 struct lkpi_hw *lhw;
2606 struct ieee80211_scan_state *ss;
2607 struct ieee80211vap *vap;
2610 if ((lhw->scan_flags & LKPI_SCAN_RUNNING) == 0) {
2616 if (vap->iv_flags_ext & IEEE80211_FEXT_SCAN_OFFLOAD) {
2617 /* Nothing to do. */
2619 struct ieee80211_hw *hw;
2620 struct lkpi_vif *lvif;
2621 struct ieee80211_vif *vif;
2623 hw = LHW_TO_HW(lhw);
2624 lvif = VAP_TO_LVIF(vap);
2625 vif = LVIF_TO_VIF(lvif);
2626 lkpi_80211_mo_sw_scan_complete(hw, vif);
2628 /* Send PS to stop buffering if n80211 does not for us? */
2630 if (vap->iv_state == IEEE80211_S_SCAN)
2631 lkpi_hw_conf_idle(hw, true);
2636 lkpi_ic_set_channel(struct ieee80211com *ic)
2638 struct lkpi_hw *lhw;
2639 struct ieee80211_hw *hw;
2640 struct ieee80211_channel *c;
2641 struct linuxkpi_ieee80211_channel *chan;
2646 /* If we do not support (*config)() save us the work. */
2647 if (lhw->ops->config == NULL)
2651 if (c == NULL || c == IEEE80211_CHAN_ANYC) {
2652 ic_printf(ic, "%s: c %p ops->config %p\n", __func__,
2653 c, lhw->ops->config);
2657 chan = lkpi_find_lkpi80211_chan(lhw, c);
2659 ic_printf(ic, "%s: c %p chan %p\n", __func__,
2664 /* XXX max power for scanning? */
2667 hw = LHW_TO_HW(lhw);
2668 cfg80211_chandef_create(&hw->conf.chandef, chan,
2669 NL80211_CHAN_NO_HT);
2671 error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_CHANNEL);
2672 if (error != 0 && error != EOPNOTSUPP) {
2673 ic_printf(ic, "ERROR: %s: config %#0x returned %d\n",
2674 __func__, IEEE80211_CONF_CHANGE_CHANNEL, error);
2675 /* XXX should we unroll to the previous chandef? */
2678 /* Update radiotap channels as well. */
2679 lhw->rtap_tx.wt_chan_freq = htole16(c->ic_freq);
2680 lhw->rtap_tx.wt_chan_flags = htole16(c->ic_flags);
2681 lhw->rtap_rx.wr_chan_freq = htole16(c->ic_freq);
2682 lhw->rtap_rx.wr_chan_flags = htole16(c->ic_flags);
2685 /* Currently PS is hard coded off! Not sure it belongs here. */
2687 if (ieee80211_hw_check(hw, SUPPORTS_PS) &&
2688 (hw->conf.flags & IEEE80211_CONF_PS) != 0) {
2689 hw->conf.flags &= ~IEEE80211_CONF_PS;
2690 error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_PS);
2691 if (error != 0 && error != EOPNOTSUPP)
2692 ic_printf(ic, "ERROR: %s: config %#0x returned "
2693 "%d\n", __func__, IEEE80211_CONF_CHANGE_PS,
2698 static struct ieee80211_node *
2699 lkpi_ic_node_alloc(struct ieee80211vap *vap,
2700 const uint8_t mac[IEEE80211_ADDR_LEN])
2702 struct ieee80211com *ic;
2703 struct lkpi_hw *lhw;
2704 struct ieee80211_node *ni;
2705 struct ieee80211_hw *hw;
2706 struct lkpi_sta *lsta;
2711 /* We keep allocations de-coupled so we can deal with the two worlds. */
2712 if (lhw->ic_node_alloc == NULL)
2715 ni = lhw->ic_node_alloc(vap, mac);
2719 hw = LHW_TO_HW(lhw);
2720 lsta = lkpi_lsta_alloc(vap, mac, hw, ni);
2722 if (lhw->ic_node_free != NULL)
2723 lhw->ic_node_free(ni);
2731 lkpi_ic_node_init(struct ieee80211_node *ni)
2733 struct ieee80211com *ic;
2734 struct lkpi_hw *lhw;
2735 struct lkpi_sta *lsta;
2736 struct lkpi_vif *lvif;
2742 if (lhw->ic_node_init != NULL) {
2743 error = lhw->ic_node_init(ni);
2748 lvif = VAP_TO_LVIF(ni->ni_vap);
2750 lsta = ni->ni_drv_data;
2752 /* Now take the reference before linking it to the table. */
2753 lsta->ni = ieee80211_ref_node(ni);
2755 LKPI_80211_LVIF_LOCK(lvif);
2756 TAILQ_INSERT_TAIL(&lvif->lsta_head, lsta, lsta_entry);
2757 LKPI_80211_LVIF_UNLOCK(lvif);
2759 /* XXX-BZ Sync other state over. */
2766 lkpi_ic_node_cleanup(struct ieee80211_node *ni)
2768 struct ieee80211com *ic;
2769 struct lkpi_hw *lhw;
2774 /* XXX-BZ remove from driver, ... */
2777 if (lhw->ic_node_cleanup != NULL)
2778 lhw->ic_node_cleanup(ni);
2782 lkpi_ic_node_free(struct ieee80211_node *ni)
2784 struct ieee80211com *ic;
2785 struct lkpi_hw *lhw;
2786 struct lkpi_sta *lsta;
2790 lsta = ni->ni_drv_data;
2794 /* XXX-BZ free resources, ... */
2797 /* Flush mbufq (make sure to release ni refs!). */
2799 KASSERT(mbufq_len(&lsta->txq) == 0, ("%s: lsta %p has txq len %d != 0\n",
2800 __func__, lsta, mbufq_len(&lsta->txq)));
2804 /* Drain sta->txq[] */
2805 mtx_destroy(&lsta->txq_mtx);
2807 /* Remove lsta if added_to_drv. */
2808 /* Remove lsta from vif */
2810 /* remove ref from lsta node... */
2815 if (lhw->ic_node_free != NULL)
2816 lhw->ic_node_free(ni);
2820 lkpi_ic_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
2821 const struct ieee80211_bpf_params *params __unused)
2823 struct lkpi_sta *lsta;
2825 lsta = ni->ni_drv_data;
2827 /* Queue the packet and enqueue the task to handle it. */
2828 LKPI_80211_LSTA_LOCK(lsta);
2829 mbufq_enqueue(&lsta->txq, m);
2830 LKPI_80211_LSTA_UNLOCK(lsta);
2832 #ifdef LINUXKPI_DEBUG_80211
2833 if (linuxkpi_debug_80211 & D80211_TRACE_TX)
2834 printf("%s:%d lsta %p ni %p %6D mbuf_qlen %d\n",
2835 __func__, __LINE__, lsta, ni, ni->ni_macaddr, ":",
2836 mbufq_len(&lsta->txq));
2839 taskqueue_enqueue(taskqueue_thread, &lsta->txq_task);
2844 lkpi_80211_txq_tx_one(struct lkpi_sta *lsta, struct mbuf *m)
2846 struct ieee80211_node *ni;
2847 struct ieee80211_frame *wh;
2848 struct ieee80211_key *k;
2849 struct sk_buff *skb;
2850 struct ieee80211com *ic;
2851 struct lkpi_hw *lhw;
2852 struct ieee80211_hw *hw;
2853 struct lkpi_vif *lvif;
2854 struct ieee80211_vif *vif;
2855 struct ieee80211_channel *c;
2856 struct ieee80211_tx_control control;
2857 struct ieee80211_tx_info *info;
2858 struct ieee80211_sta *sta;
2863 #ifdef LINUXKPI_DEBUG_80211
2864 if (linuxkpi_debug_80211 & D80211_TRACE_TX_DUMP)
2865 hexdump(mtod(m, const void *), m->m_len, "RAW TX (plain) ", 0);
2869 #ifndef TRY_HW_CRYPTO
2870 /* Encrypt the frame if need be; XXX-BZ info->control.hw_key. */
2871 wh = mtod(m, struct ieee80211_frame *);
2872 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) {
2873 /* Retrieve key for TX && do software encryption. */
2874 k = ieee80211_crypto_encap(ni, m);
2876 ieee80211_free_node(ni);
2885 hw = LHW_TO_HW(lhw);
2888 if (ieee80211_radiotap_active_vap(ni->ni_vap)) {
2889 struct lkpi_radiotap_tx_hdr *rtap;
2891 rtap = &lhw->rtap_tx;
2894 rtap->wt_flags |= IEEE80211_RADIOTAP_F_WEP;
2895 if (m->m_flags & M_FRAG)
2896 rtap->wt_flags |= IEEE80211_RADIOTAP_F_FRAG;
2899 if (c != NULL && c != IEEE80211_CHAN_ANYC) {
2900 rtap->wt_chan_freq = htole16(c->ic_freq);
2901 rtap->wt_chan_flags = htole16(c->ic_flags);
2904 ieee80211_radiotap_tx(ni->ni_vap, m);
2908 * net80211 should handle hw->extra_tx_headroom.
2909 * Though for as long as we are copying we don't mind.
2910 * XXX-BZ rtw88 asks for too much headroom for ipv6+tcp:
2911 * https://lists.freebsd.org/archives/freebsd-transport/2022-February/000012.html
2913 skb = dev_alloc_skb(hw->extra_tx_headroom + m->m_pkthdr.len);
2915 printf("XXX ERROR %s: skb alloc failed\n", __func__);
2916 ieee80211_free_node(ni);
2920 skb_reserve(skb, hw->extra_tx_headroom);
2922 /* XXX-BZ we need a SKB version understanding mbuf. */
2923 /* Save the mbuf for ieee80211_tx_complete(). */
2924 skb->m_free_func = lkpi_ieee80211_free_skb_mbuf;
2927 skb_put_data(skb, m->m_data, m->m_pkthdr.len);
2929 buf = skb_put(skb, m->m_pkthdr.len);
2930 m_copydata(m, 0, m->m_pkthdr.len, buf);
2933 m->m_pkthdr.PH_loc.ptr = ni;
2935 lvif = VAP_TO_LVIF(ni->ni_vap);
2936 vif = LVIF_TO_VIF(lvif);
2938 /* XXX-BZ review this at some point [4] vs. [8] vs. [16](TID). */
2939 ac = M_WME_GETAC(m);
2940 skb->priority = WME_AC_TO_TID(ac);
2941 ac = lkpi_ac_net_to_l80211(ac);
2942 skb_set_queue_mapping(skb, ac);
2944 info = IEEE80211_SKB_CB(skb);
2945 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
2946 /* Slight delay; probably only happens on scanning so fine? */
2947 if (c == NULL || c == IEEE80211_CHAN_ANYC)
2949 info->band = lkpi_net80211_chan_to_nl80211_band(c);
2950 info->hw_queue = ac; /* XXX-BZ is this correct? */
2951 if (m->m_flags & M_EAPOL)
2952 info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO;
2953 info->control.vif = vif;
2954 /* XXX-BZ info->control.rates */
2956 lsta = lkpi_find_lsta_by_ni(lvif, ni);
2958 sta = LSTA_TO_STA(lsta);
2959 #ifdef TRY_HW_CRYPTO
2960 info->control.hw_key = lsta->kc;
2969 struct lkpi_txq *ltxq;
2971 ltxq = TXQ_TO_LTXQ(sta->txq[ac]); /* XXX-BZ re-check */
2973 * We currently do not use queues but do direct TX.
2974 * The exception to the rule is initial packets, as we cannot
2975 * TX until queues are allocated (at least for iwlwifi).
2976 * So we wake_tx_queue in newstate and register any dequeue
2977 * calls. In the time until then we queue packets and
2978 * let the driver deal with them.
2980 if (!ltxq->seen_dequeue) {
2982 /* Prevent an ordering problem, likely other issues. */
2983 while (!skb_queue_empty(<xq->skbq)) {
2984 struct sk_buff *skb2;
2986 skb2 = skb_dequeue(<xq->skbq);
2988 memset(&control, 0, sizeof(control));
2990 lkpi_80211_mo_tx(hw, &control, skb2);
2995 if (0 && ltxq->seen_dequeue && skb_queue_empty(<xq->skbq))
2998 skb_queue_tail(<xq->skbq, skb);
2999 #ifdef LINUXKPI_DEBUG_80211
3000 if (linuxkpi_debug_80211 & D80211_TRACE_TX)
3001 printf("%s:%d lsta %p sta %p ni %p %6D skb %p lxtq %p "
3002 "qlen %u WAKE_TX_Q ac %d prio %u qmap %u\n",
3003 __func__, __LINE__, lsta, sta, ni,
3004 ni->ni_macaddr, ":", skb, ltxq,
3005 skb_queue_len(<xq->skbq), ac,
3006 skb->priority, skb->qmap);
3008 lkpi_80211_mo_wake_tx_queue(hw, sta->txq[ac]); /* XXX-BZ */
3013 #ifdef LINUXKPI_DEBUG_80211
3014 if (linuxkpi_debug_80211 & D80211_TRACE_TX)
3015 printf("%s:%d lsta %p sta %p ni %p %6D skb %p TX ac %d prio %u qmap %u\n",
3016 __func__, __LINE__, lsta, sta, ni, ni->ni_macaddr, ":",
3017 skb, ac, skb->priority, skb->qmap);
3019 memset(&control, 0, sizeof(control));
3022 lkpi_80211_mo_tx(hw, &control, skb);
3027 lkpi_80211_txq_task(void *ctx, int pending)
3029 struct lkpi_sta *lsta;
3035 #ifdef LINUXKPI_DEBUG_80211
3036 if (linuxkpi_debug_80211 & D80211_TRACE_TX)
3037 printf("%s:%d lsta %p ni %p %6D pending %d mbuf_qlen %d\n",
3038 __func__, __LINE__, lsta, lsta->ni, lsta->ni->ni_macaddr, ":",
3039 pending, mbufq_len(&lsta->txq));
3042 mbufq_init(&mq, IFQ_MAXLEN);
3044 LKPI_80211_LSTA_LOCK(lsta);
3045 mbufq_concat(&mq, &lsta->txq);
3046 LKPI_80211_LSTA_UNLOCK(lsta);
3048 m = mbufq_dequeue(&mq);
3050 lkpi_80211_txq_tx_one(lsta, m);
3051 m = mbufq_dequeue(&mq);
3056 lkpi_ic_transmit(struct ieee80211com *ic, struct mbuf *m)
3062 /* Quick and dirty cheating hack. */
3063 struct ieee80211_node *ni;
3065 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
3066 return (lkpi_ic_raw_xmit(ni, m, NULL));
3070 lkpi_ic_getradiocaps(struct ieee80211com *ic, int maxchan,
3071 int *n, struct ieee80211_channel *c)
3073 struct lkpi_hw *lhw;
3074 struct ieee80211_hw *hw;
3075 struct linuxkpi_ieee80211_channel *channels;
3076 uint8_t bands[IEEE80211_MODE_BYTES];
3077 int chan_flags, error, i, nchans;
3081 hw = LHW_TO_HW(lhw);
3083 /* NL80211_BAND_2GHZ */
3085 if (hw->wiphy->bands[NL80211_BAND_2GHZ] != NULL)
3086 nchans = hw->wiphy->bands[NL80211_BAND_2GHZ]->n_channels;
3088 memset(bands, 0, sizeof(bands));
3090 setbit(bands, IEEE80211_MODE_11B);
3091 /* XXX-BZ unclear how to check for 11g. */
3092 setbit(bands, IEEE80211_MODE_11G);
3094 if (hw->wiphy->bands[NL80211_BAND_2GHZ]->ht_cap.ht_supported) {
3095 setbit(bands, IEEE80211_MODE_11NG);
3096 chan_flags |= NET80211_CBW_FLAG_HT40;
3100 channels = hw->wiphy->bands[NL80211_BAND_2GHZ]->channels;
3101 for (i = 0; i < nchans && *n < maxchan; i++) {
3102 uint32_t nflags = 0;
3103 int cflags = chan_flags;
3105 if (channels[i].flags & IEEE80211_CHAN_DISABLED) {
3106 printf("%s: %s: Skipping disabled chan "
3107 "[%u/%u/%#x]\n", ic->ic_name, __func__,
3108 channels[i].hw_value,
3109 channels[i].center_freq, channels[i].flags);
3112 if (channels[i].flags & IEEE80211_CHAN_NO_IR)
3113 nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE);
3114 if (channels[i].flags & IEEE80211_CHAN_RADAR)
3115 nflags |= IEEE80211_CHAN_DFS;
3116 if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ)
3117 cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80);
3118 if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ)
3119 cflags &= ~NET80211_CBW_FLAG_VHT80;
3120 /* XXX how to map the remaining enum ieee80211_channel_flags? */
3121 if (channels[i].flags & IEEE80211_CHAN_NO_HT40)
3122 cflags &= ~NET80211_CBW_FLAG_HT40;
3124 error = ieee80211_add_channel_cbw(c, maxchan, n,
3125 channels[i].hw_value, channels[i].center_freq,
3126 channels[i].max_power,
3127 nflags, bands, chan_flags);
3128 /* net80211::ENOBUFS: *n >= maxchans */
3129 if (error != 0 && error != ENOBUFS)
3130 printf("%s: %s: Adding chan %u/%u/%#x/%#x/%#x/%#x "
3131 "returned error %d\n", ic->ic_name,
3132 __func__, channels[i].hw_value,
3133 channels[i].center_freq, channels[i].flags,
3134 nflags, chan_flags, cflags, error);
3140 /* NL80211_BAND_5GHZ */
3142 if (hw->wiphy->bands[NL80211_BAND_5GHZ] != NULL)
3143 nchans = hw->wiphy->bands[NL80211_BAND_5GHZ]->n_channels;
3145 memset(bands, 0, sizeof(bands));
3147 setbit(bands, IEEE80211_MODE_11A);
3149 if (hw->wiphy->bands[NL80211_BAND_5GHZ]->ht_cap.ht_supported) {
3150 setbit(bands, IEEE80211_MODE_11NA);
3151 chan_flags |= NET80211_CBW_FLAG_HT40;
3153 if (hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.vht_supported){
3155 ic->ic_flags_ext |= IEEE80211_FEXT_VHT;
3157 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap;
3159 setbit(bands, IEEE80211_MODE_VHT_5GHZ);
3160 chan_flags |= NET80211_CBW_FLAG_VHT80;
3161 if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160MHZ(
3163 chan_flags |= NET80211_CBW_FLAG_VHT160;
3164 if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160_80P80MHZ(
3166 chan_flags |= NET80211_CBW_FLAG_VHT80P80;
3170 channels = hw->wiphy->bands[NL80211_BAND_5GHZ]->channels;
3171 for (i = 0; i < nchans && *n < maxchan; i++) {
3172 uint32_t nflags = 0;
3173 int cflags = chan_flags;
3175 if (channels[i].flags & IEEE80211_CHAN_DISABLED) {
3176 printf("%s: %s: Skipping disabled chan "
3177 "[%u/%u/%#x]\n", ic->ic_name, __func__,
3178 channels[i].hw_value,
3179 channels[i].center_freq, channels[i].flags);
3182 if (channels[i].flags & IEEE80211_CHAN_NO_IR)
3183 nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE);
3184 if (channels[i].flags & IEEE80211_CHAN_RADAR)
3185 nflags |= IEEE80211_CHAN_DFS;
3186 if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ)
3187 cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80);
3188 if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ)
3189 cflags &= ~NET80211_CBW_FLAG_VHT80;
3190 /* XXX hwo to map the remaining enum ieee80211_channel_flags? */
3191 if (channels[i].flags & IEEE80211_CHAN_NO_HT40)
3192 cflags &= ~NET80211_CBW_FLAG_HT40;
3194 error = ieee80211_add_channel_cbw(c, maxchan, n,
3195 channels[i].hw_value, channels[i].center_freq,
3196 channels[i].max_power,
3197 nflags, bands, chan_flags);
3198 /* net80211::ENOBUFS: *n >= maxchans */
3199 if (error != 0 && error != ENOBUFS)
3200 printf("%s: %s: Adding chan %u/%u/%#x/%#x/%#x/%#x "
3201 "returned error %d\n", ic->ic_name,
3202 __func__, channels[i].hw_value,
3203 channels[i].center_freq, channels[i].flags,
3204 nflags, chan_flags, cflags, error);
3212 lkpi_ieee80211_ifalloc(void)
3214 struct ieee80211com *ic;
3216 ic = malloc(sizeof(*ic), M_LKPI80211, M_WAITOK | M_ZERO);
3220 /* Setting these happens later when we have device information. */
3221 ic->ic_softc = NULL;
3222 ic->ic_name = "linuxkpi";
3227 struct ieee80211_hw *
3228 linuxkpi_ieee80211_alloc_hw(size_t priv_len, const struct ieee80211_ops *ops)
3230 struct ieee80211_hw *hw;
3231 struct lkpi_hw *lhw;
3232 struct wiphy *wiphy;
3234 /* Get us and the driver data also allocated. */
3235 wiphy = wiphy_new(&linuxkpi_mac80211cfgops, sizeof(*lhw) + priv_len);
3239 lhw = wiphy_priv(wiphy);
3242 mtx_init(&lhw->mtx, "lhw", NULL, MTX_DEF | MTX_RECURSE);
3243 TAILQ_INIT(&lhw->lvif_head);
3246 * XXX-BZ TODO make sure there is a "_null" function to all ops
3249 hw = LHW_TO_HW(lhw);
3251 hw->conf.flags |= IEEE80211_CONF_IDLE;
3252 hw->priv = (void *)(lhw + 1);
3255 lhw->ic = lkpi_ieee80211_ifalloc();
3256 if (lhw->ic == NULL) {
3257 ieee80211_free_hw(hw);
3267 linuxkpi_ieee80211_iffree(struct ieee80211_hw *hw)
3269 struct lkpi_hw *lhw;
3271 lhw = HW_TO_LHW(hw);
3272 free(lhw->ic, M_LKPI80211);
3275 /* Cleanup more of lhw here or in wiphy_free()? */
3276 mtx_destroy(&lhw->mtx);
3281 linuxkpi_set_ieee80211_dev(struct ieee80211_hw *hw, char *name)
3283 struct lkpi_hw *lhw;
3284 struct ieee80211com *ic;
3286 lhw = HW_TO_LHW(hw);
3289 /* Now set a proper name before ieee80211_ifattach(). */
3293 /* XXX-BZ do we also need to set wiphy name? */
3296 struct ieee80211_hw *
3297 linuxkpi_wiphy_to_ieee80211_hw(struct wiphy *wiphy)
3299 struct lkpi_hw *lhw;
3301 lhw = wiphy_priv(wiphy);
3302 return (LHW_TO_HW(lhw));
3306 lkpi_radiotap_attach(struct lkpi_hw *lhw)
3308 struct ieee80211com *ic;
3311 ieee80211_radiotap_attach(ic,
3312 &lhw->rtap_tx.wt_ihdr, sizeof(lhw->rtap_tx),
3313 LKPI_RTAP_TX_FLAGS_PRESENT,
3314 &lhw->rtap_rx.wr_ihdr, sizeof(lhw->rtap_rx),
3315 LKPI_RTAP_RX_FLAGS_PRESENT);
3319 linuxkpi_ieee80211_ifattach(struct ieee80211_hw *hw)
3321 struct ieee80211com *ic;
3322 struct lkpi_hw *lhw;
3325 lhw = HW_TO_LHW(hw);
3328 /* We do it this late as wiphy->dev should be set for the name. */
3329 lhw->workq = alloc_ordered_workqueue(wiphy_name(hw->wiphy), 0);
3330 if (lhw->workq == NULL)
3333 /* XXX-BZ figure this out how they count his... */
3334 if (!is_zero_ether_addr(hw->wiphy->perm_addr)) {
3335 IEEE80211_ADDR_COPY(ic->ic_macaddr,
3336 hw->wiphy->perm_addr);
3337 } else if (hw->wiphy->n_addresses > 0) {
3338 /* We take the first one. */
3339 IEEE80211_ADDR_COPY(ic->ic_macaddr,
3340 hw->wiphy->addresses[0].addr);
3342 ic_printf(ic, "%s: warning, no hardware address!\n", __func__);
3346 /* See comment in lkpi_80211_txq_tx_one(). */
3347 ic->ic_headroom = hw->extra_tx_headroom;
3350 ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */
3351 ic->ic_opmode = IEEE80211_M_STA;
3353 /* Set device capabilities. */
3354 /* XXX-BZ we need to get these from linux80211/drivers and convert. */
3357 IEEE80211_C_MONITOR |
3358 IEEE80211_C_WPA | /* WPA/RSN */
3363 IEEE80211_C_SHSLOT | /* short slot time supported */
3364 IEEE80211_C_SHPREAMBLE /* short preamble supported */
3367 /* Scanning is a different kind of beast to re-work. */
3368 ic->ic_caps |= IEEE80211_C_BGSCAN;
3370 if (lhw->ops->hw_scan) {
3372 * Advertise full-offload scanning.
3374 * Not limiting to SINGLE_SCAN_ON_ALL_BANDS here as otherwise
3375 * we essentially disable hw_scan for all drivers not setting
3378 ic->ic_flags_ext |= IEEE80211_FEXT_SCAN_OFFLOAD;
3382 ic->ic_htcaps = IEEE80211_HTC_HT /* HT operation */
3383 | IEEE80211_HTC_AMPDU /* A-MPDU tx/rx */
3384 | IEEE80211_HTC_AMSDU /* A-MSDU tx/rx */
3385 | IEEE80211_HTCAP_MAXAMSDU_3839
3386 /* max A-MSDU length */
3387 | IEEE80211_HTCAP_SMPS_OFF; /* SM power save off */
3388 ic->ic_htcaps |= IEEE80211_HTCAP_SHORTGI20;
3389 ic->ic_htcaps |= IEEE80211_HTCAP_CHWIDTH40 | IEEE80211_HTCAP_SHORTGI40;
3390 ic->ic_htcaps |= IEEE80211_HTCAP_TXSTBC;
3393 ic->ic_cryptocaps = 0;
3394 #ifdef TRY_HW_CRYPTO
3395 if (hw->wiphy->n_cipher_suites > 0) {
3396 for (i = 0; i < hw->wiphy->n_cipher_suites; i++)
3397 ic->ic_cryptocaps |= lkpi_l80211_to_net80211_cyphers(
3398 hw->wiphy->cipher_suites[i]);
3402 lkpi_ic_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans,
3405 ieee80211_ifattach(ic);
3407 ic->ic_update_mcast = lkpi_ic_update_mcast;
3408 ic->ic_update_promisc = lkpi_ic_update_promisc;
3409 ic->ic_update_chw = lkpi_ic_update_chw;
3410 ic->ic_parent = lkpi_ic_parent;
3411 ic->ic_scan_start = lkpi_ic_scan_start;
3412 ic->ic_scan_end = lkpi_ic_scan_end;
3413 ic->ic_set_channel = lkpi_ic_set_channel;
3414 ic->ic_transmit = lkpi_ic_transmit;
3415 ic->ic_raw_xmit = lkpi_ic_raw_xmit;
3416 ic->ic_vap_create = lkpi_ic_vap_create;
3417 ic->ic_vap_delete = lkpi_ic_vap_delete;
3418 ic->ic_getradiocaps = lkpi_ic_getradiocaps;
3419 ic->ic_wme.wme_update = lkpi_ic_wme_update;
3421 lhw->ic_node_alloc = ic->ic_node_alloc;
3422 ic->ic_node_alloc = lkpi_ic_node_alloc;
3423 lhw->ic_node_init = ic->ic_node_init;
3424 ic->ic_node_init = lkpi_ic_node_init;
3425 lhw->ic_node_cleanup = ic->ic_node_cleanup;
3426 ic->ic_node_cleanup = lkpi_ic_node_cleanup;
3427 lhw->ic_node_free = ic->ic_node_free;
3428 ic->ic_node_free = lkpi_ic_node_free;
3430 lkpi_radiotap_attach(lhw);
3433 * Assign the first possible channel for now; seems Realtek drivers
3436 for (band = 0; band < NUM_NL80211_BANDS &&
3437 hw->conf.chandef.chan == NULL; band++) {
3438 struct ieee80211_supported_band *supband;
3439 struct linuxkpi_ieee80211_channel *channels;
3441 supband = hw->wiphy->bands[band];
3442 if (supband == NULL || supband->n_channels == 0)
3445 channels = supband->channels;
3446 for (i = 0; i < supband->n_channels; i++) {
3448 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
3451 cfg80211_chandef_create(&hw->conf.chandef, &channels[i],
3452 NL80211_CHAN_NO_HT);
3458 ieee80211_announce(ic);
3464 linuxkpi_ieee80211_ifdetach(struct ieee80211_hw *hw)
3466 struct lkpi_hw *lhw;
3467 struct ieee80211com *ic;
3469 lhw = HW_TO_LHW(hw);
3471 ieee80211_ifdetach(ic);
3475 linuxkpi_ieee80211_iterate_interfaces(struct ieee80211_hw *hw,
3476 enum ieee80211_iface_iter flags,
3477 void(*iterfunc)(void *, uint8_t *, struct ieee80211_vif *),
3480 struct lkpi_hw *lhw;
3481 struct lkpi_vif *lvif;
3482 struct ieee80211_vif *vif;
3483 bool active, atomic, nin_drv;
3485 lhw = HW_TO_LHW(hw);
3487 if (flags & ~(IEEE80211_IFACE_ITER_NORMAL|
3488 IEEE80211_IFACE_ITER_RESUME_ALL|
3489 IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER|
3490 IEEE80211_IFACE_ITER__ACTIVE|IEEE80211_IFACE_ITER__ATOMIC)) {
3491 ic_printf(lhw->ic, "XXX TODO %s flags(%#x) not yet supported.\n",
3495 active = (flags & IEEE80211_IFACE_ITER__ACTIVE) != 0;
3496 atomic = (flags & IEEE80211_IFACE_ITER__ATOMIC) != 0;
3497 nin_drv = (flags & IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER) != 0;
3500 LKPI_80211_LHW_LOCK(lhw);
3501 TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) {
3502 struct ieee80211vap *vap;
3504 vif = LVIF_TO_VIF(lvif);
3507 * If we want "active" interfaces, we need to distinguish on
3508 * whether the driver knows about them or not to be able to
3509 * handle the "resume" case correctly. Skip the ones the
3510 * driver does not know about.
3512 if (active && !lvif->added_to_drv &&
3513 (flags & IEEE80211_IFACE_ITER_RESUME_ALL) != 0)
3517 * If we shall skip interfaces not added to the driver do so
3518 * if we haven't yet.
3520 if (nin_drv && !lvif->added_to_drv)
3524 * Run the iterator function if we are either not asking
3525 * asking for active only or if the VAP is "running".
3527 /* XXX-BZ probably should have state in the lvif as well. */
3528 vap = LVIF_TO_VAP(lvif);
3529 if (!active || (vap->iv_state != IEEE80211_S_INIT))
3530 iterfunc(arg, vif->addr, vif);
3533 LKPI_80211_LHW_UNLOCK(lhw);
3537 linuxkpi_ieee80211_iterate_keys(struct ieee80211_hw *hw,
3538 struct ieee80211_vif *vif,
3539 void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_vif *,
3540 struct ieee80211_sta *, struct ieee80211_key_conf *, void *),
3548 linuxkpi_ieee80211_iterate_chan_contexts(struct ieee80211_hw *hw,
3549 void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_chanctx_conf *,
3558 linuxkpi_ieee80211_iterate_stations_atomic(struct ieee80211_hw *hw,
3559 void (*iterfunc)(void *, struct ieee80211_sta *), void *arg)
3561 struct lkpi_hw *lhw;
3562 struct lkpi_vif *lvif;
3563 struct lkpi_sta *lsta;
3564 struct ieee80211_sta *sta;
3566 KASSERT(hw != NULL && iterfunc != NULL,
3567 ("%s: hw %p iterfunc %p arg %p\n", __func__, hw, iterfunc, arg));
3569 lhw = HW_TO_LHW(hw);
3571 LKPI_80211_LHW_LOCK(lhw);
3572 TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) {
3574 LKPI_80211_LVIF_LOCK(lvif);
3575 TAILQ_FOREACH(lsta, &lvif->lsta_head, lsta_entry) {
3576 if (!lsta->added_to_drv)
3578 sta = LSTA_TO_STA(lsta);
3581 LKPI_80211_LVIF_UNLOCK(lvif);
3583 LKPI_80211_LHW_UNLOCK(lhw);
3587 linuxkpi_regulatory_set_wiphy_regd_sync(struct wiphy *wiphy,
3588 struct linuxkpi_ieee80211_regdomain *regd)
3590 struct lkpi_hw *lhw;
3591 struct ieee80211com *ic;
3592 struct ieee80211_regdomain *rd;
3594 lhw = wiphy_priv(wiphy);
3597 rd = &ic->ic_regdomain;
3598 if (rd->isocc[0] == '\0') {
3599 rd->isocc[0] = regd->alpha2[0];
3600 rd->isocc[1] = regd->alpha2[1];
3604 /* XXX-BZ finish the rest. */
3610 linuxkpi_ieee80211_scan_completed(struct ieee80211_hw *hw,
3611 struct cfg80211_scan_info *info)
3613 struct lkpi_hw *lhw;
3614 struct ieee80211com *ic;
3615 struct ieee80211_scan_state *ss;
3617 lhw = wiphy_priv(hw->wiphy);
3621 ieee80211_scan_done(ss->ss_vap);
3623 LKPI_80211_LHW_LOCK(lhw);
3624 free(lhw->hw_req->ies.common_ies, M_80211_VAP);
3625 free(lhw->hw_req, M_LKPI80211);
3627 lhw->scan_flags &= ~LKPI_SCAN_RUNNING;
3629 LKPI_80211_LHW_UNLOCK(lhw);
3635 linuxkpi_ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
3636 struct ieee80211_sta *sta, struct napi_struct *napi __unused)
3638 struct epoch_tracker et;
3639 struct lkpi_hw *lhw;
3640 struct ieee80211com *ic;
3642 struct skb_shared_info *shinfo;
3643 struct ieee80211_rx_status *rx_status;
3644 struct ieee80211_rx_stats rx_stats;
3645 struct ieee80211_node *ni;
3646 struct ieee80211vap *vap;
3647 struct ieee80211_hdr *hdr;
3648 struct lkpi_sta *lsta;
3653 /* Need 80211 stats here. */
3659 * For now do the data copy; we can later improve things. Might even
3660 * have an mbuf backing the skb data then?
3662 m = m_get2(skb->len, M_NOWAIT, MT_DATA, M_PKTHDR);
3665 m_copyback(m, 0, skb->tail - skb->data, skb->data);
3667 shinfo = skb_shinfo(skb);
3669 for (i = 0; i < shinfo->nr_frags; i++) {
3670 m_copyback(m, offset, shinfo->frags[i].size,
3671 (uint8_t *)linux_page_address(shinfo->frags[i].page) +
3672 shinfo->frags[i].offset);
3673 offset += shinfo->frags[i].size;
3676 rx_status = IEEE80211_SKB_RXCB(skb);
3678 hdr = (void *)skb->data;
3679 is_beacon = ieee80211_is_beacon(hdr->frame_control);
3681 #ifdef LINUXKPI_DEBUG_80211
3682 if (is_beacon && (linuxkpi_debug_80211 & D80211_TRACE_RX_BEACONS) == 0)
3683 goto no_trace_beacons;
3685 if (linuxkpi_debug_80211 & D80211_TRACE_RX)
3686 printf("TRACE-RX: %s: skb %p a/l/d/t-len (%u/%u/%u/%u) "
3687 "h %p d %p t %p e %p sh %p (%u) m %p plen %u len %u%s\n",
3688 __func__, skb, skb->_alloc_len, skb->len, skb->data_len,
3689 skb->truesize, skb->head, skb->data, skb->tail, skb->end,
3690 shinfo, shinfo->nr_frags,
3691 m, m->m_pkthdr.len, m->m_len, is_beacon ? " beacon" : "");
3693 if (linuxkpi_debug_80211 & D80211_TRACE_RX_DUMP)
3694 hexdump(mtod(m, const void *), m->m_len, "RX (raw) ", 0);
3696 /* Implement a dump_rxcb() !!! */
3697 if (linuxkpi_debug_80211 & D80211_TRACE_RX)
3698 printf("TRACE %s: RXCB: %ju %ju %u, %#0x, %u, %#0x, %#0x, "
3699 "%u band %u, %u { %d %d %d %d }, %d, %#x %#x %#x %#x %u %u %u\n",
3701 (uintmax_t)rx_status->boottime_ns,
3702 (uintmax_t)rx_status->mactime,
3703 rx_status->device_timestamp,
3707 rx_status->encoding,
3708 rx_status->ampdu_reference,
3711 rx_status->chain_signal[0],
3712 rx_status->chain_signal[1],
3713 rx_status->chain_signal[2],
3714 rx_status->chain_signal[3],
3716 rx_status->enc_flags,
3720 rx_status->zero_length_psdu_type,
3722 rx_status->rate_idx);
3726 memset(&rx_stats, 0, sizeof(rx_stats));
3727 rx_stats.r_flags = IEEE80211_R_NF | IEEE80211_R_RSSI;
3728 /* XXX-BZ correct hardcoded rssi and noise floor, how? survey? */
3729 rx_stats.c_nf = -96;
3730 if (ieee80211_hw_check(hw, SIGNAL_DBM) &&
3731 !(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
3732 rx_stats.c_rssi = rx_status->signal;
3734 rx_stats.c_rssi = 0;
3735 rx_stats.c_rssi -= rx_stats.c_nf;
3736 rx_stats.r_flags |= IEEE80211_R_BAND;
3738 lkpi_nl80211_band_to_net80211_band(rx_status->band);
3739 rx_stats.r_flags |= IEEE80211_R_FREQ | IEEE80211_R_IEEE;
3740 rx_stats.c_freq = rx_status->freq;
3741 rx_stats.c_ieee = ieee80211_mhz2ieee(rx_stats.c_freq, rx_stats.c_band);
3743 /* XXX (*sta_statistics)() to get to some of that? */
3744 /* XXX-BZ dump the FreeBSD version of rx_stats as well! */
3746 lhw = HW_TO_LHW(hw);
3749 ok = ieee80211_add_rx_params(m, &rx_stats);
3751 counter_u64_add(ic->ic_ierrors, 1);
3756 lsta = STA_TO_LSTA(sta);
3757 ni = ieee80211_ref_node(lsta->ni);
3759 struct ieee80211_frame_min *wh;
3761 wh = mtod(m, struct ieee80211_frame_min *);
3762 ni = ieee80211_find_rxnode(ic, wh);
3764 lsta = ni->ni_drv_data;
3771 * XXX-BZ can we improve this by looking at the frame hdr
3772 * or other meta-data passed up?
3774 vap = TAILQ_FIRST(&ic->ic_vaps);
3776 #ifdef LINUXKPI_DEBUG_80211
3777 if (linuxkpi_debug_80211 & D80211_TRACE_RX)
3778 printf("TRACE %s: sta %p lsta %p state %d ni %p vap %p%s\n",
3779 __func__, sta, lsta, (lsta != NULL) ? lsta->state : -1,
3780 ni, vap, is_beacon ? " beacon" : "");
3783 if (ni != NULL && vap != NULL && is_beacon &&
3784 rx_status->device_timestamp > 0 &&
3785 m->m_pkthdr.len >= sizeof(struct ieee80211_frame)) {
3786 struct lkpi_vif *lvif;
3787 struct ieee80211_vif *vif;
3788 struct ieee80211_frame *wh;
3790 wh = mtod(m, struct ieee80211_frame *);
3791 if (!IEEE80211_ADDR_EQ(wh->i_addr2, ni->ni_bssid))
3792 goto skip_device_ts;
3794 lvif = VAP_TO_LVIF(vap);
3795 vif = LVIF_TO_VIF(lvif);
3797 IMPROVE("TIMING_BEACON_ONLY?");
3798 /* mac80211 specific (not net80211) so keep it here. */
3799 vif->bss_conf.sync_device_ts = rx_status->device_timestamp;
3801 * net80211 should take care of the other information (sync_tsf,
3802 * sync_dtim_count) as otherwise we need to parse the beacon.
3807 if (vap != NULL && vap->iv_state > IEEE80211_S_INIT &&
3808 ieee80211_radiotap_active_vap(vap)) {
3809 struct lkpi_radiotap_rx_hdr *rtap;
3811 rtap = &lhw->rtap_rx;
3812 rtap->wr_tsft = rx_status->device_timestamp;
3814 if (rx_status->enc_flags & RX_ENC_FLAG_SHORTPRE)
3815 rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
3816 if (rx_status->enc_flags & RX_ENC_FLAG_SHORT_GI)
3817 rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTGI;
3818 #if 0 /* .. or it does not given we strip it below. */
3819 if (ieee80211_hw_check(hw, RX_INCLUDES_FCS))
3820 rtap->wr_flags |= IEEE80211_RADIOTAP_F_FCS;
3822 if (rx_status->flag & RX_FLAG_FAILED_FCS_CRC)
3823 rtap->wr_flags |= IEEE80211_RADIOTAP_F_BADFCS;
3826 /* XXX TODO status->encoding / rate_index / bw */
3827 rtap->wr_chan_freq = htole16(rx_stats.c_freq);
3828 if (ic->ic_curchan->ic_ieee == rx_stats.c_ieee)
3829 rtap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags);
3830 rtap->wr_dbm_antsignal = rx_stats.c_rssi;
3831 rtap->wr_dbm_antnoise = rx_stats.c_nf;
3834 if (ieee80211_hw_check(hw, RX_INCLUDES_FCS))
3835 m_adj(m, -IEEE80211_CRC_LEN);
3837 NET_EPOCH_ENTER(et);
3839 ok = ieee80211_input_mimo(ni, m);
3840 ieee80211_free_node(ni);
3842 ok = ieee80211_input_mimo_all(ic, m);
3846 #ifdef LINUXKPI_DEBUG_80211
3847 if (linuxkpi_debug_80211 & D80211_TRACE_RX)
3848 printf("TRACE %s: handled frame type %#0x\n", __func__, ok);
3854 /* The skb is ours so we can free it :-) */
3859 linuxkpi_ieee80211_get_tid(struct ieee80211_hdr *hdr)
3861 const struct ieee80211_frame *wh;
3863 wh = (const struct ieee80211_frame *)hdr;
3864 return (ieee80211_gettid(wh));
3868 linuxkpi_wiphy_new(const struct cfg80211_ops *ops, size_t priv_len)
3870 struct lkpi_wiphy *lwiphy;
3872 lwiphy = kzalloc(sizeof(*lwiphy) + priv_len, GFP_KERNEL);
3878 return (LWIPHY_TO_WIPHY(lwiphy));
3882 linuxkpi_wiphy_free(struct wiphy *wiphy)
3884 struct lkpi_wiphy *lwiphy;
3889 lwiphy = WIPHY_TO_LWIPHY(wiphy);
3894 linuxkpi_ieee80211_channel_to_frequency(uint32_t channel,
3895 enum nl80211_band band)
3899 case NL80211_BAND_2GHZ:
3900 return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_2GHZ));
3902 case NL80211_BAND_5GHZ:
3903 return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_5GHZ));
3906 /* XXX abort, retry, error, panic? */
3914 linuxkpi_ieee80211_frequency_to_channel(uint32_t freq, uint32_t flags __unused)
3917 return (ieee80211_mhz2ieee(freq, 0));
3920 static struct lkpi_sta *
3921 lkpi_find_lsta_by_ni(struct lkpi_vif *lvif, struct ieee80211_node *ni)
3923 struct lkpi_sta *lsta, *temp;
3925 LKPI_80211_LVIF_LOCK(lvif);
3926 TAILQ_FOREACH_SAFE(lsta, &lvif->lsta_head, lsta_entry, temp) {
3927 if (lsta->ni == ni) {
3928 LKPI_80211_LVIF_UNLOCK(lvif);
3932 LKPI_80211_LVIF_UNLOCK(lvif);
3937 struct ieee80211_sta *
3938 linuxkpi_ieee80211_find_sta(struct ieee80211_vif *vif, const u8 *peer)
3940 struct lkpi_vif *lvif;
3941 struct lkpi_sta *lsta, *temp;
3942 struct ieee80211_sta *sta;
3944 lvif = VIF_TO_LVIF(vif);
3946 LKPI_80211_LVIF_LOCK(lvif);
3947 TAILQ_FOREACH_SAFE(lsta, &lvif->lsta_head, lsta_entry, temp) {
3948 sta = LSTA_TO_STA(lsta);
3949 if (IEEE80211_ADDR_EQ(sta->addr, peer)) {
3950 LKPI_80211_LVIF_UNLOCK(lvif);
3954 LKPI_80211_LVIF_UNLOCK(lvif);
3958 struct ieee80211_sta *
3959 linuxkpi_ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw,
3960 const uint8_t *addr, const uint8_t *ourvifaddr)
3962 struct lkpi_hw *lhw;
3963 struct lkpi_vif *lvif;
3964 struct lkpi_sta *lsta;
3965 struct ieee80211_vif *vif;
3966 struct ieee80211_sta *sta;
3968 lhw = wiphy_priv(hw->wiphy);
3971 LKPI_80211_LHW_LOCK(lhw);
3972 TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) {
3974 /* XXX-BZ check our address from the vif. */
3976 vif = LVIF_TO_VIF(lvif);
3977 if (ourvifaddr != NULL &&
3978 !IEEE80211_ADDR_EQ(vif->addr, ourvifaddr))
3980 sta = linuxkpi_ieee80211_find_sta(vif, addr);
3984 LKPI_80211_LHW_UNLOCK(lhw);
3987 lsta = STA_TO_LSTA(sta);
3988 if (!lsta->added_to_drv)
3996 linuxkpi_ieee80211_tx_dequeue(struct ieee80211_hw *hw,
3997 struct ieee80211_txq *txq)
3999 struct lkpi_txq *ltxq;
4000 struct sk_buff *skb;
4002 ltxq = TXQ_TO_LTXQ(txq);
4003 ltxq->seen_dequeue = true;
4005 skb = skb_dequeue(<xq->skbq);
4011 linuxkpi_ieee80211_txq_get_depth(struct ieee80211_txq *txq,
4012 unsigned long *frame_cnt, unsigned long *byte_cnt)
4014 struct lkpi_txq *ltxq;
4015 struct sk_buff *skb;
4016 unsigned long fc, bc;
4018 ltxq = TXQ_TO_LTXQ(txq);
4021 skb_queue_walk(<xq->skbq, skb) {
4030 /* Validate that this is doing the correct thing. */
4031 /* Should we keep track on en/dequeue? */
4036 * We are called from ieee80211_free_txskb() or ieee80211_tx_status().
4037 * The latter tries to derive the success status from the info flags
4038 * passed back from the driver. rawx_mit() saves the ni on the m and the
4039 * m on the skb for us to be able to give feedback to net80211.
4042 linuxkpi_ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb,
4045 struct ieee80211_node *ni;
4052 ni = m->m_pkthdr.PH_loc.ptr;
4053 /* Status: 0 is ok, != 0 is error. */
4054 ieee80211_tx_complete(ni, m, status);
4055 /* ni & mbuf were consumed. */
4062 * This is an internal bandaid for the moment for the way we glue
4063 * skbs and mbufs together for TX. Once we have skbs backed by
4064 * mbufs this should go away.
4065 * This is a public function but kept on the private KPI (lkpi_)
4066 * and is not exposed by a header file.
4069 lkpi_ieee80211_free_skb_mbuf(void *p)
4071 struct ieee80211_node *ni;
4077 m = (struct mbuf *)p;
4080 ni = m->m_pkthdr.PH_loc.ptr;
4081 m->m_pkthdr.PH_loc.ptr = NULL;
4083 ieee80211_free_node(ni);
4088 linuxkpi_ieee80211_queue_delayed_work(struct ieee80211_hw *hw,
4089 struct delayed_work *w, int delay)
4091 struct lkpi_hw *lhw;
4093 /* Need to make sure hw is in a stable (non-suspended) state. */
4096 lhw = HW_TO_LHW(hw);
4097 queue_delayed_work(lhw->workq, w, delay);
4101 linuxkpi_ieee80211_queue_work(struct ieee80211_hw *hw,
4102 struct work_struct *w)
4104 struct lkpi_hw *lhw;
4106 /* Need to make sure hw is in a stable (non-suspended) state. */
4109 lhw = HW_TO_LHW(hw);
4110 queue_work(lhw->workq, w);
4114 linuxkpi_ieee80211_pspoll_get(struct ieee80211_hw *hw,
4115 struct ieee80211_vif *vif)
4117 struct lkpi_vif *lvif;
4118 struct ieee80211vap *vap;
4119 struct sk_buff *skb;
4120 struct ieee80211_frame_pspoll *psp;
4123 skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*psp));
4127 skb_reserve(skb, hw->extra_tx_headroom);
4129 lvif = VIF_TO_LVIF(vif);
4130 vap = LVIF_TO_VAP(lvif);
4132 psp = skb_put_zero(skb, sizeof(*psp));
4133 psp->i_fc[0] = IEEE80211_FC0_VERSION_0;
4134 psp->i_fc[0] |= IEEE80211_FC0_SUBTYPE_PS_POLL | IEEE80211_FC0_TYPE_CTL;
4135 v = htole16(vif->bss_conf.aid | 1<<15 | 1<<16);
4136 memcpy(&psp->i_aid, &v, sizeof(v));
4137 IEEE80211_ADDR_COPY(psp->i_bssid, vap->iv_bss->ni_macaddr);
4138 IEEE80211_ADDR_COPY(psp->i_ta, vif->addr);
4144 linuxkpi_ieee80211_nullfunc_get(struct ieee80211_hw *hw,
4145 struct ieee80211_vif *vif, bool qos)
4147 struct lkpi_vif *lvif;
4148 struct ieee80211vap *vap;
4149 struct sk_buff *skb;
4150 struct ieee80211_frame *nullf;
4152 skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*nullf));
4156 skb_reserve(skb, hw->extra_tx_headroom);
4158 lvif = VIF_TO_LVIF(vif);
4159 vap = LVIF_TO_VAP(lvif);
4161 nullf = skb_put_zero(skb, sizeof(*nullf));
4162 nullf->i_fc[0] = IEEE80211_FC0_VERSION_0;
4163 nullf->i_fc[0] |= IEEE80211_FC0_SUBTYPE_NODATA | IEEE80211_FC0_TYPE_DATA;
4164 nullf->i_fc[1] = IEEE80211_FC1_DIR_TODS;
4166 IEEE80211_ADDR_COPY(nullf->i_addr1, vap->iv_bss->ni_bssid);
4167 IEEE80211_ADDR_COPY(nullf->i_addr2, vif->addr);
4168 IEEE80211_ADDR_COPY(nullf->i_addr3, vap->iv_bss->ni_macaddr);
4173 struct wireless_dev *
4174 linuxkpi_ieee80211_vif_to_wdev(struct ieee80211_vif *vif)
4176 struct lkpi_vif *lvif;
4178 lvif = VIF_TO_LVIF(vif);
4179 return (&lvif->wdev);
4183 linuxkpi_ieee80211_connection_loss(struct ieee80211_vif *vif)
4185 struct lkpi_vif *lvif;
4186 struct ieee80211vap *vap;
4187 enum ieee80211_state nstate;
4190 lvif = VIF_TO_LVIF(vif);
4191 vap = LVIF_TO_VAP(lvif);
4194 * Go to init; otherwise we need to elaborately check state and
4195 * handle accordingly, e.g., if in RUN we could call iv_bmiss.
4196 * Let the statemachine handle all neccessary changes.
4198 nstate = IEEE80211_S_INIT;
4199 arg = 0; /* Not a valid reason. */
4201 #ifdef LINUXKPI_DEBUG_80211
4202 if (linuxkpi_debug_80211 & D80211_TRACE)
4203 ic_printf(vap->iv_ic, "%s: vif %p\n", __func__, vif);
4205 ieee80211_new_state(vap, nstate, arg);
4209 linuxkpi_ieee80211_beacon_loss(struct ieee80211_vif *vif)
4211 struct lkpi_vif *lvif;
4212 struct ieee80211vap *vap;
4213 enum ieee80211_state nstate;
4216 lvif = VIF_TO_LVIF(vif);
4217 vap = LVIF_TO_VAP(lvif);
4220 * Go to scan; otherwise we need to elaborately check state and
4221 * handle accordingly, e.g., if in RUN we could call iv_bmiss.
4222 * Let the statemachine handle all neccessary changes.
4224 nstate = IEEE80211_S_SCAN;
4227 /* We should be in RUN. Can we assert that? */
4228 #ifdef LINUXKPI_DEBUG_80211
4229 if (linuxkpi_debug_80211 & D80211_TRACE || vap->iv_state != IEEE80211_S_RUN)
4230 ic_printf(vap->iv_ic, "%s: vif %p vap %p state %s\n", __func__,
4231 vif, vap, ieee80211_state_name[vap->iv_state]);
4233 ieee80211_new_state(vap, nstate, arg);
4236 MODULE_VERSION(linuxkpi_wlan, 1);
4237 MODULE_DEPEND(linuxkpi_wlan, linuxkpi, 1, 1, 1);
4238 MODULE_DEPEND(linuxkpi_wlan, wlan, 1, 1, 1);