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> |
| 12 | #include <linux/netdevice.h> |
| 13 | #include <linux/types.h> |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/skbuff.h> |
| 16 | #include <linux/if_arp.h> |
Johannes Berg | 0d17440 | 2007-12-17 15:07:43 +0100 | [diff] [blame] | 17 | #include <linux/timer.h> |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 18 | #include <linux/rtnetlink.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 19 | |
| 20 | #include <net/mac80211.h> |
| 21 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 22 | #include "driver-ops.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 23 | #include "rate.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 24 | #include "sta_info.h" |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 25 | #include "debugfs_sta.h" |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 26 | #include "mesh.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 27 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 28 | /** |
| 29 | * DOC: STA information lifetime rules |
| 30 | * |
| 31 | * STA info structures (&struct sta_info) are managed in a hash table |
| 32 | * for faster lookup and a list for iteration. They are managed using |
| 33 | * RCU, i.e. access to the list and hash table is protected by RCU. |
| 34 | * |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 35 | * Upon allocating a STA info structure with sta_info_alloc(), the caller owns |
| 36 | * that structure. It must then either destroy it using sta_info_destroy() |
| 37 | * (which is pretty useless) or insert it into the hash table using |
| 38 | * sta_info_insert() which demotes the reference from ownership to a regular |
| 39 | * RCU-protected reference; if the function is called without protection by an |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 40 | * RCU critical section the reference is instantly invalidated. Note that the |
| 41 | * caller may not do much with the STA info before inserting it, in particular, |
| 42 | * it may not start any mesh peer link management or add encryption keys. |
| 43 | * |
| 44 | * When the insertion fails (sta_info_insert()) returns non-zero), the |
| 45 | * structure will have been freed by sta_info_insert()! |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 46 | * |
Luis R. Rodriguez | 7e189a1 | 2009-06-02 18:38:14 -0400 | [diff] [blame] | 47 | * sta entries are added by mac80211 when you establish a link with a |
| 48 | * peer. This means different things for the different type of interfaces |
| 49 | * we support. For a regular station this mean we add the AP sta when we |
| 50 | * receive an assocation response from the AP. For IBSS this occurs when |
| 51 | * we receive a probe response or a beacon from target IBSS network. For |
| 52 | * WDS we add the sta for the peer imediately upon device open. When using |
| 53 | * AP mode we add stations for each respective station upon request from |
| 54 | * userspace through nl80211. |
| 55 | * |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 56 | * Because there are debugfs entries for each station, and adding those |
| 57 | * must be able to sleep, it is also possible to "pin" a station entry, |
| 58 | * that means it can be removed from the hash table but not be freed. |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 59 | * See the comment in __sta_info_unlink() for more information, this is |
| 60 | * an internal capability only. |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 61 | * |
| 62 | * In order to remove a STA info structure, the caller needs to first |
Johannes Berg | dbbea67 | 2008-02-26 14:34:06 +0100 | [diff] [blame] | 63 | * unlink it (sta_info_unlink()) from the list and hash tables and |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 64 | * then destroy it; sta_info_destroy() will wait for an RCU grace period |
| 65 | * to elapse before actually freeing it. Due to the pinning and the |
| 66 | * possibility of multiple callers trying to remove the same STA info at |
| 67 | * the same time, sta_info_unlink() can clear the STA info pointer it is |
| 68 | * passed to indicate that the STA info is owned by somebody else now. |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 69 | * |
Johannes Berg | dbbea67 | 2008-02-26 14:34:06 +0100 | [diff] [blame] | 70 | * If sta_info_unlink() did not clear the pointer then the caller owns |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 71 | * the STA info structure now and is responsible of destroying it with |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 72 | * a call to sta_info_destroy(). |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 73 | * |
| 74 | * In all other cases, there is no concept of ownership on a STA entry, |
| 75 | * each structure is owned by the global hash table/list until it is |
| 76 | * removed. All users of the structure need to be RCU protected so that |
| 77 | * the structure won't be freed before they are done using it. |
| 78 | */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 79 | |
| 80 | /* Caller must hold local->sta_lock */ |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 81 | static int sta_info_hash_del(struct ieee80211_local *local, |
| 82 | struct sta_info *sta) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 83 | { |
| 84 | struct sta_info *s; |
| 85 | |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 86 | s = local->sta_hash[STA_HASH(sta->sta.addr)]; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 87 | if (!s) |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 88 | return -ENOENT; |
| 89 | if (s == sta) { |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 90 | rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 91 | s->hnext); |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 92 | return 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 95 | while (s->hnext && s->hnext != sta) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 96 | s = s->hnext; |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 97 | if (s->hnext) { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 98 | rcu_assign_pointer(s->hnext, sta->hnext); |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 99 | return 0; |
| 100 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 101 | |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 102 | return -ENOENT; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 105 | /* protected by RCU */ |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 106 | struct sta_info *sta_info_get(struct ieee80211_local *local, const u8 *addr) |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 107 | { |
| 108 | struct sta_info *sta; |
| 109 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 110 | sta = rcu_dereference(local->sta_hash[STA_HASH(addr)]); |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 111 | while (sta) { |
Shaddy Baddah | 5cf12e8 | 2008-11-28 17:08:10 +1100 | [diff] [blame] | 112 | if (memcmp(sta->sta.addr, addr, ETH_ALEN) == 0) |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 113 | break; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 114 | sta = rcu_dereference(sta->hnext); |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 115 | } |
| 116 | return sta; |
| 117 | } |
| 118 | |
Johannes Berg | 3b53fde8 | 2009-11-16 12:00:37 +0100 | [diff] [blame^] | 119 | struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata, |
| 120 | int idx) |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 121 | { |
Johannes Berg | 3b53fde8 | 2009-11-16 12:00:37 +0100 | [diff] [blame^] | 122 | struct ieee80211_local *local = sdata->local; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 123 | struct sta_info *sta; |
| 124 | int i = 0; |
| 125 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 126 | list_for_each_entry_rcu(sta, &local->sta_list, list) { |
Johannes Berg | 3b53fde8 | 2009-11-16 12:00:37 +0100 | [diff] [blame^] | 127 | if (sdata != sta->sdata) |
Luis Carlos Cobo | 2a8ca29 | 2008-02-29 17:51:25 -0800 | [diff] [blame] | 128 | continue; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 129 | if (i < idx) { |
| 130 | ++i; |
| 131 | continue; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 132 | } |
Luis Carlos Cobo | 2a8ca29 | 2008-02-29 17:51:25 -0800 | [diff] [blame] | 133 | return sta; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 134 | } |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 135 | |
| 136 | return NULL; |
| 137 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 138 | |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 139 | /** |
| 140 | * __sta_info_free - internal STA free helper |
| 141 | * |
Randy Dunlap | 6ef307b | 2008-07-03 13:52:18 -0700 | [diff] [blame] | 142 | * @local: pointer to the global information |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 143 | * @sta: STA info to free |
| 144 | * |
| 145 | * This function must undo everything done by sta_info_alloc() |
| 146 | * that may happen before sta_info_insert(). |
| 147 | */ |
| 148 | static void __sta_info_free(struct ieee80211_local *local, |
| 149 | struct sta_info *sta) |
| 150 | { |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 151 | rate_control_free_sta(sta); |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 152 | rate_control_put(sta->rate_ctrl); |
| 153 | |
| 154 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 155 | printk(KERN_DEBUG "%s: Destroyed STA %pM\n", |
| 156 | wiphy_name(local->hw.wiphy), sta->sta.addr); |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 157 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 158 | |
| 159 | kfree(sta); |
| 160 | } |
| 161 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 162 | void sta_info_destroy(struct sta_info *sta) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 163 | { |
Johannes Berg | 97bff8e | 2008-03-31 19:23:00 +0200 | [diff] [blame] | 164 | struct ieee80211_local *local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 165 | struct sk_buff *skb; |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 166 | int i; |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 167 | |
Johannes Berg | 97bff8e | 2008-03-31 19:23:00 +0200 | [diff] [blame] | 168 | might_sleep(); |
| 169 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 170 | if (!sta) |
| 171 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 172 | |
Johannes Berg | 97bff8e | 2008-03-31 19:23:00 +0200 | [diff] [blame] | 173 | local = sta->local; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 174 | |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 175 | cancel_work_sync(&sta->drv_unblock_wk); |
| 176 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 177 | rate_control_remove_sta_debugfs(sta); |
| 178 | ieee80211_sta_debugfs_remove(sta); |
| 179 | |
| 180 | #ifdef CONFIG_MAC80211_MESH |
| 181 | if (ieee80211_vif_is_mesh(&sta->sdata->vif)) |
| 182 | mesh_plink_deactivate(sta); |
| 183 | #endif |
| 184 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 185 | /* |
| 186 | * We have only unlinked the key, and actually destroying it |
| 187 | * may mean it is removed from hardware which requires that |
| 188 | * the key->sta pointer is still valid, so flush the key todo |
| 189 | * list here. |
| 190 | * |
| 191 | * ieee80211_key_todo() will synchronize_rcu() so after this |
| 192 | * nothing can reference this sta struct any more. |
| 193 | */ |
| 194 | ieee80211_key_todo(); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 195 | |
| 196 | #ifdef CONFIG_MAC80211_MESH |
| 197 | if (ieee80211_vif_is_mesh(&sta->sdata->vif)) |
| 198 | del_timer_sync(&sta->plink_timer); |
| 199 | #endif |
| 200 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 201 | while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) { |
| 202 | local->total_ps_buffered--; |
| 203 | dev_kfree_skb_any(skb); |
| 204 | } |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 205 | |
| 206 | while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 207 | dev_kfree_skb_any(skb); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 208 | |
Ron Rindjunsky | fe3bf0f | 2008-01-28 14:07:19 +0200 | [diff] [blame] | 209 | for (i = 0; i < STA_TID_NUM; i++) { |
Johannes Berg | 55687e3 | 2009-02-10 21:25:51 +0100 | [diff] [blame] | 210 | struct tid_ampdu_rx *tid_rx; |
| 211 | struct tid_ampdu_tx *tid_tx; |
| 212 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 213 | spin_lock_bh(&sta->lock); |
Johannes Berg | 55687e3 | 2009-02-10 21:25:51 +0100 | [diff] [blame] | 214 | tid_rx = sta->ampdu_mlme.tid_rx[i]; |
| 215 | /* Make sure timer won't free the tid_rx struct, see below */ |
| 216 | if (tid_rx) |
| 217 | tid_rx->shutdown = true; |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame] | 218 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 219 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 55687e3 | 2009-02-10 21:25:51 +0100 | [diff] [blame] | 220 | |
| 221 | /* |
| 222 | * Outside spinlock - shutdown is true now so that the timer |
| 223 | * won't free tid_rx, we have to do that now. Can't let the |
| 224 | * timer do it because we have to sync the timer outside the |
| 225 | * lock that it takes itself. |
| 226 | */ |
| 227 | if (tid_rx) { |
| 228 | del_timer_sync(&tid_rx->session_timer); |
| 229 | kfree(tid_rx); |
| 230 | } |
| 231 | |
| 232 | /* |
| 233 | * No need to do such complications for TX agg sessions, the |
| 234 | * path leading to freeing the tid_tx struct goes via a call |
| 235 | * from the driver, and thus needs to look up the sta struct |
| 236 | * again, which cannot be found when we get here. Hence, we |
| 237 | * just need to delete the timer and free the aggregation |
| 238 | * info; we won't be telling the peer about it then but that |
| 239 | * doesn't matter if we're not talking to it again anyway. |
| 240 | */ |
| 241 | tid_tx = sta->ampdu_mlme.tid_tx[i]; |
| 242 | if (tid_tx) { |
| 243 | del_timer_sync(&tid_tx->addba_resp_timer); |
Johannes Berg | cd8ffc8 | 2009-03-23 17:28:41 +0100 | [diff] [blame] | 244 | /* |
| 245 | * STA removed while aggregation session being |
| 246 | * started? Bit odd, but purge frames anyway. |
| 247 | */ |
| 248 | skb_queue_purge(&tid_tx->pending); |
Johannes Berg | 55687e3 | 2009-02-10 21:25:51 +0100 | [diff] [blame] | 249 | kfree(tid_tx); |
| 250 | } |
Ron Rindjunsky | fe3bf0f | 2008-01-28 14:07:19 +0200 | [diff] [blame] | 251 | } |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 252 | |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 253 | __sta_info_free(local, sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 257 | /* Caller must hold local->sta_lock */ |
| 258 | static void sta_info_hash_add(struct ieee80211_local *local, |
| 259 | struct sta_info *sta) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 260 | { |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 261 | sta->hnext = local->sta_hash[STA_HASH(sta->sta.addr)]; |
| 262 | rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 263 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 264 | |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 265 | static void sta_unblock(struct work_struct *wk) |
| 266 | { |
| 267 | struct sta_info *sta; |
| 268 | |
| 269 | sta = container_of(wk, struct sta_info, drv_unblock_wk); |
| 270 | |
| 271 | if (sta->dead) |
| 272 | return; |
| 273 | |
| 274 | if (!test_sta_flags(sta, WLAN_STA_PS_STA)) |
| 275 | ieee80211_sta_ps_deliver_wakeup(sta); |
| 276 | else if (test_and_clear_sta_flags(sta, WLAN_STA_PSPOLL)) |
| 277 | ieee80211_sta_ps_deliver_poll_response(sta); |
| 278 | } |
| 279 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 280 | struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata, |
| 281 | u8 *addr, gfp_t gfp) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 282 | { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 283 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 284 | struct sta_info *sta; |
Ron Rindjunsky | 16c5f15 | 2007-12-25 17:00:34 +0200 | [diff] [blame] | 285 | int i; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 286 | |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 287 | sta = kzalloc(sizeof(*sta) + local->hw.sta_data_size, gfp); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 288 | if (!sta) |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 289 | return NULL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 290 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 291 | spin_lock_init(&sta->lock); |
Johannes Berg | 5a9f7b0 | 2008-06-18 14:58:09 +0200 | [diff] [blame] | 292 | spin_lock_init(&sta->flaglock); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 293 | INIT_WORK(&sta->drv_unblock_wk, sta_unblock); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 294 | |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 295 | memcpy(sta->sta.addr, addr, ETH_ALEN); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 296 | sta->local = local; |
| 297 | sta->sdata = sdata; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 298 | |
| 299 | sta->rate_ctrl = rate_control_get(local->rate_ctrl); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 300 | sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl, |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 301 | &sta->sta, gfp); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 302 | if (!sta->rate_ctrl_priv) { |
| 303 | rate_control_put(sta->rate_ctrl); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 304 | kfree(sta); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 305 | return NULL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Ron Rindjunsky | 16c5f15 | 2007-12-25 17:00:34 +0200 | [diff] [blame] | 308 | for (i = 0; i < STA_TID_NUM; i++) { |
| 309 | /* timer_to_tid must be initialized with identity mapping to |
| 310 | * enable session_timer's data differentiation. refer to |
| 311 | * sta_rx_agg_session_timer_expired for useage */ |
| 312 | sta->timer_to_tid[i] = i; |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 313 | /* rx */ |
| 314 | sta->ampdu_mlme.tid_state_rx[i] = HT_AGG_STATE_IDLE; |
| 315 | sta->ampdu_mlme.tid_rx[i] = NULL; |
| 316 | /* tx */ |
| 317 | sta->ampdu_mlme.tid_state_tx[i] = HT_AGG_STATE_IDLE; |
| 318 | sta->ampdu_mlme.tid_tx[i] = NULL; |
| 319 | sta->ampdu_mlme.addba_req_num[i] = 0; |
Ron Rindjunsky | 16c5f15 | 2007-12-25 17:00:34 +0200 | [diff] [blame] | 320 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 321 | skb_queue_head_init(&sta->ps_tx_buf); |
| 322 | skb_queue_head_init(&sta->tx_filtered); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 323 | |
Senthil Balasubramanian | cccaec9 | 2009-05-14 18:42:08 +0530 | [diff] [blame] | 324 | for (i = 0; i < NUM_RX_DATA_QUEUES; i++) |
| 325 | sta->last_seq_ctrl[i] = cpu_to_le16(USHORT_MAX); |
| 326 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 327 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 328 | printk(KERN_DEBUG "%s: Allocated STA %pM\n", |
| 329 | wiphy_name(local->hw.wiphy), sta->sta.addr); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 330 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 331 | |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 332 | #ifdef CONFIG_MAC80211_MESH |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 333 | sta->plink_state = PLINK_LISTEN; |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 334 | init_timer(&sta->plink_timer); |
| 335 | #endif |
| 336 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 337 | return sta; |
| 338 | } |
| 339 | |
| 340 | int sta_info_insert(struct sta_info *sta) |
| 341 | { |
| 342 | struct ieee80211_local *local = sta->local; |
| 343 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 344 | unsigned long flags; |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 345 | int err = 0; |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 346 | |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 347 | /* |
| 348 | * Can't be a WARN_ON because it can be triggered through a race: |
| 349 | * something inserts a STA (on one CPU) without holding the RTNL |
| 350 | * and another CPU turns off the net device. |
| 351 | */ |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 352 | if (unlikely(!netif_running(sdata->dev))) { |
| 353 | err = -ENETDOWN; |
| 354 | goto out_free; |
| 355 | } |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 356 | |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 357 | if (WARN_ON(compare_ether_addr(sta->sta.addr, sdata->dev->dev_addr) == 0 || |
Johannes Berg | c6a1fa1 | 2008-10-07 12:04:32 +0200 | [diff] [blame] | 358 | is_multicast_ether_addr(sta->sta.addr))) { |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 359 | err = -EINVAL; |
| 360 | goto out_free; |
| 361 | } |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 362 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 363 | spin_lock_irqsave(&local->sta_lock, flags); |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 364 | /* check if STA exists already */ |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 365 | if (sta_info_get(local, sta->sta.addr)) { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 366 | spin_unlock_irqrestore(&local->sta_lock, flags); |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 367 | err = -EEXIST; |
| 368 | goto out_free; |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 369 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 370 | list_add(&sta->list, &local->sta_list); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 371 | local->sta_generation++; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 372 | local->num_sta++; |
| 373 | sta_info_hash_add(local, sta); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 374 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 375 | /* notify driver */ |
| 376 | if (local->ops->sta_notify) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 377 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 378 | sdata = container_of(sdata->bss, |
| 379 | struct ieee80211_sub_if_data, |
| 380 | u.ap); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 381 | |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 382 | drv_sta_notify(local, &sdata->vif, STA_NOTIFY_ADD, &sta->sta); |
Johannes Berg | fbc44bf | 2009-10-01 22:06:29 +0200 | [diff] [blame] | 383 | sdata = sta->sdata; |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 384 | } |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 385 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 386 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 387 | printk(KERN_DEBUG "%s: Inserted STA %pM\n", |
| 388 | wiphy_name(local->hw.wiphy), sta->sta.addr); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 389 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 390 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 391 | spin_unlock_irqrestore(&local->sta_lock, flags); |
| 392 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 393 | #ifdef CONFIG_MAC80211_DEBUGFS |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 394 | /* |
| 395 | * Debugfs entry adding might sleep, so schedule process |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 396 | * context task for adding entry for STAs that do not yet |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 397 | * have one. |
| 398 | * NOTE: due to auto-freeing semantics this may only be done |
| 399 | * if the insertion is successful! |
| 400 | */ |
Johannes Berg | 49ec6fa2 | 2008-04-03 14:31:05 +0200 | [diff] [blame] | 401 | schedule_work(&local->sta_debugfs_add); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 402 | #endif |
| 403 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 404 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
| 405 | mesh_accept_plinks_update(sdata); |
| 406 | |
| 407 | return 0; |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 408 | out_free: |
| 409 | BUG_ON(!err); |
| 410 | __sta_info_free(local, sta); |
| 411 | return err; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 414 | static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid) |
| 415 | { |
| 416 | /* |
| 417 | * This format has been mandated by the IEEE specifications, |
| 418 | * so this line may not be changed to use the __set_bit() format. |
| 419 | */ |
| 420 | bss->tim[aid / 8] |= (1 << (aid % 8)); |
| 421 | } |
| 422 | |
| 423 | static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, u16 aid) |
| 424 | { |
| 425 | /* |
| 426 | * This format has been mandated by the IEEE specifications, |
| 427 | * so this line may not be changed to use the __clear_bit() format. |
| 428 | */ |
| 429 | bss->tim[aid / 8] &= ~(1 << (aid % 8)); |
| 430 | } |
| 431 | |
| 432 | static void __sta_info_set_tim_bit(struct ieee80211_if_ap *bss, |
| 433 | struct sta_info *sta) |
| 434 | { |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 435 | BUG_ON(!bss); |
| 436 | |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 437 | __bss_tim_set(bss, sta->sta.aid); |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 438 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 439 | if (sta->local->ops->set_tim) { |
| 440 | sta->local->tim_in_locked_section = true; |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 441 | drv_set_tim(sta->local, &sta->sta, true); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 442 | sta->local->tim_in_locked_section = false; |
| 443 | } |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | void sta_info_set_tim_bit(struct sta_info *sta) |
| 447 | { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 448 | unsigned long flags; |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 449 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 450 | BUG_ON(!sta->sdata->bss); |
| 451 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 452 | spin_lock_irqsave(&sta->local->sta_lock, flags); |
| 453 | __sta_info_set_tim_bit(sta->sdata->bss, sta); |
| 454 | spin_unlock_irqrestore(&sta->local->sta_lock, flags); |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | static void __sta_info_clear_tim_bit(struct ieee80211_if_ap *bss, |
| 458 | struct sta_info *sta) |
| 459 | { |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 460 | BUG_ON(!bss); |
| 461 | |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 462 | __bss_tim_clear(bss, sta->sta.aid); |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 463 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 464 | if (sta->local->ops->set_tim) { |
| 465 | sta->local->tim_in_locked_section = true; |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 466 | drv_set_tim(sta->local, &sta->sta, false); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 467 | sta->local->tim_in_locked_section = false; |
| 468 | } |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | void sta_info_clear_tim_bit(struct sta_info *sta) |
| 472 | { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 473 | unsigned long flags; |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 474 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 475 | BUG_ON(!sta->sdata->bss); |
| 476 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 477 | spin_lock_irqsave(&sta->local->sta_lock, flags); |
| 478 | __sta_info_clear_tim_bit(sta->sdata->bss, sta); |
| 479 | spin_unlock_irqrestore(&sta->local->sta_lock, flags); |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 480 | } |
| 481 | |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 482 | static void __sta_info_unlink(struct sta_info **sta) |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 483 | { |
| 484 | struct ieee80211_local *local = (*sta)->local; |
| 485 | struct ieee80211_sub_if_data *sdata = (*sta)->sdata; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 486 | /* |
| 487 | * pull caller's reference if we're already gone. |
| 488 | */ |
| 489 | if (sta_info_hash_del(local, *sta)) { |
| 490 | *sta = NULL; |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 491 | return; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 492 | } |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 493 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 494 | if ((*sta)->key) { |
| 495 | ieee80211_key_free((*sta)->key); |
| 496 | WARN_ON((*sta)->key); |
| 497 | } |
| 498 | |
Johannes Berg | 7d1559f | 2008-04-08 13:08:20 +0200 | [diff] [blame] | 499 | list_del(&(*sta)->list); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 500 | (*sta)->dead = true; |
Johannes Berg | 7d1559f | 2008-04-08 13:08:20 +0200 | [diff] [blame] | 501 | |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 502 | if (test_and_clear_sta_flags(*sta, |
| 503 | WLAN_STA_PS_STA | WLAN_STA_PS_DRIVER)) { |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 504 | BUG_ON(!sdata->bss); |
| 505 | |
| 506 | atomic_dec(&sdata->bss->num_sta_ps); |
Johannes Berg | 7d1559f | 2008-04-08 13:08:20 +0200 | [diff] [blame] | 507 | __sta_info_clear_tim_bit(sdata->bss, *sta); |
| 508 | } |
| 509 | |
| 510 | local->num_sta--; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 511 | local->sta_generation++; |
Johannes Berg | 7d1559f | 2008-04-08 13:08:20 +0200 | [diff] [blame] | 512 | |
Felix Fietkau | f14543ee | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 513 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
| 514 | rcu_assign_pointer(sdata->u.vlan.sta, NULL); |
| 515 | |
Johannes Berg | 7d1559f | 2008-04-08 13:08:20 +0200 | [diff] [blame] | 516 | if (local->ops->sta_notify) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 517 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 518 | sdata = container_of(sdata->bss, |
| 519 | struct ieee80211_sub_if_data, |
| 520 | u.ap); |
Johannes Berg | 7d1559f | 2008-04-08 13:08:20 +0200 | [diff] [blame] | 521 | |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 522 | drv_sta_notify(local, &sdata->vif, STA_NOTIFY_REMOVE, |
| 523 | &(*sta)->sta); |
Johannes Berg | fbc44bf | 2009-10-01 22:06:29 +0200 | [diff] [blame] | 524 | sdata = (*sta)->sdata; |
Johannes Berg | 7d1559f | 2008-04-08 13:08:20 +0200 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
| 528 | mesh_accept_plinks_update(sdata); |
| 529 | #ifdef CONFIG_MAC80211_MESH |
| 530 | del_timer(&(*sta)->plink_timer); |
| 531 | #endif |
| 532 | } |
| 533 | |
| 534 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 535 | printk(KERN_DEBUG "%s: Removed STA %pM\n", |
| 536 | wiphy_name(local->hw.wiphy), (*sta)->sta.addr); |
Johannes Berg | 7d1559f | 2008-04-08 13:08:20 +0200 | [diff] [blame] | 537 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 538 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 539 | /* |
Johannes Berg | 7d1559f | 2008-04-08 13:08:20 +0200 | [diff] [blame] | 540 | * Finally, pull caller's reference if the STA is pinned by the |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 541 | * task that is adding the debugfs entries. In that case, we |
| 542 | * leave the STA "to be freed". |
| 543 | * |
| 544 | * The rules are not trivial, but not too complex either: |
| 545 | * (1) pin_status is only modified under the sta_lock |
Johannes Berg | 49ec6fa2 | 2008-04-03 14:31:05 +0200 | [diff] [blame] | 546 | * (2) STAs may only be pinned under the RTNL so that |
| 547 | * sta_info_flush() is guaranteed to actually destroy |
| 548 | * all STAs that are active for a given interface, this |
| 549 | * is required for correctness because otherwise we |
| 550 | * could notify a driver that an interface is going |
| 551 | * away and only after that (!) notify it about a STA |
| 552 | * on that interface going away. |
| 553 | * (3) sta_info_debugfs_add_work() will set the status |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 554 | * to PINNED when it found an item that needs a new |
| 555 | * debugfs directory created. In that case, that item |
| 556 | * must not be freed although all *RCU* users are done |
| 557 | * with it. Hence, we tell the caller of _unlink() |
| 558 | * that the item is already gone (as can happen when |
| 559 | * two tasks try to unlink/destroy at the same time) |
Johannes Berg | 49ec6fa2 | 2008-04-03 14:31:05 +0200 | [diff] [blame] | 560 | * (4) We set the pin_status to DESTROY here when we |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 561 | * find such an item. |
Johannes Berg | 49ec6fa2 | 2008-04-03 14:31:05 +0200 | [diff] [blame] | 562 | * (5) sta_info_debugfs_add_work() will reset the pin_status |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 563 | * from PINNED to NORMAL when it is done with the item, |
| 564 | * but will check for DESTROY before resetting it in |
| 565 | * which case it will free the item. |
| 566 | */ |
| 567 | if ((*sta)->pin_status == STA_INFO_PIN_STAT_PINNED) { |
| 568 | (*sta)->pin_status = STA_INFO_PIN_STAT_DESTROY; |
| 569 | *sta = NULL; |
| 570 | return; |
| 571 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 574 | void sta_info_unlink(struct sta_info **sta) |
| 575 | { |
| 576 | struct ieee80211_local *local = (*sta)->local; |
| 577 | unsigned long flags; |
| 578 | |
| 579 | spin_lock_irqsave(&local->sta_lock, flags); |
| 580 | __sta_info_unlink(sta); |
| 581 | spin_unlock_irqrestore(&local->sta_lock, flags); |
| 582 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 583 | |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 584 | static int sta_info_buffer_expired(struct sta_info *sta, |
| 585 | struct sk_buff *skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 586 | { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 587 | struct ieee80211_tx_info *info; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 588 | int timeout; |
| 589 | |
| 590 | if (!skb) |
| 591 | return 0; |
| 592 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 593 | info = IEEE80211_SKB_CB(skb); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 594 | |
| 595 | /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */ |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 596 | timeout = (sta->listen_interval * |
| 597 | sta->sdata->vif.bss_conf.beacon_int * |
| 598 | 32 / 15625) * HZ; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 599 | if (timeout < STA_TX_BUFFER_EXPIRE) |
| 600 | timeout = STA_TX_BUFFER_EXPIRE; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 601 | return time_after(jiffies, info->control.jiffies + timeout); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | |
| 605 | static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local, |
| 606 | struct sta_info *sta) |
| 607 | { |
| 608 | unsigned long flags; |
| 609 | struct sk_buff *skb; |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 610 | struct ieee80211_sub_if_data *sdata; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 611 | |
| 612 | if (skb_queue_empty(&sta->ps_tx_buf)) |
| 613 | return; |
| 614 | |
| 615 | for (;;) { |
| 616 | spin_lock_irqsave(&sta->ps_tx_buf.lock, flags); |
| 617 | skb = skb_peek(&sta->ps_tx_buf); |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 618 | if (sta_info_buffer_expired(sta, skb)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 619 | skb = __skb_dequeue(&sta->ps_tx_buf); |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 620 | else |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 621 | skb = NULL; |
| 622 | spin_unlock_irqrestore(&sta->ps_tx_buf.lock, flags); |
| 623 | |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 624 | if (!skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 625 | break; |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 626 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 627 | sdata = sta->sdata; |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 628 | local->total_ps_buffered--; |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 629 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 630 | printk(KERN_DEBUG "Buffered frame expired (STA %pM)\n", |
| 631 | sta->sta.addr); |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 632 | #endif |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 633 | dev_kfree_skb(skb); |
| 634 | |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 635 | if (skb_queue_empty(&sta->ps_tx_buf)) |
| 636 | sta_info_clear_tim_bit(sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 637 | } |
| 638 | } |
| 639 | |
| 640 | |
| 641 | static void sta_info_cleanup(unsigned long data) |
| 642 | { |
| 643 | struct ieee80211_local *local = (struct ieee80211_local *) data; |
| 644 | struct sta_info *sta; |
| 645 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 646 | rcu_read_lock(); |
| 647 | list_for_each_entry_rcu(sta, &local->sta_list, list) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 648 | sta_info_cleanup_expire_buffered(local, sta); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 649 | rcu_read_unlock(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 650 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 651 | if (local->quiescing) |
| 652 | return; |
| 653 | |
Johannes Berg | 0d17440 | 2007-12-17 15:07:43 +0100 | [diff] [blame] | 654 | local->sta_cleanup.expires = |
| 655 | round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 656 | add_timer(&local->sta_cleanup); |
| 657 | } |
| 658 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 659 | #ifdef CONFIG_MAC80211_DEBUGFS |
Jiri Slaby | 4d6141c3 | 2008-04-07 21:53:49 +0200 | [diff] [blame] | 660 | /* |
| 661 | * See comment in __sta_info_unlink, |
| 662 | * caller must hold local->sta_lock. |
| 663 | */ |
| 664 | static void __sta_info_pin(struct sta_info *sta) |
| 665 | { |
| 666 | WARN_ON(sta->pin_status != STA_INFO_PIN_STAT_NORMAL); |
| 667 | sta->pin_status = STA_INFO_PIN_STAT_PINNED; |
| 668 | } |
| 669 | |
| 670 | /* |
| 671 | * See comment in __sta_info_unlink, returns sta if it |
| 672 | * needs to be destroyed. |
| 673 | */ |
| 674 | static struct sta_info *__sta_info_unpin(struct sta_info *sta) |
| 675 | { |
| 676 | struct sta_info *ret = NULL; |
| 677 | unsigned long flags; |
| 678 | |
| 679 | spin_lock_irqsave(&sta->local->sta_lock, flags); |
| 680 | WARN_ON(sta->pin_status != STA_INFO_PIN_STAT_DESTROY && |
| 681 | sta->pin_status != STA_INFO_PIN_STAT_PINNED); |
| 682 | if (sta->pin_status == STA_INFO_PIN_STAT_DESTROY) |
| 683 | ret = sta; |
| 684 | sta->pin_status = STA_INFO_PIN_STAT_NORMAL; |
| 685 | spin_unlock_irqrestore(&sta->local->sta_lock, flags); |
| 686 | |
| 687 | return ret; |
| 688 | } |
| 689 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 690 | static void sta_info_debugfs_add_work(struct work_struct *work) |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 691 | { |
| 692 | struct ieee80211_local *local = |
| 693 | container_of(work, struct ieee80211_local, sta_debugfs_add); |
| 694 | struct sta_info *sta, *tmp; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 695 | unsigned long flags; |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 696 | |
Johannes Berg | 49ec6fa2 | 2008-04-03 14:31:05 +0200 | [diff] [blame] | 697 | /* We need to keep the RTNL across the whole pinned status. */ |
| 698 | rtnl_lock(); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 699 | while (1) { |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 700 | sta = NULL; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 701 | |
| 702 | spin_lock_irqsave(&local->sta_lock, flags); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 703 | list_for_each_entry(tmp, &local->sta_list, list) { |
Johannes Berg | 63044e9 | 2008-10-07 12:04:29 +0200 | [diff] [blame] | 704 | /* |
| 705 | * debugfs.add_has_run will be set by |
| 706 | * ieee80211_sta_debugfs_add regardless |
| 707 | * of what else it does. |
| 708 | */ |
| 709 | if (!tmp->debugfs.add_has_run) { |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 710 | sta = tmp; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 711 | __sta_info_pin(sta); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 712 | break; |
| 713 | } |
| 714 | } |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 715 | spin_unlock_irqrestore(&local->sta_lock, flags); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 716 | |
| 717 | if (!sta) |
| 718 | break; |
| 719 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 720 | ieee80211_sta_debugfs_add(sta); |
| 721 | rate_control_add_sta_debugfs(sta); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 722 | |
| 723 | sta = __sta_info_unpin(sta); |
Johannes Berg | 4f6fab4 | 2008-03-31 19:23:02 +0200 | [diff] [blame] | 724 | sta_info_destroy(sta); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 725 | } |
Johannes Berg | 49ec6fa2 | 2008-04-03 14:31:05 +0200 | [diff] [blame] | 726 | rtnl_unlock(); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 727 | } |
| 728 | #endif |
| 729 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 730 | void sta_info_init(struct ieee80211_local *local) |
| 731 | { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 732 | spin_lock_init(&local->sta_lock); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 733 | INIT_LIST_HEAD(&local->sta_list); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 734 | |
Pavel Emelyanov | b24b8a2 | 2008-01-23 21:20:07 -0800 | [diff] [blame] | 735 | setup_timer(&local->sta_cleanup, sta_info_cleanup, |
| 736 | (unsigned long)local); |
Johannes Berg | 0d17440 | 2007-12-17 15:07:43 +0100 | [diff] [blame] | 737 | local->sta_cleanup.expires = |
| 738 | round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 739 | |
| 740 | #ifdef CONFIG_MAC80211_DEBUGFS |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 741 | INIT_WORK(&local->sta_debugfs_add, sta_info_debugfs_add_work); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 742 | #endif |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | int sta_info_start(struct ieee80211_local *local) |
| 746 | { |
| 747 | add_timer(&local->sta_cleanup); |
| 748 | return 0; |
| 749 | } |
| 750 | |
| 751 | void sta_info_stop(struct ieee80211_local *local) |
| 752 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 753 | del_timer(&local->sta_cleanup); |
Johannes Berg | 49ec6fa2 | 2008-04-03 14:31:05 +0200 | [diff] [blame] | 754 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 755 | /* |
| 756 | * Make sure the debugfs adding work isn't pending after this |
| 757 | * because we're about to be destroyed. It doesn't matter |
| 758 | * whether it ran or not since we're going to flush all STAs |
| 759 | * anyway. |
| 760 | */ |
| 761 | cancel_work_sync(&local->sta_debugfs_add); |
| 762 | #endif |
Johannes Berg | dc6676b | 2008-03-31 19:23:03 +0200 | [diff] [blame] | 763 | |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 764 | sta_info_flush(local, NULL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 765 | } |
| 766 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 767 | /** |
| 768 | * sta_info_flush - flush matching STA entries from the STA table |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 769 | * |
| 770 | * Returns the number of removed STA entries. |
| 771 | * |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 772 | * @local: local interface data |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 773 | * @sdata: matching rule for the net device (sta->dev) or %NULL to match all STAs |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 774 | */ |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 775 | int sta_info_flush(struct ieee80211_local *local, |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 776 | struct ieee80211_sub_if_data *sdata) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 777 | { |
| 778 | struct sta_info *sta, *tmp; |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 779 | LIST_HEAD(tmp_list); |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 780 | int ret = 0; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 781 | unsigned long flags; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 782 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 783 | might_sleep(); |
| 784 | |
| 785 | spin_lock_irqsave(&local->sta_lock, flags); |
| 786 | list_for_each_entry_safe(sta, tmp, &local->sta_list, list) { |
| 787 | if (!sdata || sdata == sta->sdata) { |
| 788 | __sta_info_unlink(&sta); |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 789 | if (sta) { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 790 | list_add_tail(&sta->list, &tmp_list); |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 791 | ret++; |
| 792 | } |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 793 | } |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 794 | } |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 795 | spin_unlock_irqrestore(&local->sta_lock, flags); |
| 796 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 797 | list_for_each_entry_safe(sta, tmp, &tmp_list, list) |
| 798 | sta_info_destroy(sta); |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 799 | |
| 800 | return ret; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 801 | } |
Johannes Berg | dc6676b | 2008-03-31 19:23:03 +0200 | [diff] [blame] | 802 | |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 803 | void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata, |
| 804 | unsigned long exp_time) |
| 805 | { |
| 806 | struct ieee80211_local *local = sdata->local; |
| 807 | struct sta_info *sta, *tmp; |
| 808 | LIST_HEAD(tmp_list); |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 809 | unsigned long flags; |
| 810 | |
| 811 | spin_lock_irqsave(&local->sta_lock, flags); |
| 812 | list_for_each_entry_safe(sta, tmp, &local->sta_list, list) |
| 813 | if (time_after(jiffies, sta->last_rx + exp_time)) { |
| 814 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 815 | printk(KERN_DEBUG "%s: expiring inactive STA %pM\n", |
| 816 | sdata->dev->name, sta->sta.addr); |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 817 | #endif |
| 818 | __sta_info_unlink(&sta); |
| 819 | if (sta) |
| 820 | list_add(&sta->list, &tmp_list); |
| 821 | } |
| 822 | spin_unlock_irqrestore(&local->sta_lock, flags); |
| 823 | |
| 824 | list_for_each_entry_safe(sta, tmp, &tmp_list, list) |
| 825 | sta_info_destroy(sta); |
| 826 | } |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 827 | |
Johannes Berg | 5ed176e | 2009-11-04 14:42:28 +0100 | [diff] [blame] | 828 | struct ieee80211_sta *ieee80211_find_sta_by_hw(struct ieee80211_hw *hw, |
| 829 | const u8 *addr) |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 830 | { |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 831 | struct sta_info *sta = sta_info_get(hw_to_local(hw), addr); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 832 | |
| 833 | if (!sta) |
| 834 | return NULL; |
| 835 | return &sta->sta; |
| 836 | } |
Johannes Berg | 5ed176e | 2009-11-04 14:42:28 +0100 | [diff] [blame] | 837 | EXPORT_SYMBOL_GPL(ieee80211_find_sta_by_hw); |
| 838 | |
| 839 | struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_vif *vif, |
| 840 | const u8 *addr) |
| 841 | { |
| 842 | struct ieee80211_sub_if_data *sdata; |
| 843 | |
| 844 | if (!vif) |
| 845 | return NULL; |
| 846 | |
| 847 | sdata = vif_to_sdata(vif); |
| 848 | |
| 849 | return ieee80211_find_sta_by_hw(&sdata->local->hw, addr); |
| 850 | } |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 851 | EXPORT_SYMBOL(ieee80211_find_sta); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 852 | |
| 853 | /* powersave support code */ |
| 854 | void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta) |
| 855 | { |
| 856 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 857 | struct ieee80211_local *local = sdata->local; |
| 858 | int sent, buffered; |
| 859 | |
| 860 | drv_sta_notify(local, &sdata->vif, STA_NOTIFY_AWAKE, &sta->sta); |
| 861 | |
| 862 | if (!skb_queue_empty(&sta->ps_tx_buf)) |
| 863 | sta_info_clear_tim_bit(sta); |
| 864 | |
| 865 | /* Send all buffered frames to the station */ |
| 866 | sent = ieee80211_add_pending_skbs(local, &sta->tx_filtered); |
| 867 | buffered = ieee80211_add_pending_skbs(local, &sta->ps_tx_buf); |
| 868 | sent += buffered; |
| 869 | local->total_ps_buffered -= buffered; |
| 870 | |
| 871 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
| 872 | printk(KERN_DEBUG "%s: STA %pM aid %d sending %d filtered/%d PS frames " |
| 873 | "since STA not sleeping anymore\n", sdata->dev->name, |
| 874 | sta->sta.addr, sta->sta.aid, sent - buffered, buffered); |
| 875 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
| 876 | } |
| 877 | |
| 878 | void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta) |
| 879 | { |
| 880 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 881 | struct ieee80211_local *local = sdata->local; |
| 882 | struct sk_buff *skb; |
| 883 | int no_pending_pkts; |
| 884 | |
| 885 | skb = skb_dequeue(&sta->tx_filtered); |
| 886 | if (!skb) { |
| 887 | skb = skb_dequeue(&sta->ps_tx_buf); |
| 888 | if (skb) |
| 889 | local->total_ps_buffered--; |
| 890 | } |
| 891 | no_pending_pkts = skb_queue_empty(&sta->tx_filtered) && |
| 892 | skb_queue_empty(&sta->ps_tx_buf); |
| 893 | |
| 894 | if (skb) { |
| 895 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 896 | struct ieee80211_hdr *hdr = |
| 897 | (struct ieee80211_hdr *) skb->data; |
| 898 | |
| 899 | /* |
| 900 | * Tell TX path to send this frame even though the STA may |
| 901 | * still remain is PS mode after this frame exchange. |
| 902 | */ |
| 903 | info->flags |= IEEE80211_TX_CTL_PSPOLL_RESPONSE; |
| 904 | |
| 905 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
| 906 | printk(KERN_DEBUG "STA %pM aid %d: PS Poll (entries after %d)\n", |
| 907 | sta->sta.addr, sta->sta.aid, |
| 908 | skb_queue_len(&sta->ps_tx_buf)); |
| 909 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
| 910 | |
| 911 | /* Use MoreData flag to indicate whether there are more |
| 912 | * buffered frames for this STA */ |
| 913 | if (no_pending_pkts) |
| 914 | hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA); |
| 915 | else |
| 916 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA); |
| 917 | |
| 918 | ieee80211_add_pending_skb(local, skb); |
| 919 | |
| 920 | if (no_pending_pkts) |
| 921 | sta_info_clear_tim_bit(sta); |
| 922 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
| 923 | } else { |
| 924 | /* |
| 925 | * FIXME: This can be the result of a race condition between |
| 926 | * us expiring a frame and the station polling for it. |
| 927 | * Should we send it a null-func frame indicating we |
| 928 | * have nothing buffered for it? |
| 929 | */ |
| 930 | printk(KERN_DEBUG "%s: STA %pM sent PS Poll even " |
| 931 | "though there are no buffered frames for it\n", |
| 932 | sdata->dev->name, sta->sta.addr); |
| 933 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | void ieee80211_sta_block_awake(struct ieee80211_hw *hw, |
| 938 | struct ieee80211_sta *pubsta, bool block) |
| 939 | { |
| 940 | struct sta_info *sta = container_of(pubsta, struct sta_info, sta); |
| 941 | |
| 942 | if (block) |
| 943 | set_sta_flags(sta, WLAN_STA_PS_DRIVER); |
| 944 | else |
| 945 | ieee80211_queue_work(hw, &sta->drv_unblock_wk); |
| 946 | } |
| 947 | EXPORT_SYMBOL(ieee80211_sta_block_awake); |