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