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