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