blob: 81c4e3392f40a1c5ebebbef20acb1d44d7d6fca5 [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#include "mesh.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070025
26/* Caller must hold local->sta_lock */
27static void sta_info_hash_add(struct ieee80211_local *local,
28 struct sta_info *sta)
29{
30 sta->hnext = local->sta_hash[STA_HASH(sta->addr)];
31 local->sta_hash[STA_HASH(sta->addr)] = sta;
32}
33
34
35/* Caller must hold local->sta_lock */
Michael Wube8755e2007-07-27 15:43:23 +020036static int sta_info_hash_del(struct ieee80211_local *local,
37 struct sta_info *sta)
Jiri Bencf0706e82007-05-05 11:45:53 -070038{
39 struct sta_info *s;
40
41 s = local->sta_hash[STA_HASH(sta->addr)];
42 if (!s)
Michael Wube8755e2007-07-27 15:43:23 +020043 return -ENOENT;
44 if (s == sta) {
Jiri Bencf0706e82007-05-05 11:45:53 -070045 local->sta_hash[STA_HASH(sta->addr)] = s->hnext;
Michael Wube8755e2007-07-27 15:43:23 +020046 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070047 }
48
Michael Wube8755e2007-07-27 15:43:23 +020049 while (s->hnext && s->hnext != sta)
Jiri Bencf0706e82007-05-05 11:45:53 -070050 s = s->hnext;
Michael Wube8755e2007-07-27 15:43:23 +020051 if (s->hnext) {
52 s->hnext = sta->hnext;
53 return 0;
54 }
Jiri Bencf0706e82007-05-05 11:45:53 -070055
Michael Wube8755e2007-07-27 15:43:23 +020056 return -ENOENT;
Jiri Bencf0706e82007-05-05 11:45:53 -070057}
58
Johannes Berg43ba7e92008-02-21 14:09:30 +010059/* must hold local->sta_lock */
60static struct sta_info *__sta_info_find(struct ieee80211_local *local,
61 u8 *addr)
62{
63 struct sta_info *sta;
64
65 sta = local->sta_hash[STA_HASH(addr)];
66 while (sta) {
67 if (compare_ether_addr(sta->addr, addr) == 0)
68 break;
69 sta = sta->hnext;
70 }
71 return sta;
72}
73
Jiri Bencf0706e82007-05-05 11:45:53 -070074struct sta_info *sta_info_get(struct ieee80211_local *local, u8 *addr)
75{
76 struct sta_info *sta;
77
Michael Wube8755e2007-07-27 15:43:23 +020078 read_lock_bh(&local->sta_lock);
Johannes Berg43ba7e92008-02-21 14:09:30 +010079 sta = __sta_info_find(local, addr);
80 if (sta)
81 __sta_info_get(sta);
Michael Wube8755e2007-07-27 15:43:23 +020082 read_unlock_bh(&local->sta_lock);
Jiri Bencf0706e82007-05-05 11:45:53 -070083
84 return sta;
85}
86EXPORT_SYMBOL(sta_info_get);
87
Luis Carlos Coboee385852008-02-23 15:17:11 +010088struct sta_info *sta_info_get_by_idx(struct ieee80211_local *local, int idx,
89 struct net_device *dev)
90{
91 struct sta_info *sta;
92 int i = 0;
93
94 read_lock_bh(&local->sta_lock);
95 list_for_each_entry(sta, &local->sta_list, list) {
96 if (i < idx) {
97 ++i;
98 continue;
99 } else if (!dev || dev == sta->dev) {
100 __sta_info_get(sta);
101 read_unlock_bh(&local->sta_lock);
102 return sta;
103 }
104 }
105 read_unlock_bh(&local->sta_lock);
106
107 return NULL;
108}
Jiri Bencf0706e82007-05-05 11:45:53 -0700109
110static void sta_info_release(struct kref *kref)
111{
112 struct sta_info *sta = container_of(kref, struct sta_info, kref);
113 struct ieee80211_local *local = sta->local;
114 struct sk_buff *skb;
Ron Rindjunsky07db2182007-12-25 17:00:33 +0200115 int i;
Jiri Bencf0706e82007-05-05 11:45:53 -0700116
117 /* free sta structure; it has already been removed from
118 * hash table etc. external structures. Make sure that all
119 * buffered frames are release (one might have been added
120 * after sta_info_free() was called). */
121 while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
122 local->total_ps_buffered--;
123 dev_kfree_skb_any(skb);
124 }
125 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
126 dev_kfree_skb_any(skb);
127 }
Ron Rindjunskyfe3bf0f2008-01-28 14:07:19 +0200128 for (i = 0; i < STA_TID_NUM; i++) {
Ron Rindjunsky07db2182007-12-25 17:00:33 +0200129 del_timer_sync(&sta->ampdu_mlme.tid_rx[i].session_timer);
Ron Rindjunskyfe3bf0f2008-01-28 14:07:19 +0200130 del_timer_sync(&sta->ampdu_mlme.tid_tx[i].addba_resp_timer);
131 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700132 rate_control_free_sta(sta->rate_ctrl, sta->rate_ctrl_priv);
133 rate_control_put(sta->rate_ctrl);
134 kfree(sta);
135}
136
137
138void sta_info_put(struct sta_info *sta)
139{
140 kref_put(&sta->kref, sta_info_release);
141}
142EXPORT_SYMBOL(sta_info_put);
143
144
Johannes Berg43ba7e92008-02-21 14:09:30 +0100145struct sta_info *sta_info_add(struct ieee80211_local *local,
146 struct net_device *dev, u8 *addr, gfp_t gfp)
Jiri Bencf0706e82007-05-05 11:45:53 -0700147{
148 struct sta_info *sta;
Ron Rindjunsky16c5f152007-12-25 17:00:34 +0200149 int i;
Joe Perches0795af52007-10-03 17:59:30 -0700150 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e82007-05-05 11:45:53 -0700151
152 sta = kzalloc(sizeof(*sta), gfp);
153 if (!sta)
Johannes Berg43ba7e92008-02-21 14:09:30 +0100154 return ERR_PTR(-ENOMEM);
Jiri Bencf0706e82007-05-05 11:45:53 -0700155
156 kref_init(&sta->kref);
157
158 sta->rate_ctrl = rate_control_get(local->rate_ctrl);
159 sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl, gfp);
160 if (!sta->rate_ctrl_priv) {
161 rate_control_put(sta->rate_ctrl);
Jiri Bencf0706e82007-05-05 11:45:53 -0700162 kfree(sta);
Johannes Berg43ba7e92008-02-21 14:09:30 +0100163 return ERR_PTR(-ENOMEM);
Jiri Bencf0706e82007-05-05 11:45:53 -0700164 }
165
166 memcpy(sta->addr, addr, ETH_ALEN);
167 sta->local = local;
168 sta->dev = dev;
Ron Rindjunsky16c5f152007-12-25 17:00:34 +0200169 spin_lock_init(&sta->ampdu_mlme.ampdu_rx);
Ron Rindjunskyfe3bf0f2008-01-28 14:07:19 +0200170 spin_lock_init(&sta->ampdu_mlme.ampdu_tx);
Ron Rindjunsky16c5f152007-12-25 17:00:34 +0200171 for (i = 0; i < STA_TID_NUM; i++) {
172 /* timer_to_tid must be initialized with identity mapping to
173 * enable session_timer's data differentiation. refer to
174 * sta_rx_agg_session_timer_expired for useage */
175 sta->timer_to_tid[i] = i;
Ron Rindjunskyfe3bf0f2008-01-28 14:07:19 +0200176 /* tid to tx queue: initialize according to HW (0 is valid) */
177 sta->tid_to_tx_q[i] = local->hw.queues;
Ron Rindjunsky16c5f152007-12-25 17:00:34 +0200178 /* rx timers */
179 sta->ampdu_mlme.tid_rx[i].session_timer.function =
180 sta_rx_agg_session_timer_expired;
181 sta->ampdu_mlme.tid_rx[i].session_timer.data =
182 (unsigned long)&sta->timer_to_tid[i];
183 init_timer(&sta->ampdu_mlme.tid_rx[i].session_timer);
Ron Rindjunskyfe3bf0f2008-01-28 14:07:19 +0200184 /* tx timers */
185 sta->ampdu_mlme.tid_tx[i].addba_resp_timer.function =
186 sta_addba_resp_timer_expired;
187 sta->ampdu_mlme.tid_tx[i].addba_resp_timer.data =
188 (unsigned long)&sta->timer_to_tid[i];
189 init_timer(&sta->ampdu_mlme.tid_tx[i].addba_resp_timer);
Ron Rindjunsky16c5f152007-12-25 17:00:34 +0200190 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700191 skb_queue_head_init(&sta->ps_tx_buf);
192 skb_queue_head_init(&sta->tx_filtered);
Michael Wube8755e2007-07-27 15:43:23 +0200193 write_lock_bh(&local->sta_lock);
Johannes Berg43ba7e92008-02-21 14:09:30 +0100194 /* mark sta as used (by caller) */
195 __sta_info_get(sta);
196 /* check if STA exists already */
197 if (__sta_info_find(local, addr)) {
198 write_unlock_bh(&local->sta_lock);
199 sta_info_put(sta);
200 return ERR_PTR(-EEXIST);
201 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700202 list_add(&sta->list, &local->sta_list);
203 local->num_sta++;
204 sta_info_hash_add(local, sta);
Johannes Berg32bfd352007-12-19 01:31:26 +0100205 if (local->ops->sta_notify) {
206 struct ieee80211_sub_if_data *sdata;
207
208 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100209 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
Johannes Berg32bfd352007-12-19 01:31:26 +0100210 sdata = sdata->u.vlan.ap;
211
212 local->ops->sta_notify(local_to_hw(local), &sdata->vif,
213 STA_NOTIFY_ADD, addr);
214 }
Michael Wube8755e2007-07-27 15:43:23 +0200215 write_unlock_bh(&local->sta_lock);
Jiri Bencf0706e82007-05-05 11:45:53 -0700216
217#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -0700218 printk(KERN_DEBUG "%s: Added STA %s\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -0400219 wiphy_name(local->hw.wiphy), print_mac(mac, addr));
Jiri Bencf0706e82007-05-05 11:45:53 -0700220#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
221
Jiri Bence9f207f2007-05-05 11:46:38 -0700222#ifdef CONFIG_MAC80211_DEBUGFS
Michael Wube8755e2007-07-27 15:43:23 +0200223 /* debugfs entry adding might sleep, so schedule process
224 * context task for adding entry for STAs that do not yet
225 * have one. */
226 queue_work(local->hw.workqueue, &local->sta_debugfs_add);
Jiri Bence9f207f2007-05-05 11:46:38 -0700227#endif
228
Jiri Bencf0706e82007-05-05 11:45:53 -0700229 return sta;
230}
231
Johannes Berg004c8722008-02-20 11:21:35 +0100232static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid)
233{
234 /*
235 * This format has been mandated by the IEEE specifications,
236 * so this line may not be changed to use the __set_bit() format.
237 */
238 bss->tim[aid / 8] |= (1 << (aid % 8));
239}
240
241static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, u16 aid)
242{
243 /*
244 * This format has been mandated by the IEEE specifications,
245 * so this line may not be changed to use the __clear_bit() format.
246 */
247 bss->tim[aid / 8] &= ~(1 << (aid % 8));
248}
249
250static void __sta_info_set_tim_bit(struct ieee80211_if_ap *bss,
251 struct sta_info *sta)
252{
253 if (bss)
254 __bss_tim_set(bss, sta->aid);
255 if (sta->local->ops->set_tim)
256 sta->local->ops->set_tim(local_to_hw(sta->local), sta->aid, 1);
257}
258
259void sta_info_set_tim_bit(struct sta_info *sta)
260{
261 struct ieee80211_sub_if_data *sdata;
262
263 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
264
265 read_lock_bh(&sta->local->sta_lock);
266 __sta_info_set_tim_bit(sdata->bss, sta);
267 read_unlock_bh(&sta->local->sta_lock);
268}
269
270static void __sta_info_clear_tim_bit(struct ieee80211_if_ap *bss,
271 struct sta_info *sta)
272{
273 if (bss)
274 __bss_tim_clear(bss, sta->aid);
275 if (sta->local->ops->set_tim)
276 sta->local->ops->set_tim(local_to_hw(sta->local), sta->aid, 0);
277}
278
279void sta_info_clear_tim_bit(struct sta_info *sta)
280{
281 struct ieee80211_sub_if_data *sdata;
282
283 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
284
285 read_lock_bh(&sta->local->sta_lock);
286 __sta_info_clear_tim_bit(sdata->bss, sta);
287 read_unlock_bh(&sta->local->sta_lock);
288}
289
Michael Wube8755e2007-07-27 15:43:23 +0200290/* Caller must hold local->sta_lock */
291void sta_info_remove(struct sta_info *sta)
Jiri Bencf0706e82007-05-05 11:45:53 -0700292{
293 struct ieee80211_local *local = sta->local;
294 struct ieee80211_sub_if_data *sdata;
295
Michael Wube8755e2007-07-27 15:43:23 +0200296 /* don't do anything if we've been removed already */
297 if (sta_info_hash_del(local, sta))
298 return;
299
Jiri Bencf0706e82007-05-05 11:45:53 -0700300 list_del(&sta->list);
301 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
302 if (sta->flags & WLAN_STA_PS) {
303 sta->flags &= ~WLAN_STA_PS;
304 if (sdata->bss)
305 atomic_dec(&sdata->bss->num_sta_ps);
Johannes Berg004c8722008-02-20 11:21:35 +0100306 __sta_info_clear_tim_bit(sdata->bss, sta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700307 }
308 local->num_sta--;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100309
Johannes Berg902acc72008-02-23 15:17:19 +0100310 if (ieee80211_vif_is_mesh(&sdata->vif))
Luis Carlos Coboee385852008-02-23 15:17:11 +0100311 mesh_accept_plinks_update(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700312}
313
Michael Wube8755e2007-07-27 15:43:23 +0200314void sta_info_free(struct sta_info *sta)
Jiri Bencf0706e82007-05-05 11:45:53 -0700315{
316 struct sk_buff *skb;
317 struct ieee80211_local *local = sta->local;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100318 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
319
Joe Perches0795af52007-10-03 17:59:30 -0700320 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e82007-05-05 11:45:53 -0700321
Michael Wube8755e2007-07-27 15:43:23 +0200322 might_sleep();
323
324 write_lock_bh(&local->sta_lock);
325 sta_info_remove(sta);
326 write_unlock_bh(&local->sta_lock);
Jiri Bencf0706e82007-05-05 11:45:53 -0700327
Johannes Berg902acc72008-02-23 15:17:19 +0100328 if (ieee80211_vif_is_mesh(&sdata->vif))
Luis Carlos Coboee385852008-02-23 15:17:11 +0100329 mesh_plink_deactivate(sta);
Luis Carlos Coboee385852008-02-23 15:17:11 +0100330
Jiri Bencf0706e82007-05-05 11:45:53 -0700331 while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
332 local->total_ps_buffered--;
Michael Wube8755e2007-07-27 15:43:23 +0200333 dev_kfree_skb(skb);
Jiri Bencf0706e82007-05-05 11:45:53 -0700334 }
335 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
Michael Wube8755e2007-07-27 15:43:23 +0200336 dev_kfree_skb(skb);
Jiri Bencf0706e82007-05-05 11:45:53 -0700337 }
338
Michael Wube8755e2007-07-27 15:43:23 +0200339#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -0700340 printk(KERN_DEBUG "%s: Removed STA %s\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -0400341 wiphy_name(local->hw.wiphy), print_mac(mac, sta->addr));
Michael Wube8755e2007-07-27 15:43:23 +0200342#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
343
Johannes Berg11a843b2007-08-28 17:01:55 -0400344 ieee80211_key_free(sta->key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100345 WARN_ON(sta->key);
Michael Wube8755e2007-07-27 15:43:23 +0200346
Johannes Berg32bfd352007-12-19 01:31:26 +0100347 if (local->ops->sta_notify) {
Johannes Berg32bfd352007-12-19 01:31:26 +0100348
Johannes Berg51fb61e2007-12-19 01:31:27 +0100349 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
Johannes Berg32bfd352007-12-19 01:31:26 +0100350 sdata = sdata->u.vlan.ap;
351
352 local->ops->sta_notify(local_to_hw(local), &sdata->vif,
353 STA_NOTIFY_REMOVE, sta->addr);
354 }
Tomas Winkler478f8d22007-09-30 13:52:37 +0200355
Michael Wube8755e2007-07-27 15:43:23 +0200356 rate_control_remove_sta_debugfs(sta);
357 ieee80211_sta_debugfs_remove(sta);
358
359 sta_info_put(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700360}
361
362
363static inline int sta_info_buffer_expired(struct ieee80211_local *local,
364 struct sta_info *sta,
365 struct sk_buff *skb)
366{
367 struct ieee80211_tx_packet_data *pkt_data;
368 int timeout;
369
370 if (!skb)
371 return 0;
372
373 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
374
375 /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */
376 timeout = (sta->listen_interval * local->hw.conf.beacon_int * 32 /
377 15625) * HZ;
378 if (timeout < STA_TX_BUFFER_EXPIRE)
379 timeout = STA_TX_BUFFER_EXPIRE;
380 return time_after(jiffies, pkt_data->jiffies + timeout);
381}
382
383
384static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
385 struct sta_info *sta)
386{
387 unsigned long flags;
388 struct sk_buff *skb;
Johannes Berg836341a2008-02-20 02:07:21 +0100389 struct ieee80211_sub_if_data *sdata;
Joe Perches0795af52007-10-03 17:59:30 -0700390 DECLARE_MAC_BUF(mac);
Jiri Bencf0706e82007-05-05 11:45:53 -0700391
392 if (skb_queue_empty(&sta->ps_tx_buf))
393 return;
394
395 for (;;) {
396 spin_lock_irqsave(&sta->ps_tx_buf.lock, flags);
397 skb = skb_peek(&sta->ps_tx_buf);
Johannes Berg836341a2008-02-20 02:07:21 +0100398 if (sta_info_buffer_expired(local, sta, skb))
Jiri Bencf0706e82007-05-05 11:45:53 -0700399 skb = __skb_dequeue(&sta->ps_tx_buf);
Johannes Berg836341a2008-02-20 02:07:21 +0100400 else
Jiri Bencf0706e82007-05-05 11:45:53 -0700401 skb = NULL;
402 spin_unlock_irqrestore(&sta->ps_tx_buf.lock, flags);
403
Johannes Berg836341a2008-02-20 02:07:21 +0100404 if (!skb)
Jiri Bencf0706e82007-05-05 11:45:53 -0700405 break;
Johannes Berg836341a2008-02-20 02:07:21 +0100406
407 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
408 local->total_ps_buffered--;
409 printk(KERN_DEBUG "Buffered frame expired (STA "
410 "%s)\n", print_mac(mac, sta->addr));
411 dev_kfree_skb(skb);
412
Johannes Berg004c8722008-02-20 11:21:35 +0100413 if (skb_queue_empty(&sta->ps_tx_buf))
414 sta_info_clear_tim_bit(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700415 }
416}
417
418
419static void sta_info_cleanup(unsigned long data)
420{
421 struct ieee80211_local *local = (struct ieee80211_local *) data;
422 struct sta_info *sta;
423
Michael Wube8755e2007-07-27 15:43:23 +0200424 read_lock_bh(&local->sta_lock);
Jiri Bencf0706e82007-05-05 11:45:53 -0700425 list_for_each_entry(sta, &local->sta_list, list) {
426 __sta_info_get(sta);
427 sta_info_cleanup_expire_buffered(local, sta);
428 sta_info_put(sta);
429 }
Michael Wube8755e2007-07-27 15:43:23 +0200430 read_unlock_bh(&local->sta_lock);
Jiri Bencf0706e82007-05-05 11:45:53 -0700431
Johannes Berg0d174402007-12-17 15:07:43 +0100432 local->sta_cleanup.expires =
433 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL);
Jiri Bencf0706e82007-05-05 11:45:53 -0700434 add_timer(&local->sta_cleanup);
435}
436
Jiri Bence9f207f2007-05-05 11:46:38 -0700437#ifdef CONFIG_MAC80211_DEBUGFS
438static void sta_info_debugfs_add_task(struct work_struct *work)
439{
440 struct ieee80211_local *local =
441 container_of(work, struct ieee80211_local, sta_debugfs_add);
442 struct sta_info *sta, *tmp;
443
444 while (1) {
Jiri Bence9f207f2007-05-05 11:46:38 -0700445 sta = NULL;
Michael Wube8755e2007-07-27 15:43:23 +0200446 read_lock_bh(&local->sta_lock);
Jiri Bence9f207f2007-05-05 11:46:38 -0700447 list_for_each_entry(tmp, &local->sta_list, list) {
Michael Wube8755e2007-07-27 15:43:23 +0200448 if (!tmp->debugfs.dir) {
Jiri Bence9f207f2007-05-05 11:46:38 -0700449 sta = tmp;
450 __sta_info_get(sta);
451 break;
452 }
453 }
Michael Wube8755e2007-07-27 15:43:23 +0200454 read_unlock_bh(&local->sta_lock);
Jiri Bence9f207f2007-05-05 11:46:38 -0700455
456 if (!sta)
457 break;
458
Jiri Bence9f207f2007-05-05 11:46:38 -0700459 ieee80211_sta_debugfs_add(sta);
460 rate_control_add_sta_debugfs(sta);
461 sta_info_put(sta);
462 }
463}
464#endif
465
Jiri Bencf0706e82007-05-05 11:45:53 -0700466void sta_info_init(struct ieee80211_local *local)
467{
Michael Wube8755e2007-07-27 15:43:23 +0200468 rwlock_init(&local->sta_lock);
Jiri Bencf0706e82007-05-05 11:45:53 -0700469 INIT_LIST_HEAD(&local->sta_list);
Jiri Bencf0706e82007-05-05 11:45:53 -0700470
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -0800471 setup_timer(&local->sta_cleanup, sta_info_cleanup,
472 (unsigned long)local);
Johannes Berg0d174402007-12-17 15:07:43 +0100473 local->sta_cleanup.expires =
474 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL);
Jiri Bence9f207f2007-05-05 11:46:38 -0700475
476#ifdef CONFIG_MAC80211_DEBUGFS
477 INIT_WORK(&local->sta_debugfs_add, sta_info_debugfs_add_task);
478#endif
Jiri Bencf0706e82007-05-05 11:45:53 -0700479}
480
481int sta_info_start(struct ieee80211_local *local)
482{
483 add_timer(&local->sta_cleanup);
484 return 0;
485}
486
487void sta_info_stop(struct ieee80211_local *local)
488{
Jiri Bencf0706e82007-05-05 11:45:53 -0700489 del_timer(&local->sta_cleanup);
Michael Wube8755e2007-07-27 15:43:23 +0200490 sta_info_flush(local, NULL);
Jiri Bencf0706e82007-05-05 11:45:53 -0700491}
492
Jiri Bencf0706e82007-05-05 11:45:53 -0700493/**
494 * sta_info_flush - flush matching STA entries from the STA table
495 * @local: local interface data
496 * @dev: matching rule for the net device (sta->dev) or %NULL to match all STAs
497 */
498void sta_info_flush(struct ieee80211_local *local, struct net_device *dev)
499{
500 struct sta_info *sta, *tmp;
Michael Wube8755e2007-07-27 15:43:23 +0200501 LIST_HEAD(tmp_list);
Jiri Bencf0706e82007-05-05 11:45:53 -0700502
Michael Wube8755e2007-07-27 15:43:23 +0200503 write_lock_bh(&local->sta_lock);
Jiri Bencf0706e82007-05-05 11:45:53 -0700504 list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
Michael Wube8755e2007-07-27 15:43:23 +0200505 if (!dev || dev == sta->dev) {
506 __sta_info_get(sta);
507 sta_info_remove(sta);
508 list_add_tail(&sta->list, &tmp_list);
509 }
510 write_unlock_bh(&local->sta_lock);
511
512 list_for_each_entry_safe(sta, tmp, &tmp_list, list) {
513 sta_info_free(sta);
514 sta_info_put(sta);
515 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700516}