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