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 | |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame^] | 58 | /* must hold local->sta_lock */ |
| 59 | static struct sta_info *__sta_info_find(struct ieee80211_local *local, |
| 60 | u8 *addr) |
| 61 | { |
| 62 | struct sta_info *sta; |
| 63 | |
| 64 | sta = local->sta_hash[STA_HASH(addr)]; |
| 65 | while (sta) { |
| 66 | if (compare_ether_addr(sta->addr, addr) == 0) |
| 67 | break; |
| 68 | sta = sta->hnext; |
| 69 | } |
| 70 | return sta; |
| 71 | } |
| 72 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 73 | struct sta_info *sta_info_get(struct ieee80211_local *local, u8 *addr) |
| 74 | { |
| 75 | struct sta_info *sta; |
| 76 | |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 77 | read_lock_bh(&local->sta_lock); |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame^] | 78 | sta = __sta_info_find(local, addr); |
| 79 | if (sta) |
| 80 | __sta_info_get(sta); |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 81 | read_unlock_bh(&local->sta_lock); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 82 | |
| 83 | return sta; |
| 84 | } |
| 85 | EXPORT_SYMBOL(sta_info_get); |
| 86 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 87 | |
| 88 | static void sta_info_release(struct kref *kref) |
| 89 | { |
| 90 | struct sta_info *sta = container_of(kref, struct sta_info, kref); |
| 91 | struct ieee80211_local *local = sta->local; |
| 92 | struct sk_buff *skb; |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 93 | int i; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 94 | |
| 95 | /* free sta structure; it has already been removed from |
| 96 | * hash table etc. external structures. Make sure that all |
| 97 | * buffered frames are release (one might have been added |
| 98 | * after sta_info_free() was called). */ |
| 99 | while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) { |
| 100 | local->total_ps_buffered--; |
| 101 | dev_kfree_skb_any(skb); |
| 102 | } |
| 103 | while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) { |
| 104 | dev_kfree_skb_any(skb); |
| 105 | } |
Ron Rindjunsky | fe3bf0f | 2008-01-28 14:07:19 +0200 | [diff] [blame] | 106 | for (i = 0; i < STA_TID_NUM; i++) { |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 107 | del_timer_sync(&sta->ampdu_mlme.tid_rx[i].session_timer); |
Ron Rindjunsky | fe3bf0f | 2008-01-28 14:07:19 +0200 | [diff] [blame] | 108 | del_timer_sync(&sta->ampdu_mlme.tid_tx[i].addba_resp_timer); |
| 109 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 110 | rate_control_free_sta(sta->rate_ctrl, sta->rate_ctrl_priv); |
| 111 | rate_control_put(sta->rate_ctrl); |
| 112 | kfree(sta); |
| 113 | } |
| 114 | |
| 115 | |
| 116 | void sta_info_put(struct sta_info *sta) |
| 117 | { |
| 118 | kref_put(&sta->kref, sta_info_release); |
| 119 | } |
| 120 | EXPORT_SYMBOL(sta_info_put); |
| 121 | |
| 122 | |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame^] | 123 | struct sta_info *sta_info_add(struct ieee80211_local *local, |
| 124 | struct net_device *dev, u8 *addr, gfp_t gfp) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 125 | { |
| 126 | struct sta_info *sta; |
Ron Rindjunsky | 16c5f15 | 2007-12-25 17:00:34 +0200 | [diff] [blame] | 127 | int i; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 128 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 129 | |
| 130 | sta = kzalloc(sizeof(*sta), gfp); |
| 131 | if (!sta) |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame^] | 132 | return ERR_PTR(-ENOMEM); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 133 | |
| 134 | kref_init(&sta->kref); |
| 135 | |
| 136 | sta->rate_ctrl = rate_control_get(local->rate_ctrl); |
| 137 | sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl, gfp); |
| 138 | if (!sta->rate_ctrl_priv) { |
| 139 | rate_control_put(sta->rate_ctrl); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 140 | kfree(sta); |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame^] | 141 | return ERR_PTR(-ENOMEM); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | memcpy(sta->addr, addr, ETH_ALEN); |
| 145 | sta->local = local; |
| 146 | sta->dev = dev; |
Ron Rindjunsky | 16c5f15 | 2007-12-25 17:00:34 +0200 | [diff] [blame] | 147 | spin_lock_init(&sta->ampdu_mlme.ampdu_rx); |
Ron Rindjunsky | fe3bf0f | 2008-01-28 14:07:19 +0200 | [diff] [blame] | 148 | spin_lock_init(&sta->ampdu_mlme.ampdu_tx); |
Ron Rindjunsky | 16c5f15 | 2007-12-25 17:00:34 +0200 | [diff] [blame] | 149 | for (i = 0; i < STA_TID_NUM; i++) { |
| 150 | /* timer_to_tid must be initialized with identity mapping to |
| 151 | * enable session_timer's data differentiation. refer to |
| 152 | * sta_rx_agg_session_timer_expired for useage */ |
| 153 | sta->timer_to_tid[i] = i; |
Ron Rindjunsky | fe3bf0f | 2008-01-28 14:07:19 +0200 | [diff] [blame] | 154 | /* tid to tx queue: initialize according to HW (0 is valid) */ |
| 155 | sta->tid_to_tx_q[i] = local->hw.queues; |
Ron Rindjunsky | 16c5f15 | 2007-12-25 17:00:34 +0200 | [diff] [blame] | 156 | /* rx timers */ |
| 157 | sta->ampdu_mlme.tid_rx[i].session_timer.function = |
| 158 | sta_rx_agg_session_timer_expired; |
| 159 | sta->ampdu_mlme.tid_rx[i].session_timer.data = |
| 160 | (unsigned long)&sta->timer_to_tid[i]; |
| 161 | init_timer(&sta->ampdu_mlme.tid_rx[i].session_timer); |
Ron Rindjunsky | fe3bf0f | 2008-01-28 14:07:19 +0200 | [diff] [blame] | 162 | /* tx timers */ |
| 163 | sta->ampdu_mlme.tid_tx[i].addba_resp_timer.function = |
| 164 | sta_addba_resp_timer_expired; |
| 165 | sta->ampdu_mlme.tid_tx[i].addba_resp_timer.data = |
| 166 | (unsigned long)&sta->timer_to_tid[i]; |
| 167 | init_timer(&sta->ampdu_mlme.tid_tx[i].addba_resp_timer); |
Ron Rindjunsky | 16c5f15 | 2007-12-25 17:00:34 +0200 | [diff] [blame] | 168 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 169 | skb_queue_head_init(&sta->ps_tx_buf); |
| 170 | skb_queue_head_init(&sta->tx_filtered); |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 171 | write_lock_bh(&local->sta_lock); |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame^] | 172 | /* mark sta as used (by caller) */ |
| 173 | __sta_info_get(sta); |
| 174 | /* check if STA exists already */ |
| 175 | if (__sta_info_find(local, addr)) { |
| 176 | write_unlock_bh(&local->sta_lock); |
| 177 | sta_info_put(sta); |
| 178 | return ERR_PTR(-EEXIST); |
| 179 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 180 | list_add(&sta->list, &local->sta_list); |
| 181 | local->num_sta++; |
| 182 | sta_info_hash_add(local, sta); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 183 | if (local->ops->sta_notify) { |
| 184 | struct ieee80211_sub_if_data *sdata; |
| 185 | |
| 186 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 187 | if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN) |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 188 | sdata = sdata->u.vlan.ap; |
| 189 | |
| 190 | local->ops->sta_notify(local_to_hw(local), &sdata->vif, |
| 191 | STA_NOTIFY_ADD, addr); |
| 192 | } |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 193 | write_unlock_bh(&local->sta_lock); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 194 | |
| 195 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 196 | printk(KERN_DEBUG "%s: Added STA %s\n", |
Johannes Berg | dd1cd4c | 2007-09-18 17:29:20 -0400 | [diff] [blame] | 197 | wiphy_name(local->hw.wiphy), print_mac(mac, addr)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 198 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 199 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 200 | #ifdef CONFIG_MAC80211_DEBUGFS |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 201 | /* debugfs entry adding might sleep, so schedule process |
| 202 | * context task for adding entry for STAs that do not yet |
| 203 | * have one. */ |
| 204 | queue_work(local->hw.workqueue, &local->sta_debugfs_add); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 205 | #endif |
| 206 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 207 | return sta; |
| 208 | } |
| 209 | |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 210 | static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid) |
| 211 | { |
| 212 | /* |
| 213 | * This format has been mandated by the IEEE specifications, |
| 214 | * so this line may not be changed to use the __set_bit() format. |
| 215 | */ |
| 216 | bss->tim[aid / 8] |= (1 << (aid % 8)); |
| 217 | } |
| 218 | |
| 219 | static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, u16 aid) |
| 220 | { |
| 221 | /* |
| 222 | * This format has been mandated by the IEEE specifications, |
| 223 | * so this line may not be changed to use the __clear_bit() format. |
| 224 | */ |
| 225 | bss->tim[aid / 8] &= ~(1 << (aid % 8)); |
| 226 | } |
| 227 | |
| 228 | static void __sta_info_set_tim_bit(struct ieee80211_if_ap *bss, |
| 229 | struct sta_info *sta) |
| 230 | { |
| 231 | if (bss) |
| 232 | __bss_tim_set(bss, sta->aid); |
| 233 | if (sta->local->ops->set_tim) |
| 234 | sta->local->ops->set_tim(local_to_hw(sta->local), sta->aid, 1); |
| 235 | } |
| 236 | |
| 237 | void sta_info_set_tim_bit(struct sta_info *sta) |
| 238 | { |
| 239 | struct ieee80211_sub_if_data *sdata; |
| 240 | |
| 241 | sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev); |
| 242 | |
| 243 | read_lock_bh(&sta->local->sta_lock); |
| 244 | __sta_info_set_tim_bit(sdata->bss, sta); |
| 245 | read_unlock_bh(&sta->local->sta_lock); |
| 246 | } |
| 247 | |
| 248 | static void __sta_info_clear_tim_bit(struct ieee80211_if_ap *bss, |
| 249 | struct sta_info *sta) |
| 250 | { |
| 251 | if (bss) |
| 252 | __bss_tim_clear(bss, sta->aid); |
| 253 | if (sta->local->ops->set_tim) |
| 254 | sta->local->ops->set_tim(local_to_hw(sta->local), sta->aid, 0); |
| 255 | } |
| 256 | |
| 257 | void sta_info_clear_tim_bit(struct sta_info *sta) |
| 258 | { |
| 259 | struct ieee80211_sub_if_data *sdata; |
| 260 | |
| 261 | sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev); |
| 262 | |
| 263 | read_lock_bh(&sta->local->sta_lock); |
| 264 | __sta_info_clear_tim_bit(sdata->bss, sta); |
| 265 | read_unlock_bh(&sta->local->sta_lock); |
| 266 | } |
| 267 | |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 268 | /* Caller must hold local->sta_lock */ |
| 269 | void sta_info_remove(struct sta_info *sta) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 270 | { |
| 271 | struct ieee80211_local *local = sta->local; |
| 272 | struct ieee80211_sub_if_data *sdata; |
| 273 | |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 274 | /* don't do anything if we've been removed already */ |
| 275 | if (sta_info_hash_del(local, sta)) |
| 276 | return; |
| 277 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 278 | list_del(&sta->list); |
| 279 | sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev); |
| 280 | if (sta->flags & WLAN_STA_PS) { |
| 281 | sta->flags &= ~WLAN_STA_PS; |
| 282 | if (sdata->bss) |
| 283 | atomic_dec(&sdata->bss->num_sta_ps); |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 284 | __sta_info_clear_tim_bit(sdata->bss, sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 285 | } |
| 286 | local->num_sta--; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 289 | void sta_info_free(struct sta_info *sta) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 290 | { |
| 291 | struct sk_buff *skb; |
| 292 | struct ieee80211_local *local = sta->local; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 293 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 294 | |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 295 | might_sleep(); |
| 296 | |
| 297 | write_lock_bh(&local->sta_lock); |
| 298 | sta_info_remove(sta); |
| 299 | write_unlock_bh(&local->sta_lock); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 300 | |
| 301 | while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) { |
| 302 | local->total_ps_buffered--; |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 303 | dev_kfree_skb(skb); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 304 | } |
| 305 | while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) { |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 306 | dev_kfree_skb(skb); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 309 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 310 | printk(KERN_DEBUG "%s: Removed STA %s\n", |
Johannes Berg | dd1cd4c | 2007-09-18 17:29:20 -0400 | [diff] [blame] | 311 | wiphy_name(local->hw.wiphy), print_mac(mac, sta->addr)); |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 312 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 313 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 314 | ieee80211_key_free(sta->key); |
| 315 | sta->key = NULL; |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 316 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 317 | if (local->ops->sta_notify) { |
| 318 | struct ieee80211_sub_if_data *sdata; |
| 319 | |
| 320 | sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev); |
| 321 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 322 | if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN) |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 323 | sdata = sdata->u.vlan.ap; |
| 324 | |
| 325 | local->ops->sta_notify(local_to_hw(local), &sdata->vif, |
| 326 | STA_NOTIFY_REMOVE, sta->addr); |
| 327 | } |
Tomas Winkler | 478f8d2 | 2007-09-30 13:52:37 +0200 | [diff] [blame] | 328 | |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 329 | rate_control_remove_sta_debugfs(sta); |
| 330 | ieee80211_sta_debugfs_remove(sta); |
| 331 | |
| 332 | sta_info_put(sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | |
| 336 | static inline int sta_info_buffer_expired(struct ieee80211_local *local, |
| 337 | struct sta_info *sta, |
| 338 | struct sk_buff *skb) |
| 339 | { |
| 340 | struct ieee80211_tx_packet_data *pkt_data; |
| 341 | int timeout; |
| 342 | |
| 343 | if (!skb) |
| 344 | return 0; |
| 345 | |
| 346 | pkt_data = (struct ieee80211_tx_packet_data *) skb->cb; |
| 347 | |
| 348 | /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */ |
| 349 | timeout = (sta->listen_interval * local->hw.conf.beacon_int * 32 / |
| 350 | 15625) * HZ; |
| 351 | if (timeout < STA_TX_BUFFER_EXPIRE) |
| 352 | timeout = STA_TX_BUFFER_EXPIRE; |
| 353 | return time_after(jiffies, pkt_data->jiffies + timeout); |
| 354 | } |
| 355 | |
| 356 | |
| 357 | static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local, |
| 358 | struct sta_info *sta) |
| 359 | { |
| 360 | unsigned long flags; |
| 361 | struct sk_buff *skb; |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 362 | struct ieee80211_sub_if_data *sdata; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 363 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 364 | |
| 365 | if (skb_queue_empty(&sta->ps_tx_buf)) |
| 366 | return; |
| 367 | |
| 368 | for (;;) { |
| 369 | spin_lock_irqsave(&sta->ps_tx_buf.lock, flags); |
| 370 | skb = skb_peek(&sta->ps_tx_buf); |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 371 | if (sta_info_buffer_expired(local, sta, skb)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 372 | skb = __skb_dequeue(&sta->ps_tx_buf); |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 373 | else |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 374 | skb = NULL; |
| 375 | spin_unlock_irqrestore(&sta->ps_tx_buf.lock, flags); |
| 376 | |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 377 | if (!skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 378 | break; |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 379 | |
| 380 | sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev); |
| 381 | local->total_ps_buffered--; |
| 382 | printk(KERN_DEBUG "Buffered frame expired (STA " |
| 383 | "%s)\n", print_mac(mac, sta->addr)); |
| 384 | dev_kfree_skb(skb); |
| 385 | |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 386 | if (skb_queue_empty(&sta->ps_tx_buf)) |
| 387 | sta_info_clear_tim_bit(sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 388 | } |
| 389 | } |
| 390 | |
| 391 | |
| 392 | static void sta_info_cleanup(unsigned long data) |
| 393 | { |
| 394 | struct ieee80211_local *local = (struct ieee80211_local *) data; |
| 395 | struct sta_info *sta; |
| 396 | |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 397 | read_lock_bh(&local->sta_lock); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 398 | list_for_each_entry(sta, &local->sta_list, list) { |
| 399 | __sta_info_get(sta); |
| 400 | sta_info_cleanup_expire_buffered(local, sta); |
| 401 | sta_info_put(sta); |
| 402 | } |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 403 | read_unlock_bh(&local->sta_lock); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 404 | |
Johannes Berg | 0d17440 | 2007-12-17 15:07:43 +0100 | [diff] [blame] | 405 | local->sta_cleanup.expires = |
| 406 | round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 407 | add_timer(&local->sta_cleanup); |
| 408 | } |
| 409 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 410 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 411 | static void sta_info_debugfs_add_task(struct work_struct *work) |
| 412 | { |
| 413 | struct ieee80211_local *local = |
| 414 | container_of(work, struct ieee80211_local, sta_debugfs_add); |
| 415 | struct sta_info *sta, *tmp; |
| 416 | |
| 417 | while (1) { |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 418 | sta = NULL; |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 419 | read_lock_bh(&local->sta_lock); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 420 | list_for_each_entry(tmp, &local->sta_list, list) { |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 421 | if (!tmp->debugfs.dir) { |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 422 | sta = tmp; |
| 423 | __sta_info_get(sta); |
| 424 | break; |
| 425 | } |
| 426 | } |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 427 | read_unlock_bh(&local->sta_lock); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 428 | |
| 429 | if (!sta) |
| 430 | break; |
| 431 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 432 | ieee80211_sta_debugfs_add(sta); |
| 433 | rate_control_add_sta_debugfs(sta); |
| 434 | sta_info_put(sta); |
| 435 | } |
| 436 | } |
| 437 | #endif |
| 438 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 439 | void sta_info_init(struct ieee80211_local *local) |
| 440 | { |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 441 | rwlock_init(&local->sta_lock); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 442 | INIT_LIST_HEAD(&local->sta_list); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 443 | |
Pavel Emelyanov | b24b8a2 | 2008-01-23 21:20:07 -0800 | [diff] [blame] | 444 | setup_timer(&local->sta_cleanup, sta_info_cleanup, |
| 445 | (unsigned long)local); |
Johannes Berg | 0d17440 | 2007-12-17 15:07:43 +0100 | [diff] [blame] | 446 | local->sta_cleanup.expires = |
| 447 | round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 448 | |
| 449 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 450 | INIT_WORK(&local->sta_debugfs_add, sta_info_debugfs_add_task); |
| 451 | #endif |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | int sta_info_start(struct ieee80211_local *local) |
| 455 | { |
| 456 | add_timer(&local->sta_cleanup); |
| 457 | return 0; |
| 458 | } |
| 459 | |
| 460 | void sta_info_stop(struct ieee80211_local *local) |
| 461 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 462 | del_timer(&local->sta_cleanup); |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 463 | sta_info_flush(local, NULL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 466 | /** |
| 467 | * sta_info_flush - flush matching STA entries from the STA table |
| 468 | * @local: local interface data |
| 469 | * @dev: matching rule for the net device (sta->dev) or %NULL to match all STAs |
| 470 | */ |
| 471 | void sta_info_flush(struct ieee80211_local *local, struct net_device *dev) |
| 472 | { |
| 473 | struct sta_info *sta, *tmp; |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 474 | LIST_HEAD(tmp_list); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 475 | |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 476 | write_lock_bh(&local->sta_lock); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 477 | list_for_each_entry_safe(sta, tmp, &local->sta_list, list) |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 478 | if (!dev || dev == sta->dev) { |
| 479 | __sta_info_get(sta); |
| 480 | sta_info_remove(sta); |
| 481 | list_add_tail(&sta->list, &tmp_list); |
| 482 | } |
| 483 | write_unlock_bh(&local->sta_lock); |
| 484 | |
| 485 | list_for_each_entry_safe(sta, tmp, &tmp_list, list) { |
| 486 | sta_info_free(sta); |
| 487 | sta_info_put(sta); |
| 488 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 489 | } |