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