]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - net/mac80211/sta_info.c
Merge remote-tracking branches 'asoc/topic/atmel', 'asoc/topic/bcm2835' and 'asoc...
[mirror_ubuntu-zesty-kernel.git] / net / mac80211 / sta_info.c
CommitLineData
f0706e82
JB
1/*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
d98ad83e 4 * Copyright 2013-2014 Intel Mobile Communications GmbH
0ead2510 5 * Copyright (C) 2015 Intel Deutschland GmbH
f0706e82
JB
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/init.h>
888d04df 14#include <linux/etherdevice.h>
f0706e82
JB
15#include <linux/netdevice.h>
16#include <linux/types.h>
17#include <linux/slab.h>
18#include <linux/skbuff.h>
19#include <linux/if_arp.h>
0d174406 20#include <linux/timer.h>
d0709a65 21#include <linux/rtnetlink.h>
f0706e82
JB
22
23#include <net/mac80211.h>
24#include "ieee80211_i.h"
24487981 25#include "driver-ops.h"
2c8dccc7 26#include "rate.h"
f0706e82 27#include "sta_info.h"
e9f207f0 28#include "debugfs_sta.h"
ee385855 29#include "mesh.h"
ce662b44 30#include "wme.h"
f0706e82 31
d0709a65
JB
32/**
33 * DOC: STA information lifetime rules
34 *
35 * STA info structures (&struct sta_info) are managed in a hash table
36 * for faster lookup and a list for iteration. They are managed using
37 * RCU, i.e. access to the list and hash table is protected by RCU.
38 *
34e89507
JB
39 * Upon allocating a STA info structure with sta_info_alloc(), the caller
40 * owns that structure. It must then insert it into the hash table using
41 * either sta_info_insert() or sta_info_insert_rcu(); only in the latter
42 * case (which acquires an rcu read section but must not be called from
43 * within one) will the pointer still be valid after the call. Note that
44 * the caller may not do much with the STA info before inserting it, in
45 * particular, it may not start any mesh peer link management or add
46 * encryption keys.
93e5deb1
JB
47 *
48 * When the insertion fails (sta_info_insert()) returns non-zero), the
49 * structure will have been freed by sta_info_insert()!
d0709a65 50 *
34e89507 51 * Station entries are added by mac80211 when you establish a link with a
7e189a12
LR
52 * peer. This means different things for the different type of interfaces
53 * we support. For a regular station this mean we add the AP sta when we
25985edc 54 * receive an association response from the AP. For IBSS this occurs when
34e89507 55 * get to know about a peer on the same IBSS. For WDS we add the sta for
25985edc 56 * the peer immediately upon device open. When using AP mode we add stations
34e89507 57 * for each respective station upon request from userspace through nl80211.
7e189a12 58 *
34e89507
JB
59 * In order to remove a STA info structure, various sta_info_destroy_*()
60 * calls are available.
d0709a65 61 *
34e89507
JB
62 * There is no concept of ownership on a STA entry, each structure is
63 * owned by the global hash table/list until it is removed. All users of
64 * the structure need to be RCU protected so that the structure won't be
65 * freed before they are done using it.
d0709a65 66 */
f0706e82 67
7bedd0cf
JB
68static const struct rhashtable_params sta_rht_params = {
69 .nelem_hint = 3, /* start small */
caf22d31 70 .automatic_shrinking = true,
7bedd0cf 71 .head_offset = offsetof(struct sta_info, hash_node),
ac100ce5 72 .key_offset = offsetof(struct sta_info, addr),
7bedd0cf
JB
73 .key_len = ETH_ALEN,
74 .hashfn = sta_addr_hash,
ebd82b39 75 .max_size = CONFIG_MAC80211_STA_HASH_MAX_SIZE,
7bedd0cf
JB
76};
77
4d33960b 78/* Caller must hold local->sta_mtx */
be8755e1
MW
79static int sta_info_hash_del(struct ieee80211_local *local,
80 struct sta_info *sta)
f0706e82 81{
7bedd0cf
JB
82 return rhashtable_remove_fast(&local->sta_hash, &sta->hash_node,
83 sta_rht_params);
f0706e82
JB
84}
85
5108ca82 86static void __cleanup_single_sta(struct sta_info *sta)
b22cfcfc 87{
b22cfcfc
EP
88 int ac, i;
89 struct tid_ampdu_tx *tid_tx;
90 struct ieee80211_sub_if_data *sdata = sta->sdata;
91 struct ieee80211_local *local = sdata->local;
d012a605 92 struct ps_data *ps;
b22cfcfc 93
e3685e03 94 if (test_sta_flag(sta, WLAN_STA_PS_STA) ||
5ac2e350
JB
95 test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
96 test_sta_flag(sta, WLAN_STA_PS_DELIVER)) {
d012a605
MP
97 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
98 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
99 ps = &sdata->bss->ps;
3f52b7e3
MP
100 else if (ieee80211_vif_is_mesh(&sdata->vif))
101 ps = &sdata->u.mesh.ps;
d012a605
MP
102 else
103 return;
b22cfcfc
EP
104
105 clear_sta_flag(sta, WLAN_STA_PS_STA);
e3685e03 106 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
5ac2e350 107 clear_sta_flag(sta, WLAN_STA_PS_DELIVER);
b22cfcfc 108
d012a605 109 atomic_dec(&ps->num_sta_ps);
b22cfcfc
EP
110 }
111
ba8c3d6f
FF
112 if (sta->sta.txq[0]) {
113 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
114 struct txq_info *txqi = to_txq_info(sta->sta.txq[i]);
115 int n = skb_queue_len(&txqi->queue);
116
117 ieee80211_purge_tx_queue(&local->hw, &txqi->queue);
118 atomic_sub(n, &sdata->txqs_len[txqi->txq.ac]);
119 }
120 }
121
b22cfcfc
EP
122 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
123 local->total_ps_buffered -= skb_queue_len(&sta->ps_tx_buf[ac]);
1f98ab7f
FF
124 ieee80211_purge_tx_queue(&local->hw, &sta->ps_tx_buf[ac]);
125 ieee80211_purge_tx_queue(&local->hw, &sta->tx_filtered[ac]);
b22cfcfc
EP
126 }
127
45b5028e
TP
128 if (ieee80211_vif_is_mesh(&sdata->vif))
129 mesh_sta_cleanup(sta);
b22cfcfc 130
5ac2e350 131 cancel_work_sync(&sta->drv_deliver_wk);
b22cfcfc
EP
132
133 /*
134 * Destroy aggregation state here. It would be nice to wait for the
135 * driver to finish aggregation stop and then clean up, but for now
136 * drivers have to handle aggregation stop being requested, followed
137 * directly by station destruction.
138 */
5a306f58 139 for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
661eb381 140 kfree(sta->ampdu_mlme.tid_start_tx[i]);
b22cfcfc
EP
141 tid_tx = rcu_dereference_raw(sta->ampdu_mlme.tid_tx[i]);
142 if (!tid_tx)
143 continue;
1f98ab7f 144 ieee80211_purge_tx_queue(&local->hw, &tid_tx->pending);
b22cfcfc
EP
145 kfree(tid_tx);
146 }
5108ca82 147}
b22cfcfc 148
5108ca82
JB
149static void cleanup_single_sta(struct sta_info *sta)
150{
151 struct ieee80211_sub_if_data *sdata = sta->sdata;
152 struct ieee80211_local *local = sdata->local;
153
154 __cleanup_single_sta(sta);
b22cfcfc
EP
155 sta_info_free(local, sta);
156}
157
d0709a65 158/* protected by RCU */
abe60632
JB
159struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata,
160 const u8 *addr)
f0706e82 161{
abe60632 162 struct ieee80211_local *local = sdata->local;
60f4b626
JB
163 struct sta_info *sta;
164 struct rhash_head *tmp;
165 const struct bucket_table *tbl;
f0706e82 166
60f4b626
JB
167 rcu_read_lock();
168 tbl = rht_dereference_rcu(local->sta_hash.tbl, &local->sta_hash);
f0706e82 169
60f4b626
JB
170 for_each_sta_info(local, tbl, addr, sta, tmp) {
171 if (sta->sdata == sdata) {
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 }
178 }
179 rcu_read_unlock();
180 return NULL;
43ba7e95
JB
181}
182
0e5ded5a
FF
183/*
184 * Get sta info either from the specified interface
185 * or from one of its vlans
186 */
187struct sta_info *sta_info_get_bss(struct ieee80211_sub_if_data *sdata,
188 const u8 *addr)
189{
190 struct ieee80211_local *local = sdata->local;
191 struct sta_info *sta;
7bedd0cf
JB
192 struct rhash_head *tmp;
193 const struct bucket_table *tbl;
0e5ded5a 194
7bedd0cf
JB
195 rcu_read_lock();
196 tbl = rht_dereference_rcu(local->sta_hash.tbl, &local->sta_hash);
197
198 for_each_sta_info(local, tbl, addr, sta, tmp) {
199 if (sta->sdata == sdata ||
200 (sta->sdata->bss && sta->sdata->bss == sdata->bss)) {
201 rcu_read_unlock();
202 /* this is safe as the caller must already hold
203 * another rcu read section or the mutex
204 */
205 return sta;
206 }
0e5ded5a 207 }
7bedd0cf
JB
208 rcu_read_unlock();
209 return NULL;
0e5ded5a
FF
210}
211
3b53fde8
JB
212struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata,
213 int idx)
ee385855 214{
3b53fde8 215 struct ieee80211_local *local = sdata->local;
ee385855
LCC
216 struct sta_info *sta;
217 int i = 0;
218
d0709a65 219 list_for_each_entry_rcu(sta, &local->sta_list, list) {
3b53fde8 220 if (sdata != sta->sdata)
2a8ca29a 221 continue;
ee385855
LCC
222 if (i < idx) {
223 ++i;
224 continue;
ee385855 225 }
2a8ca29a 226 return sta;
ee385855 227 }
ee385855
LCC
228
229 return NULL;
230}
f0706e82 231
93e5deb1 232/**
d9a7ddb0 233 * sta_info_free - free STA
93e5deb1 234 *
6ef307bc 235 * @local: pointer to the global information
93e5deb1
JB
236 * @sta: STA info to free
237 *
238 * This function must undo everything done by sta_info_alloc()
d9a7ddb0
JB
239 * that may happen before sta_info_insert(). It may only be
240 * called when sta_info_insert() has not been attempted (and
241 * if that fails, the station is freed anyway.)
93e5deb1 242 */
d9a7ddb0 243void sta_info_free(struct ieee80211_local *local, struct sta_info *sta)
93e5deb1 244{
889cbb91 245 if (sta->rate_ctrl)
af65cd96 246 rate_control_free_sta(sta);
93e5deb1 247
bdcbd8e0 248 sta_dbg(sta->sdata, "Destroyed STA %pM\n", sta->sta.addr);
93e5deb1 249
ba8c3d6f
FF
250 if (sta->sta.txq[0])
251 kfree(to_txq_info(sta->sta.txq[0]));
53d04525 252 kfree(rcu_dereference_raw(sta->sta.rates));
433f5bc1
JB
253#ifdef CONFIG_MAC80211_MESH
254 kfree(sta->mesh);
255#endif
93e5deb1
JB
256 kfree(sta);
257}
258
4d33960b 259/* Caller must hold local->sta_mtx */
d0709a65
JB
260static void sta_info_hash_add(struct ieee80211_local *local,
261 struct sta_info *sta)
f0706e82 262{
7bedd0cf
JB
263 rhashtable_insert_fast(&local->sta_hash, &sta->hash_node,
264 sta_rht_params);
f0706e82 265}
f0706e82 266
5ac2e350 267static void sta_deliver_ps_frames(struct work_struct *wk)
af818581
JB
268{
269 struct sta_info *sta;
270
5ac2e350 271 sta = container_of(wk, struct sta_info, drv_deliver_wk);
af818581
JB
272
273 if (sta->dead)
274 return;
275
5ac2e350
JB
276 local_bh_disable();
277 if (!test_sta_flag(sta, WLAN_STA_PS_STA))
af818581 278 ieee80211_sta_ps_deliver_wakeup(sta);
5ac2e350 279 else if (test_and_clear_sta_flag(sta, WLAN_STA_PSPOLL))
af818581 280 ieee80211_sta_ps_deliver_poll_response(sta);
5ac2e350 281 else if (test_and_clear_sta_flag(sta, WLAN_STA_UAPSD))
47086fc5 282 ieee80211_sta_ps_deliver_uapsd(sta);
5ac2e350 283 local_bh_enable();
af818581
JB
284}
285
af65cd96
JB
286static int sta_prepare_rate_control(struct ieee80211_local *local,
287 struct sta_info *sta, gfp_t gfp)
288{
30686bf7 289 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL))
af65cd96
JB
290 return 0;
291
889cbb91 292 sta->rate_ctrl = local->rate_ctrl;
af65cd96 293 sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl,
35c347ac 294 sta, gfp);
889cbb91 295 if (!sta->rate_ctrl_priv)
af65cd96 296 return -ENOMEM;
af65cd96
JB
297
298 return 0;
299}
300
73651ee6 301struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
56544160 302 const u8 *addr, gfp_t gfp)
f0706e82 303{
d0709a65 304 struct ieee80211_local *local = sdata->local;
ba8c3d6f 305 struct ieee80211_hw *hw = &local->hw;
f0706e82 306 struct sta_info *sta;
16c5f15c 307 int i;
f0706e82 308
ba8c3d6f 309 sta = kzalloc(sizeof(*sta) + hw->sta_data_size, gfp);
f0706e82 310 if (!sta)
73651ee6 311 return NULL;
f0706e82 312
07346f81 313 spin_lock_init(&sta->lock);
1d147bfa 314 spin_lock_init(&sta->ps_lock);
5ac2e350 315 INIT_WORK(&sta->drv_deliver_wk, sta_deliver_ps_frames);
67c282c0 316 INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work);
a93e3644 317 mutex_init(&sta->ampdu_mlme.mtx);
87f59c70 318#ifdef CONFIG_MAC80211_MESH
433f5bc1
JB
319 if (ieee80211_vif_is_mesh(&sdata->vif)) {
320 sta->mesh = kzalloc(sizeof(*sta->mesh), gfp);
321 if (!sta->mesh)
322 goto free;
323 spin_lock_init(&sta->mesh->plink_lock);
324 if (ieee80211_vif_is_mesh(&sdata->vif) &&
325 !sdata->u.mesh.user_mpm)
326 init_timer(&sta->mesh->plink_timer);
327 sta->mesh->nonpeer_pm = NL80211_MESH_POWER_ACTIVE;
328 }
87f59c70 329#endif
07346f81 330
ac100ce5 331 memcpy(sta->addr, addr, ETH_ALEN);
17741cdc 332 memcpy(sta->sta.addr, addr, ETH_ALEN);
d0709a65
JB
333 sta->local = local;
334 sta->sdata = sdata;
e5a9f8d0 335 sta->rx_stats.last_rx = jiffies;
f0706e82 336
71ec375c
JB
337 sta->sta_state = IEEE80211_STA_NONE;
338
b6da911b
LK
339 /* Mark TID as unreserved */
340 sta->reserved_tid = IEEE80211_TID_UNRESERVED;
341
84b00607 342 sta->last_connected = ktime_get_seconds();
e5a9f8d0
JB
343 ewma_signal_init(&sta->rx_stats.avg_signal);
344 for (i = 0; i < ARRAY_SIZE(sta->rx_stats.chain_signal_avg); i++)
345 ewma_signal_init(&sta->rx_stats.chain_signal_avg[i]);
541a45a1 346
ba8c3d6f
FF
347 if (local->ops->wake_tx_queue) {
348 void *txq_data;
349 int size = sizeof(struct txq_info) +
350 ALIGN(hw->txq_data_size, sizeof(void *));
351
352 txq_data = kcalloc(ARRAY_SIZE(sta->sta.txq), size, gfp);
353 if (!txq_data)
354 goto free;
355
356 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
357 struct txq_info *txq = txq_data + i * size;
358
359 ieee80211_init_tx_queue(sdata, sta, txq, i);
360 }
abfbc3af 361 }
f0706e82 362
ba8c3d6f
FF
363 if (sta_prepare_rate_control(local, sta, gfp))
364 goto free_txq;
365
5a306f58 366 for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
a622ab72
JB
367 /*
368 * timer_to_tid must be initialized with identity mapping
369 * to enable session_timer's data differentiation. See
370 * sta_rx_agg_session_timer_expired for usage.
371 */
16c5f15c 372 sta->timer_to_tid[i] = i;
16c5f15c 373 }
948d887d
JB
374 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
375 skb_queue_head_init(&sta->ps_tx_buf[i]);
376 skb_queue_head_init(&sta->tx_filtered[i]);
377 }
73651ee6 378
5a306f58 379 for (i = 0; i < IEEE80211_NUM_TIDS; i++)
4be929be 380 sta->last_seq_ctrl[i] = cpu_to_le16(USHRT_MAX);
cccaec98 381
af0ed69b 382 sta->sta.smps_mode = IEEE80211_SMPS_OFF;
687da132
EG
383 if (sdata->vif.type == NL80211_IFTYPE_AP ||
384 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
385 struct ieee80211_supported_band *sband =
ba8c3d6f 386 hw->wiphy->bands[ieee80211_get_sdata_band(sdata)];
687da132
EG
387 u8 smps = (sband->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >>
388 IEEE80211_HT_CAP_SM_PS_SHIFT;
389 /*
390 * Assume that hostapd advertises our caps in the beacon and
391 * this is the known_smps_mode for a station that just assciated
392 */
393 switch (smps) {
394 case WLAN_HT_SMPS_CONTROL_DISABLED:
395 sta->known_smps_mode = IEEE80211_SMPS_OFF;
396 break;
397 case WLAN_HT_SMPS_CONTROL_STATIC:
398 sta->known_smps_mode = IEEE80211_SMPS_STATIC;
399 break;
400 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
401 sta->known_smps_mode = IEEE80211_SMPS_DYNAMIC;
402 break;
403 default:
404 WARN_ON(1);
405 }
406 }
af0ed69b 407
bdcbd8e0 408 sta_dbg(sdata, "Allocated STA %pM\n", sta->sta.addr);
ef04a297 409
abfbc3af 410 return sta;
ba8c3d6f
FF
411
412free_txq:
413 if (sta->sta.txq[0])
414 kfree(to_txq_info(sta->sta.txq[0]));
415free:
433f5bc1
JB
416#ifdef CONFIG_MAC80211_MESH
417 kfree(sta->mesh);
418#endif
ba8c3d6f
FF
419 kfree(sta);
420 return NULL;
73651ee6
JB
421}
422
8c71df7a 423static int sta_info_insert_check(struct sta_info *sta)
34e89507 424{
34e89507 425 struct ieee80211_sub_if_data *sdata = sta->sdata;
34e89507 426
03e4497e
JB
427 /*
428 * Can't be a WARN_ON because it can be triggered through a race:
429 * something inserts a STA (on one CPU) without holding the RTNL
430 * and another CPU turns off the net device.
431 */
8c71df7a
GE
432 if (unlikely(!ieee80211_sdata_running(sdata)))
433 return -ENETDOWN;
03e4497e 434
b203ca39 435 if (WARN_ON(ether_addr_equal(sta->sta.addr, sdata->vif.addr) ||
8c71df7a
GE
436 is_multicast_ether_addr(sta->sta.addr)))
437 return -EINVAL;
438
31104891
JB
439 /* Strictly speaking this isn't necessary as we hold the mutex, but
440 * the rhashtable code can't really deal with that distinction. We
441 * do require the mutex for correctness though.
442 */
443 rcu_read_lock();
444 lockdep_assert_held(&sdata->local->sta_mtx);
445 if (ieee80211_hw_check(&sdata->local->hw, NEEDS_UNIQUE_STA_ADDR) &&
446 ieee80211_find_sta_by_ifaddr(&sdata->local->hw, sta->addr, NULL)) {
447 rcu_read_unlock();
448 return -ENOTUNIQ;
449 }
450 rcu_read_unlock();
451
8c71df7a
GE
452 return 0;
453}
454
f09603a2
JB
455static int sta_info_insert_drv_state(struct ieee80211_local *local,
456 struct ieee80211_sub_if_data *sdata,
457 struct sta_info *sta)
458{
459 enum ieee80211_sta_state state;
460 int err = 0;
461
462 for (state = IEEE80211_STA_NOTEXIST; state < sta->sta_state; state++) {
463 err = drv_sta_state(local, sdata, sta, state, state + 1);
464 if (err)
465 break;
466 }
467
468 if (!err) {
a4ec45a4
JB
469 /*
470 * Drivers using legacy sta_add/sta_remove callbacks only
471 * get uploaded set to true after sta_add is called.
472 */
473 if (!local->ops->sta_add)
474 sta->uploaded = true;
f09603a2
JB
475 return 0;
476 }
477
478 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
bdcbd8e0
JB
479 sdata_info(sdata,
480 "failed to move IBSS STA %pM to state %d (%d) - keeping it anyway\n",
481 sta->sta.addr, state + 1, err);
f09603a2
JB
482 err = 0;
483 }
484
485 /* unwind on error */
486 for (; state > IEEE80211_STA_NOTEXIST; state--)
487 WARN_ON(drv_sta_state(local, sdata, sta, state, state - 1));
488
489 return err;
490}
491
8c71df7a
GE
492/*
493 * should be called with sta_mtx locked
494 * this function replaces the mutex lock
495 * with a RCU lock
496 */
4d33960b 497static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU)
8c71df7a
GE
498{
499 struct ieee80211_local *local = sta->local;
500 struct ieee80211_sub_if_data *sdata = sta->sdata;
7852e361 501 struct station_info sinfo;
8c71df7a
GE
502 int err = 0;
503
504 lockdep_assert_held(&local->sta_mtx);
34e89507 505
7852e361
JB
506 /* check if STA exists already */
507 if (sta_info_get_bss(sdata, sta->sta.addr)) {
508 err = -EEXIST;
509 goto out_err;
4d33960b 510 }
32bfd35d 511
7852e361
JB
512 local->num_sta++;
513 local->sta_generation++;
514 smp_mb();
4d33960b 515
5108ca82
JB
516 /* simplify things and don't accept BA sessions yet */
517 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
518
7852e361
JB
519 /* make the station visible */
520 sta_info_hash_add(local, sta);
83d5cc01 521
2bad7748 522 list_add_tail_rcu(&sta->list, &local->sta_list);
4d33960b 523
5108ca82
JB
524 /* notify driver */
525 err = sta_info_insert_drv_state(local, sdata, sta);
526 if (err)
527 goto out_remove;
528
7852e361 529 set_sta_flag(sta, WLAN_STA_INSERTED);
5108ca82
JB
530 /* accept BA sessions now */
531 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
4d33960b 532
21f659bf 533 ieee80211_recalc_min_chandef(sdata);
7852e361
JB
534 ieee80211_sta_debugfs_add(sta);
535 rate_control_add_sta_debugfs(sta);
4d33960b 536
7852e361
JB
537 memset(&sinfo, 0, sizeof(sinfo));
538 sinfo.filled = 0;
539 sinfo.generation = local->sta_generation;
540 cfg80211_new_sta(sdata->dev, sta->sta.addr, &sinfo, GFP_KERNEL);
d0709a65 541
bdcbd8e0 542 sta_dbg(sdata, "Inserted STA %pM\n", sta->sta.addr);
f0706e82 543
34e89507
JB
544 /* move reference to rcu-protected */
545 rcu_read_lock();
546 mutex_unlock(&local->sta_mtx);
e9f207f0 547
73651ee6
JB
548 if (ieee80211_vif_is_mesh(&sdata->vif))
549 mesh_accept_plinks_update(sdata);
550
8c71df7a 551 return 0;
5108ca82
JB
552 out_remove:
553 sta_info_hash_del(local, sta);
554 list_del_rcu(&sta->list);
555 local->num_sta--;
556 synchronize_net();
557 __cleanup_single_sta(sta);
4d33960b
JB
558 out_err:
559 mutex_unlock(&local->sta_mtx);
560 rcu_read_lock();
561 return err;
8c71df7a
GE
562}
563
564int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU)
565{
566 struct ieee80211_local *local = sta->local;
308f7fcf 567 int err;
8c71df7a 568
4d33960b
JB
569 might_sleep();
570
31104891
JB
571 mutex_lock(&local->sta_mtx);
572
8c71df7a
GE
573 err = sta_info_insert_check(sta);
574 if (err) {
31104891 575 mutex_unlock(&local->sta_mtx);
8c71df7a
GE
576 rcu_read_lock();
577 goto out_free;
578 }
579
4d33960b 580 err = sta_info_insert_finish(sta);
8c71df7a
GE
581 if (err)
582 goto out_free;
583
73651ee6 584 return 0;
93e5deb1 585 out_free:
d9a7ddb0 586 sta_info_free(local, sta);
93e5deb1 587 return err;
f0706e82
JB
588}
589
34e89507
JB
590int sta_info_insert(struct sta_info *sta)
591{
592 int err = sta_info_insert_rcu(sta);
593
594 rcu_read_unlock();
595
596 return err;
597}
598
d012a605 599static inline void __bss_tim_set(u8 *tim, u16 id)
004c872e
JB
600{
601 /*
602 * This format has been mandated by the IEEE specifications,
603 * so this line may not be changed to use the __set_bit() format.
604 */
d012a605 605 tim[id / 8] |= (1 << (id % 8));
004c872e
JB
606}
607
d012a605 608static inline void __bss_tim_clear(u8 *tim, u16 id)
004c872e
JB
609{
610 /*
611 * This format has been mandated by the IEEE specifications,
612 * so this line may not be changed to use the __clear_bit() format.
613 */
d012a605 614 tim[id / 8] &= ~(1 << (id % 8));
004c872e
JB
615}
616
3d5839b6
IP
617static inline bool __bss_tim_get(u8 *tim, u16 id)
618{
619 /*
620 * This format has been mandated by the IEEE specifications,
621 * so this line may not be changed to use the test_bit() format.
622 */
623 return tim[id / 8] & (1 << (id % 8));
624}
625
948d887d 626static unsigned long ieee80211_tids_for_ac(int ac)
004c872e 627{
948d887d
JB
628 /* If we ever support TIDs > 7, this obviously needs to be adjusted */
629 switch (ac) {
630 case IEEE80211_AC_VO:
631 return BIT(6) | BIT(7);
632 case IEEE80211_AC_VI:
633 return BIT(4) | BIT(5);
634 case IEEE80211_AC_BE:
635 return BIT(0) | BIT(3);
636 case IEEE80211_AC_BK:
637 return BIT(1) | BIT(2);
638 default:
639 WARN_ON(1);
640 return 0;
d0709a65 641 }
004c872e
JB
642}
643
9b7a86f3 644static void __sta_info_recalc_tim(struct sta_info *sta, bool ignore_pending)
004c872e 645{
c868cb35 646 struct ieee80211_local *local = sta->local;
d012a605 647 struct ps_data *ps;
948d887d
JB
648 bool indicate_tim = false;
649 u8 ignore_for_tim = sta->sta.uapsd_queues;
650 int ac;
a69bd8e6 651 u16 id = sta->sta.aid;
d012a605
MP
652
653 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
654 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
655 if (WARN_ON_ONCE(!sta->sdata->bss))
656 return;
004c872e 657
d012a605 658 ps = &sta->sdata->bss->ps;
3f52b7e3
MP
659#ifdef CONFIG_MAC80211_MESH
660 } else if (ieee80211_vif_is_mesh(&sta->sdata->vif)) {
661 ps = &sta->sdata->u.mesh.ps;
3f52b7e3 662#endif
d012a605 663 } else {
c868cb35 664 return;
d012a605 665 }
3e122be0 666
c868cb35 667 /* No need to do anything if the driver does all */
30686bf7 668 if (ieee80211_hw_check(&local->hw, AP_LINK_PS))
c868cb35 669 return;
004c872e 670
c868cb35
JB
671 if (sta->dead)
672 goto done;
3e122be0 673
948d887d
JB
674 /*
675 * If all ACs are delivery-enabled then we should build
676 * the TIM bit for all ACs anyway; if only some are then
677 * we ignore those and build the TIM bit using only the
678 * non-enabled ones.
679 */
680 if (ignore_for_tim == BIT(IEEE80211_NUM_ACS) - 1)
681 ignore_for_tim = 0;
682
9b7a86f3
JB
683 if (ignore_pending)
684 ignore_for_tim = BIT(IEEE80211_NUM_ACS) - 1;
685
948d887d
JB
686 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
687 unsigned long tids;
3e122be0 688
948d887d
JB
689 if (ignore_for_tim & BIT(ac))
690 continue;
691
692 indicate_tim |= !skb_queue_empty(&sta->tx_filtered[ac]) ||
693 !skb_queue_empty(&sta->ps_tx_buf[ac]);
694 if (indicate_tim)
695 break;
3e122be0 696
948d887d
JB
697 tids = ieee80211_tids_for_ac(ac);
698
699 indicate_tim |=
700 sta->driver_buffered_tids & tids;
ba8c3d6f
FF
701 indicate_tim |=
702 sta->txq_buffered_tids & tids;
d0709a65 703 }
004c872e 704
c868cb35 705 done:
65f704a5 706 spin_lock_bh(&local->tim_lock);
004c872e 707
3d5839b6
IP
708 if (indicate_tim == __bss_tim_get(ps->tim, id))
709 goto out_unlock;
710
948d887d 711 if (indicate_tim)
d012a605 712 __bss_tim_set(ps->tim, id);
c868cb35 713 else
d012a605 714 __bss_tim_clear(ps->tim, id);
004c872e 715
9b7a86f3 716 if (local->ops->set_tim && !WARN_ON(sta->dead)) {
c868cb35 717 local->tim_in_locked_section = true;
948d887d 718 drv_set_tim(local, &sta->sta, indicate_tim);
c868cb35
JB
719 local->tim_in_locked_section = false;
720 }
3e122be0 721
3d5839b6 722out_unlock:
65f704a5 723 spin_unlock_bh(&local->tim_lock);
004c872e
JB
724}
725
9b7a86f3
JB
726void sta_info_recalc_tim(struct sta_info *sta)
727{
728 __sta_info_recalc_tim(sta, false);
729}
730
cd0b8d89 731static bool sta_info_buffer_expired(struct sta_info *sta, struct sk_buff *skb)
f0706e82 732{
e039fa4a 733 struct ieee80211_tx_info *info;
f0706e82
JB
734 int timeout;
735
736 if (!skb)
cd0b8d89 737 return false;
f0706e82 738
e039fa4a 739 info = IEEE80211_SKB_CB(skb);
f0706e82
JB
740
741 /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */
57c4d7b4
JB
742 timeout = (sta->listen_interval *
743 sta->sdata->vif.bss_conf.beacon_int *
744 32 / 15625) * HZ;
f0706e82
JB
745 if (timeout < STA_TX_BUFFER_EXPIRE)
746 timeout = STA_TX_BUFFER_EXPIRE;
e039fa4a 747 return time_after(jiffies, info->control.jiffies + timeout);
f0706e82
JB
748}
749
750
948d887d
JB
751static bool sta_info_cleanup_expire_buffered_ac(struct ieee80211_local *local,
752 struct sta_info *sta, int ac)
f0706e82
JB
753{
754 unsigned long flags;
755 struct sk_buff *skb;
756
60750397
JB
757 /*
758 * First check for frames that should expire on the filtered
759 * queue. Frames here were rejected by the driver and are on
760 * a separate queue to avoid reordering with normal PS-buffered
761 * frames. They also aren't accounted for right now in the
762 * total_ps_buffered counter.
763 */
764 for (;;) {
948d887d
JB
765 spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
766 skb = skb_peek(&sta->tx_filtered[ac]);
60750397 767 if (sta_info_buffer_expired(sta, skb))
948d887d 768 skb = __skb_dequeue(&sta->tx_filtered[ac]);
60750397
JB
769 else
770 skb = NULL;
948d887d 771 spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
60750397
JB
772
773 /*
774 * Frames are queued in order, so if this one
775 * hasn't expired yet we can stop testing. If
776 * we actually reached the end of the queue we
777 * also need to stop, of course.
778 */
779 if (!skb)
780 break;
d4fa14cd 781 ieee80211_free_txskb(&local->hw, skb);
60750397
JB
782 }
783
784 /*
785 * Now also check the normal PS-buffered queue, this will
786 * only find something if the filtered queue was emptied
787 * since the filtered frames are all before the normal PS
788 * buffered frames.
789 */
f0706e82 790 for (;;) {
948d887d
JB
791 spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
792 skb = skb_peek(&sta->ps_tx_buf[ac]);
57c4d7b4 793 if (sta_info_buffer_expired(sta, skb))
948d887d 794 skb = __skb_dequeue(&sta->ps_tx_buf[ac]);
836341a7 795 else
f0706e82 796 skb = NULL;
948d887d 797 spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
f0706e82 798
60750397
JB
799 /*
800 * frames are queued in order, so if this one
801 * hasn't expired yet (or we reached the end of
802 * the queue) we can stop testing
803 */
836341a7 804 if (!skb)
f0706e82 805 break;
836341a7 806
836341a7 807 local->total_ps_buffered--;
bdcbd8e0
JB
808 ps_dbg(sta->sdata, "Buffered frame expired (STA %pM)\n",
809 sta->sta.addr);
d4fa14cd 810 ieee80211_free_txskb(&local->hw, skb);
f0706e82 811 }
3393a608 812
60750397
JB
813 /*
814 * Finally, recalculate the TIM bit for this station -- it might
815 * now be clear because the station was too slow to retrieve its
816 * frames.
817 */
818 sta_info_recalc_tim(sta);
819
820 /*
821 * Return whether there are any frames still buffered, this is
822 * used to check whether the cleanup timer still needs to run,
823 * if there are no frames we don't need to rearm the timer.
824 */
948d887d
JB
825 return !(skb_queue_empty(&sta->ps_tx_buf[ac]) &&
826 skb_queue_empty(&sta->tx_filtered[ac]));
827}
828
829static bool sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
830 struct sta_info *sta)
831{
832 bool have_buffered = false;
833 int ac;
834
3f52b7e3
MP
835 /* This is only necessary for stations on BSS/MBSS interfaces */
836 if (!sta->sdata->bss &&
837 !ieee80211_vif_is_mesh(&sta->sdata->vif))
948d887d
JB
838 return false;
839
840 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
841 have_buffered |=
842 sta_info_cleanup_expire_buffered_ac(local, sta, ac);
843
844 return have_buffered;
f0706e82
JB
845}
846
d778207b 847static int __must_check __sta_info_destroy_part1(struct sta_info *sta)
f0706e82 848{
34e89507
JB
849 struct ieee80211_local *local;
850 struct ieee80211_sub_if_data *sdata;
6d10e46b 851 int ret;
f0706e82 852
34e89507 853 might_sleep();
f0706e82 854
34e89507
JB
855 if (!sta)
856 return -ENOENT;
5bb644a0 857
34e89507
JB
858 local = sta->local;
859 sdata = sta->sdata;
f0706e82 860
83d5cc01
JB
861 lockdep_assert_held(&local->sta_mtx);
862
098a6070
JB
863 /*
864 * Before removing the station from the driver and
865 * rate control, it might still start new aggregation
866 * sessions -- block that to make sure the tear-down
867 * will be sufficient.
868 */
c2c98fde 869 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
c82c4a80 870 ieee80211_sta_tear_down_BA_sessions(sta, AGG_STOP_DESTROY_STA);
098a6070 871
34e89507 872 ret = sta_info_hash_del(local, sta);
b01711be 873 if (WARN_ON(ret))
34e89507
JB
874 return ret;
875
a7a6bdd0
AN
876 /*
877 * for TDLS peers, make sure to return to the base channel before
878 * removal.
879 */
880 if (test_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL)) {
881 drv_tdls_cancel_channel_switch(local, sdata, &sta->sta);
882 clear_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL);
883 }
884
794454ce 885 list_del_rcu(&sta->list);
ef044763 886 sta->removed = true;
4d33960b 887
6a9d1b91
JB
888 drv_sta_pre_rcu_remove(local, sta->sdata, sta);
889
a710c816
JB
890 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
891 rcu_access_pointer(sdata->u.vlan.sta) == sta)
892 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
893
d778207b
JB
894 return 0;
895}
896
897static void __sta_info_destroy_part2(struct sta_info *sta)
898{
899 struct ieee80211_local *local = sta->local;
900 struct ieee80211_sub_if_data *sdata = sta->sdata;
6f7a8d26 901 struct station_info sinfo = {};
d778207b
JB
902 int ret;
903
904 /*
905 * NOTE: This assumes at least synchronize_net() was done
906 * after _part1 and before _part2!
907 */
908
909 might_sleep();
910 lockdep_assert_held(&local->sta_mtx);
911
c8782078 912 /* now keys can no longer be reached */
6d10e46b 913 ieee80211_free_sta_keys(local, sta);
34e89507 914
9b7a86f3
JB
915 /* disable TIM bit - last chance to tell driver */
916 __sta_info_recalc_tim(sta, true);
917
34e89507
JB
918 sta->dead = true;
919
34e89507
JB
920 local->num_sta--;
921 local->sta_generation++;
922
83d5cc01 923 while (sta->sta_state > IEEE80211_STA_NONE) {
f09603a2
JB
924 ret = sta_info_move_state(sta, sta->sta_state - 1);
925 if (ret) {
83d5cc01
JB
926 WARN_ON_ONCE(1);
927 break;
928 }
929 }
d9a7ddb0 930
f09603a2 931 if (sta->uploaded) {
f09603a2
JB
932 ret = drv_sta_state(local, sdata, sta, IEEE80211_STA_NONE,
933 IEEE80211_STA_NOTEXIST);
934 WARN_ON_ONCE(ret != 0);
935 }
34e89507 936
bdcbd8e0
JB
937 sta_dbg(sdata, "Removed STA %pM\n", sta->sta.addr);
938
6f7a8d26
JB
939 sta_set_sinfo(sta, &sinfo);
940 cfg80211_del_sta_sinfo(sdata->dev, sta->sta.addr, &sinfo, GFP_KERNEL);
ec15e68b 941
34e89507
JB
942 rate_control_remove_sta_debugfs(sta);
943 ieee80211_sta_debugfs_remove(sta);
21f659bf 944 ieee80211_recalc_min_chandef(sdata);
34e89507 945
d34ba216 946 cleanup_single_sta(sta);
d778207b
JB
947}
948
949int __must_check __sta_info_destroy(struct sta_info *sta)
950{
951 int err = __sta_info_destroy_part1(sta);
952
953 if (err)
954 return err;
955
956 synchronize_net();
957
958 __sta_info_destroy_part2(sta);
34e89507
JB
959
960 return 0;
4d6141c3
JS
961}
962
34e89507 963int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata, const u8 *addr)
4d6141c3 964{
34e89507
JB
965 struct sta_info *sta;
966 int ret;
4d6141c3 967
34e89507 968 mutex_lock(&sdata->local->sta_mtx);
7852e361 969 sta = sta_info_get(sdata, addr);
34e89507
JB
970 ret = __sta_info_destroy(sta);
971 mutex_unlock(&sdata->local->sta_mtx);
4d6141c3
JS
972
973 return ret;
974}
975
34e89507
JB
976int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata,
977 const u8 *addr)
e9f207f0 978{
34e89507
JB
979 struct sta_info *sta;
980 int ret;
e9f207f0 981
34e89507 982 mutex_lock(&sdata->local->sta_mtx);
7852e361 983 sta = sta_info_get_bss(sdata, addr);
34e89507
JB
984 ret = __sta_info_destroy(sta);
985 mutex_unlock(&sdata->local->sta_mtx);
d0709a65 986
34e89507
JB
987 return ret;
988}
e9f207f0 989
34e89507
JB
990static void sta_info_cleanup(unsigned long data)
991{
992 struct ieee80211_local *local = (struct ieee80211_local *) data;
993 struct sta_info *sta;
3393a608 994 bool timer_needed = false;
34e89507
JB
995
996 rcu_read_lock();
997 list_for_each_entry_rcu(sta, &local->sta_list, list)
3393a608
JO
998 if (sta_info_cleanup_expire_buffered(local, sta))
999 timer_needed = true;
34e89507 1000 rcu_read_unlock();
e9f207f0 1001
34e89507
JB
1002 if (local->quiescing)
1003 return;
d0709a65 1004
3393a608
JO
1005 if (!timer_needed)
1006 return;
1007
26d59535
JB
1008 mod_timer(&local->sta_cleanup,
1009 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL));
e9f207f0 1010}
e9f207f0 1011
7bedd0cf 1012u32 sta_addr_hash(const void *key, u32 length, u32 seed)
f0706e82 1013{
7bedd0cf
JB
1014 return jhash(key, ETH_ALEN, seed);
1015}
1016
1017int sta_info_init(struct ieee80211_local *local)
1018{
1019 int err;
1020
1021 err = rhashtable_init(&local->sta_hash, &sta_rht_params);
1022 if (err)
1023 return err;
1024
4d33960b 1025 spin_lock_init(&local->tim_lock);
34e89507 1026 mutex_init(&local->sta_mtx);
f0706e82 1027 INIT_LIST_HEAD(&local->sta_list);
f0706e82 1028
b24b8a24
PE
1029 setup_timer(&local->sta_cleanup, sta_info_cleanup,
1030 (unsigned long)local);
7bedd0cf 1031 return 0;
f0706e82
JB
1032}
1033
1034void sta_info_stop(struct ieee80211_local *local)
1035{
a56f992c 1036 del_timer_sync(&local->sta_cleanup);
7bedd0cf 1037 rhashtable_destroy(&local->sta_hash);
f0706e82
JB
1038}
1039
051007d9 1040
e716251d 1041int __sta_info_flush(struct ieee80211_sub_if_data *sdata, bool vlans)
f0706e82 1042{
b998e8bb 1043 struct ieee80211_local *local = sdata->local;
f0706e82 1044 struct sta_info *sta, *tmp;
d778207b 1045 LIST_HEAD(free_list);
44213b5e 1046 int ret = 0;
f0706e82 1047
d0709a65 1048 might_sleep();
be8755e1 1049
e716251d
JB
1050 WARN_ON(vlans && sdata->vif.type != NL80211_IFTYPE_AP);
1051 WARN_ON(vlans && !sdata->bss);
1052
34e89507 1053 mutex_lock(&local->sta_mtx);
d0709a65 1054 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
e716251d
JB
1055 if (sdata == sta->sdata ||
1056 (vlans && sdata->bss == sta->sdata->bss)) {
d778207b
JB
1057 if (!WARN_ON(__sta_info_destroy_part1(sta)))
1058 list_add(&sta->free_list, &free_list);
34316837
JB
1059 ret++;
1060 }
be8755e1 1061 }
d778207b
JB
1062
1063 if (!list_empty(&free_list)) {
1064 synchronize_net();
1065 list_for_each_entry_safe(sta, tmp, &free_list, free_list)
1066 __sta_info_destroy_part2(sta);
1067 }
34e89507 1068 mutex_unlock(&local->sta_mtx);
44213b5e 1069
051007d9
JB
1070 return ret;
1071}
1072
24723d1b
JB
1073void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
1074 unsigned long exp_time)
1075{
1076 struct ieee80211_local *local = sdata->local;
1077 struct sta_info *sta, *tmp;
24723d1b 1078
34e89507 1079 mutex_lock(&local->sta_mtx);
e46a2cf9
MSS
1080
1081 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
ec2b774e
ML
1082 if (sdata != sta->sdata)
1083 continue;
1084
e5a9f8d0 1085 if (time_after(jiffies, sta->rx_stats.last_rx + exp_time)) {
eea57d42
MSS
1086 sta_dbg(sta->sdata, "expiring inactive STA %pM\n",
1087 sta->sta.addr);
3f52b7e3
MP
1088
1089 if (ieee80211_vif_is_mesh(&sdata->vif) &&
1090 test_sta_flag(sta, WLAN_STA_PS_STA))
1091 atomic_dec(&sdata->u.mesh.ps.num_sta_ps);
1092
34e89507 1093 WARN_ON(__sta_info_destroy(sta));
24723d1b 1094 }
e46a2cf9
MSS
1095 }
1096
34e89507 1097 mutex_unlock(&local->sta_mtx);
24723d1b 1098}
17741cdc 1099
686b9cb9 1100struct ieee80211_sta *ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw,
7bedd0cf
JB
1101 const u8 *addr,
1102 const u8 *localaddr)
17741cdc 1103{
7bedd0cf
JB
1104 struct ieee80211_local *local = hw_to_local(hw);
1105 struct sta_info *sta;
1106 struct rhash_head *tmp;
1107 const struct bucket_table *tbl;
1108
1109 tbl = rht_dereference_rcu(local->sta_hash.tbl, &local->sta_hash);
17741cdc 1110
686b9cb9
BG
1111 /*
1112 * Just return a random station if localaddr is NULL
1113 * ... first in list.
1114 */
7bedd0cf 1115 for_each_sta_info(local, tbl, addr, sta, tmp) {
686b9cb9 1116 if (localaddr &&
b203ca39 1117 !ether_addr_equal(sta->sdata->vif.addr, localaddr))
686b9cb9 1118 continue;
f7c65594
JB
1119 if (!sta->uploaded)
1120 return NULL;
abe60632 1121 return &sta->sta;
f7c65594
JB
1122 }
1123
abe60632 1124 return NULL;
17741cdc 1125}
686b9cb9 1126EXPORT_SYMBOL_GPL(ieee80211_find_sta_by_ifaddr);
5ed176e1
JB
1127
1128struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_vif *vif,
1129 const u8 *addr)
1130{
f7c65594 1131 struct sta_info *sta;
5ed176e1
JB
1132
1133 if (!vif)
1134 return NULL;
1135
f7c65594
JB
1136 sta = sta_info_get_bss(vif_to_sdata(vif), addr);
1137 if (!sta)
1138 return NULL;
1139
1140 if (!sta->uploaded)
1141 return NULL;
5ed176e1 1142
f7c65594 1143 return &sta->sta;
5ed176e1 1144}
17741cdc 1145EXPORT_SYMBOL(ieee80211_find_sta);
af818581 1146
e3685e03
JB
1147/* powersave support code */
1148void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
50a9432d 1149{
608383bf 1150 struct ieee80211_sub_if_data *sdata = sta->sdata;
e3685e03
JB
1151 struct ieee80211_local *local = sdata->local;
1152 struct sk_buff_head pending;
ba8c3d6f 1153 int filtered = 0, buffered = 0, ac, i;
e3685e03 1154 unsigned long flags;
d012a605
MP
1155 struct ps_data *ps;
1156
3918edb0
FF
1157 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1158 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
1159 u.ap);
1160
1161 if (sdata->vif.type == NL80211_IFTYPE_AP)
d012a605 1162 ps = &sdata->bss->ps;
3f52b7e3
MP
1163 else if (ieee80211_vif_is_mesh(&sdata->vif))
1164 ps = &sdata->u.mesh.ps;
d012a605
MP
1165 else
1166 return;
50a9432d 1167
c2c98fde 1168 clear_sta_flag(sta, WLAN_STA_SP);
47086fc5 1169
5a306f58 1170 BUILD_BUG_ON(BITS_TO_LONGS(IEEE80211_NUM_TIDS) > 1);
948d887d 1171 sta->driver_buffered_tids = 0;
ba8c3d6f 1172 sta->txq_buffered_tids = 0;
af818581 1173
30686bf7 1174 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
d057e5a3 1175 drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta);
af818581 1176
ba8c3d6f
FF
1177 if (sta->sta.txq[0]) {
1178 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
1179 struct txq_info *txqi = to_txq_info(sta->sta.txq[i]);
1180
1181 if (!skb_queue_len(&txqi->queue))
1182 continue;
1183
1184 drv_wake_tx_queue(local, txqi);
1185 }
1186 }
1187
948d887d 1188 skb_queue_head_init(&pending);
af818581 1189
1d147bfa
EG
1190 /* sync with ieee80211_tx_h_unicast_ps_buf */
1191 spin_lock(&sta->ps_lock);
af818581 1192 /* Send all buffered frames to the station */
948d887d
JB
1193 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1194 int count = skb_queue_len(&pending), tmp;
1195
987c285c 1196 spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
948d887d 1197 skb_queue_splice_tail_init(&sta->tx_filtered[ac], &pending);
987c285c 1198 spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
948d887d
JB
1199 tmp = skb_queue_len(&pending);
1200 filtered += tmp - count;
1201 count = tmp;
1202
987c285c 1203 spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
948d887d 1204 skb_queue_splice_tail_init(&sta->ps_tx_buf[ac], &pending);
987c285c 1205 spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
948d887d
JB
1206 tmp = skb_queue_len(&pending);
1207 buffered += tmp - count;
1208 }
1209
e3685e03 1210 ieee80211_add_pending_skbs(local, &pending);
5ac2e350
JB
1211
1212 /* now we're no longer in the deliver code */
1213 clear_sta_flag(sta, WLAN_STA_PS_DELIVER);
1214
1215 /* The station might have polled and then woken up before we responded,
1216 * so clear these flags now to avoid them sticking around.
1217 */
1218 clear_sta_flag(sta, WLAN_STA_PSPOLL);
1219 clear_sta_flag(sta, WLAN_STA_UAPSD);
1d147bfa 1220 spin_unlock(&sta->ps_lock);
948d887d 1221
e3685e03
JB
1222 atomic_dec(&ps->num_sta_ps);
1223
687da132 1224 /* This station just woke up and isn't aware of our SMPS state */
062f1d6d
CYY
1225 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
1226 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
687da132
EG
1227 sdata->smps_mode) &&
1228 sta->known_smps_mode != sdata->bss->req_smps &&
1229 sta_info_tx_streams(sta) != 1) {
1230 ht_dbg(sdata,
1231 "%pM just woke up and MIMO capable - update SMPS\n",
1232 sta->sta.addr);
1233 ieee80211_send_smps_action(sdata, sdata->bss->req_smps,
1234 sta->sta.addr,
1235 sdata->vif.bss_conf.bssid);
1236 }
1237
af818581
JB
1238 local->total_ps_buffered -= buffered;
1239
c868cb35
JB
1240 sta_info_recalc_tim(sta);
1241
bdcbd8e0
JB
1242 ps_dbg(sdata,
1243 "STA %pM aid %d sending %d filtered/%d PS frames since STA not sleeping anymore\n",
1244 sta->sta.addr, sta->sta.aid, filtered, buffered);
17c18bf8
JB
1245
1246 ieee80211_check_fast_xmit(sta);
af818581
JB
1247}
1248
0ead2510 1249static void ieee80211_send_null_response(struct sta_info *sta, int tid,
b77cf4f8 1250 enum ieee80211_frame_release_type reason,
0ead2510 1251 bool call_driver, bool more_data)
af818581 1252{
0ead2510 1253 struct ieee80211_sub_if_data *sdata = sta->sdata;
af818581 1254 struct ieee80211_local *local = sdata->local;
ce662b44 1255 struct ieee80211_qos_hdr *nullfunc;
af818581 1256 struct sk_buff *skb;
ce662b44
JB
1257 int size = sizeof(*nullfunc);
1258 __le16 fc;
a74a8c84 1259 bool qos = sta->sta.wme;
ce662b44 1260 struct ieee80211_tx_info *info;
55de908a 1261 struct ieee80211_chanctx_conf *chanctx_conf;
af818581 1262
ce662b44
JB
1263 if (qos) {
1264 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
1265 IEEE80211_STYPE_QOS_NULLFUNC |
1266 IEEE80211_FCTL_FROMDS);
1267 } else {
1268 size -= 2;
1269 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
1270 IEEE80211_STYPE_NULLFUNC |
1271 IEEE80211_FCTL_FROMDS);
af818581 1272 }
af818581 1273
ce662b44
JB
1274 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
1275 if (!skb)
1276 return;
1277
1278 skb_reserve(skb, local->hw.extra_tx_headroom);
1279
1280 nullfunc = (void *) skb_put(skb, size);
1281 nullfunc->frame_control = fc;
1282 nullfunc->duration_id = 0;
1283 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
1284 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1285 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
864a6040 1286 nullfunc->seq_ctrl = 0;
ce662b44 1287
59b66255
JB
1288 skb->priority = tid;
1289 skb_set_queue_mapping(skb, ieee802_1d_to_ac[tid]);
ce662b44 1290 if (qos) {
ce662b44
JB
1291 nullfunc->qos_ctrl = cpu_to_le16(tid);
1292
0ead2510 1293 if (reason == IEEE80211_FRAME_RELEASE_UAPSD) {
ce662b44
JB
1294 nullfunc->qos_ctrl |=
1295 cpu_to_le16(IEEE80211_QOS_CTL_EOSP);
0ead2510
EG
1296 if (more_data)
1297 nullfunc->frame_control |=
1298 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
1299 }
ce662b44
JB
1300 }
1301
1302 info = IEEE80211_SKB_CB(skb);
1303
1304 /*
1305 * Tell TX path to send this frame even though the
1306 * STA may still remain is PS mode after this frame
deeaee19
JB
1307 * exchange. Also set EOSP to indicate this packet
1308 * ends the poll/service period.
ce662b44 1309 */
02f2f1a9 1310 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER |
deeaee19
JB
1311 IEEE80211_TX_STATUS_EOSP |
1312 IEEE80211_TX_CTL_REQ_TX_STATUS;
ce662b44 1313
6b127c71
SM
1314 info->control.flags |= IEEE80211_TX_CTRL_PS_RESPONSE;
1315
b77cf4f8
JB
1316 if (call_driver)
1317 drv_allow_buffered_frames(local, sta, BIT(tid), 1,
1318 reason, false);
40b96408 1319
89afe614
JB
1320 skb->dev = sdata->dev;
1321
55de908a
JB
1322 rcu_read_lock();
1323 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
1324 if (WARN_ON(!chanctx_conf)) {
1325 rcu_read_unlock();
1326 kfree_skb(skb);
1327 return;
1328 }
1329
73c4e195 1330 info->band = chanctx_conf->def.chan->band;
7c10770f 1331 ieee80211_xmit(sdata, sta, skb);
55de908a 1332 rcu_read_unlock();
ce662b44
JB
1333}
1334
0a1cb809
JB
1335static int find_highest_prio_tid(unsigned long tids)
1336{
1337 /* lower 3 TIDs aren't ordered perfectly */
1338 if (tids & 0xF8)
1339 return fls(tids) - 1;
1340 /* TID 0 is BE just like TID 3 */
1341 if (tids & BIT(0))
1342 return 0;
1343 return fls(tids) - 1;
1344}
1345
0ead2510
EG
1346/* Indicates if the MORE_DATA bit should be set in the last
1347 * frame obtained by ieee80211_sta_ps_get_frames.
1348 * Note that driver_release_tids is relevant only if
1349 * reason = IEEE80211_FRAME_RELEASE_PSPOLL
1350 */
1351static bool
1352ieee80211_sta_ps_more_data(struct sta_info *sta, u8 ignored_acs,
1353 enum ieee80211_frame_release_type reason,
1354 unsigned long driver_release_tids)
1355{
1356 int ac;
1357
1358 /* If the driver has data on more than one TID then
1359 * certainly there's more data if we release just a
1360 * single frame now (from a single TID). This will
1361 * only happen for PS-Poll.
1362 */
1363 if (reason == IEEE80211_FRAME_RELEASE_PSPOLL &&
1364 hweight16(driver_release_tids) > 1)
1365 return true;
1366
1367 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1368 if (ignored_acs & BIT(ac))
1369 continue;
1370
1371 if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
1372 !skb_queue_empty(&sta->ps_tx_buf[ac]))
1373 return true;
1374 }
1375
1376 return false;
1377}
1378
47086fc5 1379static void
0ead2510
EG
1380ieee80211_sta_ps_get_frames(struct sta_info *sta, int n_frames, u8 ignored_acs,
1381 enum ieee80211_frame_release_type reason,
1382 struct sk_buff_head *frames,
1383 unsigned long *driver_release_tids)
af818581
JB
1384{
1385 struct ieee80211_sub_if_data *sdata = sta->sdata;
1386 struct ieee80211_local *local = sdata->local;
948d887d 1387 int ac;
948d887d 1388
f9f760b4 1389 /* Get response frame(s) and more data bit for the last one. */
948d887d 1390 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
4049e09a
JB
1391 unsigned long tids;
1392
47086fc5 1393 if (ignored_acs & BIT(ac))
948d887d
JB
1394 continue;
1395
4049e09a
JB
1396 tids = ieee80211_tids_for_ac(ac);
1397
f9f760b4
JB
1398 /* if we already have frames from software, then we can't also
1399 * release from hardware queues
1400 */
0ead2510
EG
1401 if (skb_queue_empty(frames)) {
1402 *driver_release_tids |=
1403 sta->driver_buffered_tids & tids;
1404 *driver_release_tids |= sta->txq_buffered_tids & tids;
ba8c3d6f 1405 }
948d887d 1406
0ead2510 1407 if (!*driver_release_tids) {
f9f760b4
JB
1408 struct sk_buff *skb;
1409
1410 while (n_frames > 0) {
1411 skb = skb_dequeue(&sta->tx_filtered[ac]);
1412 if (!skb) {
1413 skb = skb_dequeue(
1414 &sta->ps_tx_buf[ac]);
1415 if (skb)
1416 local->total_ps_buffered--;
1417 }
1418 if (!skb)
1419 break;
1420 n_frames--;
0ead2510 1421 __skb_queue_tail(frames, skb);
f9f760b4 1422 }
4049e09a 1423 }
948d887d 1424
0ead2510
EG
1425 /* If we have more frames buffered on this AC, then abort the
1426 * loop since we can't send more data from other ACs before
1427 * the buffered frames from this.
f9f760b4 1428 */
948d887d 1429 if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
0ead2510 1430 !skb_queue_empty(&sta->ps_tx_buf[ac]))
948d887d 1431 break;
af818581 1432 }
0ead2510
EG
1433}
1434
1435static void
1436ieee80211_sta_ps_deliver_response(struct sta_info *sta,
1437 int n_frames, u8 ignored_acs,
1438 enum ieee80211_frame_release_type reason)
1439{
1440 struct ieee80211_sub_if_data *sdata = sta->sdata;
1441 struct ieee80211_local *local = sdata->local;
1442 unsigned long driver_release_tids = 0;
1443 struct sk_buff_head frames;
1444 bool more_data;
1445
1446 /* Service or PS-Poll period starts */
1447 set_sta_flag(sta, WLAN_STA_SP);
1448
1449 __skb_queue_head_init(&frames);
1450
1451 ieee80211_sta_ps_get_frames(sta, n_frames, ignored_acs, reason,
1452 &frames, &driver_release_tids);
1453
1454 more_data = ieee80211_sta_ps_more_data(sta, ignored_acs, reason, driver_release_tids);
1455
1a57081a 1456 if (driver_release_tids && reason == IEEE80211_FRAME_RELEASE_PSPOLL)
0ead2510
EG
1457 driver_release_tids =
1458 BIT(find_highest_prio_tid(driver_release_tids));
af818581 1459
f9f760b4 1460 if (skb_queue_empty(&frames) && !driver_release_tids) {
ce662b44 1461 int tid;
af818581
JB
1462
1463 /*
ce662b44
JB
1464 * For PS-Poll, this can only happen due to a race condition
1465 * when we set the TIM bit and the station notices it, but
1466 * before it can poll for the frame we expire it.
1467 *
1468 * For uAPSD, this is said in the standard (11.2.1.5 h):
1469 * At each unscheduled SP for a non-AP STA, the AP shall
1470 * attempt to transmit at least one MSDU or MMPDU, but no
1471 * more than the value specified in the Max SP Length field
1472 * in the QoS Capability element from delivery-enabled ACs,
1473 * that are destined for the non-AP STA.
1474 *
1475 * Since we have no other MSDU/MMPDU, transmit a QoS null frame.
af818581 1476 */
af818581 1477
ce662b44
JB
1478 /* This will evaluate to 1, 3, 5 or 7. */
1479 tid = 7 - ((ffs(~ignored_acs) - 1) << 1);
af818581 1480
0ead2510 1481 ieee80211_send_null_response(sta, tid, reason, true, false);
f9f760b4 1482 } else if (!driver_release_tids) {
47086fc5
JB
1483 struct sk_buff_head pending;
1484 struct sk_buff *skb;
40b96408
JB
1485 int num = 0;
1486 u16 tids = 0;
b77cf4f8 1487 bool need_null = false;
af818581 1488
47086fc5 1489 skb_queue_head_init(&pending);
af818581 1490
47086fc5
JB
1491 while ((skb = __skb_dequeue(&frames))) {
1492 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1493 struct ieee80211_hdr *hdr = (void *) skb->data;
40b96408
JB
1494 u8 *qoshdr = NULL;
1495
1496 num++;
af818581 1497
47086fc5
JB
1498 /*
1499 * Tell TX path to send this frame even though the
1500 * STA may still remain is PS mode after this frame
1501 * exchange.
1502 */
6b127c71
SM
1503 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER;
1504 info->control.flags |= IEEE80211_TX_CTRL_PS_RESPONSE;
47086fc5
JB
1505
1506 /*
1507 * Use MoreData flag to indicate whether there are
1508 * more buffered frames for this STA
1509 */
24b9c373 1510 if (more_data || !skb_queue_empty(&frames))
47086fc5
JB
1511 hdr->frame_control |=
1512 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
24b9c373
JD
1513 else
1514 hdr->frame_control &=
1515 cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
47086fc5 1516
40b96408
JB
1517 if (ieee80211_is_data_qos(hdr->frame_control) ||
1518 ieee80211_is_qos_nullfunc(hdr->frame_control))
1519 qoshdr = ieee80211_get_qos_ctl(hdr);
1520
b77cf4f8 1521 tids |= BIT(skb->priority);
52a3f20c 1522
b77cf4f8
JB
1523 __skb_queue_tail(&pending, skb);
1524
1525 /* end service period after last frame or add one */
1526 if (!skb_queue_empty(&frames))
1527 continue;
1528
1529 if (reason != IEEE80211_FRAME_RELEASE_UAPSD) {
1530 /* for PS-Poll, there's only one frame */
52a3f20c
MP
1531 info->flags |= IEEE80211_TX_STATUS_EOSP |
1532 IEEE80211_TX_CTL_REQ_TX_STATUS;
b77cf4f8 1533 break;
52a3f20c 1534 }
deeaee19 1535
b77cf4f8
JB
1536 /* For uAPSD, things are a bit more complicated. If the
1537 * last frame has a QoS header (i.e. is a QoS-data or
1538 * QoS-nulldata frame) then just set the EOSP bit there
1539 * and be done.
1540 * If the frame doesn't have a QoS header (which means
1541 * it should be a bufferable MMPDU) then we can't set
1542 * the EOSP bit in the QoS header; add a QoS-nulldata
1543 * frame to the list to send it after the MMPDU.
1544 *
1545 * Note that this code is only in the mac80211-release
1546 * code path, we assume that the driver will not buffer
1547 * anything but QoS-data frames, or if it does, will
1548 * create the QoS-nulldata frame by itself if needed.
1549 *
1550 * Cf. 802.11-2012 10.2.1.10 (c).
1551 */
1552 if (qoshdr) {
1553 *qoshdr |= IEEE80211_QOS_CTL_EOSP;
40b96408 1554
b77cf4f8
JB
1555 info->flags |= IEEE80211_TX_STATUS_EOSP |
1556 IEEE80211_TX_CTL_REQ_TX_STATUS;
1557 } else {
1558 /* The standard isn't completely clear on this
1559 * as it says the more-data bit should be set
1560 * if there are more BUs. The QoS-Null frame
1561 * we're about to send isn't buffered yet, we
1562 * only create it below, but let's pretend it
1563 * was buffered just in case some clients only
1564 * expect more-data=0 when eosp=1.
1565 */
1566 hdr->frame_control |=
1567 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
1568 need_null = true;
1569 num++;
1570 }
1571 break;
47086fc5 1572 }
af818581 1573
40b96408
JB
1574 drv_allow_buffered_frames(local, sta, tids, num,
1575 reason, more_data);
1576
47086fc5 1577 ieee80211_add_pending_skbs(local, &pending);
af818581 1578
b77cf4f8
JB
1579 if (need_null)
1580 ieee80211_send_null_response(
0ead2510
EG
1581 sta, find_highest_prio_tid(tids),
1582 reason, false, false);
b77cf4f8 1583
c868cb35 1584 sta_info_recalc_tim(sta);
af818581 1585 } else {
ba8c3d6f
FF
1586 unsigned long tids = sta->txq_buffered_tids & driver_release_tids;
1587 int tid;
1588
af818581 1589 /*
4049e09a
JB
1590 * We need to release a frame that is buffered somewhere in the
1591 * driver ... it'll have to handle that.
f9f760b4
JB
1592 * Note that the driver also has to check the number of frames
1593 * on the TIDs we're releasing from - if there are more than
1594 * n_frames it has to set the more-data bit (if we didn't ask
1595 * it to set it anyway due to other buffered frames); if there
1596 * are fewer than n_frames it has to make sure to adjust that
1597 * to allow the service period to end properly.
4049e09a
JB
1598 */
1599 drv_release_buffered_frames(local, sta, driver_release_tids,
47086fc5 1600 n_frames, reason, more_data);
4049e09a
JB
1601
1602 /*
1603 * Note that we don't recalculate the TIM bit here as it would
1604 * most likely have no effect at all unless the driver told us
f9f760b4 1605 * that the TID(s) became empty before returning here from the
4049e09a 1606 * release function.
f9f760b4 1607 * Either way, however, when the driver tells us that the TID(s)
ba8c3d6f
FF
1608 * became empty or we find that a txq became empty, we'll do the
1609 * TIM recalculation.
af818581 1610 */
ba8c3d6f
FF
1611
1612 if (!sta->sta.txq[0])
1613 return;
1614
1615 for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
1616 struct txq_info *txqi = to_txq_info(sta->sta.txq[tid]);
1617
1618 if (!(tids & BIT(tid)) || skb_queue_len(&txqi->queue))
1619 continue;
1620
1621 sta_info_recalc_tim(sta);
1622 break;
1623 }
af818581
JB
1624 }
1625}
1626
47086fc5
JB
1627void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta)
1628{
1629 u8 ignore_for_response = sta->sta.uapsd_queues;
1630
1631 /*
1632 * If all ACs are delivery-enabled then we should reply
1633 * from any of them, if only some are enabled we reply
1634 * only from the non-enabled ones.
1635 */
1636 if (ignore_for_response == BIT(IEEE80211_NUM_ACS) - 1)
1637 ignore_for_response = 0;
1638
1639 ieee80211_sta_ps_deliver_response(sta, 1, ignore_for_response,
1640 IEEE80211_FRAME_RELEASE_PSPOLL);
1641}
1642
1643void ieee80211_sta_ps_deliver_uapsd(struct sta_info *sta)
1644{
1645 int n_frames = sta->sta.max_sp;
1646 u8 delivery_enabled = sta->sta.uapsd_queues;
1647
1648 /*
1649 * If we ever grow support for TSPEC this might happen if
1650 * the TSPEC update from hostapd comes in between a trigger
1651 * frame setting WLAN_STA_UAPSD in the RX path and this
1652 * actually getting called.
1653 */
1654 if (!delivery_enabled)
1655 return;
1656
47086fc5
JB
1657 switch (sta->sta.max_sp) {
1658 case 1:
1659 n_frames = 2;
1660 break;
1661 case 2:
1662 n_frames = 4;
1663 break;
1664 case 3:
1665 n_frames = 6;
1666 break;
1667 case 0:
1668 /* XXX: what is a good value? */
13a8098a 1669 n_frames = 128;
47086fc5
JB
1670 break;
1671 }
1672
1673 ieee80211_sta_ps_deliver_response(sta, n_frames, ~delivery_enabled,
1674 IEEE80211_FRAME_RELEASE_UAPSD);
1675}
1676
af818581
JB
1677void ieee80211_sta_block_awake(struct ieee80211_hw *hw,
1678 struct ieee80211_sta *pubsta, bool block)
1679{
1680 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1681
b5878a2d
JB
1682 trace_api_sta_block_awake(sta->local, pubsta, block);
1683
5ac2e350 1684 if (block) {
c2c98fde 1685 set_sta_flag(sta, WLAN_STA_PS_DRIVER);
17c18bf8 1686 ieee80211_clear_fast_xmit(sta);
5ac2e350
JB
1687 return;
1688 }
1689
1690 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1691 return;
1692
1693 if (!test_sta_flag(sta, WLAN_STA_PS_STA)) {
1694 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
1695 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
1696 ieee80211_queue_work(hw, &sta->drv_deliver_wk);
1697 } else if (test_sta_flag(sta, WLAN_STA_PSPOLL) ||
1698 test_sta_flag(sta, WLAN_STA_UAPSD)) {
1699 /* must be asleep in this case */
1700 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
1701 ieee80211_queue_work(hw, &sta->drv_deliver_wk);
1702 } else {
1703 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
17c18bf8 1704 ieee80211_check_fast_xmit(sta);
5ac2e350 1705 }
af818581
JB
1706}
1707EXPORT_SYMBOL(ieee80211_sta_block_awake);
dcf55fb5 1708
e943789e 1709void ieee80211_sta_eosp(struct ieee80211_sta *pubsta)
37fbd908
JB
1710{
1711 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1712 struct ieee80211_local *local = sta->local;
37fbd908
JB
1713
1714 trace_api_eosp(local, pubsta);
1715
e943789e 1716 clear_sta_flag(sta, WLAN_STA_SP);
37fbd908 1717}
e943789e 1718EXPORT_SYMBOL(ieee80211_sta_eosp);
37fbd908 1719
0ead2510
EG
1720void ieee80211_send_eosp_nullfunc(struct ieee80211_sta *pubsta, int tid)
1721{
1722 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1723 enum ieee80211_frame_release_type reason;
1724 bool more_data;
1725
1726 trace_api_send_eosp_nullfunc(sta->local, pubsta, tid);
1727
1728 reason = IEEE80211_FRAME_RELEASE_UAPSD;
1729 more_data = ieee80211_sta_ps_more_data(sta, ~sta->sta.uapsd_queues,
1730 reason, 0);
1731
1732 ieee80211_send_null_response(sta, tid, reason, false, more_data);
1733}
1734EXPORT_SYMBOL(ieee80211_send_eosp_nullfunc);
1735
042ec453
JB
1736void ieee80211_sta_set_buffered(struct ieee80211_sta *pubsta,
1737 u8 tid, bool buffered)
dcf55fb5
FF
1738{
1739 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1740
5a306f58 1741 if (WARN_ON(tid >= IEEE80211_NUM_TIDS))
042ec453
JB
1742 return;
1743
1b000789
JB
1744 trace_api_sta_set_buffered(sta->local, pubsta, tid, buffered);
1745
948d887d
JB
1746 if (buffered)
1747 set_bit(tid, &sta->driver_buffered_tids);
1748 else
1749 clear_bit(tid, &sta->driver_buffered_tids);
1750
c868cb35 1751 sta_info_recalc_tim(sta);
dcf55fb5 1752}
042ec453 1753EXPORT_SYMBOL(ieee80211_sta_set_buffered);
d9a7ddb0 1754
83d5cc01
JB
1755int sta_info_move_state(struct sta_info *sta,
1756 enum ieee80211_sta_state new_state)
d9a7ddb0 1757{
8bf11d8d 1758 might_sleep();
d9a7ddb0
JB
1759
1760 if (sta->sta_state == new_state)
1761 return 0;
1762
f09603a2
JB
1763 /* check allowed transitions first */
1764
1765 switch (new_state) {
1766 case IEEE80211_STA_NONE:
1767 if (sta->sta_state != IEEE80211_STA_AUTH)
1768 return -EINVAL;
1769 break;
1770 case IEEE80211_STA_AUTH:
1771 if (sta->sta_state != IEEE80211_STA_NONE &&
1772 sta->sta_state != IEEE80211_STA_ASSOC)
1773 return -EINVAL;
1774 break;
1775 case IEEE80211_STA_ASSOC:
1776 if (sta->sta_state != IEEE80211_STA_AUTH &&
1777 sta->sta_state != IEEE80211_STA_AUTHORIZED)
1778 return -EINVAL;
1779 break;
1780 case IEEE80211_STA_AUTHORIZED:
1781 if (sta->sta_state != IEEE80211_STA_ASSOC)
1782 return -EINVAL;
1783 break;
1784 default:
1785 WARN(1, "invalid state %d", new_state);
1786 return -EINVAL;
1787 }
1788
bdcbd8e0
JB
1789 sta_dbg(sta->sdata, "moving STA %pM to state %d\n",
1790 sta->sta.addr, new_state);
f09603a2
JB
1791
1792 /*
1793 * notify the driver before the actual changes so it can
1794 * fail the transition
1795 */
1796 if (test_sta_flag(sta, WLAN_STA_INSERTED)) {
1797 int err = drv_sta_state(sta->local, sta->sdata, sta,
1798 sta->sta_state, new_state);
1799 if (err)
1800 return err;
1801 }
1802
1803 /* reflect the change in all state variables */
1804
d9a7ddb0
JB
1805 switch (new_state) {
1806 case IEEE80211_STA_NONE:
1807 if (sta->sta_state == IEEE80211_STA_AUTH)
1808 clear_bit(WLAN_STA_AUTH, &sta->_flags);
d9a7ddb0
JB
1809 break;
1810 case IEEE80211_STA_AUTH:
1811 if (sta->sta_state == IEEE80211_STA_NONE)
1812 set_bit(WLAN_STA_AUTH, &sta->_flags);
1813 else if (sta->sta_state == IEEE80211_STA_ASSOC)
1814 clear_bit(WLAN_STA_ASSOC, &sta->_flags);
d9a7ddb0
JB
1815 break;
1816 case IEEE80211_STA_ASSOC:
29623892 1817 if (sta->sta_state == IEEE80211_STA_AUTH) {
d9a7ddb0 1818 set_bit(WLAN_STA_ASSOC, &sta->_flags);
29623892 1819 } else if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
7e3ed02c
FF
1820 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1821 (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1822 !sta->sdata->u.vlan.sta))
1823 atomic_dec(&sta->sdata->bss->num_mcast_sta);
d9a7ddb0 1824 clear_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
17c18bf8 1825 ieee80211_clear_fast_xmit(sta);
f09603a2 1826 }
d9a7ddb0
JB
1827 break;
1828 case IEEE80211_STA_AUTHORIZED:
29623892 1829 if (sta->sta_state == IEEE80211_STA_ASSOC) {
7e3ed02c
FF
1830 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1831 (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1832 !sta->sdata->u.vlan.sta))
1833 atomic_inc(&sta->sdata->bss->num_mcast_sta);
d9a7ddb0 1834 set_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
17c18bf8 1835 ieee80211_check_fast_xmit(sta);
f09603a2 1836 }
d9a7ddb0
JB
1837 break;
1838 default:
f09603a2 1839 break;
d9a7ddb0
JB
1840 }
1841
d9a7ddb0
JB
1842 sta->sta_state = new_state;
1843
1844 return 0;
1845}
687da132
EG
1846
1847u8 sta_info_tx_streams(struct sta_info *sta)
1848{
1849 struct ieee80211_sta_ht_cap *ht_cap = &sta->sta.ht_cap;
1850 u8 rx_streams;
1851
1852 if (!sta->sta.ht_cap.ht_supported)
1853 return 1;
1854
1855 if (sta->sta.vht_cap.vht_supported) {
1856 int i;
1857 u16 tx_mcs_map =
1858 le16_to_cpu(sta->sta.vht_cap.vht_mcs.tx_mcs_map);
1859
1860 for (i = 7; i >= 0; i--)
1861 if ((tx_mcs_map & (0x3 << (i * 2))) !=
1862 IEEE80211_VHT_MCS_NOT_SUPPORTED)
1863 return i + 1;
1864 }
1865
1866 if (ht_cap->mcs.rx_mask[3])
1867 rx_streams = 4;
1868 else if (ht_cap->mcs.rx_mask[2])
1869 rx_streams = 3;
1870 else if (ht_cap->mcs.rx_mask[1])
1871 rx_streams = 2;
1872 else
1873 rx_streams = 1;
1874
1875 if (!(ht_cap->mcs.tx_params & IEEE80211_HT_MCS_TX_RX_DIFF))
1876 return rx_streams;
1877
1878 return ((ht_cap->mcs.tx_params & IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
1879 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT) + 1;
1880}
b7ffbd7e 1881
fbd6ff5c
JB
1882static void sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
1883{
1884 rinfo->flags = 0;
1885
e5a9f8d0 1886 if (sta->rx_stats.last_rate_flag & RX_FLAG_HT) {
fbd6ff5c 1887 rinfo->flags |= RATE_INFO_FLAGS_MCS;
e5a9f8d0
JB
1888 rinfo->mcs = sta->rx_stats.last_rate_idx;
1889 } else if (sta->rx_stats.last_rate_flag & RX_FLAG_VHT) {
fbd6ff5c 1890 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
e5a9f8d0
JB
1891 rinfo->nss = sta->rx_stats.last_rate_vht_nss;
1892 rinfo->mcs = sta->rx_stats.last_rate_idx;
fbd6ff5c
JB
1893 } else {
1894 struct ieee80211_supported_band *sband;
1895 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
1896 u16 brate;
1897
1898 sband = sta->local->hw.wiphy->bands[
1899 ieee80211_get_sdata_band(sta->sdata)];
e5a9f8d0 1900 brate = sband->bitrates[sta->rx_stats.last_rate_idx].bitrate;
fbd6ff5c
JB
1901 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
1902 }
1903
e5a9f8d0 1904 if (sta->rx_stats.last_rate_flag & RX_FLAG_SHORT_GI)
fbd6ff5c
JB
1905 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
1906
e5a9f8d0 1907 if (sta->rx_stats.last_rate_flag & RX_FLAG_5MHZ)
fbd6ff5c 1908 rinfo->bw = RATE_INFO_BW_5;
e5a9f8d0 1909 else if (sta->rx_stats.last_rate_flag & RX_FLAG_10MHZ)
fbd6ff5c 1910 rinfo->bw = RATE_INFO_BW_10;
e5a9f8d0 1911 else if (sta->rx_stats.last_rate_flag & RX_FLAG_40MHZ)
fbd6ff5c 1912 rinfo->bw = RATE_INFO_BW_40;
e5a9f8d0 1913 else if (sta->rx_stats.last_rate_vht_flag & RX_VHT_FLAG_80MHZ)
fbd6ff5c 1914 rinfo->bw = RATE_INFO_BW_80;
e5a9f8d0 1915 else if (sta->rx_stats.last_rate_vht_flag & RX_VHT_FLAG_160MHZ)
fbd6ff5c
JB
1916 rinfo->bw = RATE_INFO_BW_160;
1917 else
1918 rinfo->bw = RATE_INFO_BW_20;
1919}
1920
b7ffbd7e
JB
1921void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
1922{
1923 struct ieee80211_sub_if_data *sdata = sta->sdata;
1924 struct ieee80211_local *local = sdata->local;
9a244409 1925 struct rate_control_ref *ref = NULL;
b7ffbd7e
JB
1926 u32 thr = 0;
1927 int i, ac;
1928
9a244409
JL
1929 if (test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
1930 ref = local->rate_ctrl;
1931
b7ffbd7e
JB
1932 sinfo->generation = sdata->local->sta_generation;
1933
225b8189
JB
1934 /* do before driver, so beacon filtering drivers have a
1935 * chance to e.g. just add the number of filtered beacons
1936 * (or just modify the value entirely, of course)
1937 */
1938 if (sdata->vif.type == NL80211_IFTYPE_STATION)
1939 sinfo->rx_beacon = sdata->u.mgd.count_beacon_signal;
1940
2b9a7e1b
JB
1941 drv_sta_statistics(local, sdata, &sta->sta, sinfo);
1942
319090bf
JB
1943 sinfo->filled |= BIT(NL80211_STA_INFO_INACTIVE_TIME) |
1944 BIT(NL80211_STA_INFO_STA_FLAGS) |
1945 BIT(NL80211_STA_INFO_BSS_PARAM) |
1946 BIT(NL80211_STA_INFO_CONNECTED_TIME) |
976bd9ef
JB
1947 BIT(NL80211_STA_INFO_RX_DROP_MISC);
1948
1949 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
1950 sinfo->beacon_loss_count = sdata->u.mgd.beacon_loss_count;
1951 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_LOSS);
1952 }
b7ffbd7e 1953
84b00607 1954 sinfo->connected_time = ktime_get_seconds() - sta->last_connected;
e5a9f8d0
JB
1955 sinfo->inactive_time =
1956 jiffies_to_msecs(jiffies - sta->rx_stats.last_rx);
2b9a7e1b 1957
319090bf
JB
1958 if (!(sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES64) |
1959 BIT(NL80211_STA_INFO_TX_BYTES)))) {
2b9a7e1b
JB
1960 sinfo->tx_bytes = 0;
1961 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
e5a9f8d0 1962 sinfo->tx_bytes += sta->tx_stats.bytes[ac];
319090bf 1963 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BYTES64);
2b9a7e1b
JB
1964 }
1965
319090bf 1966 if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_PACKETS))) {
2b9a7e1b
JB
1967 sinfo->tx_packets = 0;
1968 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
e5a9f8d0 1969 sinfo->tx_packets += sta->tx_stats.packets[ac];
319090bf 1970 sinfo->filled |= BIT(NL80211_STA_INFO_TX_PACKETS);
2b9a7e1b
JB
1971 }
1972
319090bf
JB
1973 if (!(sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES64) |
1974 BIT(NL80211_STA_INFO_RX_BYTES)))) {
e5a9f8d0 1975 sinfo->rx_bytes = sta->rx_stats.bytes;
319090bf 1976 sinfo->filled |= BIT(NL80211_STA_INFO_RX_BYTES64);
2b9a7e1b
JB
1977 }
1978
319090bf 1979 if (!(sinfo->filled & BIT(NL80211_STA_INFO_RX_PACKETS))) {
e5a9f8d0 1980 sinfo->rx_packets = sta->rx_stats.packets;
319090bf 1981 sinfo->filled |= BIT(NL80211_STA_INFO_RX_PACKETS);
2b9a7e1b
JB
1982 }
1983
319090bf 1984 if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_RETRIES))) {
e5a9f8d0 1985 sinfo->tx_retries = sta->status_stats.retry_count;
319090bf 1986 sinfo->filled |= BIT(NL80211_STA_INFO_TX_RETRIES);
2b9a7e1b
JB
1987 }
1988
319090bf 1989 if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_FAILED))) {
e5a9f8d0 1990 sinfo->tx_failed = sta->status_stats.retry_failed;
319090bf 1991 sinfo->filled |= BIT(NL80211_STA_INFO_TX_FAILED);
b7ffbd7e 1992 }
2b9a7e1b 1993
e5a9f8d0 1994 sinfo->rx_dropped_misc = sta->rx_stats.dropped;
b7ffbd7e 1995
225b8189
JB
1996 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1997 !(sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)) {
1998 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_RX) |
1999 BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
2000 sinfo->rx_beacon_signal_avg = ieee80211_ave_rssi(&sdata->vif);
2001 }
2002
30686bf7
JB
2003 if (ieee80211_hw_check(&sta->local->hw, SIGNAL_DBM) ||
2004 ieee80211_hw_check(&sta->local->hw, SIGNAL_UNSPEC)) {
319090bf 2005 if (!(sinfo->filled & BIT(NL80211_STA_INFO_SIGNAL))) {
e5a9f8d0 2006 sinfo->signal = (s8)sta->rx_stats.last_signal;
319090bf 2007 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
2b9a7e1b
JB
2008 }
2009
319090bf 2010 if (!(sinfo->filled & BIT(NL80211_STA_INFO_SIGNAL_AVG))) {
40d9a38a 2011 sinfo->signal_avg =
e5a9f8d0 2012 -ewma_signal_read(&sta->rx_stats.avg_signal);
319090bf 2013 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL_AVG);
2b9a7e1b 2014 }
b7ffbd7e 2015 }
2b9a7e1b 2016
e5a9f8d0 2017 if (sta->rx_stats.chains &&
319090bf
JB
2018 !(sinfo->filled & (BIT(NL80211_STA_INFO_CHAIN_SIGNAL) |
2019 BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)))) {
2020 sinfo->filled |= BIT(NL80211_STA_INFO_CHAIN_SIGNAL) |
2021 BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG);
b7ffbd7e 2022
e5a9f8d0 2023 sinfo->chains = sta->rx_stats.chains;
b7ffbd7e 2024 for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
e5a9f8d0
JB
2025 sinfo->chain_signal[i] =
2026 sta->rx_stats.chain_signal_last[i];
b7ffbd7e 2027 sinfo->chain_signal_avg[i] =
e5a9f8d0 2028 -ewma_signal_read(&sta->rx_stats.chain_signal_avg[i]);
b7ffbd7e
JB
2029 }
2030 }
2031
319090bf 2032 if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE))) {
e5a9f8d0
JB
2033 sta_set_rate_info_tx(sta, &sta->tx_stats.last_rate,
2034 &sinfo->txrate);
319090bf 2035 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE);
2b9a7e1b
JB
2036 }
2037
319090bf 2038 if (!(sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE))) {
2b9a7e1b 2039 sta_set_rate_info_rx(sta, &sinfo->rxrate);
319090bf 2040 sinfo->filled |= BIT(NL80211_STA_INFO_RX_BITRATE);
2b9a7e1b 2041 }
b7ffbd7e 2042
79c892b8
JB
2043 sinfo->filled |= BIT(NL80211_STA_INFO_TID_STATS);
2044 for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) {
2045 struct cfg80211_tid_stats *tidstats = &sinfo->pertid[i];
2046
2047 if (!(tidstats->filled & BIT(NL80211_TID_STATS_RX_MSDU))) {
2048 tidstats->filled |= BIT(NL80211_TID_STATS_RX_MSDU);
e5a9f8d0 2049 tidstats->rx_msdu = sta->rx_stats.msdu[i];
79c892b8
JB
2050 }
2051
2052 if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU))) {
2053 tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU);
e5a9f8d0 2054 tidstats->tx_msdu = sta->tx_stats.msdu[i];
79c892b8
JB
2055 }
2056
2057 if (!(tidstats->filled &
2058 BIT(NL80211_TID_STATS_TX_MSDU_RETRIES)) &&
30686bf7 2059 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
79c892b8
JB
2060 tidstats->filled |=
2061 BIT(NL80211_TID_STATS_TX_MSDU_RETRIES);
e5a9f8d0
JB
2062 tidstats->tx_msdu_retries =
2063 sta->status_stats.msdu_retries[i];
79c892b8
JB
2064 }
2065
2066 if (!(tidstats->filled &
2067 BIT(NL80211_TID_STATS_TX_MSDU_FAILED)) &&
30686bf7 2068 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
79c892b8
JB
2069 tidstats->filled |=
2070 BIT(NL80211_TID_STATS_TX_MSDU_FAILED);
e5a9f8d0
JB
2071 tidstats->tx_msdu_failed =
2072 sta->status_stats.msdu_failed[i];
79c892b8
JB
2073 }
2074 }
2075
b7ffbd7e
JB
2076 if (ieee80211_vif_is_mesh(&sdata->vif)) {
2077#ifdef CONFIG_MAC80211_MESH
319090bf
JB
2078 sinfo->filled |= BIT(NL80211_STA_INFO_LLID) |
2079 BIT(NL80211_STA_INFO_PLID) |
2080 BIT(NL80211_STA_INFO_PLINK_STATE) |
2081 BIT(NL80211_STA_INFO_LOCAL_PM) |
2082 BIT(NL80211_STA_INFO_PEER_PM) |
2083 BIT(NL80211_STA_INFO_NONPEER_PM);
b7ffbd7e 2084
433f5bc1
JB
2085 sinfo->llid = sta->mesh->llid;
2086 sinfo->plid = sta->mesh->plid;
2087 sinfo->plink_state = sta->mesh->plink_state;
b7ffbd7e 2088 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
319090bf 2089 sinfo->filled |= BIT(NL80211_STA_INFO_T_OFFSET);
433f5bc1 2090 sinfo->t_offset = sta->mesh->t_offset;
b7ffbd7e 2091 }
433f5bc1
JB
2092 sinfo->local_pm = sta->mesh->local_pm;
2093 sinfo->peer_pm = sta->mesh->peer_pm;
2094 sinfo->nonpeer_pm = sta->mesh->nonpeer_pm;
b7ffbd7e
JB
2095#endif
2096 }
2097
2098 sinfo->bss_param.flags = 0;
2099 if (sdata->vif.bss_conf.use_cts_prot)
2100 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
2101 if (sdata->vif.bss_conf.use_short_preamble)
2102 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
2103 if (sdata->vif.bss_conf.use_short_slot)
2104 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
785e21a8 2105 sinfo->bss_param.dtim_period = sdata->vif.bss_conf.dtim_period;
b7ffbd7e
JB
2106 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
2107
2108 sinfo->sta_flags.set = 0;
2109 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2110 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2111 BIT(NL80211_STA_FLAG_WME) |
2112 BIT(NL80211_STA_FLAG_MFP) |
2113 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2114 BIT(NL80211_STA_FLAG_ASSOCIATED) |
2115 BIT(NL80211_STA_FLAG_TDLS_PEER);
2116 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2117 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
2118 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
2119 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
a74a8c84 2120 if (sta->sta.wme)
b7ffbd7e
JB
2121 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
2122 if (test_sta_flag(sta, WLAN_STA_MFP))
2123 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
2124 if (test_sta_flag(sta, WLAN_STA_AUTH))
2125 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
2126 if (test_sta_flag(sta, WLAN_STA_ASSOC))
2127 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
2128 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
2129 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
2130
2131 /* check if the driver has a SW RC implementation */
2132 if (ref && ref->ops->get_expected_throughput)
2133 thr = ref->ops->get_expected_throughput(sta->rate_ctrl_priv);
2134 else
2135 thr = drv_get_expected_throughput(local, &sta->sta);
2136
2137 if (thr != 0) {
319090bf 2138 sinfo->filled |= BIT(NL80211_STA_INFO_EXPECTED_THROUGHPUT);
b7ffbd7e
JB
2139 sinfo->expected_throughput = thr;
2140 }
2141}