xref: /openbmc/linux/net/mac80211/sta_info.c (revision 0d17440688ad83de46e94e9fa11edb5a7fb3d180)
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>
17*0d174406SJohannes 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;
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);
121f0706e82SJiri Benc 	kfree(sta);
122f0706e82SJiri Benc }
123f0706e82SJiri Benc 
124f0706e82SJiri Benc 
125f0706e82SJiri Benc void sta_info_put(struct sta_info *sta)
126f0706e82SJiri Benc {
127f0706e82SJiri Benc 	kref_put(&sta->kref, sta_info_release);
128f0706e82SJiri Benc }
129f0706e82SJiri Benc EXPORT_SYMBOL(sta_info_put);
130f0706e82SJiri Benc 
131f0706e82SJiri Benc 
132f0706e82SJiri Benc struct sta_info * sta_info_add(struct ieee80211_local *local,
133f0706e82SJiri Benc 			       struct net_device *dev, u8 *addr, gfp_t gfp)
134f0706e82SJiri Benc {
135f0706e82SJiri Benc 	struct sta_info *sta;
1360795af57SJoe Perches 	DECLARE_MAC_BUF(mac);
137f0706e82SJiri Benc 
138f0706e82SJiri Benc 	sta = kzalloc(sizeof(*sta), gfp);
139f0706e82SJiri Benc 	if (!sta)
140f0706e82SJiri Benc 		return NULL;
141f0706e82SJiri Benc 
142f0706e82SJiri Benc 	kref_init(&sta->kref);
143f0706e82SJiri Benc 
144f0706e82SJiri Benc 	sta->rate_ctrl = rate_control_get(local->rate_ctrl);
145f0706e82SJiri Benc 	sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl, gfp);
146f0706e82SJiri Benc 	if (!sta->rate_ctrl_priv) {
147f0706e82SJiri Benc 		rate_control_put(sta->rate_ctrl);
148f0706e82SJiri Benc 		kfree(sta);
149f0706e82SJiri Benc 		return NULL;
150f0706e82SJiri Benc 	}
151f0706e82SJiri Benc 
152f0706e82SJiri Benc 	memcpy(sta->addr, addr, ETH_ALEN);
153f0706e82SJiri Benc 	sta->local = local;
154f0706e82SJiri Benc 	sta->dev = dev;
155f0706e82SJiri Benc 	skb_queue_head_init(&sta->ps_tx_buf);
156f0706e82SJiri Benc 	skb_queue_head_init(&sta->tx_filtered);
157f0706e82SJiri Benc 	__sta_info_get(sta);	/* sta used by caller, decremented by
158f0706e82SJiri Benc 				 * sta_info_put() */
159be8755e1SMichael Wu 	write_lock_bh(&local->sta_lock);
160f0706e82SJiri Benc 	list_add(&sta->list, &local->sta_list);
161f0706e82SJiri Benc 	local->num_sta++;
162f0706e82SJiri Benc 	sta_info_hash_add(local, sta);
163478f8d2bSTomas Winkler 	if (local->ops->sta_notify)
164478f8d2bSTomas Winkler 		local->ops->sta_notify(local_to_hw(local), dev->ifindex,
165478f8d2bSTomas Winkler 					STA_NOTIFY_ADD, addr);
166be8755e1SMichael Wu 	write_unlock_bh(&local->sta_lock);
167f0706e82SJiri Benc 
168f0706e82SJiri Benc #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1690795af57SJoe Perches 	printk(KERN_DEBUG "%s: Added STA %s\n",
170dd1cd4c6SJohannes Berg 	       wiphy_name(local->hw.wiphy), print_mac(mac, addr));
171f0706e82SJiri Benc #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
172f0706e82SJiri Benc 
173e9f207f0SJiri Benc #ifdef CONFIG_MAC80211_DEBUGFS
174e9f207f0SJiri Benc 	/* debugfs entry adding might sleep, so schedule process
175e9f207f0SJiri Benc 	 * context task for adding entry for STAs that do not yet
176e9f207f0SJiri Benc 	 * have one. */
177e9f207f0SJiri Benc 	queue_work(local->hw.workqueue, &local->sta_debugfs_add);
178e9f207f0SJiri Benc #endif
179e9f207f0SJiri Benc 
180f0706e82SJiri Benc 	return sta;
181f0706e82SJiri Benc }
182f0706e82SJiri Benc 
183be8755e1SMichael Wu /* Caller must hold local->sta_lock */
184be8755e1SMichael Wu void sta_info_remove(struct sta_info *sta)
185f0706e82SJiri Benc {
186f0706e82SJiri Benc 	struct ieee80211_local *local = sta->local;
187f0706e82SJiri Benc 	struct ieee80211_sub_if_data *sdata;
188f0706e82SJiri Benc 
189be8755e1SMichael Wu 	/* don't do anything if we've been removed already */
190be8755e1SMichael Wu 	if (sta_info_hash_del(local, sta))
191be8755e1SMichael Wu 		return;
192be8755e1SMichael Wu 
193f0706e82SJiri Benc 	list_del(&sta->list);
194f0706e82SJiri Benc 	sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
195f0706e82SJiri Benc 	if (sta->flags & WLAN_STA_PS) {
196f0706e82SJiri Benc 		sta->flags &= ~WLAN_STA_PS;
197f0706e82SJiri Benc 		if (sdata->bss)
198f0706e82SJiri Benc 			atomic_dec(&sdata->bss->num_sta_ps);
199f0706e82SJiri Benc 	}
200f0706e82SJiri Benc 	local->num_sta--;
201f0706e82SJiri Benc 	sta_info_remove_aid_ptr(sta);
202be8755e1SMichael Wu 
203f0706e82SJiri Benc }
204f0706e82SJiri Benc 
205be8755e1SMichael Wu void sta_info_free(struct sta_info *sta)
206f0706e82SJiri Benc {
207f0706e82SJiri Benc 	struct sk_buff *skb;
208f0706e82SJiri Benc 	struct ieee80211_local *local = sta->local;
2090795af57SJoe Perches 	DECLARE_MAC_BUF(mac);
210f0706e82SJiri Benc 
211be8755e1SMichael Wu 	might_sleep();
212be8755e1SMichael Wu 
213be8755e1SMichael Wu 	write_lock_bh(&local->sta_lock);
214f0706e82SJiri Benc 	sta_info_remove(sta);
215be8755e1SMichael Wu 	write_unlock_bh(&local->sta_lock);
216f0706e82SJiri Benc 
217f0706e82SJiri Benc 	while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
218f0706e82SJiri Benc 		local->total_ps_buffered--;
219be8755e1SMichael Wu 		dev_kfree_skb(skb);
220f0706e82SJiri Benc 	}
221f0706e82SJiri Benc 	while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
222be8755e1SMichael Wu 		dev_kfree_skb(skb);
223f0706e82SJiri Benc 	}
224f0706e82SJiri Benc 
225be8755e1SMichael Wu #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2260795af57SJoe Perches 	printk(KERN_DEBUG "%s: Removed STA %s\n",
227dd1cd4c6SJohannes Berg 	       wiphy_name(local->hw.wiphy), print_mac(mac, sta->addr));
228be8755e1SMichael Wu #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
229be8755e1SMichael Wu 
230be8755e1SMichael Wu 	ieee80211_key_free(sta->key);
231be8755e1SMichael Wu 	sta->key = NULL;
232be8755e1SMichael Wu 
233478f8d2bSTomas Winkler 	if (local->ops->sta_notify)
234478f8d2bSTomas Winkler 		local->ops->sta_notify(local_to_hw(local), sta->dev->ifindex,
235478f8d2bSTomas Winkler 					STA_NOTIFY_REMOVE, sta->addr);
236478f8d2bSTomas Winkler 
237be8755e1SMichael Wu 	rate_control_remove_sta_debugfs(sta);
238be8755e1SMichael Wu 	ieee80211_sta_debugfs_remove(sta);
239be8755e1SMichael Wu 
240be8755e1SMichael Wu 	sta_info_put(sta);
241f0706e82SJiri Benc }
242f0706e82SJiri Benc 
243f0706e82SJiri Benc 
244f0706e82SJiri Benc static inline int sta_info_buffer_expired(struct ieee80211_local *local,
245f0706e82SJiri Benc 					  struct sta_info *sta,
246f0706e82SJiri Benc 					  struct sk_buff *skb)
247f0706e82SJiri Benc {
248f0706e82SJiri Benc 	struct ieee80211_tx_packet_data *pkt_data;
249f0706e82SJiri Benc 	int timeout;
250f0706e82SJiri Benc 
251f0706e82SJiri Benc 	if (!skb)
252f0706e82SJiri Benc 		return 0;
253f0706e82SJiri Benc 
254f0706e82SJiri Benc 	pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
255f0706e82SJiri Benc 
256f0706e82SJiri Benc 	/* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */
257f0706e82SJiri Benc 	timeout = (sta->listen_interval * local->hw.conf.beacon_int * 32 /
258f0706e82SJiri Benc 		   15625) * HZ;
259f0706e82SJiri Benc 	if (timeout < STA_TX_BUFFER_EXPIRE)
260f0706e82SJiri Benc 		timeout = STA_TX_BUFFER_EXPIRE;
261f0706e82SJiri Benc 	return time_after(jiffies, pkt_data->jiffies + timeout);
262f0706e82SJiri Benc }
263f0706e82SJiri Benc 
264f0706e82SJiri Benc 
265f0706e82SJiri Benc static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
266f0706e82SJiri Benc 					     struct sta_info *sta)
267f0706e82SJiri Benc {
268f0706e82SJiri Benc 	unsigned long flags;
269f0706e82SJiri Benc 	struct sk_buff *skb;
2700795af57SJoe Perches 	DECLARE_MAC_BUF(mac);
271f0706e82SJiri Benc 
272f0706e82SJiri Benc 	if (skb_queue_empty(&sta->ps_tx_buf))
273f0706e82SJiri Benc 		return;
274f0706e82SJiri Benc 
275f0706e82SJiri Benc 	for (;;) {
276f0706e82SJiri Benc 		spin_lock_irqsave(&sta->ps_tx_buf.lock, flags);
277f0706e82SJiri Benc 		skb = skb_peek(&sta->ps_tx_buf);
278f0706e82SJiri Benc 		if (sta_info_buffer_expired(local, sta, skb)) {
279f0706e82SJiri Benc 			skb = __skb_dequeue(&sta->ps_tx_buf);
280f0706e82SJiri Benc 			if (skb_queue_empty(&sta->ps_tx_buf))
281f0706e82SJiri Benc 				sta->flags &= ~WLAN_STA_TIM;
282f0706e82SJiri Benc 		} else
283f0706e82SJiri Benc 			skb = NULL;
284f0706e82SJiri Benc 		spin_unlock_irqrestore(&sta->ps_tx_buf.lock, flags);
285f0706e82SJiri Benc 
286f0706e82SJiri Benc 		if (skb) {
287f0706e82SJiri Benc 			local->total_ps_buffered--;
288f0706e82SJiri Benc 			printk(KERN_DEBUG "Buffered frame expired (STA "
2890795af57SJoe Perches 			       "%s)\n", print_mac(mac, sta->addr));
290f0706e82SJiri Benc 			dev_kfree_skb(skb);
291f0706e82SJiri Benc 		} else
292f0706e82SJiri Benc 			break;
293f0706e82SJiri Benc 	}
294f0706e82SJiri Benc }
295f0706e82SJiri Benc 
296f0706e82SJiri Benc 
297f0706e82SJiri Benc static void sta_info_cleanup(unsigned long data)
298f0706e82SJiri Benc {
299f0706e82SJiri Benc 	struct ieee80211_local *local = (struct ieee80211_local *) data;
300f0706e82SJiri Benc 	struct sta_info *sta;
301f0706e82SJiri Benc 
302be8755e1SMichael Wu 	read_lock_bh(&local->sta_lock);
303f0706e82SJiri Benc 	list_for_each_entry(sta, &local->sta_list, list) {
304f0706e82SJiri Benc 		__sta_info_get(sta);
305f0706e82SJiri Benc 		sta_info_cleanup_expire_buffered(local, sta);
306f0706e82SJiri Benc 		sta_info_put(sta);
307f0706e82SJiri Benc 	}
308be8755e1SMichael Wu 	read_unlock_bh(&local->sta_lock);
309f0706e82SJiri Benc 
310*0d174406SJohannes Berg 	local->sta_cleanup.expires =
311*0d174406SJohannes Berg 		round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL);
312f0706e82SJiri Benc 	add_timer(&local->sta_cleanup);
313f0706e82SJiri Benc }
314f0706e82SJiri Benc 
315e9f207f0SJiri Benc #ifdef CONFIG_MAC80211_DEBUGFS
316e9f207f0SJiri Benc static void sta_info_debugfs_add_task(struct work_struct *work)
317e9f207f0SJiri Benc {
318e9f207f0SJiri Benc 	struct ieee80211_local *local =
319e9f207f0SJiri Benc 		container_of(work, struct ieee80211_local, sta_debugfs_add);
320e9f207f0SJiri Benc 	struct sta_info *sta, *tmp;
321e9f207f0SJiri Benc 
322e9f207f0SJiri Benc 	while (1) {
323e9f207f0SJiri Benc 		sta = NULL;
324be8755e1SMichael Wu 		read_lock_bh(&local->sta_lock);
325e9f207f0SJiri Benc 		list_for_each_entry(tmp, &local->sta_list, list) {
326be8755e1SMichael Wu 			if (!tmp->debugfs.dir) {
327e9f207f0SJiri Benc 				sta = tmp;
328e9f207f0SJiri Benc 				__sta_info_get(sta);
329e9f207f0SJiri Benc 				break;
330e9f207f0SJiri Benc 			}
331e9f207f0SJiri Benc 		}
332be8755e1SMichael Wu 		read_unlock_bh(&local->sta_lock);
333e9f207f0SJiri Benc 
334e9f207f0SJiri Benc 		if (!sta)
335e9f207f0SJiri Benc 			break;
336e9f207f0SJiri Benc 
337e9f207f0SJiri Benc 		ieee80211_sta_debugfs_add(sta);
338e9f207f0SJiri Benc 		rate_control_add_sta_debugfs(sta);
339e9f207f0SJiri Benc 		sta_info_put(sta);
340e9f207f0SJiri Benc 	}
341e9f207f0SJiri Benc }
342e9f207f0SJiri Benc #endif
343e9f207f0SJiri Benc 
344f0706e82SJiri Benc void sta_info_init(struct ieee80211_local *local)
345f0706e82SJiri Benc {
346be8755e1SMichael Wu 	rwlock_init(&local->sta_lock);
347f0706e82SJiri Benc 	INIT_LIST_HEAD(&local->sta_list);
348f0706e82SJiri Benc 
349f0706e82SJiri Benc 	init_timer(&local->sta_cleanup);
350*0d174406SJohannes Berg 	local->sta_cleanup.expires =
351*0d174406SJohannes Berg 		round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL);
352f0706e82SJiri Benc 	local->sta_cleanup.data = (unsigned long) local;
353f0706e82SJiri Benc 	local->sta_cleanup.function = sta_info_cleanup;
354e9f207f0SJiri Benc 
355e9f207f0SJiri Benc #ifdef CONFIG_MAC80211_DEBUGFS
356e9f207f0SJiri Benc 	INIT_WORK(&local->sta_debugfs_add, sta_info_debugfs_add_task);
357e9f207f0SJiri Benc #endif
358f0706e82SJiri Benc }
359f0706e82SJiri Benc 
360f0706e82SJiri Benc int sta_info_start(struct ieee80211_local *local)
361f0706e82SJiri Benc {
362f0706e82SJiri Benc 	add_timer(&local->sta_cleanup);
363f0706e82SJiri Benc 	return 0;
364f0706e82SJiri Benc }
365f0706e82SJiri Benc 
366f0706e82SJiri Benc void sta_info_stop(struct ieee80211_local *local)
367f0706e82SJiri Benc {
368f0706e82SJiri Benc 	del_timer(&local->sta_cleanup);
369be8755e1SMichael Wu 	sta_info_flush(local, NULL);
370f0706e82SJiri Benc }
371f0706e82SJiri Benc 
372f0706e82SJiri Benc void sta_info_remove_aid_ptr(struct sta_info *sta)
373f0706e82SJiri Benc {
374f0706e82SJiri Benc 	struct ieee80211_sub_if_data *sdata;
375f0706e82SJiri Benc 
376f0706e82SJiri Benc 	if (sta->aid <= 0)
377f0706e82SJiri Benc 		return;
378f0706e82SJiri Benc 
379f0706e82SJiri Benc 	sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
380f0706e82SJiri Benc 
381f0706e82SJiri Benc 	if (sdata->local->ops->set_tim)
382f0706e82SJiri Benc 		sdata->local->ops->set_tim(local_to_hw(sdata->local),
383f0706e82SJiri Benc 					  sta->aid, 0);
384f0706e82SJiri Benc 	if (sdata->bss)
385f0706e82SJiri Benc 		__bss_tim_clear(sdata->bss, sta->aid);
386f0706e82SJiri Benc }
387f0706e82SJiri Benc 
388f0706e82SJiri Benc 
389f0706e82SJiri Benc /**
390f0706e82SJiri Benc  * sta_info_flush - flush matching STA entries from the STA table
391f0706e82SJiri Benc  * @local: local interface data
392f0706e82SJiri Benc  * @dev: matching rule for the net device (sta->dev) or %NULL to match all STAs
393f0706e82SJiri Benc  */
394f0706e82SJiri Benc void sta_info_flush(struct ieee80211_local *local, struct net_device *dev)
395f0706e82SJiri Benc {
396f0706e82SJiri Benc 	struct sta_info *sta, *tmp;
397be8755e1SMichael Wu 	LIST_HEAD(tmp_list);
398f0706e82SJiri Benc 
399be8755e1SMichael Wu 	write_lock_bh(&local->sta_lock);
400f0706e82SJiri Benc 	list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
401be8755e1SMichael Wu 		if (!dev || dev == sta->dev) {
402be8755e1SMichael Wu 			__sta_info_get(sta);
403be8755e1SMichael Wu 			sta_info_remove(sta);
404be8755e1SMichael Wu 			list_add_tail(&sta->list, &tmp_list);
405be8755e1SMichael Wu 		}
406be8755e1SMichael Wu 	write_unlock_bh(&local->sta_lock);
407be8755e1SMichael Wu 
408be8755e1SMichael Wu 	list_for_each_entry_safe(sta, tmp, &tmp_list, list) {
409be8755e1SMichael Wu 		sta_info_free(sta);
410be8755e1SMichael Wu 		sta_info_put(sta);
411be8755e1SMichael Wu 	}
412f0706e82SJiri Benc }
413