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