blob: 0800e02cce05fa4720d0251a4b8a148bccb1708c [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
Felix Fietkauba8c3d62015-03-27 21:30:37 +0100109 if (sta->sta.txq[0]) {
110 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
111 struct txq_info *txqi = to_txq_info(sta->sta.txq[i]);
112 int n = skb_queue_len(&txqi->queue);
113
114 ieee80211_purge_tx_queue(&local->hw, &txqi->queue);
115 atomic_sub(n, &sdata->txqs_len[txqi->txq.ac]);
116 }
117 }
118
Eliad Pellerb22cfcf2012-09-09 14:43:51 +0300119 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
120 local->total_ps_buffered -= skb_queue_len(&sta->ps_tx_buf[ac]);
Felix Fietkau1f98ab72012-11-10 03:44:14 +0100121 ieee80211_purge_tx_queue(&local->hw, &sta->ps_tx_buf[ac]);
122 ieee80211_purge_tx_queue(&local->hw, &sta->tx_filtered[ac]);
Eliad Pellerb22cfcf2012-09-09 14:43:51 +0300123 }
124
Thomas Pedersen45b50282013-02-06 10:17:21 -0800125 if (ieee80211_vif_is_mesh(&sdata->vif))
126 mesh_sta_cleanup(sta);
Eliad Pellerb22cfcf2012-09-09 14:43:51 +0300127
Johannes Berg5ac2e352014-05-27 16:32:27 +0200128 cancel_work_sync(&sta->drv_deliver_wk);
Eliad Pellerb22cfcf2012-09-09 14:43:51 +0300129
130 /*
131 * Destroy aggregation state here. It would be nice to wait for the
132 * driver to finish aggregation stop and then clean up, but for now
133 * drivers have to handle aggregation stop being requested, followed
134 * directly by station destruction.
135 */
Johannes Berg5a306f52012-11-14 23:22:21 +0100136 for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
Johannes Berg661eb382013-06-12 22:47:56 +0200137 kfree(sta->ampdu_mlme.tid_start_tx[i]);
Eliad Pellerb22cfcf2012-09-09 14:43:51 +0300138 tid_tx = rcu_dereference_raw(sta->ampdu_mlme.tid_tx[i]);
139 if (!tid_tx)
140 continue;
Felix Fietkau1f98ab72012-11-10 03:44:14 +0100141 ieee80211_purge_tx_queue(&local->hw, &tid_tx->pending);
Eliad Pellerb22cfcf2012-09-09 14:43:51 +0300142 kfree(tid_tx);
143 }
Johannes Berg5108ca82014-02-17 20:49:03 +0100144}
Eliad Pellerb22cfcf2012-09-09 14:43:51 +0300145
Johannes Berg5108ca82014-02-17 20:49:03 +0100146static void cleanup_single_sta(struct sta_info *sta)
147{
148 struct ieee80211_sub_if_data *sdata = sta->sdata;
149 struct ieee80211_local *local = sdata->local;
150
151 __cleanup_single_sta(sta);
Eliad Pellerb22cfcf2012-09-09 14:43:51 +0300152 sta_info_free(local, sta);
153}
154
Johannes Bergd0709a62008-02-25 16:27:46 +0100155/* protected by RCU */
Johannes Bergabe60632009-11-25 17:46:18 +0100156struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata,
157 const u8 *addr)
Johannes Berg43ba7e92008-02-21 14:09:30 +0100158{
Johannes Bergabe60632009-11-25 17:46:18 +0100159 struct ieee80211_local *local = sdata->local;
Johannes Berg43ba7e92008-02-21 14:09:30 +0100160
Johannes Berg7bedd0c2015-02-13 21:55:15 +0100161 return rhashtable_lookup_fast(&local->sta_hash, addr, sta_rht_params);
Johannes Berg43ba7e92008-02-21 14:09:30 +0100162}
163
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100164/*
165 * Get sta info either from the specified interface
166 * or from one of its vlans
167 */
168struct sta_info *sta_info_get_bss(struct ieee80211_sub_if_data *sdata,
169 const u8 *addr)
170{
171 struct ieee80211_local *local = sdata->local;
172 struct sta_info *sta;
Johannes Berg7bedd0c2015-02-13 21:55:15 +0100173 struct rhash_head *tmp;
174 const struct bucket_table *tbl;
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100175
Johannes Berg7bedd0c2015-02-13 21:55:15 +0100176 rcu_read_lock();
177 tbl = rht_dereference_rcu(local->sta_hash.tbl, &local->sta_hash);
178
179 for_each_sta_info(local, tbl, addr, sta, tmp) {
180 if (sta->sdata == sdata ||
181 (sta->sdata->bss && sta->sdata->bss == sdata->bss)) {
182 rcu_read_unlock();
183 /* this is safe as the caller must already hold
184 * another rcu read section or the mutex
185 */
186 return sta;
187 }
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100188 }
Johannes Berg7bedd0c2015-02-13 21:55:15 +0100189 rcu_read_unlock();
190 return NULL;
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100191}
192
Johannes Berg3b53fde82009-11-16 12:00:37 +0100193struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata,
194 int idx)
Luis Carlos Coboee385852008-02-23 15:17:11 +0100195{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100196 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100197 struct sta_info *sta;
198 int i = 0;
199
Johannes Bergd0709a62008-02-25 16:27:46 +0100200 list_for_each_entry_rcu(sta, &local->sta_list, list) {
Johannes Berg3b53fde82009-11-16 12:00:37 +0100201 if (sdata != sta->sdata)
Luis Carlos Cobo2a8ca292008-02-29 17:51:25 -0800202 continue;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100203 if (i < idx) {
204 ++i;
205 continue;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100206 }
Luis Carlos Cobo2a8ca292008-02-29 17:51:25 -0800207 return sta;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100208 }
Luis Carlos Coboee385852008-02-23 15:17:11 +0100209
210 return NULL;
211}
Jiri Bencf0706e82007-05-05 11:45:53 -0700212
Johannes Berg93e5deb2008-04-01 15:21:00 +0200213/**
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100214 * sta_info_free - free STA
Johannes Berg93e5deb2008-04-01 15:21:00 +0200215 *
Randy Dunlap6ef307b2008-07-03 13:52:18 -0700216 * @local: pointer to the global information
Johannes Berg93e5deb2008-04-01 15:21:00 +0200217 * @sta: STA info to free
218 *
219 * This function must undo everything done by sta_info_alloc()
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100220 * that may happen before sta_info_insert(). It may only be
221 * called when sta_info_insert() has not been attempted (and
222 * if that fails, the station is freed anyway.)
Johannes Berg93e5deb2008-04-01 15:21:00 +0200223 */
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100224void sta_info_free(struct ieee80211_local *local, struct sta_info *sta)
Johannes Berg93e5deb2008-04-01 15:21:00 +0200225{
Johannes Berg889cbb92012-01-17 10:33:29 +0100226 if (sta->rate_ctrl)
Johannes Bergaf65cd962009-11-17 18:18:36 +0100227 rate_control_free_sta(sta);
Johannes Berg93e5deb2008-04-01 15:21:00 +0200228
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200229 sta_dbg(sta->sdata, "Destroyed STA %pM\n", sta->sta.addr);
Johannes Berg93e5deb2008-04-01 15:21:00 +0200230
Felix Fietkauba8c3d62015-03-27 21:30:37 +0100231 if (sta->sta.txq[0])
232 kfree(to_txq_info(sta->sta.txq[0]));
Felix Fietkau53d04522014-05-27 22:33:57 +0200233 kfree(rcu_dereference_raw(sta->sta.rates));
Johannes Berg93e5deb2008-04-01 15:21:00 +0200234 kfree(sta);
235}
236
Johannes Berg4d339602011-12-15 11:24:20 +0100237/* Caller must hold local->sta_mtx */
Johannes Bergd0709a62008-02-25 16:27:46 +0100238static void sta_info_hash_add(struct ieee80211_local *local,
239 struct sta_info *sta)
Jiri Bencf0706e82007-05-05 11:45:53 -0700240{
Johannes Berg7bedd0c2015-02-13 21:55:15 +0100241 rhashtable_insert_fast(&local->sta_hash, &sta->hash_node,
242 sta_rht_params);
Jiri Bencf0706e82007-05-05 11:45:53 -0700243}
Jiri Bencf0706e82007-05-05 11:45:53 -0700244
Johannes Berg5ac2e352014-05-27 16:32:27 +0200245static void sta_deliver_ps_frames(struct work_struct *wk)
Johannes Bergaf818582009-11-06 11:35:50 +0100246{
247 struct sta_info *sta;
248
Johannes Berg5ac2e352014-05-27 16:32:27 +0200249 sta = container_of(wk, struct sta_info, drv_deliver_wk);
Johannes Bergaf818582009-11-06 11:35:50 +0100250
251 if (sta->dead)
252 return;
253
Johannes Berg5ac2e352014-05-27 16:32:27 +0200254 local_bh_disable();
255 if (!test_sta_flag(sta, WLAN_STA_PS_STA))
Johannes Bergaf818582009-11-06 11:35:50 +0100256 ieee80211_sta_ps_deliver_wakeup(sta);
Johannes Berg5ac2e352014-05-27 16:32:27 +0200257 else if (test_and_clear_sta_flag(sta, WLAN_STA_PSPOLL))
Johannes Bergaf818582009-11-06 11:35:50 +0100258 ieee80211_sta_ps_deliver_poll_response(sta);
Johannes Berg5ac2e352014-05-27 16:32:27 +0200259 else if (test_and_clear_sta_flag(sta, WLAN_STA_UAPSD))
Johannes Berg47086fc2011-09-29 16:04:33 +0200260 ieee80211_sta_ps_deliver_uapsd(sta);
Johannes Berg5ac2e352014-05-27 16:32:27 +0200261 local_bh_enable();
Johannes Bergaf818582009-11-06 11:35:50 +0100262}
263
Johannes Bergaf65cd962009-11-17 18:18:36 +0100264static int sta_prepare_rate_control(struct ieee80211_local *local,
265 struct sta_info *sta, gfp_t gfp)
266{
267 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
268 return 0;
269
Johannes Berg889cbb92012-01-17 10:33:29 +0100270 sta->rate_ctrl = local->rate_ctrl;
Johannes Bergaf65cd962009-11-17 18:18:36 +0100271 sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl,
Johannes Berg35c347a2015-03-05 16:10:08 +0100272 sta, gfp);
Johannes Berg889cbb92012-01-17 10:33:29 +0100273 if (!sta->rate_ctrl_priv)
Johannes Bergaf65cd962009-11-17 18:18:36 +0100274 return -ENOMEM;
Johannes Bergaf65cd962009-11-17 18:18:36 +0100275
276 return 0;
277}
278
Johannes Berg73651ee2008-02-25 16:27:47 +0100279struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
Johannes Berg56544162011-12-14 13:28:46 +0100280 const u8 *addr, gfp_t gfp)
Jiri Bencf0706e82007-05-05 11:45:53 -0700281{
Johannes Bergd0709a62008-02-25 16:27:46 +0100282 struct ieee80211_local *local = sdata->local;
Felix Fietkauba8c3d62015-03-27 21:30:37 +0100283 struct ieee80211_hw *hw = &local->hw;
Jiri Bencf0706e82007-05-05 11:45:53 -0700284 struct sta_info *sta;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530285 struct timespec uptime;
Ron Rindjunsky16c5f152007-12-25 17:00:34 +0200286 int i;
Jiri Bencf0706e82007-05-05 11:45:53 -0700287
Felix Fietkauba8c3d62015-03-27 21:30:37 +0100288 sta = kzalloc(sizeof(*sta) + hw->sta_data_size, gfp);
Jiri Bencf0706e82007-05-05 11:45:53 -0700289 if (!sta)
Johannes Berg73651ee2008-02-25 16:27:47 +0100290 return NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700291
Johannes Berg07346f812008-05-03 01:02:02 +0200292 spin_lock_init(&sta->lock);
Emmanuel Grumbach1d147bf2014-02-20 09:22:11 +0200293 spin_lock_init(&sta->ps_lock);
Johannes Berg5ac2e352014-05-27 16:32:27 +0200294 INIT_WORK(&sta->drv_deliver_wk, sta_deliver_ps_frames);
Johannes Berg67c282c2010-06-10 10:21:43 +0200295 INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work);
Johannes Berga93e3642010-06-10 10:21:46 +0200296 mutex_init(&sta->ampdu_mlme.mtx);
Thomas Pedersen87f59c72013-03-01 22:02:52 -0800297#ifdef CONFIG_MAC80211_MESH
Bob Copeland48bf6be2015-04-13 17:26:28 -0400298 spin_lock_init(&sta->plink_lock);
Thomas Pedersen87f59c72013-03-01 22:02:52 -0800299 if (ieee80211_vif_is_mesh(&sdata->vif) &&
300 !sdata->u.mesh.user_mpm)
301 init_timer(&sta->plink_timer);
Thomas Pedersen6c7c4cb2013-06-20 23:50:59 -0700302 sta->nonpeer_pm = NL80211_MESH_POWER_ACTIVE;
Thomas Pedersen87f59c72013-03-01 22:02:52 -0800303#endif
Johannes Berg07346f812008-05-03 01:02:02 +0200304
Johannes Berg17741cd2008-09-11 00:02:02 +0200305 memcpy(sta->sta.addr, addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100306 sta->local = local;
307 sta->sdata = sdata;
Felix Fietkau8bc8aec2011-03-21 20:01:00 +0100308 sta->last_rx = jiffies;
Jiri Bencf0706e82007-05-05 11:45:53 -0700309
Johannes Berg71ec3752012-01-20 13:55:20 +0100310 sta->sta_state = IEEE80211_STA_NONE;
311
Liad Kaufmanb6da9112014-11-19 13:47:38 +0200312 /* Mark TID as unreserved */
313 sta->reserved_tid = IEEE80211_TID_UNRESERVED;
314
Thomas Gleixner18171522014-06-11 23:59:14 +0000315 ktime_get_ts(&uptime);
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530316 sta->last_connected = uptime.tv_sec;
Bruno Randolf541a45a2010-12-02 19:12:43 +0900317 ewma_init(&sta->avg_signal, 1024, 8);
Felix Fietkauef0621e2013-04-22 16:29:31 +0200318 for (i = 0; i < ARRAY_SIZE(sta->chain_signal_avg); i++)
319 ewma_init(&sta->chain_signal_avg[i], 1024, 8);
Bruno Randolf541a45a2010-12-02 19:12:43 +0900320
Felix Fietkauba8c3d62015-03-27 21:30:37 +0100321 if (local->ops->wake_tx_queue) {
322 void *txq_data;
323 int size = sizeof(struct txq_info) +
324 ALIGN(hw->txq_data_size, sizeof(void *));
325
326 txq_data = kcalloc(ARRAY_SIZE(sta->sta.txq), size, gfp);
327 if (!txq_data)
328 goto free;
329
330 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
331 struct txq_info *txq = txq_data + i * size;
332
333 ieee80211_init_tx_queue(sdata, sta, txq, i);
334 }
Johannes Bergabfbc3a2015-02-25 10:03:25 +0100335 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700336
Felix Fietkauba8c3d62015-03-27 21:30:37 +0100337 if (sta_prepare_rate_control(local, sta, gfp))
338 goto free_txq;
339
Johannes Berg5a306f52012-11-14 23:22:21 +0100340 for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
Johannes Berga622ab72010-06-10 10:21:39 +0200341 /*
342 * timer_to_tid must be initialized with identity mapping
343 * to enable session_timer's data differentiation. See
344 * sta_rx_agg_session_timer_expired for usage.
345 */
Ron Rindjunsky16c5f152007-12-25 17:00:34 +0200346 sta->timer_to_tid[i] = i;
Ron Rindjunsky16c5f152007-12-25 17:00:34 +0200347 }
Johannes Berg948d8872011-09-29 16:04:29 +0200348 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
349 skb_queue_head_init(&sta->ps_tx_buf[i]);
350 skb_queue_head_init(&sta->tx_filtered[i]);
351 }
Johannes Berg73651ee2008-02-25 16:27:47 +0100352
Johannes Berg5a306f52012-11-14 23:22:21 +0100353 for (i = 0; i < IEEE80211_NUM_TIDS; i++)
Alexey Dobriyan4be929b2010-05-24 14:33:03 -0700354 sta->last_seq_ctrl[i] = cpu_to_le16(USHRT_MAX);
Senthil Balasubramaniancccaec92009-05-14 18:42:08 +0530355
Johannes Bergaf0ed692013-02-12 14:21:00 +0100356 sta->sta.smps_mode = IEEE80211_SMPS_OFF;
Emmanuel Grumbach687da132013-10-01 16:45:43 +0300357 if (sdata->vif.type == NL80211_IFTYPE_AP ||
358 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
359 struct ieee80211_supported_band *sband =
Felix Fietkauba8c3d62015-03-27 21:30:37 +0100360 hw->wiphy->bands[ieee80211_get_sdata_band(sdata)];
Emmanuel Grumbach687da132013-10-01 16:45:43 +0300361 u8 smps = (sband->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >>
362 IEEE80211_HT_CAP_SM_PS_SHIFT;
363 /*
364 * Assume that hostapd advertises our caps in the beacon and
365 * this is the known_smps_mode for a station that just assciated
366 */
367 switch (smps) {
368 case WLAN_HT_SMPS_CONTROL_DISABLED:
369 sta->known_smps_mode = IEEE80211_SMPS_OFF;
370 break;
371 case WLAN_HT_SMPS_CONTROL_STATIC:
372 sta->known_smps_mode = IEEE80211_SMPS_STATIC;
373 break;
374 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
375 sta->known_smps_mode = IEEE80211_SMPS_DYNAMIC;
376 break;
377 default:
378 WARN_ON(1);
379 }
380 }
Johannes Bergaf0ed692013-02-12 14:21:00 +0100381
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200382 sta_dbg(sdata, "Allocated STA %pM\n", sta->sta.addr);
Johannes Bergef04a292014-01-06 15:56:59 +0100383
Johannes Bergabfbc3a2015-02-25 10:03:25 +0100384 return sta;
Felix Fietkauba8c3d62015-03-27 21:30:37 +0100385
386free_txq:
387 if (sta->sta.txq[0])
388 kfree(to_txq_info(sta->sta.txq[0]));
389free:
390 kfree(sta);
391 return NULL;
Johannes Berg73651ee2008-02-25 16:27:47 +0100392}
393
Guy Eilam8c71df72011-08-17 15:18:14 +0300394static int sta_info_insert_check(struct sta_info *sta)
Johannes Berg34e89502010-02-03 13:59:58 +0100395{
Johannes Berg34e89502010-02-03 13:59:58 +0100396 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg34e89502010-02-03 13:59:58 +0100397
Johannes Berg03e44972008-02-27 09:56:40 +0100398 /*
399 * Can't be a WARN_ON because it can be triggered through a race:
400 * something inserts a STA (on one CPU) without holding the RTNL
401 * and another CPU turns off the net device.
402 */
Guy Eilam8c71df72011-08-17 15:18:14 +0300403 if (unlikely(!ieee80211_sdata_running(sdata)))
404 return -ENETDOWN;
Johannes Berg03e44972008-02-27 09:56:40 +0100405
Joe Perchesb203ca32012-05-08 18:56:52 +0000406 if (WARN_ON(ether_addr_equal(sta->sta.addr, sdata->vif.addr) ||
Guy Eilam8c71df72011-08-17 15:18:14 +0300407 is_multicast_ether_addr(sta->sta.addr)))
408 return -EINVAL;
409
410 return 0;
411}
412
Johannes Bergf09603a2012-01-20 13:55:21 +0100413static int sta_info_insert_drv_state(struct ieee80211_local *local,
414 struct ieee80211_sub_if_data *sdata,
415 struct sta_info *sta)
416{
417 enum ieee80211_sta_state state;
418 int err = 0;
419
420 for (state = IEEE80211_STA_NOTEXIST; state < sta->sta_state; state++) {
421 err = drv_sta_state(local, sdata, sta, state, state + 1);
422 if (err)
423 break;
424 }
425
426 if (!err) {
Johannes Berga4ec45a2012-01-20 13:55:22 +0100427 /*
428 * Drivers using legacy sta_add/sta_remove callbacks only
429 * get uploaded set to true after sta_add is called.
430 */
431 if (!local->ops->sta_add)
432 sta->uploaded = true;
Johannes Bergf09603a2012-01-20 13:55:21 +0100433 return 0;
434 }
435
436 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200437 sdata_info(sdata,
438 "failed to move IBSS STA %pM to state %d (%d) - keeping it anyway\n",
439 sta->sta.addr, state + 1, err);
Johannes Bergf09603a2012-01-20 13:55:21 +0100440 err = 0;
441 }
442
443 /* unwind on error */
444 for (; state > IEEE80211_STA_NOTEXIST; state--)
445 WARN_ON(drv_sta_state(local, sdata, sta, state, state - 1));
446
447 return err;
448}
449
Guy Eilam8c71df72011-08-17 15:18:14 +0300450/*
451 * should be called with sta_mtx locked
452 * this function replaces the mutex lock
453 * with a RCU lock
454 */
Johannes Berg4d339602011-12-15 11:24:20 +0100455static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU)
Guy Eilam8c71df72011-08-17 15:18:14 +0300456{
457 struct ieee80211_local *local = sta->local;
458 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg7852e362012-01-20 13:55:24 +0100459 struct station_info sinfo;
Guy Eilam8c71df72011-08-17 15:18:14 +0300460 int err = 0;
461
462 lockdep_assert_held(&local->sta_mtx);
Johannes Berg34e89502010-02-03 13:59:58 +0100463
Johannes Berg7852e362012-01-20 13:55:24 +0100464 /* check if STA exists already */
465 if (sta_info_get_bss(sdata, sta->sta.addr)) {
466 err = -EEXIST;
467 goto out_err;
Johannes Berg43ba7e92008-02-21 14:09:30 +0100468 }
Johannes Berg32bfd352007-12-19 01:31:26 +0100469
Johannes Berg7852e362012-01-20 13:55:24 +0100470 local->num_sta++;
471 local->sta_generation++;
472 smp_mb();
Johannes Berg4d339602011-12-15 11:24:20 +0100473
Johannes Berg5108ca82014-02-17 20:49:03 +0100474 /* simplify things and don't accept BA sessions yet */
475 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
476
Johannes Berg7852e362012-01-20 13:55:24 +0100477 /* make the station visible */
478 sta_info_hash_add(local, sta);
Johannes Berg4d339602011-12-15 11:24:20 +0100479
Arik Nemtsov2bad77482014-10-22 12:32:16 +0300480 list_add_tail_rcu(&sta->list, &local->sta_list);
Johannes Berg83d5cc02012-01-12 09:31:10 +0100481
Johannes Berg5108ca82014-02-17 20:49:03 +0100482 /* notify driver */
483 err = sta_info_insert_drv_state(local, sdata, sta);
484 if (err)
485 goto out_remove;
486
Johannes Berg7852e362012-01-20 13:55:24 +0100487 set_sta_flag(sta, WLAN_STA_INSERTED);
Johannes Berg5108ca82014-02-17 20:49:03 +0100488 /* accept BA sessions now */
489 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
Johannes Berg4d339602011-12-15 11:24:20 +0100490
Eliad Peller21f659b2013-11-11 20:14:01 +0200491 ieee80211_recalc_min_chandef(sdata);
Johannes Berg7852e362012-01-20 13:55:24 +0100492 ieee80211_sta_debugfs_add(sta);
493 rate_control_add_sta_debugfs(sta);
Johannes Berg4d339602011-12-15 11:24:20 +0100494
Johannes Berg7852e362012-01-20 13:55:24 +0100495 memset(&sinfo, 0, sizeof(sinfo));
496 sinfo.filled = 0;
497 sinfo.generation = local->sta_generation;
498 cfg80211_new_sta(sdata->dev, sta->sta.addr, &sinfo, GFP_KERNEL);
Johannes Bergd0709a62008-02-25 16:27:46 +0100499
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200500 sta_dbg(sdata, "Inserted STA %pM\n", sta->sta.addr);
Jiri Bencf0706e82007-05-05 11:45:53 -0700501
Johannes Berg34e89502010-02-03 13:59:58 +0100502 /* move reference to rcu-protected */
503 rcu_read_lock();
504 mutex_unlock(&local->sta_mtx);
Jiri Bence9f207f2007-05-05 11:46:38 -0700505
Johannes Berg73651ee2008-02-25 16:27:47 +0100506 if (ieee80211_vif_is_mesh(&sdata->vif))
507 mesh_accept_plinks_update(sdata);
508
509 return 0;
Johannes Berg5108ca82014-02-17 20:49:03 +0100510 out_remove:
511 sta_info_hash_del(local, sta);
512 list_del_rcu(&sta->list);
513 local->num_sta--;
514 synchronize_net();
515 __cleanup_single_sta(sta);
Johannes Berg4d339602011-12-15 11:24:20 +0100516 out_err:
517 mutex_unlock(&local->sta_mtx);
518 rcu_read_lock();
519 return err;
Guy Eilam8c71df72011-08-17 15:18:14 +0300520}
521
522int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU)
523{
524 struct ieee80211_local *local = sta->local;
Zhao, Gang308f7fc2014-04-21 12:53:00 +0800525 int err;
Guy Eilam8c71df72011-08-17 15:18:14 +0300526
Johannes Berg4d339602011-12-15 11:24:20 +0100527 might_sleep();
528
Guy Eilam8c71df72011-08-17 15:18:14 +0300529 err = sta_info_insert_check(sta);
530 if (err) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700531 rcu_read_lock();
532 goto out_free;
533 }
534
Johannes Berg004c8722008-02-20 11:21:35 +0100535 mutex_lock(&local->sta_mtx);
536
Johannes Berg4d339602011-12-15 11:24:20 +0100537 err = sta_info_insert_finish(sta);
Guy Eilam8c71df72011-08-17 15:18:14 +0300538 if (err)
Johannes Berg004c8722008-02-20 11:21:35 +0100539 goto out_free;
Johannes Bergd0709a62008-02-25 16:27:46 +0100540
Johannes Berg004c8722008-02-20 11:21:35 +0100541 return 0;
Johannes Berg93e5deb2008-04-01 15:21:00 +0200542 out_free:
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100543 sta_info_free(local, sta);
Johannes Berg93e5deb2008-04-01 15:21:00 +0200544 return err;
Jiri Bencf0706e82007-05-05 11:45:53 -0700545}
546
Johannes Berg34e89502010-02-03 13:59:58 +0100547int sta_info_insert(struct sta_info *sta)
548{
549 int err = sta_info_insert_rcu(sta);
550
551 rcu_read_unlock();
552
553 return err;
554}
555
Marco Porschd012a602012-10-10 12:39:50 -0700556static inline void __bss_tim_set(u8 *tim, u16 id)
Johannes Berg004c8722008-02-20 11:21:35 +0100557{
558 /*
559 * This format has been mandated by the IEEE specifications,
560 * so this line may not be changed to use the __set_bit() format.
561 */
Marco Porschd012a602012-10-10 12:39:50 -0700562 tim[id / 8] |= (1 << (id % 8));
Johannes Berg004c8722008-02-20 11:21:35 +0100563}
564
Marco Porschd012a602012-10-10 12:39:50 -0700565static inline void __bss_tim_clear(u8 *tim, u16 id)
Johannes Berg004c8722008-02-20 11:21:35 +0100566{
567 /*
568 * This format has been mandated by the IEEE specifications,
569 * so this line may not be changed to use the __clear_bit() format.
570 */
Marco Porschd012a602012-10-10 12:39:50 -0700571 tim[id / 8] &= ~(1 << (id % 8));
Johannes Berg004c8722008-02-20 11:21:35 +0100572}
573
Ilan Peer3d5839b2013-03-05 15:27:20 +0200574static inline bool __bss_tim_get(u8 *tim, u16 id)
575{
576 /*
577 * This format has been mandated by the IEEE specifications,
578 * so this line may not be changed to use the test_bit() format.
579 */
580 return tim[id / 8] & (1 << (id % 8));
581}
582
Johannes Berg948d8872011-09-29 16:04:29 +0200583static unsigned long ieee80211_tids_for_ac(int ac)
Johannes Berg004c8722008-02-20 11:21:35 +0100584{
Johannes Berg948d8872011-09-29 16:04:29 +0200585 /* If we ever support TIDs > 7, this obviously needs to be adjusted */
586 switch (ac) {
587 case IEEE80211_AC_VO:
588 return BIT(6) | BIT(7);
589 case IEEE80211_AC_VI:
590 return BIT(4) | BIT(5);
591 case IEEE80211_AC_BE:
592 return BIT(0) | BIT(3);
593 case IEEE80211_AC_BK:
594 return BIT(1) | BIT(2);
595 default:
596 WARN_ON(1);
597 return 0;
Johannes Bergd0709a62008-02-25 16:27:46 +0100598 }
Johannes Berg004c8722008-02-20 11:21:35 +0100599}
600
Johannes Berg9b7a86f2015-01-09 11:40:39 +0100601static void __sta_info_recalc_tim(struct sta_info *sta, bool ignore_pending)
Johannes Berg004c8722008-02-20 11:21:35 +0100602{
Johannes Bergc868cb352011-09-29 16:04:27 +0200603 struct ieee80211_local *local = sta->local;
Marco Porschd012a602012-10-10 12:39:50 -0700604 struct ps_data *ps;
Johannes Berg948d8872011-09-29 16:04:29 +0200605 bool indicate_tim = false;
606 u8 ignore_for_tim = sta->sta.uapsd_queues;
607 int ac;
Marco Porschd012a602012-10-10 12:39:50 -0700608 u16 id;
Johannes Berg004c8722008-02-20 11:21:35 +0100609
Marco Porschd012a602012-10-10 12:39:50 -0700610 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
611 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
612 if (WARN_ON_ONCE(!sta->sdata->bss))
613 return;
614
615 ps = &sta->sdata->bss->ps;
616 id = sta->sta.aid;
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100617#ifdef CONFIG_MAC80211_MESH
618 } else if (ieee80211_vif_is_mesh(&sta->sdata->vif)) {
619 ps = &sta->sdata->u.mesh.ps;
Thomas Pedersen204d1302013-11-05 11:17:05 -0800620 /* TIM map only for 1 <= PLID <= IEEE80211_MAX_AID */
Chun-Yeow Yeoh6f101ef2013-11-13 15:43:03 +0800621 id = sta->plid % (IEEE80211_MAX_AID + 1);
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100622#endif
Marco Porschd012a602012-10-10 12:39:50 -0700623 } else {
Johannes Bergc868cb352011-09-29 16:04:27 +0200624 return;
Marco Porschd012a602012-10-10 12:39:50 -0700625 }
Johannes Berg3e122be2008-07-09 14:40:34 +0200626
Johannes Bergc868cb352011-09-29 16:04:27 +0200627 /* No need to do anything if the driver does all */
628 if (local->hw.flags & IEEE80211_HW_AP_LINK_PS)
629 return;
Johannes Berg004c8722008-02-20 11:21:35 +0100630
Johannes Bergc868cb352011-09-29 16:04:27 +0200631 if (sta->dead)
632 goto done;
Johannes Berg3e122be2008-07-09 14:40:34 +0200633
Johannes Berg948d8872011-09-29 16:04:29 +0200634 /*
635 * If all ACs are delivery-enabled then we should build
636 * the TIM bit for all ACs anyway; if only some are then
637 * we ignore those and build the TIM bit using only the
638 * non-enabled ones.
639 */
640 if (ignore_for_tim == BIT(IEEE80211_NUM_ACS) - 1)
641 ignore_for_tim = 0;
Johannes Berg3e122be2008-07-09 14:40:34 +0200642
Johannes Berg9b7a86f2015-01-09 11:40:39 +0100643 if (ignore_pending)
644 ignore_for_tim = BIT(IEEE80211_NUM_ACS) - 1;
645
Johannes Berg948d8872011-09-29 16:04:29 +0200646 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
647 unsigned long tids;
648
649 if (ignore_for_tim & BIT(ac))
650 continue;
651
652 indicate_tim |= !skb_queue_empty(&sta->tx_filtered[ac]) ||
653 !skb_queue_empty(&sta->ps_tx_buf[ac]);
654 if (indicate_tim)
655 break;
656
657 tids = ieee80211_tids_for_ac(ac);
658
659 indicate_tim |=
660 sta->driver_buffered_tids & tids;
Felix Fietkauba8c3d62015-03-27 21:30:37 +0100661 indicate_tim |=
662 sta->txq_buffered_tids & tids;
Johannes Bergd0709a62008-02-25 16:27:46 +0100663 }
Johannes Berg004c8722008-02-20 11:21:35 +0100664
Johannes Bergc868cb352011-09-29 16:04:27 +0200665 done:
Johannes Berg65f704a2013-02-13 17:39:53 +0100666 spin_lock_bh(&local->tim_lock);
Johannes Berg004c8722008-02-20 11:21:35 +0100667
Ilan Peer3d5839b2013-03-05 15:27:20 +0200668 if (indicate_tim == __bss_tim_get(ps->tim, id))
669 goto out_unlock;
670
Johannes Berg948d8872011-09-29 16:04:29 +0200671 if (indicate_tim)
Marco Porschd012a602012-10-10 12:39:50 -0700672 __bss_tim_set(ps->tim, id);
Johannes Bergc868cb352011-09-29 16:04:27 +0200673 else
Marco Porschd012a602012-10-10 12:39:50 -0700674 __bss_tim_clear(ps->tim, id);
Johannes Berg3e122be2008-07-09 14:40:34 +0200675
Johannes Berg9b7a86f2015-01-09 11:40:39 +0100676 if (local->ops->set_tim && !WARN_ON(sta->dead)) {
Johannes Bergc868cb352011-09-29 16:04:27 +0200677 local->tim_in_locked_section = true;
Johannes Berg948d8872011-09-29 16:04:29 +0200678 drv_set_tim(local, &sta->sta, indicate_tim);
Johannes Bergc868cb352011-09-29 16:04:27 +0200679 local->tim_in_locked_section = false;
Johannes Berg004c8722008-02-20 11:21:35 +0100680 }
Johannes Berg004c8722008-02-20 11:21:35 +0100681
Ilan Peer3d5839b2013-03-05 15:27:20 +0200682out_unlock:
Johannes Berg65f704a2013-02-13 17:39:53 +0100683 spin_unlock_bh(&local->tim_lock);
Johannes Berg004c8722008-02-20 11:21:35 +0100684}
685
Johannes Berg9b7a86f2015-01-09 11:40:39 +0100686void sta_info_recalc_tim(struct sta_info *sta)
687{
688 __sta_info_recalc_tim(sta, false);
689}
690
Johannes Bergcd0b8d82011-09-06 14:13:06 +0200691static bool sta_info_buffer_expired(struct sta_info *sta, struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -0700692{
Johannes Berge039fa42008-05-15 12:55:29 +0200693 struct ieee80211_tx_info *info;
Jiri Bencf0706e82007-05-05 11:45:53 -0700694 int timeout;
695
696 if (!skb)
Johannes Bergcd0b8d82011-09-06 14:13:06 +0200697 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -0700698
Johannes Berge039fa42008-05-15 12:55:29 +0200699 info = IEEE80211_SKB_CB(skb);
Jiri Bencf0706e82007-05-05 11:45:53 -0700700
701 /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */
Johannes Berg57c4d7b2009-04-23 16:10:04 +0200702 timeout = (sta->listen_interval *
703 sta->sdata->vif.bss_conf.beacon_int *
704 32 / 15625) * HZ;
Jiri Bencf0706e82007-05-05 11:45:53 -0700705 if (timeout < STA_TX_BUFFER_EXPIRE)
706 timeout = STA_TX_BUFFER_EXPIRE;
Johannes Berge039fa42008-05-15 12:55:29 +0200707 return time_after(jiffies, info->control.jiffies + timeout);
Jiri Bencf0706e82007-05-05 11:45:53 -0700708}
709
710
Johannes Berg948d8872011-09-29 16:04:29 +0200711static bool sta_info_cleanup_expire_buffered_ac(struct ieee80211_local *local,
712 struct sta_info *sta, int ac)
Jiri Bencf0706e82007-05-05 11:45:53 -0700713{
714 unsigned long flags;
715 struct sk_buff *skb;
716
Johannes Berg60750392011-09-29 16:04:28 +0200717 /*
718 * First check for frames that should expire on the filtered
719 * queue. Frames here were rejected by the driver and are on
720 * a separate queue to avoid reordering with normal PS-buffered
721 * frames. They also aren't accounted for right now in the
722 * total_ps_buffered counter.
723 */
Jiri Bencf0706e82007-05-05 11:45:53 -0700724 for (;;) {
Johannes Berg948d8872011-09-29 16:04:29 +0200725 spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
726 skb = skb_peek(&sta->tx_filtered[ac]);
Johannes Berg57c4d7b2009-04-23 16:10:04 +0200727 if (sta_info_buffer_expired(sta, skb))
Johannes Berg948d8872011-09-29 16:04:29 +0200728 skb = __skb_dequeue(&sta->tx_filtered[ac]);
Johannes Berg836341a2008-02-20 02:07:21 +0100729 else
Jiri Bencf0706e82007-05-05 11:45:53 -0700730 skb = NULL;
Johannes Berg948d8872011-09-29 16:04:29 +0200731 spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
Jiri Bencf0706e82007-05-05 11:45:53 -0700732
Johannes Berg60750392011-09-29 16:04:28 +0200733 /*
734 * Frames are queued in order, so if this one
735 * hasn't expired yet we can stop testing. If
736 * we actually reached the end of the queue we
737 * also need to stop, of course.
738 */
739 if (!skb)
740 break;
Felix Fietkaud4fa14c2012-10-10 22:40:23 +0200741 ieee80211_free_txskb(&local->hw, skb);
Johannes Berg60750392011-09-29 16:04:28 +0200742 }
743
744 /*
745 * Now also check the normal PS-buffered queue, this will
746 * only find something if the filtered queue was emptied
747 * since the filtered frames are all before the normal PS
748 * buffered frames.
749 */
Jiri Bencf0706e82007-05-05 11:45:53 -0700750 for (;;) {
Johannes Berg948d8872011-09-29 16:04:29 +0200751 spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
752 skb = skb_peek(&sta->ps_tx_buf[ac]);
Jiri Bencf0706e82007-05-05 11:45:53 -0700753 if (sta_info_buffer_expired(sta, skb))
Johannes Berg948d8872011-09-29 16:04:29 +0200754 skb = __skb_dequeue(&sta->ps_tx_buf[ac]);
Jiri Bencf0706e82007-05-05 11:45:53 -0700755 else
756 skb = NULL;
Johannes Berg948d8872011-09-29 16:04:29 +0200757 spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
Jiri Bencf0706e82007-05-05 11:45:53 -0700758
Johannes Berg60750392011-09-29 16:04:28 +0200759 /*
760 * frames are queued in order, so if this one
761 * hasn't expired yet (or we reached the end of
762 * the queue) we can stop testing
763 */
Johannes Berg836341a2008-02-20 02:07:21 +0100764 if (!skb)
Jiri Bencf0706e82007-05-05 11:45:53 -0700765 break;
Johannes Berg836341a2008-02-20 02:07:21 +0100766
Johannes Berg836341a2008-02-20 02:07:21 +0100767 local->total_ps_buffered--;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200768 ps_dbg(sta->sdata, "Buffered frame expired (STA %pM)\n",
769 sta->sta.addr);
Felix Fietkaud4fa14c2012-10-10 22:40:23 +0200770 ieee80211_free_txskb(&local->hw, skb);
Jiri Bencf0706e82007-05-05 11:45:53 -0700771 }
Juuso Oikarinen3393a602010-04-19 10:12:52 +0300772
Johannes Berg60750392011-09-29 16:04:28 +0200773 /*
774 * Finally, recalculate the TIM bit for this station -- it might
775 * now be clear because the station was too slow to retrieve its
776 * frames.
777 */
778 sta_info_recalc_tim(sta);
779
780 /*
781 * Return whether there are any frames still buffered, this is
782 * used to check whether the cleanup timer still needs to run,
783 * if there are no frames we don't need to rearm the timer.
784 */
Johannes Berg948d8872011-09-29 16:04:29 +0200785 return !(skb_queue_empty(&sta->ps_tx_buf[ac]) &&
786 skb_queue_empty(&sta->tx_filtered[ac]));
787}
788
789static bool sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
790 struct sta_info *sta)
791{
792 bool have_buffered = false;
793 int ac;
794
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100795 /* This is only necessary for stations on BSS/MBSS interfaces */
796 if (!sta->sdata->bss &&
797 !ieee80211_vif_is_mesh(&sta->sdata->vif))
Johannes Berg948d8872011-09-29 16:04:29 +0200798 return false;
799
800 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
801 have_buffered |=
802 sta_info_cleanup_expire_buffered_ac(local, sta, ac);
803
804 return have_buffered;
Jiri Bencf0706e82007-05-05 11:45:53 -0700805}
806
Johannes Bergd7782072013-12-04 23:12:31 +0100807static int __must_check __sta_info_destroy_part1(struct sta_info *sta)
Johannes Berg34e89502010-02-03 13:59:58 +0100808{
809 struct ieee80211_local *local;
810 struct ieee80211_sub_if_data *sdata;
Johannes Berg6d10e462013-03-06 23:09:11 +0100811 int ret;
Johannes Berg34e89502010-02-03 13:59:58 +0100812
813 might_sleep();
814
815 if (!sta)
816 return -ENOENT;
817
818 local = sta->local;
819 sdata = sta->sdata;
820
Johannes Berg83d5cc02012-01-12 09:31:10 +0100821 lockdep_assert_held(&local->sta_mtx);
822
Johannes Berg098a6072010-04-06 11:18:47 +0200823 /*
824 * Before removing the station from the driver and
825 * rate control, it might still start new aggregation
826 * sessions -- block that to make sure the tear-down
827 * will be sufficient.
828 */
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200829 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
Johannes Bergc82c4a82012-07-18 13:31:31 +0200830 ieee80211_sta_tear_down_BA_sessions(sta, AGG_STOP_DESTROY_STA);
Johannes Berg098a6072010-04-06 11:18:47 +0200831
Johannes Berg34e89502010-02-03 13:59:58 +0100832 ret = sta_info_hash_del(local, sta);
Johannes Bergb01711b2013-12-04 20:25:27 +0100833 if (WARN_ON(ret))
Johannes Berg34e89502010-02-03 13:59:58 +0100834 return ret;
835
Arik Nemtsova7a6bdd2014-11-09 18:50:19 +0200836 /*
837 * for TDLS peers, make sure to return to the base channel before
838 * removal.
839 */
840 if (test_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL)) {
841 drv_tdls_cancel_channel_switch(local, sdata, &sta->sta);
842 clear_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL);
843 }
844
Arik Nemtsov794454c2012-06-03 23:32:32 +0300845 list_del_rcu(&sta->list);
Johannes Berg4d339602011-12-15 11:24:20 +0100846
Johannes Berg6a9d1b92013-12-04 22:39:17 +0100847 drv_sta_pre_rcu_remove(local, sta->sdata, sta);
848
Johannes Berga710c812013-12-04 20:11:06 +0100849 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
850 rcu_access_pointer(sdata->u.vlan.sta) == sta)
851 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
852
Johannes Bergd7782072013-12-04 23:12:31 +0100853 return 0;
854}
855
856static void __sta_info_destroy_part2(struct sta_info *sta)
857{
858 struct ieee80211_local *local = sta->local;
859 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg6f7a8d22014-11-14 20:32:57 +0100860 struct station_info sinfo = {};
Johannes Bergd7782072013-12-04 23:12:31 +0100861 int ret;
862
863 /*
864 * NOTE: This assumes at least synchronize_net() was done
865 * after _part1 and before _part2!
866 */
867
868 might_sleep();
869 lockdep_assert_held(&local->sta_mtx);
870
Johannes Bergc8782072013-12-04 23:05:45 +0100871 /* now keys can no longer be reached */
Johannes Berg6d10e462013-03-06 23:09:11 +0100872 ieee80211_free_sta_keys(local, sta);
Johannes Berg34e89502010-02-03 13:59:58 +0100873
Johannes Berg9b7a86f2015-01-09 11:40:39 +0100874 /* disable TIM bit - last chance to tell driver */
875 __sta_info_recalc_tim(sta, true);
876
Johannes Berg34e89502010-02-03 13:59:58 +0100877 sta->dead = true;
878
Johannes Berg34e89502010-02-03 13:59:58 +0100879 local->num_sta--;
880 local->sta_generation++;
881
Johannes Berg83d5cc02012-01-12 09:31:10 +0100882 while (sta->sta_state > IEEE80211_STA_NONE) {
Johannes Bergf09603a2012-01-20 13:55:21 +0100883 ret = sta_info_move_state(sta, sta->sta_state - 1);
884 if (ret) {
Johannes Berg83d5cc02012-01-12 09:31:10 +0100885 WARN_ON_ONCE(1);
886 break;
887 }
888 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100889
Johannes Bergf09603a2012-01-20 13:55:21 +0100890 if (sta->uploaded) {
Johannes Bergf09603a2012-01-20 13:55:21 +0100891 ret = drv_sta_state(local, sdata, sta, IEEE80211_STA_NONE,
892 IEEE80211_STA_NOTEXIST);
893 WARN_ON_ONCE(ret != 0);
894 }
Johannes Berg34e89502010-02-03 13:59:58 +0100895
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200896 sta_dbg(sdata, "Removed STA %pM\n", sta->sta.addr);
897
Johannes Berg6f7a8d22014-11-14 20:32:57 +0100898 sta_set_sinfo(sta, &sinfo);
899 cfg80211_del_sta_sinfo(sdata->dev, sta->sta.addr, &sinfo, GFP_KERNEL);
Jouni Malinenec15e682011-03-23 15:29:52 +0200900
Johannes Berg34e89502010-02-03 13:59:58 +0100901 rate_control_remove_sta_debugfs(sta);
902 ieee80211_sta_debugfs_remove(sta);
Eliad Peller21f659b2013-11-11 20:14:01 +0200903 ieee80211_recalc_min_chandef(sdata);
Johannes Berg34e89502010-02-03 13:59:58 +0100904
Johannes Bergd34ba212013-12-04 22:46:11 +0100905 cleanup_single_sta(sta);
Johannes Bergd7782072013-12-04 23:12:31 +0100906}
907
908int __must_check __sta_info_destroy(struct sta_info *sta)
909{
910 int err = __sta_info_destroy_part1(sta);
911
912 if (err)
913 return err;
914
915 synchronize_net();
916
917 __sta_info_destroy_part2(sta);
Johannes Berg34e89502010-02-03 13:59:58 +0100918
919 return 0;
920}
921
922int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata, const u8 *addr)
923{
924 struct sta_info *sta;
925 int ret;
926
927 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg7852e362012-01-20 13:55:24 +0100928 sta = sta_info_get(sdata, addr);
Johannes Berg34e89502010-02-03 13:59:58 +0100929 ret = __sta_info_destroy(sta);
930 mutex_unlock(&sdata->local->sta_mtx);
931
932 return ret;
933}
934
935int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata,
936 const u8 *addr)
937{
938 struct sta_info *sta;
939 int ret;
940
941 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg7852e362012-01-20 13:55:24 +0100942 sta = sta_info_get_bss(sdata, addr);
Johannes Berg34e89502010-02-03 13:59:58 +0100943 ret = __sta_info_destroy(sta);
944 mutex_unlock(&sdata->local->sta_mtx);
945
946 return ret;
947}
Jiri Bencf0706e82007-05-05 11:45:53 -0700948
949static void sta_info_cleanup(unsigned long data)
950{
951 struct ieee80211_local *local = (struct ieee80211_local *) data;
952 struct sta_info *sta;
Juuso Oikarinen3393a602010-04-19 10:12:52 +0300953 bool timer_needed = false;
Jiri Bencf0706e82007-05-05 11:45:53 -0700954
Johannes Bergd0709a62008-02-25 16:27:46 +0100955 rcu_read_lock();
956 list_for_each_entry_rcu(sta, &local->sta_list, list)
Juuso Oikarinen3393a602010-04-19 10:12:52 +0300957 if (sta_info_cleanup_expire_buffered(local, sta))
958 timer_needed = true;
Johannes Bergd0709a62008-02-25 16:27:46 +0100959 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -0700960
Johannes Berg5bb644a2009-05-17 11:40:42 +0200961 if (local->quiescing)
962 return;
963
Juuso Oikarinen3393a602010-04-19 10:12:52 +0300964 if (!timer_needed)
965 return;
966
Johannes Berg26d59532011-04-01 13:52:48 +0200967 mod_timer(&local->sta_cleanup,
968 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL));
Jiri Bencf0706e82007-05-05 11:45:53 -0700969}
970
Johannes Berg7bedd0c2015-02-13 21:55:15 +0100971u32 sta_addr_hash(const void *key, u32 length, u32 seed)
Jiri Bencf0706e82007-05-05 11:45:53 -0700972{
Johannes Berg7bedd0c2015-02-13 21:55:15 +0100973 return jhash(key, ETH_ALEN, seed);
974}
975
976int sta_info_init(struct ieee80211_local *local)
977{
978 int err;
979
980 err = rhashtable_init(&local->sta_hash, &sta_rht_params);
981 if (err)
982 return err;
983
Johannes Berg4d339602011-12-15 11:24:20 +0100984 spin_lock_init(&local->tim_lock);
Johannes Berg34e89502010-02-03 13:59:58 +0100985 mutex_init(&local->sta_mtx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700986 INIT_LIST_HEAD(&local->sta_list);
Jiri Bencf0706e82007-05-05 11:45:53 -0700987
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -0800988 setup_timer(&local->sta_cleanup, sta_info_cleanup,
989 (unsigned long)local);
Johannes Berg7bedd0c2015-02-13 21:55:15 +0100990 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700991}
992
993void sta_info_stop(struct ieee80211_local *local)
994{
Johannes Berga56f9922012-12-13 23:08:52 +0100995 del_timer_sync(&local->sta_cleanup);
Johannes Berg7bedd0c2015-02-13 21:55:15 +0100996 rhashtable_destroy(&local->sta_hash);
Jiri Bencf0706e82007-05-05 11:45:53 -0700997}
998
Johannes Berg051007d2012-12-13 23:49:02 +0100999
Johannes Berge7162512013-12-04 23:18:37 +01001000int __sta_info_flush(struct ieee80211_sub_if_data *sdata, bool vlans)
Jiri Bencf0706e82007-05-05 11:45:53 -07001001{
Johannes Bergb998e8b2012-12-13 23:07:46 +01001002 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001003 struct sta_info *sta, *tmp;
Johannes Bergd7782072013-12-04 23:12:31 +01001004 LIST_HEAD(free_list);
Johannes Berg44213b52008-02-25 16:27:49 +01001005 int ret = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001006
Johannes Bergd0709a62008-02-25 16:27:46 +01001007 might_sleep();
1008
Johannes Berge7162512013-12-04 23:18:37 +01001009 WARN_ON(vlans && sdata->vif.type != NL80211_IFTYPE_AP);
1010 WARN_ON(vlans && !sdata->bss);
1011
Johannes Berg34e89502010-02-03 13:59:58 +01001012 mutex_lock(&local->sta_mtx);
Johannes Berg34e89502010-02-03 13:59:58 +01001013 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
Johannes Berge7162512013-12-04 23:18:37 +01001014 if (sdata == sta->sdata ||
1015 (vlans && sdata->bss == sta->sdata->bss)) {
Johannes Bergd7782072013-12-04 23:12:31 +01001016 if (!WARN_ON(__sta_info_destroy_part1(sta)))
1017 list_add(&sta->free_list, &free_list);
Johannes Berg34316832012-02-25 21:40:46 +01001018 ret++;
1019 }
Johannes Berg34e89502010-02-03 13:59:58 +01001020 }
Johannes Bergd7782072013-12-04 23:12:31 +01001021
1022 if (!list_empty(&free_list)) {
1023 synchronize_net();
1024 list_for_each_entry_safe(sta, tmp, &free_list, free_list)
1025 __sta_info_destroy_part2(sta);
1026 }
Johannes Berg34e89502010-02-03 13:59:58 +01001027 mutex_unlock(&local->sta_mtx);
Johannes Berg44213b52008-02-25 16:27:49 +01001028
Johannes Berg051007d2012-12-13 23:49:02 +01001029 return ret;
1030}
1031
Johannes Berg24723d12008-09-11 00:01:46 +02001032void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
1033 unsigned long exp_time)
1034{
1035 struct ieee80211_local *local = sdata->local;
1036 struct sta_info *sta, *tmp;
Johannes Berg24723d12008-09-11 00:01:46 +02001037
Johannes Berg34e89502010-02-03 13:59:58 +01001038 mutex_lock(&local->sta_mtx);
Mohammed Shafi Shajakhane46a2cf2011-12-26 10:43:29 +05301039
1040 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
Marek Lindnerec2b7742011-12-20 23:16:52 +08001041 if (sdata != sta->sdata)
1042 continue;
1043
Johannes Berg24723d12008-09-11 00:01:46 +02001044 if (time_after(jiffies, sta->last_rx + exp_time)) {
Mohammed Shafi Shajakhaneea57d42012-10-08 21:33:47 +05301045 sta_dbg(sta->sdata, "expiring inactive STA %pM\n",
1046 sta->sta.addr);
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001047
1048 if (ieee80211_vif_is_mesh(&sdata->vif) &&
1049 test_sta_flag(sta, WLAN_STA_PS_STA))
1050 atomic_dec(&sdata->u.mesh.ps.num_sta_ps);
1051
Johannes Berg34e89502010-02-03 13:59:58 +01001052 WARN_ON(__sta_info_destroy(sta));
Johannes Berg24723d12008-09-11 00:01:46 +02001053 }
Mohammed Shafi Shajakhane46a2cf2011-12-26 10:43:29 +05301054 }
1055
Johannes Berg34e89502010-02-03 13:59:58 +01001056 mutex_unlock(&local->sta_mtx);
Johannes Berg24723d12008-09-11 00:01:46 +02001057}
Johannes Berg17741cd2008-09-11 00:02:02 +02001058
Ben Greear686b9cb2010-09-23 09:44:36 -07001059struct ieee80211_sta *ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw,
Johannes Berg7bedd0c2015-02-13 21:55:15 +01001060 const u8 *addr,
1061 const u8 *localaddr)
Johannes Berg17741cd2008-09-11 00:02:02 +02001062{
Johannes Berg7bedd0c2015-02-13 21:55:15 +01001063 struct ieee80211_local *local = hw_to_local(hw);
1064 struct sta_info *sta;
1065 struct rhash_head *tmp;
1066 const struct bucket_table *tbl;
1067
1068 tbl = rht_dereference_rcu(local->sta_hash.tbl, &local->sta_hash);
Johannes Berg17741cd2008-09-11 00:02:02 +02001069
Ben Greear686b9cb2010-09-23 09:44:36 -07001070 /*
1071 * Just return a random station if localaddr is NULL
1072 * ... first in list.
1073 */
Johannes Berg7bedd0c2015-02-13 21:55:15 +01001074 for_each_sta_info(local, tbl, addr, sta, tmp) {
Ben Greear686b9cb2010-09-23 09:44:36 -07001075 if (localaddr &&
Joe Perchesb203ca32012-05-08 18:56:52 +00001076 !ether_addr_equal(sta->sdata->vif.addr, localaddr))
Ben Greear686b9cb2010-09-23 09:44:36 -07001077 continue;
Johannes Bergf7c65592010-04-30 13:48:36 +02001078 if (!sta->uploaded)
1079 return NULL;
Johannes Bergabe60632009-11-25 17:46:18 +01001080 return &sta->sta;
Johannes Bergf7c65592010-04-30 13:48:36 +02001081 }
1082
Johannes Bergabe60632009-11-25 17:46:18 +01001083 return NULL;
Johannes Berg17741cd2008-09-11 00:02:02 +02001084}
Ben Greear686b9cb2010-09-23 09:44:36 -07001085EXPORT_SYMBOL_GPL(ieee80211_find_sta_by_ifaddr);
Johannes Berg5ed176e2009-11-04 14:42:28 +01001086
1087struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_vif *vif,
1088 const u8 *addr)
1089{
Johannes Bergf7c65592010-04-30 13:48:36 +02001090 struct sta_info *sta;
Johannes Berg5ed176e2009-11-04 14:42:28 +01001091
1092 if (!vif)
1093 return NULL;
1094
Johannes Bergf7c65592010-04-30 13:48:36 +02001095 sta = sta_info_get_bss(vif_to_sdata(vif), addr);
1096 if (!sta)
1097 return NULL;
Johannes Berg5ed176e2009-11-04 14:42:28 +01001098
Johannes Bergf7c65592010-04-30 13:48:36 +02001099 if (!sta->uploaded)
1100 return NULL;
1101
1102 return &sta->sta;
Johannes Berg5ed176e2009-11-04 14:42:28 +01001103}
Johannes Berg17741cd2008-09-11 00:02:02 +02001104EXPORT_SYMBOL(ieee80211_find_sta);
Johannes Bergaf818582009-11-06 11:35:50 +01001105
Johannes Berge3685e02014-02-20 11:19:58 +01001106/* powersave support code */
1107void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
Johannes Berg50a94322010-11-16 11:50:28 -08001108{
Helmut Schaa608383b2012-01-30 15:18:00 +01001109 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berge3685e02014-02-20 11:19:58 +01001110 struct ieee80211_local *local = sdata->local;
1111 struct sk_buff_head pending;
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001112 int filtered = 0, buffered = 0, ac, i;
Johannes Berge3685e02014-02-20 11:19:58 +01001113 unsigned long flags;
Marco Porschd012a602012-10-10 12:39:50 -07001114 struct ps_data *ps;
1115
Felix Fietkau3918edb2014-07-25 16:20:23 +02001116 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1117 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
1118 u.ap);
1119
1120 if (sdata->vif.type == NL80211_IFTYPE_AP)
Marco Porschd012a602012-10-10 12:39:50 -07001121 ps = &sdata->bss->ps;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001122 else if (ieee80211_vif_is_mesh(&sdata->vif))
1123 ps = &sdata->u.mesh.ps;
Marco Porschd012a602012-10-10 12:39:50 -07001124 else
1125 return;
Johannes Berg50a94322010-11-16 11:50:28 -08001126
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001127 clear_sta_flag(sta, WLAN_STA_SP);
Johannes Berg47086fc2011-09-29 16:04:33 +02001128
Johannes Berg5a306f52012-11-14 23:22:21 +01001129 BUILD_BUG_ON(BITS_TO_LONGS(IEEE80211_NUM_TIDS) > 1);
Johannes Berg948d8872011-09-29 16:04:29 +02001130 sta->driver_buffered_tids = 0;
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001131 sta->txq_buffered_tids = 0;
Johannes Berg948d8872011-09-29 16:04:29 +02001132
Arik Nemtsovd057e5a2011-01-31 22:29:13 +02001133 if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS))
1134 drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta);
Johannes Bergaf818582009-11-06 11:35:50 +01001135
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001136 if (sta->sta.txq[0]) {
1137 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
1138 struct txq_info *txqi = to_txq_info(sta->sta.txq[i]);
1139
1140 if (!skb_queue_len(&txqi->queue))
1141 continue;
1142
1143 drv_wake_tx_queue(local, txqi);
1144 }
1145 }
1146
Johannes Berg948d8872011-09-29 16:04:29 +02001147 skb_queue_head_init(&pending);
Johannes Bergaf818582009-11-06 11:35:50 +01001148
Emmanuel Grumbach1d147bf2014-02-20 09:22:11 +02001149 /* sync with ieee80211_tx_h_unicast_ps_buf */
1150 spin_lock(&sta->ps_lock);
Johannes Bergaf818582009-11-06 11:35:50 +01001151 /* Send all buffered frames to the station */
Johannes Berg948d8872011-09-29 16:04:29 +02001152 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1153 int count = skb_queue_len(&pending), tmp;
1154
Arik Nemtsov987c2852012-11-05 10:27:52 +02001155 spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
Johannes Berg948d8872011-09-29 16:04:29 +02001156 skb_queue_splice_tail_init(&sta->tx_filtered[ac], &pending);
Arik Nemtsov987c2852012-11-05 10:27:52 +02001157 spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
Johannes Berg948d8872011-09-29 16:04:29 +02001158 tmp = skb_queue_len(&pending);
1159 filtered += tmp - count;
1160 count = tmp;
1161
Arik Nemtsov987c2852012-11-05 10:27:52 +02001162 spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
Johannes Berg948d8872011-09-29 16:04:29 +02001163 skb_queue_splice_tail_init(&sta->ps_tx_buf[ac], &pending);
Arik Nemtsov987c2852012-11-05 10:27:52 +02001164 spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
Johannes Berg948d8872011-09-29 16:04:29 +02001165 tmp = skb_queue_len(&pending);
1166 buffered += tmp - count;
1167 }
1168
Johannes Berge3685e02014-02-20 11:19:58 +01001169 ieee80211_add_pending_skbs(local, &pending);
Johannes Berg5ac2e352014-05-27 16:32:27 +02001170
1171 /* now we're no longer in the deliver code */
1172 clear_sta_flag(sta, WLAN_STA_PS_DELIVER);
1173
1174 /* The station might have polled and then woken up before we responded,
1175 * so clear these flags now to avoid them sticking around.
1176 */
1177 clear_sta_flag(sta, WLAN_STA_PSPOLL);
1178 clear_sta_flag(sta, WLAN_STA_UAPSD);
Emmanuel Grumbach1d147bf2014-02-20 09:22:11 +02001179 spin_unlock(&sta->ps_lock);
Johannes Berg948d8872011-09-29 16:04:29 +02001180
Johannes Berge3685e02014-02-20 11:19:58 +01001181 atomic_dec(&ps->num_sta_ps);
1182
Emmanuel Grumbach687da132013-10-01 16:45:43 +03001183 /* This station just woke up and isn't aware of our SMPS state */
Chun-Yeow Yeoh062f1d62014-04-22 18:19:25 +08001184 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
1185 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
Emmanuel Grumbach687da132013-10-01 16:45:43 +03001186 sdata->smps_mode) &&
1187 sta->known_smps_mode != sdata->bss->req_smps &&
1188 sta_info_tx_streams(sta) != 1) {
1189 ht_dbg(sdata,
1190 "%pM just woke up and MIMO capable - update SMPS\n",
1191 sta->sta.addr);
1192 ieee80211_send_smps_action(sdata, sdata->bss->req_smps,
1193 sta->sta.addr,
1194 sdata->vif.bss_conf.bssid);
1195 }
1196
Johannes Bergaf818582009-11-06 11:35:50 +01001197 local->total_ps_buffered -= buffered;
1198
Johannes Bergc868cb352011-09-29 16:04:27 +02001199 sta_info_recalc_tim(sta);
1200
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001201 ps_dbg(sdata,
1202 "STA %pM aid %d sending %d filtered/%d PS frames since STA not sleeping anymore\n",
1203 sta->sta.addr, sta->sta.aid, filtered, buffered);
Johannes Bergaf818582009-11-06 11:35:50 +01001204}
1205
Johannes Bergce662b442011-09-29 16:04:34 +02001206static void ieee80211_send_null_response(struct ieee80211_sub_if_data *sdata,
1207 struct sta_info *sta, int tid,
Johannes Bergb77cf4f2014-01-09 00:00:38 +01001208 enum ieee80211_frame_release_type reason,
1209 bool call_driver)
Johannes Bergce662b442011-09-29 16:04:34 +02001210{
1211 struct ieee80211_local *local = sdata->local;
1212 struct ieee80211_qos_hdr *nullfunc;
1213 struct sk_buff *skb;
1214 int size = sizeof(*nullfunc);
1215 __le16 fc;
Johannes Berga74a8c82014-07-22 14:50:47 +02001216 bool qos = sta->sta.wme;
Johannes Bergce662b442011-09-29 16:04:34 +02001217 struct ieee80211_tx_info *info;
Johannes Berg55de9082012-07-26 17:24:39 +02001218 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Bergce662b442011-09-29 16:04:34 +02001219
1220 if (qos) {
1221 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
1222 IEEE80211_STYPE_QOS_NULLFUNC |
1223 IEEE80211_FCTL_FROMDS);
1224 } else {
1225 size -= 2;
1226 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
1227 IEEE80211_STYPE_NULLFUNC |
1228 IEEE80211_FCTL_FROMDS);
1229 }
1230
1231 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
1232 if (!skb)
1233 return;
1234
1235 skb_reserve(skb, local->hw.extra_tx_headroom);
1236
1237 nullfunc = (void *) skb_put(skb, size);
1238 nullfunc->frame_control = fc;
1239 nullfunc->duration_id = 0;
1240 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
1241 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1242 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
Johannes Berg864a6042014-03-04 13:46:53 +01001243 nullfunc->seq_ctrl = 0;
Johannes Bergce662b442011-09-29 16:04:34 +02001244
Johannes Berg59b66252011-10-13 13:19:19 +02001245 skb->priority = tid;
1246 skb_set_queue_mapping(skb, ieee802_1d_to_ac[tid]);
Johannes Bergce662b442011-09-29 16:04:34 +02001247 if (qos) {
Johannes Bergce662b442011-09-29 16:04:34 +02001248 nullfunc->qos_ctrl = cpu_to_le16(tid);
1249
Johannes Berg40b96402011-09-29 16:04:38 +02001250 if (reason == IEEE80211_FRAME_RELEASE_UAPSD)
Johannes Bergce662b442011-09-29 16:04:34 +02001251 nullfunc->qos_ctrl |=
1252 cpu_to_le16(IEEE80211_QOS_CTL_EOSP);
1253 }
1254
1255 info = IEEE80211_SKB_CB(skb);
1256
1257 /*
1258 * Tell TX path to send this frame even though the
1259 * STA may still remain is PS mode after this frame
Johannes Bergdeeaee192011-09-29 16:04:35 +02001260 * exchange. Also set EOSP to indicate this packet
1261 * ends the poll/service period.
Johannes Bergce662b442011-09-29 16:04:34 +02001262 */
Johannes Berg02f2f1a2012-02-27 12:18:30 +01001263 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER |
Johannes Bergdeeaee192011-09-29 16:04:35 +02001264 IEEE80211_TX_STATUS_EOSP |
1265 IEEE80211_TX_CTL_REQ_TX_STATUS;
Johannes Bergce662b442011-09-29 16:04:34 +02001266
Sujith Manoharan6b127c72014-12-10 21:26:10 +05301267 info->control.flags |= IEEE80211_TX_CTRL_PS_RESPONSE;
1268
Johannes Bergb77cf4f2014-01-09 00:00:38 +01001269 if (call_driver)
1270 drv_allow_buffered_frames(local, sta, BIT(tid), 1,
1271 reason, false);
Johannes Berg40b96402011-09-29 16:04:38 +02001272
Johannes Berg89afe612013-02-13 15:39:57 +01001273 skb->dev = sdata->dev;
1274
Johannes Berg55de9082012-07-26 17:24:39 +02001275 rcu_read_lock();
1276 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
1277 if (WARN_ON(!chanctx_conf)) {
1278 rcu_read_unlock();
1279 kfree_skb(skb);
1280 return;
1281 }
1282
Johannes Berg73c4e192014-11-09 18:50:09 +02001283 info->band = chanctx_conf->def.chan->band;
Johannes Berg7c107702015-03-20 14:18:27 +01001284 ieee80211_xmit(sdata, sta, skb);
Johannes Berg55de9082012-07-26 17:24:39 +02001285 rcu_read_unlock();
Johannes Bergce662b442011-09-29 16:04:34 +02001286}
1287
Johannes Berg0a1cb802014-01-09 11:05:31 +01001288static int find_highest_prio_tid(unsigned long tids)
1289{
1290 /* lower 3 TIDs aren't ordered perfectly */
1291 if (tids & 0xF8)
1292 return fls(tids) - 1;
1293 /* TID 0 is BE just like TID 3 */
1294 if (tids & BIT(0))
1295 return 0;
1296 return fls(tids) - 1;
1297}
1298
Johannes Berg47086fc2011-09-29 16:04:33 +02001299static void
1300ieee80211_sta_ps_deliver_response(struct sta_info *sta,
1301 int n_frames, u8 ignored_acs,
1302 enum ieee80211_frame_release_type reason)
Johannes Bergaf818582009-11-06 11:35:50 +01001303{
1304 struct ieee80211_sub_if_data *sdata = sta->sdata;
1305 struct ieee80211_local *local = sdata->local;
Johannes Berg948d8872011-09-29 16:04:29 +02001306 bool more_data = false;
1307 int ac;
Johannes Berg4049e092011-09-29 16:04:32 +02001308 unsigned long driver_release_tids = 0;
Johannes Berg47086fc2011-09-29 16:04:33 +02001309 struct sk_buff_head frames;
1310
Johannes Bergdeeaee192011-09-29 16:04:35 +02001311 /* Service or PS-Poll period starts */
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001312 set_sta_flag(sta, WLAN_STA_SP);
Johannes Bergdeeaee192011-09-29 16:04:35 +02001313
Johannes Berg47086fc2011-09-29 16:04:33 +02001314 __skb_queue_head_init(&frames);
Johannes Bergaf818582009-11-06 11:35:50 +01001315
Johannes Bergf9f760b2014-01-08 17:45:07 +01001316 /* Get response frame(s) and more data bit for the last one. */
Johannes Berg948d8872011-09-29 16:04:29 +02001317 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
Johannes Berg4049e092011-09-29 16:04:32 +02001318 unsigned long tids;
1319
Johannes Berg47086fc2011-09-29 16:04:33 +02001320 if (ignored_acs & BIT(ac))
Johannes Berg948d8872011-09-29 16:04:29 +02001321 continue;
1322
Johannes Berg4049e092011-09-29 16:04:32 +02001323 tids = ieee80211_tids_for_ac(ac);
1324
Johannes Bergf9f760b2014-01-08 17:45:07 +01001325 /* if we already have frames from software, then we can't also
1326 * release from hardware queues
1327 */
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001328 if (skb_queue_empty(&frames)) {
Johannes Bergf9f760b2014-01-08 17:45:07 +01001329 driver_release_tids |= sta->driver_buffered_tids & tids;
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001330 driver_release_tids |= sta->txq_buffered_tids & tids;
1331 }
Johannes Berg47086fc2011-09-29 16:04:33 +02001332
Johannes Bergf9f760b2014-01-08 17:45:07 +01001333 if (driver_release_tids) {
1334 /* If the driver has data on more than one TID then
Johannes Berg4049e092011-09-29 16:04:32 +02001335 * certainly there's more data if we release just a
Johannes Bergf9f760b2014-01-08 17:45:07 +01001336 * single frame now (from a single TID). This will
1337 * only happen for PS-Poll.
Johannes Berg4049e092011-09-29 16:04:32 +02001338 */
Johannes Berg47086fc2011-09-29 16:04:33 +02001339 if (reason == IEEE80211_FRAME_RELEASE_PSPOLL &&
1340 hweight16(driver_release_tids) > 1) {
Johannes Berg4049e092011-09-29 16:04:32 +02001341 more_data = true;
1342 driver_release_tids =
Johannes Berg0a1cb802014-01-09 11:05:31 +01001343 BIT(find_highest_prio_tid(
1344 driver_release_tids));
Johannes Berg4049e092011-09-29 16:04:32 +02001345 break;
Johannes Berg948d8872011-09-29 16:04:29 +02001346 }
Johannes Bergf9f760b2014-01-08 17:45:07 +01001347 } else {
1348 struct sk_buff *skb;
1349
1350 while (n_frames > 0) {
1351 skb = skb_dequeue(&sta->tx_filtered[ac]);
1352 if (!skb) {
1353 skb = skb_dequeue(
1354 &sta->ps_tx_buf[ac]);
1355 if (skb)
1356 local->total_ps_buffered--;
1357 }
1358 if (!skb)
1359 break;
1360 n_frames--;
1361 __skb_queue_tail(&frames, skb);
1362 }
Johannes Berg948d8872011-09-29 16:04:29 +02001363 }
1364
Johannes Bergf9f760b2014-01-08 17:45:07 +01001365 /* If we have more frames buffered on this AC, then set the
1366 * more-data bit and abort the loop since we can't send more
1367 * data from other ACs before the buffered frames from this.
1368 */
Johannes Berg948d8872011-09-29 16:04:29 +02001369 if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
1370 !skb_queue_empty(&sta->ps_tx_buf[ac])) {
1371 more_data = true;
1372 break;
1373 }
Johannes Bergaf818582009-11-06 11:35:50 +01001374 }
Johannes Bergaf818582009-11-06 11:35:50 +01001375
Johannes Bergf9f760b2014-01-08 17:45:07 +01001376 if (skb_queue_empty(&frames) && !driver_release_tids) {
Johannes Bergce662b442011-09-29 16:04:34 +02001377 int tid;
Johannes Berg4049e092011-09-29 16:04:32 +02001378
Johannes Bergce662b442011-09-29 16:04:34 +02001379 /*
1380 * For PS-Poll, this can only happen due to a race condition
1381 * when we set the TIM bit and the station notices it, but
1382 * before it can poll for the frame we expire it.
1383 *
1384 * For uAPSD, this is said in the standard (11.2.1.5 h):
1385 * At each unscheduled SP for a non-AP STA, the AP shall
1386 * attempt to transmit at least one MSDU or MMPDU, but no
1387 * more than the value specified in the Max SP Length field
1388 * in the QoS Capability element from delivery-enabled ACs,
1389 * that are destined for the non-AP STA.
1390 *
1391 * Since we have no other MSDU/MMPDU, transmit a QoS null frame.
1392 */
1393
1394 /* This will evaluate to 1, 3, 5 or 7. */
1395 tid = 7 - ((ffs(~ignored_acs) - 1) << 1);
1396
Johannes Bergb77cf4f2014-01-09 00:00:38 +01001397 ieee80211_send_null_response(sdata, sta, tid, reason, true);
Johannes Bergf9f760b2014-01-08 17:45:07 +01001398 } else if (!driver_release_tids) {
Johannes Berg47086fc2011-09-29 16:04:33 +02001399 struct sk_buff_head pending;
1400 struct sk_buff *skb;
Johannes Berg40b96402011-09-29 16:04:38 +02001401 int num = 0;
1402 u16 tids = 0;
Johannes Bergb77cf4f2014-01-09 00:00:38 +01001403 bool need_null = false;
Johannes Bergaf818582009-11-06 11:35:50 +01001404
Johannes Berg47086fc2011-09-29 16:04:33 +02001405 skb_queue_head_init(&pending);
Johannes Bergaf818582009-11-06 11:35:50 +01001406
Johannes Berg47086fc2011-09-29 16:04:33 +02001407 while ((skb = __skb_dequeue(&frames))) {
1408 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1409 struct ieee80211_hdr *hdr = (void *) skb->data;
Johannes Berg40b96402011-09-29 16:04:38 +02001410 u8 *qoshdr = NULL;
1411
1412 num++;
Johannes Bergaf818582009-11-06 11:35:50 +01001413
Johannes Berg47086fc2011-09-29 16:04:33 +02001414 /*
1415 * Tell TX path to send this frame even though the
1416 * STA may still remain is PS mode after this frame
1417 * exchange.
1418 */
Sujith Manoharan6b127c72014-12-10 21:26:10 +05301419 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER;
1420 info->control.flags |= IEEE80211_TX_CTRL_PS_RESPONSE;
Johannes Bergaf818582009-11-06 11:35:50 +01001421
Johannes Berg47086fc2011-09-29 16:04:33 +02001422 /*
1423 * Use MoreData flag to indicate whether there are
1424 * more buffered frames for this STA
1425 */
Janusz.Dziedzic@tieto.com24b9c372011-11-07 09:47:47 +02001426 if (more_data || !skb_queue_empty(&frames))
Johannes Berg47086fc2011-09-29 16:04:33 +02001427 hdr->frame_control |=
1428 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
Janusz.Dziedzic@tieto.com24b9c372011-11-07 09:47:47 +02001429 else
1430 hdr->frame_control &=
1431 cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
Johannes Berg47086fc2011-09-29 16:04:33 +02001432
Johannes Berg40b96402011-09-29 16:04:38 +02001433 if (ieee80211_is_data_qos(hdr->frame_control) ||
1434 ieee80211_is_qos_nullfunc(hdr->frame_control))
1435 qoshdr = ieee80211_get_qos_ctl(hdr);
1436
Johannes Bergb77cf4f2014-01-09 00:00:38 +01001437 tids |= BIT(skb->priority);
1438
1439 __skb_queue_tail(&pending, skb);
1440
1441 /* end service period after last frame or add one */
1442 if (!skb_queue_empty(&frames))
1443 continue;
1444
1445 if (reason != IEEE80211_FRAME_RELEASE_UAPSD) {
1446 /* for PS-Poll, there's only one frame */
1447 info->flags |= IEEE80211_TX_STATUS_EOSP |
1448 IEEE80211_TX_CTL_REQ_TX_STATUS;
1449 break;
1450 }
1451
1452 /* For uAPSD, things are a bit more complicated. If the
1453 * last frame has a QoS header (i.e. is a QoS-data or
1454 * QoS-nulldata frame) then just set the EOSP bit there
1455 * and be done.
1456 * If the frame doesn't have a QoS header (which means
1457 * it should be a bufferable MMPDU) then we can't set
1458 * the EOSP bit in the QoS header; add a QoS-nulldata
1459 * frame to the list to send it after the MMPDU.
1460 *
1461 * Note that this code is only in the mac80211-release
1462 * code path, we assume that the driver will not buffer
1463 * anything but QoS-data frames, or if it does, will
1464 * create the QoS-nulldata frame by itself if needed.
1465 *
1466 * Cf. 802.11-2012 10.2.1.10 (c).
1467 */
1468 if (qoshdr) {
1469 *qoshdr |= IEEE80211_QOS_CTL_EOSP;
Johannes Berg47086fc2011-09-29 16:04:33 +02001470
Marco Porsch52a3f202012-03-16 15:30:26 +01001471 info->flags |= IEEE80211_TX_STATUS_EOSP |
1472 IEEE80211_TX_CTL_REQ_TX_STATUS;
Johannes Bergb77cf4f2014-01-09 00:00:38 +01001473 } else {
1474 /* The standard isn't completely clear on this
1475 * as it says the more-data bit should be set
1476 * if there are more BUs. The QoS-Null frame
1477 * we're about to send isn't buffered yet, we
1478 * only create it below, but let's pretend it
1479 * was buffered just in case some clients only
1480 * expect more-data=0 when eosp=1.
1481 */
1482 hdr->frame_control |=
1483 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
1484 need_null = true;
1485 num++;
Marco Porsch52a3f202012-03-16 15:30:26 +01001486 }
Johannes Bergb77cf4f2014-01-09 00:00:38 +01001487 break;
Johannes Berg47086fc2011-09-29 16:04:33 +02001488 }
1489
Johannes Berg40b96402011-09-29 16:04:38 +02001490 drv_allow_buffered_frames(local, sta, tids, num,
1491 reason, more_data);
1492
Johannes Berg47086fc2011-09-29 16:04:33 +02001493 ieee80211_add_pending_skbs(local, &pending);
Johannes Bergaf818582009-11-06 11:35:50 +01001494
Johannes Bergb77cf4f2014-01-09 00:00:38 +01001495 if (need_null)
1496 ieee80211_send_null_response(
1497 sdata, sta, find_highest_prio_tid(tids),
1498 reason, false);
1499
Johannes Bergc868cb352011-09-29 16:04:27 +02001500 sta_info_recalc_tim(sta);
Johannes Bergaf818582009-11-06 11:35:50 +01001501 } else {
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001502 unsigned long tids = sta->txq_buffered_tids & driver_release_tids;
1503 int tid;
1504
Johannes Bergaf818582009-11-06 11:35:50 +01001505 /*
Johannes Berg4049e092011-09-29 16:04:32 +02001506 * We need to release a frame that is buffered somewhere in the
1507 * driver ... it'll have to handle that.
Johannes Bergf9f760b2014-01-08 17:45:07 +01001508 * Note that the driver also has to check the number of frames
1509 * on the TIDs we're releasing from - if there are more than
1510 * n_frames it has to set the more-data bit (if we didn't ask
1511 * it to set it anyway due to other buffered frames); if there
1512 * are fewer than n_frames it has to make sure to adjust that
1513 * to allow the service period to end properly.
Johannes Bergaf818582009-11-06 11:35:50 +01001514 */
Johannes Berg4049e092011-09-29 16:04:32 +02001515 drv_release_buffered_frames(local, sta, driver_release_tids,
Johannes Berg47086fc2011-09-29 16:04:33 +02001516 n_frames, reason, more_data);
Johannes Berg4049e092011-09-29 16:04:32 +02001517
1518 /*
1519 * Note that we don't recalculate the TIM bit here as it would
1520 * most likely have no effect at all unless the driver told us
Johannes Bergf9f760b2014-01-08 17:45:07 +01001521 * that the TID(s) became empty before returning here from the
Johannes Berg4049e092011-09-29 16:04:32 +02001522 * release function.
Johannes Bergf9f760b2014-01-08 17:45:07 +01001523 * Either way, however, when the driver tells us that the TID(s)
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001524 * became empty or we find that a txq became empty, we'll do the
1525 * TIM recalculation.
Johannes Berg4049e092011-09-29 16:04:32 +02001526 */
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001527
1528 if (!sta->sta.txq[0])
1529 return;
1530
1531 for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
1532 struct txq_info *txqi = to_txq_info(sta->sta.txq[tid]);
1533
1534 if (!(tids & BIT(tid)) || skb_queue_len(&txqi->queue))
1535 continue;
1536
1537 sta_info_recalc_tim(sta);
1538 break;
1539 }
Johannes Bergaf818582009-11-06 11:35:50 +01001540 }
1541}
1542
Johannes Bergaf818582009-11-06 11:35:50 +01001543void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta)
1544{
Johannes Berg47086fc2011-09-29 16:04:33 +02001545 u8 ignore_for_response = sta->sta.uapsd_queues;
Johannes Bergaf818582009-11-06 11:35:50 +01001546
Johannes Berg47086fc2011-09-29 16:04:33 +02001547 /*
1548 * If all ACs are delivery-enabled then we should reply
1549 * from any of them, if only some are enabled we reply
1550 * only from the non-enabled ones.
1551 */
1552 if (ignore_for_response == BIT(IEEE80211_NUM_ACS) - 1)
1553 ignore_for_response = 0;
1554
1555 ieee80211_sta_ps_deliver_response(sta, 1, ignore_for_response,
1556 IEEE80211_FRAME_RELEASE_PSPOLL);
1557}
1558
1559void ieee80211_sta_ps_deliver_uapsd(struct sta_info *sta)
1560{
1561 int n_frames = sta->sta.max_sp;
1562 u8 delivery_enabled = sta->sta.uapsd_queues;
1563
1564 /*
1565 * If we ever grow support for TSPEC this might happen if
1566 * the TSPEC update from hostapd comes in between a trigger
1567 * frame setting WLAN_STA_UAPSD in the RX path and this
1568 * actually getting called.
1569 */
1570 if (!delivery_enabled)
1571 return;
1572
Johannes Berg47086fc2011-09-29 16:04:33 +02001573 switch (sta->sta.max_sp) {
1574 case 1:
1575 n_frames = 2;
1576 break;
1577 case 2:
1578 n_frames = 4;
1579 break;
1580 case 3:
1581 n_frames = 6;
1582 break;
1583 case 0:
1584 /* XXX: what is a good value? */
Andrei Otcheretianski13a80982014-11-04 11:33:04 +02001585 n_frames = 128;
Johannes Berg47086fc2011-09-29 16:04:33 +02001586 break;
Johannes Bergaf818582009-11-06 11:35:50 +01001587 }
Johannes Bergaf818582009-11-06 11:35:50 +01001588
Johannes Berg47086fc2011-09-29 16:04:33 +02001589 ieee80211_sta_ps_deliver_response(sta, n_frames, ~delivery_enabled,
1590 IEEE80211_FRAME_RELEASE_UAPSD);
Johannes Bergaf818582009-11-06 11:35:50 +01001591}
1592
1593void ieee80211_sta_block_awake(struct ieee80211_hw *hw,
1594 struct ieee80211_sta *pubsta, bool block)
1595{
1596 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1597
Johannes Bergb5878a22010-04-07 16:48:40 +02001598 trace_api_sta_block_awake(sta->local, pubsta, block);
1599
Johannes Berg5ac2e352014-05-27 16:32:27 +02001600 if (block) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001601 set_sta_flag(sta, WLAN_STA_PS_DRIVER);
Johannes Berg5ac2e352014-05-27 16:32:27 +02001602 return;
1603 }
1604
1605 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1606 return;
1607
1608 if (!test_sta_flag(sta, WLAN_STA_PS_STA)) {
1609 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
1610 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
1611 ieee80211_queue_work(hw, &sta->drv_deliver_wk);
1612 } else if (test_sta_flag(sta, WLAN_STA_PSPOLL) ||
1613 test_sta_flag(sta, WLAN_STA_UAPSD)) {
1614 /* must be asleep in this case */
1615 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
1616 ieee80211_queue_work(hw, &sta->drv_deliver_wk);
1617 } else {
1618 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
1619 }
Johannes Bergaf818582009-11-06 11:35:50 +01001620}
1621EXPORT_SYMBOL(ieee80211_sta_block_awake);
Felix Fietkaudcf55fb2011-04-17 17:45:00 +02001622
Johannes Berge9437892013-02-15 21:38:08 +01001623void ieee80211_sta_eosp(struct ieee80211_sta *pubsta)
Johannes Berg37fbd902011-09-29 16:04:39 +02001624{
1625 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1626 struct ieee80211_local *local = sta->local;
Johannes Berg37fbd902011-09-29 16:04:39 +02001627
1628 trace_api_eosp(local, pubsta);
1629
Johannes Berge9437892013-02-15 21:38:08 +01001630 clear_sta_flag(sta, WLAN_STA_SP);
Johannes Berg37fbd902011-09-29 16:04:39 +02001631}
Johannes Berge9437892013-02-15 21:38:08 +01001632EXPORT_SYMBOL(ieee80211_sta_eosp);
Johannes Berg37fbd902011-09-29 16:04:39 +02001633
Johannes Berg042ec452011-09-29 16:04:26 +02001634void ieee80211_sta_set_buffered(struct ieee80211_sta *pubsta,
1635 u8 tid, bool buffered)
Felix Fietkaudcf55fb2011-04-17 17:45:00 +02001636{
1637 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1638
Johannes Berg5a306f52012-11-14 23:22:21 +01001639 if (WARN_ON(tid >= IEEE80211_NUM_TIDS))
Johannes Berg042ec452011-09-29 16:04:26 +02001640 return;
1641
Johannes Berg1b000782013-12-19 10:47:48 +01001642 trace_api_sta_set_buffered(sta->local, pubsta, tid, buffered);
1643
Johannes Berg948d8872011-09-29 16:04:29 +02001644 if (buffered)
1645 set_bit(tid, &sta->driver_buffered_tids);
1646 else
1647 clear_bit(tid, &sta->driver_buffered_tids);
1648
Johannes Bergc868cb352011-09-29 16:04:27 +02001649 sta_info_recalc_tim(sta);
Felix Fietkaudcf55fb2011-04-17 17:45:00 +02001650}
Johannes Berg042ec452011-09-29 16:04:26 +02001651EXPORT_SYMBOL(ieee80211_sta_set_buffered);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001652
Johannes Berg83d5cc02012-01-12 09:31:10 +01001653int sta_info_move_state(struct sta_info *sta,
1654 enum ieee80211_sta_state new_state)
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001655{
Johannes Berg8bf11d82011-12-15 11:17:37 +01001656 might_sleep();
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001657
1658 if (sta->sta_state == new_state)
1659 return 0;
1660
Johannes Bergf09603a2012-01-20 13:55:21 +01001661 /* check allowed transitions first */
1662
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001663 switch (new_state) {
1664 case IEEE80211_STA_NONE:
Johannes Bergf09603a2012-01-20 13:55:21 +01001665 if (sta->sta_state != IEEE80211_STA_AUTH)
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001666 return -EINVAL;
1667 break;
1668 case IEEE80211_STA_AUTH:
Johannes Bergf09603a2012-01-20 13:55:21 +01001669 if (sta->sta_state != IEEE80211_STA_NONE &&
1670 sta->sta_state != IEEE80211_STA_ASSOC)
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001671 return -EINVAL;
1672 break;
1673 case IEEE80211_STA_ASSOC:
Johannes Bergf09603a2012-01-20 13:55:21 +01001674 if (sta->sta_state != IEEE80211_STA_AUTH &&
1675 sta->sta_state != IEEE80211_STA_AUTHORIZED)
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001676 return -EINVAL;
1677 break;
1678 case IEEE80211_STA_AUTHORIZED:
Johannes Bergf09603a2012-01-20 13:55:21 +01001679 if (sta->sta_state != IEEE80211_STA_ASSOC)
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001680 return -EINVAL;
1681 break;
1682 default:
1683 WARN(1, "invalid state %d", new_state);
1684 return -EINVAL;
1685 }
1686
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001687 sta_dbg(sta->sdata, "moving STA %pM to state %d\n",
1688 sta->sta.addr, new_state);
Johannes Bergf09603a2012-01-20 13:55:21 +01001689
1690 /*
1691 * notify the driver before the actual changes so it can
1692 * fail the transition
1693 */
1694 if (test_sta_flag(sta, WLAN_STA_INSERTED)) {
1695 int err = drv_sta_state(sta->local, sta->sdata, sta,
1696 sta->sta_state, new_state);
1697 if (err)
1698 return err;
1699 }
1700
1701 /* reflect the change in all state variables */
1702
1703 switch (new_state) {
1704 case IEEE80211_STA_NONE:
1705 if (sta->sta_state == IEEE80211_STA_AUTH)
1706 clear_bit(WLAN_STA_AUTH, &sta->_flags);
1707 break;
1708 case IEEE80211_STA_AUTH:
1709 if (sta->sta_state == IEEE80211_STA_NONE)
1710 set_bit(WLAN_STA_AUTH, &sta->_flags);
1711 else if (sta->sta_state == IEEE80211_STA_ASSOC)
1712 clear_bit(WLAN_STA_ASSOC, &sta->_flags);
1713 break;
1714 case IEEE80211_STA_ASSOC:
1715 if (sta->sta_state == IEEE80211_STA_AUTH) {
1716 set_bit(WLAN_STA_ASSOC, &sta->_flags);
1717 } else if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001718 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1719 (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1720 !sta->sdata->u.vlan.sta))
1721 atomic_dec(&sta->sdata->bss->num_mcast_sta);
Johannes Bergf09603a2012-01-20 13:55:21 +01001722 clear_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
1723 }
1724 break;
1725 case IEEE80211_STA_AUTHORIZED:
1726 if (sta->sta_state == IEEE80211_STA_ASSOC) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001727 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1728 (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1729 !sta->sdata->u.vlan.sta))
1730 atomic_inc(&sta->sdata->bss->num_mcast_sta);
Johannes Bergf09603a2012-01-20 13:55:21 +01001731 set_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
1732 }
1733 break;
1734 default:
1735 break;
1736 }
1737
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001738 sta->sta_state = new_state;
1739
1740 return 0;
1741}
Emmanuel Grumbach687da132013-10-01 16:45:43 +03001742
1743u8 sta_info_tx_streams(struct sta_info *sta)
1744{
1745 struct ieee80211_sta_ht_cap *ht_cap = &sta->sta.ht_cap;
1746 u8 rx_streams;
1747
1748 if (!sta->sta.ht_cap.ht_supported)
1749 return 1;
1750
1751 if (sta->sta.vht_cap.vht_supported) {
1752 int i;
1753 u16 tx_mcs_map =
1754 le16_to_cpu(sta->sta.vht_cap.vht_mcs.tx_mcs_map);
1755
1756 for (i = 7; i >= 0; i--)
1757 if ((tx_mcs_map & (0x3 << (i * 2))) !=
1758 IEEE80211_VHT_MCS_NOT_SUPPORTED)
1759 return i + 1;
1760 }
1761
1762 if (ht_cap->mcs.rx_mask[3])
1763 rx_streams = 4;
1764 else if (ht_cap->mcs.rx_mask[2])
1765 rx_streams = 3;
1766 else if (ht_cap->mcs.rx_mask[1])
1767 rx_streams = 2;
1768 else
1769 rx_streams = 1;
1770
1771 if (!(ht_cap->mcs.tx_params & IEEE80211_HT_MCS_TX_RX_DIFF))
1772 return rx_streams;
1773
1774 return ((ht_cap->mcs.tx_params & IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
1775 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT) + 1;
1776}
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001777
1778void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
1779{
1780 struct ieee80211_sub_if_data *sdata = sta->sdata;
1781 struct ieee80211_local *local = sdata->local;
John W. Linville9a244402014-07-25 10:22:36 -04001782 struct rate_control_ref *ref = NULL;
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001783 struct timespec uptime;
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001784 u32 thr = 0;
1785 int i, ac;
1786
John W. Linville9a244402014-07-25 10:22:36 -04001787 if (test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
1788 ref = local->rate_ctrl;
1789
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001790 sinfo->generation = sdata->local->sta_generation;
1791
Johannes Berg225b8182015-01-21 21:09:02 +01001792 /* do before driver, so beacon filtering drivers have a
1793 * chance to e.g. just add the number of filtered beacons
1794 * (or just modify the value entirely, of course)
1795 */
1796 if (sdata->vif.type == NL80211_IFTYPE_STATION)
1797 sinfo->rx_beacon = sdata->u.mgd.count_beacon_signal;
1798
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001799 drv_sta_statistics(local, sdata, &sta->sta, sinfo);
1800
Johannes Berg319090b2014-11-17 14:08:11 +01001801 sinfo->filled |= BIT(NL80211_STA_INFO_INACTIVE_TIME) |
1802 BIT(NL80211_STA_INFO_STA_FLAGS) |
1803 BIT(NL80211_STA_INFO_BSS_PARAM) |
1804 BIT(NL80211_STA_INFO_CONNECTED_TIME) |
1805 BIT(NL80211_STA_INFO_RX_DROP_MISC) |
1806 BIT(NL80211_STA_INFO_BEACON_LOSS);
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001807
Thomas Gleixner18171522014-06-11 23:59:14 +00001808 ktime_get_ts(&uptime);
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001809 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001810 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001811
Johannes Berg319090b2014-11-17 14:08:11 +01001812 if (!(sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES64) |
1813 BIT(NL80211_STA_INFO_TX_BYTES)))) {
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001814 sinfo->tx_bytes = 0;
1815 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
1816 sinfo->tx_bytes += sta->tx_bytes[ac];
Johannes Berg319090b2014-11-17 14:08:11 +01001817 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BYTES64);
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001818 }
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001819
Johannes Berg319090b2014-11-17 14:08:11 +01001820 if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_PACKETS))) {
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001821 sinfo->tx_packets = 0;
1822 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
1823 sinfo->tx_packets += sta->tx_packets[ac];
Johannes Berg319090b2014-11-17 14:08:11 +01001824 sinfo->filled |= BIT(NL80211_STA_INFO_TX_PACKETS);
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001825 }
1826
Johannes Berg319090b2014-11-17 14:08:11 +01001827 if (!(sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES64) |
1828 BIT(NL80211_STA_INFO_RX_BYTES)))) {
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001829 sinfo->rx_bytes = sta->rx_bytes;
Johannes Berg319090b2014-11-17 14:08:11 +01001830 sinfo->filled |= BIT(NL80211_STA_INFO_RX_BYTES64);
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001831 }
1832
Johannes Berg319090b2014-11-17 14:08:11 +01001833 if (!(sinfo->filled & BIT(NL80211_STA_INFO_RX_PACKETS))) {
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001834 sinfo->rx_packets = sta->rx_packets;
Johannes Berg319090b2014-11-17 14:08:11 +01001835 sinfo->filled |= BIT(NL80211_STA_INFO_RX_PACKETS);
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001836 }
1837
Johannes Berg319090b2014-11-17 14:08:11 +01001838 if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_RETRIES))) {
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001839 sinfo->tx_retries = sta->tx_retry_count;
Johannes Berg319090b2014-11-17 14:08:11 +01001840 sinfo->filled |= BIT(NL80211_STA_INFO_TX_RETRIES);
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001841 }
1842
Johannes Berg319090b2014-11-17 14:08:11 +01001843 if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_FAILED))) {
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001844 sinfo->tx_failed = sta->tx_retry_failed;
Johannes Berg319090b2014-11-17 14:08:11 +01001845 sinfo->filled |= BIT(NL80211_STA_INFO_TX_FAILED);
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001846 }
1847
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001848 sinfo->rx_dropped_misc = sta->rx_dropped;
1849 sinfo->beacon_loss_count = sta->beacon_loss_count;
1850
Johannes Berg225b8182015-01-21 21:09:02 +01001851 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1852 !(sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)) {
1853 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_RX) |
1854 BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
1855 sinfo->rx_beacon_signal_avg = ieee80211_ave_rssi(&sdata->vif);
1856 }
1857
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001858 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
1859 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
Johannes Berg319090b2014-11-17 14:08:11 +01001860 if (!(sinfo->filled & BIT(NL80211_STA_INFO_SIGNAL))) {
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001861 sinfo->signal = (s8)sta->last_signal;
Johannes Berg319090b2014-11-17 14:08:11 +01001862 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001863 }
1864
Johannes Berg319090b2014-11-17 14:08:11 +01001865 if (!(sinfo->filled & BIT(NL80211_STA_INFO_SIGNAL_AVG))) {
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001866 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
Johannes Berg319090b2014-11-17 14:08:11 +01001867 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL_AVG);
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001868 }
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001869 }
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001870
1871 if (sta->chains &&
Johannes Berg319090b2014-11-17 14:08:11 +01001872 !(sinfo->filled & (BIT(NL80211_STA_INFO_CHAIN_SIGNAL) |
1873 BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)))) {
1874 sinfo->filled |= BIT(NL80211_STA_INFO_CHAIN_SIGNAL) |
1875 BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG);
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001876
1877 sinfo->chains = sta->chains;
1878 for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
1879 sinfo->chain_signal[i] = sta->chain_signal_last[i];
1880 sinfo->chain_signal_avg[i] =
1881 (s8) -ewma_read(&sta->chain_signal_avg[i]);
1882 }
1883 }
1884
Johannes Berg319090b2014-11-17 14:08:11 +01001885 if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE))) {
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001886 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
Johannes Berg319090b2014-11-17 14:08:11 +01001887 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE);
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001888 }
1889
Johannes Berg319090b2014-11-17 14:08:11 +01001890 if (!(sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE))) {
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001891 sta_set_rate_info_rx(sta, &sinfo->rxrate);
Johannes Berg319090b2014-11-17 14:08:11 +01001892 sinfo->filled |= BIT(NL80211_STA_INFO_RX_BITRATE);
Johannes Berg2b9a7e12014-11-17 11:35:23 +01001893 }
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001894
Johannes Berg79c892b2014-11-21 14:26:31 +01001895 sinfo->filled |= BIT(NL80211_STA_INFO_TID_STATS);
1896 for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) {
1897 struct cfg80211_tid_stats *tidstats = &sinfo->pertid[i];
1898
1899 if (!(tidstats->filled & BIT(NL80211_TID_STATS_RX_MSDU))) {
1900 tidstats->filled |= BIT(NL80211_TID_STATS_RX_MSDU);
1901 tidstats->rx_msdu = sta->rx_msdu[i];
1902 }
1903
1904 if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU))) {
1905 tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU);
1906 tidstats->tx_msdu = sta->tx_msdu[i];
1907 }
1908
1909 if (!(tidstats->filled &
1910 BIT(NL80211_TID_STATS_TX_MSDU_RETRIES)) &&
1911 local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
1912 tidstats->filled |=
1913 BIT(NL80211_TID_STATS_TX_MSDU_RETRIES);
1914 tidstats->tx_msdu_retries = sta->tx_msdu_retries[i];
1915 }
1916
1917 if (!(tidstats->filled &
1918 BIT(NL80211_TID_STATS_TX_MSDU_FAILED)) &&
1919 local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
1920 tidstats->filled |=
1921 BIT(NL80211_TID_STATS_TX_MSDU_FAILED);
1922 tidstats->tx_msdu_failed = sta->tx_msdu_failed[i];
1923 }
1924 }
1925
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001926 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1927#ifdef CONFIG_MAC80211_MESH
Johannes Berg319090b2014-11-17 14:08:11 +01001928 sinfo->filled |= BIT(NL80211_STA_INFO_LLID) |
1929 BIT(NL80211_STA_INFO_PLID) |
1930 BIT(NL80211_STA_INFO_PLINK_STATE) |
1931 BIT(NL80211_STA_INFO_LOCAL_PM) |
1932 BIT(NL80211_STA_INFO_PEER_PM) |
1933 BIT(NL80211_STA_INFO_NONPEER_PM);
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001934
1935 sinfo->llid = sta->llid;
1936 sinfo->plid = sta->plid;
1937 sinfo->plink_state = sta->plink_state;
1938 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
Johannes Berg319090b2014-11-17 14:08:11 +01001939 sinfo->filled |= BIT(NL80211_STA_INFO_T_OFFSET);
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001940 sinfo->t_offset = sta->t_offset;
1941 }
1942 sinfo->local_pm = sta->local_pm;
1943 sinfo->peer_pm = sta->peer_pm;
1944 sinfo->nonpeer_pm = sta->nonpeer_pm;
1945#endif
1946 }
1947
1948 sinfo->bss_param.flags = 0;
1949 if (sdata->vif.bss_conf.use_cts_prot)
1950 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
1951 if (sdata->vif.bss_conf.use_short_preamble)
1952 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
1953 if (sdata->vif.bss_conf.use_short_slot)
1954 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
Emmanuel Grumbach785e21a2014-09-03 15:25:04 +03001955 sinfo->bss_param.dtim_period = sdata->vif.bss_conf.dtim_period;
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001956 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
1957
1958 sinfo->sta_flags.set = 0;
1959 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
1960 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
1961 BIT(NL80211_STA_FLAG_WME) |
1962 BIT(NL80211_STA_FLAG_MFP) |
1963 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1964 BIT(NL80211_STA_FLAG_ASSOCIATED) |
1965 BIT(NL80211_STA_FLAG_TDLS_PEER);
1966 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1967 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
1968 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
1969 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
Johannes Berga74a8c82014-07-22 14:50:47 +02001970 if (sta->sta.wme)
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001971 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
1972 if (test_sta_flag(sta, WLAN_STA_MFP))
1973 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
1974 if (test_sta_flag(sta, WLAN_STA_AUTH))
1975 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
1976 if (test_sta_flag(sta, WLAN_STA_ASSOC))
1977 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1978 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1979 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
1980
1981 /* check if the driver has a SW RC implementation */
1982 if (ref && ref->ops->get_expected_throughput)
1983 thr = ref->ops->get_expected_throughput(sta->rate_ctrl_priv);
1984 else
1985 thr = drv_get_expected_throughput(local, &sta->sta);
1986
1987 if (thr != 0) {
Johannes Berg319090b2014-11-17 14:08:11 +01001988 sinfo->filled |= BIT(NL80211_STA_INFO_EXPECTED_THROUGHPUT);
Johannes Bergb7ffbd72014-06-04 17:31:56 +02001989 sinfo->expected_throughput = thr;
1990 }
1991}