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> |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 18 | #include <linux/rtnetlink.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 19 | |
| 20 | #include <net/mac80211.h> |
| 21 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 22 | #include "driver-ops.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 23 | #include "rate.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 24 | #include "sta_info.h" |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 25 | #include "debugfs_sta.h" |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 26 | #include "mesh.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 27 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 28 | /** |
| 29 | * DOC: STA information lifetime rules |
| 30 | * |
| 31 | * STA info structures (&struct sta_info) are managed in a hash table |
| 32 | * for faster lookup and a list for iteration. They are managed using |
| 33 | * RCU, i.e. access to the list and hash table is protected by RCU. |
| 34 | * |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 35 | * Upon allocating a STA info structure with sta_info_alloc(), the caller |
| 36 | * owns that structure. It must then insert it into the hash table using |
| 37 | * either sta_info_insert() or sta_info_insert_rcu(); only in the latter |
| 38 | * case (which acquires an rcu read section but must not be called from |
| 39 | * within one) will the pointer still be valid after the call. Note that |
| 40 | * the caller may not do much with the STA info before inserting it, in |
| 41 | * particular, it may not start any mesh peer link management or add |
| 42 | * encryption keys. |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 43 | * |
| 44 | * When the insertion fails (sta_info_insert()) returns non-zero), the |
| 45 | * structure will have been freed by sta_info_insert()! |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 46 | * |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 47 | * Station entries are added by mac80211 when you establish a link with a |
Luis R. Rodriguez | 7e189a1 | 2009-06-02 18:38:14 -0400 | [diff] [blame] | 48 | * peer. This means different things for the different type of interfaces |
| 49 | * we support. For a regular station this mean we add the AP sta when we |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 50 | * receive an association response from the AP. For IBSS this occurs when |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 51 | * get to know about a peer on the same IBSS. For WDS we add the sta for |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 52 | * the peer immediately upon device open. When using AP mode we add stations |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 53 | * for each respective station upon request from userspace through nl80211. |
Luis R. Rodriguez | 7e189a1 | 2009-06-02 18:38:14 -0400 | [diff] [blame] | 54 | * |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 55 | * In order to remove a STA info structure, various sta_info_destroy_*() |
| 56 | * calls are available. |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 57 | * |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 58 | * There is no concept of ownership on a STA entry, each structure is |
| 59 | * owned by the global hash table/list until it is removed. All users of |
| 60 | * the structure need to be RCU protected so that the structure won't be |
| 61 | * freed before they are done using it. |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 62 | */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 63 | |
| 64 | /* Caller must hold local->sta_lock */ |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 65 | static int sta_info_hash_del(struct ieee80211_local *local, |
| 66 | struct sta_info *sta) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 67 | { |
| 68 | struct sta_info *s; |
| 69 | |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 70 | s = rcu_dereference_protected(local->sta_hash[STA_HASH(sta->sta.addr)], |
| 71 | lockdep_is_held(&local->sta_lock)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 72 | if (!s) |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 73 | return -ENOENT; |
| 74 | if (s == sta) { |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 75 | rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 76 | s->hnext); |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 77 | return 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 80 | while (rcu_access_pointer(s->hnext) && |
| 81 | rcu_access_pointer(s->hnext) != sta) |
| 82 | s = rcu_dereference_protected(s->hnext, |
| 83 | lockdep_is_held(&local->sta_lock)); |
| 84 | if (rcu_access_pointer(s->hnext)) { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 85 | rcu_assign_pointer(s->hnext, sta->hnext); |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 86 | return 0; |
| 87 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 88 | |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 89 | return -ENOENT; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 92 | /* protected by RCU */ |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 93 | struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata, |
| 94 | const u8 *addr) |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 95 | { |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 96 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 97 | struct sta_info *sta; |
| 98 | |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 99 | sta = rcu_dereference_check(local->sta_hash[STA_HASH(addr)], |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 100 | lockdep_is_held(&local->sta_lock) || |
| 101 | lockdep_is_held(&local->sta_mtx)); |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 102 | while (sta) { |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 103 | if (sta->sdata == sdata && !sta->dummy && |
| 104 | memcmp(sta->sta.addr, addr, ETH_ALEN) == 0) |
| 105 | break; |
| 106 | sta = rcu_dereference_check(sta->hnext, |
| 107 | lockdep_is_held(&local->sta_lock) || |
| 108 | lockdep_is_held(&local->sta_mtx)); |
| 109 | } |
| 110 | return sta; |
| 111 | } |
| 112 | |
| 113 | /* get a station info entry even if it is a dummy station*/ |
| 114 | struct sta_info *sta_info_get_rx(struct ieee80211_sub_if_data *sdata, |
| 115 | const u8 *addr) |
| 116 | { |
| 117 | struct ieee80211_local *local = sdata->local; |
| 118 | struct sta_info *sta; |
| 119 | |
| 120 | sta = rcu_dereference_check(local->sta_hash[STA_HASH(addr)], |
| 121 | lockdep_is_held(&local->sta_lock) || |
| 122 | lockdep_is_held(&local->sta_mtx)); |
| 123 | while (sta) { |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 124 | if (sta->sdata == sdata && |
| 125 | memcmp(sta->sta.addr, addr, ETH_ALEN) == 0) |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 126 | break; |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 127 | sta = rcu_dereference_check(sta->hnext, |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 128 | lockdep_is_held(&local->sta_lock) || |
| 129 | lockdep_is_held(&local->sta_mtx)); |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 130 | } |
| 131 | return sta; |
| 132 | } |
| 133 | |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 134 | /* |
| 135 | * Get sta info either from the specified interface |
| 136 | * or from one of its vlans |
| 137 | */ |
| 138 | struct sta_info *sta_info_get_bss(struct ieee80211_sub_if_data *sdata, |
| 139 | const u8 *addr) |
| 140 | { |
| 141 | struct ieee80211_local *local = sdata->local; |
| 142 | struct sta_info *sta; |
| 143 | |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 144 | sta = rcu_dereference_check(local->sta_hash[STA_HASH(addr)], |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 145 | lockdep_is_held(&local->sta_lock) || |
| 146 | lockdep_is_held(&local->sta_mtx)); |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 147 | while (sta) { |
| 148 | if ((sta->sdata == sdata || |
Johannes Berg | a2c1e3d | 2010-09-14 21:34:14 +0200 | [diff] [blame] | 149 | (sta->sdata->bss && sta->sdata->bss == sdata->bss)) && |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 150 | !sta->dummy && |
| 151 | memcmp(sta->sta.addr, addr, ETH_ALEN) == 0) |
| 152 | break; |
| 153 | sta = rcu_dereference_check(sta->hnext, |
| 154 | lockdep_is_held(&local->sta_lock) || |
| 155 | lockdep_is_held(&local->sta_mtx)); |
| 156 | } |
| 157 | return sta; |
| 158 | } |
| 159 | |
| 160 | /* |
| 161 | * Get sta info either from the specified interface |
| 162 | * or from one of its vlans (including dummy stations) |
| 163 | */ |
| 164 | struct sta_info *sta_info_get_bss_rx(struct ieee80211_sub_if_data *sdata, |
| 165 | const u8 *addr) |
| 166 | { |
| 167 | struct ieee80211_local *local = sdata->local; |
| 168 | struct sta_info *sta; |
| 169 | |
| 170 | sta = rcu_dereference_check(local->sta_hash[STA_HASH(addr)], |
| 171 | lockdep_is_held(&local->sta_lock) || |
| 172 | lockdep_is_held(&local->sta_mtx)); |
| 173 | while (sta) { |
| 174 | if ((sta->sdata == sdata || |
| 175 | (sta->sdata->bss && sta->sdata->bss == sdata->bss)) && |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 176 | memcmp(sta->sta.addr, addr, ETH_ALEN) == 0) |
| 177 | break; |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 178 | sta = rcu_dereference_check(sta->hnext, |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 179 | lockdep_is_held(&local->sta_lock) || |
| 180 | lockdep_is_held(&local->sta_mtx)); |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 181 | } |
| 182 | return sta; |
| 183 | } |
| 184 | |
Johannes Berg | 3b53fde8 | 2009-11-16 12:00:37 +0100 | [diff] [blame] | 185 | struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata, |
| 186 | int idx) |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 187 | { |
Johannes Berg | 3b53fde8 | 2009-11-16 12:00:37 +0100 | [diff] [blame] | 188 | struct ieee80211_local *local = sdata->local; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 189 | struct sta_info *sta; |
| 190 | int i = 0; |
| 191 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 192 | list_for_each_entry_rcu(sta, &local->sta_list, list) { |
Johannes Berg | 3b53fde8 | 2009-11-16 12:00:37 +0100 | [diff] [blame] | 193 | if (sdata != sta->sdata) |
Luis Carlos Cobo | 2a8ca29 | 2008-02-29 17:51:25 -0800 | [diff] [blame] | 194 | continue; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 195 | if (i < idx) { |
| 196 | ++i; |
| 197 | continue; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 198 | } |
Luis Carlos Cobo | 2a8ca29 | 2008-02-29 17:51:25 -0800 | [diff] [blame] | 199 | return sta; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 200 | } |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 201 | |
| 202 | return NULL; |
| 203 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 204 | |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 205 | /** |
| 206 | * __sta_info_free - internal STA free helper |
| 207 | * |
Randy Dunlap | 6ef307b | 2008-07-03 13:52:18 -0700 | [diff] [blame] | 208 | * @local: pointer to the global information |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 209 | * @sta: STA info to free |
| 210 | * |
| 211 | * This function must undo everything done by sta_info_alloc() |
| 212 | * that may happen before sta_info_insert(). |
| 213 | */ |
| 214 | static void __sta_info_free(struct ieee80211_local *local, |
| 215 | struct sta_info *sta) |
| 216 | { |
Johannes Berg | af65cd96 | 2009-11-17 18:18:36 +0100 | [diff] [blame] | 217 | if (sta->rate_ctrl) { |
| 218 | rate_control_free_sta(sta); |
| 219 | rate_control_put(sta->rate_ctrl); |
| 220 | } |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 221 | |
| 222 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Joe Perches | 0fb9a9e | 2010-08-20 16:25:38 -0700 | [diff] [blame] | 223 | wiphy_debug(local->hw.wiphy, "Destroyed STA %pM\n", sta->sta.addr); |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 224 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 225 | |
| 226 | kfree(sta); |
| 227 | } |
| 228 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 229 | /* Caller must hold local->sta_lock */ |
| 230 | static void sta_info_hash_add(struct ieee80211_local *local, |
| 231 | struct sta_info *sta) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 232 | { |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 233 | sta->hnext = local->sta_hash[STA_HASH(sta->sta.addr)]; |
| 234 | rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 235 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 236 | |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 237 | static void sta_unblock(struct work_struct *wk) |
| 238 | { |
| 239 | struct sta_info *sta; |
| 240 | |
| 241 | sta = container_of(wk, struct sta_info, drv_unblock_wk); |
| 242 | |
| 243 | if (sta->dead) |
| 244 | return; |
| 245 | |
| 246 | if (!test_sta_flags(sta, WLAN_STA_PS_STA)) |
| 247 | ieee80211_sta_ps_deliver_wakeup(sta); |
Johannes Berg | 50a9432 | 2010-11-16 11:50:28 -0800 | [diff] [blame] | 248 | else if (test_and_clear_sta_flags(sta, WLAN_STA_PSPOLL)) { |
| 249 | clear_sta_flags(sta, WLAN_STA_PS_DRIVER); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 250 | ieee80211_sta_ps_deliver_poll_response(sta); |
Johannes Berg | 50a9432 | 2010-11-16 11:50:28 -0800 | [diff] [blame] | 251 | } else |
| 252 | clear_sta_flags(sta, WLAN_STA_PS_DRIVER); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 253 | } |
| 254 | |
Johannes Berg | af65cd96 | 2009-11-17 18:18:36 +0100 | [diff] [blame] | 255 | static int sta_prepare_rate_control(struct ieee80211_local *local, |
| 256 | struct sta_info *sta, gfp_t gfp) |
| 257 | { |
| 258 | if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) |
| 259 | return 0; |
| 260 | |
| 261 | sta->rate_ctrl = rate_control_get(local->rate_ctrl); |
| 262 | sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl, |
| 263 | &sta->sta, gfp); |
| 264 | if (!sta->rate_ctrl_priv) { |
| 265 | rate_control_put(sta->rate_ctrl); |
| 266 | return -ENOMEM; |
| 267 | } |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 272 | struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata, |
| 273 | u8 *addr, gfp_t gfp) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 274 | { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 275 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 276 | struct sta_info *sta; |
Mohammed Shafi Shajakhan | ebe27c9 | 2011-04-08 21:24:24 +0530 | [diff] [blame] | 277 | struct timespec uptime; |
Ron Rindjunsky | 16c5f15 | 2007-12-25 17:00:34 +0200 | [diff] [blame] | 278 | int i; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 279 | |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 280 | sta = kzalloc(sizeof(*sta) + local->hw.sta_data_size, gfp); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 281 | if (!sta) |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 282 | return NULL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 283 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 284 | spin_lock_init(&sta->lock); |
Johannes Berg | 5a9f7b0 | 2008-06-18 14:58:09 +0200 | [diff] [blame] | 285 | spin_lock_init(&sta->flaglock); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 286 | INIT_WORK(&sta->drv_unblock_wk, sta_unblock); |
Johannes Berg | 67c282c | 2010-06-10 10:21:43 +0200 | [diff] [blame] | 287 | INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work); |
Johannes Berg | a93e364 | 2010-06-10 10:21:46 +0200 | [diff] [blame] | 288 | mutex_init(&sta->ampdu_mlme.mtx); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 289 | |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 290 | memcpy(sta->sta.addr, addr, ETH_ALEN); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 291 | sta->local = local; |
| 292 | sta->sdata = sdata; |
Felix Fietkau | 8bc8aec | 2011-03-21 20:01:00 +0100 | [diff] [blame] | 293 | sta->last_rx = jiffies; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 294 | |
Mohammed Shafi Shajakhan | ebe27c9 | 2011-04-08 21:24:24 +0530 | [diff] [blame] | 295 | do_posix_clock_monotonic_gettime(&uptime); |
| 296 | sta->last_connected = uptime.tv_sec; |
Bruno Randolf | 541a45a | 2010-12-02 19:12:43 +0900 | [diff] [blame] | 297 | ewma_init(&sta->avg_signal, 1024, 8); |
| 298 | |
Johannes Berg | af65cd96 | 2009-11-17 18:18:36 +0100 | [diff] [blame] | 299 | if (sta_prepare_rate_control(local, sta, gfp)) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 300 | kfree(sta); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 301 | return NULL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Ron Rindjunsky | 16c5f15 | 2007-12-25 17:00:34 +0200 | [diff] [blame] | 304 | for (i = 0; i < STA_TID_NUM; i++) { |
Johannes Berg | a622ab7 | 2010-06-10 10:21:39 +0200 | [diff] [blame] | 305 | /* |
| 306 | * timer_to_tid must be initialized with identity mapping |
| 307 | * to enable session_timer's data differentiation. See |
| 308 | * sta_rx_agg_session_timer_expired for usage. |
| 309 | */ |
Ron Rindjunsky | 16c5f15 | 2007-12-25 17:00:34 +0200 | [diff] [blame] | 310 | sta->timer_to_tid[i] = i; |
Ron Rindjunsky | 16c5f15 | 2007-12-25 17:00:34 +0200 | [diff] [blame] | 311 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 312 | skb_queue_head_init(&sta->ps_tx_buf); |
| 313 | skb_queue_head_init(&sta->tx_filtered); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 314 | |
Senthil Balasubramanian | cccaec9 | 2009-05-14 18:42:08 +0530 | [diff] [blame] | 315 | for (i = 0; i < NUM_RX_DATA_QUEUES; i++) |
Alexey Dobriyan | 4be929b | 2010-05-24 14:33:03 -0700 | [diff] [blame] | 316 | sta->last_seq_ctrl[i] = cpu_to_le16(USHRT_MAX); |
Senthil Balasubramanian | cccaec9 | 2009-05-14 18:42:08 +0530 | [diff] [blame] | 317 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 318 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Joe Perches | 0fb9a9e | 2010-08-20 16:25:38 -0700 | [diff] [blame] | 319 | wiphy_debug(local->hw.wiphy, "Allocated STA %pM\n", sta->sta.addr); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 320 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 321 | |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 322 | #ifdef CONFIG_MAC80211_MESH |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 323 | sta->plink_state = NL80211_PLINK_LISTEN; |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 324 | init_timer(&sta->plink_timer); |
| 325 | #endif |
| 326 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 327 | return sta; |
| 328 | } |
| 329 | |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 330 | static int sta_info_finish_insert(struct sta_info *sta, |
| 331 | bool async, bool dummy_reinsert) |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 332 | { |
| 333 | struct ieee80211_local *local = sta->local; |
| 334 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 335 | struct station_info sinfo; |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 336 | unsigned long flags; |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 337 | int err = 0; |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 338 | |
Johannes Berg | 46a5eba | 2010-09-15 13:28:15 +0200 | [diff] [blame] | 339 | lockdep_assert_held(&local->sta_mtx); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 340 | |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 341 | if (!sta->dummy || dummy_reinsert) { |
| 342 | /* notify driver */ |
| 343 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
| 344 | sdata = container_of(sdata->bss, |
| 345 | struct ieee80211_sub_if_data, |
| 346 | u.ap); |
| 347 | err = drv_sta_add(local, sdata, &sta->sta); |
| 348 | if (err) { |
| 349 | if (!async) |
| 350 | return err; |
| 351 | printk(KERN_DEBUG "%s: failed to add IBSS STA %pM to " |
| 352 | "driver (%d) - keeping it anyway.\n", |
| 353 | sdata->name, sta->sta.addr, err); |
| 354 | } else { |
| 355 | sta->uploaded = true; |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 356 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 357 | if (async) |
| 358 | wiphy_debug(local->hw.wiphy, |
| 359 | "Finished adding IBSS STA %pM\n", |
| 360 | sta->sta.addr); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 361 | #endif |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | sdata = sta->sdata; |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 365 | } |
| 366 | |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 367 | if (!dummy_reinsert) { |
| 368 | if (!async) { |
| 369 | local->num_sta++; |
| 370 | local->sta_generation++; |
| 371 | smp_mb(); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 372 | |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 373 | /* make the station visible */ |
| 374 | spin_lock_irqsave(&local->sta_lock, flags); |
| 375 | sta_info_hash_add(local, sta); |
| 376 | spin_unlock_irqrestore(&local->sta_lock, flags); |
| 377 | } |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 378 | |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 379 | list_add(&sta->list, &local->sta_list); |
| 380 | } else { |
| 381 | sta->dummy = false; |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 382 | } |
| 383 | |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 384 | if (!sta->dummy) { |
| 385 | ieee80211_sta_debugfs_add(sta); |
| 386 | rate_control_add_sta_debugfs(sta); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 387 | |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 388 | memset(&sinfo, 0, sizeof(sinfo)); |
| 389 | sinfo.filled = 0; |
| 390 | sinfo.generation = local->sta_generation; |
| 391 | cfg80211_new_sta(sdata->dev, sta->sta.addr, &sinfo, GFP_KERNEL); |
| 392 | } |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 393 | |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | static void sta_info_finish_pending(struct ieee80211_local *local) |
| 398 | { |
| 399 | struct sta_info *sta; |
| 400 | unsigned long flags; |
| 401 | |
| 402 | spin_lock_irqsave(&local->sta_lock, flags); |
| 403 | while (!list_empty(&local->sta_pending_list)) { |
| 404 | sta = list_first_entry(&local->sta_pending_list, |
| 405 | struct sta_info, list); |
| 406 | list_del(&sta->list); |
| 407 | spin_unlock_irqrestore(&local->sta_lock, flags); |
| 408 | |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 409 | sta_info_finish_insert(sta, true, false); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 410 | |
| 411 | spin_lock_irqsave(&local->sta_lock, flags); |
| 412 | } |
| 413 | spin_unlock_irqrestore(&local->sta_lock, flags); |
| 414 | } |
| 415 | |
| 416 | static void sta_info_finish_work(struct work_struct *work) |
| 417 | { |
| 418 | struct ieee80211_local *local = |
| 419 | container_of(work, struct ieee80211_local, sta_finish_work); |
| 420 | |
| 421 | mutex_lock(&local->sta_mtx); |
| 422 | sta_info_finish_pending(local); |
| 423 | mutex_unlock(&local->sta_mtx); |
| 424 | } |
| 425 | |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 426 | static int sta_info_insert_check(struct sta_info *sta) |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 427 | { |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 428 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 429 | |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 430 | /* |
| 431 | * Can't be a WARN_ON because it can be triggered through a race: |
| 432 | * something inserts a STA (on one CPU) without holding the RTNL |
| 433 | * and another CPU turns off the net device. |
| 434 | */ |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 435 | if (unlikely(!ieee80211_sdata_running(sdata))) |
| 436 | return -ENETDOWN; |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 437 | |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 438 | if (WARN_ON(compare_ether_addr(sta->sta.addr, sdata->vif.addr) == 0 || |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 439 | is_multicast_ether_addr(sta->sta.addr))) |
| 440 | return -EINVAL; |
| 441 | |
| 442 | return 0; |
| 443 | } |
| 444 | |
| 445 | static int sta_info_insert_ibss(struct sta_info *sta) __acquires(RCU) |
| 446 | { |
| 447 | struct ieee80211_local *local = sta->local; |
| 448 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 449 | unsigned long flags; |
| 450 | |
| 451 | spin_lock_irqsave(&local->sta_lock, flags); |
| 452 | /* check if STA exists already */ |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 453 | if (sta_info_get_bss_rx(sdata, sta->sta.addr)) { |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 454 | spin_unlock_irqrestore(&local->sta_lock, flags); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 455 | rcu_read_lock(); |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 456 | return -EEXIST; |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 457 | } |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 458 | |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 459 | local->num_sta++; |
| 460 | local->sta_generation++; |
| 461 | smp_mb(); |
| 462 | sta_info_hash_add(local, sta); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 463 | |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 464 | list_add_tail(&sta->list, &local->sta_pending_list); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 465 | |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 466 | rcu_read_lock(); |
| 467 | spin_unlock_irqrestore(&local->sta_lock, flags); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 468 | |
| 469 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 470 | wiphy_debug(local->hw.wiphy, "Added IBSS STA %pM\n", |
| 471 | sta->sta.addr); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 472 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 473 | |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 474 | ieee80211_queue_work(&local->hw, &local->sta_finish_work); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 475 | |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | /* |
| 480 | * should be called with sta_mtx locked |
| 481 | * this function replaces the mutex lock |
| 482 | * with a RCU lock |
| 483 | */ |
| 484 | static int sta_info_insert_non_ibss(struct sta_info *sta) __acquires(RCU) |
| 485 | { |
| 486 | struct ieee80211_local *local = sta->local; |
| 487 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 488 | unsigned long flags; |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 489 | struct sta_info *exist_sta; |
| 490 | bool dummy_reinsert = false; |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 491 | int err = 0; |
| 492 | |
| 493 | lockdep_assert_held(&local->sta_mtx); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 494 | |
| 495 | /* |
| 496 | * On first glance, this will look racy, because the code |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 497 | * in this function, which inserts a station with sleeping, |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 498 | * unlocks the sta_lock between checking existence in the |
| 499 | * hash table and inserting into it. |
| 500 | * |
| 501 | * However, it is not racy against itself because it keeps |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 502 | * the mutex locked. |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 503 | */ |
| 504 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 505 | spin_lock_irqsave(&local->sta_lock, flags); |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 506 | /* |
| 507 | * check if STA exists already. |
| 508 | * only accept a scenario of a second call to sta_info_insert_non_ibss |
| 509 | * with a dummy station entry that was inserted earlier |
| 510 | * in that case - assume that the dummy station flag should |
| 511 | * be removed. |
| 512 | */ |
| 513 | exist_sta = sta_info_get_bss_rx(sdata, sta->sta.addr); |
| 514 | if (exist_sta) { |
| 515 | if (exist_sta == sta && sta->dummy) { |
| 516 | dummy_reinsert = true; |
| 517 | } else { |
| 518 | spin_unlock_irqrestore(&local->sta_lock, flags); |
| 519 | mutex_unlock(&local->sta_mtx); |
| 520 | rcu_read_lock(); |
| 521 | return -EEXIST; |
| 522 | } |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 523 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 524 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 525 | spin_unlock_irqrestore(&local->sta_lock, flags); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 526 | |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 527 | err = sta_info_finish_insert(sta, false, dummy_reinsert); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 528 | if (err) { |
| 529 | mutex_unlock(&local->sta_mtx); |
| 530 | rcu_read_lock(); |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 531 | return err; |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 532 | } |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 533 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 534 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 535 | wiphy_debug(local->hw.wiphy, "Inserted %sSTA %pM\n", |
| 536 | sta->dummy ? "dummy " : "", sta->sta.addr); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 537 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 538 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 539 | /* move reference to rcu-protected */ |
| 540 | rcu_read_lock(); |
| 541 | mutex_unlock(&local->sta_mtx); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 542 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 543 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
| 544 | mesh_accept_plinks_update(sdata); |
| 545 | |
| 546 | return 0; |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU) |
| 550 | { |
| 551 | struct ieee80211_local *local = sta->local; |
| 552 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 553 | int err = 0; |
| 554 | |
| 555 | err = sta_info_insert_check(sta); |
| 556 | if (err) { |
| 557 | rcu_read_lock(); |
| 558 | goto out_free; |
| 559 | } |
| 560 | |
| 561 | /* |
| 562 | * In ad-hoc mode, we sometimes need to insert stations |
| 563 | * from tasklet context from the RX path. To avoid races, |
| 564 | * always do so in that case -- see the comment below. |
| 565 | */ |
| 566 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { |
| 567 | err = sta_info_insert_ibss(sta); |
| 568 | if (err) |
| 569 | goto out_free; |
| 570 | |
| 571 | return 0; |
| 572 | } |
| 573 | |
| 574 | /* |
| 575 | * It might seem that the function called below is in race against |
| 576 | * the function call above that atomically inserts the station... That, |
| 577 | * however, is not true because the above code can only |
| 578 | * be invoked for IBSS interfaces, and the below code will |
| 579 | * not be -- and the two do not race against each other as |
| 580 | * the hash table also keys off the interface. |
| 581 | */ |
| 582 | |
| 583 | might_sleep(); |
| 584 | |
| 585 | mutex_lock(&local->sta_mtx); |
| 586 | |
| 587 | err = sta_info_insert_non_ibss(sta); |
| 588 | if (err) |
| 589 | goto out_free; |
| 590 | |
| 591 | return 0; |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 592 | out_free: |
| 593 | BUG_ON(!err); |
| 594 | __sta_info_free(local, sta); |
| 595 | return err; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 598 | int sta_info_insert(struct sta_info *sta) |
| 599 | { |
| 600 | int err = sta_info_insert_rcu(sta); |
| 601 | |
| 602 | rcu_read_unlock(); |
| 603 | |
| 604 | return err; |
| 605 | } |
| 606 | |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 607 | /* Caller must hold sta->local->sta_mtx */ |
| 608 | int sta_info_reinsert(struct sta_info *sta) |
| 609 | { |
| 610 | struct ieee80211_local *local = sta->local; |
| 611 | int err = 0; |
| 612 | |
| 613 | err = sta_info_insert_check(sta); |
| 614 | if (err) { |
| 615 | mutex_unlock(&local->sta_mtx); |
| 616 | return err; |
| 617 | } |
| 618 | |
| 619 | might_sleep(); |
| 620 | |
| 621 | err = sta_info_insert_non_ibss(sta); |
| 622 | rcu_read_unlock(); |
| 623 | return err; |
| 624 | } |
| 625 | |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 626 | static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid) |
| 627 | { |
| 628 | /* |
| 629 | * This format has been mandated by the IEEE specifications, |
| 630 | * so this line may not be changed to use the __set_bit() format. |
| 631 | */ |
| 632 | bss->tim[aid / 8] |= (1 << (aid % 8)); |
| 633 | } |
| 634 | |
| 635 | static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, u16 aid) |
| 636 | { |
| 637 | /* |
| 638 | * This format has been mandated by the IEEE specifications, |
| 639 | * so this line may not be changed to use the __clear_bit() format. |
| 640 | */ |
| 641 | bss->tim[aid / 8] &= ~(1 << (aid % 8)); |
| 642 | } |
| 643 | |
| 644 | static void __sta_info_set_tim_bit(struct ieee80211_if_ap *bss, |
| 645 | struct sta_info *sta) |
| 646 | { |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 647 | BUG_ON(!bss); |
| 648 | |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 649 | __bss_tim_set(bss, sta->sta.aid); |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 650 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 651 | if (sta->local->ops->set_tim) { |
| 652 | sta->local->tim_in_locked_section = true; |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 653 | drv_set_tim(sta->local, &sta->sta, true); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 654 | sta->local->tim_in_locked_section = false; |
| 655 | } |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | void sta_info_set_tim_bit(struct sta_info *sta) |
| 659 | { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 660 | unsigned long flags; |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 661 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 662 | BUG_ON(!sta->sdata->bss); |
| 663 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 664 | spin_lock_irqsave(&sta->local->sta_lock, flags); |
| 665 | __sta_info_set_tim_bit(sta->sdata->bss, sta); |
| 666 | spin_unlock_irqrestore(&sta->local->sta_lock, flags); |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | static void __sta_info_clear_tim_bit(struct ieee80211_if_ap *bss, |
| 670 | struct sta_info *sta) |
| 671 | { |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 672 | BUG_ON(!bss); |
| 673 | |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 674 | __bss_tim_clear(bss, sta->sta.aid); |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 675 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 676 | if (sta->local->ops->set_tim) { |
| 677 | sta->local->tim_in_locked_section = true; |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 678 | drv_set_tim(sta->local, &sta->sta, false); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 679 | sta->local->tim_in_locked_section = false; |
| 680 | } |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | void sta_info_clear_tim_bit(struct sta_info *sta) |
| 684 | { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 685 | unsigned long flags; |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 686 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 687 | BUG_ON(!sta->sdata->bss); |
| 688 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 689 | spin_lock_irqsave(&sta->local->sta_lock, flags); |
| 690 | __sta_info_clear_tim_bit(sta->sdata->bss, sta); |
| 691 | spin_unlock_irqrestore(&sta->local->sta_lock, flags); |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 692 | } |
| 693 | |
Johannes Berg | cd0b8d8 | 2011-09-06 14:13:06 +0200 | [diff] [blame] | 694 | static bool sta_info_buffer_expired(struct sta_info *sta, struct sk_buff *skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 695 | { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 696 | struct ieee80211_tx_info *info; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 697 | int timeout; |
| 698 | |
| 699 | if (!skb) |
Johannes Berg | cd0b8d8 | 2011-09-06 14:13:06 +0200 | [diff] [blame] | 700 | return false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 701 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 702 | info = IEEE80211_SKB_CB(skb); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 703 | |
| 704 | /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */ |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 705 | timeout = (sta->listen_interval * |
| 706 | sta->sdata->vif.bss_conf.beacon_int * |
| 707 | 32 / 15625) * HZ; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 708 | if (timeout < STA_TX_BUFFER_EXPIRE) |
| 709 | timeout = STA_TX_BUFFER_EXPIRE; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 710 | return time_after(jiffies, info->control.jiffies + timeout); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | |
Juuso Oikarinen | 3393a60 | 2010-04-19 10:12:52 +0300 | [diff] [blame] | 714 | static bool sta_info_cleanup_expire_buffered(struct ieee80211_local *local, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 715 | struct sta_info *sta) |
| 716 | { |
| 717 | unsigned long flags; |
| 718 | struct sk_buff *skb; |
| 719 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 720 | for (;;) { |
| 721 | spin_lock_irqsave(&sta->ps_tx_buf.lock, flags); |
| 722 | skb = skb_peek(&sta->ps_tx_buf); |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 723 | if (sta_info_buffer_expired(sta, skb)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 724 | skb = __skb_dequeue(&sta->ps_tx_buf); |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 725 | else |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 726 | skb = NULL; |
| 727 | spin_unlock_irqrestore(&sta->ps_tx_buf.lock, flags); |
| 728 | |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 729 | if (!skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 730 | break; |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 731 | |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 732 | local->total_ps_buffered--; |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 733 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 734 | printk(KERN_DEBUG "Buffered frame expired (STA %pM)\n", |
| 735 | sta->sta.addr); |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 736 | #endif |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 737 | dev_kfree_skb(skb); |
| 738 | |
Felix Fietkau | dcf55fb | 2011-04-17 17:45:00 +0200 | [diff] [blame] | 739 | if (skb_queue_empty(&sta->ps_tx_buf) && |
| 740 | !test_sta_flags(sta, WLAN_STA_PS_DRIVER_BUF)) |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 741 | sta_info_clear_tim_bit(sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 742 | } |
Juuso Oikarinen | 3393a60 | 2010-04-19 10:12:52 +0300 | [diff] [blame] | 743 | |
Johannes Berg | cd0b8d8 | 2011-09-06 14:13:06 +0200 | [diff] [blame] | 744 | return !skb_queue_empty(&sta->ps_tx_buf); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 745 | } |
| 746 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 747 | static int __must_check __sta_info_destroy(struct sta_info *sta) |
| 748 | { |
| 749 | struct ieee80211_local *local; |
| 750 | struct ieee80211_sub_if_data *sdata; |
| 751 | struct sk_buff *skb; |
| 752 | unsigned long flags; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 753 | int ret, i; |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 754 | |
| 755 | might_sleep(); |
| 756 | |
| 757 | if (!sta) |
| 758 | return -ENOENT; |
| 759 | |
| 760 | local = sta->local; |
| 761 | sdata = sta->sdata; |
| 762 | |
Johannes Berg | 098a607 | 2010-04-06 11:18:47 +0200 | [diff] [blame] | 763 | /* |
| 764 | * Before removing the station from the driver and |
| 765 | * rate control, it might still start new aggregation |
| 766 | * sessions -- block that to make sure the tear-down |
| 767 | * will be sufficient. |
| 768 | */ |
| 769 | set_sta_flags(sta, WLAN_STA_BLOCK_BA); |
Johannes Berg | 53f73c0 | 2010-10-05 19:37:40 +0200 | [diff] [blame] | 770 | ieee80211_sta_tear_down_BA_sessions(sta, true); |
Johannes Berg | 098a607 | 2010-04-06 11:18:47 +0200 | [diff] [blame] | 771 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 772 | spin_lock_irqsave(&local->sta_lock, flags); |
| 773 | ret = sta_info_hash_del(local, sta); |
| 774 | /* this might still be the pending list ... which is fine */ |
| 775 | if (!ret) |
| 776 | list_del(&sta->list); |
| 777 | spin_unlock_irqrestore(&local->sta_lock, flags); |
| 778 | if (ret) |
| 779 | return ret; |
| 780 | |
Johannes Berg | 8cb2315 | 2011-05-12 15:07:15 +0200 | [diff] [blame] | 781 | mutex_lock(&local->key_mtx); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 782 | for (i = 0; i < NUM_DEFAULT_KEYS; i++) |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 783 | __ieee80211_key_free(key_mtx_dereference(local, sta->gtk[i])); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 784 | if (sta->ptk) |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 785 | __ieee80211_key_free(key_mtx_dereference(local, sta->ptk)); |
Johannes Berg | 8cb2315 | 2011-05-12 15:07:15 +0200 | [diff] [blame] | 786 | mutex_unlock(&local->key_mtx); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 787 | |
| 788 | sta->dead = true; |
| 789 | |
| 790 | if (test_and_clear_sta_flags(sta, |
| 791 | WLAN_STA_PS_STA | WLAN_STA_PS_DRIVER)) { |
| 792 | BUG_ON(!sdata->bss); |
| 793 | |
| 794 | atomic_dec(&sdata->bss->num_sta_ps); |
Johannes Berg | 4bae7d97 | 2011-09-06 12:47:39 +0200 | [diff] [blame] | 795 | sta_info_clear_tim_bit(sta); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | local->num_sta--; |
| 799 | local->sta_generation++; |
| 800 | |
| 801 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
| 802 | rcu_assign_pointer(sdata->u.vlan.sta, NULL); |
| 803 | |
| 804 | if (sta->uploaded) { |
| 805 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
| 806 | sdata = container_of(sdata->bss, |
| 807 | struct ieee80211_sub_if_data, |
| 808 | u.ap); |
| 809 | drv_sta_remove(local, sdata, &sta->sta); |
| 810 | sdata = sta->sdata; |
| 811 | } |
| 812 | |
Johannes Berg | e64b379 | 2010-04-06 11:18:43 +0200 | [diff] [blame] | 813 | /* |
| 814 | * At this point, after we wait for an RCU grace period, |
| 815 | * neither mac80211 nor the driver can reference this |
| 816 | * sta struct any more except by still existing timers |
| 817 | * associated with this station that we clean up below. |
| 818 | */ |
| 819 | synchronize_rcu(); |
| 820 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 821 | #ifdef CONFIG_MAC80211_MESH |
Johannes Berg | e64b379 | 2010-04-06 11:18:43 +0200 | [diff] [blame] | 822 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 823 | mesh_accept_plinks_update(sdata); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 824 | #endif |
| 825 | |
| 826 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Joe Perches | 0fb9a9e | 2010-08-20 16:25:38 -0700 | [diff] [blame] | 827 | wiphy_debug(local->hw.wiphy, "Removed STA %pM\n", sta->sta.addr); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 828 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 829 | cancel_work_sync(&sta->drv_unblock_wk); |
| 830 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 831 | cfg80211_del_sta(sdata->dev, sta->sta.addr, GFP_KERNEL); |
| 832 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 833 | rate_control_remove_sta_debugfs(sta); |
| 834 | ieee80211_sta_debugfs_remove(sta); |
| 835 | |
| 836 | #ifdef CONFIG_MAC80211_MESH |
| 837 | if (ieee80211_vif_is_mesh(&sta->sdata->vif)) { |
| 838 | mesh_plink_deactivate(sta); |
| 839 | del_timer_sync(&sta->plink_timer); |
| 840 | } |
| 841 | #endif |
| 842 | |
| 843 | while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) { |
| 844 | local->total_ps_buffered--; |
| 845 | dev_kfree_skb_any(skb); |
| 846 | } |
| 847 | |
| 848 | while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) |
| 849 | dev_kfree_skb_any(skb); |
| 850 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 851 | __sta_info_free(local, sta); |
| 852 | |
| 853 | return 0; |
| 854 | } |
| 855 | |
| 856 | int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata, const u8 *addr) |
| 857 | { |
| 858 | struct sta_info *sta; |
| 859 | int ret; |
| 860 | |
| 861 | mutex_lock(&sdata->local->sta_mtx); |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 862 | sta = sta_info_get_rx(sdata, addr); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 863 | ret = __sta_info_destroy(sta); |
| 864 | mutex_unlock(&sdata->local->sta_mtx); |
| 865 | |
| 866 | return ret; |
| 867 | } |
| 868 | |
| 869 | int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata, |
| 870 | const u8 *addr) |
| 871 | { |
| 872 | struct sta_info *sta; |
| 873 | int ret; |
| 874 | |
| 875 | mutex_lock(&sdata->local->sta_mtx); |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 876 | sta = sta_info_get_bss_rx(sdata, addr); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 877 | ret = __sta_info_destroy(sta); |
| 878 | mutex_unlock(&sdata->local->sta_mtx); |
| 879 | |
| 880 | return ret; |
| 881 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 882 | |
| 883 | static void sta_info_cleanup(unsigned long data) |
| 884 | { |
| 885 | struct ieee80211_local *local = (struct ieee80211_local *) data; |
| 886 | struct sta_info *sta; |
Juuso Oikarinen | 3393a60 | 2010-04-19 10:12:52 +0300 | [diff] [blame] | 887 | bool timer_needed = false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 888 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 889 | rcu_read_lock(); |
| 890 | list_for_each_entry_rcu(sta, &local->sta_list, list) |
Juuso Oikarinen | 3393a60 | 2010-04-19 10:12:52 +0300 | [diff] [blame] | 891 | if (sta_info_cleanup_expire_buffered(local, sta)) |
| 892 | timer_needed = true; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 893 | rcu_read_unlock(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 894 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 895 | if (local->quiescing) |
| 896 | return; |
| 897 | |
Juuso Oikarinen | 3393a60 | 2010-04-19 10:12:52 +0300 | [diff] [blame] | 898 | if (!timer_needed) |
| 899 | return; |
| 900 | |
Johannes Berg | 26d5953 | 2011-04-01 13:52:48 +0200 | [diff] [blame] | 901 | mod_timer(&local->sta_cleanup, |
| 902 | round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | void sta_info_init(struct ieee80211_local *local) |
| 906 | { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 907 | spin_lock_init(&local->sta_lock); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 908 | mutex_init(&local->sta_mtx); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 909 | INIT_LIST_HEAD(&local->sta_list); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 910 | INIT_LIST_HEAD(&local->sta_pending_list); |
| 911 | INIT_WORK(&local->sta_finish_work, sta_info_finish_work); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 912 | |
Pavel Emelyanov | b24b8a2 | 2008-01-23 21:20:07 -0800 | [diff] [blame] | 913 | setup_timer(&local->sta_cleanup, sta_info_cleanup, |
| 914 | (unsigned long)local); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | void sta_info_stop(struct ieee80211_local *local) |
| 918 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 919 | del_timer(&local->sta_cleanup); |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 920 | sta_info_flush(local, NULL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 921 | } |
| 922 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 923 | /** |
| 924 | * sta_info_flush - flush matching STA entries from the STA table |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 925 | * |
| 926 | * Returns the number of removed STA entries. |
| 927 | * |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 928 | * @local: local interface data |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 929 | * @sdata: matching rule for the net device (sta->dev) or %NULL to match all STAs |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 930 | */ |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 931 | int sta_info_flush(struct ieee80211_local *local, |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 932 | struct ieee80211_sub_if_data *sdata) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 933 | { |
| 934 | struct sta_info *sta, *tmp; |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 935 | int ret = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 936 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 937 | might_sleep(); |
| 938 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 939 | mutex_lock(&local->sta_mtx); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 940 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 941 | sta_info_finish_pending(local); |
| 942 | |
| 943 | list_for_each_entry_safe(sta, tmp, &local->sta_list, list) { |
| 944 | if (!sdata || sdata == sta->sdata) |
| 945 | WARN_ON(__sta_info_destroy(sta)); |
| 946 | } |
| 947 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 948 | |
| 949 | return ret; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 950 | } |
Johannes Berg | dc6676b | 2008-03-31 19:23:03 +0200 | [diff] [blame] | 951 | |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 952 | void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata, |
| 953 | unsigned long exp_time) |
| 954 | { |
| 955 | struct ieee80211_local *local = sdata->local; |
| 956 | struct sta_info *sta, *tmp; |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 957 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 958 | mutex_lock(&local->sta_mtx); |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 959 | list_for_each_entry_safe(sta, tmp, &local->sta_list, list) |
| 960 | if (time_after(jiffies, sta->last_rx + exp_time)) { |
| 961 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 962 | printk(KERN_DEBUG "%s: expiring inactive STA %pM\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 963 | sdata->name, sta->sta.addr); |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 964 | #endif |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 965 | WARN_ON(__sta_info_destroy(sta)); |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 966 | } |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 967 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 968 | } |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 969 | |
Ben Greear | 686b9cb | 2010-09-23 09:44:36 -0700 | [diff] [blame] | 970 | struct ieee80211_sta *ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw, |
| 971 | const u8 *addr, |
| 972 | const u8 *localaddr) |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 973 | { |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 974 | struct sta_info *sta, *nxt; |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 975 | |
Ben Greear | 686b9cb | 2010-09-23 09:44:36 -0700 | [diff] [blame] | 976 | /* |
| 977 | * Just return a random station if localaddr is NULL |
| 978 | * ... first in list. |
| 979 | */ |
Johannes Berg | f7c6559 | 2010-04-30 13:48:36 +0200 | [diff] [blame] | 980 | for_each_sta_info(hw_to_local(hw), addr, sta, nxt) { |
Ben Greear | 686b9cb | 2010-09-23 09:44:36 -0700 | [diff] [blame] | 981 | if (localaddr && |
| 982 | compare_ether_addr(sta->sdata->vif.addr, localaddr) != 0) |
| 983 | continue; |
Johannes Berg | f7c6559 | 2010-04-30 13:48:36 +0200 | [diff] [blame] | 984 | if (!sta->uploaded) |
| 985 | return NULL; |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 986 | return &sta->sta; |
Johannes Berg | f7c6559 | 2010-04-30 13:48:36 +0200 | [diff] [blame] | 987 | } |
| 988 | |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 989 | return NULL; |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 990 | } |
Ben Greear | 686b9cb | 2010-09-23 09:44:36 -0700 | [diff] [blame] | 991 | EXPORT_SYMBOL_GPL(ieee80211_find_sta_by_ifaddr); |
Johannes Berg | 5ed176e | 2009-11-04 14:42:28 +0100 | [diff] [blame] | 992 | |
| 993 | struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_vif *vif, |
| 994 | const u8 *addr) |
| 995 | { |
Johannes Berg | f7c6559 | 2010-04-30 13:48:36 +0200 | [diff] [blame] | 996 | struct sta_info *sta; |
Johannes Berg | 5ed176e | 2009-11-04 14:42:28 +0100 | [diff] [blame] | 997 | |
| 998 | if (!vif) |
| 999 | return NULL; |
| 1000 | |
Johannes Berg | f7c6559 | 2010-04-30 13:48:36 +0200 | [diff] [blame] | 1001 | sta = sta_info_get_bss(vif_to_sdata(vif), addr); |
| 1002 | if (!sta) |
| 1003 | return NULL; |
Johannes Berg | 5ed176e | 2009-11-04 14:42:28 +0100 | [diff] [blame] | 1004 | |
Johannes Berg | f7c6559 | 2010-04-30 13:48:36 +0200 | [diff] [blame] | 1005 | if (!sta->uploaded) |
| 1006 | return NULL; |
| 1007 | |
| 1008 | return &sta->sta; |
Johannes Berg | 5ed176e | 2009-11-04 14:42:28 +0100 | [diff] [blame] | 1009 | } |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 1010 | EXPORT_SYMBOL(ieee80211_find_sta); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1011 | |
Johannes Berg | 50a9432 | 2010-11-16 11:50:28 -0800 | [diff] [blame] | 1012 | static void clear_sta_ps_flags(void *_sta) |
| 1013 | { |
| 1014 | struct sta_info *sta = _sta; |
| 1015 | |
| 1016 | clear_sta_flags(sta, WLAN_STA_PS_DRIVER | WLAN_STA_PS_STA); |
| 1017 | } |
| 1018 | |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1019 | /* powersave support code */ |
| 1020 | void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta) |
| 1021 | { |
| 1022 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 1023 | struct ieee80211_local *local = sdata->local; |
| 1024 | int sent, buffered; |
| 1025 | |
Felix Fietkau | dcf55fb | 2011-04-17 17:45:00 +0200 | [diff] [blame] | 1026 | clear_sta_flags(sta, WLAN_STA_PS_DRIVER_BUF); |
Arik Nemtsov | d057e5a | 2011-01-31 22:29:13 +0200 | [diff] [blame] | 1027 | if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS)) |
| 1028 | drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1029 | |
| 1030 | if (!skb_queue_empty(&sta->ps_tx_buf)) |
| 1031 | sta_info_clear_tim_bit(sta); |
| 1032 | |
| 1033 | /* Send all buffered frames to the station */ |
| 1034 | sent = ieee80211_add_pending_skbs(local, &sta->tx_filtered); |
Johannes Berg | 50a9432 | 2010-11-16 11:50:28 -0800 | [diff] [blame] | 1035 | buffered = ieee80211_add_pending_skbs_fn(local, &sta->ps_tx_buf, |
| 1036 | clear_sta_ps_flags, sta); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1037 | sent += buffered; |
| 1038 | local->total_ps_buffered -= buffered; |
| 1039 | |
| 1040 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
| 1041 | printk(KERN_DEBUG "%s: STA %pM aid %d sending %d filtered/%d PS frames " |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 1042 | "since STA not sleeping anymore\n", sdata->name, |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1043 | sta->sta.addr, sta->sta.aid, sent - buffered, buffered); |
| 1044 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
| 1045 | } |
| 1046 | |
| 1047 | void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta) |
| 1048 | { |
| 1049 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 1050 | struct ieee80211_local *local = sdata->local; |
| 1051 | struct sk_buff *skb; |
| 1052 | int no_pending_pkts; |
| 1053 | |
| 1054 | skb = skb_dequeue(&sta->tx_filtered); |
| 1055 | if (!skb) { |
| 1056 | skb = skb_dequeue(&sta->ps_tx_buf); |
| 1057 | if (skb) |
| 1058 | local->total_ps_buffered--; |
| 1059 | } |
| 1060 | no_pending_pkts = skb_queue_empty(&sta->tx_filtered) && |
| 1061 | skb_queue_empty(&sta->ps_tx_buf); |
| 1062 | |
| 1063 | if (skb) { |
| 1064 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1065 | struct ieee80211_hdr *hdr = |
| 1066 | (struct ieee80211_hdr *) skb->data; |
| 1067 | |
| 1068 | /* |
| 1069 | * Tell TX path to send this frame even though the STA may |
| 1070 | * still remain is PS mode after this frame exchange. |
| 1071 | */ |
| 1072 | info->flags |= IEEE80211_TX_CTL_PSPOLL_RESPONSE; |
| 1073 | |
| 1074 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
| 1075 | printk(KERN_DEBUG "STA %pM aid %d: PS Poll (entries after %d)\n", |
| 1076 | sta->sta.addr, sta->sta.aid, |
| 1077 | skb_queue_len(&sta->ps_tx_buf)); |
| 1078 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
| 1079 | |
| 1080 | /* Use MoreData flag to indicate whether there are more |
| 1081 | * buffered frames for this STA */ |
| 1082 | if (no_pending_pkts) |
| 1083 | hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA); |
| 1084 | else |
| 1085 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA); |
| 1086 | |
| 1087 | ieee80211_add_pending_skb(local, skb); |
| 1088 | |
| 1089 | if (no_pending_pkts) |
| 1090 | sta_info_clear_tim_bit(sta); |
| 1091 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
| 1092 | } else { |
| 1093 | /* |
| 1094 | * FIXME: This can be the result of a race condition between |
| 1095 | * us expiring a frame and the station polling for it. |
| 1096 | * Should we send it a null-func frame indicating we |
| 1097 | * have nothing buffered for it? |
| 1098 | */ |
| 1099 | printk(KERN_DEBUG "%s: STA %pM sent PS Poll even " |
| 1100 | "though there are no buffered frames for it\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 1101 | sdata->name, sta->sta.addr); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1102 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
| 1103 | } |
| 1104 | } |
| 1105 | |
| 1106 | void ieee80211_sta_block_awake(struct ieee80211_hw *hw, |
| 1107 | struct ieee80211_sta *pubsta, bool block) |
| 1108 | { |
| 1109 | struct sta_info *sta = container_of(pubsta, struct sta_info, sta); |
| 1110 | |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 1111 | trace_api_sta_block_awake(sta->local, pubsta, block); |
| 1112 | |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1113 | if (block) |
| 1114 | set_sta_flags(sta, WLAN_STA_PS_DRIVER); |
Johannes Berg | 50a9432 | 2010-11-16 11:50:28 -0800 | [diff] [blame] | 1115 | else if (test_sta_flags(sta, WLAN_STA_PS_DRIVER)) |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1116 | ieee80211_queue_work(hw, &sta->drv_unblock_wk); |
| 1117 | } |
| 1118 | EXPORT_SYMBOL(ieee80211_sta_block_awake); |
Felix Fietkau | dcf55fb | 2011-04-17 17:45:00 +0200 | [diff] [blame] | 1119 | |
| 1120 | void ieee80211_sta_set_tim(struct ieee80211_sta *pubsta) |
| 1121 | { |
| 1122 | struct sta_info *sta = container_of(pubsta, struct sta_info, sta); |
| 1123 | |
| 1124 | set_sta_flags(sta, WLAN_STA_PS_DRIVER_BUF); |
| 1125 | sta_info_set_tim_bit(sta); |
| 1126 | } |
| 1127 | EXPORT_SYMBOL(ieee80211_sta_set_tim); |