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