2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
4 * Copyright 2013-2014 Intel Mobile Communications GmbH
5 * Copyright (C) 2015 - 2016 Intel Deutschland GmbH
6 * Copyright (C) 2018-2020 Intel Corporation
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/etherdevice.h>
16 #include <linux/netdevice.h>
17 #include <linux/types.h>
18 #include <linux/slab.h>
19 #include <linux/skbuff.h>
20 #include <linux/if_arp.h>
21 #include <linux/timer.h>
22 #include <linux/rtnetlink.h>
24 #include <net/mac80211.h>
25 #include "ieee80211_i.h"
26 #include "driver-ops.h"
29 #include "debugfs_sta.h"
34 * DOC: STA information lifetime rules
36 * STA info structures (&struct sta_info) are managed in a hash table
37 * for faster lookup and a list for iteration. They are managed using
38 * RCU, i.e. access to the list and hash table is protected by RCU.
40 * Upon allocating a STA info structure with sta_info_alloc(), the caller
41 * owns that structure. It must then insert it into the hash table using
42 * either sta_info_insert() or sta_info_insert_rcu(); only in the latter
43 * case (which acquires an rcu read section but must not be called from
44 * within one) will the pointer still be valid after the call. Note that
45 * the caller may not do much with the STA info before inserting it, in
46 * particular, it may not start any mesh peer link management or add
49 * When the insertion fails (sta_info_insert()) returns non-zero), the
50 * structure will have been freed by sta_info_insert()!
52 * Station entries are added by mac80211 when you establish a link with a
53 * peer. This means different things for the different type of interfaces
54 * we support. For a regular station this mean we add the AP sta when we
55 * receive an association response from the AP. For IBSS this occurs when
56 * get to know about a peer on the same IBSS. For WDS we add the sta for
57 * the peer immediately upon device open. When using AP mode we add stations
58 * for each respective station upon request from userspace through nl80211.
60 * In order to remove a STA info structure, various sta_info_destroy_*()
61 * calls are available.
63 * There is no concept of ownership on a STA entry, each structure is
64 * owned by the global hash table/list until it is removed. All users of
65 * the structure need to be RCU protected so that the structure won't be
66 * freed before they are done using it.
69 static const struct rhashtable_params sta_rht_params = {
70 .nelem_hint = 3, /* start small */
71 .automatic_shrinking = true,
72 .head_offset = offsetof(struct sta_info, hash_node),
73 .key_offset = offsetof(struct sta_info, addr),
75 .max_size = CONFIG_MAC80211_STA_HASH_MAX_SIZE,
78 /* Caller must hold local->sta_mtx */
79 static int sta_info_hash_del(struct ieee80211_local *local,
82 return rhltable_remove(&local->sta_hash, &sta->hash_node,
86 static void __cleanup_single_sta(struct sta_info *sta)
89 struct tid_ampdu_tx *tid_tx;
90 struct ieee80211_sub_if_data *sdata = sta->sdata;
91 struct ieee80211_local *local = sdata->local;
92 struct fq *fq = &local->fq;
95 if (test_sta_flag(sta, WLAN_STA_PS_STA) ||
96 test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
97 test_sta_flag(sta, WLAN_STA_PS_DELIVER)) {
98 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
99 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
100 ps = &sdata->bss->ps;
101 else if (ieee80211_vif_is_mesh(&sdata->vif))
102 ps = &sdata->u.mesh.ps;
106 clear_sta_flag(sta, WLAN_STA_PS_STA);
107 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
108 clear_sta_flag(sta, WLAN_STA_PS_DELIVER);
110 atomic_dec(&ps->num_sta_ps);
113 if (sta->sta.txq[0]) {
114 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
115 struct txq_info *txqi = to_txq_info(sta->sta.txq[i]);
117 spin_lock_bh(&fq->lock);
118 ieee80211_txq_purge(local, txqi);
119 spin_unlock_bh(&fq->lock);
123 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
124 local->total_ps_buffered -= skb_queue_len(&sta->ps_tx_buf[ac]);
125 ieee80211_purge_tx_queue(&local->hw, &sta->ps_tx_buf[ac]);
126 ieee80211_purge_tx_queue(&local->hw, &sta->tx_filtered[ac]);
129 if (ieee80211_vif_is_mesh(&sdata->vif))
130 mesh_sta_cleanup(sta);
132 cancel_work_sync(&sta->drv_deliver_wk);
135 * Destroy aggregation state here. It would be nice to wait for the
136 * driver to finish aggregation stop and then clean up, but for now
137 * drivers have to handle aggregation stop being requested, followed
138 * directly by station destruction.
140 for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
141 kfree(sta->ampdu_mlme.tid_start_tx[i]);
142 tid_tx = rcu_dereference_raw(sta->ampdu_mlme.tid_tx[i]);
145 ieee80211_purge_tx_queue(&local->hw, &tid_tx->pending);
150 static void cleanup_single_sta(struct sta_info *sta)
152 struct ieee80211_sub_if_data *sdata = sta->sdata;
153 struct ieee80211_local *local = sdata->local;
155 __cleanup_single_sta(sta);
156 sta_info_free(local, sta);
159 struct rhlist_head *sta_info_hash_lookup(struct ieee80211_local *local,
162 return rhltable_lookup(&local->sta_hash, addr, sta_rht_params);
165 /* protected by RCU */
166 struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata,
169 struct ieee80211_local *local = sdata->local;
170 struct rhlist_head *tmp;
171 struct sta_info *sta;
174 for_each_sta_info(local, addr, sta, tmp) {
175 if (sta->sdata == sdata) {
177 /* this is safe as the caller must already hold
178 * another rcu read section or the mutex
188 * Get sta info either from the specified interface
189 * or from one of its vlans
191 struct sta_info *sta_info_get_bss(struct ieee80211_sub_if_data *sdata,
194 struct ieee80211_local *local = sdata->local;
195 struct rhlist_head *tmp;
196 struct sta_info *sta;
199 for_each_sta_info(local, addr, sta, tmp) {
200 if (sta->sdata == sdata ||
201 (sta->sdata->bss && sta->sdata->bss == sdata->bss)) {
203 /* this is safe as the caller must already hold
204 * another rcu read section or the mutex
213 struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata,
216 struct ieee80211_local *local = sdata->local;
217 struct sta_info *sta;
220 list_for_each_entry_rcu(sta, &local->sta_list, list) {
221 if (sdata != sta->sdata)
234 * sta_info_free - free STA
236 * @local: pointer to the global information
237 * @sta: STA info to free
239 * This function must undo everything done by sta_info_alloc()
240 * that may happen before sta_info_insert(). It may only be
241 * called when sta_info_insert() has not been attempted (and
242 * if that fails, the station is freed anyway.)
244 void sta_info_free(struct ieee80211_local *local, struct sta_info *sta)
247 * If we had used sta_info_pre_move_state() then we might not
248 * have gone through the state transitions down again, so do
249 * it here now (and warn if it's inserted).
251 * This will clear state such as fast TX/RX that may have been
252 * allocated during state transitions.
254 while (sta->sta_state > IEEE80211_STA_NONE) {
257 WARN_ON_ONCE(test_sta_flag(sta, WLAN_STA_INSERTED));
259 ret = sta_info_move_state(sta, sta->sta_state - 1);
260 if (WARN_ONCE(ret, "sta_info_move_state() returned %d\n", ret))
265 rate_control_free_sta(sta);
267 sta_dbg(sta->sdata, "Destroyed STA %pM\n", sta->sta.addr);
270 kfree(to_txq_info(sta->sta.txq[0]));
271 kfree(rcu_dereference_raw(sta->sta.rates));
272 #ifdef CONFIG_MAC80211_MESH
275 free_percpu(sta->pcpu_rx_stats);
279 /* Caller must hold local->sta_mtx */
280 static int sta_info_hash_add(struct ieee80211_local *local,
281 struct sta_info *sta)
283 return rhltable_insert(&local->sta_hash, &sta->hash_node,
287 static void sta_deliver_ps_frames(struct work_struct *wk)
289 struct sta_info *sta;
291 sta = container_of(wk, struct sta_info, drv_deliver_wk);
297 if (!test_sta_flag(sta, WLAN_STA_PS_STA))
298 ieee80211_sta_ps_deliver_wakeup(sta);
299 else if (test_and_clear_sta_flag(sta, WLAN_STA_PSPOLL))
300 ieee80211_sta_ps_deliver_poll_response(sta);
301 else if (test_and_clear_sta_flag(sta, WLAN_STA_UAPSD))
302 ieee80211_sta_ps_deliver_uapsd(sta);
306 static int sta_prepare_rate_control(struct ieee80211_local *local,
307 struct sta_info *sta, gfp_t gfp)
309 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL))
312 sta->rate_ctrl = local->rate_ctrl;
313 sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl,
315 if (!sta->rate_ctrl_priv)
321 struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
322 const u8 *addr, gfp_t gfp)
324 struct ieee80211_local *local = sdata->local;
325 struct ieee80211_hw *hw = &local->hw;
326 struct sta_info *sta;
329 sta = kzalloc(sizeof(*sta) + hw->sta_data_size, gfp);
333 if (ieee80211_hw_check(hw, USES_RSS)) {
335 alloc_percpu_gfp(struct ieee80211_sta_rx_stats, gfp);
336 if (!sta->pcpu_rx_stats)
340 spin_lock_init(&sta->lock);
341 spin_lock_init(&sta->ps_lock);
342 INIT_WORK(&sta->drv_deliver_wk, sta_deliver_ps_frames);
343 INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work);
344 mutex_init(&sta->ampdu_mlme.mtx);
345 #ifdef CONFIG_MAC80211_MESH
346 if (ieee80211_vif_is_mesh(&sdata->vif)) {
347 sta->mesh = kzalloc(sizeof(*sta->mesh), gfp);
350 spin_lock_init(&sta->mesh->plink_lock);
351 if (ieee80211_vif_is_mesh(&sdata->vif) &&
352 !sdata->u.mesh.user_mpm)
353 init_timer(&sta->mesh->plink_timer);
354 sta->mesh->nonpeer_pm = NL80211_MESH_POWER_ACTIVE;
358 memcpy(sta->addr, addr, ETH_ALEN);
359 memcpy(sta->sta.addr, addr, ETH_ALEN);
360 sta->sta.max_rx_aggregation_subframes =
361 local->hw.max_rx_aggregation_subframes;
365 sta->rx_stats.last_rx = jiffies;
367 u64_stats_init(&sta->rx_stats.syncp);
369 ieee80211_init_frag_cache(&sta->frags);
371 sta->sta_state = IEEE80211_STA_NONE;
373 /* Mark TID as unreserved */
374 sta->reserved_tid = IEEE80211_TID_UNRESERVED;
376 sta->last_connected = ktime_get_seconds();
377 ewma_signal_init(&sta->rx_stats_avg.signal);
378 for (i = 0; i < ARRAY_SIZE(sta->rx_stats_avg.chain_signal); i++)
379 ewma_signal_init(&sta->rx_stats_avg.chain_signal[i]);
381 if (local->ops->wake_tx_queue) {
383 int size = sizeof(struct txq_info) +
384 ALIGN(hw->txq_data_size, sizeof(void *));
386 txq_data = kcalloc(ARRAY_SIZE(sta->sta.txq), size, gfp);
390 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
391 struct txq_info *txq = txq_data + i * size;
393 ieee80211_txq_init(sdata, sta, txq, i);
397 if (sta_prepare_rate_control(local, sta, gfp))
400 for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
402 * timer_to_tid must be initialized with identity mapping
403 * to enable session_timer's data differentiation. See
404 * sta_rx_agg_session_timer_expired for usage.
406 sta->timer_to_tid[i] = i;
408 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
409 skb_queue_head_init(&sta->ps_tx_buf[i]);
410 skb_queue_head_init(&sta->tx_filtered[i]);
413 for (i = 0; i < IEEE80211_NUM_TIDS; i++)
414 sta->last_seq_ctrl[i] = cpu_to_le16(USHRT_MAX);
416 sta->sta.smps_mode = IEEE80211_SMPS_OFF;
417 if (sdata->vif.type == NL80211_IFTYPE_AP ||
418 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
419 struct ieee80211_supported_band *sband;
422 sband = ieee80211_get_sband(sdata);
426 smps = (sband->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >>
427 IEEE80211_HT_CAP_SM_PS_SHIFT;
429 * Assume that hostapd advertises our caps in the beacon and
430 * this is the known_smps_mode for a station that just assciated
433 case WLAN_HT_SMPS_CONTROL_DISABLED:
434 sta->known_smps_mode = IEEE80211_SMPS_OFF;
436 case WLAN_HT_SMPS_CONTROL_STATIC:
437 sta->known_smps_mode = IEEE80211_SMPS_STATIC;
439 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
440 sta->known_smps_mode = IEEE80211_SMPS_DYNAMIC;
447 sta->sta.max_rc_amsdu_len = IEEE80211_MAX_MPDU_LEN_HT_BA;
449 sta_dbg(sdata, "Allocated STA %pM\n", sta->sta.addr);
455 kfree(to_txq_info(sta->sta.txq[0]));
457 free_percpu(sta->pcpu_rx_stats);
458 #ifdef CONFIG_MAC80211_MESH
465 static int sta_info_insert_check(struct sta_info *sta)
467 struct ieee80211_sub_if_data *sdata = sta->sdata;
470 * Can't be a WARN_ON because it can be triggered through a race:
471 * something inserts a STA (on one CPU) without holding the RTNL
472 * and another CPU turns off the net device.
474 if (unlikely(!ieee80211_sdata_running(sdata)))
477 if (WARN_ON(ether_addr_equal(sta->sta.addr, sdata->vif.addr) ||
478 is_multicast_ether_addr(sta->sta.addr)))
481 /* The RCU read lock is required by rhashtable due to
482 * asynchronous resize/rehash. We also require the mutex
486 lockdep_assert_held(&sdata->local->sta_mtx);
487 if (ieee80211_hw_check(&sdata->local->hw, NEEDS_UNIQUE_STA_ADDR) &&
488 ieee80211_find_sta_by_ifaddr(&sdata->local->hw, sta->addr, NULL)) {
497 static int sta_info_insert_drv_state(struct ieee80211_local *local,
498 struct ieee80211_sub_if_data *sdata,
499 struct sta_info *sta)
501 enum ieee80211_sta_state state;
504 for (state = IEEE80211_STA_NOTEXIST; state < sta->sta_state; state++) {
505 err = drv_sta_state(local, sdata, sta, state, state + 1);
512 * Drivers using legacy sta_add/sta_remove callbacks only
513 * get uploaded set to true after sta_add is called.
515 if (!local->ops->sta_add)
516 sta->uploaded = true;
520 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
522 "failed to move IBSS STA %pM to state %d (%d) - keeping it anyway\n",
523 sta->sta.addr, state + 1, err);
527 /* unwind on error */
528 for (; state > IEEE80211_STA_NOTEXIST; state--)
529 WARN_ON(drv_sta_state(local, sdata, sta, state, state - 1));
535 * should be called with sta_mtx locked
536 * this function replaces the mutex lock
539 static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU)
541 struct ieee80211_local *local = sta->local;
542 struct ieee80211_sub_if_data *sdata = sta->sdata;
543 struct station_info *sinfo;
546 lockdep_assert_held(&local->sta_mtx);
548 sinfo = kzalloc(sizeof(struct station_info), GFP_KERNEL);
554 /* check if STA exists already */
555 if (sta_info_get_bss(sdata, sta->sta.addr)) {
561 local->sta_generation++;
564 /* simplify things and don't accept BA sessions yet */
565 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
567 /* make the station visible */
568 err = sta_info_hash_add(local, sta);
572 list_add_tail_rcu(&sta->list, &local->sta_list);
575 err = sta_info_insert_drv_state(local, sdata, sta);
579 set_sta_flag(sta, WLAN_STA_INSERTED);
580 /* accept BA sessions now */
581 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
583 ieee80211_sta_debugfs_add(sta);
584 rate_control_add_sta_debugfs(sta);
586 sinfo->generation = local->sta_generation;
587 cfg80211_new_sta(sdata->dev, sta->sta.addr, sinfo, GFP_KERNEL);
590 sta_dbg(sdata, "Inserted STA %pM\n", sta->sta.addr);
592 /* move reference to rcu-protected */
594 mutex_unlock(&local->sta_mtx);
596 if (ieee80211_vif_is_mesh(&sdata->vif))
597 mesh_accept_plinks_update(sdata);
601 sta_info_hash_del(local, sta);
602 list_del_rcu(&sta->list);
606 cleanup_single_sta(sta);
608 mutex_unlock(&local->sta_mtx);
614 int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU)
616 struct ieee80211_local *local = sta->local;
621 mutex_lock(&local->sta_mtx);
623 err = sta_info_insert_check(sta);
625 sta_info_free(local, sta);
626 mutex_unlock(&local->sta_mtx);
631 return sta_info_insert_finish(sta);
634 int sta_info_insert(struct sta_info *sta)
636 int err = sta_info_insert_rcu(sta);
643 static inline void __bss_tim_set(u8 *tim, u16 id)
646 * This format has been mandated by the IEEE specifications,
647 * so this line may not be changed to use the __set_bit() format.
649 tim[id / 8] |= (1 << (id % 8));
652 static inline void __bss_tim_clear(u8 *tim, u16 id)
655 * This format has been mandated by the IEEE specifications,
656 * so this line may not be changed to use the __clear_bit() format.
658 tim[id / 8] &= ~(1 << (id % 8));
661 static inline bool __bss_tim_get(u8 *tim, u16 id)
664 * This format has been mandated by the IEEE specifications,
665 * so this line may not be changed to use the test_bit() format.
667 return tim[id / 8] & (1 << (id % 8));
670 static unsigned long ieee80211_tids_for_ac(int ac)
672 /* If we ever support TIDs > 7, this obviously needs to be adjusted */
674 case IEEE80211_AC_VO:
675 return BIT(6) | BIT(7);
676 case IEEE80211_AC_VI:
677 return BIT(4) | BIT(5);
678 case IEEE80211_AC_BE:
679 return BIT(0) | BIT(3);
680 case IEEE80211_AC_BK:
681 return BIT(1) | BIT(2);
688 static void __sta_info_recalc_tim(struct sta_info *sta, bool ignore_pending)
690 struct ieee80211_local *local = sta->local;
692 bool indicate_tim = false;
693 u8 ignore_for_tim = sta->sta.uapsd_queues;
695 u16 id = sta->sta.aid;
697 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
698 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
699 if (WARN_ON_ONCE(!sta->sdata->bss))
702 ps = &sta->sdata->bss->ps;
703 #ifdef CONFIG_MAC80211_MESH
704 } else if (ieee80211_vif_is_mesh(&sta->sdata->vif)) {
705 ps = &sta->sdata->u.mesh.ps;
711 /* No need to do anything if the driver does all */
712 if (ieee80211_hw_check(&local->hw, AP_LINK_PS) && !local->ops->set_tim)
719 * If all ACs are delivery-enabled then we should build
720 * the TIM bit for all ACs anyway; if only some are then
721 * we ignore those and build the TIM bit using only the
724 if (ignore_for_tim == BIT(IEEE80211_NUM_ACS) - 1)
728 ignore_for_tim = BIT(IEEE80211_NUM_ACS) - 1;
730 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
733 if (ignore_for_tim & BIT(ac))
736 indicate_tim |= !skb_queue_empty(&sta->tx_filtered[ac]) ||
737 !skb_queue_empty(&sta->ps_tx_buf[ac]);
741 tids = ieee80211_tids_for_ac(ac);
744 sta->driver_buffered_tids & tids;
746 sta->txq_buffered_tids & tids;
750 spin_lock_bh(&local->tim_lock);
752 if (indicate_tim == __bss_tim_get(ps->tim, id))
756 __bss_tim_set(ps->tim, id);
758 __bss_tim_clear(ps->tim, id);
760 if (local->ops->set_tim && !WARN_ON(sta->dead)) {
761 local->tim_in_locked_section = true;
762 drv_set_tim(local, &sta->sta, indicate_tim);
763 local->tim_in_locked_section = false;
767 spin_unlock_bh(&local->tim_lock);
770 void sta_info_recalc_tim(struct sta_info *sta)
772 __sta_info_recalc_tim(sta, false);
775 static bool sta_info_buffer_expired(struct sta_info *sta, struct sk_buff *skb)
777 struct ieee80211_tx_info *info;
783 info = IEEE80211_SKB_CB(skb);
785 /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */
786 timeout = (sta->listen_interval *
787 sta->sdata->vif.bss_conf.beacon_int *
789 if (timeout < STA_TX_BUFFER_EXPIRE)
790 timeout = STA_TX_BUFFER_EXPIRE;
791 return time_after(jiffies, info->control.jiffies + timeout);
795 static bool sta_info_cleanup_expire_buffered_ac(struct ieee80211_local *local,
796 struct sta_info *sta, int ac)
802 * First check for frames that should expire on the filtered
803 * queue. Frames here were rejected by the driver and are on
804 * a separate queue to avoid reordering with normal PS-buffered
805 * frames. They also aren't accounted for right now in the
806 * total_ps_buffered counter.
809 spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
810 skb = skb_peek(&sta->tx_filtered[ac]);
811 if (sta_info_buffer_expired(sta, skb))
812 skb = __skb_dequeue(&sta->tx_filtered[ac]);
815 spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
818 * Frames are queued in order, so if this one
819 * hasn't expired yet we can stop testing. If
820 * we actually reached the end of the queue we
821 * also need to stop, of course.
825 ieee80211_free_txskb(&local->hw, skb);
829 * Now also check the normal PS-buffered queue, this will
830 * only find something if the filtered queue was emptied
831 * since the filtered frames are all before the normal PS
835 spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
836 skb = skb_peek(&sta->ps_tx_buf[ac]);
837 if (sta_info_buffer_expired(sta, skb))
838 skb = __skb_dequeue(&sta->ps_tx_buf[ac]);
841 spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
844 * frames are queued in order, so if this one
845 * hasn't expired yet (or we reached the end of
846 * the queue) we can stop testing
851 local->total_ps_buffered--;
852 ps_dbg(sta->sdata, "Buffered frame expired (STA %pM)\n",
854 ieee80211_free_txskb(&local->hw, skb);
858 * Finally, recalculate the TIM bit for this station -- it might
859 * now be clear because the station was too slow to retrieve its
862 sta_info_recalc_tim(sta);
865 * Return whether there are any frames still buffered, this is
866 * used to check whether the cleanup timer still needs to run,
867 * if there are no frames we don't need to rearm the timer.
869 return !(skb_queue_empty(&sta->ps_tx_buf[ac]) &&
870 skb_queue_empty(&sta->tx_filtered[ac]));
873 static bool sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
874 struct sta_info *sta)
876 bool have_buffered = false;
879 /* This is only necessary for stations on BSS/MBSS interfaces */
880 if (!sta->sdata->bss &&
881 !ieee80211_vif_is_mesh(&sta->sdata->vif))
884 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
886 sta_info_cleanup_expire_buffered_ac(local, sta, ac);
888 return have_buffered;
891 static int __must_check __sta_info_destroy_part1(struct sta_info *sta)
893 struct ieee80211_local *local;
894 struct ieee80211_sub_if_data *sdata;
905 lockdep_assert_held(&local->sta_mtx);
908 * Before removing the station from the driver and
909 * rate control, it might still start new aggregation
910 * sessions -- block that to make sure the tear-down
911 * will be sufficient.
913 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
914 ieee80211_sta_tear_down_BA_sessions(sta, AGG_STOP_DESTROY_STA);
917 * Before removing the station from the driver there might be pending
918 * rx frames on RSS queues sent prior to the disassociation - wait for
919 * all such frames to be processed.
921 drv_sync_rx_queues(local, sta);
923 ret = sta_info_hash_del(local, sta);
928 * for TDLS peers, make sure to return to the base channel before
931 if (test_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL)) {
932 drv_tdls_cancel_channel_switch(local, sdata, &sta->sta);
933 clear_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL);
936 list_del_rcu(&sta->list);
939 drv_sta_pre_rcu_remove(local, sta->sdata, sta);
941 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
942 rcu_access_pointer(sdata->u.vlan.sta) == sta)
943 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
948 static void __sta_info_destroy_part2(struct sta_info *sta)
950 struct ieee80211_local *local = sta->local;
951 struct ieee80211_sub_if_data *sdata = sta->sdata;
952 struct station_info *sinfo;
956 * NOTE: This assumes at least synchronize_net() was done
957 * after _part1 and before _part2!
961 lockdep_assert_held(&local->sta_mtx);
963 if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
964 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
968 /* now keys can no longer be reached */
969 ieee80211_free_sta_keys(local, sta);
971 /* disable TIM bit - last chance to tell driver */
972 __sta_info_recalc_tim(sta, true);
977 local->sta_generation++;
979 while (sta->sta_state > IEEE80211_STA_NONE) {
980 ret = sta_info_move_state(sta, sta->sta_state - 1);
988 ret = drv_sta_state(local, sdata, sta, IEEE80211_STA_NONE,
989 IEEE80211_STA_NOTEXIST);
990 WARN_ON_ONCE(ret != 0);
993 sta_dbg(sdata, "Removed STA %pM\n", sta->sta.addr);
995 sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL);
997 sta_set_sinfo(sta, sinfo);
998 cfg80211_del_sta_sinfo(sdata->dev, sta->sta.addr, sinfo, GFP_KERNEL);
1001 rate_control_remove_sta_debugfs(sta);
1002 ieee80211_sta_debugfs_remove(sta);
1004 ieee80211_destroy_frag_cache(&sta->frags);
1006 cleanup_single_sta(sta);
1009 int __must_check __sta_info_destroy(struct sta_info *sta)
1011 int err = __sta_info_destroy_part1(sta);
1018 __sta_info_destroy_part2(sta);
1023 int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata, const u8 *addr)
1025 struct sta_info *sta;
1028 mutex_lock(&sdata->local->sta_mtx);
1029 sta = sta_info_get(sdata, addr);
1030 ret = __sta_info_destroy(sta);
1031 mutex_unlock(&sdata->local->sta_mtx);
1036 int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata,
1039 struct sta_info *sta;
1042 mutex_lock(&sdata->local->sta_mtx);
1043 sta = sta_info_get_bss(sdata, addr);
1044 ret = __sta_info_destroy(sta);
1045 mutex_unlock(&sdata->local->sta_mtx);
1050 static void sta_info_cleanup(unsigned long data)
1052 struct ieee80211_local *local = (struct ieee80211_local *) data;
1053 struct sta_info *sta;
1054 bool timer_needed = false;
1057 list_for_each_entry_rcu(sta, &local->sta_list, list)
1058 if (sta_info_cleanup_expire_buffered(local, sta))
1059 timer_needed = true;
1062 if (local->quiescing)
1068 mod_timer(&local->sta_cleanup,
1069 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL));
1072 int sta_info_init(struct ieee80211_local *local)
1076 err = rhltable_init(&local->sta_hash, &sta_rht_params);
1080 spin_lock_init(&local->tim_lock);
1081 mutex_init(&local->sta_mtx);
1082 INIT_LIST_HEAD(&local->sta_list);
1084 setup_timer(&local->sta_cleanup, sta_info_cleanup,
1085 (unsigned long)local);
1089 void sta_info_stop(struct ieee80211_local *local)
1091 del_timer_sync(&local->sta_cleanup);
1092 rhltable_destroy(&local->sta_hash);
1096 int __sta_info_flush(struct ieee80211_sub_if_data *sdata, bool vlans)
1098 struct ieee80211_local *local = sdata->local;
1099 struct sta_info *sta, *tmp;
1100 LIST_HEAD(free_list);
1105 WARN_ON(vlans && sdata->vif.type != NL80211_IFTYPE_AP);
1106 WARN_ON(vlans && !sdata->bss);
1108 mutex_lock(&local->sta_mtx);
1109 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
1110 if (sdata == sta->sdata ||
1111 (vlans && sdata->bss == sta->sdata->bss)) {
1112 if (!WARN_ON(__sta_info_destroy_part1(sta)))
1113 list_add(&sta->free_list, &free_list);
1118 if (!list_empty(&free_list)) {
1120 list_for_each_entry_safe(sta, tmp, &free_list, free_list)
1121 __sta_info_destroy_part2(sta);
1123 mutex_unlock(&local->sta_mtx);
1128 void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
1129 unsigned long exp_time)
1131 struct ieee80211_local *local = sdata->local;
1132 struct sta_info *sta, *tmp;
1134 mutex_lock(&local->sta_mtx);
1136 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
1137 unsigned long last_active = ieee80211_sta_last_active(sta);
1139 if (sdata != sta->sdata)
1142 if (time_is_before_jiffies(last_active + exp_time)) {
1143 sta_dbg(sta->sdata, "expiring inactive STA %pM\n",
1146 if (ieee80211_vif_is_mesh(&sdata->vif) &&
1147 test_sta_flag(sta, WLAN_STA_PS_STA))
1148 atomic_dec(&sdata->u.mesh.ps.num_sta_ps);
1150 WARN_ON(__sta_info_destroy(sta));
1154 mutex_unlock(&local->sta_mtx);
1157 struct ieee80211_sta *ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw,
1159 const u8 *localaddr)
1161 struct ieee80211_local *local = hw_to_local(hw);
1162 struct rhlist_head *tmp;
1163 struct sta_info *sta;
1166 * Just return a random station if localaddr is NULL
1167 * ... first in list.
1169 for_each_sta_info(local, addr, sta, tmp) {
1171 !ether_addr_equal(sta->sdata->vif.addr, localaddr))
1180 EXPORT_SYMBOL_GPL(ieee80211_find_sta_by_ifaddr);
1182 struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_vif *vif,
1185 struct sta_info *sta;
1190 sta = sta_info_get_bss(vif_to_sdata(vif), addr);
1199 EXPORT_SYMBOL(ieee80211_find_sta);
1201 /* powersave support code */
1202 void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
1204 struct ieee80211_sub_if_data *sdata = sta->sdata;
1205 struct ieee80211_local *local = sdata->local;
1206 struct sk_buff_head pending;
1207 int filtered = 0, buffered = 0, ac, i;
1208 unsigned long flags;
1211 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1212 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
1215 if (sdata->vif.type == NL80211_IFTYPE_AP)
1216 ps = &sdata->bss->ps;
1217 else if (ieee80211_vif_is_mesh(&sdata->vif))
1218 ps = &sdata->u.mesh.ps;
1222 clear_sta_flag(sta, WLAN_STA_SP);
1224 BUILD_BUG_ON(BITS_TO_LONGS(IEEE80211_NUM_TIDS) > 1);
1225 sta->driver_buffered_tids = 0;
1226 sta->txq_buffered_tids = 0;
1228 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
1229 drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta);
1231 if (sta->sta.txq[0]) {
1232 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
1233 if (!txq_has_queue(sta->sta.txq[i]))
1236 drv_wake_tx_queue(local, to_txq_info(sta->sta.txq[i]));
1240 skb_queue_head_init(&pending);
1242 /* sync with ieee80211_tx_h_unicast_ps_buf */
1243 spin_lock(&sta->ps_lock);
1244 /* Send all buffered frames to the station */
1245 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1246 int count = skb_queue_len(&pending), tmp;
1248 spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
1249 skb_queue_splice_tail_init(&sta->tx_filtered[ac], &pending);
1250 spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
1251 tmp = skb_queue_len(&pending);
1252 filtered += tmp - count;
1255 spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
1256 skb_queue_splice_tail_init(&sta->ps_tx_buf[ac], &pending);
1257 spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
1258 tmp = skb_queue_len(&pending);
1259 buffered += tmp - count;
1262 ieee80211_add_pending_skbs(local, &pending);
1264 /* now we're no longer in the deliver code */
1265 clear_sta_flag(sta, WLAN_STA_PS_DELIVER);
1267 /* The station might have polled and then woken up before we responded,
1268 * so clear these flags now to avoid them sticking around.
1270 clear_sta_flag(sta, WLAN_STA_PSPOLL);
1271 clear_sta_flag(sta, WLAN_STA_UAPSD);
1272 spin_unlock(&sta->ps_lock);
1274 atomic_dec(&ps->num_sta_ps);
1276 /* This station just woke up and isn't aware of our SMPS state */
1277 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
1278 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
1279 sdata->smps_mode) &&
1280 sta->known_smps_mode != sdata->bss->req_smps &&
1281 sta_info_tx_streams(sta) != 1) {
1283 "%pM just woke up and MIMO capable - update SMPS\n",
1285 ieee80211_send_smps_action(sdata, sdata->bss->req_smps,
1287 sdata->vif.bss_conf.bssid);
1290 local->total_ps_buffered -= buffered;
1292 sta_info_recalc_tim(sta);
1295 "STA %pM aid %d sending %d filtered/%d PS frames since STA not sleeping anymore\n",
1296 sta->sta.addr, sta->sta.aid, filtered, buffered);
1298 ieee80211_check_fast_xmit(sta);
1301 static void ieee80211_send_null_response(struct sta_info *sta, int tid,
1302 enum ieee80211_frame_release_type reason,
1303 bool call_driver, bool more_data)
1305 struct ieee80211_sub_if_data *sdata = sta->sdata;
1306 struct ieee80211_local *local = sdata->local;
1307 struct ieee80211_qos_hdr *nullfunc;
1308 struct sk_buff *skb;
1309 int size = sizeof(*nullfunc);
1311 bool qos = sta->sta.wme;
1312 struct ieee80211_tx_info *info;
1313 struct ieee80211_chanctx_conf *chanctx_conf;
1316 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
1317 IEEE80211_STYPE_QOS_NULLFUNC |
1318 IEEE80211_FCTL_FROMDS);
1321 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
1322 IEEE80211_STYPE_NULLFUNC |
1323 IEEE80211_FCTL_FROMDS);
1326 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
1330 skb_reserve(skb, local->hw.extra_tx_headroom);
1332 nullfunc = (void *) skb_put(skb, size);
1333 nullfunc->frame_control = fc;
1334 nullfunc->duration_id = 0;
1335 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
1336 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1337 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
1338 nullfunc->seq_ctrl = 0;
1340 skb->priority = tid;
1341 skb_set_queue_mapping(skb, ieee802_1d_to_ac[tid]);
1343 nullfunc->qos_ctrl = cpu_to_le16(tid);
1345 if (reason == IEEE80211_FRAME_RELEASE_UAPSD) {
1346 nullfunc->qos_ctrl |=
1347 cpu_to_le16(IEEE80211_QOS_CTL_EOSP);
1349 nullfunc->frame_control |=
1350 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
1354 info = IEEE80211_SKB_CB(skb);
1357 * Tell TX path to send this frame even though the
1358 * STA may still remain is PS mode after this frame
1359 * exchange. Also set EOSP to indicate this packet
1360 * ends the poll/service period.
1362 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER |
1363 IEEE80211_TX_STATUS_EOSP |
1364 IEEE80211_TX_CTL_REQ_TX_STATUS;
1366 info->control.flags |= IEEE80211_TX_CTRL_PS_RESPONSE;
1369 drv_allow_buffered_frames(local, sta, BIT(tid), 1,
1372 skb->dev = sdata->dev;
1375 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
1376 if (WARN_ON(!chanctx_conf)) {
1382 info->band = chanctx_conf->def.chan->band;
1383 ieee80211_xmit(sdata, sta, skb);
1387 static int find_highest_prio_tid(unsigned long tids)
1389 /* lower 3 TIDs aren't ordered perfectly */
1391 return fls(tids) - 1;
1392 /* TID 0 is BE just like TID 3 */
1395 return fls(tids) - 1;
1398 /* Indicates if the MORE_DATA bit should be set in the last
1399 * frame obtained by ieee80211_sta_ps_get_frames.
1400 * Note that driver_release_tids is relevant only if
1401 * reason = IEEE80211_FRAME_RELEASE_PSPOLL
1404 ieee80211_sta_ps_more_data(struct sta_info *sta, u8 ignored_acs,
1405 enum ieee80211_frame_release_type reason,
1406 unsigned long driver_release_tids)
1410 /* If the driver has data on more than one TID then
1411 * certainly there's more data if we release just a
1412 * single frame now (from a single TID). This will
1413 * only happen for PS-Poll.
1415 if (reason == IEEE80211_FRAME_RELEASE_PSPOLL &&
1416 hweight16(driver_release_tids) > 1)
1419 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1420 if (ignored_acs & BIT(ac))
1423 if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
1424 !skb_queue_empty(&sta->ps_tx_buf[ac]))
1432 ieee80211_sta_ps_get_frames(struct sta_info *sta, int n_frames, u8 ignored_acs,
1433 enum ieee80211_frame_release_type reason,
1434 struct sk_buff_head *frames,
1435 unsigned long *driver_release_tids)
1437 struct ieee80211_sub_if_data *sdata = sta->sdata;
1438 struct ieee80211_local *local = sdata->local;
1441 /* Get response frame(s) and more data bit for the last one. */
1442 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1445 if (ignored_acs & BIT(ac))
1448 tids = ieee80211_tids_for_ac(ac);
1450 /* if we already have frames from software, then we can't also
1451 * release from hardware queues
1453 if (skb_queue_empty(frames)) {
1454 *driver_release_tids |=
1455 sta->driver_buffered_tids & tids;
1456 *driver_release_tids |= sta->txq_buffered_tids & tids;
1459 if (!*driver_release_tids) {
1460 struct sk_buff *skb;
1462 while (n_frames > 0) {
1463 skb = skb_dequeue(&sta->tx_filtered[ac]);
1466 &sta->ps_tx_buf[ac]);
1468 local->total_ps_buffered--;
1473 __skb_queue_tail(frames, skb);
1477 /* If we have more frames buffered on this AC, then abort the
1478 * loop since we can't send more data from other ACs before
1479 * the buffered frames from this.
1481 if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
1482 !skb_queue_empty(&sta->ps_tx_buf[ac]))
1488 ieee80211_sta_ps_deliver_response(struct sta_info *sta,
1489 int n_frames, u8 ignored_acs,
1490 enum ieee80211_frame_release_type reason)
1492 struct ieee80211_sub_if_data *sdata = sta->sdata;
1493 struct ieee80211_local *local = sdata->local;
1494 unsigned long driver_release_tids = 0;
1495 struct sk_buff_head frames;
1498 /* Service or PS-Poll period starts */
1499 set_sta_flag(sta, WLAN_STA_SP);
1501 __skb_queue_head_init(&frames);
1503 ieee80211_sta_ps_get_frames(sta, n_frames, ignored_acs, reason,
1504 &frames, &driver_release_tids);
1506 more_data = ieee80211_sta_ps_more_data(sta, ignored_acs, reason, driver_release_tids);
1508 if (driver_release_tids && reason == IEEE80211_FRAME_RELEASE_PSPOLL)
1509 driver_release_tids =
1510 BIT(find_highest_prio_tid(driver_release_tids));
1512 if (skb_queue_empty(&frames) && !driver_release_tids) {
1516 * For PS-Poll, this can only happen due to a race condition
1517 * when we set the TIM bit and the station notices it, but
1518 * before it can poll for the frame we expire it.
1520 * For uAPSD, this is said in the standard (11.2.1.5 h):
1521 * At each unscheduled SP for a non-AP STA, the AP shall
1522 * attempt to transmit at least one MSDU or MMPDU, but no
1523 * more than the value specified in the Max SP Length field
1524 * in the QoS Capability element from delivery-enabled ACs,
1525 * that are destined for the non-AP STA.
1527 * Since we have no other MSDU/MMPDU, transmit a QoS null frame.
1530 /* This will evaluate to 1, 3, 5 or 7. */
1531 tid = 7 - ((ffs(~ignored_acs) - 1) << 1);
1533 ieee80211_send_null_response(sta, tid, reason, true, false);
1534 } else if (!driver_release_tids) {
1535 struct sk_buff_head pending;
1536 struct sk_buff *skb;
1539 bool need_null = false;
1541 skb_queue_head_init(&pending);
1543 while ((skb = __skb_dequeue(&frames))) {
1544 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1545 struct ieee80211_hdr *hdr = (void *) skb->data;
1551 * Tell TX path to send this frame even though the
1552 * STA may still remain is PS mode after this frame
1555 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER;
1556 info->control.flags |= IEEE80211_TX_CTRL_PS_RESPONSE;
1559 * Use MoreData flag to indicate whether there are
1560 * more buffered frames for this STA
1562 if (more_data || !skb_queue_empty(&frames))
1563 hdr->frame_control |=
1564 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
1566 hdr->frame_control &=
1567 cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
1569 if (ieee80211_is_data_qos(hdr->frame_control) ||
1570 ieee80211_is_qos_nullfunc(hdr->frame_control))
1571 qoshdr = ieee80211_get_qos_ctl(hdr);
1573 tids |= BIT(skb->priority);
1575 __skb_queue_tail(&pending, skb);
1577 /* end service period after last frame or add one */
1578 if (!skb_queue_empty(&frames))
1581 if (reason != IEEE80211_FRAME_RELEASE_UAPSD) {
1582 /* for PS-Poll, there's only one frame */
1583 info->flags |= IEEE80211_TX_STATUS_EOSP |
1584 IEEE80211_TX_CTL_REQ_TX_STATUS;
1588 /* For uAPSD, things are a bit more complicated. If the
1589 * last frame has a QoS header (i.e. is a QoS-data or
1590 * QoS-nulldata frame) then just set the EOSP bit there
1592 * If the frame doesn't have a QoS header (which means
1593 * it should be a bufferable MMPDU) then we can't set
1594 * the EOSP bit in the QoS header; add a QoS-nulldata
1595 * frame to the list to send it after the MMPDU.
1597 * Note that this code is only in the mac80211-release
1598 * code path, we assume that the driver will not buffer
1599 * anything but QoS-data frames, or if it does, will
1600 * create the QoS-nulldata frame by itself if needed.
1602 * Cf. 802.11-2012 10.2.1.10 (c).
1605 *qoshdr |= IEEE80211_QOS_CTL_EOSP;
1607 info->flags |= IEEE80211_TX_STATUS_EOSP |
1608 IEEE80211_TX_CTL_REQ_TX_STATUS;
1610 /* The standard isn't completely clear on this
1611 * as it says the more-data bit should be set
1612 * if there are more BUs. The QoS-Null frame
1613 * we're about to send isn't buffered yet, we
1614 * only create it below, but let's pretend it
1615 * was buffered just in case some clients only
1616 * expect more-data=0 when eosp=1.
1618 hdr->frame_control |=
1619 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
1626 drv_allow_buffered_frames(local, sta, tids, num,
1629 ieee80211_add_pending_skbs(local, &pending);
1632 ieee80211_send_null_response(
1633 sta, find_highest_prio_tid(tids),
1634 reason, false, false);
1636 sta_info_recalc_tim(sta);
1641 * We need to release a frame that is buffered somewhere in the
1642 * driver ... it'll have to handle that.
1643 * Note that the driver also has to check the number of frames
1644 * on the TIDs we're releasing from - if there are more than
1645 * n_frames it has to set the more-data bit (if we didn't ask
1646 * it to set it anyway due to other buffered frames); if there
1647 * are fewer than n_frames it has to make sure to adjust that
1648 * to allow the service period to end properly.
1650 drv_release_buffered_frames(local, sta, driver_release_tids,
1651 n_frames, reason, more_data);
1654 * Note that we don't recalculate the TIM bit here as it would
1655 * most likely have no effect at all unless the driver told us
1656 * that the TID(s) became empty before returning here from the
1658 * Either way, however, when the driver tells us that the TID(s)
1659 * became empty or we find that a txq became empty, we'll do the
1660 * TIM recalculation.
1663 if (!sta->sta.txq[0])
1666 for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
1667 if (!(driver_release_tids & BIT(tid)) ||
1668 txq_has_queue(sta->sta.txq[tid]))
1671 sta_info_recalc_tim(sta);
1677 void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta)
1679 u8 ignore_for_response = sta->sta.uapsd_queues;
1682 * If all ACs are delivery-enabled then we should reply
1683 * from any of them, if only some are enabled we reply
1684 * only from the non-enabled ones.
1686 if (ignore_for_response == BIT(IEEE80211_NUM_ACS) - 1)
1687 ignore_for_response = 0;
1689 ieee80211_sta_ps_deliver_response(sta, 1, ignore_for_response,
1690 IEEE80211_FRAME_RELEASE_PSPOLL);
1693 void ieee80211_sta_ps_deliver_uapsd(struct sta_info *sta)
1695 int n_frames = sta->sta.max_sp;
1696 u8 delivery_enabled = sta->sta.uapsd_queues;
1699 * If we ever grow support for TSPEC this might happen if
1700 * the TSPEC update from hostapd comes in between a trigger
1701 * frame setting WLAN_STA_UAPSD in the RX path and this
1702 * actually getting called.
1704 if (!delivery_enabled)
1707 switch (sta->sta.max_sp) {
1718 /* XXX: what is a good value? */
1723 ieee80211_sta_ps_deliver_response(sta, n_frames, ~delivery_enabled,
1724 IEEE80211_FRAME_RELEASE_UAPSD);
1727 void ieee80211_sta_block_awake(struct ieee80211_hw *hw,
1728 struct ieee80211_sta *pubsta, bool block)
1730 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1732 trace_api_sta_block_awake(sta->local, pubsta, block);
1735 set_sta_flag(sta, WLAN_STA_PS_DRIVER);
1736 ieee80211_clear_fast_xmit(sta);
1740 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1743 if (!test_sta_flag(sta, WLAN_STA_PS_STA)) {
1744 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
1745 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
1746 ieee80211_queue_work(hw, &sta->drv_deliver_wk);
1747 } else if (test_sta_flag(sta, WLAN_STA_PSPOLL) ||
1748 test_sta_flag(sta, WLAN_STA_UAPSD)) {
1749 /* must be asleep in this case */
1750 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
1751 ieee80211_queue_work(hw, &sta->drv_deliver_wk);
1753 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
1754 ieee80211_check_fast_xmit(sta);
1757 EXPORT_SYMBOL(ieee80211_sta_block_awake);
1759 void ieee80211_sta_eosp(struct ieee80211_sta *pubsta)
1761 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1762 struct ieee80211_local *local = sta->local;
1764 trace_api_eosp(local, pubsta);
1766 clear_sta_flag(sta, WLAN_STA_SP);
1768 EXPORT_SYMBOL(ieee80211_sta_eosp);
1770 void ieee80211_send_eosp_nullfunc(struct ieee80211_sta *pubsta, int tid)
1772 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1773 enum ieee80211_frame_release_type reason;
1776 trace_api_send_eosp_nullfunc(sta->local, pubsta, tid);
1778 reason = IEEE80211_FRAME_RELEASE_UAPSD;
1779 more_data = ieee80211_sta_ps_more_data(sta, ~sta->sta.uapsd_queues,
1782 ieee80211_send_null_response(sta, tid, reason, false, more_data);
1784 EXPORT_SYMBOL(ieee80211_send_eosp_nullfunc);
1786 void ieee80211_sta_set_buffered(struct ieee80211_sta *pubsta,
1787 u8 tid, bool buffered)
1789 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1791 if (WARN_ON(tid >= IEEE80211_NUM_TIDS))
1794 trace_api_sta_set_buffered(sta->local, pubsta, tid, buffered);
1797 set_bit(tid, &sta->driver_buffered_tids);
1799 clear_bit(tid, &sta->driver_buffered_tids);
1801 sta_info_recalc_tim(sta);
1803 EXPORT_SYMBOL(ieee80211_sta_set_buffered);
1806 ieee80211_recalc_p2p_go_ps_allowed(struct ieee80211_sub_if_data *sdata)
1808 struct ieee80211_local *local = sdata->local;
1809 bool allow_p2p_go_ps = sdata->vif.p2p;
1810 struct sta_info *sta;
1813 list_for_each_entry_rcu(sta, &local->sta_list, list) {
1814 if (sdata != sta->sdata ||
1815 !test_sta_flag(sta, WLAN_STA_ASSOC))
1817 if (!sta->sta.support_p2p_ps) {
1818 allow_p2p_go_ps = false;
1824 if (allow_p2p_go_ps != sdata->vif.bss_conf.allow_p2p_go_ps) {
1825 sdata->vif.bss_conf.allow_p2p_go_ps = allow_p2p_go_ps;
1826 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_P2P_PS);
1830 int sta_info_move_state(struct sta_info *sta,
1831 enum ieee80211_sta_state new_state)
1835 if (sta->sta_state == new_state)
1838 /* check allowed transitions first */
1840 switch (new_state) {
1841 case IEEE80211_STA_NONE:
1842 if (sta->sta_state != IEEE80211_STA_AUTH)
1845 case IEEE80211_STA_AUTH:
1846 if (sta->sta_state != IEEE80211_STA_NONE &&
1847 sta->sta_state != IEEE80211_STA_ASSOC)
1850 case IEEE80211_STA_ASSOC:
1851 if (sta->sta_state != IEEE80211_STA_AUTH &&
1852 sta->sta_state != IEEE80211_STA_AUTHORIZED)
1855 case IEEE80211_STA_AUTHORIZED:
1856 if (sta->sta_state != IEEE80211_STA_ASSOC)
1860 WARN(1, "invalid state %d", new_state);
1864 sta_dbg(sta->sdata, "moving STA %pM to state %d\n",
1865 sta->sta.addr, new_state);
1868 * notify the driver before the actual changes so it can
1869 * fail the transition
1871 if (test_sta_flag(sta, WLAN_STA_INSERTED)) {
1872 int err = drv_sta_state(sta->local, sta->sdata, sta,
1873 sta->sta_state, new_state);
1878 /* reflect the change in all state variables */
1880 switch (new_state) {
1881 case IEEE80211_STA_NONE:
1882 if (sta->sta_state == IEEE80211_STA_AUTH)
1883 clear_bit(WLAN_STA_AUTH, &sta->_flags);
1885 case IEEE80211_STA_AUTH:
1886 if (sta->sta_state == IEEE80211_STA_NONE) {
1887 set_bit(WLAN_STA_AUTH, &sta->_flags);
1888 } else if (sta->sta_state == IEEE80211_STA_ASSOC) {
1889 clear_bit(WLAN_STA_ASSOC, &sta->_flags);
1890 ieee80211_recalc_min_chandef(sta->sdata);
1891 if (!sta->sta.support_p2p_ps)
1892 ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
1895 case IEEE80211_STA_ASSOC:
1896 if (sta->sta_state == IEEE80211_STA_AUTH) {
1897 set_bit(WLAN_STA_ASSOC, &sta->_flags);
1898 ieee80211_recalc_min_chandef(sta->sdata);
1899 if (!sta->sta.support_p2p_ps)
1900 ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
1901 } else if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
1902 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1903 (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1904 !sta->sdata->u.vlan.sta))
1905 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1906 clear_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
1907 ieee80211_clear_fast_xmit(sta);
1908 ieee80211_clear_fast_rx(sta);
1911 case IEEE80211_STA_AUTHORIZED:
1912 if (sta->sta_state == IEEE80211_STA_ASSOC) {
1913 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1914 (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1915 !sta->sdata->u.vlan.sta))
1916 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1917 set_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
1918 ieee80211_check_fast_xmit(sta);
1919 ieee80211_check_fast_rx(sta);
1921 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1922 sta->sdata->vif.type == NL80211_IFTYPE_AP)
1923 cfg80211_send_layer2_update(sta->sdata->dev,
1930 sta->sta_state = new_state;
1935 u8 sta_info_tx_streams(struct sta_info *sta)
1937 struct ieee80211_sta_ht_cap *ht_cap = &sta->sta.ht_cap;
1940 if (!sta->sta.ht_cap.ht_supported)
1943 if (sta->sta.vht_cap.vht_supported) {
1946 le16_to_cpu(sta->sta.vht_cap.vht_mcs.tx_mcs_map);
1948 for (i = 7; i >= 0; i--)
1949 if ((tx_mcs_map & (0x3 << (i * 2))) !=
1950 IEEE80211_VHT_MCS_NOT_SUPPORTED)
1954 if (ht_cap->mcs.rx_mask[3])
1956 else if (ht_cap->mcs.rx_mask[2])
1958 else if (ht_cap->mcs.rx_mask[1])
1963 if (!(ht_cap->mcs.tx_params & IEEE80211_HT_MCS_TX_RX_DIFF))
1966 return ((ht_cap->mcs.tx_params & IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
1967 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT) + 1;
1970 static struct ieee80211_sta_rx_stats *
1971 sta_get_last_rx_stats(struct sta_info *sta)
1973 struct ieee80211_sta_rx_stats *stats = &sta->rx_stats;
1974 struct ieee80211_local *local = sta->local;
1977 if (!ieee80211_hw_check(&local->hw, USES_RSS))
1980 for_each_possible_cpu(cpu) {
1981 struct ieee80211_sta_rx_stats *cpustats;
1983 cpustats = per_cpu_ptr(sta->pcpu_rx_stats, cpu);
1985 if (time_after(cpustats->last_rx, stats->last_rx))
1992 static void sta_stats_decode_rate(struct ieee80211_local *local, u16 rate,
1993 struct rate_info *rinfo)
1995 rinfo->bw = (rate & STA_STATS_RATE_BW_MASK) >>
1996 STA_STATS_RATE_BW_SHIFT;
1998 if (rate & STA_STATS_RATE_VHT) {
1999 rinfo->flags = RATE_INFO_FLAGS_VHT_MCS;
2000 rinfo->mcs = rate & 0xf;
2001 rinfo->nss = (rate & 0xf0) >> 4;
2002 } else if (rate & STA_STATS_RATE_HT) {
2003 rinfo->flags = RATE_INFO_FLAGS_MCS;
2004 rinfo->mcs = rate & 0xff;
2005 } else if (rate & STA_STATS_RATE_LEGACY) {
2006 struct ieee80211_supported_band *sband;
2010 sband = local->hw.wiphy->bands[(rate >> 4) & 0xf];
2011 brate = sband->bitrates[rate & 0xf].bitrate;
2012 if (rinfo->bw == RATE_INFO_BW_5)
2014 else if (rinfo->bw == RATE_INFO_BW_10)
2018 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
2021 if (rate & STA_STATS_RATE_SGI)
2022 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
2025 static void sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
2027 u16 rate = ACCESS_ONCE(sta_get_last_rx_stats(sta)->last_rate);
2029 if (rate == STA_STATS_RATE_INVALID)
2032 sta_stats_decode_rate(sta->local, rate, rinfo);
2035 static void sta_set_tidstats(struct sta_info *sta,
2036 struct cfg80211_tid_stats *tidstats,
2039 struct ieee80211_local *local = sta->local;
2041 if (!(tidstats->filled & BIT(NL80211_TID_STATS_RX_MSDU))) {
2045 start = u64_stats_fetch_begin(&sta->rx_stats.syncp);
2046 tidstats->rx_msdu = sta->rx_stats.msdu[tid];
2047 } while (u64_stats_fetch_retry(&sta->rx_stats.syncp, start));
2049 tidstats->filled |= BIT(NL80211_TID_STATS_RX_MSDU);
2052 if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU))) {
2053 tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU);
2054 tidstats->tx_msdu = sta->tx_stats.msdu[tid];
2057 if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU_RETRIES)) &&
2058 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
2059 tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU_RETRIES);
2060 tidstats->tx_msdu_retries = sta->status_stats.msdu_retries[tid];
2063 if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU_FAILED)) &&
2064 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
2065 tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU_FAILED);
2066 tidstats->tx_msdu_failed = sta->status_stats.msdu_failed[tid];
2070 static inline u64 sta_get_stats_bytes(struct ieee80211_sta_rx_stats *rxstats)
2076 start = u64_stats_fetch_begin(&rxstats->syncp);
2077 value = rxstats->bytes;
2078 } while (u64_stats_fetch_retry(&rxstats->syncp, start));
2083 void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
2085 struct ieee80211_sub_if_data *sdata = sta->sdata;
2086 struct ieee80211_local *local = sdata->local;
2087 struct rate_control_ref *ref = NULL;
2090 struct ieee80211_sta_rx_stats *last_rxstats;
2092 last_rxstats = sta_get_last_rx_stats(sta);
2094 if (test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
2095 ref = local->rate_ctrl;
2097 sinfo->generation = sdata->local->sta_generation;
2099 /* do before driver, so beacon filtering drivers have a
2100 * chance to e.g. just add the number of filtered beacons
2101 * (or just modify the value entirely, of course)
2103 if (sdata->vif.type == NL80211_IFTYPE_STATION)
2104 sinfo->rx_beacon = sdata->u.mgd.count_beacon_signal;
2106 drv_sta_statistics(local, sdata, &sta->sta, sinfo);
2108 sinfo->filled |= BIT(NL80211_STA_INFO_INACTIVE_TIME) |
2109 BIT(NL80211_STA_INFO_STA_FLAGS) |
2110 BIT(NL80211_STA_INFO_BSS_PARAM) |
2111 BIT(NL80211_STA_INFO_CONNECTED_TIME) |
2112 BIT(NL80211_STA_INFO_RX_DROP_MISC);
2114 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
2115 sinfo->beacon_loss_count = sdata->u.mgd.beacon_loss_count;
2116 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_LOSS);
2119 sinfo->connected_time = ktime_get_seconds() - sta->last_connected;
2120 sinfo->inactive_time =
2121 jiffies_to_msecs(jiffies - ieee80211_sta_last_active(sta));
2123 if (!(sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES64) |
2124 BIT(NL80211_STA_INFO_TX_BYTES)))) {
2125 sinfo->tx_bytes = 0;
2126 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
2127 sinfo->tx_bytes += sta->tx_stats.bytes[ac];
2128 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BYTES64);
2131 if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_PACKETS))) {
2132 sinfo->tx_packets = 0;
2133 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
2134 sinfo->tx_packets += sta->tx_stats.packets[ac];
2135 sinfo->filled |= BIT(NL80211_STA_INFO_TX_PACKETS);
2138 if (!(sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES64) |
2139 BIT(NL80211_STA_INFO_RX_BYTES)))) {
2140 sinfo->rx_bytes += sta_get_stats_bytes(&sta->rx_stats);
2142 if (sta->pcpu_rx_stats) {
2143 for_each_possible_cpu(cpu) {
2144 struct ieee80211_sta_rx_stats *cpurxs;
2146 cpurxs = per_cpu_ptr(sta->pcpu_rx_stats, cpu);
2147 sinfo->rx_bytes += sta_get_stats_bytes(cpurxs);
2151 sinfo->filled |= BIT(NL80211_STA_INFO_RX_BYTES64);
2154 if (!(sinfo->filled & BIT(NL80211_STA_INFO_RX_PACKETS))) {
2155 sinfo->rx_packets = sta->rx_stats.packets;
2156 if (sta->pcpu_rx_stats) {
2157 for_each_possible_cpu(cpu) {
2158 struct ieee80211_sta_rx_stats *cpurxs;
2160 cpurxs = per_cpu_ptr(sta->pcpu_rx_stats, cpu);
2161 sinfo->rx_packets += cpurxs->packets;
2164 sinfo->filled |= BIT(NL80211_STA_INFO_RX_PACKETS);
2167 if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_RETRIES))) {
2168 sinfo->tx_retries = sta->status_stats.retry_count;
2169 sinfo->filled |= BIT(NL80211_STA_INFO_TX_RETRIES);
2172 if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_FAILED))) {
2173 sinfo->tx_failed = sta->status_stats.retry_failed;
2174 sinfo->filled |= BIT(NL80211_STA_INFO_TX_FAILED);
2177 sinfo->rx_dropped_misc = sta->rx_stats.dropped;
2178 if (sta->pcpu_rx_stats) {
2179 for_each_possible_cpu(cpu) {
2180 struct ieee80211_sta_rx_stats *cpurxs;
2182 cpurxs = per_cpu_ptr(sta->pcpu_rx_stats, cpu);
2183 sinfo->rx_dropped_misc += cpurxs->dropped;
2187 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2188 !(sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)) {
2189 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_RX) |
2190 BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
2191 sinfo->rx_beacon_signal_avg = ieee80211_ave_rssi(&sdata->vif);
2194 if (ieee80211_hw_check(&sta->local->hw, SIGNAL_DBM) ||
2195 ieee80211_hw_check(&sta->local->hw, SIGNAL_UNSPEC)) {
2196 if (!(sinfo->filled & BIT(NL80211_STA_INFO_SIGNAL))) {
2197 sinfo->signal = (s8)last_rxstats->last_signal;
2198 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
2201 if (!sta->pcpu_rx_stats &&
2202 !(sinfo->filled & BIT(NL80211_STA_INFO_SIGNAL_AVG))) {
2204 -ewma_signal_read(&sta->rx_stats_avg.signal);
2205 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL_AVG);
2209 /* for the average - if pcpu_rx_stats isn't set - rxstats must point to
2210 * the sta->rx_stats struct, so the check here is fine with and without
2213 if (last_rxstats->chains &&
2214 !(sinfo->filled & (BIT(NL80211_STA_INFO_CHAIN_SIGNAL) |
2215 BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)))) {
2216 sinfo->filled |= BIT(NL80211_STA_INFO_CHAIN_SIGNAL);
2217 if (!sta->pcpu_rx_stats)
2218 sinfo->filled |= BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG);
2220 sinfo->chains = last_rxstats->chains;
2222 for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
2223 sinfo->chain_signal[i] =
2224 last_rxstats->chain_signal_last[i];
2225 sinfo->chain_signal_avg[i] =
2226 -ewma_signal_read(&sta->rx_stats_avg.chain_signal[i]);
2230 if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE))) {
2231 sta_set_rate_info_tx(sta, &sta->tx_stats.last_rate,
2233 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE);
2236 if (!(sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE))) {
2237 sta_set_rate_info_rx(sta, &sinfo->rxrate);
2238 sinfo->filled |= BIT(NL80211_STA_INFO_RX_BITRATE);
2241 sinfo->filled |= BIT(NL80211_STA_INFO_TID_STATS);
2242 for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) {
2243 struct cfg80211_tid_stats *tidstats = &sinfo->pertid[i];
2245 sta_set_tidstats(sta, tidstats, i);
2248 if (ieee80211_vif_is_mesh(&sdata->vif)) {
2249 #ifdef CONFIG_MAC80211_MESH
2250 sinfo->filled |= BIT(NL80211_STA_INFO_LLID) |
2251 BIT(NL80211_STA_INFO_PLID) |
2252 BIT(NL80211_STA_INFO_PLINK_STATE) |
2253 BIT(NL80211_STA_INFO_LOCAL_PM) |
2254 BIT(NL80211_STA_INFO_PEER_PM) |
2255 BIT(NL80211_STA_INFO_NONPEER_PM);
2257 sinfo->llid = sta->mesh->llid;
2258 sinfo->plid = sta->mesh->plid;
2259 sinfo->plink_state = sta->mesh->plink_state;
2260 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
2261 sinfo->filled |= BIT(NL80211_STA_INFO_T_OFFSET);
2262 sinfo->t_offset = sta->mesh->t_offset;
2264 sinfo->local_pm = sta->mesh->local_pm;
2265 sinfo->peer_pm = sta->mesh->peer_pm;
2266 sinfo->nonpeer_pm = sta->mesh->nonpeer_pm;
2270 sinfo->bss_param.flags = 0;
2271 if (sdata->vif.bss_conf.use_cts_prot)
2272 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
2273 if (sdata->vif.bss_conf.use_short_preamble)
2274 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
2275 if (sdata->vif.bss_conf.use_short_slot)
2276 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
2277 sinfo->bss_param.dtim_period = sdata->vif.bss_conf.dtim_period;
2278 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
2280 sinfo->sta_flags.set = 0;
2281 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2282 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2283 BIT(NL80211_STA_FLAG_WME) |
2284 BIT(NL80211_STA_FLAG_MFP) |
2285 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2286 BIT(NL80211_STA_FLAG_ASSOCIATED) |
2287 BIT(NL80211_STA_FLAG_TDLS_PEER);
2288 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2289 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
2290 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
2291 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
2293 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
2294 if (test_sta_flag(sta, WLAN_STA_MFP))
2295 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
2296 if (test_sta_flag(sta, WLAN_STA_AUTH))
2297 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
2298 if (test_sta_flag(sta, WLAN_STA_ASSOC))
2299 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
2300 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
2301 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
2303 thr = sta_get_expected_throughput(sta);
2306 sinfo->filled |= BIT(NL80211_STA_INFO_EXPECTED_THROUGHPUT);
2307 sinfo->expected_throughput = thr;
2311 u32 sta_get_expected_throughput(struct sta_info *sta)
2313 struct ieee80211_sub_if_data *sdata = sta->sdata;
2314 struct ieee80211_local *local = sdata->local;
2315 struct rate_control_ref *ref = NULL;
2318 if (test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
2319 ref = local->rate_ctrl;
2321 /* check if the driver has a SW RC implementation */
2322 if (ref && ref->ops->get_expected_throughput)
2323 thr = ref->ops->get_expected_throughput(sta->rate_ctrl_priv);
2325 thr = drv_get_expected_throughput(local, sta);
2330 unsigned long ieee80211_sta_last_active(struct sta_info *sta)
2332 struct ieee80211_sta_rx_stats *stats = sta_get_last_rx_stats(sta);
2334 if (!sta->status_stats.last_ack ||
2335 time_after(stats->last_rx, sta->status_stats.last_ack))
2336 return stats->last_rx;
2337 return sta->status_stats.last_ack;