blob: 1f3c9eb985009c5453cebb895472e9b82f074b28 [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
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 Berg0d174402007-12-17 15:07:43 +010017#include <linux/timer.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070018
19#include <net/mac80211.h>
20#include "ieee80211_i.h"
21#include "ieee80211_rate.h"
22#include "sta_info.h"
Jiri Bence9f207f2007-05-05 11:46:38 -070023#include "debugfs_sta.h"
Luis Carlos Coboee385852008-02-23 15:17:11 +010024#ifdef CONFIG_MAC80211_MESH
25#include "mesh.h"
26#endif
Jiri Bencf0706e82007-05-05 11:45:53 -070027
28/* Caller must hold local->sta_lock */
29static void sta_info_hash_add(struct ieee80211_local *local,
30 struct sta_info *sta)
31{
32 sta->hnext = local->sta_hash[STA_HASH(sta->addr)];
33 local->sta_hash[STA_HASH(sta->addr)] = sta;
34}
35
36
37/* Caller must hold local->sta_lock */
Michael Wube8755e2007-07-27 15:43:23 +020038static int sta_info_hash_del(struct ieee80211_local *local,
39 struct sta_info *sta)
Jiri Bencf0706e82007-05-05 11:45:53 -070040{
41 struct sta_info *s;
42
43 s = local->sta_hash[STA_HASH(sta->addr)];
44 if (!s)
Michael Wube8755e2007-07-27 15:43:23 +020045 return -ENOENT;
46 if (s == sta) {
Jiri Bencf0706e82007-05-05 11:45:53 -070047 local->sta_hash[STA_HASH(sta->addr)] = s->hnext;
Michael Wube8755e2007-07-27 15:43:23 +020048 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070049 }
50
Michael Wube8755e2007-07-27 15:43:23 +020051 while (s->hnext && s->hnext != sta)
Jiri Bencf0706e82007-05-05 11:45:53 -070052 s = s->hnext;
Michael Wube8755e2007-07-27 15:43:23 +020053 if (s->hnext) {
54 s->hnext = sta->hnext;
55 return 0;
56 }
Jiri Bencf0706e82007-05-05 11:45:53 -070057
Michael Wube8755e2007-07-27 15:43:23 +020058 return -ENOENT;
Jiri Bencf0706e82007-05-05 11:45:53 -070059}
60
Johannes Berg43ba7e92008-02-21 14:09:30 +010061/* must hold local->sta_lock */
62static struct sta_info *__sta_info_find(struct ieee80211_local *local,
63 u8 *addr)
64{
65 struct sta_info *sta;
66
67 sta = local->sta_hash[STA_HASH(addr)];
68 while (sta) {
69 if (compare_ether_addr(sta->addr, addr) == 0)
70 break;
71 sta = sta->hnext;
72 }
73 return sta;
74}
75
Jiri Bencf0706e82007-05-05 11:45:53 -070076struct sta_info *sta_info_get(struct ieee80211_local *local, u8 *addr)
77{
78 struct sta_info *sta;
79
Michael Wube8755e2007-07-27 15:43:23 +020080 read_lock_bh(&local->sta_lock);
Johannes Berg43ba7e92008-02-21 14:09:30 +010081 sta = __sta_info_find(local, addr);
82 if (sta)
83 __sta_info_get(sta);
Michael Wube8755e2007-07-27 15:43:23 +020084 read_unlock_bh(&local->sta_lock);
Jiri Bencf0706e82007-05-05 11:45:53 -070085
86 return sta;
87}
88EXPORT_SYMBOL(sta_info_get);
89
Luis Carlos Coboee385852008-02-23 15:17:11 +010090struct sta_info *sta_info_get_by_idx(struct ieee80211_local *local, int idx,
91 struct net_device *dev)
92{
93 struct sta_info *sta;
94 int i = 0;
95
96 read_lock_bh(&local->sta_lock);
97 list_for_each_entry(sta, &local->sta_list, list) {
98 if (i < idx) {
99 ++i;
100 continue;
101 } else if (!dev || dev == sta->dev) {
102 __sta_info_get(sta);
103 read_unlock_bh(&local->sta_lock);
104 return sta;
105 }
106 }
107 read_unlock_bh(&local->sta_lock);
108
109 return NULL;
110}
Jiri Bencf0706e82007-05-05 11:45:53 -0700111
112static void sta_info_release(struct kref *kref)
113{
114 struct sta_info *sta = container_of(kref, struct sta_info, kref);
115 struct ieee80211_local *local = sta->local;
116 struct sk_buff *skb;
Ron Rindjunsky07db2182007-12-25 17:00:33 +0200117 int i;
Jiri Bencf0706e82007-05-05 11:45:53 -0700118
119 /* free sta structure; it has already been removed from
120 * hash table etc. external structures. Make sure that all
121 * buffered frames are release (one might have been added
122 * after sta_info_free() was called). */
123 while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
124 local->total_ps_buffered--;
125 dev_kfree_skb_any(skb);
126 }
127 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
128 dev_kfree_skb_any(skb);
129 }
Ron Rindjunskyfe3bf0f2008-01-28 14:07:19 +0200130 for (i = 0; i < STA_TID_NUM; i++) {
Ron Rindjunsky07db2182007-12-25 17:00:33 +0200131 del_timer_sync(&sta->ampdu_mlme.tid_rx[i].session_timer);
Ron Rindjunskyfe3bf0f2008-01-28 14:07:19 +0200132 del_timer_sync(&sta->ampdu_mlme.tid_tx[i].addba_resp_timer);
133 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700134 rate_control_free_sta(sta->rate_ctrl, sta->rate_ctrl_priv);
135 rate_control_put(sta->rate_ctrl);
136 kfree(sta);
137}
138
139
140void sta_info_put(struct sta_info *sta)
141{
142 kref_put(&sta->kref, sta_info_release);
143}
144EXPORT_SYMBOL(sta_info_put);
145
146
Johannes Berg43ba7e92008-02-21 14:09:30 +0100147struct sta_info *sta_info_add(struct ieee80211_local *local,
148 struct net_device *dev, u8 *addr, gfp_t gfp)
Jiri Bencf0706e82007-05-05 11:45:53 -0700149{
150 struct sta_info *sta;
Ron Rindjunsky16c5f152007-12-25 17:00:34 +0200151 int i;
Joe Perches0795af52007-10-03 17:59:30 -0700152 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e82007-05-05 11:45:53 -0700153
154 sta = kzalloc(sizeof(*sta), gfp);
155 if (!sta)
Johannes Berg43ba7e92008-02-21 14:09:30 +0100156 return ERR_PTR(-ENOMEM);
Jiri Bencf0706e82007-05-05 11:45:53 -0700157
158 kref_init(&sta->kref);
159
160 sta->rate_ctrl = rate_control_get(local->rate_ctrl);
161 sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl, gfp);
162 if (!sta->rate_ctrl_priv) {
163 rate_control_put(sta->rate_ctrl);
Jiri Bencf0706e82007-05-05 11:45:53 -0700164 kfree(sta);
Johannes Berg43ba7e92008-02-21 14:09:30 +0100165 return ERR_PTR(-ENOMEM);
Jiri Bencf0706e82007-05-05 11:45:53 -0700166 }
167
168 memcpy(sta->addr, addr, ETH_ALEN);
169 sta->local = local;
170 sta->dev = dev;
Ron Rindjunsky16c5f152007-12-25 17:00:34 +0200171 spin_lock_init(&sta->ampdu_mlme.ampdu_rx);
Ron Rindjunskyfe3bf0f2008-01-28 14:07:19 +0200172 spin_lock_init(&sta->ampdu_mlme.ampdu_tx);
Ron Rindjunsky16c5f152007-12-25 17:00:34 +0200173 for (i = 0; i < STA_TID_NUM; i++) {
174 /* timer_to_tid must be initialized with identity mapping to
175 * enable session_timer's data differentiation. refer to
176 * sta_rx_agg_session_timer_expired for useage */
177 sta->timer_to_tid[i] = i;
Ron Rindjunskyfe3bf0f2008-01-28 14:07:19 +0200178 /* tid to tx queue: initialize according to HW (0 is valid) */
179 sta->tid_to_tx_q[i] = local->hw.queues;
Ron Rindjunsky16c5f152007-12-25 17:00:34 +0200180 /* rx timers */
181 sta->ampdu_mlme.tid_rx[i].session_timer.function =
182 sta_rx_agg_session_timer_expired;
183 sta->ampdu_mlme.tid_rx[i].session_timer.data =
184 (unsigned long)&sta->timer_to_tid[i];
185 init_timer(&sta->ampdu_mlme.tid_rx[i].session_timer);
Ron Rindjunskyfe3bf0f2008-01-28 14:07:19 +0200186 /* tx timers */
187 sta->ampdu_mlme.tid_tx[i].addba_resp_timer.function =
188 sta_addba_resp_timer_expired;
189 sta->ampdu_mlme.tid_tx[i].addba_resp_timer.data =
190 (unsigned long)&sta->timer_to_tid[i];
191 init_timer(&sta->ampdu_mlme.tid_tx[i].addba_resp_timer);
Ron Rindjunsky16c5f152007-12-25 17:00:34 +0200192 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700193 skb_queue_head_init(&sta->ps_tx_buf);
194 skb_queue_head_init(&sta->tx_filtered);
Michael Wube8755e2007-07-27 15:43:23 +0200195 write_lock_bh(&local->sta_lock);
Johannes Berg43ba7e92008-02-21 14:09:30 +0100196 /* mark sta as used (by caller) */
197 __sta_info_get(sta);
198 /* check if STA exists already */
199 if (__sta_info_find(local, addr)) {
200 write_unlock_bh(&local->sta_lock);
201 sta_info_put(sta);
202 return ERR_PTR(-EEXIST);
203 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700204 list_add(&sta->list, &local->sta_list);
205 local->num_sta++;
206 sta_info_hash_add(local, sta);
Johannes Berg32bfd352007-12-19 01:31:26 +0100207 if (local->ops->sta_notify) {
208 struct ieee80211_sub_if_data *sdata;
209
210 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100211 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
Johannes Berg32bfd352007-12-19 01:31:26 +0100212 sdata = sdata->u.vlan.ap;
213
214 local->ops->sta_notify(local_to_hw(local), &sdata->vif,
215 STA_NOTIFY_ADD, addr);
216 }
Michael Wube8755e2007-07-27 15:43:23 +0200217 write_unlock_bh(&local->sta_lock);
Jiri Bencf0706e82007-05-05 11:45:53 -0700218
219#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -0700220 printk(KERN_DEBUG "%s: Added STA %s\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -0400221 wiphy_name(local->hw.wiphy), print_mac(mac, addr));
Jiri Bencf0706e82007-05-05 11:45:53 -0700222#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
223
Jiri Bence9f207f2007-05-05 11:46:38 -0700224#ifdef CONFIG_MAC80211_DEBUGFS
Michael Wube8755e2007-07-27 15:43:23 +0200225 /* debugfs entry adding might sleep, so schedule process
226 * context task for adding entry for STAs that do not yet
227 * have one. */
228 queue_work(local->hw.workqueue, &local->sta_debugfs_add);
Jiri Bence9f207f2007-05-05 11:46:38 -0700229#endif
230
Jiri Bencf0706e82007-05-05 11:45:53 -0700231 return sta;
232}
233
Johannes Berg004c8722008-02-20 11:21:35 +0100234static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid)
235{
236 /*
237 * This format has been mandated by the IEEE specifications,
238 * so this line may not be changed to use the __set_bit() format.
239 */
240 bss->tim[aid / 8] |= (1 << (aid % 8));
241}
242
243static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, u16 aid)
244{
245 /*
246 * This format has been mandated by the IEEE specifications,
247 * so this line may not be changed to use the __clear_bit() format.
248 */
249 bss->tim[aid / 8] &= ~(1 << (aid % 8));
250}
251
252static void __sta_info_set_tim_bit(struct ieee80211_if_ap *bss,
253 struct sta_info *sta)
254{
255 if (bss)
256 __bss_tim_set(bss, sta->aid);
257 if (sta->local->ops->set_tim)
258 sta->local->ops->set_tim(local_to_hw(sta->local), sta->aid, 1);
259}
260
261void sta_info_set_tim_bit(struct sta_info *sta)
262{
263 struct ieee80211_sub_if_data *sdata;
264
265 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
266
267 read_lock_bh(&sta->local->sta_lock);
268 __sta_info_set_tim_bit(sdata->bss, sta);
269 read_unlock_bh(&sta->local->sta_lock);
270}
271
272static void __sta_info_clear_tim_bit(struct ieee80211_if_ap *bss,
273 struct sta_info *sta)
274{
275 if (bss)
276 __bss_tim_clear(bss, sta->aid);
277 if (sta->local->ops->set_tim)
278 sta->local->ops->set_tim(local_to_hw(sta->local), sta->aid, 0);
279}
280
281void sta_info_clear_tim_bit(struct sta_info *sta)
282{
283 struct ieee80211_sub_if_data *sdata;
284
285 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
286
287 read_lock_bh(&sta->local->sta_lock);
288 __sta_info_clear_tim_bit(sdata->bss, sta);
289 read_unlock_bh(&sta->local->sta_lock);
290}
291
Michael Wube8755e2007-07-27 15:43:23 +0200292/* Caller must hold local->sta_lock */
293void sta_info_remove(struct sta_info *sta)
Jiri Bencf0706e82007-05-05 11:45:53 -0700294{
295 struct ieee80211_local *local = sta->local;
296 struct ieee80211_sub_if_data *sdata;
297
Michael Wube8755e2007-07-27 15:43:23 +0200298 /* don't do anything if we've been removed already */
299 if (sta_info_hash_del(local, sta))
300 return;
301
Jiri Bencf0706e82007-05-05 11:45:53 -0700302 list_del(&sta->list);
303 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
304 if (sta->flags & WLAN_STA_PS) {
305 sta->flags &= ~WLAN_STA_PS;
306 if (sdata->bss)
307 atomic_dec(&sdata->bss->num_sta_ps);
Johannes Berg004c8722008-02-20 11:21:35 +0100308 __sta_info_clear_tim_bit(sdata->bss, sta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700309 }
310 local->num_sta--;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100311
312#ifdef CONFIG_MAC80211_MESH
313 if (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT)
314 mesh_accept_plinks_update(sdata->dev);
315#endif
Jiri Bencf0706e82007-05-05 11:45:53 -0700316}
317
Michael Wube8755e2007-07-27 15:43:23 +0200318void sta_info_free(struct sta_info *sta)
Jiri Bencf0706e82007-05-05 11:45:53 -0700319{
320 struct sk_buff *skb;
321 struct ieee80211_local *local = sta->local;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100322 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
323
Joe Perches0795af52007-10-03 17:59:30 -0700324 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e82007-05-05 11:45:53 -0700325
Michael Wube8755e2007-07-27 15:43:23 +0200326 might_sleep();
327
328 write_lock_bh(&local->sta_lock);
329 sta_info_remove(sta);
330 write_unlock_bh(&local->sta_lock);
Jiri Bencf0706e82007-05-05 11:45:53 -0700331
Luis Carlos Coboee385852008-02-23 15:17:11 +0100332#ifdef CONFIG_MAC80211_MESH
333 if (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT) {
334 spin_lock_bh(&sta->plink_lock);
335 mesh_plink_deactivate(sta);
336 spin_unlock_bh(&sta->plink_lock);
337 }
338#endif
339
Jiri Bencf0706e82007-05-05 11:45:53 -0700340 while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
341 local->total_ps_buffered--;
Michael Wube8755e2007-07-27 15:43:23 +0200342 dev_kfree_skb(skb);
Jiri Bencf0706e82007-05-05 11:45:53 -0700343 }
344 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
Michael Wube8755e2007-07-27 15:43:23 +0200345 dev_kfree_skb(skb);
Jiri Bencf0706e82007-05-05 11:45:53 -0700346 }
347
Michael Wube8755e2007-07-27 15:43:23 +0200348#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -0700349 printk(KERN_DEBUG "%s: Removed STA %s\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -0400350 wiphy_name(local->hw.wiphy), print_mac(mac, sta->addr));
Michael Wube8755e2007-07-27 15:43:23 +0200351#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
352
Johannes Berg11a843b2007-08-28 17:01:55 -0400353 ieee80211_key_free(sta->key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100354 WARN_ON(sta->key);
Michael Wube8755e2007-07-27 15:43:23 +0200355
Johannes Berg32bfd352007-12-19 01:31:26 +0100356 if (local->ops->sta_notify) {
Johannes Berg32bfd352007-12-19 01:31:26 +0100357
Johannes Berg51fb61e2007-12-19 01:31:27 +0100358 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
Johannes Berg32bfd352007-12-19 01:31:26 +0100359 sdata = sdata->u.vlan.ap;
360
361 local->ops->sta_notify(local_to_hw(local), &sdata->vif,
362 STA_NOTIFY_REMOVE, sta->addr);
363 }
Tomas Winkler478f8d22007-09-30 13:52:37 +0200364
Michael Wube8755e2007-07-27 15:43:23 +0200365 rate_control_remove_sta_debugfs(sta);
366 ieee80211_sta_debugfs_remove(sta);
367
368 sta_info_put(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700369}
370
371
372static inline int sta_info_buffer_expired(struct ieee80211_local *local,
373 struct sta_info *sta,
374 struct sk_buff *skb)
375{
376 struct ieee80211_tx_packet_data *pkt_data;
377 int timeout;
378
379 if (!skb)
380 return 0;
381
382 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
383
384 /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */
385 timeout = (sta->listen_interval * local->hw.conf.beacon_int * 32 /
386 15625) * HZ;
387 if (timeout < STA_TX_BUFFER_EXPIRE)
388 timeout = STA_TX_BUFFER_EXPIRE;
389 return time_after(jiffies, pkt_data->jiffies + timeout);
390}
391
392
393static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
394 struct sta_info *sta)
395{
396 unsigned long flags;
397 struct sk_buff *skb;
Johannes Berg836341a2008-02-20 02:07:21 +0100398 struct ieee80211_sub_if_data *sdata;
Joe Perches0795af52007-10-03 17:59:30 -0700399 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e82007-05-05 11:45:53 -0700400
401 if (skb_queue_empty(&sta->ps_tx_buf))
402 return;
403
404 for (;;) {
405 spin_lock_irqsave(&sta->ps_tx_buf.lock, flags);
406 skb = skb_peek(&sta->ps_tx_buf);
Johannes Berg836341a2008-02-20 02:07:21 +0100407 if (sta_info_buffer_expired(local, sta, skb))
Jiri Bencf0706e82007-05-05 11:45:53 -0700408 skb = __skb_dequeue(&sta->ps_tx_buf);
Johannes Berg836341a2008-02-20 02:07:21 +0100409 else
Jiri Bencf0706e82007-05-05 11:45:53 -0700410 skb = NULL;
411 spin_unlock_irqrestore(&sta->ps_tx_buf.lock, flags);
412
Johannes Berg836341a2008-02-20 02:07:21 +0100413 if (!skb)
Jiri Bencf0706e82007-05-05 11:45:53 -0700414 break;
Johannes Berg836341a2008-02-20 02:07:21 +0100415
416 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
417 local->total_ps_buffered--;
418 printk(KERN_DEBUG "Buffered frame expired (STA "
419 "%s)\n", print_mac(mac, sta->addr));
420 dev_kfree_skb(skb);
421
Johannes Berg004c8722008-02-20 11:21:35 +0100422 if (skb_queue_empty(&sta->ps_tx_buf))
423 sta_info_clear_tim_bit(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700424 }
425}
426
427
428static void sta_info_cleanup(unsigned long data)
429{
430 struct ieee80211_local *local = (struct ieee80211_local *) data;
431 struct sta_info *sta;
432
Michael Wube8755e2007-07-27 15:43:23 +0200433 read_lock_bh(&local->sta_lock);
Jiri Bencf0706e82007-05-05 11:45:53 -0700434 list_for_each_entry(sta, &local->sta_list, list) {
435 __sta_info_get(sta);
436 sta_info_cleanup_expire_buffered(local, sta);
437 sta_info_put(sta);
438 }
Michael Wube8755e2007-07-27 15:43:23 +0200439 read_unlock_bh(&local->sta_lock);
Jiri Bencf0706e82007-05-05 11:45:53 -0700440
Johannes Berg0d174402007-12-17 15:07:43 +0100441 local->sta_cleanup.expires =
442 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL);
Jiri Bencf0706e82007-05-05 11:45:53 -0700443 add_timer(&local->sta_cleanup);
444}
445
Jiri Bence9f207f2007-05-05 11:46:38 -0700446#ifdef CONFIG_MAC80211_DEBUGFS
447static void sta_info_debugfs_add_task(struct work_struct *work)
448{
449 struct ieee80211_local *local =
450 container_of(work, struct ieee80211_local, sta_debugfs_add);
451 struct sta_info *sta, *tmp;
452
453 while (1) {
Jiri Bence9f207f2007-05-05 11:46:38 -0700454 sta = NULL;
Michael Wube8755e2007-07-27 15:43:23 +0200455 read_lock_bh(&local->sta_lock);
Jiri Bence9f207f2007-05-05 11:46:38 -0700456 list_for_each_entry(tmp, &local->sta_list, list) {
Michael Wube8755e2007-07-27 15:43:23 +0200457 if (!tmp->debugfs.dir) {
Jiri Bence9f207f2007-05-05 11:46:38 -0700458 sta = tmp;
459 __sta_info_get(sta);
460 break;
461 }
462 }
Michael Wube8755e2007-07-27 15:43:23 +0200463 read_unlock_bh(&local->sta_lock);
Jiri Bence9f207f2007-05-05 11:46:38 -0700464
465 if (!sta)
466 break;
467
Jiri Bence9f207f2007-05-05 11:46:38 -0700468 ieee80211_sta_debugfs_add(sta);
469 rate_control_add_sta_debugfs(sta);
470 sta_info_put(sta);
471 }
472}
473#endif
474
Jiri Bencf0706e82007-05-05 11:45:53 -0700475void sta_info_init(struct ieee80211_local *local)
476{
Michael Wube8755e2007-07-27 15:43:23 +0200477 rwlock_init(&local->sta_lock);
Jiri Bencf0706e82007-05-05 11:45:53 -0700478 INIT_LIST_HEAD(&local->sta_list);
Jiri Bencf0706e82007-05-05 11:45:53 -0700479
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -0800480 setup_timer(&local->sta_cleanup, sta_info_cleanup,
481 (unsigned long)local);
Johannes Berg0d174402007-12-17 15:07:43 +0100482 local->sta_cleanup.expires =
483 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL);
Jiri Bence9f207f2007-05-05 11:46:38 -0700484
485#ifdef CONFIG_MAC80211_DEBUGFS
486 INIT_WORK(&local->sta_debugfs_add, sta_info_debugfs_add_task);
487#endif
Jiri Bencf0706e82007-05-05 11:45:53 -0700488}
489
490int sta_info_start(struct ieee80211_local *local)
491{
492 add_timer(&local->sta_cleanup);
493 return 0;
494}
495
496void sta_info_stop(struct ieee80211_local *local)
497{
Jiri Bencf0706e82007-05-05 11:45:53 -0700498 del_timer(&local->sta_cleanup);
Michael Wube8755e2007-07-27 15:43:23 +0200499 sta_info_flush(local, NULL);
Jiri Bencf0706e82007-05-05 11:45:53 -0700500}
501
Jiri Bencf0706e82007-05-05 11:45:53 -0700502/**
503 * sta_info_flush - flush matching STA entries from the STA table
504 * @local: local interface data
505 * @dev: matching rule for the net device (sta->dev) or %NULL to match all STAs
506 */
507void sta_info_flush(struct ieee80211_local *local, struct net_device *dev)
508{
509 struct sta_info *sta, *tmp;
Michael Wube8755e2007-07-27 15:43:23 +0200510 LIST_HEAD(tmp_list);
Jiri Bencf0706e82007-05-05 11:45:53 -0700511
Michael Wube8755e2007-07-27 15:43:23 +0200512 write_lock_bh(&local->sta_lock);
Jiri Bencf0706e82007-05-05 11:45:53 -0700513 list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
Michael Wube8755e2007-07-27 15:43:23 +0200514 if (!dev || dev == sta->dev) {
515 __sta_info_get(sta);
516 sta_info_remove(sta);
517 list_add_tail(&sta->list, &tmp_list);
518 }
519 write_unlock_bh(&local->sta_lock);
520
521 list_for_each_entry_safe(sta, tmp, &tmp_list, list) {
522 sta_info_free(sta);
523 sta_info_put(sta);
524 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700525}