xref: /openbmc/linux/net/mac80211/sta_info.c (revision be8755e1804d6f60e6a96a46ac6bc46ce6dfca53)
1f0706e82SJiri Benc /*
2f0706e82SJiri Benc  * Copyright 2002-2005, Instant802 Networks, Inc.
3f0706e82SJiri Benc  * Copyright 2006-2007	Jiri Benc <jbenc@suse.cz>
4f0706e82SJiri Benc  *
5f0706e82SJiri Benc  * This program is free software; you can redistribute it and/or modify
6f0706e82SJiri Benc  * it under the terms of the GNU General Public License version 2 as
7f0706e82SJiri Benc  * published by the Free Software Foundation.
8f0706e82SJiri Benc  */
9f0706e82SJiri Benc 
10f0706e82SJiri Benc #include <linux/module.h>
11f0706e82SJiri Benc #include <linux/init.h>
12f0706e82SJiri Benc #include <linux/netdevice.h>
13f0706e82SJiri Benc #include <linux/types.h>
14f0706e82SJiri Benc #include <linux/slab.h>
15f0706e82SJiri Benc #include <linux/skbuff.h>
16f0706e82SJiri Benc #include <linux/if_arp.h>
17f0706e82SJiri Benc 
18f0706e82SJiri Benc #include <net/mac80211.h>
19f0706e82SJiri Benc #include "ieee80211_i.h"
20f0706e82SJiri Benc #include "ieee80211_rate.h"
21f0706e82SJiri Benc #include "sta_info.h"
22e9f207f0SJiri Benc #include "debugfs_key.h"
23e9f207f0SJiri Benc #include "debugfs_sta.h"
24f0706e82SJiri Benc 
25f0706e82SJiri Benc /* Caller must hold local->sta_lock */
26f0706e82SJiri Benc static void sta_info_hash_add(struct ieee80211_local *local,
27f0706e82SJiri Benc 			      struct sta_info *sta)
28f0706e82SJiri Benc {
29f0706e82SJiri Benc 	sta->hnext = local->sta_hash[STA_HASH(sta->addr)];
30f0706e82SJiri Benc 	local->sta_hash[STA_HASH(sta->addr)] = sta;
31f0706e82SJiri Benc }
32f0706e82SJiri Benc 
33f0706e82SJiri Benc 
34f0706e82SJiri Benc /* Caller must hold local->sta_lock */
35*be8755e1SMichael Wu static int sta_info_hash_del(struct ieee80211_local *local,
36f0706e82SJiri Benc 			     struct sta_info *sta)
37f0706e82SJiri Benc {
38f0706e82SJiri Benc 	struct sta_info *s;
39f0706e82SJiri Benc 
40f0706e82SJiri Benc 	s = local->sta_hash[STA_HASH(sta->addr)];
41f0706e82SJiri Benc 	if (!s)
42*be8755e1SMichael Wu 		return -ENOENT;
43*be8755e1SMichael Wu 	if (s == sta) {
44f0706e82SJiri Benc 		local->sta_hash[STA_HASH(sta->addr)] = s->hnext;
45*be8755e1SMichael Wu 		return 0;
46f0706e82SJiri Benc 	}
47f0706e82SJiri Benc 
48*be8755e1SMichael Wu 	while (s->hnext && s->hnext != sta)
49f0706e82SJiri Benc 		s = s->hnext;
50*be8755e1SMichael Wu 	if (s->hnext) {
51*be8755e1SMichael Wu 		s->hnext = sta->hnext;
52*be8755e1SMichael Wu 		return 0;
53f0706e82SJiri Benc 	}
54f0706e82SJiri Benc 
55*be8755e1SMichael Wu 	return -ENOENT;
56f0706e82SJiri Benc }
57f0706e82SJiri Benc 
58f0706e82SJiri Benc struct sta_info *sta_info_get(struct ieee80211_local *local, u8 *addr)
59f0706e82SJiri Benc {
60f0706e82SJiri Benc 	struct sta_info *sta;
61f0706e82SJiri Benc 
62*be8755e1SMichael Wu 	read_lock_bh(&local->sta_lock);
63f0706e82SJiri Benc 	sta = local->sta_hash[STA_HASH(addr)];
64f0706e82SJiri Benc 	while (sta) {
65f0706e82SJiri Benc 		if (memcmp(sta->addr, addr, ETH_ALEN) == 0) {
66f0706e82SJiri Benc 			__sta_info_get(sta);
67f0706e82SJiri Benc 			break;
68f0706e82SJiri Benc 		}
69f0706e82SJiri Benc 		sta = sta->hnext;
70f0706e82SJiri Benc 	}
71*be8755e1SMichael Wu 	read_unlock_bh(&local->sta_lock);
72f0706e82SJiri Benc 
73f0706e82SJiri Benc 	return sta;
74f0706e82SJiri Benc }
75f0706e82SJiri Benc EXPORT_SYMBOL(sta_info_get);
76f0706e82SJiri Benc 
77f0706e82SJiri Benc int sta_info_min_txrate_get(struct ieee80211_local *local)
78f0706e82SJiri Benc {
79f0706e82SJiri Benc 	struct sta_info *sta;
80f0706e82SJiri Benc 	struct ieee80211_hw_mode *mode;
81f0706e82SJiri Benc 	int min_txrate = 9999999;
82f0706e82SJiri Benc 	int i;
83f0706e82SJiri Benc 
84*be8755e1SMichael Wu 	read_lock_bh(&local->sta_lock);
85f0706e82SJiri Benc 	mode = local->oper_hw_mode;
86f0706e82SJiri Benc 	for (i = 0; i < STA_HASH_SIZE; i++) {
87f0706e82SJiri Benc 		sta = local->sta_hash[i];
88f0706e82SJiri Benc 		while (sta) {
89f0706e82SJiri Benc 			if (sta->txrate < min_txrate)
90f0706e82SJiri Benc 				min_txrate = sta->txrate;
91f0706e82SJiri Benc 			sta = sta->hnext;
92f0706e82SJiri Benc 		}
93f0706e82SJiri Benc 	}
94*be8755e1SMichael Wu 	read_unlock_bh(&local->sta_lock);
95f0706e82SJiri Benc 	if (min_txrate == 9999999)
96f0706e82SJiri Benc 		min_txrate = 0;
97f0706e82SJiri Benc 
98f0706e82SJiri Benc 	return mode->rates[min_txrate].rate;
99f0706e82SJiri Benc }
100f0706e82SJiri Benc 
101f0706e82SJiri Benc 
102f0706e82SJiri Benc static void sta_info_release(struct kref *kref)
103f0706e82SJiri Benc {
104f0706e82SJiri Benc 	struct sta_info *sta = container_of(kref, struct sta_info, kref);
105f0706e82SJiri Benc 	struct ieee80211_local *local = sta->local;
106f0706e82SJiri Benc 	struct sk_buff *skb;
107f0706e82SJiri Benc 
108f0706e82SJiri Benc 	/* free sta structure; it has already been removed from
109f0706e82SJiri Benc 	 * hash table etc. external structures. Make sure that all
110f0706e82SJiri Benc 	 * buffered frames are release (one might have been added
111f0706e82SJiri Benc 	 * after sta_info_free() was called). */
112f0706e82SJiri Benc 	while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
113f0706e82SJiri Benc 		local->total_ps_buffered--;
114f0706e82SJiri Benc 		dev_kfree_skb_any(skb);
115f0706e82SJiri Benc 	}
116f0706e82SJiri Benc 	while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
117f0706e82SJiri Benc 		dev_kfree_skb_any(skb);
118f0706e82SJiri Benc 	}
119f0706e82SJiri Benc 	rate_control_free_sta(sta->rate_ctrl, sta->rate_ctrl_priv);
120f0706e82SJiri Benc 	rate_control_put(sta->rate_ctrl);
121e9f207f0SJiri Benc 	if (sta->key)
122e9f207f0SJiri Benc 		ieee80211_debugfs_key_sta_del(sta->key, sta);
123f0706e82SJiri Benc 	kfree(sta);
124f0706e82SJiri Benc }
125f0706e82SJiri Benc 
126f0706e82SJiri Benc 
127f0706e82SJiri Benc void sta_info_put(struct sta_info *sta)
128f0706e82SJiri Benc {
129f0706e82SJiri Benc 	kref_put(&sta->kref, sta_info_release);
130f0706e82SJiri Benc }
131f0706e82SJiri Benc EXPORT_SYMBOL(sta_info_put);
132f0706e82SJiri Benc 
133f0706e82SJiri Benc 
134f0706e82SJiri Benc struct sta_info * sta_info_add(struct ieee80211_local *local,
135f0706e82SJiri Benc 			       struct net_device *dev, u8 *addr, gfp_t gfp)
136f0706e82SJiri Benc {
137f0706e82SJiri Benc 	struct sta_info *sta;
138f0706e82SJiri Benc 
139f0706e82SJiri Benc 	sta = kzalloc(sizeof(*sta), gfp);
140f0706e82SJiri Benc 	if (!sta)
141f0706e82SJiri Benc 		return NULL;
142f0706e82SJiri Benc 
143f0706e82SJiri Benc 	kref_init(&sta->kref);
144f0706e82SJiri Benc 
145f0706e82SJiri Benc 	sta->rate_ctrl = rate_control_get(local->rate_ctrl);
146f0706e82SJiri Benc 	sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl, gfp);
147f0706e82SJiri Benc 	if (!sta->rate_ctrl_priv) {
148f0706e82SJiri Benc 		rate_control_put(sta->rate_ctrl);
149f0706e82SJiri Benc 		kfree(sta);
150f0706e82SJiri Benc 		return NULL;
151f0706e82SJiri Benc 	}
152f0706e82SJiri Benc 
153f0706e82SJiri Benc 	memcpy(sta->addr, addr, ETH_ALEN);
154f0706e82SJiri Benc 	sta->local = local;
155f0706e82SJiri Benc 	sta->dev = dev;
156f0706e82SJiri Benc 	skb_queue_head_init(&sta->ps_tx_buf);
157f0706e82SJiri Benc 	skb_queue_head_init(&sta->tx_filtered);
158f0706e82SJiri Benc 	__sta_info_get(sta);	/* sta used by caller, decremented by
159f0706e82SJiri Benc 				 * sta_info_put() */
160*be8755e1SMichael Wu 	write_lock_bh(&local->sta_lock);
161f0706e82SJiri Benc 	list_add(&sta->list, &local->sta_list);
162f0706e82SJiri Benc 	local->num_sta++;
163f0706e82SJiri Benc 	sta_info_hash_add(local, sta);
164f0706e82SJiri Benc 	if (local->ops->sta_table_notification)
165f0706e82SJiri Benc 		local->ops->sta_table_notification(local_to_hw(local),
166f0706e82SJiri Benc 						  local->num_sta);
167*be8755e1SMichael Wu 	write_unlock_bh(&local->sta_lock);
168f0706e82SJiri Benc 	sta->key_idx_compression = HW_KEY_IDX_INVALID;
169f0706e82SJiri Benc 
170f0706e82SJiri Benc #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
171f0706e82SJiri Benc 	printk(KERN_DEBUG "%s: Added STA " MAC_FMT "\n",
172f0706e82SJiri Benc 	       local->mdev->name, MAC_ARG(addr));
173f0706e82SJiri Benc #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
174f0706e82SJiri Benc 
175e9f207f0SJiri Benc #ifdef CONFIG_MAC80211_DEBUGFS
176e9f207f0SJiri Benc 	/* debugfs entry adding might sleep, so schedule process
177e9f207f0SJiri Benc 	 * context task for adding entry for STAs that do not yet
178e9f207f0SJiri Benc 	 * have one. */
179e9f207f0SJiri Benc 	queue_work(local->hw.workqueue, &local->sta_debugfs_add);
180e9f207f0SJiri Benc #endif
181e9f207f0SJiri Benc 
182f0706e82SJiri Benc 	return sta;
183f0706e82SJiri Benc }
184f0706e82SJiri Benc 
185*be8755e1SMichael Wu /* Caller must hold local->sta_lock */
186*be8755e1SMichael Wu void sta_info_remove(struct sta_info *sta)
187f0706e82SJiri Benc {
188f0706e82SJiri Benc 	struct ieee80211_local *local = sta->local;
189f0706e82SJiri Benc 	struct ieee80211_sub_if_data *sdata;
190f0706e82SJiri Benc 
191*be8755e1SMichael Wu 	/* don't do anything if we've been removed already */
192*be8755e1SMichael Wu 	if (sta_info_hash_del(local, sta))
193*be8755e1SMichael Wu 		return;
194*be8755e1SMichael Wu 
195f0706e82SJiri Benc 	list_del(&sta->list);
196f0706e82SJiri Benc 	sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
197f0706e82SJiri Benc 	if (sta->flags & WLAN_STA_PS) {
198f0706e82SJiri Benc 		sta->flags &= ~WLAN_STA_PS;
199f0706e82SJiri Benc 		if (sdata->bss)
200f0706e82SJiri Benc 			atomic_dec(&sdata->bss->num_sta_ps);
201f0706e82SJiri Benc 	}
202f0706e82SJiri Benc 	local->num_sta--;
203f0706e82SJiri Benc 	sta_info_remove_aid_ptr(sta);
204*be8755e1SMichael Wu 
205*be8755e1SMichael Wu 	if (local->ops->sta_table_notification)
206*be8755e1SMichael Wu 		local->ops->sta_table_notification(local_to_hw(local),
207*be8755e1SMichael Wu 						   local->num_sta);
208f0706e82SJiri Benc }
209f0706e82SJiri Benc 
210*be8755e1SMichael Wu void sta_info_free(struct sta_info *sta)
211f0706e82SJiri Benc {
212f0706e82SJiri Benc 	struct sk_buff *skb;
213f0706e82SJiri Benc 	struct ieee80211_local *local = sta->local;
214f0706e82SJiri Benc 
215*be8755e1SMichael Wu 	might_sleep();
216*be8755e1SMichael Wu 
217*be8755e1SMichael Wu 	write_lock_bh(&local->sta_lock);
218f0706e82SJiri Benc 	sta_info_remove(sta);
219*be8755e1SMichael Wu 	write_unlock_bh(&local->sta_lock);
220f0706e82SJiri Benc 
221f0706e82SJiri Benc 	while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
222f0706e82SJiri Benc 		local->total_ps_buffered--;
223*be8755e1SMichael Wu 		dev_kfree_skb(skb);
224f0706e82SJiri Benc 	}
225f0706e82SJiri Benc 	while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
226*be8755e1SMichael Wu 		dev_kfree_skb(skb);
227f0706e82SJiri Benc 	}
228f0706e82SJiri Benc 
229f0706e82SJiri Benc 	if (sta->key) {
230f0706e82SJiri Benc 		if (local->ops->set_key) {
231f0706e82SJiri Benc 			struct ieee80211_key_conf *key;
232f0706e82SJiri Benc 			key = ieee80211_key_data2conf(local, sta->key);
233f0706e82SJiri Benc 			if (key) {
234f0706e82SJiri Benc 				local->ops->set_key(local_to_hw(local),
235f0706e82SJiri Benc 						   DISABLE_KEY,
236f0706e82SJiri Benc 						   sta->addr, key, sta->aid);
237f0706e82SJiri Benc 				kfree(key);
238f0706e82SJiri Benc 			}
239f0706e82SJiri Benc 		}
240f0706e82SJiri Benc 	} else if (sta->key_idx_compression != HW_KEY_IDX_INVALID) {
241f0706e82SJiri Benc 		struct ieee80211_key_conf conf;
242f0706e82SJiri Benc 		memset(&conf, 0, sizeof(conf));
243f0706e82SJiri Benc 		conf.hw_key_idx = sta->key_idx_compression;
244f0706e82SJiri Benc 		conf.alg = ALG_NULL;
245f0706e82SJiri Benc 		conf.flags |= IEEE80211_KEY_FORCE_SW_ENCRYPT;
246f0706e82SJiri Benc 		local->ops->set_key(local_to_hw(local), DISABLE_KEY,
247f0706e82SJiri Benc 				   sta->addr, &conf, sta->aid);
248f0706e82SJiri Benc 		sta->key_idx_compression = HW_KEY_IDX_INVALID;
249f0706e82SJiri Benc 	}
250f0706e82SJiri Benc 
251*be8755e1SMichael Wu #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
252*be8755e1SMichael Wu 	printk(KERN_DEBUG "%s: Removed STA " MAC_FMT "\n",
253*be8755e1SMichael Wu 	       local->mdev->name, MAC_ARG(sta->addr));
254*be8755e1SMichael Wu #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
255*be8755e1SMichael Wu 
256*be8755e1SMichael Wu 	if (sta->key) {
257*be8755e1SMichael Wu 		ieee80211_debugfs_key_remove(sta->key);
258*be8755e1SMichael Wu 		ieee80211_key_free(sta->key);
259*be8755e1SMichael Wu 		sta->key = NULL;
260*be8755e1SMichael Wu 	}
261*be8755e1SMichael Wu 
262*be8755e1SMichael Wu 	rate_control_remove_sta_debugfs(sta);
263*be8755e1SMichael Wu 	ieee80211_sta_debugfs_remove(sta);
264*be8755e1SMichael Wu 
265*be8755e1SMichael Wu 	sta_info_put(sta);
266f0706e82SJiri Benc }
267f0706e82SJiri Benc 
268f0706e82SJiri Benc 
269f0706e82SJiri Benc static inline int sta_info_buffer_expired(struct ieee80211_local *local,
270f0706e82SJiri Benc 					  struct sta_info *sta,
271f0706e82SJiri Benc 					  struct sk_buff *skb)
272f0706e82SJiri Benc {
273f0706e82SJiri Benc 	struct ieee80211_tx_packet_data *pkt_data;
274f0706e82SJiri Benc 	int timeout;
275f0706e82SJiri Benc 
276f0706e82SJiri Benc 	if (!skb)
277f0706e82SJiri Benc 		return 0;
278f0706e82SJiri Benc 
279f0706e82SJiri Benc 	pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
280f0706e82SJiri Benc 
281f0706e82SJiri Benc 	/* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */
282f0706e82SJiri Benc 	timeout = (sta->listen_interval * local->hw.conf.beacon_int * 32 /
283f0706e82SJiri Benc 		   15625) * HZ;
284f0706e82SJiri Benc 	if (timeout < STA_TX_BUFFER_EXPIRE)
285f0706e82SJiri Benc 		timeout = STA_TX_BUFFER_EXPIRE;
286f0706e82SJiri Benc 	return time_after(jiffies, pkt_data->jiffies + timeout);
287f0706e82SJiri Benc }
288f0706e82SJiri Benc 
289f0706e82SJiri Benc 
290f0706e82SJiri Benc static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
291f0706e82SJiri Benc 					     struct sta_info *sta)
292f0706e82SJiri Benc {
293f0706e82SJiri Benc 	unsigned long flags;
294f0706e82SJiri Benc 	struct sk_buff *skb;
295f0706e82SJiri Benc 
296f0706e82SJiri Benc 	if (skb_queue_empty(&sta->ps_tx_buf))
297f0706e82SJiri Benc 		return;
298f0706e82SJiri Benc 
299f0706e82SJiri Benc 	for (;;) {
300f0706e82SJiri Benc 		spin_lock_irqsave(&sta->ps_tx_buf.lock, flags);
301f0706e82SJiri Benc 		skb = skb_peek(&sta->ps_tx_buf);
302f0706e82SJiri Benc 		if (sta_info_buffer_expired(local, sta, skb)) {
303f0706e82SJiri Benc 			skb = __skb_dequeue(&sta->ps_tx_buf);
304f0706e82SJiri Benc 			if (skb_queue_empty(&sta->ps_tx_buf))
305f0706e82SJiri Benc 				sta->flags &= ~WLAN_STA_TIM;
306f0706e82SJiri Benc 		} else
307f0706e82SJiri Benc 			skb = NULL;
308f0706e82SJiri Benc 		spin_unlock_irqrestore(&sta->ps_tx_buf.lock, flags);
309f0706e82SJiri Benc 
310f0706e82SJiri Benc 		if (skb) {
311f0706e82SJiri Benc 			local->total_ps_buffered--;
312f0706e82SJiri Benc 			printk(KERN_DEBUG "Buffered frame expired (STA "
313f0706e82SJiri Benc 			       MAC_FMT ")\n", MAC_ARG(sta->addr));
314f0706e82SJiri Benc 			dev_kfree_skb(skb);
315f0706e82SJiri Benc 		} else
316f0706e82SJiri Benc 			break;
317f0706e82SJiri Benc 	}
318f0706e82SJiri Benc }
319f0706e82SJiri Benc 
320f0706e82SJiri Benc 
321f0706e82SJiri Benc static void sta_info_cleanup(unsigned long data)
322f0706e82SJiri Benc {
323f0706e82SJiri Benc 	struct ieee80211_local *local = (struct ieee80211_local *) data;
324f0706e82SJiri Benc 	struct sta_info *sta;
325f0706e82SJiri Benc 
326*be8755e1SMichael Wu 	read_lock_bh(&local->sta_lock);
327f0706e82SJiri Benc 	list_for_each_entry(sta, &local->sta_list, list) {
328f0706e82SJiri Benc 		__sta_info_get(sta);
329f0706e82SJiri Benc 		sta_info_cleanup_expire_buffered(local, sta);
330f0706e82SJiri Benc 		sta_info_put(sta);
331f0706e82SJiri Benc 	}
332*be8755e1SMichael Wu 	read_unlock_bh(&local->sta_lock);
333f0706e82SJiri Benc 
334f0706e82SJiri Benc 	local->sta_cleanup.expires = jiffies + STA_INFO_CLEANUP_INTERVAL;
335f0706e82SJiri Benc 	add_timer(&local->sta_cleanup);
336f0706e82SJiri Benc }
337f0706e82SJiri Benc 
338e9f207f0SJiri Benc #ifdef CONFIG_MAC80211_DEBUGFS
339e9f207f0SJiri Benc static void sta_info_debugfs_add_task(struct work_struct *work)
340e9f207f0SJiri Benc {
341e9f207f0SJiri Benc 	struct ieee80211_local *local =
342e9f207f0SJiri Benc 		container_of(work, struct ieee80211_local, sta_debugfs_add);
343e9f207f0SJiri Benc 	struct sta_info *sta, *tmp;
344e9f207f0SJiri Benc 
345e9f207f0SJiri Benc 	while (1) {
346e9f207f0SJiri Benc 		sta = NULL;
347*be8755e1SMichael Wu 		read_lock_bh(&local->sta_lock);
348e9f207f0SJiri Benc 		list_for_each_entry(tmp, &local->sta_list, list) {
349*be8755e1SMichael Wu 			if (!tmp->debugfs.dir) {
350e9f207f0SJiri Benc 				sta = tmp;
351e9f207f0SJiri Benc 				__sta_info_get(sta);
352e9f207f0SJiri Benc 				break;
353e9f207f0SJiri Benc 			}
354e9f207f0SJiri Benc 		}
355*be8755e1SMichael Wu 		read_unlock_bh(&local->sta_lock);
356e9f207f0SJiri Benc 
357e9f207f0SJiri Benc 		if (!sta)
358e9f207f0SJiri Benc 			break;
359e9f207f0SJiri Benc 
360e9f207f0SJiri Benc 		ieee80211_sta_debugfs_add(sta);
361e9f207f0SJiri Benc 		rate_control_add_sta_debugfs(sta);
362e9f207f0SJiri Benc 		sta_info_put(sta);
363e9f207f0SJiri Benc 	}
364e9f207f0SJiri Benc }
365e9f207f0SJiri Benc #endif
366e9f207f0SJiri Benc 
367f0706e82SJiri Benc void sta_info_init(struct ieee80211_local *local)
368f0706e82SJiri Benc {
369*be8755e1SMichael Wu 	rwlock_init(&local->sta_lock);
370f0706e82SJiri Benc 	INIT_LIST_HEAD(&local->sta_list);
371f0706e82SJiri Benc 
372f0706e82SJiri Benc 	init_timer(&local->sta_cleanup);
373f0706e82SJiri Benc 	local->sta_cleanup.expires = jiffies + STA_INFO_CLEANUP_INTERVAL;
374f0706e82SJiri Benc 	local->sta_cleanup.data = (unsigned long) local;
375f0706e82SJiri Benc 	local->sta_cleanup.function = sta_info_cleanup;
376e9f207f0SJiri Benc 
377e9f207f0SJiri Benc #ifdef CONFIG_MAC80211_DEBUGFS
378e9f207f0SJiri Benc 	INIT_WORK(&local->sta_debugfs_add, sta_info_debugfs_add_task);
379e9f207f0SJiri Benc #endif
380f0706e82SJiri Benc }
381f0706e82SJiri Benc 
382f0706e82SJiri Benc int sta_info_start(struct ieee80211_local *local)
383f0706e82SJiri Benc {
384f0706e82SJiri Benc 	add_timer(&local->sta_cleanup);
385f0706e82SJiri Benc 	return 0;
386f0706e82SJiri Benc }
387f0706e82SJiri Benc 
388f0706e82SJiri Benc void sta_info_stop(struct ieee80211_local *local)
389f0706e82SJiri Benc {
390f0706e82SJiri Benc 	del_timer(&local->sta_cleanup);
391*be8755e1SMichael Wu 	sta_info_flush(local, NULL);
392f0706e82SJiri Benc }
393f0706e82SJiri Benc 
394f0706e82SJiri Benc void sta_info_remove_aid_ptr(struct sta_info *sta)
395f0706e82SJiri Benc {
396f0706e82SJiri Benc 	struct ieee80211_sub_if_data *sdata;
397f0706e82SJiri Benc 
398f0706e82SJiri Benc 	if (sta->aid <= 0)
399f0706e82SJiri Benc 		return;
400f0706e82SJiri Benc 
401f0706e82SJiri Benc 	sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
402f0706e82SJiri Benc 
403f0706e82SJiri Benc 	if (sdata->local->ops->set_tim)
404f0706e82SJiri Benc 		sdata->local->ops->set_tim(local_to_hw(sdata->local),
405f0706e82SJiri Benc 					  sta->aid, 0);
406f0706e82SJiri Benc 	if (sdata->bss)
407f0706e82SJiri Benc 		__bss_tim_clear(sdata->bss, sta->aid);
408f0706e82SJiri Benc }
409f0706e82SJiri Benc 
410f0706e82SJiri Benc 
411f0706e82SJiri Benc /**
412f0706e82SJiri Benc  * sta_info_flush - flush matching STA entries from the STA table
413f0706e82SJiri Benc  * @local: local interface data
414f0706e82SJiri Benc  * @dev: matching rule for the net device (sta->dev) or %NULL to match all STAs
415f0706e82SJiri Benc  */
416f0706e82SJiri Benc void sta_info_flush(struct ieee80211_local *local, struct net_device *dev)
417f0706e82SJiri Benc {
418f0706e82SJiri Benc 	struct sta_info *sta, *tmp;
419*be8755e1SMichael Wu 	LIST_HEAD(tmp_list);
420f0706e82SJiri Benc 
421*be8755e1SMichael Wu 	write_lock_bh(&local->sta_lock);
422f0706e82SJiri Benc 	list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
423*be8755e1SMichael Wu 		if (!dev || dev == sta->dev) {
424*be8755e1SMichael Wu 			__sta_info_get(sta);
425*be8755e1SMichael Wu 			sta_info_remove(sta);
426*be8755e1SMichael Wu 			list_add_tail(&sta->list, &tmp_list);
427*be8755e1SMichael Wu 		}
428*be8755e1SMichael Wu 	write_unlock_bh(&local->sta_lock);
429*be8755e1SMichael Wu 
430*be8755e1SMichael Wu 	list_for_each_entry_safe(sta, tmp, &tmp_list, list) {
431*be8755e1SMichael Wu 		sta_info_free(sta);
432*be8755e1SMichael Wu 		sta_info_put(sta);
433*be8755e1SMichael Wu 	}
434f0706e82SJiri Benc }
435