blob: 81cc499fa4a90f44c66896bc418c00318139b149 [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
Johannes Bergd98ad832014-09-03 15:24:57 +03004 * Copyright 2013-2014 Intel Mobile Communications GmbH
Jiri Bencf0706e82007-05-05 11:45:53 -07005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/module.h>
12#include <linux/init.h>
Felix Fietkau888d04d2012-03-01 15:22:09 +010013#include <linux/etherdevice.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070014#include <linux/netdevice.h>
15#include <linux/types.h>
16#include <linux/slab.h>
17#include <linux/skbuff.h>
18#include <linux/if_arp.h>
Johannes Berg0d174402007-12-17 15:07:43 +010019#include <linux/timer.h>
Johannes Bergd0709a62008-02-25 16:27:46 +010020#include <linux/rtnetlink.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070021
22#include <net/mac80211.h>
23#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020024#include "driver-ops.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040025#include "rate.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070026#include "sta_info.h"
Jiri Bence9f207f2007-05-05 11:46:38 -070027#include "debugfs_sta.h"
Luis Carlos Coboee385852008-02-23 15:17:11 +010028#include "mesh.h"
Johannes Bergce662b442011-09-29 16:04:34 +020029#include "wme.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070030
Johannes Bergd0709a62008-02-25 16:27:46 +010031/**
32 * DOC: STA information lifetime rules
33 *
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.
37 *
Johannes Berg34e89502010-02-03 13:59:58 +010038 * 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
45 * encryption keys.
Johannes Berg93e5deb2008-04-01 15:21:00 +020046 *
47 * When the insertion fails (sta_info_insert()) returns non-zero), the
48 * structure will have been freed by sta_info_insert()!
Johannes Bergd0709a62008-02-25 16:27:46 +010049 *
Johannes Berg34e89502010-02-03 13:59:58 +010050 * Station entries are added by mac80211 when you establish a link with a
Luis R. Rodriguez7e189a12009-06-02 18:38:14 -040051 * 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
Lucas De Marchi25985ed2011-03-30 22:57:33 -030053 * receive an association response from the AP. For IBSS this occurs when
Johannes Berg34e89502010-02-03 13:59:58 +010054 * get to know about a peer on the same IBSS. For WDS we add the sta for
Lucas De Marchi25985ed2011-03-30 22:57:33 -030055 * the peer immediately upon device open. When using AP mode we add stations
Johannes Berg34e89502010-02-03 13:59:58 +010056 * for each respective station upon request from userspace through nl80211.
Luis R. Rodriguez7e189a12009-06-02 18:38:14 -040057 *
Johannes Berg34e89502010-02-03 13:59:58 +010058 * In order to remove a STA info structure, various sta_info_destroy_*()
59 * calls are available.
Johannes Bergd0709a62008-02-25 16:27:46 +010060 *
Johannes Berg34e89502010-02-03 13:59:58 +010061 * 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.
Johannes Bergd0709a62008-02-25 16:27:46 +010065 */
Jiri Bencf0706e82007-05-05 11:45:53 -070066
Johannes Berg7bedd0c2015-02-13 21:55:15 +010067static const struct rhashtable_params sta_rht_params = {
68 .nelem_hint = 3, /* start small */
69 .head_offset = offsetof(struct sta_info, hash_node),
70 .key_offset = offsetof(struct sta_info, sta.addr),
71 .key_len = ETH_ALEN,
72 .hashfn = sta_addr_hash,
73};
74
Johannes Berg4d339602011-12-15 11:24:20 +010075/* Caller must hold local->sta_mtx */
Michael Wube8755e2007-07-27 15:43:23 +020076static int sta_info_hash_del(struct ieee80211_local *local,
77 struct sta_info *sta)
Jiri Bencf0706e82007-05-05 11:45:53 -070078{
Johannes Berg7bedd0c2015-02-13 21:55:15 +010079 return rhashtable_remove_fast(&local->sta_hash, &sta->hash_node,
80 sta_rht_params);
Jiri Bencf0706e82007-05-05 11:45:53 -070081}
82
Johannes Berg5108ca82014-02-17 20:49:03 +010083static void __cleanup_single_sta(struct sta_info *sta)
Eliad Pellerb22cfcf2012-09-09 14:43:51 +030084{
Eliad Pellerb22cfcf2012-09-09 14:43:51 +030085 int ac, i;
86 struct tid_ampdu_tx *tid_tx;
87 struct ieee80211_sub_if_data *sdata = sta->sdata;
88 struct ieee80211_local *local = sdata->local;
Marco Porschd012a602012-10-10 12:39:50 -070089 struct ps_data *ps;
Eliad Pellerb22cfcf2012-09-09 14:43:51 +030090
Johannes Berge3685e02014-02-20 11:19:58 +010091 if (test_sta_flag(sta, WLAN_STA_PS_STA) ||
Johannes Berg5ac2e352014-05-27 16:32:27 +020092 test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
93 test_sta_flag(sta, WLAN_STA_PS_DELIVER)) {
Marco Porschd012a602012-10-10 12:39:50 -070094 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
95 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
96 ps = &sdata->bss->ps;
Marco Porsch3f52b7e2013-01-30 18:14:08 +010097 else if (ieee80211_vif_is_mesh(&sdata->vif))
98 ps = &sdata->u.mesh.ps;
Marco Porschd012a602012-10-10 12:39:50 -070099 else
100 return;
Eliad Pellerb22cfcf2012-09-09 14:43:51 +0300101
102 clear_sta_flag(sta, WLAN_STA_PS_STA);
Johannes Berge3685e02014-02-20 11:19:58 +0100103 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
Johannes Berg5ac2e352014-05-27 16:32:27 +0200104 clear_sta_flag(sta, WLAN_STA_PS_DELIVER);
Eliad Pellerb22cfcf2012-09-09 14:43:51 +0300105
Marco Porschd012a602012-10-10 12:39:50 -0700106 atomic_dec(&ps->num_sta_ps);
Eliad Pellerb22cfcf2012-09-09 14:43:51 +0300107 }
108
109 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
110 local->total_ps_buffered -= skb_queue_len(&sta->ps_tx_buf[ac]);
Felix Fietkau1f98ab72012-11-10 03:44:14 +0100111 ieee80211_purge_tx_queue(&local->hw, &sta->ps_tx_buf[ac]);
112 ieee80211_purge_tx_queue(&local->hw, &sta->tx_filtered[ac]);
Eliad Pellerb22cfcf2012-09-09 14:43:51 +0300113 }
114
Thomas Pedersen45b50282013-02-06 10:17:21 -0800115 if (ieee80211_vif_is_mesh(&sdata->vif))
116 mesh_sta_cleanup(sta);
Eliad Pellerb22cfcf2012-09-09 14:43:51 +0300117
Johannes Berg5ac2e352014-05-27 16:32:27 +0200118 cancel_work_sync(&sta->drv_deliver_wk);
Eliad Pellerb22cfcf2012-09-09 14:43:51 +0300119
120 /*
121 * Destroy aggregation state here. It would be nice to wait for the
122 * driver to finish aggregation stop and then clean up, but for now
123 * drivers have to handle aggregation stop being requested, followed
124 * directly by station destruction.
125 */
Johannes Berg5a306f52012-11-14 23:22:21 +0100126 for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
Johannes Berg661eb382013-06-12 22:47:56 +0200127 kfree(sta->ampdu_mlme.tid_start_tx[i]);
Eliad Pellerb22cfcf2012-09-09 14:43:51 +0300128 tid_tx = rcu_dereference_raw(sta->ampdu_mlme.tid_tx[i]);
129 if (!tid_tx)
130 continue;
Felix Fietkau1f98ab72012-11-10 03:44:14 +0100131 ieee80211_purge_tx_queue(&local->hw, &tid_tx->pending);
Eliad Pellerb22cfcf2012-09-09 14:43:51 +0300132 kfree(tid_tx);
133 }
Johannes Berg5108ca82014-02-17 20:49:03 +0100134}
Eliad Pellerb22cfcf2012-09-09 14:43:51 +0300135
Johannes Berg5108ca82014-02-17 20:49:03 +0100136static void cleanup_single_sta(struct sta_info *sta)
137{
138 struct ieee80211_sub_if_data *sdata = sta->sdata;
139 struct ieee80211_local *local = sdata->local;
140
141 __cleanup_single_sta(sta);
Eliad Pellerb22cfcf2012-09-09 14:43:51 +0300142 sta_info_free(local, sta);
143}
144
Johannes Bergd0709a62008-02-25 16:27:46 +0100145/* protected by RCU */
Johannes Bergabe60632009-11-25 17:46:18 +0100146struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata,
147 const u8 *addr)
Johannes Berg43ba7e92008-02-21 14:09:30 +0100148{
Johannes Bergabe60632009-11-25 17:46:18 +0100149 struct ieee80211_local *local = sdata->local;
Johannes Berg43ba7e92008-02-21 14:09:30 +0100150
Johannes Berg7bedd0c2015-02-13 21:55:15 +0100151 return rhashtable_lookup_fast(&local->sta_hash, addr, sta_rht_params);
Johannes Berg43ba7e92008-02-21 14:09:30 +0100152}
153
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100154/*
155 * Get sta info either from the specified interface
156 * or from one of its vlans
157 */
158struct sta_info *sta_info_get_bss(struct ieee80211_sub_if_data *sdata,
159 const u8 *addr)
160{
161 struct ieee80211_local *local = sdata->local;
162 struct sta_info *sta;
Johannes Berg7bedd0c2015-02-13 21:55:15 +0100163 struct rhash_head *tmp;
164 const struct bucket_table *tbl;
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100165
Johannes Berg7bedd0c2015-02-13 21:55:15 +0100166 rcu_read_lock();
167 tbl = rht_dereference_rcu(local->sta_hash.tbl, &local->sta_hash);
168
169 for_each_sta_info(local, tbl, addr, sta, tmp) {
170 if (sta->sdata == sdata ||
171 (sta->sdata->bss && sta->sdata->bss == sdata->bss)) {
172 rcu_read_unlock();
173 /* this is safe as the caller must already hold
174 * another rcu read section or the mutex
175 */
176 return sta;
177 }
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100178 }
Johannes Berg7bedd0c2015-02-13 21:55:15 +0100179 rcu_read_unlock();
180 return NULL;
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100181}
182
Johannes Berg3b53fde82009-11-16 12:00:37 +0100183struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata,
184 int idx)
Luis Carlos Coboee385852008-02-23 15:17:11 +0100185{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100186 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100187 struct sta_info *sta;
188 int i = 0;
189
Johannes Bergd0709a62008-02-25 16:27:46 +0100190 list_for_each_entry_rcu(sta, &local->sta_list, list) {
Johannes Berg3b53fde82009-11-16 12:00:37 +0100191 if (sdata != sta->sdata)
Luis Carlos Cobo2a8ca292008-02-29 17:51:25 -0800192 continue;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100193 if (i < idx) {
194 ++i;
195 continue;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100196 }
Luis Carlos Cobo2a8ca292008-02-29 17:51:25 -0800197 return sta;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100198 }
Luis Carlos Coboee385852008-02-23 15:17:11 +0100199
200 return NULL;
201}
Jiri Bencf0706e82007-05-05 11:45:53 -0700202
Johannes Berg93e5deb2008-04-01 15:21:00 +0200203/**
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100204 * sta_info_free - free STA
Johannes Berg93e5deb2008-04-01 15:21:00 +0200205 *
Randy Dunlap6ef307b2008-07-03 13:52:18 -0700206 * @local: pointer to the global information
Johannes Berg93e5deb2008-04-01 15:21:00 +0200207 * @sta: STA info to free
208 *
209 * This function must undo everything done by sta_info_alloc()
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100210 * that may happen before sta_info_insert(). It may only be
211 * called when sta_info_insert() has not been attempted (and
212 * if that fails, the station is freed anyway.)
Johannes Berg93e5deb2008-04-01 15:21:00 +0200213 */
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100214void sta_info_free(struct ieee80211_local *local, struct sta_info *sta)
Johannes Berg93e5deb2008-04-01 15:21:00 +0200215{
Johannes Berg889cbb92012-01-17 10:33:29 +0100216 if (sta->rate_ctrl)
Johannes Bergaf65cd962009-11-17 18:18:36 +0100217 rate_control_free_sta(sta);
Johannes Berg93e5deb2008-04-01 15:21:00 +0200218
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200219 sta_dbg(sta->sdata, "Destroyed STA %pM\n", sta->sta.addr);
Johannes Berg93e5deb2008-04-01 15:21:00 +0200220
Felix Fietkau53d04522014-05-27 22:33:57 +0200221 kfree(rcu_dereference_raw(sta->sta.rates));
Johannes Berg93e5deb2008-04-01 15:21:00 +0200222 kfree(sta);
223}
224
Johannes Berg4d339602011-12-15 11:24:20 +0100225/* Caller must hold local->sta_mtx */
Johannes Bergd0709a62008-02-25 16:27:46 +0100226static void sta_info_hash_add(struct ieee80211_local *local,
227 struct sta_info *sta)
Jiri Bencf0706e82007-05-05 11:45:53 -0700228{
Johannes Berg7bedd0c2015-02-13 21:55:15 +0100229 rhashtable_insert_fast(&local->sta_hash, &sta->hash_node,
230 sta_rht_params);
Jiri Bencf0706e82007-05-05 11:45:53 -0700231}
Jiri Bencf0706e82007-05-05 11:45:53 -0700232
Johannes Berg5ac2e352014-05-27 16:32:27 +0200233static void sta_deliver_ps_frames(struct work_struct *wk)
Johannes Bergaf818582009-11-06 11:35:50 +0100234{
235 struct sta_info *sta;
236
Johannes Berg5ac2e352014-05-27 16:32:27 +0200237 sta = container_of(wk, struct sta_info, drv_deliver_wk);
Johannes Bergaf818582009-11-06 11:35:50 +0100238
239 if (sta->dead)
240 return;
241
Johannes Berg5ac2e352014-05-27 16:32:27 +0200242 local_bh_disable();
243 if (!test_sta_flag(sta, WLAN_STA_PS_STA))
Johannes Bergaf818582009-11-06 11:35:50 +0100244 ieee80211_sta_ps_deliver_wakeup(sta);
Johannes Berg5ac2e352014-05-27 16:32:27 +0200245 else if (test_and_clear_sta_flag(sta, WLAN_STA_PSPOLL))
Johannes Bergaf818582009-11-06 11:35:50 +0100246 ieee80211_sta_ps_deliver_poll_response(sta);
Johannes Berg5ac2e352014-05-27 16:32:27 +0200247 else if (test_and_clear_sta_flag(sta, WLAN_STA_UAPSD))
Johannes Berg47086fc2011-09-29 16:04:33 +0200248 ieee80211_sta_ps_deliver_uapsd(sta);
Johannes Berg5ac2e352014-05-27 16:32:27 +0200249 local_bh_enable();
Johannes Bergaf818582009-11-06 11:35:50 +0100250}
251
Johannes Bergaf65cd962009-11-17 18:18:36 +0100252static int sta_prepare_rate_control(struct ieee80211_local *local,
253 struct sta_info *sta, gfp_t gfp)
254{
255 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
256 return 0;
257
Johannes Berg889cbb92012-01-17 10:33:29 +0100258 sta->rate_ctrl = local->rate_ctrl;
Johannes Bergaf65cd962009-11-17 18:18:36 +0100259 sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl,
260 &sta->sta, gfp);
Johannes Berg889cbb92012-01-17 10:33:29 +0100261 if (!sta->rate_ctrl_priv)
Johannes Bergaf65cd962009-11-17 18:18:36 +0100262 return -ENOMEM;
Johannes Bergaf65cd962009-11-17 18:18:36 +0100263
264 return 0;
265}
266
Johannes Berg73651ee2008-02-25 16:27:47 +0100267struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
Johannes Berg56544162011-12-14 13:28:46 +0100268 const u8 *addr, gfp_t gfp)
Jiri Bencf0706e82007-05-05 11:45:53 -0700269{
Johannes Bergd0709a62008-02-25 16:27:46 +0100270 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -0700271 struct sta_info *sta;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530272 struct timespec uptime;
Ron Rindjunsky16c5f152007-12-25 17:00:34 +0200273 int i;
Jiri Bencf0706e82007-05-05 11:45:53 -0700274
Johannes Berg17741cd2008-09-11 00:02:02 +0200275 sta = kzalloc(sizeof(*sta) + local->hw.sta_data_size, gfp);
Jiri Bencf0706e82007-05-05 11:45:53 -0700276 if (!sta)
Johannes Berg73651ee2008-02-25 16:27:47 +0100277 return NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700278
Johannes Berg07346f812008-05-03 01:02:02 +0200279 spin_lock_init(&sta->lock);
Emmanuel Grumbach1d147bf2014-02-20 09:22:11 +0200280 spin_lock_init(&sta->ps_lock);
Johannes Berg5ac2e352014-05-27 16:32:27 +0200281 INIT_WORK(&sta->drv_deliver_wk, sta_deliver_ps_frames);
Johannes Berg67c282c2010-06-10 10:21:43 +0200282 INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work);
Johannes Berga93e3642010-06-10 10:21:46 +0200283 mutex_init(&sta->ampdu_mlme.mtx);
Thomas Pedersen87f59c72013-03-01 22:02:52 -0800284#ifdef CONFIG_MAC80211_MESH
285 if (ieee80211_vif_is_mesh(&sdata->vif) &&
286 !sdata->u.mesh.user_mpm)
287 init_timer(&sta->plink_timer);
Thomas Pedersen6c7c4cb2013-06-20 23:50:59 -0700288 sta->nonpeer_pm = NL80211_MESH_POWER_ACTIVE;
Thomas Pedersen87f59c72013-03-01 22:02:52 -0800289#endif
Johannes Berg07346f812008-05-03 01:02:02 +0200290
Johannes Berg17741cd2008-09-11 00:02:02 +0200291 memcpy(sta->sta.addr, addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100292 sta->local = local;
293 sta->sdata = sdata;
Felix Fietkau8bc8aec2011-03-21 20:01:00 +0100294 sta->last_rx = jiffies;
Jiri Bencf0706e82007-05-05 11:45:53 -0700295
Johannes Berg71ec3752012-01-20 13:55:20 +0100296 sta->sta_state = IEEE80211_STA_NONE;
297
Liad Kaufmanb6da9112014-11-19 13:47:38 +0200298 /* Mark TID as unreserved */
299 sta->reserved_tid = IEEE80211_TID_UNRESERVED;
300
Thomas Gleixner18171522014-06-11 23:59:14 +0000301 ktime_get_ts(&uptime);
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530302 sta->last_connected = uptime.tv_sec;
Bruno Randolf541a45a2010-12-02 19:12:43 +0900303 ewma_init(&sta->avg_signal, 1024, 8);
Felix Fietkauef0621e2013-04-22 16:29:31 +0200304 for (i = 0; i < ARRAY_SIZE(sta->chain_signal_avg); i++)
305 ewma_init(&sta->chain_signal_avg[i], 1024, 8);
Bruno Randolf541a45a2010-12-02 19:12:43 +0900306
Johannes Bergabfbc3a2015-02-25 10:03:25 +0100307 if (sta_prepare_rate_control(local, sta, gfp)) {
308 kfree(sta);
309 return NULL;
310 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700311
Johannes Berg5a306f52012-11-14 23:22:21 +0100312 for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
Johannes Berga622ab72010-06-10 10:21:39 +0200313 /*
314 * timer_to_tid must be initialized with identity mapping
315 * to enable session_timer's data differentiation. See
316 * sta_rx_agg_session_timer_expired for usage.
317 */
Ron Rindjunsky16c5f152007-12-25 17:00:34 +0200318 sta->timer_to_tid[i] = i;
Ron Rindjunsky16c5f152007-12-25 17:00:34 +0200319 }
Johannes Berg948d8872011-09-29 16:04:29 +0200320 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
321 skb_queue_head_init(&sta->ps_tx_buf[i]);
322 skb_queue_head_init(&sta->tx_filtered[i]);
323 }
Johannes Berg73651ee2008-02-25 16:27:47 +0100324
Johannes Berg5a306f52012-11-14 23:22:21 +0100325 for (i = 0; i < IEEE80211_NUM_TIDS; i++)
Alexey Dobriyan4be929b2010-05-24 14:33:03 -0700326 sta->last_seq_ctrl[i] = cpu_to_le16(USHRT_MAX);
Senthil Balasubramaniancccaec92009-05-14 18:42:08 +0530327
Johannes Bergaf0ed692013-02-12 14:21:00 +0100328 sta->sta.smps_mode = IEEE80211_SMPS_OFF;
Emmanuel Grumbach687da132013-10-01 16:45:43 +0300329 if (sdata->vif.type == NL80211_IFTYPE_AP ||
330 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
331 struct ieee80211_supported_band *sband =
332 local->hw.wiphy->bands[ieee80211_get_sdata_band(sdata)];
333 u8 smps = (sband->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >>
334 IEEE80211_HT_CAP_SM_PS_SHIFT;
335 /*
336 * Assume that hostapd advertises our caps in the beacon and
337 * this is the known_smps_mode for a station that just assciated
338 */
339 switch (smps) {
340 case WLAN_HT_SMPS_CONTROL_DISABLED:
341 sta->known_smps_mode = IEEE80211_SMPS_OFF;
342 break;
343 case WLAN_HT_SMPS_CONTROL_STATIC:
344 sta->known_smps_mode = IEEE80211_SMPS_STATIC;
345 break;
346 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
347 sta->known_smps_mode = IEEE80211_SMPS_DYNAMIC;
348 break;
349 default:
350 WARN_ON(1);
351 }
352 }
Johannes Bergaf0ed692013-02-12 14:21:00 +0100353
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200354 sta_dbg(sdata, "Allocated STA %pM\n", sta->sta.addr);
Johannes Bergef04a292014-01-06 15:56:59 +0100355
Johannes Bergabfbc3a2015-02-25 10:03:25 +0100356 return sta;
Johannes Berg73651ee2008-02-25 16:27:47 +0100357}
358
Guy Eilam8c71df72011-08-17 15:18:14 +0300359static int sta_info_insert_check(struct sta_info *sta)
Johannes Berg34e89502010-02-03 13:59:58 +0100360{
Johannes Berg34e89502010-02-03 13:59:58 +0100361 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg34e89502010-02-03 13:59:58 +0100362
Johannes Berg03e44972008-02-27 09:56:40 +0100363 /*
364 * Can't be a WARN_ON because it can be triggered through a race:
365 * something inserts a STA (on one CPU) without holding the RTNL
366 * and another CPU turns off the net device.
367 */
Guy Eilam8c71df72011-08-17 15:18:14 +0300368 if (unlikely(!ieee80211_sdata_running(sdata)))
369 return -ENETDOWN;
Johannes Berg03e44972008-02-27 09:56:40 +0100370
Joe Perchesb203ca32012-05-08 18:56:52 +0000371 if (WARN_ON(ether_addr_equal(sta->sta.addr, sdata->vif.addr) ||
Guy Eilam8c71df72011-08-17 15:18:14 +0300372 is_multicast_ether_addr(sta->sta.addr)))
373 return -EINVAL;
374
375 return 0;
376}
377
Johannes Bergf09603a2012-01-20 13:55:21 +0100378static int sta_info_insert_drv_state(struct ieee80211_local *local,
379 struct ieee80211_sub_if_data *sdata,
380 struct sta_info *sta)
381{
382 enum ieee80211_sta_state state;
383 int err = 0;
384
385 for (state = IEEE80211_STA_NOTEXIST; state < sta->sta_state; state++) {
386 err = drv_sta_state(local, sdata, sta, state, state + 1);
387 if (err)
388 break;
389 }
390
391 if (!err) {
Johannes Berga4ec45a2012-01-20 13:55:22 +0100392 /*
393 * Drivers using legacy sta_add/sta_remove callbacks only
394 * get uploaded set to true after sta_add is called.
395 */
396 if (!local->ops->sta_add)
397 sta->uploaded = true;
Johannes Bergf09603a2012-01-20 13:55:21 +0100398 return 0;
399 }
400
401 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200402 sdata_info(sdata,
403 "failed to move IBSS STA %pM to state %d (%d) - keeping it anyway\n",
404 sta->sta.addr, state + 1, err);
Johannes Bergf09603a2012-01-20 13:55:21 +0100405 err = 0;
406 }
407
408 /* unwind on error */
409 for (; state > IEEE80211_STA_NOTEXIST; state--)
410 WARN_ON(drv_sta_state(local, sdata, sta, state, state - 1));
411
412 return err;
413}
414
Guy Eilam8c71df72011-08-17 15:18:14 +0300415/*
416 * should be called with sta_mtx locked
417 * this function replaces the mutex lock
418 * with a RCU lock
419 */
Johannes Berg4d339602011-12-15 11:24:20 +0100420static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU)
Guy Eilam8c71df72011-08-17 15:18:14 +0300421{
422 struct ieee80211_local *local = sta->local;
423 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg7852e362012-01-20 13:55:24 +0100424 struct station_info sinfo;
Guy Eilam8c71df72011-08-17 15:18:14 +0300425 int err = 0;
426
427 lockdep_assert_held(&local->sta_mtx);
Johannes Berg34e89502010-02-03 13:59:58 +0100428
Johannes Berg7852e362012-01-20 13:55:24 +0100429 /* check if STA exists already */
430 if (sta_info_get_bss(sdata, sta->sta.addr)) {
431 err = -EEXIST;
432 goto out_err;
Johannes Berg43ba7e92008-02-21 14:09:30 +0100433 }
Johannes Berg32bfd352007-12-19 01:31:26 +0100434
Johannes Berg7852e362012-01-20 13:55:24 +0100435 local->num_sta++;
436 local->sta_generation++;
437 smp_mb();
Johannes Berg4d339602011-12-15 11:24:20 +0100438
Johannes Berg5108ca82014-02-17 20:49:03 +0100439 /* simplify things and don't accept BA sessions yet */
440 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
441
Johannes Berg7852e362012-01-20 13:55:24 +0100442 /* make the station visible */
443 sta_info_hash_add(local, sta);
Johannes Berg4d339602011-12-15 11:24:20 +0100444
Arik Nemtsov2bad77482014-10-22 12:32:16 +0300445 list_add_tail_rcu(&sta->list, &local->sta_list);
Johannes Berg83d5cc02012-01-12 09:31:10 +0100446
Johannes Berg5108ca82014-02-17 20:49:03 +0100447 /* notify driver */
448 err = sta_info_insert_drv_state(local, sdata, sta);
449 if (err)
450 goto out_remove;
451
Johannes Berg7852e362012-01-20 13:55:24 +0100452 set_sta_flag(sta, WLAN_STA_INSERTED);
Johannes Berg5108ca82014-02-17 20:49:03 +0100453 /* accept BA sessions now */
454 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
Johannes Berg4d339602011-12-15 11:24:20 +0100455
Eliad Peller21f659b2013-11-11 20:14:01 +0200456 ieee80211_recalc_min_chandef(sdata);
Johannes Berg7852e362012-01-20 13:55:24 +0100457 ieee80211_sta_debugfs_add(sta);
458 rate_control_add_sta_debugfs(sta);
Johannes Berg4d339602011-12-15 11:24:20 +0100459
Johannes Berg7852e362012-01-20 13:55:24 +0100460 memset(&sinfo, 0, sizeof(sinfo));
461 sinfo.filled = 0;
462 sinfo.generation = local->sta_generation;
463 cfg80211_new_sta(sdata->dev, sta->sta.addr, &sinfo, GFP_KERNEL);
Johannes Bergd0709a62008-02-25 16:27:46 +0100464
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200465 sta_dbg(sdata, "Inserted STA %pM\n", sta->sta.addr);
Jiri Bencf0706e82007-05-05 11:45:53 -0700466
Johannes Berg34e89502010-02-03 13:59:58 +0100467 /* move reference to rcu-protected */
468 rcu_read_lock();
469 mutex_unlock(&local->sta_mtx);
Jiri Bence9f207f2007-05-05 11:46:38 -0700470
Johannes Berg73651ee2008-02-25 16:27:47 +0100471 if (ieee80211_vif_is_mesh(&sdata->vif))
472 mesh_accept_plinks_update(sdata);
473
474 return 0;
Johannes Berg5108ca82014-02-17 20:49:03 +0100475 out_remove:
476 sta_info_hash_del(local, sta);
477 list_del_rcu(&sta->list);
478 local->num_sta--;
479 synchronize_net();
480 __cleanup_single_sta(sta);
Johannes Berg4d339602011-12-15 11:24:20 +0100481 out_err:
482 mutex_unlock(&local->sta_mtx);
483 rcu_read_lock();
484 return err;
Guy Eilam8c71df72011-08-17 15:18:14 +0300485}
486
487int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU)
488{
489 struct ieee80211_local *local = sta->local;
Zhao, Gang308f7fc2014-04-21 12:53:00 +0800490 int err;
Guy Eilam8c71df72011-08-17 15:18:14 +0300491
Johannes Berg4d339602011-12-15 11:24:20 +0100492 might_sleep();
493
Guy Eilam8c71df72011-08-17 15:18:14 +0300494 err = sta_info_insert_check(sta);
495 if (err) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700496 rcu_read_lock();
497 goto out_free;
498 }
499
Johannes Berg004c8722008-02-20 11:21:35 +0100500 mutex_lock(&local->sta_mtx);
501
Johannes Berg4d339602011-12-15 11:24:20 +0100502 err = sta_info_insert_finish(sta);
Guy Eilam8c71df72011-08-17 15:18:14 +0300503 if (err)
Johannes Berg004c8722008-02-20 11:21:35 +0100504 goto out_free;
Johannes Bergd0709a62008-02-25 16:27:46 +0100505
Johannes Berg004c8722008-02-20 11:21:35 +0100506 return 0;
Johannes Berg93e5deb2008-04-01 15:21:00 +0200507 out_free:
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100508 sta_info_free(local, sta);
Johannes Berg93e5deb2008-04-01 15:21:00 +0200509 return err;
Jiri Bencf0706e82007-05-05 11:45:53 -0700510}
511
Johannes Berg34e89502010-02-03 13:59:58 +0100512int sta_info_insert(struct sta_info *sta)
513{
514 int err = sta_info_insert_rcu(sta);
515
516 rcu_read_unlock();
517
518 return err;
519}
520
Marco Porschd012a602012-10-10 12:39:50 -0700521static inline void __bss_tim_set(u8 *tim, u16 id)
Johannes Berg004c8722008-02-20 11:21:35 +0100522{
523 /*
524 * This format has been mandated by the IEEE specifications,
525 * so this line may not be changed to use the __set_bit() format.
526 */
Marco Porschd012a602012-10-10 12:39:50 -0700527 tim[id / 8] |= (1 << (id % 8));
Johannes Berg004c8722008-02-20 11:21:35 +0100528}
529
Marco Porschd012a602012-10-10 12:39:50 -0700530static inline void __bss_tim_clear(u8 *tim, u16 id)
Johannes Berg004c8722008-02-20 11:21:35 +0100531{
532 /*
533 * This format has been mandated by the IEEE specifications,
534 * so this line may not be changed to use the __clear_bit() format.
535 */
Marco Porschd012a602012-10-10 12:39:50 -0700536 tim[id / 8] &= ~(1 << (id % 8));
Johannes Berg004c8722008-02-20 11:21:35 +0100537}
538
Ilan Peer3d5839b2013-03-05 15:27:20 +0200539static inline bool __bss_tim_get(u8 *tim, u16 id)
540{
541 /*
542 * This format has been mandated by the IEEE specifications,
543 * so this line may not be changed to use the test_bit() format.
544 */
545 return tim[id / 8] & (1 << (id % 8));
546}
547
Johannes Berg948d8872011-09-29 16:04:29 +0200548static unsigned long ieee80211_tids_for_ac(int ac)
Johannes Berg004c8722008-02-20 11:21:35 +0100549{
Johannes Berg948d8872011-09-29 16:04:29 +0200550 /* If we ever support TIDs > 7, this obviously needs to be adjusted */
551 switch (ac) {
552 case IEEE80211_AC_VO:
553 return BIT(6) | BIT(7);
554 case IEEE80211_AC_VI:
555 return BIT(4) | BIT(5);
556 case IEEE80211_AC_BE:
557 return BIT(0) | BIT(3);
558 case IEEE80211_AC_BK:
559 return BIT(1) | BIT(2);
560 default:
561 WARN_ON(1);
562 return 0;
Johannes Bergd0709a62008-02-25 16:27:46 +0100563 }
Johannes Berg004c8722008-02-20 11:21:35 +0100564}
565
Johannes Berg9b7a86f2015-01-09 11:40:39 +0100566static void __sta_info_recalc_tim(struct sta_info *sta, bool ignore_pending)
Johannes Berg004c8722008-02-20 11:21:35 +0100567{
Johannes Bergc868cb352011-09-29 16:04:27 +0200568 struct ieee80211_local *local = sta->local;
Marco Porschd012a602012-10-10 12:39:50 -0700569 struct ps_data *ps;
Johannes Berg948d8872011-09-29 16:04:29 +0200570 bool indicate_tim = false;
571 u8 ignore_for_tim = sta->sta.uapsd_queues;
572 int ac;
Marco Porschd012a602012-10-10 12:39:50 -0700573 u16 id;
Johannes Berg004c8722008-02-20 11:21:35 +0100574
Marco Porschd012a602012-10-10 12:39:50 -0700575 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
576 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
577 if (WARN_ON_ONCE(!sta->sdata->bss))
578 return;
579
580 ps = &sta->sdata->bss->ps;
581 id = sta->sta.aid;
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100582#ifdef CONFIG_MAC80211_MESH
583 } else if (ieee80211_vif_is_mesh(&sta->sdata->vif)) {
584 ps = &sta->sdata->u.mesh.ps;
Thomas Pedersen204d1302013-11-05 11:17:05 -0800585 /* TIM map only for 1 <= PLID <= IEEE80211_MAX_AID */
Chun-Yeow Yeoh6f101ef2013-11-13 15:43:03 +0800586 id = sta->plid % (IEEE80211_MAX_AID + 1);
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100587#endif
Marco Porschd012a602012-10-10 12:39:50 -0700588 } else {
Johannes Bergc868cb352011-09-29 16:04:27 +0200589 return;
Marco Porschd012a602012-10-10 12:39:50 -0700590 }
Johannes Berg3e122be2008-07-09 14:40:34 +0200591
Johannes Bergc868cb352011-09-29 16:04:27 +0200592 /* No need to do anything if the driver does all */
593 if (local->hw.flags & IEEE80211_HW_AP_LINK_PS)
594 return;
Johannes Berg004c8722008-02-20 11:21:35 +0100595
Johannes Bergc868cb352011-09-29 16:04:27 +0200596 if (sta->dead)
597 goto done;
Johannes Berg3e122be2008-07-09 14:40:34 +0200598
Johannes Berg948d8872011-09-29 16:04:29 +0200599 /*
600 * If all ACs are delivery-enabled then we should build
601 * the TIM bit for all ACs anyway; if only some are then
602 * we ignore those and build the TIM bit using only the
603 * non-enabled ones.
604 */
605 if (ignore_for_tim == BIT(IEEE80211_NUM_ACS) - 1)
606 ignore_for_tim = 0;
Johannes Berg3e122be2008-07-09 14:40:34 +0200607
Johannes Berg9b7a86f2015-01-09 11:40:39 +0100608 if (ignore_pending)
609 ignore_for_tim = BIT(IEEE80211_NUM_ACS) - 1;
610
Johannes Berg948d8872011-09-29 16:04:29 +0200611 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
612 unsigned long tids;
613
614 if (ignore_for_tim & BIT(ac))
615 continue;
616
617 indicate_tim |= !skb_queue_empty(&sta->tx_filtered[ac]) ||
618 !skb_queue_empty(&sta->ps_tx_buf[ac]);
619 if (indicate_tim)
620 break;
621
622 tids = ieee80211_tids_for_ac(ac);
623
624 indicate_tim |=
625 sta->driver_buffered_tids & tids;
Johannes Bergd0709a62008-02-25 16:27:46 +0100626 }
Johannes Berg004c8722008-02-20 11:21:35 +0100627
Johannes Bergc868cb352011-09-29 16:04:27 +0200628 done:
Johannes Berg65f704a2013-02-13 17:39:53 +0100629 spin_lock_bh(&local->tim_lock);
Johannes Berg004c8722008-02-20 11:21:35 +0100630
Ilan Peer3d5839b2013-03-05 15:27:20 +0200631 if (indicate_tim == __bss_tim_get(ps->tim, id))
632 goto out_unlock;
633
Johannes Berg948d8872011-09-29 16:04:29 +0200634 if (indicate_tim)
Marco Porschd012a602012-10-10 12:39:50 -0700635 __bss_tim_set(ps->tim, id);
Johannes Bergc868cb352011-09-29 16:04:27 +0200636 else
Marco Porschd012a602012-10-10 12:39:50 -0700637 __bss_tim_clear(ps->tim, id);
Johannes Berg3e122be2008-07-09 14:40:34 +0200638
Johannes Berg9b7a86f2015-01-09 11:40:39 +0100639 if (local->ops->set_tim && !WARN_ON(sta->dead)) {
Johannes Bergc868cb352011-09-29 16:04:27 +0200640 local->tim_in_locked_section = true;
Johannes Berg948d8872011-09-29 16:04:29 +0200641 drv_set_tim(local, &sta->sta, indicate_tim);
Johannes Bergc868cb352011-09-29 16:04:27 +0200642 local->tim_in_locked_section = false;
Johannes Berg004c8722008-02-20 11:21:35 +0100643 }
Johannes Berg004c8722008-02-20 11:21:35 +0100644
Ilan Peer3d5839b2013-03-05 15:27:20 +0200645out_unlock:
Johannes Berg65f704a2013-02-13 17:39:53 +0100646 spin_unlock_bh(&local->tim_lock);
Johannes Berg004c8722008-02-20 11:21:35 +0100647}
648
Johannes Berg9b7a86f2015-01-09 11:40:39 +0100649void sta_info_recalc_tim(struct sta_info *sta)
650{
651 __sta_info_recalc_tim(sta, false);
652}
653
Johannes Bergcd0b8d82011-09-06 14:13:06 +0200654static bool sta_info_buffer_expired(struct sta_info *sta, struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -0700655{
Johannes Berge039fa42008-05-15 12:55:29 +0200656 struct ieee80211_tx_info *info;
Jiri Bencf0706e82007-05-05 11:45:53 -0700657 int timeout;
658
659 if (!skb)
Johannes Bergcd0b8d82011-09-06 14:13:06 +0200660 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -0700661
Johannes Berge039fa42008-05-15 12:55:29 +0200662 info = IEEE80211_SKB_CB(skb);
Jiri Bencf0706e82007-05-05 11:45:53 -0700663
664 /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */
Johannes Berg57c4d7b2009-04-23 16:10:04 +0200665 timeout = (sta->listen_interval *
666 sta->sdata->vif.bss_conf.beacon_int *
667 32 / 15625) * HZ;
Jiri Bencf0706e82007-05-05 11:45:53 -0700668 if (timeout < STA_TX_BUFFER_EXPIRE)
669 timeout = STA_TX_BUFFER_EXPIRE;
Johannes Berge039fa42008-05-15 12:55:29 +0200670 return time_after(jiffies, info->control.jiffies + timeout);
Jiri Bencf0706e82007-05-05 11:45:53 -0700671}
672
673
Johannes Berg948d8872011-09-29 16:04:29 +0200674static bool sta_info_cleanup_expire_buffered_ac(struct ieee80211_local *local,
675 struct sta_info *sta, int ac)
Jiri Bencf0706e82007-05-05 11:45:53 -0700676{
677 unsigned long flags;
678 struct sk_buff *skb;
679
Johannes Berg60750392011-09-29 16:04:28 +0200680 /*
681 * First check for frames that should expire on the filtered
682 * queue. Frames here were rejected by the driver and are on
683 * a separate queue to avoid reordering with normal PS-buffered
684 * frames. They also aren't accounted for right now in the
685 * total_ps_buffered counter.
686 */
Jiri Bencf0706e82007-05-05 11:45:53 -0700687 for (;;) {
Johannes Berg948d8872011-09-29 16:04:29 +0200688 spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
689 skb = skb_peek(&sta->tx_filtered[ac]);
Johannes Berg57c4d7b2009-04-23 16:10:04 +0200690 if (sta_info_buffer_expired(sta, skb))
Johannes Berg948d8872011-09-29 16:04:29 +0200691 skb = __skb_dequeue(&sta->tx_filtered[ac]);
Johannes Berg836341a2008-02-20 02:07:21 +0100692 else
Jiri Bencf0706e82007-05-05 11:45:53 -0700693 skb = NULL;
Johannes Berg948d8872011-09-29 16:04:29 +0200694 spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
Jiri Bencf0706e82007-05-05 11:45:53 -0700695
Johannes Berg60750392011-09-29 16:04:28 +0200696 /*
697 * Frames are queued in order, so if this one
698 * hasn't expired yet we can stop testing. If
699 * we actually reached the end of the queue we
700 * also need to stop, of course.
701 */
702 if (!skb)
703 break;
Felix Fietkaud4fa14c2012-10-10 22:40:23 +0200704 ieee80211_free_txskb(&local->hw, skb);
Johannes Berg60750392011-09-29 16:04:28 +0200705 }
706
707 /*
708 * Now also check the normal PS-buffered queue, this will
709 * only find something if the filtered queue was emptied
710 * since the filtered frames are all before the normal PS
711 * buffered frames.
712 */
Jiri Bencf0706e82007-05-05 11:45:53 -0700713 for (;;) {
Johannes Berg948d8872011-09-29 16:04:29 +0200714 spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
715 skb = skb_peek(&sta->ps_tx_buf[ac]);
Jiri Bencf0706e82007-05-05 11:45:53 -0700716 if (sta_info_buffer_expired(sta, skb))
Johannes Berg948d8872011-09-29 16:04:29 +0200717 skb = __skb_dequeue(&sta->ps_tx_buf[ac]);
Jiri Bencf0706e82007-05-05 11:45:53 -0700718 else
719 skb = NULL;
Johannes Berg948d8872011-09-29 16:04:29 +0200720 spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
Jiri Bencf0706e82007-05-05 11:45:53 -0700721
Johannes Berg60750392011-09-29 16:04:28 +0200722 /*
723 * frames are queued in order, so if this one
724 * hasn't expired yet (or we reached the end of
725 * the queue) we can stop testing
726 */
Johannes Berg836341a2008-02-20 02:07:21 +0100727 if (!skb)
Jiri Bencf0706e82007-05-05 11:45:53 -0700728 break;
Johannes Berg836341a2008-02-20 02:07:21 +0100729
Johannes Berg836341a2008-02-20 02:07:21 +0100730 local->total_ps_buffered--;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200731 ps_dbg(sta->sdata, "Buffered frame expired (STA %pM)\n",
732 sta->sta.addr);
Felix Fietkaud4fa14c2012-10-10 22:40:23 +0200733 ieee80211_free_txskb(&local->hw, skb);
Jiri Bencf0706e82007-05-05 11:45:53 -0700734 }
Juuso Oikarinen3393a602010-04-19 10:12:52 +0300735
Johannes Berg60750392011-09-29 16:04:28 +0200736 /*
737 * Finally, recalculate the TIM bit for this station -- it might
738 * now be clear because the station was too slow to retrieve its
739 * frames.
740 */
741 sta_info_recalc_tim(sta);
742
743 /*
744 * Return whether there are any frames still buffered, this is
745 * used to check whether the cleanup timer still needs to run,
746 * if there are no frames we don't need to rearm the timer.
747 */
Johannes Berg948d8872011-09-29 16:04:29 +0200748 return !(skb_queue_empty(&sta->ps_tx_buf[ac]) &&
749 skb_queue_empty(&sta->tx_filtered[ac]));
750}
751
752static bool sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
753 struct sta_info *sta)
754{
755 bool have_buffered = false;
756 int ac;
757
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100758 /* This is only necessary for stations on BSS/MBSS interfaces */
759 if (!sta->sdata->bss &&
760 !ieee80211_vif_is_mesh(&sta->sdata->vif))
Johannes Berg948d8872011-09-29 16:04:29 +0200761 return false;
762
763 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
764 have_buffered |=
765 sta_info_cleanup_expire_buffered_ac(local, sta, ac);
766
767 return have_buffered;
Jiri Bencf0706e82007-05-05 11:45:53 -0700768}
769
Johannes Bergd7782072013-12-04 23:12:31 +0100770static int __must_check __sta_info_destroy_part1(struct sta_info *sta)
Johannes Berg34e89502010-02-03 13:59:58 +0100771{
772 struct ieee80211_local *local;
773 struct ieee80211_sub_if_data *sdata;
Johannes Berg6d10e462013-03-06 23:09:11 +0100774 int ret;
Johannes Berg34e89502010-02-03 13:59:58 +0100775
776 might_sleep();
777
778 if (!sta)
779 return -ENOENT;
780
781 local = sta->local;
782 sdata = sta->sdata;
783
Johannes Berg83d5cc02012-01-12 09:31:10 +0100784 lockdep_assert_held(&local->sta_mtx);
785
Johannes Berg098a6072010-04-06 11:18:47 +0200786 /*
787 * Before removing the station from the driver and
788 * rate control, it might still start new aggregation
789 * sessions -- block that to make sure the tear-down
790 * will be sufficient.
791 */
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200792 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
Johannes Bergc82c4a82012-07-18 13:31:31 +0200793 ieee80211_sta_tear_down_BA_sessions(sta, AGG_STOP_DESTROY_STA);
Johannes Berg098a6072010-04-06 11:18:47 +0200794
Johannes Berg34e89502010-02-03 13:59:58 +0100795 ret = sta_info_hash_del(local, sta);
Johannes Bergb01711b2013-12-04 20:25:27 +0100796 if (WARN_ON(ret))
Johannes Berg34e89502010-02-03 13:59:58 +0100797 return ret;
798
Arik Nemtsova7a6bdd2014-11-09 18:50:19 +0200799 /*
800 * for TDLS peers, make sure to return to the base channel before
801 * removal.
802 */
803 if (test_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL)) {
804 drv_tdls_cancel_channel_switch(local, sdata, &sta->sta);
805 clear_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL);
806 }
807
Arik Nemtsov794454c2012-06-03 23:32:32 +0300808 list_del_rcu(&sta->list);
Johannes Berg4d339602011-12-15 11:24:20 +0100809
Johannes Berg6a9d1b92013-12-04 22:39:17 +0100810 drv_sta_pre_rcu_remove(local, sta->sdata, sta);
811
Johannes Berga710c812013-12-04 20:11:06 +0100812 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
813 rcu_access_pointer(sdata->u.vlan.sta) == sta)
814 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
815
Johannes Bergd7782072013-12-04 23:12:31 +0100816 return 0;
817}
818
819static void __sta_info_destroy_part2(struct sta_info *sta)
820{
821 struct ieee80211_local *local = sta->local;
822 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg6f7a8d22014-11-14 20:32:57 +0100823 struct station_info sinfo = {};
Johannes Bergd7782072013-12-04 23:12:31 +0100824 int ret;
825
826 /*
827 * NOTE: This assumes at least synchronize_net() was done
828 * after _part1 and before _part2!
829 */
830
831 might_sleep();
832 lockdep_assert_held(&local->sta_mtx);
833
Johannes Bergc8782072013-12-04 23:05:45 +0100834 /* now keys can no longer be reached */
Johannes Berg6d10e462013-03-06 23:09:11 +0100835 ieee80211_free_sta_keys(local, sta);
Johannes Berg34e89502010-02-03 13:59:58 +0100836
Johannes Berg9b7a86f2015-01-09 11:40:39 +0100837 /* disable TIM bit - last chance to tell driver */
838 __sta_info_recalc_tim(sta, true);
839
Johannes Berg34e89502010-02-03 13:59:58 +0100840 sta->dead = true;
841
Johannes Berg34e89502010-02-03 13:59:58 +0100842 local->num_sta--;
843 local->sta_generation++;
844
Johannes Berg83d5cc02012-01-12 09:31:10 +0100845 while (sta->sta_state > IEEE80211_STA_NONE) {
Johannes Bergf09603a2012-01-20 13:55:21 +0100846 ret = sta_info_move_state(sta, sta->sta_state - 1);
847 if (ret) {
Johannes Berg83d5cc02012-01-12 09:31:10 +0100848 WARN_ON_ONCE(1);
849 break;
850 }
851 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100852
Johannes Bergf09603a2012-01-20 13:55:21 +0100853 if (sta->uploaded) {
Johannes Bergf09603a2012-01-20 13:55:21 +0100854 ret = drv_sta_state(local, sdata, sta, IEEE80211_STA_NONE,
855 IEEE80211_STA_NOTEXIST);
856 WARN_ON_ONCE(ret != 0);
857 }
Johannes Berg34e89502010-02-03 13:59:58 +0100858
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200859 sta_dbg(sdata, "Removed STA %pM\n", sta->sta.addr);
860
Johannes Berg6f7a8d22014-11-14 20:32:57 +0100861 sta_set_sinfo(sta, &sinfo);
862 cfg80211_del_sta_sinfo(sdata->dev, sta->sta.addr, &sinfo, GFP_KERNEL);
Jouni Malinenec15e682011-03-23 15:29:52 +0200863
Johannes Berg34e89502010-02-03 13:59:58 +0100864 rate_control_remove_sta_debugfs(sta);
865 ieee80211_sta_debugfs_remove(sta);
Eliad Peller21f659b2013-11-11 20:14:01 +0200866 ieee80211_recalc_min_chandef(sdata);
Johannes Berg34e89502010-02-03 13:59:58 +0100867
Johannes Bergd34ba212013-12-04 22:46:11 +0100868 cleanup_single_sta(sta);
Johannes Bergd7782072013-12-04 23:12:31 +0100869}
870
871int __must_check __sta_info_destroy(struct sta_info *sta)
872{
873 int err = __sta_info_destroy_part1(sta);
874
875 if (err)
876 return err;
877
878 synchronize_net();
879
880 __sta_info_destroy_part2(sta);
Johannes Berg34e89502010-02-03 13:59:58 +0100881
882 return 0;
883}
884
885int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata, const u8 *addr)
886{
887 struct sta_info *sta;
888 int ret;
889
890 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg7852e362012-01-20 13:55:24 +0100891 sta = sta_info_get(sdata, addr);
Johannes Berg34e89502010-02-03 13:59:58 +0100892 ret = __sta_info_destroy(sta);
893 mutex_unlock(&sdata->local->sta_mtx);
894
895 return ret;
896}
897
898int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata,
899 const u8 *addr)
900{
901 struct sta_info *sta;
902 int ret;
903
904 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg7852e362012-01-20 13:55:24 +0100905 sta = sta_info_get_bss(sdata, addr);
Johannes Berg34e89502010-02-03 13:59:58 +0100906 ret = __sta_info_destroy(sta);
907 mutex_unlock(&sdata->local->sta_mtx);
908
909 return ret;
910}
Jiri Bencf0706e82007-05-05 11:45:53 -0700911
912static void sta_info_cleanup(unsigned long data)
913{
914 struct ieee80211_local *local = (struct ieee80211_local *) data;
915 struct sta_info *sta;
Juuso Oikarinen3393a602010-04-19 10:12:52 +0300916 bool timer_needed = false;
Jiri Bencf0706e82007-05-05 11:45:53 -0700917
Johannes Bergd0709a62008-02-25 16:27:46 +0100918 rcu_read_lock();
919 list_for_each_entry_rcu(sta, &local->sta_list, list)
Juuso Oikarinen3393a602010-04-19 10:12:52 +0300920 if (sta_info_cleanup_expire_buffered(local, sta))
921 timer_needed = true;
Johannes Bergd0709a62008-02-25 16:27:46 +0100922 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -0700923
Johannes Berg5bb644a2009-05-17 11:40:42 +0200924 if (local->quiescing)
925 return;
926
Juuso Oikarinen3393a602010-04-19 10:12:52 +0300927 if (!timer_needed)
928 return;
929
Johannes Berg26d59532011-04-01 13:52:48 +0200930 mod_timer(&local->sta_cleanup,
931 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL));
Jiri Bencf0706e82007-05-05 11:45:53 -0700932}
933
Johannes Berg7bedd0c2015-02-13 21:55:15 +0100934u32 sta_addr_hash(const void *key, u32 length, u32 seed)
Jiri Bencf0706e82007-05-05 11:45:53 -0700935{
Johannes Berg7bedd0c2015-02-13 21:55:15 +0100936 return jhash(key, ETH_ALEN, seed);
937}
938
939int sta_info_init(struct ieee80211_local *local)
940{
941 int err;
942
943 err = rhashtable_init(&local->sta_hash, &sta_rht_params);
944 if (err)
945 return err;
946
Johannes Berg4d339602011-12-15 11:24:20 +0100947 spin_lock_init(&local->tim_lock);
Johannes Berg34e89502010-02-03 13:59:58 +0100948 mutex_init(&local->sta_mtx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700949 INIT_LIST_HEAD(&local->sta_list);
Jiri Bencf0706e82007-05-05 11:45:53 -0700950
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -0800951 setup_timer(&local->sta_cleanup, sta_info_cleanup,
952 (unsigned long)local);
Johannes Berg7bedd0c2015-02-13 21:55:15 +0100953 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700954}
955
956void sta_info_stop(struct ieee80211_local *local)
957{
Johannes Berga56f9922012-12-13 23:08:52 +0100958 del_timer_sync(&local->sta_cleanup);
Johannes Berg7bedd0c2015-02-13 21:55:15 +0100959 rhashtable_destroy(&local->sta_hash);
Jiri Bencf0706e82007-05-05 11:45:53 -0700960}
961
Johannes Berg051007d2012-12-13 23:49:02 +0100962
Johannes Berge7162512013-12-04 23:18:37 +0100963int __sta_info_flush(struct ieee80211_sub_if_data *sdata, bool vlans)
Jiri Bencf0706e82007-05-05 11:45:53 -0700964{
Johannes Bergb998e8b2012-12-13 23:07:46 +0100965 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -0700966 struct sta_info *sta, *tmp;
Johannes Bergd7782072013-12-04 23:12:31 +0100967 LIST_HEAD(free_list);
Johannes Berg44213b52008-02-25 16:27:49 +0100968 int ret = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700969
Johannes Bergd0709a62008-02-25 16:27:46 +0100970 might_sleep();
971
Johannes Berge7162512013-12-04 23:18:37 +0100972 WARN_ON(vlans && sdata->vif.type != NL80211_IFTYPE_AP);
973 WARN_ON(vlans && !sdata->bss);
974
Johannes Berg34e89502010-02-03 13:59:58 +0100975 mutex_lock(&local->sta_mtx);
Johannes Berg34e89502010-02-03 13:59:58 +0100976 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
Johannes Berge7162512013-12-04 23:18:37 +0100977 if (sdata == sta->sdata ||
978 (vlans && sdata->bss == sta->sdata->bss)) {
Johannes Bergd7782072013-12-04 23:12:31 +0100979 if (!WARN_ON(__sta_info_destroy_part1(sta)))
980 list_add(&sta->free_list, &free_list);
Johannes Berg34316832012-02-25 21:40:46 +0100981 ret++;
982 }
Johannes Berg34e89502010-02-03 13:59:58 +0100983 }
Johannes Bergd7782072013-12-04 23:12:31 +0100984
985 if (!list_empty(&free_list)) {
986 synchronize_net();
987 list_for_each_entry_safe(sta, tmp, &free_list, free_list)
988 __sta_info_destroy_part2(sta);
989 }
Johannes Berg34e89502010-02-03 13:59:58 +0100990 mutex_unlock(&local->sta_mtx);
Johannes Berg44213b52008-02-25 16:27:49 +0100991
Johannes Berg051007d2012-12-13 23:49:02 +0100992 return ret;
993}
994
Johannes Berg24723d12008-09-11 00:01:46 +0200995void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
996 unsigned long exp_time)
997{
998 struct ieee80211_local *local = sdata->local;
999 struct sta_info *sta, *tmp;
Johannes Berg24723d12008-09-11 00:01:46 +02001000
Johannes Berg34e89502010-02-03 13:59:58 +01001001 mutex_lock(&local->sta_mtx);
Mohammed Shafi Shajakhane46a2cf2011-12-26 10:43:29 +05301002
1003 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
Marek Lindnerec2b7742011-12-20 23:16:52 +08001004 if (sdata != sta->sdata)
1005 continue;
1006
Johannes Berg24723d12008-09-11 00:01:46 +02001007 if (time_after(jiffies, sta->last_rx + exp_time)) {
Mohammed Shafi Shajakhaneea57d42012-10-08 21:33:47 +05301008 sta_dbg(sta->sdata, "expiring inactive STA %pM\n",
1009 sta->sta.addr);
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001010
1011 if (ieee80211_vif_is_mesh(&sdata->vif) &&
1012 test_sta_flag(sta, WLAN_STA_PS_STA))
1013 atomic_dec(&sdata->u.mesh.ps.num_sta_ps);
1014
Johannes Berg34e89502010-02-03 13:59:58 +01001015 WARN_ON(__sta_info_destroy(sta));
Johannes Berg24723d12008-09-11 00:01:46 +02001016 }
Mohammed Shafi Shajakhane46a2cf2011-12-26 10:43:29 +05301017 }
1018
Johannes Berg34e89502010-02-03 13:59:58 +01001019 mutex_unlock(&local->sta_mtx);
Johannes Berg24723d12008-09-11 00:01:46 +02001020}
Johannes Berg17741cd2008-09-11 00:02:02 +02001021
Ben Greear686b9cb2010-09-23 09:44:36 -07001022struct ieee80211_sta *ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw,
Johannes Berg7bedd0c2015-02-13 21:55:15 +01001023 const u8 *addr,
1024 const u8 *localaddr)
Johannes Berg17741cd2008-09-11 00:02:02 +02001025{
Johannes Berg7bedd0c2015-02-13 21:55:15 +01001026 struct ieee80211_local *local = hw_to_local(hw);
1027 struct sta_info *sta;
1028 struct rhash_head *tmp;
1029 const struct bucket_table *tbl;
1030
1031 tbl = rht_dereference_rcu(local->sta_hash.tbl, &local->sta_hash);
Johannes Berg17741cd2008-09-11 00:02:02 +02001032
Ben Greear686b9cb2010-09-23 09:44:36 -07001033 /*
1034 * Just return a random station if localaddr is NULL
1035 * ... first in list.
1036 */
Johannes Berg7bedd0c2015-02-13 21:55:15 +01001037 for_each_sta_info(local, tbl, addr, sta, tmp) {
Ben Greear686b9cb2010-09-23 09:44:36 -07001038 if (localaddr &&
Joe Perchesb203ca32012-05-08 18:56:52 +00001039 !ether_addr_equal(sta->sdata->vif.addr, localaddr))
Ben Greear686b9cb2010-09-23 09:44:36 -07001040 continue;
Johannes Bergf7c65592010-04-30 13:48:36 +02001041 if (!sta->uploaded)
1042 return NULL;
Johannes Bergabe60632009-11-25 17:46:18 +01001043 return &sta->sta;
Johannes Bergf7c65592010-04-30 13:48:36 +02001044 }
1045
Johannes Bergabe60632009-11-25 17:46:18 +01001046 return NULL;
Johannes Berg17741cd2008-09-11 00:02:02 +02001047}
Ben Greear686b9cb2010-09-23 09:44:36 -07001048EXPORT_SYMBOL_GPL(ieee80211_find_sta_by_ifaddr);
Johannes Berg5ed176e2009-11-04 14:42:28 +01001049
1050struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_vif *vif,
1051 const u8 *addr)
1052{
Johannes Bergf7c65592010-04-30 13:48:36 +02001053 struct sta_info *sta;
Johannes Berg5ed176e2009-11-04 14:42:28 +01001054
1055 if (!vif)
1056 return NULL;
1057
Johannes Bergf7c65592010-04-30 13:48:36 +02001058 sta = sta_info_get_bss(vif_to_sdata(vif), addr);
1059 if (!sta)
1060 return NULL;
Johannes Berg5ed176e2009-11-04 14:42:28 +01001061
Johannes Bergf7c65592010-04-30 13:48:36 +02001062 if (!sta->uploaded)
1063 return NULL;
1064
1065 return &sta->sta;
Johannes Berg5ed176e2009-11-04 14:42:28 +01001066}
Johannes Berg17741cd2008-09-11 00:02:02 +02001067EXPORT_SYMBOL(ieee80211_find_sta);
Johannes Bergaf818582009-11-06 11:35:50 +01001068
Johannes Berge3685e02014-02-20 11:19:58 +01001069/* powersave support code */
1070void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
Johannes Berg50a94322010-11-16 11:50:28 -08001071{
Helmut Schaa608383b2012-01-30 15:18:00 +01001072 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berge3685e02014-02-20 11:19:58 +01001073 struct ieee80211_local *local = sdata->local;
1074 struct sk_buff_head pending;
1075 int filtered = 0, buffered = 0, ac;
1076 unsigned long flags;
Marco Porschd012a602012-10-10 12:39:50 -07001077 struct ps_data *ps;
1078
Felix Fietkau3918edb2014-07-25 16:20:23 +02001079 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1080 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
1081 u.ap);
1082
1083 if (sdata->vif.type == NL80211_IFTYPE_AP)
Marco Porschd012a602012-10-10 12:39:50 -07001084 ps = &sdata->bss->ps;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001085 else if (ieee80211_vif_is_mesh(&sdata->vif))
1086 ps = &sdata->u.mesh.ps;
Marco Porschd012a602012-10-10 12:39:50 -07001087 else
1088 return;
Johannes Berg50a94322010-11-16 11:50:28 -08001089
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001090 clear_sta_flag(sta, WLAN_STA_SP);
Johannes Berg47086fc2011-09-29 16:04:33 +02001091
Johannes Berg5a306f52012-11-14 23:22:21 +01001092 BUILD_BUG_ON(BITS_TO_LONGS(IEEE80211_NUM_TIDS) > 1);
Johannes Berg948d8872011-09-29 16:04:29 +02001093 sta->driver_buffered_tids = 0;
1094
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001095 if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS))
1096 drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta);
Johannes Bergaf818582009-11-06 11:35:50 +01001097
Johannes Berg948d8872011-09-29 16:04:29 +02001098 skb_queue_head_init(&pending);
Johannes Bergaf818582009-11-06 11:35:50 +01001099
Emmanuel Grumbach1d147bf2014-02-20 09:22:11 +02001100 /* sync with ieee80211_tx_h_unicast_ps_buf */
1101 spin_lock(&sta->ps_lock);
Johannes Bergaf818582009-11-06 11:35:50 +01001102 /* Send all buffered frames to the station */
Johannes Berg948d8872011-09-29 16:04:29 +02001103 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1104 int count = skb_queue_len(&pending), tmp;
1105
Arik Nemtsov987c2852012-11-05 10:27:52 +02001106 spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
Johannes Berg948d8872011-09-29 16:04:29 +02001107 skb_queue_splice_tail_init(&sta->tx_filtered[ac], &pending);
Arik Nemtsov987c2852012-11-05 10:27:52 +02001108 spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
Johannes Berg948d8872011-09-29 16:04:29 +02001109 tmp = skb_queue_len(&pending);
1110 filtered += tmp - count;
1111 count = tmp;
1112
Arik Nemtsov987c2852012-11-05 10:27:52 +02001113 spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
Johannes Berg948d8872011-09-29 16:04:29 +02001114 skb_queue_splice_tail_init(&sta->ps_tx_buf[ac], &pending);
Arik Nemtsov987c2852012-11-05 10:27:52 +02001115 spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
Johannes Berg948d8872011-09-29 16:04:29 +02001116 tmp = skb_queue_len(&pending);
1117 buffered += tmp - count;
1118 }
1119
Johannes Berge3685e02014-02-20 11:19:58 +01001120 ieee80211_add_pending_skbs(local, &pending);
Johannes Berg5ac2e352014-05-27 16:32:27 +02001121
1122 /* now we're no longer in the deliver code */
1123 clear_sta_flag(sta, WLAN_STA_PS_DELIVER);
1124
1125 /* The station might have polled and then woken up before we responded,
1126 * so clear these flags now to avoid them sticking around.
1127 */
1128 clear_sta_flag(sta, WLAN_STA_PSPOLL);
1129 clear_sta_flag(sta, WLAN_STA_UAPSD);
Emmanuel Grumbach1d147bf2014-02-20 09:22:11 +02001130 spin_unlock(&sta->ps_lock);
Johannes Berg948d8872011-09-29 16:04:29 +02001131
Johannes Berge3685e02014-02-20 11:19:58 +01001132 atomic_dec(&ps->num_sta_ps);
1133
Emmanuel Grumbach687da132013-10-01 16:45:43 +03001134 /* This station just woke up and isn't aware of our SMPS state */
Chun-Yeow Yeoh062f1d62014-04-22 18:19:25 +08001135 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
1136 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
Emmanuel Grumbach687da132013-10-01 16:45:43 +03001137 sdata->smps_mode) &&
1138 sta->known_smps_mode != sdata->bss->req_smps &&
1139 sta_info_tx_streams(sta) != 1) {
1140 ht_dbg(sdata,
1141 "%pM just woke up and MIMO capable - update SMPS\n",
1142 sta->sta.addr);
1143 ieee80211_send_smps_action(sdata, sdata->bss->req_smps,
1144 sta->sta.addr,
1145 sdata->vif.bss_conf.bssid);
1146 }
1147
Johannes Bergaf818582009-11-06 11:35:50 +01001148 local->total_ps_buffered -= buffered;
1149
Johannes Bergc868cb352011-09-29 16:04:27 +02001150 sta_info_recalc_tim(sta);
1151
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001152 ps_dbg(sdata,
1153 "STA %pM aid %d sending %d filtered/%d PS frames since STA not sleeping anymore\n",
1154 sta->sta.addr, sta->sta.aid, filtered, buffered);
Johannes Bergaf818582009-11-06 11:35:50 +01001155}
1156
Johannes Bergce662b442011-09-29 16:04:34 +02001157static void ieee80211_send_null_response(struct ieee80211_sub_if_data *sdata,
1158 struct sta_info *sta, int tid,
Johannes Bergb77cf4f2014-01-09 00:00:38 +01001159 enum ieee80211_frame_release_type reason,
1160 bool call_driver)
Johannes Bergce662b442011-09-29 16:04:34 +02001161{
1162 struct ieee80211_local *local = sdata->local;
1163 struct ieee80211_qos_hdr *nullfunc;
1164 struct sk_buff *skb;
1165 int size = sizeof(*nullfunc);
1166 __le16 fc;
Johannes Berga74a8c82014-07-22 14:50:47 +02001167 bool qos = sta->sta.wme;
Johannes Bergce662b442011-09-29 16:04:34 +02001168 struct ieee80211_tx_info *info;
Johannes Berg55de9082012-07-26 17:24:39 +02001169 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Bergce662b442011-09-29 16:04:34 +02001170
1171 if (qos) {
1172 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
1173 IEEE80211_STYPE_QOS_NULLFUNC |
1174 IEEE80211_FCTL_FROMDS);
1175 } else {
1176 size -= 2;
1177 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
1178 IEEE80211_STYPE_NULLFUNC |
1179 IEEE80211_FCTL_FROMDS);
1180 }
1181
1182 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
1183 if (!skb)
1184 return;
1185
1186 skb_reserve(skb, local->hw.extra_tx_headroom);
1187
1188 nullfunc = (void *) skb_put(skb, size);
1189 nullfunc->frame_control = fc;
1190 nullfunc->duration_id = 0;
1191 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
1192 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1193 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
Johannes Berg864a6042014-03-04 13:46:53 +01001194 nullfunc->seq_ctrl = 0;
Johannes Bergce662b442011-09-29 16:04:34 +02001195
Johannes Berg59b66252011-10-13 13:19:19 +02001196 skb->priority = tid;
1197 skb_set_queue_mapping(skb, ieee802_1d_to_ac[tid]);
Johannes Bergce662b442011-09-29 16:04:34 +02001198 if (qos) {
Johannes Bergce662b442011-09-29 16:04:34 +02001199 nullfunc->qos_ctrl = cpu_to_le16(tid);
1200
Johannes Berg40b96402011-09-29 16:04:38 +02001201 if (reason == IEEE80211_FRAME_RELEASE_UAPSD)
Johannes Bergce662b442011-09-29 16:04:34 +02001202 nullfunc->qos_ctrl |=
1203 cpu_to_le16(IEEE80211_QOS_CTL_EOSP);
1204 }
1205
1206 info = IEEE80211_SKB_CB(skb);
1207
1208 /*
1209 * Tell TX path to send this frame even though the
1210 * STA may still remain is PS mode after this frame
Johannes Bergdeeaee12011-09-29 16:04:35 +02001211 * exchange. Also set EOSP to indicate this packet
1212 * ends the poll/service period.
Johannes Bergce662b442011-09-29 16:04:34 +02001213 */
Johannes Berg02f2f1a2012-02-27 12:18:30 +01001214 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER |
Johannes Bergdeeaee12011-09-29 16:04:35 +02001215 IEEE80211_TX_STATUS_EOSP |
1216 IEEE80211_TX_CTL_REQ_TX_STATUS;
Johannes Bergce662b442011-09-29 16:04:34 +02001217
Sujith Manoharan6b127c72014-12-10 21:26:10 +05301218 info->control.flags |= IEEE80211_TX_CTRL_PS_RESPONSE;
1219
Johannes Bergb77cf4f2014-01-09 00:00:38 +01001220 if (call_driver)
1221 drv_allow_buffered_frames(local, sta, BIT(tid), 1,
1222 reason, false);
Johannes Berg40b96402011-09-29 16:04:38 +02001223
Johannes Berg89afe612013-02-13 15:39:57 +01001224 skb->dev = sdata->dev;
1225
Johannes Berg55de9082012-07-26 17:24:39 +02001226 rcu_read_lock();
1227 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
1228 if (WARN_ON(!chanctx_conf)) {
1229 rcu_read_unlock();
1230 kfree_skb(skb);
1231 return;
1232 }
1233
Johannes Berg73c4e192014-11-09 18:50:09 +02001234 info->band = chanctx_conf->def.chan->band;
Johannes Berg7c107702015-03-20 14:18:27 +01001235 ieee80211_xmit(sdata, sta, skb);
Johannes Berg55de9082012-07-26 17:24:39 +02001236 rcu_read_unlock();
Johannes Bergce662b442011-09-29 16:04:34 +02001237}
1238
Johannes Berg0a1cb802014-01-09 11:05:31 +01001239static int find_highest_prio_tid(unsigned long tids)
1240{
1241 /* lower 3 TIDs aren't ordered perfectly */
1242 if (tids & 0xF8)
1243 return fls(tids) - 1;
1244 /* TID 0 is BE just like TID 3 */
1245 if (tids & BIT(0))
1246 return 0;
1247 return fls(tids) - 1;
1248}
1249
Johannes Berg47086fc2011-09-29 16:04:33 +02001250static void
1251ieee80211_sta_ps_deliver_response(struct sta_info *sta,
1252 int n_frames, u8 ignored_acs,
1253 enum ieee80211_frame_release_type reason)
Johannes Bergaf818582009-11-06 11:35:50 +01001254{
1255 struct ieee80211_sub_if_data *sdata = sta->sdata;
1256 struct ieee80211_local *local = sdata->local;
Johannes Berg948d8872011-09-29 16:04:29 +02001257 bool more_data = false;
1258 int ac;
Johannes Berg4049e092011-09-29 16:04:32 +02001259 unsigned long driver_release_tids = 0;
Johannes Berg47086fc2011-09-29 16:04:33 +02001260 struct sk_buff_head frames;
1261
Johannes Bergdeeaee12011-09-29 16:04:35 +02001262 /* Service or PS-Poll period starts */
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001263 set_sta_flag(sta, WLAN_STA_SP);
Johannes Bergdeeaee12011-09-29 16:04:35 +02001264
Johannes Berg47086fc2011-09-29 16:04:33 +02001265 __skb_queue_head_init(&frames);
Johannes Bergaf818582009-11-06 11:35:50 +01001266
Johannes Bergf9f760b2014-01-08 17:45:07 +01001267 /* Get response frame(s) and more data bit for the last one. */
Johannes Berg948d8872011-09-29 16:04:29 +02001268 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
Johannes Berg4049e092011-09-29 16:04:32 +02001269 unsigned long tids;
1270
Johannes Berg47086fc2011-09-29 16:04:33 +02001271 if (ignored_acs & BIT(ac))
Johannes Berg948d8872011-09-29 16:04:29 +02001272 continue;
1273
Johannes Berg4049e092011-09-29 16:04:32 +02001274 tids = ieee80211_tids_for_ac(ac);
1275
Johannes Bergf9f760b2014-01-08 17:45:07 +01001276 /* if we already have frames from software, then we can't also
1277 * release from hardware queues
1278 */
1279 if (skb_queue_empty(&frames))
1280 driver_release_tids |= sta->driver_buffered_tids & tids;
Johannes Berg47086fc2011-09-29 16:04:33 +02001281
Johannes Bergf9f760b2014-01-08 17:45:07 +01001282 if (driver_release_tids) {
1283 /* If the driver has data on more than one TID then
Johannes Berg4049e092011-09-29 16:04:32 +02001284 * certainly there's more data if we release just a
Johannes Bergf9f760b2014-01-08 17:45:07 +01001285 * single frame now (from a single TID). This will
1286 * only happen for PS-Poll.
Johannes Berg4049e092011-09-29 16:04:32 +02001287 */
Johannes Berg47086fc2011-09-29 16:04:33 +02001288 if (reason == IEEE80211_FRAME_RELEASE_PSPOLL &&
1289 hweight16(driver_release_tids) > 1) {
Johannes Berg4049e092011-09-29 16:04:32 +02001290 more_data = true;
1291 driver_release_tids =
Johannes Berg0a1cb802014-01-09 11:05:31 +01001292 BIT(find_highest_prio_tid(
1293 driver_release_tids));
Johannes Berg4049e092011-09-29 16:04:32 +02001294 break;
Johannes Berg948d8872011-09-29 16:04:29 +02001295 }
Johannes Bergf9f760b2014-01-08 17:45:07 +01001296 } else {
1297 struct sk_buff *skb;
1298
1299 while (n_frames > 0) {
1300 skb = skb_dequeue(&sta->tx_filtered[ac]);
1301 if (!skb) {
1302 skb = skb_dequeue(
1303 &sta->ps_tx_buf[ac]);
1304 if (skb)
1305 local->total_ps_buffered--;
1306 }
1307 if (!skb)
1308 break;
1309 n_frames--;
1310 __skb_queue_tail(&frames, skb);
1311 }
Johannes Berg948d8872011-09-29 16:04:29 +02001312 }
1313
Johannes Bergf9f760b2014-01-08 17:45:07 +01001314 /* If we have more frames buffered on this AC, then set the
1315 * more-data bit and abort the loop since we can't send more
1316 * data from other ACs before the buffered frames from this.
1317 */
Johannes Berg948d8872011-09-29 16:04:29 +02001318 if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
1319 !skb_queue_empty(&sta->ps_tx_buf[ac])) {
1320 more_data = true;
1321 break;
1322 }
Johannes Bergaf818582009-11-06 11:35:50 +01001323 }
Johannes Bergaf818582009-11-06 11:35:50 +01001324
Johannes Bergf9f760b2014-01-08 17:45:07 +01001325 if (skb_queue_empty(&frames) && !driver_release_tids) {
Johannes Bergce662b442011-09-29 16:04:34 +02001326 int tid;
Johannes Berg4049e092011-09-29 16:04:32 +02001327
Johannes Bergce662b442011-09-29 16:04:34 +02001328 /*
1329 * For PS-Poll, this can only happen due to a race condition
1330 * when we set the TIM bit and the station notices it, but
1331 * before it can poll for the frame we expire it.
1332 *
1333 * For uAPSD, this is said in the standard (11.2.1.5 h):
1334 * At each unscheduled SP for a non-AP STA, the AP shall
1335 * attempt to transmit at least one MSDU or MMPDU, but no
1336 * more than the value specified in the Max SP Length field
1337 * in the QoS Capability element from delivery-enabled ACs,
1338 * that are destined for the non-AP STA.
1339 *
1340 * Since we have no other MSDU/MMPDU, transmit a QoS null frame.
1341 */
1342
1343 /* This will evaluate to 1, 3, 5 or 7. */
1344 tid = 7 - ((ffs(~ignored_acs) - 1) << 1);
1345
Johannes Bergb77cf4f2014-01-09 00:00:38 +01001346 ieee80211_send_null_response(sdata, sta, tid, reason, true);
Johannes Bergf9f760b2014-01-08 17:45:07 +01001347 } else if (!driver_release_tids) {
Johannes Berg47086fc2011-09-29 16:04:33 +02001348 struct sk_buff_head pending;
1349 struct sk_buff *skb;
Johannes Berg40b96402011-09-29 16:04:38 +02001350 int num = 0;
1351 u16 tids = 0;
Johannes Bergb77cf4f2014-01-09 00:00:38 +01001352 bool need_null = false;
Johannes Bergaf818582009-11-06 11:35:50 +01001353
Johannes Berg47086fc2011-09-29 16:04:33 +02001354 skb_queue_head_init(&pending);
Johannes Bergaf818582009-11-06 11:35:50 +01001355
Johannes Berg47086fc2011-09-29 16:04:33 +02001356 while ((skb = __skb_dequeue(&frames))) {
1357 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1358 struct ieee80211_hdr *hdr = (void *) skb->data;
Johannes Berg40b96402011-09-29 16:04:38 +02001359 u8 *qoshdr = NULL;
1360
1361 num++;
Johannes Bergaf818582009-11-06 11:35:50 +01001362
Johannes Berg47086fc2011-09-29 16:04:33 +02001363 /*
1364 * Tell TX path to send this frame even though the
1365 * STA may still remain is PS mode after this frame
1366 * exchange.
1367 */
Sujith Manoharan6b127c72014-12-10 21:26:10 +05301368 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER;
1369 info->control.flags |= IEEE80211_TX_CTRL_PS_RESPONSE;
Johannes Bergaf818582009-11-06 11:35:50 +01001370
Johannes Berg47086fc2011-09-29 16:04:33 +02001371 /*
1372 * Use MoreData flag to indicate whether there are
1373 * more buffered frames for this STA
1374 */
Janusz.Dziedzic@tieto.com24b9c372011-11-07 09:47:47 +02001375 if (more_data || !skb_queue_empty(&frames))
Johannes Berg47086fc2011-09-29 16:04:33 +02001376 hdr->frame_control |=
1377 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
Janusz.Dziedzic@tieto.com24b9c372011-11-07 09:47:47 +02001378 else
1379 hdr->frame_control &=
1380 cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
Johannes Berg47086fc2011-09-29 16:04:33 +02001381
Johannes Berg40b96402011-09-29 16:04:38 +02001382 if (ieee80211_is_data_qos(hdr->frame_control) ||
1383 ieee80211_is_qos_nullfunc(hdr->frame_control))
1384 qoshdr = ieee80211_get_qos_ctl(hdr);
1385
Johannes Bergb77cf4f2014-01-09 00:00:38 +01001386 tids |= BIT(skb->priority);
1387
1388 __skb_queue_tail(&pending, skb);
1389
1390 /* end service period after last frame or add one */
1391 if (!skb_queue_empty(&frames))
1392 continue;
1393
1394 if (reason != IEEE80211_FRAME_RELEASE_UAPSD) {
1395 /* for PS-Poll, there's only one frame */
1396 info->flags |= IEEE80211_TX_STATUS_EOSP |
1397 IEEE80211_TX_CTL_REQ_TX_STATUS;
1398 break;
1399 }
1400
1401 /* For uAPSD, things are a bit more complicated. If the
1402 * last frame has a QoS header (i.e. is a QoS-data or
1403 * QoS-nulldata frame) then just set the EOSP bit there
1404 * and be done.
1405 * If the frame doesn't have a QoS header (which means
1406 * it should be a bufferable MMPDU) then we can't set
1407 * the EOSP bit in the QoS header; add a QoS-nulldata
1408 * frame to the list to send it after the MMPDU.
1409 *
1410 * Note that this code is only in the mac80211-release
1411 * code path, we assume that the driver will not buffer
1412 * anything but QoS-data frames, or if it does, will
1413 * create the QoS-nulldata frame by itself if needed.
1414 *
1415 * Cf. 802.11-2012 10.2.1.10 (c).
1416 */
1417 if (qoshdr) {
1418 *qoshdr |= IEEE80211_QOS_CTL_EOSP;
Johannes Berg47086fc2011-09-29 16:04:33 +02001419
Marco Porsch52a3f202012-03-16 15:30:26 +01001420 info->flags |= IEEE80211_TX_STATUS_EOSP |
1421 IEEE80211_TX_CTL_REQ_TX_STATUS;
Johannes Bergb77cf4f2014-01-09 00:00:38 +01001422 } else {
1423 /* The standard isn't completely clear on this
1424 * as it says the more-data bit should be set
1425 * if there are more BUs. The QoS-Null frame
1426 * we're about to send isn't buffered yet, we
1427 * only create it below, but let's pretend it
1428 * was buffered just in case some clients only
1429 * expect more-data=0 when eosp=1.
1430 */
1431 hdr->frame_control |=
1432 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
1433 need_null = true;
1434 num++;
Marco Porsch52a3f202012-03-16 15:30:26 +01001435 }
Johannes Bergb77cf4f2014-01-09 00:00:38 +01001436 break;
Johannes Berg47086fc2011-09-29 16:04:33 +02001437 }
1438
Johannes Berg40b96402011-09-29 16:04:38 +02001439 drv_allow_buffered_frames(local, sta, tids, num,
1440 reason, more_data);
1441
Johannes Berg47086fc2011-09-29 16:04:33 +02001442 ieee80211_add_pending_skbs(local, &pending);
Johannes Bergaf818582009-11-06 11:35:50 +01001443
Johannes Bergb77cf4f2014-01-09 00:00:38 +01001444 if (need_null)
1445 ieee80211_send_null_response(
1446 sdata, sta, find_highest_prio_tid(tids),
1447 reason, false);
1448
Johannes Bergc868cb352011-09-29 16:04:27 +02001449 sta_info_recalc_tim(sta);
Johannes Bergaf818582009-11-06 11:35:50 +01001450 } else {
1451 /*
Johannes Berg4049e092011-09-29 16:04:32 +02001452 * We need to release a frame that is buffered somewhere in the
1453 * driver ... it'll have to handle that.
Johannes Bergf9f760b2014-01-08 17:45:07 +01001454 * Note that the driver also has to check the number of frames
1455 * on the TIDs we're releasing from - if there are more than
1456 * n_frames it has to set the more-data bit (if we didn't ask
1457 * it to set it anyway due to other buffered frames); if there
1458 * are fewer than n_frames it has to make sure to adjust that
1459 * to allow the service period to end properly.
Johannes Bergaf818582009-11-06 11:35:50 +01001460 */
Johannes Berg4049e092011-09-29 16:04:32 +02001461 drv_release_buffered_frames(local, sta, driver_release_tids,
Johannes Berg47086fc2011-09-29 16:04:33 +02001462 n_frames, reason, more_data);
Johannes Berg4049e092011-09-29 16:04:32 +02001463
1464 /*
1465 * Note that we don't recalculate the TIM bit here as it would
1466 * most likely have no effect at all unless the driver told us
Johannes Bergf9f760b2014-01-08 17:45:07 +01001467 * that the TID(s) became empty before returning here from the
Johannes Berg4049e092011-09-29 16:04:32 +02001468 * release function.
Johannes Bergf9f760b2014-01-08 17:45:07 +01001469 * Either way, however, when the driver tells us that the TID(s)
Johannes Berg4049e092011-09-29 16:04:32 +02001470 * became empty we'll do the TIM recalculation.
1471 */
Johannes Bergaf818582009-11-06 11:35:50 +01001472 }
1473}
1474
Johannes Bergaf818582009-11-06 11:35:50 +01001475void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta)
1476{
Johannes Berg47086fc2011-09-29 16:04:33 +02001477 u8 ignore_for_response = sta->sta.uapsd_queues;
Johannes Bergaf818582009-11-06 11:35:50 +01001478
Johannes Berg47086fc2011-09-29 16:04:33 +02001479 /*
1480 * If all ACs are delivery-enabled then we should reply
1481 * from any of them, if only some are enabled we reply
1482 * only from the non-enabled ones.
1483 */
1484 if (ignore_for_response == BIT(IEEE80211_NUM_ACS) - 1)
1485 ignore_for_response = 0;
1486
1487 ieee80211_sta_ps_deliver_response(sta, 1, ignore_for_response,
1488 IEEE80211_FRAME_RELEASE_PSPOLL);
1489}
1490
1491void ieee80211_sta_ps_deliver_uapsd(struct sta_info *sta)
1492{
1493 int n_frames = sta->sta.max_sp;
1494 u8 delivery_enabled = sta->sta.uapsd_queues;
1495
1496 /*
1497 * If we ever grow support for TSPEC this might happen if
1498 * the TSPEC update from hostapd comes in between a trigger
1499 * frame setting WLAN_STA_UAPSD in the RX path and this
1500 * actually getting called.
1501 */
1502 if (!delivery_enabled)
1503 return;
1504
Johannes Berg47086fc2011-09-29 16:04:33 +02001505 switch (sta->sta.max_sp) {
1506 case 1:
1507 n_frames = 2;
1508 break;
1509 case 2:
1510 n_frames = 4;
1511 break;
1512 case 3:
1513 n_frames = 6;
1514 break;
1515 case 0:
1516 /* XXX: what is a good value? */
Andrei Otcheretianski13a80982014-11-04 11:33:04 +02001517 n_frames = 128;
Johannes Berg47086fc2011-09-29 16:04:33 +02001518 break;
Johannes Bergaf818582009-11-06 11:35:50 +01001519 }
Johannes Bergaf818582009-11-06 11:35:50 +01001520
Johannes Berg47086fc2011-09-29 16:04:33 +02001521 ieee80211_sta_ps_deliver_response(sta, n_frames, ~delivery_enabled,
1522 IEEE80211_FRAME_RELEASE_UAPSD);
Johannes Bergaf818582009-11-06 11:35:50 +01001523}
1524
1525void ieee80211_sta_block_awake(struct ieee80211_hw *hw,
1526 struct ieee80211_sta *pubsta, bool block)
1527{
1528 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1529
Johannes Bergb5878a22010-04-07 16:48:40 +02001530 trace_api_sta_block_awake(sta->local, pubsta, block);
1531
Johannes Berg5ac2e352014-05-27 16:32:27 +02001532 if (block) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001533 set_sta_flag(sta, WLAN_STA_PS_DRIVER);
Johannes Berg5ac2e352014-05-27 16:32:27 +02001534 return;
1535 }
1536
1537 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1538 return;
1539
1540 if (!test_sta_flag(sta, WLAN_STA_PS_STA)) {
1541 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
1542 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
1543 ieee80211_queue_work(hw, &sta->drv_deliver_wk);
1544 } else if (test_sta_flag(sta, WLAN_STA_PSPOLL) ||
1545 test_sta_flag(sta, WLAN_STA_UAPSD)) {
1546 /* must be asleep in this case */
1547 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
1548 ieee80211_queue_work(hw, &sta->drv_deliver_wk);
1549 } else {
1550 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
1551 }
Johannes Bergaf818582009-11-06 11:35:50 +01001552}
1553EXPORT_SYMBOL(ieee80211_sta_block_awake);
Felix Fietkaudcf55fb2011-04-17 17:45:00 +02001554
Johannes Berge9437892013-02-15 21:38:08 +01001555void ieee80211_sta_eosp(struct ieee80211_sta *pubsta)
Johannes Berg37fbd902011-09-29 16:04:39 +02001556{
1557 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1558 struct ieee80211_local *local = sta->local;
Johannes Berg37fbd902011-09-29 16:04:39 +02001559
1560 trace_api_eosp(local, pubsta);
1561
Johannes Berge9437892013-02-15 21:38:08 +01001562 clear_sta_flag(sta, WLAN_STA_SP);
Johannes Berg37fbd902011-09-29 16:04:39 +02001563}
Johannes Berge9437892013-02-15 21:38:08 +01001564EXPORT_SYMBOL(ieee80211_sta_eosp);
Johannes Berg37fbd902011-09-29 16:04:39 +02001565
Johannes Berg042ec452011-09-29 16:04:26 +02001566void ieee80211_sta_set_buffered(struct ieee80211_sta *pubsta,
1567 u8 tid, bool buffered)
Felix Fietkaudcf55fb2011-04-17 17:45:00 +02001568{
1569 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1570
Johannes Berg5a306f52012-11-14 23:22:21 +01001571 if (WARN_ON(tid >= IEEE80211_NUM_TIDS))
Johannes Berg042ec452011-09-29 16:04:26 +02001572 return;
1573
Johannes Berg1b000782013-12-19 10:47:48 +01001574 trace_api_sta_set_buffered(sta->local, pubsta, tid, buffered);
1575
Johannes Berg948d8872011-09-29 16:04:29 +02001576 if (buffered)
1577 set_bit(tid, &sta->driver_buffered_tids);
1578 else
1579 clear_bit(tid, &sta->driver_buffered_tids);
1580
Johannes Bergc868cb352011-09-29 16:04:27 +02001581 sta_info_recalc_tim(sta);
Felix Fietkaudcf55fb2011-04-17 17:45:00 +02001582}
Johannes Berg042ec452011-09-29 16:04:26 +02001583EXPORT_SYMBOL(ieee80211_sta_set_buffered);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001584
Johannes Berg83d5cc02012-01-12 09:31:10 +01001585int sta_info_move_state(struct sta_info *sta,
1586 enum ieee80211_sta_state new_state)
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001587{
Johannes Berg8bf11d82011-12-15 11:17:37 +01001588 might_sleep();
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001589
1590 if (sta->sta_state == new_state)
1591 return 0;
1592
Johannes Bergf09603a2012-01-20 13:55:21 +01001593 /* check allowed transitions first */
1594
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001595 switch (new_state) {
1596 case IEEE80211_STA_NONE:
Johannes Bergf09603a2012-01-20 13:55:21 +01001597 if (sta->sta_state != IEEE80211_STA_AUTH)
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001598 return -EINVAL;
1599 break;
1600 case IEEE80211_STA_AUTH:
Johannes Bergf09603a2012-01-20 13:55:21 +01001601 if (sta->sta_state != IEEE80211_STA_NONE &&
1602 sta->sta_state != IEEE80211_STA_ASSOC)
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001603 return -EINVAL;
1604 break;
1605 case IEEE80211_STA_ASSOC:
Johannes Bergf09603a2012-01-20 13:55:21 +01001606 if (sta->sta_state != IEEE80211_STA_AUTH &&
1607 sta->sta_state != IEEE80211_STA_AUTHORIZED)
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001608 return -EINVAL;
1609 break;
1610 case IEEE80211_STA_AUTHORIZED:
Johannes Bergf09603a2012-01-20 13:55:21 +01001611 if (sta->sta_state != IEEE80211_STA_ASSOC)
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001612 return -EINVAL;
1613 break;
1614 default:
1615 WARN(1, "invalid state %d", new_state);
1616 return -EINVAL;
1617 }
1618
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001619 sta_dbg(sta->sdata, "moving STA %pM to state %d\n",
1620 sta->sta.addr, new_state);
Johannes Bergf09603a2012-01-20 13:55:21 +01001621
1622 /*
1623 * notify the driver before the actual changes so it can
1624 * fail the transition
1625 */
1626 if (test_sta_flag(sta, WLAN_STA_INSERTED)) {
1627 int err = drv_sta_state(sta->local, sta->sdata, sta,
1628 sta->sta_state, new_state);
1629 if (err)
1630 return err;
1631 }
1632
1633 /* reflect the change in all state variables */
1634
1635 switch (new_state) {
1636 case IEEE80211_STA_NONE:
1637 if (sta->sta_state == IEEE80211_STA_AUTH)
1638 clear_bit(WLAN_STA_AUTH, &sta->_flags);
1639 break;
1640 case IEEE80211_STA_AUTH:
1641 if (sta->sta_state == IEEE80211_STA_NONE)
1642 set_bit(WLAN_STA_AUTH, &sta->_flags);
1643 else if (sta->sta_state == IEEE80211_STA_ASSOC)
1644 clear_bit(WLAN_STA_ASSOC, &sta->_flags);
1645 break;
1646 case IEEE80211_STA_ASSOC:
1647 if (sta->sta_state == IEEE80211_STA_AUTH) {
1648 set_bit(WLAN_STA_ASSOC, &sta->_flags);
1649 } else if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001650 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1651 (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1652 !sta->sdata->u.vlan.sta))
1653 atomic_dec(&sta->sdata->bss->num_mcast_sta);
Johannes Bergf09603a2012-01-20 13:55:21 +01001654 clear_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
1655 }
1656 break;
1657 case IEEE80211_STA_AUTHORIZED:
1658 if (sta->sta_state == IEEE80211_STA_ASSOC) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001659 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1660 (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1661 !sta->sdata->u.vlan.sta))
1662 atomic_inc(&sta->sdata->bss->num_mcast_sta);
Johannes Bergf09603a2012-01-20 13:55:21 +01001663 set_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
1664 }
1665 break;
1666 default:
1667 break;
1668 }
1669
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001670 sta->sta_state = new_state;
1671
1672 return 0;
1673}
Emmanuel Grumbach687da132013-10-01 16:45:43 +03001674
1675u8 sta_info_tx_streams(struct sta_info *sta)
1676{
1677 struct ieee80211_sta_ht_cap *ht_cap = &sta->sta.ht_cap;
1678 u8 rx_streams;
1679
1680 if (!sta->sta.ht_cap.ht_supported)
1681 return 1;
1682
1683 if (sta->sta.vht_cap.vht_supported) {
1684 int i;
1685 u16 tx_mcs_map =
1686 le16_to_cpu(sta->sta.vht_cap.vht_mcs.tx_mcs_map);
1687
1688 for (i = 7; i >= 0; i--)
1689 if ((tx_mcs_map & (0x3 << (i * 2))) !=
1690 IEEE80211_VHT_MCS_NOT_SUPPORTED)
1691 return i + 1;
1692 }
1693
1694 if (ht_cap->mcs.rx_mask[3])
1695 rx_streams = 4;
1696 else if (ht_cap->mcs.rx_mask[2])
1697 rx_streams = 3;
1698 else if (ht_cap->mcs.rx_mask[1])
1699 rx_streams = 2;
1700 else
1701 rx_streams = 1;
1702
1703 if (!(ht_cap->mcs.tx_params & IEEE80211_HT_MCS_TX_RX_DIFF))
1704 return rx_streams;
1705
1706 return ((ht_cap->mcs.tx_params & IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
1707 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT) + 1;
1708}
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001709
1710void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
1711{
1712 struct ieee80211_sub_if_data *sdata = sta->sdata;
1713 struct ieee80211_local *local = sdata->local;
John W. Linville9a244402014-07-25 10:22:36 -04001714 struct rate_control_ref *ref = NULL;
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001715 struct timespec uptime;
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001716 u32 thr = 0;
1717 int i, ac;
1718
John W. Linville9a244402014-07-25 10:22:36 -04001719 if (test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
1720 ref = local->rate_ctrl;
1721
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001722 sinfo->generation = sdata->local->sta_generation;
1723
Johannes Berg225b8182015-01-21 21:09:02 +01001724 /* do before driver, so beacon filtering drivers have a
1725 * chance to e.g. just add the number of filtered beacons
1726 * (or just modify the value entirely, of course)
1727 */
1728 if (sdata->vif.type == NL80211_IFTYPE_STATION)
1729 sinfo->rx_beacon = sdata->u.mgd.count_beacon_signal;
1730
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001731 drv_sta_statistics(local, sdata, &sta->sta, sinfo);
1732
Johannes Berg319090b2014-11-17 14:08:11 +01001733 sinfo->filled |= BIT(NL80211_STA_INFO_INACTIVE_TIME) |
1734 BIT(NL80211_STA_INFO_STA_FLAGS) |
1735 BIT(NL80211_STA_INFO_BSS_PARAM) |
1736 BIT(NL80211_STA_INFO_CONNECTED_TIME) |
1737 BIT(NL80211_STA_INFO_RX_DROP_MISC) |
1738 BIT(NL80211_STA_INFO_BEACON_LOSS);
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001739
Thomas Gleixner18171522014-06-11 23:59:14 +00001740 ktime_get_ts(&uptime);
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001741 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001742 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001743
Johannes Berg319090b2014-11-17 14:08:11 +01001744 if (!(sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES64) |
1745 BIT(NL80211_STA_INFO_TX_BYTES)))) {
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001746 sinfo->tx_bytes = 0;
1747 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
1748 sinfo->tx_bytes += sta->tx_bytes[ac];
Johannes Berg319090b2014-11-17 14:08:11 +01001749 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BYTES64);
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001750 }
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001751
Johannes Berg319090b2014-11-17 14:08:11 +01001752 if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_PACKETS))) {
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001753 sinfo->tx_packets = 0;
1754 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
1755 sinfo->tx_packets += sta->tx_packets[ac];
Johannes Berg319090b2014-11-17 14:08:11 +01001756 sinfo->filled |= BIT(NL80211_STA_INFO_TX_PACKETS);
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001757 }
1758
Johannes Berg319090b2014-11-17 14:08:11 +01001759 if (!(sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES64) |
1760 BIT(NL80211_STA_INFO_RX_BYTES)))) {
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001761 sinfo->rx_bytes = sta->rx_bytes;
Johannes Berg319090b2014-11-17 14:08:11 +01001762 sinfo->filled |= BIT(NL80211_STA_INFO_RX_BYTES64);
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001763 }
1764
Johannes Berg319090b2014-11-17 14:08:11 +01001765 if (!(sinfo->filled & BIT(NL80211_STA_INFO_RX_PACKETS))) {
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001766 sinfo->rx_packets = sta->rx_packets;
Johannes Berg319090b2014-11-17 14:08:11 +01001767 sinfo->filled |= BIT(NL80211_STA_INFO_RX_PACKETS);
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001768 }
1769
Johannes Berg319090b2014-11-17 14:08:11 +01001770 if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_RETRIES))) {
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001771 sinfo->tx_retries = sta->tx_retry_count;
Johannes Berg319090b2014-11-17 14:08:11 +01001772 sinfo->filled |= BIT(NL80211_STA_INFO_TX_RETRIES);
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001773 }
1774
Johannes Berg319090b2014-11-17 14:08:11 +01001775 if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_FAILED))) {
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001776 sinfo->tx_failed = sta->tx_retry_failed;
Johannes Berg319090b2014-11-17 14:08:11 +01001777 sinfo->filled |= BIT(NL80211_STA_INFO_TX_FAILED);
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001778 }
1779
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001780 sinfo->rx_dropped_misc = sta->rx_dropped;
1781 sinfo->beacon_loss_count = sta->beacon_loss_count;
1782
Johannes Berg225b8182015-01-21 21:09:02 +01001783 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1784 !(sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)) {
1785 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_RX) |
1786 BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
1787 sinfo->rx_beacon_signal_avg = ieee80211_ave_rssi(&sdata->vif);
1788 }
1789
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001790 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
1791 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
Johannes Berg319090b2014-11-17 14:08:11 +01001792 if (!(sinfo->filled & BIT(NL80211_STA_INFO_SIGNAL))) {
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001793 sinfo->signal = (s8)sta->last_signal;
Johannes Berg319090b2014-11-17 14:08:11 +01001794 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001795 }
1796
Johannes Berg319090b2014-11-17 14:08:11 +01001797 if (!(sinfo->filled & BIT(NL80211_STA_INFO_SIGNAL_AVG))) {
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001798 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
Johannes Berg319090b2014-11-17 14:08:11 +01001799 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL_AVG);
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001800 }
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001801 }
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001802
1803 if (sta->chains &&
Johannes Berg319090b2014-11-17 14:08:11 +01001804 !(sinfo->filled & (BIT(NL80211_STA_INFO_CHAIN_SIGNAL) |
1805 BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)))) {
1806 sinfo->filled |= BIT(NL80211_STA_INFO_CHAIN_SIGNAL) |
1807 BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG);
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001808
1809 sinfo->chains = sta->chains;
1810 for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
1811 sinfo->chain_signal[i] = sta->chain_signal_last[i];
1812 sinfo->chain_signal_avg[i] =
1813 (s8) -ewma_read(&sta->chain_signal_avg[i]);
1814 }
1815 }
1816
Johannes Berg319090b2014-11-17 14:08:11 +01001817 if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE))) {
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001818 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
Johannes Berg319090b2014-11-17 14:08:11 +01001819 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE);
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001820 }
1821
Johannes Berg319090b2014-11-17 14:08:11 +01001822 if (!(sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE))) {
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001823 sta_set_rate_info_rx(sta, &sinfo->rxrate);
Johannes Berg319090b2014-11-17 14:08:11 +01001824 sinfo->filled |= BIT(NL80211_STA_INFO_RX_BITRATE);
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001825 }
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001826
Johannes Berg79c892b2014-11-21 14:26:31 +01001827 sinfo->filled |= BIT(NL80211_STA_INFO_TID_STATS);
1828 for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) {
1829 struct cfg80211_tid_stats *tidstats = &sinfo->pertid[i];
1830
1831 if (!(tidstats->filled & BIT(NL80211_TID_STATS_RX_MSDU))) {
1832 tidstats->filled |= BIT(NL80211_TID_STATS_RX_MSDU);
1833 tidstats->rx_msdu = sta->rx_msdu[i];
1834 }
1835
1836 if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU))) {
1837 tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU);
1838 tidstats->tx_msdu = sta->tx_msdu[i];
1839 }
1840
1841 if (!(tidstats->filled &
1842 BIT(NL80211_TID_STATS_TX_MSDU_RETRIES)) &&
1843 local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
1844 tidstats->filled |=
1845 BIT(NL80211_TID_STATS_TX_MSDU_RETRIES);
1846 tidstats->tx_msdu_retries = sta->tx_msdu_retries[i];
1847 }
1848
1849 if (!(tidstats->filled &
1850 BIT(NL80211_TID_STATS_TX_MSDU_FAILED)) &&
1851 local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
1852 tidstats->filled |=
1853 BIT(NL80211_TID_STATS_TX_MSDU_FAILED);
1854 tidstats->tx_msdu_failed = sta->tx_msdu_failed[i];
1855 }
1856 }
1857
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001858 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1859#ifdef CONFIG_MAC80211_MESH
Johannes Berg319090b2014-11-17 14:08:11 +01001860 sinfo->filled |= BIT(NL80211_STA_INFO_LLID) |
1861 BIT(NL80211_STA_INFO_PLID) |
1862 BIT(NL80211_STA_INFO_PLINK_STATE) |
1863 BIT(NL80211_STA_INFO_LOCAL_PM) |
1864 BIT(NL80211_STA_INFO_PEER_PM) |
1865 BIT(NL80211_STA_INFO_NONPEER_PM);
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001866
1867 sinfo->llid = sta->llid;
1868 sinfo->plid = sta->plid;
1869 sinfo->plink_state = sta->plink_state;
1870 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
Johannes Berg319090b2014-11-17 14:08:11 +01001871 sinfo->filled |= BIT(NL80211_STA_INFO_T_OFFSET);
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001872 sinfo->t_offset = sta->t_offset;
1873 }
1874 sinfo->local_pm = sta->local_pm;
1875 sinfo->peer_pm = sta->peer_pm;
1876 sinfo->nonpeer_pm = sta->nonpeer_pm;
1877#endif
1878 }
1879
1880 sinfo->bss_param.flags = 0;
1881 if (sdata->vif.bss_conf.use_cts_prot)
1882 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
1883 if (sdata->vif.bss_conf.use_short_preamble)
1884 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
1885 if (sdata->vif.bss_conf.use_short_slot)
1886 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
Emmanuel Grumbach785e21a2014-09-03 15:25:04 +03001887 sinfo->bss_param.dtim_period = sdata->vif.bss_conf.dtim_period;
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001888 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
1889
1890 sinfo->sta_flags.set = 0;
1891 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
1892 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
1893 BIT(NL80211_STA_FLAG_WME) |
1894 BIT(NL80211_STA_FLAG_MFP) |
1895 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1896 BIT(NL80211_STA_FLAG_ASSOCIATED) |
1897 BIT(NL80211_STA_FLAG_TDLS_PEER);
1898 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1899 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
1900 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
1901 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
Johannes Berga74a8c82014-07-22 14:50:47 +02001902 if (sta->sta.wme)
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001903 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
1904 if (test_sta_flag(sta, WLAN_STA_MFP))
1905 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
1906 if (test_sta_flag(sta, WLAN_STA_AUTH))
1907 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
1908 if (test_sta_flag(sta, WLAN_STA_ASSOC))
1909 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1910 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1911 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
1912
1913 /* check if the driver has a SW RC implementation */
1914 if (ref && ref->ops->get_expected_throughput)
1915 thr = ref->ops->get_expected_throughput(sta->rate_ctrl_priv);
1916 else
1917 thr = drv_get_expected_throughput(local, &sta->sta);
1918
1919 if (thr != 0) {
Johannes Berg319090b2014-11-17 14:08:11 +01001920 sinfo->filled |= BIT(NL80211_STA_INFO_EXPECTED_THROUGHPUT);
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001921 sinfo->expected_throughput = thr;
1922 }
1923}