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> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | */ |
| 9 | |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/init.h> |
Felix Fietkau | 888d04d | 2012-03-01 15:22:09 +0100 | [diff] [blame] | 12 | #include <linux/etherdevice.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 13 | #include <linux/netdevice.h> |
| 14 | #include <linux/types.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/skbuff.h> |
| 17 | #include <linux/if_arp.h> |
Johannes Berg | 0d17440 | 2007-12-17 15:07:43 +0100 | [diff] [blame] | 18 | #include <linux/timer.h> |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 19 | #include <linux/rtnetlink.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 20 | |
| 21 | #include <net/mac80211.h> |
| 22 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 23 | #include "driver-ops.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 24 | #include "rate.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 25 | #include "sta_info.h" |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 26 | #include "debugfs_sta.h" |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 27 | #include "mesh.h" |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 28 | #include "wme.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 29 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 30 | /** |
| 31 | * DOC: STA information lifetime rules |
| 32 | * |
| 33 | * STA info structures (&struct sta_info) are managed in a hash table |
| 34 | * for faster lookup and a list for iteration. They are managed using |
| 35 | * RCU, i.e. access to the list and hash table is protected by RCU. |
| 36 | * |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 37 | * Upon allocating a STA info structure with sta_info_alloc(), the caller |
| 38 | * owns that structure. It must then insert it into the hash table using |
| 39 | * either sta_info_insert() or sta_info_insert_rcu(); only in the latter |
| 40 | * case (which acquires an rcu read section but must not be called from |
| 41 | * within one) will the pointer still be valid after the call. Note that |
| 42 | * the caller may not do much with the STA info before inserting it, in |
| 43 | * particular, it may not start any mesh peer link management or add |
| 44 | * encryption keys. |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 45 | * |
| 46 | * When the insertion fails (sta_info_insert()) returns non-zero), the |
| 47 | * structure will have been freed by sta_info_insert()! |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 48 | * |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 49 | * 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] | 50 | * peer. This means different things for the different type of interfaces |
| 51 | * 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] | 52 | * receive an association response from the AP. For IBSS this occurs when |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 53 | * 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] | 54 | * 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] | 55 | * for each respective station upon request from userspace through nl80211. |
Luis R. Rodriguez | 7e189a1 | 2009-06-02 18:38:14 -0400 | [diff] [blame] | 56 | * |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 57 | * In order to remove a STA info structure, various sta_info_destroy_*() |
| 58 | * calls are available. |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 59 | * |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 60 | * There is no concept of ownership on a STA entry, each structure is |
| 61 | * owned by the global hash table/list until it is removed. All users of |
| 62 | * the structure need to be RCU protected so that the structure won't be |
| 63 | * freed before they are done using it. |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 64 | */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 65 | |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 66 | /* Caller must hold local->sta_mtx */ |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 67 | static int sta_info_hash_del(struct ieee80211_local *local, |
| 68 | struct sta_info *sta) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 69 | { |
| 70 | struct sta_info *s; |
| 71 | |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 72 | s = rcu_dereference_protected(local->sta_hash[STA_HASH(sta->sta.addr)], |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 73 | lockdep_is_held(&local->sta_mtx)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 74 | if (!s) |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 75 | return -ENOENT; |
| 76 | if (s == sta) { |
Eric Dumazet | cf778b0 | 2012-01-12 04:41:32 +0000 | [diff] [blame] | 77 | rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 78 | s->hnext); |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 79 | return 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 82 | while (rcu_access_pointer(s->hnext) && |
| 83 | rcu_access_pointer(s->hnext) != sta) |
| 84 | s = rcu_dereference_protected(s->hnext, |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 85 | lockdep_is_held(&local->sta_mtx)); |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 86 | if (rcu_access_pointer(s->hnext)) { |
Eric Dumazet | cf778b0 | 2012-01-12 04:41:32 +0000 | [diff] [blame] | 87 | rcu_assign_pointer(s->hnext, sta->hnext); |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 88 | return 0; |
| 89 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 90 | |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 91 | return -ENOENT; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Johannes Berg | 97f97b1 | 2012-12-13 22:54:58 +0100 | [diff] [blame] | 94 | static void cleanup_single_sta(struct sta_info *sta) |
Eliad Peller | b22cfcf | 2012-09-09 14:43:51 +0300 | [diff] [blame] | 95 | { |
Eliad Peller | b22cfcf | 2012-09-09 14:43:51 +0300 | [diff] [blame] | 96 | int ac, i; |
| 97 | struct tid_ampdu_tx *tid_tx; |
| 98 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 99 | struct ieee80211_local *local = sdata->local; |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 100 | struct ps_data *ps; |
Eliad Peller | b22cfcf | 2012-09-09 14:43:51 +0300 | [diff] [blame] | 101 | |
| 102 | /* |
| 103 | * At this point, when being called as call_rcu callback, |
| 104 | * neither mac80211 nor the driver can reference this |
| 105 | * sta struct any more except by still existing timers |
| 106 | * associated with this station that we clean up below. |
Johannes Berg | 051007d | 2012-12-13 23:49:02 +0100 | [diff] [blame] | 107 | * |
| 108 | * Note though that this still uses the sdata and even |
| 109 | * calls the driver in AP and mesh mode, so interfaces |
| 110 | * of those types mush use call sta_info_flush_cleanup() |
| 111 | * (typically via sta_info_flush()) before deconfiguring |
| 112 | * the driver. |
| 113 | * |
| 114 | * In station mode, nothing happens here so it doesn't |
| 115 | * have to (and doesn't) do that, this is intentional to |
| 116 | * speed up roaming. |
Eliad Peller | b22cfcf | 2012-09-09 14:43:51 +0300 | [diff] [blame] | 117 | */ |
| 118 | |
| 119 | if (test_sta_flag(sta, WLAN_STA_PS_STA)) { |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 120 | if (sta->sdata->vif.type == NL80211_IFTYPE_AP || |
| 121 | sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
| 122 | ps = &sdata->bss->ps; |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 123 | else if (ieee80211_vif_is_mesh(&sdata->vif)) |
| 124 | ps = &sdata->u.mesh.ps; |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 125 | else |
| 126 | return; |
Eliad Peller | b22cfcf | 2012-09-09 14:43:51 +0300 | [diff] [blame] | 127 | |
| 128 | clear_sta_flag(sta, WLAN_STA_PS_STA); |
| 129 | |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 130 | atomic_dec(&ps->num_sta_ps); |
Eliad Peller | b22cfcf | 2012-09-09 14:43:51 +0300 | [diff] [blame] | 131 | sta_info_recalc_tim(sta); |
| 132 | } |
| 133 | |
| 134 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 135 | local->total_ps_buffered -= skb_queue_len(&sta->ps_tx_buf[ac]); |
Felix Fietkau | 1f98ab7 | 2012-11-10 03:44:14 +0100 | [diff] [blame] | 136 | ieee80211_purge_tx_queue(&local->hw, &sta->ps_tx_buf[ac]); |
| 137 | ieee80211_purge_tx_queue(&local->hw, &sta->tx_filtered[ac]); |
Eliad Peller | b22cfcf | 2012-09-09 14:43:51 +0300 | [diff] [blame] | 138 | } |
| 139 | |
Thomas Pedersen | 45b5028 | 2013-02-06 10:17:21 -0800 | [diff] [blame] | 140 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
| 141 | mesh_sta_cleanup(sta); |
Eliad Peller | b22cfcf | 2012-09-09 14:43:51 +0300 | [diff] [blame] | 142 | |
| 143 | cancel_work_sync(&sta->drv_unblock_wk); |
| 144 | |
| 145 | /* |
| 146 | * Destroy aggregation state here. It would be nice to wait for the |
| 147 | * driver to finish aggregation stop and then clean up, but for now |
| 148 | * drivers have to handle aggregation stop being requested, followed |
| 149 | * directly by station destruction. |
| 150 | */ |
Johannes Berg | 5a306f5 | 2012-11-14 23:22:21 +0100 | [diff] [blame] | 151 | for (i = 0; i < IEEE80211_NUM_TIDS; i++) { |
Eliad Peller | b22cfcf | 2012-09-09 14:43:51 +0300 | [diff] [blame] | 152 | tid_tx = rcu_dereference_raw(sta->ampdu_mlme.tid_tx[i]); |
| 153 | if (!tid_tx) |
| 154 | continue; |
Felix Fietkau | 1f98ab7 | 2012-11-10 03:44:14 +0100 | [diff] [blame] | 155 | ieee80211_purge_tx_queue(&local->hw, &tid_tx->pending); |
Eliad Peller | b22cfcf | 2012-09-09 14:43:51 +0300 | [diff] [blame] | 156 | kfree(tid_tx); |
| 157 | } |
| 158 | |
| 159 | sta_info_free(local, sta); |
| 160 | } |
| 161 | |
Johannes Berg | 97f97b1 | 2012-12-13 22:54:58 +0100 | [diff] [blame] | 162 | void ieee80211_cleanup_sdata_stas(struct ieee80211_sub_if_data *sdata) |
| 163 | { |
| 164 | struct sta_info *sta; |
| 165 | |
| 166 | spin_lock_bh(&sdata->cleanup_stations_lock); |
| 167 | while (!list_empty(&sdata->cleanup_stations)) { |
| 168 | sta = list_first_entry(&sdata->cleanup_stations, |
| 169 | struct sta_info, list); |
| 170 | list_del(&sta->list); |
| 171 | spin_unlock_bh(&sdata->cleanup_stations_lock); |
| 172 | |
| 173 | cleanup_single_sta(sta); |
| 174 | |
| 175 | spin_lock_bh(&sdata->cleanup_stations_lock); |
| 176 | } |
| 177 | |
| 178 | spin_unlock_bh(&sdata->cleanup_stations_lock); |
| 179 | } |
| 180 | |
Eliad Peller | b22cfcf | 2012-09-09 14:43:51 +0300 | [diff] [blame] | 181 | static void free_sta_rcu(struct rcu_head *h) |
| 182 | { |
| 183 | struct sta_info *sta = container_of(h, struct sta_info, rcu_head); |
Johannes Berg | 97f97b1 | 2012-12-13 22:54:58 +0100 | [diff] [blame] | 184 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Eliad Peller | b22cfcf | 2012-09-09 14:43:51 +0300 | [diff] [blame] | 185 | |
Johannes Berg | 97f97b1 | 2012-12-13 22:54:58 +0100 | [diff] [blame] | 186 | spin_lock(&sdata->cleanup_stations_lock); |
| 187 | list_add_tail(&sta->list, &sdata->cleanup_stations); |
| 188 | spin_unlock(&sdata->cleanup_stations_lock); |
| 189 | |
| 190 | ieee80211_queue_work(&sdata->local->hw, &sdata->cleanup_stations_wk); |
Eliad Peller | b22cfcf | 2012-09-09 14:43:51 +0300 | [diff] [blame] | 191 | } |
| 192 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 193 | /* protected by RCU */ |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 194 | struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata, |
| 195 | const u8 *addr) |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 196 | { |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 197 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 198 | struct sta_info *sta; |
| 199 | |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 200 | sta = rcu_dereference_check(local->sta_hash[STA_HASH(addr)], |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 201 | lockdep_is_held(&local->sta_mtx)); |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 202 | while (sta) { |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 203 | if (sta->sdata == sdata && |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 204 | ether_addr_equal(sta->sta.addr, addr)) |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 205 | break; |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 206 | sta = rcu_dereference_check(sta->hnext, |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 207 | lockdep_is_held(&local->sta_mtx)); |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 208 | } |
| 209 | return sta; |
| 210 | } |
| 211 | |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 212 | /* |
| 213 | * Get sta info either from the specified interface |
| 214 | * or from one of its vlans |
| 215 | */ |
| 216 | struct sta_info *sta_info_get_bss(struct ieee80211_sub_if_data *sdata, |
| 217 | const u8 *addr) |
| 218 | { |
| 219 | struct ieee80211_local *local = sdata->local; |
| 220 | struct sta_info *sta; |
| 221 | |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 222 | sta = rcu_dereference_check(local->sta_hash[STA_HASH(addr)], |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 223 | lockdep_is_held(&local->sta_mtx)); |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 224 | while (sta) { |
| 225 | if ((sta->sdata == sdata || |
Johannes Berg | a2c1e3d | 2010-09-14 21:34:14 +0200 | [diff] [blame] | 226 | (sta->sdata->bss && sta->sdata->bss == sdata->bss)) && |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 227 | ether_addr_equal(sta->sta.addr, addr)) |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 228 | break; |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 229 | sta = rcu_dereference_check(sta->hnext, |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 230 | lockdep_is_held(&local->sta_mtx)); |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 231 | } |
| 232 | return sta; |
| 233 | } |
| 234 | |
Johannes Berg | 3b53fde8 | 2009-11-16 12:00:37 +0100 | [diff] [blame] | 235 | struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata, |
| 236 | int idx) |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 237 | { |
Johannes Berg | 3b53fde8 | 2009-11-16 12:00:37 +0100 | [diff] [blame] | 238 | struct ieee80211_local *local = sdata->local; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 239 | struct sta_info *sta; |
| 240 | int i = 0; |
| 241 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 242 | list_for_each_entry_rcu(sta, &local->sta_list, list) { |
Johannes Berg | 3b53fde8 | 2009-11-16 12:00:37 +0100 | [diff] [blame] | 243 | if (sdata != sta->sdata) |
Luis Carlos Cobo | 2a8ca29 | 2008-02-29 17:51:25 -0800 | [diff] [blame] | 244 | continue; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 245 | if (i < idx) { |
| 246 | ++i; |
| 247 | continue; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 248 | } |
Luis Carlos Cobo | 2a8ca29 | 2008-02-29 17:51:25 -0800 | [diff] [blame] | 249 | return sta; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 250 | } |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 251 | |
| 252 | return NULL; |
| 253 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 254 | |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 255 | /** |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 256 | * sta_info_free - free STA |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 257 | * |
Randy Dunlap | 6ef307b | 2008-07-03 13:52:18 -0700 | [diff] [blame] | 258 | * @local: pointer to the global information |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 259 | * @sta: STA info to free |
| 260 | * |
| 261 | * This function must undo everything done by sta_info_alloc() |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 262 | * that may happen before sta_info_insert(). It may only be |
| 263 | * called when sta_info_insert() has not been attempted (and |
| 264 | * if that fails, the station is freed anyway.) |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 265 | */ |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 266 | void sta_info_free(struct ieee80211_local *local, struct sta_info *sta) |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 267 | { |
Johannes Berg | 889cbb9 | 2012-01-17 10:33:29 +0100 | [diff] [blame] | 268 | if (sta->rate_ctrl) |
Johannes Berg | af65cd96 | 2009-11-17 18:18:36 +0100 | [diff] [blame] | 269 | rate_control_free_sta(sta); |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 270 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 271 | sta_dbg(sta->sdata, "Destroyed STA %pM\n", sta->sta.addr); |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 272 | |
| 273 | kfree(sta); |
| 274 | } |
| 275 | |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 276 | /* Caller must hold local->sta_mtx */ |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 277 | static void sta_info_hash_add(struct ieee80211_local *local, |
| 278 | struct sta_info *sta) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 279 | { |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 280 | lockdep_assert_held(&local->sta_mtx); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 281 | sta->hnext = local->sta_hash[STA_HASH(sta->sta.addr)]; |
Eric Dumazet | cf778b0 | 2012-01-12 04:41:32 +0000 | [diff] [blame] | 282 | rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 283 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 284 | |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 285 | static void sta_unblock(struct work_struct *wk) |
| 286 | { |
| 287 | struct sta_info *sta; |
| 288 | |
| 289 | sta = container_of(wk, struct sta_info, drv_unblock_wk); |
| 290 | |
| 291 | if (sta->dead) |
| 292 | return; |
| 293 | |
Helmut Schaa | 5442047 | 2012-01-17 09:22:49 +0100 | [diff] [blame] | 294 | if (!test_sta_flag(sta, WLAN_STA_PS_STA)) { |
| 295 | local_bh_disable(); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 296 | ieee80211_sta_ps_deliver_wakeup(sta); |
Helmut Schaa | 5442047 | 2012-01-17 09:22:49 +0100 | [diff] [blame] | 297 | local_bh_enable(); |
| 298 | } else if (test_and_clear_sta_flag(sta, WLAN_STA_PSPOLL)) { |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 299 | clear_sta_flag(sta, WLAN_STA_PS_DRIVER); |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 300 | |
| 301 | local_bh_disable(); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 302 | ieee80211_sta_ps_deliver_poll_response(sta); |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 303 | local_bh_enable(); |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 304 | } else if (test_and_clear_sta_flag(sta, WLAN_STA_UAPSD)) { |
| 305 | clear_sta_flag(sta, WLAN_STA_PS_DRIVER); |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 306 | |
| 307 | local_bh_disable(); |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 308 | ieee80211_sta_ps_deliver_uapsd(sta); |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 309 | local_bh_enable(); |
Johannes Berg | 50a9432 | 2010-11-16 11:50:28 -0800 | [diff] [blame] | 310 | } else |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 311 | clear_sta_flag(sta, WLAN_STA_PS_DRIVER); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 312 | } |
| 313 | |
Johannes Berg | af65cd96 | 2009-11-17 18:18:36 +0100 | [diff] [blame] | 314 | static int sta_prepare_rate_control(struct ieee80211_local *local, |
| 315 | struct sta_info *sta, gfp_t gfp) |
| 316 | { |
| 317 | if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) |
| 318 | return 0; |
| 319 | |
Johannes Berg | 889cbb9 | 2012-01-17 10:33:29 +0100 | [diff] [blame] | 320 | sta->rate_ctrl = local->rate_ctrl; |
Johannes Berg | af65cd96 | 2009-11-17 18:18:36 +0100 | [diff] [blame] | 321 | sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl, |
| 322 | &sta->sta, gfp); |
Johannes Berg | 889cbb9 | 2012-01-17 10:33:29 +0100 | [diff] [blame] | 323 | if (!sta->rate_ctrl_priv) |
Johannes Berg | af65cd96 | 2009-11-17 18:18:36 +0100 | [diff] [blame] | 324 | return -ENOMEM; |
Johannes Berg | af65cd96 | 2009-11-17 18:18:36 +0100 | [diff] [blame] | 325 | |
| 326 | return 0; |
| 327 | } |
| 328 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 329 | struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 5654416 | 2011-12-14 13:28:46 +0100 | [diff] [blame] | 330 | const u8 *addr, gfp_t gfp) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 331 | { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 332 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 333 | struct sta_info *sta; |
Mohammed Shafi Shajakhan | ebe27c9 | 2011-04-08 21:24:24 +0530 | [diff] [blame] | 334 | struct timespec uptime; |
Ron Rindjunsky | 16c5f15 | 2007-12-25 17:00:34 +0200 | [diff] [blame] | 335 | int i; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 336 | |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 337 | sta = kzalloc(sizeof(*sta) + local->hw.sta_data_size, gfp); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 338 | if (!sta) |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 339 | return NULL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 340 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 341 | spin_lock_init(&sta->lock); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 342 | INIT_WORK(&sta->drv_unblock_wk, sta_unblock); |
Johannes Berg | 67c282c | 2010-06-10 10:21:43 +0200 | [diff] [blame] | 343 | INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work); |
Johannes Berg | a93e364 | 2010-06-10 10:21:46 +0200 | [diff] [blame] | 344 | mutex_init(&sta->ampdu_mlme.mtx); |
Thomas Pedersen | 87f59c7 | 2013-03-01 22:02:52 -0800 | [diff] [blame] | 345 | #ifdef CONFIG_MAC80211_MESH |
| 346 | if (ieee80211_vif_is_mesh(&sdata->vif) && |
| 347 | !sdata->u.mesh.user_mpm) |
| 348 | init_timer(&sta->plink_timer); |
| 349 | #endif |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 350 | |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 351 | memcpy(sta->sta.addr, addr, ETH_ALEN); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 352 | sta->local = local; |
| 353 | sta->sdata = sdata; |
Felix Fietkau | 8bc8aec | 2011-03-21 20:01:00 +0100 | [diff] [blame] | 354 | sta->last_rx = jiffies; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 355 | |
Johannes Berg | 71ec375 | 2012-01-20 13:55:20 +0100 | [diff] [blame] | 356 | sta->sta_state = IEEE80211_STA_NONE; |
| 357 | |
Mohammed Shafi Shajakhan | ebe27c9 | 2011-04-08 21:24:24 +0530 | [diff] [blame] | 358 | do_posix_clock_monotonic_gettime(&uptime); |
| 359 | sta->last_connected = uptime.tv_sec; |
Bruno Randolf | 541a45a | 2010-12-02 19:12:43 +0900 | [diff] [blame] | 360 | ewma_init(&sta->avg_signal, 1024, 8); |
Felix Fietkau | ef0621e | 2013-04-22 16:29:31 +0200 | [diff] [blame] | 361 | for (i = 0; i < ARRAY_SIZE(sta->chain_signal_avg); i++) |
| 362 | ewma_init(&sta->chain_signal_avg[i], 1024, 8); |
Bruno Randolf | 541a45a | 2010-12-02 19:12:43 +0900 | [diff] [blame] | 363 | |
Johannes Berg | af65cd96 | 2009-11-17 18:18:36 +0100 | [diff] [blame] | 364 | if (sta_prepare_rate_control(local, sta, gfp)) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 365 | kfree(sta); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 366 | return NULL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Johannes Berg | 5a306f5 | 2012-11-14 23:22:21 +0100 | [diff] [blame] | 369 | for (i = 0; i < IEEE80211_NUM_TIDS; i++) { |
Johannes Berg | a622ab7 | 2010-06-10 10:21:39 +0200 | [diff] [blame] | 370 | /* |
| 371 | * timer_to_tid must be initialized with identity mapping |
| 372 | * to enable session_timer's data differentiation. See |
| 373 | * sta_rx_agg_session_timer_expired for usage. |
| 374 | */ |
Ron Rindjunsky | 16c5f15 | 2007-12-25 17:00:34 +0200 | [diff] [blame] | 375 | sta->timer_to_tid[i] = i; |
Ron Rindjunsky | 16c5f15 | 2007-12-25 17:00:34 +0200 | [diff] [blame] | 376 | } |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 377 | for (i = 0; i < IEEE80211_NUM_ACS; i++) { |
| 378 | skb_queue_head_init(&sta->ps_tx_buf[i]); |
| 379 | skb_queue_head_init(&sta->tx_filtered[i]); |
| 380 | } |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 381 | |
Johannes Berg | 5a306f5 | 2012-11-14 23:22:21 +0100 | [diff] [blame] | 382 | for (i = 0; i < IEEE80211_NUM_TIDS; i++) |
Alexey Dobriyan | 4be929b | 2010-05-24 14:33:03 -0700 | [diff] [blame] | 383 | sta->last_seq_ctrl[i] = cpu_to_le16(USHRT_MAX); |
Senthil Balasubramanian | cccaec9 | 2009-05-14 18:42:08 +0530 | [diff] [blame] | 384 | |
Johannes Berg | af0ed69 | 2013-02-12 14:21:00 +0100 | [diff] [blame] | 385 | sta->sta.smps_mode = IEEE80211_SMPS_OFF; |
| 386 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 387 | sta_dbg(sdata, "Allocated STA %pM\n", sta->sta.addr); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 388 | |
| 389 | return sta; |
| 390 | } |
| 391 | |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 392 | static int sta_info_insert_check(struct sta_info *sta) |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 393 | { |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 394 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 395 | |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 396 | /* |
| 397 | * Can't be a WARN_ON because it can be triggered through a race: |
| 398 | * something inserts a STA (on one CPU) without holding the RTNL |
| 399 | * and another CPU turns off the net device. |
| 400 | */ |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 401 | if (unlikely(!ieee80211_sdata_running(sdata))) |
| 402 | return -ENETDOWN; |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 403 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 404 | if (WARN_ON(ether_addr_equal(sta->sta.addr, sdata->vif.addr) || |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 405 | is_multicast_ether_addr(sta->sta.addr))) |
| 406 | return -EINVAL; |
| 407 | |
| 408 | return 0; |
| 409 | } |
| 410 | |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 411 | static int sta_info_insert_drv_state(struct ieee80211_local *local, |
| 412 | struct ieee80211_sub_if_data *sdata, |
| 413 | struct sta_info *sta) |
| 414 | { |
| 415 | enum ieee80211_sta_state state; |
| 416 | int err = 0; |
| 417 | |
| 418 | for (state = IEEE80211_STA_NOTEXIST; state < sta->sta_state; state++) { |
| 419 | err = drv_sta_state(local, sdata, sta, state, state + 1); |
| 420 | if (err) |
| 421 | break; |
| 422 | } |
| 423 | |
| 424 | if (!err) { |
Johannes Berg | a4ec45a | 2012-01-20 13:55:22 +0100 | [diff] [blame] | 425 | /* |
| 426 | * Drivers using legacy sta_add/sta_remove callbacks only |
| 427 | * get uploaded set to true after sta_add is called. |
| 428 | */ |
| 429 | if (!local->ops->sta_add) |
| 430 | sta->uploaded = true; |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 431 | return 0; |
| 432 | } |
| 433 | |
| 434 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 435 | sdata_info(sdata, |
| 436 | "failed to move IBSS STA %pM to state %d (%d) - keeping it anyway\n", |
| 437 | sta->sta.addr, state + 1, err); |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 438 | err = 0; |
| 439 | } |
| 440 | |
| 441 | /* unwind on error */ |
| 442 | for (; state > IEEE80211_STA_NOTEXIST; state--) |
| 443 | WARN_ON(drv_sta_state(local, sdata, sta, state, state - 1)); |
| 444 | |
| 445 | return err; |
| 446 | } |
| 447 | |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 448 | /* |
| 449 | * should be called with sta_mtx locked |
| 450 | * this function replaces the mutex lock |
| 451 | * with a RCU lock |
| 452 | */ |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 453 | static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU) |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 454 | { |
| 455 | struct ieee80211_local *local = sta->local; |
| 456 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 457 | struct station_info sinfo; |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 458 | int err = 0; |
| 459 | |
| 460 | lockdep_assert_held(&local->sta_mtx); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 461 | |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 462 | /* check if STA exists already */ |
| 463 | if (sta_info_get_bss(sdata, sta->sta.addr)) { |
| 464 | err = -EEXIST; |
| 465 | goto out_err; |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 466 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 467 | |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 468 | /* notify driver */ |
| 469 | err = sta_info_insert_drv_state(local, sdata, sta); |
| 470 | if (err) |
| 471 | goto out_err; |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 472 | |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 473 | local->num_sta++; |
| 474 | local->sta_generation++; |
| 475 | smp_mb(); |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 476 | |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 477 | /* make the station visible */ |
| 478 | sta_info_hash_add(local, sta); |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 479 | |
Arik Nemtsov | 794454c | 2012-06-03 23:32:32 +0300 | [diff] [blame] | 480 | list_add_rcu(&sta->list, &local->sta_list); |
Johannes Berg | 83d5cc0 | 2012-01-12 09:31:10 +0100 | [diff] [blame] | 481 | |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 482 | set_sta_flag(sta, WLAN_STA_INSERTED); |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 483 | |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 484 | ieee80211_sta_debugfs_add(sta); |
| 485 | rate_control_add_sta_debugfs(sta); |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 486 | |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 487 | memset(&sinfo, 0, sizeof(sinfo)); |
| 488 | sinfo.filled = 0; |
| 489 | sinfo.generation = local->sta_generation; |
| 490 | cfg80211_new_sta(sdata->dev, sta->sta.addr, &sinfo, GFP_KERNEL); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 491 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 492 | sta_dbg(sdata, "Inserted STA %pM\n", sta->sta.addr); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 493 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 494 | /* move reference to rcu-protected */ |
| 495 | rcu_read_lock(); |
| 496 | mutex_unlock(&local->sta_mtx); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 497 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 498 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
| 499 | mesh_accept_plinks_update(sdata); |
| 500 | |
| 501 | return 0; |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 502 | out_err: |
| 503 | mutex_unlock(&local->sta_mtx); |
| 504 | rcu_read_lock(); |
| 505 | return err; |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU) |
| 509 | { |
| 510 | struct ieee80211_local *local = sta->local; |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 511 | int err = 0; |
| 512 | |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 513 | might_sleep(); |
| 514 | |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 515 | err = sta_info_insert_check(sta); |
| 516 | if (err) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 517 | rcu_read_lock(); |
| 518 | goto out_free; |
| 519 | } |
| 520 | |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 521 | mutex_lock(&local->sta_mtx); |
| 522 | |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 523 | err = sta_info_insert_finish(sta); |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 524 | if (err) |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 525 | goto out_free; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 526 | |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 527 | return 0; |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 528 | out_free: |
| 529 | BUG_ON(!err); |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 530 | sta_info_free(local, sta); |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 531 | return err; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 532 | } |
| 533 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 534 | int sta_info_insert(struct sta_info *sta) |
| 535 | { |
| 536 | int err = sta_info_insert_rcu(sta); |
| 537 | |
| 538 | rcu_read_unlock(); |
| 539 | |
| 540 | return err; |
| 541 | } |
| 542 | |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 543 | static inline void __bss_tim_set(u8 *tim, u16 id) |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 544 | { |
| 545 | /* |
| 546 | * This format has been mandated by the IEEE specifications, |
| 547 | * so this line may not be changed to use the __set_bit() format. |
| 548 | */ |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 549 | tim[id / 8] |= (1 << (id % 8)); |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 550 | } |
| 551 | |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 552 | static inline void __bss_tim_clear(u8 *tim, u16 id) |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 553 | { |
| 554 | /* |
| 555 | * This format has been mandated by the IEEE specifications, |
| 556 | * so this line may not be changed to use the __clear_bit() format. |
| 557 | */ |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 558 | tim[id / 8] &= ~(1 << (id % 8)); |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 559 | } |
| 560 | |
Ilan Peer | 3d5839b | 2013-03-05 15:27:20 +0200 | [diff] [blame] | 561 | static inline bool __bss_tim_get(u8 *tim, u16 id) |
| 562 | { |
| 563 | /* |
| 564 | * This format has been mandated by the IEEE specifications, |
| 565 | * so this line may not be changed to use the test_bit() format. |
| 566 | */ |
| 567 | return tim[id / 8] & (1 << (id % 8)); |
| 568 | } |
| 569 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 570 | static unsigned long ieee80211_tids_for_ac(int ac) |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 571 | { |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 572 | /* If we ever support TIDs > 7, this obviously needs to be adjusted */ |
| 573 | switch (ac) { |
| 574 | case IEEE80211_AC_VO: |
| 575 | return BIT(6) | BIT(7); |
| 576 | case IEEE80211_AC_VI: |
| 577 | return BIT(4) | BIT(5); |
| 578 | case IEEE80211_AC_BE: |
| 579 | return BIT(0) | BIT(3); |
| 580 | case IEEE80211_AC_BK: |
| 581 | return BIT(1) | BIT(2); |
| 582 | default: |
| 583 | WARN_ON(1); |
| 584 | return 0; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 585 | } |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 586 | } |
| 587 | |
Johannes Berg | c868cb35 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 588 | void sta_info_recalc_tim(struct sta_info *sta) |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 589 | { |
Johannes Berg | c868cb35 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 590 | struct ieee80211_local *local = sta->local; |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 591 | struct ps_data *ps; |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 592 | bool indicate_tim = false; |
| 593 | u8 ignore_for_tim = sta->sta.uapsd_queues; |
| 594 | int ac; |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 595 | u16 id; |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 596 | |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 597 | if (sta->sdata->vif.type == NL80211_IFTYPE_AP || |
| 598 | sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) { |
| 599 | if (WARN_ON_ONCE(!sta->sdata->bss)) |
| 600 | return; |
| 601 | |
| 602 | ps = &sta->sdata->bss->ps; |
| 603 | id = sta->sta.aid; |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 604 | #ifdef CONFIG_MAC80211_MESH |
| 605 | } else if (ieee80211_vif_is_mesh(&sta->sdata->vif)) { |
| 606 | ps = &sta->sdata->u.mesh.ps; |
| 607 | /* TIM map only for PLID <= IEEE80211_MAX_AID */ |
| 608 | id = le16_to_cpu(sta->plid) % IEEE80211_MAX_AID; |
| 609 | #endif |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 610 | } else { |
Johannes Berg | c868cb35 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 611 | return; |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 612 | } |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 613 | |
Johannes Berg | c868cb35 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 614 | /* No need to do anything if the driver does all */ |
| 615 | if (local->hw.flags & IEEE80211_HW_AP_LINK_PS) |
| 616 | return; |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 617 | |
Johannes Berg | c868cb35 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 618 | if (sta->dead) |
| 619 | goto done; |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 620 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 621 | /* |
| 622 | * If all ACs are delivery-enabled then we should build |
| 623 | * the TIM bit for all ACs anyway; if only some are then |
| 624 | * we ignore those and build the TIM bit using only the |
| 625 | * non-enabled ones. |
| 626 | */ |
| 627 | if (ignore_for_tim == BIT(IEEE80211_NUM_ACS) - 1) |
| 628 | ignore_for_tim = 0; |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 629 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 630 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 631 | unsigned long tids; |
| 632 | |
| 633 | if (ignore_for_tim & BIT(ac)) |
| 634 | continue; |
| 635 | |
| 636 | indicate_tim |= !skb_queue_empty(&sta->tx_filtered[ac]) || |
| 637 | !skb_queue_empty(&sta->ps_tx_buf[ac]); |
| 638 | if (indicate_tim) |
| 639 | break; |
| 640 | |
| 641 | tids = ieee80211_tids_for_ac(ac); |
| 642 | |
| 643 | indicate_tim |= |
| 644 | sta->driver_buffered_tids & tids; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 645 | } |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 646 | |
Johannes Berg | c868cb35 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 647 | done: |
Johannes Berg | 65f704a | 2013-02-13 17:39:53 +0100 | [diff] [blame] | 648 | spin_lock_bh(&local->tim_lock); |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 649 | |
Ilan Peer | 3d5839b | 2013-03-05 15:27:20 +0200 | [diff] [blame] | 650 | if (indicate_tim == __bss_tim_get(ps->tim, id)) |
| 651 | goto out_unlock; |
| 652 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 653 | if (indicate_tim) |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 654 | __bss_tim_set(ps->tim, id); |
Johannes Berg | c868cb35 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 655 | else |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 656 | __bss_tim_clear(ps->tim, id); |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 657 | |
Johannes Berg | c868cb35 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 658 | if (local->ops->set_tim) { |
| 659 | local->tim_in_locked_section = true; |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 660 | drv_set_tim(local, &sta->sta, indicate_tim); |
Johannes Berg | c868cb35 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 661 | local->tim_in_locked_section = false; |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 662 | } |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 663 | |
Ilan Peer | 3d5839b | 2013-03-05 15:27:20 +0200 | [diff] [blame] | 664 | out_unlock: |
Johannes Berg | 65f704a | 2013-02-13 17:39:53 +0100 | [diff] [blame] | 665 | spin_unlock_bh(&local->tim_lock); |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 666 | } |
| 667 | |
Johannes Berg | cd0b8d8 | 2011-09-06 14:13:06 +0200 | [diff] [blame] | 668 | 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] | 669 | { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 670 | struct ieee80211_tx_info *info; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 671 | int timeout; |
| 672 | |
| 673 | if (!skb) |
Johannes Berg | cd0b8d8 | 2011-09-06 14:13:06 +0200 | [diff] [blame] | 674 | return false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 675 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 676 | info = IEEE80211_SKB_CB(skb); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 677 | |
| 678 | /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */ |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 679 | timeout = (sta->listen_interval * |
| 680 | sta->sdata->vif.bss_conf.beacon_int * |
| 681 | 32 / 15625) * HZ; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 682 | if (timeout < STA_TX_BUFFER_EXPIRE) |
| 683 | timeout = STA_TX_BUFFER_EXPIRE; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 684 | return time_after(jiffies, info->control.jiffies + timeout); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 688 | static bool sta_info_cleanup_expire_buffered_ac(struct ieee80211_local *local, |
| 689 | struct sta_info *sta, int ac) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 690 | { |
| 691 | unsigned long flags; |
| 692 | struct sk_buff *skb; |
| 693 | |
Johannes Berg | 6075039 | 2011-09-29 16:04:28 +0200 | [diff] [blame] | 694 | /* |
| 695 | * First check for frames that should expire on the filtered |
| 696 | * queue. Frames here were rejected by the driver and are on |
| 697 | * a separate queue to avoid reordering with normal PS-buffered |
| 698 | * frames. They also aren't accounted for right now in the |
| 699 | * total_ps_buffered counter. |
| 700 | */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 701 | for (;;) { |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 702 | spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags); |
| 703 | skb = skb_peek(&sta->tx_filtered[ac]); |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 704 | if (sta_info_buffer_expired(sta, skb)) |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 705 | skb = __skb_dequeue(&sta->tx_filtered[ac]); |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 706 | else |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 707 | skb = NULL; |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 708 | spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 709 | |
Johannes Berg | 6075039 | 2011-09-29 16:04:28 +0200 | [diff] [blame] | 710 | /* |
| 711 | * Frames are queued in order, so if this one |
| 712 | * hasn't expired yet we can stop testing. If |
| 713 | * we actually reached the end of the queue we |
| 714 | * also need to stop, of course. |
| 715 | */ |
| 716 | if (!skb) |
| 717 | break; |
Felix Fietkau | d4fa14c | 2012-10-10 22:40:23 +0200 | [diff] [blame] | 718 | ieee80211_free_txskb(&local->hw, skb); |
Johannes Berg | 6075039 | 2011-09-29 16:04:28 +0200 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | /* |
| 722 | * Now also check the normal PS-buffered queue, this will |
| 723 | * only find something if the filtered queue was emptied |
| 724 | * since the filtered frames are all before the normal PS |
| 725 | * buffered frames. |
| 726 | */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 727 | for (;;) { |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 728 | spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags); |
| 729 | skb = skb_peek(&sta->ps_tx_buf[ac]); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 730 | if (sta_info_buffer_expired(sta, skb)) |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 731 | skb = __skb_dequeue(&sta->ps_tx_buf[ac]); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 732 | else |
| 733 | skb = NULL; |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 734 | spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 735 | |
Johannes Berg | 6075039 | 2011-09-29 16:04:28 +0200 | [diff] [blame] | 736 | /* |
| 737 | * frames are queued in order, so if this one |
| 738 | * hasn't expired yet (or we reached the end of |
| 739 | * the queue) we can stop testing |
| 740 | */ |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 741 | if (!skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 742 | break; |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 743 | |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 744 | local->total_ps_buffered--; |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 745 | ps_dbg(sta->sdata, "Buffered frame expired (STA %pM)\n", |
| 746 | sta->sta.addr); |
Felix Fietkau | d4fa14c | 2012-10-10 22:40:23 +0200 | [diff] [blame] | 747 | ieee80211_free_txskb(&local->hw, skb); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 748 | } |
Juuso Oikarinen | 3393a60 | 2010-04-19 10:12:52 +0300 | [diff] [blame] | 749 | |
Johannes Berg | 6075039 | 2011-09-29 16:04:28 +0200 | [diff] [blame] | 750 | /* |
| 751 | * Finally, recalculate the TIM bit for this station -- it might |
| 752 | * now be clear because the station was too slow to retrieve its |
| 753 | * frames. |
| 754 | */ |
| 755 | sta_info_recalc_tim(sta); |
| 756 | |
| 757 | /* |
| 758 | * Return whether there are any frames still buffered, this is |
| 759 | * used to check whether the cleanup timer still needs to run, |
| 760 | * if there are no frames we don't need to rearm the timer. |
| 761 | */ |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 762 | return !(skb_queue_empty(&sta->ps_tx_buf[ac]) && |
| 763 | skb_queue_empty(&sta->tx_filtered[ac])); |
| 764 | } |
| 765 | |
| 766 | static bool sta_info_cleanup_expire_buffered(struct ieee80211_local *local, |
| 767 | struct sta_info *sta) |
| 768 | { |
| 769 | bool have_buffered = false; |
| 770 | int ac; |
| 771 | |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 772 | /* This is only necessary for stations on BSS/MBSS interfaces */ |
| 773 | if (!sta->sdata->bss && |
| 774 | !ieee80211_vif_is_mesh(&sta->sdata->vif)) |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 775 | return false; |
| 776 | |
| 777 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) |
| 778 | have_buffered |= |
| 779 | sta_info_cleanup_expire_buffered_ac(local, sta, ac); |
| 780 | |
| 781 | return have_buffered; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 782 | } |
| 783 | |
Johannes Berg | 83d5cc0 | 2012-01-12 09:31:10 +0100 | [diff] [blame] | 784 | int __must_check __sta_info_destroy(struct sta_info *sta) |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 785 | { |
| 786 | struct ieee80211_local *local; |
| 787 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 6d10e46 | 2013-03-06 23:09:11 +0100 | [diff] [blame] | 788 | int ret; |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 789 | |
| 790 | might_sleep(); |
| 791 | |
| 792 | if (!sta) |
| 793 | return -ENOENT; |
| 794 | |
| 795 | local = sta->local; |
| 796 | sdata = sta->sdata; |
| 797 | |
Johannes Berg | 83d5cc0 | 2012-01-12 09:31:10 +0100 | [diff] [blame] | 798 | lockdep_assert_held(&local->sta_mtx); |
| 799 | |
Johannes Berg | 098a607 | 2010-04-06 11:18:47 +0200 | [diff] [blame] | 800 | /* |
| 801 | * Before removing the station from the driver and |
| 802 | * rate control, it might still start new aggregation |
| 803 | * sessions -- block that to make sure the tear-down |
| 804 | * will be sufficient. |
| 805 | */ |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 806 | set_sta_flag(sta, WLAN_STA_BLOCK_BA); |
Johannes Berg | c82c4a8 | 2012-07-18 13:31:31 +0200 | [diff] [blame] | 807 | ieee80211_sta_tear_down_BA_sessions(sta, AGG_STOP_DESTROY_STA); |
Johannes Berg | 098a607 | 2010-04-06 11:18:47 +0200 | [diff] [blame] | 808 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 809 | ret = sta_info_hash_del(local, sta); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 810 | if (ret) |
| 811 | return ret; |
| 812 | |
Arik Nemtsov | 794454c | 2012-06-03 23:32:32 +0300 | [diff] [blame] | 813 | list_del_rcu(&sta->list); |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 814 | |
Johannes Berg | 6d10e46 | 2013-03-06 23:09:11 +0100 | [diff] [blame] | 815 | /* this always calls synchronize_net() */ |
| 816 | ieee80211_free_sta_keys(local, sta); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 817 | |
| 818 | sta->dead = true; |
| 819 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 820 | local->num_sta--; |
| 821 | local->sta_generation++; |
| 822 | |
| 823 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
Stephen Hemminger | a9b3cd7 | 2011-08-01 16:19:00 +0000 | [diff] [blame] | 824 | RCU_INIT_POINTER(sdata->u.vlan.sta, NULL); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 825 | |
Johannes Berg | 83d5cc0 | 2012-01-12 09:31:10 +0100 | [diff] [blame] | 826 | while (sta->sta_state > IEEE80211_STA_NONE) { |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 827 | ret = sta_info_move_state(sta, sta->sta_state - 1); |
| 828 | if (ret) { |
Johannes Berg | 83d5cc0 | 2012-01-12 09:31:10 +0100 | [diff] [blame] | 829 | WARN_ON_ONCE(1); |
| 830 | break; |
| 831 | } |
| 832 | } |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 833 | |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 834 | if (sta->uploaded) { |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 835 | ret = drv_sta_state(local, sdata, sta, IEEE80211_STA_NONE, |
| 836 | IEEE80211_STA_NOTEXIST); |
| 837 | WARN_ON_ONCE(ret != 0); |
| 838 | } |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 839 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 840 | sta_dbg(sdata, "Removed STA %pM\n", sta->sta.addr); |
| 841 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 842 | cfg80211_del_sta(sdata->dev, sta->sta.addr, GFP_KERNEL); |
| 843 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 844 | rate_control_remove_sta_debugfs(sta); |
| 845 | ieee80211_sta_debugfs_remove(sta); |
| 846 | |
Eliad Peller | b22cfcf | 2012-09-09 14:43:51 +0300 | [diff] [blame] | 847 | call_rcu(&sta->rcu_head, free_sta_rcu); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 848 | |
| 849 | return 0; |
| 850 | } |
| 851 | |
| 852 | int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata, const u8 *addr) |
| 853 | { |
| 854 | struct sta_info *sta; |
| 855 | int ret; |
| 856 | |
| 857 | mutex_lock(&sdata->local->sta_mtx); |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 858 | sta = sta_info_get(sdata, addr); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 859 | ret = __sta_info_destroy(sta); |
| 860 | mutex_unlock(&sdata->local->sta_mtx); |
| 861 | |
| 862 | return ret; |
| 863 | } |
| 864 | |
| 865 | int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata, |
| 866 | const u8 *addr) |
| 867 | { |
| 868 | struct sta_info *sta; |
| 869 | int ret; |
| 870 | |
| 871 | mutex_lock(&sdata->local->sta_mtx); |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 872 | sta = sta_info_get_bss(sdata, addr); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 873 | ret = __sta_info_destroy(sta); |
| 874 | mutex_unlock(&sdata->local->sta_mtx); |
| 875 | |
| 876 | return ret; |
| 877 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 878 | |
| 879 | static void sta_info_cleanup(unsigned long data) |
| 880 | { |
| 881 | struct ieee80211_local *local = (struct ieee80211_local *) data; |
| 882 | struct sta_info *sta; |
Juuso Oikarinen | 3393a60 | 2010-04-19 10:12:52 +0300 | [diff] [blame] | 883 | bool timer_needed = false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 884 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 885 | rcu_read_lock(); |
| 886 | list_for_each_entry_rcu(sta, &local->sta_list, list) |
Juuso Oikarinen | 3393a60 | 2010-04-19 10:12:52 +0300 | [diff] [blame] | 887 | if (sta_info_cleanup_expire_buffered(local, sta)) |
| 888 | timer_needed = true; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 889 | rcu_read_unlock(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 890 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 891 | if (local->quiescing) |
| 892 | return; |
| 893 | |
Juuso Oikarinen | 3393a60 | 2010-04-19 10:12:52 +0300 | [diff] [blame] | 894 | if (!timer_needed) |
| 895 | return; |
| 896 | |
Johannes Berg | 26d5953 | 2011-04-01 13:52:48 +0200 | [diff] [blame] | 897 | mod_timer(&local->sta_cleanup, |
| 898 | round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | void sta_info_init(struct ieee80211_local *local) |
| 902 | { |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 903 | spin_lock_init(&local->tim_lock); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 904 | mutex_init(&local->sta_mtx); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 905 | INIT_LIST_HEAD(&local->sta_list); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 906 | |
Pavel Emelyanov | b24b8a2 | 2008-01-23 21:20:07 -0800 | [diff] [blame] | 907 | setup_timer(&local->sta_cleanup, sta_info_cleanup, |
| 908 | (unsigned long)local); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | void sta_info_stop(struct ieee80211_local *local) |
| 912 | { |
Johannes Berg | a56f992 | 2012-12-13 23:08:52 +0100 | [diff] [blame] | 913 | del_timer_sync(&local->sta_cleanup); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 914 | } |
| 915 | |
Johannes Berg | 051007d | 2012-12-13 23:49:02 +0100 | [diff] [blame] | 916 | |
| 917 | int sta_info_flush_defer(struct ieee80211_sub_if_data *sdata) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 918 | { |
Johannes Berg | b998e8b | 2012-12-13 23:07:46 +0100 | [diff] [blame] | 919 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 920 | struct sta_info *sta, *tmp; |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 921 | int ret = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 922 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 923 | might_sleep(); |
| 924 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 925 | mutex_lock(&local->sta_mtx); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 926 | list_for_each_entry_safe(sta, tmp, &local->sta_list, list) { |
Johannes Berg | b998e8b | 2012-12-13 23:07:46 +0100 | [diff] [blame] | 927 | if (sdata == sta->sdata) { |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 928 | WARN_ON(__sta_info_destroy(sta)); |
Johannes Berg | 3431683 | 2012-02-25 21:40:46 +0100 | [diff] [blame] | 929 | ret++; |
| 930 | } |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 931 | } |
| 932 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 933 | |
Johannes Berg | 051007d | 2012-12-13 23:49:02 +0100 | [diff] [blame] | 934 | return ret; |
| 935 | } |
| 936 | |
| 937 | void sta_info_flush_cleanup(struct ieee80211_sub_if_data *sdata) |
| 938 | { |
Johannes Berg | b998e8b | 2012-12-13 23:07:46 +0100 | [diff] [blame] | 939 | ieee80211_cleanup_sdata_stas(sdata); |
| 940 | cancel_work_sync(&sdata->cleanup_stations_wk); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 941 | } |
Johannes Berg | dc6676b | 2008-03-31 19:23:03 +0200 | [diff] [blame] | 942 | |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 943 | void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata, |
| 944 | unsigned long exp_time) |
| 945 | { |
| 946 | struct ieee80211_local *local = sdata->local; |
| 947 | struct sta_info *sta, *tmp; |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 948 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 949 | mutex_lock(&local->sta_mtx); |
Mohammed Shafi Shajakhan | e46a2cf | 2011-12-26 10:43:29 +0530 | [diff] [blame] | 950 | |
| 951 | list_for_each_entry_safe(sta, tmp, &local->sta_list, list) { |
Marek Lindner | ec2b774 | 2011-12-20 23:16:52 +0800 | [diff] [blame] | 952 | if (sdata != sta->sdata) |
| 953 | continue; |
| 954 | |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 955 | if (time_after(jiffies, sta->last_rx + exp_time)) { |
Mohammed Shafi Shajakhan | eea57d4 | 2012-10-08 21:33:47 +0530 | [diff] [blame] | 956 | sta_dbg(sta->sdata, "expiring inactive STA %pM\n", |
| 957 | sta->sta.addr); |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 958 | |
| 959 | if (ieee80211_vif_is_mesh(&sdata->vif) && |
| 960 | test_sta_flag(sta, WLAN_STA_PS_STA)) |
| 961 | atomic_dec(&sdata->u.mesh.ps.num_sta_ps); |
| 962 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 963 | WARN_ON(__sta_info_destroy(sta)); |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 964 | } |
Mohammed Shafi Shajakhan | e46a2cf | 2011-12-26 10:43:29 +0530 | [diff] [blame] | 965 | } |
| 966 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 967 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 968 | } |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 969 | |
Ben Greear | 686b9cb | 2010-09-23 09:44:36 -0700 | [diff] [blame] | 970 | struct ieee80211_sta *ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw, |
| 971 | const u8 *addr, |
| 972 | const u8 *localaddr) |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 973 | { |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 974 | struct sta_info *sta, *nxt; |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 975 | |
Ben Greear | 686b9cb | 2010-09-23 09:44:36 -0700 | [diff] [blame] | 976 | /* |
| 977 | * Just return a random station if localaddr is NULL |
| 978 | * ... first in list. |
| 979 | */ |
Johannes Berg | f7c6559 | 2010-04-30 13:48:36 +0200 | [diff] [blame] | 980 | for_each_sta_info(hw_to_local(hw), addr, sta, nxt) { |
Ben Greear | 686b9cb | 2010-09-23 09:44:36 -0700 | [diff] [blame] | 981 | if (localaddr && |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 982 | !ether_addr_equal(sta->sdata->vif.addr, localaddr)) |
Ben Greear | 686b9cb | 2010-09-23 09:44:36 -0700 | [diff] [blame] | 983 | continue; |
Johannes Berg | f7c6559 | 2010-04-30 13:48:36 +0200 | [diff] [blame] | 984 | if (!sta->uploaded) |
| 985 | return NULL; |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 986 | return &sta->sta; |
Johannes Berg | f7c6559 | 2010-04-30 13:48:36 +0200 | [diff] [blame] | 987 | } |
| 988 | |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 989 | return NULL; |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 990 | } |
Ben Greear | 686b9cb | 2010-09-23 09:44:36 -0700 | [diff] [blame] | 991 | EXPORT_SYMBOL_GPL(ieee80211_find_sta_by_ifaddr); |
Johannes Berg | 5ed176e | 2009-11-04 14:42:28 +0100 | [diff] [blame] | 992 | |
| 993 | struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_vif *vif, |
| 994 | const u8 *addr) |
| 995 | { |
Johannes Berg | f7c6559 | 2010-04-30 13:48:36 +0200 | [diff] [blame] | 996 | struct sta_info *sta; |
Johannes Berg | 5ed176e | 2009-11-04 14:42:28 +0100 | [diff] [blame] | 997 | |
| 998 | if (!vif) |
| 999 | return NULL; |
| 1000 | |
Johannes Berg | f7c6559 | 2010-04-30 13:48:36 +0200 | [diff] [blame] | 1001 | sta = sta_info_get_bss(vif_to_sdata(vif), addr); |
| 1002 | if (!sta) |
| 1003 | return NULL; |
Johannes Berg | 5ed176e | 2009-11-04 14:42:28 +0100 | [diff] [blame] | 1004 | |
Johannes Berg | f7c6559 | 2010-04-30 13:48:36 +0200 | [diff] [blame] | 1005 | if (!sta->uploaded) |
| 1006 | return NULL; |
| 1007 | |
| 1008 | return &sta->sta; |
Johannes Berg | 5ed176e | 2009-11-04 14:42:28 +0100 | [diff] [blame] | 1009 | } |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 1010 | EXPORT_SYMBOL(ieee80211_find_sta); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1011 | |
Johannes Berg | 50a9432 | 2010-11-16 11:50:28 -0800 | [diff] [blame] | 1012 | static void clear_sta_ps_flags(void *_sta) |
| 1013 | { |
| 1014 | struct sta_info *sta = _sta; |
Helmut Schaa | 608383b | 2012-01-30 15:18:00 +0100 | [diff] [blame] | 1015 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 1016 | struct ps_data *ps; |
| 1017 | |
| 1018 | if (sdata->vif.type == NL80211_IFTYPE_AP || |
| 1019 | sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
| 1020 | ps = &sdata->bss->ps; |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 1021 | else if (ieee80211_vif_is_mesh(&sdata->vif)) |
| 1022 | ps = &sdata->u.mesh.ps; |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 1023 | else |
| 1024 | return; |
Johannes Berg | 50a9432 | 2010-11-16 11:50:28 -0800 | [diff] [blame] | 1025 | |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1026 | clear_sta_flag(sta, WLAN_STA_PS_DRIVER); |
Helmut Schaa | 608383b | 2012-01-30 15:18:00 +0100 | [diff] [blame] | 1027 | if (test_and_clear_sta_flag(sta, WLAN_STA_PS_STA)) |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 1028 | atomic_dec(&ps->num_sta_ps); |
Johannes Berg | 50a9432 | 2010-11-16 11:50:28 -0800 | [diff] [blame] | 1029 | } |
| 1030 | |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1031 | /* powersave support code */ |
| 1032 | void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta) |
| 1033 | { |
| 1034 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 1035 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1036 | struct sk_buff_head pending; |
| 1037 | int filtered = 0, buffered = 0, ac; |
Arik Nemtsov | 987c285 | 2012-11-05 10:27:52 +0200 | [diff] [blame] | 1038 | unsigned long flags; |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1039 | |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1040 | clear_sta_flag(sta, WLAN_STA_SP); |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1041 | |
Johannes Berg | 5a306f5 | 2012-11-14 23:22:21 +0100 | [diff] [blame] | 1042 | BUILD_BUG_ON(BITS_TO_LONGS(IEEE80211_NUM_TIDS) > 1); |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1043 | sta->driver_buffered_tids = 0; |
| 1044 | |
Arik Nemtsov | d057e5a | 2011-01-31 22:29:13 +0200 | [diff] [blame] | 1045 | if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS)) |
| 1046 | drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1047 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1048 | skb_queue_head_init(&pending); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1049 | |
| 1050 | /* Send all buffered frames to the station */ |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1051 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 1052 | int count = skb_queue_len(&pending), tmp; |
| 1053 | |
Arik Nemtsov | 987c285 | 2012-11-05 10:27:52 +0200 | [diff] [blame] | 1054 | spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags); |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1055 | skb_queue_splice_tail_init(&sta->tx_filtered[ac], &pending); |
Arik Nemtsov | 987c285 | 2012-11-05 10:27:52 +0200 | [diff] [blame] | 1056 | spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags); |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1057 | tmp = skb_queue_len(&pending); |
| 1058 | filtered += tmp - count; |
| 1059 | count = tmp; |
| 1060 | |
Arik Nemtsov | 987c285 | 2012-11-05 10:27:52 +0200 | [diff] [blame] | 1061 | spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags); |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1062 | skb_queue_splice_tail_init(&sta->ps_tx_buf[ac], &pending); |
Arik Nemtsov | 987c285 | 2012-11-05 10:27:52 +0200 | [diff] [blame] | 1063 | spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags); |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1064 | tmp = skb_queue_len(&pending); |
| 1065 | buffered += tmp - count; |
| 1066 | } |
| 1067 | |
| 1068 | ieee80211_add_pending_skbs_fn(local, &pending, clear_sta_ps_flags, sta); |
| 1069 | |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1070 | local->total_ps_buffered -= buffered; |
| 1071 | |
Johannes Berg | c868cb35 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 1072 | sta_info_recalc_tim(sta); |
| 1073 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 1074 | ps_dbg(sdata, |
| 1075 | "STA %pM aid %d sending %d filtered/%d PS frames since STA not sleeping anymore\n", |
| 1076 | sta->sta.addr, sta->sta.aid, filtered, buffered); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1077 | } |
| 1078 | |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1079 | static void ieee80211_send_null_response(struct ieee80211_sub_if_data *sdata, |
| 1080 | struct sta_info *sta, int tid, |
Johannes Berg | 40b9640 | 2011-09-29 16:04:38 +0200 | [diff] [blame] | 1081 | enum ieee80211_frame_release_type reason) |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1082 | { |
| 1083 | struct ieee80211_local *local = sdata->local; |
| 1084 | struct ieee80211_qos_hdr *nullfunc; |
| 1085 | struct sk_buff *skb; |
| 1086 | int size = sizeof(*nullfunc); |
| 1087 | __le16 fc; |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1088 | bool qos = test_sta_flag(sta, WLAN_STA_WME); |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1089 | struct ieee80211_tx_info *info; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1090 | struct ieee80211_chanctx_conf *chanctx_conf; |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1091 | |
| 1092 | if (qos) { |
| 1093 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | |
| 1094 | IEEE80211_STYPE_QOS_NULLFUNC | |
| 1095 | IEEE80211_FCTL_FROMDS); |
| 1096 | } else { |
| 1097 | size -= 2; |
| 1098 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | |
| 1099 | IEEE80211_STYPE_NULLFUNC | |
| 1100 | IEEE80211_FCTL_FROMDS); |
| 1101 | } |
| 1102 | |
| 1103 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + size); |
| 1104 | if (!skb) |
| 1105 | return; |
| 1106 | |
| 1107 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 1108 | |
| 1109 | nullfunc = (void *) skb_put(skb, size); |
| 1110 | nullfunc->frame_control = fc; |
| 1111 | nullfunc->duration_id = 0; |
| 1112 | memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN); |
| 1113 | memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); |
| 1114 | memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN); |
| 1115 | |
Johannes Berg | 59b6625 | 2011-10-13 13:19:19 +0200 | [diff] [blame] | 1116 | skb->priority = tid; |
| 1117 | skb_set_queue_mapping(skb, ieee802_1d_to_ac[tid]); |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1118 | if (qos) { |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1119 | nullfunc->qos_ctrl = cpu_to_le16(tid); |
| 1120 | |
Johannes Berg | 40b9640 | 2011-09-29 16:04:38 +0200 | [diff] [blame] | 1121 | if (reason == IEEE80211_FRAME_RELEASE_UAPSD) |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1122 | nullfunc->qos_ctrl |= |
| 1123 | cpu_to_le16(IEEE80211_QOS_CTL_EOSP); |
| 1124 | } |
| 1125 | |
| 1126 | info = IEEE80211_SKB_CB(skb); |
| 1127 | |
| 1128 | /* |
| 1129 | * Tell TX path to send this frame even though the |
| 1130 | * STA may still remain is PS mode after this frame |
Johannes Berg | deeaee19 | 2011-09-29 16:04:35 +0200 | [diff] [blame] | 1131 | * exchange. Also set EOSP to indicate this packet |
| 1132 | * ends the poll/service period. |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1133 | */ |
Johannes Berg | 02f2f1a | 2012-02-27 12:18:30 +0100 | [diff] [blame] | 1134 | info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER | |
Felix Fietkau | d6d23de | 2013-06-04 12:15:42 +0200 | [diff] [blame^] | 1135 | IEEE80211_TX_CTL_PS_RESPONSE | |
Johannes Berg | deeaee19 | 2011-09-29 16:04:35 +0200 | [diff] [blame] | 1136 | IEEE80211_TX_STATUS_EOSP | |
| 1137 | IEEE80211_TX_CTL_REQ_TX_STATUS; |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1138 | |
Johannes Berg | 40b9640 | 2011-09-29 16:04:38 +0200 | [diff] [blame] | 1139 | drv_allow_buffered_frames(local, sta, BIT(tid), 1, reason, false); |
| 1140 | |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 1141 | skb->dev = sdata->dev; |
| 1142 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1143 | rcu_read_lock(); |
| 1144 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 1145 | if (WARN_ON(!chanctx_conf)) { |
| 1146 | rcu_read_unlock(); |
| 1147 | kfree_skb(skb); |
| 1148 | return; |
| 1149 | } |
| 1150 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 1151 | ieee80211_xmit(sdata, skb, chanctx_conf->def.chan->band); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1152 | rcu_read_unlock(); |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1153 | } |
| 1154 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1155 | static void |
| 1156 | ieee80211_sta_ps_deliver_response(struct sta_info *sta, |
| 1157 | int n_frames, u8 ignored_acs, |
| 1158 | enum ieee80211_frame_release_type reason) |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1159 | { |
| 1160 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 1161 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1162 | bool found = false; |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1163 | bool more_data = false; |
| 1164 | int ac; |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1165 | unsigned long driver_release_tids = 0; |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1166 | struct sk_buff_head frames; |
| 1167 | |
Johannes Berg | deeaee19 | 2011-09-29 16:04:35 +0200 | [diff] [blame] | 1168 | /* Service or PS-Poll period starts */ |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1169 | set_sta_flag(sta, WLAN_STA_SP); |
Johannes Berg | deeaee19 | 2011-09-29 16:04:35 +0200 | [diff] [blame] | 1170 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1171 | __skb_queue_head_init(&frames); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1172 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1173 | /* |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1174 | * Get response frame(s) and more data bit for it. |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1175 | */ |
| 1176 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1177 | unsigned long tids; |
| 1178 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1179 | if (ignored_acs & BIT(ac)) |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1180 | continue; |
| 1181 | |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1182 | tids = ieee80211_tids_for_ac(ac); |
| 1183 | |
| 1184 | if (!found) { |
| 1185 | driver_release_tids = sta->driver_buffered_tids & tids; |
| 1186 | if (driver_release_tids) { |
| 1187 | found = true; |
| 1188 | } else { |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1189 | struct sk_buff *skb; |
| 1190 | |
| 1191 | while (n_frames > 0) { |
| 1192 | skb = skb_dequeue(&sta->tx_filtered[ac]); |
| 1193 | if (!skb) { |
| 1194 | skb = skb_dequeue( |
| 1195 | &sta->ps_tx_buf[ac]); |
| 1196 | if (skb) |
| 1197 | local->total_ps_buffered--; |
| 1198 | } |
| 1199 | if (!skb) |
| 1200 | break; |
| 1201 | n_frames--; |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1202 | found = true; |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1203 | __skb_queue_tail(&frames, skb); |
| 1204 | } |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | /* |
| 1208 | * If the driver has data on more than one TID then |
| 1209 | * certainly there's more data if we release just a |
| 1210 | * single frame now (from a single TID). |
| 1211 | */ |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1212 | if (reason == IEEE80211_FRAME_RELEASE_PSPOLL && |
| 1213 | hweight16(driver_release_tids) > 1) { |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1214 | more_data = true; |
| 1215 | driver_release_tids = |
| 1216 | BIT(ffs(driver_release_tids) - 1); |
| 1217 | break; |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1218 | } |
| 1219 | } |
| 1220 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1221 | if (!skb_queue_empty(&sta->tx_filtered[ac]) || |
| 1222 | !skb_queue_empty(&sta->ps_tx_buf[ac])) { |
| 1223 | more_data = true; |
| 1224 | break; |
| 1225 | } |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1226 | } |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1227 | |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1228 | if (!found) { |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1229 | int tid; |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1230 | |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1231 | /* |
| 1232 | * For PS-Poll, this can only happen due to a race condition |
| 1233 | * when we set the TIM bit and the station notices it, but |
| 1234 | * before it can poll for the frame we expire it. |
| 1235 | * |
| 1236 | * For uAPSD, this is said in the standard (11.2.1.5 h): |
| 1237 | * At each unscheduled SP for a non-AP STA, the AP shall |
| 1238 | * attempt to transmit at least one MSDU or MMPDU, but no |
| 1239 | * more than the value specified in the Max SP Length field |
| 1240 | * in the QoS Capability element from delivery-enabled ACs, |
| 1241 | * that are destined for the non-AP STA. |
| 1242 | * |
| 1243 | * Since we have no other MSDU/MMPDU, transmit a QoS null frame. |
| 1244 | */ |
| 1245 | |
| 1246 | /* This will evaluate to 1, 3, 5 or 7. */ |
| 1247 | tid = 7 - ((ffs(~ignored_acs) - 1) << 1); |
| 1248 | |
Johannes Berg | 40b9640 | 2011-09-29 16:04:38 +0200 | [diff] [blame] | 1249 | ieee80211_send_null_response(sdata, sta, tid, reason); |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1250 | return; |
| 1251 | } |
| 1252 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1253 | if (!driver_release_tids) { |
| 1254 | struct sk_buff_head pending; |
| 1255 | struct sk_buff *skb; |
Johannes Berg | 40b9640 | 2011-09-29 16:04:38 +0200 | [diff] [blame] | 1256 | int num = 0; |
| 1257 | u16 tids = 0; |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1258 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1259 | skb_queue_head_init(&pending); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1260 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1261 | while ((skb = __skb_dequeue(&frames))) { |
| 1262 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1263 | struct ieee80211_hdr *hdr = (void *) skb->data; |
Johannes Berg | 40b9640 | 2011-09-29 16:04:38 +0200 | [diff] [blame] | 1264 | u8 *qoshdr = NULL; |
| 1265 | |
| 1266 | num++; |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1267 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1268 | /* |
| 1269 | * Tell TX path to send this frame even though the |
| 1270 | * STA may still remain is PS mode after this frame |
| 1271 | * exchange. |
| 1272 | */ |
Felix Fietkau | d6d23de | 2013-06-04 12:15:42 +0200 | [diff] [blame^] | 1273 | info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER | |
| 1274 | IEEE80211_TX_CTL_PS_RESPONSE; |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1275 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1276 | /* |
| 1277 | * Use MoreData flag to indicate whether there are |
| 1278 | * more buffered frames for this STA |
| 1279 | */ |
Janusz.Dziedzic@tieto.com | 24b9c37 | 2011-11-07 09:47:47 +0200 | [diff] [blame] | 1280 | if (more_data || !skb_queue_empty(&frames)) |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1281 | hdr->frame_control |= |
| 1282 | cpu_to_le16(IEEE80211_FCTL_MOREDATA); |
Janusz.Dziedzic@tieto.com | 24b9c37 | 2011-11-07 09:47:47 +0200 | [diff] [blame] | 1283 | else |
| 1284 | hdr->frame_control &= |
| 1285 | cpu_to_le16(~IEEE80211_FCTL_MOREDATA); |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1286 | |
Johannes Berg | 40b9640 | 2011-09-29 16:04:38 +0200 | [diff] [blame] | 1287 | if (ieee80211_is_data_qos(hdr->frame_control) || |
| 1288 | ieee80211_is_qos_nullfunc(hdr->frame_control)) |
| 1289 | qoshdr = ieee80211_get_qos_ctl(hdr); |
| 1290 | |
Marco Porsch | 52a3f20 | 2012-03-16 15:30:26 +0100 | [diff] [blame] | 1291 | /* end service period after last frame */ |
| 1292 | if (skb_queue_empty(&frames)) { |
| 1293 | if (reason == IEEE80211_FRAME_RELEASE_UAPSD && |
| 1294 | qoshdr) |
| 1295 | *qoshdr |= IEEE80211_QOS_CTL_EOSP; |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1296 | |
Marco Porsch | 52a3f20 | 2012-03-16 15:30:26 +0100 | [diff] [blame] | 1297 | info->flags |= IEEE80211_TX_STATUS_EOSP | |
| 1298 | IEEE80211_TX_CTL_REQ_TX_STATUS; |
| 1299 | } |
Johannes Berg | deeaee19 | 2011-09-29 16:04:35 +0200 | [diff] [blame] | 1300 | |
Johannes Berg | 40b9640 | 2011-09-29 16:04:38 +0200 | [diff] [blame] | 1301 | if (qoshdr) |
| 1302 | tids |= BIT(*qoshdr & IEEE80211_QOS_CTL_TID_MASK); |
| 1303 | else |
| 1304 | tids |= BIT(0); |
| 1305 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1306 | __skb_queue_tail(&pending, skb); |
| 1307 | } |
| 1308 | |
Johannes Berg | 40b9640 | 2011-09-29 16:04:38 +0200 | [diff] [blame] | 1309 | drv_allow_buffered_frames(local, sta, tids, num, |
| 1310 | reason, more_data); |
| 1311 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1312 | ieee80211_add_pending_skbs(local, &pending); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1313 | |
Johannes Berg | c868cb35 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 1314 | sta_info_recalc_tim(sta); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1315 | } else { |
| 1316 | /* |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1317 | * We need to release a frame that is buffered somewhere in the |
| 1318 | * driver ... it'll have to handle that. |
| 1319 | * Note that, as per the comment above, it'll also have to see |
| 1320 | * if there is more than just one frame on the specific TID that |
| 1321 | * we're releasing from, and it needs to set the more-data bit |
| 1322 | * accordingly if we tell it that there's no more data. If we do |
| 1323 | * tell it there's more data, then of course the more-data bit |
| 1324 | * needs to be set anyway. |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1325 | */ |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1326 | drv_release_buffered_frames(local, sta, driver_release_tids, |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1327 | n_frames, reason, more_data); |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1328 | |
| 1329 | /* |
| 1330 | * Note that we don't recalculate the TIM bit here as it would |
| 1331 | * most likely have no effect at all unless the driver told us |
| 1332 | * that the TID became empty before returning here from the |
| 1333 | * release function. |
| 1334 | * Either way, however, when the driver tells us that the TID |
| 1335 | * became empty we'll do the TIM recalculation. |
| 1336 | */ |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1337 | } |
| 1338 | } |
| 1339 | |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1340 | void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta) |
| 1341 | { |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1342 | u8 ignore_for_response = sta->sta.uapsd_queues; |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1343 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1344 | /* |
| 1345 | * If all ACs are delivery-enabled then we should reply |
| 1346 | * from any of them, if only some are enabled we reply |
| 1347 | * only from the non-enabled ones. |
| 1348 | */ |
| 1349 | if (ignore_for_response == BIT(IEEE80211_NUM_ACS) - 1) |
| 1350 | ignore_for_response = 0; |
| 1351 | |
| 1352 | ieee80211_sta_ps_deliver_response(sta, 1, ignore_for_response, |
| 1353 | IEEE80211_FRAME_RELEASE_PSPOLL); |
| 1354 | } |
| 1355 | |
| 1356 | void ieee80211_sta_ps_deliver_uapsd(struct sta_info *sta) |
| 1357 | { |
| 1358 | int n_frames = sta->sta.max_sp; |
| 1359 | u8 delivery_enabled = sta->sta.uapsd_queues; |
| 1360 | |
| 1361 | /* |
| 1362 | * If we ever grow support for TSPEC this might happen if |
| 1363 | * the TSPEC update from hostapd comes in between a trigger |
| 1364 | * frame setting WLAN_STA_UAPSD in the RX path and this |
| 1365 | * actually getting called. |
| 1366 | */ |
| 1367 | if (!delivery_enabled) |
| 1368 | return; |
| 1369 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1370 | switch (sta->sta.max_sp) { |
| 1371 | case 1: |
| 1372 | n_frames = 2; |
| 1373 | break; |
| 1374 | case 2: |
| 1375 | n_frames = 4; |
| 1376 | break; |
| 1377 | case 3: |
| 1378 | n_frames = 6; |
| 1379 | break; |
| 1380 | case 0: |
| 1381 | /* XXX: what is a good value? */ |
| 1382 | n_frames = 8; |
| 1383 | break; |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1384 | } |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1385 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1386 | ieee80211_sta_ps_deliver_response(sta, n_frames, ~delivery_enabled, |
| 1387 | IEEE80211_FRAME_RELEASE_UAPSD); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | void ieee80211_sta_block_awake(struct ieee80211_hw *hw, |
| 1391 | struct ieee80211_sta *pubsta, bool block) |
| 1392 | { |
| 1393 | struct sta_info *sta = container_of(pubsta, struct sta_info, sta); |
| 1394 | |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 1395 | trace_api_sta_block_awake(sta->local, pubsta, block); |
| 1396 | |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1397 | if (block) |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1398 | set_sta_flag(sta, WLAN_STA_PS_DRIVER); |
| 1399 | else if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1400 | ieee80211_queue_work(hw, &sta->drv_unblock_wk); |
| 1401 | } |
| 1402 | EXPORT_SYMBOL(ieee80211_sta_block_awake); |
Felix Fietkau | dcf55fb | 2011-04-17 17:45:00 +0200 | [diff] [blame] | 1403 | |
Johannes Berg | e943789 | 2013-02-15 21:38:08 +0100 | [diff] [blame] | 1404 | void ieee80211_sta_eosp(struct ieee80211_sta *pubsta) |
Johannes Berg | 37fbd90 | 2011-09-29 16:04:39 +0200 | [diff] [blame] | 1405 | { |
| 1406 | struct sta_info *sta = container_of(pubsta, struct sta_info, sta); |
| 1407 | struct ieee80211_local *local = sta->local; |
Johannes Berg | 37fbd90 | 2011-09-29 16:04:39 +0200 | [diff] [blame] | 1408 | |
| 1409 | trace_api_eosp(local, pubsta); |
| 1410 | |
Johannes Berg | e943789 | 2013-02-15 21:38:08 +0100 | [diff] [blame] | 1411 | clear_sta_flag(sta, WLAN_STA_SP); |
Johannes Berg | 37fbd90 | 2011-09-29 16:04:39 +0200 | [diff] [blame] | 1412 | } |
Johannes Berg | e943789 | 2013-02-15 21:38:08 +0100 | [diff] [blame] | 1413 | EXPORT_SYMBOL(ieee80211_sta_eosp); |
Johannes Berg | 37fbd90 | 2011-09-29 16:04:39 +0200 | [diff] [blame] | 1414 | |
Johannes Berg | 042ec45 | 2011-09-29 16:04:26 +0200 | [diff] [blame] | 1415 | void ieee80211_sta_set_buffered(struct ieee80211_sta *pubsta, |
| 1416 | u8 tid, bool buffered) |
Felix Fietkau | dcf55fb | 2011-04-17 17:45:00 +0200 | [diff] [blame] | 1417 | { |
| 1418 | struct sta_info *sta = container_of(pubsta, struct sta_info, sta); |
| 1419 | |
Johannes Berg | 5a306f5 | 2012-11-14 23:22:21 +0100 | [diff] [blame] | 1420 | if (WARN_ON(tid >= IEEE80211_NUM_TIDS)) |
Johannes Berg | 042ec45 | 2011-09-29 16:04:26 +0200 | [diff] [blame] | 1421 | return; |
| 1422 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1423 | if (buffered) |
| 1424 | set_bit(tid, &sta->driver_buffered_tids); |
| 1425 | else |
| 1426 | clear_bit(tid, &sta->driver_buffered_tids); |
| 1427 | |
Johannes Berg | c868cb35 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 1428 | sta_info_recalc_tim(sta); |
Felix Fietkau | dcf55fb | 2011-04-17 17:45:00 +0200 | [diff] [blame] | 1429 | } |
Johannes Berg | 042ec45 | 2011-09-29 16:04:26 +0200 | [diff] [blame] | 1430 | EXPORT_SYMBOL(ieee80211_sta_set_buffered); |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1431 | |
Johannes Berg | 83d5cc0 | 2012-01-12 09:31:10 +0100 | [diff] [blame] | 1432 | int sta_info_move_state(struct sta_info *sta, |
| 1433 | enum ieee80211_sta_state new_state) |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1434 | { |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 1435 | might_sleep(); |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1436 | |
| 1437 | if (sta->sta_state == new_state) |
| 1438 | return 0; |
| 1439 | |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 1440 | /* check allowed transitions first */ |
| 1441 | |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1442 | switch (new_state) { |
| 1443 | case IEEE80211_STA_NONE: |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 1444 | if (sta->sta_state != IEEE80211_STA_AUTH) |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1445 | return -EINVAL; |
| 1446 | break; |
| 1447 | case IEEE80211_STA_AUTH: |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 1448 | if (sta->sta_state != IEEE80211_STA_NONE && |
| 1449 | sta->sta_state != IEEE80211_STA_ASSOC) |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1450 | return -EINVAL; |
| 1451 | break; |
| 1452 | case IEEE80211_STA_ASSOC: |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 1453 | if (sta->sta_state != IEEE80211_STA_AUTH && |
| 1454 | sta->sta_state != IEEE80211_STA_AUTHORIZED) |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1455 | return -EINVAL; |
| 1456 | break; |
| 1457 | case IEEE80211_STA_AUTHORIZED: |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 1458 | if (sta->sta_state != IEEE80211_STA_ASSOC) |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1459 | return -EINVAL; |
| 1460 | break; |
| 1461 | default: |
| 1462 | WARN(1, "invalid state %d", new_state); |
| 1463 | return -EINVAL; |
| 1464 | } |
| 1465 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 1466 | sta_dbg(sta->sdata, "moving STA %pM to state %d\n", |
| 1467 | sta->sta.addr, new_state); |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 1468 | |
| 1469 | /* |
| 1470 | * notify the driver before the actual changes so it can |
| 1471 | * fail the transition |
| 1472 | */ |
| 1473 | if (test_sta_flag(sta, WLAN_STA_INSERTED)) { |
| 1474 | int err = drv_sta_state(sta->local, sta->sdata, sta, |
| 1475 | sta->sta_state, new_state); |
| 1476 | if (err) |
| 1477 | return err; |
| 1478 | } |
| 1479 | |
| 1480 | /* reflect the change in all state variables */ |
| 1481 | |
| 1482 | switch (new_state) { |
| 1483 | case IEEE80211_STA_NONE: |
| 1484 | if (sta->sta_state == IEEE80211_STA_AUTH) |
| 1485 | clear_bit(WLAN_STA_AUTH, &sta->_flags); |
| 1486 | break; |
| 1487 | case IEEE80211_STA_AUTH: |
| 1488 | if (sta->sta_state == IEEE80211_STA_NONE) |
| 1489 | set_bit(WLAN_STA_AUTH, &sta->_flags); |
| 1490 | else if (sta->sta_state == IEEE80211_STA_ASSOC) |
| 1491 | clear_bit(WLAN_STA_ASSOC, &sta->_flags); |
| 1492 | break; |
| 1493 | case IEEE80211_STA_ASSOC: |
| 1494 | if (sta->sta_state == IEEE80211_STA_AUTH) { |
| 1495 | set_bit(WLAN_STA_ASSOC, &sta->_flags); |
| 1496 | } else if (sta->sta_state == IEEE80211_STA_AUTHORIZED) { |
Felix Fietkau | 7e3ed02 | 2012-04-23 19:49:03 +0200 | [diff] [blame] | 1497 | if (sta->sdata->vif.type == NL80211_IFTYPE_AP || |
| 1498 | (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN && |
| 1499 | !sta->sdata->u.vlan.sta)) |
| 1500 | atomic_dec(&sta->sdata->bss->num_mcast_sta); |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 1501 | clear_bit(WLAN_STA_AUTHORIZED, &sta->_flags); |
| 1502 | } |
| 1503 | break; |
| 1504 | case IEEE80211_STA_AUTHORIZED: |
| 1505 | if (sta->sta_state == IEEE80211_STA_ASSOC) { |
Felix Fietkau | 7e3ed02 | 2012-04-23 19:49:03 +0200 | [diff] [blame] | 1506 | if (sta->sdata->vif.type == NL80211_IFTYPE_AP || |
| 1507 | (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN && |
| 1508 | !sta->sdata->u.vlan.sta)) |
| 1509 | atomic_inc(&sta->sdata->bss->num_mcast_sta); |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 1510 | set_bit(WLAN_STA_AUTHORIZED, &sta->_flags); |
| 1511 | } |
| 1512 | break; |
| 1513 | default: |
| 1514 | break; |
| 1515 | } |
| 1516 | |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1517 | sta->sta_state = new_state; |
| 1518 | |
| 1519 | return 0; |
| 1520 | } |