xref: /openbmc/linux/net/mac80211/sta_info.c (revision 16c5f15c73e97e22a1fcc6518da32bdcf98aec3d)
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>
170d174406SJohannes Berg #include <linux/timer.h>
18f0706e82SJiri Benc 
19f0706e82SJiri Benc #include <net/mac80211.h>
20f0706e82SJiri Benc #include "ieee80211_i.h"
21f0706e82SJiri Benc #include "ieee80211_rate.h"
22f0706e82SJiri Benc #include "sta_info.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 */
35be8755e1SMichael 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)
42be8755e1SMichael Wu 		return -ENOENT;
43be8755e1SMichael Wu 	if (s == sta) {
44f0706e82SJiri Benc 		local->sta_hash[STA_HASH(sta->addr)] = s->hnext;
45be8755e1SMichael Wu 		return 0;
46f0706e82SJiri Benc 	}
47f0706e82SJiri Benc 
48be8755e1SMichael Wu 	while (s->hnext && s->hnext != sta)
49f0706e82SJiri Benc 		s = s->hnext;
50be8755e1SMichael Wu 	if (s->hnext) {
51be8755e1SMichael Wu 		s->hnext = sta->hnext;
52be8755e1SMichael Wu 		return 0;
53f0706e82SJiri Benc 	}
54f0706e82SJiri Benc 
55be8755e1SMichael 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 
62be8755e1SMichael 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 	}
71be8755e1SMichael 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 
84be8755e1SMichael 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 	}
94be8755e1SMichael 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;
10707db2183SRon Rindjunsky 	int i;
108f0706e82SJiri Benc 
109f0706e82SJiri Benc 	/* free sta structure; it has already been removed from
110f0706e82SJiri Benc 	 * hash table etc. external structures. Make sure that all
111f0706e82SJiri Benc 	 * buffered frames are release (one might have been added
112f0706e82SJiri Benc 	 * after sta_info_free() was called). */
113f0706e82SJiri Benc 	while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
114f0706e82SJiri Benc 		local->total_ps_buffered--;
115f0706e82SJiri Benc 		dev_kfree_skb_any(skb);
116f0706e82SJiri Benc 	}
117f0706e82SJiri Benc 	while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
118f0706e82SJiri Benc 		dev_kfree_skb_any(skb);
119f0706e82SJiri Benc 	}
12007db2183SRon Rindjunsky 	for (i = 0; i <  STA_TID_NUM; i++)
12107db2183SRon Rindjunsky 		del_timer_sync(&sta->ampdu_mlme.tid_rx[i].session_timer);
122f0706e82SJiri Benc 	rate_control_free_sta(sta->rate_ctrl, sta->rate_ctrl_priv);
123f0706e82SJiri Benc 	rate_control_put(sta->rate_ctrl);
124f0706e82SJiri Benc 	kfree(sta);
125f0706e82SJiri Benc }
126f0706e82SJiri Benc 
127f0706e82SJiri Benc 
128f0706e82SJiri Benc void sta_info_put(struct sta_info *sta)
129f0706e82SJiri Benc {
130f0706e82SJiri Benc 	kref_put(&sta->kref, sta_info_release);
131f0706e82SJiri Benc }
132f0706e82SJiri Benc EXPORT_SYMBOL(sta_info_put);
133f0706e82SJiri Benc 
134f0706e82SJiri Benc 
135f0706e82SJiri Benc struct sta_info * sta_info_add(struct ieee80211_local *local,
136f0706e82SJiri Benc 			       struct net_device *dev, u8 *addr, gfp_t gfp)
137f0706e82SJiri Benc {
138f0706e82SJiri Benc 	struct sta_info *sta;
139*16c5f15cSRon Rindjunsky 	int i;
1400795af57SJoe Perches 	DECLARE_MAC_BUF(mac);
141f0706e82SJiri Benc 
142f0706e82SJiri Benc 	sta = kzalloc(sizeof(*sta), gfp);
143f0706e82SJiri Benc 	if (!sta)
144f0706e82SJiri Benc 		return NULL;
145f0706e82SJiri Benc 
146f0706e82SJiri Benc 	kref_init(&sta->kref);
147f0706e82SJiri Benc 
148f0706e82SJiri Benc 	sta->rate_ctrl = rate_control_get(local->rate_ctrl);
149f0706e82SJiri Benc 	sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl, gfp);
150f0706e82SJiri Benc 	if (!sta->rate_ctrl_priv) {
151f0706e82SJiri Benc 		rate_control_put(sta->rate_ctrl);
152f0706e82SJiri Benc 		kfree(sta);
153f0706e82SJiri Benc 		return NULL;
154f0706e82SJiri Benc 	}
155f0706e82SJiri Benc 
156f0706e82SJiri Benc 	memcpy(sta->addr, addr, ETH_ALEN);
157f0706e82SJiri Benc 	sta->local = local;
158f0706e82SJiri Benc 	sta->dev = dev;
159*16c5f15cSRon Rindjunsky 	spin_lock_init(&sta->ampdu_mlme.ampdu_rx);
160*16c5f15cSRon Rindjunsky 	for (i = 0; i < STA_TID_NUM; i++) {
161*16c5f15cSRon Rindjunsky 		/* timer_to_tid must be initialized with identity mapping to
162*16c5f15cSRon Rindjunsky 		 * enable session_timer's data differentiation. refer to
163*16c5f15cSRon Rindjunsky 		 * sta_rx_agg_session_timer_expired for useage */
164*16c5f15cSRon Rindjunsky 		sta->timer_to_tid[i] = i;
165*16c5f15cSRon Rindjunsky 		/* rx timers */
166*16c5f15cSRon Rindjunsky 		sta->ampdu_mlme.tid_rx[i].session_timer.function =
167*16c5f15cSRon Rindjunsky 			sta_rx_agg_session_timer_expired;
168*16c5f15cSRon Rindjunsky 		sta->ampdu_mlme.tid_rx[i].session_timer.data =
169*16c5f15cSRon Rindjunsky 			(unsigned long)&sta->timer_to_tid[i];
170*16c5f15cSRon Rindjunsky 		init_timer(&sta->ampdu_mlme.tid_rx[i].session_timer);
171*16c5f15cSRon Rindjunsky 	}
172f0706e82SJiri Benc 	skb_queue_head_init(&sta->ps_tx_buf);
173f0706e82SJiri Benc 	skb_queue_head_init(&sta->tx_filtered);
174f0706e82SJiri Benc 	__sta_info_get(sta);	/* sta used by caller, decremented by
175f0706e82SJiri Benc 				 * sta_info_put() */
176be8755e1SMichael Wu 	write_lock_bh(&local->sta_lock);
177f0706e82SJiri Benc 	list_add(&sta->list, &local->sta_list);
178f0706e82SJiri Benc 	local->num_sta++;
179f0706e82SJiri Benc 	sta_info_hash_add(local, sta);
180478f8d2bSTomas Winkler 	if (local->ops->sta_notify)
181478f8d2bSTomas Winkler 		local->ops->sta_notify(local_to_hw(local), dev->ifindex,
182478f8d2bSTomas Winkler 					STA_NOTIFY_ADD, addr);
183be8755e1SMichael Wu 	write_unlock_bh(&local->sta_lock);
184f0706e82SJiri Benc 
185f0706e82SJiri Benc #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1860795af57SJoe Perches 	printk(KERN_DEBUG "%s: Added STA %s\n",
187dd1cd4c6SJohannes Berg 	       wiphy_name(local->hw.wiphy), print_mac(mac, addr));
188f0706e82SJiri Benc #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
189f0706e82SJiri Benc 
190e9f207f0SJiri Benc #ifdef CONFIG_MAC80211_DEBUGFS
191e9f207f0SJiri Benc 	/* debugfs entry adding might sleep, so schedule process
192e9f207f0SJiri Benc 	 * context task for adding entry for STAs that do not yet
193e9f207f0SJiri Benc 	 * have one. */
194e9f207f0SJiri Benc 	queue_work(local->hw.workqueue, &local->sta_debugfs_add);
195e9f207f0SJiri Benc #endif
196e9f207f0SJiri Benc 
197f0706e82SJiri Benc 	return sta;
198f0706e82SJiri Benc }
199f0706e82SJiri Benc 
200be8755e1SMichael Wu /* Caller must hold local->sta_lock */
201be8755e1SMichael Wu void sta_info_remove(struct sta_info *sta)
202f0706e82SJiri Benc {
203f0706e82SJiri Benc 	struct ieee80211_local *local = sta->local;
204f0706e82SJiri Benc 	struct ieee80211_sub_if_data *sdata;
205f0706e82SJiri Benc 
206be8755e1SMichael Wu 	/* don't do anything if we've been removed already */
207be8755e1SMichael Wu 	if (sta_info_hash_del(local, sta))
208be8755e1SMichael Wu 		return;
209be8755e1SMichael Wu 
210f0706e82SJiri Benc 	list_del(&sta->list);
211f0706e82SJiri Benc 	sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
212f0706e82SJiri Benc 	if (sta->flags & WLAN_STA_PS) {
213f0706e82SJiri Benc 		sta->flags &= ~WLAN_STA_PS;
214f0706e82SJiri Benc 		if (sdata->bss)
215f0706e82SJiri Benc 			atomic_dec(&sdata->bss->num_sta_ps);
216f0706e82SJiri Benc 	}
217f0706e82SJiri Benc 	local->num_sta--;
218f0706e82SJiri Benc 	sta_info_remove_aid_ptr(sta);
219be8755e1SMichael Wu 
220f0706e82SJiri Benc }
221f0706e82SJiri Benc 
222be8755e1SMichael Wu void sta_info_free(struct sta_info *sta)
223f0706e82SJiri Benc {
224f0706e82SJiri Benc 	struct sk_buff *skb;
225f0706e82SJiri Benc 	struct ieee80211_local *local = sta->local;
2260795af57SJoe Perches 	DECLARE_MAC_BUF(mac);
227f0706e82SJiri Benc 
228be8755e1SMichael Wu 	might_sleep();
229be8755e1SMichael Wu 
230be8755e1SMichael Wu 	write_lock_bh(&local->sta_lock);
231f0706e82SJiri Benc 	sta_info_remove(sta);
232be8755e1SMichael Wu 	write_unlock_bh(&local->sta_lock);
233f0706e82SJiri Benc 
234f0706e82SJiri Benc 	while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
235f0706e82SJiri Benc 		local->total_ps_buffered--;
236be8755e1SMichael Wu 		dev_kfree_skb(skb);
237f0706e82SJiri Benc 	}
238f0706e82SJiri Benc 	while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
239be8755e1SMichael Wu 		dev_kfree_skb(skb);
240f0706e82SJiri Benc 	}
241f0706e82SJiri Benc 
242be8755e1SMichael Wu #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2430795af57SJoe Perches 	printk(KERN_DEBUG "%s: Removed STA %s\n",
244dd1cd4c6SJohannes Berg 	       wiphy_name(local->hw.wiphy), print_mac(mac, sta->addr));
245be8755e1SMichael Wu #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
246be8755e1SMichael Wu 
247be8755e1SMichael Wu 	ieee80211_key_free(sta->key);
248be8755e1SMichael Wu 	sta->key = NULL;
249be8755e1SMichael Wu 
250478f8d2bSTomas Winkler 	if (local->ops->sta_notify)
251478f8d2bSTomas Winkler 		local->ops->sta_notify(local_to_hw(local), sta->dev->ifindex,
252478f8d2bSTomas Winkler 					STA_NOTIFY_REMOVE, sta->addr);
253478f8d2bSTomas Winkler 
254be8755e1SMichael Wu 	rate_control_remove_sta_debugfs(sta);
255be8755e1SMichael Wu 	ieee80211_sta_debugfs_remove(sta);
256be8755e1SMichael Wu 
257be8755e1SMichael Wu 	sta_info_put(sta);
258f0706e82SJiri Benc }
259f0706e82SJiri Benc 
260f0706e82SJiri Benc 
261f0706e82SJiri Benc static inline int sta_info_buffer_expired(struct ieee80211_local *local,
262f0706e82SJiri Benc 					  struct sta_info *sta,
263f0706e82SJiri Benc 					  struct sk_buff *skb)
264f0706e82SJiri Benc {
265f0706e82SJiri Benc 	struct ieee80211_tx_packet_data *pkt_data;
266f0706e82SJiri Benc 	int timeout;
267f0706e82SJiri Benc 
268f0706e82SJiri Benc 	if (!skb)
269f0706e82SJiri Benc 		return 0;
270f0706e82SJiri Benc 
271f0706e82SJiri Benc 	pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
272f0706e82SJiri Benc 
273f0706e82SJiri Benc 	/* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */
274f0706e82SJiri Benc 	timeout = (sta->listen_interval * local->hw.conf.beacon_int * 32 /
275f0706e82SJiri Benc 		   15625) * HZ;
276f0706e82SJiri Benc 	if (timeout < STA_TX_BUFFER_EXPIRE)
277f0706e82SJiri Benc 		timeout = STA_TX_BUFFER_EXPIRE;
278f0706e82SJiri Benc 	return time_after(jiffies, pkt_data->jiffies + timeout);
279f0706e82SJiri Benc }
280f0706e82SJiri Benc 
281f0706e82SJiri Benc 
282f0706e82SJiri Benc static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
283f0706e82SJiri Benc 					     struct sta_info *sta)
284f0706e82SJiri Benc {
285f0706e82SJiri Benc 	unsigned long flags;
286f0706e82SJiri Benc 	struct sk_buff *skb;
2870795af57SJoe Perches 	DECLARE_MAC_BUF(mac);
288f0706e82SJiri Benc 
289f0706e82SJiri Benc 	if (skb_queue_empty(&sta->ps_tx_buf))
290f0706e82SJiri Benc 		return;
291f0706e82SJiri Benc 
292f0706e82SJiri Benc 	for (;;) {
293f0706e82SJiri Benc 		spin_lock_irqsave(&sta->ps_tx_buf.lock, flags);
294f0706e82SJiri Benc 		skb = skb_peek(&sta->ps_tx_buf);
295f0706e82SJiri Benc 		if (sta_info_buffer_expired(local, sta, skb)) {
296f0706e82SJiri Benc 			skb = __skb_dequeue(&sta->ps_tx_buf);
297f0706e82SJiri Benc 			if (skb_queue_empty(&sta->ps_tx_buf))
298f0706e82SJiri Benc 				sta->flags &= ~WLAN_STA_TIM;
299f0706e82SJiri Benc 		} else
300f0706e82SJiri Benc 			skb = NULL;
301f0706e82SJiri Benc 		spin_unlock_irqrestore(&sta->ps_tx_buf.lock, flags);
302f0706e82SJiri Benc 
303f0706e82SJiri Benc 		if (skb) {
304f0706e82SJiri Benc 			local->total_ps_buffered--;
305f0706e82SJiri Benc 			printk(KERN_DEBUG "Buffered frame expired (STA "
3060795af57SJoe Perches 			       "%s)\n", print_mac(mac, sta->addr));
307f0706e82SJiri Benc 			dev_kfree_skb(skb);
308f0706e82SJiri Benc 		} else
309f0706e82SJiri Benc 			break;
310f0706e82SJiri Benc 	}
311f0706e82SJiri Benc }
312f0706e82SJiri Benc 
313f0706e82SJiri Benc 
314f0706e82SJiri Benc static void sta_info_cleanup(unsigned long data)
315f0706e82SJiri Benc {
316f0706e82SJiri Benc 	struct ieee80211_local *local = (struct ieee80211_local *) data;
317f0706e82SJiri Benc 	struct sta_info *sta;
318f0706e82SJiri Benc 
319be8755e1SMichael Wu 	read_lock_bh(&local->sta_lock);
320f0706e82SJiri Benc 	list_for_each_entry(sta, &local->sta_list, list) {
321f0706e82SJiri Benc 		__sta_info_get(sta);
322f0706e82SJiri Benc 		sta_info_cleanup_expire_buffered(local, sta);
323f0706e82SJiri Benc 		sta_info_put(sta);
324f0706e82SJiri Benc 	}
325be8755e1SMichael Wu 	read_unlock_bh(&local->sta_lock);
326f0706e82SJiri Benc 
3270d174406SJohannes Berg 	local->sta_cleanup.expires =
3280d174406SJohannes Berg 		round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL);
329f0706e82SJiri Benc 	add_timer(&local->sta_cleanup);
330f0706e82SJiri Benc }
331f0706e82SJiri Benc 
332e9f207f0SJiri Benc #ifdef CONFIG_MAC80211_DEBUGFS
333e9f207f0SJiri Benc static void sta_info_debugfs_add_task(struct work_struct *work)
334e9f207f0SJiri Benc {
335e9f207f0SJiri Benc 	struct ieee80211_local *local =
336e9f207f0SJiri Benc 		container_of(work, struct ieee80211_local, sta_debugfs_add);
337e9f207f0SJiri Benc 	struct sta_info *sta, *tmp;
338e9f207f0SJiri Benc 
339e9f207f0SJiri Benc 	while (1) {
340e9f207f0SJiri Benc 		sta = NULL;
341be8755e1SMichael Wu 		read_lock_bh(&local->sta_lock);
342e9f207f0SJiri Benc 		list_for_each_entry(tmp, &local->sta_list, list) {
343be8755e1SMichael Wu 			if (!tmp->debugfs.dir) {
344e9f207f0SJiri Benc 				sta = tmp;
345e9f207f0SJiri Benc 				__sta_info_get(sta);
346e9f207f0SJiri Benc 				break;
347e9f207f0SJiri Benc 			}
348e9f207f0SJiri Benc 		}
349be8755e1SMichael Wu 		read_unlock_bh(&local->sta_lock);
350e9f207f0SJiri Benc 
351e9f207f0SJiri Benc 		if (!sta)
352e9f207f0SJiri Benc 			break;
353e9f207f0SJiri Benc 
354e9f207f0SJiri Benc 		ieee80211_sta_debugfs_add(sta);
355e9f207f0SJiri Benc 		rate_control_add_sta_debugfs(sta);
356e9f207f0SJiri Benc 		sta_info_put(sta);
357e9f207f0SJiri Benc 	}
358e9f207f0SJiri Benc }
359e9f207f0SJiri Benc #endif
360e9f207f0SJiri Benc 
361f0706e82SJiri Benc void sta_info_init(struct ieee80211_local *local)
362f0706e82SJiri Benc {
363be8755e1SMichael Wu 	rwlock_init(&local->sta_lock);
364f0706e82SJiri Benc 	INIT_LIST_HEAD(&local->sta_list);
365f0706e82SJiri Benc 
366b24b8a24SPavel Emelyanov 	setup_timer(&local->sta_cleanup, sta_info_cleanup,
367b24b8a24SPavel Emelyanov 		    (unsigned long)local);
3680d174406SJohannes Berg 	local->sta_cleanup.expires =
3690d174406SJohannes Berg 		round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL);
370e9f207f0SJiri Benc 
371e9f207f0SJiri Benc #ifdef CONFIG_MAC80211_DEBUGFS
372e9f207f0SJiri Benc 	INIT_WORK(&local->sta_debugfs_add, sta_info_debugfs_add_task);
373e9f207f0SJiri Benc #endif
374f0706e82SJiri Benc }
375f0706e82SJiri Benc 
376f0706e82SJiri Benc int sta_info_start(struct ieee80211_local *local)
377f0706e82SJiri Benc {
378f0706e82SJiri Benc 	add_timer(&local->sta_cleanup);
379f0706e82SJiri Benc 	return 0;
380f0706e82SJiri Benc }
381f0706e82SJiri Benc 
382f0706e82SJiri Benc void sta_info_stop(struct ieee80211_local *local)
383f0706e82SJiri Benc {
384f0706e82SJiri Benc 	del_timer(&local->sta_cleanup);
385be8755e1SMichael Wu 	sta_info_flush(local, NULL);
386f0706e82SJiri Benc }
387f0706e82SJiri Benc 
388f0706e82SJiri Benc void sta_info_remove_aid_ptr(struct sta_info *sta)
389f0706e82SJiri Benc {
390f0706e82SJiri Benc 	struct ieee80211_sub_if_data *sdata;
391f0706e82SJiri Benc 
392f0706e82SJiri Benc 	if (sta->aid <= 0)
393f0706e82SJiri Benc 		return;
394f0706e82SJiri Benc 
395f0706e82SJiri Benc 	sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
396f0706e82SJiri Benc 
397f0706e82SJiri Benc 	if (sdata->local->ops->set_tim)
398f0706e82SJiri Benc 		sdata->local->ops->set_tim(local_to_hw(sdata->local),
399f0706e82SJiri Benc 					  sta->aid, 0);
400f0706e82SJiri Benc 	if (sdata->bss)
401f0706e82SJiri Benc 		__bss_tim_clear(sdata->bss, sta->aid);
402f0706e82SJiri Benc }
403f0706e82SJiri Benc 
404f0706e82SJiri Benc 
405f0706e82SJiri Benc /**
406f0706e82SJiri Benc  * sta_info_flush - flush matching STA entries from the STA table
407f0706e82SJiri Benc  * @local: local interface data
408f0706e82SJiri Benc  * @dev: matching rule for the net device (sta->dev) or %NULL to match all STAs
409f0706e82SJiri Benc  */
410f0706e82SJiri Benc void sta_info_flush(struct ieee80211_local *local, struct net_device *dev)
411f0706e82SJiri Benc {
412f0706e82SJiri Benc 	struct sta_info *sta, *tmp;
413be8755e1SMichael Wu 	LIST_HEAD(tmp_list);
414f0706e82SJiri Benc 
415be8755e1SMichael Wu 	write_lock_bh(&local->sta_lock);
416f0706e82SJiri Benc 	list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
417be8755e1SMichael Wu 		if (!dev || dev == sta->dev) {
418be8755e1SMichael Wu 			__sta_info_get(sta);
419be8755e1SMichael Wu 			sta_info_remove(sta);
420be8755e1SMichael Wu 			list_add_tail(&sta->list, &tmp_list);
421be8755e1SMichael Wu 		}
422be8755e1SMichael Wu 	write_unlock_bh(&local->sta_lock);
423be8755e1SMichael Wu 
424be8755e1SMichael Wu 	list_for_each_entry_safe(sta, tmp, &tmp_list, list) {
425be8755e1SMichael Wu 		sta_info_free(sta);
426be8755e1SMichael Wu 		sta_info_put(sta);
427be8755e1SMichael Wu 	}
428f0706e82SJiri Benc }
429