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