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