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