1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2002-2005, Instant802 Networks, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
5 * Copyright 2013-2014 Intel Mobile Communications GmbH
6 * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
7 * Copyright (C) 2018-2022 Intel Corporation
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/etherdevice.h>
13 #include <linux/netdevice.h>
14 #include <linux/types.h>
15 #include <linux/slab.h>
16 #include <linux/skbuff.h>
17 #include <linux/if_arp.h>
18 #include <linux/timer.h>
19 #include <linux/rtnetlink.h>
21 #include <net/codel.h>
22 #include <net/mac80211.h>
23 #include "ieee80211_i.h"
24 #include "driver-ops.h"
27 #include "debugfs_sta.h"
32 * DOC: STA information lifetime rules
34 * STA info structures (&struct sta_info) are managed in a hash table
35 * for faster lookup and a list for iteration. They are managed using
36 * RCU, i.e. access to the list and hash table is protected by RCU.
38 * Upon allocating a STA info structure with sta_info_alloc(), the caller
39 * owns that structure. It must then insert it into the hash table using
40 * either sta_info_insert() or sta_info_insert_rcu(); only in the latter
41 * case (which acquires an rcu read section but must not be called from
42 * within one) will the pointer still be valid after the call. Note that
43 * the caller may not do much with the STA info before inserting it, in
44 * particular, it may not start any mesh peer link management or add
47 * When the insertion fails (sta_info_insert()) returns non-zero), the
48 * structure will have been freed by sta_info_insert()!
50 * Station entries are added by mac80211 when you establish a link with a
51 * peer. This means different things for the different type of interfaces
52 * we support. For a regular station this mean we add the AP sta when we
53 * receive an association response from the AP. For IBSS this occurs when
54 * get to know about a peer on the same IBSS. For WDS we add the sta for
55 * the peer immediately upon device open. When using AP mode we add stations
56 * for each respective station upon request from userspace through nl80211.
58 * In order to remove a STA info structure, various sta_info_destroy_*()
59 * calls are available.
61 * There is no concept of ownership on a STA entry, each structure is
62 * owned by the global hash table/list until it is removed. All users of
63 * the structure need to be RCU protected so that the structure won't be
64 * freed before they are done using it.
67 struct sta_link_alloc {
68 struct link_sta_info info;
69 struct ieee80211_link_sta sta;
70 struct rcu_head rcu_head;
73 static const struct rhashtable_params sta_rht_params = {
74 .nelem_hint = 3, /* start small */
75 .automatic_shrinking = true,
76 .head_offset = offsetof(struct sta_info, hash_node),
77 .key_offset = offsetof(struct sta_info, addr),
79 .max_size = CONFIG_MAC80211_STA_HASH_MAX_SIZE,
82 static const struct rhashtable_params link_sta_rht_params = {
83 .nelem_hint = 3, /* start small */
84 .automatic_shrinking = true,
85 .head_offset = offsetof(struct link_sta_info, link_hash_node),
86 .key_offset = offsetof(struct link_sta_info, addr),
88 .max_size = CONFIG_MAC80211_STA_HASH_MAX_SIZE,
91 /* Caller must hold local->sta_mtx */
92 static int sta_info_hash_del(struct ieee80211_local *local,
95 return rhltable_remove(&local->sta_hash, &sta->hash_node,
99 static int link_sta_info_hash_add(struct ieee80211_local *local,
100 struct link_sta_info *link_sta)
102 lockdep_assert_held(&local->sta_mtx);
103 return rhltable_insert(&local->link_sta_hash,
104 &link_sta->link_hash_node,
105 link_sta_rht_params);
108 static int link_sta_info_hash_del(struct ieee80211_local *local,
109 struct link_sta_info *link_sta)
111 lockdep_assert_held(&local->sta_mtx);
112 return rhltable_remove(&local->link_sta_hash,
113 &link_sta->link_hash_node,
114 link_sta_rht_params);
117 static void __cleanup_single_sta(struct sta_info *sta)
120 struct tid_ampdu_tx *tid_tx;
121 struct ieee80211_sub_if_data *sdata = sta->sdata;
122 struct ieee80211_local *local = sdata->local;
125 if (test_sta_flag(sta, WLAN_STA_PS_STA) ||
126 test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
127 test_sta_flag(sta, WLAN_STA_PS_DELIVER)) {
128 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
129 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
130 ps = &sdata->bss->ps;
131 else if (ieee80211_vif_is_mesh(&sdata->vif))
132 ps = &sdata->u.mesh.ps;
136 clear_sta_flag(sta, WLAN_STA_PS_STA);
137 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
138 clear_sta_flag(sta, WLAN_STA_PS_DELIVER);
140 atomic_dec(&ps->num_sta_ps);
143 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
144 struct txq_info *txqi;
146 if (!sta->sta.txq[i])
149 txqi = to_txq_info(sta->sta.txq[i]);
151 ieee80211_txq_purge(local, txqi);
154 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
155 local->total_ps_buffered -= skb_queue_len(&sta->ps_tx_buf[ac]);
156 ieee80211_purge_tx_queue(&local->hw, &sta->ps_tx_buf[ac]);
157 ieee80211_purge_tx_queue(&local->hw, &sta->tx_filtered[ac]);
160 if (ieee80211_vif_is_mesh(&sdata->vif))
161 mesh_sta_cleanup(sta);
163 cancel_work_sync(&sta->drv_deliver_wk);
166 * Destroy aggregation state here. It would be nice to wait for the
167 * driver to finish aggregation stop and then clean up, but for now
168 * drivers have to handle aggregation stop being requested, followed
169 * directly by station destruction.
171 for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
172 kfree(sta->ampdu_mlme.tid_start_tx[i]);
173 tid_tx = rcu_dereference_raw(sta->ampdu_mlme.tid_tx[i]);
176 ieee80211_purge_tx_queue(&local->hw, &tid_tx->pending);
181 static void cleanup_single_sta(struct sta_info *sta)
183 struct ieee80211_sub_if_data *sdata = sta->sdata;
184 struct ieee80211_local *local = sdata->local;
186 __cleanup_single_sta(sta);
187 sta_info_free(local, sta);
190 struct rhlist_head *sta_info_hash_lookup(struct ieee80211_local *local,
193 return rhltable_lookup(&local->sta_hash, addr, sta_rht_params);
196 /* protected by RCU */
197 struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata,
200 struct ieee80211_local *local = sdata->local;
201 struct rhlist_head *tmp;
202 struct sta_info *sta;
205 for_each_sta_info(local, addr, sta, tmp) {
206 if (sta->sdata == sdata) {
208 /* this is safe as the caller must already hold
209 * another rcu read section or the mutex
219 * Get sta info either from the specified interface
220 * or from one of its vlans
222 struct sta_info *sta_info_get_bss(struct ieee80211_sub_if_data *sdata,
225 struct ieee80211_local *local = sdata->local;
226 struct rhlist_head *tmp;
227 struct sta_info *sta;
230 for_each_sta_info(local, addr, sta, tmp) {
231 if (sta->sdata == sdata ||
232 (sta->sdata->bss && sta->sdata->bss == sdata->bss)) {
234 /* this is safe as the caller must already hold
235 * another rcu read section or the mutex
244 struct rhlist_head *link_sta_info_hash_lookup(struct ieee80211_local *local,
247 return rhltable_lookup(&local->link_sta_hash, addr,
248 link_sta_rht_params);
251 struct link_sta_info *
252 link_sta_info_get_bss(struct ieee80211_sub_if_data *sdata, const u8 *addr)
254 struct ieee80211_local *local = sdata->local;
255 struct rhlist_head *tmp;
256 struct link_sta_info *link_sta;
259 for_each_link_sta_info(local, addr, link_sta, tmp) {
260 struct sta_info *sta = link_sta->sta;
262 if (sta->sdata == sdata ||
263 (sta->sdata->bss && sta->sdata->bss == sdata->bss)) {
265 /* this is safe as the caller must already hold
266 * another rcu read section or the mutex
275 struct ieee80211_sta *
276 ieee80211_find_sta_by_link_addrs(struct ieee80211_hw *hw,
279 unsigned int *link_id)
281 struct ieee80211_local *local = hw_to_local(hw);
282 struct link_sta_info *link_sta;
283 struct rhlist_head *tmp;
285 for_each_link_sta_info(local, addr, link_sta, tmp) {
286 struct sta_info *sta = link_sta->sta;
287 struct ieee80211_link_data *link;
288 u8 _link_id = link_sta->link_id;
296 link = rcu_dereference(sta->sdata->link[_link_id]);
300 if (memcmp(link->conf->addr, localaddr, ETH_ALEN))
310 EXPORT_SYMBOL_GPL(ieee80211_find_sta_by_link_addrs);
312 struct sta_info *sta_info_get_by_addrs(struct ieee80211_local *local,
313 const u8 *sta_addr, const u8 *vif_addr)
315 struct rhlist_head *tmp;
316 struct sta_info *sta;
318 for_each_sta_info(local, sta_addr, sta, tmp) {
319 if (ether_addr_equal(vif_addr, sta->sdata->vif.addr))
326 struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata,
329 struct ieee80211_local *local = sdata->local;
330 struct sta_info *sta;
333 list_for_each_entry_rcu(sta, &local->sta_list, list,
334 lockdep_is_held(&local->sta_mtx)) {
335 if (sdata != sta->sdata)
347 static void sta_info_free_link(struct link_sta_info *link_sta)
349 free_percpu(link_sta->pcpu_rx_stats);
352 static void sta_remove_link(struct sta_info *sta, unsigned int link_id,
355 struct sta_link_alloc *alloc = NULL;
356 struct link_sta_info *link_sta;
358 link_sta = rcu_dereference_protected(sta->link[link_id],
359 lockdep_is_held(&sta->local->sta_mtx));
361 if (WARN_ON(!link_sta))
365 link_sta_info_hash_del(sta->local, link_sta);
367 if (test_sta_flag(sta, WLAN_STA_INSERTED))
368 ieee80211_link_sta_debugfs_remove(link_sta);
370 if (link_sta != &sta->deflink)
371 alloc = container_of(link_sta, typeof(*alloc), info);
373 sta->sta.valid_links &= ~BIT(link_id);
374 RCU_INIT_POINTER(sta->link[link_id], NULL);
375 RCU_INIT_POINTER(sta->sta.link[link_id], NULL);
377 sta_info_free_link(&alloc->info);
378 kfree_rcu(alloc, rcu_head);
381 ieee80211_sta_recalc_aggregates(&sta->sta);
385 * sta_info_free - free STA
387 * @local: pointer to the global information
388 * @sta: STA info to free
390 * This function must undo everything done by sta_info_alloc()
391 * that may happen before sta_info_insert(). It may only be
392 * called when sta_info_insert() has not been attempted (and
393 * if that fails, the station is freed anyway.)
395 void sta_info_free(struct ieee80211_local *local, struct sta_info *sta)
399 for (i = 0; i < ARRAY_SIZE(sta->link); i++) {
400 if (!(sta->sta.valid_links & BIT(i)))
403 sta_remove_link(sta, i, false);
407 * If we had used sta_info_pre_move_state() then we might not
408 * have gone through the state transitions down again, so do
409 * it here now (and warn if it's inserted).
411 * This will clear state such as fast TX/RX that may have been
412 * allocated during state transitions.
414 while (sta->sta_state > IEEE80211_STA_NONE) {
417 WARN_ON_ONCE(test_sta_flag(sta, WLAN_STA_INSERTED));
419 ret = sta_info_move_state(sta, sta->sta_state - 1);
420 if (WARN_ONCE(ret, "sta_info_move_state() returned %d\n", ret))
425 rate_control_free_sta(sta);
427 sta_dbg(sta->sdata, "Destroyed STA %pM\n", sta->sta.addr);
429 kfree(to_txq_info(sta->sta.txq[0]));
430 kfree(rcu_dereference_raw(sta->sta.rates));
431 #ifdef CONFIG_MAC80211_MESH
435 sta_info_free_link(&sta->deflink);
439 /* Caller must hold local->sta_mtx */
440 static int sta_info_hash_add(struct ieee80211_local *local,
441 struct sta_info *sta)
443 return rhltable_insert(&local->sta_hash, &sta->hash_node,
447 static void sta_deliver_ps_frames(struct work_struct *wk)
449 struct sta_info *sta;
451 sta = container_of(wk, struct sta_info, drv_deliver_wk);
457 if (!test_sta_flag(sta, WLAN_STA_PS_STA))
458 ieee80211_sta_ps_deliver_wakeup(sta);
459 else if (test_and_clear_sta_flag(sta, WLAN_STA_PSPOLL))
460 ieee80211_sta_ps_deliver_poll_response(sta);
461 else if (test_and_clear_sta_flag(sta, WLAN_STA_UAPSD))
462 ieee80211_sta_ps_deliver_uapsd(sta);
466 static int sta_prepare_rate_control(struct ieee80211_local *local,
467 struct sta_info *sta, gfp_t gfp)
469 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL))
472 sta->rate_ctrl = local->rate_ctrl;
473 sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl,
475 if (!sta->rate_ctrl_priv)
481 static int sta_info_alloc_link(struct ieee80211_local *local,
482 struct link_sta_info *link_info,
485 struct ieee80211_hw *hw = &local->hw;
488 if (ieee80211_hw_check(hw, USES_RSS)) {
489 link_info->pcpu_rx_stats =
490 alloc_percpu_gfp(struct ieee80211_sta_rx_stats, gfp);
491 if (!link_info->pcpu_rx_stats)
495 link_info->rx_stats.last_rx = jiffies;
496 u64_stats_init(&link_info->rx_stats.syncp);
498 ewma_signal_init(&link_info->rx_stats_avg.signal);
499 ewma_avg_signal_init(&link_info->status_stats.avg_ack_signal);
500 for (i = 0; i < ARRAY_SIZE(link_info->rx_stats_avg.chain_signal); i++)
501 ewma_signal_init(&link_info->rx_stats_avg.chain_signal[i]);
506 static void sta_info_add_link(struct sta_info *sta,
507 unsigned int link_id,
508 struct link_sta_info *link_info,
509 struct ieee80211_link_sta *link_sta)
511 link_info->sta = sta;
512 link_info->link_id = link_id;
513 link_info->pub = link_sta;
514 link_info->pub->sta = &sta->sta;
515 link_sta->link_id = link_id;
516 rcu_assign_pointer(sta->link[link_id], link_info);
517 rcu_assign_pointer(sta->sta.link[link_id], link_sta);
519 link_sta->smps_mode = IEEE80211_SMPS_OFF;
520 link_sta->agg.max_rc_amsdu_len = IEEE80211_MAX_MPDU_LEN_HT_BA;
523 static struct sta_info *
524 __sta_info_alloc(struct ieee80211_sub_if_data *sdata,
525 const u8 *addr, int link_id, const u8 *link_addr,
528 struct ieee80211_local *local = sdata->local;
529 struct ieee80211_hw *hw = &local->hw;
530 struct sta_info *sta;
535 sta = kzalloc(sizeof(*sta) + hw->sta_data_size, gfp);
542 if (sta_info_alloc_link(local, &sta->deflink, gfp))
546 sta_info_add_link(sta, link_id, &sta->deflink,
548 sta->sta.valid_links = BIT(link_id);
550 sta_info_add_link(sta, 0, &sta->deflink, &sta->sta.deflink);
553 sta->sta.cur = &sta->sta.deflink.agg;
555 spin_lock_init(&sta->lock);
556 spin_lock_init(&sta->ps_lock);
557 INIT_WORK(&sta->drv_deliver_wk, sta_deliver_ps_frames);
558 INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work);
559 mutex_init(&sta->ampdu_mlme.mtx);
560 #ifdef CONFIG_MAC80211_MESH
561 if (ieee80211_vif_is_mesh(&sdata->vif)) {
562 sta->mesh = kzalloc(sizeof(*sta->mesh), gfp);
565 sta->mesh->plink_sta = sta;
566 spin_lock_init(&sta->mesh->plink_lock);
567 if (!sdata->u.mesh.user_mpm)
568 timer_setup(&sta->mesh->plink_timer, mesh_plink_timer,
570 sta->mesh->nonpeer_pm = NL80211_MESH_POWER_ACTIVE;
574 memcpy(sta->addr, addr, ETH_ALEN);
575 memcpy(sta->sta.addr, addr, ETH_ALEN);
576 memcpy(sta->deflink.addr, link_addr, ETH_ALEN);
577 memcpy(sta->sta.deflink.addr, link_addr, ETH_ALEN);
578 sta->sta.max_rx_aggregation_subframes =
579 local->hw.max_rx_aggregation_subframes;
581 /* TODO link specific alloc and assignments for MLO Link STA */
583 /* Extended Key ID needs to install keys for keyid 0 and 1 Rx-only.
584 * The Tx path starts to use a key as soon as the key slot ptk_idx
585 * references to is not NULL. To not use the initial Rx-only key
586 * prematurely for Tx initialize ptk_idx to an impossible PTK keyid
587 * which always will refer to a NULL key.
589 BUILD_BUG_ON(ARRAY_SIZE(sta->ptk) <= INVALID_PTK_KEYIDX);
590 sta->ptk_idx = INVALID_PTK_KEYIDX;
593 ieee80211_init_frag_cache(&sta->frags);
595 sta->sta_state = IEEE80211_STA_NONE;
597 if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
598 sta->amsdu_mesh_control = -1;
600 /* Mark TID as unreserved */
601 sta->reserved_tid = IEEE80211_TID_UNRESERVED;
603 sta->last_connected = ktime_get_seconds();
605 size = sizeof(struct txq_info) +
606 ALIGN(hw->txq_data_size, sizeof(void *));
608 txq_data = kcalloc(ARRAY_SIZE(sta->sta.txq), size, gfp);
612 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
613 struct txq_info *txq = txq_data + i * size;
615 /* might not do anything for the (bufferable) MMPDU TXQ */
616 ieee80211_txq_init(sdata, sta, txq, i);
619 if (sta_prepare_rate_control(local, sta, gfp))
622 sta->airtime_weight = IEEE80211_DEFAULT_AIRTIME_WEIGHT;
624 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
625 skb_queue_head_init(&sta->ps_tx_buf[i]);
626 skb_queue_head_init(&sta->tx_filtered[i]);
627 sta->airtime[i].deficit = sta->airtime_weight;
628 atomic_set(&sta->airtime[i].aql_tx_pending, 0);
629 sta->airtime[i].aql_limit_low = local->aql_txq_limit_low[i];
630 sta->airtime[i].aql_limit_high = local->aql_txq_limit_high[i];
633 for (i = 0; i < IEEE80211_NUM_TIDS; i++)
634 sta->last_seq_ctrl[i] = cpu_to_le16(USHRT_MAX);
636 for (i = 0; i < NUM_NL80211_BANDS; i++) {
640 if (!hw->wiphy->bands[i])
644 case NL80211_BAND_2GHZ:
645 case NL80211_BAND_LC:
647 * We use both here, even if we cannot really know for
648 * sure the station will support both, but the only use
649 * for this is when we don't know anything yet and send
650 * management frames, and then we'll pick the lowest
651 * possible rate anyway.
652 * If we don't include _G here, we cannot find a rate
653 * in P2P, and thus trigger the WARN_ONCE() in rate.c
655 mandatory = IEEE80211_RATE_MANDATORY_B |
656 IEEE80211_RATE_MANDATORY_G;
658 case NL80211_BAND_5GHZ:
659 mandatory = IEEE80211_RATE_MANDATORY_A;
661 case NL80211_BAND_60GHZ:
667 for (r = 0; r < hw->wiphy->bands[i]->n_bitrates; r++) {
668 struct ieee80211_rate *rate;
670 rate = &hw->wiphy->bands[i]->bitrates[r];
672 if (!(rate->flags & mandatory))
674 sta->sta.deflink.supp_rates[i] |= BIT(r);
678 sta->cparams.ce_threshold = CODEL_DISABLED_THRESHOLD;
679 sta->cparams.target = MS2TIME(20);
680 sta->cparams.interval = MS2TIME(100);
681 sta->cparams.ecn = true;
682 sta->cparams.ce_threshold_selector = 0;
683 sta->cparams.ce_threshold_mask = 0;
685 sta_dbg(sdata, "Allocated STA %pM\n", sta->sta.addr);
690 kfree(to_txq_info(sta->sta.txq[0]));
692 sta_info_free_link(&sta->deflink);
693 #ifdef CONFIG_MAC80211_MESH
700 struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
701 const u8 *addr, gfp_t gfp)
703 return __sta_info_alloc(sdata, addr, -1, addr, gfp);
706 struct sta_info *sta_info_alloc_with_link(struct ieee80211_sub_if_data *sdata,
708 unsigned int link_id,
712 return __sta_info_alloc(sdata, mld_addr, link_id, link_addr, gfp);
715 static int sta_info_insert_check(struct sta_info *sta)
717 struct ieee80211_sub_if_data *sdata = sta->sdata;
720 * Can't be a WARN_ON because it can be triggered through a race:
721 * something inserts a STA (on one CPU) without holding the RTNL
722 * and another CPU turns off the net device.
724 if (unlikely(!ieee80211_sdata_running(sdata)))
727 if (WARN_ON(ether_addr_equal(sta->sta.addr, sdata->vif.addr) ||
728 !is_valid_ether_addr(sta->sta.addr)))
731 /* The RCU read lock is required by rhashtable due to
732 * asynchronous resize/rehash. We also require the mutex
736 lockdep_assert_held(&sdata->local->sta_mtx);
737 if (ieee80211_hw_check(&sdata->local->hw, NEEDS_UNIQUE_STA_ADDR) &&
738 ieee80211_find_sta_by_ifaddr(&sdata->local->hw, sta->addr, NULL)) {
747 static int sta_info_insert_drv_state(struct ieee80211_local *local,
748 struct ieee80211_sub_if_data *sdata,
749 struct sta_info *sta)
751 enum ieee80211_sta_state state;
754 for (state = IEEE80211_STA_NOTEXIST; state < sta->sta_state; state++) {
755 err = drv_sta_state(local, sdata, sta, state, state + 1);
762 * Drivers using legacy sta_add/sta_remove callbacks only
763 * get uploaded set to true after sta_add is called.
765 if (!local->ops->sta_add)
766 sta->uploaded = true;
770 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
772 "failed to move IBSS STA %pM to state %d (%d) - keeping it anyway\n",
773 sta->sta.addr, state + 1, err);
777 /* unwind on error */
778 for (; state > IEEE80211_STA_NOTEXIST; state--)
779 WARN_ON(drv_sta_state(local, sdata, sta, state, state - 1));
785 ieee80211_recalc_p2p_go_ps_allowed(struct ieee80211_sub_if_data *sdata)
787 struct ieee80211_local *local = sdata->local;
788 bool allow_p2p_go_ps = sdata->vif.p2p;
789 struct sta_info *sta;
792 list_for_each_entry_rcu(sta, &local->sta_list, list) {
793 if (sdata != sta->sdata ||
794 !test_sta_flag(sta, WLAN_STA_ASSOC))
796 if (!sta->sta.support_p2p_ps) {
797 allow_p2p_go_ps = false;
803 if (allow_p2p_go_ps != sdata->vif.bss_conf.allow_p2p_go_ps) {
804 sdata->vif.bss_conf.allow_p2p_go_ps = allow_p2p_go_ps;
805 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
811 * should be called with sta_mtx locked
812 * this function replaces the mutex lock
815 static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU)
817 struct ieee80211_local *local = sta->local;
818 struct ieee80211_sub_if_data *sdata = sta->sdata;
819 struct station_info *sinfo = NULL;
822 lockdep_assert_held(&local->sta_mtx);
824 /* check if STA exists already */
825 if (sta_info_get_bss(sdata, sta->sta.addr)) {
830 sinfo = kzalloc(sizeof(struct station_info), GFP_KERNEL);
837 local->sta_generation++;
840 /* simplify things and don't accept BA sessions yet */
841 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
843 /* make the station visible */
844 err = sta_info_hash_add(local, sta);
848 if (sta->sta.valid_links) {
849 err = link_sta_info_hash_add(local, &sta->deflink);
851 sta_info_hash_del(local, sta);
856 list_add_tail_rcu(&sta->list, &local->sta_list);
858 /* update channel context before notifying the driver about state
859 * change, this enables driver using the updated channel context right away.
861 if (sta->sta_state >= IEEE80211_STA_ASSOC) {
862 ieee80211_recalc_min_chandef(sta->sdata, -1);
863 if (!sta->sta.support_p2p_ps)
864 ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
868 err = sta_info_insert_drv_state(local, sdata, sta);
872 set_sta_flag(sta, WLAN_STA_INSERTED);
874 /* accept BA sessions now */
875 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
877 ieee80211_sta_debugfs_add(sta);
878 rate_control_add_sta_debugfs(sta);
879 if (sta->sta.valid_links) {
882 for (i = 0; i < ARRAY_SIZE(sta->link); i++) {
883 struct link_sta_info *link_sta;
885 link_sta = rcu_dereference_protected(sta->link[i],
886 lockdep_is_held(&local->sta_mtx));
891 ieee80211_link_sta_debugfs_add(link_sta);
892 if (sdata->vif.active_links & BIT(i))
893 ieee80211_link_sta_debugfs_drv_add(link_sta);
896 ieee80211_link_sta_debugfs_add(&sta->deflink);
897 ieee80211_link_sta_debugfs_drv_add(&sta->deflink);
900 sinfo->generation = local->sta_generation;
901 cfg80211_new_sta(sdata->dev, sta->sta.addr, sinfo, GFP_KERNEL);
904 sta_dbg(sdata, "Inserted STA %pM\n", sta->sta.addr);
906 /* move reference to rcu-protected */
908 mutex_unlock(&local->sta_mtx);
910 if (ieee80211_vif_is_mesh(&sdata->vif))
911 mesh_accept_plinks_update(sdata);
915 if (sta->sta.valid_links)
916 link_sta_info_hash_del(local, &sta->deflink);
917 sta_info_hash_del(local, sta);
918 list_del_rcu(&sta->list);
923 cleanup_single_sta(sta);
924 mutex_unlock(&local->sta_mtx);
930 int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU)
932 struct ieee80211_local *local = sta->local;
937 mutex_lock(&local->sta_mtx);
939 err = sta_info_insert_check(sta);
941 sta_info_free(local, sta);
942 mutex_unlock(&local->sta_mtx);
947 return sta_info_insert_finish(sta);
950 int sta_info_insert(struct sta_info *sta)
952 int err = sta_info_insert_rcu(sta);
959 static inline void __bss_tim_set(u8 *tim, u16 id)
962 * This format has been mandated by the IEEE specifications,
963 * so this line may not be changed to use the __set_bit() format.
965 tim[id / 8] |= (1 << (id % 8));
968 static inline void __bss_tim_clear(u8 *tim, u16 id)
971 * This format has been mandated by the IEEE specifications,
972 * so this line may not be changed to use the __clear_bit() format.
974 tim[id / 8] &= ~(1 << (id % 8));
977 static inline bool __bss_tim_get(u8 *tim, u16 id)
980 * This format has been mandated by the IEEE specifications,
981 * so this line may not be changed to use the test_bit() format.
983 return tim[id / 8] & (1 << (id % 8));
986 static unsigned long ieee80211_tids_for_ac(int ac)
988 /* If we ever support TIDs > 7, this obviously needs to be adjusted */
990 case IEEE80211_AC_VO:
991 return BIT(6) | BIT(7);
992 case IEEE80211_AC_VI:
993 return BIT(4) | BIT(5);
994 case IEEE80211_AC_BE:
995 return BIT(0) | BIT(3);
996 case IEEE80211_AC_BK:
997 return BIT(1) | BIT(2);
1004 static void __sta_info_recalc_tim(struct sta_info *sta, bool ignore_pending)
1006 struct ieee80211_local *local = sta->local;
1008 bool indicate_tim = false;
1009 u8 ignore_for_tim = sta->sta.uapsd_queues;
1011 u16 id = sta->sta.aid;
1013 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1014 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
1015 if (WARN_ON_ONCE(!sta->sdata->bss))
1018 ps = &sta->sdata->bss->ps;
1019 #ifdef CONFIG_MAC80211_MESH
1020 } else if (ieee80211_vif_is_mesh(&sta->sdata->vif)) {
1021 ps = &sta->sdata->u.mesh.ps;
1027 /* No need to do anything if the driver does all */
1028 if (ieee80211_hw_check(&local->hw, AP_LINK_PS) && !local->ops->set_tim)
1035 * If all ACs are delivery-enabled then we should build
1036 * the TIM bit for all ACs anyway; if only some are then
1037 * we ignore those and build the TIM bit using only the
1040 if (ignore_for_tim == BIT(IEEE80211_NUM_ACS) - 1)
1044 ignore_for_tim = BIT(IEEE80211_NUM_ACS) - 1;
1046 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1049 if (ignore_for_tim & ieee80211_ac_to_qos_mask[ac])
1052 indicate_tim |= !skb_queue_empty(&sta->tx_filtered[ac]) ||
1053 !skb_queue_empty(&sta->ps_tx_buf[ac]);
1057 tids = ieee80211_tids_for_ac(ac);
1060 sta->driver_buffered_tids & tids;
1062 sta->txq_buffered_tids & tids;
1066 spin_lock_bh(&local->tim_lock);
1068 if (indicate_tim == __bss_tim_get(ps->tim, id))
1072 __bss_tim_set(ps->tim, id);
1074 __bss_tim_clear(ps->tim, id);
1076 if (local->ops->set_tim && !WARN_ON(sta->dead)) {
1077 local->tim_in_locked_section = true;
1078 drv_set_tim(local, &sta->sta, indicate_tim);
1079 local->tim_in_locked_section = false;
1083 spin_unlock_bh(&local->tim_lock);
1086 void sta_info_recalc_tim(struct sta_info *sta)
1088 __sta_info_recalc_tim(sta, false);
1091 static bool sta_info_buffer_expired(struct sta_info *sta, struct sk_buff *skb)
1093 struct ieee80211_tx_info *info;
1099 info = IEEE80211_SKB_CB(skb);
1101 /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */
1102 timeout = (sta->listen_interval *
1103 sta->sdata->vif.bss_conf.beacon_int *
1105 if (timeout < STA_TX_BUFFER_EXPIRE)
1106 timeout = STA_TX_BUFFER_EXPIRE;
1107 return time_after(jiffies, info->control.jiffies + timeout);
1111 static bool sta_info_cleanup_expire_buffered_ac(struct ieee80211_local *local,
1112 struct sta_info *sta, int ac)
1114 unsigned long flags;
1115 struct sk_buff *skb;
1118 * First check for frames that should expire on the filtered
1119 * queue. Frames here were rejected by the driver and are on
1120 * a separate queue to avoid reordering with normal PS-buffered
1121 * frames. They also aren't accounted for right now in the
1122 * total_ps_buffered counter.
1125 spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
1126 skb = skb_peek(&sta->tx_filtered[ac]);
1127 if (sta_info_buffer_expired(sta, skb))
1128 skb = __skb_dequeue(&sta->tx_filtered[ac]);
1131 spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
1134 * Frames are queued in order, so if this one
1135 * hasn't expired yet we can stop testing. If
1136 * we actually reached the end of the queue we
1137 * also need to stop, of course.
1141 ieee80211_free_txskb(&local->hw, skb);
1145 * Now also check the normal PS-buffered queue, this will
1146 * only find something if the filtered queue was emptied
1147 * since the filtered frames are all before the normal PS
1151 spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
1152 skb = skb_peek(&sta->ps_tx_buf[ac]);
1153 if (sta_info_buffer_expired(sta, skb))
1154 skb = __skb_dequeue(&sta->ps_tx_buf[ac]);
1157 spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
1160 * frames are queued in order, so if this one
1161 * hasn't expired yet (or we reached the end of
1162 * the queue) we can stop testing
1167 local->total_ps_buffered--;
1168 ps_dbg(sta->sdata, "Buffered frame expired (STA %pM)\n",
1170 ieee80211_free_txskb(&local->hw, skb);
1174 * Finally, recalculate the TIM bit for this station -- it might
1175 * now be clear because the station was too slow to retrieve its
1178 sta_info_recalc_tim(sta);
1181 * Return whether there are any frames still buffered, this is
1182 * used to check whether the cleanup timer still needs to run,
1183 * if there are no frames we don't need to rearm the timer.
1185 return !(skb_queue_empty(&sta->ps_tx_buf[ac]) &&
1186 skb_queue_empty(&sta->tx_filtered[ac]));
1189 static bool sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
1190 struct sta_info *sta)
1192 bool have_buffered = false;
1195 /* This is only necessary for stations on BSS/MBSS interfaces */
1196 if (!sta->sdata->bss &&
1197 !ieee80211_vif_is_mesh(&sta->sdata->vif))
1200 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
1202 sta_info_cleanup_expire_buffered_ac(local, sta, ac);
1204 return have_buffered;
1207 static int __must_check __sta_info_destroy_part1(struct sta_info *sta)
1209 struct ieee80211_local *local;
1210 struct ieee80211_sub_if_data *sdata;
1221 lockdep_assert_held(&local->sta_mtx);
1224 * Before removing the station from the driver and
1225 * rate control, it might still start new aggregation
1226 * sessions -- block that to make sure the tear-down
1227 * will be sufficient.
1229 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
1230 ieee80211_sta_tear_down_BA_sessions(sta, AGG_STOP_DESTROY_STA);
1233 * Before removing the station from the driver there might be pending
1234 * rx frames on RSS queues sent prior to the disassociation - wait for
1235 * all such frames to be processed.
1237 drv_sync_rx_queues(local, sta);
1239 for (i = 0; i < ARRAY_SIZE(sta->link); i++) {
1240 struct link_sta_info *link_sta;
1242 if (!(sta->sta.valid_links & BIT(i)))
1245 link_sta = rcu_dereference_protected(sta->link[i],
1246 lockdep_is_held(&local->sta_mtx));
1248 link_sta_info_hash_del(local, link_sta);
1251 ret = sta_info_hash_del(local, sta);
1256 * for TDLS peers, make sure to return to the base channel before
1259 if (test_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL)) {
1260 drv_tdls_cancel_channel_switch(local, sdata, &sta->sta);
1261 clear_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL);
1264 list_del_rcu(&sta->list);
1265 sta->removed = true;
1267 drv_sta_pre_rcu_remove(local, sta->sdata, sta);
1269 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1270 rcu_access_pointer(sdata->u.vlan.sta) == sta)
1271 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
1276 static void __sta_info_destroy_part2(struct sta_info *sta)
1278 struct ieee80211_local *local = sta->local;
1279 struct ieee80211_sub_if_data *sdata = sta->sdata;
1280 struct station_info *sinfo;
1284 * NOTE: This assumes at least synchronize_net() was done
1285 * after _part1 and before _part2!
1289 lockdep_assert_held(&local->sta_mtx);
1291 if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
1292 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1296 /* now keys can no longer be reached */
1297 ieee80211_free_sta_keys(local, sta);
1299 /* disable TIM bit - last chance to tell driver */
1300 __sta_info_recalc_tim(sta, true);
1305 local->sta_generation++;
1307 while (sta->sta_state > IEEE80211_STA_NONE) {
1308 ret = sta_info_move_state(sta, sta->sta_state - 1);
1315 if (sta->uploaded) {
1316 ret = drv_sta_state(local, sdata, sta, IEEE80211_STA_NONE,
1317 IEEE80211_STA_NOTEXIST);
1318 WARN_ON_ONCE(ret != 0);
1321 sta_dbg(sdata, "Removed STA %pM\n", sta->sta.addr);
1323 sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL);
1325 sta_set_sinfo(sta, sinfo, true);
1326 cfg80211_del_sta_sinfo(sdata->dev, sta->sta.addr, sinfo, GFP_KERNEL);
1329 ieee80211_sta_debugfs_remove(sta);
1331 ieee80211_destroy_frag_cache(&sta->frags);
1333 cleanup_single_sta(sta);
1336 int __must_check __sta_info_destroy(struct sta_info *sta)
1338 int err = __sta_info_destroy_part1(sta);
1345 __sta_info_destroy_part2(sta);
1350 int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata, const u8 *addr)
1352 struct sta_info *sta;
1355 mutex_lock(&sdata->local->sta_mtx);
1356 sta = sta_info_get(sdata, addr);
1357 ret = __sta_info_destroy(sta);
1358 mutex_unlock(&sdata->local->sta_mtx);
1363 int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata,
1366 struct sta_info *sta;
1369 mutex_lock(&sdata->local->sta_mtx);
1370 sta = sta_info_get_bss(sdata, addr);
1371 ret = __sta_info_destroy(sta);
1372 mutex_unlock(&sdata->local->sta_mtx);
1377 static void sta_info_cleanup(struct timer_list *t)
1379 struct ieee80211_local *local = from_timer(local, t, sta_cleanup);
1380 struct sta_info *sta;
1381 bool timer_needed = false;
1384 list_for_each_entry_rcu(sta, &local->sta_list, list)
1385 if (sta_info_cleanup_expire_buffered(local, sta))
1386 timer_needed = true;
1389 if (local->quiescing)
1395 mod_timer(&local->sta_cleanup,
1396 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL));
1399 int sta_info_init(struct ieee80211_local *local)
1403 err = rhltable_init(&local->sta_hash, &sta_rht_params);
1407 err = rhltable_init(&local->link_sta_hash, &link_sta_rht_params);
1409 rhltable_destroy(&local->sta_hash);
1413 spin_lock_init(&local->tim_lock);
1414 mutex_init(&local->sta_mtx);
1415 INIT_LIST_HEAD(&local->sta_list);
1417 timer_setup(&local->sta_cleanup, sta_info_cleanup, 0);
1421 void sta_info_stop(struct ieee80211_local *local)
1423 del_timer_sync(&local->sta_cleanup);
1424 rhltable_destroy(&local->sta_hash);
1425 rhltable_destroy(&local->link_sta_hash);
1429 int __sta_info_flush(struct ieee80211_sub_if_data *sdata, bool vlans)
1431 struct ieee80211_local *local = sdata->local;
1432 struct sta_info *sta, *tmp;
1433 LIST_HEAD(free_list);
1438 WARN_ON(vlans && sdata->vif.type != NL80211_IFTYPE_AP);
1439 WARN_ON(vlans && !sdata->bss);
1441 mutex_lock(&local->sta_mtx);
1442 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
1443 if (sdata == sta->sdata ||
1444 (vlans && sdata->bss == sta->sdata->bss)) {
1445 if (!WARN_ON(__sta_info_destroy_part1(sta)))
1446 list_add(&sta->free_list, &free_list);
1451 if (!list_empty(&free_list)) {
1453 list_for_each_entry_safe(sta, tmp, &free_list, free_list)
1454 __sta_info_destroy_part2(sta);
1456 mutex_unlock(&local->sta_mtx);
1461 void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
1462 unsigned long exp_time)
1464 struct ieee80211_local *local = sdata->local;
1465 struct sta_info *sta, *tmp;
1467 mutex_lock(&local->sta_mtx);
1469 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
1470 unsigned long last_active = ieee80211_sta_last_active(sta);
1472 if (sdata != sta->sdata)
1475 if (time_is_before_jiffies(last_active + exp_time)) {
1476 sta_dbg(sta->sdata, "expiring inactive STA %pM\n",
1479 if (ieee80211_vif_is_mesh(&sdata->vif) &&
1480 test_sta_flag(sta, WLAN_STA_PS_STA))
1481 atomic_dec(&sdata->u.mesh.ps.num_sta_ps);
1483 WARN_ON(__sta_info_destroy(sta));
1487 mutex_unlock(&local->sta_mtx);
1490 struct ieee80211_sta *ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw,
1492 const u8 *localaddr)
1494 struct ieee80211_local *local = hw_to_local(hw);
1495 struct rhlist_head *tmp;
1496 struct sta_info *sta;
1499 * Just return a random station if localaddr is NULL
1500 * ... first in list.
1502 for_each_sta_info(local, addr, sta, tmp) {
1504 !ether_addr_equal(sta->sdata->vif.addr, localaddr))
1513 EXPORT_SYMBOL_GPL(ieee80211_find_sta_by_ifaddr);
1515 struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_vif *vif,
1518 struct sta_info *sta;
1523 sta = sta_info_get_bss(vif_to_sdata(vif), addr);
1532 EXPORT_SYMBOL(ieee80211_find_sta);
1534 /* powersave support code */
1535 void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
1537 struct ieee80211_sub_if_data *sdata = sta->sdata;
1538 struct ieee80211_local *local = sdata->local;
1539 struct sk_buff_head pending;
1540 int filtered = 0, buffered = 0, ac, i;
1541 unsigned long flags;
1544 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1545 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
1548 if (sdata->vif.type == NL80211_IFTYPE_AP)
1549 ps = &sdata->bss->ps;
1550 else if (ieee80211_vif_is_mesh(&sdata->vif))
1551 ps = &sdata->u.mesh.ps;
1555 clear_sta_flag(sta, WLAN_STA_SP);
1557 BUILD_BUG_ON(BITS_TO_LONGS(IEEE80211_NUM_TIDS) > 1);
1558 sta->driver_buffered_tids = 0;
1559 sta->txq_buffered_tids = 0;
1561 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
1562 drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta);
1564 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
1565 if (!sta->sta.txq[i] || !txq_has_queue(sta->sta.txq[i]))
1568 schedule_and_wake_txq(local, to_txq_info(sta->sta.txq[i]));
1571 skb_queue_head_init(&pending);
1573 /* sync with ieee80211_tx_h_unicast_ps_buf */
1574 spin_lock(&sta->ps_lock);
1575 /* Send all buffered frames to the station */
1576 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1577 int count = skb_queue_len(&pending), tmp;
1579 spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
1580 skb_queue_splice_tail_init(&sta->tx_filtered[ac], &pending);
1581 spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
1582 tmp = skb_queue_len(&pending);
1583 filtered += tmp - count;
1586 spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
1587 skb_queue_splice_tail_init(&sta->ps_tx_buf[ac], &pending);
1588 spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
1589 tmp = skb_queue_len(&pending);
1590 buffered += tmp - count;
1593 ieee80211_add_pending_skbs(local, &pending);
1595 /* now we're no longer in the deliver code */
1596 clear_sta_flag(sta, WLAN_STA_PS_DELIVER);
1598 /* The station might have polled and then woken up before we responded,
1599 * so clear these flags now to avoid them sticking around.
1601 clear_sta_flag(sta, WLAN_STA_PSPOLL);
1602 clear_sta_flag(sta, WLAN_STA_UAPSD);
1603 spin_unlock(&sta->ps_lock);
1605 atomic_dec(&ps->num_sta_ps);
1607 local->total_ps_buffered -= buffered;
1609 sta_info_recalc_tim(sta);
1612 "STA %pM aid %d sending %d filtered/%d PS frames since STA woke up\n",
1613 sta->sta.addr, sta->sta.aid, filtered, buffered);
1615 ieee80211_check_fast_xmit(sta);
1618 static void ieee80211_send_null_response(struct sta_info *sta, int tid,
1619 enum ieee80211_frame_release_type reason,
1620 bool call_driver, bool more_data)
1622 struct ieee80211_sub_if_data *sdata = sta->sdata;
1623 struct ieee80211_local *local = sdata->local;
1624 struct ieee80211_qos_hdr *nullfunc;
1625 struct sk_buff *skb;
1626 int size = sizeof(*nullfunc);
1628 bool qos = sta->sta.wme;
1629 struct ieee80211_tx_info *info;
1630 struct ieee80211_chanctx_conf *chanctx_conf;
1633 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
1634 IEEE80211_STYPE_QOS_NULLFUNC |
1635 IEEE80211_FCTL_FROMDS);
1638 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
1639 IEEE80211_STYPE_NULLFUNC |
1640 IEEE80211_FCTL_FROMDS);
1643 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
1647 skb_reserve(skb, local->hw.extra_tx_headroom);
1649 nullfunc = skb_put(skb, size);
1650 nullfunc->frame_control = fc;
1651 nullfunc->duration_id = 0;
1652 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
1653 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1654 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
1655 nullfunc->seq_ctrl = 0;
1657 skb->priority = tid;
1658 skb_set_queue_mapping(skb, ieee802_1d_to_ac[tid]);
1660 nullfunc->qos_ctrl = cpu_to_le16(tid);
1662 if (reason == IEEE80211_FRAME_RELEASE_UAPSD) {
1663 nullfunc->qos_ctrl |=
1664 cpu_to_le16(IEEE80211_QOS_CTL_EOSP);
1666 nullfunc->frame_control |=
1667 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
1671 info = IEEE80211_SKB_CB(skb);
1674 * Tell TX path to send this frame even though the
1675 * STA may still remain is PS mode after this frame
1676 * exchange. Also set EOSP to indicate this packet
1677 * ends the poll/service period.
1679 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER |
1680 IEEE80211_TX_STATUS_EOSP |
1681 IEEE80211_TX_CTL_REQ_TX_STATUS;
1683 info->control.flags |= IEEE80211_TX_CTRL_PS_RESPONSE;
1686 drv_allow_buffered_frames(local, sta, BIT(tid), 1,
1689 skb->dev = sdata->dev;
1692 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
1693 if (WARN_ON(!chanctx_conf)) {
1699 info->band = chanctx_conf->def.chan->band;
1700 ieee80211_xmit(sdata, sta, skb);
1704 static int find_highest_prio_tid(unsigned long tids)
1706 /* lower 3 TIDs aren't ordered perfectly */
1708 return fls(tids) - 1;
1709 /* TID 0 is BE just like TID 3 */
1712 return fls(tids) - 1;
1715 /* Indicates if the MORE_DATA bit should be set in the last
1716 * frame obtained by ieee80211_sta_ps_get_frames.
1717 * Note that driver_release_tids is relevant only if
1718 * reason = IEEE80211_FRAME_RELEASE_PSPOLL
1721 ieee80211_sta_ps_more_data(struct sta_info *sta, u8 ignored_acs,
1722 enum ieee80211_frame_release_type reason,
1723 unsigned long driver_release_tids)
1727 /* If the driver has data on more than one TID then
1728 * certainly there's more data if we release just a
1729 * single frame now (from a single TID). This will
1730 * only happen for PS-Poll.
1732 if (reason == IEEE80211_FRAME_RELEASE_PSPOLL &&
1733 hweight16(driver_release_tids) > 1)
1736 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1737 if (ignored_acs & ieee80211_ac_to_qos_mask[ac])
1740 if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
1741 !skb_queue_empty(&sta->ps_tx_buf[ac]))
1749 ieee80211_sta_ps_get_frames(struct sta_info *sta, int n_frames, u8 ignored_acs,
1750 enum ieee80211_frame_release_type reason,
1751 struct sk_buff_head *frames,
1752 unsigned long *driver_release_tids)
1754 struct ieee80211_sub_if_data *sdata = sta->sdata;
1755 struct ieee80211_local *local = sdata->local;
1758 /* Get response frame(s) and more data bit for the last one. */
1759 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1762 if (ignored_acs & ieee80211_ac_to_qos_mask[ac])
1765 tids = ieee80211_tids_for_ac(ac);
1767 /* if we already have frames from software, then we can't also
1768 * release from hardware queues
1770 if (skb_queue_empty(frames)) {
1771 *driver_release_tids |=
1772 sta->driver_buffered_tids & tids;
1773 *driver_release_tids |= sta->txq_buffered_tids & tids;
1776 if (!*driver_release_tids) {
1777 struct sk_buff *skb;
1779 while (n_frames > 0) {
1780 skb = skb_dequeue(&sta->tx_filtered[ac]);
1783 &sta->ps_tx_buf[ac]);
1785 local->total_ps_buffered--;
1790 __skb_queue_tail(frames, skb);
1794 /* If we have more frames buffered on this AC, then abort the
1795 * loop since we can't send more data from other ACs before
1796 * the buffered frames from this.
1798 if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
1799 !skb_queue_empty(&sta->ps_tx_buf[ac]))
1805 ieee80211_sta_ps_deliver_response(struct sta_info *sta,
1806 int n_frames, u8 ignored_acs,
1807 enum ieee80211_frame_release_type reason)
1809 struct ieee80211_sub_if_data *sdata = sta->sdata;
1810 struct ieee80211_local *local = sdata->local;
1811 unsigned long driver_release_tids = 0;
1812 struct sk_buff_head frames;
1815 /* Service or PS-Poll period starts */
1816 set_sta_flag(sta, WLAN_STA_SP);
1818 __skb_queue_head_init(&frames);
1820 ieee80211_sta_ps_get_frames(sta, n_frames, ignored_acs, reason,
1821 &frames, &driver_release_tids);
1823 more_data = ieee80211_sta_ps_more_data(sta, ignored_acs, reason, driver_release_tids);
1825 if (driver_release_tids && reason == IEEE80211_FRAME_RELEASE_PSPOLL)
1826 driver_release_tids =
1827 BIT(find_highest_prio_tid(driver_release_tids));
1829 if (skb_queue_empty(&frames) && !driver_release_tids) {
1833 * For PS-Poll, this can only happen due to a race condition
1834 * when we set the TIM bit and the station notices it, but
1835 * before it can poll for the frame we expire it.
1837 * For uAPSD, this is said in the standard (11.2.1.5 h):
1838 * At each unscheduled SP for a non-AP STA, the AP shall
1839 * attempt to transmit at least one MSDU or MMPDU, but no
1840 * more than the value specified in the Max SP Length field
1841 * in the QoS Capability element from delivery-enabled ACs,
1842 * that are destined for the non-AP STA.
1844 * Since we have no other MSDU/MMPDU, transmit a QoS null frame.
1847 /* This will evaluate to 1, 3, 5 or 7. */
1848 for (ac = IEEE80211_AC_VO; ac < IEEE80211_NUM_ACS; ac++)
1849 if (!(ignored_acs & ieee80211_ac_to_qos_mask[ac]))
1853 ieee80211_send_null_response(sta, tid, reason, true, false);
1854 } else if (!driver_release_tids) {
1855 struct sk_buff_head pending;
1856 struct sk_buff *skb;
1859 bool need_null = false;
1861 skb_queue_head_init(&pending);
1863 while ((skb = __skb_dequeue(&frames))) {
1864 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1865 struct ieee80211_hdr *hdr = (void *) skb->data;
1871 * Tell TX path to send this frame even though the
1872 * STA may still remain is PS mode after this frame
1875 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER;
1876 info->control.flags |= IEEE80211_TX_CTRL_PS_RESPONSE;
1879 * Use MoreData flag to indicate whether there are
1880 * more buffered frames for this STA
1882 if (more_data || !skb_queue_empty(&frames))
1883 hdr->frame_control |=
1884 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
1886 hdr->frame_control &=
1887 cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
1889 if (ieee80211_is_data_qos(hdr->frame_control) ||
1890 ieee80211_is_qos_nullfunc(hdr->frame_control))
1891 qoshdr = ieee80211_get_qos_ctl(hdr);
1893 tids |= BIT(skb->priority);
1895 __skb_queue_tail(&pending, skb);
1897 /* end service period after last frame or add one */
1898 if (!skb_queue_empty(&frames))
1901 if (reason != IEEE80211_FRAME_RELEASE_UAPSD) {
1902 /* for PS-Poll, there's only one frame */
1903 info->flags |= IEEE80211_TX_STATUS_EOSP |
1904 IEEE80211_TX_CTL_REQ_TX_STATUS;
1908 /* For uAPSD, things are a bit more complicated. If the
1909 * last frame has a QoS header (i.e. is a QoS-data or
1910 * QoS-nulldata frame) then just set the EOSP bit there
1912 * If the frame doesn't have a QoS header (which means
1913 * it should be a bufferable MMPDU) then we can't set
1914 * the EOSP bit in the QoS header; add a QoS-nulldata
1915 * frame to the list to send it after the MMPDU.
1917 * Note that this code is only in the mac80211-release
1918 * code path, we assume that the driver will not buffer
1919 * anything but QoS-data frames, or if it does, will
1920 * create the QoS-nulldata frame by itself if needed.
1922 * Cf. 802.11-2012 10.2.1.10 (c).
1925 *qoshdr |= IEEE80211_QOS_CTL_EOSP;
1927 info->flags |= IEEE80211_TX_STATUS_EOSP |
1928 IEEE80211_TX_CTL_REQ_TX_STATUS;
1930 /* The standard isn't completely clear on this
1931 * as it says the more-data bit should be set
1932 * if there are more BUs. The QoS-Null frame
1933 * we're about to send isn't buffered yet, we
1934 * only create it below, but let's pretend it
1935 * was buffered just in case some clients only
1936 * expect more-data=0 when eosp=1.
1938 hdr->frame_control |=
1939 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
1946 drv_allow_buffered_frames(local, sta, tids, num,
1949 ieee80211_add_pending_skbs(local, &pending);
1952 ieee80211_send_null_response(
1953 sta, find_highest_prio_tid(tids),
1954 reason, false, false);
1956 sta_info_recalc_tim(sta);
1961 * We need to release a frame that is buffered somewhere in the
1962 * driver ... it'll have to handle that.
1963 * Note that the driver also has to check the number of frames
1964 * on the TIDs we're releasing from - if there are more than
1965 * n_frames it has to set the more-data bit (if we didn't ask
1966 * it to set it anyway due to other buffered frames); if there
1967 * are fewer than n_frames it has to make sure to adjust that
1968 * to allow the service period to end properly.
1970 drv_release_buffered_frames(local, sta, driver_release_tids,
1971 n_frames, reason, more_data);
1974 * Note that we don't recalculate the TIM bit here as it would
1975 * most likely have no effect at all unless the driver told us
1976 * that the TID(s) became empty before returning here from the
1978 * Either way, however, when the driver tells us that the TID(s)
1979 * became empty or we find that a txq became empty, we'll do the
1980 * TIM recalculation.
1983 for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
1984 if (!sta->sta.txq[tid] ||
1985 !(driver_release_tids & BIT(tid)) ||
1986 txq_has_queue(sta->sta.txq[tid]))
1989 sta_info_recalc_tim(sta);
1995 void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta)
1997 u8 ignore_for_response = sta->sta.uapsd_queues;
2000 * If all ACs are delivery-enabled then we should reply
2001 * from any of them, if only some are enabled we reply
2002 * only from the non-enabled ones.
2004 if (ignore_for_response == BIT(IEEE80211_NUM_ACS) - 1)
2005 ignore_for_response = 0;
2007 ieee80211_sta_ps_deliver_response(sta, 1, ignore_for_response,
2008 IEEE80211_FRAME_RELEASE_PSPOLL);
2011 void ieee80211_sta_ps_deliver_uapsd(struct sta_info *sta)
2013 int n_frames = sta->sta.max_sp;
2014 u8 delivery_enabled = sta->sta.uapsd_queues;
2017 * If we ever grow support for TSPEC this might happen if
2018 * the TSPEC update from hostapd comes in between a trigger
2019 * frame setting WLAN_STA_UAPSD in the RX path and this
2020 * actually getting called.
2022 if (!delivery_enabled)
2025 switch (sta->sta.max_sp) {
2036 /* XXX: what is a good value? */
2041 ieee80211_sta_ps_deliver_response(sta, n_frames, ~delivery_enabled,
2042 IEEE80211_FRAME_RELEASE_UAPSD);
2045 void ieee80211_sta_block_awake(struct ieee80211_hw *hw,
2046 struct ieee80211_sta *pubsta, bool block)
2048 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2050 trace_api_sta_block_awake(sta->local, pubsta, block);
2053 set_sta_flag(sta, WLAN_STA_PS_DRIVER);
2054 ieee80211_clear_fast_xmit(sta);
2058 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
2061 if (!test_sta_flag(sta, WLAN_STA_PS_STA)) {
2062 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
2063 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
2064 ieee80211_queue_work(hw, &sta->drv_deliver_wk);
2065 } else if (test_sta_flag(sta, WLAN_STA_PSPOLL) ||
2066 test_sta_flag(sta, WLAN_STA_UAPSD)) {
2067 /* must be asleep in this case */
2068 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
2069 ieee80211_queue_work(hw, &sta->drv_deliver_wk);
2071 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
2072 ieee80211_check_fast_xmit(sta);
2075 EXPORT_SYMBOL(ieee80211_sta_block_awake);
2077 void ieee80211_sta_eosp(struct ieee80211_sta *pubsta)
2079 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2080 struct ieee80211_local *local = sta->local;
2082 trace_api_eosp(local, pubsta);
2084 clear_sta_flag(sta, WLAN_STA_SP);
2086 EXPORT_SYMBOL(ieee80211_sta_eosp);
2088 void ieee80211_send_eosp_nullfunc(struct ieee80211_sta *pubsta, int tid)
2090 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2091 enum ieee80211_frame_release_type reason;
2094 trace_api_send_eosp_nullfunc(sta->local, pubsta, tid);
2096 reason = IEEE80211_FRAME_RELEASE_UAPSD;
2097 more_data = ieee80211_sta_ps_more_data(sta, ~sta->sta.uapsd_queues,
2100 ieee80211_send_null_response(sta, tid, reason, false, more_data);
2102 EXPORT_SYMBOL(ieee80211_send_eosp_nullfunc);
2104 void ieee80211_sta_set_buffered(struct ieee80211_sta *pubsta,
2105 u8 tid, bool buffered)
2107 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2109 if (WARN_ON(tid >= IEEE80211_NUM_TIDS))
2112 trace_api_sta_set_buffered(sta->local, pubsta, tid, buffered);
2115 set_bit(tid, &sta->driver_buffered_tids);
2117 clear_bit(tid, &sta->driver_buffered_tids);
2119 sta_info_recalc_tim(sta);
2121 EXPORT_SYMBOL(ieee80211_sta_set_buffered);
2123 void ieee80211_sta_register_airtime(struct ieee80211_sta *pubsta, u8 tid,
2124 u32 tx_airtime, u32 rx_airtime)
2126 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2127 struct ieee80211_local *local = sta->sdata->local;
2128 u8 ac = ieee80211_ac_from_tid(tid);
2132 if (sta->local->airtime_flags & AIRTIME_USE_TX)
2133 airtime += tx_airtime;
2134 if (sta->local->airtime_flags & AIRTIME_USE_RX)
2135 airtime += rx_airtime;
2137 spin_lock_bh(&local->active_txq_lock[ac]);
2138 sta->airtime[ac].tx_airtime += tx_airtime;
2139 sta->airtime[ac].rx_airtime += rx_airtime;
2141 diff = (u32)jiffies - sta->airtime[ac].last_active;
2142 if (diff <= AIRTIME_ACTIVE_DURATION)
2143 sta->airtime[ac].deficit -= airtime;
2145 spin_unlock_bh(&local->active_txq_lock[ac]);
2147 EXPORT_SYMBOL(ieee80211_sta_register_airtime);
2149 void __ieee80211_sta_recalc_aggregates(struct sta_info *sta, u16 active_links)
2154 if (!sta->sta.valid_links || !sta->sta.mlo) {
2155 sta->sta.cur = &sta->sta.deflink.agg;
2160 for (link_id = 0; link_id < ARRAY_SIZE((sta)->link); link_id++) {
2161 struct ieee80211_link_sta *link_sta;
2164 if (!(active_links & BIT(link_id)))
2167 link_sta = rcu_dereference(sta->sta.link[link_id]);
2172 sta->cur = sta->sta.deflink.agg;
2177 sta->cur.max_amsdu_len =
2178 min(sta->cur.max_amsdu_len,
2179 link_sta->agg.max_amsdu_len);
2180 sta->cur.max_rc_amsdu_len =
2181 min(sta->cur.max_rc_amsdu_len,
2182 link_sta->agg.max_rc_amsdu_len);
2184 for (i = 0; i < ARRAY_SIZE(sta->cur.max_tid_amsdu_len); i++)
2185 sta->cur.max_tid_amsdu_len[i] =
2186 min(sta->cur.max_tid_amsdu_len[i],
2187 link_sta->agg.max_tid_amsdu_len[i]);
2191 sta->sta.cur = &sta->cur;
2194 void ieee80211_sta_recalc_aggregates(struct ieee80211_sta *pubsta)
2196 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2198 __ieee80211_sta_recalc_aggregates(sta, sta->sdata->vif.active_links);
2200 EXPORT_SYMBOL(ieee80211_sta_recalc_aggregates);
2202 void ieee80211_sta_update_pending_airtime(struct ieee80211_local *local,
2203 struct sta_info *sta, u8 ac,
2204 u16 tx_airtime, bool tx_completed)
2208 if (!wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL))
2211 if (!tx_completed) {
2213 atomic_add(tx_airtime,
2214 &sta->airtime[ac].aql_tx_pending);
2216 atomic_add(tx_airtime, &local->aql_total_pending_airtime);
2217 atomic_add(tx_airtime, &local->aql_ac_pending_airtime[ac]);
2222 tx_pending = atomic_sub_return(tx_airtime,
2223 &sta->airtime[ac].aql_tx_pending);
2225 atomic_cmpxchg(&sta->airtime[ac].aql_tx_pending,
2229 atomic_sub(tx_airtime, &local->aql_total_pending_airtime);
2230 tx_pending = atomic_sub_return(tx_airtime,
2231 &local->aql_ac_pending_airtime[ac]);
2232 if (WARN_ONCE(tx_pending < 0,
2233 "Device %s AC %d pending airtime underflow: %u, %u",
2234 wiphy_name(local->hw.wiphy), ac, tx_pending,
2236 atomic_cmpxchg(&local->aql_ac_pending_airtime[ac],
2238 atomic_sub(tx_pending, &local->aql_total_pending_airtime);
2242 int sta_info_move_state(struct sta_info *sta,
2243 enum ieee80211_sta_state new_state)
2247 if (sta->sta_state == new_state)
2250 /* check allowed transitions first */
2252 switch (new_state) {
2253 case IEEE80211_STA_NONE:
2254 if (sta->sta_state != IEEE80211_STA_AUTH)
2257 case IEEE80211_STA_AUTH:
2258 if (sta->sta_state != IEEE80211_STA_NONE &&
2259 sta->sta_state != IEEE80211_STA_ASSOC)
2262 case IEEE80211_STA_ASSOC:
2263 if (sta->sta_state != IEEE80211_STA_AUTH &&
2264 sta->sta_state != IEEE80211_STA_AUTHORIZED)
2267 case IEEE80211_STA_AUTHORIZED:
2268 if (sta->sta_state != IEEE80211_STA_ASSOC)
2272 WARN(1, "invalid state %d", new_state);
2276 sta_dbg(sta->sdata, "moving STA %pM to state %d\n",
2277 sta->sta.addr, new_state);
2280 * notify the driver before the actual changes so it can
2281 * fail the transition
2283 if (test_sta_flag(sta, WLAN_STA_INSERTED)) {
2284 int err = drv_sta_state(sta->local, sta->sdata, sta,
2285 sta->sta_state, new_state);
2290 /* reflect the change in all state variables */
2292 switch (new_state) {
2293 case IEEE80211_STA_NONE:
2294 if (sta->sta_state == IEEE80211_STA_AUTH)
2295 clear_bit(WLAN_STA_AUTH, &sta->_flags);
2297 case IEEE80211_STA_AUTH:
2298 if (sta->sta_state == IEEE80211_STA_NONE) {
2299 set_bit(WLAN_STA_AUTH, &sta->_flags);
2300 } else if (sta->sta_state == IEEE80211_STA_ASSOC) {
2301 clear_bit(WLAN_STA_ASSOC, &sta->_flags);
2302 ieee80211_recalc_min_chandef(sta->sdata, -1);
2303 if (!sta->sta.support_p2p_ps)
2304 ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
2307 case IEEE80211_STA_ASSOC:
2308 if (sta->sta_state == IEEE80211_STA_AUTH) {
2309 set_bit(WLAN_STA_ASSOC, &sta->_flags);
2310 sta->assoc_at = ktime_get_boottime_ns();
2311 ieee80211_recalc_min_chandef(sta->sdata, -1);
2312 if (!sta->sta.support_p2p_ps)
2313 ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
2314 } else if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
2315 ieee80211_vif_dec_num_mcast(sta->sdata);
2316 clear_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
2317 ieee80211_clear_fast_xmit(sta);
2318 ieee80211_clear_fast_rx(sta);
2321 case IEEE80211_STA_AUTHORIZED:
2322 if (sta->sta_state == IEEE80211_STA_ASSOC) {
2323 ieee80211_vif_inc_num_mcast(sta->sdata);
2324 set_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
2325 ieee80211_check_fast_xmit(sta);
2326 ieee80211_check_fast_rx(sta);
2328 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
2329 sta->sdata->vif.type == NL80211_IFTYPE_AP)
2330 cfg80211_send_layer2_update(sta->sdata->dev,
2337 sta->sta_state = new_state;
2342 static struct ieee80211_sta_rx_stats *
2343 sta_get_last_rx_stats(struct sta_info *sta)
2345 struct ieee80211_sta_rx_stats *stats = &sta->deflink.rx_stats;
2348 if (!sta->deflink.pcpu_rx_stats)
2351 for_each_possible_cpu(cpu) {
2352 struct ieee80211_sta_rx_stats *cpustats;
2354 cpustats = per_cpu_ptr(sta->deflink.pcpu_rx_stats, cpu);
2356 if (time_after(cpustats->last_rx, stats->last_rx))
2363 static void sta_stats_decode_rate(struct ieee80211_local *local, u32 rate,
2364 struct rate_info *rinfo)
2366 rinfo->bw = STA_STATS_GET(BW, rate);
2368 switch (STA_STATS_GET(TYPE, rate)) {
2369 case STA_STATS_RATE_TYPE_VHT:
2370 rinfo->flags = RATE_INFO_FLAGS_VHT_MCS;
2371 rinfo->mcs = STA_STATS_GET(VHT_MCS, rate);
2372 rinfo->nss = STA_STATS_GET(VHT_NSS, rate);
2373 if (STA_STATS_GET(SGI, rate))
2374 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
2376 case STA_STATS_RATE_TYPE_HT:
2377 rinfo->flags = RATE_INFO_FLAGS_MCS;
2378 rinfo->mcs = STA_STATS_GET(HT_MCS, rate);
2379 if (STA_STATS_GET(SGI, rate))
2380 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
2382 case STA_STATS_RATE_TYPE_LEGACY: {
2383 struct ieee80211_supported_band *sband;
2386 int band = STA_STATS_GET(LEGACY_BAND, rate);
2387 int rate_idx = STA_STATS_GET(LEGACY_IDX, rate);
2389 sband = local->hw.wiphy->bands[band];
2391 if (WARN_ON_ONCE(!sband->bitrates))
2394 brate = sband->bitrates[rate_idx].bitrate;
2395 if (rinfo->bw == RATE_INFO_BW_5)
2397 else if (rinfo->bw == RATE_INFO_BW_10)
2401 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
2404 case STA_STATS_RATE_TYPE_HE:
2405 rinfo->flags = RATE_INFO_FLAGS_HE_MCS;
2406 rinfo->mcs = STA_STATS_GET(HE_MCS, rate);
2407 rinfo->nss = STA_STATS_GET(HE_NSS, rate);
2408 rinfo->he_gi = STA_STATS_GET(HE_GI, rate);
2409 rinfo->he_ru_alloc = STA_STATS_GET(HE_RU, rate);
2410 rinfo->he_dcm = STA_STATS_GET(HE_DCM, rate);
2412 case STA_STATS_RATE_TYPE_EHT:
2413 rinfo->flags = RATE_INFO_FLAGS_EHT_MCS;
2414 rinfo->mcs = STA_STATS_GET(EHT_MCS, rate);
2415 rinfo->nss = STA_STATS_GET(EHT_NSS, rate);
2416 rinfo->eht_gi = STA_STATS_GET(EHT_GI, rate);
2417 rinfo->eht_ru_alloc = STA_STATS_GET(EHT_RU, rate);
2422 static int sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
2424 u32 rate = READ_ONCE(sta_get_last_rx_stats(sta)->last_rate);
2426 if (rate == STA_STATS_RATE_INVALID)
2429 sta_stats_decode_rate(sta->local, rate, rinfo);
2433 static inline u64 sta_get_tidstats_msdu(struct ieee80211_sta_rx_stats *rxstats,
2440 start = u64_stats_fetch_begin(&rxstats->syncp);
2441 value = rxstats->msdu[tid];
2442 } while (u64_stats_fetch_retry(&rxstats->syncp, start));
2447 static void sta_set_tidstats(struct sta_info *sta,
2448 struct cfg80211_tid_stats *tidstats,
2451 struct ieee80211_local *local = sta->local;
2454 if (!(tidstats->filled & BIT(NL80211_TID_STATS_RX_MSDU))) {
2455 tidstats->rx_msdu += sta_get_tidstats_msdu(&sta->deflink.rx_stats,
2458 if (sta->deflink.pcpu_rx_stats) {
2459 for_each_possible_cpu(cpu) {
2460 struct ieee80211_sta_rx_stats *cpurxs;
2462 cpurxs = per_cpu_ptr(sta->deflink.pcpu_rx_stats,
2464 tidstats->rx_msdu +=
2465 sta_get_tidstats_msdu(cpurxs, tid);
2469 tidstats->filled |= BIT(NL80211_TID_STATS_RX_MSDU);
2472 if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU))) {
2473 tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU);
2474 tidstats->tx_msdu = sta->deflink.tx_stats.msdu[tid];
2477 if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU_RETRIES)) &&
2478 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
2479 tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU_RETRIES);
2480 tidstats->tx_msdu_retries = sta->deflink.status_stats.msdu_retries[tid];
2483 if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU_FAILED)) &&
2484 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
2485 tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU_FAILED);
2486 tidstats->tx_msdu_failed = sta->deflink.status_stats.msdu_failed[tid];
2489 if (tid < IEEE80211_NUM_TIDS) {
2490 spin_lock_bh(&local->fq.lock);
2493 tidstats->filled |= BIT(NL80211_TID_STATS_TXQ_STATS);
2494 ieee80211_fill_txq_stats(&tidstats->txq_stats,
2495 to_txq_info(sta->sta.txq[tid]));
2498 spin_unlock_bh(&local->fq.lock);
2502 static inline u64 sta_get_stats_bytes(struct ieee80211_sta_rx_stats *rxstats)
2508 start = u64_stats_fetch_begin(&rxstats->syncp);
2509 value = rxstats->bytes;
2510 } while (u64_stats_fetch_retry(&rxstats->syncp, start));
2515 void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo,
2518 struct ieee80211_sub_if_data *sdata = sta->sdata;
2519 struct ieee80211_local *local = sdata->local;
2522 struct ieee80211_sta_rx_stats *last_rxstats;
2524 last_rxstats = sta_get_last_rx_stats(sta);
2526 sinfo->generation = sdata->local->sta_generation;
2528 /* do before driver, so beacon filtering drivers have a
2529 * chance to e.g. just add the number of filtered beacons
2530 * (or just modify the value entirely, of course)
2532 if (sdata->vif.type == NL80211_IFTYPE_STATION)
2533 sinfo->rx_beacon = sdata->deflink.u.mgd.count_beacon_signal;
2535 drv_sta_statistics(local, sdata, &sta->sta, sinfo);
2536 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME) |
2537 BIT_ULL(NL80211_STA_INFO_STA_FLAGS) |
2538 BIT_ULL(NL80211_STA_INFO_BSS_PARAM) |
2539 BIT_ULL(NL80211_STA_INFO_CONNECTED_TIME) |
2540 BIT_ULL(NL80211_STA_INFO_ASSOC_AT_BOOTTIME) |
2541 BIT_ULL(NL80211_STA_INFO_RX_DROP_MISC);
2543 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
2544 sinfo->beacon_loss_count =
2545 sdata->deflink.u.mgd.beacon_loss_count;
2546 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_LOSS);
2549 sinfo->connected_time = ktime_get_seconds() - sta->last_connected;
2550 sinfo->assoc_at = sta->assoc_at;
2551 sinfo->inactive_time =
2552 jiffies_to_msecs(jiffies - ieee80211_sta_last_active(sta));
2554 if (!(sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES64) |
2555 BIT_ULL(NL80211_STA_INFO_TX_BYTES)))) {
2556 sinfo->tx_bytes = 0;
2557 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
2558 sinfo->tx_bytes += sta->deflink.tx_stats.bytes[ac];
2559 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES64);
2562 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_PACKETS))) {
2563 sinfo->tx_packets = 0;
2564 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
2565 sinfo->tx_packets += sta->deflink.tx_stats.packets[ac];
2566 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS);
2569 if (!(sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES64) |
2570 BIT_ULL(NL80211_STA_INFO_RX_BYTES)))) {
2571 sinfo->rx_bytes += sta_get_stats_bytes(&sta->deflink.rx_stats);
2573 if (sta->deflink.pcpu_rx_stats) {
2574 for_each_possible_cpu(cpu) {
2575 struct ieee80211_sta_rx_stats *cpurxs;
2577 cpurxs = per_cpu_ptr(sta->deflink.pcpu_rx_stats,
2579 sinfo->rx_bytes += sta_get_stats_bytes(cpurxs);
2583 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BYTES64);
2586 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_PACKETS))) {
2587 sinfo->rx_packets = sta->deflink.rx_stats.packets;
2588 if (sta->deflink.pcpu_rx_stats) {
2589 for_each_possible_cpu(cpu) {
2590 struct ieee80211_sta_rx_stats *cpurxs;
2592 cpurxs = per_cpu_ptr(sta->deflink.pcpu_rx_stats,
2594 sinfo->rx_packets += cpurxs->packets;
2597 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_PACKETS);
2600 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_RETRIES))) {
2601 sinfo->tx_retries = sta->deflink.status_stats.retry_count;
2602 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_RETRIES);
2605 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_FAILED))) {
2606 sinfo->tx_failed = sta->deflink.status_stats.retry_failed;
2607 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED);
2610 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_DURATION))) {
2611 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
2612 sinfo->rx_duration += sta->airtime[ac].rx_airtime;
2613 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION);
2616 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_DURATION))) {
2617 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
2618 sinfo->tx_duration += sta->airtime[ac].tx_airtime;
2619 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_DURATION);
2622 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_AIRTIME_WEIGHT))) {
2623 sinfo->airtime_weight = sta->airtime_weight;
2624 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_AIRTIME_WEIGHT);
2627 sinfo->rx_dropped_misc = sta->deflink.rx_stats.dropped;
2628 if (sta->deflink.pcpu_rx_stats) {
2629 for_each_possible_cpu(cpu) {
2630 struct ieee80211_sta_rx_stats *cpurxs;
2632 cpurxs = per_cpu_ptr(sta->deflink.pcpu_rx_stats, cpu);
2633 sinfo->rx_dropped_misc += cpurxs->dropped;
2637 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2638 !(sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)) {
2639 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX) |
2640 BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
2641 sinfo->rx_beacon_signal_avg = ieee80211_ave_rssi(&sdata->vif);
2644 if (ieee80211_hw_check(&sta->local->hw, SIGNAL_DBM) ||
2645 ieee80211_hw_check(&sta->local->hw, SIGNAL_UNSPEC)) {
2646 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_SIGNAL))) {
2647 sinfo->signal = (s8)last_rxstats->last_signal;
2648 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
2651 if (!sta->deflink.pcpu_rx_stats &&
2652 !(sinfo->filled & BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG))) {
2654 -ewma_signal_read(&sta->deflink.rx_stats_avg.signal);
2655 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
2659 /* for the average - if pcpu_rx_stats isn't set - rxstats must point to
2660 * the sta->rx_stats struct, so the check here is fine with and without
2663 if (last_rxstats->chains &&
2664 !(sinfo->filled & (BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL) |
2665 BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)))) {
2666 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL);
2667 if (!sta->deflink.pcpu_rx_stats)
2668 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG);
2670 sinfo->chains = last_rxstats->chains;
2672 for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
2673 sinfo->chain_signal[i] =
2674 last_rxstats->chain_signal_last[i];
2675 sinfo->chain_signal_avg[i] =
2676 -ewma_signal_read(&sta->deflink.rx_stats_avg.chain_signal[i]);
2680 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) &&
2681 !sta->sta.valid_links) {
2682 sta_set_rate_info_tx(sta, &sta->deflink.tx_stats.last_rate,
2684 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
2687 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) &&
2688 !sta->sta.valid_links) {
2689 if (sta_set_rate_info_rx(sta, &sinfo->rxrate) == 0)
2690 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BITRATE);
2693 if (tidstats && !cfg80211_sinfo_alloc_tid_stats(sinfo, GFP_KERNEL)) {
2694 for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++)
2695 sta_set_tidstats(sta, &sinfo->pertid[i], i);
2698 if (ieee80211_vif_is_mesh(&sdata->vif)) {
2699 #ifdef CONFIG_MAC80211_MESH
2700 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_LLID) |
2701 BIT_ULL(NL80211_STA_INFO_PLID) |
2702 BIT_ULL(NL80211_STA_INFO_PLINK_STATE) |
2703 BIT_ULL(NL80211_STA_INFO_LOCAL_PM) |
2704 BIT_ULL(NL80211_STA_INFO_PEER_PM) |
2705 BIT_ULL(NL80211_STA_INFO_NONPEER_PM) |
2706 BIT_ULL(NL80211_STA_INFO_CONNECTED_TO_GATE) |
2707 BIT_ULL(NL80211_STA_INFO_CONNECTED_TO_AS);
2709 sinfo->llid = sta->mesh->llid;
2710 sinfo->plid = sta->mesh->plid;
2711 sinfo->plink_state = sta->mesh->plink_state;
2712 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
2713 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_T_OFFSET);
2714 sinfo->t_offset = sta->mesh->t_offset;
2716 sinfo->local_pm = sta->mesh->local_pm;
2717 sinfo->peer_pm = sta->mesh->peer_pm;
2718 sinfo->nonpeer_pm = sta->mesh->nonpeer_pm;
2719 sinfo->connected_to_gate = sta->mesh->connected_to_gate;
2720 sinfo->connected_to_as = sta->mesh->connected_to_as;
2724 sinfo->bss_param.flags = 0;
2725 if (sdata->vif.bss_conf.use_cts_prot)
2726 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
2727 if (sdata->vif.bss_conf.use_short_preamble)
2728 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
2729 if (sdata->vif.bss_conf.use_short_slot)
2730 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
2731 sinfo->bss_param.dtim_period = sdata->vif.bss_conf.dtim_period;
2732 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
2734 sinfo->sta_flags.set = 0;
2735 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2736 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2737 BIT(NL80211_STA_FLAG_WME) |
2738 BIT(NL80211_STA_FLAG_MFP) |
2739 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2740 BIT(NL80211_STA_FLAG_ASSOCIATED) |
2741 BIT(NL80211_STA_FLAG_TDLS_PEER);
2742 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2743 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
2744 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
2745 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
2747 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
2748 if (test_sta_flag(sta, WLAN_STA_MFP))
2749 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
2750 if (test_sta_flag(sta, WLAN_STA_AUTH))
2751 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
2752 if (test_sta_flag(sta, WLAN_STA_ASSOC))
2753 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
2754 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
2755 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
2757 thr = sta_get_expected_throughput(sta);
2760 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_EXPECTED_THROUGHPUT);
2761 sinfo->expected_throughput = thr;
2764 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL)) &&
2765 sta->deflink.status_stats.ack_signal_filled) {
2766 sinfo->ack_signal = sta->deflink.status_stats.last_ack_signal;
2767 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL);
2770 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL_AVG)) &&
2771 sta->deflink.status_stats.ack_signal_filled) {
2772 sinfo->avg_ack_signal =
2773 -(s8)ewma_avg_signal_read(
2774 &sta->deflink.status_stats.avg_ack_signal);
2776 BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL_AVG);
2779 if (ieee80211_vif_is_mesh(&sdata->vif)) {
2780 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_AIRTIME_LINK_METRIC);
2781 sinfo->airtime_link_metric =
2782 airtime_link_metric_get(local, sta);
2786 u32 sta_get_expected_throughput(struct sta_info *sta)
2788 struct ieee80211_sub_if_data *sdata = sta->sdata;
2789 struct ieee80211_local *local = sdata->local;
2790 struct rate_control_ref *ref = NULL;
2793 if (test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
2794 ref = local->rate_ctrl;
2796 /* check if the driver has a SW RC implementation */
2797 if (ref && ref->ops->get_expected_throughput)
2798 thr = ref->ops->get_expected_throughput(sta->rate_ctrl_priv);
2800 thr = drv_get_expected_throughput(local, sta);
2805 unsigned long ieee80211_sta_last_active(struct sta_info *sta)
2807 struct ieee80211_sta_rx_stats *stats = sta_get_last_rx_stats(sta);
2809 if (!sta->deflink.status_stats.last_ack ||
2810 time_after(stats->last_rx, sta->deflink.status_stats.last_ack))
2811 return stats->last_rx;
2812 return sta->deflink.status_stats.last_ack;
2815 static void sta_update_codel_params(struct sta_info *sta, u32 thr)
2817 if (thr && thr < STA_SLOW_THRESHOLD * sta->local->num_sta) {
2818 sta->cparams.target = MS2TIME(50);
2819 sta->cparams.interval = MS2TIME(300);
2820 sta->cparams.ecn = false;
2822 sta->cparams.target = MS2TIME(20);
2823 sta->cparams.interval = MS2TIME(100);
2824 sta->cparams.ecn = true;
2828 void ieee80211_sta_set_expected_throughput(struct ieee80211_sta *pubsta,
2831 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2833 sta_update_codel_params(sta, thr);
2836 int ieee80211_sta_allocate_link(struct sta_info *sta, unsigned int link_id)
2838 struct ieee80211_sub_if_data *sdata = sta->sdata;
2839 struct sta_link_alloc *alloc;
2842 lockdep_assert_held(&sdata->local->sta_mtx);
2844 /* must represent an MLD from the start */
2845 if (WARN_ON(!sta->sta.valid_links))
2848 if (WARN_ON(sta->sta.valid_links & BIT(link_id) ||
2849 sta->link[link_id]))
2852 alloc = kzalloc(sizeof(*alloc), GFP_KERNEL);
2856 ret = sta_info_alloc_link(sdata->local, &alloc->info, GFP_KERNEL);
2862 sta_info_add_link(sta, link_id, &alloc->info, &alloc->sta);
2864 ieee80211_link_sta_debugfs_add(&alloc->info);
2869 void ieee80211_sta_free_link(struct sta_info *sta, unsigned int link_id)
2871 lockdep_assert_held(&sta->sdata->local->sta_mtx);
2873 sta_remove_link(sta, link_id, false);
2876 int ieee80211_sta_activate_link(struct sta_info *sta, unsigned int link_id)
2878 struct ieee80211_sub_if_data *sdata = sta->sdata;
2879 struct link_sta_info *link_sta;
2880 u16 old_links = sta->sta.valid_links;
2881 u16 new_links = old_links | BIT(link_id);
2884 link_sta = rcu_dereference_protected(sta->link[link_id],
2885 lockdep_is_held(&sdata->local->sta_mtx));
2887 if (WARN_ON(old_links == new_links || !link_sta))
2891 if (link_sta_info_hash_lookup(sdata->local, link_sta->addr)) {
2895 /* we only modify under the mutex so this is fine */
2898 sta->sta.valid_links = new_links;
2900 if (!test_sta_flag(sta, WLAN_STA_INSERTED))
2903 /* Ensure the values are updated for the driver,
2904 * redone by sta_remove_link on failure.
2906 ieee80211_sta_recalc_aggregates(&sta->sta);
2908 ret = drv_change_sta_links(sdata->local, sdata, &sta->sta,
2909 old_links, new_links);
2911 sta->sta.valid_links = old_links;
2912 sta_remove_link(sta, link_id, false);
2917 ret = link_sta_info_hash_add(sdata->local, link_sta);
2922 void ieee80211_sta_remove_link(struct sta_info *sta, unsigned int link_id)
2924 struct ieee80211_sub_if_data *sdata = sta->sdata;
2925 u16 old_links = sta->sta.valid_links;
2927 lockdep_assert_held(&sdata->local->sta_mtx);
2929 sta->sta.valid_links &= ~BIT(link_id);
2931 if (test_sta_flag(sta, WLAN_STA_INSERTED))
2932 drv_change_sta_links(sdata->local, sdata, &sta->sta,
2933 old_links, sta->sta.valid_links);
2935 sta_remove_link(sta, link_id, true);
2938 void ieee80211_sta_set_max_amsdu_subframes(struct sta_info *sta,
2939 const u8 *ext_capab,
2940 unsigned int ext_capab_len)
2944 sta->sta.max_amsdu_subframes = 0;
2946 if (ext_capab_len < 8)
2949 /* The sender might not have sent the last bit, consider it to be 0 */
2950 val = u8_get_bits(ext_capab[7], WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB);
2952 /* we did get all the bits, take the MSB as well */
2953 if (ext_capab_len >= 9)
2954 val |= u8_get_bits(ext_capab[8],
2955 WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB) << 1;
2958 sta->sta.max_amsdu_subframes = 4 << val;
2961 #ifdef CONFIG_LOCKDEP
2962 bool lockdep_sta_mutex_held(struct ieee80211_sta *pubsta)
2964 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2966 return lockdep_is_held(&sta->local->sta_mtx);
2968 EXPORT_SYMBOL(lockdep_sta_mutex_held);